Skip to content

Commit

Permalink
use gray pixel rather than opacity to create mask
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Dec 10, 2023
1 parent ae46413 commit f3941be
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions magick/paint.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
floodplane_image=CloneImage(image,0,0,MagickTrue,&image->exception);
if (floodplane_image == (Image *) NULL)
return(MagickFalse);
(void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel);
floodplane_image->matte=MagickFalse;
floodplane_image->colorspace=GRAYColorspace;
(void) QueryColorCompliance("#000",AllCompliance,
&floodplane_image->background_color,exception);
(void) SetImageBackgroundColor(floodplane_image);
segment_info=AcquireVirtualMemory(MaxStacksize,sizeof(*segment_stack));
if (segment_info == (MemoryInfo *) NULL)
{
Expand Down Expand Up @@ -230,12 +234,12 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
const PixelPacket
*magick_restrict p;

ssize_t
x;

PixelPacket
*magick_restrict q;

ssize_t
x;

/*
Pop segment off stack.
*/
Expand All @@ -257,12 +261,12 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
q+=x1;
for (x=x1; x >= 0; x--)
{
if (q->opacity == (Quantum) TransparentOpacity)
if (GetPixelGray(q) != 0)
break;
SetMagickPixelPacket(image,p,indexes+x,&pixel);
if (IsMagickColorSimilar(&pixel,target) == invert)
break;
q->opacity=(Quantum) TransparentOpacity;
SetPixelGray(q,QuantumRange);
p--;
q--;
}
Expand Down Expand Up @@ -292,12 +296,12 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
indexes=GetCacheViewVirtualIndexQueue(image_view);
for ( ; x < (ssize_t) image->columns; x++)
{
if (q->opacity == (Quantum) TransparentOpacity)
if (GetPixelGray(q) != 0)
break;
SetMagickPixelPacket(image,p,indexes+x,&pixel);
if (IsMagickColorSimilar(&pixel,target) == invert)
break;
q->opacity=(Quantum) TransparentOpacity;
SetPixelGray(q,QuantumRange);
p++;
q++;
}
Expand All @@ -321,7 +325,7 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
indexes=GetCacheViewVirtualIndexQueue(image_view);
for ( ; x <= x2; x++)
{
if (q->opacity == (Quantum) TransparentOpacity)
if (GetPixelGray(q) != 0)
break;
SetMagickPixelPacket(image,p,indexes+x,&pixel);
if (IsMagickColorSimilar(&pixel,target) != invert)
Expand All @@ -341,12 +345,12 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
IndexPacket
*magick_restrict indexes;

ssize_t
x;

PixelPacket
*magick_restrict q;

ssize_t
x;

/*
Tile fill color onto floodplane.
*/
Expand All @@ -358,7 +362,7 @@ MagickExport MagickBooleanType FloodfillPaintImage(Image *image,
indexes=GetCacheViewAuthenticIndexQueue(image_view);
for (x=0; x < (ssize_t) image->columns; x++)
{
if (GetPixelOpacity(p) != OpaqueOpacity)
if (GetPixelGray(p) != 0)
{
(void) GetFillColor(draw_info,x,y,&fill_color);
SetMagickPixelPacket(image,&fill_color,(IndexPacket *) NULL,&fill);
Expand Down

0 comments on commit f3941be

Please sign in to comment.