Skip to content

Commit

Permalink
set channel mask to the proper value (#5843)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Dec 3, 2022
1 parent e9885fb commit 64d2830
Showing 1 changed file with 20 additions and 33 deletions.
53 changes: 20 additions & 33 deletions MagickCore/channel.c
Expand Up @@ -73,7 +73,7 @@
%
% ChannelFxImage() applies a channel expression to the specified image. The
% expression consists of one or more channels, either mnemonic or numeric (e.g.
% red, 1), separated by actions as follows:
% r, red, 0), separated by actions as follows:
%
% <=> exchange two channels (e.g. red<=>blue)
% => copy one channel to another channel (e.g. red=>green)
Expand Down Expand Up @@ -122,20 +122,17 @@ static MagickBooleanType ChannelImage(Image *destination_image,
*destination_view;

MagickBooleanType
status;
status = MagickTrue;

size_t
height,
width;
height = MagickMin(source_image->rows,destination_image->rows),
width = MagickMin(source_image->columns,destination_image->columns);

ssize_t
y;

status=MagickTrue;
source_view=AcquireVirtualCacheView(source_image,exception);
destination_view=AcquireAuthenticCacheView(destination_image,exception);
height=MagickMin(source_image->rows,destination_image->rows);
width=MagickMin(source_image->columns,destination_image->columns);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static) shared(status) \
magick_number_threads(source_image,source_image,height,1)
Expand Down Expand Up @@ -196,43 +193,42 @@ MagickExport Image *ChannelFxImage(const Image *image,const char *expression,
#define ChannelFxImageTag "ChannelFx/Image"

ChannelFx
channel_op;
channel_op = ExtractChannelOp;

ChannelType
channel_mask;
channel_mask = image->channel_mask;

char
token[MagickPathExtent];
token[MagickPathExtent] = "";

const char
*p;
*p = expression;

const Image
*source_image;
*source_image = image;

double
pixel;
pixel = 0.0;

Image
*destination_image;
*destination_image = (Image *) NULL;

MagickBooleanType
status;
status = MagickTrue;

PixelChannel
source_channel,
destination_channel;
source_channel = 0,
destination_channel = RedPixelChannel;

ssize_t
channels;
channels = 0;

assert(image != (Image *) NULL);
assert(image->signature == MagickCoreSignature);
if (IsEventLogging() != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickCoreSignature);
source_image=image;
destination_image=CloneImage(source_image,0,0,MagickTrue,exception);
if (destination_image == (Image *) NULL)
return((Image *) NULL);
Expand All @@ -244,13 +240,8 @@ MagickExport Image *ChannelFxImage(const Image *image,const char *expression,
destination_image=GetLastImageInList(destination_image);
return((Image *) NULL);
}
destination_channel=RedPixelChannel;
channel_mask=UndefinedChannel;
pixel=0.0;
p=(char *) expression;
(void) GetNextToken(p,&p,MagickPathExtent,token);
channel_op=ExtractChannelOp;
for (channels=0; *token != '\0'; )
while (*token != '\0')
{
ssize_t
i;
Expand All @@ -267,10 +258,9 @@ MagickExport Image *ChannelFxImage(const Image *image,const char *expression,
}
case '|':
{
source_image=GetFirstImageInList(source_image);
if (GetNextImageInList(source_image) != (Image *) NULL)
source_image=GetNextImageInList(source_image);
else
source_image=GetFirstImageInList(source_image);
(void) GetNextToken(p,&p,MagickPathExtent,token);
break;
}
Expand Down Expand Up @@ -303,7 +293,7 @@ MagickExport Image *ChannelFxImage(const Image *image,const char *expression,
(void) GetNextToken(p,&p,MagickPathExtent,token);
channels=0;
destination_channel=RedPixelChannel;
channel_mask=UndefinedChannel;
channel_mask=destination_image->channel_mask;
break;
}
default:
Expand Down Expand Up @@ -357,10 +347,6 @@ MagickExport Image *ChannelFxImage(const Image *image,const char *expression,
}
}
destination_channel=(PixelChannel) i;
if (i >= (ssize_t) GetPixelChannels(destination_image))
(void) SetPixelMetaChannels(destination_image,(size_t) (
destination_channel-GetPixelChannels(destination_image)+1),
exception);
if (image->colorspace != UndefinedColorspace)
switch (destination_channel)
{
Expand Down Expand Up @@ -402,7 +388,8 @@ MagickExport Image *ChannelFxImage(const Image *image,const char *expression,
break;
}
}
channel_mask=(ChannelType) (channel_mask | ParseChannelOption(token));
channel_mask=(ChannelType) (channel_mask |
(1UL << ParseChannelOption(token)));
if (((channels >= 1) || (destination_channel >= 1)) &&
(IsGrayColorspace(destination_image->colorspace) != MagickFalse))
(void) SetImageColorspace(destination_image,sRGBColorspace,exception);
Expand Down

0 comments on commit 64d2830

Please sign in to comment.