]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Sun, 23 May 2010 20:09:56 +0000 (20:09 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Sun, 23 May 2010 20:09:56 +0000 (20:09 +0000)
ChangeLog
magick/colorspace.c

index 4c471ca8c386a79136e88a0c4eeca82655825d05..4bc018b04cc052a9e3cd69502718bdb0d4d1f533 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -32,6 +32,7 @@
     to the image otherwise it sets the border for the layout manager.
   * 24-bit BMP images are not colormapped even if header colors != 0.
   * Set DPX user data like this: -set profile dpx:userdata.txt.
+  * Make sure Lab => RGB => Lab survives the round trip.
 
 2010-05-15  6.6.1-10 Cristy  <quetzlzacatenango@image...>
   * Use ScaleCharToQuantum() in coders/src.c (reference
index 95c36a4245d693eaf3a7f8fa47d25d548a797532..12d326fc938430a4ef2fb41eb1d4f0bbe63a6e0a 100644 (file)
@@ -115,8 +115,20 @@ static inline void ConvertRGBToXYZ(const Quantum red,const Quantum green,
   assert(Y != (double *) NULL);
   assert(Z != (double *) NULL);
   r=QuantumScale*red;
+  if (r > 0.04045)
+    r=pow((r+0.055)/1.055,2.4);
+  else
+    r/=12.92;
   g=QuantumScale*green;
+  if (g > 0.04045)
+    g=pow((g+0.055)/1.055,2.4);
+  else
+    g/=12.92;
   b=QuantumScale*blue;
+  if (b > 0.04045)
+    b=pow((b+0.055)/1.055,2.4);
+  else
+    b/=12.92;
   *X=0.4124240*r+0.3575790*g+0.1804640*b;
   *Y=0.2126560*r+0.7151580*g+0.0721856*b;
   *Z=0.0193324*r+0.1191930*g+0.9504440*b;
@@ -133,7 +145,7 @@ static double LabF1(double alpha)
 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.9642)
 #define D50Y  (1.0)
 #define D50Z  (0.8249)
 
@@ -148,16 +160,18 @@ static inline void ConvertXYZToLab(const double X,const double Y,const double Z,
   *L=0.0;
   *a=0.5;
   *b=0.5;
-  if ((X == 0.0) && (Y == 0.0) && (Z == 0.0))
-    puts("a");
   if ((X == 0.0) && (Y == 0.0) && (Z == 0.0))
     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+0.5;
-  *b=(200.0*(fy-fz))/255.0+0.5;
+  *a=(500.0*(fx-fy))/255.0;
+  if (*a < 0.0)
+    *a+=1.0;
+  *b=(200.0*(fy-fz))/255.0;
+  if (*b < 0.0)
+    *b+=1.0;
 }
 
 MagickExport MagickBooleanType RGBTransformImage(Image *image,
@@ -1262,7 +1276,6 @@ static double LabF2(double alpha)
   return(0.0);
 }
 
-
 static inline void ConvertLabToXYZ(const double L,const double a,const double b,
   double *X,double *Y,double *Z)
 {
@@ -1281,8 +1294,8 @@ static inline void ConvertLabToXYZ(const double L,const double a,const double b,
   if (L <= 0.0)
     return;
   y=(100.0*L+16.0)/116.0;
-  x=y+255.0*0.002*(a-0.5);
-  z=y-255.0*0.005*(b-0.5);
+  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);