]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Mon, 8 Apr 2013 12:03:11 +0000 (12:03 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Mon, 8 Apr 2013 12:03:11 +0000 (12:03 +0000)
MagickCore/gem.c

index 34658bb1e52b77f6a7240ef02afa55bddc4c5f32..8df3e5aabfdc7a222d553353718490b5bdc1df4a 100644 (file)
@@ -89,13 +89,14 @@ MagickPrivate void ConvertHCLToRGB(const double hue,const double chroma,
   const double luma,double *red,double *green,double *blue)
 {
   double
-    b,
-    c,
-    g,
-    h,
-    m,
-    r,
-    x;
+    C,
+    H,
+    L,
+    u,
+    v,
+    X,
+    Y,
+    Z;
 
   /*
     Convert HCL to RGB colorspace.
@@ -103,51 +104,13 @@ MagickPrivate void ConvertHCLToRGB(const double hue,const double chroma,
   assert(red != (double *) NULL);
   assert(green != (double *) NULL);
   assert(blue != (double *) NULL);
-  h=6.0*hue;
-  c=chroma;
-  x=c*(1.0-fabs(fmod(h,2.0)-1.0));
-  r=0.0;
-  g=0.0;
-  b=0.0;
-  if ((0.0 <= h) && (h < 1.0))
-    {
-      r=c;
-      g=x;
-    }
-  else
-    if ((1.0 <= h) && (h < 2.0))
-      {
-        r=x;
-        g=c;
-      }
-    else
-      if ((2.0 <= h) && (h < 3.0))
-        {
-          g=c;
-          b=x;
-        }
-      else
-        if ((3.0 <= h) && (h < 4.0))
-          {
-            g=x;
-            b=c;
-          }
-        else
-          if ((4.0 <= h) && (h < 5.0))
-            {
-              r=x;
-              b=c;
-            }
-          else
-            if ((5.0 <= h) && (h < 6.0))
-              {
-                r=c;
-                b=x;
-              }
-  m=luma-(0.298839f*r+0.586811f*g+0.114350f*b);
-  *red=QuantumRange*(r+m);
-  *green=QuantumRange*(g+m);
-  *blue=QuantumRange*(b+m);
+  L=luma;
+  C=chroma;
+  H=hue;
+  u=C*cos(360.0*H*MagickPI/180.0)+134.0/354.0;
+  v=C*sin(360.0*H*MagickPI/180.0)+140.0/262.0;
+  ConvertLuvToXYZ(L,u,v,&X,&Y,&Z);
+  ConvertXYZToRGB(X,Y,Z,red,green,blue);
 }
 \f
 /*
@@ -546,58 +509,36 @@ MagickPrivate void ConvertLCHuvToRGB(const double luma,const double chroma,
 %      component of the HCL color space.
 %
 */
-
-static inline double MagickMax(const double x,const double y)
-{
-  if (x > y)
-    return(x);
-  return(y);
-}
-
-static inline double MagickMin(const double x,const double y)
-{
-  if (x < y)
-    return(x);
-  return(y);
-}
-
 MagickPrivate void ConvertRGBToHCL(const double red,const double green,
   const double blue,double *hue,double *chroma,double *luma)
 {
   double
-    b,
-    c,
-    g,
-    h,
-    max,
-    r;
+    C,
+    H,
+    L,
+    u,
+    v,
+    X,
+    Y,
+    Z;
 
   /*
     Convert RGB to HCL colorspace.
   */
-  assert(hue != (double *) NULL);
-  assert(chroma != (double *) NULL);
   assert(luma != (double *) NULL);
-  r=red;
-  g=green;
-  b=blue;
-  max=MagickMax(r,MagickMax(g,b));
-  c=max-(double) MagickMin(r,MagickMin(g,b));
-  h=0.0;
-  if (c == 0.0)
-    h=0.0;
-  else
-    if (red == max)
-      h=fmod((g-b)/c+6.0,6.0);
-    else
-      if (green == max)
-        h=((b-r)/c)+2.0;
-      else
-        if (blue == max)
-          h=((r-g)/c)+4.0;
-  *hue=(h/6.0);
-  *chroma=QuantumScale*c;
-  *luma=QuantumScale*(0.298839f*r+0.586811f*g+0.114350f*b);
+  assert(chroma != (double *) NULL);
+  assert(hue != (double *) NULL);
+  ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
+  ConvertXYZToLuv(X,Y,Z,&L,&u,&v);
+  C=hypot(u-134.0/254.0,v-140.0/262.0);
+  H=180.0*atan2(v-140.0/262.0,u-134.0/254.0)/MagickPI/360.0;
+  if (H < 0.0)
+    H+=1.0;
+  if (H >= 1.0)
+    H-=1.0;
+  *luma=L;
+  *chroma=C;
+  *hue=H;
 }
 \f
 /*
@@ -704,6 +645,21 @@ MagickPrivate void ConvertRGBToHSB(const double red,const double green,
 %      component of the HSL color space.
 %
 */
+
+static inline double MagickMax(const double x,const double y)
+{
+  if (x > y)
+    return(x);
+  return(y);
+}
+
+static inline double MagickMin(const double x,const double y)
+{
+  if (x < y)
+    return(x);
+  return(y);
+}
+
 MagickExport void ConvertRGBToHSL(const double red,const double green,
   const double blue,double *hue,double *saturation,double *lightness)
 {
@@ -859,7 +815,7 @@ MagickPrivate void ConvertRGBToLCHab(const double red,const double green,
     Z;
 
   /*
-    Convert RGB to LCH colorspace.
+    Convert RGB to LCHab colorspace.
   */
   assert(luma != (double *) NULL);
   assert(chroma != (double *) NULL);
@@ -919,7 +875,7 @@ MagickPrivate void ConvertRGBToLCHuv(const double red,const double green,
     Z;
 
   /*
-    Convert RGB to LCH colorspace.
+    Convert RGB to LCHuv colorspace.
   */
   assert(luma != (double *) NULL);
   assert(chroma != (double *) NULL);