blob: 121bb49b8ab60b8434083b46331857d012725907 [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% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 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"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
cristy4c08aed2011-07-01 19:47:50 +000054#include "MagickCore/string-private.h"
cristy0740a982011-10-13 15:01:01 +000055#include "MagickCore/thread-private.h"
cristy18c6c272011-09-23 14:40:37 +000056#include "MagickCore/utility-private.h"
cristy3ed852e2009-09-05 21:47:34 +000057
58/*
cristy154fa9d2011-08-05 14:25:15 +000059 Constant declaration.
60*/
cristy3a557c02011-08-06 19:48:02 +000061static const char
cristy638895a2011-08-06 23:19:14 +000062 MogrifyBackgroundColor[] = "#ffffff", /* white */
63 MogrifyBorderColor[] = "#dfdfdf", /* gray */
64 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000065
66/*
cristy3ed852e2009-09-05 21:47:34 +000067 Define declarations.
68*/
69#define UndefinedCompressionQuality 0UL
70
71/*
cristy3ed852e2009-09-05 21:47:34 +000072%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73% %
74% %
75% %
cristy5063d812010-10-19 16:28:10 +000076% 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 +000077% %
78% %
79% %
80%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81%
82% MagickCommandGenesis() applies image processing options to an image as
83% prescribed by command line options.
84%
85% The format of the MagickCommandGenesis method is:
86%
87% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000088% MagickCommand command,int argc,char **argv,char **metadata,
89% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000090%
91% A description of each parameter follows:
92%
93% o image_info: the image info.
94%
cristy5063d812010-10-19 16:28:10 +000095% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000096% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000097% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
98% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000099%
100% o argc: Specifies a pointer to an integer describing the number of
101% elements in the argument vector.
102%
103% o argv: Specifies a pointer to a text array containing the command line
104% arguments.
105%
cristy5063d812010-10-19 16:28:10 +0000106% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000107%
108% o exception: return any errors or warnings in this structure.
109%
110*/
111WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
112 MagickCommand command,int argc,char **argv,char **metadata,
113 ExceptionInfo *exception)
114{
115 char
116 *option;
117
118 double
119 duration,
120 elapsed_time,
121 user_time;
122
cristy3980b0d2009-10-25 14:37:13 +0000123 MagickBooleanType
124 concurrent,
125 regard_warnings,
126 status;
127
cristybb503372010-05-27 20:51:26 +0000128 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000129 i;
130
131 TimerInfo
132 *timer;
133
cristybb503372010-05-27 20:51:26 +0000134 size_t
cristy3980b0d2009-10-25 14:37:13 +0000135 iterations;
136
cristyd0a94fa2010-03-12 14:18:11 +0000137 (void) setlocale(LC_ALL,"");
138 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000139 concurrent=MagickFalse;
140 duration=(-1.0);
141 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000142 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000143 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000144 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000145 {
146 option=argv[i];
147 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
148 continue;
149 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000150 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000151 if (LocaleCompare("concurrent",option+1) == 0)
152 concurrent=MagickTrue;
153 if (LocaleCompare("debug",option+1) == 0)
154 (void) SetLogEventMask(argv[++i]);
155 if (LocaleCompare("duration",option+1) == 0)
cristydbdd0e32011-11-04 23:29:40 +0000156 duration=StringToDouble(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000157 if (LocaleCompare("regard-warnings",option+1) == 0)
158 regard_warnings=MagickTrue;
159 }
160 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000161 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000162 {
cristybb503372010-05-27 20:51:26 +0000163 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000164 {
cristy33557d72009-11-06 00:54:33 +0000165 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000166 continue;
167 if (duration > 0)
168 {
169 if (GetElapsedTime(timer) > duration)
170 continue;
171 (void) ContinueTimer(timer);
172 }
173 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000174 if (exception->severity != UndefinedException)
175 {
176 if ((exception->severity > ErrorException) ||
177 (regard_warnings != MagickFalse))
178 status=MagickTrue;
179 CatchException(exception);
180 }
cristy3d1a5512009-10-25 21:23:27 +0000181 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000182 {
183 (void) fputs(*metadata,stdout);
184 (void) fputc('\n',stdout);
185 *metadata=DestroyString(*metadata);
186 }
187 }
188 }
cristyceae09d2009-10-28 17:18:47 +0000189 else
190 {
191 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000192#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000193 # pragma omp parallel for shared(status)
194#endif
cristybb503372010-05-27 20:51:26 +0000195 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000196 {
cristy33557d72009-11-06 00:54:33 +0000197 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000198 continue;
199 if (duration > 0)
200 {
201 if (GetElapsedTime(timer) > duration)
202 continue;
203 (void) ContinueTimer(timer);
204 }
205 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000206#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000207 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000208#endif
209 {
210 if (exception->severity != UndefinedException)
211 {
212 if ((exception->severity > ErrorException) ||
213 (regard_warnings != MagickFalse))
214 status=MagickTrue;
215 CatchException(exception);
216 }
217 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
218 {
219 (void) fputs(*metadata,stdout);
220 (void) fputc('\n',stdout);
221 *metadata=DestroyString(*metadata);
222 }
223 }
224 }
225 }
cristy3980b0d2009-10-25 14:37:13 +0000226 if (iterations > 1)
227 {
228 elapsed_time=GetElapsedTime(timer);
229 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000230 (void) FormatLocaleFile(stderr,
cristy03d09372011-11-27 16:54:13 +0000231 "Performance[%.20g]: %.20gi %gips %0.3fu %lu:%02lu.%03lu\n",
232 (double) GetOpenMPMaximumThreads(),(double) iterations,(double)
233 iterations/elapsed_time,user_time,(unsigned long) (elapsed_time/60.0),
234 (unsigned long) floor(fmod(elapsed_time,60.0)),(unsigned long)
235 (1000.0*(elapsed_time-floor(elapsed_time))+0.5));
cristy3980b0d2009-10-25 14:37:13 +0000236 }
237 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000238 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000239}
240
241/*
242%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243% %
244% %
245% %
cristy3ed852e2009-09-05 21:47:34 +0000246+ M o g r i f y I m a g e %
247% %
248% %
249% %
250%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251%
anthonye9c27192011-03-27 08:07:06 +0000252% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000253% image that may be part of a large list, but also handles any 'region'
254% image handling.
anthonye9c27192011-03-27 08:07:06 +0000255%
256% The image in the list may be modified in three different ways...
257%
258% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
259% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
260% * replace by a list of images (only the -separate option!)
261%
262% In each case the result is returned into the list, and a pointer to the
263% modified image (last image added if replaced by a list of images) is
264% returned.
265%
266% ASIDE: The -crop is present but restricted to non-tile single image crops
267%
268% This means if all the images are being processed (such as by
269% MogrifyImages(), next image to be processed will be as per the pointer
270% (*image)->next. Also the image list may grow as a result of some specific
271% operations but as images are never merged or deleted, it will never shrink
272% in length. Typically the list will remain the same length.
273%
274% WARNING: As the image pointed to may be replaced, the first image in the
275% list may also change. GetFirstImageInList() should be used by caller if
276% they wish return the Image pointer to the first image in list.
277%
cristy3ed852e2009-09-05 21:47:34 +0000278%
279% The format of the MogrifyImage method is:
280%
281% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
282% const char **argv,Image **image)
283%
284% A description of each parameter follows:
285%
286% o image_info: the image info..
287%
288% o argc: Specifies a pointer to an integer describing the number of
289% elements in the argument vector.
290%
291% o argv: Specifies a pointer to a text array containing the command line
292% arguments.
293%
294% o image: the image.
295%
296% o exception: return any errors or warnings in this structure.
297%
298*/
299
anthonydf8ebac2011-04-27 09:03:19 +0000300static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
301 ExceptionInfo *exception)
302{
303 char
304 key[MaxTextExtent];
305
306 ExceptionInfo
307 *sans_exception;
308
309 Image
310 *image;
311
312 ImageInfo
313 *read_info;
314
cristyfcd785b2011-11-08 01:48:33 +0000315 /*
316 Read an image into a image cache if not already present. Return the image
317 that is in the cache under that filename.
318 */
cristyb51dff52011-05-19 16:55:47 +0000319 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000320 sans_exception=AcquireExceptionInfo();
321 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
322 sans_exception=DestroyExceptionInfo(sans_exception);
323 if (image != (Image *) NULL)
324 return(image);
325 read_info=CloneImageInfo(image_info);
326 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
327 image=ReadImage(read_info,exception);
328 read_info=DestroyImageInfo(read_info);
329 if (image != (Image *) NULL)
330 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
331 return(image);
332}
333
cristy3ed852e2009-09-05 21:47:34 +0000334static MagickBooleanType IsPathWritable(const char *path)
335{
336 if (IsPathAccessible(path) == MagickFalse)
337 return(MagickFalse);
cristy18c6c272011-09-23 14:40:37 +0000338 if (access_utf8(path,W_OK) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000339 return(MagickFalse);
340 return(MagickTrue);
341}
342
cristybb503372010-05-27 20:51:26 +0000343static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000344{
345 if (x > y)
346 return(x);
347 return(y);
348}
349
anthonydf8ebac2011-04-27 09:03:19 +0000350static MagickBooleanType MonitorProgress(const char *text,
351 const MagickOffsetType offset,const MagickSizeType extent,
352 void *wand_unused(client_data))
353{
354 char
355 message[MaxTextExtent],
356 tag[MaxTextExtent];
357
358 const char
359 *locale_message;
360
361 register char
362 *p;
363
364 if (extent < 2)
365 return(MagickTrue);
366 (void) CopyMagickMemory(tag,text,MaxTextExtent);
367 p=strrchr(tag,'/');
368 if (p != (char *) NULL)
369 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000370 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000371 locale_message=GetLocaleMessage(message);
372 if (locale_message == message)
373 locale_message=tag;
374 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000375 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
376 locale_message,(long) offset,(unsigned long) extent,(long)
377 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000378 else
cristyb51dff52011-05-19 16:55:47 +0000379 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000380 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
381 (100L*offset/(extent-1)));
382 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000383 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000384 (void) fflush(stderr);
385 return(MagickTrue);
386}
387
cristy3884f692011-07-08 18:00:18 +0000388static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000389 const SparseColorMethod method,const char *arguments,
390 const MagickBooleanType color_from_image,ExceptionInfo *exception)
391{
anthonydf8ebac2011-04-27 09:03:19 +0000392 char
393 token[MaxTextExtent];
394
395 const char
396 *p;
397
398 double
399 *sparse_arguments;
400
anthonydf8ebac2011-04-27 09:03:19 +0000401 Image
402 *sparse_image;
403
cristy4c08aed2011-07-01 19:47:50 +0000404 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000405 color;
406
407 MagickBooleanType
408 error;
409
cristy5f09d852011-05-29 01:39:29 +0000410 register size_t
411 x;
412
413 size_t
414 number_arguments,
415 number_colors;
416
cristyf4425a72011-11-08 01:52:04 +0000417 /*
418 SparseColorOption() parses the complex -sparse-color argument into an an
419 array of floating point values then calls SparseColorImage(). Argument is
420 a complex mix of floating-point pixel coodinates, and color specifications
421 (or direct floating point numbers). The number of floats needed to
422 represent a color varies depending on the current channel setting.
423 */
anthonydf8ebac2011-04-27 09:03:19 +0000424 assert(image != (Image *) NULL);
425 assert(image->signature == MagickSignature);
426 if (image->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
428 assert(exception != (ExceptionInfo *) NULL);
429 assert(exception->signature == MagickSignature);
430 /*
431 Limit channels according to image - and add up number of color channel.
432 */
anthonydf8ebac2011-04-27 09:03:19 +0000433 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000434 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000435 number_colors++;
cristyed231572011-07-14 02:18:59 +0000436 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000437 number_colors++;
cristyed231572011-07-14 02:18:59 +0000438 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000439 number_colors++;
cristyed231572011-07-14 02:18:59 +0000440 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000441 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000442 number_colors++;
cristyed231572011-07-14 02:18:59 +0000443 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000444 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000445 number_colors++;
446
447 /*
448 Read string, to determine number of arguments needed,
449 */
450 p=arguments;
451 x=0;
452 while( *p != '\0' )
453 {
454 GetMagickToken(p,&p,token);
455 if ( token[0] == ',' ) continue;
456 if ( isalpha((int) token[0]) || token[0] == '#' ) {
457 if ( color_from_image ) {
458 (void) ThrowMagickException(exception,GetMagickModule(),
459 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
460 "Color arg given, when colors are coming from image");
461 return( (Image *)NULL);
462 }
463 x += number_colors; /* color argument */
464 }
465 else {
466 x++; /* floating point argument */
467 }
468 }
469 error=MagickTrue;
470 if ( color_from_image ) {
471 /* just the control points are being given */
472 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
473 number_arguments=(x/2)*(2+number_colors);
474 }
475 else {
476 /* control points and color values */
477 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
478 number_arguments=x;
479 }
480 if ( error ) {
481 (void) ThrowMagickException(exception,GetMagickModule(),
482 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
483 "Invalid number of Arguments");
484 return( (Image *)NULL);
485 }
486
487 /* Allocate and fill in the floating point arguments */
488 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
489 sizeof(*sparse_arguments));
490 if (sparse_arguments == (double *) NULL) {
491 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
492 "MemoryAllocationFailed","%s","SparseColorOption");
493 return( (Image *)NULL);
494 }
495 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
496 sizeof(*sparse_arguments));
497 p=arguments;
498 x=0;
499 while( *p != '\0' && x < number_arguments ) {
500 /* X coordinate */
501 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
502 if ( token[0] == '\0' ) break;
503 if ( isalpha((int) token[0]) || token[0] == '#' ) {
504 (void) ThrowMagickException(exception,GetMagickModule(),
505 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
506 "Color found, instead of X-coord");
507 error = MagickTrue;
508 break;
509 }
cristydbdd0e32011-11-04 23:29:40 +0000510 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000511 /* Y coordinate */
512 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
513 if ( token[0] == '\0' ) break;
514 if ( isalpha((int) token[0]) || token[0] == '#' ) {
515 (void) ThrowMagickException(exception,GetMagickModule(),
516 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
517 "Color found, instead of Y-coord");
518 error = MagickTrue;
519 break;
520 }
cristydbdd0e32011-11-04 23:29:40 +0000521 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000522 /* color values for this control point */
523#if 0
524 if ( (color_from_image ) {
525 /* get color from image */
526 /* HOW??? */
527 }
528 else
529#endif
530 {
531 /* color name or function given in string argument */
532 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
533 if ( token[0] == '\0' ) break;
534 if ( isalpha((int) token[0]) || token[0] == '#' ) {
535 /* Color string given */
cristy269c9412011-10-13 23:41:15 +0000536 (void) QueryColorCompliance(token,AllCompliance,&color,exception);
cristyed231572011-07-14 02:18:59 +0000537 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000538 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000539 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000540 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000541 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000542 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000543 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000544 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000545 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000546 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000547 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000548 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000549 }
550 else {
551 /* Colors given as a set of floating point values - experimental */
552 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000553 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000554 {
anthonydf8ebac2011-04-27 09:03:19 +0000555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristydbdd0e32011-11-04 23:29:40 +0000558 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000559 token[0] = ','; /* used this token - get another */
560 }
cristyed231572011-07-14 02:18:59 +0000561 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000562 {
anthonydf8ebac2011-04-27 09:03:19 +0000563 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
564 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
565 break;
cristydbdd0e32011-11-04 23:29:40 +0000566 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000567 token[0] = ','; /* used this token - get another */
568 }
cristyed231572011-07-14 02:18:59 +0000569 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000570 {
anthonydf8ebac2011-04-27 09:03:19 +0000571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristydbdd0e32011-11-04 23:29:40 +0000574 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
cristyed231572011-07-14 02:18:59 +0000577 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000578 (image->colorspace == CMYKColorspace))
579 {
anthonydf8ebac2011-04-27 09:03:19 +0000580 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
581 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
582 break;
cristydbdd0e32011-11-04 23:29:40 +0000583 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000584 token[0] = ','; /* used this token - get another */
585 }
cristyed231572011-07-14 02:18:59 +0000586 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000587 (image->matte != MagickFalse))
588 {
anthonydf8ebac2011-04-27 09:03:19 +0000589 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
590 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
591 break;
cristydbdd0e32011-11-04 23:29:40 +0000592 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000593 token[0] = ','; /* used this token - get another */
594 }
595 }
596 }
597 }
598 if ( number_arguments != x && !error ) {
599 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
600 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
601 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
602 return( (Image *)NULL);
603 }
604 if ( error )
605 return( (Image *)NULL);
606
607 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000608 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
609 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000610 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
611 return( sparse_image );
612}
613
cristy3ed852e2009-09-05 21:47:34 +0000614WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
615 const char **argv,Image **image,ExceptionInfo *exception)
616{
anthonydf8ebac2011-04-27 09:03:19 +0000617 ChannelType
618 channel;
619
cristy633f0c62011-09-15 13:27:36 +0000620 CompositeOperator
621 compose;
622
anthonydf8ebac2011-04-27 09:03:19 +0000623 const char
624 *format,
625 *option;
626
cristy9ed1f812011-10-08 02:00:08 +0000627 double
628 attenuate;
629
anthonydf8ebac2011-04-27 09:03:19 +0000630 DrawInfo
631 *draw_info;
632
633 GeometryInfo
634 geometry_info;
635
cristy3ed852e2009-09-05 21:47:34 +0000636 Image
637 *region_image;
638
anthonydf8ebac2011-04-27 09:03:19 +0000639 ImageInfo
640 *mogrify_info;
641
cristyebbcfea2011-02-25 02:43:54 +0000642 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000643 status;
644
cristy4c08aed2011-07-01 19:47:50 +0000645 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000646 fill;
cristy3ed852e2009-09-05 21:47:34 +0000647
anthonydf8ebac2011-04-27 09:03:19 +0000648 MagickStatusType
649 flags;
650
cristy28474bf2011-09-11 23:32:52 +0000651 PixelInterpolateMethod
652 interpolate_method;
653
anthonydf8ebac2011-04-27 09:03:19 +0000654 QuantizeInfo
655 *quantize_info;
656
657 RectangleInfo
658 geometry,
659 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000660
cristybb503372010-05-27 20:51:26 +0000661 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000662 i;
663
664 /*
665 Initialize method variables.
666 */
667 assert(image_info != (const ImageInfo *) NULL);
668 assert(image_info->signature == MagickSignature);
669 assert(image != (Image **) NULL);
670 assert((*image)->signature == MagickSignature);
671 if ((*image)->debug != MagickFalse)
672 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
673 if (argc < 0)
674 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000675 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000676 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
677 quantize_info=AcquireQuantizeInfo(mogrify_info);
678 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000679 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000680 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000681 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000682 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000683 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000684 channel=mogrify_info->channel;
685 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000686 SetGeometry(*image,&region_geometry);
687 region_image=NewImageList();
688 /*
689 Transmogrify the image.
690 */
cristybb503372010-05-27 20:51:26 +0000691 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000692 {
anthonydf8ebac2011-04-27 09:03:19 +0000693 Image
694 *mogrify_image;
695
anthonye9c27192011-03-27 08:07:06 +0000696 ssize_t
697 count;
698
anthonydf8ebac2011-04-27 09:03:19 +0000699 option=argv[i];
700 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000701 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000702 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
703 0L);
cristycee97112010-05-28 00:44:52 +0000704 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000705 break;
cristy6b3da3a2010-06-20 02:21:46 +0000706 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000707 mogrify_image=(Image *)NULL;
708 switch (*(option+1))
709 {
710 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000711 {
anthonydf8ebac2011-04-27 09:03:19 +0000712 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000713 {
anthonydf8ebac2011-04-27 09:03:19 +0000714 /*
715 Adaptive blur image.
716 */
cristy6fccee12011-10-20 18:43:18 +0000717 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000718 flags=ParseGeometry(argv[i+1],&geometry_info);
719 if ((flags & SigmaValue) == 0)
720 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000721 if ((flags & XiValue) == 0)
722 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000723 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000724 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000725 break;
cristy3ed852e2009-09-05 21:47:34 +0000726 }
anthonydf8ebac2011-04-27 09:03:19 +0000727 if (LocaleCompare("adaptive-resize",option+1) == 0)
728 {
729 /*
730 Adaptive resize image.
731 */
cristy6fccee12011-10-20 18:43:18 +0000732 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000733 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
734 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy28474bf2011-09-11 23:32:52 +0000735 geometry.height,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000736 break;
737 }
738 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
739 {
740 /*
741 Adaptive sharpen image.
742 */
cristy6fccee12011-10-20 18:43:18 +0000743 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000744 flags=ParseGeometry(argv[i+1],&geometry_info);
745 if ((flags & SigmaValue) == 0)
746 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000747 if ((flags & XiValue) == 0)
748 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000749 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000750 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000751 break;
752 }
753 if (LocaleCompare("affine",option+1) == 0)
754 {
755 /*
756 Affine matrix.
757 */
758 if (*option == '+')
759 {
760 GetAffineMatrix(&draw_info->affine);
761 break;
762 }
763 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
764 break;
765 }
766 if (LocaleCompare("alpha",option+1) == 0)
767 {
768 AlphaChannelType
769 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000770
cristy6fccee12011-10-20 18:43:18 +0000771 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000772 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
773 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000774 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000775 break;
776 }
777 if (LocaleCompare("annotate",option+1) == 0)
778 {
779 char
780 *text,
781 geometry[MaxTextExtent];
782
783 /*
784 Annotate image.
785 */
cristy6fccee12011-10-20 18:43:18 +0000786 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000787 SetGeometryInfo(&geometry_info);
788 flags=ParseGeometry(argv[i+1],&geometry_info);
789 if ((flags & SigmaValue) == 0)
790 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000791 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
792 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000793 if (text == (char *) NULL)
794 break;
795 (void) CloneString(&draw_info->text,text);
796 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000797 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000798 geometry_info.xi,geometry_info.psi);
799 (void) CloneString(&draw_info->geometry,geometry);
800 draw_info->affine.sx=cos(DegreesToRadians(
801 fmod(geometry_info.rho,360.0)));
802 draw_info->affine.rx=sin(DegreesToRadians(
803 fmod(geometry_info.rho,360.0)));
804 draw_info->affine.ry=(-sin(DegreesToRadians(
805 fmod(geometry_info.sigma,360.0))));
806 draw_info->affine.sy=cos(DegreesToRadians(
807 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000808 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000809 break;
810 }
811 if (LocaleCompare("antialias",option+1) == 0)
812 {
813 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
814 MagickFalse;
815 draw_info->text_antialias=(*option == '-') ? MagickTrue :
816 MagickFalse;
817 break;
818 }
cristy9ed1f812011-10-08 02:00:08 +0000819 if (LocaleCompare("attenuate",option+1) == 0)
820 {
821 if (*option == '+')
822 {
823 attenuate=1.0;
824 break;
825 }
cristydbdd0e32011-11-04 23:29:40 +0000826 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000827 break;
828 }
anthonydf8ebac2011-04-27 09:03:19 +0000829 if (LocaleCompare("auto-gamma",option+1) == 0)
830 {
831 /*
832 Auto Adjust Gamma of image based on its mean
833 */
cristy6fccee12011-10-20 18:43:18 +0000834 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000835 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000836 break;
837 }
838 if (LocaleCompare("auto-level",option+1) == 0)
839 {
840 /*
841 Perfectly Normalize (max/min stretch) the image
842 */
cristy6fccee12011-10-20 18:43:18 +0000843 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000844 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000845 break;
846 }
847 if (LocaleCompare("auto-orient",option+1) == 0)
848 {
cristy6fccee12011-10-20 18:43:18 +0000849 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000850 switch ((*image)->orientation)
851 {
852 case TopRightOrientation:
853 {
854 mogrify_image=FlopImage(*image,exception);
855 break;
856 }
857 case BottomRightOrientation:
858 {
859 mogrify_image=RotateImage(*image,180.0,exception);
860 break;
861 }
862 case BottomLeftOrientation:
863 {
864 mogrify_image=FlipImage(*image,exception);
865 break;
866 }
867 case LeftTopOrientation:
868 {
869 mogrify_image=TransposeImage(*image,exception);
870 break;
871 }
872 case RightTopOrientation:
873 {
874 mogrify_image=RotateImage(*image,90.0,exception);
875 break;
876 }
877 case RightBottomOrientation:
878 {
879 mogrify_image=TransverseImage(*image,exception);
880 break;
881 }
882 case LeftBottomOrientation:
883 {
884 mogrify_image=RotateImage(*image,270.0,exception);
885 break;
886 }
887 default:
888 break;
889 }
890 if (mogrify_image != (Image *) NULL)
891 mogrify_image->orientation=TopLeftOrientation;
892 break;
893 }
894 break;
895 }
896 case 'b':
897 {
898 if (LocaleCompare("black-threshold",option+1) == 0)
899 {
900 /*
901 Black threshold image.
902 */
cristy6fccee12011-10-20 18:43:18 +0000903 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000904 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000905 break;
906 }
907 if (LocaleCompare("blue-shift",option+1) == 0)
908 {
909 /*
910 Blue shift image.
911 */
cristy6fccee12011-10-20 18:43:18 +0000912 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000913 geometry_info.rho=1.5;
914 if (*option == '-')
915 flags=ParseGeometry(argv[i+1],&geometry_info);
916 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
917 break;
918 }
919 if (LocaleCompare("blur",option+1) == 0)
920 {
921 /*
922 Gaussian blur image.
923 */
cristy6fccee12011-10-20 18:43:18 +0000924 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000925 flags=ParseGeometry(argv[i+1],&geometry_info);
926 if ((flags & SigmaValue) == 0)
927 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000928 if ((flags & XiValue) == 0)
929 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000930 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000931 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000932 break;
933 }
934 if (LocaleCompare("border",option+1) == 0)
935 {
936 /*
937 Surround image with a border of solid color.
938 */
cristy6fccee12011-10-20 18:43:18 +0000939 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000940 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
941 if ((flags & SigmaValue) == 0)
942 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000943 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000944 break;
945 }
946 if (LocaleCompare("bordercolor",option+1) == 0)
947 {
948 if (*option == '+')
949 {
cristy9950d572011-10-01 18:22:35 +0000950 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000951 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000952 break;
953 }
cristy9950d572011-10-01 18:22:35 +0000954 (void) QueryColorCompliance(argv[i+1],AllCompliance,
955 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000956 break;
957 }
958 if (LocaleCompare("box",option+1) == 0)
959 {
cristy9950d572011-10-01 18:22:35 +0000960 (void) QueryColorCompliance(argv[i+1],AllCompliance,
961 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000962 break;
963 }
964 if (LocaleCompare("brightness-contrast",option+1) == 0)
965 {
966 double
967 brightness,
968 contrast;
969
970 GeometryInfo
971 geometry_info;
972
973 MagickStatusType
974 flags;
975
976 /*
977 Brightness / contrast image.
978 */
cristy6fccee12011-10-20 18:43:18 +0000979 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000980 flags=ParseGeometry(argv[i+1],&geometry_info);
981 brightness=geometry_info.rho;
982 contrast=0.0;
983 if ((flags & SigmaValue) != 0)
984 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000985 (void) BrightnessContrastImage(*image,brightness,contrast,
986 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000987 break;
988 }
989 break;
990 }
991 case 'c':
992 {
993 if (LocaleCompare("cdl",option+1) == 0)
994 {
995 char
996 *color_correction_collection;
997
998 /*
999 Color correct with a color decision list.
1000 */
cristy6fccee12011-10-20 18:43:18 +00001001 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001002 color_correction_collection=FileToString(argv[i+1],~0,exception);
1003 if (color_correction_collection == (char *) NULL)
1004 break;
cristy1bfa9f02011-08-11 02:35:43 +00001005 (void) ColorDecisionListImage(*image,color_correction_collection,
1006 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001007 break;
1008 }
1009 if (LocaleCompare("channel",option+1) == 0)
1010 {
1011 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +00001012 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +00001013 else
cristyfa806a72011-07-04 02:06:13 +00001014 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristye2a912b2011-12-05 20:02:07 +00001015 SetPixelChannelMapMask(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001016 break;
1017 }
1018 if (LocaleCompare("charcoal",option+1) == 0)
1019 {
1020 /*
1021 Charcoal image.
1022 */
cristy6fccee12011-10-20 18:43:18 +00001023 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001024 flags=ParseGeometry(argv[i+1],&geometry_info);
1025 if ((flags & SigmaValue) == 0)
1026 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001027 if ((flags & XiValue) == 0)
1028 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001029 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001030 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001031 break;
1032 }
1033 if (LocaleCompare("chop",option+1) == 0)
1034 {
1035 /*
1036 Chop the image.
1037 */
cristy6fccee12011-10-20 18:43:18 +00001038 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001039 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1040 mogrify_image=ChopImage(*image,&geometry,exception);
1041 break;
1042 }
1043 if (LocaleCompare("clamp",option+1) == 0)
1044 {
1045 /*
1046 Clamp image.
1047 */
cristy6fccee12011-10-20 18:43:18 +00001048 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001049 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001050 break;
1051 }
1052 if (LocaleCompare("clip",option+1) == 0)
1053 {
cristy6fccee12011-10-20 18:43:18 +00001054 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001055 if (*option == '+')
1056 {
cristy018f07f2011-09-04 21:15:19 +00001057 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001058 break;
1059 }
cristy018f07f2011-09-04 21:15:19 +00001060 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001061 break;
1062 }
1063 if (LocaleCompare("clip-mask",option+1) == 0)
1064 {
1065 CacheView
1066 *mask_view;
1067
1068 Image
1069 *mask_image;
1070
cristy4c08aed2011-07-01 19:47:50 +00001071 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001072 *restrict q;
1073
1074 register ssize_t
1075 x;
1076
1077 ssize_t
1078 y;
1079
cristy6fccee12011-10-20 18:43:18 +00001080 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001081 if (*option == '+')
1082 {
1083 /*
1084 Remove a mask.
1085 */
cristy018f07f2011-09-04 21:15:19 +00001086 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001087 break;
1088 }
1089 /*
1090 Set the image mask.
1091 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1092 */
1093 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1094 if (mask_image == (Image *) NULL)
1095 break;
cristy574cc262011-08-05 01:23:58 +00001096 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001097 return(MagickFalse);
1098 mask_view=AcquireCacheView(mask_image);
1099 for (y=0; y < (ssize_t) mask_image->rows; y++)
1100 {
1101 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1102 exception);
cristyacd2ed22011-08-30 01:44:23 +00001103 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001104 break;
1105 for (x=0; x < (ssize_t) mask_image->columns; x++)
1106 {
1107 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001108 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1109 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1110 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1111 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001112 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001113 }
1114 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1115 break;
1116 }
1117 mask_view=DestroyCacheView(mask_view);
1118 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001119 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001120 break;
1121 }
1122 if (LocaleCompare("clip-path",option+1) == 0)
1123 {
cristy6fccee12011-10-20 18:43:18 +00001124 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001125 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001126 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001127 break;
1128 }
1129 if (LocaleCompare("colorize",option+1) == 0)
1130 {
1131 /*
1132 Colorize the image.
1133 */
cristy6fccee12011-10-20 18:43:18 +00001134 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001135 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001136 break;
1137 }
1138 if (LocaleCompare("color-matrix",option+1) == 0)
1139 {
1140 KernelInfo
1141 *kernel;
1142
cristy6fccee12011-10-20 18:43:18 +00001143 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001144 kernel=AcquireKernelInfo(argv[i+1]);
1145 if (kernel == (KernelInfo *) NULL)
1146 break;
1147 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1148 kernel=DestroyKernelInfo(kernel);
1149 break;
1150 }
1151 if (LocaleCompare("colors",option+1) == 0)
1152 {
1153 /*
1154 Reduce the number of colors in the image.
1155 */
cristy6fccee12011-10-20 18:43:18 +00001156 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001157 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1158 if (quantize_info->number_colors == 0)
1159 break;
1160 if (((*image)->storage_class == DirectClass) ||
1161 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001162 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001163 else
cristy018f07f2011-09-04 21:15:19 +00001164 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001165 break;
1166 }
1167 if (LocaleCompare("colorspace",option+1) == 0)
1168 {
1169 ColorspaceType
1170 colorspace;
1171
cristy6fccee12011-10-20 18:43:18 +00001172 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001173 if (*option == '+')
1174 {
cristye941a752011-10-15 01:52:48 +00001175 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001176 break;
1177 }
1178 colorspace=(ColorspaceType) ParseCommandOption(
1179 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001180 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001181 break;
1182 }
cristy633f0c62011-09-15 13:27:36 +00001183 if (LocaleCompare("compose",option+1) == 0)
1184 {
cristy6fccee12011-10-20 18:43:18 +00001185 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001186 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1187 MagickFalse,argv[i+1]);
1188 break;
1189 }
anthonydf8ebac2011-04-27 09:03:19 +00001190 if (LocaleCompare("contrast",option+1) == 0)
1191 {
cristy6fccee12011-10-20 18:43:18 +00001192 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001193 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001194 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001195 break;
1196 }
1197 if (LocaleCompare("contrast-stretch",option+1) == 0)
1198 {
1199 double
1200 black_point,
1201 white_point;
1202
1203 MagickStatusType
1204 flags;
1205
1206 /*
1207 Contrast stretch image.
1208 */
cristy6fccee12011-10-20 18:43:18 +00001209 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001210 flags=ParseGeometry(argv[i+1],&geometry_info);
1211 black_point=geometry_info.rho;
1212 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1213 black_point;
1214 if ((flags & PercentValue) != 0)
1215 {
1216 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1217 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1218 }
1219 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1220 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001221 (void) ContrastStretchImage(*image,black_point,white_point,
1222 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001223 break;
1224 }
1225 if (LocaleCompare("convolve",option+1) == 0)
1226 {
anthonydf8ebac2011-04-27 09:03:19 +00001227 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001228 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001229
cristy6fccee12011-10-20 18:43:18 +00001230 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001231 kernel_info=AcquireKernelInfo(argv[i+1]);
1232 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001233 break;
cristy0a922382011-07-16 15:30:34 +00001234 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001235 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001236 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001237 break;
1238 }
1239 if (LocaleCompare("crop",option+1) == 0)
1240 {
1241 /*
1242 Crop a image to a smaller size
1243 */
cristy6fccee12011-10-20 18:43:18 +00001244 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001245 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001246 break;
1247 }
1248 if (LocaleCompare("cycle",option+1) == 0)
1249 {
1250 /*
1251 Cycle an image colormap.
1252 */
cristy6fccee12011-10-20 18:43:18 +00001253 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001254 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1255 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001256 break;
1257 }
1258 break;
1259 }
1260 case 'd':
1261 {
1262 if (LocaleCompare("decipher",option+1) == 0)
1263 {
1264 StringInfo
1265 *passkey;
1266
1267 /*
1268 Decipher pixels.
1269 */
cristy6fccee12011-10-20 18:43:18 +00001270 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001271 passkey=FileToStringInfo(argv[i+1],~0,exception);
1272 if (passkey != (StringInfo *) NULL)
1273 {
1274 (void) PasskeyDecipherImage(*image,passkey,exception);
1275 passkey=DestroyStringInfo(passkey);
1276 }
1277 break;
1278 }
1279 if (LocaleCompare("density",option+1) == 0)
1280 {
1281 /*
1282 Set image density.
1283 */
1284 (void) CloneString(&draw_info->density,argv[i+1]);
1285 break;
1286 }
1287 if (LocaleCompare("depth",option+1) == 0)
1288 {
cristy6fccee12011-10-20 18:43:18 +00001289 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001290 if (*option == '+')
1291 {
cristy8a11cb12011-10-19 23:53:34 +00001292 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001293 break;
1294 }
cristy8a11cb12011-10-19 23:53:34 +00001295 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1296 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001297 break;
1298 }
1299 if (LocaleCompare("deskew",option+1) == 0)
1300 {
1301 double
1302 threshold;
1303
1304 /*
1305 Straighten the image.
1306 */
cristy6fccee12011-10-20 18:43:18 +00001307 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001308 if (*option == '+')
1309 threshold=40.0*QuantumRange/100.0;
1310 else
cristy9b34e302011-11-05 02:15:45 +00001311 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1312 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001313 mogrify_image=DeskewImage(*image,threshold,exception);
1314 break;
1315 }
1316 if (LocaleCompare("despeckle",option+1) == 0)
1317 {
1318 /*
1319 Reduce the speckles within an image.
1320 */
cristy6fccee12011-10-20 18:43:18 +00001321 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001322 mogrify_image=DespeckleImage(*image,exception);
1323 break;
1324 }
1325 if (LocaleCompare("display",option+1) == 0)
1326 {
1327 (void) CloneString(&draw_info->server_name,argv[i+1]);
1328 break;
1329 }
1330 if (LocaleCompare("distort",option+1) == 0)
1331 {
1332 char
1333 *args,
1334 token[MaxTextExtent];
1335
1336 const char
1337 *p;
1338
1339 DistortImageMethod
1340 method;
1341
1342 double
1343 *arguments;
1344
1345 register ssize_t
1346 x;
1347
1348 size_t
1349 number_arguments;
1350
1351 /*
1352 Distort image.
1353 */
cristy6fccee12011-10-20 18:43:18 +00001354 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001355 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1356 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001357 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001358 {
anthonydf8ebac2011-04-27 09:03:19 +00001359 double
1360 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001361
1362 /*
1363 Special Case - Argument is actually a resize geometry!
1364 Convert that to an appropriate distortion argument array.
1365 */
anthonydf8ebac2011-04-27 09:03:19 +00001366 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001367 exception);
1368 resize_args[0]=(double) geometry.width;
1369 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001370 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001371 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001372 break;
1373 }
cristy018f07f2011-09-04 21:15:19 +00001374 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1375 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001376 if (args == (char *) NULL)
1377 break;
1378 p=(char *) args;
1379 for (x=0; *p != '\0'; x++)
1380 {
1381 GetMagickToken(p,&p,token);
1382 if (*token == ',')
1383 GetMagickToken(p,&p,token);
1384 }
1385 number_arguments=(size_t) x;
1386 arguments=(double *) AcquireQuantumMemory(number_arguments,
1387 sizeof(*arguments));
1388 if (arguments == (double *) NULL)
1389 ThrowWandFatalException(ResourceLimitFatalError,
1390 "MemoryAllocationFailed",(*image)->filename);
1391 (void) ResetMagickMemory(arguments,0,number_arguments*
1392 sizeof(*arguments));
1393 p=(char *) args;
1394 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1395 {
1396 GetMagickToken(p,&p,token);
1397 if (*token == ',')
1398 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001399 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001400 }
1401 args=DestroyString(args);
1402 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1403 (*option == '+') ? MagickTrue : MagickFalse,exception);
1404 arguments=(double *) RelinquishMagickMemory(arguments);
1405 break;
1406 }
1407 if (LocaleCompare("dither",option+1) == 0)
1408 {
1409 if (*option == '+')
1410 {
1411 quantize_info->dither=MagickFalse;
1412 break;
1413 }
1414 quantize_info->dither=MagickTrue;
1415 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1416 MagickDitherOptions,MagickFalse,argv[i+1]);
1417 if (quantize_info->dither_method == NoDitherMethod)
1418 quantize_info->dither=MagickFalse;
1419 break;
1420 }
1421 if (LocaleCompare("draw",option+1) == 0)
1422 {
1423 /*
1424 Draw image.
1425 */
cristy6fccee12011-10-20 18:43:18 +00001426 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001427 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001428 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001429 break;
1430 }
1431 break;
1432 }
1433 case 'e':
1434 {
1435 if (LocaleCompare("edge",option+1) == 0)
1436 {
1437 /*
1438 Enhance edges in the image.
1439 */
cristy6fccee12011-10-20 18:43:18 +00001440 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001441 flags=ParseGeometry(argv[i+1],&geometry_info);
1442 if ((flags & SigmaValue) == 0)
1443 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001444 mogrify_image=EdgeImage(*image,geometry_info.rho,
1445 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001446 break;
1447 }
1448 if (LocaleCompare("emboss",option+1) == 0)
1449 {
1450 /*
1451 Gaussian embossen image.
1452 */
cristy6fccee12011-10-20 18:43:18 +00001453 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001454 flags=ParseGeometry(argv[i+1],&geometry_info);
1455 if ((flags & SigmaValue) == 0)
1456 geometry_info.sigma=1.0;
1457 mogrify_image=EmbossImage(*image,geometry_info.rho,
1458 geometry_info.sigma,exception);
1459 break;
1460 }
1461 if (LocaleCompare("encipher",option+1) == 0)
1462 {
1463 StringInfo
1464 *passkey;
1465
1466 /*
1467 Encipher pixels.
1468 */
cristy6fccee12011-10-20 18:43:18 +00001469 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001470 passkey=FileToStringInfo(argv[i+1],~0,exception);
1471 if (passkey != (StringInfo *) NULL)
1472 {
1473 (void) PasskeyEncipherImage(*image,passkey,exception);
1474 passkey=DestroyStringInfo(passkey);
1475 }
1476 break;
1477 }
1478 if (LocaleCompare("encoding",option+1) == 0)
1479 {
1480 (void) CloneString(&draw_info->encoding,argv[i+1]);
1481 break;
1482 }
1483 if (LocaleCompare("enhance",option+1) == 0)
1484 {
1485 /*
1486 Enhance image.
1487 */
cristy6fccee12011-10-20 18:43:18 +00001488 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001489 mogrify_image=EnhanceImage(*image,exception);
1490 break;
1491 }
1492 if (LocaleCompare("equalize",option+1) == 0)
1493 {
1494 /*
1495 Equalize image.
1496 */
cristy6fccee12011-10-20 18:43:18 +00001497 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001498 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001499 break;
1500 }
1501 if (LocaleCompare("evaluate",option+1) == 0)
1502 {
1503 double
1504 constant;
1505
1506 MagickEvaluateOperator
1507 op;
1508
cristy6fccee12011-10-20 18:43:18 +00001509 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001510 op=(MagickEvaluateOperator) ParseCommandOption(
1511 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001512 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1513 1.0);
cristyd42d9952011-07-08 14:21:50 +00001514 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001515 break;
1516 }
1517 if (LocaleCompare("extent",option+1) == 0)
1518 {
1519 /*
1520 Set the image extent.
1521 */
cristy6fccee12011-10-20 18:43:18 +00001522 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001523 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1524 if (geometry.width == 0)
1525 geometry.width=(*image)->columns;
1526 if (geometry.height == 0)
1527 geometry.height=(*image)->rows;
1528 mogrify_image=ExtentImage(*image,&geometry,exception);
1529 break;
1530 }
1531 break;
1532 }
1533 case 'f':
1534 {
1535 if (LocaleCompare("family",option+1) == 0)
1536 {
1537 if (*option == '+')
1538 {
1539 if (draw_info->family != (char *) NULL)
1540 draw_info->family=DestroyString(draw_info->family);
1541 break;
1542 }
1543 (void) CloneString(&draw_info->family,argv[i+1]);
1544 break;
1545 }
1546 if (LocaleCompare("features",option+1) == 0)
1547 {
1548 if (*option == '+')
1549 {
1550 (void) DeleteImageArtifact(*image,"identify:features");
1551 break;
1552 }
1553 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1554 break;
1555 }
1556 if (LocaleCompare("fill",option+1) == 0)
1557 {
1558 ExceptionInfo
1559 *sans;
1560
cristy4c08aed2011-07-01 19:47:50 +00001561 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001562 if (*option == '+')
1563 {
cristy269c9412011-10-13 23:41:15 +00001564 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001565 exception);
1566 (void) QueryColorCompliance("none",AllCompliance,
1567 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001568 if (draw_info->fill_pattern != (Image *) NULL)
1569 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1570 break;
1571 }
1572 sans=AcquireExceptionInfo();
cristy269c9412011-10-13 23:41:15 +00001573 (void) QueryColorCompliance(argv[i+1],AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001574 sans);
1575 status=QueryColorCompliance(argv[i+1],AllCompliance,
1576 &draw_info->fill,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001577 sans=DestroyExceptionInfo(sans);
1578 if (status == MagickFalse)
1579 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1580 exception);
1581 break;
1582 }
1583 if (LocaleCompare("flip",option+1) == 0)
1584 {
1585 /*
1586 Flip image scanlines.
1587 */
cristy6fccee12011-10-20 18:43:18 +00001588 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001589 mogrify_image=FlipImage(*image,exception);
1590 break;
1591 }
anthonydf8ebac2011-04-27 09:03:19 +00001592 if (LocaleCompare("floodfill",option+1) == 0)
1593 {
cristy4c08aed2011-07-01 19:47:50 +00001594 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001595 target;
1596
1597 /*
1598 Floodfill image.
1599 */
cristy6fccee12011-10-20 18:43:18 +00001600 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001601 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001602 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001603 exception);
cristyd42d9952011-07-08 14:21:50 +00001604 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001605 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001606 break;
1607 }
anthony3d2f4862011-05-01 13:48:16 +00001608 if (LocaleCompare("flop",option+1) == 0)
1609 {
1610 /*
1611 Flop image scanlines.
1612 */
cristy6fccee12011-10-20 18:43:18 +00001613 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001614 mogrify_image=FlopImage(*image,exception);
1615 break;
1616 }
anthonydf8ebac2011-04-27 09:03:19 +00001617 if (LocaleCompare("font",option+1) == 0)
1618 {
1619 if (*option == '+')
1620 {
1621 if (draw_info->font != (char *) NULL)
1622 draw_info->font=DestroyString(draw_info->font);
1623 break;
1624 }
1625 (void) CloneString(&draw_info->font,argv[i+1]);
1626 break;
1627 }
1628 if (LocaleCompare("format",option+1) == 0)
1629 {
1630 format=argv[i+1];
1631 break;
1632 }
1633 if (LocaleCompare("frame",option+1) == 0)
1634 {
1635 FrameInfo
1636 frame_info;
1637
1638 /*
1639 Surround image with an ornamental border.
1640 */
cristy6fccee12011-10-20 18:43:18 +00001641 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001642 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1643 frame_info.width=geometry.width;
1644 frame_info.height=geometry.height;
1645 if ((flags & HeightValue) == 0)
1646 frame_info.height=geometry.width;
1647 frame_info.outer_bevel=geometry.x;
1648 frame_info.inner_bevel=geometry.y;
1649 frame_info.x=(ssize_t) frame_info.width;
1650 frame_info.y=(ssize_t) frame_info.height;
1651 frame_info.width=(*image)->columns+2*frame_info.width;
1652 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001653 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001654 break;
1655 }
1656 if (LocaleCompare("function",option+1) == 0)
1657 {
1658 char
1659 *arguments,
1660 token[MaxTextExtent];
1661
1662 const char
1663 *p;
1664
1665 double
1666 *parameters;
1667
1668 MagickFunction
1669 function;
1670
1671 register ssize_t
1672 x;
1673
1674 size_t
1675 number_parameters;
1676
1677 /*
1678 Function Modify Image Values
1679 */
cristy6fccee12011-10-20 18:43:18 +00001680 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001681 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1682 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001683 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1684 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001685 if (arguments == (char *) NULL)
1686 break;
1687 p=(char *) arguments;
1688 for (x=0; *p != '\0'; x++)
1689 {
1690 GetMagickToken(p,&p,token);
1691 if (*token == ',')
1692 GetMagickToken(p,&p,token);
1693 }
1694 number_parameters=(size_t) x;
1695 parameters=(double *) AcquireQuantumMemory(number_parameters,
1696 sizeof(*parameters));
1697 if (parameters == (double *) NULL)
1698 ThrowWandFatalException(ResourceLimitFatalError,
1699 "MemoryAllocationFailed",(*image)->filename);
1700 (void) ResetMagickMemory(parameters,0,number_parameters*
1701 sizeof(*parameters));
1702 p=(char *) arguments;
1703 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1704 {
1705 GetMagickToken(p,&p,token);
1706 if (*token == ',')
1707 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001708 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001709 }
1710 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001711 (void) FunctionImage(*image,function,number_parameters,parameters,
1712 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001713 parameters=(double *) RelinquishMagickMemory(parameters);
1714 break;
1715 }
1716 break;
1717 }
1718 case 'g':
1719 {
1720 if (LocaleCompare("gamma",option+1) == 0)
1721 {
1722 /*
1723 Gamma image.
1724 */
cristy6fccee12011-10-20 18:43:18 +00001725 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001726 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001727 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001728 else
cristydbdd0e32011-11-04 23:29:40 +00001729 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001730 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001731 break;
1732 }
1733 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1734 (LocaleCompare("gaussian",option+1) == 0))
1735 {
1736 /*
1737 Gaussian blur image.
1738 */
cristy6fccee12011-10-20 18:43:18 +00001739 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001740 flags=ParseGeometry(argv[i+1],&geometry_info);
1741 if ((flags & SigmaValue) == 0)
1742 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001743 if ((flags & XiValue) == 0)
1744 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001745 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001746 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001747 break;
1748 }
1749 if (LocaleCompare("geometry",option+1) == 0)
1750 {
1751 /*
1752 Record Image offset, Resize last image.
1753 */
cristy6fccee12011-10-20 18:43:18 +00001754 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001755 if (*option == '+')
1756 {
1757 if ((*image)->geometry != (char *) NULL)
1758 (*image)->geometry=DestroyString((*image)->geometry);
1759 break;
1760 }
1761 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1762 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1763 (void) CloneString(&(*image)->geometry,argv[i+1]);
1764 else
1765 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1766 (*image)->filter,(*image)->blur,exception);
1767 break;
1768 }
1769 if (LocaleCompare("gravity",option+1) == 0)
1770 {
1771 if (*option == '+')
1772 {
1773 draw_info->gravity=UndefinedGravity;
1774 break;
1775 }
1776 draw_info->gravity=(GravityType) ParseCommandOption(
1777 MagickGravityOptions,MagickFalse,argv[i+1]);
1778 break;
1779 }
1780 break;
1781 }
1782 case 'h':
1783 {
1784 if (LocaleCompare("highlight-color",option+1) == 0)
1785 {
1786 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1787 break;
1788 }
1789 break;
1790 }
1791 case 'i':
1792 {
1793 if (LocaleCompare("identify",option+1) == 0)
1794 {
1795 char
1796 *text;
1797
cristy6fccee12011-10-20 18:43:18 +00001798 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001799 if (format == (char *) NULL)
1800 {
cristya4037272011-08-28 15:11:39 +00001801 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1802 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001803 break;
1804 }
cristy018f07f2011-09-04 21:15:19 +00001805 text=InterpretImageProperties(mogrify_info,*image,format,
1806 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001807 if (text == (char *) NULL)
1808 break;
1809 (void) fputs(text,stdout);
1810 (void) fputc('\n',stdout);
1811 text=DestroyString(text);
1812 break;
1813 }
1814 if (LocaleCompare("implode",option+1) == 0)
1815 {
1816 /*
1817 Implode image.
1818 */
cristy6fccee12011-10-20 18:43:18 +00001819 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001820 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001821 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1822 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001823 break;
1824 }
1825 if (LocaleCompare("interline-spacing",option+1) == 0)
1826 {
1827 if (*option == '+')
1828 (void) ParseGeometry("0",&geometry_info);
1829 else
1830 (void) ParseGeometry(argv[i+1],&geometry_info);
1831 draw_info->interline_spacing=geometry_info.rho;
1832 break;
1833 }
cristy28474bf2011-09-11 23:32:52 +00001834 if (LocaleCompare("interpolate",option+1) == 0)
1835 {
1836 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1837 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1838 break;
1839 }
anthonydf8ebac2011-04-27 09:03:19 +00001840 if (LocaleCompare("interword-spacing",option+1) == 0)
1841 {
1842 if (*option == '+')
1843 (void) ParseGeometry("0",&geometry_info);
1844 else
1845 (void) ParseGeometry(argv[i+1],&geometry_info);
1846 draw_info->interword_spacing=geometry_info.rho;
1847 break;
1848 }
1849 break;
1850 }
1851 case 'k':
1852 {
1853 if (LocaleCompare("kerning",option+1) == 0)
1854 {
1855 if (*option == '+')
1856 (void) ParseGeometry("0",&geometry_info);
1857 else
1858 (void) ParseGeometry(argv[i+1],&geometry_info);
1859 draw_info->kerning=geometry_info.rho;
1860 break;
1861 }
1862 break;
1863 }
1864 case 'l':
1865 {
1866 if (LocaleCompare("lat",option+1) == 0)
1867 {
1868 /*
1869 Local adaptive threshold image.
1870 */
cristy6fccee12011-10-20 18:43:18 +00001871 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001872 flags=ParseGeometry(argv[i+1],&geometry_info);
1873 if ((flags & PercentValue) != 0)
1874 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1875 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001876 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001877 geometry_info.xi,exception);
1878 break;
1879 }
1880 if (LocaleCompare("level",option+1) == 0)
1881 {
1882 MagickRealType
1883 black_point,
1884 gamma,
1885 white_point;
1886
1887 MagickStatusType
1888 flags;
1889
1890 /*
1891 Parse levels.
1892 */
cristy6fccee12011-10-20 18:43:18 +00001893 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001894 flags=ParseGeometry(argv[i+1],&geometry_info);
1895 black_point=geometry_info.rho;
1896 white_point=(MagickRealType) QuantumRange;
1897 if ((flags & SigmaValue) != 0)
1898 white_point=geometry_info.sigma;
1899 gamma=1.0;
1900 if ((flags & XiValue) != 0)
1901 gamma=geometry_info.xi;
1902 if ((flags & PercentValue) != 0)
1903 {
1904 black_point*=(MagickRealType) (QuantumRange/100.0);
1905 white_point*=(MagickRealType) (QuantumRange/100.0);
1906 }
1907 if ((flags & SigmaValue) == 0)
1908 white_point=(MagickRealType) QuantumRange-black_point;
1909 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001910 (void) LevelizeImage(*image,black_point,white_point,gamma,
1911 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001912 else
cristy01e9afd2011-08-10 17:38:41 +00001913 (void) LevelImage(*image,black_point,white_point,gamma,
1914 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001915 break;
1916 }
1917 if (LocaleCompare("level-colors",option+1) == 0)
1918 {
1919 char
1920 token[MaxTextExtent];
1921
1922 const char
1923 *p;
1924
cristy4c08aed2011-07-01 19:47:50 +00001925 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001926 black_point,
1927 white_point;
1928
1929 p=(const char *) argv[i+1];
1930 GetMagickToken(p,&p,token); /* get black point color */
1931 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001932 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001933 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001934 else
cristy269c9412011-10-13 23:41:15 +00001935 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001936 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001937 if (isalpha((int) token[0]) || (token[0] == '#'))
1938 GetMagickToken(p,&p,token);
1939 if (*token == '\0')
1940 white_point=black_point; /* set everything to that color */
1941 else
1942 {
1943 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1944 GetMagickToken(p,&p,token); /* Get white point color. */
1945 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001946 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001947 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001948 else
cristy269c9412011-10-13 23:41:15 +00001949 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001950 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001951 }
cristy490408a2011-07-07 14:42:05 +00001952 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001953 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001954 break;
1955 }
1956 if (LocaleCompare("linear-stretch",option+1) == 0)
1957 {
1958 double
1959 black_point,
1960 white_point;
1961
1962 MagickStatusType
1963 flags;
1964
cristy6fccee12011-10-20 18:43:18 +00001965 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001966 flags=ParseGeometry(argv[i+1],&geometry_info);
1967 black_point=geometry_info.rho;
1968 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1969 if ((flags & SigmaValue) != 0)
1970 white_point=geometry_info.sigma;
1971 if ((flags & PercentValue) != 0)
1972 {
1973 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1974 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1975 }
1976 if ((flags & SigmaValue) == 0)
1977 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1978 black_point;
cristy33bd5152011-08-24 01:42:24 +00001979 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001980 break;
1981 }
1982 if (LocaleCompare("linewidth",option+1) == 0)
1983 {
cristy9b34e302011-11-05 02:15:45 +00001984 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001985 break;
1986 }
1987 if (LocaleCompare("liquid-rescale",option+1) == 0)
1988 {
1989 /*
1990 Liquid rescale image.
1991 */
cristy6fccee12011-10-20 18:43:18 +00001992 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001993 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1994 if ((flags & XValue) == 0)
1995 geometry.x=1;
1996 if ((flags & YValue) == 0)
1997 geometry.y=0;
1998 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1999 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2000 break;
2001 }
2002 if (LocaleCompare("lowlight-color",option+1) == 0)
2003 {
2004 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2005 break;
2006 }
2007 break;
2008 }
2009 case 'm':
2010 {
2011 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002012 {
cristy3ed852e2009-09-05 21:47:34 +00002013 Image
anthonydf8ebac2011-04-27 09:03:19 +00002014 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002015
anthonydf8ebac2011-04-27 09:03:19 +00002016 /*
2017 Transform image colors to match this set of colors.
2018 */
cristy6fccee12011-10-20 18:43:18 +00002019 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002020 if (*option == '+')
2021 break;
2022 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2023 if (remap_image == (Image *) NULL)
2024 break;
cristy018f07f2011-09-04 21:15:19 +00002025 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002026 remap_image=DestroyImage(remap_image);
2027 break;
2028 }
2029 if (LocaleCompare("mask",option+1) == 0)
2030 {
2031 Image
2032 *mask;
2033
cristy6fccee12011-10-20 18:43:18 +00002034 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002035 if (*option == '+')
2036 {
2037 /*
2038 Remove a mask.
2039 */
cristy018f07f2011-09-04 21:15:19 +00002040 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002041 break;
2042 }
2043 /*
2044 Set the image mask.
2045 */
2046 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2047 if (mask == (Image *) NULL)
2048 break;
cristy018f07f2011-09-04 21:15:19 +00002049 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002050 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002051 break;
2052 }
2053 if (LocaleCompare("matte",option+1) == 0)
2054 {
2055 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002056 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002057 break;
2058 }
2059 if (LocaleCompare("median",option+1) == 0)
2060 {
2061 /*
2062 Median filter image.
2063 */
cristy6fccee12011-10-20 18:43:18 +00002064 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002065 flags=ParseGeometry(argv[i+1],&geometry_info);
2066 if ((flags & SigmaValue) == 0)
2067 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002068 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002069 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002070 break;
2071 }
2072 if (LocaleCompare("mode",option+1) == 0)
2073 {
2074 /*
2075 Mode image.
2076 */
cristy6fccee12011-10-20 18:43:18 +00002077 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002078 flags=ParseGeometry(argv[i+1],&geometry_info);
2079 if ((flags & SigmaValue) == 0)
2080 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002081 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002082 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002083 break;
2084 }
2085 if (LocaleCompare("modulate",option+1) == 0)
2086 {
cristy6fccee12011-10-20 18:43:18 +00002087 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002088 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002089 break;
2090 }
2091 if (LocaleCompare("monitor",option+1) == 0)
2092 {
2093 if (*option == '+')
2094 {
2095 (void) SetImageProgressMonitor(*image,
2096 (MagickProgressMonitor) NULL,(void *) NULL);
2097 break;
2098 }
2099 (void) SetImageProgressMonitor(*image,MonitorProgress,
2100 (void *) NULL);
2101 break;
2102 }
2103 if (LocaleCompare("monochrome",option+1) == 0)
2104 {
cristy6fccee12011-10-20 18:43:18 +00002105 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002106 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002107 break;
2108 }
2109 if (LocaleCompare("morphology",option+1) == 0)
2110 {
2111 char
2112 token[MaxTextExtent];
2113
2114 const char
2115 *p;
2116
2117 KernelInfo
2118 *kernel;
2119
2120 MorphologyMethod
2121 method;
2122
2123 ssize_t
2124 iterations;
2125
2126 /*
2127 Morphological Image Operation
2128 */
cristy6fccee12011-10-20 18:43:18 +00002129 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002130 p=argv[i+1];
2131 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002132 method=(MorphologyMethod) ParseCommandOption(
2133 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002134 iterations=1L;
2135 GetMagickToken(p,&p,token);
2136 if ((*p == ':') || (*p == ','))
2137 GetMagickToken(p,&p,token);
2138 if ((*p != '\0'))
2139 iterations=(ssize_t) StringToLong(p);
2140 kernel=AcquireKernelInfo(argv[i+2]);
2141 if (kernel == (KernelInfo *) NULL)
2142 {
2143 (void) ThrowMagickException(exception,GetMagickModule(),
2144 OptionError,"UnabletoParseKernel","morphology");
2145 status=MagickFalse;
2146 break;
2147 }
cristyf4ad9df2011-07-08 16:49:03 +00002148 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2149 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002150 kernel=DestroyKernelInfo(kernel);
2151 break;
2152 }
2153 if (LocaleCompare("motion-blur",option+1) == 0)
2154 {
2155 /*
2156 Motion blur image.
2157 */
cristy6fccee12011-10-20 18:43:18 +00002158 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002159 flags=ParseGeometry(argv[i+1],&geometry_info);
2160 if ((flags & SigmaValue) == 0)
2161 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002162 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristy7497f482011-12-08 01:57:31 +00002163 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002164 break;
2165 }
2166 break;
2167 }
2168 case 'n':
2169 {
2170 if (LocaleCompare("negate",option+1) == 0)
2171 {
cristy6fccee12011-10-20 18:43:18 +00002172 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002173 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002174 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002175 break;
2176 }
2177 if (LocaleCompare("noise",option+1) == 0)
2178 {
cristy6fccee12011-10-20 18:43:18 +00002179 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002180 if (*option == '-')
2181 {
cristyf36cbcb2011-09-07 13:28:22 +00002182 flags=ParseGeometry(argv[i+1],&geometry_info);
2183 if ((flags & SigmaValue) == 0)
2184 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002185 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002186 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002187 }
2188 else
2189 {
2190 NoiseType
2191 noise;
2192
2193 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2194 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002195 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002196 }
2197 break;
2198 }
2199 if (LocaleCompare("normalize",option+1) == 0)
2200 {
cristy6fccee12011-10-20 18:43:18 +00002201 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002202 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002203 break;
2204 }
2205 break;
2206 }
2207 case 'o':
2208 {
2209 if (LocaleCompare("opaque",option+1) == 0)
2210 {
cristy4c08aed2011-07-01 19:47:50 +00002211 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002212 target;
2213
cristy6fccee12011-10-20 18:43:18 +00002214 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002215 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002216 exception);
cristyd42d9952011-07-08 14:21:50 +00002217 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002218 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002219 break;
2220 }
2221 if (LocaleCompare("ordered-dither",option+1) == 0)
2222 {
cristy6fccee12011-10-20 18:43:18 +00002223 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002224 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002225 break;
2226 }
2227 break;
2228 }
2229 case 'p':
2230 {
2231 if (LocaleCompare("paint",option+1) == 0)
2232 {
cristy6fccee12011-10-20 18:43:18 +00002233 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002234 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002235 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2236 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002237 break;
2238 }
2239 if (LocaleCompare("pen",option+1) == 0)
2240 {
2241 if (*option == '+')
2242 {
cristy9950d572011-10-01 18:22:35 +00002243 (void) QueryColorCompliance("none",AllCompliance,
2244 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002245 break;
2246 }
cristy9950d572011-10-01 18:22:35 +00002247 (void) QueryColorCompliance(argv[i+1],AllCompliance,
2248 &draw_info->fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002249 break;
2250 }
2251 if (LocaleCompare("pointsize",option+1) == 0)
2252 {
2253 if (*option == '+')
2254 (void) ParseGeometry("12",&geometry_info);
2255 else
2256 (void) ParseGeometry(argv[i+1],&geometry_info);
2257 draw_info->pointsize=geometry_info.rho;
2258 break;
2259 }
2260 if (LocaleCompare("polaroid",option+1) == 0)
2261 {
2262 double
2263 angle;
2264
2265 RandomInfo
2266 *random_info;
2267
2268 /*
2269 Simulate a Polaroid picture.
2270 */
cristy6fccee12011-10-20 18:43:18 +00002271 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002272 random_info=AcquireRandomInfo();
2273 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2274 random_info=DestroyRandomInfo(random_info);
2275 if (*option == '-')
2276 {
2277 SetGeometryInfo(&geometry_info);
2278 flags=ParseGeometry(argv[i+1],&geometry_info);
2279 angle=geometry_info.rho;
2280 }
cristy5c4e2582011-09-11 19:21:03 +00002281 mogrify_image=PolaroidImage(*image,draw_info,angle,
cristy28474bf2011-09-11 23:32:52 +00002282 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002283 break;
2284 }
2285 if (LocaleCompare("posterize",option+1) == 0)
2286 {
2287 /*
2288 Posterize image.
2289 */
cristy6fccee12011-10-20 18:43:18 +00002290 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002291 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002292 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002293 break;
2294 }
2295 if (LocaleCompare("preview",option+1) == 0)
2296 {
2297 PreviewType
2298 preview_type;
2299
2300 /*
2301 Preview image.
2302 */
cristy6fccee12011-10-20 18:43:18 +00002303 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002304 if (*option == '+')
2305 preview_type=UndefinedPreview;
2306 else
cristy28474bf2011-09-11 23:32:52 +00002307 preview_type=(PreviewType) ParseCommandOption(
2308 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002309 mogrify_image=PreviewImage(*image,preview_type,exception);
2310 break;
2311 }
2312 if (LocaleCompare("profile",option+1) == 0)
2313 {
2314 const char
2315 *name;
2316
2317 const StringInfo
2318 *profile;
2319
2320 Image
2321 *profile_image;
2322
2323 ImageInfo
2324 *profile_info;
2325
cristy6fccee12011-10-20 18:43:18 +00002326 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002327 if (*option == '+')
2328 {
2329 /*
2330 Remove a profile from the image.
2331 */
2332 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002333 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002334 break;
2335 }
2336 /*
2337 Associate a profile with the image.
2338 */
2339 profile_info=CloneImageInfo(mogrify_info);
2340 profile=GetImageProfile(*image,"iptc");
2341 if (profile != (StringInfo *) NULL)
2342 profile_info->profile=(void *) CloneStringInfo(profile);
2343 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2344 profile_info=DestroyImageInfo(profile_info);
2345 if (profile_image == (Image *) NULL)
2346 {
2347 StringInfo
2348 *profile;
2349
2350 profile_info=CloneImageInfo(mogrify_info);
2351 (void) CopyMagickString(profile_info->filename,argv[i+1],
2352 MaxTextExtent);
2353 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2354 if (profile != (StringInfo *) NULL)
2355 {
2356 (void) ProfileImage(*image,profile_info->magick,
2357 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002358 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002359 profile=DestroyStringInfo(profile);
2360 }
2361 profile_info=DestroyImageInfo(profile_info);
2362 break;
2363 }
2364 ResetImageProfileIterator(profile_image);
2365 name=GetNextImageProfile(profile_image);
2366 while (name != (const char *) NULL)
2367 {
2368 profile=GetImageProfile(profile_image,name);
2369 if (profile != (StringInfo *) NULL)
2370 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002371 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002372 name=GetNextImageProfile(profile_image);
2373 }
2374 profile_image=DestroyImage(profile_image);
2375 break;
2376 }
2377 break;
2378 }
2379 case 'q':
2380 {
2381 if (LocaleCompare("quantize",option+1) == 0)
2382 {
2383 if (*option == '+')
2384 {
2385 quantize_info->colorspace=UndefinedColorspace;
2386 break;
2387 }
2388 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2389 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2390 break;
2391 }
2392 break;
2393 }
2394 case 'r':
2395 {
2396 if (LocaleCompare("radial-blur",option+1) == 0)
2397 {
2398 /*
2399 Radial blur image.
2400 */
cristy6fccee12011-10-20 18:43:18 +00002401 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002402 flags=ParseGeometry(argv[i+1],&geometry_info);
2403 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2404 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002405 break;
2406 }
2407 if (LocaleCompare("raise",option+1) == 0)
2408 {
2409 /*
2410 Surround image with a raise of solid color.
2411 */
2412 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2413 if ((flags & SigmaValue) == 0)
2414 geometry.height=geometry.width;
2415 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002416 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002417 break;
2418 }
2419 if (LocaleCompare("random-threshold",option+1) == 0)
2420 {
2421 /*
2422 Threshold image.
2423 */
cristy6fccee12011-10-20 18:43:18 +00002424 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002425 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002426 break;
2427 }
2428 if (LocaleCompare("recolor",option+1) == 0)
2429 {
2430 KernelInfo
2431 *kernel;
2432
cristy6fccee12011-10-20 18:43:18 +00002433 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002434 kernel=AcquireKernelInfo(argv[i+1]);
2435 if (kernel == (KernelInfo *) NULL)
2436 break;
2437 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2438 kernel=DestroyKernelInfo(kernel);
2439 break;
2440 }
2441 if (LocaleCompare("region",option+1) == 0)
2442 {
cristy6fccee12011-10-20 18:43:18 +00002443 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002444 if (region_image != (Image *) NULL)
2445 {
2446 /*
2447 Composite region.
2448 */
2449 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002450 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002451 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002452 *image=DestroyImage(*image);
2453 *image=region_image;
2454 region_image = (Image *) NULL;
2455 }
2456 if (*option == '+')
2457 break;
2458 /*
2459 Apply transformations to a selected region of the image.
2460 */
cristy3ed852e2009-09-05 21:47:34 +00002461 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2462 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002463 mogrify_image=CropImage(*image,&region_geometry,exception);
2464 if (mogrify_image == (Image *) NULL)
2465 break;
2466 region_image=(*image);
2467 *image=mogrify_image;
2468 mogrify_image=(Image *) NULL;
2469 break;
cristy3ed852e2009-09-05 21:47:34 +00002470 }
anthonydf8ebac2011-04-27 09:03:19 +00002471 if (LocaleCompare("render",option+1) == 0)
2472 {
cristy6fccee12011-10-20 18:43:18 +00002473 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002474 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2475 break;
2476 }
2477 if (LocaleCompare("remap",option+1) == 0)
2478 {
2479 Image
2480 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002481
anthonydf8ebac2011-04-27 09:03:19 +00002482 /*
2483 Transform image colors to match this set of colors.
2484 */
cristy6fccee12011-10-20 18:43:18 +00002485 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002486 if (*option == '+')
2487 break;
2488 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2489 if (remap_image == (Image *) NULL)
2490 break;
cristy018f07f2011-09-04 21:15:19 +00002491 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002492 remap_image=DestroyImage(remap_image);
2493 break;
2494 }
2495 if (LocaleCompare("repage",option+1) == 0)
2496 {
2497 if (*option == '+')
2498 {
2499 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2500 break;
2501 }
2502 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002503 break;
2504 }
2505 if (LocaleCompare("resample",option+1) == 0)
2506 {
2507 /*
2508 Resample image.
2509 */
cristy6fccee12011-10-20 18:43:18 +00002510 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002511 flags=ParseGeometry(argv[i+1],&geometry_info);
2512 if ((flags & SigmaValue) == 0)
2513 geometry_info.sigma=geometry_info.rho;
2514 mogrify_image=ResampleImage(*image,geometry_info.rho,
2515 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2516 break;
2517 }
2518 if (LocaleCompare("resize",option+1) == 0)
2519 {
2520 /*
2521 Resize image.
2522 */
cristy6fccee12011-10-20 18:43:18 +00002523 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002524 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2525 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2526 (*image)->filter,(*image)->blur,exception);
2527 break;
2528 }
2529 if (LocaleCompare("roll",option+1) == 0)
2530 {
2531 /*
2532 Roll image.
2533 */
cristy6fccee12011-10-20 18:43:18 +00002534 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002535 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2536 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2537 break;
2538 }
2539 if (LocaleCompare("rotate",option+1) == 0)
2540 {
2541 char
2542 *geometry;
2543
2544 /*
2545 Check for conditional image rotation.
2546 */
cristy6fccee12011-10-20 18:43:18 +00002547 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002548 if (strchr(argv[i+1],'>') != (char *) NULL)
2549 if ((*image)->columns <= (*image)->rows)
2550 break;
2551 if (strchr(argv[i+1],'<') != (char *) NULL)
2552 if ((*image)->columns >= (*image)->rows)
2553 break;
2554 /*
2555 Rotate image.
2556 */
2557 geometry=ConstantString(argv[i+1]);
2558 (void) SubstituteString(&geometry,">","");
2559 (void) SubstituteString(&geometry,"<","");
2560 (void) ParseGeometry(geometry,&geometry_info);
2561 geometry=DestroyString(geometry);
2562 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2563 break;
2564 }
2565 break;
2566 }
2567 case 's':
2568 {
2569 if (LocaleCompare("sample",option+1) == 0)
2570 {
2571 /*
2572 Sample image with pixel replication.
2573 */
cristy6fccee12011-10-20 18:43:18 +00002574 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002575 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2576 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2577 exception);
2578 break;
2579 }
2580 if (LocaleCompare("scale",option+1) == 0)
2581 {
2582 /*
2583 Resize image.
2584 */
cristy6fccee12011-10-20 18:43:18 +00002585 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002586 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2587 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2588 exception);
2589 break;
2590 }
2591 if (LocaleCompare("selective-blur",option+1) == 0)
2592 {
2593 /*
2594 Selectively blur pixels within a contrast threshold.
2595 */
cristy6fccee12011-10-20 18:43:18 +00002596 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002597 flags=ParseGeometry(argv[i+1],&geometry_info);
2598 if ((flags & PercentValue) != 0)
2599 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002600 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002601 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002602 break;
2603 }
2604 if (LocaleCompare("separate",option+1) == 0)
2605 {
2606 /*
2607 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002608 */
cristy6fccee12011-10-20 18:43:18 +00002609 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3139dc22011-07-08 00:11:42 +00002610 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002611 break;
2612 }
2613 if (LocaleCompare("sepia-tone",option+1) == 0)
2614 {
2615 double
2616 threshold;
2617
2618 /*
2619 Sepia-tone image.
2620 */
cristy6fccee12011-10-20 18:43:18 +00002621 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002622 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2623 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002624 mogrify_image=SepiaToneImage(*image,threshold,exception);
2625 break;
2626 }
2627 if (LocaleCompare("segment",option+1) == 0)
2628 {
2629 /*
2630 Segment image.
2631 */
cristy6fccee12011-10-20 18:43:18 +00002632 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002633 flags=ParseGeometry(argv[i+1],&geometry_info);
2634 if ((flags & SigmaValue) == 0)
2635 geometry_info.sigma=1.0;
2636 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002637 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2638 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002639 break;
2640 }
2641 if (LocaleCompare("set",option+1) == 0)
2642 {
2643 char
2644 *value;
2645
2646 /*
2647 Set image option.
2648 */
2649 if (*option == '+')
2650 {
2651 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2652 (void) DeleteImageRegistry(argv[i+1]+9);
2653 else
2654 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2655 {
2656 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2657 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2658 }
2659 else
2660 (void) DeleteImageProperty(*image,argv[i+1]);
2661 break;
2662 }
cristy018f07f2011-09-04 21:15:19 +00002663 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2664 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002665 if (value == (char *) NULL)
2666 break;
2667 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2668 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2669 exception);
2670 else
2671 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2672 {
2673 (void) SetImageOption(image_info,argv[i+1]+7,value);
2674 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2675 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2676 }
2677 else
cristyd15e6592011-10-15 00:13:06 +00002678 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002679 value=DestroyString(value);
2680 break;
2681 }
2682 if (LocaleCompare("shade",option+1) == 0)
2683 {
2684 /*
2685 Shade image.
2686 */
cristy6fccee12011-10-20 18:43:18 +00002687 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002688 flags=ParseGeometry(argv[i+1],&geometry_info);
2689 if ((flags & SigmaValue) == 0)
2690 geometry_info.sigma=1.0;
2691 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2692 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2693 break;
2694 }
2695 if (LocaleCompare("shadow",option+1) == 0)
2696 {
2697 /*
2698 Shadow image.
2699 */
cristy6fccee12011-10-20 18:43:18 +00002700 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002701 flags=ParseGeometry(argv[i+1],&geometry_info);
2702 if ((flags & SigmaValue) == 0)
2703 geometry_info.sigma=1.0;
2704 if ((flags & XiValue) == 0)
2705 geometry_info.xi=4.0;
2706 if ((flags & PsiValue) == 0)
2707 geometry_info.psi=4.0;
2708 mogrify_image=ShadowImage(*image,geometry_info.rho,
2709 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2710 ceil(geometry_info.psi-0.5),exception);
2711 break;
2712 }
2713 if (LocaleCompare("sharpen",option+1) == 0)
2714 {
2715 /*
2716 Sharpen image.
2717 */
cristy6fccee12011-10-20 18:43:18 +00002718 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002719 flags=ParseGeometry(argv[i+1],&geometry_info);
2720 if ((flags & SigmaValue) == 0)
2721 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002722 if ((flags & XiValue) == 0)
2723 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002724 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002725 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002726 break;
2727 }
2728 if (LocaleCompare("shave",option+1) == 0)
2729 {
2730 /*
2731 Shave the image edges.
2732 */
cristy6fccee12011-10-20 18:43:18 +00002733 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002734 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2735 mogrify_image=ShaveImage(*image,&geometry,exception);
2736 break;
2737 }
2738 if (LocaleCompare("shear",option+1) == 0)
2739 {
2740 /*
2741 Shear image.
2742 */
cristy6fccee12011-10-20 18:43:18 +00002743 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002744 flags=ParseGeometry(argv[i+1],&geometry_info);
2745 if ((flags & SigmaValue) == 0)
2746 geometry_info.sigma=geometry_info.rho;
2747 mogrify_image=ShearImage(*image,geometry_info.rho,
2748 geometry_info.sigma,exception);
2749 break;
2750 }
2751 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2752 {
2753 /*
2754 Sigmoidal non-linearity contrast control.
2755 */
cristy6fccee12011-10-20 18:43:18 +00002756 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002757 flags=ParseGeometry(argv[i+1],&geometry_info);
2758 if ((flags & SigmaValue) == 0)
2759 geometry_info.sigma=(double) QuantumRange/2.0;
2760 if ((flags & PercentValue) != 0)
2761 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2762 100.0;
cristy9ee60942011-07-06 14:54:38 +00002763 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002764 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2765 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002766 break;
2767 }
2768 if (LocaleCompare("sketch",option+1) == 0)
2769 {
2770 /*
2771 Sketch image.
2772 */
cristy6fccee12011-10-20 18:43:18 +00002773 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002774 flags=ParseGeometry(argv[i+1],&geometry_info);
2775 if ((flags & SigmaValue) == 0)
2776 geometry_info.sigma=1.0;
2777 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002778 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002779 break;
2780 }
2781 if (LocaleCompare("solarize",option+1) == 0)
2782 {
2783 double
2784 threshold;
2785
cristy6fccee12011-10-20 18:43:18 +00002786 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002787 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2788 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002789 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002790 break;
2791 }
2792 if (LocaleCompare("sparse-color",option+1) == 0)
2793 {
2794 SparseColorMethod
2795 method;
2796
2797 char
2798 *arguments;
2799
2800 /*
2801 Sparse Color Interpolated Gradient
2802 */
cristy6fccee12011-10-20 18:43:18 +00002803 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002804 method=(SparseColorMethod) ParseCommandOption(
2805 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002806 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2807 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002808 if (arguments == (char *) NULL)
2809 break;
cristy3884f692011-07-08 18:00:18 +00002810 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002811 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2812 arguments=DestroyString(arguments);
2813 break;
2814 }
2815 if (LocaleCompare("splice",option+1) == 0)
2816 {
2817 /*
2818 Splice a solid color into the image.
2819 */
cristy6fccee12011-10-20 18:43:18 +00002820 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002821 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2822 mogrify_image=SpliceImage(*image,&geometry,exception);
2823 break;
2824 }
2825 if (LocaleCompare("spread",option+1) == 0)
2826 {
2827 /*
2828 Spread an image.
2829 */
cristy6fccee12011-10-20 18:43:18 +00002830 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002831 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002832 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002833 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002834 break;
2835 }
2836 if (LocaleCompare("statistic",option+1) == 0)
2837 {
2838 StatisticType
2839 type;
2840
cristy6fccee12011-10-20 18:43:18 +00002841 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002842 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2843 MagickFalse,argv[i+1]);
2844 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002845 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2846 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002847 break;
2848 }
2849 if (LocaleCompare("stretch",option+1) == 0)
2850 {
2851 if (*option == '+')
2852 {
2853 draw_info->stretch=UndefinedStretch;
2854 break;
2855 }
2856 draw_info->stretch=(StretchType) ParseCommandOption(
2857 MagickStretchOptions,MagickFalse,argv[i+1]);
2858 break;
2859 }
2860 if (LocaleCompare("strip",option+1) == 0)
2861 {
2862 /*
2863 Strip image of profiles and comments.
2864 */
cristy6fccee12011-10-20 18:43:18 +00002865 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002866 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002867 break;
2868 }
2869 if (LocaleCompare("stroke",option+1) == 0)
2870 {
2871 ExceptionInfo
2872 *sans;
2873
2874 if (*option == '+')
2875 {
cristy9950d572011-10-01 18:22:35 +00002876 (void) QueryColorCompliance("none",AllCompliance,
2877 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002878 if (draw_info->stroke_pattern != (Image *) NULL)
2879 draw_info->stroke_pattern=DestroyImage(
2880 draw_info->stroke_pattern);
2881 break;
2882 }
2883 sans=AcquireExceptionInfo();
cristy9950d572011-10-01 18:22:35 +00002884 status=QueryColorCompliance(argv[i+1],AllCompliance,
2885 &draw_info->stroke,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002886 sans=DestroyExceptionInfo(sans);
2887 if (status == MagickFalse)
2888 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2889 exception);
2890 break;
2891 }
2892 if (LocaleCompare("strokewidth",option+1) == 0)
2893 {
cristy9b34e302011-11-05 02:15:45 +00002894 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002895 break;
2896 }
2897 if (LocaleCompare("style",option+1) == 0)
2898 {
2899 if (*option == '+')
2900 {
2901 draw_info->style=UndefinedStyle;
2902 break;
2903 }
2904 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2905 MagickFalse,argv[i+1]);
2906 break;
2907 }
2908 if (LocaleCompare("swirl",option+1) == 0)
2909 {
2910 /*
2911 Swirl image.
2912 */
cristy6fccee12011-10-20 18:43:18 +00002913 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002914 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002915 mogrify_image=SwirlImage(*image,geometry_info.rho,
2916 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002917 break;
2918 }
2919 break;
2920 }
2921 case 't':
2922 {
2923 if (LocaleCompare("threshold",option+1) == 0)
2924 {
2925 double
2926 threshold;
2927
2928 /*
2929 Threshold image.
2930 */
cristy6fccee12011-10-20 18:43:18 +00002931 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002932 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002933 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002934 else
cristy9b34e302011-11-05 02:15:45 +00002935 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2936 1.0);
cristye941a752011-10-15 01:52:48 +00002937 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002938 break;
2939 }
2940 if (LocaleCompare("thumbnail",option+1) == 0)
2941 {
2942 /*
2943 Thumbnail image.
2944 */
cristy6fccee12011-10-20 18:43:18 +00002945 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002946 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2947 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2948 exception);
2949 break;
2950 }
2951 if (LocaleCompare("tile",option+1) == 0)
2952 {
2953 if (*option == '+')
2954 {
2955 if (draw_info->fill_pattern != (Image *) NULL)
2956 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2957 break;
2958 }
2959 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2960 exception);
2961 break;
2962 }
2963 if (LocaleCompare("tint",option+1) == 0)
2964 {
2965 /*
2966 Tint the image.
2967 */
cristy6fccee12011-10-20 18:43:18 +00002968 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00002969 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002970 break;
2971 }
2972 if (LocaleCompare("transform",option+1) == 0)
2973 {
2974 /*
2975 Affine transform image.
2976 */
cristy6fccee12011-10-20 18:43:18 +00002977 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002978 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2979 exception);
2980 break;
2981 }
2982 if (LocaleCompare("transparent",option+1) == 0)
2983 {
cristy4c08aed2011-07-01 19:47:50 +00002984 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002985 target;
2986
cristy6fccee12011-10-20 18:43:18 +00002987 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002988 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002989 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002990 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002991 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00002992 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002993 break;
2994 }
2995 if (LocaleCompare("transpose",option+1) == 0)
2996 {
2997 /*
2998 Transpose image scanlines.
2999 */
cristy6fccee12011-10-20 18:43:18 +00003000 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003001 mogrify_image=TransposeImage(*image,exception);
3002 break;
3003 }
3004 if (LocaleCompare("transverse",option+1) == 0)
3005 {
3006 /*
3007 Transverse image scanlines.
3008 */
cristy6fccee12011-10-20 18:43:18 +00003009 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003010 mogrify_image=TransverseImage(*image,exception);
3011 break;
3012 }
3013 if (LocaleCompare("treedepth",option+1) == 0)
3014 {
3015 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3016 break;
3017 }
3018 if (LocaleCompare("trim",option+1) == 0)
3019 {
3020 /*
3021 Trim image.
3022 */
cristy6fccee12011-10-20 18:43:18 +00003023 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003024 mogrify_image=TrimImage(*image,exception);
3025 break;
3026 }
3027 if (LocaleCompare("type",option+1) == 0)
3028 {
3029 ImageType
3030 type;
3031
cristy6fccee12011-10-20 18:43:18 +00003032 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003033 if (*option == '+')
3034 type=UndefinedType;
3035 else
3036 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3037 argv[i+1]);
3038 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003039 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003040 break;
3041 }
3042 break;
3043 }
3044 case 'u':
3045 {
3046 if (LocaleCompare("undercolor",option+1) == 0)
3047 {
cristy9950d572011-10-01 18:22:35 +00003048 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3049 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003050 break;
3051 }
3052 if (LocaleCompare("unique",option+1) == 0)
3053 {
3054 if (*option == '+')
3055 {
3056 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3057 break;
3058 }
3059 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3060 (void) SetImageArtifact(*image,"verbose","true");
3061 break;
3062 }
3063 if (LocaleCompare("unique-colors",option+1) == 0)
3064 {
3065 /*
3066 Unique image colors.
3067 */
cristy6fccee12011-10-20 18:43:18 +00003068 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003069 mogrify_image=UniqueImageColors(*image,exception);
3070 break;
3071 }
3072 if (LocaleCompare("unsharp",option+1) == 0)
3073 {
3074 /*
3075 Unsharp mask image.
3076 */
cristy6fccee12011-10-20 18:43:18 +00003077 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003078 flags=ParseGeometry(argv[i+1],&geometry_info);
3079 if ((flags & SigmaValue) == 0)
3080 geometry_info.sigma=1.0;
3081 if ((flags & XiValue) == 0)
3082 geometry_info.xi=1.0;
3083 if ((flags & PsiValue) == 0)
3084 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003085 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3086 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003087 break;
3088 }
3089 break;
3090 }
3091 case 'v':
3092 {
3093 if (LocaleCompare("verbose",option+1) == 0)
3094 {
3095 (void) SetImageArtifact(*image,option+1,
3096 *option == '+' ? "false" : "true");
3097 break;
3098 }
3099 if (LocaleCompare("vignette",option+1) == 0)
3100 {
3101 /*
3102 Vignette image.
3103 */
cristy6fccee12011-10-20 18:43:18 +00003104 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003105 flags=ParseGeometry(argv[i+1],&geometry_info);
3106 if ((flags & SigmaValue) == 0)
3107 geometry_info.sigma=1.0;
3108 if ((flags & XiValue) == 0)
3109 geometry_info.xi=0.1*(*image)->columns;
3110 if ((flags & PsiValue) == 0)
3111 geometry_info.psi=0.1*(*image)->rows;
3112 mogrify_image=VignetteImage(*image,geometry_info.rho,
3113 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3114 ceil(geometry_info.psi-0.5),exception);
3115 break;
3116 }
3117 if (LocaleCompare("virtual-pixel",option+1) == 0)
3118 {
3119 if (*option == '+')
3120 {
3121 (void) SetImageVirtualPixelMethod(*image,
3122 UndefinedVirtualPixelMethod);
3123 break;
3124 }
3125 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3126 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3127 argv[i+1]));
3128 break;
3129 }
3130 break;
3131 }
3132 case 'w':
3133 {
3134 if (LocaleCompare("wave",option+1) == 0)
3135 {
3136 /*
3137 Wave image.
3138 */
cristy6fccee12011-10-20 18:43:18 +00003139 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003140 flags=ParseGeometry(argv[i+1],&geometry_info);
3141 if ((flags & SigmaValue) == 0)
3142 geometry_info.sigma=1.0;
3143 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003144 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003145 break;
3146 }
3147 if (LocaleCompare("weight",option+1) == 0)
3148 {
3149 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3150 if (LocaleCompare(argv[i+1],"all") == 0)
3151 draw_info->weight=0;
3152 if (LocaleCompare(argv[i+1],"bold") == 0)
3153 draw_info->weight=700;
3154 if (LocaleCompare(argv[i+1],"bolder") == 0)
3155 if (draw_info->weight <= 800)
3156 draw_info->weight+=100;
3157 if (LocaleCompare(argv[i+1],"lighter") == 0)
3158 if (draw_info->weight >= 100)
3159 draw_info->weight-=100;
3160 if (LocaleCompare(argv[i+1],"normal") == 0)
3161 draw_info->weight=400;
3162 break;
3163 }
3164 if (LocaleCompare("white-threshold",option+1) == 0)
3165 {
3166 /*
3167 White threshold image.
3168 */
cristy6fccee12011-10-20 18:43:18 +00003169 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003170 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003171 break;
3172 }
3173 break;
3174 }
3175 default:
3176 break;
3177 }
3178 /*
3179 Replace current image with any image that was generated
3180 */
3181 if (mogrify_image != (Image *) NULL)
3182 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003183 i+=count;
3184 }
3185 if (region_image != (Image *) NULL)
3186 {
anthonydf8ebac2011-04-27 09:03:19 +00003187 /*
3188 Composite transformed region onto image.
3189 */
cristy6fccee12011-10-20 18:43:18 +00003190 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonya129f702011-04-14 01:08:48 +00003191 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003192 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003193 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003194 *image=DestroyImage(*image);
3195 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003196 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003197 }
3198 /*
3199 Free resources.
3200 */
anthonydf8ebac2011-04-27 09:03:19 +00003201 quantize_info=DestroyQuantizeInfo(quantize_info);
3202 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003203 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003204 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003205 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003206}
3207
3208/*
3209%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3210% %
3211% %
3212% %
cristy5063d812010-10-19 16:28:10 +00003213+ 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 +00003214% %
3215% %
3216% %
3217%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3218%
3219% MogrifyImageCommand() transforms an image or a sequence of images. These
3220% transforms include image scaling, image rotation, color reduction, and
3221% others. The transmogrified image overwrites the original image.
3222%
3223% The format of the MogrifyImageCommand method is:
3224%
3225% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3226% const char **argv,char **metadata,ExceptionInfo *exception)
3227%
3228% A description of each parameter follows:
3229%
3230% o image_info: the image info.
3231%
3232% o argc: the number of elements in the argument vector.
3233%
3234% o argv: A text array containing the command line arguments.
3235%
3236% o metadata: any metadata is returned here.
3237%
3238% o exception: return any errors or warnings in this structure.
3239%
3240*/
3241
3242static MagickBooleanType MogrifyUsage(void)
3243{
3244 static const char
3245 *miscellaneous[]=
3246 {
3247 "-debug events display copious debugging information",
3248 "-help print program options",
3249 "-list type print a list of supported option arguments",
3250 "-log format format of debugging information",
3251 "-version print version information",
3252 (char *) NULL
3253 },
3254 *operators[]=
3255 {
3256 "-adaptive-blur geometry",
3257 " adaptively blur pixels; decrease effect near edges",
3258 "-adaptive-resize geometry",
3259 " adaptively resize image using 'mesh' interpolation",
3260 "-adaptive-sharpen geometry",
3261 " adaptively sharpen pixels; increase effect near edges",
3262 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3263 " transparent, extract, background, or shape",
3264 "-annotate geometry text",
3265 " annotate the image with text",
3266 "-auto-gamma automagically adjust gamma level of image",
3267 "-auto-level automagically adjust color levels of image",
3268 "-auto-orient automagically orient (rotate) image",
3269 "-bench iterations measure performance",
3270 "-black-threshold value",
3271 " force all pixels below the threshold into black",
3272 "-blue-shift simulate a scene at nighttime in the moonlight",
3273 "-blur geometry reduce image noise and reduce detail levels",
3274 "-border geometry surround image with a border of color",
3275 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003276 "-brightness-contrast geometry",
3277 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003278 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003279 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003280 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003281 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003282 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003283 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003284 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003285 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003286 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003287 "-contrast enhance or reduce the image contrast",
3288 "-contrast-stretch geometry",
3289 " improve contrast by `stretching' the intensity range",
3290 "-convolve coefficients",
3291 " apply a convolution kernel to the image",
3292 "-cycle amount cycle the image colormap",
3293 "-decipher filename convert cipher pixels to plain pixels",
3294 "-deskew threshold straighten an image",
3295 "-despeckle reduce the speckles within an image",
3296 "-distort method args",
3297 " distort images according to given method ad args",
3298 "-draw string annotate the image with a graphic primitive",
3299 "-edge radius apply a filter to detect edges in the image",
3300 "-encipher filename convert plain pixels to cipher pixels",
3301 "-emboss radius emboss an image",
3302 "-enhance apply a digital filter to enhance a noisy image",
3303 "-equalize perform histogram equalization to an image",
3304 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003305 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003306 "-extent geometry set the image size",
3307 "-extract geometry extract area from image",
3308 "-fft implements the discrete Fourier transform (DFT)",
3309 "-flip flip image vertically",
3310 "-floodfill geometry color",
3311 " floodfill the image with color",
3312 "-flop flop image horizontally",
3313 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003314 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003315 " apply function over image values",
3316 "-gamma value level of gamma correction",
3317 "-gaussian-blur geometry",
3318 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003319 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003320 "-identify identify the format and characteristics of the image",
3321 "-ift implements the inverse discrete Fourier transform (DFT)",
3322 "-implode amount implode image pixels about the center",
3323 "-lat geometry local adaptive thresholding",
3324 "-layers method optimize, merge, or compare image layers",
3325 "-level value adjust the level of image contrast",
3326 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003327 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003328 "-linear-stretch geometry",
3329 " improve contrast by `stretching with saturation'",
3330 "-liquid-rescale geometry",
3331 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003332 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003333 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003334 "-modulate value vary the brightness, saturation, and hue",
3335 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003336 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003337 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003338 "-motion-blur geometry",
3339 " simulate motion blur",
3340 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003341 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003342 "-normalize transform image to span the full range of colors",
3343 "-opaque color change this color to the fill color",
3344 "-ordered-dither NxN",
3345 " add a noise pattern to the image with specific",
3346 " amplitudes",
3347 "-paint radius simulate an oil painting",
3348 "-polaroid angle simulate a Polaroid picture",
3349 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003350 "-profile filename add, delete, or apply an image profile",
3351 "-quantize colorspace reduce colors in this colorspace",
3352 "-radial-blur angle radial blur the image",
3353 "-raise value lighten/darken image edges to create a 3-D effect",
3354 "-random-threshold low,high",
3355 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003356 "-region geometry apply options to a portion of the image",
3357 "-render render vector graphics",
3358 "-repage geometry size and location of an image canvas",
3359 "-resample geometry change the resolution of an image",
3360 "-resize geometry resize the image",
3361 "-roll geometry roll an image vertically or horizontally",
3362 "-rotate degrees apply Paeth rotation to the image",
3363 "-sample geometry scale image with pixel sampling",
3364 "-scale geometry scale the image",
3365 "-segment values segment an image",
3366 "-selective-blur geometry",
3367 " selectively blur pixels within a contrast threshold",
3368 "-sepia-tone threshold",
3369 " simulate a sepia-toned photo",
3370 "-set property value set an image property",
3371 "-shade degrees shade the image using a distant light source",
3372 "-shadow geometry simulate an image shadow",
3373 "-sharpen geometry sharpen the image",
3374 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003375 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003376 "-sigmoidal-contrast geometry",
3377 " increase the contrast without saturating highlights or shadows",
3378 "-sketch geometry simulate a pencil sketch",
3379 "-solarize threshold negate all pixels above the threshold level",
3380 "-sparse-color method args",
3381 " fill in a image based on a few color points",
3382 "-splice geometry splice the background color into the image",
3383 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003384 "-statistic type radius",
3385 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003386 "-strip strip image of all profiles and comments",
3387 "-swirl degrees swirl image pixels about the center",
3388 "-threshold value threshold the image",
3389 "-thumbnail geometry create a thumbnail of the image",
3390 "-tile filename tile image when filling a graphic primitive",
3391 "-tint value tint the image with the fill color",
3392 "-transform affine transform image",
3393 "-transparent color make this color transparent within the image",
3394 "-transpose flip image vertically and rotate 90 degrees",
3395 "-transverse flop image horizontally and rotate 270 degrees",
3396 "-trim trim image edges",
3397 "-type type image type",
3398 "-unique-colors discard all but one of any pixel color",
3399 "-unsharp geometry sharpen the image",
3400 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003401 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003402 "-white-threshold value",
3403 " force all pixels above the threshold into white",
3404 (char *) NULL
3405 },
3406 *sequence_operators[]=
3407 {
cristy4285d782011-02-09 20:12:28 +00003408 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003409 "-clut apply a color lookup table to the image",
3410 "-coalesce merge a sequence of images",
3411 "-combine combine a sequence of images",
3412 "-composite composite image",
3413 "-crop geometry cut out a rectangular region of the image",
3414 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003415 "-evaluate-sequence operator",
3416 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003417 "-flatten flatten a sequence of images",
3418 "-fx expression apply mathematical expression to an image channel(s)",
3419 "-hald-clut apply a Hald color lookup table to the image",
3420 "-morph value morph an image sequence",
3421 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003422 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003423 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003424 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003425 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003426 "-write filename write images to this file",
3427 (char *) NULL
3428 },
3429 *settings[]=
3430 {
3431 "-adjoin join images into a single multi-image file",
3432 "-affine matrix affine transform matrix",
3433 "-alpha option activate, deactivate, reset, or set the alpha channel",
3434 "-antialias remove pixel-aliasing",
3435 "-authenticate password",
3436 " decipher image with this password",
3437 "-attenuate value lessen (or intensify) when adding noise to an image",
3438 "-background color background color",
3439 "-bias value add bias when convolving an image",
3440 "-black-point-compensation",
3441 " use black point compensation",
3442 "-blue-primary point chromaticity blue primary point",
3443 "-bordercolor color border color",
3444 "-caption string assign a caption to an image",
3445 "-channel type apply option to select image channels",
3446 "-colors value preferred number of colors in the image",
3447 "-colorspace type alternate image colorspace",
3448 "-comment string annotate image with comment",
3449 "-compose operator set image composite operator",
3450 "-compress type type of pixel compression when writing the image",
3451 "-define format:option",
3452 " define one or more image format options",
3453 "-delay value display the next image after pausing",
3454 "-density geometry horizontal and vertical density of the image",
3455 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003456 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003457 "-display server get image or font from this X server",
3458 "-dispose method layer disposal method",
3459 "-dither method apply error diffusion to image",
3460 "-encoding type text encoding type",
3461 "-endian type endianness (MSB or LSB) of the image",
3462 "-family name render text with this font family",
3463 "-fill color color to use when filling a graphic primitive",
3464 "-filter type use this filter when resizing an image",
3465 "-font name render text with this font",
3466 "-format \"string\" output formatted image characteristics",
3467 "-fuzz distance colors within this distance are considered equal",
3468 "-gravity type horizontal and vertical text placement",
3469 "-green-primary point chromaticity green primary point",
3470 "-intent type type of rendering intent when managing the image color",
3471 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003472 "-interline-spacing value",
3473 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003474 "-interpolate method pixel color interpolation method",
3475 "-interword-spacing value",
3476 " set the space between two words",
3477 "-kerning value set the space between two letters",
3478 "-label string assign a label to an image",
3479 "-limit type value pixel cache resource limit",
3480 "-loop iterations add Netscape loop extension to your GIF animation",
3481 "-mask filename associate a mask with the image",
3482 "-mattecolor color frame color",
3483 "-monitor monitor progress",
3484 "-orient type image orientation",
3485 "-page geometry size and location of an image canvas (setting)",
3486 "-ping efficiently determine image attributes",
3487 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003488 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003489 "-preview type image preview type",
3490 "-quality value JPEG/MIFF/PNG compression level",
3491 "-quiet suppress all warning messages",
3492 "-red-primary point chromaticity red primary point",
3493 "-regard-warnings pay attention to warning messages",
3494 "-remap filename transform image colors to match this set of colors",
3495 "-respect-parentheses settings remain in effect until parenthesis boundary",
3496 "-sampling-factor geometry",
3497 " horizontal and vertical sampling factor",
3498 "-scene value image scene number",
3499 "-seed value seed a new sequence of pseudo-random numbers",
3500 "-size geometry width and height of image",
3501 "-stretch type render text with this font stretch",
3502 "-stroke color graphic primitive stroke color",
3503 "-strokewidth value graphic primitive stroke width",
3504 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003505 "-synchronize synchronize image to storage device",
3506 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003507 "-texture filename name of texture to tile onto the image background",
3508 "-tile-offset geometry",
3509 " tile offset",
3510 "-treedepth value color tree depth",
3511 "-transparent-color color",
3512 " transparent color",
3513 "-undercolor color annotation bounding box color",
3514 "-units type the units of image resolution",
3515 "-verbose print detailed information about the image",
3516 "-view FlashPix viewing transforms",
3517 "-virtual-pixel method",
3518 " virtual pixel access method",
3519 "-weight type render text with this font weight",
3520 "-white-point point chromaticity white point",
3521 (char *) NULL
3522 },
3523 *stack_operators[]=
3524 {
anthonyb69c4b32011-03-23 04:37:44 +00003525 "-delete indexes delete the image from the image sequence",
3526 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003527 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003528 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003529 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003530 "-swap indexes swap two images in the image sequence",
3531 (char *) NULL
3532 };
3533
3534 const char
3535 **p;
3536
cristybb503372010-05-27 20:51:26 +00003537 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003538 (void) printf("Copyright: %s\n",GetMagickCopyright());
3539 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003540 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3541 GetClientName());
3542 (void) printf("\nImage Settings:\n");
3543 for (p=settings; *p != (char *) NULL; p++)
3544 (void) printf(" %s\n",*p);
3545 (void) printf("\nImage Operators:\n");
3546 for (p=operators; *p != (char *) NULL; p++)
3547 (void) printf(" %s\n",*p);
3548 (void) printf("\nImage Sequence Operators:\n");
3549 for (p=sequence_operators; *p != (char *) NULL; p++)
3550 (void) printf(" %s\n",*p);
3551 (void) printf("\nImage Stack Operators:\n");
3552 for (p=stack_operators; *p != (char *) NULL; p++)
3553 (void) printf(" %s\n",*p);
3554 (void) printf("\nMiscellaneous Options:\n");
3555 for (p=miscellaneous; *p != (char *) NULL; p++)
3556 (void) printf(" %s\n",*p);
3557 (void) printf(
3558 "\nBy default, the image format of `file' is determined by its magic\n");
3559 (void) printf(
3560 "number. To specify a particular image format, precede the filename\n");
3561 (void) printf(
3562 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3563 (void) printf(
3564 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3565 (void) printf("'-' for standard input or output.\n");
3566 return(MagickFalse);
3567}
3568
3569WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3570 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3571{
3572#define DestroyMogrify() \
3573{ \
3574 if (format != (char *) NULL) \
3575 format=DestroyString(format); \
3576 if (path != (char *) NULL) \
3577 path=DestroyString(path); \
3578 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003579 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003580 argv[i]=DestroyString(argv[i]); \
3581 argv=(char **) RelinquishMagickMemory(argv); \
3582}
3583#define ThrowMogrifyException(asperity,tag,option) \
3584{ \
3585 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3586 option); \
3587 DestroyMogrify(); \
3588 return(MagickFalse); \
3589}
3590#define ThrowMogrifyInvalidArgumentException(option,argument) \
3591{ \
3592 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3593 "InvalidArgument","`%s': %s",argument,option); \
3594 DestroyMogrify(); \
3595 return(MagickFalse); \
3596}
3597
3598 char
3599 *format,
3600 *option,
3601 *path;
3602
3603 Image
3604 *image;
3605
3606 ImageStack
3607 image_stack[MaxImageStackDepth+1];
3608
cristy3ed852e2009-09-05 21:47:34 +00003609 MagickBooleanType
3610 global_colormap;
3611
3612 MagickBooleanType
3613 fire,
cristyebbcfea2011-02-25 02:43:54 +00003614 pend,
3615 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003616
3617 MagickStatusType
3618 status;
3619
cristyebbcfea2011-02-25 02:43:54 +00003620 register ssize_t
3621 i;
3622
3623 ssize_t
3624 j,
3625 k;
3626
cristy3ed852e2009-09-05 21:47:34 +00003627 /*
3628 Set defaults.
3629 */
3630 assert(image_info != (ImageInfo *) NULL);
3631 assert(image_info->signature == MagickSignature);
3632 if (image_info->debug != MagickFalse)
3633 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3634 assert(exception != (ExceptionInfo *) NULL);
3635 if (argc == 2)
3636 {
3637 option=argv[1];
3638 if ((LocaleCompare("version",option+1) == 0) ||
3639 (LocaleCompare("-version",option+1) == 0))
3640 {
cristyb51dff52011-05-19 16:55:47 +00003641 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003642 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003643 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3644 GetMagickCopyright());
3645 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3646 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003647 return(MagickFalse);
3648 }
3649 }
3650 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003651 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003652 format=(char *) NULL;
3653 path=(char *) NULL;
3654 global_colormap=MagickFalse;
3655 k=0;
3656 j=1;
3657 NewImageStack();
3658 option=(char *) NULL;
3659 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003660 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003661 status=MagickTrue;
3662 /*
3663 Parse command line.
3664 */
3665 ReadCommandlLine(argc,&argv);
3666 status=ExpandFilenames(&argc,&argv);
3667 if (status == MagickFalse)
3668 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3669 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003670 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003671 {
3672 option=argv[i];
3673 if (LocaleCompare(option,"(") == 0)
3674 {
3675 FireImageStack(MagickFalse,MagickTrue,pend);
3676 if (k == MaxImageStackDepth)
3677 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3678 option);
3679 PushImageStack();
3680 continue;
3681 }
3682 if (LocaleCompare(option,")") == 0)
3683 {
3684 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3685 if (k == 0)
3686 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3687 PopImageStack();
3688 continue;
3689 }
cristy042ee782011-04-22 18:48:30 +00003690 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003691 {
3692 char
3693 backup_filename[MaxTextExtent],
3694 *filename;
3695
3696 Image
3697 *images;
3698
3699 /*
3700 Option is a file name: begin by reading image from specified file.
3701 */
3702 FireImageStack(MagickFalse,MagickFalse,pend);
3703 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003704 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003705 filename=argv[++i];
3706 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3707 images=ReadImages(image_info,exception);
3708 status&=(images != (Image *) NULL) &&
3709 (exception->severity < ErrorException);
3710 if (images == (Image *) NULL)
3711 continue;
cristydaa76602010-06-30 13:05:11 +00003712 if (format != (char *) NULL)
3713 (void) CopyMagickString(images->filename,images->magick_filename,
3714 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003715 if (path != (char *) NULL)
3716 {
3717 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003718 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003719 path,*DirectorySeparator,filename);
3720 }
3721 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003722 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003723 AppendImageStack(images);
3724 FinalizeImageSettings(image_info,image,MagickFalse);
3725 if (global_colormap != MagickFalse)
3726 {
3727 QuantizeInfo
3728 *quantize_info;
3729
3730 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003731 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003732 quantize_info=DestroyQuantizeInfo(quantize_info);
3733 }
3734 *backup_filename='\0';
3735 if ((LocaleCompare(image->filename,"-") != 0) &&
3736 (IsPathWritable(image->filename) != MagickFalse))
3737 {
cristybb503372010-05-27 20:51:26 +00003738 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003739 i;
3740
3741 /*
3742 Rename image file as backup.
3743 */
3744 (void) CopyMagickString(backup_filename,image->filename,
3745 MaxTextExtent);
3746 for (i=0; i < 6; i++)
3747 {
3748 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3749 if (IsPathAccessible(backup_filename) == MagickFalse)
3750 break;
3751 }
3752 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003753 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003754 *backup_filename='\0';
3755 }
3756 /*
3757 Write transmogrified image to disk.
3758 */
3759 image_info->synchronize=MagickTrue;
3760 status&=WriteImages(image_info,image,image->filename,exception);
3761 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003762 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003763 RemoveAllImageStack();
3764 continue;
3765 }
3766 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3767 switch (*(option+1))
3768 {
3769 case 'a':
3770 {
3771 if (LocaleCompare("adaptive-blur",option+1) == 0)
3772 {
3773 i++;
cristybb503372010-05-27 20:51:26 +00003774 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003775 ThrowMogrifyException(OptionError,"MissingArgument",option);
3776 if (IsGeometry(argv[i]) == MagickFalse)
3777 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3778 break;
3779 }
3780 if (LocaleCompare("adaptive-resize",option+1) == 0)
3781 {
3782 i++;
cristybb503372010-05-27 20:51:26 +00003783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003784 ThrowMogrifyException(OptionError,"MissingArgument",option);
3785 if (IsGeometry(argv[i]) == MagickFalse)
3786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3787 break;
3788 }
3789 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3790 {
3791 i++;
cristybb503372010-05-27 20:51:26 +00003792 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003793 ThrowMogrifyException(OptionError,"MissingArgument",option);
3794 if (IsGeometry(argv[i]) == MagickFalse)
3795 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3796 break;
3797 }
3798 if (LocaleCompare("affine",option+1) == 0)
3799 {
3800 if (*option == '+')
3801 break;
3802 i++;
cristybb503372010-05-27 20:51:26 +00003803 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003804 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003805 break;
3806 }
3807 if (LocaleCompare("alpha",option+1) == 0)
3808 {
cristybb503372010-05-27 20:51:26 +00003809 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003810 type;
3811
3812 if (*option == '+')
3813 break;
3814 i++;
cristybb503372010-05-27 20:51:26 +00003815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003816 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003817 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003818 if (type < 0)
3819 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3820 argv[i]);
3821 break;
3822 }
3823 if (LocaleCompare("annotate",option+1) == 0)
3824 {
3825 if (*option == '+')
3826 break;
3827 i++;
cristybb503372010-05-27 20:51:26 +00003828 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003829 ThrowMogrifyException(OptionError,"MissingArgument",option);
3830 if (IsGeometry(argv[i]) == MagickFalse)
3831 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003832 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003833 ThrowMogrifyException(OptionError,"MissingArgument",option);
3834 i++;
3835 break;
3836 }
3837 if (LocaleCompare("antialias",option+1) == 0)
3838 break;
3839 if (LocaleCompare("append",option+1) == 0)
3840 break;
3841 if (LocaleCompare("attenuate",option+1) == 0)
3842 {
3843 if (*option == '+')
3844 break;
3845 i++;
cristybb503372010-05-27 20:51:26 +00003846 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003847 ThrowMogrifyException(OptionError,"MissingArgument",option);
3848 if (IsGeometry(argv[i]) == MagickFalse)
3849 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3850 break;
3851 }
3852 if (LocaleCompare("authenticate",option+1) == 0)
3853 {
3854 if (*option == '+')
3855 break;
3856 i++;
cristybb503372010-05-27 20:51:26 +00003857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003858 ThrowMogrifyException(OptionError,"MissingArgument",option);
3859 break;
3860 }
3861 if (LocaleCompare("auto-gamma",option+1) == 0)
3862 break;
3863 if (LocaleCompare("auto-level",option+1) == 0)
3864 break;
3865 if (LocaleCompare("auto-orient",option+1) == 0)
3866 break;
3867 if (LocaleCompare("average",option+1) == 0)
3868 break;
3869 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3870 }
3871 case 'b':
3872 {
3873 if (LocaleCompare("background",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 break;
3881 }
3882 if (LocaleCompare("bias",option+1) == 0)
3883 {
3884 if (*option == '+')
3885 break;
3886 i++;
cristybb503372010-05-27 20:51:26 +00003887 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003888 ThrowMogrifyException(OptionError,"MissingArgument",option);
3889 if (IsGeometry(argv[i]) == MagickFalse)
3890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3891 break;
3892 }
3893 if (LocaleCompare("black-point-compensation",option+1) == 0)
3894 break;
3895 if (LocaleCompare("black-threshold",option+1) == 0)
3896 {
3897 if (*option == '+')
3898 break;
3899 i++;
cristybb503372010-05-27 20:51:26 +00003900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003901 ThrowMogrifyException(OptionError,"MissingArgument",option);
3902 if (IsGeometry(argv[i]) == MagickFalse)
3903 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3904 break;
3905 }
3906 if (LocaleCompare("blue-primary",option+1) == 0)
3907 {
3908 if (*option == '+')
3909 break;
3910 i++;
cristybb503372010-05-27 20:51:26 +00003911 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003912 ThrowMogrifyException(OptionError,"MissingArgument",option);
3913 if (IsGeometry(argv[i]) == MagickFalse)
3914 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3915 break;
3916 }
3917 if (LocaleCompare("blue-shift",option+1) == 0)
3918 {
3919 i++;
cristybb503372010-05-27 20:51:26 +00003920 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003921 ThrowMogrifyException(OptionError,"MissingArgument",option);
3922 if (IsGeometry(argv[i]) == MagickFalse)
3923 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3924 break;
3925 }
3926 if (LocaleCompare("blur",option+1) == 0)
3927 {
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 if (IsGeometry(argv[i]) == MagickFalse)
3932 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3933 break;
3934 }
3935 if (LocaleCompare("border",option+1) == 0)
3936 {
3937 if (*option == '+')
3938 break;
3939 i++;
cristybb503372010-05-27 20:51:26 +00003940 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003941 ThrowMogrifyException(OptionError,"MissingArgument",option);
3942 if (IsGeometry(argv[i]) == MagickFalse)
3943 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3944 break;
3945 }
3946 if (LocaleCompare("bordercolor",option+1) == 0)
3947 {
3948 if (*option == '+')
3949 break;
3950 i++;
cristybb503372010-05-27 20:51:26 +00003951 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003952 ThrowMogrifyException(OptionError,"MissingArgument",option);
3953 break;
3954 }
3955 if (LocaleCompare("box",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 break;
3963 }
cristya28d6b82010-01-11 20:03:47 +00003964 if (LocaleCompare("brightness-contrast",option+1) == 0)
3965 {
3966 i++;
cristybb503372010-05-27 20:51:26 +00003967 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003968 ThrowMogrifyException(OptionError,"MissingArgument",option);
3969 if (IsGeometry(argv[i]) == MagickFalse)
3970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3971 break;
3972 }
cristy3ed852e2009-09-05 21:47:34 +00003973 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3974 }
3975 case 'c':
3976 {
3977 if (LocaleCompare("cache",option+1) == 0)
3978 {
3979 if (*option == '+')
3980 break;
3981 i++;
cristybb503372010-05-27 20:51:26 +00003982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003983 ThrowMogrifyException(OptionError,"MissingArgument",option);
3984 if (IsGeometry(argv[i]) == MagickFalse)
3985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3986 break;
3987 }
3988 if (LocaleCompare("caption",option+1) == 0)
3989 {
3990 if (*option == '+')
3991 break;
3992 i++;
cristybb503372010-05-27 20:51:26 +00003993 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003994 ThrowMogrifyException(OptionError,"MissingArgument",option);
3995 break;
3996 }
3997 if (LocaleCompare("channel",option+1) == 0)
3998 {
cristybb503372010-05-27 20:51:26 +00003999 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004000 channel;
4001
4002 if (*option == '+')
4003 break;
4004 i++;
cristybb503372010-05-27 20:51:26 +00004005 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004006 ThrowMogrifyException(OptionError,"MissingArgument",option);
4007 channel=ParseChannelOption(argv[i]);
4008 if (channel < 0)
4009 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4010 argv[i]);
4011 break;
4012 }
4013 if (LocaleCompare("cdl",option+1) == 0)
4014 {
4015 if (*option == '+')
4016 break;
4017 i++;
cristybb503372010-05-27 20:51:26 +00004018 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004019 ThrowMogrifyException(OptionError,"MissingArgument",option);
4020 break;
4021 }
4022 if (LocaleCompare("charcoal",option+1) == 0)
4023 {
4024 if (*option == '+')
4025 break;
4026 i++;
cristybb503372010-05-27 20:51:26 +00004027 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004028 ThrowMogrifyException(OptionError,"MissingArgument",option);
4029 if (IsGeometry(argv[i]) == MagickFalse)
4030 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4031 break;
4032 }
4033 if (LocaleCompare("chop",option+1) == 0)
4034 {
4035 if (*option == '+')
4036 break;
4037 i++;
cristybb503372010-05-27 20:51:26 +00004038 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004039 ThrowMogrifyException(OptionError,"MissingArgument",option);
4040 if (IsGeometry(argv[i]) == MagickFalse)
4041 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4042 break;
4043 }
cristy1eb45dd2009-09-25 16:38:06 +00004044 if (LocaleCompare("clamp",option+1) == 0)
4045 break;
4046 if (LocaleCompare("clip",option+1) == 0)
4047 break;
cristy3ed852e2009-09-05 21:47:34 +00004048 if (LocaleCompare("clip-mask",option+1) == 0)
4049 {
4050 if (*option == '+')
4051 break;
4052 i++;
cristybb503372010-05-27 20:51:26 +00004053 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004054 ThrowMogrifyException(OptionError,"MissingArgument",option);
4055 break;
4056 }
4057 if (LocaleCompare("clut",option+1) == 0)
4058 break;
4059 if (LocaleCompare("coalesce",option+1) == 0)
4060 break;
4061 if (LocaleCompare("colorize",option+1) == 0)
4062 {
4063 if (*option == '+')
4064 break;
4065 i++;
cristybb503372010-05-27 20:51:26 +00004066 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004067 ThrowMogrifyException(OptionError,"MissingArgument",option);
4068 if (IsGeometry(argv[i]) == MagickFalse)
4069 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4070 break;
4071 }
cristye6365592010-04-02 17:31:23 +00004072 if (LocaleCompare("color-matrix",option+1) == 0)
4073 {
cristyb6bd4ad2010-08-08 01:12:27 +00004074 KernelInfo
4075 *kernel_info;
4076
cristye6365592010-04-02 17:31:23 +00004077 if (*option == '+')
4078 break;
4079 i++;
cristybb503372010-05-27 20:51:26 +00004080 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004081 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004082 kernel_info=AcquireKernelInfo(argv[i]);
4083 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004084 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004085 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004086 break;
4087 }
cristy3ed852e2009-09-05 21:47:34 +00004088 if (LocaleCompare("colors",option+1) == 0)
4089 {
4090 if (*option == '+')
4091 break;
4092 i++;
cristybb503372010-05-27 20:51:26 +00004093 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004094 ThrowMogrifyException(OptionError,"MissingArgument",option);
4095 if (IsGeometry(argv[i]) == MagickFalse)
4096 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4097 break;
4098 }
4099 if (LocaleCompare("colorspace",option+1) == 0)
4100 {
cristybb503372010-05-27 20:51:26 +00004101 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004102 colorspace;
4103
4104 if (*option == '+')
4105 break;
4106 i++;
cristybb503372010-05-27 20:51:26 +00004107 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004108 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004109 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004110 argv[i]);
4111 if (colorspace < 0)
4112 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4113 argv[i]);
4114 break;
4115 }
4116 if (LocaleCompare("combine",option+1) == 0)
4117 break;
4118 if (LocaleCompare("comment",option+1) == 0)
4119 {
4120 if (*option == '+')
4121 break;
4122 i++;
cristybb503372010-05-27 20:51:26 +00004123 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004124 ThrowMogrifyException(OptionError,"MissingArgument",option);
4125 break;
4126 }
4127 if (LocaleCompare("composite",option+1) == 0)
4128 break;
4129 if (LocaleCompare("compress",option+1) == 0)
4130 {
cristybb503372010-05-27 20:51:26 +00004131 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004132 compress;
4133
4134 if (*option == '+')
4135 break;
4136 i++;
cristybb503372010-05-27 20:51:26 +00004137 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004138 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004139 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004140 argv[i]);
4141 if (compress < 0)
4142 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4143 argv[i]);
4144 break;
4145 }
cristy22879752009-10-25 23:55:40 +00004146 if (LocaleCompare("concurrent",option+1) == 0)
4147 break;
cristy3ed852e2009-09-05 21:47:34 +00004148 if (LocaleCompare("contrast",option+1) == 0)
4149 break;
4150 if (LocaleCompare("contrast-stretch",option+1) == 0)
4151 {
4152 i++;
cristybb503372010-05-27 20:51:26 +00004153 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004154 ThrowMogrifyException(OptionError,"MissingArgument",option);
4155 if (IsGeometry(argv[i]) == MagickFalse)
4156 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4157 break;
4158 }
4159 if (LocaleCompare("convolve",option+1) == 0)
4160 {
cristyb6bd4ad2010-08-08 01:12:27 +00004161 KernelInfo
4162 *kernel_info;
4163
cristy3ed852e2009-09-05 21:47:34 +00004164 if (*option == '+')
4165 break;
4166 i++;
cristybb503372010-05-27 20:51:26 +00004167 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004168 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004169 kernel_info=AcquireKernelInfo(argv[i]);
4170 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004171 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004172 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004173 break;
4174 }
4175 if (LocaleCompare("crop",option+1) == 0)
4176 {
4177 if (*option == '+')
4178 break;
4179 i++;
cristybb503372010-05-27 20:51:26 +00004180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004181 ThrowMogrifyException(OptionError,"MissingArgument",option);
4182 if (IsGeometry(argv[i]) == MagickFalse)
4183 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4184 break;
4185 }
4186 if (LocaleCompare("cycle",option+1) == 0)
4187 {
4188 if (*option == '+')
4189 break;
4190 i++;
cristybb503372010-05-27 20:51:26 +00004191 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004192 ThrowMogrifyException(OptionError,"MissingArgument",option);
4193 if (IsGeometry(argv[i]) == MagickFalse)
4194 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4195 break;
4196 }
4197 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4198 }
4199 case 'd':
4200 {
4201 if (LocaleCompare("decipher",option+1) == 0)
4202 {
4203 if (*option == '+')
4204 break;
4205 i++;
cristybb503372010-05-27 20:51:26 +00004206 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004207 ThrowMogrifyException(OptionError,"MissingArgument",option);
4208 break;
4209 }
4210 if (LocaleCompare("deconstruct",option+1) == 0)
4211 break;
4212 if (LocaleCompare("debug",option+1) == 0)
4213 {
cristybb503372010-05-27 20:51:26 +00004214 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004215 event;
4216
4217 if (*option == '+')
4218 break;
4219 i++;
cristybb503372010-05-27 20:51:26 +00004220 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004221 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004222 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004223 if (event < 0)
4224 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4225 argv[i]);
4226 (void) SetLogEventMask(argv[i]);
4227 break;
4228 }
4229 if (LocaleCompare("define",option+1) == 0)
4230 {
4231 i++;
cristybb503372010-05-27 20:51:26 +00004232 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004233 ThrowMogrifyException(OptionError,"MissingArgument",option);
4234 if (*option == '+')
4235 {
4236 const char
4237 *define;
4238
4239 define=GetImageOption(image_info,argv[i]);
4240 if (define == (const char *) NULL)
4241 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4242 break;
4243 }
4244 break;
4245 }
4246 if (LocaleCompare("delay",option+1) == 0)
4247 {
4248 if (*option == '+')
4249 break;
4250 i++;
cristybb503372010-05-27 20:51:26 +00004251 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004252 ThrowMogrifyException(OptionError,"MissingArgument",option);
4253 if (IsGeometry(argv[i]) == MagickFalse)
4254 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4255 break;
4256 }
cristyecb10ff2011-03-22 13:14:03 +00004257 if (LocaleCompare("delete",option+1) == 0)
4258 {
4259 if (*option == '+')
4260 break;
4261 i++;
4262 if (i == (ssize_t) (argc-1))
4263 ThrowMogrifyException(OptionError,"MissingArgument",option);
4264 if (IsGeometry(argv[i]) == MagickFalse)
4265 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4266 break;
4267 }
cristy3ed852e2009-09-05 21:47:34 +00004268 if (LocaleCompare("density",option+1) == 0)
4269 {
4270 if (*option == '+')
4271 break;
4272 i++;
cristybb503372010-05-27 20:51:26 +00004273 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004274 ThrowMogrifyException(OptionError,"MissingArgument",option);
4275 if (IsGeometry(argv[i]) == MagickFalse)
4276 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4277 break;
4278 }
4279 if (LocaleCompare("depth",option+1) == 0)
4280 {
4281 if (*option == '+')
4282 break;
4283 i++;
cristybb503372010-05-27 20:51:26 +00004284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004285 ThrowMogrifyException(OptionError,"MissingArgument",option);
4286 if (IsGeometry(argv[i]) == MagickFalse)
4287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4288 break;
4289 }
4290 if (LocaleCompare("deskew",option+1) == 0)
4291 {
4292 if (*option == '+')
4293 break;
4294 i++;
cristybb503372010-05-27 20:51:26 +00004295 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004296 ThrowMogrifyException(OptionError,"MissingArgument",option);
4297 if (IsGeometry(argv[i]) == MagickFalse)
4298 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4299 break;
4300 }
4301 if (LocaleCompare("despeckle",option+1) == 0)
4302 break;
4303 if (LocaleCompare("dft",option+1) == 0)
4304 break;
cristyc9b12952010-03-28 01:12:28 +00004305 if (LocaleCompare("direction",option+1) == 0)
4306 {
cristybb503372010-05-27 20:51:26 +00004307 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004308 direction;
4309
4310 if (*option == '+')
4311 break;
4312 i++;
cristybb503372010-05-27 20:51:26 +00004313 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004314 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004315 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004316 argv[i]);
4317 if (direction < 0)
4318 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4319 argv[i]);
4320 break;
4321 }
cristy3ed852e2009-09-05 21:47:34 +00004322 if (LocaleCompare("display",option+1) == 0)
4323 {
4324 if (*option == '+')
4325 break;
4326 i++;
cristybb503372010-05-27 20:51:26 +00004327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004328 ThrowMogrifyException(OptionError,"MissingArgument",option);
4329 break;
4330 }
4331 if (LocaleCompare("dispose",option+1) == 0)
4332 {
cristybb503372010-05-27 20:51:26 +00004333 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004334 dispose;
4335
4336 if (*option == '+')
4337 break;
4338 i++;
cristybb503372010-05-27 20:51:26 +00004339 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004340 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004341 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004342 if (dispose < 0)
4343 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4344 argv[i]);
4345 break;
4346 }
4347 if (LocaleCompare("distort",option+1) == 0)
4348 {
cristybb503372010-05-27 20:51:26 +00004349 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004350 op;
4351
4352 i++;
cristybb503372010-05-27 20:51:26 +00004353 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004354 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004355 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004356 if (op < 0)
4357 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4358 argv[i]);
4359 i++;
cristybb503372010-05-27 20:51:26 +00004360 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004361 ThrowMogrifyException(OptionError,"MissingArgument",option);
4362 break;
4363 }
4364 if (LocaleCompare("dither",option+1) == 0)
4365 {
cristybb503372010-05-27 20:51:26 +00004366 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004367 method;
4368
4369 if (*option == '+')
4370 break;
4371 i++;
cristybb503372010-05-27 20:51:26 +00004372 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004373 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004374 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004375 if (method < 0)
4376 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4377 argv[i]);
4378 break;
4379 }
4380 if (LocaleCompare("draw",option+1) == 0)
4381 {
4382 if (*option == '+')
4383 break;
4384 i++;
cristybb503372010-05-27 20:51:26 +00004385 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004386 ThrowMogrifyException(OptionError,"MissingArgument",option);
4387 break;
4388 }
cristyecb10ff2011-03-22 13:14:03 +00004389 if (LocaleCompare("duplicate",option+1) == 0)
4390 {
4391 if (*option == '+')
4392 break;
4393 i++;
4394 if (i == (ssize_t) (argc-1))
4395 ThrowMogrifyException(OptionError,"MissingArgument",option);
4396 if (IsGeometry(argv[i]) == MagickFalse)
4397 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4398 break;
4399 }
cristy22879752009-10-25 23:55:40 +00004400 if (LocaleCompare("duration",option+1) == 0)
4401 {
4402 if (*option == '+')
4403 break;
4404 i++;
cristybb503372010-05-27 20:51:26 +00004405 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004406 ThrowMogrifyException(OptionError,"MissingArgument",option);
4407 if (IsGeometry(argv[i]) == MagickFalse)
4408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4409 break;
4410 }
cristy3ed852e2009-09-05 21:47:34 +00004411 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4412 }
4413 case 'e':
4414 {
4415 if (LocaleCompare("edge",option+1) == 0)
4416 {
4417 if (*option == '+')
4418 break;
4419 i++;
cristybb503372010-05-27 20:51:26 +00004420 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004421 ThrowMogrifyException(OptionError,"MissingArgument",option);
4422 if (IsGeometry(argv[i]) == MagickFalse)
4423 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4424 break;
4425 }
4426 if (LocaleCompare("emboss",option+1) == 0)
4427 {
4428 if (*option == '+')
4429 break;
4430 i++;
cristybb503372010-05-27 20:51:26 +00004431 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004432 ThrowMogrifyException(OptionError,"MissingArgument",option);
4433 if (IsGeometry(argv[i]) == MagickFalse)
4434 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4435 break;
4436 }
4437 if (LocaleCompare("encipher",option+1) == 0)
4438 {
4439 if (*option == '+')
4440 break;
4441 i++;
cristybb503372010-05-27 20:51:26 +00004442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004443 ThrowMogrifyException(OptionError,"MissingArgument",option);
4444 break;
4445 }
4446 if (LocaleCompare("encoding",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("endian",option+1) == 0)
4456 {
cristybb503372010-05-27 20:51:26 +00004457 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004458 endian;
4459
4460 if (*option == '+')
4461 break;
4462 i++;
cristybb503372010-05-27 20:51:26 +00004463 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004464 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004465 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004466 if (endian < 0)
4467 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4468 argv[i]);
4469 break;
4470 }
4471 if (LocaleCompare("enhance",option+1) == 0)
4472 break;
4473 if (LocaleCompare("equalize",option+1) == 0)
4474 break;
4475 if (LocaleCompare("evaluate",option+1) == 0)
4476 {
cristybb503372010-05-27 20:51:26 +00004477 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004478 op;
4479
4480 if (*option == '+')
4481 break;
4482 i++;
cristybb503372010-05-27 20:51:26 +00004483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004484 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004485 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004486 if (op < 0)
4487 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4488 argv[i]);
4489 i++;
cristybb503372010-05-27 20:51:26 +00004490 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004491 ThrowMogrifyException(OptionError,"MissingArgument",option);
4492 if (IsGeometry(argv[i]) == MagickFalse)
4493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4494 break;
4495 }
cristyd18ae7c2010-03-07 17:39:52 +00004496 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4497 {
cristybb503372010-05-27 20:51:26 +00004498 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004499 op;
4500
4501 if (*option == '+')
4502 break;
4503 i++;
cristybb503372010-05-27 20:51:26 +00004504 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004505 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004506 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004507 if (op < 0)
4508 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4509 argv[i]);
4510 break;
4511 }
cristy3ed852e2009-09-05 21:47:34 +00004512 if (LocaleCompare("extent",option+1) == 0)
4513 {
4514 if (*option == '+')
4515 break;
4516 i++;
cristybb503372010-05-27 20:51:26 +00004517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004518 ThrowMogrifyException(OptionError,"MissingArgument",option);
4519 if (IsGeometry(argv[i]) == MagickFalse)
4520 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4521 break;
4522 }
4523 if (LocaleCompare("extract",option+1) == 0)
4524 {
4525 if (*option == '+')
4526 break;
4527 i++;
cristybb503372010-05-27 20:51:26 +00004528 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004529 ThrowMogrifyException(OptionError,"MissingArgument",option);
4530 if (IsGeometry(argv[i]) == MagickFalse)
4531 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4532 break;
4533 }
4534 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4535 }
4536 case 'f':
4537 {
4538 if (LocaleCompare("family",option+1) == 0)
4539 {
4540 if (*option == '+')
4541 break;
4542 i++;
cristybb503372010-05-27 20:51:26 +00004543 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004544 ThrowMogrifyException(OptionError,"MissingArgument",option);
4545 break;
4546 }
4547 if (LocaleCompare("fill",option+1) == 0)
4548 {
4549 if (*option == '+')
4550 break;
4551 i++;
cristybb503372010-05-27 20:51:26 +00004552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004553 ThrowMogrifyException(OptionError,"MissingArgument",option);
4554 break;
4555 }
4556 if (LocaleCompare("filter",option+1) == 0)
4557 {
cristybb503372010-05-27 20:51:26 +00004558 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004559 filter;
4560
4561 if (*option == '+')
4562 break;
4563 i++;
cristybb503372010-05-27 20:51:26 +00004564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004565 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004566 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004567 if (filter < 0)
4568 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4569 argv[i]);
4570 break;
4571 }
4572 if (LocaleCompare("flatten",option+1) == 0)
4573 break;
4574 if (LocaleCompare("flip",option+1) == 0)
4575 break;
4576 if (LocaleCompare("flop",option+1) == 0)
4577 break;
4578 if (LocaleCompare("floodfill",option+1) == 0)
4579 {
4580 if (*option == '+')
4581 break;
4582 i++;
cristybb503372010-05-27 20:51:26 +00004583 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004584 ThrowMogrifyException(OptionError,"MissingArgument",option);
4585 if (IsGeometry(argv[i]) == MagickFalse)
4586 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4587 i++;
cristybb503372010-05-27 20:51:26 +00004588 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004589 ThrowMogrifyException(OptionError,"MissingArgument",option);
4590 break;
4591 }
4592 if (LocaleCompare("font",option+1) == 0)
4593 {
4594 if (*option == '+')
4595 break;
4596 i++;
cristybb503372010-05-27 20:51:26 +00004597 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004598 ThrowMogrifyException(OptionError,"MissingArgument",option);
4599 break;
4600 }
4601 if (LocaleCompare("format",option+1) == 0)
4602 {
4603 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4604 (void) CloneString(&format,(char *) NULL);
4605 if (*option == '+')
4606 break;
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 (void) CloneString(&format,argv[i]);
4611 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4612 (void) ConcatenateMagickString(image_info->filename,":",
4613 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004614 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004615 if (*image_info->magick == '\0')
4616 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4617 format);
4618 break;
4619 }
4620 if (LocaleCompare("frame",option+1) == 0)
4621 {
4622 if (*option == '+')
4623 break;
4624 i++;
cristybb503372010-05-27 20:51:26 +00004625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004626 ThrowMogrifyException(OptionError,"MissingArgument",option);
4627 if (IsGeometry(argv[i]) == MagickFalse)
4628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4629 break;
4630 }
4631 if (LocaleCompare("function",option+1) == 0)
4632 {
cristybb503372010-05-27 20:51:26 +00004633 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004634 op;
4635
4636 if (*option == '+')
4637 break;
4638 i++;
cristybb503372010-05-27 20:51:26 +00004639 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004640 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004641 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004642 if (op < 0)
4643 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4644 i++;
cristybb503372010-05-27 20:51:26 +00004645 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004646 ThrowMogrifyException(OptionError,"MissingArgument",option);
4647 break;
4648 }
4649 if (LocaleCompare("fuzz",option+1) == 0)
4650 {
4651 if (*option == '+')
4652 break;
4653 i++;
cristybb503372010-05-27 20:51:26 +00004654 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004655 ThrowMogrifyException(OptionError,"MissingArgument",option);
4656 if (IsGeometry(argv[i]) == MagickFalse)
4657 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4658 break;
4659 }
4660 if (LocaleCompare("fx",option+1) == 0)
4661 {
4662 if (*option == '+')
4663 break;
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 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4670 }
4671 case 'g':
4672 {
4673 if (LocaleCompare("gamma",option+1) == 0)
4674 {
4675 i++;
cristybb503372010-05-27 20:51:26 +00004676 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004677 ThrowMogrifyException(OptionError,"MissingArgument",option);
4678 if (IsGeometry(argv[i]) == MagickFalse)
4679 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4680 break;
4681 }
4682 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4683 (LocaleCompare("gaussian",option+1) == 0))
4684 {
4685 i++;
cristybb503372010-05-27 20:51:26 +00004686 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004687 ThrowMogrifyException(OptionError,"MissingArgument",option);
4688 if (IsGeometry(argv[i]) == MagickFalse)
4689 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4690 break;
4691 }
4692 if (LocaleCompare("geometry",option+1) == 0)
4693 {
4694 if (*option == '+')
4695 break;
4696 i++;
cristybb503372010-05-27 20:51:26 +00004697 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004698 ThrowMogrifyException(OptionError,"MissingArgument",option);
4699 if (IsGeometry(argv[i]) == MagickFalse)
4700 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4701 break;
4702 }
4703 if (LocaleCompare("gravity",option+1) == 0)
4704 {
cristybb503372010-05-27 20:51:26 +00004705 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004706 gravity;
4707
4708 if (*option == '+')
4709 break;
4710 i++;
cristybb503372010-05-27 20:51:26 +00004711 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004712 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004713 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004714 if (gravity < 0)
4715 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4716 argv[i]);
4717 break;
4718 }
4719 if (LocaleCompare("green-primary",option+1) == 0)
4720 {
4721 if (*option == '+')
4722 break;
4723 i++;
cristybb503372010-05-27 20:51:26 +00004724 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004725 ThrowMogrifyException(OptionError,"MissingArgument",option);
4726 if (IsGeometry(argv[i]) == MagickFalse)
4727 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4728 break;
4729 }
4730 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4731 }
4732 case 'h':
4733 {
4734 if (LocaleCompare("hald-clut",option+1) == 0)
4735 break;
4736 if ((LocaleCompare("help",option+1) == 0) ||
4737 (LocaleCompare("-help",option+1) == 0))
4738 return(MogrifyUsage());
4739 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4740 }
4741 case 'i':
4742 {
4743 if (LocaleCompare("identify",option+1) == 0)
4744 break;
4745 if (LocaleCompare("idft",option+1) == 0)
4746 break;
4747 if (LocaleCompare("implode",option+1) == 0)
4748 {
4749 if (*option == '+')
4750 break;
4751 i++;
cristybb503372010-05-27 20:51:26 +00004752 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004753 ThrowMogrifyException(OptionError,"MissingArgument",option);
4754 if (IsGeometry(argv[i]) == MagickFalse)
4755 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4756 break;
4757 }
4758 if (LocaleCompare("intent",option+1) == 0)
4759 {
cristybb503372010-05-27 20:51:26 +00004760 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004761 intent;
4762
4763 if (*option == '+')
4764 break;
4765 i++;
cristybb503372010-05-27 20:51:26 +00004766 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004767 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004768 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004769 if (intent < 0)
4770 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4771 argv[i]);
4772 break;
4773 }
4774 if (LocaleCompare("interlace",option+1) == 0)
4775 {
cristybb503372010-05-27 20:51:26 +00004776 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004777 interlace;
4778
4779 if (*option == '+')
4780 break;
4781 i++;
cristybb503372010-05-27 20:51:26 +00004782 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004783 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004784 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004785 argv[i]);
4786 if (interlace < 0)
4787 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4788 argv[i]);
4789 break;
4790 }
cristyb32b90a2009-09-07 21:45:48 +00004791 if (LocaleCompare("interline-spacing",option+1) == 0)
4792 {
4793 if (*option == '+')
4794 break;
4795 i++;
cristybb503372010-05-27 20:51:26 +00004796 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004797 ThrowMogrifyException(OptionError,"MissingArgument",option);
4798 if (IsGeometry(argv[i]) == MagickFalse)
4799 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4800 break;
4801 }
cristy3ed852e2009-09-05 21:47:34 +00004802 if (LocaleCompare("interpolate",option+1) == 0)
4803 {
cristybb503372010-05-27 20:51:26 +00004804 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004805 interpolate;
4806
4807 if (*option == '+')
4808 break;
4809 i++;
cristybb503372010-05-27 20:51:26 +00004810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004811 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004812 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004813 argv[i]);
4814 if (interpolate < 0)
4815 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4816 argv[i]);
4817 break;
4818 }
4819 if (LocaleCompare("interword-spacing",option+1) == 0)
4820 {
4821 if (*option == '+')
4822 break;
4823 i++;
cristybb503372010-05-27 20:51:26 +00004824 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004825 ThrowMogrifyException(OptionError,"MissingArgument",option);
4826 if (IsGeometry(argv[i]) == MagickFalse)
4827 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4828 break;
4829 }
4830 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4831 }
4832 case 'k':
4833 {
4834 if (LocaleCompare("kerning",option+1) == 0)
4835 {
4836 if (*option == '+')
4837 break;
4838 i++;
cristybb503372010-05-27 20:51:26 +00004839 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004840 ThrowMogrifyException(OptionError,"MissingArgument",option);
4841 if (IsGeometry(argv[i]) == MagickFalse)
4842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4843 break;
4844 }
4845 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4846 }
4847 case 'l':
4848 {
4849 if (LocaleCompare("label",option+1) == 0)
4850 {
4851 if (*option == '+')
4852 break;
4853 i++;
cristybb503372010-05-27 20:51:26 +00004854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004855 ThrowMogrifyException(OptionError,"MissingArgument",option);
4856 break;
4857 }
4858 if (LocaleCompare("lat",option+1) == 0)
4859 {
4860 if (*option == '+')
4861 break;
4862 i++;
cristybb503372010-05-27 20:51:26 +00004863 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004864 ThrowMogrifyException(OptionError,"MissingArgument",option);
4865 if (IsGeometry(argv[i]) == MagickFalse)
4866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4867 }
4868 if (LocaleCompare("layers",option+1) == 0)
4869 {
cristybb503372010-05-27 20:51:26 +00004870 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004871 type;
4872
4873 if (*option == '+')
4874 break;
4875 i++;
cristybb503372010-05-27 20:51:26 +00004876 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004877 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004878 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004879 if (type < 0)
4880 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4881 argv[i]);
4882 break;
4883 }
4884 if (LocaleCompare("level",option+1) == 0)
4885 {
4886 i++;
cristybb503372010-05-27 20:51:26 +00004887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004888 ThrowMogrifyException(OptionError,"MissingArgument",option);
4889 if (IsGeometry(argv[i]) == MagickFalse)
4890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4891 break;
4892 }
4893 if (LocaleCompare("level-colors",option+1) == 0)
4894 {
4895 i++;
cristybb503372010-05-27 20:51:26 +00004896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004897 ThrowMogrifyException(OptionError,"MissingArgument",option);
4898 break;
4899 }
4900 if (LocaleCompare("linewidth",option+1) == 0)
4901 {
4902 if (*option == '+')
4903 break;
4904 i++;
cristybb503372010-05-27 20:51:26 +00004905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004906 ThrowMogrifyException(OptionError,"MissingArgument",option);
4907 if (IsGeometry(argv[i]) == MagickFalse)
4908 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4909 break;
4910 }
4911 if (LocaleCompare("limit",option+1) == 0)
4912 {
4913 char
4914 *p;
4915
4916 double
4917 value;
4918
cristybb503372010-05-27 20:51:26 +00004919 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004920 resource;
4921
4922 if (*option == '+')
4923 break;
4924 i++;
cristybb503372010-05-27 20:51:26 +00004925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004926 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004927 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004928 argv[i]);
4929 if (resource < 0)
4930 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4931 argv[i]);
4932 i++;
cristybb503372010-05-27 20:51:26 +00004933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004934 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00004935 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004936 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004937 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4938 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4939 break;
4940 }
4941 if (LocaleCompare("liquid-rescale",option+1) == 0)
4942 {
4943 i++;
cristybb503372010-05-27 20:51:26 +00004944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004945 ThrowMogrifyException(OptionError,"MissingArgument",option);
4946 if (IsGeometry(argv[i]) == MagickFalse)
4947 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4948 break;
4949 }
4950 if (LocaleCompare("list",option+1) == 0)
4951 {
cristybb503372010-05-27 20:51:26 +00004952 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004953 list;
4954
4955 if (*option == '+')
4956 break;
4957 i++;
cristybb503372010-05-27 20:51:26 +00004958 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004959 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004960 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004961 if (list < 0)
4962 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004963 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004964 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004965 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004966 }
4967 if (LocaleCompare("log",option+1) == 0)
4968 {
4969 if (*option == '+')
4970 break;
4971 i++;
cristybb503372010-05-27 20:51:26 +00004972 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004973 (strchr(argv[i],'%') == (char *) NULL))
4974 ThrowMogrifyException(OptionError,"MissingArgument",option);
4975 break;
4976 }
4977 if (LocaleCompare("loop",option+1) == 0)
4978 {
4979 if (*option == '+')
4980 break;
4981 i++;
cristybb503372010-05-27 20:51:26 +00004982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004983 ThrowMogrifyException(OptionError,"MissingArgument",option);
4984 if (IsGeometry(argv[i]) == MagickFalse)
4985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4986 break;
4987 }
4988 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4989 }
4990 case 'm':
4991 {
4992 if (LocaleCompare("map",option+1) == 0)
4993 {
4994 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4995 if (*option == '+')
4996 break;
4997 i++;
cristybb503372010-05-27 20:51:26 +00004998 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004999 ThrowMogrifyException(OptionError,"MissingArgument",option);
5000 break;
5001 }
5002 if (LocaleCompare("mask",option+1) == 0)
5003 {
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("matte",option+1) == 0)
5012 break;
5013 if (LocaleCompare("mattecolor",option+1) == 0)
5014 {
5015 if (*option == '+')
5016 break;
5017 i++;
cristybb503372010-05-27 20:51:26 +00005018 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005019 ThrowMogrifyException(OptionError,"MissingArgument",option);
5020 break;
5021 }
cristyf40785b2010-03-06 02:27:27 +00005022 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005023 break;
cristyf40785b2010-03-06 02:27:27 +00005024 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005025 break;
cristy3ed852e2009-09-05 21:47:34 +00005026 if (LocaleCompare("modulate",option+1) == 0)
5027 {
5028 if (*option == '+')
5029 break;
5030 i++;
cristybb503372010-05-27 20:51:26 +00005031 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005032 ThrowMogrifyException(OptionError,"MissingArgument",option);
5033 if (IsGeometry(argv[i]) == MagickFalse)
5034 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5035 break;
5036 }
5037 if (LocaleCompare("median",option+1) == 0)
5038 {
5039 if (*option == '+')
5040 break;
5041 i++;
cristybb503372010-05-27 20:51:26 +00005042 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005043 ThrowMogrifyException(OptionError,"MissingArgument",option);
5044 if (IsGeometry(argv[i]) == MagickFalse)
5045 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5046 break;
5047 }
cristy69ec32d2011-02-27 23:57:09 +00005048 if (LocaleCompare("mode",option+1) == 0)
5049 {
5050 if (*option == '+')
5051 break;
5052 i++;
5053 if (i == (ssize_t) argc)
5054 ThrowMogrifyException(OptionError,"MissingArgument",option);
5055 if (IsGeometry(argv[i]) == MagickFalse)
5056 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5057 break;
5058 }
cristy3ed852e2009-09-05 21:47:34 +00005059 if (LocaleCompare("monitor",option+1) == 0)
5060 break;
5061 if (LocaleCompare("monochrome",option+1) == 0)
5062 break;
5063 if (LocaleCompare("morph",option+1) == 0)
5064 {
5065 if (*option == '+')
5066 break;
5067 i++;
cristybb503372010-05-27 20:51:26 +00005068 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005069 ThrowMogrifyException(OptionError,"MissingArgument",option);
5070 if (IsGeometry(argv[i]) == MagickFalse)
5071 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5072 break;
5073 }
anthony29188a82010-01-22 10:12:34 +00005074 if (LocaleCompare("morphology",option+1) == 0)
5075 {
anthony29188a82010-01-22 10:12:34 +00005076 char
5077 token[MaxTextExtent];
5078
cristyb6bd4ad2010-08-08 01:12:27 +00005079 KernelInfo
5080 *kernel_info;
5081
5082 ssize_t
5083 op;
5084
anthony29188a82010-01-22 10:12:34 +00005085 i++;
cristybb503372010-05-27 20:51:26 +00005086 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005087 ThrowMogrifyException(OptionError,"MissingArgument",option);
5088 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005089 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005090 if (op < 0)
5091 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005092 token);
anthony29188a82010-01-22 10:12:34 +00005093 i++;
cristybb503372010-05-27 20:51:26 +00005094 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005095 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005096 kernel_info=AcquireKernelInfo(argv[i]);
5097 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005098 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005099 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005100 break;
5101 }
cristy3ed852e2009-09-05 21:47:34 +00005102 if (LocaleCompare("mosaic",option+1) == 0)
5103 break;
5104 if (LocaleCompare("motion-blur",option+1) == 0)
5105 {
5106 if (*option == '+')
5107 break;
5108 i++;
cristybb503372010-05-27 20:51:26 +00005109 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005110 ThrowMogrifyException(OptionError,"MissingArgument",option);
5111 if (IsGeometry(argv[i]) == MagickFalse)
5112 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5113 break;
5114 }
5115 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5116 }
5117 case 'n':
5118 {
5119 if (LocaleCompare("negate",option+1) == 0)
5120 break;
5121 if (LocaleCompare("noise",option+1) == 0)
5122 {
5123 i++;
cristybb503372010-05-27 20:51:26 +00005124 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005125 ThrowMogrifyException(OptionError,"MissingArgument",option);
5126 if (*option == '+')
5127 {
cristybb503372010-05-27 20:51:26 +00005128 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005129 noise;
5130
cristy042ee782011-04-22 18:48:30 +00005131 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005132 if (noise < 0)
5133 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5134 argv[i]);
5135 break;
5136 }
5137 if (IsGeometry(argv[i]) == MagickFalse)
5138 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5139 break;
5140 }
5141 if (LocaleCompare("noop",option+1) == 0)
5142 break;
5143 if (LocaleCompare("normalize",option+1) == 0)
5144 break;
5145 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5146 }
5147 case 'o':
5148 {
5149 if (LocaleCompare("opaque",option+1) == 0)
5150 {
cristy3ed852e2009-09-05 21:47:34 +00005151 i++;
cristybb503372010-05-27 20:51:26 +00005152 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005153 ThrowMogrifyException(OptionError,"MissingArgument",option);
5154 break;
5155 }
5156 if (LocaleCompare("ordered-dither",option+1) == 0)
5157 {
5158 if (*option == '+')
5159 break;
5160 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("orient",option+1) == 0)
5166 {
cristybb503372010-05-27 20:51:26 +00005167 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005168 orientation;
5169
5170 orientation=UndefinedOrientation;
5171 if (*option == '+')
5172 break;
5173 i++;
cristybb503372010-05-27 20:51:26 +00005174 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005175 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005176 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005177 argv[i]);
5178 if (orientation < 0)
5179 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5180 argv[i]);
5181 break;
5182 }
5183 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5184 }
5185 case 'p':
5186 {
5187 if (LocaleCompare("page",option+1) == 0)
5188 {
5189 if (*option == '+')
5190 break;
5191 i++;
cristybb503372010-05-27 20:51:26 +00005192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005193 ThrowMogrifyException(OptionError,"MissingArgument",option);
5194 break;
5195 }
5196 if (LocaleCompare("paint",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 if (IsGeometry(argv[i]) == MagickFalse)
5204 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5205 break;
5206 }
5207 if (LocaleCompare("path",option+1) == 0)
5208 {
5209 (void) CloneString(&path,(char *) NULL);
5210 if (*option == '+')
5211 break;
5212 i++;
cristybb503372010-05-27 20:51:26 +00005213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005214 ThrowMogrifyException(OptionError,"MissingArgument",option);
5215 (void) CloneString(&path,argv[i]);
5216 break;
5217 }
5218 if (LocaleCompare("pointsize",option+1) == 0)
5219 {
5220 if (*option == '+')
5221 break;
5222 i++;
cristybb503372010-05-27 20:51:26 +00005223 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005224 ThrowMogrifyException(OptionError,"MissingArgument",option);
5225 if (IsGeometry(argv[i]) == MagickFalse)
5226 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5227 break;
5228 }
5229 if (LocaleCompare("polaroid",option+1) == 0)
5230 {
5231 if (*option == '+')
5232 break;
5233 i++;
cristybb503372010-05-27 20:51:26 +00005234 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005235 ThrowMogrifyException(OptionError,"MissingArgument",option);
5236 if (IsGeometry(argv[i]) == MagickFalse)
5237 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5238 break;
5239 }
5240 if (LocaleCompare("posterize",option+1) == 0)
5241 {
5242 if (*option == '+')
5243 break;
5244 i++;
cristybb503372010-05-27 20:51:26 +00005245 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005246 ThrowMogrifyException(OptionError,"MissingArgument",option);
5247 if (IsGeometry(argv[i]) == MagickFalse)
5248 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5249 break;
5250 }
cristye7f51092010-01-17 00:39:37 +00005251 if (LocaleCompare("precision",option+1) == 0)
5252 {
5253 if (*option == '+')
5254 break;
5255 i++;
cristybb503372010-05-27 20:51:26 +00005256 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005257 ThrowMogrifyException(OptionError,"MissingArgument",option);
5258 if (IsGeometry(argv[i]) == MagickFalse)
5259 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5260 break;
5261 }
cristy3ed852e2009-09-05 21:47:34 +00005262 if (LocaleCompare("print",option+1) == 0)
5263 {
5264 if (*option == '+')
5265 break;
5266 i++;
cristybb503372010-05-27 20:51:26 +00005267 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005268 ThrowMogrifyException(OptionError,"MissingArgument",option);
5269 break;
5270 }
5271 if (LocaleCompare("process",option+1) == 0)
5272 {
5273 if (*option == '+')
5274 break;
5275 i++;
cristybb503372010-05-27 20:51:26 +00005276 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005277 ThrowMogrifyException(OptionError,"MissingArgument",option);
5278 break;
5279 }
5280 if (LocaleCompare("profile",option+1) == 0)
5281 {
5282 i++;
cristybb503372010-05-27 20:51:26 +00005283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005284 ThrowMogrifyException(OptionError,"MissingArgument",option);
5285 break;
5286 }
5287 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5288 }
5289 case 'q':
5290 {
5291 if (LocaleCompare("quality",option+1) == 0)
5292 {
5293 if (*option == '+')
5294 break;
5295 i++;
cristybb503372010-05-27 20:51:26 +00005296 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005297 ThrowMogrifyException(OptionError,"MissingArgument",option);
5298 if (IsGeometry(argv[i]) == MagickFalse)
5299 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5300 break;
5301 }
5302 if (LocaleCompare("quantize",option+1) == 0)
5303 {
cristybb503372010-05-27 20:51:26 +00005304 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005305 colorspace;
5306
5307 if (*option == '+')
5308 break;
5309 i++;
cristybb503372010-05-27 20:51:26 +00005310 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005311 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005312 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005313 argv[i]);
5314 if (colorspace < 0)
5315 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5316 argv[i]);
5317 break;
5318 }
5319 if (LocaleCompare("quiet",option+1) == 0)
5320 break;
5321 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5322 }
5323 case 'r':
5324 {
5325 if (LocaleCompare("radial-blur",option+1) == 0)
5326 {
5327 i++;
cristybb503372010-05-27 20:51:26 +00005328 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005329 ThrowMogrifyException(OptionError,"MissingArgument",option);
5330 if (IsGeometry(argv[i]) == MagickFalse)
5331 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5332 break;
5333 }
5334 if (LocaleCompare("raise",option+1) == 0)
5335 {
5336 i++;
cristybb503372010-05-27 20:51:26 +00005337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005338 ThrowMogrifyException(OptionError,"MissingArgument",option);
5339 if (IsGeometry(argv[i]) == MagickFalse)
5340 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5341 break;
5342 }
5343 if (LocaleCompare("random-threshold",option+1) == 0)
5344 {
5345 if (*option == '+')
5346 break;
5347 i++;
cristybb503372010-05-27 20:51:26 +00005348 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005349 ThrowMogrifyException(OptionError,"MissingArgument",option);
5350 if (IsGeometry(argv[i]) == MagickFalse)
5351 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5352 break;
5353 }
cristye6365592010-04-02 17:31:23 +00005354 if (LocaleCompare("recolor",option+1) == 0)
5355 {
5356 if (*option == '+')
5357 break;
5358 i++;
cristybb503372010-05-27 20:51:26 +00005359 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005360 ThrowMogrifyException(OptionError,"MissingArgument",option);
5361 if (IsGeometry(argv[i]) == MagickFalse)
5362 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5363 break;
5364 }
cristy3ed852e2009-09-05 21:47:34 +00005365 if (LocaleCompare("red-primary",option+1) == 0)
5366 {
5367 if (*option == '+')
5368 break;
5369 i++;
cristybb503372010-05-27 20:51:26 +00005370 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005371 ThrowMogrifyException(OptionError,"MissingArgument",option);
5372 if (IsGeometry(argv[i]) == MagickFalse)
5373 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5374 }
cristy9f2083a2010-04-22 19:48:05 +00005375 if (LocaleCompare("regard-warnings",option+1) == 0)
5376 break;
cristy3ed852e2009-09-05 21:47:34 +00005377 if (LocaleCompare("region",option+1) == 0)
5378 {
5379 if (*option == '+')
5380 break;
5381 i++;
cristybb503372010-05-27 20:51:26 +00005382 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005383 ThrowMogrifyException(OptionError,"MissingArgument",option);
5384 if (IsGeometry(argv[i]) == MagickFalse)
5385 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5386 break;
5387 }
cristyf0c78232010-03-15 12:53:40 +00005388 if (LocaleCompare("remap",option+1) == 0)
5389 {
5390 if (*option == '+')
5391 break;
5392 i++;
cristybb503372010-05-27 20:51:26 +00005393 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005394 ThrowMogrifyException(OptionError,"MissingArgument",option);
5395 break;
5396 }
cristy3ed852e2009-09-05 21:47:34 +00005397 if (LocaleCompare("render",option+1) == 0)
5398 break;
5399 if (LocaleCompare("repage",option+1) == 0)
5400 {
5401 if (*option == '+')
5402 break;
5403 i++;
cristybb503372010-05-27 20:51:26 +00005404 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005405 ThrowMogrifyException(OptionError,"MissingArgument",option);
5406 if (IsGeometry(argv[i]) == MagickFalse)
5407 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5408 break;
5409 }
5410 if (LocaleCompare("resample",option+1) == 0)
5411 {
5412 if (*option == '+')
5413 break;
5414 i++;
cristybb503372010-05-27 20:51:26 +00005415 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005416 ThrowMogrifyException(OptionError,"MissingArgument",option);
5417 if (IsGeometry(argv[i]) == MagickFalse)
5418 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5419 break;
5420 }
5421 if (LocaleCompare("resize",option+1) == 0)
5422 {
5423 if (*option == '+')
5424 break;
5425 i++;
cristybb503372010-05-27 20:51:26 +00005426 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005427 ThrowMogrifyException(OptionError,"MissingArgument",option);
5428 if (IsGeometry(argv[i]) == MagickFalse)
5429 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5430 break;
5431 }
cristyebbcfea2011-02-25 02:43:54 +00005432 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5433 {
5434 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5435 break;
5436 }
cristy3ed852e2009-09-05 21:47:34 +00005437 if (LocaleCompare("reverse",option+1) == 0)
5438 break;
5439 if (LocaleCompare("roll",option+1) == 0)
5440 {
5441 if (*option == '+')
5442 break;
5443 i++;
cristybb503372010-05-27 20:51:26 +00005444 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005445 ThrowMogrifyException(OptionError,"MissingArgument",option);
5446 if (IsGeometry(argv[i]) == MagickFalse)
5447 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5448 break;
5449 }
5450 if (LocaleCompare("rotate",option+1) == 0)
5451 {
5452 i++;
cristybb503372010-05-27 20:51:26 +00005453 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005454 ThrowMogrifyException(OptionError,"MissingArgument",option);
5455 if (IsGeometry(argv[i]) == MagickFalse)
5456 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5457 break;
5458 }
5459 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5460 }
5461 case 's':
5462 {
5463 if (LocaleCompare("sample",option+1) == 0)
5464 {
5465 if (*option == '+')
5466 break;
5467 i++;
cristybb503372010-05-27 20:51:26 +00005468 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005469 ThrowMogrifyException(OptionError,"MissingArgument",option);
5470 if (IsGeometry(argv[i]) == MagickFalse)
5471 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5472 break;
5473 }
5474 if (LocaleCompare("sampling-factor",option+1) == 0)
5475 {
5476 if (*option == '+')
5477 break;
5478 i++;
cristybb503372010-05-27 20:51:26 +00005479 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005480 ThrowMogrifyException(OptionError,"MissingArgument",option);
5481 if (IsGeometry(argv[i]) == MagickFalse)
5482 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5483 break;
5484 }
5485 if (LocaleCompare("scale",option+1) == 0)
5486 {
5487 if (*option == '+')
5488 break;
5489 i++;
cristybb503372010-05-27 20:51:26 +00005490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005491 ThrowMogrifyException(OptionError,"MissingArgument",option);
5492 if (IsGeometry(argv[i]) == MagickFalse)
5493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5494 break;
5495 }
5496 if (LocaleCompare("scene",option+1) == 0)
5497 {
5498 if (*option == '+')
5499 break;
5500 i++;
cristybb503372010-05-27 20:51:26 +00005501 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005502 ThrowMogrifyException(OptionError,"MissingArgument",option);
5503 if (IsGeometry(argv[i]) == MagickFalse)
5504 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5505 break;
5506 }
5507 if (LocaleCompare("seed",option+1) == 0)
5508 {
5509 if (*option == '+')
5510 break;
5511 i++;
cristybb503372010-05-27 20:51:26 +00005512 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005513 ThrowMogrifyException(OptionError,"MissingArgument",option);
5514 if (IsGeometry(argv[i]) == MagickFalse)
5515 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5516 break;
5517 }
5518 if (LocaleCompare("segment",option+1) == 0)
5519 {
5520 if (*option == '+')
5521 break;
5522 i++;
cristybb503372010-05-27 20:51:26 +00005523 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005524 ThrowMogrifyException(OptionError,"MissingArgument",option);
5525 if (IsGeometry(argv[i]) == MagickFalse)
5526 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5527 break;
5528 }
5529 if (LocaleCompare("selective-blur",option+1) == 0)
5530 {
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("separate",option+1) == 0)
5539 break;
5540 if (LocaleCompare("sepia-tone",option+1) == 0)
5541 {
5542 if (*option == '+')
5543 break;
5544 i++;
cristybb503372010-05-27 20:51:26 +00005545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005546 ThrowMogrifyException(OptionError,"MissingArgument",option);
5547 if (IsGeometry(argv[i]) == MagickFalse)
5548 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5549 break;
5550 }
5551 if (LocaleCompare("set",option+1) == 0)
5552 {
5553 i++;
cristybb503372010-05-27 20:51:26 +00005554 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005555 ThrowMogrifyException(OptionError,"MissingArgument",option);
5556 if (*option == '+')
5557 break;
5558 i++;
cristybb503372010-05-27 20:51:26 +00005559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005560 ThrowMogrifyException(OptionError,"MissingArgument",option);
5561 break;
5562 }
5563 if (LocaleCompare("shade",option+1) == 0)
5564 {
5565 i++;
cristybb503372010-05-27 20:51:26 +00005566 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005567 ThrowMogrifyException(OptionError,"MissingArgument",option);
5568 if (IsGeometry(argv[i]) == MagickFalse)
5569 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5570 break;
5571 }
5572 if (LocaleCompare("shadow",option+1) == 0)
5573 {
5574 if (*option == '+')
5575 break;
5576 i++;
cristybb503372010-05-27 20:51:26 +00005577 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005578 ThrowMogrifyException(OptionError,"MissingArgument",option);
5579 if (IsGeometry(argv[i]) == MagickFalse)
5580 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5581 break;
5582 }
5583 if (LocaleCompare("sharpen",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("shave",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("shear",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("sigmoidal-contrast",option+1) == 0)
5613 {
5614 i++;
cristybb503372010-05-27 20:51:26 +00005615 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005616 ThrowMogrifyException(OptionError,"MissingArgument",option);
5617 if (IsGeometry(argv[i]) == MagickFalse)
5618 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5619 break;
5620 }
5621 if (LocaleCompare("size",option+1) == 0)
5622 {
5623 if (*option == '+')
5624 break;
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("sketch",option+1) == 0)
5633 {
5634 if (*option == '+')
5635 break;
5636 i++;
cristybb503372010-05-27 20:51:26 +00005637 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005638 ThrowMogrifyException(OptionError,"MissingArgument",option);
5639 if (IsGeometry(argv[i]) == MagickFalse)
5640 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5641 break;
5642 }
cristy4285d782011-02-09 20:12:28 +00005643 if (LocaleCompare("smush",option+1) == 0)
5644 {
cristy4285d782011-02-09 20:12:28 +00005645 i++;
5646 if (i == (ssize_t) argc)
5647 ThrowMogrifyException(OptionError,"MissingArgument",option);
5648 if (IsGeometry(argv[i]) == MagickFalse)
5649 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005650 i++;
5651 break;
5652 }
cristy3ed852e2009-09-05 21:47:34 +00005653 if (LocaleCompare("solarize",option+1) == 0)
5654 {
5655 if (*option == '+')
5656 break;
5657 i++;
cristybb503372010-05-27 20:51:26 +00005658 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005659 ThrowMogrifyException(OptionError,"MissingArgument",option);
5660 if (IsGeometry(argv[i]) == MagickFalse)
5661 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5662 break;
5663 }
5664 if (LocaleCompare("sparse-color",option+1) == 0)
5665 {
cristybb503372010-05-27 20:51:26 +00005666 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005667 op;
5668
5669 i++;
cristybb503372010-05-27 20:51:26 +00005670 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005671 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005672 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005673 if (op < 0)
5674 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5675 argv[i]);
5676 i++;
cristybb503372010-05-27 20:51:26 +00005677 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005678 ThrowMogrifyException(OptionError,"MissingArgument",option);
5679 break;
5680 }
5681 if (LocaleCompare("spread",option+1) == 0)
5682 {
5683 if (*option == '+')
5684 break;
5685 i++;
cristybb503372010-05-27 20:51:26 +00005686 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005687 ThrowMogrifyException(OptionError,"MissingArgument",option);
5688 if (IsGeometry(argv[i]) == MagickFalse)
5689 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5690 break;
5691 }
cristy0834d642011-03-18 18:26:08 +00005692 if (LocaleCompare("statistic",option+1) == 0)
5693 {
5694 ssize_t
5695 op;
5696
5697 if (*option == '+')
5698 break;
5699 i++;
5700 if (i == (ssize_t) argc)
5701 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005702 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005703 if (op < 0)
5704 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5705 argv[i]);
5706 i++;
5707 if (i == (ssize_t) (argc-1))
5708 ThrowMogrifyException(OptionError,"MissingArgument",option);
5709 if (IsGeometry(argv[i]) == MagickFalse)
5710 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5711 break;
5712 }
cristy3ed852e2009-09-05 21:47:34 +00005713 if (LocaleCompare("stretch",option+1) == 0)
5714 {
cristybb503372010-05-27 20:51:26 +00005715 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005716 stretch;
5717
5718 if (*option == '+')
5719 break;
5720 i++;
cristybb503372010-05-27 20:51:26 +00005721 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005722 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005723 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005724 if (stretch < 0)
5725 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5726 argv[i]);
5727 break;
5728 }
5729 if (LocaleCompare("strip",option+1) == 0)
5730 break;
5731 if (LocaleCompare("stroke",option+1) == 0)
5732 {
5733 if (*option == '+')
5734 break;
5735 i++;
cristybb503372010-05-27 20:51:26 +00005736 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005737 ThrowMogrifyException(OptionError,"MissingArgument",option);
5738 break;
5739 }
5740 if (LocaleCompare("strokewidth",option+1) == 0)
5741 {
5742 if (*option == '+')
5743 break;
5744 i++;
cristybb503372010-05-27 20:51:26 +00005745 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005746 ThrowMogrifyException(OptionError,"MissingArgument",option);
5747 if (IsGeometry(argv[i]) == MagickFalse)
5748 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5749 break;
5750 }
5751 if (LocaleCompare("style",option+1) == 0)
5752 {
cristybb503372010-05-27 20:51:26 +00005753 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005754 style;
5755
5756 if (*option == '+')
5757 break;
5758 i++;
cristybb503372010-05-27 20:51:26 +00005759 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005760 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005761 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005762 if (style < 0)
5763 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5764 argv[i]);
5765 break;
5766 }
cristyecb10ff2011-03-22 13:14:03 +00005767 if (LocaleCompare("swap",option+1) == 0)
5768 {
5769 if (*option == '+')
5770 break;
5771 i++;
5772 if (i == (ssize_t) (argc-1))
5773 ThrowMogrifyException(OptionError,"MissingArgument",option);
5774 if (IsGeometry(argv[i]) == MagickFalse)
5775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5776 break;
5777 }
cristy3ed852e2009-09-05 21:47:34 +00005778 if (LocaleCompare("swirl",option+1) == 0)
5779 {
5780 if (*option == '+')
5781 break;
5782 i++;
cristybb503372010-05-27 20:51:26 +00005783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005784 ThrowMogrifyException(OptionError,"MissingArgument",option);
5785 if (IsGeometry(argv[i]) == MagickFalse)
5786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5787 break;
5788 }
cristyd9a29192010-10-16 16:49:53 +00005789 if (LocaleCompare("synchronize",option+1) == 0)
5790 break;
cristy3ed852e2009-09-05 21:47:34 +00005791 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5792 }
5793 case 't':
5794 {
5795 if (LocaleCompare("taint",option+1) == 0)
5796 break;
5797 if (LocaleCompare("texture",option+1) == 0)
5798 {
5799 if (*option == '+')
5800 break;
5801 i++;
cristybb503372010-05-27 20:51:26 +00005802 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005803 ThrowMogrifyException(OptionError,"MissingArgument",option);
5804 break;
5805 }
5806 if (LocaleCompare("tile",option+1) == 0)
5807 {
5808 if (*option == '+')
5809 break;
5810 i++;
cristybb503372010-05-27 20:51:26 +00005811 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005812 ThrowMogrifyException(OptionError,"MissingArgument",option);
5813 break;
5814 }
5815 if (LocaleCompare("tile-offset",option+1) == 0)
5816 {
5817 if (*option == '+')
5818 break;
5819 i++;
cristybb503372010-05-27 20:51:26 +00005820 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005821 ThrowMogrifyException(OptionError,"MissingArgument",option);
5822 if (IsGeometry(argv[i]) == MagickFalse)
5823 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5824 break;
5825 }
5826 if (LocaleCompare("tint",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 if (IsGeometry(argv[i]) == MagickFalse)
5834 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5835 break;
5836 }
5837 if (LocaleCompare("transform",option+1) == 0)
5838 break;
5839 if (LocaleCompare("transpose",option+1) == 0)
5840 break;
5841 if (LocaleCompare("transverse",option+1) == 0)
5842 break;
5843 if (LocaleCompare("threshold",option+1) == 0)
5844 {
5845 if (*option == '+')
5846 break;
5847 i++;
cristybb503372010-05-27 20:51:26 +00005848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005849 ThrowMogrifyException(OptionError,"MissingArgument",option);
5850 if (IsGeometry(argv[i]) == MagickFalse)
5851 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5852 break;
5853 }
5854 if (LocaleCompare("thumbnail",option+1) == 0)
5855 {
5856 if (*option == '+')
5857 break;
5858 i++;
cristybb503372010-05-27 20:51:26 +00005859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005860 ThrowMogrifyException(OptionError,"MissingArgument",option);
5861 if (IsGeometry(argv[i]) == MagickFalse)
5862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5863 break;
5864 }
5865 if (LocaleCompare("transparent",option+1) == 0)
5866 {
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 break;
5871 }
5872 if (LocaleCompare("transparent-color",option+1) == 0)
5873 {
5874 if (*option == '+')
5875 break;
5876 i++;
cristybb503372010-05-27 20:51:26 +00005877 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005878 ThrowMogrifyException(OptionError,"MissingArgument",option);
5879 break;
5880 }
5881 if (LocaleCompare("treedepth",option+1) == 0)
5882 {
5883 if (*option == '+')
5884 break;
5885 i++;
cristybb503372010-05-27 20:51:26 +00005886 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005887 ThrowMogrifyException(OptionError,"MissingArgument",option);
5888 if (IsGeometry(argv[i]) == MagickFalse)
5889 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5890 break;
5891 }
5892 if (LocaleCompare("trim",option+1) == 0)
5893 break;
5894 if (LocaleCompare("type",option+1) == 0)
5895 {
cristybb503372010-05-27 20:51:26 +00005896 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005897 type;
5898
5899 if (*option == '+')
5900 break;
5901 i++;
cristybb503372010-05-27 20:51:26 +00005902 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005903 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005904 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005905 if (type < 0)
5906 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5907 argv[i]);
5908 break;
5909 }
5910 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5911 }
5912 case 'u':
5913 {
5914 if (LocaleCompare("undercolor",option+1) == 0)
5915 {
5916 if (*option == '+')
5917 break;
5918 i++;
cristybb503372010-05-27 20:51:26 +00005919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005920 ThrowMogrifyException(OptionError,"MissingArgument",option);
5921 break;
5922 }
5923 if (LocaleCompare("unique-colors",option+1) == 0)
5924 break;
5925 if (LocaleCompare("units",option+1) == 0)
5926 {
cristybb503372010-05-27 20:51:26 +00005927 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005928 units;
5929
5930 if (*option == '+')
5931 break;
5932 i++;
cristybb503372010-05-27 20:51:26 +00005933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005934 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005935 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005936 argv[i]);
5937 if (units < 0)
5938 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5939 argv[i]);
5940 break;
5941 }
5942 if (LocaleCompare("unsharp",option+1) == 0)
5943 {
5944 i++;
cristybb503372010-05-27 20:51:26 +00005945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005946 ThrowMogrifyException(OptionError,"MissingArgument",option);
5947 if (IsGeometry(argv[i]) == MagickFalse)
5948 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5949 break;
5950 }
5951 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5952 }
5953 case 'v':
5954 {
5955 if (LocaleCompare("verbose",option+1) == 0)
5956 {
5957 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5958 break;
5959 }
5960 if ((LocaleCompare("version",option+1) == 0) ||
5961 (LocaleCompare("-version",option+1) == 0))
5962 {
cristyb51dff52011-05-19 16:55:47 +00005963 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005964 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005965 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5966 GetMagickCopyright());
5967 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5968 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005969 break;
5970 }
5971 if (LocaleCompare("view",option+1) == 0)
5972 {
5973 if (*option == '+')
5974 break;
5975 i++;
cristybb503372010-05-27 20:51:26 +00005976 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005977 ThrowMogrifyException(OptionError,"MissingArgument",option);
5978 break;
5979 }
5980 if (LocaleCompare("vignette",option+1) == 0)
5981 {
5982 if (*option == '+')
5983 break;
5984 i++;
cristybb503372010-05-27 20:51:26 +00005985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005986 ThrowMogrifyException(OptionError,"MissingArgument",option);
5987 if (IsGeometry(argv[i]) == MagickFalse)
5988 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5989 break;
5990 }
5991 if (LocaleCompare("virtual-pixel",option+1) == 0)
5992 {
cristybb503372010-05-27 20:51:26 +00005993 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005994 method;
5995
5996 if (*option == '+')
5997 break;
5998 i++;
cristybb503372010-05-27 20:51:26 +00005999 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006000 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006001 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006002 argv[i]);
6003 if (method < 0)
6004 ThrowMogrifyException(OptionError,
6005 "UnrecognizedVirtualPixelMethod",argv[i]);
6006 break;
6007 }
6008 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6009 }
6010 case 'w':
6011 {
6012 if (LocaleCompare("wave",option+1) == 0)
6013 {
6014 i++;
cristybb503372010-05-27 20:51:26 +00006015 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006016 ThrowMogrifyException(OptionError,"MissingArgument",option);
6017 if (IsGeometry(argv[i]) == MagickFalse)
6018 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6019 break;
6020 }
6021 if (LocaleCompare("weight",option+1) == 0)
6022 {
6023 if (*option == '+')
6024 break;
6025 i++;
cristybb503372010-05-27 20:51:26 +00006026 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006027 ThrowMogrifyException(OptionError,"MissingArgument",option);
6028 break;
6029 }
6030 if (LocaleCompare("white-point",option+1) == 0)
6031 {
6032 if (*option == '+')
6033 break;
6034 i++;
cristybb503372010-05-27 20:51:26 +00006035 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006036 ThrowMogrifyException(OptionError,"MissingArgument",option);
6037 if (IsGeometry(argv[i]) == MagickFalse)
6038 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6039 break;
6040 }
6041 if (LocaleCompare("white-threshold",option+1) == 0)
6042 {
6043 if (*option == '+')
6044 break;
6045 i++;
cristybb503372010-05-27 20:51:26 +00006046 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006047 ThrowMogrifyException(OptionError,"MissingArgument",option);
6048 if (IsGeometry(argv[i]) == MagickFalse)
6049 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6050 break;
6051 }
6052 if (LocaleCompare("write",option+1) == 0)
6053 {
6054 i++;
cristybb503372010-05-27 20:51:26 +00006055 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006056 ThrowMogrifyException(OptionError,"MissingArgument",option);
6057 break;
6058 }
6059 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6060 }
6061 case '?':
6062 break;
6063 default:
6064 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6065 }
cristy042ee782011-04-22 18:48:30 +00006066 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6067 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006068 if (fire != MagickFalse)
6069 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6070 }
6071 if (k != 0)
6072 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006073 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006074 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6075 DestroyMogrify();
6076 return(status != 0 ? MagickTrue : MagickFalse);
6077}
6078
6079/*
6080%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6081% %
6082% %
6083% %
6084+ M o g r i f y I m a g e I n f o %
6085% %
6086% %
6087% %
6088%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6089%
6090% MogrifyImageInfo() applies image processing settings to the image as
6091% prescribed by command line options.
6092%
6093% The format of the MogrifyImageInfo method is:
6094%
6095% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6096% const char **argv,ExceptionInfo *exception)
6097%
6098% A description of each parameter follows:
6099%
6100% o image_info: the image info..
6101%
6102% o argc: Specifies a pointer to an integer describing the number of
6103% elements in the argument vector.
6104%
6105% o argv: Specifies a pointer to a text array containing the command line
6106% arguments.
6107%
6108% o exception: return any errors or warnings in this structure.
6109%
6110*/
6111WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6112 const int argc,const char **argv,ExceptionInfo *exception)
6113{
6114 const char
6115 *option;
6116
6117 GeometryInfo
6118 geometry_info;
6119
cristybb503372010-05-27 20:51:26 +00006120 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006121 count;
6122
cristybb503372010-05-27 20:51:26 +00006123 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006124 i;
6125
6126 /*
6127 Initialize method variables.
6128 */
6129 assert(image_info != (ImageInfo *) NULL);
6130 assert(image_info->signature == MagickSignature);
6131 if (image_info->debug != MagickFalse)
6132 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6133 image_info->filename);
6134 if (argc < 0)
6135 return(MagickTrue);
6136 /*
6137 Set the image settings.
6138 */
cristybb503372010-05-27 20:51:26 +00006139 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006140 {
6141 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006142 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006143 continue;
cristy042ee782011-04-22 18:48:30 +00006144 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006145 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006146 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006147 break;
6148 switch (*(option+1))
6149 {
6150 case 'a':
6151 {
6152 if (LocaleCompare("adjoin",option+1) == 0)
6153 {
6154 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6155 break;
6156 }
6157 if (LocaleCompare("antialias",option+1) == 0)
6158 {
6159 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6160 break;
6161 }
cristy3ed852e2009-09-05 21:47:34 +00006162 if (LocaleCompare("authenticate",option+1) == 0)
6163 {
6164 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006165 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006166 else
anthony1afdc7a2011-10-05 11:54:28 +00006167 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006168 break;
6169 }
6170 break;
6171 }
6172 case 'b':
6173 {
6174 if (LocaleCompare("background",option+1) == 0)
6175 {
6176 if (*option == '+')
6177 {
6178 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006179 (void) QueryColorCompliance(MogrifyBackgroundColor,
6180 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006181 break;
6182 }
6183 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006184 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6185 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006186 break;
6187 }
6188 if (LocaleCompare("bias",option+1) == 0)
6189 {
6190 if (*option == '+')
6191 {
6192 (void) SetImageOption(image_info,option+1,"0.0");
6193 break;
6194 }
6195 (void) SetImageOption(image_info,option+1,argv[i+1]);
6196 break;
6197 }
6198 if (LocaleCompare("black-point-compensation",option+1) == 0)
6199 {
6200 if (*option == '+')
6201 {
6202 (void) SetImageOption(image_info,option+1,"false");
6203 break;
6204 }
6205 (void) SetImageOption(image_info,option+1,"true");
6206 break;
6207 }
6208 if (LocaleCompare("blue-primary",option+1) == 0)
6209 {
6210 if (*option == '+')
6211 {
6212 (void) SetImageOption(image_info,option+1,"0.0");
6213 break;
6214 }
6215 (void) SetImageOption(image_info,option+1,argv[i+1]);
6216 break;
6217 }
6218 if (LocaleCompare("bordercolor",option+1) == 0)
6219 {
6220 if (*option == '+')
6221 {
6222 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006223 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006224 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006225 break;
6226 }
cristy9950d572011-10-01 18:22:35 +00006227 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6228 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006229 (void) SetImageOption(image_info,option+1,argv[i+1]);
6230 break;
6231 }
6232 if (LocaleCompare("box",option+1) == 0)
6233 {
6234 if (*option == '+')
6235 {
6236 (void) SetImageOption(image_info,"undercolor","none");
6237 break;
6238 }
6239 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6240 break;
6241 }
6242 break;
6243 }
6244 case 'c':
6245 {
6246 if (LocaleCompare("cache",option+1) == 0)
6247 {
6248 MagickSizeType
6249 limit;
6250
6251 limit=MagickResourceInfinity;
6252 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006253 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6254 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006255 (void) SetMagickResourceLimit(MemoryResource,limit);
6256 (void) SetMagickResourceLimit(MapResource,2*limit);
6257 break;
6258 }
6259 if (LocaleCompare("caption",option+1) == 0)
6260 {
6261 if (*option == '+')
6262 {
6263 (void) DeleteImageOption(image_info,option+1);
6264 break;
6265 }
6266 (void) SetImageOption(image_info,option+1,argv[i+1]);
6267 break;
6268 }
6269 if (LocaleCompare("channel",option+1) == 0)
6270 {
6271 if (*option == '+')
6272 {
6273 image_info->channel=DefaultChannels;
6274 break;
6275 }
6276 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6277 break;
6278 }
cristy3ed852e2009-09-05 21:47:34 +00006279 if (LocaleCompare("colorspace",option+1) == 0)
6280 {
6281 if (*option == '+')
6282 {
6283 image_info->colorspace=UndefinedColorspace;
6284 (void) SetImageOption(image_info,option+1,"undefined");
6285 break;
6286 }
cristy042ee782011-04-22 18:48:30 +00006287 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006288 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6289 (void) SetImageOption(image_info,option+1,argv[i+1]);
6290 break;
6291 }
cristy3ed852e2009-09-05 21:47:34 +00006292 if (LocaleCompare("comment",option+1) == 0)
6293 {
6294 if (*option == '+')
6295 {
6296 (void) DeleteImageOption(image_info,option+1);
6297 break;
6298 }
6299 (void) SetImageOption(image_info,option+1,argv[i+1]);
6300 break;
6301 }
6302 if (LocaleCompare("compose",option+1) == 0)
6303 {
6304 if (*option == '+')
6305 {
6306 (void) SetImageOption(image_info,option+1,"undefined");
6307 break;
6308 }
6309 (void) SetImageOption(image_info,option+1,argv[i+1]);
6310 break;
6311 }
6312 if (LocaleCompare("compress",option+1) == 0)
6313 {
6314 if (*option == '+')
6315 {
6316 image_info->compression=UndefinedCompression;
6317 (void) SetImageOption(image_info,option+1,"undefined");
6318 break;
6319 }
cristy042ee782011-04-22 18:48:30 +00006320 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006321 MagickCompressOptions,MagickFalse,argv[i+1]);
6322 (void) SetImageOption(image_info,option+1,argv[i+1]);
6323 break;
6324 }
6325 break;
6326 }
6327 case 'd':
6328 {
6329 if (LocaleCompare("debug",option+1) == 0)
6330 {
6331 if (*option == '+')
6332 (void) SetLogEventMask("none");
6333 else
6334 (void) SetLogEventMask(argv[i+1]);
6335 image_info->debug=IsEventLogging();
6336 break;
6337 }
6338 if (LocaleCompare("define",option+1) == 0)
6339 {
6340 if (*option == '+')
6341 {
6342 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6343 (void) DeleteImageRegistry(argv[i+1]+9);
6344 else
6345 (void) DeleteImageOption(image_info,argv[i+1]);
6346 break;
6347 }
6348 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6349 {
6350 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6351 exception);
6352 break;
6353 }
6354 (void) DefineImageOption(image_info,argv[i+1]);
6355 break;
6356 }
6357 if (LocaleCompare("delay",option+1) == 0)
6358 {
6359 if (*option == '+')
6360 {
6361 (void) SetImageOption(image_info,option+1,"0");
6362 break;
6363 }
6364 (void) SetImageOption(image_info,option+1,argv[i+1]);
6365 break;
6366 }
6367 if (LocaleCompare("density",option+1) == 0)
6368 {
6369 /*
6370 Set image density.
6371 */
6372 if (*option == '+')
6373 {
6374 if (image_info->density != (char *) NULL)
6375 image_info->density=DestroyString(image_info->density);
6376 (void) SetImageOption(image_info,option+1,"72");
6377 break;
6378 }
6379 (void) CloneString(&image_info->density,argv[i+1]);
6380 (void) SetImageOption(image_info,option+1,argv[i+1]);
6381 break;
6382 }
6383 if (LocaleCompare("depth",option+1) == 0)
6384 {
6385 if (*option == '+')
6386 {
6387 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6388 break;
6389 }
cristye27293e2009-12-18 02:53:20 +00006390 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006391 break;
6392 }
cristyc9b12952010-03-28 01:12:28 +00006393 if (LocaleCompare("direction",option+1) == 0)
6394 {
6395 if (*option == '+')
6396 {
6397 (void) SetImageOption(image_info,option+1,"undefined");
6398 break;
6399 }
6400 (void) SetImageOption(image_info,option+1,argv[i+1]);
6401 break;
6402 }
cristy3ed852e2009-09-05 21:47:34 +00006403 if (LocaleCompare("display",option+1) == 0)
6404 {
6405 if (*option == '+')
6406 {
6407 if (image_info->server_name != (char *) NULL)
6408 image_info->server_name=DestroyString(
6409 image_info->server_name);
6410 break;
6411 }
6412 (void) CloneString(&image_info->server_name,argv[i+1]);
6413 break;
6414 }
6415 if (LocaleCompare("dispose",option+1) == 0)
6416 {
6417 if (*option == '+')
6418 {
6419 (void) SetImageOption(image_info,option+1,"undefined");
6420 break;
6421 }
6422 (void) SetImageOption(image_info,option+1,argv[i+1]);
6423 break;
6424 }
6425 if (LocaleCompare("dither",option+1) == 0)
6426 {
6427 if (*option == '+')
6428 {
6429 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006430 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006431 break;
6432 }
6433 (void) SetImageOption(image_info,option+1,argv[i+1]);
6434 image_info->dither=MagickTrue;
6435 break;
6436 }
6437 break;
6438 }
6439 case 'e':
6440 {
6441 if (LocaleCompare("encoding",option+1) == 0)
6442 {
6443 if (*option == '+')
6444 {
6445 (void) SetImageOption(image_info,option+1,"undefined");
6446 break;
6447 }
6448 (void) SetImageOption(image_info,option+1,argv[i+1]);
6449 break;
6450 }
6451 if (LocaleCompare("endian",option+1) == 0)
6452 {
6453 if (*option == '+')
6454 {
6455 image_info->endian=UndefinedEndian;
6456 (void) SetImageOption(image_info,option+1,"undefined");
6457 break;
6458 }
cristy042ee782011-04-22 18:48:30 +00006459 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006460 MagickEndianOptions,MagickFalse,argv[i+1]);
6461 (void) SetImageOption(image_info,option+1,argv[i+1]);
6462 break;
6463 }
6464 if (LocaleCompare("extract",option+1) == 0)
6465 {
6466 /*
6467 Set image extract geometry.
6468 */
6469 if (*option == '+')
6470 {
6471 if (image_info->extract != (char *) NULL)
6472 image_info->extract=DestroyString(image_info->extract);
6473 break;
6474 }
6475 (void) CloneString(&image_info->extract,argv[i+1]);
6476 break;
6477 }
6478 break;
6479 }
6480 case 'f':
6481 {
6482 if (LocaleCompare("fill",option+1) == 0)
6483 {
6484 if (*option == '+')
6485 {
6486 (void) SetImageOption(image_info,option+1,"none");
6487 break;
6488 }
6489 (void) SetImageOption(image_info,option+1,argv[i+1]);
6490 break;
6491 }
6492 if (LocaleCompare("filter",option+1) == 0)
6493 {
6494 if (*option == '+')
6495 {
6496 (void) SetImageOption(image_info,option+1,"undefined");
6497 break;
6498 }
6499 (void) SetImageOption(image_info,option+1,argv[i+1]);
6500 break;
6501 }
6502 if (LocaleCompare("font",option+1) == 0)
6503 {
6504 if (*option == '+')
6505 {
6506 if (image_info->font != (char *) NULL)
6507 image_info->font=DestroyString(image_info->font);
6508 break;
6509 }
6510 (void) CloneString(&image_info->font,argv[i+1]);
6511 break;
6512 }
6513 if (LocaleCompare("format",option+1) == 0)
6514 {
6515 register const char
6516 *q;
6517
6518 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006519 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006520 image_info->ping=MagickFalse;
6521 (void) SetImageOption(image_info,option+1,argv[i+1]);
6522 break;
6523 }
6524 if (LocaleCompare("fuzz",option+1) == 0)
6525 {
6526 if (*option == '+')
6527 {
6528 image_info->fuzz=0.0;
6529 (void) SetImageOption(image_info,option+1,"0");
6530 break;
6531 }
cristydbdd0e32011-11-04 23:29:40 +00006532 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6533 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006534 (void) SetImageOption(image_info,option+1,argv[i+1]);
6535 break;
6536 }
6537 break;
6538 }
6539 case 'g':
6540 {
6541 if (LocaleCompare("gravity",option+1) == 0)
6542 {
6543 if (*option == '+')
6544 {
6545 (void) SetImageOption(image_info,option+1,"undefined");
6546 break;
6547 }
6548 (void) SetImageOption(image_info,option+1,argv[i+1]);
6549 break;
6550 }
6551 if (LocaleCompare("green-primary",option+1) == 0)
6552 {
6553 if (*option == '+')
6554 {
6555 (void) SetImageOption(image_info,option+1,"0.0");
6556 break;
6557 }
6558 (void) SetImageOption(image_info,option+1,argv[i+1]);
6559 break;
6560 }
6561 break;
6562 }
6563 case 'i':
6564 {
6565 if (LocaleCompare("intent",option+1) == 0)
6566 {
6567 if (*option == '+')
6568 {
6569 (void) SetImageOption(image_info,option+1,"undefined");
6570 break;
6571 }
6572 (void) SetImageOption(image_info,option+1,argv[i+1]);
6573 break;
6574 }
6575 if (LocaleCompare("interlace",option+1) == 0)
6576 {
6577 if (*option == '+')
6578 {
6579 image_info->interlace=UndefinedInterlace;
6580 (void) SetImageOption(image_info,option+1,"undefined");
6581 break;
6582 }
cristy042ee782011-04-22 18:48:30 +00006583 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006584 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6585 (void) SetImageOption(image_info,option+1,argv[i+1]);
6586 break;
6587 }
cristyb32b90a2009-09-07 21:45:48 +00006588 if (LocaleCompare("interline-spacing",option+1) == 0)
6589 {
6590 if (*option == '+')
6591 {
6592 (void) SetImageOption(image_info,option+1,"undefined");
6593 break;
6594 }
6595 (void) SetImageOption(image_info,option+1,argv[i+1]);
6596 break;
6597 }
cristy3ed852e2009-09-05 21:47:34 +00006598 if (LocaleCompare("interpolate",option+1) == 0)
6599 {
6600 if (*option == '+')
6601 {
6602 (void) SetImageOption(image_info,option+1,"undefined");
6603 break;
6604 }
6605 (void) SetImageOption(image_info,option+1,argv[i+1]);
6606 break;
6607 }
6608 if (LocaleCompare("interword-spacing",option+1) == 0)
6609 {
6610 if (*option == '+')
6611 {
6612 (void) SetImageOption(image_info,option+1,"undefined");
6613 break;
6614 }
6615 (void) SetImageOption(image_info,option+1,argv[i+1]);
6616 break;
6617 }
6618 break;
6619 }
6620 case 'k':
6621 {
6622 if (LocaleCompare("kerning",option+1) == 0)
6623 {
6624 if (*option == '+')
6625 {
6626 (void) SetImageOption(image_info,option+1,"undefined");
6627 break;
6628 }
6629 (void) SetImageOption(image_info,option+1,argv[i+1]);
6630 break;
6631 }
6632 break;
6633 }
6634 case 'l':
6635 {
6636 if (LocaleCompare("label",option+1) == 0)
6637 {
6638 if (*option == '+')
6639 {
6640 (void) DeleteImageOption(image_info,option+1);
6641 break;
6642 }
6643 (void) SetImageOption(image_info,option+1,argv[i+1]);
6644 break;
6645 }
6646 if (LocaleCompare("limit",option+1) == 0)
6647 {
6648 MagickSizeType
6649 limit;
6650
6651 ResourceType
6652 type;
6653
6654 if (*option == '+')
6655 break;
cristy042ee782011-04-22 18:48:30 +00006656 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006657 MagickFalse,argv[i+1]);
6658 limit=MagickResourceInfinity;
6659 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006660 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006661 (void) SetMagickResourceLimit(type,limit);
6662 break;
6663 }
6664 if (LocaleCompare("list",option+1) == 0)
6665 {
cristybb503372010-05-27 20:51:26 +00006666 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006667 list;
6668
6669 /*
6670 Display configuration list.
6671 */
cristy042ee782011-04-22 18:48:30 +00006672 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006673 switch (list)
6674 {
6675 case MagickCoderOptions:
6676 {
6677 (void) ListCoderInfo((FILE *) NULL,exception);
6678 break;
6679 }
6680 case MagickColorOptions:
6681 {
6682 (void) ListColorInfo((FILE *) NULL,exception);
6683 break;
6684 }
6685 case MagickConfigureOptions:
6686 {
6687 (void) ListConfigureInfo((FILE *) NULL,exception);
6688 break;
6689 }
6690 case MagickDelegateOptions:
6691 {
6692 (void) ListDelegateInfo((FILE *) NULL,exception);
6693 break;
6694 }
6695 case MagickFontOptions:
6696 {
6697 (void) ListTypeInfo((FILE *) NULL,exception);
6698 break;
6699 }
6700 case MagickFormatOptions:
6701 {
6702 (void) ListMagickInfo((FILE *) NULL,exception);
6703 break;
6704 }
6705 case MagickLocaleOptions:
6706 {
6707 (void) ListLocaleInfo((FILE *) NULL,exception);
6708 break;
6709 }
6710 case MagickLogOptions:
6711 {
6712 (void) ListLogInfo((FILE *) NULL,exception);
6713 break;
6714 }
6715 case MagickMagicOptions:
6716 {
6717 (void) ListMagicInfo((FILE *) NULL,exception);
6718 break;
6719 }
6720 case MagickMimeOptions:
6721 {
6722 (void) ListMimeInfo((FILE *) NULL,exception);
6723 break;
6724 }
6725 case MagickModuleOptions:
6726 {
6727 (void) ListModuleInfo((FILE *) NULL,exception);
6728 break;
6729 }
6730 case MagickPolicyOptions:
6731 {
6732 (void) ListPolicyInfo((FILE *) NULL,exception);
6733 break;
6734 }
6735 case MagickResourceOptions:
6736 {
6737 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6738 break;
6739 }
6740 case MagickThresholdOptions:
6741 {
6742 (void) ListThresholdMaps((FILE *) NULL,exception);
6743 break;
6744 }
6745 default:
6746 {
cristy042ee782011-04-22 18:48:30 +00006747 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006748 exception);
6749 break;
6750 }
6751 }
cristyaeb2cbc2010-05-07 13:28:58 +00006752 break;
cristy3ed852e2009-09-05 21:47:34 +00006753 }
6754 if (LocaleCompare("log",option+1) == 0)
6755 {
6756 if (*option == '+')
6757 break;
6758 (void) SetLogFormat(argv[i+1]);
6759 break;
6760 }
6761 if (LocaleCompare("loop",option+1) == 0)
6762 {
6763 if (*option == '+')
6764 {
6765 (void) SetImageOption(image_info,option+1,"0");
6766 break;
6767 }
6768 (void) SetImageOption(image_info,option+1,argv[i+1]);
6769 break;
6770 }
6771 break;
6772 }
6773 case 'm':
6774 {
6775 if (LocaleCompare("matte",option+1) == 0)
6776 {
6777 if (*option == '+')
6778 {
6779 (void) SetImageOption(image_info,option+1,"false");
6780 break;
6781 }
6782 (void) SetImageOption(image_info,option+1,"true");
6783 break;
6784 }
6785 if (LocaleCompare("mattecolor",option+1) == 0)
6786 {
6787 if (*option == '+')
6788 {
6789 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006790 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006791 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006792 break;
6793 }
6794 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006795 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6796 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006797 break;
6798 }
6799 if (LocaleCompare("monitor",option+1) == 0)
6800 {
6801 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6802 (void *) NULL);
6803 break;
6804 }
6805 if (LocaleCompare("monochrome",option+1) == 0)
6806 {
6807 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6808 break;
6809 }
6810 break;
6811 }
6812 case 'o':
6813 {
6814 if (LocaleCompare("orient",option+1) == 0)
6815 {
6816 if (*option == '+')
6817 {
6818 image_info->orientation=UndefinedOrientation;
6819 (void) SetImageOption(image_info,option+1,"undefined");
6820 break;
6821 }
cristy042ee782011-04-22 18:48:30 +00006822 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006823 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006824 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006825 break;
6826 }
6827 }
6828 case 'p':
6829 {
6830 if (LocaleCompare("page",option+1) == 0)
6831 {
6832 char
6833 *canonical_page,
6834 page[MaxTextExtent];
6835
6836 const char
6837 *image_option;
6838
6839 MagickStatusType
6840 flags;
6841
6842 RectangleInfo
6843 geometry;
6844
6845 if (*option == '+')
6846 {
6847 (void) DeleteImageOption(image_info,option+1);
6848 (void) CloneString(&image_info->page,(char *) NULL);
6849 break;
6850 }
6851 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6852 image_option=GetImageOption(image_info,"page");
6853 if (image_option != (const char *) NULL)
6854 flags=ParseAbsoluteGeometry(image_option,&geometry);
6855 canonical_page=GetPageGeometry(argv[i+1]);
6856 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6857 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006858 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006859 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006860 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006861 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006862 (unsigned long) geometry.width,(unsigned long) geometry.height,
6863 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006864 (void) SetImageOption(image_info,option+1,page);
6865 (void) CloneString(&image_info->page,page);
6866 break;
6867 }
6868 if (LocaleCompare("pen",option+1) == 0)
6869 {
6870 if (*option == '+')
6871 {
6872 (void) SetImageOption(image_info,option+1,"none");
6873 break;
6874 }
6875 (void) SetImageOption(image_info,option+1,argv[i+1]);
6876 break;
6877 }
6878 if (LocaleCompare("ping",option+1) == 0)
6879 {
6880 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6881 break;
6882 }
6883 if (LocaleCompare("pointsize",option+1) == 0)
6884 {
6885 if (*option == '+')
6886 geometry_info.rho=0.0;
6887 else
6888 (void) ParseGeometry(argv[i+1],&geometry_info);
6889 image_info->pointsize=geometry_info.rho;
6890 break;
6891 }
cristye7f51092010-01-17 00:39:37 +00006892 if (LocaleCompare("precision",option+1) == 0)
6893 {
cristybf2766a2010-01-17 03:33:23 +00006894 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006895 break;
6896 }
cristy3ed852e2009-09-05 21:47:34 +00006897 if (LocaleCompare("preview",option+1) == 0)
6898 {
6899 /*
6900 Preview image.
6901 */
6902 if (*option == '+')
6903 {
6904 image_info->preview_type=UndefinedPreview;
6905 break;
6906 }
cristy042ee782011-04-22 18:48:30 +00006907 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006908 MagickPreviewOptions,MagickFalse,argv[i+1]);
6909 break;
6910 }
6911 break;
6912 }
6913 case 'q':
6914 {
6915 if (LocaleCompare("quality",option+1) == 0)
6916 {
6917 /*
6918 Set image compression quality.
6919 */
6920 if (*option == '+')
6921 {
6922 image_info->quality=UndefinedCompressionQuality;
6923 (void) SetImageOption(image_info,option+1,"0");
6924 break;
6925 }
cristye27293e2009-12-18 02:53:20 +00006926 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006927 (void) SetImageOption(image_info,option+1,argv[i+1]);
6928 break;
6929 }
6930 if (LocaleCompare("quiet",option+1) == 0)
6931 {
6932 static WarningHandler
6933 warning_handler = (WarningHandler) NULL;
6934
6935 if (*option == '+')
6936 {
6937 /*
6938 Restore error or warning messages.
6939 */
6940 warning_handler=SetWarningHandler(warning_handler);
6941 break;
6942 }
6943 /*
6944 Suppress error or warning messages.
6945 */
6946 warning_handler=SetWarningHandler((WarningHandler) NULL);
6947 break;
6948 }
6949 break;
6950 }
6951 case 'r':
6952 {
6953 if (LocaleCompare("red-primary",option+1) == 0)
6954 {
6955 if (*option == '+')
6956 {
6957 (void) SetImageOption(image_info,option+1,"0.0");
6958 break;
6959 }
6960 (void) SetImageOption(image_info,option+1,argv[i+1]);
6961 break;
6962 }
6963 break;
6964 }
6965 case 's':
6966 {
6967 if (LocaleCompare("sampling-factor",option+1) == 0)
6968 {
6969 /*
6970 Set image sampling factor.
6971 */
6972 if (*option == '+')
6973 {
6974 if (image_info->sampling_factor != (char *) NULL)
6975 image_info->sampling_factor=DestroyString(
6976 image_info->sampling_factor);
6977 break;
6978 }
6979 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6980 break;
6981 }
6982 if (LocaleCompare("scene",option+1) == 0)
6983 {
6984 /*
6985 Set image scene.
6986 */
6987 if (*option == '+')
6988 {
6989 image_info->scene=0;
6990 (void) SetImageOption(image_info,option+1,"0");
6991 break;
6992 }
cristye27293e2009-12-18 02:53:20 +00006993 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006994 (void) SetImageOption(image_info,option+1,argv[i+1]);
6995 break;
6996 }
6997 if (LocaleCompare("seed",option+1) == 0)
6998 {
cristybb503372010-05-27 20:51:26 +00006999 size_t
cristy3ed852e2009-09-05 21:47:34 +00007000 seed;
7001
7002 if (*option == '+')
7003 {
cristybb503372010-05-27 20:51:26 +00007004 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007005 SeedPseudoRandomGenerator(seed);
7006 break;
7007 }
cristye27293e2009-12-18 02:53:20 +00007008 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007009 SeedPseudoRandomGenerator(seed);
7010 break;
7011 }
7012 if (LocaleCompare("size",option+1) == 0)
7013 {
7014 if (*option == '+')
7015 {
7016 if (image_info->size != (char *) NULL)
7017 image_info->size=DestroyString(image_info->size);
7018 break;
7019 }
7020 (void) CloneString(&image_info->size,argv[i+1]);
7021 break;
7022 }
7023 if (LocaleCompare("stroke",option+1) == 0)
7024 {
7025 if (*option == '+')
7026 {
7027 (void) SetImageOption(image_info,option+1,"none");
7028 break;
7029 }
7030 (void) SetImageOption(image_info,option+1,argv[i+1]);
7031 break;
7032 }
7033 if (LocaleCompare("strokewidth",option+1) == 0)
7034 {
7035 if (*option == '+')
7036 {
7037 (void) SetImageOption(image_info,option+1,"0");
7038 break;
7039 }
7040 (void) SetImageOption(image_info,option+1,argv[i+1]);
7041 break;
7042 }
cristyd9a29192010-10-16 16:49:53 +00007043 if (LocaleCompare("synchronize",option+1) == 0)
7044 {
7045 if (*option == '+')
7046 {
7047 image_info->synchronize=MagickFalse;
7048 break;
7049 }
7050 image_info->synchronize=MagickTrue;
7051 break;
7052 }
cristy3ed852e2009-09-05 21:47:34 +00007053 break;
7054 }
7055 case 't':
7056 {
7057 if (LocaleCompare("taint",option+1) == 0)
7058 {
7059 if (*option == '+')
7060 {
7061 (void) SetImageOption(image_info,option+1,"false");
7062 break;
7063 }
7064 (void) SetImageOption(image_info,option+1,"true");
7065 break;
7066 }
7067 if (LocaleCompare("texture",option+1) == 0)
7068 {
7069 if (*option == '+')
7070 {
7071 if (image_info->texture != (char *) NULL)
7072 image_info->texture=DestroyString(image_info->texture);
7073 break;
7074 }
7075 (void) CloneString(&image_info->texture,argv[i+1]);
7076 break;
7077 }
7078 if (LocaleCompare("tile-offset",option+1) == 0)
7079 {
7080 if (*option == '+')
7081 {
7082 (void) SetImageOption(image_info,option+1,"0");
7083 break;
7084 }
7085 (void) SetImageOption(image_info,option+1,argv[i+1]);
7086 break;
7087 }
7088 if (LocaleCompare("transparent-color",option+1) == 0)
7089 {
7090 if (*option == '+')
7091 {
cristy9950d572011-10-01 18:22:35 +00007092 (void) QueryColorCompliance("none",AllCompliance,
7093 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007094 (void) SetImageOption(image_info,option+1,"none");
7095 break;
7096 }
cristy9950d572011-10-01 18:22:35 +00007097 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7098 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007099 (void) SetImageOption(image_info,option+1,argv[i+1]);
7100 break;
7101 }
7102 if (LocaleCompare("type",option+1) == 0)
7103 {
7104 if (*option == '+')
7105 {
cristy5f1c1ff2010-12-23 21:38:06 +00007106 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007107 (void) SetImageOption(image_info,option+1,"undefined");
7108 break;
7109 }
cristy042ee782011-04-22 18:48:30 +00007110 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007111 MagickFalse,argv[i+1]);
7112 (void) SetImageOption(image_info,option+1,argv[i+1]);
7113 break;
7114 }
7115 break;
7116 }
7117 case 'u':
7118 {
7119 if (LocaleCompare("undercolor",option+1) == 0)
7120 {
7121 if (*option == '+')
7122 {
7123 (void) DeleteImageOption(image_info,option+1);
7124 break;
7125 }
7126 (void) SetImageOption(image_info,option+1,argv[i+1]);
7127 break;
7128 }
7129 if (LocaleCompare("units",option+1) == 0)
7130 {
7131 if (*option == '+')
7132 {
7133 image_info->units=UndefinedResolution;
7134 (void) SetImageOption(image_info,option+1,"undefined");
7135 break;
7136 }
cristy042ee782011-04-22 18:48:30 +00007137 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007138 MagickResolutionOptions,MagickFalse,argv[i+1]);
7139 (void) SetImageOption(image_info,option+1,argv[i+1]);
7140 break;
7141 }
7142 break;
7143 }
7144 case 'v':
7145 {
7146 if (LocaleCompare("verbose",option+1) == 0)
7147 {
7148 if (*option == '+')
7149 {
7150 image_info->verbose=MagickFalse;
7151 break;
7152 }
7153 image_info->verbose=MagickTrue;
7154 image_info->ping=MagickFalse;
7155 break;
7156 }
7157 if (LocaleCompare("view",option+1) == 0)
7158 {
7159 if (*option == '+')
7160 {
7161 if (image_info->view != (char *) NULL)
7162 image_info->view=DestroyString(image_info->view);
7163 break;
7164 }
7165 (void) CloneString(&image_info->view,argv[i+1]);
7166 break;
7167 }
7168 if (LocaleCompare("virtual-pixel",option+1) == 0)
7169 {
7170 if (*option == '+')
7171 {
7172 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7173 (void) SetImageOption(image_info,option+1,"undefined");
7174 break;
7175 }
7176 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007177 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007178 argv[i+1]);
7179 (void) SetImageOption(image_info,option+1,argv[i+1]);
7180 break;
7181 }
7182 break;
7183 }
7184 case 'w':
7185 {
7186 if (LocaleCompare("white-point",option+1) == 0)
7187 {
7188 if (*option == '+')
7189 {
7190 (void) SetImageOption(image_info,option+1,"0.0");
7191 break;
7192 }
7193 (void) SetImageOption(image_info,option+1,argv[i+1]);
7194 break;
7195 }
7196 break;
7197 }
7198 default:
7199 break;
7200 }
7201 i+=count;
7202 }
7203 return(MagickTrue);
7204}
7205
7206/*
7207%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7208% %
7209% %
7210% %
7211+ M o g r i f y I m a g e L i s t %
7212% %
7213% %
7214% %
7215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7216%
7217% MogrifyImageList() applies any command line options that might affect the
7218% entire image list (e.g. -append, -coalesce, etc.).
7219%
7220% The format of the MogrifyImage method is:
7221%
7222% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7223% const char **argv,Image **images,ExceptionInfo *exception)
7224%
7225% A description of each parameter follows:
7226%
7227% o image_info: the image info..
7228%
7229% o argc: Specifies a pointer to an integer describing the number of
7230% elements in the argument vector.
7231%
7232% o argv: Specifies a pointer to a text array containing the command line
7233% arguments.
7234%
anthonye9c27192011-03-27 08:07:06 +00007235% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007236%
7237% o exception: return any errors or warnings in this structure.
7238%
7239*/
7240WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7241 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7242{
cristy3ed852e2009-09-05 21:47:34 +00007243 const char
7244 *option;
7245
cristy6b3da3a2010-06-20 02:21:46 +00007246 ImageInfo
7247 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007248
7249 MagickStatusType
7250 status;
7251
cristy28474bf2011-09-11 23:32:52 +00007252 PixelInterpolateMethod
7253 interpolate_method;
7254
cristy3ed852e2009-09-05 21:47:34 +00007255 QuantizeInfo
7256 *quantize_info;
7257
cristybb503372010-05-27 20:51:26 +00007258 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007259 i;
7260
cristy6b3da3a2010-06-20 02:21:46 +00007261 ssize_t
7262 count,
7263 index;
7264
cristy3ed852e2009-09-05 21:47:34 +00007265 /*
7266 Apply options to the image list.
7267 */
7268 assert(image_info != (ImageInfo *) NULL);
7269 assert(image_info->signature == MagickSignature);
7270 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007271 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007272 assert((*images)->signature == MagickSignature);
7273 if ((*images)->debug != MagickFalse)
7274 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7275 (*images)->filename);
7276 if ((argc <= 0) || (*argv == (char *) NULL))
7277 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007278 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007279 mogrify_info=CloneImageInfo(image_info);
7280 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007281 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007282 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007283 {
cristy74fe8f12009-10-03 19:09:01 +00007284 if (*images == (Image *) NULL)
7285 break;
cristy3ed852e2009-09-05 21:47:34 +00007286 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007287 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007288 continue;
cristy042ee782011-04-22 18:48:30 +00007289 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007290 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007291 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007292 break;
cristy6b3da3a2010-06-20 02:21:46 +00007293 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007294 switch (*(option+1))
7295 {
7296 case 'a':
7297 {
7298 if (LocaleCompare("affinity",option+1) == 0)
7299 {
cristy6fccee12011-10-20 18:43:18 +00007300 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007301 if (*option == '+')
7302 {
cristy018f07f2011-09-04 21:15:19 +00007303 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7304 exception);
cristy3ed852e2009-09-05 21:47:34 +00007305 break;
7306 }
7307 i++;
7308 break;
7309 }
7310 if (LocaleCompare("append",option+1) == 0)
7311 {
7312 Image
7313 *append_image;
7314
cristy6fccee12011-10-20 18:43:18 +00007315 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007316 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7317 MagickFalse,exception);
7318 if (append_image == (Image *) NULL)
7319 {
7320 status=MagickFalse;
7321 break;
7322 }
7323 *images=DestroyImageList(*images);
7324 *images=append_image;
7325 break;
7326 }
7327 if (LocaleCompare("average",option+1) == 0)
7328 {
7329 Image
7330 *average_image;
7331
cristyd18ae7c2010-03-07 17:39:52 +00007332 /*
7333 Average an image sequence (deprecated).
7334 */
cristy6fccee12011-10-20 18:43:18 +00007335 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007336 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7337 exception);
cristy3ed852e2009-09-05 21:47:34 +00007338 if (average_image == (Image *) NULL)
7339 {
7340 status=MagickFalse;
7341 break;
7342 }
7343 *images=DestroyImageList(*images);
7344 *images=average_image;
7345 break;
7346 }
7347 break;
7348 }
7349 case 'c':
7350 {
7351 if (LocaleCompare("channel",option+1) == 0)
7352 {
cristyf4ad9df2011-07-08 16:49:03 +00007353 ChannelType
7354 channel;
7355
cristy3ed852e2009-09-05 21:47:34 +00007356 if (*option == '+')
7357 {
7358 channel=DefaultChannels;
7359 break;
7360 }
7361 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristye2a912b2011-12-05 20:02:07 +00007362 SetPixelChannelMapMask(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007363 break;
7364 }
7365 if (LocaleCompare("clut",option+1) == 0)
7366 {
7367 Image
7368 *clut_image,
7369 *image;
7370
cristy6fccee12011-10-20 18:43:18 +00007371 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007372 image=RemoveFirstImageFromList(images);
7373 clut_image=RemoveFirstImageFromList(images);
7374 if (clut_image == (Image *) NULL)
7375 {
7376 status=MagickFalse;
7377 break;
7378 }
cristy28474bf2011-09-11 23:32:52 +00007379 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007380 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007381 *images=DestroyImageList(*images);
7382 *images=image;
7383 break;
7384 }
7385 if (LocaleCompare("coalesce",option+1) == 0)
7386 {
7387 Image
7388 *coalesce_image;
7389
cristy6fccee12011-10-20 18:43:18 +00007390 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007391 coalesce_image=CoalesceImages(*images,exception);
7392 if (coalesce_image == (Image *) NULL)
7393 {
7394 status=MagickFalse;
7395 break;
7396 }
7397 *images=DestroyImageList(*images);
7398 *images=coalesce_image;
7399 break;
7400 }
7401 if (LocaleCompare("combine",option+1) == 0)
7402 {
7403 Image
7404 *combine_image;
7405
cristy6fccee12011-10-20 18:43:18 +00007406 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007407 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007408 if (combine_image == (Image *) NULL)
7409 {
7410 status=MagickFalse;
7411 break;
7412 }
7413 *images=DestroyImageList(*images);
7414 *images=combine_image;
7415 break;
7416 }
7417 if (LocaleCompare("composite",option+1) == 0)
7418 {
7419 Image
7420 *mask_image,
7421 *composite_image,
7422 *image;
7423
7424 RectangleInfo
7425 geometry;
7426
cristy6fccee12011-10-20 18:43:18 +00007427 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007428 image=RemoveFirstImageFromList(images);
7429 composite_image=RemoveFirstImageFromList(images);
7430 if (composite_image == (Image *) NULL)
7431 {
7432 status=MagickFalse;
7433 break;
7434 }
7435 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007436 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007437 SetGeometry(composite_image,&geometry);
7438 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7439 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7440 &geometry);
7441 mask_image=RemoveFirstImageFromList(images);
7442 if (mask_image != (Image *) NULL)
7443 {
7444 if ((image->compose == DisplaceCompositeOp) ||
7445 (image->compose == DistortCompositeOp))
7446 {
7447 /*
7448 Merge Y displacement into X displacement image.
7449 */
7450 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007451 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007452 mask_image=DestroyImage(mask_image);
7453 }
7454 else
7455 {
7456 /*
7457 Set a blending mask for the composition.
cristy28474bf2011-09-11 23:32:52 +00007458 Posible error, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007459 */
7460 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007461 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007462 }
7463 }
cristyf4ad9df2011-07-08 16:49:03 +00007464 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007465 geometry.x,geometry.y,exception);
anthonya129f702011-04-14 01:08:48 +00007466 if (mask_image != (Image *) NULL)
7467 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007468 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007469 *images=DestroyImageList(*images);
7470 *images=image;
7471 break;
7472 }
cristy3ed852e2009-09-05 21:47:34 +00007473 break;
7474 }
7475 case 'd':
7476 {
7477 if (LocaleCompare("deconstruct",option+1) == 0)
7478 {
7479 Image
7480 *deconstruct_image;
7481
cristy6fccee12011-10-20 18:43:18 +00007482 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007483 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007484 exception);
cristy3ed852e2009-09-05 21:47:34 +00007485 if (deconstruct_image == (Image *) NULL)
7486 {
7487 status=MagickFalse;
7488 break;
7489 }
7490 *images=DestroyImageList(*images);
7491 *images=deconstruct_image;
7492 break;
7493 }
7494 if (LocaleCompare("delete",option+1) == 0)
7495 {
7496 if (*option == '+')
7497 DeleteImages(images,"-1",exception);
7498 else
7499 DeleteImages(images,argv[i+1],exception);
7500 break;
7501 }
7502 if (LocaleCompare("dither",option+1) == 0)
7503 {
7504 if (*option == '+')
7505 {
7506 quantize_info->dither=MagickFalse;
7507 break;
7508 }
7509 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007510 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007511 MagickDitherOptions,MagickFalse,argv[i+1]);
7512 break;
7513 }
cristyecb10ff2011-03-22 13:14:03 +00007514 if (LocaleCompare("duplicate",option+1) == 0)
7515 {
cristy72988482011-03-29 16:34:38 +00007516 Image
7517 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007518
anthony2b6bcae2011-03-23 13:05:34 +00007519 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007520 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7521 else
7522 {
7523 const char
7524 *p;
7525
anthony2b6bcae2011-03-23 13:05:34 +00007526 size_t
7527 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007528
anthony2b6bcae2011-03-23 13:05:34 +00007529 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007530 p=strchr(argv[i+1],',');
7531 if (p == (const char *) NULL)
7532 duplicate_images=DuplicateImages(*images,number_duplicates,
7533 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007534 else
cristy72988482011-03-29 16:34:38 +00007535 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7536 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007537 }
7538 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007539 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007540 break;
7541 }
cristy3ed852e2009-09-05 21:47:34 +00007542 break;
7543 }
cristyd18ae7c2010-03-07 17:39:52 +00007544 case 'e':
7545 {
7546 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7547 {
7548 Image
7549 *evaluate_image;
7550
7551 MagickEvaluateOperator
7552 op;
7553
cristy6fccee12011-10-20 18:43:18 +00007554 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007555 op=(MagickEvaluateOperator) ParseCommandOption(
7556 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007557 evaluate_image=EvaluateImages(*images,op,exception);
7558 if (evaluate_image == (Image *) NULL)
7559 {
7560 status=MagickFalse;
7561 break;
7562 }
7563 *images=DestroyImageList(*images);
7564 *images=evaluate_image;
7565 break;
7566 }
7567 break;
7568 }
cristy3ed852e2009-09-05 21:47:34 +00007569 case 'f':
7570 {
cristyf0a247f2009-10-04 00:20:03 +00007571 if (LocaleCompare("fft",option+1) == 0)
7572 {
7573 Image
7574 *fourier_image;
7575
7576 /*
7577 Implements the discrete Fourier transform (DFT).
7578 */
cristy6fccee12011-10-20 18:43:18 +00007579 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007580 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7581 MagickTrue : MagickFalse,exception);
7582 if (fourier_image == (Image *) NULL)
7583 break;
7584 *images=DestroyImage(*images);
7585 *images=fourier_image;
7586 break;
7587 }
cristy3ed852e2009-09-05 21:47:34 +00007588 if (LocaleCompare("flatten",option+1) == 0)
7589 {
7590 Image
7591 *flatten_image;
7592
cristy6fccee12011-10-20 18:43:18 +00007593 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007594 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7595 if (flatten_image == (Image *) NULL)
7596 break;
7597 *images=DestroyImageList(*images);
7598 *images=flatten_image;
7599 break;
7600 }
7601 if (LocaleCompare("fx",option+1) == 0)
7602 {
7603 Image
7604 *fx_image;
7605
cristy6fccee12011-10-20 18:43:18 +00007606 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007607 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007608 if (fx_image == (Image *) NULL)
7609 {
7610 status=MagickFalse;
7611 break;
7612 }
7613 *images=DestroyImageList(*images);
7614 *images=fx_image;
7615 break;
7616 }
7617 break;
7618 }
7619 case 'h':
7620 {
7621 if (LocaleCompare("hald-clut",option+1) == 0)
7622 {
7623 Image
7624 *hald_image,
7625 *image;
7626
cristy6fccee12011-10-20 18:43:18 +00007627 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007628 image=RemoveFirstImageFromList(images);
7629 hald_image=RemoveFirstImageFromList(images);
7630 if (hald_image == (Image *) NULL)
7631 {
7632 status=MagickFalse;
7633 break;
7634 }
cristy7c0a0a42011-08-23 17:57:25 +00007635 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007636 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007637 if (*images != (Image *) NULL)
7638 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007639 *images=image;
7640 break;
7641 }
7642 break;
7643 }
7644 case 'i':
7645 {
7646 if (LocaleCompare("ift",option+1) == 0)
7647 {
7648 Image
cristy8587f882009-11-13 20:28:49 +00007649 *fourier_image,
7650 *magnitude_image,
7651 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007652
7653 /*
7654 Implements the inverse fourier discrete Fourier transform (DFT).
7655 */
cristy6fccee12011-10-20 18:43:18 +00007656 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007657 magnitude_image=RemoveFirstImageFromList(images);
7658 phase_image=RemoveFirstImageFromList(images);
7659 if (phase_image == (Image *) NULL)
7660 {
7661 status=MagickFalse;
7662 break;
7663 }
7664 fourier_image=InverseFourierTransformImage(magnitude_image,
7665 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007666 if (fourier_image == (Image *) NULL)
7667 break;
cristy0aff6ea2009-11-14 01:40:53 +00007668 if (*images != (Image *) NULL)
7669 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007670 *images=fourier_image;
7671 break;
7672 }
7673 if (LocaleCompare("insert",option+1) == 0)
7674 {
7675 Image
7676 *p,
7677 *q;
7678
7679 index=0;
7680 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007681 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007682 p=RemoveLastImageFromList(images);
7683 if (p == (Image *) NULL)
7684 {
7685 (void) ThrowMagickException(exception,GetMagickModule(),
7686 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7687 status=MagickFalse;
7688 break;
7689 }
7690 q=p;
7691 if (index == 0)
7692 PrependImageToList(images,q);
7693 else
cristybb503372010-05-27 20:51:26 +00007694 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007695 AppendImageToList(images,q);
7696 else
7697 {
7698 q=GetImageFromList(*images,index-1);
7699 if (q == (Image *) NULL)
7700 {
7701 (void) ThrowMagickException(exception,GetMagickModule(),
7702 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7703 status=MagickFalse;
7704 break;
7705 }
7706 InsertImageInList(&q,p);
7707 }
7708 *images=GetFirstImageInList(q);
7709 break;
7710 }
cristy28474bf2011-09-11 23:32:52 +00007711 if (LocaleCompare("interpolate",option+1) == 0)
7712 {
7713 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7714 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7715 break;
7716 }
cristy3ed852e2009-09-05 21:47:34 +00007717 break;
7718 }
7719 case 'l':
7720 {
7721 if (LocaleCompare("layers",option+1) == 0)
7722 {
7723 Image
7724 *layers;
7725
7726 ImageLayerMethod
7727 method;
7728
cristy6fccee12011-10-20 18:43:18 +00007729 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007730 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007731 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007732 MagickFalse,argv[i+1]);
7733 switch (method)
7734 {
7735 case CoalesceLayer:
7736 {
7737 layers=CoalesceImages(*images,exception);
7738 break;
7739 }
7740 case CompareAnyLayer:
7741 case CompareClearLayer:
7742 case CompareOverlayLayer:
7743 default:
7744 {
cristy8a9106f2011-07-05 14:39:26 +00007745 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007746 break;
7747 }
7748 case MergeLayer:
7749 case FlattenLayer:
7750 case MosaicLayer:
7751 case TrimBoundsLayer:
7752 {
7753 layers=MergeImageLayers(*images,method,exception);
7754 break;
7755 }
7756 case DisposeLayer:
7757 {
7758 layers=DisposeImages(*images,exception);
7759 break;
7760 }
7761 case OptimizeImageLayer:
7762 {
7763 layers=OptimizeImageLayers(*images,exception);
7764 break;
7765 }
7766 case OptimizePlusLayer:
7767 {
7768 layers=OptimizePlusImageLayers(*images,exception);
7769 break;
7770 }
7771 case OptimizeTransLayer:
7772 {
7773 OptimizeImageTransparency(*images,exception);
7774 break;
7775 }
7776 case RemoveDupsLayer:
7777 {
7778 RemoveDuplicateLayers(images,exception);
7779 break;
7780 }
7781 case RemoveZeroLayer:
7782 {
7783 RemoveZeroDelayLayers(images,exception);
7784 break;
7785 }
7786 case OptimizeLayer:
7787 {
7788 /*
7789 General Purpose, GIF Animation Optimizer.
7790 */
7791 layers=CoalesceImages(*images,exception);
7792 if (layers == (Image *) NULL)
7793 {
7794 status=MagickFalse;
7795 break;
7796 }
cristy3ed852e2009-09-05 21:47:34 +00007797 *images=DestroyImageList(*images);
7798 *images=layers;
7799 layers=OptimizeImageLayers(*images,exception);
7800 if (layers == (Image *) NULL)
7801 {
7802 status=MagickFalse;
7803 break;
7804 }
cristy3ed852e2009-09-05 21:47:34 +00007805 *images=DestroyImageList(*images);
7806 *images=layers;
7807 layers=(Image *) NULL;
7808 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007809 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7810 exception);
cristy3ed852e2009-09-05 21:47:34 +00007811 break;
7812 }
7813 case CompositeLayer:
7814 {
7815 CompositeOperator
7816 compose;
7817
7818 Image
7819 *source;
7820
7821 RectangleInfo
7822 geometry;
7823
7824 /*
7825 Split image sequence at the first 'NULL:' image.
7826 */
7827 source=(*images);
7828 while (source != (Image *) NULL)
7829 {
7830 source=GetNextImageInList(source);
7831 if ((source != (Image *) NULL) &&
7832 (LocaleCompare(source->magick,"NULL") == 0))
7833 break;
7834 }
7835 if (source != (Image *) NULL)
7836 {
7837 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7838 (GetNextImageInList(source) == (Image *) NULL))
7839 source=(Image *) NULL;
7840 else
7841 {
7842 /*
7843 Separate the two lists, junk the null: image.
7844 */
7845 source=SplitImageList(source->previous);
7846 DeleteImageFromList(&source);
7847 }
7848 }
7849 if (source == (Image *) NULL)
7850 {
7851 (void) ThrowMagickException(exception,GetMagickModule(),
7852 OptionError,"MissingNullSeparator","layers Composite");
7853 status=MagickFalse;
7854 break;
7855 }
7856 /*
7857 Adjust offset with gravity and virtual canvas.
7858 */
7859 SetGeometry(*images,&geometry);
7860 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7861 geometry.width=source->page.width != 0 ?
7862 source->page.width : source->columns;
7863 geometry.height=source->page.height != 0 ?
7864 source->page.height : source->rows;
7865 GravityAdjustGeometry((*images)->page.width != 0 ?
7866 (*images)->page.width : (*images)->columns,
7867 (*images)->page.height != 0 ? (*images)->page.height :
7868 (*images)->rows,(*images)->gravity,&geometry);
7869 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007870 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007871 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007872 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007873 MagickComposeOptions,MagickFalse,option);
7874 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7875 exception);
7876 source=DestroyImageList(source);
7877 break;
7878 }
7879 }
7880 if (layers == (Image *) NULL)
7881 break;
cristy3ed852e2009-09-05 21:47:34 +00007882 *images=DestroyImageList(*images);
7883 *images=layers;
7884 break;
7885 }
7886 break;
7887 }
7888 case 'm':
7889 {
7890 if (LocaleCompare("map",option+1) == 0)
7891 {
cristy6fccee12011-10-20 18:43:18 +00007892 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007893 if (*option == '+')
7894 {
cristy018f07f2011-09-04 21:15:19 +00007895 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7896 exception);
cristy3ed852e2009-09-05 21:47:34 +00007897 break;
7898 }
7899 i++;
7900 break;
7901 }
cristyf40785b2010-03-06 02:27:27 +00007902 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007903 {
7904 Image
cristyf40785b2010-03-06 02:27:27 +00007905 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007906
cristyd18ae7c2010-03-07 17:39:52 +00007907 /*
7908 Maximum image sequence (deprecated).
7909 */
cristy6fccee12011-10-20 18:43:18 +00007910 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007911 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007912 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007913 {
7914 status=MagickFalse;
7915 break;
7916 }
7917 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007918 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007919 break;
7920 }
cristyf40785b2010-03-06 02:27:27 +00007921 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007922 {
7923 Image
cristyf40785b2010-03-06 02:27:27 +00007924 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007925
cristyd18ae7c2010-03-07 17:39:52 +00007926 /*
7927 Minimum image sequence (deprecated).
7928 */
cristy6fccee12011-10-20 18:43:18 +00007929 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007930 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007931 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007932 {
7933 status=MagickFalse;
7934 break;
7935 }
7936 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007937 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007938 break;
7939 }
cristy3ed852e2009-09-05 21:47:34 +00007940 if (LocaleCompare("morph",option+1) == 0)
7941 {
7942 Image
7943 *morph_image;
7944
cristy6fccee12011-10-20 18:43:18 +00007945 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007946 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007947 exception);
7948 if (morph_image == (Image *) NULL)
7949 {
7950 status=MagickFalse;
7951 break;
7952 }
7953 *images=DestroyImageList(*images);
7954 *images=morph_image;
7955 break;
7956 }
7957 if (LocaleCompare("mosaic",option+1) == 0)
7958 {
7959 Image
7960 *mosaic_image;
7961
cristy6fccee12011-10-20 18:43:18 +00007962 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007963 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7964 if (mosaic_image == (Image *) NULL)
7965 {
7966 status=MagickFalse;
7967 break;
7968 }
7969 *images=DestroyImageList(*images);
7970 *images=mosaic_image;
7971 break;
7972 }
7973 break;
7974 }
7975 case 'p':
7976 {
7977 if (LocaleCompare("print",option+1) == 0)
7978 {
7979 char
7980 *string;
7981
cristy6fccee12011-10-20 18:43:18 +00007982 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007983 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7984 exception);
cristy3ed852e2009-09-05 21:47:34 +00007985 if (string == (char *) NULL)
7986 break;
cristyb51dff52011-05-19 16:55:47 +00007987 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007988 string=DestroyString(string);
7989 }
7990 if (LocaleCompare("process",option+1) == 0)
7991 {
7992 char
7993 **arguments;
7994
7995 int
7996 j,
7997 number_arguments;
7998
cristy6fccee12011-10-20 18:43:18 +00007999 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008000 arguments=StringToArgv(argv[i+1],&number_arguments);
8001 if (arguments == (char **) NULL)
8002 break;
8003 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8004 {
8005 char
8006 breaker,
8007 quote,
8008 *token;
8009
8010 const char
8011 *arguments;
8012
8013 int
8014 next,
8015 status;
8016
8017 size_t
8018 length;
8019
8020 TokenInfo
8021 *token_info;
8022
8023 /*
8024 Support old style syntax, filter="-option arg".
8025 */
8026 length=strlen(argv[i+1]);
8027 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008028 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008029 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8030 sizeof(*token));
8031 if (token == (char *) NULL)
8032 break;
8033 next=0;
8034 arguments=argv[i+1];
8035 token_info=AcquireTokenInfo();
8036 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8037 "\"",'\0',&breaker,&next,&quote);
8038 token_info=DestroyTokenInfo(token_info);
8039 if (status == 0)
8040 {
8041 const char
8042 *argv;
8043
8044 argv=(&(arguments[next]));
8045 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8046 exception);
8047 }
8048 token=DestroyString(token);
8049 break;
8050 }
cristy91c0da22010-05-02 01:44:07 +00008051 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008052 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8053 number_arguments-2,(const char **) arguments+2,exception);
8054 for (j=0; j < number_arguments; j++)
8055 arguments[j]=DestroyString(arguments[j]);
8056 arguments=(char **) RelinquishMagickMemory(arguments);
8057 break;
8058 }
8059 break;
8060 }
8061 case 'r':
8062 {
8063 if (LocaleCompare("reverse",option+1) == 0)
8064 {
8065 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008066 break;
8067 }
8068 break;
8069 }
8070 case 's':
8071 {
cristy4285d782011-02-09 20:12:28 +00008072 if (LocaleCompare("smush",option+1) == 0)
8073 {
8074 Image
8075 *smush_image;
8076
8077 ssize_t
8078 offset;
8079
cristy6fccee12011-10-20 18:43:18 +00008080 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008081 offset=(ssize_t) StringToLong(argv[i+1]);
8082 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8083 MagickFalse,offset,exception);
8084 if (smush_image == (Image *) NULL)
8085 {
8086 status=MagickFalse;
8087 break;
8088 }
8089 *images=DestroyImageList(*images);
8090 *images=smush_image;
8091 break;
8092 }
cristy3ed852e2009-09-05 21:47:34 +00008093 if (LocaleCompare("swap",option+1) == 0)
8094 {
8095 Image
8096 *p,
8097 *q,
8098 *swap;
8099
cristybb503372010-05-27 20:51:26 +00008100 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008101 swap_index;
8102
8103 index=(-1);
8104 swap_index=(-2);
8105 if (*option != '+')
8106 {
8107 GeometryInfo
8108 geometry_info;
8109
8110 MagickStatusType
8111 flags;
8112
8113 swap_index=(-1);
8114 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008115 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008116 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008117 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008118 }
8119 p=GetImageFromList(*images,index);
8120 q=GetImageFromList(*images,swap_index);
8121 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8122 {
8123 (void) ThrowMagickException(exception,GetMagickModule(),
8124 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8125 status=MagickFalse;
8126 break;
8127 }
8128 if (p == q)
8129 break;
8130 swap=CloneImage(p,0,0,MagickTrue,exception);
8131 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8132 ReplaceImageInList(&q,swap);
8133 *images=GetFirstImageInList(q);
8134 break;
8135 }
8136 break;
8137 }
8138 case 'w':
8139 {
8140 if (LocaleCompare("write",option+1) == 0)
8141 {
cristy071dd7b2010-04-09 13:04:54 +00008142 char
cristy06609ee2010-03-17 20:21:27 +00008143 key[MaxTextExtent];
8144
cristy3ed852e2009-09-05 21:47:34 +00008145 Image
8146 *write_images;
8147
8148 ImageInfo
8149 *write_info;
8150
cristy6fccee12011-10-20 18:43:18 +00008151 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008152 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008153 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008154 write_images=(*images);
8155 if (*option == '+')
8156 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008157 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008158 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8159 write_info=DestroyImageInfo(write_info);
8160 if (*option == '+')
8161 write_images=DestroyImageList(write_images);
8162 break;
8163 }
8164 break;
8165 }
8166 default:
8167 break;
8168 }
8169 i+=count;
8170 }
8171 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008172 mogrify_info=DestroyImageInfo(mogrify_info);
8173 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008174 return(status != 0 ? MagickTrue : MagickFalse);
8175}
8176
8177/*
8178%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8179% %
8180% %
8181% %
8182+ M o g r i f y I m a g e s %
8183% %
8184% %
8185% %
8186%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8187%
8188% MogrifyImages() applies image processing options to a sequence of images as
8189% prescribed by command line options.
8190%
8191% The format of the MogrifyImage method is:
8192%
8193% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8194% const MagickBooleanType post,const int argc,const char **argv,
8195% Image **images,Exceptioninfo *exception)
8196%
8197% A description of each parameter follows:
8198%
8199% o image_info: the image info..
8200%
8201% o post: If true, post process image list operators otherwise pre-process.
8202%
8203% o argc: Specifies a pointer to an integer describing the number of
8204% elements in the argument vector.
8205%
8206% o argv: Specifies a pointer to a text array containing the command line
8207% arguments.
8208%
anthonye9c27192011-03-27 08:07:06 +00008209% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008210%
8211% o exception: return any errors or warnings in this structure.
8212%
8213*/
8214WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8215 const MagickBooleanType post,const int argc,const char **argv,
8216 Image **images,ExceptionInfo *exception)
8217{
8218#define MogrifyImageTag "Mogrify/Image"
8219
anthonye9c27192011-03-27 08:07:06 +00008220 MagickStatusType
8221 status;
cristy3ed852e2009-09-05 21:47:34 +00008222
cristy0e9f9c12010-02-11 03:00:47 +00008223 MagickBooleanType
8224 proceed;
8225
anthonye9c27192011-03-27 08:07:06 +00008226 size_t
8227 n;
cristy3ed852e2009-09-05 21:47:34 +00008228
cristybb503372010-05-27 20:51:26 +00008229 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008230 i;
8231
cristy3ed852e2009-09-05 21:47:34 +00008232 assert(image_info != (ImageInfo *) NULL);
8233 assert(image_info->signature == MagickSignature);
8234 if (images == (Image **) NULL)
8235 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008236 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008237 assert((*images)->signature == MagickSignature);
8238 if ((*images)->debug != MagickFalse)
8239 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8240 (*images)->filename);
8241 if ((argc <= 0) || (*argv == (char *) NULL))
8242 return(MagickTrue);
8243 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8244 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008245 status=0;
anthonye9c27192011-03-27 08:07:06 +00008246
anthonyce2716b2011-04-22 09:51:34 +00008247#if 0
cristy1e604812011-05-19 18:07:50 +00008248 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8249 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008250#endif
8251
anthonye9c27192011-03-27 08:07:06 +00008252 /*
8253 Pre-process multi-image sequence operators
8254 */
cristy3ed852e2009-09-05 21:47:34 +00008255 if (post == MagickFalse)
8256 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008257 /*
8258 For each image, process simple single image operators
8259 */
8260 i=0;
8261 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008262 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008263 {
anthonyce2716b2011-04-22 09:51:34 +00008264#if 0
cristy1e604812011-05-19 18:07:50 +00008265 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8266 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008267#endif
anthonye9c27192011-03-27 08:07:06 +00008268 status&=MogrifyImage(image_info,argc,argv,images,exception);
8269 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008270 if (proceed == MagickFalse)
8271 break;
anthonye9c27192011-03-27 08:07:06 +00008272 if ( (*images)->next == (Image *) NULL )
8273 break;
8274 *images=(*images)->next;
8275 i++;
cristy3ed852e2009-09-05 21:47:34 +00008276 }
anthonye9c27192011-03-27 08:07:06 +00008277 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008278#if 0
cristy1e604812011-05-19 18:07:50 +00008279 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8280 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008281#endif
anthonye9c27192011-03-27 08:07:06 +00008282
8283 /*
8284 Post-process, multi-image sequence operators
8285 */
8286 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008287 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008288 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008289 return(status != 0 ? MagickTrue : MagickFalse);
8290}