Monday, April 21, 2008

RGB -> XYZ conversion

Here is the official way to do it:
http://www.w3.org/Graphics/Color/sRGB

They use

// 0.4125 0.3576 0.1805
// 0.2126 0.7152 0.0722
// 0.0193 0.1192 0.9505

to convert from RGB to XYZ and

// 3.2410 -1.5374 -0.4986
// -0.9692 1.8760 0.0416
// 0.0556 -0.2040 1.0570


to convert back.


Here is how I do it:
const FLOAT3x3 RGB2XYZ = {0.5141364, 0.3238786, 0.16036376,
0.265068, 0.67023428, 0.06409157,
0.0241188, 0.1228178, 0.84442666};


Here is how I convert back:
const float3x3 XYZ2RGB = { 2.5651,-1.1665,-0.3986,
-1.0217, 1.9777, 0.0439,
0.0753, -0.2543, 1.1892};


You should definitely try out different ways to do this :-)

3 comments:

acid2 said...

Where are your numbers from? Is this simply tweaked versions of the W3 version - to look nicer, or is there some maths behind them?

Unknown said...

Great, I'll give it a shot. Thanks. I'll check if there are any differences...You get some special reasons for this? Btw, I am trying to do some spectrum rendering on GPU. The biggest problem is the transformation between Spectrum and XYZ. A numerical integration would be needed, which brings the performance down badly. The only way I figured out is to pre-compute the integration with some basis functions and store them in the tables (textures). It works, but not a perfect solution:(

Data said...

In the deferred renderer pipeline,
where do you do(would you do) conversion ?