]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/paint.c
(no commit message)
[imagemagick] / MagickCore / paint.c
index 9e21fdae03fcceb36fd6fa5341f1953228a841dd..4d9ffeb68f285a5236e30c5d1900067b58def304 100644 (file)
 %  specified, the color value is changed for any neighbor pixel that does not
 %  match the bordercolor member of image.
 %
-%  By default target must match a particular pixel color exactly.
-%  However, in many cases two colors may differ by a small amount.  The
-%  fuzz member of image defines how much tolerance is acceptable to
-%  consider two colors as the same.  For example, set fuzz to 10 and the
-%  color red at intensities of 100 and 102 respectively are now
-%  interpreted as the same color for the purposes of the floodfill.
+%  By default target must match a particular pixel color exactly.  However,
+%  in many cases two colors may differ by a small amount.  The fuzz member of
+%  image defines how much tolerance is acceptable to consider two colors as
+%  the same.  For example, set fuzz to 10 and the color red at intensities of
+%  100 and 102 respectively are now interpreted as the same color for the
+%  purposes of the floodfill.
 %
 %  The format of the FloodfillPaintImage method is:
 %
 %      MagickBooleanType FloodfillPaintImage(Image *image,
 %        const DrawInfo *draw_info,const PixelInfo target,
 %        const ssize_t x_offset,const ssize_t y_offset,
-%        const MagickBooleanType invert)
+%        const MagickBooleanType invert,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %
 %    o invert: paint any pixel that does not match the target color.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
   const DrawInfo *draw_info,const PixelInfo *target,const ssize_t x_offset,
-  const ssize_t y_offset,const MagickBooleanType invert)
+  const ssize_t y_offset,const MagickBooleanType invert,
+  ExceptionInfo *exception)
 {
 #define MaxStacksize  (1UL << 15)
 #define PushSegmentStack(up,left,right,delta) \
@@ -126,14 +129,12 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
     *floodplane_view,
     *image_view;
 
-  ExceptionInfo
-    *exception;
-
   Image
     *floodplane_image;
 
   MagickBooleanType
-    skip;
+    skip,
+    status;
 
   PixelInfo
     fill,
@@ -169,18 +170,17 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
     return(MagickFalse);
   if ((y_offset < 0) || (y_offset >= (ssize_t) image->rows))
     return(MagickFalse);
-  exception=(&image->exception);
   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
     return(MagickFalse);
   if (image->matte == MagickFalse)
-    (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
+    (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
   /*
     Set floodfill state.
   */
   floodplane_image=CloneImage(image,0,0,MagickTrue,&image->exception);
   if (floodplane_image == (Image *) NULL)
     return(MagickFalse);
-  (void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel);
+  (void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel,exception);
   segment_stack=(SegmentInfo *) AcquireQuantumMemory(MaxStacksize,
     sizeof(*segment_stack));
   if (segment_stack == (SegmentInfo *) NULL)
@@ -192,6 +192,7 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
   /*
     Push initial segment on stack.
   */
+  status=MagickTrue;
   x=x_offset;
   y=y_offset;
   start=0;
@@ -207,12 +208,12 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
     register const Quantum
       *restrict p;
 
-    register ssize_t
-      x;
-
     register Quantum
       *restrict q;
 
+    register ssize_t
+      x;
+
     /*
       Pop segment off stack.
     */
@@ -262,8 +263,7 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
                 exception);
               q=GetCacheViewAuthenticPixels(floodplane_view,x,y,
                 image->columns-x,1,exception);
-              if ((p == (const Quantum *) NULL) ||
-                  (q == (Quantum *) NULL))
+              if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
                 break;
               for ( ; x < (ssize_t) image->columns; x++)
               {
@@ -272,12 +272,12 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
                 SetPixelInfo(image,p,&pixel);
                 if (IsFuzzyEquivalencePixelInfo(&pixel,target) == invert)
                   break;
-                SetPixelAlpha(floodplane_image,
-                  TransparentAlpha,q);
+                SetPixelAlpha(floodplane_image,TransparentAlpha,q);
                 p+=GetPixelChannels(image);
                 q+=GetPixelChannels(floodplane_image);
               }
-              if (SyncCacheViewAuthenticPixels(floodplane_view,exception) == MagickFalse)
+              status=SyncCacheViewAuthenticPixels(floodplane_view,exception);
+              if (status == MagickFalse)
                 break;
             }
           PushSegmentStack(y,start,x-1,offset);
@@ -292,8 +292,7 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
             exception);
           q=GetCacheViewAuthenticPixels(floodplane_view,x,y,(size_t) (x2-x+1),1,
             exception);
