]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Wed, 29 Aug 2012 17:22:14 +0000 (17:22 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Wed, 29 Aug 2012 17:22:14 +0000 (17:22 +0000)
MagickCore/colorspace.c
MagickCore/colorspace.h
MagickCore/option.c

index 57e8d8231e74ebd835be4a36be6f5882335ec803..b4d1600894d7f27da8815d0c9d30bde081a20cbf 100644 (file)
@@ -751,6 +751,81 @@ static MagickBooleanType sRGBTransformImage(Image *image,
         return(MagickFalse);
       return(status);
     }
+    case LCHColorspace:
+    {
+      /*
+        Transform image from sRGB to LCH.
+      */
+      if (image->storage_class == PseudoClass)
+        {
+          if (SyncImage(image,exception) == MagickFalse)
+            return(MagickFalse);
+          if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
+            return(MagickFalse);
+        }
+      image_view=AcquireAuthenticCacheView(image,exception);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+      #pragma omp parallel for schedule(static,4) shared(status) \
+        dynamic_number_threads(image,image->columns,image->rows,1)
+#endif
+      for (y=0; y < (ssize_t) image->rows; y++)
+      {
+        MagickBooleanType
+          sync;
+
+        register ssize_t
+          x;
+
+        register Quantum
+          *restrict q;
+
+        if (status == MagickFalse)
+          continue;
+        q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
+          exception);
+        if (q == (Quantum *) NULL)
+          {
+            status=MagickFalse;
+            continue;
+          }
+        for (x=0; x < (ssize_t) image->columns; x++)
+        {
+          double
+            a,
+            b,
+            blue,
+            C,
+            green,
+            H,
+            L,
+            red,
+            X,
+            Y,
+            Z;
+
+          red=InversesRGBCompandor((double) GetPixelRed(image,q));
+          green=InversesRGBCompandor((double) GetPixelGreen(image,q));
+          blue=InversesRGBCompandor((double) GetPixelBlue(image,q));
+          ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
+          ConvertXYZToLab(X,Y,Z,&L,&a,&b);
+          C=sqrt(a*a+b*b);
+          H=atan2(b,a)*180.0/MagickPI;
+          if (H < 0.0)
+            H+=1.0;
+          SetPixelRed(image,ClampToQuantum(QuantumRange*L),q);
+          SetPixelGreen(image,ClampToQuantum(QuantumRange*C),q);
+          SetPixelBlue(image,ClampToQuantum(QuantumRange*H),q);
+          q+=GetPixelChannels(image);
+        }
+        sync=SyncCacheViewAuthenticPixels(image_view,exception);
+        if (sync == MagickFalse)
+          status=MagickFalse;
+      }
+      image_view=DestroyCacheView(image_view);
+      if (SetImageColorspace(image,colorspace,exception) == MagickFalse)
+        return(MagickFalse);
+      return(status);
+    }
     case LogColorspace:
     {
 #define DisplayGamma  (1.0/1.7)
@@ -2549,6 +2624,79 @@ static MagickBooleanType TransformsRGBImage(Image *image,
         return(MagickFalse);
       return(status);
     }
+    case LCHColorspace:
+    {
+      /*
+        Transform image from LCH to sRGB.
+      */
+      if (image->storage_class == PseudoClass)
+        {
+          if (SyncImage(image,exception) == MagickFalse)
+            return(MagickFalse);
+          if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
+            return(MagickFalse);
+        }
+      image_view=AcquireAuthenticCacheView(image,exception);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+      #pragma omp parallel for schedule(static,4) shared(status) \
+        dynamic_number_threads(image,image->columns,image->rows,1)
+#endif
+      for (y=0; y < (ssize_t) image->rows; y++)
+      {
+        MagickBooleanType
+          sync;
+
+        register ssize_t
+          x;
+
+        register Quantum
+          *restrict q;
+
+        if (status == MagickFalse)
+          continue;
+        q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
+          exception);
+        if (q == (Quantum *) NULL)
+          {
+            status=MagickFalse;
+            continue;
+          }
+        for (x=0; x < (ssize_t) image->columns; x++)
+        {
+          double
+            a,
+            b,
+            blue,
+            C,
+            green,
+            H,
+            L,
+            red,
+            X,
+            Y,
+            Z;
+
+          L=QuantumScale*GetPixelRed(image,q);
+          C=QuantumScale*GetPixelGreen(image,q);
+          H=QuantumScale*GetPixelBlue(image,q);
+          a=C*cos(H*(MagickPI/180.0));
+          b=C*sin(H*(MagickPI/180.0));
+          ConvertLabToXYZ(L,a,b,&X,&Y,&Z);
+          ConvertXYZToRGB(X,Y,Z,&red,&green,&blue);
+          SetPixelRed(image,ClampToQuantum(sRGBCompandor(red)),q);
+          SetPixelGreen(image,ClampToQuantum(sRGBCompandor(green)),q);
+          SetPixelBlue(image,ClampToQuantum(sRGBCompandor(blue)),q);
+          q+=GetPixelChannels(image);
+        }
+        sync=SyncCacheViewAuthenticPixels(image_view,exception);
+        if (sync == MagickFalse)
+          status=MagickFalse;
+      }
+      image_view=DestroyCacheView(image_view);
+      if (SetImageColorspace(image,sRGBColorspace,exception) == MagickFalse)
+        return(MagickFalse);
+      return(status);
+    }
     case LogColorspace:
     {
       const char
index 0442d8ae1cac36b2e573707c22d19341d321383c..321b4a69f1cddaad90f3bd4819759b8339d12651 100644 (file)
@@ -33,6 +33,7 @@ typedef enum
   HSLColorspace,
   HWBColorspace,
   LabColorspace,
+  LCHColorspace,
   LogColorspace,
   LuvColorspace,
   OHTAColorspace,
index 1e4d824dae11be78e0cfa4259136f8f2ad003151..9b081ea7817841e677e8d79770e65dfbfb5b7365 100644 (file)
@@ -870,6 +870,7 @@ static const OptionInfo
     { "HSL", HSLColorspace, UndefinedOptionFlag, MagickFalse },
     { "HWB", HWBColorspace, UndefinedOptionFlag, MagickFalse },
     { "Lab", LabColorspace, UndefinedOptionFlag, MagickFalse },
+    { "LCH", LCHColorspace, UndefinedOptionFlag, MagickFalse },
     { "Log", LogColorspace, UndefinedOptionFlag, MagickFalse },
     { "Luv", LuvColorspace, UndefinedOptionFlag, MagickFalse },
     { "OHTA", OHTAColorspace, UndefinedOptionFlag, MagickFalse },