patches1_xcms_fixes.diff Index: xc/lib/X11/Xcmsint.h =================================================================== --- xc.orig/lib/X11/Xcmsint.h 2005-11-22 08:07:53.000000000 +0100 +++ xc/lib/X11/Xcmsint.h 2005-11-22 08:33:36.000000000 +0100 @@ -211,13 +211,45 @@ */ #define XCMS_ATAN(x) _XcmsArcTangent(x) -#define XCMS_COS(x) _XcmsCosine(x) +#define XCMS_COS(x) (\ + (XcmsFloat)\ + (x > 0.0)\ + ?\ + ((x 0.0)\ + ?\ + ((x0.0 ? PI/2 : -PI/2)\ + : ( (x > 0)\ + ?(\ + (y > 0)\ + ?\ + XCMS_ATAN(x/y)\ + :\ + PI-XCMS_ATAN(x/XCMS_FABS(y))\ + )\ + :(\ + (y > 0)\ + ?\ + -XCMS_ATAN(XCMS_FABS(x)/y)\ + :\ + XCMS_ATAN(x/y)-PI\ + )\ + ) double _XcmsArcTangent(double a); double _XcmsCosine(double a); double _XcmsCubeRoot(double a); @@ -241,17 +273,10 @@ # define radians(d) ((XcmsFloat)(d) * PI / 180.0) #endif /* radians */ -#define XCMS_CIEUSTAROFHUE(h,c) \ -((XCMS_COS((h)) == 0.0) ? (XcmsFloat)0.0 : (XcmsFloat) \ -((XcmsFloat)(c) / (XcmsFloat)XCMS_SQRT((XCMS_TAN(h) * XCMS_TAN(h)) + \ -(XcmsFloat)1.0))) -#define XCMS_CIEVSTAROFHUE(h,c) \ -((XCMS_COS((h)) == 0.0) ? (XcmsFloat)0.0 : (XcmsFloat) \ -((XcmsFloat)(c) / (XcmsFloat)XCMS_SQRT(((XcmsFloat)1.0 / \ -(XcmsFloat)(XCMS_TAN(h) * XCMS_TAN(h))) + (XcmsFloat)1.0))) +#define XCMS_CIEUSTAROFHUE(h,c) XCMS_COS(h)*c +#define XCMS_CIEVSTAROFHUE(h,c) XCMS_SIN(h)*c /* this hue is returned in radians */ -#define XCMS_CIELUV_PMETRIC_HUE(u,v) \ -(((u) != 0.0) ? XCMS_ATAN( (v) / (u)) : ((v >= 0.0) ? PI / 2 : -(PI / 2))) +#define XCMS_CIELUV_PMETRIC_HUE(u,v) XCMS_ATAN2(v, u) #define XCMS_CIELUV_PMETRIC_CHROMA(u,v) XCMS_SQRT(((u)*(u)) + ((v)*(v))) #define XCMS_CIEASTAROFHUE(h,c) XCMS_CIEUSTAROFHUE((h), (c)) Index: xc/lib/X11/Luv.c =================================================================== --- xc.orig/lib/X11/Luv.c 2005-11-22 08:07:53.000000000 +0100 +++ xc/lib/X11/Luv.c 2005-11-22 08:24:54.000000000 +0100 @@ -282,7 +282,7 @@ uvY_return.u_prime = pLuv_WhitePt->spec.CIEuvY.u_prime; uvY_return.v_prime = pLuv_WhitePt->spec.CIEuvY.v_prime; } else { - tmpVal = 13.0 * (pColor->spec.CIELuv.L_star / 100.0); + tmpVal = 13.0 * pColor->spec.CIELuv.L_star; uvY_return.u_prime = pColor->spec.CIELuv.u_star/tmpVal + pLuv_WhitePt->spec.CIEuvY.u_prime; uvY_return.v_prime = pColor->spec.CIELuv.v_star/tmpVal + @@ -367,7 +367,7 @@ (pColor->spec.CIEuvY.Y * 903.29) : ((XcmsFloat)(XCMS_CUBEROOT(pColor->spec.CIEuvY.Y) * 116.0) - 16.0); - tmpVal = 13.0 * (Luv_return.L_star / 100.0); + tmpVal = 13.0 * Luv_return.L_star; Luv_return.u_star = tmpVal * (pColor->spec.CIEuvY.u_prime - pLuv_WhitePt->spec.CIEuvY.u_prime); Luv_return.v_star = tmpVal * Index: xc/lib/X11/Lab.c =================================================================== --- xc.orig/lib/X11/Lab.c 2005-11-22 08:07:53.000000000 +0100 +++ xc/lib/X11/Lab.c 2005-11-22 08:41:33.000000000 +0100 @@ -31,10 +31,9 @@ * This file contains routines that support the CIE L*a*b* * color space to include conversions to and from the CIE * XYZ space. These conversions are from Principles of - * Color Technology Second Edition, Fred W. Billmeyer, Jr. - * and Max Saltzman, John Wiley & Sons, Inc., 1981. + * Physique de la couleur, R sève. ed Masson, Paris, 1996. * - * Note that the range for L* is 0 to 1. + * Note that the range for L* is 0 to 100. */ /* $XFree86: xc/lib/X11/Lab.c,v 1.4 2003/04/13 19:22:16 dawes Exp $ */ @@ -55,7 +54,6 @@ #else # define XMY_DBL_EPSILON 0.00001 #endif -#define DIV16BY116 0.137931 /* * FORWARD DECLARATIONS @@ -231,7 +229,7 @@ */ { XcmsCIEXYZ XYZ_return; - XcmsFloat tmpFloat, tmpL; + XcmsFloat tmpX, tmpY, tmpZ, tmpX2, tmpY2, tmpZ2; XcmsColor whitePt; int i; XcmsColor *pColor = pColors_in_out; @@ -273,31 +271,22 @@ return(XcmsFailure); } - /* Calculate Y: assume that Yn = 1.0 */ - tmpL = (pColor->spec.CIELab.L_star + 16.0) / 116.0; - XYZ_return.Y = tmpL * tmpL * tmpL; - - if (XYZ_return.Y < 0.008856) { - /* Calculate Y: assume that Yn = 1.0 */ - tmpL = pColor->spec.CIELab.L_star / 9.03292; - - /* Calculate X */ - XYZ_return.X = pLab_WhitePt->spec.CIEXYZ.X * - ((pColor->spec.CIELab.a_star / 3893.5) + tmpL); - /* Calculate Y */ - XYZ_return.Y = tmpL; - /* Calculate Z */ - XYZ_return.Z = pLab_WhitePt->spec.CIEXYZ.Z * - (tmpL - (pColor->spec.CIELab.b_star / 1557.4)); - } else { - /* Calculate X */ - tmpFloat = tmpL + (pColor->spec.CIELab.a_star / 5.0); - XYZ_return.X = pLab_WhitePt->spec.CIEXYZ.X * tmpFloat * tmpFloat * tmpFloat; - - /* Calculate Z */ - tmpFloat = tmpL - (pColor->spec.CIELab.b_star / 2.0); - XYZ_return.Z = pLab_WhitePt->spec.CIEXYZ.Z * tmpFloat * tmpFloat * tmpFloat; - } + /* Calculate X Y Z: assume that Yn = 1.0 */ + tmpX2 = pColor->spec.CIELab.a_star * 0.232 + pColor->spec.CIELab.L_star; /*116/500 = 0.232*/ + tmpY2 = pColor->spec.CIELab.L_star; + tmpZ2 = pColor->spec.CIELab.L_star - pColor->spec.CIELab.b_star * 0.580; /*116/200 =0.58*/ + tmpY = (tmpY2 + 16.0) / 116.0; + tmpX = (tmpX2 + 16.0) / 116.0; + tmpZ = (tmpZ2 + 16.0) / 116.0; + tmpX = tmpX * tmpX * tmpX; + tmpY = tmpY * tmpY * tmpY; + tmpZ = tmpZ * tmpZ * tmpZ; + if (tmpX2 < 8.0) tmpX = tmpX2 / 903.296296; + if (tmpY2 < 8.0) tmpY = tmpY2 / 903.296296; + if (tmpZ2 < 8.0) tmpZ = tmpZ2 / 903.296296; + XYZ_return.X = pLab_WhitePt->spec.CIEXYZ.X * tmpX; + XYZ_return.Y = tmpY; + XYZ_return.Z = pLab_WhitePt->spec.CIEXYZ.Z * tmpZ; memcpy((char *)&pColor->spec.CIEXYZ, (char *)&XYZ_return, sizeof(XcmsCIEXYZ)); @@ -334,7 +323,7 @@ */ { XcmsCIELab Lab_return; - XcmsFloat fX_Xn, fY_Yn, fZ_Zn; + XcmsFloat fX_Xn, fY_Yn, fZ_Zn, tmpX, tmpY, tmpZ; XcmsColor whitePt; int i; XcmsColor *pColor = pColors_in_out; @@ -376,33 +365,19 @@ return(XcmsFailure); } - /* Calculate L*: assume Yn = 1.0 */ - if (pColor->spec.CIEXYZ.Y < 0.008856) { - fY_Yn = (0.07787 * pColor->spec.CIEXYZ.Y) + DIV16BY116; - /* note fY_Yn used to compute Lab_return.a below */ - Lab_return.L_star = 116.0 * (fY_Yn - DIV16BY116); - } else { - fY_Yn = (XcmsFloat)XCMS_CUBEROOT(pColor->spec.CIEXYZ.Y); - /* note fY_Yn used to compute Lab_return.a_star below */ - Lab_return.L_star = (116.0 * fY_Yn) - 16.0; - } - - /* Calculate f(X/Xn) */ - if ((fX_Xn = pColor->spec.CIEXYZ.X / pLab_WhitePt->spec.CIEXYZ.X) < 0.008856) { - fX_Xn = (0.07787 * fX_Xn) + DIV16BY116; - } else { - fX_Xn = (XcmsFloat) XCMS_CUBEROOT(fX_Xn); - } - - /* Calculate f(Z/Zn) */ - if ((fZ_Zn = pColor->spec.CIEXYZ.Z / pLab_WhitePt->spec.CIEXYZ.Z) < 0.008856) { - fZ_Zn = (0.07787 * fZ_Zn) + DIV16BY116; - } else { - fZ_Zn = (XcmsFloat) XCMS_CUBEROOT(fZ_Zn); - } - - Lab_return.a_star = 5.0 * (fX_Xn - fY_Yn); - Lab_return.b_star = 2.0 * (fY_Yn - fZ_Zn); + /* Calculate L* a* b*: assume Yn = 1.0 */ + tmpX = pColor->spec.CIEXYZ.X / pLab_WhitePt->spec.CIEXYZ.X; + tmpY = pColor->spec.CIEXYZ.Y; + tmpZ = pColor->spec.CIEXYZ.Z / pLab_WhitePt->spec.CIEXYZ.Z; + fX_Xn = 116 * (XcmsFloat)XCMS_CUBEROOT(tmpX) - 16; + fY_Yn = 116 * (XcmsFloat)XCMS_CUBEROOT(tmpY) - 16; + fZ_Zn = 116 * (XcmsFloat)XCMS_CUBEROOT(tmpZ) - 16; + if (fX_Xn < 8.0) fX_Xn = tmpX * 903.296296; + if (fY_Yn < 8.0) fY_Yn = tmpY * 903.296296; + if (fZ_Zn < 8.0) fZ_Zn = tmpZ * 903.296296; + Lab_return.L_star = fY_Yn; + Lab_return.a_star = 4.31034 * (fX_Xn - fY_Yn); /* 500/116 = 4.31034*/ + Lab_return.b_star = 1.72414 * (fY_Yn - fZ_Zn); /* 200/116 = 1.72414*/ memcpy((char *)&pColor->spec.CIELab, (char *)&Lab_return, sizeof(XcmsCIELab));