-          if ((p == (const Quantum *) NULL) ||
-              (q == (Quantum *) NULL))
+          if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
             break;
           for ( ; x <= x2; x++)
           {
@@ -314,12 +313,12 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
     register const Quantum
       *restrict p;
 
-    register ssize_t
-      x;
-
     register Quantum
       *restrict q;
 
+    register ssize_t
+      x;
+
     /*
       Tile fill color onto floodplane.
     */
@@ -342,8 +341,7 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
             SetPixelGreen(image,ClampToQuantum(fill.green),q);
           if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
             SetPixelBlue(image,ClampToQuantum(fill.blue),q);
-          if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
-              (image->colorspace == CMYKColorspace))
+          if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
             SetPixelBlack(image,ClampToQuantum(fill.black),q);
           if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
             SetPixelAlpha(image,ClampToQuantum(fill.alpha),q);
@@ -382,7 +380,7 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
 %
 %      MagickBooleanType GradientImage(Image *image,const GradientType type,
 %        const SpreadMethod method,const PixelPacket *start_color,
-%        const PixelPacket *stop_color)
+%        const PixelPacket *stop_color,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -396,6 +394,8 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
 %
 %    o stop_color: the stop color.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 
 static inline double MagickMax(const double x,const double y)
@@ -405,7 +405,8 @@ static inline double MagickMax(const double x,const double y)
 
 MagickExport MagickBooleanType GradientImage(Image *image,
   const GradientType type,const SpreadMethod method,
-  const PixelPacket *start_color,const PixelPacket *stop_color)
+  const PixelPacket *start_color,const PixelPacket *stop_color,
+  ExceptionInfo *exception)
 {
   DrawInfo
     *draw_info;
@@ -489,7 +490,7 @@ MagickExport MagickBooleanType GradientImage(Image *image,
 %  The format of the OilPaintImage method is:
 %
 %      Image *OilPaintImage(const Image *image,const double radius,
-%        ExceptionInfo *exception)
+%        const double sigma,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -497,6 +498,8 @@ MagickExport MagickBooleanType GradientImage(Image *image,
 %
 %    o radius: the radius of the circular neighborhood.
 %
+%    o sigma: the standard deviation of the Gaussian, in pixels.
+%
 %    o exception: return any errors or warnings in this structure.
 %
 */
@@ -524,15 +527,13 @@ static size_t **AcquireHistogramThreadSet(const size_t count)
     number_threads;
 
   number_threads=GetOpenMPMaximumThreads();
-  histogram=(size_t **) AcquireQuantumMemory(number_threads,
-    sizeof(*histogram));
+  histogram=(size_t **) AcquireQuantumMemory(number_threads,sizeof(*histogram));
   if (histogram == (size_t **) NULL)
     return((size_t **) NULL);
   (void) ResetMagickMemory(histogram,0,number_threads*sizeof(*histogram));
   for (i=0; i < (ssize_t) number_threads; i++)
   {
-    histogram[i]=(size_t *) AcquireQuantumMemory(count,
-      sizeof(**histogram));
+    histogram[i]=(size_t *) AcquireQuantumMemory(count,sizeof(**histogram));
     if (histogram[i] == (size_t *) NULL)
       return(DestroyHistogramThreadSet(histogram));
   }
@@ -540,7 +541,7 @@ static size_t **AcquireHistogramThreadSet(const size_t count)
 }
 
 MagickExport Image *OilPaintImage(const Image *image,const double radius,
-  ExceptionInfo *exception)
+  const double sigma,ExceptionInfo *exception)
 {
 #define NumberPaintBins  256
 #define OilPaintImageTag  "OilPaint/Image"
@@ -559,7 +560,7 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius,
     progress;
 
   size_t
-    **restrict histograms,
+    **histograms,
     width;
 
   ssize_t
@@ -574,7 +575,7 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
   assert(exception->signature == MagickSignature);
-  width=GetOptimalKernelWidth2D(radius,0.5);
+  width=GetOptimalKernelWidth2D(radius,sigma);
   paint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
   if (paint_image == (Image *) NULL)
     return((Image *) NULL);
@@ -604,15 +605,15 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius,
     register const Quantum
       *restrict p;
 
-    register ssize_t
-      x;
-
     register Quantum
       *restrict q;
 
     register size_t
       *histogram;
 
+    register ssize_t
+      x;
+
     if (status == MagickFalse)
       continue;
     p=GetCacheViewVirtualPixels(image_view,-((ssize_t) width/2L),y-(ssize_t)
@@ -650,7 +651,8 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius,
       {
         for (u=0; u < (ssize_t) width; u++)
         {
-          k=(ssize_t) ScaleQuantumToChar(GetPixelIntensity(image,p+u+i));
+          k=(ssize_t) ScaleQuantumToChar(GetPixelIntensity(image,p+
+            GetPixelChannels(image)*(u+i)));
           histogram[k]++;
           if (histogram[k] > count)
             {
@@ -660,16 +662,19 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius,
         }
         i+=(ssize_t) (image->columns+width);
       }
-      SetPixelRed(paint_image,GetPixelRed(image,p+j*
-        GetPixelChannels(image)),q);
-      SetPixelGreen(paint_image,GetPixelGreen(image,p+j*
-        GetPixelChannels(image)),q);
-      SetPixelBlue(paint_image,GetPixelBlue(image,p+j*
-        GetPixelChannels(image)),q);
-      if (image->colorspace == CMYKColorspace)
+      if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
+        SetPixelRed(paint_image,GetPixelRed(image,p+j*
+          GetPixelChannels(image)),q);
+      if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
+        SetPixelGreen(paint_image,GetPixelGreen(image,p+j*
+          GetPixelChannels(image)),q);
+      if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
+        SetPixelBlue(paint_image,GetPixelBlue(image,p+j*
+          GetPixelChannels(image)),q);
+      if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
         SetPixelBlack(paint_image,GetPixelBlack(image,p+j*
           GetPixelChannels(image)),q);
-      if (image->matte != MagickFalse)
+      if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
         SetPixelAlpha(paint_image,GetPixelAlpha(image,p+j*
           GetPixelChannels(image)),q);
       p+=GetPixelChannels(image);
@@ -712,17 +717,17 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius,
 %  OpaquePaintImage() changes any pixel that matches color with the color
 %  defined by fill.
 %
-%  By default color must match a particular pixel color exactly.  However,
-%  in many cases two colors may differ by a small amount.  Fuzz defines
-%  how much tolerance is acceptable to consider two colors as the same.
-%  For example, set fuzz to 10 and the color red at intensities of 100 and
-%  102 respectively are now interpreted as the same color.
+%  By default color must match a particular pixel color exactly.  However, in
+%  many cases two colors may differ by a small amount.  Fuzz defines how much
+%  tolerance is acceptable to consider two colors as the same.  For example,
+%  set fuzz to 10 and the color red at intensities of 100 and 102 respectively
+%  are now interpreted as the same color.
 %
 %  The format of the OpaquePaintImage method is:
 %
 %      MagickBooleanType OpaquePaintImage(Image *image,
 %        const PixelPacket *target,const PixelPacket *fill,
-%        const MagickBooleanType invert)
+%        const MagickBooleanType invert,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -734,18 +739,18 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius,
 %
 %    o invert: paint any pixel that does not match the target color.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickExport MagickBooleanType OpaquePaintImage(Image *image,
-  const PixelInfo *target,const PixelInfo *fill,const MagickBooleanType invert)
+  const PixelInfo *target,const PixelInfo *fill,const MagickBooleanType invert,
+  ExceptionInfo *exception)
 {
 #define OpaquePaintImageTag  "Opaque/Image"
 
   CacheView
     *image_view;
 
-  ExceptionInfo
-    *exception;
-
   MagickBooleanType
     status;
 
@@ -764,7 +769,6 @@ MagickExport MagickBooleanType OpaquePaintImage(Image *image,
   assert(fill != (PixelInfo *) NULL);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  exception=(&image->exception);
   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
     return(MagickFalse);
   /*
@@ -782,16 +786,16 @@ MagickExport MagickBooleanType OpaquePaintImage(Image *image,
     PixelInfo
       pixel;
 
-    register ssize_t
-      x;
-
     register Quantum
       *restrict q;
 
+    register ssize_t
+      x;
+
     if (status == MagickFalse)
       continue;
     q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
-    if (q == (const Quantum *) NULL)
+    if (q == (Quantum *) NULL)
       {
         status=MagickFalse;
         continue;
@@ -808,8 +812,7 @@ MagickExport MagickBooleanType OpaquePaintImage(Image *image,
             SetPixelGreen(image,ClampToQuantum(fill->green),q);
           if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
             SetPixelBlue(image,ClampToQuantum(fill->blue),q);
-          if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
-              (image->colorspace == CMYKColorspace))
+          if ((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0)
             SetPixelBlack(image,ClampToQuantum(fill->black),q);
           if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
             SetPixelAlpha(image,ClampToQuantum(fill->alpha),q);
@@ -850,17 +853,17 @@ MagickExport MagickBooleanType OpaquePaintImage(Image *image,
 %  TransparentPaintImage() changes the opacity value associated with any pixel
 %  that matches color to the value defined by opacity.
 %
-%  By default color must match a particular pixel color exactly.  However,
-%  in many cases two colors may differ by a small amount.  Fuzz defines
-%  how much tolerance is acceptable to consider two colors as the same.
-%  For example, set fuzz to 10 and the color red at intensities of 100 and
-%  102 respectively are now interpreted as the same color.
+%  By default color must match a particular pixel color exactly.  However, in
+%  many cases two colors may differ by a small amount.  Fuzz defines how much
+%  tolerance is acceptable to consider two colors as the same.  For example,
+%  set fuzz to 10 and the color red at intensities of 100 and 102 respectively
+%  are now interpreted as the same color.
 %
 %  The format of the TransparentPaintImage method is:
 %
 %      MagickBooleanType TransparentPaintImage(Image *image,
 %        const PixelInfo *target,const Quantum opacity,
-%        const MagickBooleanType invert)
+%        const MagickBooleanType invert,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -872,19 +875,18 @@ MagickExport MagickBooleanType OpaquePaintImage(Image *image,
 %
 %    o invert: paint any pixel that does not match the target color.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickExport MagickBooleanType TransparentPaintImage(Image *image,
-  const PixelInfo *target,const Quantum opacity,
-  const MagickBooleanType invert)
+  const PixelInfo *target,const Quantum opacity,const MagickBooleanType invert,
+  ExceptionInfo *exception)
 {
 #define TransparentPaintImageTag  "Transparent/Image"
 
   CacheView
     *image_view;
 
-  ExceptionInfo
-    *exception;
-
   MagickBooleanType
     status;
 
@@ -902,11 +904,10 @@ MagickExport MagickBooleanType TransparentPaintImage(Image *image,
   assert(target != (PixelInfo *) NULL);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  exception=(&image->exception);
   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
     return(MagickFalse);
   if (image->matte == MagickFalse)
-    (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
+    (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
   /*
     Make image color transparent.
   */
@@ -931,7 +932,7 @@ MagickExport MagickBooleanType TransparentPaintImage(Image *image,
     if (status == MagickFalse)
       continue;
     q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
-    if (q == (const Quantum *) NULL)
+    if (q == (Quantum *) NULL)
       {
         status=MagickFalse;
         continue;
@@ -978,18 +979,18 @@ MagickExport MagickBooleanType TransparentPaintImage(Image *image,
 %  TransparentPaintImageChroma() changes the opacity value associated with any
 %  pixel that matches color to the value defined by opacity.
 %
-%  As there is one fuzz value for the all the channels, the
-%  TransparentPaintImage() API is not suitable for the operations like chroma,
-%  where the tolerance for similarity of two color component (RGB) can be
-%  different, Thus we define this method take two target pixels (one
-%  low and one hight) and all the pixels of an image which are lying between
-%  these two pixels are made transparent.
+%  As there is one fuzz value for the all the channels, TransparentPaintImage()
+%  is not suitable for the operations like chroma, where the tolerance for
+%  similarity of two color component (RGB) can be different. Thus we define
+%  this method to take two target pixels (one low and one high) and all the
+%  pixels of an image which are lying between these two pixels are made
+%  transparent.
 %
-%  The format of the TransparentPaintImage method is:
+%  The format of the TransparentPaintImageChroma method is:
 %
-%      MagickBooleanType TransparentPaintImage(Image *image,
-%        const PixelInfo *low,const PixelInfo *hight,
-%        const Quantum opacity,const MagickBooleanType invert)
+%      MagickBooleanType TransparentPaintImageChroma(Image *image,
+%        const PixelInfo *low,const PixelInfo *high,const Quantum opacity,
+%        const MagickBooleanType invert,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -1003,19 +1004,18 @@ MagickExport MagickBooleanType TransparentPaintImage(Image *image,
 %
 %    o invert: paint any pixel that does not match the target color.
 %
+%    o exception: return any errors or warnings in this structure.
+%
 */
 MagickExport MagickBooleanType TransparentPaintImageChroma(Image *image,
-  const PixelInfo *low,const PixelInfo *high,
-  const Quantum opacity,const MagickBooleanType invert)
+  const PixelInfo *low,const PixelInfo *high,const Quantum opacity,
+  const MagickBooleanType invert,ExceptionInfo *exception)
 {
 #define TransparentPaintImageTag  "Transparent/Image"
 
   CacheView
     *image_view;
 
-  ExceptionInfo
-    *exception;
-
   MagickBooleanType
     status;
 
@@ -1031,11 +1031,10 @@ MagickExport MagickBooleanType TransparentPaintImageChroma(Image *image,
   assert(low != (PixelInfo *) NULL);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  exception=(&image->exception);
   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
     return(MagickFalse);
   if (image->matte == MagickFalse)
-    (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
+    (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
   /*
     Make image color transparent.
   */
@@ -1053,16 +1052,16 @@ MagickExport MagickBooleanType TransparentPaintImageChroma(Image *image,
     PixelInfo
       pixel;
 
-    register ssize_t
-      x;
-
     register Quantum
       *restrict q;
 
+    register ssize_t
+      x;
+
     if (status == MagickFalse)
       continue;
     q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
-    if (q == (const Quantum *) NULL)
+    if (q == (Quantum *) NULL)
       {
         status=MagickFalse;
         continue;
@@ -1073,8 +1072,8 @@ MagickExport MagickBooleanType TransparentPaintImageChroma(Image *image,
       SetPixelInfo(image,q,&pixel);
       match=((pixel.red >= low->red) && (pixel.red <= high->red) &&
         (pixel.green >= low->green) && (pixel.green <= high->green) &&
-        (pixel.blue  >= low->blue) && (pixel.blue <= high->blue)) ?
-        MagickTrue : MagickFalse;
+        (pixel.blue  >= low->blue) && (pixel.blue <= high->blue)) ? MagickTrue :
+        MagickFalse;
       if (match != invert)
         SetPixelAlpha(image,opacity,q);
       q+=GetPixelChannels(image);