]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Tue, 10 Apr 2012 01:41:25 +0000 (01:41 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Tue, 10 Apr 2012 01:41:25 +0000 (01:41 +0000)
MagickCore/fx.c
MagickCore/threshold.c

index 9e542abbda56b381b465a8c0d203d9ba8c1ece9a..46875b6be541a6f5612a40874af208ff7edf5f2f 100644 (file)
@@ -757,6 +757,12 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
     GetPixelInfo(image,&pixel);
     for (x=0; x < (ssize_t) image->columns; x++)
     {
+      if (GetPixelMask(colorize_image,q) != 0)
+        {
+          p+=GetPixelChannels(image);
+          q+=GetPixelChannels(colorize_image);
+          continue;
+        }
       GetPixelInfoPixel(image,p,&pixel);
       Colorize(pixel.red,blend_percentage.red,colorize->red);
       Colorize(pixel.green,blend_percentage.green,colorize->green);
index 8a3204499bd32c35e575ac1ee4b68f23354c120b..286cde85f845d2397715a87f0b7ca1b5a3d6f577 100644 (file)
@@ -483,6 +483,8 @@ MagickExport MagickBooleanType BlackThresholdImage(Image *image,
   const char *thresholds,ExceptionInfo *exception)
 {
 #define ThresholdImageTag  "Threshold/Image"
+#define BlackThreshold(pixel,threshold_percentage) \
+  if (pixel < threshold_percentage) pixel=QuantumRange;
 
   CacheView
     *image_view;
@@ -496,15 +498,12 @@ MagickExport MagickBooleanType BlackThresholdImage(Image *image,
   MagickOffsetType
     progress;
 
-  MagickRealType
-    threshold[5];
+  PixelInfo
+    threshold_percentage;
 
   MagickStatusType
     flags;
 
-  register ssize_t
-    i;
-
   ssize_t
     y;
 
@@ -518,20 +517,26 @@ MagickExport MagickBooleanType BlackThresholdImage(Image *image,
     return(MagickFalse);
   if (IsGrayColorspace(image->colorspace) != MagickFalse)
     (void) TransformImageColorspace(image,sRGBColorspace,exception);
+  GetPixelInfo(image,&threshold_percentage);
   flags=ParseGeometry(thresholds,&geometry_info);
-  for (i=0; i < 5; i++)
-    threshold[i]=geometry_info.rho;
+  threshold_percentage.red=geometry_info.rho;
+  threshold_percentage.green=geometry_info.rho;
+  threshold_percentage.blue=geometry_info.rho;
+  threshold_percentage.black=geometry_info.rho;
+  threshold_percentage.alpha=100.0;
   if ((flags & SigmaValue) != 0)
-    threshold[1]=geometry_info.sigma;
+    threshold_percentage.green=geometry_info.sigma;
   if ((flags & XiValue) != 0)
-    threshold[2]=geometry_info.xi;
+    threshold_percentage.blue=geometry_info.xi;
   if ((flags & PsiValue) != 0)
-    threshold[3]=geometry_info.psi;
-  if ((flags & ChiValue) != 0)
-    threshold[4]=geometry_info.chi;
-  if ((flags & PercentValue) != 0)
-    for (i=0; i < 5; i++)
-      threshold[i]*=(QuantumRange/100.0);
+    threshold_percentage.alpha=geometry_info.psi;
+  if (threshold_percentage.colorspace == CMYKColorspace)
+    {
+      if ((flags & PsiValue) != 0)
+        threshold_percentage.black=geometry_info.psi;
+      if ((flags & ChiValue) != 0)
+        threshold_percentage.alpha=geometry_info.chi;
+    }
   /*
     White threshold image.
   */
@@ -543,6 +548,9 @@ MagickExport MagickBooleanType BlackThresholdImage(Image *image,
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
+    PixelInfo
+      pixel;
+
     register ssize_t
       x;
 
@@ -557,35 +565,21 @@ MagickExport MagickBooleanType BlackThresholdImage(Image *image,
         status=MagickFalse;
         continue;
       }
+    GetPixelInfo(image,&pixel);
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      register ssize_t
-        i;
-
-      ssize_t
-        n;
-
       if (GetPixelMask(image,q) != 0)
         {
           q+=GetPixelChannels(image);
           continue;
         }
-      n=0;
-      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
-      {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        if ((traits & UpdatePixelTrait) == 0)
-          continue;
-        if ((MagickRealType) q[i] < threshold[n++ % 5])
-          q[i]=QuantumRange;
-      }
+      GetPixelInfoPixel(image,q,&pixel);
+      BlackThreshold(pixel.red,threshold_percentage.red);
+      BlackThreshold(pixel.green,threshold_percentage.green);
+      BlackThreshold(pixel.blue,threshold_percentage.blue);
+      BlackThreshold(pixel.black,threshold_percentage.black);
+      BlackThreshold(pixel.alpha,threshold_percentage.alpha);
+      SetPixelInfoPixel(image,&pixel,q);
       q+=GetPixelChannels(image);
     }
     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
@@ -1603,6 +1597,8 @@ MagickExport MagickBooleanType WhiteThresholdImage(Image *image,
   const char *thresholds,ExceptionInfo *exception)
 {
 #define ThresholdImageTag  "Threshold/Image"
+#define WhiteThreshold(pixel,threshold_percentage) \
+  if (pixel > threshold_percentage) pixel=QuantumRange;
 
   CacheView
     *image_view;
@@ -1616,15 +1612,12 @@ MagickExport MagickBooleanType WhiteThresholdImage(Image *image,
   MagickOffsetType
     progress;
 
-  MagickRealType
-    threshold[5];
+  PixelInfo
+    threshold_percentage;
 
   MagickStatusType
     flags;
 
-  register ssize_t
-    i;
-
   ssize_t
     y;
 
@@ -1638,20 +1631,26 @@ MagickExport MagickBooleanType WhiteThresholdImage(Image *image,
     return(MagickFalse);
   if (IsGrayColorspace(image->colorspace) != MagickFalse)
     (void) TransformImageColorspace(image,sRGBColorspace,exception);
+  GetPixelInfo(image,&threshold_percentage);
   flags=ParseGeometry(thresholds,&geometry_info);
-  for (i=0; i < 5; i++)
-    threshold[i]=geometry_info.rho;
+  threshold_percentage.red=geometry_info.rho;
+  threshold_percentage.green=geometry_info.rho;
+  threshold_percentage.blue=geometry_info.rho;
+  threshold_percentage.black=geometry_info.rho;
+  threshold_percentage.alpha=100.0;
   if ((flags & SigmaValue) != 0)
-    threshold[1]=geometry_info.sigma;
+    threshold_percentage.green=geometry_info.sigma;
   if ((flags & XiValue) != 0)
-    threshold[2]=geometry_info.xi;
+    threshold_percentage.blue=geometry_info.xi;
   if ((flags & PsiValue) != 0)
-    threshold[3]=geometry_info.psi;
-  if ((flags & ChiValue) != 0)
-    threshold[4]=geometry_info.chi;
-  if ((flags & PercentValue) != 0)
-    for (i=0; i < 5; i++)
-      threshold[i]*=(QuantumRange/100.0);
+    threshold_percentage.alpha=geometry_info.psi;
+  if (threshold_percentage.colorspace == CMYKColorspace)
+    {
+      if ((flags & PsiValue) != 0)
+        threshold_percentage.black=geometry_info.psi;
+      if ((flags & ChiValue) != 0)
+        threshold_percentage.alpha=geometry_info.chi;
+    }
   /*
     White threshold image.
   */
@@ -1663,6 +1662,9 @@ MagickExport MagickBooleanType WhiteThresholdImage(Image *image,
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
+    PixelInfo
+      pixel;
+
     register ssize_t
       x;
 
@@ -1677,35 +1679,21 @@ MagickExport MagickBooleanType WhiteThresholdImage(Image *image,
         status=MagickFalse;
         continue;
       }
+    GetPixelInfo(image,&pixel);
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      register ssize_t
-        i;
-
-      ssize_t
-        n;
-
       if (GetPixelMask(image,q) != 0)
         {
           q+=GetPixelChannels(image);
           continue;
         }
-      n=0;
-      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
-      {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        if ((traits & UpdatePixelTrait) == 0)
-          continue;
-        if ((MagickRealType) q[i] > threshold[n++ % 5])
-          q[i]=QuantumRange;
-      }
+      GetPixelInfoPixel(image,q,&pixel);
+      WhiteThreshold(pixel.red,threshold_percentage.red);
+      WhiteThreshold(pixel.green,threshold_percentage.green);
+      WhiteThreshold(pixel.blue,threshold_percentage.blue);
+      WhiteThreshold(pixel.black,threshold_percentage.black);
+      WhiteThreshold(pixel.alpha,threshold_percentage.alpha);
+      SetPixelInfoPixel(image,&pixel,q);
       q+=GetPixelChannels(image);
     }
     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)