*Z=0.0139322*r+0.0971045*g+0.7141733*b;
}
-static double LabF1(double alpha)
-{
-
- if (alpha <= ((24.0/116.0)*(24.0/116.0)*(24.0/116.0)))
- return((841.0/108.0)*alpha+(16.0/116.0));
- return(pow(alpha,1.0/3.0));
-}
-
static inline void ConvertXYZToLab(const double X,const double Y,const double Z,
double *L,double *a,double *b)
{
-#define D50X (0.9642)
+#define D50X (0.964221)
#define D50Y (1.0)
-#define D50Z (0.8249)
+#define D50Z (0.825211)
+#define CIEEpsilon (216.0/24389.0)
+#define CIEK (24389.0/27.0)
double
- fx,
- fy,
- fz;
+ x,
+ y,
+ z;
assert(L != (double *) NULL);
assert(a != (double *) NULL);
assert(b != (double *) NULL);
- *L=0.0;
- *a=0.5;
- *b=0.5;
- if ((fabs(X) < MagickEpsilon) && (fabs(Y) < MagickEpsilon) &&
- (fabs(Z) < MagickEpsilon))
- return;
- fx=LabF1(X/D50X);
- fy=LabF1(Y/D50Y);
- fz=LabF1(Z/D50Z);
- *L=(116.0*fy-16.0)/100.0;
- *a=(500.0*(fx-fy))/255.0;
+ if ((X/D50X) > CIEEpsilon)
+ x=pow(X/D50X,1.0/3.0);
+ else
+ x=(CIEK*X/D50X+16.0)/116.0;
+ if ((Y/D50Y) > CIEEpsilon)
+ y=pow(Y/D50Y,1.0/3.0);
+ else
+ y=(CIEK*Y/D50Y+16.0)/116.0;
+ if ((Z/D50Z) > CIEEpsilon)
+ z=pow(Z/D50Z,1.0/3.0);
+ else
+ z=(CIEK*Z/D50Z+16.0)/116.0;
+ *L=((116.0*y)-16.0)/100.0;
+ *a=(500.0*(x-y))/255.0;
if (*a < 0.0)
*a+=1.0;
- *b=(200.0*(fy-fz))/255.0;
+ *b=(200.0*(y-z))/255.0;
if (*b < 0.0)
*b+=1.0;
}
image->colorspace=colorspace;
image->rendering_intent=UndefinedIntent;
image->gamma=1.000f;
- ResetMagickMemory(&image->chromaticity,0,sizeof(image->chromaticity));
+ (void) ResetMagickMemory(&image->chromaticity,0,sizeof(image->chromaticity));
if (IssRGBColorspace(colorspace) != MagickFalse)
{
image->rendering_intent=PerceptualIntent;
%
*/
-static double LabF2(double alpha)
-{
- double
- beta;
-
- if (alpha > (24.0/116.0))
- return(alpha*alpha*alpha);
- beta=(108.0/841.0)*(alpha-(16.0/116.0));
- if (beta > 0.0)
- return(beta);
- return(0.0);
-}
-
static inline void ConvertLabToXYZ(const double L,const double a,const double b,
double *X,double *Y,double *Z)
{
assert(X != (double *) NULL);
assert(Y != (double *) NULL);
assert(Z != (double *) NULL);
- *X=0.0;
- *Y=0.0;
- *Z=0.0;
- if (L <= 0.0)
- return;
y=(100.0*L+16.0)/116.0;
- x=y+255.0*0.002*(a > 0.5 ? a-1.0 : a);
- z=y-255.0*0.005*(b > 0.5 ? b-1.0 : b);
- *X=D50X*LabF2(x);
- *Y=D50Y*LabF2(y);
- *Z=D50Z*LabF2(z);
+ x=y+255.0*(a > 0.5 ? a-1.0 : a)/500.0;
+ z=y-255.0*(b > 0.5 ? b-1.0 : b)/200.0;
+ if (pow(x,3.0) > CIEEpsilon)
+ x=pow(x,3.0);
+ else
+ x=(116.0*x-16.0)/CIEK;
+ if (pow(y,3.0) > CIEEpsilon)
+ y=pow(y,3.0);
+ else
+ y=L/CIEK;
+ if (pow(z,3.0) > CIEEpsilon)
+ z=pow(z,3.0);
+ else
+ z=(116*z-16.0)/CIEK;
+ *X=D50X*x;
+ *Y=D50Y*y;
+ *Z=D50Z*z;
}
static inline ssize_t RoundToYCC(const MagickRealType value)
static MagickBooleanType TransformsRGBImage(Image *image,
const ColorspaceType colorspace,ExceptionInfo *exception)
{
-#define D50X (0.9642)
-#define D50Y (1.0)
-#define D50Z (0.8249)
#define TransformsRGBImageTag "Transform/Image"
#if !defined(MAGICKCORE_HDRI_SUPPORT)