% September 2011 %
% %
% %
-% 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 %
#include "MagickWand/studio.h"
#include "MagickWand/MagickWand.h"
#include "MagickWand/magick-wand-private.h"
+#include "MagickWand/mogrify.h"
#include "MagickWand/wand.h"
#include "MagickWand/wandcli.h"
#include "MagickWand/wandcli-private.h"
-#include "MagickWand/operation.h"
+#include "MagickCore/image-private.h"
#include "MagickCore/monitor-private.h"
+#include "MagickWand/operation.h"
#include "MagickCore/thread-private.h"
#include "MagickCore/string-private.h"
#include "MagickCore/pixel-private.h"
\f
+/*
+ Constant declaration.
+*/
+static const char
+ MogrifyBackgroundColor[] = "#fff", /* white */
+ MogrifyBorderColor[] = "#dfdfdf", /* sRGB gray */
+ MogrifyMatteColor[] = "#bdbdbd"; /* slightly darker gray */
+\f
/*
Define declarations.
*/
/* FUTURE: why is this default so specific? */
#define DEFAULT_DISSIMILARITY_THRESHOLD "0.31830988618379067154"
-/*
- Constant declaration. (temporary exports)
-*/
-static const char
- BackgroundColor[] = "#fff", /* white */
- BorderColor[] = "#dfdfdf", /* sRGB gray */
- MatteColor[] = "#bdbdbd"; /* slightly darker gray */
-
/* For Debugging Geometry Input */
#define ReportGeometry(flags,info) \
(void) FormatLocaleFile(stderr, "Geometry = 0x%04X : %lg x %lg %+lg %+lg\n", \
if (image != (Image *) NULL)
return(image);
read_info=CloneImageInfo(image_info);
- (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
+ if (path != (const char *) NULL)
+ (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
image=ReadImage(read_info,exception);
read_info=DestroyImageInfo(read_info);
if (image != (Image *) NULL)
an array of floating point values than call SparseColorImage().
Argument is a complex mix of floating-point pixel coodinates, and color
specifications (or direct floating point numbers). The number of floats
- needed to represent a color varies depending on teh current channel
+ needed to represent a color varies depending on the current channel
setting.
This really should be in MagickCore, so that other API's can make use of it.
*/
static Image *SparseColorOption(const Image *image,
- const SparseColorMethod method,const char *arguments,
- ExceptionInfo *exception)
+ const SparseColorMethod method,const char *arguments,ExceptionInfo *exception)
{
char
token[MaxTextExtent];
% arg2 is currently only used by "-limit"
%
*/
-WandExport void CLISettingOptionInfo(MagickCLI *cli_wand,
- const char *option,const char *arg1, const char *arg2)
+WandPrivate void CLISettingOptionInfo(MagickCLI *cli_wand,
+ const char *option,const char *arg1n, const char *arg2n)
{
ssize_t
parse; /* option argument parsing (string to value table lookup) */
- assert(cli_wand != (MagickCLI *) NULL);
- assert(cli_wand->signature == WandSignature);
- assert(cli_wand->wand.signature == WandSignature);
- if (IfMagickTrue(cli_wand->wand.debug))
- (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name);
+ const char /* percent escaped versions of the args */
+ *arg1,
+ *arg2;
#define _image_info (cli_wand->wand.image_info)
+#define _image (cli_wand->wand.images)
#define _exception (cli_wand->wand.exception)
#define _draw_info (cli_wand->draw_info)
#define _quantize_info (cli_wand->quantize_info)
#define ArgBooleanString (IfSetOption?"true":"false")
#define ArgOption(def) (IfSetOption?arg1:(const char *)(def))
-#if 0
-Setting are not directly involved with images, so can not
-interpret Percent Escapes in Arguments, At least not yet */
+ assert(cli_wand != (MagickCLI *) NULL);
+ assert(cli_wand->signature == WandSignature);
+ assert(cli_wand->wand.signature == WandSignature);
+
+ if (IfMagickTrue(cli_wand->wand.debug))
+ (void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
+ "- Setting Option: %s \"%s\" \"%s\"", option,arg1n,arg2n);
+ arg1 = arg1n,
+ arg2 = arg2n;
+
+#if 1
#define _process_flags (cli_wand->process_flags)
#define _option_type ((CommandOptionFlags) cli_wand->command->flags)
/* Interpret Percent Escapes in Arguments - using first image */
- arg1 = arg1n,
- arg2 = arg2n;
if ( (((_process_flags & ProcessInterpretProperities) != 0 )
|| ((_option_type & AlwaysInterpretArgsFlag) != 0)
) && ((_option_type & NeverInterpretArgsFlag) == 0) ) {
Better error handling of QueryColorCompliance() needed.
*/
(void) SetImageOption(_image_info,option+1,ArgOption(NULL));
- (void) QueryColorCompliance(ArgOption(BackgroundColor),AllCompliance,
+ (void) QueryColorCompliance(ArgOption(MogrifyBackgroundColor),AllCompliance,
&_image_info->background_color,_exception);
break;
}
break;
}
(void) DeleteImageOption(_image_info,option+1);
- (void) QueryColorCompliance(BorderColor,AllCompliance,
+ (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
&_image_info->border_color,_exception);
- (void) QueryColorCompliance(BorderColor,AllCompliance,
+ (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
&_draw_info->border_color,_exception);
break;
}
}
if (LocaleCompare("channel",option+1) == 0)
{
- arg1=ArgOption("default");
- parse=ParseChannelOption(arg1);
+ parse=ParseChannelOption(ArgOption("Default"));
if (parse < 0)
CLIWandExceptArgBreak(OptionError,"UnrecognizedChannelType",
option,arg1);
(void) CloneString(&_draw_info->family,ArgOption(NULL));
break;
}
+ if (LocaleCompare("features",option+1) == 0)
+ {
+ (void) SetImageOption(_image_info,"identify:features",
+ ArgBooleanString);
+ if (IfSetOption)
+ (void) SetImageArtifact(_image,"verbose","true");
+ break;
+ }
if (LocaleCompare("fill",option+1) == 0)
{
/* Set "fill" OR "fill-pattern" in _draw_info
SyncImageSettings() used to set per-image attribute.
FUTURE: Can't find anything else using _image_info->fuzz directly!
- remove direct sttribute from image_info
+ convert structure attribute to 'option' string
*/
arg1=ArgOption("0");
if (IfMagickFalse(IsGeometry(arg1)))
}
case 'i':
{
+ if (LocaleCompare("intensity",option+1) == 0)
+ {
+ arg1 = ArgOption("undefined");
+ parse = ParseCommandOption(MagickPixelIntensityOptions,MagickFalse,
+ arg1);
+ if (parse < 0)
+ CLIWandExceptArgBreak(OptionError,"UnrecognizedIntensityType",
+ option,arg1);
+ (void) SetImageOption(_image_info,option+1,arg1);
+ break;
+ }
if (LocaleCompare("intent",option+1) == 0)
{
/* Only used by coders: MIFF, MPC, BMP, PNG
and for image profile call to AcquireTransformThreadSet()
SyncImageSettings() used to set per-image attribute.
*/
- arg1 = ArgOption("indefined");
+ arg1 = ArgOption("undefined");
parse = ParseCommandOption(MagickIntentOptions,MagickFalse,arg1);
if (parse < 0)
CLIWandExceptArgBreak(OptionError,"UnrecognizedIntentType",
{
/* SyncImageSettings() used to set per-image attribute. */
(void) SetImageOption(_image_info,option+1,ArgOption(NULL));
- (void) QueryColorCompliance(ArgOption(MatteColor),AllCompliance,
+ (void) QueryColorCompliance(ArgOption(MogrifyMatteColor),AllCompliance,
&_image_info->matte_color,_exception);
break;
}
(void) SetImageOption(_image_info,option+1,ArgOption(NULL));
break;
}
+ if (LocaleCompare("moments",option+1) == 0)
+ {
+ (void) SetImageOption(_image_info,"identify:moments",
+ ArgBooleanString);
+ if (IfSetOption)
+ (void) SetImageArtifact(_image,"verbose","true");
+ break;
+ }
if (LocaleCompare("monitor",option+1) == 0)
{
(void) SetImageInfoProgressMonitor(_image_info, IfSetOption?
if (IfMagickFalse(IsGeometry(arg1)))
CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
SetRandomSecretKey(
- IfSetOption ? (const unsigned long) StringToUnsignedLong(arg1)
- : (const unsigned long) time((time_t *) NULL) );
+ IfSetOption ? (unsigned long) StringToUnsignedLong(arg1)
+ : (unsigned long) time((time_t *) NULL) );
break;
}
if (LocaleCompare("size",option+1) == 0)
CLIWandExceptionBreak(OptionError,"UnrecognizedOption",option);
}
-#if 0
/* clean up percent escape interpreted strings */
if (arg1 != arg1n )
arg1=DestroyString((char *)arg1);
if (arg2 != arg2n )
arg2=DestroyString((char *)arg2);
-#endif
#undef _image_info
#undef _exception
also change. GetFirstImageInList() should be used by caller if they wish
return the Image pointer to the first image in list.
*/
-static void CLISimpleOperatorImage(MagickCLI *cli_wand,
+static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
const char *option, const char *arg1n, const char *arg2n)
{
Image *
ssize_t
parse;
- const char /* For percent escape interpretImageProperties() */
+ const char /* percent escaped versions of the args */
*arg1,
*arg2;
-#define _image_info (cli_wand->wand.image_info)
-#define _image (cli_wand->wand.images)
-#define _exception (cli_wand->wand.exception)
-#define _draw_info (cli_wand->draw_info)
-#define _quantize_info (cli_wand->quantize_info)
-#define _process_flags (cli_wand->process_flags)
-#define _option_type ((CommandOptionFlags) cli_wand->command->flags)
-#define IfNormalOp (*option=='-')
-#define IfPlusOp (*option!='-')
-#define normal_op IsMagickTrue(IfNormalOp)
-#define plus_alt_op IsMagickFalse(IfNormalOp)
+#define _image_info (cli_wand->wand.image_info)
+#define _image (cli_wand->wand.images)
+#define _exception (cli_wand->wand.exception)
+#define _draw_info (cli_wand->draw_info)
+#define _quantize_info (cli_wand->quantize_info)
+#define _process_flags (cli_wand->process_flags)
+#define _option_type ((CommandOptionFlags) cli_wand->command->flags)
+#define IfNormalOp (*option=='-')
+#define IfPlusOp (*option!='-')
+#define IsNormalOp IsMagickTrue(IfNormalOp)
+#define IsPlusOp IsMagickFalse(IfNormalOp)
assert(cli_wand != (MagickCLI *) NULL);
assert(cli_wand->signature == WandSignature);
if (IfMagickTrue(cli_wand->wand.debug))
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name);
- /* Interpret Percent Escapes in Arguments - using first image */
arg1 = arg1n,
arg2 = arg2n;
+
+ /* Interpret Percent Escapes in Arguments - using first image */
if ( (((_process_flags & ProcessInterpretProperities) != 0 )
|| ((_option_type & AlwaysInterpretArgsFlag) != 0)
) && ((_option_type & NeverInterpretArgsFlag) == 0) ) {
}
case 'c':
{
+ if (LocaleCompare("canny",option+1) == 0)
+ {
+ flags=ParseGeometry(arg1,&geometry_info);
+ if ((flags & (RhoValue|SigmaValue)) == 0)
+ CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
+ if ((flags & SigmaValue) == 0)
+ geometry_info.sigma=1.0;
+ if ((flags & XiValue) == 0)
+ geometry_info.xi=10;
+ if ((flags & PsiValue) == 0)
+ geometry_info.psi=30;
+ if ((flags & PercentValue) != 0)
+ {
+ geometry_info.xi/=100.0;
+ geometry_info.psi/=100.0;
+ }
+ new_image=CannyEdgeImage(_image,geometry_info.rho,geometry_info.sigma,
+ geometry_info.xi,geometry_info.psi,_exception);
+ break;
+ }
if (LocaleCompare("cdl",option+1) == 0)
{
/* Note: arguments do not have percent escapes expanded */
/*
Color correct with a color decision list.
*/
- color_correction_collection=FileToString(arg1,~0,_exception);
+ color_correction_collection=FileToString(arg1,~0UL,_exception);
if (color_correction_collection == (char *) NULL)
break;
(void) ColorDecisionListImage(_image,color_correction_collection,
break;
for (x=0; x < (ssize_t) mask_image->columns; x++)
{
- if (IfMagickFalse(mask_image->alpha_trait))
+ if (mask_image->alpha_trait != BlendPixelTrait)
SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
- SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
- SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
- SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
+ SetPixelGray(mask_image,GetPixelAlpha(mask_image,q),q);
q+=GetPixelChannels(mask_image);
}
if (IfMagickFalse(SyncCacheViewAuthenticPixels(mask_view,_exception)))
/* clean up and set the write mask */
mask_view=DestroyCacheView(mask_view);
mask_image->alpha_trait=BlendPixelTrait;
+ (void) SetImageColorspace(_image,GRAYColorspace,_exception);
(void) SetImageMask(_image,mask_image,_exception);
mask_image=DestroyImage(mask_image);
break;
}
if (LocaleCompare("clip-path",option+1) == 0)
{
- (void) ClipImagePath(_image,arg1,normal_op,_exception);
+ (void) ClipImagePath(_image,arg1,IsNormalOp,_exception);
/* Note: Use "+clip-mask" remove the write mask added */
break;
}
That seems to be a little strange!
*/
(void) TransformImageColorspace(_image,
- IfNormalOp ? _image_info->colorspace : RGBColorspace,
+ IfNormalOp ? _image_info->colorspace : sRGBColorspace,
_exception);
break;
}
if (LocaleCompare("contrast",option+1) == 0)
{
- CLIWandWarnReplaced(normal_op?"-level":"+level");
- (void) ContrastImage(_image,normal_op,_exception);
+ CLIWandWarnReplaced(IfNormalOp?"-level":"+level");
+ (void) ContrastImage(_image,IsNormalOp,_exception);
break;
}
if (LocaleCompare("contrast-stretch",option+1) == 0)
StringInfo
*passkey;
- passkey=FileToStringInfo(arg1,~0,_exception);
+ passkey=FileToStringInfo(arg1,~0UL,_exception);
if (passkey == (StringInfo *) NULL)
CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
CLIWandExceptArgBreak(OptionError,"InvalidNumberList",option,arg2);
new_image=DistortImage(_image,(DistortImageMethod) parse,count,args,
- plus_alt_op,_exception);
+ IsPlusOp,_exception);
args=(double *) RelinquishMagickMemory(args);
break;
}
flags=ParseGeometry(arg1,&geometry_info);
if ((flags & (RhoValue|SigmaValue)) == 0)
CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
- if ((flags & SigmaValue) == 0)
- geometry_info.sigma=1.0;
- new_image=EdgeImage(_image,geometry_info.rho,geometry_info.sigma,
- _exception);
+ new_image=EdgeImage(_image,geometry_info.rho,_exception);
break;
}
if (LocaleCompare("emboss",option+1) == 0)
StringInfo
*passkey;
- passkey=FileToStringInfo(arg1,~0,_exception);
+ passkey=FileToStringInfo(arg1,~0UL,_exception);
if (passkey != (StringInfo *) NULL)
{
(void) PasskeyEncipherImage(_image,passkey,_exception);
}
case 'f':
{
- if (LocaleCompare("features",option+1) == 0)
- {
- /* FUTURE: move to SyncImageSettings() and AcqireImage()??? */
- if (IfPlusOp) {
- (void) DeleteImageArtifact(_image,"identify:features");
- break;
- }
- (void) SetImageArtifact(_image,"identify:features","true");
- (void) SetImageArtifact(_image,"verbose","true");
- break;
- }
if (LocaleCompare("flip",option+1) == 0)
{
new_image=FlipImage(_image,_exception);
(void) ParsePageGeometry(_image,arg1,&geometry,_exception);
(void) QueryColorCompliance(arg2,AllCompliance,&target,_exception);
(void) FloodfillPaintImage(_image,_draw_info,&target,geometry.x,
- geometry.y,plus_alt_op,_exception);
+ geometry.y,IsPlusOp,_exception);
break;
}
if (LocaleCompare("frame",option+1) == 0)
_image->filter,_exception);
break;
}
+ if (LocaleCompare("grayscale",option+1) == 0)
+ {
+ parse=ParseCommandOption(MagickPixelIntensityOptions,
+ MagickFalse,arg1);
+ if (parse < 0)
+ CLIWandExceptArgBreak(OptionError,"UnrecognizedIntensityMethod",
+ option,arg1);
+ (void) GrayscaleImage(_image,(PixelIntensityMethod) parse,_exception);
+ break;
+ }
+ CLIWandExceptionBreak(OptionError,"UnrecognizedOption",option);
+ }
+ case 'h':
+ {
+ if (LocaleCompare("hough-lines",option+1) == 0)
+ {
+ flags=ParseGeometry(arg1,&geometry_info);
+ if ((flags & (RhoValue|SigmaValue)) == 0)
+ CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
+ if ((flags & SigmaValue) == 0)
+ geometry_info.sigma=geometry_info.rho;
+ if ((flags & XiValue) == 0)
+ geometry_info.xi=40;
+ new_image=HoughLineImage(_image,(size_t) geometry_info.rho,
+ (size_t) geometry_info.sigma,(size_t) geometry_info.xi,_exception);
+ break;
+ }
CLIWandExceptionBreak(OptionError,"UnrecognizedOption",option);
}
case 'i':
*text;
format=GetImageOption(_image_info,"format");
- if (format == (char *) NULL) {
- (void) IdentifyImage(_image,stdout,_image_info->verbose,_exception);
- break;
- }
+ if (format == (char *) NULL)
+ {
+ (void) IdentifyImage(_image,stdout,_image_info->verbose,
+ _exception);
+ break;
+ }
text=InterpretImageProperties(_image_info,_image,format,_exception);
if (text == (char *) NULL)
CLIWandExceptionBreak(OptionWarning,"InterpretPropertyFailure",
- option);
+ option);
(void) fputs(text,stdout);
- (void) fputc('\n',stdout);
text=DestroyString((char *)text);
break;
}
&white_point,_exception);
}
(void) LevelImageColors(_image,&black_point,&white_point,
- plus_alt_op,_exception);
+ IsPlusOp,_exception);
break;
}
if (LocaleCompare("linear-stretch",option+1) == 0)
}
case 'm':
{
+ if (LocaleCompare("magnify",option+1) == 0)
+ {
+ new_image=MagnifyImage(_image,_exception);
+ break;
+ }
if (LocaleCompare("map",option+1) == 0)
{
CLIWandWarnReplaced("-remap");
{
CLIWandWarnReplaced(IfNormalOp?"-alpha Set":"-alpha Off");
(void) SetImageAlphaChannel(_image,IfNormalOp ? SetAlphaChannel :
- DeactivateAlphaChannel, _exception);
+ DeactivateAlphaChannel, _exception);
+ break;
+ }
+ if (LocaleCompare("mean-shift",option+1) == 0)
+ {
+ flags=ParseGeometry(arg1,&geometry_info);
+ if ((flags & (RhoValue|SigmaValue)) == 0)
+ CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
+ if ((flags & SigmaValue) == 0)
+ geometry_info.sigma=1.0;
+ if ((flags & XiValue) == 0)
+ geometry_info.xi=0.10*QuantumRange;
+ if ((flags & PercentValue) != 0)
+ geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
+ new_image=MeanShiftImage(_image,(size_t) geometry_info.rho,
+ (size_t) geometry_info.sigma,geometry_info.xi,_exception);
break;
}
if (LocaleCompare("median",option+1) == 0)
{
if (LocaleCompare("negate",option+1) == 0)
{
- (void) NegateImage(_image, plus_alt_op, _exception);
+ (void) NegateImage(_image, IsPlusOp, _exception);
break;
}
if (LocaleCompare("noise",option+1) == 0)
target;
(void) QueryColorCompliance(arg1,AllCompliance,&target,_exception);
- (void) OpaquePaintImage(_image,&target,&_draw_info->fill,plus_alt_op,
+ (void) OpaquePaintImage(_image,&target,&_draw_info->fill,IsPlusOp,
_exception);
break;
}
}
case 'r':
{
- if (LocaleCompare("radial-blur",option+1) == 0)
+ if (LocaleCompare("rotational-blur",option+1) == 0)
{
flags=ParseGeometry(arg1,&geometry_info);
if ((flags & RhoValue) == 0)
CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
- new_image=RadialBlurImage(_image,geometry_info.rho,_exception);
+ new_image=RotationalBlurImage(_image,geometry_info.rho,_exception);
break;
}
if (LocaleCompare("raise",option+1) == 0)
if (IfMagickFalse(IsGeometry(arg1)))
CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
flags=ParsePageGeometry(_image,arg1,&geometry,_exception);
- (void) RaiseImage(_image,&geometry,normal_op,_exception);
+ (void) RaiseImage(_image,&geometry,IsNormalOp,_exception);
break;
}
if (LocaleCompare("random-threshold",option+1) == 0)
flags=ParseGeometry(arg1,&geometry_info);
if (((flags & RhoValue) == 0) || ((flags & SigmaValue) == 0))
CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
- new_image=ShadeImage(_image,normal_op,geometry_info.rho,
+ new_image=ShadeImage(_image,IsNormalOp,geometry_info.rho,
geometry_info.sigma,_exception);
break;
}
if ((flags & PercentValue) != 0)
geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
100.0;
- (void) SigmoidalContrastImage(_image,normal_op,geometry_info.rho,
+ (void) SigmoidalContrastImage(_image,IsNormalOp,geometry_info.rho,
geometry_info.sigma,_exception);
break;
}
threshold;
threshold=(double) QuantumRange/2;
- if (normal_op) {
+ if (IfNormalOp) {
if (IfMagickFalse(IsGeometry(arg1)))
CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
threshold=StringToDoubleInterval(arg1,(double) QuantumRange+1.0);
(void) QueryColorCompliance(arg1,AllCompliance,&target,_exception);
(void) TransparentPaintImage(_image,&target,(Quantum)
- TransparentAlpha,plus_alt_op,_exception);
+ TransparentAlpha,IsPlusOp,_exception);
break;
}
if (LocaleCompare("transpose",option+1) == 0)
Option is not documented, bt appears to be for "identify".
We may need a identify specific verbose!
*/
- if (plus_alt_op) {
+ if (IsPlusOp) {
(void) DeleteImageArtifact(_image,"identify:unique-colors");
break;
}
geometry_info.xi=0.1*_image->columns;
if ((flags & PsiValue) == 0)
geometry_info.psi=0.1*_image->rows;
+ if ((flags & PercentValue) != 0)
+ {
+ geometry_info.xi*=(double) _image->columns/100.0;
+ geometry_info.psi*=(double) _image->rows/100.0;
+ }
new_image=VignetteImage(_image,geometry_info.rho,geometry_info.sigma,
(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
ceil(geometry_info.psi-0.5),_exception);
if (new_image != (Image *) NULL)
ReplaceImageInListReturnLast(&_image,new_image);
- return;
+ return(MagickTrue);
#undef _image_info
#undef _draw_info
#undef _quantize_info
#undef _exception
#undef IfNormalOp
#undef IfPlusOp
-#undef normal_op
-#undef plus_alt_op
+#undef IsNormalOp
+#undef IsPlusOp
}
-WandExport void CLISimpleOperatorImages(MagickCLI *cli_wand,
- const char *option, const char *arg1, const char *arg2)
+WandPrivate MagickBooleanType CLISimpleOperatorImages(MagickCLI *cli_wand,
+ const char *option,const char *arg1,const char *arg2)
{
#if !USE_WAND_METHODS
size_t
assert(cli_wand->signature == WandSignature);
assert(cli_wand->wand.signature == WandSignature);
assert(cli_wand->wand.images != (Image *) NULL); /* images must be present */
+
if (IfMagickTrue(cli_wand->wand.debug))
- (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name);
+ (void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
+ "- Simple Operator: %s \"%s\" \"%s\"", option,arg1,arg2);
#if !USE_WAND_METHODS
/* FUTURE add appropriate tracing */
CLISimpleOperatorImage(cli_wand, option, arg1, arg2);
MagickResetIterator(&cli_wand->wand);
#endif
- return;
+ return(MagickTrue);
}
\f
/*
%
% The format of the MogrifyImage method is:
%
-% void CLIListOperatorImages(MagickCLI *cli_wand,
-% const char *option, const char *arg1, const char *arg2)
+% MagickBooleanType CLIListOperatorImages(MagickCLI *cli_wand,
+% const char *option,const char *arg1,const char *arg2)
%
% A description of each parameter follows:
%
% arg2 is currently not used
%
*/
-WandExport void CLIListOperatorImages(MagickCLI *cli_wand,
- const char *option,const char *arg1n, const char *arg2n)
+WandPrivate MagickBooleanType CLIListOperatorImages(MagickCLI *cli_wand,
+ const char *option,const char *arg1n,const char *arg2n)
{
- ssize_t
- parse;
+ const char /* percent escaped versions of the args */
+ *arg1,
+ *arg2;
Image
*new_images;
- const char /* For percent escape interpretImageProperties() */
- *arg1,
- *arg2;
+ MagickStatusType
+ status;
+
+ ssize_t
+ parse;
#define _image_info (cli_wand->wand.image_info)
#define _images (cli_wand->wand.images)
#define _option_type ((CommandOptionFlags) cli_wand->command->flags)
#define IfNormalOp (*option=='-')
#define IfPlusOp (*option!='-')
-#define normal_op IsMagickTrue(IfNormalOp)
+#define IsNormalOp IsMagickTrue(IfNormalOp)
assert(cli_wand != (MagickCLI *) NULL);
assert(cli_wand->signature == WandSignature);
assert(cli_wand->wand.signature == WandSignature);
assert(_images != (Image *) NULL); /* _images must be present */
+
if (IfMagickTrue(cli_wand->wand.debug))
- (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name);
+ (void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
+ "- List Operator: %s \"%s\" \"%s\"", option,arg1n,arg2n);
- /* Interpret Percent Escapes in Arguments - using first image */
arg1 = arg1n;
arg2 = arg2n;
+
+ /* Interpret Percent Escapes in Arguments - using first image */
if ( (((_process_flags & ProcessInterpretProperities) != 0 )
|| ((_option_type & AlwaysInterpretArgsFlag) != 0)
) && ((_option_type & NeverInterpretArgsFlag) == 0) ) {
#undef _process_flags
#undef _option_type
-#if 0
- (void) FormatLocaleFile(stderr,
- "CLIListOperatorImages: \"%s\" \"%s\" \"%s\"\n",option,arg1,arg2);
-#endif
-
-
+ status=MagickTrue;
new_images=NewImageList();
switch (*(option+1))
{
if (LocaleCompare("append",option+1) == 0)
{
- new_images=AppendImages(_images,normal_op,_exception);
+ new_images=AppendImages(_images,IsNormalOp,_exception);
break;
}
if (LocaleCompare("average",option+1) == 0)
}
if (LocaleCompare("combine",option+1) == 0)
{
- /* FUTURE - this may be replaced by a 'channel' method */
- parse = ParseCommandOption(MagickColorspaceOptions,MagickFalse,arg1);
+ parse = (ssize_t) sRGBColorspace; /* default (backward compatible) */
+ if ( IfPlusOp )
+ parse = ParseCommandOption(MagickColorspaceOptions,MagickFalse,
+ arg1);
+ if (parse < 0)
+ CLIWandExceptArgBreak(OptionError,"UnrecognizedColorspace",option,
+ arg1);
new_images=CombineImages(_images,(ColorspaceType) parse,_exception);
break;
}
+ if (LocaleCompare("compare",option+1) == 0)
+ {
+ double
+ distortion;
+
+ Image
+ *image,
+ *reconstruct_image;
+
+ MetricType
+ metric;
+
+ /*
+ Mathematically and visually annotate the difference between an
+ image and its reconstruction.
+ */
+ image=RemoveFirstImageFromList(&_images);
+ reconstruct_image=RemoveFirstImageFromList(&_images);
+ /* FUTURE - produce Exception, rather than silent fail */
+ if (reconstruct_image == (Image *) NULL)
+ break;
+ metric=UndefinedErrorMetric;
+ option=GetImageOption(_image_info,"metric");
+ if (option != (const char *) NULL)
+ metric=(MetricType) ParseCommandOption(MagickMetricOptions,
+ MagickFalse,option);
+ new_images=CompareImages(image,reconstruct_image,metric,&distortion,
+ _exception);
+ (void) distortion;
+ reconstruct_image=DestroyImage(reconstruct_image);
+ image=DestroyImage(image);
+ break;
+ }
+ if (LocaleCompare("complex",option+1) == 0)
+ {
+ parse=ParseCommandOption(MagickComplexOptions,MagickFalse,arg1);
+ if (parse < 0)
+ CLIWandExceptArgBreak(OptionError,"UnrecognizedEvaluateOperator",
+ option,arg1);
+ new_images=ComplexImages(_images,(ComplexOperator) parse,_exception);
+ break;
+ }
if (LocaleCompare("composite",option+1) == 0)
{
CompositeOperator
/* FUTURE - this should not be here! - should be part of -geometry */
(void) TransformImage(&source_image,(char *) NULL,
source_image->geometry,_exception);
-
SetGeometry(source_image,&geometry);
(void) ParseAbsoluteGeometry(source_image->geometry,&geometry);
GravityAdjustGeometry(new_images->columns,new_images->rows,
- new_images->gravity, &geometry);
-
+ new_images->gravity, &geometry);
mask_image=RemoveFirstImageFromList(&_images);
if (mask_image != (Image *) NULL)
- { /* handle a third write mask image */
+ {
if ((compose == DisplaceCompositeOp) ||
- (compose == DistortCompositeOp)) {
- /* Merge Y displacement into X displace/distort map. */
- (void) CompositeImage(source_image,mask_image,
+ (compose == DistortCompositeOp))
+ status&=CompositeImage(source_image,mask_image,
CopyGreenCompositeOp,MagickTrue,0,0,_exception);
- mask_image=DestroyImage(mask_image);
- }
- else {
- /* Set a blending mask for the composition. */
- (void) NegateImage(mask_image,MagickFalse,_exception);
- (void) SetImageMask(source_image,mask_image,_exception);
- mask_image=DestroyImage(mask_image);
- }
+ else
+ {
+ Image
+ *image;
+
+ RectangleInfo
+ source_geometry;
+
+ source_geometry.width=mask_image->columns;
+ source_geometry.height=mask_image->rows;
+ source_geometry.x=(-geometry.x);
+ source_geometry.y=(-geometry.y);
+ geometry.x=0;
+ geometry.y=0;
+ image=ExtentImage(source_image,&source_geometry,_exception);
+ if (image != (Image *) NULL)
+ {
+ source_image=DestroyImage(source_image);
+ source_image=image;
+ }
+ status&=CompositeImage(source_image,mask_image,
+ IntensityCompositeOp,MagickTrue,0,0,_exception);
+ }
+ mask_image=DestroyImage(mask_image);
}
- (void) CompositeImage(new_images,source_image,compose,clip_to_self,
+ status&=CompositeImage(new_images,source_image,compose,clip_to_self,
geometry.x,geometry.y,_exception);
- (void) SetImageMask(new_images,(Image *) NULL,_exception);
source_image=DestroyImage(source_image);
break;
}
{
if (LocaleCompare("evaluate-sequence",option+1) == 0)
{
- parse = ParseCommandOption(MagickEvaluateOptions,MagickFalse,arg1);
- if ( parse < 0 )
+ parse=ParseCommandOption(MagickEvaluateOptions,MagickFalse,arg1);
+ if (parse < 0)
CLIWandExceptArgBreak(OptionError,"UnrecognizedEvaluateOperator",
- option,arg1);
+ option,arg1);
new_images=EvaluateImages(_images,(MagickEvaluateOperator)parse,
- _exception);
+ _exception);
break;
}
CLIWandExceptionBreak(OptionError,"UnrecognizedOption",option);
{
if (LocaleCompare("fft",option+1) == 0)
{
- new_images=ForwardFourierTransformImage(_images,normal_op,_exception);
+ new_images=ForwardFourierTransformImage(_images,IsNormalOp,_exception);
break;
}
if (LocaleCompare("flatten",option+1) == 0)
if (phase_image == (Image *) NULL)
break;
new_images=InverseFourierTransformImage(magnitude_image,phase_image,
- normal_op,_exception);
+ IsNormalOp,_exception);
magnitude_image=DestroyImage(magnitude_image);
phase_image=DestroyImage(phase_image);
break;
(void) RemapImages(_quantize_info,_images,(Image *) NULL,_exception);
break;
}
+ if (LocaleCompare("metric",option+1) == 0)
+ break;
if (LocaleCompare("morph",option+1) == 0)
{
Image
args=(double *) RelinquishMagickMemory(args);
break;
}
- if (LocaleCompare("print",option+1) == 0)
- {
- (void) FormatLocaleFile(stdout,"%s",arg1);
- break;
- }
if (LocaleCompare("process",option+1) == 0)
{
/* FUTURE: better parsing using ScriptToken() from string ??? */
/*
Support old style syntax, filter="-option arg1".
*/
+ assert(arg1 != (const char *) NULL);
length=strlen(arg1);
token=(char *) NULL;
if (~length >= (MaxTextExtent-1))
if (IfMagickFalse(IsGeometry(arg1)))
CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
offset=(ssize_t) StringToLong(arg1);
- new_images=SmushImages(_images,normal_op,offset,_exception);
+ new_images=SmushImages(_images,IsNormalOp,offset,_exception);
break;
}
if (LocaleCompare("subimage",option+1) == 0)
compare_image=GetImageFromList(_images,1);
/* Comparision Metric */
- metric=UndefinedMetric;
+ metric=UndefinedErrorMetric;
value=GetImageOption(_image_info,"metric");
if (value != (const char *) NULL)
metric=(MetricType) ParseCommandOption(MagickMetricOptions,
MagickFalse,value);
- new_images=SimilarityImage(base_image,compare_image,metric,
+ new_images=SimilarityImage(base_image,compare_image,metric,0.0,
&offset,&similarity,_exception);
if ( new_images != (Image *)NULL ) {
index,
swap_index;
- index=-1;
- swap_index=-2;
+ index=(-1);
+ swap_index=(-2);
if (IfNormalOp) {
GeometryInfo
geometry_info;
swap_index=(-1);
flags=ParseGeometry(arg1,&geometry_info);
- if ((flags & RhoValue) != 0)
+ if ((flags & RhoValue) == 0)
CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
index=(ssize_t) geometry_info.rho;
if ((flags & SigmaValue) != 0)
/* if new image list generated, replace existing image list */
if (new_images == (Image *) NULL)
- return;
+ return(status == 0 ? MagickFalse : MagickTrue);
_images=DestroyImageList(_images);
_images=GetFirstImageInList(new_images);
- return;
+ return(status == 0 ? MagickFalse : MagickTrue);
#undef _image_info
#undef _images
#undef _quantize_info
#undef IfNormalOp
#undef IfPlusOp
-#undef normal_op
+#undef IsNormalOp
}
\f
/*
% Currently arg2 is not used.
%
*/
-WandExport void CLINoImageOperator(MagickCLI *cli_wand,
- const char *option, const char *arg1, const char *arg2)
+WandPrivate void CLINoImageOperator(MagickCLI *cli_wand,
+ const char *option,const char *arg1n,const char *arg2n)
{
-#if 0
- const char /* For percent escape interpretImageProperties() */
+ const char /* percent escaped versions of the args */
*arg1,
*arg2;
-#endif
#define _image_info (cli_wand->wand.image_info)
#define _images (cli_wand->wand.images)
#define _exception (cli_wand->wand.exception)
+#define _process_flags (cli_wand->process_flags)
+#define _option_type ((CommandOptionFlags) cli_wand->command->flags)
#define IfNormalOp (*option=='-')
#define IfPlusOp (*option!='-')
assert(cli_wand != (MagickCLI *) NULL);
assert(cli_wand->signature == WandSignature);
assert(cli_wand->wand.signature == WandSignature);
- if (IfMagickTrue(cli_wand->wand.debug))
- (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name);
-#if 0
- Not able to be used as their may not be any images!
- Also the only option that may have arguments that can be percent escaped is
- "-clone".
+ if (IfMagickTrue(cli_wand->wand.debug))
+ (void) CLILogEvent(cli_wand,CommandEvent,GetMagickModule(),
+ "- NoImage Operator: %s \"%s\" \"%s\"", option,arg1n,arg2n);
-#define _process_flags (cli_wand->process_flags)
-#define _option_type ((CommandOptionFlags) cli_wand->command->flags)
- /* Interpret Percent Escapes in Arguments - using first image */
arg1 = arg1n;
arg2 = arg2n;
+
+ /* Interpret Percent Escapes in Arguments - using first image */
if ( (((_process_flags & ProcessInterpretProperities) != 0 )
|| ((_option_type & AlwaysInterpretArgsFlag) != 0)
) && ((_option_type & NeverInterpretArgsFlag) == 0) ) {
}
#undef _process_flags
#undef _option_type
-#endif
do { /* break to exit code */
/*
*write_info;
/* Need images, unless a "null:" output coder is used */
- if ( cli_wand->wand.images == (Image *) NULL ) {
+ if ( _images == (Image *) NULL ) {
if ( LocaleCompare(arg1,"null:") == 0 )
break;
CLIWandExceptArgBreak(OptionError,"NoImagesForWrite",option,arg1);
CLIWandExceptionBreak(ResourceLimitFatalError,
"MemoryAllocationFailed",option);
node->data = (void *)cli_wand->wand.images;
- cli_wand->wand.images = NewImageList();
node->next = cli_wand->image_list_stack;
cli_wand->image_list_stack = node;
+ cli_wand->wand.images = NewImageList();
/* handle respect-parenthesis */
if (IfMagickTrue(IsStringTrue(GetImageOption(cli_wand->wand.image_info,
option="{"; /* fall-thru so as to push image settings too */
else
break;
- /* fall thru to next if */
+ /* fall thru to operation */
}
if (LocaleCompare("{",option) == 0) {
/* stack 'push' of image_info settings */
"MemoryAllocationFailed",option);
node->data = (void *)cli_wand->wand.image_info;
+ node->next = cli_wand->image_info_stack;
+
+ cli_wand->image_info_stack = node;
cli_wand->wand.image_info = CloneImageInfo(cli_wand->wand.image_info);
if (cli_wand->wand.image_info == (ImageInfo *)NULL) {
CLIWandException(ResourceLimitFatalError,"MemoryAllocationFailed",
break;
}
- node->next = cli_wand->image_info_stack;
- cli_wand->image_info_stack = node;
-
break;
}
if (LocaleCompare(")",option) == 0) {
break;
}
+ if (LocaleCompare("print",option+1) == 0)
+ {
+ (void) FormatLocaleFile(stdout,"%s",arg1);
+ break;
+ }
if (LocaleCompare("set",option+1) == 0)
{
- /* Note: arguments are not percent escapes expanded yet */
- /* Some settings are applied to each image in memory in turn.
- While others only need to be applied once globally.
+ /* Settings are applied to each image in memory in turn (if any).
+ While a option: only need to be applied once globally.
+
+ NOTE: rguments have not been automatically percent expaneded
*/
- char
- *value;
+
+ /* escape the 'key' once only, using first image. */
+ arg1=InterpretImageProperties(_image_info,_images,arg1n,_exception);
+ if (arg1 == (char *) NULL)
+ CLIWandExceptionBreak(OptionWarning,"InterpretPropertyFailure",
+ option);
if (LocaleNCompare(arg1,"registry:",9) == 0)
{
if (IfPlusOp)
{
(void) DeleteImageRegistry(arg1+9);
+ arg1=DestroyString((char *)arg1);
break;
}
- value=InterpretImageProperties(_image_info,_images,arg2,_exception);
- if (value == (char *) NULL)
+ arg2=InterpretImageProperties(_image_info,_images,arg2n,_exception);
+ if (arg2 == (char *) NULL) {
+ arg1=DestroyString((char *)arg1);
CLIWandExceptionBreak(OptionWarning,"InterpretPropertyFailure",
option);
- (void) SetImageRegistry(StringRegistryType,arg1+9,value,_exception);
- value=DestroyString(value);
+ }
+ (void) SetImageRegistry(StringRegistryType,arg1+9,arg2,_exception);
+ arg1=DestroyString((char *)arg1);
+ arg2=DestroyString((char *)arg2);
break;
}
if (LocaleNCompare(arg1,"option:",7) == 0)
{
/* delete equivelent artifact from all images (if any) */
- MagickResetIterator(&cli_wand->wand);
- while ( IfMagickTrue(MagickNextImage(&cli_wand->wand)) )
- (void) DeleteImageArtifact(_images,arg1+7);
- MagickResetIterator(&cli_wand->wand);
+ if (_images != (Image *)NULL)
+ {
+ MagickResetIterator(&cli_wand->wand);
+ while ( IfMagickTrue(MagickNextImage(&cli_wand->wand)) )
+ (void) DeleteImageArtifact(_images,arg1+7);
+ MagickResetIterator(&cli_wand->wand);
+ }
/* now set/delete the global option as needed */
- if (IfPlusOp) {
- (void) DeleteImageOption(_image_info,arg1+7);
- break;
- }
- value=InterpretImageProperties(_image_info,_images,arg2,_exception);
- if (value == (char *) NULL)
- CLIWandExceptionBreak(OptionWarning,"InterpretPropertyFailure",
- option);
- (void) SetImageOption(_image_info,arg1+7,value);
- value=DestroyString(value);
+ /* FUTURE: make escapes in a global 'option:' delayed */
+ arg2=(char *)NULL;
+ if (IfNormalOp)
+ {
+ arg2=InterpretImageProperties(_image_info,_images,arg2n,_exception);
+ if (arg2 == (char *) NULL)
+ CLIWandExceptionBreak(OptionWarning,
+ "InterpretPropertyFailure",option);
+ }
+ (void) SetImageOption(_image_info,arg1+7,arg2);
+ arg1=DestroyString((char *)arg1);
+ arg2=DestroyString((char *)arg2);
break;
}
- if ( cli_wand->wand.images == (Image *) NULL )
- CLIWandExceptArgBreak(OptionError,"NoImagesFound",option,arg1);
+ /* Set Artifacts/Properties/Attributes all images (required) */
+ if ( _images == (Image *) NULL )
+ CLIWandExceptArgBreak(OptionWarning,"NoImageForProperty",option,arg1);
+
MagickResetIterator(&cli_wand->wand);
while ( IfMagickTrue(MagickNextImage(&cli_wand->wand)) )
{
- Image
- *next;
-
- if (IfPlusOp) {
- if (LocaleNCompare(arg1,"artifact:",9) == 0)
- (void) DeleteImageArtifact(_images,arg1+9);
- else if (LocaleNCompare(arg1,"property:",9) == 0)
- (void) DeleteImageProperty(_images,arg1+9);
- else
- (void) DeleteImageProperty(_images,arg1);
- break;
- }
- next=_images;
- for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
- {
- value=InterpretImageProperties(_image_info,next,arg2,_exception);
- if (value == (char *) NULL)
- CLIWandExceptionBreak(OptionWarning,"InterpretPropertyFailure",
- option);
- if (LocaleNCompare(arg1,"artifact:",9) == 0)
- (void) SetImageArtifact(next,arg1+9,value);
- else
- if (LocaleNCompare(arg1,"property:",9) == 0)
- (void) SetImageProperty(next,arg1+9,value,_exception);
- else
- (void) SetImageProperty(next,arg1,value,_exception);
- value=DestroyString(value);
- }
- break;
+ arg2=(char *)NULL;
+ if (IfNormalOp)
+ {
+ arg2=InterpretImageProperties(_image_info,_images,arg2n,_exception);
+ if (arg2 == (char *) NULL)
+ CLIWandExceptionBreak(OptionWarning,
+ "InterpretPropertyFailure",option);
+ }
+ if (LocaleNCompare(arg1,"artifact:",9) == 0)
+ (void) SetImageArtifact(_images,arg1+9,arg2);
+ else if (LocaleNCompare(arg1,"property:",9) == 0)
+ (void) SetImageProperty(_images,arg1+9,arg2,_exception);
+ else
+ (void) SetImageProperty(_images,arg1,arg2,_exception);
+ arg2=DestroyString((char *)arg2);
}
MagickResetIterator(&cli_wand->wand);
+ arg1=DestroyString((char *)arg1);
break;
}
if (LocaleCompare("clone",option+1) == 0) {
CLIWandException(OptionError,"UnrecognizedOption",option);
+DisableMSCWarning(4127)
} while (0); /* break to exit code. */
+RestoreMSCWarning
-#if 0
/* clean up percent escape interpreted strings */
if (arg1 != arg1n )
arg1=DestroyString((char *)arg1);
if (arg2 != arg2n )
arg2=DestroyString((char *)arg2);
-#endif
#undef _image_info
#undef _images
*/
WandExport void CLIOption(MagickCLI *cli_wand,const char *option,...)
{
- const char
+ const char /* extracted option args from args */
*arg1,
*arg2;
assert(cli_wand != (MagickCLI *) NULL);
assert(cli_wand->signature == WandSignature);
assert(cli_wand->wand.signature == WandSignature);
- if (IfMagickTrue(cli_wand->wand.debug))
- (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name);
do { /* Break Code Block for error handling */
CLIWandExceptionBreak(OptionFatalError,"InvalidUseOfOption",option);
/* Get argument strings from VarArgs
- How can you determine arguments is enough was supplied? */
+ How can you determine if enough arguments was supplied?
+ What happens if not enough arguments were supplied?
+ */
{ size_t
count = cli_wand->command->type;
arg2=(const char *) va_arg(operands, const char *);
va_end(operands);
-
#if 0
(void) FormatLocaleFile(stderr,
"CLIOption: \"%s\" Count: %ld Flags: %04x Args: \"%s\" \"%s\"\n",
((option_type & SettingOptionFlags) == 0 )) /* temp hack */
CLIWandExceptionBreak(OptionError,"NoImagesFound",option);
- /* Operators work on single images, and needs a loop over the images */
- if ( (option_type & SimpleOperatorFlag) != 0)
+ /* Operators which loop of individual images, simply */
+ if ( (option_type & SimpleOperatorFlag) != 0 &&
+ cli_wand->wand.images != (Image *)NULL) /* temp hack */
CLISimpleOperatorImages(cli_wand, option, arg1, arg2);
/* Operators that work on the image list as a whole */
if ( (option_type & ListOperatorFlag) != 0 )
CLIListOperatorImages(cli_wand, option, arg1, arg2);
+DisableMSCWarning(4127)
} while (0); /* end Break code block */
+RestoreMSCWarning
cli_wand->command = (const OptionInfo *) NULL; /* prevent re-use later */
}