#include "MagickCore/monitor-private.h"
#include "MagickCore/option.h"
#include "MagickCore/pixel-accessor.h"
+#include "MagickCore/string-private.h"
#include "MagickCore/token.h"
#include "MagickCore/utility.h"
#include "MagickCore/version.h"
%
% <=> exchange two channels (e.g. red<=>blue)
% => transfer a channel to another (e.g. red=>green)
+% = assign a constant (e.g. red=>50%)
% , separate channel operations (e.g. red, green)
% | read channels from next input image (e.g. red | green)
% ; write channels to next output image (e.g. red; green; blue)
typedef enum
{
ExtractChannelOp,
+ AssignChannelOp,
ExchangeChannelOp,
TransferChannelOp
} ChannelFx;
}
static MagickBooleanType ChannelImage(Image *destination_image,
- const Image *source_image,const ChannelFx channel_op,
- const PixelChannel source_channel,const PixelChannel destination_channel,
- ExceptionInfo *exception)
+ const Image *source_image,const PixelChannel source_channel,
+ const PixelChannel destination_channel,const ChannelFx channel_op,
+ const Quantum pixel,ExceptionInfo *exception)
{
CacheView
*source_view,
(destination_traits == UndefinedPixelTrait))
continue;
offset=GetPixelChannelMapOffset(source_image,source_channel);
- SetPixelChannel(destination_image,destination_channel,p[offset],q);
+ if (channel_op == AssignChannelOp)
+ SetPixelChannel(destination_image,destination_channel,pixel,q);
+ else
+ SetPixelChannel(destination_image,destination_channel,p[offset],q);
p+=GetPixelChannels(source_image);
q+=GetPixelChannels(destination_image);
}
const Image
*source_image;
+ double
+ pixel;
+
Image
*destination_image;
if (expression == (const char *) NULL)
return(destination_image);
destination_channel=RedPixelChannel;
+ pixel=0.0;
p=(char *) expression;
GetMagickToken(p,&p,token);
for (channels=0; *p != '\0'; )
GetMagickToken(p,&p,token);
}
if (*token == '=')
- GetMagickToken(p,&p,token);
+ {
+ if (channel_op != ExchangeChannelOp)
+ channel_op=AssignChannelOp;
+ GetMagickToken(p,&p,token);
+ }
if (*token == '>')
{
if (channel_op != ExchangeChannelOp)
channel_op=TransferChannelOp;
GetMagickToken(p,&p,token);
}
- if (channel_op != ExtractChannelOp)
+ switch (channel_op)
+ {
+ case AssignChannelOp:
+ {
+ pixel=StringToDoubleInterval(token,(double) QuantumRange+1.0);
+ break;
+ }
+ case ExchangeChannelOp:
+ case TransferChannelOp:
{
i=ParsePixelChannelOption(token);
if (i < 0)
break;
}
destination_channel=(PixelChannel) i;
+ break;
}
- status=ChannelImage(destination_image,source_image,channel_op,
- source_channel,destination_channel,exception);
+ case ExtractChannelOp:
+ break;
+ }
+ status=ChannelImage(destination_image,source_image,source_channel,
+ destination_channel,channel_op,ClampToQuantum(pixel),exception);
if (status == MagickFalse)
{
destination_image=DestroyImageList(destination_image);
break;
}
+ if (channel_op == ExchangeChannelOp)
+ {
+ status=ChannelImage(destination_image,source_image,destination_channel,
+ source_channel,channel_op,ClampToQuantum(pixel),exception);
+ if (status == MagickFalse)
+ {
+ destination_image=DestroyImageList(destination_image);
+ break;
+ }
+ }
channels++;
status=SetImageProgress(source_image,ChannelFxImageTag,p-expression,
strlen(expression));