rgb2xyz.cpp

Engine/source/core/util/rgb2xyz.cpp

More...

Namespaces:

namespace

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#include "platform/platform.h"
25#include "core/util/rgb2xyz.h"
26
27#include "math/mMatrix.h"
28
29
30namespace ConvertRGB
31{
32
33// http://www.w3.org/Graphics/Color/sRGB
34static const F32 scRGB2XYZ[] = 
35{
36   0.4124f,  0.3576f,  0.1805f,  0.0f,
37   0.2126f,  0.7152f,  0.0722f,  0.0f,
38   0.0193f,  0.1192f,  0.9505f,  0.0f,
39   0.0f,     0.0f,     0.0f,     1.0f,
40};
41
42static const F32 scXYZ2RGB[] =
43{
44   3.2410f,  -1.5374f,  -0.4986f, 0.0f,
45   -0.9692f, 1.8760f,   0.0416f,  0.0f,
46   0.0556f,  -0.2040f,  1.0570f,  0.0f, 
47   0.0f,     0.0f,      0.0f,     1.0f,
48};
49
50LinearColorF toXYZ( const LinearColorF &rgbColor )
51{
52   const MatrixF &rgb2xyz = *((MatrixF *)scRGB2XYZ);
53
54   LinearColorF retColor = rgbColor;
55   rgb2xyz.mul( *(Point4F *)&retColor );
56   return retColor;
57}
58
59LinearColorF fromXYZ( const LinearColorF &xyzColor )
60{
61   const MatrixF &xyz2rgb = *((MatrixF *)scXYZ2RGB);
62
63   LinearColorF retColor = xyzColor;
64   xyz2rgb.mul( *(Point4F *)&retColor );
65   return retColor;
66}
67
68}
69