]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/paint.c
(no commit message)
[imagemagick] / MagickCore / paint.c
index e69bf0875058679cc9461b85bf940adda05335dc..75dc1259197ed5823328ea82e77e2eb15877ed5b 100644 (file)
 %                        Methods to Paint on an Image                         %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 July 1998                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -40,6 +40,7 @@
  Include declarations.
 */
 #include "MagickCore/studio.h"
+#include "MagickCore/channel.h"
 #include "MagickCore/color.h"
 #include "MagickCore/color-private.h"
 #include "MagickCore/colorspace-private.h"
@@ -110,7 +111,7 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
   const ssize_t y_offset,const MagickBooleanType invert,
   ExceptionInfo *exception)
 {
-#define MaxStacksize  (1UL << 16)
+#define MaxStacksize  131072UL
 #define PushSegmentStack(up,left,right,delta) \
 { \
   if (s >= (segment_stack+MaxStacksize)) \
@@ -139,6 +140,9 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
     skip,
     status;
 
+  MemoryInfo
+    *segment_info;
+
   PixelInfo
     fill_color,
     pixel;
@@ -173,8 +177,9 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
     return(MagickFalse);
   if (IsGrayColorspace(image->colorspace) != MagickFalse)
-    (void) TransformImageColorspace(image,RGBColorspace,exception);
-  if ((image->alpha_trait != BlendPixelTrait) && (draw_info->fill.alpha_trait == BlendPixelTrait))
+    (void) SetImageColorspace(image,sRGBColorspace,exception);
+  if ((image->alpha_trait != BlendPixelTrait) &&
+      (draw_info->fill.alpha_trait == BlendPixelTrait))
     (void) SetImageAlpha(image,OpaqueAlpha,exception);
   /*
     Set floodfill state.
@@ -188,14 +193,14 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
   (void) QueryColorCompliance("#000",AllCompliance,
     &floodplane_image->background_color,exception);
   (void) SetImageBackgroundColor(floodplane_image,exception);
-  segment_stack=(SegmentInfo *) AcquireQuantumMemory(MaxStacksize,
-    sizeof(*segment_stack));
-  if (segment_stack == (SegmentInfo *) NULL)
+  segment_info=AcquireVirtualMemory(MaxStacksize,sizeof(*segment_stack));
+  if (segment_info == (MemoryInfo *) NULL)
     {
       floodplane_image=DestroyImage(floodplane_image);
       ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
         image->filename);
     }
+  segment_stack=(SegmentInfo *) GetVirtualMemoryBlob(segment_info);
   /*
     Push initial segment on stack.
   */
@@ -347,7 +352,7 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
   }
   floodplane_view=DestroyCacheView(floodplane_view);
   image_view=DestroyCacheView(image_view);
-  segment_stack=(SegmentInfo *) RelinquishMagickMemory(segment_stack);
+  segment_info=RelinquishVirtualMemory(segment_info);
   floodplane_image=DestroyImage(floodplane_image);
   return(y == (ssize_t) image->rows ? MagickTrue : MagickFalse);
 }
@@ -577,8 +582,6 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius,
         linear_image=DestroyImage(paint_image);
       return((Image *) NULL);
     }
-  if (image->colorspace == sRGBColorspace)
-    (void) TransformImageColorspace(linear_image,sRGBColorspace,exception);
   if (SetImageStorageClass(paint_image,DirectClass,exception) == MagickFalse)
     {
       linear_image=DestroyImage(linear_image);
@@ -670,21 +673,14 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius,
       }
       for (i=0; i < (ssize_t) GetPixelChannels(linear_image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          paint_traits,
-          traits;
-
-        channel=GetPixelChannelChannel(linear_image,i);
-        traits=GetPixelChannelTraits(linear_image,channel);
-        paint_traits=GetPixelChannelTraits(paint_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(linear_image,i);
+        PixelTrait traits=GetPixelChannelTraits(linear_image,channel);
+        PixelTrait paint_traits=GetPixelChannelTraits(paint_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (paint_traits == UndefinedPixelTrait))
           continue;
         if (((paint_traits & CopyPixelTrait) != 0) ||
-            (GetPixelMask(linear_image,p) != 0))
+            (GetPixelReadMask(linear_image,p) == 0))
           {
             SetPixelChannel(paint_image,channel,p[center+i],q);
             continue;
@@ -715,8 +711,6 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius,
   image_view=DestroyCacheView(image_view);
   histograms=DestroyHistogramThreadSet(histograms);
   linear_image=DestroyImage(linear_image);
-  if (image->colorspace == sRGBColorspace)
-    (void) TransformImageColorspace(paint_image,sRGBColorspace,exception);
   if (status == MagickFalse)
     paint_image=DestroyImage(paint_image);
   return(paint_image);
@@ -792,8 +786,9 @@ MagickExport MagickBooleanType OpaquePaintImage(Image *image,
     return(MagickFalse);
   if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
       (IsPixelInfoGray(fill) == MagickFalse))
-    (void) TransformImageColorspace(image,RGBColorspace,exception);
-  if ((fill->alpha_trait == BlendPixelTrait) && (image->alpha_trait != BlendPixelTrait))
+    (void) SetImageColorspace(image,sRGBColorspace,exception);
+  if ((fill->alpha_trait == BlendPixelTrait) &&
+      (image->alpha_trait != BlendPixelTrait))
     (void) SetImageAlpha(image,OpaqueAlpha,exception);
   /*
     Make image color opaque.