Correct Yxy -> RGB conversion? back

Board: Board index ‹ Ray tracing ‹ General Development

(L) [2008/09/26] [greenhybrid] [Correct Yxy -> RGB conversion?] Wayback!

I lost the references where I grabbed the code, but I've found 2 routines for Yxy-RGB conversion, one seems to be for 70's CRTs, I hear.
* What do you know about it in general?
* Can it even be correct without the use of spectral-colors?
* Which one do you think is correct?
My current routine (I've added two questions, I'd love if you could answer):
Code: [LINK # Select all]void from_Yxy (real Y, real x, real y) {
    // 1) convert to XYZ
    real CIE_X = x * ( Y / y );
    real CIE_Y = Y;
    real CIE_Z = (1-x-y) * ( Y / y );
    //>>> Is this optional/necessary??
    /*CIE_X /= 100.0;
    CIE_Y /= 100.0;
    CIE_Z /= 100.0;*/
    // 2) To RGB
    r =  2.565 * CIE_X - 1.167 * CIE_Y - 0.398 * CIE_Z;
    g = -1.022 * CIE_X + 1.978 * CIE_Y + 0.044 * CIE_Z;
    b =  0.075 * CIE_X - 0.252 * CIE_Y + 1.177 * CIE_Z;
    //>>> What is this for??
    if ( r > 0.0031308 ) r = 1.055 * ( pow(r,(1/2.4) ) ) - 0.055;
    else                 r = 12.92 * r;
    if ( g > 0.0031308 ) g = 1.055 * ( pow(g,(1/2.4) ) ) - 0.055;
    else                 g = 12.92 * g;
    if ( b > 0.0031308 ) b = 1.055 * ( pow(b,(1/2.4) ) ) - 0.055;
    else                 b = 12.92 * b;
}

Another one I used to use:
Code: [LINK # Select all]static void Yxy_RGB (real *p_color, real Y, real x, real y) {
    real CIE_X = x * (Y / y);
    real CIE_Y = Y;
    real CIE_Z = (1-x-y) * (Y / y);
    //>>> necessary/optional?
    //CIE_X /= 100.0;
    //CIE_Y /= 100.0;
    //CIE_Z /= 100.0;
    //>>> Note: other coefficients (70's CRT?)?
    p_color[0] =   3.240479 * CIE_X - 1.537150 * CIE_Y - 0.498535 * CIE_Z;
    p_color[1] = - 0.969256 * CIE_X + 1.875991 * CIE_Y + 0.041556 * CIE_Z;
    p_color[2] =   0.055648 * CIE_X - 0.204043 * CIE_Y + 1.057311 * CIE_Z;
    //>>> same as in other code
    for (int i=0; i<3; i++) {
        if (p_color[i] > 0.0031308) {
            p_color[i] = 1.055 * (pow (p_color[i], (1/2.4))) - 0.055;
        } else {
            p_color[i] = 12.92 * p_color[i];
        }
    }
}

sidenote: my color class: [LINK http://cvs.savannah.gnu.org/viewvc/picogen/quantum/include/picogen/graphics/image.h?root=picogen&view=markup]
(L) [2008/09/26] [Michael77] [Correct Yxy -> RGB conversion?] Wayback!

>> greenhybrid wrote:Code: [LINK # Select all]    //>>> What is this for??
    if ( r > 0.0031308 ) r = 1.055 * ( pow(r,(1/2.4) ) ) - 0.055;
    else                 r = 12.92 * r;
    if ( g > 0.0031308 ) g = 1.055 * ( pow(g,(1/2.4) ) ) - 0.055;
    else                 g = 12.92 * g;
    if ( b > 0.0031308 ) b = 1.055 * ( pow(b,(1/2.4) ) ) - 0.055;
    else                 b = 12.92 * b;
}

Just to answer that question: This is the linear RGB to sRGB conversion.
(L) [2008/09/26] [tarlack] [Correct Yxy -> RGB conversion?] Wayback!

did you look at the one given in PBRT ? I don't know if it is correct, it is just a 3*3 conversion matrix...
(L) [2008/09/26] [greenhybrid] [Correct Yxy -> RGB conversion?] Wayback!

>> Michael77 wrote:greenhybrid wrote:Code: [LINK # Select all]    //>>> What is this for??
    if ( r > 0.0031308 ) r = 1.055 * ( pow(r,(1/2.4) ) ) - 0.055;
    else                 r = 12.92 * r;
    if ( g > 0.0031308 ) g = 1.055 * ( pow(g,(1/2.4) ) ) - 0.055;
    else                 g = 12.92 * g;
    if ( b > 0.0031308 ) b = 1.055 * ( pow(b,(1/2.4) ) ) - 0.055;
    else                 b = 12.92 * b;
}

Just to answer that question: This is the linear RGB to sRGB conversion.
yeah really? uh, oh. then i probably don't want it, right? i mean, i (for now) want to have those rgb-values which the screenbufer want?
thanks so far, i really wasn't aware of this.
edit: i've found this: [LINK http://en.wikipedia.org/wiki/Srgb#The_forward_transformation_.28CIE_xyY_or_CIE_XYZ_to_sRGB.29]
(L) [2008/09/26] [greenhybrid] [Correct Yxy -> RGB conversion?] Wayback!

>> tarlack wrote:did you look at the one given in PBRT ? I don't know if it is correct, it is just a 3*3 conversion matrix...
ah how could i not do that. i've bought a copy some months ago, but reading it takes some time, a real gem, and i will look into it.
(L) [2008/09/26] [madd] [Correct Yxy -> RGB conversion?] Wayback!

Compute that 3x3 matrix yourself! It's not hard. Then you know it is correct the correct one [SMILEY :D]
If you use the sRGB priminaries + white point you get the second version..
[LINK http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html]
(L) [2008/09/26] [thomast] [Correct Yxy -> RGB conversion?] Wayback!

>> greenhybrid wrote:yeah really? uh, oh. then i probably don't want it, right? i mean, i (for now) want to have those rgb-values which the screenbufer want?
You will want your final pictures to be in sRGB color space, since that is the web standard. Its just gamma correction over linear RGB.

back