]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Wed, 15 Aug 2012 13:10:55 +0000 (13:10 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Wed, 15 Aug 2012 13:10:55 +0000 (13:10 +0000)
MagickCore/composite.c
MagickCore/gem.c

index 9093844733db8c55540c9f31bbb1de07020d3877..512dab895eea69e8f20fbc4fd937fc6d05786d40 100644 (file)
@@ -217,7 +217,8 @@ static void HCLComposite(const double hue,const double chroma,const double luma,
     h,
     m,
     r,
-    x;
+    x,
+    z;
 
   /*
     Convert HCL to RGB colorspace.
@@ -233,43 +234,59 @@ static void HCLComposite(const double hue,const double chroma,const double luma,
   b=0.0;
   if ((0.0 <= h) && (h < 1.0))
     {
-      r=c;      
-      g=x;      
+      r=c;
+      g=x;
     }
   else
     if ((1.0 <= h) && (h < 2.0))
       {
-        r=x;      
-        g=c;      
+        r=x;
+        g=c;
       }
     else
       if ((2.0 <= h) && (h < 3.0))
         {
-          g=c;      
-          b=x;      
+          g=c;
+          b=x;
         }
       else
         if ((3.0 <= h) && (h < 4.0))
           {
-            g=x;      
-            b=c;      
+            g=x;
+            b=c;
           }
         else
           if ((4.0 <= h) && (h < 5.0))
             {
-              r=x;      
-              b=c;      
+              r=x;
+              b=c;
             }
           else
             if ((5.0 <= h) && (h < 6.0))
               {
-                r=c;      
-                b=x;      
+                r=c;
+                b=x;
               }
   m=luma-(0.298839*r+0.586811*g+0.114350*b);
-  *red=QuantumRange*(r+m);
-  *green=QuantumRange*(g+m);
-  *blue=QuantumRange*(b+m);
+  /*
+    Choose saturation strategy to clip it into the RGB cube; hue and luma are
+    preserved and chroma may be changed.
+  */
+  z=1.0;
+  if (m < 0.0)
+    {
+      z=luma/(luma-m);
+      m=0.0;
+    }
+  else
+    if (m+c > 1.0)
+      {
+        z=(1.0-luma)/(m+c-luma);
+        m=1.0-z*c;
+      }
+  *red=QuantumRange*(z*r+m);
+  *green=QuantumRange*(z*g+m);
+  *blue=QuantumRange*(z*b+m);
 }
 
 static void CompositeHCL(const double red,const double green,const double blue,
index 266260a67e95f52e2723703ea87b1618a69d44e2..b9b61b4e1aee009919337f7eae4f366dd4bea141 100644 (file)
@@ -95,7 +95,8 @@ MagickPrivate void ConvertHCLToRGB(const double hue,const double chroma,
     h,
     m,
     r,
-    x;
+    x,
+    z;
 
   /*
     Convert HCL to RGB colorspace.
@@ -111,43 +112,59 @@ MagickPrivate void ConvertHCLToRGB(const double hue,const double chroma,
   b=0.0;
   if ((0.0 <= h) && (h < 1.0))
     {
-      r=c;      
-      g=x;      
+      r=c;
+      g=x;
     }
   else
     if ((1.0 <= h) && (h < 2.0))
       {
-        r=x;      
-        g=c;      
+        r=x;
+        g=c;
       }
     else
       if ((2.0 <= h) && (h < 3.0))
         {
-          g=c;      
-          b=x;      
+          g=c;
+          b=x;
         }
       else
         if ((3.0 <= h) && (h < 4.0))
           {
-            g=x;      
-            b=c;      
+            g=x;
+            b=c;
           }
         else
           if ((4.0 <= h) && (h < 5.0))
             {
-              r=x;      
-              b=c;      
+              r=x;
+              b=c;
             }
           else
             if ((5.0 <= h) && (h < 6.0))
               {
-                r=c;      
-                b=x;      
+                r=c;
+                b=x;
               }
   m=luma-(0.298839*r+0.586811*g+0.114350*b);
-  *red=QuantumRange*(r+m);
-  *green=QuantumRange*(g+m);
-  *blue=QuantumRange*(b+m);
+  /*
+    Choose saturation strategy to clip it into the RGB cube; hue and luma are
+    preserved and chroma may be changed.
+  */
+  z=1.0;
+  if (m < 0.0)
+    {
+      z=luma/(luma-m);
+      m=0.0;
+    }
+  else
+    if (m+c > 1.0)
+      {
+        z=(1.0-luma)/(m+c-luma);
+        m=1.0-z*c;
+      }
+  *red=QuantumRange*(z*r+m);
+  *green=QuantumRange*(z*g+m);
+  *blue=QuantumRange*(z*b+m);
 }
 \f
 /*