From: cristy Date: Sun, 4 Mar 2012 01:21:15 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~6086 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a15140ffe282798c406b8ce865dd2c02519217e5;p=imagemagick --- diff --git a/MagickCore/channel.c b/MagickCore/channel.c index b09bb47b1..4fd75d6c3 100644 --- a/MagickCore/channel.c +++ b/MagickCore/channel.c @@ -41,6 +41,11 @@ Include declarations. */ #include "MagickCore/studio.h" +#include "MagickCore/image.h" +#include "MagickCore/list.h" +#include "MagickCore/log.h" +#include "MagickCore/option.h" +#include "MagickCore/token.h" #include "MagickCore/utility.h" #include "MagickCore/version.h" @@ -59,20 +64,134 @@ % % The format of the ChannelOperationImage method is: % -% Image *ChannelOperationImage(const Image *image, +% Image *ChannelOperationImage(const Image *images, % const char *expression,ExceptionInfo *exception) % % A description of each parameter follows: % -% o image: the image. +% o images: the images. % % o expression: A channel expression. % % o exception: return any errors or warnings in this structure. % */ -MagickExport Image *ChannelOperationImage(const Image *image, + +typedef enum +{ + ExtractChannelOp, + ExchangeChannelOp, + TransferChannelOp +} ChannelOperation; + +static MagickBooleanType ChannelImage(Image *channel_image,const Image *image, + const ChannelOperation channel_op,const PixelChannel p_channel, + const PixelChannel q_channel,ExceptionInfo *exception) +{ + return(MagickTrue); +} + +MagickExport Image *ChannelOperationImage(const Image *images, const char *expression,ExceptionInfo *exception) { - return((Image *) NULL); + char + token[MaxTextExtent]; + + ChannelOperation + channel_op; + + const char + *p; + + Image + *channel_images; + + PixelChannel + p_channel, + q_channel; + + assert(images != (Image *) NULL); + assert(images->signature == MagickSignature); + if (images->debug != MagickFalse) + (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename); + channel_images=CloneImage(images,images->columns,images->columns,MagickTrue, + exception); + p=(char *) expression; + GetMagickToken(p,&p,token); + for (q_channel=RedPixelChannel; *p != '\0'; ) + { + MagickBooleanType + status; + + ssize_t + i; + + /* + Interpret channel expression. + */ + if (*token == ',') + { + q_channel=(PixelChannel) ((ssize_t) q_channel+1); + GetMagickToken(p,&p,token); + } + if (*token == '|') + { + if (GetNextImageInList(images) != (Image *) NULL) + images=GetNextImageInList(images); + else + images=GetFirstImageInList(images); + GetMagickToken(p,&p,token); + } + if (*token == ';') + { + AppendImageToList(&channel_images,CloneImage(images, + channel_images->columns,channel_images->rows,MagickTrue,exception)); + channel_images=GetLastImageInList(channel_images); + GetMagickToken(p,&p,token); + } + i=ParsePixelChannelOption(token); + if (i < 0) + { + (void) ThrowMagickException(exception,GetMagickModule(),OptionError, + "UnableToParseExpression","`%s'",p); + channel_images=DestroyImageList(channel_images); + break; + } + p_channel=(PixelChannel) i; + channel_op=ExtractChannelOp; + GetMagickToken(p,&p,token); + if (*token == '<') + { + channel_op=ExchangeChannelOp; + GetMagickToken(p,&p,token); + } + if (*token == '=') + GetMagickToken(p,&p,token); + if (*token == '>') + { + if (channel_op != ExchangeChannelOp) + channel_op=TransferChannelOp; + GetMagickToken(p,&p,token); + } + if (channel_op != ExtractChannelOp) + { + i=ParsePixelChannelOption(token); + if (i < 0) + { + (void) ThrowMagickException(exception,GetMagickModule(),OptionError, + "UnableToParseExpression","`%s'",p); + channel_images=DestroyImageList(channel_images); + break; + } + q_channel=(PixelChannel) i; + } + status=ChannelImage(channel_images,images,channel_op,p_channel,q_channel, + exception); + if (status == MagickFalse) + { + channel_images=DestroyImageList(channel_images); + break; + } + } + return(channel_images); } diff --git a/MagickCore/option.c b/MagickCore/option.c index b11a05747..951654e08 100644 --- a/MagickCore/option.c +++ b/MagickCore/option.c @@ -2527,16 +2527,18 @@ MagickExport ssize_t ParseCommandOption(const CommandOption option_table, MagickExport ssize_t ParsePixelChannelOption(const char *channels) { char - *q; + *q, + token[MaxTextExtent]; ssize_t channel; - channel=ParseCommandOption(MagickPixelChannelOptions,MagickTrue,channels); + GetMagickToken(channels,NULL,token); + channel=ParseCommandOption(MagickPixelChannelOptions,MagickTrue,token); if (channel >= 0) return(channel); - q=(char *) channels; - channel=InterpretLocaleValue(channels,&q); + q=(char *) token; + channel=InterpretLocaleValue(token,&q); if ((q == channels) || (channel < 0) || (channel >= MaxPixelChannels)) return(-1); return(channel);