blob: 0d3ebe3578d236d08ee52e70dc11266fa297c28b [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy45ef08f2012-12-07 13:13:34 +000020% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
cristyd79e2362013-01-06 23:01:40 +000049#include "MagickWand/mogrify-private.h"
cristye80f9cb2013-01-09 01:09:31 +000050#include "MagickCore/image-private.h"
cristy4c08aed2011-07-01 19:47:50 +000051#include "MagickCore/monitor-private.h"
cristy4c08aed2011-07-01 19:47:50 +000052#include "MagickCore/string-private.h"
cristy0740a982011-10-13 15:01:01 +000053#include "MagickCore/thread-private.h"
cristy18c6c272011-09-23 14:40:37 +000054#include "MagickCore/utility-private.h"
cristy03e83172012-03-25 22:41:06 +000055
cristy3ed852e2009-09-05 21:47:34 +000056/*
cristy154fa9d2011-08-05 14:25:15 +000057 Constant declaration.
58*/
cristy3a557c02011-08-06 19:48:02 +000059static const char
cristy638895a2011-08-06 23:19:14 +000060 MogrifyBackgroundColor[] = "#ffffff", /* white */
61 MogrifyBorderColor[] = "#dfdfdf", /* gray */
62 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000063
64/*
cristy3ed852e2009-09-05 21:47:34 +000065 Define declarations.
66*/
67#define UndefinedCompressionQuality 0UL
68
69/*
cristy3ed852e2009-09-05 21:47:34 +000070%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71% %
72% %
73% %
cristy5063d812010-10-19 16:28:10 +000074% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000075% %
76% %
77% %
78%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79%
80% MagickCommandGenesis() applies image processing options to an image as
81% prescribed by command line options.
82%
83% The format of the MagickCommandGenesis method is:
84%
85% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000086% MagickCommand command,int argc,char **argv,char **metadata,
87% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000088%
89% A description of each parameter follows:
90%
91% o image_info: the image info.
92%
cristy5063d812010-10-19 16:28:10 +000093% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000094% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000095% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
96% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000097%
98% o argc: Specifies a pointer to an integer describing the number of
99% elements in the argument vector.
100%
101% o argv: Specifies a pointer to a text array containing the command line
102% arguments.
103%
cristy5063d812010-10-19 16:28:10 +0000104% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000105%
106% o exception: return any errors or warnings in this structure.
107%
108*/
109WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
110 MagickCommand command,int argc,char **argv,char **metadata,
111 ExceptionInfo *exception)
112{
113 char
114 *option;
115
116 double
117 duration,
cristy8ea926d2011-12-09 12:25:04 +0000118 serial;
cristy3980b0d2009-10-25 14:37:13 +0000119
cristy3980b0d2009-10-25 14:37:13 +0000120 MagickBooleanType
121 concurrent,
122 regard_warnings,
123 status;
124
cristybb503372010-05-27 20:51:26 +0000125 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000126 i;
127
cristybb503372010-05-27 20:51:26 +0000128 size_t
cristyc2e3aeb2011-12-09 11:09:38 +0000129 iterations,
cristyc2e3aeb2011-12-09 11:09:38 +0000130 number_threads;
cristy3980b0d2009-10-25 14:37:13 +0000131
cristy118fc662012-02-11 00:02:25 +0000132 ssize_t
133 n;
134
cristyd0a94fa2010-03-12 14:18:11 +0000135 (void) setlocale(LC_ALL,"");
136 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000137 concurrent=MagickFalse;
138 duration=(-1.0);
139 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000140 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000141 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000142 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000143 {
144 option=argv[i];
145 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
146 continue;
anthony8226e722012-04-05 14:25:46 +0000147 if (LocaleCompare("-bench",option) == 0)
cristye27293e2009-12-18 02:53:20 +0000148 iterations=StringToUnsignedLong(argv[++i]);
anthony8226e722012-04-05 14:25:46 +0000149 if (LocaleCompare("-concurrent",option) == 0)
cristy3980b0d2009-10-25 14:37:13 +0000150 concurrent=MagickTrue;
anthony8226e722012-04-05 14:25:46 +0000151 if (LocaleCompare("-debug",option) == 0)
cristy3980b0d2009-10-25 14:37:13 +0000152 (void) SetLogEventMask(argv[++i]);
cristy93053632013-01-06 23:55:19 +0000153 if (LocaleCompare("-distribute-cache",option) == 0)
cristy8f7950e2013-01-07 14:58:48 +0000154 {
cristye80f9cb2013-01-09 01:09:31 +0000155 PixelCacheServer(StringToUnsignedLong(argv[++i]));
cristy8f7950e2013-01-07 14:58:48 +0000156 exit(0);
157 }
anthony8226e722012-04-05 14:25:46 +0000158 if (LocaleCompare("-duration",option) == 0)
cristydbdd0e32011-11-04 23:29:40 +0000159 duration=StringToDouble(argv[++i],(char **) NULL);
anthony8226e722012-04-05 14:25:46 +0000160 if (LocaleCompare("-regard-warnings",option) == 0)
cristy3980b0d2009-10-25 14:37:13 +0000161 regard_warnings=MagickTrue;
162 }
cristy8ea926d2011-12-09 12:25:04 +0000163 if (iterations == 1)
164 {
165 status=command(image_info,argc,argv,metadata,exception);
166 if (exception->severity != UndefinedException)
167 {
168 if ((exception->severity > ErrorException) ||
169 (regard_warnings != MagickFalse))
170 status=MagickTrue;
171 CatchException(exception);
172 }
173 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
174 {
175 (void) fputs(*metadata,stdout);
176 (void) fputc('\n',stdout);
177 *metadata=DestroyString(*metadata);
178 }
179 return(status);
180 }
cristyfeeb98d2012-05-09 16:32:12 +0000181 number_threads=GetOpenMPMaximumThreads();
cristy8ea926d2011-12-09 12:25:04 +0000182 serial=0.0;
cristy118fc662012-02-11 00:02:25 +0000183 for (n=1; n <= (ssize_t) number_threads; n++)
cristyc2e3aeb2011-12-09 11:09:38 +0000184 {
185 double
cristy8ea926d2011-12-09 12:25:04 +0000186 e,
187 parallel,
cristyc2e3aeb2011-12-09 11:09:38 +0000188 user_time;
189
190 TimerInfo
191 *timer;
192
cristy00f87232012-05-09 13:12:34 +0000193 (void) SetMagickResourceLimit(ThreadResource,(MagickSizeType) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000194 timer=AcquireTimerInfo();
195 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000196 {
cristyc2e3aeb2011-12-09 11:09:38 +0000197 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000198 {
cristyc2e3aeb2011-12-09 11:09:38 +0000199 if (status != MagickFalse)
200 continue;
201 if (duration > 0)
202 {
203 if (GetElapsedTime(timer) > duration)
204 continue;
205 (void) ContinueTimer(timer);
206 }
207 status=command(image_info,argc,argv,metadata,exception);
cristyceae09d2009-10-28 17:18:47 +0000208 if (exception->severity != UndefinedException)
209 {
210 if ((exception->severity > ErrorException) ||
211 (regard_warnings != MagickFalse))
212 status=MagickTrue;
213 CatchException(exception);
214 }
215 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
216 {
217 (void) fputs(*metadata,stdout);
218 (void) fputc('\n',stdout);
219 *metadata=DestroyString(*metadata);
220 }
221 }
222 }
cristyc2e3aeb2011-12-09 11:09:38 +0000223 else
224 {
225 SetOpenMPNested(1);
226#if defined(MAGICKCORE_OPENMP_SUPPORT)
227 # pragma omp parallel for shared(status)
228#endif
229 for (i=0; i < (ssize_t) iterations; i++)
230 {
231 if (status != MagickFalse)
232 continue;
233 if (duration > 0)
234 {
235 if (GetElapsedTime(timer) > duration)
236 continue;
237 (void) ContinueTimer(timer);
238 }
239 status=command(image_info,argc,argv,metadata,exception);
240#if defined(MAGICKCORE_OPENMP_SUPPORT)
241 # pragma omp critical (MagickCore_CommandGenesis)
242#endif
243 {
244 if (exception->severity != UndefinedException)
245 {
246 if ((exception->severity > ErrorException) ||
247 (regard_warnings != MagickFalse))
248 status=MagickTrue;
249 CatchException(exception);
250 }
251 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
252 {
253 (void) fputs(*metadata,stdout);
254 (void) fputc('\n',stdout);
255 *metadata=DestroyString(*metadata);
256 }
257 }
258 }
259 }
cristyc2e3aeb2011-12-09 11:09:38 +0000260 user_time=GetUserTime(timer);
cristy8ea926d2011-12-09 12:25:04 +0000261 parallel=GetElapsedTime(timer);
262 e=1.0;
263 if (n == 1)
264 serial=parallel;
265 else
266 e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
267 (double) n)))-(1.0/(double) n))/(1.0-1.0/(double) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000268 (void) FormatLocaleFile(stderr,
cristy91ce84d2011-12-09 23:02:25 +0000269 "Performance[%.20g]: %.20gi %0.3fips %0.3fe %0.3fu %lu:%02lu.%03lu\n",
cristy8ea926d2011-12-09 12:25:04 +0000270 (double) n,(double) iterations,(double) iterations/parallel,e,
271 user_time,(unsigned long) (parallel/60.0),(unsigned long)
272 floor(fmod(parallel,60.0)),(unsigned long)
273 (1000.0*(parallel-floor(parallel))+0.5));
cristyc2e3aeb2011-12-09 11:09:38 +0000274 timer=DestroyTimerInfo(timer);
275 }
cristy1f9e1ed2009-11-18 04:09:38 +0000276 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000277}
278
279/*
280%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281% %
282% %
283% %
cristy3ed852e2009-09-05 21:47:34 +0000284+ M o g r i f y I m a g e %
285% %
286% %
287% %
288%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289%
anthonye9c27192011-03-27 08:07:06 +0000290% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000291% image that may be part of a large list, but also handles any 'region'
292% image handling.
anthonye9c27192011-03-27 08:07:06 +0000293%
294% The image in the list may be modified in three different ways...
295%
296% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
297% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
298% * replace by a list of images (only the -separate option!)
299%
300% In each case the result is returned into the list, and a pointer to the
301% modified image (last image added if replaced by a list of images) is
302% returned.
303%
304% ASIDE: The -crop is present but restricted to non-tile single image crops
305%
306% This means if all the images are being processed (such as by
307% MogrifyImages(), next image to be processed will be as per the pointer
308% (*image)->next. Also the image list may grow as a result of some specific
309% operations but as images are never merged or deleted, it will never shrink
310% in length. Typically the list will remain the same length.
311%
312% WARNING: As the image pointed to may be replaced, the first image in the
313% list may also change. GetFirstImageInList() should be used by caller if
314% they wish return the Image pointer to the first image in list.
315%
cristy3ed852e2009-09-05 21:47:34 +0000316%
317% The format of the MogrifyImage method is:
318%
319% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
320% const char **argv,Image **image)
321%
322% A description of each parameter follows:
323%
324% o image_info: the image info..
325%
326% o argc: Specifies a pointer to an integer describing the number of
327% elements in the argument vector.
328%
329% o argv: Specifies a pointer to a text array containing the command line
330% arguments.
331%
332% o image: the image.
333%
334% o exception: return any errors or warnings in this structure.
335%
336*/
337
anthonydf8ebac2011-04-27 09:03:19 +0000338static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
339 ExceptionInfo *exception)
340{
341 char
342 key[MaxTextExtent];
343
344 ExceptionInfo
345 *sans_exception;
346
347 Image
348 *image;
349
350 ImageInfo
351 *read_info;
352
cristyfcd785b2011-11-08 01:48:33 +0000353 /*
anthony32d85bf2012-02-15 14:54:59 +0000354 Read an image into a image cache (for repeated usage) if not already in
355 cache. Then return the image that is in the cache.
cristyfcd785b2011-11-08 01:48:33 +0000356 */
cristyb51dff52011-05-19 16:55:47 +0000357 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000358 sans_exception=AcquireExceptionInfo();
359 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
360 sans_exception=DestroyExceptionInfo(sans_exception);
361 if (image != (Image *) NULL)
362 return(image);
363 read_info=CloneImageInfo(image_info);
364 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
365 image=ReadImage(read_info,exception);
366 read_info=DestroyImageInfo(read_info);
367 if (image != (Image *) NULL)
368 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
369 return(image);
370}
371
cristyba3c5702012-06-27 13:30:13 +0000372static inline MagickBooleanType IsPathWritable(const char *path)
cristy3ed852e2009-09-05 21:47:34 +0000373{
374 if (IsPathAccessible(path) == MagickFalse)
375 return(MagickFalse);
cristy18c6c272011-09-23 14:40:37 +0000376 if (access_utf8(path,W_OK) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000377 return(MagickFalse);
378 return(MagickTrue);
379}
380
cristybb503372010-05-27 20:51:26 +0000381static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000382{
383 if (x > y)
384 return(x);
385 return(y);
386}
387
anthonydf8ebac2011-04-27 09:03:19 +0000388static MagickBooleanType MonitorProgress(const char *text,
389 const MagickOffsetType offset,const MagickSizeType extent,
390 void *wand_unused(client_data))
391{
392 char
393 message[MaxTextExtent],
394 tag[MaxTextExtent];
395
396 const char
397 *locale_message;
398
399 register char
400 *p;
401
402 if (extent < 2)
403 return(MagickTrue);
404 (void) CopyMagickMemory(tag,text,MaxTextExtent);
405 p=strrchr(tag,'/');
406 if (p != (char *) NULL)
407 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000408 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000409 locale_message=GetLocaleMessage(message);
410 if (locale_message == message)
411 locale_message=tag;
412 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000413 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
414 locale_message,(long) offset,(unsigned long) extent,(long)
415 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000416 else
cristyb51dff52011-05-19 16:55:47 +0000417 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000418 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
419 (100L*offset/(extent-1)));
420 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000421 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000422 (void) fflush(stderr);
423 return(MagickTrue);
424}
425
cristy3884f692011-07-08 18:00:18 +0000426static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000427 const SparseColorMethod method,const char *arguments,
428 const MagickBooleanType color_from_image,ExceptionInfo *exception)
429{
anthonydf8ebac2011-04-27 09:03:19 +0000430 char
431 token[MaxTextExtent];
432
433 const char
434 *p;
435
436 double
437 *sparse_arguments;
438
anthonydf8ebac2011-04-27 09:03:19 +0000439 Image
440 *sparse_image;
441
cristy4c08aed2011-07-01 19:47:50 +0000442 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000443 color;
444
445 MagickBooleanType
446 error;
447
cristy5f09d852011-05-29 01:39:29 +0000448 register size_t
449 x;
450
451 size_t
452 number_arguments,
453 number_colors;
454
cristyf4425a72011-11-08 01:52:04 +0000455 /*
456 SparseColorOption() parses the complex -sparse-color argument into an an
457 array of floating point values then calls SparseColorImage(). Argument is
458 a complex mix of floating-point pixel coodinates, and color specifications
459 (or direct floating point numbers). The number of floats needed to
460 represent a color varies depending on the current channel setting.
461 */
anthonydf8ebac2011-04-27 09:03:19 +0000462 assert(image != (Image *) NULL);
463 assert(image->signature == MagickSignature);
464 if (image->debug != MagickFalse)
465 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
466 assert(exception != (ExceptionInfo *) NULL);
467 assert(exception->signature == MagickSignature);
468 /*
469 Limit channels according to image - and add up number of color channel.
470 */
anthonydf8ebac2011-04-27 09:03:19 +0000471 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000472 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000473 number_colors++;
cristyed231572011-07-14 02:18:59 +0000474 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000475 number_colors++;
cristyed231572011-07-14 02:18:59 +0000476 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000477 number_colors++;
cristyed231572011-07-14 02:18:59 +0000478 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000479 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000480 number_colors++;
cristyed231572011-07-14 02:18:59 +0000481 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy8a46d822012-08-28 23:32:39 +0000482 (image->alpha_trait == BlendPixelTrait))
anthonydf8ebac2011-04-27 09:03:19 +0000483 number_colors++;
484
485 /*
486 Read string, to determine number of arguments needed,
487 */
488 p=arguments;
489 x=0;
490 while( *p != '\0' )
491 {
492 GetMagickToken(p,&p,token);
493 if ( token[0] == ',' ) continue;
494 if ( isalpha((int) token[0]) || token[0] == '#' ) {
495 if ( color_from_image ) {
496 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +0000497 OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
anthonydf8ebac2011-04-27 09:03:19 +0000498 "Color arg given, when colors are coming from image");
499 return( (Image *)NULL);
500 }
501 x += number_colors; /* color argument */
502 }
503 else {
504 x++; /* floating point argument */
505 }
506 }
507 error=MagickTrue;
508 if ( color_from_image ) {
509 /* just the control points are being given */
510 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
511 number_arguments=(x/2)*(2+number_colors);
512 }
513 else {
514 /* control points and color values */
515 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
516 number_arguments=x;
517 }
518 if ( error ) {
519 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +0000520 OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
anthonydf8ebac2011-04-27 09:03:19 +0000521 "Invalid number of Arguments");
522 return( (Image *)NULL);
523 }
524
525 /* Allocate and fill in the floating point arguments */
526 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
527 sizeof(*sparse_arguments));
528 if (sparse_arguments == (double *) NULL) {
529 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
530 "MemoryAllocationFailed","%s","SparseColorOption");
531 return( (Image *)NULL);
532 }
533 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
534 sizeof(*sparse_arguments));
535 p=arguments;
536 x=0;
537 while( *p != '\0' && x < number_arguments ) {
538 /* X coordinate */
539 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
540 if ( token[0] == '\0' ) break;
541 if ( isalpha((int) token[0]) || token[0] == '#' ) {
542 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +0000543 OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
anthonydf8ebac2011-04-27 09:03:19 +0000544 "Color found, instead of X-coord");
545 error = MagickTrue;
546 break;
547 }
cristydbdd0e32011-11-04 23:29:40 +0000548 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000549 /* Y coordinate */
550 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
551 if ( token[0] == '\0' ) break;
552 if ( isalpha((int) token[0]) || token[0] == '#' ) {
553 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +0000554 OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
anthonydf8ebac2011-04-27 09:03:19 +0000555 "Color found, instead of Y-coord");
556 error = MagickTrue;
557 break;
558 }
cristydbdd0e32011-11-04 23:29:40 +0000559 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000560 /* color values for this control point */
561#if 0
562 if ( (color_from_image ) {
563 /* get color from image */
564 /* HOW??? */
565 }
566 else
567#endif
568 {
569 /* color name or function given in string argument */
570 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
571 if ( token[0] == '\0' ) break;
572 if ( isalpha((int) token[0]) || token[0] == '#' ) {
573 /* Color string given */
cristy269c9412011-10-13 23:41:15 +0000574 (void) QueryColorCompliance(token,AllCompliance,&color,exception);
cristyed231572011-07-14 02:18:59 +0000575 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000576 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000577 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000578 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000579 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000580 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000581 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000582 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000583 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000584 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy8a46d822012-08-28 23:32:39 +0000585 (image->alpha_trait == BlendPixelTrait))
cristy4c08aed2011-07-01 19:47:50 +0000586 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000587 }
588 else {
589 /* Colors given as a set of floating point values - experimental */
590 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000591 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000592 {
anthonydf8ebac2011-04-27 09:03:19 +0000593 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
594 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
595 break;
cristydbdd0e32011-11-04 23:29:40 +0000596 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000597 token[0] = ','; /* used this token - get another */
598 }
cristyed231572011-07-14 02:18:59 +0000599 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000600 {
anthonydf8ebac2011-04-27 09:03:19 +0000601 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
602 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
603 break;
cristydbdd0e32011-11-04 23:29:40 +0000604 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000605 token[0] = ','; /* used this token - get another */
606 }
cristyed231572011-07-14 02:18:59 +0000607 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000608 {
anthonydf8ebac2011-04-27 09:03:19 +0000609 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
610 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
611 break;
cristydbdd0e32011-11-04 23:29:40 +0000612 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000613 token[0] = ','; /* used this token - get another */
614 }
cristyed231572011-07-14 02:18:59 +0000615 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000616 (image->colorspace == CMYKColorspace))
617 {
anthonydf8ebac2011-04-27 09:03:19 +0000618 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
619 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
620 break;
cristydbdd0e32011-11-04 23:29:40 +0000621 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000622 token[0] = ','; /* used this token - get another */
623 }
cristyed231572011-07-14 02:18:59 +0000624 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy8a46d822012-08-28 23:32:39 +0000625 (image->alpha_trait == BlendPixelTrait))
cristy3884f692011-07-08 18:00:18 +0000626 {
anthonydf8ebac2011-04-27 09:03:19 +0000627 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
628 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
629 break;
cristydbdd0e32011-11-04 23:29:40 +0000630 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000631 token[0] = ','; /* used this token - get another */
632 }
633 }
634 }
635 }
636 if ( number_arguments != x && !error ) {
637 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
anthonye5b39652012-04-21 05:37:29 +0000638 "InvalidArgument","'%s': %s","sparse-color","Argument Parsing Error");
anthonydf8ebac2011-04-27 09:03:19 +0000639 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
640 return( (Image *)NULL);
641 }
642 if ( error )
643 return( (Image *)NULL);
644
645 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000646 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
647 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000648 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
649 return( sparse_image );
650}
651
cristy3ed852e2009-09-05 21:47:34 +0000652WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
653 const char **argv,Image **image,ExceptionInfo *exception)
654{
cristy633f0c62011-09-15 13:27:36 +0000655 CompositeOperator
656 compose;
657
anthonydf8ebac2011-04-27 09:03:19 +0000658 const char
659 *format,
660 *option;
661
cristy9ed1f812011-10-08 02:00:08 +0000662 double
663 attenuate;
664
anthonydf8ebac2011-04-27 09:03:19 +0000665 DrawInfo
666 *draw_info;
667
668 GeometryInfo
669 geometry_info;
670
cristy3ed852e2009-09-05 21:47:34 +0000671 Image
672 *region_image;
673
anthonydf8ebac2011-04-27 09:03:19 +0000674 ImageInfo
675 *mogrify_info;
676
cristyebbcfea2011-02-25 02:43:54 +0000677 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000678 status;
679
cristy4c08aed2011-07-01 19:47:50 +0000680 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000681 fill;
cristy3ed852e2009-09-05 21:47:34 +0000682
anthonydf8ebac2011-04-27 09:03:19 +0000683 MagickStatusType
684 flags;
685
cristy28474bf2011-09-11 23:32:52 +0000686 PixelInterpolateMethod
687 interpolate_method;
688
anthonydf8ebac2011-04-27 09:03:19 +0000689 QuantizeInfo
690 *quantize_info;
691
692 RectangleInfo
693 geometry,
694 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000695
cristybb503372010-05-27 20:51:26 +0000696 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000697 i;
698
699 /*
700 Initialize method variables.
701 */
702 assert(image_info != (const ImageInfo *) NULL);
703 assert(image_info->signature == MagickSignature);
704 assert(image != (Image **) NULL);
705 assert((*image)->signature == MagickSignature);
706 if ((*image)->debug != MagickFalse)
707 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
708 if (argc < 0)
709 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000710 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000711 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
712 quantize_info=AcquireQuantizeInfo(mogrify_info);
713 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000714 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000715 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000716 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000717 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000718 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000719 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000720 SetGeometry(*image,&region_geometry);
721 region_image=NewImageList();
722 /*
723 Transmogrify the image.
724 */
cristybb503372010-05-27 20:51:26 +0000725 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000726 {
anthonydf8ebac2011-04-27 09:03:19 +0000727 Image
728 *mogrify_image;
729
anthonye9c27192011-03-27 08:07:06 +0000730 ssize_t
731 count;
732
anthonydf8ebac2011-04-27 09:03:19 +0000733 option=argv[i];
734 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000735 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000736 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
737 0L);
cristycee97112010-05-28 00:44:52 +0000738 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000739 break;
cristy6b3da3a2010-06-20 02:21:46 +0000740 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000741 mogrify_image=(Image *)NULL;
742 switch (*(option+1))
743 {
744 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000745 {
anthonydf8ebac2011-04-27 09:03:19 +0000746 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000747 {
anthonydf8ebac2011-04-27 09:03:19 +0000748 /*
749 Adaptive blur image.
750 */
cristy6fccee12011-10-20 18:43:18 +0000751 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000752 flags=ParseGeometry(argv[i+1],&geometry_info);
753 if ((flags & SigmaValue) == 0)
754 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000755 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +0000756 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000757 break;
cristy3ed852e2009-09-05 21:47:34 +0000758 }
anthonydf8ebac2011-04-27 09:03:19 +0000759 if (LocaleCompare("adaptive-resize",option+1) == 0)
760 {
761 /*
762 Adaptive resize image.
763 */
cristy6fccee12011-10-20 18:43:18 +0000764 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000765 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
766 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
anthonyfd706f92012-01-19 04:22:02 +0000767 geometry.height,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000768 break;
769 }
770 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
771 {
772 /*
773 Adaptive sharpen image.
774 */
cristy6fccee12011-10-20 18:43:18 +0000775 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000776 flags=ParseGeometry(argv[i+1],&geometry_info);
777 if ((flags & SigmaValue) == 0)
778 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000779 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +0000780 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000781 break;
782 }
783 if (LocaleCompare("affine",option+1) == 0)
784 {
785 /*
786 Affine matrix.
787 */
788 if (*option == '+')
789 {
790 GetAffineMatrix(&draw_info->affine);
791 break;
792 }
793 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
794 break;
795 }
796 if (LocaleCompare("alpha",option+1) == 0)
797 {
cristyb15b06c2012-08-28 11:36:48 +0000798 AlphaChannelOption
anthonydf8ebac2011-04-27 09:03:19 +0000799 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000800
cristy6fccee12011-10-20 18:43:18 +0000801 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy8cdfb342012-11-11 21:44:36 +0000802 alpha_type=(AlphaChannelOption) ParseCommandOption(
803 MagickAlphaChannelOptions,MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000804 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000805 break;
806 }
807 if (LocaleCompare("annotate",option+1) == 0)
808 {
809 char
810 *text,
811 geometry[MaxTextExtent];
812
813 /*
814 Annotate image.
815 */
cristy6fccee12011-10-20 18:43:18 +0000816 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000817 SetGeometryInfo(&geometry_info);
818 flags=ParseGeometry(argv[i+1],&geometry_info);
819 if ((flags & SigmaValue) == 0)
820 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000821 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
822 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000823 if (text == (char *) NULL)
824 break;
825 (void) CloneString(&draw_info->text,text);
826 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000827 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000828 geometry_info.xi,geometry_info.psi);
829 (void) CloneString(&draw_info->geometry,geometry);
830 draw_info->affine.sx=cos(DegreesToRadians(
831 fmod(geometry_info.rho,360.0)));
832 draw_info->affine.rx=sin(DegreesToRadians(
833 fmod(geometry_info.rho,360.0)));
834 draw_info->affine.ry=(-sin(DegreesToRadians(
835 fmod(geometry_info.sigma,360.0))));
836 draw_info->affine.sy=cos(DegreesToRadians(
837 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000838 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000839 break;
840 }
841 if (LocaleCompare("antialias",option+1) == 0)
842 {
843 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
844 MagickFalse;
845 draw_info->text_antialias=(*option == '-') ? MagickTrue :
846 MagickFalse;
847 break;
848 }
cristy9ed1f812011-10-08 02:00:08 +0000849 if (LocaleCompare("attenuate",option+1) == 0)
850 {
851 if (*option == '+')
852 {
853 attenuate=1.0;
854 break;
855 }
cristydbdd0e32011-11-04 23:29:40 +0000856 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000857 break;
858 }
anthonydf8ebac2011-04-27 09:03:19 +0000859 if (LocaleCompare("auto-gamma",option+1) == 0)
860 {
861 /*
862 Auto Adjust Gamma of image based on its mean
863 */
cristy6fccee12011-10-20 18:43:18 +0000864 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000865 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000866 break;
867 }
868 if (LocaleCompare("auto-level",option+1) == 0)
869 {
870 /*
871 Perfectly Normalize (max/min stretch) the image
872 */
cristy6fccee12011-10-20 18:43:18 +0000873 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000874 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000875 break;
876 }
877 if (LocaleCompare("auto-orient",option+1) == 0)
878 {
cristy6fccee12011-10-20 18:43:18 +0000879 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyfa5f6c72013-01-01 14:37:35 +0000880 mogrify_image=AutoOrientImage(*image,(*image)->orientation,
881 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000882 break;
883 }
884 break;
885 }
886 case 'b':
887 {
888 if (LocaleCompare("black-threshold",option+1) == 0)
889 {
890 /*
891 Black threshold image.
892 */
cristy6fccee12011-10-20 18:43:18 +0000893 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000894 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000895 break;
896 }
897 if (LocaleCompare("blue-shift",option+1) == 0)
898 {
899 /*
900 Blue shift image.
901 */
cristy6fccee12011-10-20 18:43:18 +0000902 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000903 geometry_info.rho=1.5;
904 if (*option == '-')
905 flags=ParseGeometry(argv[i+1],&geometry_info);
906 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
907 break;
908 }
909 if (LocaleCompare("blur",option+1) == 0)
910 {
911 /*
912 Gaussian blur image.
913 */
cristy6fccee12011-10-20 18:43:18 +0000914 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000915 flags=ParseGeometry(argv[i+1],&geometry_info);
916 if ((flags & SigmaValue) == 0)
917 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000918 if ((flags & XiValue) == 0)
919 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000920 mogrify_image=BlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +0000921 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000922 break;
923 }
924 if (LocaleCompare("border",option+1) == 0)
925 {
926 /*
927 Surround image with a border of solid color.
928 */
cristy6fccee12011-10-20 18:43:18 +0000929 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000930 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy633f0c62011-09-15 13:27:36 +0000931 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000932 break;
933 }
934 if (LocaleCompare("bordercolor",option+1) == 0)
935 {
936 if (*option == '+')
937 {
cristy9950d572011-10-01 18:22:35 +0000938 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000939 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000940 break;
941 }
cristy9950d572011-10-01 18:22:35 +0000942 (void) QueryColorCompliance(argv[i+1],AllCompliance,
943 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000944 break;
945 }
946 if (LocaleCompare("box",option+1) == 0)
947 {
cristy9950d572011-10-01 18:22:35 +0000948 (void) QueryColorCompliance(argv[i+1],AllCompliance,
949 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000950 break;
951 }
952 if (LocaleCompare("brightness-contrast",option+1) == 0)
953 {
954 double
955 brightness,
956 contrast;
957
958 GeometryInfo
959 geometry_info;
960
961 MagickStatusType
962 flags;
963
964 /*
965 Brightness / contrast image.
966 */
cristy6fccee12011-10-20 18:43:18 +0000967 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000968 flags=ParseGeometry(argv[i+1],&geometry_info);
969 brightness=geometry_info.rho;
970 contrast=0.0;
971 if ((flags & SigmaValue) != 0)
972 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000973 (void) BrightnessContrastImage(*image,brightness,contrast,
974 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000975 break;
976 }
977 break;
978 }
979 case 'c':
980 {
981 if (LocaleCompare("cdl",option+1) == 0)
982 {
983 char
984 *color_correction_collection;
985
986 /*
987 Color correct with a color decision list.
988 */
cristy6fccee12011-10-20 18:43:18 +0000989 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000990 color_correction_collection=FileToString(argv[i+1],~0,exception);
991 if (color_correction_collection == (char *) NULL)
992 break;
cristy1bfa9f02011-08-11 02:35:43 +0000993 (void) ColorDecisionListImage(*image,color_correction_collection,
994 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000995 break;
996 }
anthonydf8ebac2011-04-27 09:03:19 +0000997 if (LocaleCompare("charcoal",option+1) == 0)
998 {
999 /*
1000 Charcoal image.
1001 */
cristy6fccee12011-10-20 18:43:18 +00001002 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001003 flags=ParseGeometry(argv[i+1],&geometry_info);
1004 if ((flags & SigmaValue) == 0)
1005 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001006 if ((flags & XiValue) == 0)
1007 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001008 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00001009 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001010 break;
1011 }
1012 if (LocaleCompare("chop",option+1) == 0)
1013 {
1014 /*
1015 Chop the image.
1016 */
cristy6fccee12011-10-20 18:43:18 +00001017 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001018 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1019 mogrify_image=ChopImage(*image,&geometry,exception);
1020 break;
1021 }
cristy7884a932012-11-04 14:33:51 +00001022 if (LocaleCompare("perceptible",option+1) == 0)
anthonydf8ebac2011-04-27 09:03:19 +00001023 {
1024 /*
cristy7884a932012-11-04 14:33:51 +00001025 Perceptible image.
anthonydf8ebac2011-04-27 09:03:19 +00001026 */
cristy6fccee12011-10-20 18:43:18 +00001027 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy7884a932012-11-04 14:33:51 +00001028 (void) PerceptibleImage(*image,StringToDouble(argv[i+1],
1029 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001030 break;
1031 }
1032 if (LocaleCompare("clip",option+1) == 0)
1033 {
cristy6fccee12011-10-20 18:43:18 +00001034 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001035 if (*option == '+')
1036 {
cristy10a6c612012-01-29 21:41:05 +00001037 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001038 break;
1039 }
cristy018f07f2011-09-04 21:15:19 +00001040 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001041 break;
1042 }
1043 if (LocaleCompare("clip-mask",option+1) == 0)
1044 {
1045 CacheView
1046 *mask_view;
1047
1048 Image
1049 *mask_image;
1050
cristy4c08aed2011-07-01 19:47:50 +00001051 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001052 *restrict q;
1053
1054 register ssize_t
1055 x;
1056
1057 ssize_t
1058 y;
1059
cristy6fccee12011-10-20 18:43:18 +00001060 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001061 if (*option == '+')
1062 {
1063 /*
1064 Remove a mask.
1065 */
cristy018f07f2011-09-04 21:15:19 +00001066 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001067 break;
1068 }
1069 /*
1070 Set the image mask.
1071 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1072 */
1073 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1074 if (mask_image == (Image *) NULL)
1075 break;
cristy574cc262011-08-05 01:23:58 +00001076 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001077 return(MagickFalse);
cristy46ff2672012-12-14 15:32:26 +00001078 mask_view=AcquireAuthenticCacheView(mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001079 for (y=0; y < (ssize_t) mask_image->rows; y++)
1080 {
1081 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1082 exception);
cristyacd2ed22011-08-30 01:44:23 +00001083 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001084 break;
1085 for (x=0; x < (ssize_t) mask_image->columns; x++)
1086 {
cristy8a46d822012-08-28 23:32:39 +00001087 if (mask_image->alpha_trait != BlendPixelTrait)
cristy4c08aed2011-07-01 19:47:50 +00001088 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1089 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1090 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1091 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001092 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001093 }
1094 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1095 break;
1096 }
1097 mask_view=DestroyCacheView(mask_view);
cristy8a46d822012-08-28 23:32:39 +00001098 mask_image->alpha_trait=BlendPixelTrait;
cristy10a6c612012-01-29 21:41:05 +00001099 (void) SetImageMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001100 break;
1101 }
1102 if (LocaleCompare("clip-path",option+1) == 0)
1103 {
cristy6fccee12011-10-20 18:43:18 +00001104 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001105 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001106 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001107 break;
1108 }
1109 if (LocaleCompare("colorize",option+1) == 0)
1110 {
1111 /*
1112 Colorize the image.
1113 */
cristy6fccee12011-10-20 18:43:18 +00001114 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001115 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001116 break;
1117 }
1118 if (LocaleCompare("color-matrix",option+1) == 0)
1119 {
1120 KernelInfo
1121 *kernel;
1122
cristy6fccee12011-10-20 18:43:18 +00001123 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001124 kernel=AcquireKernelInfo(argv[i+1]);
1125 if (kernel == (KernelInfo *) NULL)
1126 break;
anthonyfd706f92012-01-19 04:22:02 +00001127 /* FUTURE: check on size of the matrix */
anthonydf8ebac2011-04-27 09:03:19 +00001128 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1129 kernel=DestroyKernelInfo(kernel);
1130 break;
1131 }
1132 if (LocaleCompare("colors",option+1) == 0)
1133 {
1134 /*
1135 Reduce the number of colors in the image.
1136 */
cristy6fccee12011-10-20 18:43:18 +00001137 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001138 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1139 if (quantize_info->number_colors == 0)
1140 break;
1141 if (((*image)->storage_class == DirectClass) ||
1142 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001143 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001144 else
cristy018f07f2011-09-04 21:15:19 +00001145 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001146 break;
1147 }
1148 if (LocaleCompare("colorspace",option+1) == 0)
1149 {
1150 ColorspaceType
1151 colorspace;
1152
cristy6fccee12011-10-20 18:43:18 +00001153 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001154 if (*option == '+')
1155 {
cristyc511e882012-04-16 21:11:14 +00001156 (void) TransformImageColorspace(*image,sRGBColorspace,
1157 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001158 break;
1159 }
1160 colorspace=(ColorspaceType) ParseCommandOption(
1161 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001162 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001163 break;
1164 }
cristy633f0c62011-09-15 13:27:36 +00001165 if (LocaleCompare("compose",option+1) == 0)
1166 {
cristy6fccee12011-10-20 18:43:18 +00001167 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001168 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1169 MagickFalse,argv[i+1]);
1170 break;
1171 }
anthonydf8ebac2011-04-27 09:03:19 +00001172 if (LocaleCompare("contrast",option+1) == 0)
1173 {
cristy6fccee12011-10-20 18:43:18 +00001174 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001175 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001176 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001177 break;
1178 }
1179 if (LocaleCompare("contrast-stretch",option+1) == 0)
1180 {
1181 double
1182 black_point,
1183 white_point;
1184
1185 MagickStatusType
1186 flags;
1187
1188 /*
1189 Contrast stretch image.
1190 */
cristy6fccee12011-10-20 18:43:18 +00001191 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001192 flags=ParseGeometry(argv[i+1],&geometry_info);
1193 black_point=geometry_info.rho;
1194 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1195 black_point;
1196 if ((flags & PercentValue) != 0)
1197 {
1198 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1199 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1200 }
cristya19f1d72012-08-07 18:24:38 +00001201 white_point=(double) (*image)->columns*(*image)->rows-
anthonydf8ebac2011-04-27 09:03:19 +00001202 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001203 (void) ContrastStretchImage(*image,black_point,white_point,
1204 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001205 break;
1206 }
1207 if (LocaleCompare("convolve",option+1) == 0)
1208 {
anthonydf8ebac2011-04-27 09:03:19 +00001209 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001210 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001211
cristy6fccee12011-10-20 18:43:18 +00001212 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001213 kernel_info=AcquireKernelInfo(argv[i+1]);
1214 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001215 break;
anthonyf46d4262012-03-26 03:30:34 +00001216 /* kernel_info->bias=(*image)->bias; -- FUTURE: check this path! */
cristya12d8ba2012-04-29 16:33:41 +00001217 mogrify_image=MorphologyImage(*image,CorrelateMorphology,1,
1218 kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001219 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001220 break;
1221 }
1222 if (LocaleCompare("crop",option+1) == 0)
1223 {
1224 /*
1225 Crop a image to a smaller size
1226 */
cristy6fccee12011-10-20 18:43:18 +00001227 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001228 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001229 break;
1230 }
1231 if (LocaleCompare("cycle",option+1) == 0)
1232 {
1233 /*
1234 Cycle an image colormap.
1235 */
cristy6fccee12011-10-20 18:43:18 +00001236 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001237 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1238 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001239 break;
1240 }
1241 break;
1242 }
1243 case 'd':
1244 {
1245 if (LocaleCompare("decipher",option+1) == 0)
1246 {
1247 StringInfo
1248 *passkey;
1249
1250 /*
1251 Decipher pixels.
1252 */
cristy6fccee12011-10-20 18:43:18 +00001253 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001254 passkey=FileToStringInfo(argv[i+1],~0,exception);
1255 if (passkey != (StringInfo *) NULL)
1256 {
1257 (void) PasskeyDecipherImage(*image,passkey,exception);
1258 passkey=DestroyStringInfo(passkey);
1259 }
1260 break;
1261 }
1262 if (LocaleCompare("density",option+1) == 0)
1263 {
1264 /*
1265 Set image density.
1266 */
1267 (void) CloneString(&draw_info->density,argv[i+1]);
1268 break;
1269 }
1270 if (LocaleCompare("depth",option+1) == 0)
1271 {
cristy6fccee12011-10-20 18:43:18 +00001272 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001273 if (*option == '+')
1274 {
cristy8a11cb12011-10-19 23:53:34 +00001275 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001276 break;
1277 }
cristy8a11cb12011-10-19 23:53:34 +00001278 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1279 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001280 break;
1281 }
1282 if (LocaleCompare("deskew",option+1) == 0)
1283 {
1284 double
1285 threshold;
1286
1287 /*
1288 Straighten the image.
1289 */
cristy6fccee12011-10-20 18:43:18 +00001290 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001291 if (*option == '+')
1292 threshold=40.0*QuantumRange/100.0;
1293 else
cristy9b34e302011-11-05 02:15:45 +00001294 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1295 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001296 mogrify_image=DeskewImage(*image,threshold,exception);
1297 break;
1298 }
1299 if (LocaleCompare("despeckle",option+1) == 0)
1300 {
1301 /*
1302 Reduce the speckles within an image.
1303 */
cristy6fccee12011-10-20 18:43:18 +00001304 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001305 mogrify_image=DespeckleImage(*image,exception);
1306 break;
1307 }
1308 if (LocaleCompare("display",option+1) == 0)
1309 {
1310 (void) CloneString(&draw_info->server_name,argv[i+1]);
1311 break;
1312 }
1313 if (LocaleCompare("distort",option+1) == 0)
1314 {
1315 char
1316 *args,
1317 token[MaxTextExtent];
1318
1319 const char
1320 *p;
1321
1322 DistortImageMethod
1323 method;
1324
1325 double
1326 *arguments;
1327
1328 register ssize_t
1329 x;
1330
1331 size_t
1332 number_arguments;
1333
1334 /*
1335 Distort image.
1336 */
cristy6fccee12011-10-20 18:43:18 +00001337 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001338 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1339 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001340 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001341 {
anthonydf8ebac2011-04-27 09:03:19 +00001342 double
1343 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001344
1345 /*
1346 Special Case - Argument is actually a resize geometry!
1347 Convert that to an appropriate distortion argument array.
1348 */
anthonydf8ebac2011-04-27 09:03:19 +00001349 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001350 exception);
1351 resize_args[0]=(double) geometry.width;
1352 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001353 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001354 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001355 break;
1356 }
cristy018f07f2011-09-04 21:15:19 +00001357 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1358 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001359 if (args == (char *) NULL)
1360 break;
1361 p=(char *) args;
1362 for (x=0; *p != '\0'; x++)
1363 {
1364 GetMagickToken(p,&p,token);
1365 if (*token == ',')
1366 GetMagickToken(p,&p,token);
1367 }
1368 number_arguments=(size_t) x;
1369 arguments=(double *) AcquireQuantumMemory(number_arguments,
1370 sizeof(*arguments));
1371 if (arguments == (double *) NULL)
1372 ThrowWandFatalException(ResourceLimitFatalError,
1373 "MemoryAllocationFailed",(*image)->filename);
1374 (void) ResetMagickMemory(arguments,0,number_arguments*
1375 sizeof(*arguments));
1376 p=(char *) args;
1377 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1378 {
1379 GetMagickToken(p,&p,token);
1380 if (*token == ',')
1381 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001382 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001383 }
1384 args=DestroyString(args);
1385 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1386 (*option == '+') ? MagickTrue : MagickFalse,exception);
1387 arguments=(double *) RelinquishMagickMemory(arguments);
1388 break;
1389 }
1390 if (LocaleCompare("dither",option+1) == 0)
1391 {
1392 if (*option == '+')
1393 {
cristycbda6112012-05-27 20:57:16 +00001394 quantize_info->dither_method=NoDitherMethod;
anthonydf8ebac2011-04-27 09:03:19 +00001395 break;
1396 }
anthonydf8ebac2011-04-27 09:03:19 +00001397 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1398 MagickDitherOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001399 break;
1400 }
1401 if (LocaleCompare("draw",option+1) == 0)
1402 {
1403 /*
1404 Draw image.
1405 */
cristy6fccee12011-10-20 18:43:18 +00001406 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001407 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001408 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001409 break;
1410 }
1411 break;
1412 }
1413 case 'e':
1414 {
1415 if (LocaleCompare("edge",option+1) == 0)
1416 {
1417 /*
1418 Enhance edges in the image.
1419 */
cristy6fccee12011-10-20 18:43:18 +00001420 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001421 flags=ParseGeometry(argv[i+1],&geometry_info);
1422 if ((flags & SigmaValue) == 0)
1423 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001424 mogrify_image=EdgeImage(*image,geometry_info.rho,
1425 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001426 break;
1427 }
1428 if (LocaleCompare("emboss",option+1) == 0)
1429 {
1430 /*
cristyd89705a2012-01-20 02:52:24 +00001431 Emboss image.
anthonydf8ebac2011-04-27 09:03:19 +00001432 */
cristy6fccee12011-10-20 18:43:18 +00001433 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001434 flags=ParseGeometry(argv[i+1],&geometry_info);
1435 if ((flags & SigmaValue) == 0)
1436 geometry_info.sigma=1.0;
1437 mogrify_image=EmbossImage(*image,geometry_info.rho,
1438 geometry_info.sigma,exception);
1439 break;
1440 }
1441 if (LocaleCompare("encipher",option+1) == 0)
1442 {
1443 StringInfo
1444 *passkey;
1445
1446 /*
1447 Encipher pixels.
1448 */
cristy6fccee12011-10-20 18:43:18 +00001449 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001450 passkey=FileToStringInfo(argv[i+1],~0,exception);
1451 if (passkey != (StringInfo *) NULL)
1452 {
1453 (void) PasskeyEncipherImage(*image,passkey,exception);
1454 passkey=DestroyStringInfo(passkey);
1455 }
1456 break;
1457 }
1458 if (LocaleCompare("encoding",option+1) == 0)
1459 {
1460 (void) CloneString(&draw_info->encoding,argv[i+1]);
1461 break;
1462 }
1463 if (LocaleCompare("enhance",option+1) == 0)
1464 {
1465 /*
1466 Enhance image.
1467 */
cristy6fccee12011-10-20 18:43:18 +00001468 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001469 mogrify_image=EnhanceImage(*image,exception);
1470 break;
1471 }
1472 if (LocaleCompare("equalize",option+1) == 0)
1473 {
1474 /*
1475 Equalize image.
1476 */
cristy6fccee12011-10-20 18:43:18 +00001477 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001478 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001479 break;
1480 }
1481 if (LocaleCompare("evaluate",option+1) == 0)
1482 {
1483 double
1484 constant;
1485
1486 MagickEvaluateOperator
1487 op;
1488
cristy6fccee12011-10-20 18:43:18 +00001489 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001490 op=(MagickEvaluateOperator) ParseCommandOption(
1491 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001492 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1493 1.0);
cristyd42d9952011-07-08 14:21:50 +00001494 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001495 break;
1496 }
1497 if (LocaleCompare("extent",option+1) == 0)
1498 {
1499 /*
1500 Set the image extent.
1501 */
cristy6fccee12011-10-20 18:43:18 +00001502 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001503 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1504 if (geometry.width == 0)
1505 geometry.width=(*image)->columns;
1506 if (geometry.height == 0)
1507 geometry.height=(*image)->rows;
1508 mogrify_image=ExtentImage(*image,&geometry,exception);
1509 break;
1510 }
1511 break;
1512 }
1513 case 'f':
1514 {
1515 if (LocaleCompare("family",option+1) == 0)
1516 {
1517 if (*option == '+')
1518 {
1519 if (draw_info->family != (char *) NULL)
1520 draw_info->family=DestroyString(draw_info->family);
1521 break;
1522 }
1523 (void) CloneString(&draw_info->family,argv[i+1]);
1524 break;
1525 }
1526 if (LocaleCompare("features",option+1) == 0)
1527 {
1528 if (*option == '+')
1529 {
1530 (void) DeleteImageArtifact(*image,"identify:features");
1531 break;
1532 }
1533 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1534 break;
1535 }
1536 if (LocaleCompare("fill",option+1) == 0)
1537 {
1538 ExceptionInfo
1539 *sans;
1540
anthonyfd706f92012-01-19 04:22:02 +00001541 PixelInfo
1542 color;
1543
cristy4c08aed2011-07-01 19:47:50 +00001544 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001545 if (*option == '+')
1546 {
cristy269c9412011-10-13 23:41:15 +00001547 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001548 exception);
anthonyfd706f92012-01-19 04:22:02 +00001549 draw_info->fill=fill;
anthonydf8ebac2011-04-27 09:03:19 +00001550 if (draw_info->fill_pattern != (Image *) NULL)
1551 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1552 break;
1553 }
1554 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00001555 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001556 sans=DestroyExceptionInfo(sans);
1557 if (status == MagickFalse)
1558 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1559 exception);
anthonyfd706f92012-01-19 04:22:02 +00001560 else
1561 draw_info->fill=fill=color;
anthonydf8ebac2011-04-27 09:03:19 +00001562 break;
1563 }
1564 if (LocaleCompare("flip",option+1) == 0)
1565 {
1566 /*
1567 Flip image scanlines.
1568 */
cristy6fccee12011-10-20 18:43:18 +00001569 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001570 mogrify_image=FlipImage(*image,exception);
1571 break;
1572 }
anthonydf8ebac2011-04-27 09:03:19 +00001573 if (LocaleCompare("floodfill",option+1) == 0)
1574 {
cristy4c08aed2011-07-01 19:47:50 +00001575 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001576 target;
1577
1578 /*
1579 Floodfill image.
1580 */
cristy6fccee12011-10-20 18:43:18 +00001581 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001582 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001583 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001584 exception);
cristyd42d9952011-07-08 14:21:50 +00001585 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001586 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001587 break;
1588 }
anthony3d2f4862011-05-01 13:48:16 +00001589 if (LocaleCompare("flop",option+1) == 0)
1590 {
1591 /*
1592 Flop image scanlines.
1593 */
cristy6fccee12011-10-20 18:43:18 +00001594 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001595 mogrify_image=FlopImage(*image,exception);
1596 break;
1597 }
anthonydf8ebac2011-04-27 09:03:19 +00001598 if (LocaleCompare("font",option+1) == 0)
1599 {
1600 if (*option == '+')
1601 {
1602 if (draw_info->font != (char *) NULL)
1603 draw_info->font=DestroyString(draw_info->font);
1604 break;
1605 }
1606 (void) CloneString(&draw_info->font,argv[i+1]);
1607 break;
1608 }
1609 if (LocaleCompare("format",option+1) == 0)
1610 {
1611 format=argv[i+1];
1612 break;
1613 }
1614 if (LocaleCompare("frame",option+1) == 0)
1615 {
1616 FrameInfo
1617 frame_info;
1618
1619 /*
1620 Surround image with an ornamental border.
1621 */
cristy6fccee12011-10-20 18:43:18 +00001622 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001623 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1624 frame_info.width=geometry.width;
1625 frame_info.height=geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001626 frame_info.outer_bevel=geometry.x;
1627 frame_info.inner_bevel=geometry.y;
1628 frame_info.x=(ssize_t) frame_info.width;
1629 frame_info.y=(ssize_t) frame_info.height;
1630 frame_info.width=(*image)->columns+2*frame_info.width;
1631 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001632 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001633 break;
1634 }
1635 if (LocaleCompare("function",option+1) == 0)
1636 {
1637 char
1638 *arguments,
1639 token[MaxTextExtent];
1640
1641 const char
1642 *p;
1643
1644 double
1645 *parameters;
1646
1647 MagickFunction
1648 function;
1649
1650 register ssize_t
1651 x;
1652
1653 size_t
1654 number_parameters;
1655
1656 /*
1657 Function Modify Image Values
1658 */
cristy6fccee12011-10-20 18:43:18 +00001659 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001660 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1661 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001662 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1663 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001664 if (arguments == (char *) NULL)
1665 break;
1666 p=(char *) arguments;
1667 for (x=0; *p != '\0'; x++)
1668 {
1669 GetMagickToken(p,&p,token);
1670 if (*token == ',')
1671 GetMagickToken(p,&p,token);
1672 }
1673 number_parameters=(size_t) x;
1674 parameters=(double *) AcquireQuantumMemory(number_parameters,
1675 sizeof(*parameters));
1676 if (parameters == (double *) NULL)
1677 ThrowWandFatalException(ResourceLimitFatalError,
1678 "MemoryAllocationFailed",(*image)->filename);
1679 (void) ResetMagickMemory(parameters,0,number_parameters*
1680 sizeof(*parameters));
1681 p=(char *) arguments;
1682 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1683 {
1684 GetMagickToken(p,&p,token);
1685 if (*token == ',')
1686 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001687 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001688 }
1689 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001690 (void) FunctionImage(*image,function,number_parameters,parameters,
1691 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001692 parameters=(double *) RelinquishMagickMemory(parameters);
1693 break;
1694 }
1695 break;
1696 }
1697 case 'g':
1698 {
1699 if (LocaleCompare("gamma",option+1) == 0)
1700 {
1701 /*
1702 Gamma image.
1703 */
cristy6fccee12011-10-20 18:43:18 +00001704 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001705 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001706 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001707 else
cristydbdd0e32011-11-04 23:29:40 +00001708 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001709 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001710 break;
1711 }
1712 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1713 (LocaleCompare("gaussian",option+1) == 0))
1714 {
1715 /*
1716 Gaussian blur image.
1717 */
cristy6fccee12011-10-20 18:43:18 +00001718 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001719 flags=ParseGeometry(argv[i+1],&geometry_info);
1720 if ((flags & SigmaValue) == 0)
1721 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001722 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristyd89705a2012-01-20 02:52:24 +00001723 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001724 break;
1725 }
1726 if (LocaleCompare("geometry",option+1) == 0)
1727 {
1728 /*
1729 Record Image offset, Resize last image.
1730 */
cristy6fccee12011-10-20 18:43:18 +00001731 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001732 if (*option == '+')
1733 {
1734 if ((*image)->geometry != (char *) NULL)
1735 (*image)->geometry=DestroyString((*image)->geometry);
1736 break;
1737 }
1738 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1739 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1740 (void) CloneString(&(*image)->geometry,argv[i+1]);
1741 else
1742 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
cristyaa2c16c2012-03-25 22:21:35 +00001743 (*image)->filter,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001744 break;
1745 }
1746 if (LocaleCompare("gravity",option+1) == 0)
1747 {
1748 if (*option == '+')
1749 {
1750 draw_info->gravity=UndefinedGravity;
1751 break;
1752 }
1753 draw_info->gravity=(GravityType) ParseCommandOption(
1754 MagickGravityOptions,MagickFalse,argv[i+1]);
1755 break;
1756 }
1757 break;
1758 }
1759 case 'h':
1760 {
1761 if (LocaleCompare("highlight-color",option+1) == 0)
1762 {
1763 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1764 break;
1765 }
1766 break;
1767 }
1768 case 'i':
1769 {
1770 if (LocaleCompare("identify",option+1) == 0)
1771 {
1772 char
1773 *text;
1774
cristy6fccee12011-10-20 18:43:18 +00001775 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001776 if (format == (char *) NULL)
1777 {
cristya4037272011-08-28 15:11:39 +00001778 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1779 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001780 break;
1781 }
cristy018f07f2011-09-04 21:15:19 +00001782 text=InterpretImageProperties(mogrify_info,*image,format,
1783 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001784 if (text == (char *) NULL)
1785 break;
1786 (void) fputs(text,stdout);
1787 (void) fputc('\n',stdout);
1788 text=DestroyString(text);
1789 break;
1790 }
1791 if (LocaleCompare("implode",option+1) == 0)
1792 {
1793 /*
1794 Implode image.
1795 */
cristy6fccee12011-10-20 18:43:18 +00001796 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001797 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001798 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1799 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001800 break;
1801 }
1802 if (LocaleCompare("interline-spacing",option+1) == 0)
1803 {
1804 if (*option == '+')
1805 (void) ParseGeometry("0",&geometry_info);
1806 else
1807 (void) ParseGeometry(argv[i+1],&geometry_info);
1808 draw_info->interline_spacing=geometry_info.rho;
1809 break;
1810 }
cristy28474bf2011-09-11 23:32:52 +00001811 if (LocaleCompare("interpolate",option+1) == 0)
1812 {
1813 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1814 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1815 break;
1816 }
anthonydf8ebac2011-04-27 09:03:19 +00001817 if (LocaleCompare("interword-spacing",option+1) == 0)
1818 {
1819 if (*option == '+')
1820 (void) ParseGeometry("0",&geometry_info);
1821 else
1822 (void) ParseGeometry(argv[i+1],&geometry_info);
1823 draw_info->interword_spacing=geometry_info.rho;
1824 break;
1825 }
anthonyfd706f92012-01-19 04:22:02 +00001826 if (LocaleCompare("interpolative-resize",option+1) == 0)
1827 {
1828 /*
1829 Interpolative resize image.
1830 */
1831 (void) SyncImageSettings(mogrify_info,*image,exception);
1832 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1833 mogrify_image=InterpolativeResizeImage(*image,geometry.width,
1834 geometry.height,interpolate_method,exception);
1835 break;
1836 }
anthonydf8ebac2011-04-27 09:03:19 +00001837 break;
1838 }
1839 case 'k':
1840 {
1841 if (LocaleCompare("kerning",option+1) == 0)
1842 {
1843 if (*option == '+')
1844 (void) ParseGeometry("0",&geometry_info);
1845 else
1846 (void) ParseGeometry(argv[i+1],&geometry_info);
1847 draw_info->kerning=geometry_info.rho;
1848 break;
1849 }
1850 break;
1851 }
1852 case 'l':
1853 {
1854 if (LocaleCompare("lat",option+1) == 0)
1855 {
1856 /*
1857 Local adaptive threshold image.
1858 */
cristy6fccee12011-10-20 18:43:18 +00001859 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001860 flags=ParseGeometry(argv[i+1],&geometry_info);
1861 if ((flags & PercentValue) != 0)
1862 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1863 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001864 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001865 geometry_info.xi,exception);
1866 break;
1867 }
1868 if (LocaleCompare("level",option+1) == 0)
1869 {
cristya19f1d72012-08-07 18:24:38 +00001870 double
anthonydf8ebac2011-04-27 09:03:19 +00001871 black_point,
1872 gamma,
1873 white_point;
1874
1875 MagickStatusType
1876 flags;
1877
1878 /*
1879 Parse levels.
1880 */
cristy6fccee12011-10-20 18:43:18 +00001881 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001882 flags=ParseGeometry(argv[i+1],&geometry_info);
1883 black_point=geometry_info.rho;
cristya19f1d72012-08-07 18:24:38 +00001884 white_point=(double) QuantumRange;
anthonydf8ebac2011-04-27 09:03:19 +00001885 if ((flags & SigmaValue) != 0)
1886 white_point=geometry_info.sigma;
1887 gamma=1.0;
1888 if ((flags & XiValue) != 0)
1889 gamma=geometry_info.xi;
1890 if ((flags & PercentValue) != 0)
1891 {
cristya19f1d72012-08-07 18:24:38 +00001892 black_point*=(double) (QuantumRange/100.0);
1893 white_point*=(double) (QuantumRange/100.0);
anthonydf8ebac2011-04-27 09:03:19 +00001894 }
1895 if ((flags & SigmaValue) == 0)
cristya19f1d72012-08-07 18:24:38 +00001896 white_point=(double) QuantumRange-black_point;
anthonydf8ebac2011-04-27 09:03:19 +00001897 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001898 (void) LevelizeImage(*image,black_point,white_point,gamma,
1899 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001900 else
cristy01e9afd2011-08-10 17:38:41 +00001901 (void) LevelImage(*image,black_point,white_point,gamma,
1902 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001903 break;
1904 }
1905 if (LocaleCompare("level-colors",option+1) == 0)
1906 {
1907 char
1908 token[MaxTextExtent];
1909
1910 const char
1911 *p;
1912
cristy4c08aed2011-07-01 19:47:50 +00001913 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001914 black_point,
1915 white_point;
1916
1917 p=(const char *) argv[i+1];
1918 GetMagickToken(p,&p,token); /* get black point color */
1919 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001920 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001921 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001922 else
cristy269c9412011-10-13 23:41:15 +00001923 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001924 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001925 if (isalpha((int) token[0]) || (token[0] == '#'))
1926 GetMagickToken(p,&p,token);
1927 if (*token == '\0')
1928 white_point=black_point; /* set everything to that color */
1929 else
1930 {
1931 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1932 GetMagickToken(p,&p,token); /* Get white point color. */
1933 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001934 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001935 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001936 else
cristy269c9412011-10-13 23:41:15 +00001937 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001938 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001939 }
cristy490408a2011-07-07 14:42:05 +00001940 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001941 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001942 break;
1943 }
1944 if (LocaleCompare("linear-stretch",option+1) == 0)
1945 {
1946 double
1947 black_point,
1948 white_point;
1949
1950 MagickStatusType
1951 flags;
1952
cristy6fccee12011-10-20 18:43:18 +00001953 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001954 flags=ParseGeometry(argv[i+1],&geometry_info);
1955 black_point=geometry_info.rho;
cristya19f1d72012-08-07 18:24:38 +00001956 white_point=(double) (*image)->columns*(*image)->rows;
anthonydf8ebac2011-04-27 09:03:19 +00001957 if ((flags & SigmaValue) != 0)
1958 white_point=geometry_info.sigma;
1959 if ((flags & PercentValue) != 0)
1960 {
1961 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1962 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1963 }
1964 if ((flags & SigmaValue) == 0)
cristya19f1d72012-08-07 18:24:38 +00001965 white_point=(double) (*image)->columns*(*image)->rows-
anthonydf8ebac2011-04-27 09:03:19 +00001966 black_point;
cristy33bd5152011-08-24 01:42:24 +00001967 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001968 break;
1969 }
anthonydf8ebac2011-04-27 09:03:19 +00001970 if (LocaleCompare("liquid-rescale",option+1) == 0)
1971 {
1972 /*
1973 Liquid rescale image.
1974 */
cristy6fccee12011-10-20 18:43:18 +00001975 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001976 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1977 if ((flags & XValue) == 0)
1978 geometry.x=1;
1979 if ((flags & YValue) == 0)
1980 geometry.y=0;
1981 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1982 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1983 break;
1984 }
1985 if (LocaleCompare("lowlight-color",option+1) == 0)
1986 {
1987 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1988 break;
1989 }
1990 break;
1991 }
1992 case 'm':
1993 {
1994 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001995 {
cristy3ed852e2009-09-05 21:47:34 +00001996 Image
anthonydf8ebac2011-04-27 09:03:19 +00001997 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001998
anthonydf8ebac2011-04-27 09:03:19 +00001999 /*
2000 Transform image colors to match this set of colors.
2001 */
cristy6fccee12011-10-20 18:43:18 +00002002 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002003 if (*option == '+')
2004 break;
2005 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2006 if (remap_image == (Image *) NULL)
2007 break;
cristy018f07f2011-09-04 21:15:19 +00002008 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002009 remap_image=DestroyImage(remap_image);
2010 break;
2011 }
2012 if (LocaleCompare("mask",option+1) == 0)
2013 {
2014 Image
2015 *mask;
2016
cristy6fccee12011-10-20 18:43:18 +00002017 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002018 if (*option == '+')
2019 {
2020 /*
2021 Remove a mask.
2022 */
cristy018f07f2011-09-04 21:15:19 +00002023 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002024 break;
2025 }
2026 /*
2027 Set the image mask.
2028 */
2029 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2030 if (mask == (Image *) NULL)
2031 break;
cristy018f07f2011-09-04 21:15:19 +00002032 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002033 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002034 break;
2035 }
2036 if (LocaleCompare("matte",option+1) == 0)
2037 {
2038 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002039 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002040 break;
2041 }
2042 if (LocaleCompare("median",option+1) == 0)
2043 {
2044 /*
2045 Median filter image.
2046 */
cristy6fccee12011-10-20 18:43:18 +00002047 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002048 flags=ParseGeometry(argv[i+1],&geometry_info);
2049 if ((flags & SigmaValue) == 0)
2050 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002051 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002052 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002053 break;
2054 }
2055 if (LocaleCompare("mode",option+1) == 0)
2056 {
2057 /*
2058 Mode image.
2059 */
cristy6fccee12011-10-20 18:43:18 +00002060 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002061 flags=ParseGeometry(argv[i+1],&geometry_info);
2062 if ((flags & SigmaValue) == 0)
2063 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002064 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002065 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002066 break;
2067 }
2068 if (LocaleCompare("modulate",option+1) == 0)
2069 {
cristy6fccee12011-10-20 18:43:18 +00002070 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002071 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002072 break;
2073 }
2074 if (LocaleCompare("monitor",option+1) == 0)
2075 {
2076 if (*option == '+')
2077 {
2078 (void) SetImageProgressMonitor(*image,
2079 (MagickProgressMonitor) NULL,(void *) NULL);
2080 break;
2081 }
2082 (void) SetImageProgressMonitor(*image,MonitorProgress,
2083 (void *) NULL);
2084 break;
2085 }
2086 if (LocaleCompare("monochrome",option+1) == 0)
2087 {
cristy6fccee12011-10-20 18:43:18 +00002088 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002089 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002090 break;
2091 }
2092 if (LocaleCompare("morphology",option+1) == 0)
2093 {
2094 char
2095 token[MaxTextExtent];
2096
2097 const char
2098 *p;
2099
2100 KernelInfo
2101 *kernel;
2102
2103 MorphologyMethod
2104 method;
2105
2106 ssize_t
2107 iterations;
2108
2109 /*
2110 Morphological Image Operation
2111 */
cristy6fccee12011-10-20 18:43:18 +00002112 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002113 p=argv[i+1];
2114 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002115 method=(MorphologyMethod) ParseCommandOption(
2116 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002117 iterations=1L;
2118 GetMagickToken(p,&p,token);
2119 if ((*p == ':') || (*p == ','))
2120 GetMagickToken(p,&p,token);
2121 if ((*p != '\0'))
2122 iterations=(ssize_t) StringToLong(p);
2123 kernel=AcquireKernelInfo(argv[i+2]);
2124 if (kernel == (KernelInfo *) NULL)
2125 {
2126 (void) ThrowMagickException(exception,GetMagickModule(),
2127 OptionError,"UnabletoParseKernel","morphology");
2128 status=MagickFalse;
2129 break;
2130 }
cristyf4ad9df2011-07-08 16:49:03 +00002131 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2132 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002133 kernel=DestroyKernelInfo(kernel);
2134 break;
2135 }
2136 if (LocaleCompare("motion-blur",option+1) == 0)
2137 {
2138 /*
2139 Motion blur image.
2140 */
cristy6fccee12011-10-20 18:43:18 +00002141 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002142 flags=ParseGeometry(argv[i+1],&geometry_info);
2143 if ((flags & SigmaValue) == 0)
2144 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002145 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002146 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002147 break;
2148 }
2149 break;
2150 }
2151 case 'n':
2152 {
2153 if (LocaleCompare("negate",option+1) == 0)
2154 {
cristy6fccee12011-10-20 18:43:18 +00002155 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002156 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002157 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002158 break;
2159 }
2160 if (LocaleCompare("noise",option+1) == 0)
2161 {
cristy6fccee12011-10-20 18:43:18 +00002162 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002163 if (*option == '-')
2164 {
cristyf36cbcb2011-09-07 13:28:22 +00002165 flags=ParseGeometry(argv[i+1],&geometry_info);
2166 if ((flags & SigmaValue) == 0)
2167 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002168 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002169 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002170 }
2171 else
2172 {
2173 NoiseType
2174 noise;
2175
2176 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2177 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002178 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002179 }
2180 break;
2181 }
2182 if (LocaleCompare("normalize",option+1) == 0)
2183 {
cristy6fccee12011-10-20 18:43:18 +00002184 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002185 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002186 break;
2187 }
2188 break;
2189 }
2190 case 'o':
2191 {
2192 if (LocaleCompare("opaque",option+1) == 0)
2193 {
cristy4c08aed2011-07-01 19:47:50 +00002194 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002195 target;
2196
cristy6fccee12011-10-20 18:43:18 +00002197 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002198 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002199 exception);
cristyd42d9952011-07-08 14:21:50 +00002200 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002201 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002202 break;
2203 }
2204 if (LocaleCompare("ordered-dither",option+1) == 0)
2205 {
cristy6fccee12011-10-20 18:43:18 +00002206 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002207 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002208 break;
2209 }
2210 break;
2211 }
2212 case 'p':
2213 {
2214 if (LocaleCompare("paint",option+1) == 0)
2215 {
cristy6fccee12011-10-20 18:43:18 +00002216 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002217 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002218 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2219 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002220 break;
2221 }
anthonydf8ebac2011-04-27 09:03:19 +00002222 if (LocaleCompare("pointsize",option+1) == 0)
2223 {
2224 if (*option == '+')
2225 (void) ParseGeometry("12",&geometry_info);
2226 else
2227 (void) ParseGeometry(argv[i+1],&geometry_info);
2228 draw_info->pointsize=geometry_info.rho;
2229 break;
2230 }
2231 if (LocaleCompare("polaroid",option+1) == 0)
2232 {
cristye9e3d382011-12-14 01:50:13 +00002233 const char
2234 *caption;
2235
anthonydf8ebac2011-04-27 09:03:19 +00002236 double
2237 angle;
2238
2239 RandomInfo
2240 *random_info;
2241
2242 /*
2243 Simulate a Polaroid picture.
2244 */
cristy6fccee12011-10-20 18:43:18 +00002245 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002246 random_info=AcquireRandomInfo();
2247 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2248 random_info=DestroyRandomInfo(random_info);
2249 if (*option == '-')
2250 {
2251 SetGeometryInfo(&geometry_info);
2252 flags=ParseGeometry(argv[i+1],&geometry_info);
2253 angle=geometry_info.rho;
2254 }
cristye9e3d382011-12-14 01:50:13 +00002255 caption=GetImageProperty(*image,"caption",exception);
2256 mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
cristy28474bf2011-09-11 23:32:52 +00002257 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002258 break;
2259 }
2260 if (LocaleCompare("posterize",option+1) == 0)
2261 {
2262 /*
2263 Posterize image.
2264 */
cristy6fccee12011-10-20 18:43:18 +00002265 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002266 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristycbda6112012-05-27 20:57:16 +00002267 quantize_info->dither_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002268 break;
2269 }
2270 if (LocaleCompare("preview",option+1) == 0)
2271 {
2272 PreviewType
2273 preview_type;
2274
2275 /*
2276 Preview image.
2277 */
cristy6fccee12011-10-20 18:43:18 +00002278 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002279 if (*option == '+')
2280 preview_type=UndefinedPreview;
2281 else
cristy28474bf2011-09-11 23:32:52 +00002282 preview_type=(PreviewType) ParseCommandOption(
2283 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002284 mogrify_image=PreviewImage(*image,preview_type,exception);
2285 break;
2286 }
2287 if (LocaleCompare("profile",option+1) == 0)
2288 {
2289 const char
2290 *name;
2291
2292 const StringInfo
2293 *profile;
2294
2295 Image
2296 *profile_image;
2297
2298 ImageInfo
2299 *profile_info;
2300
cristy6fccee12011-10-20 18:43:18 +00002301 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002302 if (*option == '+')
2303 {
2304 /*
2305 Remove a profile from the image.
2306 */
2307 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002308 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002309 break;
2310 }
2311 /*
2312 Associate a profile with the image.
2313 */
2314 profile_info=CloneImageInfo(mogrify_info);
2315 profile=GetImageProfile(*image,"iptc");
2316 if (profile != (StringInfo *) NULL)
2317 profile_info->profile=(void *) CloneStringInfo(profile);
2318 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2319 profile_info=DestroyImageInfo(profile_info);
2320 if (profile_image == (Image *) NULL)
2321 {
2322 StringInfo
2323 *profile;
2324
2325 profile_info=CloneImageInfo(mogrify_info);
2326 (void) CopyMagickString(profile_info->filename,argv[i+1],
2327 MaxTextExtent);
2328 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2329 if (profile != (StringInfo *) NULL)
2330 {
2331 (void) ProfileImage(*image,profile_info->magick,
2332 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002333 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002334 profile=DestroyStringInfo(profile);
2335 }
2336 profile_info=DestroyImageInfo(profile_info);
2337 break;
2338 }
2339 ResetImageProfileIterator(profile_image);
2340 name=GetNextImageProfile(profile_image);
2341 while (name != (const char *) NULL)
2342 {
2343 profile=GetImageProfile(profile_image,name);
2344 if (profile != (StringInfo *) NULL)
2345 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002346 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002347 name=GetNextImageProfile(profile_image);
2348 }
2349 profile_image=DestroyImage(profile_image);
2350 break;
2351 }
2352 break;
2353 }
2354 case 'q':
2355 {
2356 if (LocaleCompare("quantize",option+1) == 0)
2357 {
2358 if (*option == '+')
2359 {
2360 quantize_info->colorspace=UndefinedColorspace;
2361 break;
2362 }
2363 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2364 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2365 break;
2366 }
2367 break;
2368 }
2369 case 'r':
2370 {
2371 if (LocaleCompare("radial-blur",option+1) == 0)
2372 {
2373 /*
2374 Radial blur image.
2375 */
cristy6fccee12011-10-20 18:43:18 +00002376 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002377 flags=ParseGeometry(argv[i+1],&geometry_info);
cristyaa2c16c2012-03-25 22:21:35 +00002378 mogrify_image=RadialBlurImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002379 break;
2380 }
2381 if (LocaleCompare("raise",option+1) == 0)
2382 {
2383 /*
2384 Surround image with a raise of solid color.
2385 */
2386 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002387 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002388 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002389 break;
2390 }
2391 if (LocaleCompare("random-threshold",option+1) == 0)
2392 {
2393 /*
2394 Threshold image.
2395 */
cristy6fccee12011-10-20 18:43:18 +00002396 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002397 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002398 break;
2399 }
anthonydf8ebac2011-04-27 09:03:19 +00002400 if (LocaleCompare("region",option+1) == 0)
2401 {
cristy6fccee12011-10-20 18:43:18 +00002402 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002403 if (region_image != (Image *) NULL)
2404 {
2405 /*
2406 Composite region.
2407 */
cristy8a46d822012-08-28 23:32:39 +00002408 (void) CompositeImage(region_image,*image,
2409 region_image->alpha_trait == BlendPixelTrait ?
2410 CopyCompositeOp : OverCompositeOp,MagickTrue,
cristye941a752011-10-15 01:52:48 +00002411 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002412 *image=DestroyImage(*image);
2413 *image=region_image;
2414 region_image = (Image *) NULL;
2415 }
2416 if (*option == '+')
2417 break;
2418 /*
2419 Apply transformations to a selected region of the image.
2420 */
cristy3ed852e2009-09-05 21:47:34 +00002421 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2422 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002423 mogrify_image=CropImage(*image,&region_geometry,exception);
2424 if (mogrify_image == (Image *) NULL)
2425 break;
2426 region_image=(*image);
2427 *image=mogrify_image;
2428 mogrify_image=(Image *) NULL;
2429 break;
cristy3ed852e2009-09-05 21:47:34 +00002430 }
anthonydf8ebac2011-04-27 09:03:19 +00002431 if (LocaleCompare("render",option+1) == 0)
2432 {
cristy6fccee12011-10-20 18:43:18 +00002433 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002434 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2435 break;
2436 }
2437 if (LocaleCompare("remap",option+1) == 0)
2438 {
2439 Image
2440 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002441
anthonydf8ebac2011-04-27 09:03:19 +00002442 /*
2443 Transform image colors to match this set of colors.
2444 */
cristy6fccee12011-10-20 18:43:18 +00002445 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002446 if (*option == '+')
2447 break;
2448 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2449 if (remap_image == (Image *) NULL)
2450 break;
cristy018f07f2011-09-04 21:15:19 +00002451 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002452 remap_image=DestroyImage(remap_image);
2453 break;
2454 }
2455 if (LocaleCompare("repage",option+1) == 0)
2456 {
2457 if (*option == '+')
2458 {
2459 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2460 break;
2461 }
2462 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002463 break;
2464 }
2465 if (LocaleCompare("resample",option+1) == 0)
2466 {
2467 /*
2468 Resample image.
2469 */
cristy6fccee12011-10-20 18:43:18 +00002470 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002471 flags=ParseGeometry(argv[i+1],&geometry_info);
2472 if ((flags & SigmaValue) == 0)
2473 geometry_info.sigma=geometry_info.rho;
2474 mogrify_image=ResampleImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002475 geometry_info.sigma,(*image)->filter,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002476 break;
2477 }
2478 if (LocaleCompare("resize",option+1) == 0)
2479 {
2480 /*
2481 Resize image.
2482 */
cristy6fccee12011-10-20 18:43:18 +00002483 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002484 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2485 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
cristyaa2c16c2012-03-25 22:21:35 +00002486 (*image)->filter,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002487 break;
2488 }
2489 if (LocaleCompare("roll",option+1) == 0)
2490 {
2491 /*
2492 Roll image.
2493 */
cristy6fccee12011-10-20 18:43:18 +00002494 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002495 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2496 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2497 break;
2498 }
2499 if (LocaleCompare("rotate",option+1) == 0)
2500 {
2501 char
2502 *geometry;
2503
2504 /*
2505 Check for conditional image rotation.
2506 */
cristy6fccee12011-10-20 18:43:18 +00002507 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002508 if (strchr(argv[i+1],'>') != (char *) NULL)
2509 if ((*image)->columns <= (*image)->rows)
2510 break;
2511 if (strchr(argv[i+1],'<') != (char *) NULL)
2512 if ((*image)->columns >= (*image)->rows)
2513 break;
2514 /*
2515 Rotate image.
2516 */
2517 geometry=ConstantString(argv[i+1]);
2518 (void) SubstituteString(&geometry,">","");
2519 (void) SubstituteString(&geometry,"<","");
2520 (void) ParseGeometry(geometry,&geometry_info);
2521 geometry=DestroyString(geometry);
2522 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2523 break;
2524 }
2525 break;
2526 }
2527 case 's':
2528 {
2529 if (LocaleCompare("sample",option+1) == 0)
2530 {
2531 /*
2532 Sample image with pixel replication.
2533 */
cristy6fccee12011-10-20 18:43:18 +00002534 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002535 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2536 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2537 exception);
2538 break;
2539 }
2540 if (LocaleCompare("scale",option+1) == 0)
2541 {
2542 /*
2543 Resize image.
2544 */
cristy6fccee12011-10-20 18:43:18 +00002545 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002546 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2547 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2548 exception);
2549 break;
2550 }
2551 if (LocaleCompare("selective-blur",option+1) == 0)
2552 {
2553 /*
2554 Selectively blur pixels within a contrast threshold.
2555 */
cristy6fccee12011-10-20 18:43:18 +00002556 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002557 flags=ParseGeometry(argv[i+1],&geometry_info);
2558 if ((flags & PercentValue) != 0)
2559 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002560 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002561 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002562 break;
2563 }
2564 if (LocaleCompare("separate",option+1) == 0)
2565 {
2566 /*
2567 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002568 */
cristy6fccee12011-10-20 18:43:18 +00002569 (void) SyncImageSettings(mogrify_info,*image,exception);
cristydfdb19e2012-03-21 22:22:24 +00002570 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002571 break;
2572 }
2573 if (LocaleCompare("sepia-tone",option+1) == 0)
2574 {
2575 double
2576 threshold;
2577
2578 /*
2579 Sepia-tone image.
2580 */
cristy6fccee12011-10-20 18:43:18 +00002581 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002582 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2583 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002584 mogrify_image=SepiaToneImage(*image,threshold,exception);
2585 break;
2586 }
2587 if (LocaleCompare("segment",option+1) == 0)
2588 {
2589 /*
2590 Segment image.
2591 */
cristy6fccee12011-10-20 18:43:18 +00002592 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002593 flags=ParseGeometry(argv[i+1],&geometry_info);
2594 if ((flags & SigmaValue) == 0)
2595 geometry_info.sigma=1.0;
2596 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002597 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2598 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002599 break;
2600 }
2601 if (LocaleCompare("set",option+1) == 0)
2602 {
2603 char
2604 *value;
2605
2606 /*
2607 Set image option.
2608 */
2609 if (*option == '+')
2610 {
2611 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2612 (void) DeleteImageRegistry(argv[i+1]+9);
2613 else
2614 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2615 {
2616 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2617 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2618 }
2619 else
2620 (void) DeleteImageProperty(*image,argv[i+1]);
2621 break;
2622 }
cristy018f07f2011-09-04 21:15:19 +00002623 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2624 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002625 if (value == (char *) NULL)
2626 break;
2627 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2628 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2629 exception);
2630 else
2631 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2632 {
2633 (void) SetImageOption(image_info,argv[i+1]+7,value);
2634 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2635 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2636 }
2637 else
cristyd15e6592011-10-15 00:13:06 +00002638 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002639 value=DestroyString(value);
2640 break;
2641 }
2642 if (LocaleCompare("shade",option+1) == 0)
2643 {
2644 /*
2645 Shade image.
2646 */
cristy6fccee12011-10-20 18:43:18 +00002647 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002648 flags=ParseGeometry(argv[i+1],&geometry_info);
2649 if ((flags & SigmaValue) == 0)
2650 geometry_info.sigma=1.0;
2651 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2652 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2653 break;
2654 }
2655 if (LocaleCompare("shadow",option+1) == 0)
2656 {
2657 /*
2658 Shadow image.
2659 */
cristy6fccee12011-10-20 18:43:18 +00002660 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002661 flags=ParseGeometry(argv[i+1],&geometry_info);
2662 if ((flags & SigmaValue) == 0)
2663 geometry_info.sigma=1.0;
2664 if ((flags & XiValue) == 0)
2665 geometry_info.xi=4.0;
2666 if ((flags & PsiValue) == 0)
2667 geometry_info.psi=4.0;
2668 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002669 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),
2670 (ssize_t) ceil(geometry_info.psi-0.5),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002671 break;
2672 }
2673 if (LocaleCompare("sharpen",option+1) == 0)
2674 {
2675 /*
2676 Sharpen image.
2677 */
cristy6fccee12011-10-20 18:43:18 +00002678 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002679 flags=ParseGeometry(argv[i+1],&geometry_info);
2680 if ((flags & SigmaValue) == 0)
2681 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002682 if ((flags & XiValue) == 0)
2683 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002684 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002685 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002686 break;
2687 }
2688 if (LocaleCompare("shave",option+1) == 0)
2689 {
2690 /*
2691 Shave the image edges.
2692 */
cristy6fccee12011-10-20 18:43:18 +00002693 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002694 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2695 mogrify_image=ShaveImage(*image,&geometry,exception);
2696 break;
2697 }
2698 if (LocaleCompare("shear",option+1) == 0)
2699 {
2700 /*
2701 Shear image.
2702 */
cristy6fccee12011-10-20 18:43:18 +00002703 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002704 flags=ParseGeometry(argv[i+1],&geometry_info);
2705 if ((flags & SigmaValue) == 0)
2706 geometry_info.sigma=geometry_info.rho;
2707 mogrify_image=ShearImage(*image,geometry_info.rho,
2708 geometry_info.sigma,exception);
2709 break;
2710 }
2711 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2712 {
2713 /*
2714 Sigmoidal non-linearity contrast control.
2715 */
cristy6fccee12011-10-20 18:43:18 +00002716 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002717 flags=ParseGeometry(argv[i+1],&geometry_info);
2718 if ((flags & SigmaValue) == 0)
2719 geometry_info.sigma=(double) QuantumRange/2.0;
2720 if ((flags & PercentValue) != 0)
2721 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2722 100.0;
cristy9ee60942011-07-06 14:54:38 +00002723 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002724 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2725 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002726 break;
2727 }
2728 if (LocaleCompare("sketch",option+1) == 0)
2729 {
2730 /*
2731 Sketch image.
2732 */
cristy6fccee12011-10-20 18:43:18 +00002733 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002734 flags=ParseGeometry(argv[i+1],&geometry_info);
2735 if ((flags & SigmaValue) == 0)
2736 geometry_info.sigma=1.0;
2737 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002738 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002739 break;
2740 }
2741 if (LocaleCompare("solarize",option+1) == 0)
2742 {
2743 double
2744 threshold;
2745
cristy6fccee12011-10-20 18:43:18 +00002746 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002747 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2748 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002749 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002750 break;
2751 }
2752 if (LocaleCompare("sparse-color",option+1) == 0)
2753 {
2754 SparseColorMethod
2755 method;
2756
2757 char
2758 *arguments;
2759
2760 /*
2761 Sparse Color Interpolated Gradient
2762 */
cristy6fccee12011-10-20 18:43:18 +00002763 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002764 method=(SparseColorMethod) ParseCommandOption(
2765 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002766 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2767 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002768 if (arguments == (char *) NULL)
2769 break;
cristy3884f692011-07-08 18:00:18 +00002770 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002771 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2772 arguments=DestroyString(arguments);
2773 break;
2774 }
2775 if (LocaleCompare("splice",option+1) == 0)
2776 {
2777 /*
2778 Splice a solid color into the image.
2779 */
cristy6fccee12011-10-20 18:43:18 +00002780 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002781 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2782 mogrify_image=SpliceImage(*image,&geometry,exception);
2783 break;
2784 }
2785 if (LocaleCompare("spread",option+1) == 0)
2786 {
2787 /*
2788 Spread an image.
2789 */
cristy6fccee12011-10-20 18:43:18 +00002790 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002791 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002792 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002793 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002794 break;
2795 }
2796 if (LocaleCompare("statistic",option+1) == 0)
2797 {
2798 StatisticType
2799 type;
2800
cristy6fccee12011-10-20 18:43:18 +00002801 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002802 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2803 MagickFalse,argv[i+1]);
2804 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002805 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2806 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002807 break;
2808 }
2809 if (LocaleCompare("stretch",option+1) == 0)
2810 {
2811 if (*option == '+')
2812 {
2813 draw_info->stretch=UndefinedStretch;
2814 break;
2815 }
2816 draw_info->stretch=(StretchType) ParseCommandOption(
2817 MagickStretchOptions,MagickFalse,argv[i+1]);
2818 break;
2819 }
2820 if (LocaleCompare("strip",option+1) == 0)
2821 {
2822 /*
2823 Strip image of profiles and comments.
2824 */
cristy6fccee12011-10-20 18:43:18 +00002825 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002826 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002827 break;
2828 }
2829 if (LocaleCompare("stroke",option+1) == 0)
2830 {
2831 ExceptionInfo
2832 *sans;
2833
anthonyfd706f92012-01-19 04:22:02 +00002834 PixelInfo
2835 color;
2836
anthonydf8ebac2011-04-27 09:03:19 +00002837 if (*option == '+')
2838 {
cristy9950d572011-10-01 18:22:35 +00002839 (void) QueryColorCompliance("none",AllCompliance,
2840 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002841 if (draw_info->stroke_pattern != (Image *) NULL)
2842 draw_info->stroke_pattern=DestroyImage(
2843 draw_info->stroke_pattern);
2844 break;
2845 }
2846 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00002847 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002848 sans=DestroyExceptionInfo(sans);
2849 if (status == MagickFalse)
2850 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2851 exception);
anthonyfd706f92012-01-19 04:22:02 +00002852 else
2853 draw_info->stroke=color;
anthonydf8ebac2011-04-27 09:03:19 +00002854 break;
2855 }
2856 if (LocaleCompare("strokewidth",option+1) == 0)
2857 {
cristy9b34e302011-11-05 02:15:45 +00002858 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002859 break;
2860 }
2861 if (LocaleCompare("style",option+1) == 0)
2862 {
2863 if (*option == '+')
2864 {
2865 draw_info->style=UndefinedStyle;
2866 break;
2867 }
2868 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2869 MagickFalse,argv[i+1]);
2870 break;
2871 }
2872 if (LocaleCompare("swirl",option+1) == 0)
2873 {
2874 /*
2875 Swirl image.
2876 */
cristy6fccee12011-10-20 18:43:18 +00002877 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002878 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002879 mogrify_image=SwirlImage(*image,geometry_info.rho,
2880 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002881 break;
2882 }
2883 break;
2884 }
2885 case 't':
2886 {
2887 if (LocaleCompare("threshold",option+1) == 0)
2888 {
2889 double
2890 threshold;
2891
2892 /*
2893 Threshold image.
2894 */
cristy6fccee12011-10-20 18:43:18 +00002895 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002896 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002897 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002898 else
cristy9b34e302011-11-05 02:15:45 +00002899 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2900 1.0);
cristye941a752011-10-15 01:52:48 +00002901 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002902 break;
2903 }
2904 if (LocaleCompare("thumbnail",option+1) == 0)
2905 {
2906 /*
2907 Thumbnail image.
2908 */
cristy6fccee12011-10-20 18:43:18 +00002909 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002910 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2911 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2912 exception);
2913 break;
2914 }
2915 if (LocaleCompare("tile",option+1) == 0)
2916 {
2917 if (*option == '+')
2918 {
2919 if (draw_info->fill_pattern != (Image *) NULL)
2920 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2921 break;
2922 }
2923 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2924 exception);
2925 break;
2926 }
2927 if (LocaleCompare("tint",option+1) == 0)
2928 {
2929 /*
2930 Tint the image.
2931 */
cristy6fccee12011-10-20 18:43:18 +00002932 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00002933 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002934 break;
2935 }
2936 if (LocaleCompare("transform",option+1) == 0)
2937 {
2938 /*
2939 Affine transform image.
2940 */
cristy6fccee12011-10-20 18:43:18 +00002941 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002942 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2943 exception);
2944 break;
2945 }
2946 if (LocaleCompare("transparent",option+1) == 0)
2947 {
cristy4c08aed2011-07-01 19:47:50 +00002948 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002949 target;
2950
cristy6fccee12011-10-20 18:43:18 +00002951 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002952 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002953 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002954 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002955 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00002956 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002957 break;
2958 }
2959 if (LocaleCompare("transpose",option+1) == 0)
2960 {
2961 /*
2962 Transpose image scanlines.
2963 */
cristy6fccee12011-10-20 18:43:18 +00002964 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002965 mogrify_image=TransposeImage(*image,exception);
2966 break;
2967 }
2968 if (LocaleCompare("transverse",option+1) == 0)
2969 {
2970 /*
2971 Transverse image scanlines.
2972 */
cristy6fccee12011-10-20 18:43:18 +00002973 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002974 mogrify_image=TransverseImage(*image,exception);
2975 break;
2976 }
2977 if (LocaleCompare("treedepth",option+1) == 0)
2978 {
2979 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2980 break;
2981 }
2982 if (LocaleCompare("trim",option+1) == 0)
2983 {
2984 /*
2985 Trim image.
2986 */
cristy6fccee12011-10-20 18:43:18 +00002987 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002988 mogrify_image=TrimImage(*image,exception);
2989 break;
2990 }
2991 if (LocaleCompare("type",option+1) == 0)
2992 {
2993 ImageType
2994 type;
2995
cristy6fccee12011-10-20 18:43:18 +00002996 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002997 if (*option == '+')
2998 type=UndefinedType;
2999 else
3000 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3001 argv[i+1]);
3002 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003003 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003004 break;
3005 }
3006 break;
3007 }
3008 case 'u':
3009 {
3010 if (LocaleCompare("undercolor",option+1) == 0)
3011 {
cristy9950d572011-10-01 18:22:35 +00003012 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3013 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003014 break;
3015 }
3016 if (LocaleCompare("unique",option+1) == 0)
3017 {
3018 if (*option == '+')
3019 {
3020 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3021 break;
3022 }
3023 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3024 (void) SetImageArtifact(*image,"verbose","true");
3025 break;
3026 }
3027 if (LocaleCompare("unique-colors",option+1) == 0)
3028 {
3029 /*
3030 Unique image colors.
3031 */
cristy6fccee12011-10-20 18:43:18 +00003032 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003033 mogrify_image=UniqueImageColors(*image,exception);
3034 break;
3035 }
3036 if (LocaleCompare("unsharp",option+1) == 0)
3037 {
3038 /*
3039 Unsharp mask image.
3040 */
cristy6fccee12011-10-20 18:43:18 +00003041 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003042 flags=ParseGeometry(argv[i+1],&geometry_info);
3043 if ((flags & SigmaValue) == 0)
3044 geometry_info.sigma=1.0;
3045 if ((flags & XiValue) == 0)
3046 geometry_info.xi=1.0;
3047 if ((flags & PsiValue) == 0)
3048 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003049 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3050 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003051 break;
3052 }
3053 break;
3054 }
3055 case 'v':
3056 {
3057 if (LocaleCompare("verbose",option+1) == 0)
3058 {
3059 (void) SetImageArtifact(*image,option+1,
3060 *option == '+' ? "false" : "true");
3061 break;
3062 }
3063 if (LocaleCompare("vignette",option+1) == 0)
3064 {
3065 /*
3066 Vignette image.
3067 */
cristy6fccee12011-10-20 18:43:18 +00003068 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003069 flags=ParseGeometry(argv[i+1],&geometry_info);
3070 if ((flags & SigmaValue) == 0)
3071 geometry_info.sigma=1.0;
3072 if ((flags & XiValue) == 0)
3073 geometry_info.xi=0.1*(*image)->columns;
3074 if ((flags & PsiValue) == 0)
3075 geometry_info.psi=0.1*(*image)->rows;
3076 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00003077 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),
3078 (ssize_t) ceil(geometry_info.psi-0.5),exception);
anthonydf8ebac2011-04-27 09:03:19 +00003079 break;
3080 }
3081 if (LocaleCompare("virtual-pixel",option+1) == 0)
3082 {
3083 if (*option == '+')
3084 {
3085 (void) SetImageVirtualPixelMethod(*image,
cristy387430f2012-02-07 13:09:46 +00003086 UndefinedVirtualPixelMethod,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003087 break;
3088 }
3089 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3090 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy387430f2012-02-07 13:09:46 +00003091 argv[i+1]),exception);
anthonydf8ebac2011-04-27 09:03:19 +00003092 break;
3093 }
3094 break;
3095 }
3096 case 'w':
3097 {
3098 if (LocaleCompare("wave",option+1) == 0)
3099 {
3100 /*
3101 Wave image.
3102 */
cristy6fccee12011-10-20 18:43:18 +00003103 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003104 flags=ParseGeometry(argv[i+1],&geometry_info);
3105 if ((flags & SigmaValue) == 0)
3106 geometry_info.sigma=1.0;
3107 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003108 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003109 break;
3110 }
3111 if (LocaleCompare("weight",option+1) == 0)
3112 {
3113 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3114 if (LocaleCompare(argv[i+1],"all") == 0)
3115 draw_info->weight=0;
3116 if (LocaleCompare(argv[i+1],"bold") == 0)
3117 draw_info->weight=700;
3118 if (LocaleCompare(argv[i+1],"bolder") == 0)
3119 if (draw_info->weight <= 800)
3120 draw_info->weight+=100;
3121 if (LocaleCompare(argv[i+1],"lighter") == 0)
3122 if (draw_info->weight >= 100)
3123 draw_info->weight-=100;
3124 if (LocaleCompare(argv[i+1],"normal") == 0)
3125 draw_info->weight=400;
3126 break;
3127 }
3128 if (LocaleCompare("white-threshold",option+1) == 0)
3129 {
3130 /*
3131 White threshold image.
3132 */
cristy6fccee12011-10-20 18:43:18 +00003133 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003134 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003135 break;
3136 }
3137 break;
3138 }
3139 default:
3140 break;
3141 }
3142 /*
3143 Replace current image with any image that was generated
3144 */
3145 if (mogrify_image != (Image *) NULL)
3146 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003147 i+=count;
3148 }
3149 if (region_image != (Image *) NULL)
3150 {
anthonydf8ebac2011-04-27 09:03:19 +00003151 /*
3152 Composite transformed region onto image.
3153 */
cristy6fccee12011-10-20 18:43:18 +00003154 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy8a46d822012-08-28 23:32:39 +00003155 (void) CompositeImage(region_image,*image,
3156 region_image->alpha_trait == BlendPixelTrait ? CopyCompositeOp :
3157 OverCompositeOp,MagickTrue,region_geometry.x,region_geometry.y,
3158 exception);
cristy3ed852e2009-09-05 21:47:34 +00003159 *image=DestroyImage(*image);
3160 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003161 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003162 }
3163 /*
3164 Free resources.
3165 */
anthonydf8ebac2011-04-27 09:03:19 +00003166 quantize_info=DestroyQuantizeInfo(quantize_info);
3167 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003168 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003169 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003170 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003171}
3172
3173/*
3174%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3175% %
3176% %
3177% %
cristy5063d812010-10-19 16:28:10 +00003178+ M o g r i f y I m a g e C o m m a n d %
cristy3ed852e2009-09-05 21:47:34 +00003179% %
3180% %
3181% %
3182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3183%
3184% MogrifyImageCommand() transforms an image or a sequence of images. These
3185% transforms include image scaling, image rotation, color reduction, and
3186% others. The transmogrified image overwrites the original image.
3187%
3188% The format of the MogrifyImageCommand method is:
3189%
3190% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3191% const char **argv,char **metadata,ExceptionInfo *exception)
3192%
3193% A description of each parameter follows:
3194%
3195% o image_info: the image info.
3196%
3197% o argc: the number of elements in the argument vector.
3198%
3199% o argv: A text array containing the command line arguments.
3200%
3201% o metadata: any metadata is returned here.
3202%
3203% o exception: return any errors or warnings in this structure.
3204%
3205*/
3206
3207static MagickBooleanType MogrifyUsage(void)
3208{
3209 static const char
cristy87c02f42012-02-24 00:19:10 +00003210 *channel_operators[]=
3211 {
cristy5f257b22012-03-07 00:27:29 +00003212 "-channel-fx expression",
cristyd04e7bf2012-03-03 19:19:12 +00003213 " exchange, extract, or transfer one or more image channels",
cristydfdb19e2012-03-21 22:22:24 +00003214 "-separate separate an image channel into a grayscale image",
cristy87c02f42012-02-24 00:19:10 +00003215 (char *) NULL
3216 },
cristy3ed852e2009-09-05 21:47:34 +00003217 *miscellaneous[]=
3218 {
3219 "-debug events display copious debugging information",
cristy93053632013-01-06 23:55:19 +00003220 "-distribute-cache port",
cristyd79e2362013-01-06 23:01:40 +00003221 " distributed pixel cache spanning one or more servers",
cristy3ed852e2009-09-05 21:47:34 +00003222 "-help print program options",
3223 "-list type print a list of supported option arguments",
3224 "-log format format of debugging information",
3225 "-version print version information",
3226 (char *) NULL
3227 },
3228 *operators[]=
3229 {
3230 "-adaptive-blur geometry",
3231 " adaptively blur pixels; decrease effect near edges",
3232 "-adaptive-resize geometry",
3233 " adaptively resize image using 'mesh' interpolation",
3234 "-adaptive-sharpen geometry",
3235 " adaptively sharpen pixels; increase effect near edges",
3236 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3237 " transparent, extract, background, or shape",
3238 "-annotate geometry text",
3239 " annotate the image with text",
3240 "-auto-gamma automagically adjust gamma level of image",
3241 "-auto-level automagically adjust color levels of image",
3242 "-auto-orient automagically orient (rotate) image",
3243 "-bench iterations measure performance",
3244 "-black-threshold value",
3245 " force all pixels below the threshold into black",
3246 "-blue-shift simulate a scene at nighttime in the moonlight",
3247 "-blur geometry reduce image noise and reduce detail levels",
3248 "-border geometry surround image with a border of color",
3249 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003250 "-brightness-contrast geometry",
3251 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003252 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003253 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003254 "-chop geometry remove pixels from the image interior",
cristy1df20892012-11-04 01:06:40 +00003255 "-clamp keep pixel values in range (0-QuantumRange)",
cristycee97112010-05-28 00:44:52 +00003256 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003257 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003258 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003259 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003260 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003261 "-contrast enhance or reduce the image contrast",
3262 "-contrast-stretch geometry",
anthonye5b39652012-04-21 05:37:29 +00003263 " improve contrast by 'stretching' the intensity range",
cristy3ed852e2009-09-05 21:47:34 +00003264 "-convolve coefficients",
3265 " apply a convolution kernel to the image",
3266 "-cycle amount cycle the image colormap",
3267 "-decipher filename convert cipher pixels to plain pixels",
3268 "-deskew threshold straighten an image",
3269 "-despeckle reduce the speckles within an image",
3270 "-distort method args",
3271 " distort images according to given method ad args",
3272 "-draw string annotate the image with a graphic primitive",
3273 "-edge radius apply a filter to detect edges in the image",
3274 "-encipher filename convert plain pixels to cipher pixels",
3275 "-emboss radius emboss an image",
3276 "-enhance apply a digital filter to enhance a noisy image",
3277 "-equalize perform histogram equalization to an image",
3278 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003279 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003280 "-extent geometry set the image size",
3281 "-extract geometry extract area from image",
3282 "-fft implements the discrete Fourier transform (DFT)",
3283 "-flip flip image vertically",
3284 "-floodfill geometry color",
3285 " floodfill the image with color",
3286 "-flop flop image horizontally",
3287 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003288 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003289 " apply function over image values",
3290 "-gamma value level of gamma correction",
3291 "-gaussian-blur geometry",
3292 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003293 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003294 "-identify identify the format and characteristics of the image",
3295 "-ift implements the inverse discrete Fourier transform (DFT)",
3296 "-implode amount implode image pixels about the center",
anthonyfd706f92012-01-19 04:22:02 +00003297 "-interpolative-resize geometry",
3298 " resize image using interpolation",
cristy3ed852e2009-09-05 21:47:34 +00003299 "-lat geometry local adaptive thresholding",
3300 "-layers method optimize, merge, or compare image layers",
3301 "-level value adjust the level of image contrast",
3302 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003303 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003304 "-linear-stretch geometry",
anthonye5b39652012-04-21 05:37:29 +00003305 " improve contrast by 'stretching with saturation'",
cristy3ed852e2009-09-05 21:47:34 +00003306 "-liquid-rescale geometry",
3307 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003308 "-median geometry apply a median filter to the image",
cristyb4671fc2012-11-04 15:02:10 +00003309 "-mode geometry make each pixel the 'predominant color' of the",
3310 " neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003311 "-modulate value vary the brightness, saturation, and hue",
3312 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003313 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003314 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003315 "-motion-blur geometry",
3316 " simulate motion blur",
3317 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003318 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003319 "-normalize transform image to span the full range of colors",
3320 "-opaque color change this color to the fill color",
3321 "-ordered-dither NxN",
3322 " add a noise pattern to the image with specific",
3323 " amplitudes",
3324 "-paint radius simulate an oil painting",
cristy3d629e22012-11-04 01:32:13 +00003325 "-perceptible epsilon",
cristyb4671fc2012-11-04 15:02:10 +00003326 " pixel value less than |epsilon| become epsilon or",
3327 " -epsilon",
cristy3ed852e2009-09-05 21:47:34 +00003328 "-polaroid angle simulate a Polaroid picture",
3329 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003330 "-profile filename add, delete, or apply an image profile",
3331 "-quantize colorspace reduce colors in this colorspace",
3332 "-radial-blur angle radial blur the image",
3333 "-raise value lighten/darken image edges to create a 3-D effect",
3334 "-random-threshold low,high",
3335 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003336 "-region geometry apply options to a portion of the image",
3337 "-render render vector graphics",
3338 "-repage geometry size and location of an image canvas",
3339 "-resample geometry change the resolution of an image",
3340 "-resize geometry resize the image",
3341 "-roll geometry roll an image vertically or horizontally",
3342 "-rotate degrees apply Paeth rotation to the image",
3343 "-sample geometry scale image with pixel sampling",
3344 "-scale geometry scale the image",
3345 "-segment values segment an image",
3346 "-selective-blur geometry",
3347 " selectively blur pixels within a contrast threshold",
3348 "-sepia-tone threshold",
3349 " simulate a sepia-toned photo",
3350 "-set property value set an image property",
3351 "-shade degrees shade the image using a distant light source",
3352 "-shadow geometry simulate an image shadow",
3353 "-sharpen geometry sharpen the image",
3354 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003355 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003356 "-sigmoidal-contrast geometry",
cristyb4671fc2012-11-04 15:02:10 +00003357 " increase the contrast without saturating highlights or",
3358 " shadows",
cristy3ed852e2009-09-05 21:47:34 +00003359 "-sketch geometry simulate a pencil sketch",
3360 "-solarize threshold negate all pixels above the threshold level",
3361 "-sparse-color method args",
3362 " fill in a image based on a few color points",
3363 "-splice geometry splice the background color into the image",
3364 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003365 "-statistic type radius",
3366 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003367 "-strip strip image of all profiles and comments",
3368 "-swirl degrees swirl image pixels about the center",
3369 "-threshold value threshold the image",
3370 "-thumbnail geometry create a thumbnail of the image",
3371 "-tile filename tile image when filling a graphic primitive",
3372 "-tint value tint the image with the fill color",
3373 "-transform affine transform image",
3374 "-transparent color make this color transparent within the image",
3375 "-transpose flip image vertically and rotate 90 degrees",
3376 "-transverse flop image horizontally and rotate 270 degrees",
3377 "-trim trim image edges",
3378 "-type type image type",
3379 "-unique-colors discard all but one of any pixel color",
3380 "-unsharp geometry sharpen the image",
3381 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003382 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003383 "-white-threshold value",
3384 " force all pixels above the threshold into white",
3385 (char *) NULL
3386 },
3387 *sequence_operators[]=
3388 {
cristy4285d782011-02-09 20:12:28 +00003389 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003390 "-clut apply a color lookup table to the image",
3391 "-coalesce merge a sequence of images",
3392 "-combine combine a sequence of images",
3393 "-composite composite image",
3394 "-crop geometry cut out a rectangular region of the image",
3395 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003396 "-evaluate-sequence operator",
3397 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003398 "-flatten flatten a sequence of images",
3399 "-fx expression apply mathematical expression to an image channel(s)",
3400 "-hald-clut apply a Hald color lookup table to the image",
3401 "-morph value morph an image sequence",
3402 "-mosaic create a mosaic from an image sequence",
cristy8cdfb342012-11-11 21:44:36 +00003403 "-poly terms build a polynomial from the image sequence and the corresponding",
cristydbc2da92012-11-12 13:16:07 +00003404 " terms (coefficients and degree pairs).",
cristy36b94822010-05-20 12:48:16 +00003405 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003406 "-process arguments process the image with a custom image filter",
cristy4285d782011-02-09 20:12:28 +00003407 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003408 "-write filename write images to this file",
3409 (char *) NULL
3410 },
3411 *settings[]=
3412 {
3413 "-adjoin join images into a single multi-image file",
3414 "-affine matrix affine transform matrix",
3415 "-alpha option activate, deactivate, reset, or set the alpha channel",
3416 "-antialias remove pixel-aliasing",
3417 "-authenticate password",
3418 " decipher image with this password",
3419 "-attenuate value lessen (or intensify) when adding noise to an image",
3420 "-background color background color",
3421 "-bias value add bias when convolving an image",
3422 "-black-point-compensation",
3423 " use black point compensation",
3424 "-blue-primary point chromaticity blue primary point",
3425 "-bordercolor color border color",
3426 "-caption string assign a caption to an image",
3427 "-channel type apply option to select image channels",
3428 "-colors value preferred number of colors in the image",
3429 "-colorspace type alternate image colorspace",
3430 "-comment string annotate image with comment",
3431 "-compose operator set image composite operator",
3432 "-compress type type of pixel compression when writing the image",
anthonyfd706f92012-01-19 04:22:02 +00003433 "-define format:option=value",
cristy3ed852e2009-09-05 21:47:34 +00003434 " define one or more image format options",
3435 "-delay value display the next image after pausing",
3436 "-density geometry horizontal and vertical density of the image",
3437 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003438 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003439 "-display server get image or font from this X server",
3440 "-dispose method layer disposal method",
3441 "-dither method apply error diffusion to image",
3442 "-encoding type text encoding type",
3443 "-endian type endianness (MSB or LSB) of the image",
3444 "-family name render text with this font family",
cristy14154222012-06-15 23:21:49 +00003445 "-features distance analyze image features (e.g. contrast, correlation)",
cristy3ed852e2009-09-05 21:47:34 +00003446 "-fill color color to use when filling a graphic primitive",
3447 "-filter type use this filter when resizing an image",
3448 "-font name render text with this font",
anthonyfd706f92012-01-19 04:22:02 +00003449 "-format \"string\" output formatted image characteristics",
cristy3ed852e2009-09-05 21:47:34 +00003450 "-fuzz distance colors within this distance are considered equal",
3451 "-gravity type horizontal and vertical text placement",
3452 "-green-primary point chromaticity green primary point",
3453 "-intent type type of rendering intent when managing the image color",
3454 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003455 "-interline-spacing value",
3456 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003457 "-interpolate method pixel color interpolation method",
3458 "-interword-spacing value",
3459 " set the space between two words",
3460 "-kerning value set the space between two letters",
3461 "-label string assign a label to an image",
3462 "-limit type value pixel cache resource limit",
3463 "-loop iterations add Netscape loop extension to your GIF animation",
3464 "-mask filename associate a mask with the image",
3465 "-mattecolor color frame color",
3466 "-monitor monitor progress",
3467 "-orient type image orientation",
3468 "-page geometry size and location of an image canvas (setting)",
3469 "-ping efficiently determine image attributes",
3470 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003471 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003472 "-preview type image preview type",
3473 "-quality value JPEG/MIFF/PNG compression level",
3474 "-quiet suppress all warning messages",
3475 "-red-primary point chromaticity red primary point",
3476 "-regard-warnings pay attention to warning messages",
3477 "-remap filename transform image colors to match this set of colors",
3478 "-respect-parentheses settings remain in effect until parenthesis boundary",
3479 "-sampling-factor geometry",
3480 " horizontal and vertical sampling factor",
3481 "-scene value image scene number",
3482 "-seed value seed a new sequence of pseudo-random numbers",
3483 "-size geometry width and height of image",
3484 "-stretch type render text with this font stretch",
3485 "-stroke color graphic primitive stroke color",
3486 "-strokewidth value graphic primitive stroke width",
3487 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003488 "-synchronize synchronize image to storage device",
3489 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003490 "-texture filename name of texture to tile onto the image background",
3491 "-tile-offset geometry",
3492 " tile offset",
3493 "-treedepth value color tree depth",
3494 "-transparent-color color",
3495 " transparent color",
3496 "-undercolor color annotation bounding box color",
3497 "-units type the units of image resolution",
3498 "-verbose print detailed information about the image",
3499 "-view FlashPix viewing transforms",
3500 "-virtual-pixel method",
3501 " virtual pixel access method",
3502 "-weight type render text with this font weight",
3503 "-white-point point chromaticity white point",
3504 (char *) NULL
3505 },
3506 *stack_operators[]=
3507 {
anthonyb69c4b32011-03-23 04:37:44 +00003508 "-delete indexes delete the image from the image sequence",
3509 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003510 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003511 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003512 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003513 "-swap indexes swap two images in the image sequence",
3514 (char *) NULL
3515 };
3516
3517 const char
3518 **p;
3519
cristy4f7a6132012-12-23 00:35:19 +00003520 ListMagickVersion(stdout);
cristy3ed852e2009-09-05 21:47:34 +00003521 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3522 GetClientName());
3523 (void) printf("\nImage Settings:\n");
3524 for (p=settings; *p != (char *) NULL; p++)
3525 (void) printf(" %s\n",*p);
3526 (void) printf("\nImage Operators:\n");
3527 for (p=operators; *p != (char *) NULL; p++)
3528 (void) printf(" %s\n",*p);
cristy87c02f42012-02-24 00:19:10 +00003529 (void) printf("\nImage Channel Operators:\n");
3530 for (p=channel_operators; *p != (char *) NULL; p++)
3531 (void) printf(" %s\n",*p);
cristy3ed852e2009-09-05 21:47:34 +00003532 (void) printf("\nImage Sequence Operators:\n");
3533 for (p=sequence_operators; *p != (char *) NULL; p++)
3534 (void) printf(" %s\n",*p);
3535 (void) printf("\nImage Stack Operators:\n");
3536 for (p=stack_operators; *p != (char *) NULL; p++)
3537 (void) printf(" %s\n",*p);
3538 (void) printf("\nMiscellaneous Options:\n");
3539 for (p=miscellaneous; *p != (char *) NULL; p++)
3540 (void) printf(" %s\n",*p);
3541 (void) printf(
anthonyfd706f92012-01-19 04:22:02 +00003542 "\nBy default, the image format of 'file' is determined by its magic\n");
cristy3ed852e2009-09-05 21:47:34 +00003543 (void) printf(
3544 "number. To specify a particular image format, precede the filename\n");
3545 (void) printf(
3546 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3547 (void) printf(
3548 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3549 (void) printf("'-' for standard input or output.\n");
3550 return(MagickFalse);
3551}
3552
3553WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3554 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3555{
3556#define DestroyMogrify() \
3557{ \
3558 if (format != (char *) NULL) \
3559 format=DestroyString(format); \
3560 if (path != (char *) NULL) \
3561 path=DestroyString(path); \
3562 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003563 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003564 argv[i]=DestroyString(argv[i]); \
3565 argv=(char **) RelinquishMagickMemory(argv); \
3566}
3567#define ThrowMogrifyException(asperity,tag,option) \
3568{ \
cristyefe601c2013-01-05 17:51:12 +00003569 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
cristy3ed852e2009-09-05 21:47:34 +00003570 option); \
3571 DestroyMogrify(); \
3572 return(MagickFalse); \
3573}
3574#define ThrowMogrifyInvalidArgumentException(option,argument) \
3575{ \
3576 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
anthonye5b39652012-04-21 05:37:29 +00003577 "InvalidArgument","'%s': %s",argument,option); \
cristy3ed852e2009-09-05 21:47:34 +00003578 DestroyMogrify(); \
3579 return(MagickFalse); \
3580}
3581
3582 char
3583 *format,
3584 *option,
3585 *path;
3586
3587 Image
3588 *image;
3589
3590 ImageStack
3591 image_stack[MaxImageStackDepth+1];
3592
cristy3ed852e2009-09-05 21:47:34 +00003593 MagickBooleanType
3594 global_colormap;
3595
3596 MagickBooleanType
3597 fire,
cristyebbcfea2011-02-25 02:43:54 +00003598 pend,
3599 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003600
3601 MagickStatusType
3602 status;
3603
cristyebbcfea2011-02-25 02:43:54 +00003604 register ssize_t
3605 i;
3606
3607 ssize_t
3608 j,
3609 k;
3610
cristy3ed852e2009-09-05 21:47:34 +00003611 /*
3612 Set defaults.
3613 */
3614 assert(image_info != (ImageInfo *) NULL);
3615 assert(image_info->signature == MagickSignature);
3616 if (image_info->debug != MagickFalse)
3617 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3618 assert(exception != (ExceptionInfo *) NULL);
3619 if (argc == 2)
3620 {
3621 option=argv[1];
3622 if ((LocaleCompare("version",option+1) == 0) ||
3623 (LocaleCompare("-version",option+1) == 0))
3624 {
cristy4f7a6132012-12-23 00:35:19 +00003625 ListMagickVersion(stdout);
cristy3ed852e2009-09-05 21:47:34 +00003626 return(MagickFalse);
3627 }
3628 }
3629 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003630 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003631 format=(char *) NULL;
3632 path=(char *) NULL;
3633 global_colormap=MagickFalse;
3634 k=0;
3635 j=1;
3636 NewImageStack();
3637 option=(char *) NULL;
3638 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003639 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003640 status=MagickTrue;
3641 /*
3642 Parse command line.
3643 */
3644 ReadCommandlLine(argc,&argv);
3645 status=ExpandFilenames(&argc,&argv);
3646 if (status == MagickFalse)
3647 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3648 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003649 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003650 {
3651 option=argv[i];
3652 if (LocaleCompare(option,"(") == 0)
3653 {
3654 FireImageStack(MagickFalse,MagickTrue,pend);
3655 if (k == MaxImageStackDepth)
3656 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3657 option);
3658 PushImageStack();
3659 continue;
3660 }
3661 if (LocaleCompare(option,")") == 0)
3662 {
3663 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3664 if (k == 0)
3665 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3666 PopImageStack();
3667 continue;
3668 }
cristy042ee782011-04-22 18:48:30 +00003669 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003670 {
3671 char
3672 backup_filename[MaxTextExtent],
3673 *filename;
3674
3675 Image
3676 *images;
3677
3678 /*
3679 Option is a file name: begin by reading image from specified file.
3680 */
3681 FireImageStack(MagickFalse,MagickFalse,pend);
3682 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003683 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003684 filename=argv[++i];
cristy1b58f252012-03-01 01:41:41 +00003685 images=ReadImages(image_info,filename,exception);
cristy3ed852e2009-09-05 21:47:34 +00003686 status&=(images != (Image *) NULL) &&
3687 (exception->severity < ErrorException);
3688 if (images == (Image *) NULL)
3689 continue;
cristydaa76602010-06-30 13:05:11 +00003690 if (format != (char *) NULL)
3691 (void) CopyMagickString(images->filename,images->magick_filename,
3692 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003693 if (path != (char *) NULL)
3694 {
3695 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003696 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003697 path,*DirectorySeparator,filename);
3698 }
3699 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003700 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003701 AppendImageStack(images);
3702 FinalizeImageSettings(image_info,image,MagickFalse);
3703 if (global_colormap != MagickFalse)
3704 {
3705 QuantizeInfo
3706 *quantize_info;
3707
3708 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003709 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003710 quantize_info=DestroyQuantizeInfo(quantize_info);
3711 }
3712 *backup_filename='\0';
3713 if ((LocaleCompare(image->filename,"-") != 0) &&
3714 (IsPathWritable(image->filename) != MagickFalse))
3715 {
cristybb503372010-05-27 20:51:26 +00003716 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003717 i;
3718
3719 /*
3720 Rename image file as backup.
3721 */
3722 (void) CopyMagickString(backup_filename,image->filename,
3723 MaxTextExtent);
3724 for (i=0; i < 6; i++)
3725 {
3726 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3727 if (IsPathAccessible(backup_filename) == MagickFalse)
3728 break;
3729 }
3730 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003731 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003732 *backup_filename='\0';
3733 }
3734 /*
3735 Write transmogrified image to disk.
3736 */
3737 image_info->synchronize=MagickTrue;
3738 status&=WriteImages(image_info,image,image->filename,exception);
3739 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003740 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003741 RemoveAllImageStack();
3742 continue;
3743 }
3744 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3745 switch (*(option+1))
3746 {
3747 case 'a':
3748 {
3749 if (LocaleCompare("adaptive-blur",option+1) == 0)
3750 {
3751 i++;
cristybb503372010-05-27 20:51:26 +00003752 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003753 ThrowMogrifyException(OptionError,"MissingArgument",option);
3754 if (IsGeometry(argv[i]) == MagickFalse)
3755 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3756 break;
3757 }
3758 if (LocaleCompare("adaptive-resize",option+1) == 0)
3759 {
3760 i++;
cristybb503372010-05-27 20:51:26 +00003761 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003762 ThrowMogrifyException(OptionError,"MissingArgument",option);
3763 if (IsGeometry(argv[i]) == MagickFalse)
3764 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3765 break;
3766 }
3767 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3768 {
3769 i++;
cristybb503372010-05-27 20:51:26 +00003770 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003771 ThrowMogrifyException(OptionError,"MissingArgument",option);
3772 if (IsGeometry(argv[i]) == MagickFalse)
3773 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3774 break;
3775 }
3776 if (LocaleCompare("affine",option+1) == 0)
3777 {
3778 if (*option == '+')
3779 break;
3780 i++;
cristybb503372010-05-27 20:51:26 +00003781 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003782 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003783 break;
3784 }
3785 if (LocaleCompare("alpha",option+1) == 0)
3786 {
cristybb503372010-05-27 20:51:26 +00003787 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003788 type;
3789
3790 if (*option == '+')
3791 break;
3792 i++;
cristybb503372010-05-27 20:51:26 +00003793 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003794 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy288a3532012-08-28 00:19:44 +00003795 type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003796 if (type < 0)
cristyb15b06c2012-08-28 11:36:48 +00003797 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelOption",
cristy3ed852e2009-09-05 21:47:34 +00003798 argv[i]);
3799 break;
3800 }
3801 if (LocaleCompare("annotate",option+1) == 0)
3802 {
3803 if (*option == '+')
3804 break;
3805 i++;
cristybb503372010-05-27 20:51:26 +00003806 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003807 ThrowMogrifyException(OptionError,"MissingArgument",option);
3808 if (IsGeometry(argv[i]) == MagickFalse)
3809 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003811 ThrowMogrifyException(OptionError,"MissingArgument",option);
3812 i++;
3813 break;
3814 }
3815 if (LocaleCompare("antialias",option+1) == 0)
3816 break;
3817 if (LocaleCompare("append",option+1) == 0)
3818 break;
3819 if (LocaleCompare("attenuate",option+1) == 0)
3820 {
3821 if (*option == '+')
3822 break;
3823 i++;
cristybb503372010-05-27 20:51:26 +00003824 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003825 ThrowMogrifyException(OptionError,"MissingArgument",option);
3826 if (IsGeometry(argv[i]) == MagickFalse)
3827 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3828 break;
3829 }
3830 if (LocaleCompare("authenticate",option+1) == 0)
3831 {
3832 if (*option == '+')
3833 break;
3834 i++;
cristybb503372010-05-27 20:51:26 +00003835 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003836 ThrowMogrifyException(OptionError,"MissingArgument",option);
3837 break;
3838 }
3839 if (LocaleCompare("auto-gamma",option+1) == 0)
3840 break;
3841 if (LocaleCompare("auto-level",option+1) == 0)
3842 break;
3843 if (LocaleCompare("auto-orient",option+1) == 0)
3844 break;
3845 if (LocaleCompare("average",option+1) == 0)
3846 break;
3847 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3848 }
3849 case 'b':
3850 {
3851 if (LocaleCompare("background",option+1) == 0)
3852 {
3853 if (*option == '+')
3854 break;
3855 i++;
cristybb503372010-05-27 20:51:26 +00003856 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003857 ThrowMogrifyException(OptionError,"MissingArgument",option);
3858 break;
3859 }
3860 if (LocaleCompare("bias",option+1) == 0)
3861 {
3862 if (*option == '+')
3863 break;
3864 i++;
cristybb503372010-05-27 20:51:26 +00003865 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003866 ThrowMogrifyException(OptionError,"MissingArgument",option);
3867 if (IsGeometry(argv[i]) == MagickFalse)
3868 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3869 break;
3870 }
3871 if (LocaleCompare("black-point-compensation",option+1) == 0)
3872 break;
3873 if (LocaleCompare("black-threshold",option+1) == 0)
3874 {
3875 if (*option == '+')
3876 break;
3877 i++;
cristybb503372010-05-27 20:51:26 +00003878 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003879 ThrowMogrifyException(OptionError,"MissingArgument",option);
3880 if (IsGeometry(argv[i]) == MagickFalse)
3881 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3882 break;
3883 }
3884 if (LocaleCompare("blue-primary",option+1) == 0)
3885 {
3886 if (*option == '+')
3887 break;
3888 i++;
cristybb503372010-05-27 20:51:26 +00003889 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003890 ThrowMogrifyException(OptionError,"MissingArgument",option);
3891 if (IsGeometry(argv[i]) == MagickFalse)
3892 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3893 break;
3894 }
3895 if (LocaleCompare("blue-shift",option+1) == 0)
3896 {
3897 i++;
cristybb503372010-05-27 20:51:26 +00003898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003899 ThrowMogrifyException(OptionError,"MissingArgument",option);
3900 if (IsGeometry(argv[i]) == MagickFalse)
3901 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3902 break;
3903 }
3904 if (LocaleCompare("blur",option+1) == 0)
3905 {
3906 i++;
cristybb503372010-05-27 20:51:26 +00003907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003908 ThrowMogrifyException(OptionError,"MissingArgument",option);
3909 if (IsGeometry(argv[i]) == MagickFalse)
3910 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3911 break;
3912 }
3913 if (LocaleCompare("border",option+1) == 0)
3914 {
3915 if (*option == '+')
3916 break;
3917 i++;
cristybb503372010-05-27 20:51:26 +00003918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003919 ThrowMogrifyException(OptionError,"MissingArgument",option);
3920 if (IsGeometry(argv[i]) == MagickFalse)
3921 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3922 break;
3923 }
3924 if (LocaleCompare("bordercolor",option+1) == 0)
3925 {
3926 if (*option == '+')
3927 break;
3928 i++;
cristybb503372010-05-27 20:51:26 +00003929 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003930 ThrowMogrifyException(OptionError,"MissingArgument",option);
3931 break;
3932 }
3933 if (LocaleCompare("box",option+1) == 0)
3934 {
3935 if (*option == '+')
3936 break;
3937 i++;
cristybb503372010-05-27 20:51:26 +00003938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003939 ThrowMogrifyException(OptionError,"MissingArgument",option);
3940 break;
3941 }
cristya28d6b82010-01-11 20:03:47 +00003942 if (LocaleCompare("brightness-contrast",option+1) == 0)
3943 {
3944 i++;
cristybb503372010-05-27 20:51:26 +00003945 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003946 ThrowMogrifyException(OptionError,"MissingArgument",option);
3947 if (IsGeometry(argv[i]) == MagickFalse)
3948 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3949 break;
3950 }
cristy3ed852e2009-09-05 21:47:34 +00003951 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3952 }
3953 case 'c':
3954 {
3955 if (LocaleCompare("cache",option+1) == 0)
3956 {
3957 if (*option == '+')
3958 break;
3959 i++;
cristybb503372010-05-27 20:51:26 +00003960 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003961 ThrowMogrifyException(OptionError,"MissingArgument",option);
3962 if (IsGeometry(argv[i]) == MagickFalse)
3963 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3964 break;
3965 }
3966 if (LocaleCompare("caption",option+1) == 0)
3967 {
3968 if (*option == '+')
3969 break;
3970 i++;
cristybb503372010-05-27 20:51:26 +00003971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003972 ThrowMogrifyException(OptionError,"MissingArgument",option);
3973 break;
3974 }
3975 if (LocaleCompare("channel",option+1) == 0)
3976 {
cristybb503372010-05-27 20:51:26 +00003977 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003978 channel;
3979
3980 if (*option == '+')
3981 break;
3982 i++;
cristybb503372010-05-27 20:51:26 +00003983 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003984 ThrowMogrifyException(OptionError,"MissingArgument",option);
3985 channel=ParseChannelOption(argv[i]);
3986 if (channel < 0)
3987 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3988 argv[i]);
3989 break;
3990 }
cristy5f257b22012-03-07 00:27:29 +00003991 if (LocaleCompare("channel-fx",option+1) == 0)
cristy87c02f42012-02-24 00:19:10 +00003992 {
3993 ssize_t
3994 channel;
3995
3996 if (*option == '+')
3997 break;
3998 i++;
3999 if (i == (ssize_t) (argc-1))
4000 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy953c4bd2012-02-24 01:04:04 +00004001 channel=ParsePixelChannelOption(argv[i]);
cristy87c02f42012-02-24 00:19:10 +00004002 if (channel < 0)
4003 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4004 argv[i]);
4005 break;
4006 }
cristy3ed852e2009-09-05 21:47:34 +00004007 if (LocaleCompare("cdl",option+1) == 0)
4008 {
4009 if (*option == '+')
4010 break;
4011 i++;
cristybb503372010-05-27 20:51:26 +00004012 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004013 ThrowMogrifyException(OptionError,"MissingArgument",option);
4014 break;
4015 }
4016 if (LocaleCompare("charcoal",option+1) == 0)
4017 {
4018 if (*option == '+')
4019 break;
4020 i++;
cristybb503372010-05-27 20:51:26 +00004021 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004022 ThrowMogrifyException(OptionError,"MissingArgument",option);
4023 if (IsGeometry(argv[i]) == MagickFalse)
4024 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4025 break;
4026 }
4027 if (LocaleCompare("chop",option+1) == 0)
4028 {
4029 if (*option == '+')
4030 break;
4031 i++;
cristybb503372010-05-27 20:51:26 +00004032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004033 ThrowMogrifyException(OptionError,"MissingArgument",option);
4034 if (IsGeometry(argv[i]) == MagickFalse)
4035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4036 break;
4037 }
cristy1eb45dd2009-09-25 16:38:06 +00004038 if (LocaleCompare("clamp",option+1) == 0)
4039 break;
4040 if (LocaleCompare("clip",option+1) == 0)
4041 break;
cristy3ed852e2009-09-05 21:47:34 +00004042 if (LocaleCompare("clip-mask",option+1) == 0)
4043 {
4044 if (*option == '+')
4045 break;
4046 i++;
cristybb503372010-05-27 20:51:26 +00004047 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004048 ThrowMogrifyException(OptionError,"MissingArgument",option);
4049 break;
4050 }
4051 if (LocaleCompare("clut",option+1) == 0)
4052 break;
4053 if (LocaleCompare("coalesce",option+1) == 0)
4054 break;
4055 if (LocaleCompare("colorize",option+1) == 0)
4056 {
4057 if (*option == '+')
4058 break;
4059 i++;
cristybb503372010-05-27 20:51:26 +00004060 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004061 ThrowMogrifyException(OptionError,"MissingArgument",option);
4062 if (IsGeometry(argv[i]) == MagickFalse)
4063 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4064 break;
4065 }
cristye6365592010-04-02 17:31:23 +00004066 if (LocaleCompare("color-matrix",option+1) == 0)
4067 {
cristyb6bd4ad2010-08-08 01:12:27 +00004068 KernelInfo
4069 *kernel_info;
4070
cristye6365592010-04-02 17:31:23 +00004071 if (*option == '+')
4072 break;
4073 i++;
cristybb503372010-05-27 20:51:26 +00004074 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004075 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004076 kernel_info=AcquireKernelInfo(argv[i]);
4077 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004078 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004079 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004080 break;
4081 }
cristy3ed852e2009-09-05 21:47:34 +00004082 if (LocaleCompare("colors",option+1) == 0)
4083 {
4084 if (*option == '+')
4085 break;
4086 i++;
cristybb503372010-05-27 20:51:26 +00004087 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004088 ThrowMogrifyException(OptionError,"MissingArgument",option);
4089 if (IsGeometry(argv[i]) == MagickFalse)
4090 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4091 break;
4092 }
4093 if (LocaleCompare("colorspace",option+1) == 0)
4094 {
cristybb503372010-05-27 20:51:26 +00004095 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004096 colorspace;
4097
4098 if (*option == '+')
4099 break;
4100 i++;
cristybb503372010-05-27 20:51:26 +00004101 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004102 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004103 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004104 argv[i]);
4105 if (colorspace < 0)
4106 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4107 argv[i]);
4108 break;
4109 }
4110 if (LocaleCompare("combine",option+1) == 0)
cristy46f354c2012-07-04 13:31:29 +00004111 {
4112 ssize_t
4113 colorspace;
4114
4115 if (*option == '+')
4116 break;
4117 i++;
4118 if (i == (ssize_t) argc)
4119 ThrowMogrifyException(OptionError,"MissingArgument",option);
4120 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4121 argv[i]);
4122 if (colorspace < 0)
4123 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4124 argv[i]);
4125 break;
4126 }
cristy3ed852e2009-09-05 21:47:34 +00004127 if (LocaleCompare("comment",option+1) == 0)
4128 {
4129 if (*option == '+')
4130 break;
4131 i++;
cristybb503372010-05-27 20:51:26 +00004132 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004133 ThrowMogrifyException(OptionError,"MissingArgument",option);
4134 break;
4135 }
4136 if (LocaleCompare("composite",option+1) == 0)
4137 break;
4138 if (LocaleCompare("compress",option+1) == 0)
4139 {
cristybb503372010-05-27 20:51:26 +00004140 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004141 compress;
4142
4143 if (*option == '+')
4144 break;
4145 i++;
cristybb503372010-05-27 20:51:26 +00004146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004147 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004148 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004149 argv[i]);
4150 if (compress < 0)
4151 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4152 argv[i]);
4153 break;
4154 }
cristy22879752009-10-25 23:55:40 +00004155 if (LocaleCompare("concurrent",option+1) == 0)
4156 break;
cristy3ed852e2009-09-05 21:47:34 +00004157 if (LocaleCompare("contrast",option+1) == 0)
4158 break;
4159 if (LocaleCompare("contrast-stretch",option+1) == 0)
4160 {
4161 i++;
cristybb503372010-05-27 20:51:26 +00004162 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004163 ThrowMogrifyException(OptionError,"MissingArgument",option);
4164 if (IsGeometry(argv[i]) == MagickFalse)
4165 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4166 break;
4167 }
4168 if (LocaleCompare("convolve",option+1) == 0)
4169 {
cristyb6bd4ad2010-08-08 01:12:27 +00004170 KernelInfo
4171 *kernel_info;
4172
cristy3ed852e2009-09-05 21:47:34 +00004173 if (*option == '+')
4174 break;
4175 i++;
cristybb503372010-05-27 20:51:26 +00004176 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004177 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004178 kernel_info=AcquireKernelInfo(argv[i]);
4179 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004180 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004181 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004182 break;
4183 }
4184 if (LocaleCompare("crop",option+1) == 0)
4185 {
4186 if (*option == '+')
4187 break;
4188 i++;
cristybb503372010-05-27 20:51:26 +00004189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004190 ThrowMogrifyException(OptionError,"MissingArgument",option);
4191 if (IsGeometry(argv[i]) == MagickFalse)
4192 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4193 break;
4194 }
4195 if (LocaleCompare("cycle",option+1) == 0)
4196 {
4197 if (*option == '+')
4198 break;
4199 i++;
cristybb503372010-05-27 20:51:26 +00004200 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004201 ThrowMogrifyException(OptionError,"MissingArgument",option);
4202 if (IsGeometry(argv[i]) == MagickFalse)
4203 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4204 break;
4205 }
4206 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4207 }
4208 case 'd':
4209 {
4210 if (LocaleCompare("decipher",option+1) == 0)
4211 {
4212 if (*option == '+')
4213 break;
4214 i++;
cristybb503372010-05-27 20:51:26 +00004215 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004216 ThrowMogrifyException(OptionError,"MissingArgument",option);
4217 break;
4218 }
4219 if (LocaleCompare("deconstruct",option+1) == 0)
4220 break;
4221 if (LocaleCompare("debug",option+1) == 0)
4222 {
cristybb503372010-05-27 20:51:26 +00004223 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004224 event;
4225
4226 if (*option == '+')
4227 break;
4228 i++;
cristybb503372010-05-27 20:51:26 +00004229 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004230 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004231 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004232 if (event < 0)
4233 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4234 argv[i]);
4235 (void) SetLogEventMask(argv[i]);
4236 break;
4237 }
4238 if (LocaleCompare("define",option+1) == 0)
4239 {
4240 i++;
cristybb503372010-05-27 20:51:26 +00004241 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004242 ThrowMogrifyException(OptionError,"MissingArgument",option);
4243 if (*option == '+')
4244 {
4245 const char
4246 *define;
4247
4248 define=GetImageOption(image_info,argv[i]);
4249 if (define == (const char *) NULL)
4250 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4251 break;
4252 }
4253 break;
4254 }
4255 if (LocaleCompare("delay",option+1) == 0)
4256 {
4257 if (*option == '+')
4258 break;
4259 i++;
cristybb503372010-05-27 20:51:26 +00004260 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004261 ThrowMogrifyException(OptionError,"MissingArgument",option);
4262 if (IsGeometry(argv[i]) == MagickFalse)
4263 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4264 break;
4265 }
cristyecb10ff2011-03-22 13:14:03 +00004266 if (LocaleCompare("delete",option+1) == 0)
4267 {
4268 if (*option == '+')
4269 break;
4270 i++;
4271 if (i == (ssize_t) (argc-1))
4272 ThrowMogrifyException(OptionError,"MissingArgument",option);
4273 if (IsGeometry(argv[i]) == MagickFalse)
4274 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4275 break;
4276 }
cristy3ed852e2009-09-05 21:47:34 +00004277 if (LocaleCompare("density",option+1) == 0)
4278 {
4279 if (*option == '+')
4280 break;
4281 i++;
cristybb503372010-05-27 20:51:26 +00004282 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004283 ThrowMogrifyException(OptionError,"MissingArgument",option);
4284 if (IsGeometry(argv[i]) == MagickFalse)
4285 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4286 break;
4287 }
4288 if (LocaleCompare("depth",option+1) == 0)
4289 {
4290 if (*option == '+')
4291 break;
4292 i++;
cristybb503372010-05-27 20:51:26 +00004293 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004294 ThrowMogrifyException(OptionError,"MissingArgument",option);
4295 if (IsGeometry(argv[i]) == MagickFalse)
4296 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4297 break;
4298 }
4299 if (LocaleCompare("deskew",option+1) == 0)
4300 {
4301 if (*option == '+')
4302 break;
4303 i++;
cristybb503372010-05-27 20:51:26 +00004304 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004305 ThrowMogrifyException(OptionError,"MissingArgument",option);
4306 if (IsGeometry(argv[i]) == MagickFalse)
4307 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4308 break;
4309 }
4310 if (LocaleCompare("despeckle",option+1) == 0)
4311 break;
4312 if (LocaleCompare("dft",option+1) == 0)
4313 break;
cristyc9b12952010-03-28 01:12:28 +00004314 if (LocaleCompare("direction",option+1) == 0)
4315 {
cristybb503372010-05-27 20:51:26 +00004316 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004317 direction;
4318
4319 if (*option == '+')
4320 break;
4321 i++;
cristybb503372010-05-27 20:51:26 +00004322 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004323 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004324 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004325 argv[i]);
4326 if (direction < 0)
4327 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4328 argv[i]);
4329 break;
4330 }
cristy3ed852e2009-09-05 21:47:34 +00004331 if (LocaleCompare("display",option+1) == 0)
4332 {
4333 if (*option == '+')
4334 break;
4335 i++;
cristybb503372010-05-27 20:51:26 +00004336 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004337 ThrowMogrifyException(OptionError,"MissingArgument",option);
4338 break;
4339 }
4340 if (LocaleCompare("dispose",option+1) == 0)
4341 {
cristybb503372010-05-27 20:51:26 +00004342 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004343 dispose;
4344
4345 if (*option == '+')
4346 break;
4347 i++;
cristybb503372010-05-27 20:51:26 +00004348 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004349 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004350 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004351 if (dispose < 0)
4352 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4353 argv[i]);
4354 break;
4355 }
4356 if (LocaleCompare("distort",option+1) == 0)
4357 {
cristybb503372010-05-27 20:51:26 +00004358 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004359 op;
4360
4361 i++;
cristybb503372010-05-27 20:51:26 +00004362 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004363 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004364 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004365 if (op < 0)
4366 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4367 argv[i]);
4368 i++;
cristybb503372010-05-27 20:51:26 +00004369 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004370 ThrowMogrifyException(OptionError,"MissingArgument",option);
4371 break;
4372 }
4373 if (LocaleCompare("dither",option+1) == 0)
4374 {
cristybb503372010-05-27 20:51:26 +00004375 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004376 method;
4377
4378 if (*option == '+')
4379 break;
4380 i++;
cristybb503372010-05-27 20:51:26 +00004381 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004382 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004383 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004384 if (method < 0)
4385 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4386 argv[i]);
4387 break;
4388 }
4389 if (LocaleCompare("draw",option+1) == 0)
4390 {
4391 if (*option == '+')
4392 break;
4393 i++;
cristybb503372010-05-27 20:51:26 +00004394 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004395 ThrowMogrifyException(OptionError,"MissingArgument",option);
4396 break;
4397 }
cristyecb10ff2011-03-22 13:14:03 +00004398 if (LocaleCompare("duplicate",option+1) == 0)
4399 {
4400 if (*option == '+')
4401 break;
4402 i++;
4403 if (i == (ssize_t) (argc-1))
4404 ThrowMogrifyException(OptionError,"MissingArgument",option);
4405 if (IsGeometry(argv[i]) == MagickFalse)
4406 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4407 break;
4408 }
cristy22879752009-10-25 23:55:40 +00004409 if (LocaleCompare("duration",option+1) == 0)
4410 {
4411 if (*option == '+')
4412 break;
4413 i++;
cristybb503372010-05-27 20:51:26 +00004414 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004415 ThrowMogrifyException(OptionError,"MissingArgument",option);
4416 if (IsGeometry(argv[i]) == MagickFalse)
4417 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4418 break;
4419 }
cristy3ed852e2009-09-05 21:47:34 +00004420 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4421 }
4422 case 'e':
4423 {
4424 if (LocaleCompare("edge",option+1) == 0)
4425 {
4426 if (*option == '+')
4427 break;
4428 i++;
cristybb503372010-05-27 20:51:26 +00004429 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004430 ThrowMogrifyException(OptionError,"MissingArgument",option);
4431 if (IsGeometry(argv[i]) == MagickFalse)
4432 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4433 break;
4434 }
4435 if (LocaleCompare("emboss",option+1) == 0)
4436 {
4437 if (*option == '+')
4438 break;
4439 i++;
cristybb503372010-05-27 20:51:26 +00004440 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004441 ThrowMogrifyException(OptionError,"MissingArgument",option);
4442 if (IsGeometry(argv[i]) == MagickFalse)
4443 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4444 break;
4445 }
4446 if (LocaleCompare("encipher",option+1) == 0)
4447 {
4448 if (*option == '+')
4449 break;
4450 i++;
cristybb503372010-05-27 20:51:26 +00004451 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004452 ThrowMogrifyException(OptionError,"MissingArgument",option);
4453 break;
4454 }
4455 if (LocaleCompare("encoding",option+1) == 0)
4456 {
4457 if (*option == '+')
4458 break;
4459 i++;
cristybb503372010-05-27 20:51:26 +00004460 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004461 ThrowMogrifyException(OptionError,"MissingArgument",option);
4462 break;
4463 }
4464 if (LocaleCompare("endian",option+1) == 0)
4465 {
cristybb503372010-05-27 20:51:26 +00004466 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004467 endian;
4468
4469 if (*option == '+')
4470 break;
4471 i++;
cristybb503372010-05-27 20:51:26 +00004472 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004473 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004474 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004475 if (endian < 0)
4476 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4477 argv[i]);
4478 break;
4479 }
4480 if (LocaleCompare("enhance",option+1) == 0)
4481 break;
4482 if (LocaleCompare("equalize",option+1) == 0)
4483 break;
4484 if (LocaleCompare("evaluate",option+1) == 0)
4485 {
cristybb503372010-05-27 20:51:26 +00004486 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004487 op;
4488
4489 if (*option == '+')
4490 break;
4491 i++;
cristybb503372010-05-27 20:51:26 +00004492 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004493 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004494 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004495 if (op < 0)
4496 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4497 argv[i]);
4498 i++;
cristybb503372010-05-27 20:51:26 +00004499 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004500 ThrowMogrifyException(OptionError,"MissingArgument",option);
4501 if (IsGeometry(argv[i]) == MagickFalse)
4502 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4503 break;
4504 }
cristyd18ae7c2010-03-07 17:39:52 +00004505 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4506 {
cristybb503372010-05-27 20:51:26 +00004507 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004508 op;
4509
4510 if (*option == '+')
4511 break;
4512 i++;
cristybb503372010-05-27 20:51:26 +00004513 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004514 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004515 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004516 if (op < 0)
4517 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4518 argv[i]);
4519 break;
4520 }
cristy3ed852e2009-09-05 21:47:34 +00004521 if (LocaleCompare("extent",option+1) == 0)
4522 {
4523 if (*option == '+')
4524 break;
4525 i++;
cristybb503372010-05-27 20:51:26 +00004526 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004527 ThrowMogrifyException(OptionError,"MissingArgument",option);
4528 if (IsGeometry(argv[i]) == MagickFalse)
4529 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4530 break;
4531 }
4532 if (LocaleCompare("extract",option+1) == 0)
4533 {
4534 if (*option == '+')
4535 break;
4536 i++;
cristybb503372010-05-27 20:51:26 +00004537 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004538 ThrowMogrifyException(OptionError,"MissingArgument",option);
4539 if (IsGeometry(argv[i]) == MagickFalse)
4540 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4541 break;
4542 }
4543 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4544 }
4545 case 'f':
4546 {
4547 if (LocaleCompare("family",option+1) == 0)
4548 {
4549 if (*option == '+')
4550 break;
4551 i++;
cristybb503372010-05-27 20:51:26 +00004552 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004553 ThrowMogrifyException(OptionError,"MissingArgument",option);
4554 break;
4555 }
cristy14154222012-06-15 23:21:49 +00004556 if (LocaleCompare("features",option+1) == 0)
4557 {
4558 if (*option == '+')
4559 break;
4560 i++;
4561 if (i == (ssize_t) (argc-1))
4562 ThrowMogrifyException(OptionError,"MissingArgument",option);
4563 if (IsGeometry(argv[i]) == MagickFalse)
4564 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4565 break;
4566 }
cristy3ed852e2009-09-05 21:47:34 +00004567 if (LocaleCompare("fill",option+1) == 0)
4568 {
4569 if (*option == '+')
4570 break;
4571 i++;
cristybb503372010-05-27 20:51:26 +00004572 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004573 ThrowMogrifyException(OptionError,"MissingArgument",option);
4574 break;
4575 }
4576 if (LocaleCompare("filter",option+1) == 0)
4577 {
cristybb503372010-05-27 20:51:26 +00004578 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004579 filter;
4580
4581 if (*option == '+')
4582 break;
4583 i++;
cristybb503372010-05-27 20:51:26 +00004584 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004585 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004586 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004587 if (filter < 0)
4588 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4589 argv[i]);
4590 break;
4591 }
4592 if (LocaleCompare("flatten",option+1) == 0)
4593 break;
4594 if (LocaleCompare("flip",option+1) == 0)
4595 break;
4596 if (LocaleCompare("flop",option+1) == 0)
4597 break;
4598 if (LocaleCompare("floodfill",option+1) == 0)
4599 {
4600 if (*option == '+')
4601 break;
4602 i++;
cristybb503372010-05-27 20:51:26 +00004603 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004604 ThrowMogrifyException(OptionError,"MissingArgument",option);
4605 if (IsGeometry(argv[i]) == MagickFalse)
4606 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4607 i++;
cristybb503372010-05-27 20:51:26 +00004608 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004609 ThrowMogrifyException(OptionError,"MissingArgument",option);
4610 break;
4611 }
4612 if (LocaleCompare("font",option+1) == 0)
4613 {
4614 if (*option == '+')
4615 break;
4616 i++;
cristybb503372010-05-27 20:51:26 +00004617 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004618 ThrowMogrifyException(OptionError,"MissingArgument",option);
4619 break;
4620 }
4621 if (LocaleCompare("format",option+1) == 0)
4622 {
4623 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4624 (void) CloneString(&format,(char *) NULL);
4625 if (*option == '+')
4626 break;
4627 i++;
cristybb503372010-05-27 20:51:26 +00004628 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004629 ThrowMogrifyException(OptionError,"MissingArgument",option);
4630 (void) CloneString(&format,argv[i]);
4631 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4632 (void) ConcatenateMagickString(image_info->filename,":",
4633 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004634 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004635 if (*image_info->magick == '\0')
4636 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4637 format);
4638 break;
4639 }
4640 if (LocaleCompare("frame",option+1) == 0)
4641 {
4642 if (*option == '+')
4643 break;
4644 i++;
cristybb503372010-05-27 20:51:26 +00004645 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004646 ThrowMogrifyException(OptionError,"MissingArgument",option);
4647 if (IsGeometry(argv[i]) == MagickFalse)
4648 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4649 break;
4650 }
4651 if (LocaleCompare("function",option+1) == 0)
4652 {
cristybb503372010-05-27 20:51:26 +00004653 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004654 op;
4655
4656 if (*option == '+')
4657 break;
4658 i++;
cristybb503372010-05-27 20:51:26 +00004659 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004660 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004661 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004662 if (op < 0)
4663 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4664 i++;
cristybb503372010-05-27 20:51:26 +00004665 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004666 ThrowMogrifyException(OptionError,"MissingArgument",option);
4667 break;
4668 }
4669 if (LocaleCompare("fuzz",option+1) == 0)
4670 {
4671 if (*option == '+')
4672 break;
4673 i++;
cristybb503372010-05-27 20:51:26 +00004674 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004675 ThrowMogrifyException(OptionError,"MissingArgument",option);
4676 if (IsGeometry(argv[i]) == MagickFalse)
4677 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4678 break;
4679 }
4680 if (LocaleCompare("fx",option+1) == 0)
4681 {
4682 if (*option == '+')
4683 break;
4684 i++;
cristybb503372010-05-27 20:51:26 +00004685 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004686 ThrowMogrifyException(OptionError,"MissingArgument",option);
4687 break;
4688 }
4689 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4690 }
4691 case 'g':
4692 {
4693 if (LocaleCompare("gamma",option+1) == 0)
4694 {
4695 i++;
cristybb503372010-05-27 20:51:26 +00004696 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004697 ThrowMogrifyException(OptionError,"MissingArgument",option);
4698 if (IsGeometry(argv[i]) == MagickFalse)
4699 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4700 break;
4701 }
4702 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4703 (LocaleCompare("gaussian",option+1) == 0))
4704 {
4705 i++;
cristybb503372010-05-27 20:51:26 +00004706 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004707 ThrowMogrifyException(OptionError,"MissingArgument",option);
4708 if (IsGeometry(argv[i]) == MagickFalse)
4709 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4710 break;
4711 }
4712 if (LocaleCompare("geometry",option+1) == 0)
4713 {
4714 if (*option == '+')
4715 break;
4716 i++;
cristybb503372010-05-27 20:51:26 +00004717 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004718 ThrowMogrifyException(OptionError,"MissingArgument",option);
4719 if (IsGeometry(argv[i]) == MagickFalse)
4720 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4721 break;
4722 }
4723 if (LocaleCompare("gravity",option+1) == 0)
4724 {
cristybb503372010-05-27 20:51:26 +00004725 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004726 gravity;
4727
4728 if (*option == '+')
4729 break;
4730 i++;
cristybb503372010-05-27 20:51:26 +00004731 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004732 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004733 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004734 if (gravity < 0)
4735 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4736 argv[i]);
4737 break;
4738 }
4739 if (LocaleCompare("green-primary",option+1) == 0)
4740 {
4741 if (*option == '+')
4742 break;
4743 i++;
cristybb503372010-05-27 20:51:26 +00004744 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004745 ThrowMogrifyException(OptionError,"MissingArgument",option);
4746 if (IsGeometry(argv[i]) == MagickFalse)
4747 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4748 break;
4749 }
4750 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4751 }
4752 case 'h':
4753 {
4754 if (LocaleCompare("hald-clut",option+1) == 0)
4755 break;
4756 if ((LocaleCompare("help",option+1) == 0) ||
4757 (LocaleCompare("-help",option+1) == 0))
4758 return(MogrifyUsage());
4759 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4760 }
4761 case 'i':
4762 {
4763 if (LocaleCompare("identify",option+1) == 0)
4764 break;
4765 if (LocaleCompare("idft",option+1) == 0)
4766 break;
4767 if (LocaleCompare("implode",option+1) == 0)
4768 {
4769 if (*option == '+')
4770 break;
4771 i++;
cristybb503372010-05-27 20:51:26 +00004772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004773 ThrowMogrifyException(OptionError,"MissingArgument",option);
4774 if (IsGeometry(argv[i]) == MagickFalse)
4775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4776 break;
4777 }
4778 if (LocaleCompare("intent",option+1) == 0)
4779 {
cristybb503372010-05-27 20:51:26 +00004780 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004781 intent;
4782
4783 if (*option == '+')
4784 break;
4785 i++;
cristybb503372010-05-27 20:51:26 +00004786 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004787 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004788 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004789 if (intent < 0)
4790 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4791 argv[i]);
4792 break;
4793 }
4794 if (LocaleCompare("interlace",option+1) == 0)
4795 {
cristybb503372010-05-27 20:51:26 +00004796 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004797 interlace;
4798
4799 if (*option == '+')
4800 break;
4801 i++;
cristybb503372010-05-27 20:51:26 +00004802 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004803 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004804 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004805 argv[i]);
4806 if (interlace < 0)
4807 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4808 argv[i]);
4809 break;
4810 }
cristyb32b90a2009-09-07 21:45:48 +00004811 if (LocaleCompare("interline-spacing",option+1) == 0)
4812 {
4813 if (*option == '+')
4814 break;
4815 i++;
cristybb503372010-05-27 20:51:26 +00004816 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004817 ThrowMogrifyException(OptionError,"MissingArgument",option);
4818 if (IsGeometry(argv[i]) == MagickFalse)
4819 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4820 break;
4821 }
cristy3ed852e2009-09-05 21:47:34 +00004822 if (LocaleCompare("interpolate",option+1) == 0)
4823 {
cristybb503372010-05-27 20:51:26 +00004824 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004825 interpolate;
4826
4827 if (*option == '+')
4828 break;
4829 i++;
cristybb503372010-05-27 20:51:26 +00004830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004831 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004832 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004833 argv[i]);
4834 if (interpolate < 0)
4835 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4836 argv[i]);
4837 break;
4838 }
4839 if (LocaleCompare("interword-spacing",option+1) == 0)
4840 {
4841 if (*option == '+')
4842 break;
4843 i++;
cristybb503372010-05-27 20:51:26 +00004844 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004845 ThrowMogrifyException(OptionError,"MissingArgument",option);
4846 if (IsGeometry(argv[i]) == MagickFalse)
4847 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4848 break;
4849 }
4850 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4851 }
4852 case 'k':
4853 {
4854 if (LocaleCompare("kerning",option+1) == 0)
4855 {
4856 if (*option == '+')
4857 break;
4858 i++;
cristybb503372010-05-27 20:51:26 +00004859 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004860 ThrowMogrifyException(OptionError,"MissingArgument",option);
4861 if (IsGeometry(argv[i]) == MagickFalse)
4862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4863 break;
4864 }
4865 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4866 }
4867 case 'l':
4868 {
4869 if (LocaleCompare("label",option+1) == 0)
4870 {
4871 if (*option == '+')
4872 break;
4873 i++;
cristybb503372010-05-27 20:51:26 +00004874 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004875 ThrowMogrifyException(OptionError,"MissingArgument",option);
4876 break;
4877 }
4878 if (LocaleCompare("lat",option+1) == 0)
4879 {
4880 if (*option == '+')
4881 break;
4882 i++;
cristybb503372010-05-27 20:51:26 +00004883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004884 ThrowMogrifyException(OptionError,"MissingArgument",option);
4885 if (IsGeometry(argv[i]) == MagickFalse)
4886 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4887 }
4888 if (LocaleCompare("layers",option+1) == 0)
4889 {
cristybb503372010-05-27 20:51:26 +00004890 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004891 type;
4892
4893 if (*option == '+')
4894 break;
4895 i++;
cristybb503372010-05-27 20:51:26 +00004896 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004897 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004898 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004899 if (type < 0)
4900 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4901 argv[i]);
4902 break;
4903 }
4904 if (LocaleCompare("level",option+1) == 0)
4905 {
4906 i++;
cristybb503372010-05-27 20:51:26 +00004907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004908 ThrowMogrifyException(OptionError,"MissingArgument",option);
4909 if (IsGeometry(argv[i]) == MagickFalse)
4910 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4911 break;
4912 }
4913 if (LocaleCompare("level-colors",option+1) == 0)
4914 {
4915 i++;
cristybb503372010-05-27 20:51:26 +00004916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004917 ThrowMogrifyException(OptionError,"MissingArgument",option);
4918 break;
4919 }
cristy3ed852e2009-09-05 21:47:34 +00004920 if (LocaleCompare("limit",option+1) == 0)
4921 {
4922 char
4923 *p;
4924
4925 double
4926 value;
4927
cristybb503372010-05-27 20:51:26 +00004928 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004929 resource;
4930
4931 if (*option == '+')
4932 break;
4933 i++;
cristybb503372010-05-27 20:51:26 +00004934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004935 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004936 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004937 argv[i]);
4938 if (resource < 0)
4939 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4940 argv[i]);
4941 i++;
cristybb503372010-05-27 20:51:26 +00004942 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004943 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00004944 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004945 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004946 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4947 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4948 break;
4949 }
4950 if (LocaleCompare("liquid-rescale",option+1) == 0)
4951 {
4952 i++;
cristybb503372010-05-27 20:51:26 +00004953 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004954 ThrowMogrifyException(OptionError,"MissingArgument",option);
4955 if (IsGeometry(argv[i]) == MagickFalse)
4956 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4957 break;
4958 }
4959 if (LocaleCompare("list",option+1) == 0)
4960 {
cristybb503372010-05-27 20:51:26 +00004961 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004962 list;
4963
4964 if (*option == '+')
4965 break;
4966 i++;
cristybb503372010-05-27 20:51:26 +00004967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004968 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004969 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004970 if (list < 0)
4971 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004972 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004973 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004974 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004975 }
4976 if (LocaleCompare("log",option+1) == 0)
4977 {
4978 if (*option == '+')
4979 break;
4980 i++;
cristybb503372010-05-27 20:51:26 +00004981 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004982 (strchr(argv[i],'%') == (char *) NULL))
4983 ThrowMogrifyException(OptionError,"MissingArgument",option);
4984 break;
4985 }
4986 if (LocaleCompare("loop",option+1) == 0)
4987 {
4988 if (*option == '+')
4989 break;
4990 i++;
cristybb503372010-05-27 20:51:26 +00004991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004992 ThrowMogrifyException(OptionError,"MissingArgument",option);
4993 if (IsGeometry(argv[i]) == MagickFalse)
4994 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4995 break;
4996 }
4997 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4998 }
4999 case 'm':
5000 {
5001 if (LocaleCompare("map",option+1) == 0)
5002 {
5003 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5004 if (*option == '+')
5005 break;
5006 i++;
cristybb503372010-05-27 20:51:26 +00005007 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005008 ThrowMogrifyException(OptionError,"MissingArgument",option);
5009 break;
5010 }
5011 if (LocaleCompare("mask",option+1) == 0)
5012 {
5013 if (*option == '+')
5014 break;
5015 i++;
cristybb503372010-05-27 20:51:26 +00005016 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005017 ThrowMogrifyException(OptionError,"MissingArgument",option);
5018 break;
5019 }
5020 if (LocaleCompare("matte",option+1) == 0)
5021 break;
5022 if (LocaleCompare("mattecolor",option+1) == 0)
5023 {
5024 if (*option == '+')
5025 break;
5026 i++;
cristybb503372010-05-27 20:51:26 +00005027 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005028 ThrowMogrifyException(OptionError,"MissingArgument",option);
5029 break;
5030 }
cristyf40785b2010-03-06 02:27:27 +00005031 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005032 break;
cristyf40785b2010-03-06 02:27:27 +00005033 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005034 break;
cristy3ed852e2009-09-05 21:47:34 +00005035 if (LocaleCompare("modulate",option+1) == 0)
5036 {
5037 if (*option == '+')
5038 break;
5039 i++;
cristybb503372010-05-27 20:51:26 +00005040 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005041 ThrowMogrifyException(OptionError,"MissingArgument",option);
5042 if (IsGeometry(argv[i]) == MagickFalse)
5043 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5044 break;
5045 }
5046 if (LocaleCompare("median",option+1) == 0)
5047 {
5048 if (*option == '+')
5049 break;
5050 i++;
cristybb503372010-05-27 20:51:26 +00005051 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005052 ThrowMogrifyException(OptionError,"MissingArgument",option);
5053 if (IsGeometry(argv[i]) == MagickFalse)
5054 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5055 break;
5056 }
cristy69ec32d2011-02-27 23:57:09 +00005057 if (LocaleCompare("mode",option+1) == 0)
5058 {
5059 if (*option == '+')
5060 break;
5061 i++;
5062 if (i == (ssize_t) argc)
5063 ThrowMogrifyException(OptionError,"MissingArgument",option);
5064 if (IsGeometry(argv[i]) == MagickFalse)
5065 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5066 break;
5067 }
cristy3ed852e2009-09-05 21:47:34 +00005068 if (LocaleCompare("monitor",option+1) == 0)
5069 break;
5070 if (LocaleCompare("monochrome",option+1) == 0)
5071 break;
5072 if (LocaleCompare("morph",option+1) == 0)
5073 {
5074 if (*option == '+')
5075 break;
5076 i++;
cristybb503372010-05-27 20:51:26 +00005077 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005078 ThrowMogrifyException(OptionError,"MissingArgument",option);
5079 if (IsGeometry(argv[i]) == MagickFalse)
5080 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5081 break;
5082 }
anthony29188a82010-01-22 10:12:34 +00005083 if (LocaleCompare("morphology",option+1) == 0)
5084 {
anthony29188a82010-01-22 10:12:34 +00005085 char
5086 token[MaxTextExtent];
5087
cristyb6bd4ad2010-08-08 01:12:27 +00005088 KernelInfo
5089 *kernel_info;
5090
5091 ssize_t
5092 op;
5093
anthony29188a82010-01-22 10:12:34 +00005094 i++;
cristybb503372010-05-27 20:51:26 +00005095 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005096 ThrowMogrifyException(OptionError,"MissingArgument",option);
5097 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005098 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005099 if (op < 0)
5100 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005101 token);
anthony29188a82010-01-22 10:12:34 +00005102 i++;
cristybb503372010-05-27 20:51:26 +00005103 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005104 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005105 kernel_info=AcquireKernelInfo(argv[i]);
5106 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005107 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005108 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005109 break;
5110 }
cristy3ed852e2009-09-05 21:47:34 +00005111 if (LocaleCompare("mosaic",option+1) == 0)
5112 break;
5113 if (LocaleCompare("motion-blur",option+1) == 0)
5114 {
5115 if (*option == '+')
5116 break;
5117 i++;
cristybb503372010-05-27 20:51:26 +00005118 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005119 ThrowMogrifyException(OptionError,"MissingArgument",option);
5120 if (IsGeometry(argv[i]) == MagickFalse)
5121 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5122 break;
5123 }
5124 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5125 }
5126 case 'n':
5127 {
5128 if (LocaleCompare("negate",option+1) == 0)
5129 break;
5130 if (LocaleCompare("noise",option+1) == 0)
5131 {
5132 i++;
cristybb503372010-05-27 20:51:26 +00005133 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005134 ThrowMogrifyException(OptionError,"MissingArgument",option);
5135 if (*option == '+')
5136 {
cristybb503372010-05-27 20:51:26 +00005137 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005138 noise;
5139
cristy042ee782011-04-22 18:48:30 +00005140 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005141 if (noise < 0)
5142 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5143 argv[i]);
5144 break;
5145 }
5146 if (IsGeometry(argv[i]) == MagickFalse)
5147 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5148 break;
5149 }
5150 if (LocaleCompare("noop",option+1) == 0)
5151 break;
5152 if (LocaleCompare("normalize",option+1) == 0)
5153 break;
5154 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5155 }
5156 case 'o':
5157 {
5158 if (LocaleCompare("opaque",option+1) == 0)
5159 {
cristy3ed852e2009-09-05 21:47:34 +00005160 i++;
cristybb503372010-05-27 20:51:26 +00005161 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005162 ThrowMogrifyException(OptionError,"MissingArgument",option);
5163 break;
5164 }
5165 if (LocaleCompare("ordered-dither",option+1) == 0)
5166 {
5167 if (*option == '+')
5168 break;
5169 i++;
cristybb503372010-05-27 20:51:26 +00005170 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005171 ThrowMogrifyException(OptionError,"MissingArgument",option);
5172 break;
5173 }
5174 if (LocaleCompare("orient",option+1) == 0)
5175 {
cristybb503372010-05-27 20:51:26 +00005176 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005177 orientation;
5178
5179 orientation=UndefinedOrientation;
5180 if (*option == '+')
5181 break;
5182 i++;
cristybb503372010-05-27 20:51:26 +00005183 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005184 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005185 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005186 argv[i]);
5187 if (orientation < 0)
5188 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5189 argv[i]);
5190 break;
5191 }
5192 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5193 }
5194 case 'p':
5195 {
5196 if (LocaleCompare("page",option+1) == 0)
5197 {
5198 if (*option == '+')
5199 break;
5200 i++;
cristybb503372010-05-27 20:51:26 +00005201 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005202 ThrowMogrifyException(OptionError,"MissingArgument",option);
5203 break;
5204 }
5205 if (LocaleCompare("paint",option+1) == 0)
5206 {
5207 if (*option == '+')
5208 break;
5209 i++;
cristybb503372010-05-27 20:51:26 +00005210 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005211 ThrowMogrifyException(OptionError,"MissingArgument",option);
5212 if (IsGeometry(argv[i]) == MagickFalse)
5213 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5214 break;
5215 }
5216 if (LocaleCompare("path",option+1) == 0)
5217 {
5218 (void) CloneString(&path,(char *) NULL);
5219 if (*option == '+')
5220 break;
5221 i++;
cristybb503372010-05-27 20:51:26 +00005222 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005223 ThrowMogrifyException(OptionError,"MissingArgument",option);
5224 (void) CloneString(&path,argv[i]);
5225 break;
5226 }
cristyab2b40a2012-11-04 01:43:29 +00005227 if (LocaleCompare("perceptible",option+1) == 0)
5228 {
5229 if (*option == '+')
5230 break;
5231 i++;
5232 if (i == (ssize_t) argc)
5233 ThrowMogrifyException(OptionError,"MissingArgument",option);
5234 if (IsGeometry(argv[i]) == MagickFalse)
5235 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5236 break;
5237 }
cristy3ed852e2009-09-05 21:47:34 +00005238 if (LocaleCompare("pointsize",option+1) == 0)
5239 {
5240 if (*option == '+')
5241 break;
5242 i++;
cristybb503372010-05-27 20:51:26 +00005243 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005244 ThrowMogrifyException(OptionError,"MissingArgument",option);
5245 if (IsGeometry(argv[i]) == MagickFalse)
5246 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5247 break;
5248 }
5249 if (LocaleCompare("polaroid",option+1) == 0)
5250 {
5251 if (*option == '+')
5252 break;
5253 i++;
cristybb503372010-05-27 20:51:26 +00005254 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005255 ThrowMogrifyException(OptionError,"MissingArgument",option);
5256 if (IsGeometry(argv[i]) == MagickFalse)
5257 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5258 break;
5259 }
cristy8cdfb342012-11-11 21:44:36 +00005260 if (LocaleCompare("poly",option+1) == 0)
5261 {
5262 if (*option == '+')
5263 break;
5264 i++;
5265 if (i == (ssize_t) argc)
5266 ThrowMogrifyException(OptionError,"MissingArgument",option);
5267 if (IsGeometry(argv[i]) == MagickFalse)
5268 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5269 break;
5270 }
cristy3ed852e2009-09-05 21:47:34 +00005271 if (LocaleCompare("posterize",option+1) == 0)
5272 {
5273 if (*option == '+')
5274 break;
5275 i++;
cristybb503372010-05-27 20:51:26 +00005276 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005277 ThrowMogrifyException(OptionError,"MissingArgument",option);
5278 if (IsGeometry(argv[i]) == MagickFalse)
5279 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5280 break;
5281 }
cristye7f51092010-01-17 00:39:37 +00005282 if (LocaleCompare("precision",option+1) == 0)
5283 {
5284 if (*option == '+')
5285 break;
5286 i++;
cristybb503372010-05-27 20:51:26 +00005287 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005288 ThrowMogrifyException(OptionError,"MissingArgument",option);
5289 if (IsGeometry(argv[i]) == MagickFalse)
5290 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5291 break;
5292 }
cristy3ed852e2009-09-05 21:47:34 +00005293 if (LocaleCompare("print",option+1) == 0)
5294 {
5295 if (*option == '+')
5296 break;
5297 i++;
cristybb503372010-05-27 20:51:26 +00005298 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005299 ThrowMogrifyException(OptionError,"MissingArgument",option);
5300 break;
5301 }
5302 if (LocaleCompare("process",option+1) == 0)
5303 {
5304 if (*option == '+')
5305 break;
5306 i++;
cristybb503372010-05-27 20:51:26 +00005307 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005308 ThrowMogrifyException(OptionError,"MissingArgument",option);
5309 break;
5310 }
5311 if (LocaleCompare("profile",option+1) == 0)
5312 {
5313 i++;
cristybb503372010-05-27 20:51:26 +00005314 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005315 ThrowMogrifyException(OptionError,"MissingArgument",option);
5316 break;
5317 }
5318 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5319 }
5320 case 'q':
5321 {
5322 if (LocaleCompare("quality",option+1) == 0)
5323 {
5324 if (*option == '+')
5325 break;
5326 i++;
cristybb503372010-05-27 20:51:26 +00005327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005328 ThrowMogrifyException(OptionError,"MissingArgument",option);
5329 if (IsGeometry(argv[i]) == MagickFalse)
5330 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5331 break;
5332 }
5333 if (LocaleCompare("quantize",option+1) == 0)
5334 {
cristybb503372010-05-27 20:51:26 +00005335 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005336 colorspace;
5337
5338 if (*option == '+')
5339 break;
5340 i++;
cristybb503372010-05-27 20:51:26 +00005341 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005342 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005343 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005344 argv[i]);
5345 if (colorspace < 0)
5346 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5347 argv[i]);
5348 break;
5349 }
5350 if (LocaleCompare("quiet",option+1) == 0)
5351 break;
5352 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5353 }
5354 case 'r':
5355 {
5356 if (LocaleCompare("radial-blur",option+1) == 0)
5357 {
5358 i++;
cristybb503372010-05-27 20:51:26 +00005359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005360 ThrowMogrifyException(OptionError,"MissingArgument",option);
5361 if (IsGeometry(argv[i]) == MagickFalse)
5362 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5363 break;
5364 }
5365 if (LocaleCompare("raise",option+1) == 0)
5366 {
5367 i++;
cristybb503372010-05-27 20:51:26 +00005368 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005369 ThrowMogrifyException(OptionError,"MissingArgument",option);
5370 if (IsGeometry(argv[i]) == MagickFalse)
5371 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5372 break;
5373 }
5374 if (LocaleCompare("random-threshold",option+1) == 0)
5375 {
5376 if (*option == '+')
5377 break;
5378 i++;
cristybb503372010-05-27 20:51:26 +00005379 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005380 ThrowMogrifyException(OptionError,"MissingArgument",option);
5381 if (IsGeometry(argv[i]) == MagickFalse)
5382 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5383 break;
5384 }
5385 if (LocaleCompare("red-primary",option+1) == 0)
5386 {
5387 if (*option == '+')
5388 break;
5389 i++;
cristybb503372010-05-27 20:51:26 +00005390 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005391 ThrowMogrifyException(OptionError,"MissingArgument",option);
5392 if (IsGeometry(argv[i]) == MagickFalse)
5393 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5394 }
cristy9f2083a2010-04-22 19:48:05 +00005395 if (LocaleCompare("regard-warnings",option+1) == 0)
5396 break;
cristy3ed852e2009-09-05 21:47:34 +00005397 if (LocaleCompare("region",option+1) == 0)
5398 {
5399 if (*option == '+')
5400 break;
5401 i++;
cristybb503372010-05-27 20:51:26 +00005402 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005403 ThrowMogrifyException(OptionError,"MissingArgument",option);
5404 if (IsGeometry(argv[i]) == MagickFalse)
5405 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5406 break;
5407 }
cristyf0c78232010-03-15 12:53:40 +00005408 if (LocaleCompare("remap",option+1) == 0)
5409 {
5410 if (*option == '+')
5411 break;
5412 i++;
cristybb503372010-05-27 20:51:26 +00005413 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005414 ThrowMogrifyException(OptionError,"MissingArgument",option);
5415 break;
5416 }
cristy3ed852e2009-09-05 21:47:34 +00005417 if (LocaleCompare("render",option+1) == 0)
5418 break;
5419 if (LocaleCompare("repage",option+1) == 0)
5420 {
5421 if (*option == '+')
5422 break;
5423 i++;
cristybb503372010-05-27 20:51:26 +00005424 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005425 ThrowMogrifyException(OptionError,"MissingArgument",option);
5426 if (IsGeometry(argv[i]) == MagickFalse)
5427 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5428 break;
5429 }
5430 if (LocaleCompare("resample",option+1) == 0)
5431 {
5432 if (*option == '+')
5433 break;
5434 i++;
cristybb503372010-05-27 20:51:26 +00005435 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005436 ThrowMogrifyException(OptionError,"MissingArgument",option);
5437 if (IsGeometry(argv[i]) == MagickFalse)
5438 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5439 break;
5440 }
5441 if (LocaleCompare("resize",option+1) == 0)
5442 {
5443 if (*option == '+')
5444 break;
5445 i++;
cristybb503372010-05-27 20:51:26 +00005446 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005447 ThrowMogrifyException(OptionError,"MissingArgument",option);
5448 if (IsGeometry(argv[i]) == MagickFalse)
5449 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5450 break;
5451 }
cristyebbcfea2011-02-25 02:43:54 +00005452 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5453 {
5454 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5455 break;
5456 }
cristy3ed852e2009-09-05 21:47:34 +00005457 if (LocaleCompare("reverse",option+1) == 0)
5458 break;
5459 if (LocaleCompare("roll",option+1) == 0)
5460 {
5461 if (*option == '+')
5462 break;
5463 i++;
cristybb503372010-05-27 20:51:26 +00005464 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005465 ThrowMogrifyException(OptionError,"MissingArgument",option);
5466 if (IsGeometry(argv[i]) == MagickFalse)
5467 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5468 break;
5469 }
5470 if (LocaleCompare("rotate",option+1) == 0)
5471 {
5472 i++;
cristybb503372010-05-27 20:51:26 +00005473 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005474 ThrowMogrifyException(OptionError,"MissingArgument",option);
5475 if (IsGeometry(argv[i]) == MagickFalse)
5476 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5477 break;
5478 }
5479 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5480 }
5481 case 's':
5482 {
5483 if (LocaleCompare("sample",option+1) == 0)
5484 {
5485 if (*option == '+')
5486 break;
5487 i++;
cristybb503372010-05-27 20:51:26 +00005488 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005489 ThrowMogrifyException(OptionError,"MissingArgument",option);
5490 if (IsGeometry(argv[i]) == MagickFalse)
5491 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5492 break;
5493 }
5494 if (LocaleCompare("sampling-factor",option+1) == 0)
5495 {
5496 if (*option == '+')
5497 break;
5498 i++;
cristybb503372010-05-27 20:51:26 +00005499 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005500 ThrowMogrifyException(OptionError,"MissingArgument",option);
5501 if (IsGeometry(argv[i]) == MagickFalse)
5502 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5503 break;
5504 }
5505 if (LocaleCompare("scale",option+1) == 0)
5506 {
5507 if (*option == '+')
5508 break;
5509 i++;
cristybb503372010-05-27 20:51:26 +00005510 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005511 ThrowMogrifyException(OptionError,"MissingArgument",option);
5512 if (IsGeometry(argv[i]) == MagickFalse)
5513 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5514 break;
5515 }
5516 if (LocaleCompare("scene",option+1) == 0)
5517 {
5518 if (*option == '+')
5519 break;
5520 i++;
cristybb503372010-05-27 20:51:26 +00005521 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005522 ThrowMogrifyException(OptionError,"MissingArgument",option);
5523 if (IsGeometry(argv[i]) == MagickFalse)
5524 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5525 break;
5526 }
5527 if (LocaleCompare("seed",option+1) == 0)
5528 {
5529 if (*option == '+')
5530 break;
5531 i++;
cristybb503372010-05-27 20:51:26 +00005532 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005533 ThrowMogrifyException(OptionError,"MissingArgument",option);
5534 if (IsGeometry(argv[i]) == MagickFalse)
5535 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5536 break;
5537 }
5538 if (LocaleCompare("segment",option+1) == 0)
5539 {
5540 if (*option == '+')
5541 break;
5542 i++;
cristybb503372010-05-27 20:51:26 +00005543 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005544 ThrowMogrifyException(OptionError,"MissingArgument",option);
5545 if (IsGeometry(argv[i]) == MagickFalse)
5546 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5547 break;
5548 }
5549 if (LocaleCompare("selective-blur",option+1) == 0)
5550 {
5551 i++;
cristybb503372010-05-27 20:51:26 +00005552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005553 ThrowMogrifyException(OptionError,"MissingArgument",option);
5554 if (IsGeometry(argv[i]) == MagickFalse)
5555 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5556 break;
5557 }
5558 if (LocaleCompare("separate",option+1) == 0)
5559 break;
5560 if (LocaleCompare("sepia-tone",option+1) == 0)
5561 {
5562 if (*option == '+')
5563 break;
5564 i++;
cristybb503372010-05-27 20:51:26 +00005565 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005566 ThrowMogrifyException(OptionError,"MissingArgument",option);
5567 if (IsGeometry(argv[i]) == MagickFalse)
5568 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5569 break;
5570 }
5571 if (LocaleCompare("set",option+1) == 0)
5572 {
5573 i++;
cristybb503372010-05-27 20:51:26 +00005574 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005575 ThrowMogrifyException(OptionError,"MissingArgument",option);
5576 if (*option == '+')
5577 break;
5578 i++;
cristybb503372010-05-27 20:51:26 +00005579 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005580 ThrowMogrifyException(OptionError,"MissingArgument",option);
5581 break;
5582 }
5583 if (LocaleCompare("shade",option+1) == 0)
5584 {
5585 i++;
cristybb503372010-05-27 20:51:26 +00005586 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005587 ThrowMogrifyException(OptionError,"MissingArgument",option);
5588 if (IsGeometry(argv[i]) == MagickFalse)
5589 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5590 break;
5591 }
5592 if (LocaleCompare("shadow",option+1) == 0)
5593 {
5594 if (*option == '+')
5595 break;
5596 i++;
cristybb503372010-05-27 20:51:26 +00005597 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005598 ThrowMogrifyException(OptionError,"MissingArgument",option);
5599 if (IsGeometry(argv[i]) == MagickFalse)
5600 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5601 break;
5602 }
5603 if (LocaleCompare("sharpen",option+1) == 0)
5604 {
5605 i++;
cristybb503372010-05-27 20:51:26 +00005606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005607 ThrowMogrifyException(OptionError,"MissingArgument",option);
5608 if (IsGeometry(argv[i]) == MagickFalse)
5609 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5610 break;
5611 }
5612 if (LocaleCompare("shave",option+1) == 0)
5613 {
5614 if (*option == '+')
5615 break;
5616 i++;
cristybb503372010-05-27 20:51:26 +00005617 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005618 ThrowMogrifyException(OptionError,"MissingArgument",option);
5619 if (IsGeometry(argv[i]) == MagickFalse)
5620 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5621 break;
5622 }
5623 if (LocaleCompare("shear",option+1) == 0)
5624 {
5625 i++;
cristybb503372010-05-27 20:51:26 +00005626 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005627 ThrowMogrifyException(OptionError,"MissingArgument",option);
5628 if (IsGeometry(argv[i]) == MagickFalse)
5629 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5630 break;
5631 }
5632 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5633 {
5634 i++;
cristybb503372010-05-27 20:51:26 +00005635 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005636 ThrowMogrifyException(OptionError,"MissingArgument",option);
5637 if (IsGeometry(argv[i]) == MagickFalse)
5638 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5639 break;
5640 }
5641 if (LocaleCompare("size",option+1) == 0)
5642 {
5643 if (*option == '+')
5644 break;
5645 i++;
cristybb503372010-05-27 20:51:26 +00005646 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005647 ThrowMogrifyException(OptionError,"MissingArgument",option);
5648 if (IsGeometry(argv[i]) == MagickFalse)
5649 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5650 break;
5651 }
5652 if (LocaleCompare("sketch",option+1) == 0)
5653 {
5654 if (*option == '+')
5655 break;
5656 i++;
cristybb503372010-05-27 20:51:26 +00005657 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005658 ThrowMogrifyException(OptionError,"MissingArgument",option);
5659 if (IsGeometry(argv[i]) == MagickFalse)
5660 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5661 break;
5662 }
cristy4285d782011-02-09 20:12:28 +00005663 if (LocaleCompare("smush",option+1) == 0)
5664 {
cristy4285d782011-02-09 20:12:28 +00005665 i++;
5666 if (i == (ssize_t) argc)
5667 ThrowMogrifyException(OptionError,"MissingArgument",option);
5668 if (IsGeometry(argv[i]) == MagickFalse)
5669 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005670 i++;
5671 break;
5672 }
cristy3ed852e2009-09-05 21:47:34 +00005673 if (LocaleCompare("solarize",option+1) == 0)
5674 {
5675 if (*option == '+')
5676 break;
5677 i++;
cristybb503372010-05-27 20:51:26 +00005678 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005679 ThrowMogrifyException(OptionError,"MissingArgument",option);
5680 if (IsGeometry(argv[i]) == MagickFalse)
5681 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5682 break;
5683 }
5684 if (LocaleCompare("sparse-color",option+1) == 0)
5685 {
cristybb503372010-05-27 20:51:26 +00005686 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005687 op;
5688
5689 i++;
cristybb503372010-05-27 20:51:26 +00005690 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005691 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005692 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005693 if (op < 0)
5694 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5695 argv[i]);
5696 i++;
cristybb503372010-05-27 20:51:26 +00005697 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005698 ThrowMogrifyException(OptionError,"MissingArgument",option);
5699 break;
5700 }
5701 if (LocaleCompare("spread",option+1) == 0)
5702 {
5703 if (*option == '+')
5704 break;
5705 i++;
cristybb503372010-05-27 20:51:26 +00005706 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005707 ThrowMogrifyException(OptionError,"MissingArgument",option);
5708 if (IsGeometry(argv[i]) == MagickFalse)
5709 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5710 break;
5711 }
cristy0834d642011-03-18 18:26:08 +00005712 if (LocaleCompare("statistic",option+1) == 0)
5713 {
5714 ssize_t
5715 op;
5716
5717 if (*option == '+')
5718 break;
5719 i++;
5720 if (i == (ssize_t) argc)
5721 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005722 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005723 if (op < 0)
5724 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5725 argv[i]);
5726 i++;
5727 if (i == (ssize_t) (argc-1))
5728 ThrowMogrifyException(OptionError,"MissingArgument",option);
5729 if (IsGeometry(argv[i]) == MagickFalse)
5730 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5731 break;
5732 }
cristy3ed852e2009-09-05 21:47:34 +00005733 if (LocaleCompare("stretch",option+1) == 0)
5734 {
cristybb503372010-05-27 20:51:26 +00005735 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005736 stretch;
5737
5738 if (*option == '+')
5739 break;
5740 i++;
cristybb503372010-05-27 20:51:26 +00005741 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005742 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005743 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005744 if (stretch < 0)
5745 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5746 argv[i]);
5747 break;
5748 }
5749 if (LocaleCompare("strip",option+1) == 0)
5750 break;
5751 if (LocaleCompare("stroke",option+1) == 0)
5752 {
5753 if (*option == '+')
5754 break;
5755 i++;
cristybb503372010-05-27 20:51:26 +00005756 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005757 ThrowMogrifyException(OptionError,"MissingArgument",option);
5758 break;
5759 }
5760 if (LocaleCompare("strokewidth",option+1) == 0)
5761 {
5762 if (*option == '+')
5763 break;
5764 i++;
cristybb503372010-05-27 20:51:26 +00005765 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005766 ThrowMogrifyException(OptionError,"MissingArgument",option);
5767 if (IsGeometry(argv[i]) == MagickFalse)
5768 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5769 break;
5770 }
5771 if (LocaleCompare("style",option+1) == 0)
5772 {
cristybb503372010-05-27 20:51:26 +00005773 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005774 style;
5775
5776 if (*option == '+')
5777 break;
5778 i++;
cristybb503372010-05-27 20:51:26 +00005779 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005780 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005781 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005782 if (style < 0)
5783 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5784 argv[i]);
5785 break;
5786 }
cristyecb10ff2011-03-22 13:14:03 +00005787 if (LocaleCompare("swap",option+1) == 0)
5788 {
5789 if (*option == '+')
5790 break;
5791 i++;
5792 if (i == (ssize_t) (argc-1))
5793 ThrowMogrifyException(OptionError,"MissingArgument",option);
5794 if (IsGeometry(argv[i]) == MagickFalse)
5795 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5796 break;
5797 }
cristy3ed852e2009-09-05 21:47:34 +00005798 if (LocaleCompare("swirl",option+1) == 0)
5799 {
5800 if (*option == '+')
5801 break;
5802 i++;
cristybb503372010-05-27 20:51:26 +00005803 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005804 ThrowMogrifyException(OptionError,"MissingArgument",option);
5805 if (IsGeometry(argv[i]) == MagickFalse)
5806 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5807 break;
5808 }
cristyd9a29192010-10-16 16:49:53 +00005809 if (LocaleCompare("synchronize",option+1) == 0)
5810 break;
cristy3ed852e2009-09-05 21:47:34 +00005811 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5812 }
5813 case 't':
5814 {
5815 if (LocaleCompare("taint",option+1) == 0)
5816 break;
5817 if (LocaleCompare("texture",option+1) == 0)
5818 {
5819 if (*option == '+')
5820 break;
5821 i++;
cristybb503372010-05-27 20:51:26 +00005822 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005823 ThrowMogrifyException(OptionError,"MissingArgument",option);
5824 break;
5825 }
5826 if (LocaleCompare("tile",option+1) == 0)
5827 {
5828 if (*option == '+')
5829 break;
5830 i++;
cristybb503372010-05-27 20:51:26 +00005831 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005832 ThrowMogrifyException(OptionError,"MissingArgument",option);
5833 break;
5834 }
5835 if (LocaleCompare("tile-offset",option+1) == 0)
5836 {
5837 if (*option == '+')
5838 break;
5839 i++;
cristybb503372010-05-27 20:51:26 +00005840 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005841 ThrowMogrifyException(OptionError,"MissingArgument",option);
5842 if (IsGeometry(argv[i]) == MagickFalse)
5843 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5844 break;
5845 }
5846 if (LocaleCompare("tint",option+1) == 0)
5847 {
5848 if (*option == '+')
5849 break;
5850 i++;
cristybb503372010-05-27 20:51:26 +00005851 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005852 ThrowMogrifyException(OptionError,"MissingArgument",option);
5853 if (IsGeometry(argv[i]) == MagickFalse)
5854 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5855 break;
5856 }
5857 if (LocaleCompare("transform",option+1) == 0)
5858 break;
5859 if (LocaleCompare("transpose",option+1) == 0)
5860 break;
5861 if (LocaleCompare("transverse",option+1) == 0)
5862 break;
5863 if (LocaleCompare("threshold",option+1) == 0)
5864 {
5865 if (*option == '+')
5866 break;
5867 i++;
cristybb503372010-05-27 20:51:26 +00005868 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005869 ThrowMogrifyException(OptionError,"MissingArgument",option);
5870 if (IsGeometry(argv[i]) == MagickFalse)
5871 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5872 break;
5873 }
5874 if (LocaleCompare("thumbnail",option+1) == 0)
5875 {
5876 if (*option == '+')
5877 break;
5878 i++;
cristybb503372010-05-27 20:51:26 +00005879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005880 ThrowMogrifyException(OptionError,"MissingArgument",option);
5881 if (IsGeometry(argv[i]) == MagickFalse)
5882 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5883 break;
5884 }
5885 if (LocaleCompare("transparent",option+1) == 0)
5886 {
5887 i++;
cristybb503372010-05-27 20:51:26 +00005888 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005889 ThrowMogrifyException(OptionError,"MissingArgument",option);
5890 break;
5891 }
5892 if (LocaleCompare("transparent-color",option+1) == 0)
5893 {
5894 if (*option == '+')
5895 break;
5896 i++;
cristybb503372010-05-27 20:51:26 +00005897 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005898 ThrowMogrifyException(OptionError,"MissingArgument",option);
5899 break;
5900 }
5901 if (LocaleCompare("treedepth",option+1) == 0)
5902 {
5903 if (*option == '+')
5904 break;
5905 i++;
cristybb503372010-05-27 20:51:26 +00005906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005907 ThrowMogrifyException(OptionError,"MissingArgument",option);
5908 if (IsGeometry(argv[i]) == MagickFalse)
5909 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5910 break;
5911 }
5912 if (LocaleCompare("trim",option+1) == 0)
5913 break;
5914 if (LocaleCompare("type",option+1) == 0)
5915 {
cristybb503372010-05-27 20:51:26 +00005916 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005917 type;
5918
5919 if (*option == '+')
5920 break;
5921 i++;
cristybb503372010-05-27 20:51:26 +00005922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005923 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005924 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005925 if (type < 0)
5926 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5927 argv[i]);
5928 break;
5929 }
5930 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5931 }
5932 case 'u':
5933 {
5934 if (LocaleCompare("undercolor",option+1) == 0)
5935 {
5936 if (*option == '+')
5937 break;
5938 i++;
cristybb503372010-05-27 20:51:26 +00005939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005940 ThrowMogrifyException(OptionError,"MissingArgument",option);
5941 break;
5942 }
5943 if (LocaleCompare("unique-colors",option+1) == 0)
5944 break;
5945 if (LocaleCompare("units",option+1) == 0)
5946 {
cristybb503372010-05-27 20:51:26 +00005947 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005948 units;
5949
5950 if (*option == '+')
5951 break;
5952 i++;
cristybb503372010-05-27 20:51:26 +00005953 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005954 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005955 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005956 argv[i]);
5957 if (units < 0)
5958 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5959 argv[i]);
5960 break;
5961 }
5962 if (LocaleCompare("unsharp",option+1) == 0)
5963 {
5964 i++;
cristybb503372010-05-27 20:51:26 +00005965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005966 ThrowMogrifyException(OptionError,"MissingArgument",option);
5967 if (IsGeometry(argv[i]) == MagickFalse)
5968 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5969 break;
5970 }
5971 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5972 }
5973 case 'v':
5974 {
5975 if (LocaleCompare("verbose",option+1) == 0)
5976 {
5977 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5978 break;
5979 }
5980 if ((LocaleCompare("version",option+1) == 0) ||
5981 (LocaleCompare("-version",option+1) == 0))
5982 {
cristy4f7a6132012-12-23 00:35:19 +00005983 ListMagickVersion(stdout);
cristy3ed852e2009-09-05 21:47:34 +00005984 break;
5985 }
5986 if (LocaleCompare("view",option+1) == 0)
5987 {
5988 if (*option == '+')
5989 break;
5990 i++;
cristybb503372010-05-27 20:51:26 +00005991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005992 ThrowMogrifyException(OptionError,"MissingArgument",option);
5993 break;
5994 }
5995 if (LocaleCompare("vignette",option+1) == 0)
5996 {
5997 if (*option == '+')
5998 break;
5999 i++;
cristybb503372010-05-27 20:51:26 +00006000 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006001 ThrowMogrifyException(OptionError,"MissingArgument",option);
6002 if (IsGeometry(argv[i]) == MagickFalse)
6003 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6004 break;
6005 }
6006 if (LocaleCompare("virtual-pixel",option+1) == 0)
6007 {
cristybb503372010-05-27 20:51:26 +00006008 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006009 method;
6010
6011 if (*option == '+')
6012 break;
6013 i++;
cristybb503372010-05-27 20:51:26 +00006014 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006015 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006016 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006017 argv[i]);
6018 if (method < 0)
6019 ThrowMogrifyException(OptionError,
6020 "UnrecognizedVirtualPixelMethod",argv[i]);
6021 break;
6022 }
6023 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6024 }
6025 case 'w':
6026 {
6027 if (LocaleCompare("wave",option+1) == 0)
6028 {
6029 i++;
cristybb503372010-05-27 20:51:26 +00006030 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006031 ThrowMogrifyException(OptionError,"MissingArgument",option);
6032 if (IsGeometry(argv[i]) == MagickFalse)
6033 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6034 break;
6035 }
6036 if (LocaleCompare("weight",option+1) == 0)
6037 {
6038 if (*option == '+')
6039 break;
6040 i++;
cristybb503372010-05-27 20:51:26 +00006041 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006042 ThrowMogrifyException(OptionError,"MissingArgument",option);
6043 break;
6044 }
6045 if (LocaleCompare("white-point",option+1) == 0)
6046 {
6047 if (*option == '+')
6048 break;
6049 i++;
cristybb503372010-05-27 20:51:26 +00006050 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006051 ThrowMogrifyException(OptionError,"MissingArgument",option);
6052 if (IsGeometry(argv[i]) == MagickFalse)
6053 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6054 break;
6055 }
6056 if (LocaleCompare("white-threshold",option+1) == 0)
6057 {
6058 if (*option == '+')
6059 break;
6060 i++;
cristybb503372010-05-27 20:51:26 +00006061 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006062 ThrowMogrifyException(OptionError,"MissingArgument",option);
6063 if (IsGeometry(argv[i]) == MagickFalse)
6064 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6065 break;
6066 }
6067 if (LocaleCompare("write",option+1) == 0)
6068 {
6069 i++;
cristybb503372010-05-27 20:51:26 +00006070 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006071 ThrowMogrifyException(OptionError,"MissingArgument",option);
6072 break;
6073 }
6074 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6075 }
6076 case '?':
6077 break;
6078 default:
6079 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6080 }
cristy042ee782011-04-22 18:48:30 +00006081 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6082 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006083 if (fire != MagickFalse)
6084 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6085 }
6086 if (k != 0)
6087 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006088 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006089 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6090 DestroyMogrify();
6091 return(status != 0 ? MagickTrue : MagickFalse);
6092}
6093
6094/*
6095%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6096% %
6097% %
6098% %
6099+ M o g r i f y I m a g e I n f o %
6100% %
6101% %
6102% %
6103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6104%
6105% MogrifyImageInfo() applies image processing settings to the image as
6106% prescribed by command line options.
6107%
6108% The format of the MogrifyImageInfo method is:
6109%
6110% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6111% const char **argv,ExceptionInfo *exception)
6112%
6113% A description of each parameter follows:
6114%
6115% o image_info: the image info..
6116%
6117% o argc: Specifies a pointer to an integer describing the number of
6118% elements in the argument vector.
6119%
6120% o argv: Specifies a pointer to a text array containing the command line
6121% arguments.
6122%
6123% o exception: return any errors or warnings in this structure.
6124%
6125*/
6126WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6127 const int argc,const char **argv,ExceptionInfo *exception)
6128{
6129 const char
6130 *option;
6131
6132 GeometryInfo
6133 geometry_info;
6134
cristybb503372010-05-27 20:51:26 +00006135 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006136 count;
6137
cristybb503372010-05-27 20:51:26 +00006138 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006139 i;
6140
6141 /*
6142 Initialize method variables.
6143 */
6144 assert(image_info != (ImageInfo *) NULL);
6145 assert(image_info->signature == MagickSignature);
6146 if (image_info->debug != MagickFalse)
6147 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6148 image_info->filename);
6149 if (argc < 0)
6150 return(MagickTrue);
6151 /*
6152 Set the image settings.
6153 */
cristybb503372010-05-27 20:51:26 +00006154 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006155 {
6156 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006157 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006158 continue;
cristy042ee782011-04-22 18:48:30 +00006159 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006160 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006161 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006162 break;
6163 switch (*(option+1))
6164 {
6165 case 'a':
6166 {
6167 if (LocaleCompare("adjoin",option+1) == 0)
6168 {
6169 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6170 break;
6171 }
6172 if (LocaleCompare("antialias",option+1) == 0)
6173 {
6174 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6175 break;
6176 }
cristy3ed852e2009-09-05 21:47:34 +00006177 if (LocaleCompare("authenticate",option+1) == 0)
6178 {
6179 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006180 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006181 else
anthony1afdc7a2011-10-05 11:54:28 +00006182 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006183 break;
6184 }
6185 break;
6186 }
6187 case 'b':
6188 {
6189 if (LocaleCompare("background",option+1) == 0)
6190 {
6191 if (*option == '+')
6192 {
6193 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006194 (void) QueryColorCompliance(MogrifyBackgroundColor,
6195 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006196 break;
6197 }
6198 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006199 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6200 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006201 break;
6202 }
6203 if (LocaleCompare("bias",option+1) == 0)
6204 {
6205 if (*option == '+')
6206 {
6207 (void) SetImageOption(image_info,option+1,"0.0");
6208 break;
6209 }
6210 (void) SetImageOption(image_info,option+1,argv[i+1]);
6211 break;
6212 }
6213 if (LocaleCompare("black-point-compensation",option+1) == 0)
6214 {
6215 if (*option == '+')
6216 {
6217 (void) SetImageOption(image_info,option+1,"false");
6218 break;
6219 }
6220 (void) SetImageOption(image_info,option+1,"true");
6221 break;
6222 }
6223 if (LocaleCompare("blue-primary",option+1) == 0)
6224 {
6225 if (*option == '+')
6226 {
6227 (void) SetImageOption(image_info,option+1,"0.0");
6228 break;
6229 }
6230 (void) SetImageOption(image_info,option+1,argv[i+1]);
6231 break;
6232 }
6233 if (LocaleCompare("bordercolor",option+1) == 0)
6234 {
6235 if (*option == '+')
6236 {
6237 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006238 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006239 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006240 break;
6241 }
cristy9950d572011-10-01 18:22:35 +00006242 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6243 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006244 (void) SetImageOption(image_info,option+1,argv[i+1]);
6245 break;
6246 }
6247 if (LocaleCompare("box",option+1) == 0)
6248 {
6249 if (*option == '+')
6250 {
6251 (void) SetImageOption(image_info,"undercolor","none");
6252 break;
6253 }
6254 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6255 break;
6256 }
6257 break;
6258 }
6259 case 'c':
6260 {
6261 if (LocaleCompare("cache",option+1) == 0)
6262 {
6263 MagickSizeType
6264 limit;
6265
6266 limit=MagickResourceInfinity;
6267 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006268 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6269 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006270 (void) SetMagickResourceLimit(MemoryResource,limit);
6271 (void) SetMagickResourceLimit(MapResource,2*limit);
6272 break;
6273 }
6274 if (LocaleCompare("caption",option+1) == 0)
6275 {
6276 if (*option == '+')
6277 {
6278 (void) DeleteImageOption(image_info,option+1);
6279 break;
6280 }
6281 (void) SetImageOption(image_info,option+1,argv[i+1]);
6282 break;
6283 }
6284 if (LocaleCompare("channel",option+1) == 0)
6285 {
6286 if (*option == '+')
6287 {
6288 image_info->channel=DefaultChannels;
cristydfdb19e2012-03-21 22:22:24 +00006289 (void) SetImageOption(image_info,option+1,"default");
cristy3ed852e2009-09-05 21:47:34 +00006290 break;
6291 }
6292 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristydfdb19e2012-03-21 22:22:24 +00006293 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006294 break;
6295 }
cristy3ed852e2009-09-05 21:47:34 +00006296 if (LocaleCompare("colorspace",option+1) == 0)
6297 {
6298 if (*option == '+')
6299 {
6300 image_info->colorspace=UndefinedColorspace;
6301 (void) SetImageOption(image_info,option+1,"undefined");
6302 break;
6303 }
cristy042ee782011-04-22 18:48:30 +00006304 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006305 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6306 (void) SetImageOption(image_info,option+1,argv[i+1]);
6307 break;
6308 }
cristy3ed852e2009-09-05 21:47:34 +00006309 if (LocaleCompare("comment",option+1) == 0)
6310 {
6311 if (*option == '+')
6312 {
6313 (void) DeleteImageOption(image_info,option+1);
6314 break;
6315 }
6316 (void) SetImageOption(image_info,option+1,argv[i+1]);
6317 break;
6318 }
6319 if (LocaleCompare("compose",option+1) == 0)
6320 {
6321 if (*option == '+')
6322 {
6323 (void) SetImageOption(image_info,option+1,"undefined");
6324 break;
6325 }
6326 (void) SetImageOption(image_info,option+1,argv[i+1]);
6327 break;
6328 }
6329 if (LocaleCompare("compress",option+1) == 0)
6330 {
6331 if (*option == '+')
6332 {
6333 image_info->compression=UndefinedCompression;
6334 (void) SetImageOption(image_info,option+1,"undefined");
6335 break;
6336 }
cristy042ee782011-04-22 18:48:30 +00006337 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006338 MagickCompressOptions,MagickFalse,argv[i+1]);
6339 (void) SetImageOption(image_info,option+1,argv[i+1]);
6340 break;
6341 }
6342 break;
6343 }
6344 case 'd':
6345 {
6346 if (LocaleCompare("debug",option+1) == 0)
6347 {
6348 if (*option == '+')
6349 (void) SetLogEventMask("none");
6350 else
6351 (void) SetLogEventMask(argv[i+1]);
6352 image_info->debug=IsEventLogging();
6353 break;
6354 }
6355 if (LocaleCompare("define",option+1) == 0)
6356 {
6357 if (*option == '+')
6358 {
6359 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6360 (void) DeleteImageRegistry(argv[i+1]+9);
6361 else
6362 (void) DeleteImageOption(image_info,argv[i+1]);
6363 break;
6364 }
6365 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6366 {
6367 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6368 exception);
6369 break;
6370 }
6371 (void) DefineImageOption(image_info,argv[i+1]);
6372 break;
6373 }
6374 if (LocaleCompare("delay",option+1) == 0)
6375 {
6376 if (*option == '+')
6377 {
6378 (void) SetImageOption(image_info,option+1,"0");
6379 break;
6380 }
6381 (void) SetImageOption(image_info,option+1,argv[i+1]);
6382 break;
6383 }
6384 if (LocaleCompare("density",option+1) == 0)
6385 {
6386 /*
6387 Set image density.
6388 */
6389 if (*option == '+')
6390 {
6391 if (image_info->density != (char *) NULL)
6392 image_info->density=DestroyString(image_info->density);
6393 (void) SetImageOption(image_info,option+1,"72");
6394 break;
6395 }
6396 (void) CloneString(&image_info->density,argv[i+1]);
6397 (void) SetImageOption(image_info,option+1,argv[i+1]);
6398 break;
6399 }
6400 if (LocaleCompare("depth",option+1) == 0)
6401 {
6402 if (*option == '+')
6403 {
6404 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6405 break;
6406 }
cristye27293e2009-12-18 02:53:20 +00006407 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006408 break;
6409 }
cristyc9b12952010-03-28 01:12:28 +00006410 if (LocaleCompare("direction",option+1) == 0)
6411 {
6412 if (*option == '+')
6413 {
6414 (void) SetImageOption(image_info,option+1,"undefined");
6415 break;
6416 }
6417 (void) SetImageOption(image_info,option+1,argv[i+1]);
6418 break;
6419 }
cristy3ed852e2009-09-05 21:47:34 +00006420 if (LocaleCompare("display",option+1) == 0)
6421 {
6422 if (*option == '+')
6423 {
6424 if (image_info->server_name != (char *) NULL)
6425 image_info->server_name=DestroyString(
6426 image_info->server_name);
6427 break;
6428 }
6429 (void) CloneString(&image_info->server_name,argv[i+1]);
6430 break;
6431 }
6432 if (LocaleCompare("dispose",option+1) == 0)
6433 {
6434 if (*option == '+')
6435 {
6436 (void) SetImageOption(image_info,option+1,"undefined");
6437 break;
6438 }
6439 (void) SetImageOption(image_info,option+1,argv[i+1]);
6440 break;
6441 }
6442 if (LocaleCompare("dither",option+1) == 0)
6443 {
6444 if (*option == '+')
6445 {
6446 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006447 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006448 break;
6449 }
6450 (void) SetImageOption(image_info,option+1,argv[i+1]);
6451 image_info->dither=MagickTrue;
6452 break;
6453 }
6454 break;
6455 }
6456 case 'e':
6457 {
6458 if (LocaleCompare("encoding",option+1) == 0)
6459 {
6460 if (*option == '+')
6461 {
6462 (void) SetImageOption(image_info,option+1,"undefined");
6463 break;
6464 }
6465 (void) SetImageOption(image_info,option+1,argv[i+1]);
6466 break;
6467 }
6468 if (LocaleCompare("endian",option+1) == 0)
6469 {
6470 if (*option == '+')
6471 {
6472 image_info->endian=UndefinedEndian;
6473 (void) SetImageOption(image_info,option+1,"undefined");
6474 break;
6475 }
cristy042ee782011-04-22 18:48:30 +00006476 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006477 MagickEndianOptions,MagickFalse,argv[i+1]);
6478 (void) SetImageOption(image_info,option+1,argv[i+1]);
6479 break;
6480 }
6481 if (LocaleCompare("extract",option+1) == 0)
6482 {
6483 /*
6484 Set image extract geometry.
6485 */
6486 if (*option == '+')
6487 {
6488 if (image_info->extract != (char *) NULL)
6489 image_info->extract=DestroyString(image_info->extract);
6490 break;
6491 }
6492 (void) CloneString(&image_info->extract,argv[i+1]);
6493 break;
6494 }
6495 break;
6496 }
6497 case 'f':
6498 {
6499 if (LocaleCompare("fill",option+1) == 0)
6500 {
6501 if (*option == '+')
6502 {
6503 (void) SetImageOption(image_info,option+1,"none");
6504 break;
6505 }
6506 (void) SetImageOption(image_info,option+1,argv[i+1]);
6507 break;
6508 }
6509 if (LocaleCompare("filter",option+1) == 0)
6510 {
6511 if (*option == '+')
6512 {
6513 (void) SetImageOption(image_info,option+1,"undefined");
6514 break;
6515 }
6516 (void) SetImageOption(image_info,option+1,argv[i+1]);
6517 break;
6518 }
6519 if (LocaleCompare("font",option+1) == 0)
6520 {
6521 if (*option == '+')
6522 {
6523 if (image_info->font != (char *) NULL)
6524 image_info->font=DestroyString(image_info->font);
6525 break;
6526 }
6527 (void) CloneString(&image_info->font,argv[i+1]);
6528 break;
6529 }
6530 if (LocaleCompare("format",option+1) == 0)
6531 {
6532 register const char
6533 *q;
6534
6535 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006536 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006537 image_info->ping=MagickFalse;
6538 (void) SetImageOption(image_info,option+1,argv[i+1]);
6539 break;
6540 }
6541 if (LocaleCompare("fuzz",option+1) == 0)
6542 {
6543 if (*option == '+')
6544 {
6545 image_info->fuzz=0.0;
6546 (void) SetImageOption(image_info,option+1,"0");
6547 break;
6548 }
cristydbdd0e32011-11-04 23:29:40 +00006549 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6550 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006551 (void) SetImageOption(image_info,option+1,argv[i+1]);
6552 break;
6553 }
6554 break;
6555 }
6556 case 'g':
6557 {
6558 if (LocaleCompare("gravity",option+1) == 0)
6559 {
6560 if (*option == '+')
6561 {
6562 (void) SetImageOption(image_info,option+1,"undefined");
6563 break;
6564 }
6565 (void) SetImageOption(image_info,option+1,argv[i+1]);
6566 break;
6567 }
6568 if (LocaleCompare("green-primary",option+1) == 0)
6569 {
6570 if (*option == '+')
6571 {
6572 (void) SetImageOption(image_info,option+1,"0.0");
6573 break;
6574 }
6575 (void) SetImageOption(image_info,option+1,argv[i+1]);
6576 break;
6577 }
6578 break;
6579 }
6580 case 'i':
6581 {
6582 if (LocaleCompare("intent",option+1) == 0)
6583 {
6584 if (*option == '+')
6585 {
6586 (void) SetImageOption(image_info,option+1,"undefined");
6587 break;
6588 }
6589 (void) SetImageOption(image_info,option+1,argv[i+1]);
6590 break;
6591 }
6592 if (LocaleCompare("interlace",option+1) == 0)
6593 {
6594 if (*option == '+')
6595 {
6596 image_info->interlace=UndefinedInterlace;
6597 (void) SetImageOption(image_info,option+1,"undefined");
6598 break;
6599 }
cristy042ee782011-04-22 18:48:30 +00006600 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006601 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6602 (void) SetImageOption(image_info,option+1,argv[i+1]);
6603 break;
6604 }
cristyb32b90a2009-09-07 21:45:48 +00006605 if (LocaleCompare("interline-spacing",option+1) == 0)
6606 {
6607 if (*option == '+')
6608 {
6609 (void) SetImageOption(image_info,option+1,"undefined");
6610 break;
6611 }
6612 (void) SetImageOption(image_info,option+1,argv[i+1]);
6613 break;
6614 }
cristy3ed852e2009-09-05 21:47:34 +00006615 if (LocaleCompare("interpolate",option+1) == 0)
6616 {
6617 if (*option == '+')
6618 {
6619 (void) SetImageOption(image_info,option+1,"undefined");
6620 break;
6621 }
6622 (void) SetImageOption(image_info,option+1,argv[i+1]);
6623 break;
6624 }
6625 if (LocaleCompare("interword-spacing",option+1) == 0)
6626 {
6627 if (*option == '+')
6628 {
6629 (void) SetImageOption(image_info,option+1,"undefined");
6630 break;
6631 }
6632 (void) SetImageOption(image_info,option+1,argv[i+1]);
6633 break;
6634 }
6635 break;
6636 }
6637 case 'k':
6638 {
6639 if (LocaleCompare("kerning",option+1) == 0)
6640 {
6641 if (*option == '+')
6642 {
6643 (void) SetImageOption(image_info,option+1,"undefined");
6644 break;
6645 }
6646 (void) SetImageOption(image_info,option+1,argv[i+1]);
6647 break;
6648 }
6649 break;
6650 }
6651 case 'l':
6652 {
6653 if (LocaleCompare("label",option+1) == 0)
6654 {
6655 if (*option == '+')
6656 {
6657 (void) DeleteImageOption(image_info,option+1);
6658 break;
6659 }
6660 (void) SetImageOption(image_info,option+1,argv[i+1]);
6661 break;
6662 }
6663 if (LocaleCompare("limit",option+1) == 0)
6664 {
6665 MagickSizeType
6666 limit;
6667
6668 ResourceType
6669 type;
6670
6671 if (*option == '+')
6672 break;
cristy042ee782011-04-22 18:48:30 +00006673 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006674 MagickFalse,argv[i+1]);
6675 limit=MagickResourceInfinity;
6676 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006677 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006678 (void) SetMagickResourceLimit(type,limit);
6679 break;
6680 }
6681 if (LocaleCompare("list",option+1) == 0)
6682 {
cristybb503372010-05-27 20:51:26 +00006683 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006684 list;
6685
6686 /*
6687 Display configuration list.
6688 */
cristy042ee782011-04-22 18:48:30 +00006689 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006690 switch (list)
6691 {
6692 case MagickCoderOptions:
6693 {
6694 (void) ListCoderInfo((FILE *) NULL,exception);
6695 break;
6696 }
6697 case MagickColorOptions:
6698 {
6699 (void) ListColorInfo((FILE *) NULL,exception);
6700 break;
6701 }
6702 case MagickConfigureOptions:
6703 {
6704 (void) ListConfigureInfo((FILE *) NULL,exception);
6705 break;
6706 }
6707 case MagickDelegateOptions:
6708 {
6709 (void) ListDelegateInfo((FILE *) NULL,exception);
6710 break;
6711 }
6712 case MagickFontOptions:
6713 {
6714 (void) ListTypeInfo((FILE *) NULL,exception);
6715 break;
6716 }
6717 case MagickFormatOptions:
6718 {
6719 (void) ListMagickInfo((FILE *) NULL,exception);
6720 break;
6721 }
6722 case MagickLocaleOptions:
6723 {
6724 (void) ListLocaleInfo((FILE *) NULL,exception);
6725 break;
6726 }
6727 case MagickLogOptions:
6728 {
6729 (void) ListLogInfo((FILE *) NULL,exception);
6730 break;
6731 }
6732 case MagickMagicOptions:
6733 {
6734 (void) ListMagicInfo((FILE *) NULL,exception);
6735 break;
6736 }
6737 case MagickMimeOptions:
6738 {
6739 (void) ListMimeInfo((FILE *) NULL,exception);
6740 break;
6741 }
6742 case MagickModuleOptions:
6743 {
6744 (void) ListModuleInfo((FILE *) NULL,exception);
6745 break;
6746 }
6747 case MagickPolicyOptions:
6748 {
6749 (void) ListPolicyInfo((FILE *) NULL,exception);
6750 break;
6751 }
6752 case MagickResourceOptions:
6753 {
6754 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6755 break;
6756 }
6757 case MagickThresholdOptions:
6758 {
6759 (void) ListThresholdMaps((FILE *) NULL,exception);
6760 break;
6761 }
6762 default:
6763 {
cristy042ee782011-04-22 18:48:30 +00006764 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006765 exception);
6766 break;
6767 }
6768 }
cristyaeb2cbc2010-05-07 13:28:58 +00006769 break;
cristy3ed852e2009-09-05 21:47:34 +00006770 }
6771 if (LocaleCompare("log",option+1) == 0)
6772 {
6773 if (*option == '+')
6774 break;
6775 (void) SetLogFormat(argv[i+1]);
6776 break;
6777 }
6778 if (LocaleCompare("loop",option+1) == 0)
6779 {
6780 if (*option == '+')
6781 {
6782 (void) SetImageOption(image_info,option+1,"0");
6783 break;
6784 }
6785 (void) SetImageOption(image_info,option+1,argv[i+1]);
6786 break;
6787 }
6788 break;
6789 }
6790 case 'm':
6791 {
6792 if (LocaleCompare("matte",option+1) == 0)
6793 {
6794 if (*option == '+')
6795 {
6796 (void) SetImageOption(image_info,option+1,"false");
6797 break;
6798 }
6799 (void) SetImageOption(image_info,option+1,"true");
6800 break;
6801 }
6802 if (LocaleCompare("mattecolor",option+1) == 0)
6803 {
6804 if (*option == '+')
6805 {
6806 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006807 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006808 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006809 break;
6810 }
6811 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006812 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6813 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006814 break;
6815 }
6816 if (LocaleCompare("monitor",option+1) == 0)
6817 {
6818 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6819 (void *) NULL);
6820 break;
6821 }
6822 if (LocaleCompare("monochrome",option+1) == 0)
6823 {
6824 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6825 break;
6826 }
6827 break;
6828 }
6829 case 'o':
6830 {
6831 if (LocaleCompare("orient",option+1) == 0)
6832 {
6833 if (*option == '+')
6834 {
6835 image_info->orientation=UndefinedOrientation;
6836 (void) SetImageOption(image_info,option+1,"undefined");
6837 break;
6838 }
cristy042ee782011-04-22 18:48:30 +00006839 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006840 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006841 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006842 break;
6843 }
6844 }
6845 case 'p':
6846 {
6847 if (LocaleCompare("page",option+1) == 0)
6848 {
6849 char
6850 *canonical_page,
6851 page[MaxTextExtent];
6852
6853 const char
6854 *image_option;
6855
6856 MagickStatusType
6857 flags;
6858
6859 RectangleInfo
6860 geometry;
6861
6862 if (*option == '+')
6863 {
6864 (void) DeleteImageOption(image_info,option+1);
6865 (void) CloneString(&image_info->page,(char *) NULL);
6866 break;
6867 }
6868 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6869 image_option=GetImageOption(image_info,"page");
6870 if (image_option != (const char *) NULL)
6871 flags=ParseAbsoluteGeometry(image_option,&geometry);
6872 canonical_page=GetPageGeometry(argv[i+1]);
6873 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6874 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006875 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006876 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006877 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006878 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006879 (unsigned long) geometry.width,(unsigned long) geometry.height,
6880 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006881 (void) SetImageOption(image_info,option+1,page);
6882 (void) CloneString(&image_info->page,page);
6883 break;
6884 }
cristy3ed852e2009-09-05 21:47:34 +00006885 if (LocaleCompare("ping",option+1) == 0)
6886 {
6887 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6888 break;
6889 }
6890 if (LocaleCompare("pointsize",option+1) == 0)
6891 {
6892 if (*option == '+')
6893 geometry_info.rho=0.0;
6894 else
6895 (void) ParseGeometry(argv[i+1],&geometry_info);
6896 image_info->pointsize=geometry_info.rho;
6897 break;
6898 }
cristye7f51092010-01-17 00:39:37 +00006899 if (LocaleCompare("precision",option+1) == 0)
6900 {
cristybf2766a2010-01-17 03:33:23 +00006901 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006902 break;
6903 }
cristy3ed852e2009-09-05 21:47:34 +00006904 if (LocaleCompare("preview",option+1) == 0)
6905 {
6906 /*
6907 Preview image.
6908 */
6909 if (*option == '+')
6910 {
6911 image_info->preview_type=UndefinedPreview;
6912 break;
6913 }
cristy042ee782011-04-22 18:48:30 +00006914 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006915 MagickPreviewOptions,MagickFalse,argv[i+1]);
6916 break;
6917 }
6918 break;
6919 }
6920 case 'q':
6921 {
6922 if (LocaleCompare("quality",option+1) == 0)
6923 {
6924 /*
6925 Set image compression quality.
6926 */
6927 if (*option == '+')
6928 {
6929 image_info->quality=UndefinedCompressionQuality;
6930 (void) SetImageOption(image_info,option+1,"0");
6931 break;
6932 }
cristye27293e2009-12-18 02:53:20 +00006933 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006934 (void) SetImageOption(image_info,option+1,argv[i+1]);
6935 break;
6936 }
6937 if (LocaleCompare("quiet",option+1) == 0)
6938 {
6939 static WarningHandler
6940 warning_handler = (WarningHandler) NULL;
6941
6942 if (*option == '+')
6943 {
6944 /*
6945 Restore error or warning messages.
6946 */
6947 warning_handler=SetWarningHandler(warning_handler);
6948 break;
6949 }
6950 /*
6951 Suppress error or warning messages.
6952 */
6953 warning_handler=SetWarningHandler((WarningHandler) NULL);
6954 break;
6955 }
6956 break;
6957 }
6958 case 'r':
6959 {
6960 if (LocaleCompare("red-primary",option+1) == 0)
6961 {
6962 if (*option == '+')
6963 {
6964 (void) SetImageOption(image_info,option+1,"0.0");
6965 break;
6966 }
6967 (void) SetImageOption(image_info,option+1,argv[i+1]);
6968 break;
6969 }
6970 break;
6971 }
6972 case 's':
6973 {
6974 if (LocaleCompare("sampling-factor",option+1) == 0)
6975 {
6976 /*
6977 Set image sampling factor.
6978 */
6979 if (*option == '+')
6980 {
6981 if (image_info->sampling_factor != (char *) NULL)
6982 image_info->sampling_factor=DestroyString(
6983 image_info->sampling_factor);
6984 break;
6985 }
6986 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6987 break;
6988 }
6989 if (LocaleCompare("scene",option+1) == 0)
6990 {
6991 /*
6992 Set image scene.
6993 */
6994 if (*option == '+')
6995 {
6996 image_info->scene=0;
6997 (void) SetImageOption(image_info,option+1,"0");
6998 break;
6999 }
cristye27293e2009-12-18 02:53:20 +00007000 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007001 (void) SetImageOption(image_info,option+1,argv[i+1]);
7002 break;
7003 }
7004 if (LocaleCompare("seed",option+1) == 0)
7005 {
cristybb503372010-05-27 20:51:26 +00007006 size_t
cristy3ed852e2009-09-05 21:47:34 +00007007 seed;
7008
7009 if (*option == '+')
7010 {
cristybb503372010-05-27 20:51:26 +00007011 seed=(size_t) time((time_t *) NULL);
cristyd7761bb2012-04-14 01:42:05 +00007012 SetRandomSecretKey(seed);
cristy3ed852e2009-09-05 21:47:34 +00007013 break;
7014 }
cristye27293e2009-12-18 02:53:20 +00007015 seed=StringToUnsignedLong(argv[i+1]);
cristyd7761bb2012-04-14 01:42:05 +00007016 SetRandomSecretKey(seed);
cristy3ed852e2009-09-05 21:47:34 +00007017 break;
7018 }
7019 if (LocaleCompare("size",option+1) == 0)
7020 {
7021 if (*option == '+')
7022 {
7023 if (image_info->size != (char *) NULL)
7024 image_info->size=DestroyString(image_info->size);
7025 break;
7026 }
7027 (void) CloneString(&image_info->size,argv[i+1]);
7028 break;
7029 }
7030 if (LocaleCompare("stroke",option+1) == 0)
7031 {
7032 if (*option == '+')
7033 {
7034 (void) SetImageOption(image_info,option+1,"none");
7035 break;
7036 }
7037 (void) SetImageOption(image_info,option+1,argv[i+1]);
7038 break;
7039 }
7040 if (LocaleCompare("strokewidth",option+1) == 0)
7041 {
7042 if (*option == '+')
7043 {
7044 (void) SetImageOption(image_info,option+1,"0");
7045 break;
7046 }
7047 (void) SetImageOption(image_info,option+1,argv[i+1]);
7048 break;
7049 }
cristyd9a29192010-10-16 16:49:53 +00007050 if (LocaleCompare("synchronize",option+1) == 0)
7051 {
7052 if (*option == '+')
7053 {
7054 image_info->synchronize=MagickFalse;
7055 break;
7056 }
7057 image_info->synchronize=MagickTrue;
7058 break;
7059 }
cristy3ed852e2009-09-05 21:47:34 +00007060 break;
7061 }
7062 case 't':
7063 {
7064 if (LocaleCompare("taint",option+1) == 0)
7065 {
7066 if (*option == '+')
7067 {
7068 (void) SetImageOption(image_info,option+1,"false");
7069 break;
7070 }
7071 (void) SetImageOption(image_info,option+1,"true");
7072 break;
7073 }
7074 if (LocaleCompare("texture",option+1) == 0)
7075 {
7076 if (*option == '+')
7077 {
7078 if (image_info->texture != (char *) NULL)
7079 image_info->texture=DestroyString(image_info->texture);
7080 break;
7081 }
7082 (void) CloneString(&image_info->texture,argv[i+1]);
7083 break;
7084 }
7085 if (LocaleCompare("tile-offset",option+1) == 0)
7086 {
7087 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007088 (void) SetImageOption(image_info,option+1,"0");
7089 else
7090 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007091 break;
7092 }
7093 if (LocaleCompare("transparent-color",option+1) == 0)
7094 {
7095 if (*option == '+')
7096 {
cristy9950d572011-10-01 18:22:35 +00007097 (void) QueryColorCompliance("none",AllCompliance,
7098 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007099 (void) SetImageOption(image_info,option+1,"none");
7100 break;
7101 }
cristy9950d572011-10-01 18:22:35 +00007102 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7103 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007104 (void) SetImageOption(image_info,option+1,argv[i+1]);
7105 break;
7106 }
7107 if (LocaleCompare("type",option+1) == 0)
7108 {
7109 if (*option == '+')
7110 {
cristy5f1c1ff2010-12-23 21:38:06 +00007111 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007112 (void) SetImageOption(image_info,option+1,"undefined");
7113 break;
7114 }
cristy042ee782011-04-22 18:48:30 +00007115 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007116 MagickFalse,argv[i+1]);
7117 (void) SetImageOption(image_info,option+1,argv[i+1]);
7118 break;
7119 }
7120 break;
7121 }
7122 case 'u':
7123 {
7124 if (LocaleCompare("undercolor",option+1) == 0)
7125 {
7126 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007127 (void) DeleteImageOption(image_info,option+1);
7128 else
7129 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007130 break;
7131 }
7132 if (LocaleCompare("units",option+1) == 0)
7133 {
7134 if (*option == '+')
7135 {
7136 image_info->units=UndefinedResolution;
7137 (void) SetImageOption(image_info,option+1,"undefined");
7138 break;
7139 }
cristy042ee782011-04-22 18:48:30 +00007140 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007141 MagickResolutionOptions,MagickFalse,argv[i+1]);
7142 (void) SetImageOption(image_info,option+1,argv[i+1]);
7143 break;
7144 }
7145 break;
7146 }
7147 case 'v':
7148 {
7149 if (LocaleCompare("verbose",option+1) == 0)
7150 {
7151 if (*option == '+')
7152 {
7153 image_info->verbose=MagickFalse;
7154 break;
7155 }
7156 image_info->verbose=MagickTrue;
7157 image_info->ping=MagickFalse;
7158 break;
7159 }
7160 if (LocaleCompare("view",option+1) == 0)
7161 {
7162 if (*option == '+')
7163 {
7164 if (image_info->view != (char *) NULL)
7165 image_info->view=DestroyString(image_info->view);
7166 break;
7167 }
7168 (void) CloneString(&image_info->view,argv[i+1]);
7169 break;
7170 }
7171 if (LocaleCompare("virtual-pixel",option+1) == 0)
7172 {
7173 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007174 (void) SetImageOption(image_info,option+1,"undefined");
7175 else
7176 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007177 break;
7178 }
7179 break;
7180 }
7181 case 'w':
7182 {
7183 if (LocaleCompare("white-point",option+1) == 0)
7184 {
7185 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007186 (void) SetImageOption(image_info,option+1,"0.0");
7187 else
7188 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007189 break;
7190 }
7191 break;
7192 }
7193 default:
7194 break;
7195 }
7196 i+=count;
7197 }
7198 return(MagickTrue);
7199}
7200
7201/*
7202%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7203% %
7204% %
7205% %
7206+ M o g r i f y I m a g e L i s t %
7207% %
7208% %
7209% %
7210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7211%
7212% MogrifyImageList() applies any command line options that might affect the
7213% entire image list (e.g. -append, -coalesce, etc.).
7214%
7215% The format of the MogrifyImage method is:
7216%
7217% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7218% const char **argv,Image **images,ExceptionInfo *exception)
7219%
7220% A description of each parameter follows:
7221%
7222% o image_info: the image info..
7223%
7224% o argc: Specifies a pointer to an integer describing the number of
7225% elements in the argument vector.
7226%
7227% o argv: Specifies a pointer to a text array containing the command line
7228% arguments.
7229%
anthonye9c27192011-03-27 08:07:06 +00007230% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007231%
7232% o exception: return any errors or warnings in this structure.
7233%
7234*/
7235WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7236 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7237{
cristy3ed852e2009-09-05 21:47:34 +00007238 const char
7239 *option;
7240
cristy6b3da3a2010-06-20 02:21:46 +00007241 ImageInfo
7242 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007243
7244 MagickStatusType
7245 status;
7246
cristy28474bf2011-09-11 23:32:52 +00007247 PixelInterpolateMethod
7248 interpolate_method;
7249
cristy3ed852e2009-09-05 21:47:34 +00007250 QuantizeInfo
7251 *quantize_info;
7252
cristybb503372010-05-27 20:51:26 +00007253 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007254 i;
7255
cristy6b3da3a2010-06-20 02:21:46 +00007256 ssize_t
7257 count,
7258 index;
7259
cristy3ed852e2009-09-05 21:47:34 +00007260 /*
7261 Apply options to the image list.
7262 */
7263 assert(image_info != (ImageInfo *) NULL);
7264 assert(image_info->signature == MagickSignature);
7265 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007266 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007267 assert((*images)->signature == MagickSignature);
7268 if ((*images)->debug != MagickFalse)
7269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7270 (*images)->filename);
7271 if ((argc <= 0) || (*argv == (char *) NULL))
7272 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007273 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007274 mogrify_info=CloneImageInfo(image_info);
7275 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007276 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007277 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007278 {
cristy74fe8f12009-10-03 19:09:01 +00007279 if (*images == (Image *) NULL)
7280 break;
cristy3ed852e2009-09-05 21:47:34 +00007281 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007282 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007283 continue;
cristy042ee782011-04-22 18:48:30 +00007284 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007285 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007286 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007287 break;
cristy6b3da3a2010-06-20 02:21:46 +00007288 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007289 switch (*(option+1))
7290 {
7291 case 'a':
7292 {
7293 if (LocaleCompare("affinity",option+1) == 0)
7294 {
cristy6fccee12011-10-20 18:43:18 +00007295 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007296 if (*option == '+')
7297 {
cristy018f07f2011-09-04 21:15:19 +00007298 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7299 exception);
cristy3ed852e2009-09-05 21:47:34 +00007300 break;
7301 }
7302 i++;
7303 break;
7304 }
7305 if (LocaleCompare("append",option+1) == 0)
7306 {
7307 Image
7308 *append_image;
7309
cristy6fccee12011-10-20 18:43:18 +00007310 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007311 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7312 MagickFalse,exception);
7313 if (append_image == (Image *) NULL)
7314 {
7315 status=MagickFalse;
7316 break;
7317 }
7318 *images=DestroyImageList(*images);
7319 *images=append_image;
7320 break;
7321 }
7322 if (LocaleCompare("average",option+1) == 0)
7323 {
7324 Image
7325 *average_image;
7326
cristyd18ae7c2010-03-07 17:39:52 +00007327 /*
7328 Average an image sequence (deprecated).
7329 */
cristy6fccee12011-10-20 18:43:18 +00007330 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007331 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7332 exception);
cristy3ed852e2009-09-05 21:47:34 +00007333 if (average_image == (Image *) NULL)
7334 {
7335 status=MagickFalse;
7336 break;
7337 }
7338 *images=DestroyImageList(*images);
7339 *images=average_image;
7340 break;
7341 }
7342 break;
7343 }
7344 case 'c':
7345 {
cristy5f257b22012-03-07 00:27:29 +00007346 if (LocaleCompare("channel-fx",option+1) == 0)
cristy87c02f42012-02-24 00:19:10 +00007347 {
cristyd04e7bf2012-03-03 19:19:12 +00007348 Image
7349 *channel_image;
7350
7351 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy5f257b22012-03-07 00:27:29 +00007352 channel_image=ChannelFxImage(*images,argv[i+1],exception);
cristyd04e7bf2012-03-03 19:19:12 +00007353 if (channel_image == (Image *) NULL)
7354 {
7355 status=MagickFalse;
7356 break;
7357 }
7358 *images=DestroyImageList(*images);
7359 *images=channel_image;
cristy87c02f42012-02-24 00:19:10 +00007360 break;
7361 }
cristy3ed852e2009-09-05 21:47:34 +00007362 if (LocaleCompare("clut",option+1) == 0)
7363 {
7364 Image
7365 *clut_image,
7366 *image;
7367
cristy6fccee12011-10-20 18:43:18 +00007368 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007369 image=RemoveFirstImageFromList(images);
7370 clut_image=RemoveFirstImageFromList(images);
7371 if (clut_image == (Image *) NULL)
7372 {
7373 status=MagickFalse;
7374 break;
7375 }
cristy28474bf2011-09-11 23:32:52 +00007376 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007377 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007378 *images=DestroyImageList(*images);
7379 *images=image;
7380 break;
7381 }
7382 if (LocaleCompare("coalesce",option+1) == 0)
7383 {
7384 Image
7385 *coalesce_image;
7386
cristy6fccee12011-10-20 18:43:18 +00007387 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007388 coalesce_image=CoalesceImages(*images,exception);
7389 if (coalesce_image == (Image *) NULL)
7390 {
7391 status=MagickFalse;
7392 break;
7393 }
7394 *images=DestroyImageList(*images);
7395 *images=coalesce_image;
7396 break;
7397 }
7398 if (LocaleCompare("combine",option+1) == 0)
7399 {
cristy46f354c2012-07-04 13:31:29 +00007400 ColorspaceType
7401 colorspace;
7402
cristy3ed852e2009-09-05 21:47:34 +00007403 Image
7404 *combine_image;
7405
cristy6fccee12011-10-20 18:43:18 +00007406 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy46f354c2012-07-04 13:31:29 +00007407 colorspace=(ColorspaceType) ParseCommandOption(
7408 MagickColorspaceOptions,MagickFalse,argv[i+1]);
7409 combine_image=CombineImages(*images,colorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00007410 if (combine_image == (Image *) NULL)
7411 {
7412 status=MagickFalse;
7413 break;
7414 }
7415 *images=DestroyImageList(*images);
7416 *images=combine_image;
7417 break;
7418 }
7419 if (LocaleCompare("composite",option+1) == 0)
7420 {
cristy542a95b2012-04-03 19:30:58 +00007421 const char
7422 *value;
7423
cristy3ed852e2009-09-05 21:47:34 +00007424 Image
7425 *mask_image,
7426 *composite_image,
7427 *image;
7428
cristyfeb3e962012-03-29 17:25:55 +00007429 MagickBooleanType
7430 clip_to_self;
7431
cristy3ed852e2009-09-05 21:47:34 +00007432 RectangleInfo
7433 geometry;
7434
cristy6fccee12011-10-20 18:43:18 +00007435 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy542a95b2012-04-03 19:30:58 +00007436 value=GetImageOption(mogrify_info,"compose:clip-to-self");
7437 if (value == (const char *) NULL)
7438 clip_to_self=MagickTrue;
7439 else
7440 clip_to_self=IsStringTrue(GetImageOption(mogrify_info,
7441 "compose:clip-to-self")); /* if this is true */
anthony7bcfe7f2012-03-30 14:01:22 +00007442 if (IsMagickFalse(clip_to_self)) /* or */
7443 clip_to_self=IfMagickFalse(IsStringNotFalse(GetImageOption(
cristyd9ecd042012-06-17 18:26:12 +00007444 mogrify_info,"compose:outside-overlay"))) ? MagickTrue : MagickFalse; /* this false */
cristy3ed852e2009-09-05 21:47:34 +00007445 image=RemoveFirstImageFromList(images);
7446 composite_image=RemoveFirstImageFromList(images);
7447 if (composite_image == (Image *) NULL)
7448 {
7449 status=MagickFalse;
7450 break;
7451 }
7452 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007453 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007454 SetGeometry(composite_image,&geometry);
7455 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7456 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7457 &geometry);
7458 mask_image=RemoveFirstImageFromList(images);
7459 if (mask_image != (Image *) NULL)
7460 {
7461 if ((image->compose == DisplaceCompositeOp) ||
7462 (image->compose == DistortCompositeOp))
7463 {
7464 /*
7465 Merge Y displacement into X displacement image.
7466 */
cristyfeb3e962012-03-29 17:25:55 +00007467 (void) CompositeImage(composite_image,mask_image,
cristy39172402012-03-30 13:04:39 +00007468 CopyGreenCompositeOp,MagickTrue,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007469 mask_image=DestroyImage(mask_image);
7470 }
7471 else
7472 {
7473 /*
anthony80c37752012-01-16 01:03:11 +00007474 Set a blending mask for the composition.
cristy3ed852e2009-09-05 21:47:34 +00007475 */
cristy10a6c612012-01-29 21:41:05 +00007476 (void) NegateImage(mask_image,MagickFalse,exception);
cristy665e18f2012-05-17 12:39:54 +00007477 (void) SetImageMask(composite_image,mask_image,exception);
cristy10a6c612012-01-29 21:41:05 +00007478 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00007479 }
7480 }
cristyfeb3e962012-03-29 17:25:55 +00007481 (void) CompositeImage(image,composite_image,image->compose,
cristy39172402012-03-30 13:04:39 +00007482 clip_to_self,geometry.x,geometry.y,exception);
cristy10a6c612012-01-29 21:41:05 +00007483 (void) SetImageMask(image,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00007484 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007485 *images=DestroyImageList(*images);
7486 *images=image;
7487 break;
7488 }
cristy3ed852e2009-09-05 21:47:34 +00007489 break;
7490 }
7491 case 'd':
7492 {
7493 if (LocaleCompare("deconstruct",option+1) == 0)
7494 {
7495 Image
7496 *deconstruct_image;
7497
cristy6fccee12011-10-20 18:43:18 +00007498 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007499 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007500 exception);
cristy3ed852e2009-09-05 21:47:34 +00007501 if (deconstruct_image == (Image *) NULL)
7502 {
7503 status=MagickFalse;
7504 break;
7505 }
7506 *images=DestroyImageList(*images);
7507 *images=deconstruct_image;
7508 break;
7509 }
7510 if (LocaleCompare("delete",option+1) == 0)
7511 {
7512 if (*option == '+')
7513 DeleteImages(images,"-1",exception);
7514 else
7515 DeleteImages(images,argv[i+1],exception);
7516 break;
7517 }
7518 if (LocaleCompare("dither",option+1) == 0)
7519 {
7520 if (*option == '+')
7521 {
cristycbda6112012-05-27 20:57:16 +00007522 quantize_info->dither_method=NoDitherMethod;
cristy3ed852e2009-09-05 21:47:34 +00007523 break;
7524 }
cristy042ee782011-04-22 18:48:30 +00007525 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007526 MagickDitherOptions,MagickFalse,argv[i+1]);
7527 break;
7528 }
cristyecb10ff2011-03-22 13:14:03 +00007529 if (LocaleCompare("duplicate",option+1) == 0)
7530 {
cristy72988482011-03-29 16:34:38 +00007531 Image
7532 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007533
anthony2b6bcae2011-03-23 13:05:34 +00007534 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007535 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7536 else
7537 {
7538 const char
7539 *p;
7540
anthony2b6bcae2011-03-23 13:05:34 +00007541 size_t
7542 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007543
anthony2b6bcae2011-03-23 13:05:34 +00007544 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007545 p=strchr(argv[i+1],',');
7546 if (p == (const char *) NULL)
7547 duplicate_images=DuplicateImages(*images,number_duplicates,
7548 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007549 else
cristy72988482011-03-29 16:34:38 +00007550 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7551 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007552 }
7553 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007554 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007555 break;
7556 }
cristy3ed852e2009-09-05 21:47:34 +00007557 break;
7558 }
cristyd18ae7c2010-03-07 17:39:52 +00007559 case 'e':
7560 {
7561 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7562 {
7563 Image
7564 *evaluate_image;
7565
7566 MagickEvaluateOperator
7567 op;
7568
cristy6fccee12011-10-20 18:43:18 +00007569 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007570 op=(MagickEvaluateOperator) ParseCommandOption(
7571 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007572 evaluate_image=EvaluateImages(*images,op,exception);
7573 if (evaluate_image == (Image *) NULL)
7574 {
7575 status=MagickFalse;
7576 break;
7577 }
7578 *images=DestroyImageList(*images);
7579 *images=evaluate_image;
7580 break;
7581 }
7582 break;
7583 }
cristy3ed852e2009-09-05 21:47:34 +00007584 case 'f':
7585 {
cristyf0a247f2009-10-04 00:20:03 +00007586 if (LocaleCompare("fft",option+1) == 0)
7587 {
7588 Image
7589 *fourier_image;
7590
7591 /*
7592 Implements the discrete Fourier transform (DFT).
7593 */
cristy6fccee12011-10-20 18:43:18 +00007594 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007595 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7596 MagickTrue : MagickFalse,exception);
7597 if (fourier_image == (Image *) NULL)
7598 break;
7599 *images=DestroyImage(*images);
7600 *images=fourier_image;
7601 break;
7602 }
cristy3ed852e2009-09-05 21:47:34 +00007603 if (LocaleCompare("flatten",option+1) == 0)
7604 {
7605 Image
7606 *flatten_image;
7607
cristy6fccee12011-10-20 18:43:18 +00007608 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007609 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7610 if (flatten_image == (Image *) NULL)
7611 break;
7612 *images=DestroyImageList(*images);
7613 *images=flatten_image;
7614 break;
7615 }
7616 if (LocaleCompare("fx",option+1) == 0)
7617 {
7618 Image
7619 *fx_image;
7620
cristy6fccee12011-10-20 18:43:18 +00007621 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007622 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007623 if (fx_image == (Image *) NULL)
7624 {
7625 status=MagickFalse;
7626 break;
7627 }
7628 *images=DestroyImageList(*images);
7629 *images=fx_image;
7630 break;
7631 }
7632 break;
7633 }
7634 case 'h':
7635 {
7636 if (LocaleCompare("hald-clut",option+1) == 0)
7637 {
7638 Image
7639 *hald_image,
7640 *image;
7641
cristy6fccee12011-10-20 18:43:18 +00007642 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007643 image=RemoveFirstImageFromList(images);
7644 hald_image=RemoveFirstImageFromList(images);
7645 if (hald_image == (Image *) NULL)
7646 {
7647 status=MagickFalse;
7648 break;
7649 }
cristy7c0a0a42011-08-23 17:57:25 +00007650 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007651 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007652 if (*images != (Image *) NULL)
7653 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007654 *images=image;
7655 break;
7656 }
7657 break;
7658 }
7659 case 'i':
7660 {
7661 if (LocaleCompare("ift",option+1) == 0)
7662 {
7663 Image
cristy8587f882009-11-13 20:28:49 +00007664 *fourier_image,
7665 *magnitude_image,
7666 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007667
7668 /*
7669 Implements the inverse fourier discrete Fourier transform (DFT).
7670 */
cristy6fccee12011-10-20 18:43:18 +00007671 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007672 magnitude_image=RemoveFirstImageFromList(images);
7673 phase_image=RemoveFirstImageFromList(images);
7674 if (phase_image == (Image *) NULL)
7675 {
7676 status=MagickFalse;
7677 break;
7678 }
7679 fourier_image=InverseFourierTransformImage(magnitude_image,
7680 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007681 if (fourier_image == (Image *) NULL)
7682 break;
cristy0aff6ea2009-11-14 01:40:53 +00007683 if (*images != (Image *) NULL)
7684 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007685 *images=fourier_image;
7686 break;
7687 }
7688 if (LocaleCompare("insert",option+1) == 0)
7689 {
7690 Image
7691 *p,
7692 *q;
7693
7694 index=0;
7695 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007696 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007697 p=RemoveLastImageFromList(images);
7698 if (p == (Image *) NULL)
7699 {
7700 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00007701 OptionError,"NoSuchImage","`%s'",argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007702 status=MagickFalse;
7703 break;
7704 }
7705 q=p;
7706 if (index == 0)
7707 PrependImageToList(images,q);
7708 else
cristybb503372010-05-27 20:51:26 +00007709 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007710 AppendImageToList(images,q);
7711 else
7712 {
7713 q=GetImageFromList(*images,index-1);
7714 if (q == (Image *) NULL)
7715 {
7716 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00007717 OptionError,"NoSuchImage","`%s'",argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007718 status=MagickFalse;
7719 break;
7720 }
7721 InsertImageInList(&q,p);
7722 }
7723 *images=GetFirstImageInList(q);
7724 break;
7725 }
cristy28474bf2011-09-11 23:32:52 +00007726 if (LocaleCompare("interpolate",option+1) == 0)
7727 {
7728 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7729 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7730 break;
7731 }
cristy3ed852e2009-09-05 21:47:34 +00007732 break;
7733 }
7734 case 'l':
7735 {
7736 if (LocaleCompare("layers",option+1) == 0)
7737 {
7738 Image
7739 *layers;
7740
cristya0417062012-09-02 23:34:56 +00007741 LayerMethod
cristy3ed852e2009-09-05 21:47:34 +00007742 method;
7743
cristy6fccee12011-10-20 18:43:18 +00007744 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007745 layers=(Image *) NULL;
cristya0417062012-09-02 23:34:56 +00007746 method=(LayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007747 MagickFalse,argv[i+1]);
7748 switch (method)
7749 {
7750 case CoalesceLayer:
7751 {
7752 layers=CoalesceImages(*images,exception);
7753 break;
7754 }
7755 case CompareAnyLayer:
7756 case CompareClearLayer:
7757 case CompareOverlayLayer:
7758 default:
7759 {
cristy8a9106f2011-07-05 14:39:26 +00007760 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007761 break;
7762 }
7763 case MergeLayer:
7764 case FlattenLayer:
7765 case MosaicLayer:
7766 case TrimBoundsLayer:
7767 {
7768 layers=MergeImageLayers(*images,method,exception);
7769 break;
7770 }
7771 case DisposeLayer:
7772 {
7773 layers=DisposeImages(*images,exception);
7774 break;
7775 }
7776 case OptimizeImageLayer:
7777 {
7778 layers=OptimizeImageLayers(*images,exception);
7779 break;
7780 }
7781 case OptimizePlusLayer:
7782 {
7783 layers=OptimizePlusImageLayers(*images,exception);
7784 break;
7785 }
7786 case OptimizeTransLayer:
7787 {
7788 OptimizeImageTransparency(*images,exception);
7789 break;
7790 }
7791 case RemoveDupsLayer:
7792 {
7793 RemoveDuplicateLayers(images,exception);
7794 break;
7795 }
7796 case RemoveZeroLayer:
7797 {
7798 RemoveZeroDelayLayers(images,exception);
7799 break;
7800 }
7801 case OptimizeLayer:
7802 {
7803 /*
7804 General Purpose, GIF Animation Optimizer.
7805 */
7806 layers=CoalesceImages(*images,exception);
7807 if (layers == (Image *) NULL)
7808 {
7809 status=MagickFalse;
7810 break;
7811 }
cristy3ed852e2009-09-05 21:47:34 +00007812 *images=DestroyImageList(*images);
7813 *images=layers;
7814 layers=OptimizeImageLayers(*images,exception);
7815 if (layers == (Image *) NULL)
7816 {
7817 status=MagickFalse;
7818 break;
7819 }
cristy3ed852e2009-09-05 21:47:34 +00007820 *images=DestroyImageList(*images);
7821 *images=layers;
7822 layers=(Image *) NULL;
7823 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007824 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7825 exception);
cristy3ed852e2009-09-05 21:47:34 +00007826 break;
7827 }
7828 case CompositeLayer:
7829 {
7830 CompositeOperator
7831 compose;
7832
7833 Image
7834 *source;
7835
7836 RectangleInfo
7837 geometry;
7838
7839 /*
7840 Split image sequence at the first 'NULL:' image.
7841 */
7842 source=(*images);
7843 while (source != (Image *) NULL)
7844 {
7845 source=GetNextImageInList(source);
7846 if ((source != (Image *) NULL) &&
7847 (LocaleCompare(source->magick,"NULL") == 0))
7848 break;
7849 }
7850 if (source != (Image *) NULL)
7851 {
7852 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7853 (GetNextImageInList(source) == (Image *) NULL))
7854 source=(Image *) NULL;
7855 else
7856 {
7857 /*
7858 Separate the two lists, junk the null: image.
7859 */
7860 source=SplitImageList(source->previous);
7861 DeleteImageFromList(&source);
7862 }
7863 }
7864 if (source == (Image *) NULL)
7865 {
7866 (void) ThrowMagickException(exception,GetMagickModule(),
7867 OptionError,"MissingNullSeparator","layers Composite");
7868 status=MagickFalse;
7869 break;
7870 }
7871 /*
7872 Adjust offset with gravity and virtual canvas.
7873 */
7874 SetGeometry(*images,&geometry);
7875 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7876 geometry.width=source->page.width != 0 ?
7877 source->page.width : source->columns;
7878 geometry.height=source->page.height != 0 ?
7879 source->page.height : source->rows;
7880 GravityAdjustGeometry((*images)->page.width != 0 ?
7881 (*images)->page.width : (*images)->columns,
7882 (*images)->page.height != 0 ? (*images)->page.height :
7883 (*images)->rows,(*images)->gravity,&geometry);
7884 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007885 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007886 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007887 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007888 MagickComposeOptions,MagickFalse,option);
7889 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7890 exception);
7891 source=DestroyImageList(source);
7892 break;
7893 }
7894 }
7895 if (layers == (Image *) NULL)
7896 break;
cristy3ed852e2009-09-05 21:47:34 +00007897 *images=DestroyImageList(*images);
7898 *images=layers;
7899 break;
7900 }
7901 break;
7902 }
7903 case 'm':
7904 {
7905 if (LocaleCompare("map",option+1) == 0)
7906 {
cristy6fccee12011-10-20 18:43:18 +00007907 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007908 if (*option == '+')
7909 {
cristy018f07f2011-09-04 21:15:19 +00007910 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7911 exception);
cristy3ed852e2009-09-05 21:47:34 +00007912 break;
7913 }
7914 i++;
7915 break;
7916 }
cristyf40785b2010-03-06 02:27:27 +00007917 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007918 {
7919 Image
cristyf40785b2010-03-06 02:27:27 +00007920 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007921
cristyd18ae7c2010-03-07 17:39:52 +00007922 /*
7923 Maximum image sequence (deprecated).
7924 */
cristy6fccee12011-10-20 18:43:18 +00007925 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007926 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007927 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007928 {
7929 status=MagickFalse;
7930 break;
7931 }
7932 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007933 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007934 break;
7935 }
cristyf40785b2010-03-06 02:27:27 +00007936 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007937 {
7938 Image
cristyf40785b2010-03-06 02:27:27 +00007939 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007940
cristyd18ae7c2010-03-07 17:39:52 +00007941 /*
7942 Minimum image sequence (deprecated).
7943 */
cristy6fccee12011-10-20 18:43:18 +00007944 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007945 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007946 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007947 {
7948 status=MagickFalse;
7949 break;
7950 }
7951 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007952 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007953 break;
7954 }
cristy3ed852e2009-09-05 21:47:34 +00007955 if (LocaleCompare("morph",option+1) == 0)
7956 {
7957 Image
7958 *morph_image;
7959
cristy6fccee12011-10-20 18:43:18 +00007960 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007961 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007962 exception);
7963 if (morph_image == (Image *) NULL)
7964 {
7965 status=MagickFalse;
7966 break;
7967 }
7968 *images=DestroyImageList(*images);
7969 *images=morph_image;
7970 break;
7971 }
7972 if (LocaleCompare("mosaic",option+1) == 0)
7973 {
7974 Image
7975 *mosaic_image;
7976
cristy6fccee12011-10-20 18:43:18 +00007977 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007978 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7979 if (mosaic_image == (Image *) NULL)
7980 {
7981 status=MagickFalse;
7982 break;
7983 }
7984 *images=DestroyImageList(*images);
7985 *images=mosaic_image;
7986 break;
7987 }
7988 break;
7989 }
7990 case 'p':
7991 {
cristy02016cf2012-11-13 01:14:41 +00007992 if (LocaleCompare("poly",option+1) == 0)
7993 {
7994 char
7995 *args,
7996 token[MaxTextExtent];
7997
7998 const char
7999 *p;
8000
8001 double
8002 *arguments;
8003
8004 Image
8005 *polynomial_image;
8006
8007 register ssize_t
8008 x;
8009
8010 size_t
8011 number_arguments;
8012
8013 /*
8014 Polynomial image.
8015 */
8016 (void) SyncImageSettings(mogrify_info,*images,exception);
8017 args=InterpretImageProperties(mogrify_info,*images,argv[i+1],
8018 exception);
8019 if (args == (char *) NULL)
8020 break;
8021 p=(char *) args;
8022 for (x=0; *p != '\0'; x++)
8023 {
8024 GetMagickToken(p,&p,token);
8025 if (*token == ',')
8026 GetMagickToken(p,&p,token);
8027 }
8028 number_arguments=(size_t) x;
8029 arguments=(double *) AcquireQuantumMemory(number_arguments,
8030 sizeof(*arguments));
8031 if (arguments == (double *) NULL)
8032 ThrowWandFatalException(ResourceLimitFatalError,
8033 "MemoryAllocationFailed",(*images)->filename);
8034 (void) ResetMagickMemory(arguments,0,number_arguments*
8035 sizeof(*arguments));
8036 p=(char *) args;
8037 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
8038 {
8039 GetMagickToken(p,&p,token);
8040 if (*token == ',')
8041 GetMagickToken(p,&p,token);
8042 arguments[x]=StringToDouble(token,(char **) NULL);
8043 }
8044 args=DestroyString(args);
8045 polynomial_image=PolynomialImage(*images,number_arguments >> 1,
8046 arguments,exception);
8047 arguments=(double *) RelinquishMagickMemory(arguments);
8048 if (polynomial_image == (Image *) NULL)
8049 {
8050 status=MagickFalse;
8051 break;
8052 }
8053 *images=DestroyImageList(*images);
8054 *images=polynomial_image;
8055 }
cristy3ed852e2009-09-05 21:47:34 +00008056 if (LocaleCompare("print",option+1) == 0)
8057 {
8058 char
8059 *string;
8060
cristy6fccee12011-10-20 18:43:18 +00008061 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00008062 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
8063 exception);
cristy3ed852e2009-09-05 21:47:34 +00008064 if (string == (char *) NULL)
8065 break;
cristyb51dff52011-05-19 16:55:47 +00008066 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008067 string=DestroyString(string);
8068 }
8069 if (LocaleCompare("process",option+1) == 0)
8070 {
8071 char
8072 **arguments;
8073
8074 int
8075 j,
8076 number_arguments;
8077
cristy6fccee12011-10-20 18:43:18 +00008078 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008079 arguments=StringToArgv(argv[i+1],&number_arguments);
8080 if (arguments == (char **) NULL)
8081 break;
8082 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8083 {
8084 char
8085 breaker,
8086 quote,
8087 *token;
8088
8089 const char
8090 *arguments;
8091
8092 int
8093 next,
8094 status;
8095
8096 size_t
8097 length;
8098
8099 TokenInfo
8100 *token_info;
8101
8102 /*
8103 Support old style syntax, filter="-option arg".
8104 */
8105 length=strlen(argv[i+1]);
8106 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008107 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008108 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8109 sizeof(*token));
8110 if (token == (char *) NULL)
8111 break;
8112 next=0;
8113 arguments=argv[i+1];
8114 token_info=AcquireTokenInfo();
8115 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8116 "\"",'\0',&breaker,&next,&quote);
8117 token_info=DestroyTokenInfo(token_info);
8118 if (status == 0)
8119 {
8120 const char
8121 *argv;
8122
8123 argv=(&(arguments[next]));
8124 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8125 exception);
8126 }
8127 token=DestroyString(token);
8128 break;
8129 }
cristy91c0da22010-05-02 01:44:07 +00008130 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008131 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8132 number_arguments-2,(const char **) arguments+2,exception);
8133 for (j=0; j < number_arguments; j++)
8134 arguments[j]=DestroyString(arguments[j]);
8135 arguments=(char **) RelinquishMagickMemory(arguments);
8136 break;
8137 }
8138 break;
8139 }
8140 case 'r':
8141 {
8142 if (LocaleCompare("reverse",option+1) == 0)
8143 {
8144 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008145 break;
8146 }
8147 break;
8148 }
8149 case 's':
8150 {
cristy4285d782011-02-09 20:12:28 +00008151 if (LocaleCompare("smush",option+1) == 0)
8152 {
8153 Image
8154 *smush_image;
8155
8156 ssize_t
8157 offset;
8158
cristy6fccee12011-10-20 18:43:18 +00008159 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008160 offset=(ssize_t) StringToLong(argv[i+1]);
8161 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8162 MagickFalse,offset,exception);
8163 if (smush_image == (Image *) NULL)
8164 {
8165 status=MagickFalse;
8166 break;
8167 }
8168 *images=DestroyImageList(*images);
8169 *images=smush_image;
8170 break;
8171 }
cristy3ed852e2009-09-05 21:47:34 +00008172 if (LocaleCompare("swap",option+1) == 0)
8173 {
8174 Image
8175 *p,
8176 *q,
8177 *swap;
8178
cristybb503372010-05-27 20:51:26 +00008179 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008180 swap_index;
8181
8182 index=(-1);
8183 swap_index=(-2);
8184 if (*option != '+')
8185 {
8186 GeometryInfo
8187 geometry_info;
8188
8189 MagickStatusType
8190 flags;
8191
8192 swap_index=(-1);
8193 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008194 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008195 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008196 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008197 }
8198 p=GetImageFromList(*images,index);
8199 q=GetImageFromList(*images,swap_index);
8200 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8201 {
8202 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00008203 OptionError,"NoSuchImage","`%s'",(*images)->filename);
cristy3ed852e2009-09-05 21:47:34 +00008204 status=MagickFalse;
8205 break;
8206 }
8207 if (p == q)
8208 break;
8209 swap=CloneImage(p,0,0,MagickTrue,exception);
8210 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8211 ReplaceImageInList(&q,swap);
8212 *images=GetFirstImageInList(q);
8213 break;
8214 }
8215 break;
8216 }
8217 case 'w':
8218 {
8219 if (LocaleCompare("write",option+1) == 0)
8220 {
cristy071dd7b2010-04-09 13:04:54 +00008221 char
cristy06609ee2010-03-17 20:21:27 +00008222 key[MaxTextExtent];
8223
cristy3ed852e2009-09-05 21:47:34 +00008224 Image
8225 *write_images;
8226
8227 ImageInfo
8228 *write_info;
8229
cristy6fccee12011-10-20 18:43:18 +00008230 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008231 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008232 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008233 write_images=(*images);
8234 if (*option == '+')
8235 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008236 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008237 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8238 write_info=DestroyImageInfo(write_info);
8239 if (*option == '+')
8240 write_images=DestroyImageList(write_images);
8241 break;
8242 }
8243 break;
8244 }
8245 default:
8246 break;
8247 }
8248 i+=count;
8249 }
8250 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008251 mogrify_info=DestroyImageInfo(mogrify_info);
8252 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008253 return(status != 0 ? MagickTrue : MagickFalse);
8254}
8255
8256/*
8257%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8258% %
8259% %
8260% %
8261+ M o g r i f y I m a g e s %
8262% %
8263% %
8264% %
8265%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8266%
8267% MogrifyImages() applies image processing options to a sequence of images as
8268% prescribed by command line options.
8269%
8270% The format of the MogrifyImage method is:
8271%
8272% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8273% const MagickBooleanType post,const int argc,const char **argv,
8274% Image **images,Exceptioninfo *exception)
8275%
8276% A description of each parameter follows:
8277%
8278% o image_info: the image info..
8279%
8280% o post: If true, post process image list operators otherwise pre-process.
8281%
8282% o argc: Specifies a pointer to an integer describing the number of
8283% elements in the argument vector.
8284%
8285% o argv: Specifies a pointer to a text array containing the command line
8286% arguments.
8287%
anthonye9c27192011-03-27 08:07:06 +00008288% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008289%
8290% o exception: return any errors or warnings in this structure.
8291%
8292*/
8293WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8294 const MagickBooleanType post,const int argc,const char **argv,
8295 Image **images,ExceptionInfo *exception)
8296{
8297#define MogrifyImageTag "Mogrify/Image"
8298
anthonye9c27192011-03-27 08:07:06 +00008299 MagickStatusType
8300 status;
cristy3ed852e2009-09-05 21:47:34 +00008301
cristy0e9f9c12010-02-11 03:00:47 +00008302 MagickBooleanType
8303 proceed;
8304
anthonye9c27192011-03-27 08:07:06 +00008305 size_t
8306 n;
cristy3ed852e2009-09-05 21:47:34 +00008307
cristybb503372010-05-27 20:51:26 +00008308 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008309 i;
8310
cristy3ed852e2009-09-05 21:47:34 +00008311 assert(image_info != (ImageInfo *) NULL);
8312 assert(image_info->signature == MagickSignature);
8313 if (images == (Image **) NULL)
8314 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008315 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008316 assert((*images)->signature == MagickSignature);
8317 if ((*images)->debug != MagickFalse)
8318 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8319 (*images)->filename);
8320 if ((argc <= 0) || (*argv == (char *) NULL))
8321 return(MagickTrue);
8322 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8323 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008324 status=0;
anthonye9c27192011-03-27 08:07:06 +00008325
anthonyce2716b2011-04-22 09:51:34 +00008326#if 0
cristy1e604812011-05-19 18:07:50 +00008327 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8328 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008329#endif
8330
anthonye9c27192011-03-27 08:07:06 +00008331 /*
8332 Pre-process multi-image sequence operators
8333 */
cristy3ed852e2009-09-05 21:47:34 +00008334 if (post == MagickFalse)
8335 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008336 /*
8337 For each image, process simple single image operators
8338 */
8339 i=0;
8340 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008341 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008342 {
anthonyce2716b2011-04-22 09:51:34 +00008343#if 0
cristy1e604812011-05-19 18:07:50 +00008344 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8345 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008346#endif
anthonye9c27192011-03-27 08:07:06 +00008347 status&=MogrifyImage(image_info,argc,argv,images,exception);
8348 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008349 if (proceed == MagickFalse)
8350 break;
anthonye9c27192011-03-27 08:07:06 +00008351 if ( (*images)->next == (Image *) NULL )
8352 break;
8353 *images=(*images)->next;
8354 i++;
cristy3ed852e2009-09-05 21:47:34 +00008355 }
anthonye9c27192011-03-27 08:07:06 +00008356 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008357#if 0
cristy1e604812011-05-19 18:07:50 +00008358 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8359 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008360#endif
anthonye9c27192011-03-27 08:07:06 +00008361
8362 /*
8363 Post-process, multi-image sequence operators
8364 */
8365 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008366 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008367 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008368 return(status != 0 ? MagickTrue : MagickFalse);
8369}