]> granicus.if.org Git - imagemagick/blob - MagickWand/mogrify.c
0b65e0801783b30383cc73180cce9600751a77a9
[imagemagick] / MagickWand / mogrify.c
1 /*
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 %                                                                             %
20 %  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
21 %  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
40 %  request.
41 %
42 */
43 \f
44 /*
45   Include declarations.
46 */
47 #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"
54 #include "MagickCore/thread-private.h"
55 #include "MagickCore/string-private.h"
56 #include "MagickCore/utility-private.h"
57 \f
58 /*
59  Constant declaration.
60 */
61 static const char
62   MogrifyBackgroundColor[] = "#ffffff",  /* white */
63   MogrifyBorderColor[] = "#dfdfdf",  /* gray */
64   MogrifyMatteColor[] = "#bdbdbd";  /* gray */
65 \f
66 /*
67   Define declarations.
68 */
69 #define UndefinedCompressionQuality  0UL
70 \f
71 /*
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %                                                                             %
74 %                                                                             %
75 %                                                                             %
76 %     M a g i c k C o m m a n d G e n e s i s                                 %
77 %                                                                             %
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,
88 %        MagickCommand command,int argc,char **argv,char **metadata,
89 %        ExceptionInfo *exception)
90 %
91 %  A description of each parameter follows:
92 %
93 %    o image_info: the image info.
94 %
95 %    o command: Choose from ConvertImageCommand, IdentifyImageCommand,
96 %      MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
97 %      ConjureImageCommand, StreamImageCommand, ImportImageCommand,
98 %      DisplayImageCommand, or AnimateImageCommand.
99 %
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 %
106 %    o metadata: any metadata is returned here.
107 %
108 %    o exception: return any errors or warnings in this structure.
109 %
110 */
111 WandExport 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
123   MagickBooleanType
124     concurrent,
125     regard_warnings,
126     status;
127
128   register ssize_t
129     i;
130
131   TimerInfo
132     *timer;
133
134   size_t
135     iterations;
136
137   (void) setlocale(LC_ALL,"");
138   (void) setlocale(LC_NUMERIC,"C");
139   concurrent=MagickFalse;
140   duration=(-1.0);
141   iterations=1;
142   status=MagickFalse;
143   regard_warnings=MagickFalse;
144   for (i=1; i < (ssize_t) (argc-1); i++)
145   {
146     option=argv[i];
147     if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
148       continue;
149     if (LocaleCompare("bench",option+1) == 0)
150       iterations=StringToUnsignedLong(argv[++i]);
151     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)
156       duration=InterpretLocaleValue(argv[++i],(char **) NULL);
157     if (LocaleCompare("regard-warnings",option+1) == 0)
158       regard_warnings=MagickTrue;
159   }
160   timer=AcquireTimerInfo();
161   if (concurrent == MagickFalse)
162     {
163       for (i=0; i < (ssize_t) iterations; i++)
164       {
165         if (status != MagickFalse)
166           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);
174         if (exception->severity != UndefinedException)
175           {
176             if ((exception->severity > ErrorException) ||
177                 (regard_warnings != MagickFalse))
178               status=MagickTrue;
179             CatchException(exception);
180           }
181         if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
182           {
183             (void) fputs(*metadata,stdout);
184             (void) fputc('\n',stdout);
185             *metadata=DestroyString(*metadata);
186           }
187       }
188     }
189   else
190     {
191       SetOpenMPNested(1);
192 #if defined(MAGICKCORE_OPENMP_SUPPORT)
193   # pragma omp parallel for shared(status)
194 #endif
195       for (i=0; i < (ssize_t) iterations; i++)
196       {
197         if (status != MagickFalse)
198           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);
206 #if defined(MAGICKCORE_OPENMP_SUPPORT)
207   # pragma omp critical (MagickCore_CommandGenesis)
208 #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     }
226   if (iterations > 1)
227     {
228       elapsed_time=GetElapsedTime(timer);
229       user_time=GetUserTime(timer);
230       (void) FormatLocaleFile(stderr,
231         "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
232         iterations,1.0*iterations/elapsed_time,user_time,(double)
233         (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
234         (1000.0*(elapsed_time-floor(elapsed_time))));
235       (void) fflush(stderr);
236     }
237   timer=DestroyTimerInfo(timer);
238   return(status);
239 }
240 \f
241 /*
242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 %                                                                             %
244 %                                                                             %
245 %                                                                             %
246 +     M o g r i f y I m a g e                                                 %
247 %                                                                             %
248 %                                                                             %
249 %                                                                             %
250 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 %
252 %  MogrifyImage() applies simple single image processing options to a single
253 %  image that may be part of a large list, but also handles any 'region'
254 %  image handling.
255 %
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 %
278 %
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
300 /*
301 ** GetImageCache() will read an image into a image cache if not already
302 ** present then return the image that is in the cache under that filename.
303 */
304 static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
305   ExceptionInfo *exception)
306 {
307   char
308     key[MaxTextExtent];
309
310   ExceptionInfo
311     *sans_exception;
312
313   Image
314     *image;
315
316   ImageInfo
317     *read_info;
318
319   (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
320   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
334 static MagickBooleanType IsPathWritable(const char *path)
335 {
336   if (IsPathAccessible(path) == MagickFalse)
337     return(MagickFalse);
338   if (access_utf8(path,W_OK) != 0)
339     return(MagickFalse);
340   return(MagickTrue);
341 }
342
343 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
344 {
345   if (x > y)
346     return(x);
347   return(y);
348 }
349
350 static 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';
370   (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
371   locale_message=GetLocaleMessage(message);
372   if (locale_message == message)
373     locale_message=tag;
374   if (p == (char *) NULL)
375     (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
376       locale_message,(long) offset,(unsigned long) extent,(long)
377       (100L*offset/(extent-1)));
378   else
379     (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
380       locale_message,p+1,(long) offset,(unsigned long) extent,(long)
381       (100L*offset/(extent-1)));
382   if (offset == (MagickOffsetType) (extent-1))
383     (void) FormatLocaleFile(stderr,"\n");
384   (void) fflush(stderr);
385   return(MagickTrue);
386 }
387
388 static Image *SparseColorOption(const Image *image,
389   const SparseColorMethod method,const char *arguments,
390   const MagickBooleanType color_from_image,ExceptionInfo *exception)
391 {
392   char
393     token[MaxTextExtent];
394
395   const char
396     *p;
397
398   double
399     *sparse_arguments;
400
401   Image
402     *sparse_image;
403
404   PixelInfo
405     color;
406
407   MagickBooleanType
408     error;
409
410   register size_t
411     x;
412
413   size_t
414     number_arguments,
415     number_colors;
416
417   /*
418     SparseColorOption() parses the complex -sparse-color argument into an
419     an array of floating point values then calls SparseColorImage().
420     Argument is a complex mix of floating-point pixel coodinates, and color
421     specifications (or direct floating point numbers).  The number of floats
422     needed to represent a color varies depending on the current channel
423     setting.
424   */
425   assert(image != (Image *) NULL);
426   assert(image->signature == MagickSignature);
427   if (image->debug != MagickFalse)
428     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
429   assert(exception != (ExceptionInfo *) NULL);
430   assert(exception->signature == MagickSignature);
431   /*
432     Limit channels according to image - and add up number of color channel.
433   */
434   number_colors=0;
435   if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
436     number_colors++;
437   if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
438     number_colors++;
439   if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
440     number_colors++;
441   if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
442       (image->colorspace == CMYKColorspace))
443     number_colors++;
444   if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
445       (image->matte != MagickFalse))
446     number_colors++;
447
448   /*
449     Read string, to determine number of arguments needed,
450   */
451   p=arguments;
452   x=0;
453   while( *p != '\0' )
454   {
455     GetMagickToken(p,&p,token);
456     if ( token[0] == ',' ) continue;
457     if ( isalpha((int) token[0]) || token[0] == '#' ) {
458       if ( color_from_image ) {
459         (void) ThrowMagickException(exception,GetMagickModule(),
460             OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
461             "Color arg given, when colors are coming from image");
462         return( (Image *)NULL);
463       }
464       x += number_colors;  /* color argument */
465     }
466     else {
467       x++;   /* floating point argument */
468     }
469   }
470   error=MagickTrue;
471   if ( color_from_image ) {
472     /* just the control points are being given */
473     error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
474     number_arguments=(x/2)*(2+number_colors);
475   }
476   else {
477     /* control points and color values */
478     error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
479     number_arguments=x;
480   }
481   if ( error ) {
482     (void) ThrowMagickException(exception,GetMagickModule(),
483                OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
484                "Invalid number of Arguments");
485     return( (Image *)NULL);
486   }
487
488   /* Allocate and fill in the floating point arguments */
489   sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
490     sizeof(*sparse_arguments));
491   if (sparse_arguments == (double *) NULL) {
492     (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
493       "MemoryAllocationFailed","%s","SparseColorOption");
494     return( (Image *)NULL);
495   }
496   (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
497     sizeof(*sparse_arguments));
498   p=arguments;
499   x=0;
500   while( *p != '\0' && x < number_arguments ) {
501     /* X coordinate */
502     token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
503     if ( token[0] == '\0' ) break;
504     if ( isalpha((int) token[0]) || token[0] == '#' ) {
505       (void) ThrowMagickException(exception,GetMagickModule(),
506             OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
507             "Color found, instead of X-coord");
508       error = MagickTrue;
509       break;
510     }
511     sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
512     /* Y coordinate */
513     token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
514     if ( token[0] == '\0' ) break;
515     if ( isalpha((int) token[0]) || token[0] == '#' ) {
516       (void) ThrowMagickException(exception,GetMagickModule(),
517             OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
518             "Color found, instead of Y-coord");
519       error = MagickTrue;
520       break;
521     }
522     sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
523     /* color values for this control point */
524 #if 0
525     if ( (color_from_image ) {
526       /* get color from image */
527       /* HOW??? */
528     }
529     else
530 #endif
531     {
532       /* color name or function given in string argument */
533       token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
534       if ( token[0] == '\0' ) break;
535       if ( isalpha((int) token[0]) || token[0] == '#' ) {
536         /* Color string given */
537         (void) QueryMagickColor(token,&color,exception);
538         if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
539           sparse_arguments[x++] = QuantumScale*color.red;
540         if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
541           sparse_arguments[x++] = QuantumScale*color.green;
542         if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
543           sparse_arguments[x++] = QuantumScale*color.blue;
544         if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
545             (image->colorspace == CMYKColorspace))
546           sparse_arguments[x++] = QuantumScale*color.black;
547         if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
548             (image->matte != MagickFalse))
549           sparse_arguments[x++] = QuantumScale*color.alpha;
550       }
551       else {
552         /* Colors given as a set of floating point values - experimental */
553         /* NB: token contains the first floating point value to use! */
554         if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
555           {
556           while ( token[0] == ',' ) GetMagickToken(p,&p,token);
557           if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
558             break;
559           sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
560           token[0] = ','; /* used this token - get another */
561         }
562         if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
563           {
564           while ( token[0] == ',' ) GetMagickToken(p,&p,token);
565           if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
566             break;
567           sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
568           token[0] = ','; /* used this token - get another */
569         }
570         if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
571           {
572           while ( token[0] == ',' ) GetMagickToken(p,&p,token);
573           if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
574             break;
575           sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
576           token[0] = ','; /* used this token - get another */
577         }
578         if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
579             (image->colorspace == CMYKColorspace))
580           {
581           while ( token[0] == ',' ) GetMagickToken(p,&p,token);
582           if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
583             break;
584           sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
585           token[0] = ','; /* used this token - get another */
586         }
587         if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
588             (image->matte != MagickFalse))
589           {
590           while ( token[0] == ',' ) GetMagickToken(p,&p,token);
591           if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
592             break;
593           sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
594           token[0] = ','; /* used this token - get another */
595         }
596       }
597     }
598   }
599   if ( number_arguments != x && !error ) {
600     (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
601       "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
602     sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
603     return( (Image *)NULL);
604   }
605   if ( error )
606     return( (Image *)NULL);
607
608   /* Call the Interpolation function with the parsed arguments */
609   sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
610     exception);
611   sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
612   return( sparse_image );
613 }
614
615 WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
616   const char **argv,Image **image,ExceptionInfo *exception)
617 {
618   ChannelType
619     channel;
620
621   CompositeOperator
622     compose;
623
624   const char
625     *format,
626     *option;
627
628   DrawInfo
629     *draw_info;
630
631   GeometryInfo
632     geometry_info;
633
634   Image
635     *region_image;
636
637   ImageInfo
638     *mogrify_info;
639
640   MagickStatusType
641     status;
642
643   PixelInfo
644     fill;
645
646   MagickStatusType
647     flags;
648
649   PixelInterpolateMethod
650     interpolate_method;
651
652   QuantizeInfo
653     *quantize_info;
654
655   RectangleInfo
656     geometry,
657     region_geometry;
658
659   register ssize_t
660     i;
661
662   /*
663     Initialize method variables.
664   */
665   assert(image_info != (const ImageInfo *) NULL);
666   assert(image_info->signature == MagickSignature);
667   assert(image != (Image **) NULL);
668   assert((*image)->signature == MagickSignature);
669   if ((*image)->debug != MagickFalse)
670     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
671   if (argc < 0)
672     return(MagickTrue);
673   mogrify_info=CloneImageInfo(image_info);
674   draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
675   quantize_info=AcquireQuantizeInfo(mogrify_info);
676   SetGeometryInfo(&geometry_info);
677   GetPixelInfo(*image,&fill);
678   SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
679   compose=(*image)->compose;
680   interpolate_method=UndefinedInterpolatePixel;
681   channel=mogrify_info->channel;
682   format=GetImageOption(mogrify_info,"format");
683   SetGeometry(*image,&region_geometry);
684   region_image=NewImageList();
685   /*
686     Transmogrify the image.
687   */
688   for (i=0; i < (ssize_t) argc; i++)
689   {
690     Image
691       *mogrify_image;
692
693     ssize_t
694       count;
695
696     option=argv[i];
697     if (IsCommandOption(option) == MagickFalse)
698       continue;
699     count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
700       0L);
701     if ((i+count) >= (ssize_t) argc)
702       break;
703     status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
704     mogrify_image=(Image *)NULL;
705     switch (*(option+1))
706     {
707       case 'a':
708       {
709         if (LocaleCompare("adaptive-blur",option+1) == 0)
710           {
711             /*
712               Adaptive blur image.
713             */
714             (void) SyncImageSettings(mogrify_info,*image);
715             flags=ParseGeometry(argv[i+1],&geometry_info);
716             if ((flags & SigmaValue) == 0)
717               geometry_info.sigma=1.0;
718             if ((flags & XiValue) == 0)
719               geometry_info.xi=0.0;
720             mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
721               geometry_info.sigma,geometry_info.xi,exception);
722             break;
723           }
724         if (LocaleCompare("adaptive-resize",option+1) == 0)
725           {
726             /*
727               Adaptive resize image.
728             */
729             (void) SyncImageSettings(mogrify_info,*image);
730             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
731             mogrify_image=AdaptiveResizeImage(*image,geometry.width,
732               geometry.height,interpolate_method,exception);
733             break;
734           }
735         if (LocaleCompare("adaptive-sharpen",option+1) == 0)
736           {
737             /*
738               Adaptive sharpen image.
739             */
740             (void) SyncImageSettings(mogrify_info,*image);
741             flags=ParseGeometry(argv[i+1],&geometry_info);
742             if ((flags & SigmaValue) == 0)
743               geometry_info.sigma=1.0;
744             if ((flags & XiValue) == 0)
745               geometry_info.xi=0.0;
746             mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
747               geometry_info.sigma,geometry_info.xi,exception);
748             break;
749           }
750         if (LocaleCompare("affine",option+1) == 0)
751           {
752             /*
753               Affine matrix.
754             */
755             if (*option == '+')
756               {
757                 GetAffineMatrix(&draw_info->affine);
758                 break;
759               }
760             (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
761             break;
762           }
763         if (LocaleCompare("alpha",option+1) == 0)
764           {
765             AlphaChannelType
766               alpha_type;
767
768             (void) SyncImageSettings(mogrify_info,*image);
769             alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
770               MagickFalse,argv[i+1]);
771             (void) SetImageAlphaChannel(*image,alpha_type,exception);
772             break;
773           }
774         if (LocaleCompare("annotate",option+1) == 0)
775           {
776             char
777               *text,
778               geometry[MaxTextExtent];
779
780             /*
781               Annotate image.
782             */
783             (void) SyncImageSettings(mogrify_info,*image);
784             SetGeometryInfo(&geometry_info);
785             flags=ParseGeometry(argv[i+1],&geometry_info);
786             if ((flags & SigmaValue) == 0)
787               geometry_info.sigma=geometry_info.rho;
788             text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
789               exception);
790             if (text == (char *) NULL)
791               break;
792             (void) CloneString(&draw_info->text,text);
793             text=DestroyString(text);
794             (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
795               geometry_info.xi,geometry_info.psi);
796             (void) CloneString(&draw_info->geometry,geometry);
797             draw_info->affine.sx=cos(DegreesToRadians(
798               fmod(geometry_info.rho,360.0)));
799             draw_info->affine.rx=sin(DegreesToRadians(
800               fmod(geometry_info.rho,360.0)));
801             draw_info->affine.ry=(-sin(DegreesToRadians(
802               fmod(geometry_info.sigma,360.0))));
803             draw_info->affine.sy=cos(DegreesToRadians(
804               fmod(geometry_info.sigma,360.0)));
805             (void) AnnotateImage(*image,draw_info,exception);
806             break;
807           }
808         if (LocaleCompare("antialias",option+1) == 0)
809           {
810             draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
811               MagickFalse;
812             draw_info->text_antialias=(*option == '-') ? MagickTrue :
813               MagickFalse;
814             break;
815           }
816         if (LocaleCompare("auto-gamma",option+1) == 0)
817           {
818             /*
819               Auto Adjust Gamma of image based on its mean
820             */
821             (void) SyncImageSettings(mogrify_info,*image);
822             (void) AutoGammaImage(*image,exception);
823             break;
824           }
825         if (LocaleCompare("auto-level",option+1) == 0)
826           {
827             /*
828               Perfectly Normalize (max/min stretch) the image
829             */
830             (void) SyncImageSettings(mogrify_info,*image);
831             (void) AutoLevelImage(*image,exception);
832             break;
833           }
834         if (LocaleCompare("auto-orient",option+1) == 0)
835           {
836             (void) SyncImageSettings(mogrify_info,*image);
837             switch ((*image)->orientation)
838             {
839               case TopRightOrientation:
840               {
841                 mogrify_image=FlopImage(*image,exception);
842                 break;
843               }
844               case BottomRightOrientation:
845               {
846                 mogrify_image=RotateImage(*image,180.0,exception);
847                 break;
848               }
849               case BottomLeftOrientation:
850               {
851                 mogrify_image=FlipImage(*image,exception);
852                 break;
853               }
854               case LeftTopOrientation:
855               {
856                 mogrify_image=TransposeImage(*image,exception);
857                 break;
858               }
859               case RightTopOrientation:
860               {
861                 mogrify_image=RotateImage(*image,90.0,exception);
862                 break;
863               }
864               case RightBottomOrientation:
865               {
866                 mogrify_image=TransverseImage(*image,exception);
867                 break;
868               }
869               case LeftBottomOrientation:
870               {
871                 mogrify_image=RotateImage(*image,270.0,exception);
872                 break;
873               }
874               default:
875                 break;
876             }
877             if (mogrify_image != (Image *) NULL)
878               mogrify_image->orientation=TopLeftOrientation;
879             break;
880           }
881         break;
882       }
883       case 'b':
884       {
885         if (LocaleCompare("black-threshold",option+1) == 0)
886           {
887             /*
888               Black threshold image.
889             */
890             (void) SyncImageSettings(mogrify_info,*image);
891             (void) BlackThresholdImage(*image,argv[i+1],exception);
892             InheritException(exception,&(*image)->exception);
893             break;
894           }
895         if (LocaleCompare("blue-shift",option+1) == 0)
896           {
897             /*
898               Blue shift image.
899             */
900             (void) SyncImageSettings(mogrify_info,*image);
901             geometry_info.rho=1.5;
902             if (*option == '-')
903               flags=ParseGeometry(argv[i+1],&geometry_info);
904             mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
905             break;
906           }
907         if (LocaleCompare("blur",option+1) == 0)
908           {
909             /*
910               Gaussian blur image.
911             */
912             (void) SyncImageSettings(mogrify_info,*image);
913             flags=ParseGeometry(argv[i+1],&geometry_info);
914             if ((flags & SigmaValue) == 0)
915               geometry_info.sigma=1.0;
916             if ((flags & XiValue) == 0)
917               geometry_info.xi=0.0;
918             mogrify_image=BlurImage(*image,geometry_info.rho,
919               geometry_info.sigma,geometry_info.xi,exception);
920             break;
921           }
922         if (LocaleCompare("border",option+1) == 0)
923           {
924             /*
925               Surround image with a border of solid color.
926             */
927             (void) SyncImageSettings(mogrify_info,*image);
928             flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
929             if ((flags & SigmaValue) == 0)
930               geometry.height=geometry.width;
931             mogrify_image=BorderImage(*image,&geometry,compose,exception);
932             break;
933           }
934         if (LocaleCompare("bordercolor",option+1) == 0)
935           {
936             if (*option == '+')
937               {
938                 (void) QueryColorDatabase(MogrifyBorderColor,
939                   &draw_info->border_color,exception);
940                 break;
941               }
942             (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
943               exception);
944             break;
945           }
946         if (LocaleCompare("box",option+1) == 0)
947           {
948             (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
949               exception);
950             break;
951           }
952         if (LocaleCompare("brightness-contrast",option+1) == 0)
953           {
954             double
955               brightness,
956               contrast;
957
958             GeometryInfo
959               geometry_info;
960
961             MagickStatusType
962               flags;
963
964             /*
965               Brightness / contrast image.
966             */
967             (void) SyncImageSettings(mogrify_info,*image);
968             flags=ParseGeometry(argv[i+1],&geometry_info);
969             brightness=geometry_info.rho;
970             contrast=0.0;
971             if ((flags & SigmaValue) != 0)
972               contrast=geometry_info.sigma;
973             (void) BrightnessContrastImage(*image,brightness,contrast,
974               exception);
975             InheritException(exception,&(*image)->exception);
976             break;
977           }
978         break;
979       }
980       case 'c':
981       {
982         if (LocaleCompare("cdl",option+1) == 0)
983           {
984             char
985               *color_correction_collection;
986
987             /*
988               Color correct with a color decision list.
989             */
990             (void) SyncImageSettings(mogrify_info,*image);
991             color_correction_collection=FileToString(argv[i+1],~0,exception);
992             if (color_correction_collection == (char *) NULL)
993               break;
994             (void) ColorDecisionListImage(*image,color_correction_collection,
995               exception);
996             InheritException(exception,&(*image)->exception);
997             break;
998           }
999         if (LocaleCompare("channel",option+1) == 0)
1000           {
1001             if (*option == '+')
1002               channel=DefaultChannels;
1003             else
1004               channel=(ChannelType) ParseChannelOption(argv[i+1]);
1005             SetPixelChannelMap(*image,channel);
1006             break;
1007           }
1008         if (LocaleCompare("charcoal",option+1) == 0)
1009           {
1010             /*
1011               Charcoal image.
1012             */
1013             (void) SyncImageSettings(mogrify_info,*image);
1014             flags=ParseGeometry(argv[i+1],&geometry_info);
1015             if ((flags & SigmaValue) == 0)
1016               geometry_info.sigma=1.0;
1017             if ((flags & XiValue) == 0)
1018               geometry_info.xi=1.0;
1019             mogrify_image=CharcoalImage(*image,geometry_info.rho,
1020               geometry_info.sigma,geometry_info.xi,exception);
1021             break;
1022           }
1023         if (LocaleCompare("chop",option+1) == 0)
1024           {
1025             /*
1026               Chop the image.
1027             */
1028             (void) SyncImageSettings(mogrify_info,*image);
1029             (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1030             mogrify_image=ChopImage(*image,&geometry,exception);
1031             break;
1032           }
1033         if (LocaleCompare("clamp",option+1) == 0)
1034           {
1035             /*
1036               Clamp image.
1037             */
1038             (void) SyncImageSettings(mogrify_info,*image);
1039             (void) ClampImage(*image);
1040             InheritException(exception,&(*image)->exception);
1041             break;
1042           }
1043         if (LocaleCompare("clip",option+1) == 0)
1044           {
1045             (void) SyncImageSettings(mogrify_info,*image);
1046             if (*option == '+')
1047               {
1048                 (void) SetImageClipMask(*image,(Image *) NULL,exception);
1049                 break;
1050               }
1051             (void) ClipImage(*image,exception);
1052             break;
1053           }
1054         if (LocaleCompare("clip-mask",option+1) == 0)
1055           {
1056             CacheView
1057               *mask_view;
1058
1059             Image
1060               *mask_image;
1061
1062             register Quantum
1063               *restrict q;
1064
1065             register ssize_t
1066               x;
1067
1068             ssize_t
1069               y;
1070
1071             (void) SyncImageSettings(mogrify_info,*image);
1072             if (*option == '+')
1073               {
1074                 /*
1075                   Remove a mask.
1076                 */
1077                 (void) SetImageMask(*image,(Image *) NULL,exception);
1078                 break;
1079               }
1080             /*
1081               Set the image mask.
1082               FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1083             */
1084             mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1085             if (mask_image == (Image *) NULL)
1086               break;
1087             if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
1088               return(MagickFalse);
1089             mask_view=AcquireCacheView(mask_image);
1090             for (y=0; y < (ssize_t) mask_image->rows; y++)
1091             {
1092               q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1093                 exception);
1094               if (q == (Quantum *) NULL)
1095                 break;
1096               for (x=0; x < (ssize_t) mask_image->columns; x++)
1097               {
1098                 if (mask_image->matte == MagickFalse)
1099                   SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1100                 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1101                 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1102                 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
1103                 q+=GetPixelChannels(mask_image);
1104               }
1105               if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1106                 break;
1107             }
1108             mask_view=DestroyCacheView(mask_view);
1109             mask_image->matte=MagickTrue;
1110             (void) SetImageClipMask(*image,mask_image,exception);
1111             InheritException(exception,&(*image)->exception);
1112             break;
1113           }
1114         if (LocaleCompare("clip-path",option+1) == 0)
1115           {
1116             (void) SyncImageSettings(mogrify_info,*image);
1117             (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1118               MagickFalse,exception);
1119             break;
1120           }
1121         if (LocaleCompare("colorize",option+1) == 0)
1122           {
1123             /*
1124               Colorize the image.
1125             */
1126             (void) SyncImageSettings(mogrify_info,*image);
1127             mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1128               exception);
1129             break;
1130           }
1131         if (LocaleCompare("color-matrix",option+1) == 0)
1132           {
1133             KernelInfo
1134               *kernel;
1135
1136             (void) SyncImageSettings(mogrify_info,*image);
1137             kernel=AcquireKernelInfo(argv[i+1]);
1138             if (kernel == (KernelInfo *) NULL)
1139               break;
1140             mogrify_image=ColorMatrixImage(*image,kernel,exception);
1141             kernel=DestroyKernelInfo(kernel);
1142             break;
1143           }
1144         if (LocaleCompare("colors",option+1) == 0)
1145           {
1146             /*
1147               Reduce the number of colors in the image.
1148             */
1149             (void) SyncImageSettings(mogrify_info,*image);
1150             quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1151             if (quantize_info->number_colors == 0)
1152               break;
1153             if (((*image)->storage_class == DirectClass) ||
1154                 (*image)->colors > quantize_info->number_colors)
1155               (void) QuantizeImage(quantize_info,*image,exception);
1156             else
1157               (void) CompressImageColormap(*image,exception);
1158             break;
1159           }
1160         if (LocaleCompare("colorspace",option+1) == 0)
1161           {
1162             ColorspaceType
1163               colorspace;
1164
1165             (void) SyncImageSettings(mogrify_info,*image);
1166             if (*option == '+')
1167               {
1168                 (void) TransformImageColorspace(*image,RGBColorspace);
1169                 InheritException(exception,&(*image)->exception);
1170                 break;
1171               }
1172             colorspace=(ColorspaceType) ParseCommandOption(
1173               MagickColorspaceOptions,MagickFalse,argv[i+1]);
1174             (void) TransformImageColorspace(*image,colorspace);
1175             InheritException(exception,&(*image)->exception);
1176             break;
1177           }
1178         if (LocaleCompare("compose",option+1) == 0)
1179           {
1180             (void) SyncImageSettings(mogrify_info,*image);
1181             compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1182               MagickFalse,argv[i+1]);
1183             break;
1184           }
1185         if (LocaleCompare("contrast",option+1) == 0)
1186           {
1187             (void) SyncImageSettings(mogrify_info,*image);
1188             (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1189               MagickFalse,exception);
1190             break;
1191           }
1192         if (LocaleCompare("contrast-stretch",option+1) == 0)
1193           {
1194             double
1195               black_point,
1196               white_point;
1197
1198             MagickStatusType
1199               flags;
1200
1201             /*
1202               Contrast stretch image.
1203             */
1204             (void) SyncImageSettings(mogrify_info,*image);
1205             flags=ParseGeometry(argv[i+1],&geometry_info);
1206             black_point=geometry_info.rho;
1207             white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1208               black_point;
1209             if ((flags & PercentValue) != 0)
1210               {
1211                 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1212                 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1213               }
1214             white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1215               white_point;
1216             (void) ContrastStretchImage(*image,black_point,white_point,
1217               exception);
1218             InheritException(exception,&(*image)->exception);
1219             break;
1220           }
1221         if (LocaleCompare("convolve",option+1) == 0)
1222           {
1223             KernelInfo
1224               *kernel_info;
1225
1226             (void) SyncImageSettings(mogrify_info,*image);
1227             kernel_info=AcquireKernelInfo(argv[i+1]);
1228             if (kernel_info == (KernelInfo *) NULL)
1229               break;
1230             kernel_info->bias=(*image)->bias;
1231             mogrify_image=ConvolveImage(*image,kernel_info,exception);
1232             kernel_info=DestroyKernelInfo(kernel_info);
1233             break;
1234           }
1235         if (LocaleCompare("crop",option+1) == 0)
1236           {
1237             /*
1238               Crop a image to a smaller size
1239             */
1240             (void) SyncImageSettings(mogrify_info,*image);
1241             mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1242             break;
1243           }
1244         if (LocaleCompare("cycle",option+1) == 0)
1245           {
1246             /*
1247               Cycle an image colormap.
1248             */
1249             (void) SyncImageSettings(mogrify_info,*image);
1250             (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1251               exception);
1252             break;
1253           }
1254         break;
1255       }
1256       case 'd':
1257       {
1258         if (LocaleCompare("decipher",option+1) == 0)
1259           {
1260             StringInfo
1261               *passkey;
1262
1263             /*
1264               Decipher pixels.
1265             */
1266             (void) SyncImageSettings(mogrify_info,*image);
1267             passkey=FileToStringInfo(argv[i+1],~0,exception);
1268             if (passkey != (StringInfo *) NULL)
1269               {
1270                 (void) PasskeyDecipherImage(*image,passkey,exception);
1271                 passkey=DestroyStringInfo(passkey);
1272               }
1273             break;
1274           }
1275         if (LocaleCompare("density",option+1) == 0)
1276           {
1277             /*
1278               Set image density.
1279             */
1280             (void) CloneString(&draw_info->density,argv[i+1]);
1281             break;
1282           }
1283         if (LocaleCompare("depth",option+1) == 0)
1284           {
1285             (void) SyncImageSettings(mogrify_info,*image);
1286             if (*option == '+')
1287               {
1288                 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1289                 break;
1290               }
1291             (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1292             break;
1293           }
1294         if (LocaleCompare("deskew",option+1) == 0)
1295           {
1296             double
1297               threshold;
1298
1299             /*
1300               Straighten the image.
1301             */
1302             (void) SyncImageSettings(mogrify_info,*image);
1303             if (*option == '+')
1304               threshold=40.0*QuantumRange/100.0;
1305             else
1306               threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1307             mogrify_image=DeskewImage(*image,threshold,exception);
1308             break;
1309           }
1310         if (LocaleCompare("despeckle",option+1) == 0)
1311           {
1312             /*
1313               Reduce the speckles within an image.
1314             */
1315             (void) SyncImageSettings(mogrify_info,*image);
1316             mogrify_image=DespeckleImage(*image,exception);
1317             break;
1318           }
1319         if (LocaleCompare("display",option+1) == 0)
1320           {
1321             (void) CloneString(&draw_info->server_name,argv[i+1]);
1322             break;
1323           }
1324         if (LocaleCompare("distort",option+1) == 0)
1325           {
1326             char
1327               *args,
1328               token[MaxTextExtent];
1329
1330             const char
1331               *p;
1332
1333             DistortImageMethod
1334               method;
1335
1336             double
1337               *arguments;
1338
1339             register ssize_t
1340               x;
1341
1342             size_t
1343               number_arguments;
1344
1345             /*
1346               Distort image.
1347             */
1348             (void) SyncImageSettings(mogrify_info,*image);
1349             method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1350               MagickFalse,argv[i+1]);
1351             if ( method == ResizeDistortion )
1352               {
1353                  /* Special Case - Argument is actually a resize geometry!
1354                  ** Convert that to an appropriate distortion argument array.
1355                  */
1356                  double
1357                    resize_args[2];
1358                  (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1359                       exception);
1360                  resize_args[0]=(double)geometry.width;
1361                  resize_args[1]=(double)geometry.height;
1362                  mogrify_image=DistortImage(*image,method,(size_t)2,
1363                       resize_args,MagickTrue,exception);
1364                  break;
1365               }
1366             args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1367               exception);
1368             if (args == (char *) NULL)
1369               break;
1370             p=(char *) args;
1371             for (x=0; *p != '\0'; x++)
1372             {
1373               GetMagickToken(p,&p,token);
1374               if (*token == ',')
1375                 GetMagickToken(p,&p,token);
1376             }
1377             number_arguments=(size_t) x;
1378             arguments=(double *) AcquireQuantumMemory(number_arguments,
1379               sizeof(*arguments));
1380             if (arguments == (double *) NULL)
1381               ThrowWandFatalException(ResourceLimitFatalError,
1382                 "MemoryAllocationFailed",(*image)->filename);
1383             (void) ResetMagickMemory(arguments,0,number_arguments*
1384               sizeof(*arguments));
1385             p=(char *) args;
1386             for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1387             {
1388               GetMagickToken(p,&p,token);
1389               if (*token == ',')
1390                 GetMagickToken(p,&p,token);
1391               arguments[x]=InterpretLocaleValue(token,(char **) NULL);
1392             }
1393             args=DestroyString(args);
1394             mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1395               (*option == '+') ? MagickTrue : MagickFalse,exception);
1396             arguments=(double *) RelinquishMagickMemory(arguments);
1397             break;
1398           }
1399         if (LocaleCompare("dither",option+1) == 0)
1400           {
1401             if (*option == '+')
1402               {
1403                 quantize_info->dither=MagickFalse;
1404                 break;
1405               }
1406             quantize_info->dither=MagickTrue;
1407             quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1408               MagickDitherOptions,MagickFalse,argv[i+1]);
1409             if (quantize_info->dither_method == NoDitherMethod)
1410               quantize_info->dither=MagickFalse;
1411             break;
1412           }
1413         if (LocaleCompare("draw",option+1) == 0)
1414           {
1415             /*
1416               Draw image.
1417             */
1418             (void) SyncImageSettings(mogrify_info,*image);
1419             (void) CloneString(&draw_info->primitive,argv[i+1]);
1420             (void) DrawImage(*image,draw_info,exception);
1421             break;
1422           }
1423         break;
1424       }
1425       case 'e':
1426       {
1427         if (LocaleCompare("edge",option+1) == 0)
1428           {
1429             /*
1430               Enhance edges in the image.
1431             */
1432             (void) SyncImageSettings(mogrify_info,*image);
1433             flags=ParseGeometry(argv[i+1],&geometry_info);
1434             if ((flags & SigmaValue) == 0)
1435               geometry_info.sigma=1.0;
1436             mogrify_image=EdgeImage(*image,geometry_info.rho,
1437               geometry_info.sigma,exception);
1438             break;
1439           }
1440         if (LocaleCompare("emboss",option+1) == 0)
1441           {
1442             /*
1443               Gaussian embossen image.
1444             */
1445             (void) SyncImageSettings(mogrify_info,*image);
1446             flags=ParseGeometry(argv[i+1],&geometry_info);
1447             if ((flags & SigmaValue) == 0)
1448               geometry_info.sigma=1.0;
1449             mogrify_image=EmbossImage(*image,geometry_info.rho,
1450               geometry_info.sigma,exception);
1451             break;
1452           }
1453         if (LocaleCompare("encipher",option+1) == 0)
1454           {
1455             StringInfo
1456               *passkey;
1457
1458             /*
1459               Encipher pixels.
1460             */
1461             (void) SyncImageSettings(mogrify_info,*image);
1462             passkey=FileToStringInfo(argv[i+1],~0,exception);
1463             if (passkey != (StringInfo *) NULL)
1464               {
1465                 (void) PasskeyEncipherImage(*image,passkey,exception);
1466                 passkey=DestroyStringInfo(passkey);
1467               }
1468             break;
1469           }
1470         if (LocaleCompare("encoding",option+1) == 0)
1471           {
1472             (void) CloneString(&draw_info->encoding,argv[i+1]);
1473             break;
1474           }
1475         if (LocaleCompare("enhance",option+1) == 0)
1476           {
1477             /*
1478               Enhance image.
1479             */
1480             (void) SyncImageSettings(mogrify_info,*image);
1481             mogrify_image=EnhanceImage(*image,exception);
1482             break;
1483           }
1484         if (LocaleCompare("equalize",option+1) == 0)
1485           {
1486             /*
1487               Equalize image.
1488             */
1489             (void) SyncImageSettings(mogrify_info,*image);
1490             (void) EqualizeImage(*image,exception);
1491             break;
1492           }
1493         if (LocaleCompare("evaluate",option+1) == 0)
1494           {
1495             double
1496               constant;
1497
1498             MagickEvaluateOperator
1499               op;
1500
1501             (void) SyncImageSettings(mogrify_info,*image);
1502             op=(MagickEvaluateOperator) ParseCommandOption(
1503               MagickEvaluateOptions,MagickFalse,argv[i+1]);
1504             constant=SiPrefixToDouble(argv[i+2],QuantumRange);
1505             (void) EvaluateImage(*image,op,constant,exception);
1506             break;
1507           }
1508         if (LocaleCompare("extent",option+1) == 0)
1509           {
1510             /*
1511               Set the image extent.
1512             */
1513             (void) SyncImageSettings(mogrify_info,*image);
1514             flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1515             if (geometry.width == 0)
1516               geometry.width=(*image)->columns;
1517             if (geometry.height == 0)
1518               geometry.height=(*image)->rows;
1519             mogrify_image=ExtentImage(*image,&geometry,exception);
1520             break;
1521           }
1522         break;
1523       }
1524       case 'f':
1525       {
1526         if (LocaleCompare("family",option+1) == 0)
1527           {
1528             if (*option == '+')
1529               {
1530                 if (draw_info->family != (char *) NULL)
1531                   draw_info->family=DestroyString(draw_info->family);
1532                 break;
1533               }
1534             (void) CloneString(&draw_info->family,argv[i+1]);
1535             break;
1536           }
1537         if (LocaleCompare("features",option+1) == 0)
1538           {
1539             if (*option == '+')
1540               {
1541                 (void) DeleteImageArtifact(*image,"identify:features");
1542                 break;
1543               }
1544             (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1545             break;
1546           }
1547         if (LocaleCompare("fill",option+1) == 0)
1548           {
1549             ExceptionInfo
1550               *sans;
1551
1552             GetPixelInfo(*image,&fill);
1553             if (*option == '+')
1554               {
1555                 (void) QueryMagickColor("none",&fill,exception);
1556                 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1557                 if (draw_info->fill_pattern != (Image *) NULL)
1558                   draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1559                 break;
1560               }
1561             sans=AcquireExceptionInfo();
1562             (void) QueryMagickColor(argv[i+1],&fill,sans);
1563             status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1564             sans=DestroyExceptionInfo(sans);
1565             if (status == MagickFalse)
1566               draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1567                 exception);
1568             break;
1569           }
1570         if (LocaleCompare("flip",option+1) == 0)
1571           {
1572             /*
1573               Flip image scanlines.
1574             */
1575             (void) SyncImageSettings(mogrify_info,*image);
1576             mogrify_image=FlipImage(*image,exception);
1577             break;
1578           }
1579         if (LocaleCompare("floodfill",option+1) == 0)
1580           {
1581             PixelInfo
1582               target;
1583
1584             /*
1585               Floodfill image.
1586             */
1587             (void) SyncImageSettings(mogrify_info,*image);
1588             (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1589             (void) QueryMagickColor(argv[i+2],&target,exception);
1590             (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
1591               geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
1592             break;
1593           }
1594         if (LocaleCompare("flop",option+1) == 0)
1595           {
1596             /*
1597               Flop image scanlines.
1598             */
1599             (void) SyncImageSettings(mogrify_info,*image);
1600             mogrify_image=FlopImage(*image,exception);
1601             break;
1602           }
1603         if (LocaleCompare("font",option+1) == 0)
1604           {
1605             if (*option == '+')
1606               {
1607                 if (draw_info->font != (char *) NULL)
1608                   draw_info->font=DestroyString(draw_info->font);
1609                 break;
1610               }
1611             (void) CloneString(&draw_info->font,argv[i+1]);
1612             break;
1613           }
1614         if (LocaleCompare("format",option+1) == 0)
1615           {
1616             format=argv[i+1];
1617             break;
1618           }
1619         if (LocaleCompare("frame",option+1) == 0)
1620           {
1621             FrameInfo
1622               frame_info;
1623
1624             /*
1625               Surround image with an ornamental border.
1626             */
1627             (void) SyncImageSettings(mogrify_info,*image);
1628             flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1629             frame_info.width=geometry.width;
1630             frame_info.height=geometry.height;
1631             if ((flags & HeightValue) == 0)
1632               frame_info.height=geometry.width;
1633             frame_info.outer_bevel=geometry.x;
1634             frame_info.inner_bevel=geometry.y;
1635             frame_info.x=(ssize_t) frame_info.width;
1636             frame_info.y=(ssize_t) frame_info.height;
1637             frame_info.width=(*image)->columns+2*frame_info.width;
1638             frame_info.height=(*image)->rows+2*frame_info.height;
1639             mogrify_image=FrameImage(*image,&frame_info,compose,exception);
1640             break;
1641           }
1642         if (LocaleCompare("function",option+1) == 0)
1643           {
1644             char
1645               *arguments,
1646               token[MaxTextExtent];
1647
1648             const char
1649               *p;
1650
1651             double
1652               *parameters;
1653
1654             MagickFunction
1655               function;
1656
1657             register ssize_t
1658               x;
1659
1660             size_t
1661               number_parameters;
1662
1663             /*
1664               Function Modify Image Values
1665             */
1666             (void) SyncImageSettings(mogrify_info,*image);
1667             function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1668               MagickFalse,argv[i+1]);
1669             arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1670               exception);
1671             if (arguments == (char *) NULL)
1672               break;
1673             p=(char *) arguments;
1674             for (x=0; *p != '\0'; x++)
1675             {
1676               GetMagickToken(p,&p,token);
1677               if (*token == ',')
1678                 GetMagickToken(p,&p,token);
1679             }
1680             number_parameters=(size_t) x;
1681             parameters=(double *) AcquireQuantumMemory(number_parameters,
1682               sizeof(*parameters));
1683             if (parameters == (double *) NULL)
1684               ThrowWandFatalException(ResourceLimitFatalError,
1685                 "MemoryAllocationFailed",(*image)->filename);
1686             (void) ResetMagickMemory(parameters,0,number_parameters*
1687               sizeof(*parameters));
1688             p=(char *) arguments;
1689             for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1690             {
1691               GetMagickToken(p,&p,token);
1692               if (*token == ',')
1693                 GetMagickToken(p,&p,token);
1694               parameters[x]=InterpretLocaleValue(token,(char **) NULL);
1695             }
1696             arguments=DestroyString(arguments);
1697             (void) FunctionImage(*image,function,number_parameters,parameters,
1698               exception);
1699             parameters=(double *) RelinquishMagickMemory(parameters);
1700             break;
1701           }
1702         break;
1703       }
1704       case 'g':
1705       {
1706         if (LocaleCompare("gamma",option+1) == 0)
1707           {
1708             /*
1709               Gamma image.
1710             */
1711             (void) SyncImageSettings(mogrify_info,*image);
1712             if (*option == '+')
1713               (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
1714             else
1715               (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1716                 (char **) NULL),exception);
1717             break;
1718           }
1719         if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1720             (LocaleCompare("gaussian",option+1) == 0))
1721           {
1722             /*
1723               Gaussian blur image.
1724             */
1725             (void) SyncImageSettings(mogrify_info,*image);
1726             flags=ParseGeometry(argv[i+1],&geometry_info);
1727             if ((flags & SigmaValue) == 0)
1728               geometry_info.sigma=1.0;
1729             if ((flags & XiValue) == 0)
1730               geometry_info.xi=0.0;
1731             mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1732               geometry_info.sigma,geometry_info.xi,exception);
1733             break;
1734           }
1735         if (LocaleCompare("geometry",option+1) == 0)
1736           {
1737               /*
1738                 Record Image offset, Resize last image.
1739               */
1740             (void) SyncImageSettings(mogrify_info,*image);
1741             if (*option == '+')
1742               {
1743                 if ((*image)->geometry != (char *) NULL)
1744                   (*image)->geometry=DestroyString((*image)->geometry);
1745                 break;
1746               }
1747             flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1748             if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1749               (void) CloneString(&(*image)->geometry,argv[i+1]);
1750             else
1751               mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1752                 (*image)->filter,(*image)->blur,exception);
1753             break;
1754           }
1755         if (LocaleCompare("gravity",option+1) == 0)
1756           {
1757             if (*option == '+')
1758               {
1759                 draw_info->gravity=UndefinedGravity;
1760                 break;
1761               }
1762             draw_info->gravity=(GravityType) ParseCommandOption(
1763               MagickGravityOptions,MagickFalse,argv[i+1]);
1764             break;
1765           }
1766         break;
1767       }
1768       case 'h':
1769       {
1770         if (LocaleCompare("highlight-color",option+1) == 0)
1771           {
1772             (void) SetImageArtifact(*image,option+1,argv[i+1]);
1773             break;
1774           }
1775         break;
1776       }
1777       case 'i':
1778       {
1779         if (LocaleCompare("identify",option+1) == 0)
1780           {
1781             char
1782               *text;
1783
1784             (void) SyncImageSettings(mogrify_info,*image);
1785             if (format == (char *) NULL)
1786               {
1787                 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1788                   exception);
1789                 break;
1790               }
1791             text=InterpretImageProperties(mogrify_info,*image,format,
1792               exception);
1793             if (text == (char *) NULL)
1794               break;
1795             (void) fputs(text,stdout);
1796             (void) fputc('\n',stdout);
1797             text=DestroyString(text);
1798             break;
1799           }
1800         if (LocaleCompare("implode",option+1) == 0)
1801           {
1802             /*
1803               Implode image.
1804             */
1805             (void) SyncImageSettings(mogrify_info,*image);
1806             (void) ParseGeometry(argv[i+1],&geometry_info);
1807             mogrify_image=ImplodeImage(*image,geometry_info.rho,
1808               interpolate_method,exception);
1809             break;
1810           }
1811         if (LocaleCompare("interline-spacing",option+1) == 0)
1812           {
1813             if (*option == '+')
1814               (void) ParseGeometry("0",&geometry_info);
1815             else
1816               (void) ParseGeometry(argv[i+1],&geometry_info);
1817             draw_info->interline_spacing=geometry_info.rho;
1818             break;
1819           }
1820         if (LocaleCompare("interpolate",option+1) == 0)
1821           {
1822             interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1823               MagickInterpolateOptions,MagickFalse,argv[i+1]);
1824             break;
1825           }
1826         if (LocaleCompare("interword-spacing",option+1) == 0)
1827           {
1828             if (*option == '+')
1829               (void) ParseGeometry("0",&geometry_info);
1830             else
1831               (void) ParseGeometry(argv[i+1],&geometry_info);
1832             draw_info->interword_spacing=geometry_info.rho;
1833             break;
1834           }
1835         break;
1836       }
1837       case 'k':
1838       {
1839         if (LocaleCompare("kerning",option+1) == 0)
1840           {
1841             if (*option == '+')
1842               (void) ParseGeometry("0",&geometry_info);
1843             else
1844               (void) ParseGeometry(argv[i+1],&geometry_info);
1845             draw_info->kerning=geometry_info.rho;
1846             break;
1847           }
1848         break;
1849       }
1850       case 'l':
1851       {
1852         if (LocaleCompare("lat",option+1) == 0)
1853           {
1854             /*
1855               Local adaptive threshold image.
1856             */
1857             (void) SyncImageSettings(mogrify_info,*image);
1858             flags=ParseGeometry(argv[i+1],&geometry_info);
1859             if ((flags & PercentValue) != 0)
1860               geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1861             mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1862               geometry_info.rho,(size_t) geometry_info.sigma,(double)
1863               geometry_info.xi,exception);
1864             break;
1865           }
1866         if (LocaleCompare("level",option+1) == 0)
1867           {
1868             MagickRealType
1869               black_point,
1870               gamma,
1871               white_point;
1872
1873             MagickStatusType
1874               flags;
1875
1876             /*
1877               Parse levels.
1878             */
1879             (void) SyncImageSettings(mogrify_info,*image);
1880             flags=ParseGeometry(argv[i+1],&geometry_info);
1881             black_point=geometry_info.rho;
1882             white_point=(MagickRealType) QuantumRange;
1883             if ((flags & SigmaValue) != 0)
1884               white_point=geometry_info.sigma;
1885             gamma=1.0;
1886             if ((flags & XiValue) != 0)
1887               gamma=geometry_info.xi;
1888             if ((flags & PercentValue) != 0)
1889               {
1890                 black_point*=(MagickRealType) (QuantumRange/100.0);
1891                 white_point*=(MagickRealType) (QuantumRange/100.0);
1892               }
1893             if ((flags & SigmaValue) == 0)
1894               white_point=(MagickRealType) QuantumRange-black_point;
1895             if ((*option == '+') || ((flags & AspectValue) != 0))
1896               (void) LevelizeImage(*image,black_point,white_point,gamma,
1897                 exception);
1898             else
1899               (void) LevelImage(*image,black_point,white_point,gamma,
1900                 exception);
1901             InheritException(exception,&(*image)->exception);
1902             break;
1903           }
1904         if (LocaleCompare("level-colors",option+1) == 0)
1905           {
1906             char
1907               token[MaxTextExtent];
1908
1909             const char
1910               *p;
1911
1912             PixelInfo
1913               black_point,
1914               white_point;
1915
1916             p=(const char *) argv[i+1];
1917             GetMagickToken(p,&p,token);  /* get black point color */
1918             if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1919               (void) QueryMagickColor(token,&black_point,exception);
1920             else
1921               (void) QueryMagickColor("#000000",&black_point,exception);
1922             if (isalpha((int) token[0]) || (token[0] == '#'))
1923               GetMagickToken(p,&p,token);
1924             if (*token == '\0')
1925               white_point=black_point; /* set everything to that color */
1926             else
1927               {
1928                 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1929                   GetMagickToken(p,&p,token); /* Get white point color. */
1930                 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1931                   (void) QueryMagickColor(token,&white_point,exception);
1932                 else
1933                   (void) QueryMagickColor("#ffffff",&white_point,exception);
1934               }
1935             (void) LevelImageColors(*image,&black_point,&white_point,
1936               *option == '+' ? MagickTrue : MagickFalse,exception);
1937             break;
1938           }
1939         if (LocaleCompare("linear-stretch",option+1) == 0)
1940           {
1941             double
1942               black_point,
1943               white_point;
1944
1945             MagickStatusType
1946               flags;
1947
1948             (void) SyncImageSettings(mogrify_info,*image);
1949             flags=ParseGeometry(argv[i+1],&geometry_info);
1950             black_point=geometry_info.rho;
1951             white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1952             if ((flags & SigmaValue) != 0)
1953               white_point=geometry_info.sigma;
1954             if ((flags & PercentValue) != 0)
1955               {
1956                 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1957                 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1958               }
1959             if ((flags & SigmaValue) == 0)
1960               white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1961                 black_point;
1962             (void) LinearStretchImage(*image,black_point,white_point,exception);
1963             InheritException(exception,&(*image)->exception);
1964             break;
1965           }
1966         if (LocaleCompare("linewidth",option+1) == 0)
1967           {
1968             draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1969               (char **) NULL);
1970             break;
1971           }
1972         if (LocaleCompare("liquid-rescale",option+1) == 0)
1973           {
1974             /*
1975               Liquid rescale image.
1976             */
1977             (void) SyncImageSettings(mogrify_info,*image);
1978             flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1979             if ((flags & XValue) == 0)
1980               geometry.x=1;
1981             if ((flags & YValue) == 0)
1982               geometry.y=0;
1983             mogrify_image=LiquidRescaleImage(*image,geometry.width,
1984               geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1985             break;
1986           }
1987         if (LocaleCompare("lowlight-color",option+1) == 0)
1988           {
1989             (void) SetImageArtifact(*image,option+1,argv[i+1]);
1990             break;
1991           }
1992         break;
1993       }
1994       case 'm':
1995       {
1996         if (LocaleCompare("map",option+1) == 0)
1997           {
1998             Image
1999               *remap_image;
2000
2001             /*
2002               Transform image colors to match this set of colors.
2003             */
2004             (void) SyncImageSettings(mogrify_info,*image);
2005             if (*option == '+')
2006               break;
2007             remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2008             if (remap_image == (Image *) NULL)
2009               break;
2010             (void) RemapImage(quantize_info,*image,remap_image,exception);
2011             remap_image=DestroyImage(remap_image);
2012             break;
2013           }
2014         if (LocaleCompare("mask",option+1) == 0)
2015           {
2016             Image
2017               *mask;
2018
2019             (void) SyncImageSettings(mogrify_info,*image);
2020             if (*option == '+')
2021               {
2022                 /*
2023                   Remove a mask.
2024                 */
2025                 (void) SetImageMask(*image,(Image *) NULL,exception);
2026                 break;
2027               }
2028             /*
2029               Set the image mask.
2030             */
2031             mask=GetImageCache(mogrify_info,argv[i+1],exception);
2032             if (mask == (Image *) NULL)
2033               break;
2034             (void) SetImageMask(*image,mask,exception);
2035             mask=DestroyImage(mask);
2036             break;
2037           }
2038         if (LocaleCompare("matte",option+1) == 0)
2039           {
2040             (void) SetImageAlphaChannel(*image,(*option == '-') ?
2041               SetAlphaChannel : DeactivateAlphaChannel,exception);
2042             break;
2043           }
2044         if (LocaleCompare("median",option+1) == 0)
2045           {
2046             /*
2047               Median filter image.
2048             */
2049             (void) SyncImageSettings(mogrify_info,*image);
2050             flags=ParseGeometry(argv[i+1],&geometry_info);
2051             if ((flags & SigmaValue) == 0)
2052               geometry_info.sigma=geometry_info.rho;
2053             mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2054               geometry_info.rho,(size_t) geometry_info.sigma,exception);
2055             break;
2056           }
2057         if (LocaleCompare("mode",option+1) == 0)
2058           {
2059             /*
2060               Mode image.
2061             */
2062             (void) SyncImageSettings(mogrify_info,*image);
2063             flags=ParseGeometry(argv[i+1],&geometry_info);
2064             if ((flags & SigmaValue) == 0)
2065               geometry_info.sigma=geometry_info.rho;
2066             mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2067               geometry_info.rho,(size_t) geometry_info.sigma,exception);
2068             break;
2069           }
2070         if (LocaleCompare("modulate",option+1) == 0)
2071           {
2072             (void) SyncImageSettings(mogrify_info,*image);
2073             (void) ModulateImage(*image,argv[i+1],exception);
2074             break;
2075           }
2076         if (LocaleCompare("monitor",option+1) == 0)
2077           {
2078             if (*option == '+')
2079               {
2080                 (void) SetImageProgressMonitor(*image,
2081                   (MagickProgressMonitor) NULL,(void *) NULL);
2082                 break;
2083               }
2084             (void) SetImageProgressMonitor(*image,MonitorProgress,
2085               (void *) NULL);
2086             break;
2087           }
2088         if (LocaleCompare("monochrome",option+1) == 0)
2089           {
2090             (void) SyncImageSettings(mogrify_info,*image);
2091             (void) SetImageType(*image,BilevelType,exception);
2092             break;
2093           }
2094         if (LocaleCompare("morphology",option+1) == 0)
2095           {
2096             char
2097               token[MaxTextExtent];
2098
2099             const char
2100               *p;
2101
2102             KernelInfo
2103               *kernel;
2104
2105             MorphologyMethod
2106               method;
2107
2108             ssize_t
2109               iterations;
2110
2111             /*
2112               Morphological Image Operation
2113             */
2114             (void) SyncImageSettings(mogrify_info,*image);
2115             p=argv[i+1];
2116             GetMagickToken(p,&p,token);
2117             method=(MorphologyMethod) ParseCommandOption(
2118               MagickMorphologyOptions,MagickFalse,token);
2119             iterations=1L;
2120             GetMagickToken(p,&p,token);
2121             if ((*p == ':') || (*p == ','))
2122               GetMagickToken(p,&p,token);
2123             if ((*p != '\0'))
2124               iterations=(ssize_t) StringToLong(p);
2125             kernel=AcquireKernelInfo(argv[i+2]);
2126             if (kernel == (KernelInfo *) NULL)
2127               {
2128                 (void) ThrowMagickException(exception,GetMagickModule(),
2129                   OptionError,"UnabletoParseKernel","morphology");
2130                 status=MagickFalse;
2131                 break;
2132               }
2133             mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2134               exception);
2135             kernel=DestroyKernelInfo(kernel);
2136             break;
2137           }
2138         if (LocaleCompare("motion-blur",option+1) == 0)
2139           {
2140             /*
2141               Motion blur image.
2142             */
2143             (void) SyncImageSettings(mogrify_info,*image);
2144             flags=ParseGeometry(argv[i+1],&geometry_info);
2145             if ((flags & SigmaValue) == 0)
2146               geometry_info.sigma=1.0;
2147             mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2148               geometry_info.sigma,geometry_info.xi,geometry_info.psi,
2149               exception);
2150             break;
2151           }
2152         break;
2153       }
2154       case 'n':
2155       {
2156         if (LocaleCompare("negate",option+1) == 0)
2157           {
2158             (void) SyncImageSettings(mogrify_info,*image);
2159             (void) NegateImage(*image,*option == '+' ? MagickTrue :
2160               MagickFalse,exception);
2161             break;
2162           }
2163         if (LocaleCompare("noise",option+1) == 0)
2164           {
2165             (void) SyncImageSettings(mogrify_info,*image);
2166             if (*option == '-')
2167               {
2168                 flags=ParseGeometry(argv[i+1],&geometry_info);
2169                 if ((flags & SigmaValue) == 0)
2170                   geometry_info.sigma=geometry_info.rho;
2171                 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2172                   geometry_info.rho,(size_t) geometry_info.sigma,exception);
2173               }
2174             else
2175               {
2176                 NoiseType
2177                   noise;
2178
2179                 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2180                   MagickFalse,argv[i+1]);
2181                 mogrify_image=AddNoiseImage(*image,noise,exception);
2182               }
2183             break;
2184           }
2185         if (LocaleCompare("normalize",option+1) == 0)
2186           {
2187             (void) SyncImageSettings(mogrify_info,*image);
2188             (void) NormalizeImage(*image,exception);
2189             break;
2190           }
2191         break;
2192       }
2193       case 'o':
2194       {
2195         if (LocaleCompare("opaque",option+1) == 0)
2196           {
2197             PixelInfo
2198               target;
2199
2200             (void) SyncImageSettings(mogrify_info,*image);
2201             (void) QueryMagickColor(argv[i+1],&target,exception);
2202             (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2203               MagickFalse : MagickTrue,exception);
2204             break;
2205           }
2206         if (LocaleCompare("ordered-dither",option+1) == 0)
2207           {
2208             (void) SyncImageSettings(mogrify_info,*image);
2209             (void) OrderedPosterizeImage(*image,argv[i+1],exception);
2210             break;
2211           }
2212         break;
2213       }
2214       case 'p':
2215       {
2216         if (LocaleCompare("paint",option+1) == 0)
2217           {
2218             (void) SyncImageSettings(mogrify_info,*image);
2219             (void) ParseGeometry(argv[i+1],&geometry_info);
2220             mogrify_image=OilPaintImage(*image,geometry_info.rho,
2221               geometry_info.sigma,exception);
2222             break;
2223           }
2224         if (LocaleCompare("pen",option+1) == 0)
2225           {
2226             if (*option == '+')
2227               {
2228                 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2229                 break;
2230               }
2231             (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2232             break;
2233           }
2234         if (LocaleCompare("pointsize",option+1) == 0)
2235           {
2236             if (*option == '+')
2237               (void) ParseGeometry("12",&geometry_info);
2238             else
2239               (void) ParseGeometry(argv[i+1],&geometry_info);
2240             draw_info->pointsize=geometry_info.rho;
2241             break;
2242           }
2243         if (LocaleCompare("polaroid",option+1) == 0)
2244           {
2245             double
2246               angle;
2247
2248             RandomInfo
2249               *random_info;
2250
2251             /*
2252               Simulate a Polaroid picture.
2253             */
2254             (void) SyncImageSettings(mogrify_info,*image);
2255             random_info=AcquireRandomInfo();
2256             angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2257             random_info=DestroyRandomInfo(random_info);
2258             if (*option == '-')
2259               {
2260                 SetGeometryInfo(&geometry_info);
2261                 flags=ParseGeometry(argv[i+1],&geometry_info);
2262                 angle=geometry_info.rho;
2263               }
2264             mogrify_image=PolaroidImage(*image,draw_info,angle,
2265               interpolate_method,exception);
2266             break;
2267           }
2268         if (LocaleCompare("posterize",option+1) == 0)
2269           {
2270             /*
2271               Posterize image.
2272             */
2273             (void) SyncImageSettings(mogrify_info,*image);
2274             (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2275               quantize_info->dither,exception);
2276             break;
2277           }
2278         if (LocaleCompare("preview",option+1) == 0)
2279           {
2280             PreviewType
2281               preview_type;
2282
2283             /*
2284               Preview image.
2285             */
2286             (void) SyncImageSettings(mogrify_info,*image);
2287             if (*option == '+')
2288               preview_type=UndefinedPreview;
2289             else
2290               preview_type=(PreviewType) ParseCommandOption(
2291                 MagickPreviewOptions,MagickFalse,argv[i+1]);
2292             mogrify_image=PreviewImage(*image,preview_type,exception);
2293             break;
2294           }
2295         if (LocaleCompare("profile",option+1) == 0)
2296           {
2297             const char
2298               *name;
2299
2300             const StringInfo
2301               *profile;
2302
2303             Image
2304               *profile_image;
2305
2306             ImageInfo
2307               *profile_info;
2308
2309             (void) SyncImageSettings(mogrify_info,*image);
2310             if (*option == '+')
2311               {
2312                 /*
2313                   Remove a profile from the image.
2314                 */
2315                 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2316                   NULL,0,MagickTrue);
2317                 InheritException(exception,&(*image)->exception);
2318                 break;
2319               }
2320             /*
2321               Associate a profile with the image.
2322             */
2323             profile_info=CloneImageInfo(mogrify_info);
2324             profile=GetImageProfile(*image,"iptc");
2325             if (profile != (StringInfo *) NULL)
2326               profile_info->profile=(void *) CloneStringInfo(profile);
2327             profile_image=GetImageCache(profile_info,argv[i+1],exception);
2328             profile_info=DestroyImageInfo(profile_info);
2329             if (profile_image == (Image *) NULL)
2330               {
2331                 StringInfo
2332                   *profile;
2333
2334                 profile_info=CloneImageInfo(mogrify_info);
2335                 (void) CopyMagickString(profile_info->filename,argv[i+1],
2336                   MaxTextExtent);
2337                 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2338                 if (profile != (StringInfo *) NULL)
2339                   {
2340                     (void) ProfileImage(*image,profile_info->magick,
2341                       GetStringInfoDatum(profile),(size_t)
2342                       GetStringInfoLength(profile),MagickFalse);
2343                     profile=DestroyStringInfo(profile);
2344                   }
2345                 profile_info=DestroyImageInfo(profile_info);
2346                 break;
2347               }
2348             ResetImageProfileIterator(profile_image);
2349             name=GetNextImageProfile(profile_image);
2350             while (name != (const char *) NULL)
2351             {
2352               profile=GetImageProfile(profile_image,name);
2353               if (profile != (StringInfo *) NULL)
2354                 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2355                   (size_t) GetStringInfoLength(profile),MagickFalse);
2356               name=GetNextImageProfile(profile_image);
2357             }
2358             profile_image=DestroyImage(profile_image);
2359             break;
2360           }
2361         break;
2362       }
2363       case 'q':
2364       {
2365         if (LocaleCompare("quantize",option+1) == 0)
2366           {
2367             if (*option == '+')
2368               {
2369                 quantize_info->colorspace=UndefinedColorspace;
2370                 break;
2371               }
2372             quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2373               MagickColorspaceOptions,MagickFalse,argv[i+1]);
2374             break;
2375           }
2376         break;
2377       }
2378       case 'r':
2379       {
2380         if (LocaleCompare("radial-blur",option+1) == 0)
2381           {
2382             /*
2383               Radial blur image.
2384             */
2385             (void) SyncImageSettings(mogrify_info,*image);
2386             flags=ParseGeometry(argv[i+1],&geometry_info);
2387             mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2388               geometry_info.sigma,exception);
2389             break;
2390           }
2391         if (LocaleCompare("raise",option+1) == 0)
2392           {
2393             /*
2394               Surround image with a raise of solid color.
2395             */
2396             flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2397             if ((flags & SigmaValue) == 0)
2398               geometry.height=geometry.width;
2399             (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2400               MagickFalse,exception);
2401             break;
2402           }
2403         if (LocaleCompare("random-threshold",option+1) == 0)
2404           {
2405             /*
2406               Threshold image.
2407             */
2408             (void) SyncImageSettings(mogrify_info,*image);
2409             (void) RandomThresholdImage(*image,argv[i+1],exception);
2410             break;
2411           }
2412         if (LocaleCompare("recolor",option+1) == 0)
2413           {
2414             KernelInfo
2415               *kernel;
2416
2417             (void) SyncImageSettings(mogrify_info,*image);
2418             kernel=AcquireKernelInfo(argv[i+1]);
2419             if (kernel == (KernelInfo *) NULL)
2420               break;
2421             mogrify_image=ColorMatrixImage(*image,kernel,exception);
2422             kernel=DestroyKernelInfo(kernel);
2423             break;
2424           }
2425         if (LocaleCompare("region",option+1) == 0)
2426           {
2427             (void) SyncImageSettings(mogrify_info,*image);
2428             if (region_image != (Image *) NULL)
2429               {
2430                 /*
2431                   Composite region.
2432                 */
2433                 (void) CompositeImage(region_image,region_image->matte !=
2434                    MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2435                    region_geometry.x,region_geometry.y);
2436                 InheritException(exception,&region_image->exception);
2437                 *image=DestroyImage(*image);
2438                 *image=region_image;
2439                 region_image = (Image *) NULL;
2440               }
2441             if (*option == '+')
2442               break;
2443             /*
2444               Apply transformations to a selected region of the image.
2445             */
2446             (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2447               exception);
2448             mogrify_image=CropImage(*image,&region_geometry,exception);
2449             if (mogrify_image == (Image *) NULL)
2450               break;
2451             region_image=(*image);
2452             *image=mogrify_image;
2453             mogrify_image=(Image *) NULL;
2454             break;
2455           }
2456         if (LocaleCompare("render",option+1) == 0)
2457           {
2458             (void) SyncImageSettings(mogrify_info,*image);
2459             draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2460             break;
2461           }
2462         if (LocaleCompare("remap",option+1) == 0)
2463           {
2464             Image
2465               *remap_image;
2466
2467             /*
2468               Transform image colors to match this set of colors.
2469             */
2470             (void) SyncImageSettings(mogrify_info,*image);
2471             if (*option == '+')
2472               break;
2473             remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2474             if (remap_image == (Image *) NULL)
2475               break;
2476             (void) RemapImage(quantize_info,*image,remap_image,exception);
2477             remap_image=DestroyImage(remap_image);
2478             break;
2479           }
2480         if (LocaleCompare("repage",option+1) == 0)
2481           {
2482             if (*option == '+')
2483               {
2484                 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2485                 break;
2486               }
2487             (void) ResetImagePage(*image,argv[i+1]);
2488             InheritException(exception,&(*image)->exception);
2489             break;
2490           }
2491         if (LocaleCompare("resample",option+1) == 0)
2492           {
2493             /*
2494               Resample image.
2495             */
2496             (void) SyncImageSettings(mogrify_info,*image);
2497             flags=ParseGeometry(argv[i+1],&geometry_info);
2498             if ((flags & SigmaValue) == 0)
2499               geometry_info.sigma=geometry_info.rho;
2500             mogrify_image=ResampleImage(*image,geometry_info.rho,
2501               geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2502             break;
2503           }
2504         if (LocaleCompare("resize",option+1) == 0)
2505           {
2506             /*
2507               Resize image.
2508             */
2509             (void) SyncImageSettings(mogrify_info,*image);
2510             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2511             mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2512               (*image)->filter,(*image)->blur,exception);
2513             break;
2514           }
2515         if (LocaleCompare("roll",option+1) == 0)
2516           {
2517             /*
2518               Roll image.
2519             */
2520             (void) SyncImageSettings(mogrify_info,*image);
2521             (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2522             mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2523             break;
2524           }
2525         if (LocaleCompare("rotate",option+1) == 0)
2526           {
2527             char
2528               *geometry;
2529
2530             /*
2531               Check for conditional image rotation.
2532             */
2533             (void) SyncImageSettings(mogrify_info,*image);
2534             if (strchr(argv[i+1],'>') != (char *) NULL)
2535               if ((*image)->columns <= (*image)->rows)
2536                 break;
2537             if (strchr(argv[i+1],'<') != (char *) NULL)
2538               if ((*image)->columns >= (*image)->rows)
2539                 break;
2540             /*
2541               Rotate image.
2542             */
2543             geometry=ConstantString(argv[i+1]);
2544             (void) SubstituteString(&geometry,">","");
2545             (void) SubstituteString(&geometry,"<","");
2546             (void) ParseGeometry(geometry,&geometry_info);
2547             geometry=DestroyString(geometry);
2548             mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2549             break;
2550           }
2551         break;
2552       }
2553       case 's':
2554       {
2555         if (LocaleCompare("sample",option+1) == 0)
2556           {
2557             /*
2558               Sample image with pixel replication.
2559             */
2560             (void) SyncImageSettings(mogrify_info,*image);
2561             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2562             mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2563               exception);
2564             break;
2565           }
2566         if (LocaleCompare("scale",option+1) == 0)
2567           {
2568             /*
2569               Resize image.
2570             */
2571             (void) SyncImageSettings(mogrify_info,*image);
2572             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2573             mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2574               exception);
2575             break;
2576           }
2577         if (LocaleCompare("selective-blur",option+1) == 0)
2578           {
2579             /*
2580               Selectively blur pixels within a contrast threshold.
2581             */
2582             (void) SyncImageSettings(mogrify_info,*image);
2583             flags=ParseGeometry(argv[i+1],&geometry_info);
2584             if ((flags & PercentValue) != 0)
2585               geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2586             mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2587               geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
2588             break;
2589           }
2590         if (LocaleCompare("separate",option+1) == 0)
2591           {
2592             /*
2593               Break channels into separate images.
2594             */
2595             (void) SyncImageSettings(mogrify_info,*image);
2596             mogrify_image=SeparateImages(*image,exception);
2597             break;
2598           }
2599         if (LocaleCompare("sepia-tone",option+1) == 0)
2600           {
2601             double
2602               threshold;
2603
2604             /*
2605               Sepia-tone image.
2606             */
2607             (void) SyncImageSettings(mogrify_info,*image);
2608             threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2609             mogrify_image=SepiaToneImage(*image,threshold,exception);
2610             break;
2611           }
2612         if (LocaleCompare("segment",option+1) == 0)
2613           {
2614             /*
2615               Segment image.
2616             */
2617             (void) SyncImageSettings(mogrify_info,*image);
2618             flags=ParseGeometry(argv[i+1],&geometry_info);
2619             if ((flags & SigmaValue) == 0)
2620               geometry_info.sigma=1.0;
2621             (void) SegmentImage(*image,(*image)->colorspace,
2622               mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2623               exception);
2624             break;
2625           }
2626         if (LocaleCompare("set",option+1) == 0)
2627           {
2628             char
2629               *value;
2630
2631             /*
2632               Set image option.
2633             */
2634             if (*option == '+')
2635               {
2636                 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2637                   (void) DeleteImageRegistry(argv[i+1]+9);
2638                 else
2639                   if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2640                     {
2641                       (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2642                       (void) DeleteImageArtifact(*image,argv[i+1]+7);
2643                     }
2644                   else
2645                     (void) DeleteImageProperty(*image,argv[i+1]);
2646                 break;
2647               }
2648             value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2649               exception);
2650             if (value == (char *) NULL)
2651               break;
2652             if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2653               (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2654                 exception);
2655             else
2656               if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2657                 {
2658                   (void) SetImageOption(image_info,argv[i+1]+7,value);
2659                   (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2660                   (void) SetImageArtifact(*image,argv[i+1]+7,value);
2661                 }
2662               else
2663                 (void) SetImageProperty(*image,argv[i+1],value);
2664             value=DestroyString(value);
2665             break;
2666           }
2667         if (LocaleCompare("shade",option+1) == 0)
2668           {
2669             /*
2670               Shade image.
2671             */
2672             (void) SyncImageSettings(mogrify_info,*image);
2673             flags=ParseGeometry(argv[i+1],&geometry_info);
2674             if ((flags & SigmaValue) == 0)
2675               geometry_info.sigma=1.0;
2676             mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2677               MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2678             break;
2679           }
2680         if (LocaleCompare("shadow",option+1) == 0)
2681           {
2682             /*
2683               Shadow image.
2684             */
2685             (void) SyncImageSettings(mogrify_info,*image);
2686             flags=ParseGeometry(argv[i+1],&geometry_info);
2687             if ((flags & SigmaValue) == 0)
2688               geometry_info.sigma=1.0;
2689             if ((flags & XiValue) == 0)
2690               geometry_info.xi=4.0;
2691             if ((flags & PsiValue) == 0)
2692               geometry_info.psi=4.0;
2693             mogrify_image=ShadowImage(*image,geometry_info.rho,
2694               geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2695               ceil(geometry_info.psi-0.5),exception);
2696             break;
2697           }
2698         if (LocaleCompare("sharpen",option+1) == 0)
2699           {
2700             /*
2701               Sharpen image.
2702             */
2703             (void) SyncImageSettings(mogrify_info,*image);
2704             flags=ParseGeometry(argv[i+1],&geometry_info);
2705             if ((flags & SigmaValue) == 0)
2706               geometry_info.sigma=1.0;
2707             if ((flags & XiValue) == 0)
2708               geometry_info.xi=0.0;
2709             mogrify_image=SharpenImage(*image,geometry_info.rho,
2710               geometry_info.sigma,geometry_info.xi,exception);
2711             break;
2712           }
2713         if (LocaleCompare("shave",option+1) == 0)
2714           {
2715             /*
2716               Shave the image edges.
2717             */
2718             (void) SyncImageSettings(mogrify_info,*image);
2719             flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2720             mogrify_image=ShaveImage(*image,&geometry,exception);
2721             break;
2722           }
2723         if (LocaleCompare("shear",option+1) == 0)
2724           {
2725             /*
2726               Shear image.
2727             */
2728             (void) SyncImageSettings(mogrify_info,*image);
2729             flags=ParseGeometry(argv[i+1],&geometry_info);
2730             if ((flags & SigmaValue) == 0)
2731               geometry_info.sigma=geometry_info.rho;
2732             mogrify_image=ShearImage(*image,geometry_info.rho,
2733               geometry_info.sigma,exception);
2734             break;
2735           }
2736         if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2737           {
2738             /*
2739               Sigmoidal non-linearity contrast control.
2740             */
2741             (void) SyncImageSettings(mogrify_info,*image);
2742             flags=ParseGeometry(argv[i+1],&geometry_info);
2743             if ((flags & SigmaValue) == 0)
2744               geometry_info.sigma=(double) QuantumRange/2.0;
2745             if ((flags & PercentValue) != 0)
2746               geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2747                 100.0;
2748             (void) SigmoidalContrastImage(*image,(*option == '-') ?
2749               MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2750               exception);
2751             break;
2752           }
2753         if (LocaleCompare("sketch",option+1) == 0)
2754           {
2755             /*
2756               Sketch image.
2757             */
2758             (void) SyncImageSettings(mogrify_info,*image);
2759             flags=ParseGeometry(argv[i+1],&geometry_info);
2760             if ((flags & SigmaValue) == 0)
2761               geometry_info.sigma=1.0;
2762             mogrify_image=SketchImage(*image,geometry_info.rho,
2763               geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
2764             break;
2765           }
2766         if (LocaleCompare("solarize",option+1) == 0)
2767           {
2768             double
2769               threshold;
2770
2771             (void) SyncImageSettings(mogrify_info,*image);
2772             threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2773             (void) SolarizeImage(*image,threshold,exception);
2774             break;
2775           }
2776         if (LocaleCompare("sparse-color",option+1) == 0)
2777           {
2778             SparseColorMethod
2779               method;
2780
2781             char
2782               *arguments;
2783
2784             /*
2785               Sparse Color Interpolated Gradient
2786             */
2787             (void) SyncImageSettings(mogrify_info,*image);
2788             method=(SparseColorMethod) ParseCommandOption(
2789               MagickSparseColorOptions,MagickFalse,argv[i+1]);
2790             arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2791               exception);
2792             if (arguments == (char *) NULL)
2793               break;
2794             mogrify_image=SparseColorOption(*image,method,arguments,
2795               option[0] == '+' ? MagickTrue : MagickFalse,exception);
2796             arguments=DestroyString(arguments);
2797             break;
2798           }
2799         if (LocaleCompare("splice",option+1) == 0)
2800           {
2801             /*
2802               Splice a solid color into the image.
2803             */
2804             (void) SyncImageSettings(mogrify_info,*image);
2805             (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2806             mogrify_image=SpliceImage(*image,&geometry,exception);
2807             break;
2808           }
2809         if (LocaleCompare("spread",option+1) == 0)
2810           {
2811             /*
2812               Spread an image.
2813             */
2814             (void) SyncImageSettings(mogrify_info,*image);
2815             (void) ParseGeometry(argv[i+1],&geometry_info);
2816             mogrify_image=SpreadImage(*image,geometry_info.rho,
2817               interpolate_method,exception);
2818             break;
2819           }
2820         if (LocaleCompare("statistic",option+1) == 0)
2821           {
2822             StatisticType
2823               type;
2824
2825             (void) SyncImageSettings(mogrify_info,*image);
2826             type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2827               MagickFalse,argv[i+1]);
2828             (void) ParseGeometry(argv[i+2],&geometry_info);
2829             mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2830               (size_t) geometry_info.sigma,exception);
2831             break;
2832           }
2833         if (LocaleCompare("stretch",option+1) == 0)
2834           {
2835             if (*option == '+')
2836               {
2837                 draw_info->stretch=UndefinedStretch;
2838                 break;
2839               }
2840             draw_info->stretch=(StretchType) ParseCommandOption(
2841               MagickStretchOptions,MagickFalse,argv[i+1]);
2842             break;
2843           }
2844         if (LocaleCompare("strip",option+1) == 0)
2845           {
2846             /*
2847               Strip image of profiles and comments.
2848             */
2849             (void) SyncImageSettings(mogrify_info,*image);
2850             (void) StripImage(*image);
2851             InheritException(exception,&(*image)->exception);
2852             break;
2853           }
2854         if (LocaleCompare("stroke",option+1) == 0)
2855           {
2856             ExceptionInfo
2857               *sans;
2858
2859             if (*option == '+')
2860               {
2861                 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2862                 if (draw_info->stroke_pattern != (Image *) NULL)
2863                   draw_info->stroke_pattern=DestroyImage(
2864                     draw_info->stroke_pattern);
2865                 break;
2866               }
2867             sans=AcquireExceptionInfo();
2868             status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2869             sans=DestroyExceptionInfo(sans);
2870             if (status == MagickFalse)
2871               draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2872                 exception);
2873             break;
2874           }
2875         if (LocaleCompare("strokewidth",option+1) == 0)
2876           {
2877             draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2878               (char **) NULL);
2879             break;
2880           }
2881         if (LocaleCompare("style",option+1) == 0)
2882           {
2883             if (*option == '+')
2884               {
2885                 draw_info->style=UndefinedStyle;
2886                 break;
2887               }
2888             draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2889               MagickFalse,argv[i+1]);
2890             break;
2891           }
2892         if (LocaleCompare("swirl",option+1) == 0)
2893           {
2894             /*
2895               Swirl image.
2896             */
2897             (void) SyncImageSettings(mogrify_info,*image);
2898             (void) ParseGeometry(argv[i+1],&geometry_info);
2899             mogrify_image=SwirlImage(*image,geometry_info.rho,
2900               interpolate_method,exception);
2901             break;
2902           }
2903         break;
2904       }
2905       case 't':
2906       {
2907         if (LocaleCompare("threshold",option+1) == 0)
2908           {
2909             double
2910               threshold;
2911
2912             /*
2913               Threshold image.
2914             */
2915             (void) SyncImageSettings(mogrify_info,*image);
2916             if (*option == '+')
2917               threshold=(double) QuantumRange/2;
2918             else
2919               threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2920             (void) BilevelImage(*image,threshold);
2921             InheritException(exception,&(*image)->exception);
2922             break;
2923           }
2924         if (LocaleCompare("thumbnail",option+1) == 0)
2925           {
2926             /*
2927               Thumbnail image.
2928             */
2929             (void) SyncImageSettings(mogrify_info,*image);
2930             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2931             mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2932               exception);
2933             break;
2934           }
2935         if (LocaleCompare("tile",option+1) == 0)
2936           {
2937             if (*option == '+')
2938               {
2939                 if (draw_info->fill_pattern != (Image *) NULL)
2940                   draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2941                 break;
2942               }
2943             draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2944               exception);
2945             break;
2946           }
2947         if (LocaleCompare("tint",option+1) == 0)
2948           {
2949             /*
2950               Tint the image.
2951             */
2952             (void) SyncImageSettings(mogrify_info,*image);
2953             mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
2954             break;
2955           }
2956         if (LocaleCompare("transform",option+1) == 0)
2957           {
2958             /*
2959               Affine transform image.
2960             */
2961             (void) SyncImageSettings(mogrify_info,*image);
2962             mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2963               exception);
2964             break;
2965           }
2966         if (LocaleCompare("transparent",option+1) == 0)
2967           {
2968             PixelInfo
2969               target;
2970
2971             (void) SyncImageSettings(mogrify_info,*image);
2972             (void) QueryMagickColor(argv[i+1],&target,exception);
2973             (void) TransparentPaintImage(*image,&target,(Quantum)
2974               TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2975               &(*image)->exception);
2976             break;
2977           }
2978         if (LocaleCompare("transpose",option+1) == 0)
2979           {
2980             /*
2981               Transpose image scanlines.
2982             */
2983             (void) SyncImageSettings(mogrify_info,*image);
2984             mogrify_image=TransposeImage(*image,exception);
2985             break;
2986           }
2987         if (LocaleCompare("transverse",option+1) == 0)
2988           {
2989             /*
2990               Transverse image scanlines.
2991             */
2992             (void) SyncImageSettings(mogrify_info,*image);
2993             mogrify_image=TransverseImage(*image,exception);
2994             break;
2995           }
2996         if (LocaleCompare("treedepth",option+1) == 0)
2997           {
2998             quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2999             break;
3000           }
3001         if (LocaleCompare("trim",option+1) == 0)
3002           {
3003             /*
3004               Trim image.
3005             */
3006             (void) SyncImageSettings(mogrify_info,*image);
3007             mogrify_image=TrimImage(*image,exception);
3008             break;
3009           }
3010         if (LocaleCompare("type",option+1) == 0)
3011           {
3012             ImageType
3013               type;
3014
3015             (void) SyncImageSettings(mogrify_info,*image);
3016             if (*option == '+')
3017               type=UndefinedType;
3018             else
3019               type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3020                 argv[i+1]);
3021             (*image)->type=UndefinedType;
3022             (void) SetImageType(*image,type,exception);
3023             break;
3024           }
3025         break;
3026       }
3027       case 'u':
3028       {
3029         if (LocaleCompare("undercolor",option+1) == 0)
3030           {
3031             (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3032               exception);
3033             break;
3034           }
3035         if (LocaleCompare("unique",option+1) == 0)
3036           {
3037             if (*option == '+')
3038               {
3039                 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3040                 break;
3041               }
3042             (void) SetImageArtifact(*image,"identify:unique-colors","true");
3043             (void) SetImageArtifact(*image,"verbose","true");
3044             break;
3045           }
3046         if (LocaleCompare("unique-colors",option+1) == 0)
3047           {
3048             /*
3049               Unique image colors.
3050             */
3051             (void) SyncImageSettings(mogrify_info,*image);
3052             mogrify_image=UniqueImageColors(*image,exception);
3053             break;
3054           }
3055         if (LocaleCompare("unsharp",option+1) == 0)
3056           {
3057             /*
3058               Unsharp mask image.
3059             */
3060             (void) SyncImageSettings(mogrify_info,*image);
3061             flags=ParseGeometry(argv[i+1],&geometry_info);
3062             if ((flags & SigmaValue) == 0)
3063               geometry_info.sigma=1.0;
3064             if ((flags & XiValue) == 0)
3065               geometry_info.xi=1.0;
3066             if ((flags & PsiValue) == 0)
3067               geometry_info.psi=0.05;
3068             mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3069               geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
3070             break;
3071           }
3072         break;
3073       }
3074       case 'v':
3075       {
3076         if (LocaleCompare("verbose",option+1) == 0)
3077           {
3078             (void) SetImageArtifact(*image,option+1,
3079               *option == '+' ? "false" : "true");
3080             break;
3081           }
3082         if (LocaleCompare("vignette",option+1) == 0)
3083           {
3084             /*
3085               Vignette image.
3086             */
3087             (void) SyncImageSettings(mogrify_info,*image);
3088             flags=ParseGeometry(argv[i+1],&geometry_info);
3089             if ((flags & SigmaValue) == 0)
3090               geometry_info.sigma=1.0;
3091             if ((flags & XiValue) == 0)
3092               geometry_info.xi=0.1*(*image)->columns;
3093             if ((flags & PsiValue) == 0)
3094               geometry_info.psi=0.1*(*image)->rows;
3095             mogrify_image=VignetteImage(*image,geometry_info.rho,
3096               geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3097               ceil(geometry_info.psi-0.5),exception);
3098             break;
3099           }
3100         if (LocaleCompare("virtual-pixel",option+1) == 0)
3101           {
3102             if (*option == '+')
3103               {
3104                 (void) SetImageVirtualPixelMethod(*image,
3105                   UndefinedVirtualPixelMethod);
3106                 break;
3107               }
3108             (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3109               ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3110               argv[i+1]));
3111             break;
3112           }
3113         break;
3114       }
3115       case 'w':
3116       {
3117         if (LocaleCompare("wave",option+1) == 0)
3118           {
3119             /*
3120               Wave image.
3121             */
3122             (void) SyncImageSettings(mogrify_info,*image);
3123             flags=ParseGeometry(argv[i+1],&geometry_info);
3124             if ((flags & SigmaValue) == 0)
3125               geometry_info.sigma=1.0;
3126             mogrify_image=WaveImage(*image,geometry_info.rho,
3127               geometry_info.sigma,interpolate_method,exception);
3128             break;
3129           }
3130         if (LocaleCompare("weight",option+1) == 0)
3131           {
3132             draw_info->weight=StringToUnsignedLong(argv[i+1]);
3133             if (LocaleCompare(argv[i+1],"all") == 0)
3134               draw_info->weight=0;
3135             if (LocaleCompare(argv[i+1],"bold") == 0)
3136               draw_info->weight=700;
3137             if (LocaleCompare(argv[i+1],"bolder") == 0)
3138               if (draw_info->weight <= 800)
3139                 draw_info->weight+=100;
3140             if (LocaleCompare(argv[i+1],"lighter") == 0)
3141               if (draw_info->weight >= 100)
3142                 draw_info->weight-=100;
3143             if (LocaleCompare(argv[i+1],"normal") == 0)
3144               draw_info->weight=400;
3145             break;
3146           }
3147         if (LocaleCompare("white-threshold",option+1) == 0)
3148           {
3149             /*
3150               White threshold image.
3151             */
3152             (void) SyncImageSettings(mogrify_info,*image);
3153             (void) WhiteThresholdImage(*image,argv[i+1],exception);
3154             InheritException(exception,&(*image)->exception);
3155             break;
3156           }
3157         break;
3158       }
3159       default:
3160         break;
3161     }
3162     /*
3163        Replace current image with any image that was generated
3164     */
3165     if (mogrify_image != (Image *) NULL)
3166       ReplaceImageInListReturnLast(image,mogrify_image);
3167     i+=count;
3168   }
3169   if (region_image != (Image *) NULL)
3170     {
3171       /*
3172         Composite transformed region onto image.
3173       */
3174       (void) SyncImageSettings(mogrify_info,*image);
3175       (void) CompositeImage(region_image,region_image->matte !=
3176          MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3177          region_geometry.x,region_geometry.y);
3178       InheritException(exception,&region_image->exception);
3179       *image=DestroyImage(*image);
3180       *image=region_image;
3181       region_image = (Image *) NULL;
3182     }
3183   /*
3184     Free resources.
3185   */
3186   quantize_info=DestroyQuantizeInfo(quantize_info);
3187   draw_info=DestroyDrawInfo(draw_info);
3188   mogrify_info=DestroyImageInfo(mogrify_info);
3189   status=(MagickStatusType) ((*image)->exception.severity ==
3190     UndefinedException ? 1 : 0);
3191   return(status == 0 ? MagickFalse : MagickTrue);
3192 }
3193 \f
3194 /*
3195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3196 %                                                                             %
3197 %                                                                             %
3198 %                                                                             %
3199 +    M o g r i f y I m a g e C o m m a n d                                    %
3200 %                                                                             %
3201 %                                                                             %
3202 %                                                                             %
3203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3204 %
3205 %  MogrifyImageCommand() transforms an image or a sequence of images. These
3206 %  transforms include image scaling, image rotation, color reduction, and
3207 %  others. The transmogrified image overwrites the original image.
3208 %
3209 %  The format of the MogrifyImageCommand method is:
3210 %
3211 %      MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3212 %        const char **argv,char **metadata,ExceptionInfo *exception)
3213 %
3214 %  A description of each parameter follows:
3215 %
3216 %    o image_info: the image info.
3217 %
3218 %    o argc: the number of elements in the argument vector.
3219 %
3220 %    o argv: A text array containing the command line arguments.
3221 %
3222 %    o metadata: any metadata is returned here.
3223 %
3224 %    o exception: return any errors or warnings in this structure.
3225 %
3226 */
3227
3228 static MagickBooleanType MogrifyUsage(void)
3229 {
3230   static const char
3231     *miscellaneous[]=
3232     {
3233       "-debug events        display copious debugging information",
3234       "-help                print program options",
3235       "-list type           print a list of supported option arguments",
3236       "-log format          format of debugging information",
3237       "-version             print version information",
3238       (char *) NULL
3239     },
3240     *operators[]=
3241     {
3242       "-adaptive-blur geometry",
3243       "                     adaptively blur pixels; decrease effect near edges",
3244       "-adaptive-resize geometry",
3245       "                     adaptively resize image using 'mesh' interpolation",
3246       "-adaptive-sharpen geometry",
3247       "                     adaptively sharpen pixels; increase effect near edges",
3248       "-alpha option        on, activate, off, deactivate, set, opaque, copy",
3249       "                     transparent, extract, background, or shape",
3250       "-annotate geometry text",
3251       "                     annotate the image with text",
3252       "-auto-gamma          automagically adjust gamma level of image",
3253       "-auto-level          automagically adjust color levels of image",
3254       "-auto-orient         automagically orient (rotate) image",
3255       "-bench iterations    measure performance",
3256       "-black-threshold value",
3257       "                     force all pixels below the threshold into black",
3258       "-blue-shift          simulate a scene at nighttime in the moonlight",
3259       "-blur geometry       reduce image noise and reduce detail levels",
3260       "-border geometry     surround image with a border of color",
3261       "-bordercolor color   border color",
3262       "-brightness-contrast geometry",
3263       "                     improve brightness / contrast of the image",
3264       "-cdl filename        color correct with a color decision list",
3265       "-charcoal geometry   simulate a charcoal drawing",
3266       "-chop geometry       remove pixels from the image interior",
3267       "-clamp               restrict pixel range from 0 to the quantum depth",
3268       "-clip                clip along the first path from the 8BIM profile",
3269       "-clip-mask filename  associate a clip mask with the image",
3270       "-clip-path id        clip along a named path from the 8BIM profile",
3271       "-colorize value      colorize the image with the fill color",
3272       "-color-matrix matrix apply color correction to the image",
3273       "-contrast            enhance or reduce the image contrast",
3274       "-contrast-stretch geometry",
3275       "                     improve contrast by `stretching' the intensity range",
3276       "-convolve coefficients",
3277       "                     apply a convolution kernel to the image",
3278       "-cycle amount        cycle the image colormap",
3279       "-decipher filename   convert cipher pixels to plain pixels",
3280       "-deskew threshold    straighten an image",
3281       "-despeckle           reduce the speckles within an image",
3282       "-distort method args",
3283       "                     distort images according to given method ad args",
3284       "-draw string         annotate the image with a graphic primitive",
3285       "-edge radius         apply a filter to detect edges in the image",
3286       "-encipher filename   convert plain pixels to cipher pixels",
3287       "-emboss radius       emboss an image",
3288       "-enhance             apply a digital filter to enhance a noisy image",
3289       "-equalize            perform histogram equalization to an image",
3290       "-evaluate operator value",
3291       "                     evaluate an arithmetic, relational, or logical expression",
3292       "-extent geometry     set the image size",
3293       "-extract geometry    extract area from image",
3294       "-fft                 implements the discrete Fourier transform (DFT)",
3295       "-flip                flip image vertically",
3296       "-floodfill geometry color",
3297       "                     floodfill the image with color",
3298       "-flop                flop image horizontally",
3299       "-frame geometry      surround image with an ornamental border",
3300       "-function name parameters",
3301       "                     apply function over image values",
3302       "-gamma value         level of gamma correction",
3303       "-gaussian-blur geometry",
3304       "                     reduce image noise and reduce detail levels",
3305       "-geometry geometry   preferred size or location of the image",
3306       "-identify            identify the format and characteristics of the image",
3307       "-ift                 implements the inverse discrete Fourier transform (DFT)",
3308       "-implode amount      implode image pixels about the center",
3309       "-lat geometry        local adaptive thresholding",
3310       "-layers method       optimize, merge,  or compare image layers",
3311       "-level value         adjust the level of image contrast",
3312       "-level-colors color,color",
3313       "                     level image with the given colors",
3314       "-linear-stretch geometry",
3315       "                     improve contrast by `stretching with saturation'",
3316       "-liquid-rescale geometry",
3317       "                     rescale image with seam-carving",
3318       "-median geometry     apply a median filter to the image",
3319       "-mode geometry       make each pixel the 'predominant color' of the neighborhood",
3320       "-modulate value      vary the brightness, saturation, and hue",
3321       "-monochrome          transform image to black and white",
3322       "-morphology method kernel",
3323       "                     apply a morphology method to the image",
3324       "-motion-blur geometry",
3325       "                     simulate motion blur",
3326       "-negate              replace every pixel with its complementary color ",
3327       "-noise geometry      add or reduce noise in an image",
3328       "-normalize           transform image to span the full range of colors",
3329       "-opaque color        change this color to the fill color",
3330       "-ordered-dither NxN",
3331       "                     add a noise pattern to the image with specific",
3332       "                     amplitudes",
3333       "-paint radius        simulate an oil painting",
3334       "-polaroid angle      simulate a Polaroid picture",
3335       "-posterize levels    reduce the image to a limited number of color levels",
3336       "-profile filename    add, delete, or apply an image profile",
3337       "-quantize colorspace reduce colors in this colorspace",
3338       "-radial-blur angle   radial blur the image",
3339       "-raise value         lighten/darken image edges to create a 3-D effect",
3340       "-random-threshold low,high",
3341       "                     random threshold the image",
3342       "-region geometry     apply options to a portion of the image",
3343       "-render              render vector graphics",
3344       "-repage geometry     size and location of an image canvas",
3345       "-resample geometry   change the resolution of an image",
3346       "-resize geometry     resize the image",
3347       "-roll geometry       roll an image vertically or horizontally",
3348       "-rotate degrees      apply Paeth rotation to the image",
3349       "-sample geometry     scale image with pixel sampling",
3350       "-scale geometry      scale the image",
3351       "-segment values      segment an image",
3352       "-selective-blur geometry",
3353       "                     selectively blur pixels within a contrast threshold",
3354       "-sepia-tone threshold",
3355       "                     simulate a sepia-toned photo",
3356       "-set property value  set an image property",
3357       "-shade degrees       shade the image using a distant light source",
3358       "-shadow geometry     simulate an image shadow",
3359       "-sharpen geometry    sharpen the image",
3360       "-shave geometry      shave pixels from the image edges",
3361       "-shear geometry      slide one edge of the image along the X or Y axis",
3362       "-sigmoidal-contrast geometry",
3363       "                     increase the contrast without saturating highlights or shadows",
3364       "-sketch geometry     simulate a pencil sketch",
3365       "-solarize threshold  negate all pixels above the threshold level",
3366       "-sparse-color method args",
3367       "                     fill in a image based on a few color points",
3368       "-splice geometry     splice the background color into the image",
3369       "-spread radius       displace image pixels by a random amount",
3370       "-statistic type radius",
3371       "                     replace each pixel with corresponding statistic from the neighborhood",
3372       "-strip               strip image of all profiles and comments",
3373       "-swirl degrees       swirl image pixels about the center",
3374       "-threshold value     threshold the image",
3375       "-thumbnail geometry  create a thumbnail of the image",
3376       "-tile filename       tile image when filling a graphic primitive",
3377       "-tint value          tint the image with the fill color",
3378       "-transform           affine transform image",
3379       "-transparent color   make this color transparent within the image",
3380       "-transpose           flip image vertically and rotate 90 degrees",
3381       "-transverse          flop image horizontally and rotate 270 degrees",
3382       "-trim                trim image edges",
3383       "-type type           image type",
3384       "-unique-colors       discard all but one of any pixel color",
3385       "-unsharp geometry    sharpen the image",
3386       "-vignette geometry   soften the edges of the image in vignette style",
3387       "-wave geometry       alter an image along a sine wave",
3388       "-white-threshold value",
3389       "                     force all pixels above the threshold into white",
3390       (char *) NULL
3391     },
3392     *sequence_operators[]=
3393     {
3394       "-append              append an image sequence",
3395       "-clut                apply a color lookup table to the image",
3396       "-coalesce            merge a sequence of images",
3397       "-combine             combine a sequence of images",
3398       "-composite           composite image",
3399       "-crop geometry       cut out a rectangular region of the image",
3400       "-deconstruct         break down an image sequence into constituent parts",
3401       "-evaluate-sequence operator",
3402       "                     evaluate an arithmetic, relational, or logical expression",
3403       "-flatten             flatten a sequence of images",
3404       "-fx expression       apply mathematical expression to an image channel(s)",
3405       "-hald-clut           apply a Hald color lookup table to the image",
3406       "-morph value         morph an image sequence",
3407       "-mosaic              create a mosaic from an image sequence",
3408       "-print string        interpret string and print to console",
3409       "-process arguments   process the image with a custom image filter",
3410       "-separate            separate an image channel into a grayscale image",
3411       "-smush geometry      smush an image sequence together",
3412       "-write filename      write images to this file",
3413       (char *) NULL
3414     },
3415     *settings[]=
3416     {
3417       "-adjoin              join images into a single multi-image file",
3418       "-affine matrix       affine transform matrix",
3419       "-alpha option        activate, deactivate, reset, or set the alpha channel",
3420       "-antialias           remove pixel-aliasing",
3421       "-authenticate password",
3422       "                     decipher image with this password",
3423       "-attenuate value     lessen (or intensify) when adding noise to an image",
3424       "-background color    background color",
3425       "-bias value          add bias when convolving an image",
3426       "-black-point-compensation",
3427       "                     use black point compensation",
3428       "-blue-primary point  chromaticity blue primary point",
3429       "-bordercolor color   border color",
3430       "-caption string      assign a caption to an image",
3431       "-channel type        apply option to select image channels",
3432       "-colors value        preferred number of colors in the image",
3433       "-colorspace type     alternate image colorspace",
3434       "-comment string      annotate image with comment",
3435       "-compose operator    set image composite operator",
3436       "-compress type       type of pixel compression when writing the image",
3437       "-define format:option",
3438       "                     define one or more image format options",
3439       "-delay value         display the next image after pausing",
3440       "-density geometry    horizontal and vertical density of the image",
3441       "-depth value         image depth",
3442       "-direction type      render text right-to-left or left-to-right",
3443       "-display server      get image or font from this X server",
3444       "-dispose method      layer disposal method",
3445       "-dither method       apply error diffusion to image",
3446       "-encoding type       text encoding type",
3447       "-endian type         endianness (MSB or LSB) of the image",
3448       "-family name         render text with this font family",
3449       "-fill color          color to use when filling a graphic primitive",
3450       "-filter type         use this filter when resizing an image",
3451       "-font name           render text with this font",
3452       "-format \"string\"     output formatted image characteristics",
3453       "-fuzz distance       colors within this distance are considered equal",
3454       "-gravity type        horizontal and vertical text placement",
3455       "-green-primary point chromaticity green primary point",
3456       "-intent type         type of rendering intent when managing the image color",
3457       "-interlace type      type of image interlacing scheme",
3458       "-interline-spacing value",
3459       "                     set the space between two text lines",
3460       "-interpolate method  pixel color interpolation method",
3461       "-interword-spacing value",
3462       "                     set the space between two words",
3463       "-kerning value       set the space between two letters",
3464       "-label string        assign a label to an image",
3465       "-limit type value    pixel cache resource limit",
3466       "-loop iterations     add Netscape loop extension to your GIF animation",
3467       "-mask filename       associate a mask with the image",
3468       "-mattecolor color    frame color",
3469       "-monitor             monitor progress",
3470       "-orient type         image orientation",
3471       "-page geometry       size and location of an image canvas (setting)",
3472       "-ping                efficiently determine image attributes",
3473       "-pointsize value     font point size",
3474       "-precision value     maximum number of significant digits to print",
3475       "-preview type        image preview type",
3476       "-quality value       JPEG/MIFF/PNG compression level",
3477       "-quiet               suppress all warning messages",
3478       "-red-primary point   chromaticity red primary point",
3479       "-regard-warnings     pay attention to warning messages",
3480       "-remap filename      transform image colors to match this set of colors",
3481       "-respect-parentheses settings remain in effect until parenthesis boundary",
3482       "-sampling-factor geometry",
3483       "                     horizontal and vertical sampling factor",
3484       "-scene value         image scene number",
3485       "-seed value          seed a new sequence of pseudo-random numbers",
3486       "-size geometry       width and height of image",
3487       "-stretch type        render text with this font stretch",
3488       "-stroke color        graphic primitive stroke color",
3489       "-strokewidth value   graphic primitive stroke width",
3490       "-style type          render text with this font style",
3491       "-synchronize         synchronize image to storage device",
3492       "-taint               declare the image as modified",
3493       "-texture filename    name of texture to tile onto the image background",
3494       "-tile-offset geometry",
3495       "                     tile offset",
3496       "-treedepth value     color tree depth",
3497       "-transparent-color color",
3498       "                     transparent color",
3499       "-undercolor color    annotation bounding box color",
3500       "-units type          the units of image resolution",
3501       "-verbose             print detailed information about the image",
3502       "-view                FlashPix viewing transforms",
3503       "-virtual-pixel method",
3504       "                     virtual pixel access method",
3505       "-weight type         render text with this font weight",
3506       "-white-point point   chromaticity white point",
3507       (char *) NULL
3508     },
3509     *stack_operators[]=
3510     {
3511       "-delete indexes      delete the image from the image sequence",
3512       "-duplicate count,indexes",
3513       "                     duplicate an image one or more times",
3514       "-insert index        insert last image into the image sequence",
3515       "-reverse             reverse image sequence",
3516       "-swap indexes        swap two images in the image sequence",
3517       (char *) NULL
3518     };
3519
3520   const char
3521     **p;
3522
3523   (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
3524   (void) printf("Copyright: %s\n",GetMagickCopyright());
3525   (void) printf("Features: %s\n\n",GetMagickFeatures());
3526   (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3527     GetClientName());
3528   (void) printf("\nImage Settings:\n");
3529   for (p=settings; *p != (char *) NULL; p++)
3530     (void) printf("  %s\n",*p);
3531   (void) printf("\nImage Operators:\n");
3532   for (p=operators; *p != (char *) NULL; p++)
3533     (void) printf("  %s\n",*p);
3534   (void) printf("\nImage Sequence Operators:\n");
3535   for (p=sequence_operators; *p != (char *) NULL; p++)
3536     (void) printf("  %s\n",*p);
3537   (void) printf("\nImage Stack Operators:\n");
3538   for (p=stack_operators; *p != (char *) NULL; p++)
3539     (void) printf("  %s\n",*p);
3540   (void) printf("\nMiscellaneous Options:\n");
3541   for (p=miscellaneous; *p != (char *) NULL; p++)
3542     (void) printf("  %s\n",*p);
3543   (void) printf(
3544     "\nBy default, the image format of `file' is determined by its magic\n");
3545   (void) printf(
3546     "number.  To specify a particular image format, precede the filename\n");
3547   (void) printf(
3548     "with an image format name and a colon (i.e. ps:image) or specify the\n");
3549   (void) printf(
3550     "image type as the filename suffix (i.e. image.ps).  Specify 'file' as\n");
3551   (void) printf("'-' for standard input or output.\n");
3552   return(MagickFalse);
3553 }
3554
3555 WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3556   int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3557 {
3558 #define DestroyMogrify() \
3559 { \
3560   if (format != (char *) NULL) \
3561     format=DestroyString(format); \
3562   if (path != (char *) NULL) \
3563     path=DestroyString(path); \
3564   DestroyImageStack(); \
3565   for (i=0; i < (ssize_t) argc; i++) \
3566     argv[i]=DestroyString(argv[i]); \
3567   argv=(char **) RelinquishMagickMemory(argv); \
3568 }
3569 #define ThrowMogrifyException(asperity,tag,option) \
3570 { \
3571   (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3572     option); \
3573   DestroyMogrify(); \
3574   return(MagickFalse); \
3575 }
3576 #define ThrowMogrifyInvalidArgumentException(option,argument) \
3577 { \
3578   (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3579     "InvalidArgument","`%s': %s",argument,option); \
3580   DestroyMogrify(); \
3581   return(MagickFalse); \
3582 }
3583
3584   char
3585     *format,
3586     *option,
3587     *path;
3588
3589   Image
3590     *image;
3591
3592   ImageStack
3593     image_stack[MaxImageStackDepth+1];
3594
3595   MagickBooleanType
3596     global_colormap;
3597
3598   MagickBooleanType
3599     fire,
3600     pend,
3601     respect_parenthesis;
3602
3603   MagickStatusType
3604     status;
3605
3606   register ssize_t
3607     i;
3608
3609   ssize_t
3610     j,
3611     k;
3612
3613   /*
3614     Set defaults.
3615   */
3616   assert(image_info != (ImageInfo *) NULL);
3617   assert(image_info->signature == MagickSignature);
3618   if (image_info->debug != MagickFalse)
3619     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3620   assert(exception != (ExceptionInfo *) NULL);
3621   if (argc == 2)
3622     {
3623       option=argv[1];
3624       if ((LocaleCompare("version",option+1) == 0) ||
3625           (LocaleCompare("-version",option+1) == 0))
3626         {
3627           (void) FormatLocaleFile(stdout,"Version: %s\n",
3628             GetMagickVersion((size_t *) NULL));
3629           (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3630             GetMagickCopyright());
3631           (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3632             GetMagickFeatures());
3633           return(MagickFalse);
3634         }
3635     }
3636   if (argc < 2)
3637     return(MogrifyUsage());
3638   format=(char *) NULL;
3639   path=(char *) NULL;
3640   global_colormap=MagickFalse;
3641   k=0;
3642   j=1;
3643   NewImageStack();
3644   option=(char *) NULL;
3645   pend=MagickFalse;
3646   respect_parenthesis=MagickFalse;
3647   status=MagickTrue;
3648   /*
3649     Parse command line.
3650   */
3651   ReadCommandlLine(argc,&argv);
3652   status=ExpandFilenames(&argc,&argv);
3653   if (status == MagickFalse)
3654     ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3655       GetExceptionMessage(errno));
3656   for (i=1; i < (ssize_t) argc; i++)
3657   {
3658     option=argv[i];
3659     if (LocaleCompare(option,"(") == 0)
3660       {
3661         FireImageStack(MagickFalse,MagickTrue,pend);
3662         if (k == MaxImageStackDepth)
3663           ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3664             option);
3665         PushImageStack();
3666         continue;
3667       }
3668     if (LocaleCompare(option,")") == 0)
3669       {
3670         FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3671         if (k == 0)
3672           ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3673         PopImageStack();
3674         continue;
3675       }
3676     if (IsCommandOption(option) == MagickFalse)
3677       {
3678         char
3679           backup_filename[MaxTextExtent],
3680           *filename;
3681
3682         Image
3683           *images;
3684
3685         /*
3686           Option is a file name: begin by reading image from specified file.
3687         */
3688         FireImageStack(MagickFalse,MagickFalse,pend);
3689         filename=argv[i];
3690         if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
3691           filename=argv[++i];
3692         (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3693         images=ReadImages(image_info,exception);
3694         status&=(images != (Image *) NULL) &&
3695           (exception->severity < ErrorException);
3696         if (images == (Image *) NULL)
3697           continue;
3698         if (format != (char *) NULL)
3699           (void) CopyMagickString(images->filename,images->magick_filename,
3700             MaxTextExtent);
3701         if (path != (char *) NULL)
3702           {
3703             GetPathComponent(option,TailPath,filename);
3704             (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
3705               path,*DirectorySeparator,filename);
3706           }
3707         if (format != (char *) NULL)
3708           AppendImageFormat(format,images->filename);
3709         AppendImageStack(images);
3710         FinalizeImageSettings(image_info,image,MagickFalse);
3711         if (global_colormap != MagickFalse)
3712           {
3713             QuantizeInfo
3714               *quantize_info;
3715
3716             quantize_info=AcquireQuantizeInfo(image_info);
3717             (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
3718             quantize_info=DestroyQuantizeInfo(quantize_info);
3719           }
3720         *backup_filename='\0';
3721         if ((LocaleCompare(image->filename,"-") != 0) &&
3722             (IsPathWritable(image->filename) != MagickFalse))
3723           {
3724             register ssize_t
3725               i;
3726
3727             /*
3728               Rename image file as backup.
3729             */
3730             (void) CopyMagickString(backup_filename,image->filename,
3731               MaxTextExtent);
3732             for (i=0; i < 6; i++)
3733             {
3734               (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3735               if (IsPathAccessible(backup_filename) == MagickFalse)
3736                 break;
3737             }
3738             if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3739                 (rename_utf8(image->filename,backup_filename) != 0))
3740               *backup_filename='\0';
3741           }
3742         /*
3743           Write transmogrified image to disk.
3744         */
3745         image_info->synchronize=MagickTrue;
3746         status&=WriteImages(image_info,image,image->filename,exception);
3747         if ((status == MagickFalse) && (*backup_filename != '\0'))
3748           (void) remove_utf8(backup_filename);
3749         RemoveAllImageStack();
3750         continue;
3751       }
3752     pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3753     switch (*(option+1))
3754     {
3755       case 'a':
3756       {
3757         if (LocaleCompare("adaptive-blur",option+1) == 0)
3758           {
3759             i++;
3760             if (i == (ssize_t) argc)
3761               ThrowMogrifyException(OptionError,"MissingArgument",option);
3762             if (IsGeometry(argv[i]) == MagickFalse)
3763               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3764             break;
3765           }
3766         if (LocaleCompare("adaptive-resize",option+1) == 0)
3767           {
3768             i++;
3769             if (i == (ssize_t) argc)
3770               ThrowMogrifyException(OptionError,"MissingArgument",option);
3771             if (IsGeometry(argv[i]) == MagickFalse)
3772               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3773             break;
3774           }
3775         if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3776           {
3777             i++;
3778             if (i == (ssize_t) argc)
3779               ThrowMogrifyException(OptionError,"MissingArgument",option);
3780             if (IsGeometry(argv[i]) == MagickFalse)
3781               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3782             break;
3783           }
3784         if (LocaleCompare("affine",option+1) == 0)
3785           {
3786             if (*option == '+')
3787               break;
3788             i++;
3789             if (i == (ssize_t) argc)
3790               ThrowMogrifyException(OptionError,"MissingArgument",option);
3791             break;
3792           }
3793         if (LocaleCompare("alpha",option+1) == 0)
3794           {
3795             ssize_t
3796               type;
3797
3798             if (*option == '+')
3799               break;
3800             i++;
3801             if (i == (ssize_t) argc)
3802               ThrowMogrifyException(OptionError,"MissingArgument",option);
3803             type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
3804             if (type < 0)
3805               ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3806                 argv[i]);
3807             break;
3808           }
3809         if (LocaleCompare("annotate",option+1) == 0)
3810           {
3811             if (*option == '+')
3812               break;
3813             i++;
3814             if (i == (ssize_t) argc)
3815               ThrowMogrifyException(OptionError,"MissingArgument",option);
3816             if (IsGeometry(argv[i]) == MagickFalse)
3817               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3818             if (i == (ssize_t) argc)
3819               ThrowMogrifyException(OptionError,"MissingArgument",option);
3820             i++;
3821             break;
3822           }
3823         if (LocaleCompare("antialias",option+1) == 0)
3824           break;
3825         if (LocaleCompare("append",option+1) == 0)
3826           break;
3827         if (LocaleCompare("attenuate",option+1) == 0)
3828           {
3829             if (*option == '+')
3830               break;
3831             i++;
3832             if (i == (ssize_t) (argc-1))
3833               ThrowMogrifyException(OptionError,"MissingArgument",option);
3834             if (IsGeometry(argv[i]) == MagickFalse)
3835               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3836             break;
3837           }
3838         if (LocaleCompare("authenticate",option+1) == 0)
3839           {
3840             if (*option == '+')
3841               break;
3842             i++;
3843             if (i == (ssize_t) argc)
3844               ThrowMogrifyException(OptionError,"MissingArgument",option);
3845             break;
3846           }
3847         if (LocaleCompare("auto-gamma",option+1) == 0)
3848           break;
3849         if (LocaleCompare("auto-level",option+1) == 0)
3850           break;
3851         if (LocaleCompare("auto-orient",option+1) == 0)
3852           break;
3853         if (LocaleCompare("average",option+1) == 0)
3854           break;
3855         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3856       }
3857       case 'b':
3858       {
3859         if (LocaleCompare("background",option+1) == 0)
3860           {
3861             if (*option == '+')
3862               break;
3863             i++;
3864             if (i == (ssize_t) argc)
3865               ThrowMogrifyException(OptionError,"MissingArgument",option);
3866             break;
3867           }
3868         if (LocaleCompare("bias",option+1) == 0)
3869           {
3870             if (*option == '+')
3871               break;
3872             i++;
3873             if (i == (ssize_t) (argc-1))
3874               ThrowMogrifyException(OptionError,"MissingArgument",option);
3875             if (IsGeometry(argv[i]) == MagickFalse)
3876               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3877             break;
3878           }
3879         if (LocaleCompare("black-point-compensation",option+1) == 0)
3880           break;
3881         if (LocaleCompare("black-threshold",option+1) == 0)
3882           {
3883             if (*option == '+')
3884               break;
3885             i++;
3886             if (i == (ssize_t) argc)
3887               ThrowMogrifyException(OptionError,"MissingArgument",option);
3888             if (IsGeometry(argv[i]) == MagickFalse)
3889               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3890             break;
3891           }
3892         if (LocaleCompare("blue-primary",option+1) == 0)
3893           {
3894             if (*option == '+')
3895               break;
3896             i++;
3897             if (i == (ssize_t) argc)
3898               ThrowMogrifyException(OptionError,"MissingArgument",option);
3899             if (IsGeometry(argv[i]) == MagickFalse)
3900               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3901             break;
3902           }
3903         if (LocaleCompare("blue-shift",option+1) == 0)
3904           {
3905             i++;
3906             if (i == (ssize_t) argc)
3907               ThrowMogrifyException(OptionError,"MissingArgument",option);
3908             if (IsGeometry(argv[i]) == MagickFalse)
3909               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3910             break;
3911           }
3912         if (LocaleCompare("blur",option+1) == 0)
3913           {
3914             i++;
3915             if (i == (ssize_t) argc)
3916               ThrowMogrifyException(OptionError,"MissingArgument",option);
3917             if (IsGeometry(argv[i]) == MagickFalse)
3918               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3919             break;
3920           }
3921         if (LocaleCompare("border",option+1) == 0)
3922           {
3923             if (*option == '+')
3924               break;
3925             i++;
3926             if (i == (ssize_t) argc)
3927               ThrowMogrifyException(OptionError,"MissingArgument",option);
3928             if (IsGeometry(argv[i]) == MagickFalse)
3929               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3930             break;
3931           }
3932         if (LocaleCompare("bordercolor",option+1) == 0)
3933           {
3934             if (*option == '+')
3935               break;
3936             i++;
3937             if (i == (ssize_t) argc)
3938               ThrowMogrifyException(OptionError,"MissingArgument",option);
3939             break;
3940           }
3941         if (LocaleCompare("box",option+1) == 0)
3942           {
3943             if (*option == '+')
3944               break;
3945             i++;
3946             if (i == (ssize_t) argc)
3947               ThrowMogrifyException(OptionError,"MissingArgument",option);
3948             break;
3949           }
3950         if (LocaleCompare("brightness-contrast",option+1) == 0)
3951           {
3952             i++;
3953             if (i == (ssize_t) argc)
3954               ThrowMogrifyException(OptionError,"MissingArgument",option);
3955             if (IsGeometry(argv[i]) == MagickFalse)
3956               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3957             break;
3958           }
3959         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3960       }
3961       case 'c':
3962       {
3963         if (LocaleCompare("cache",option+1) == 0)
3964           {
3965             if (*option == '+')
3966               break;
3967             i++;
3968             if (i == (ssize_t) argc)
3969               ThrowMogrifyException(OptionError,"MissingArgument",option);
3970             if (IsGeometry(argv[i]) == MagickFalse)
3971               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3972             break;
3973           }
3974         if (LocaleCompare("caption",option+1) == 0)
3975           {
3976             if (*option == '+')
3977               break;
3978             i++;
3979             if (i == (ssize_t) argc)
3980               ThrowMogrifyException(OptionError,"MissingArgument",option);
3981             break;
3982           }
3983         if (LocaleCompare("channel",option+1) == 0)
3984           {
3985             ssize_t
3986               channel;
3987
3988             if (*option == '+')
3989               break;
3990             i++;
3991             if (i == (ssize_t) (argc-1))
3992               ThrowMogrifyException(OptionError,"MissingArgument",option);
3993             channel=ParseChannelOption(argv[i]);
3994             if (channel < 0)
3995               ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3996                 argv[i]);
3997             break;
3998           }
3999         if (LocaleCompare("cdl",option+1) == 0)
4000           {
4001             if (*option == '+')
4002               break;
4003             i++;
4004             if (i == (ssize_t) (argc-1))
4005               ThrowMogrifyException(OptionError,"MissingArgument",option);
4006             break;
4007           }
4008         if (LocaleCompare("charcoal",option+1) == 0)
4009           {
4010             if (*option == '+')
4011               break;
4012             i++;
4013             if (i == (ssize_t) argc)
4014               ThrowMogrifyException(OptionError,"MissingArgument",option);
4015             if (IsGeometry(argv[i]) == MagickFalse)
4016               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4017             break;
4018           }
4019         if (LocaleCompare("chop",option+1) == 0)
4020           {
4021             if (*option == '+')
4022               break;
4023             i++;
4024             if (i == (ssize_t) argc)
4025               ThrowMogrifyException(OptionError,"MissingArgument",option);
4026             if (IsGeometry(argv[i]) == MagickFalse)
4027               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4028             break;
4029           }
4030         if (LocaleCompare("clamp",option+1) == 0)
4031           break;
4032         if (LocaleCompare("clip",option+1) == 0)
4033           break;
4034         if (LocaleCompare("clip-mask",option+1) == 0)
4035           {
4036             if (*option == '+')
4037               break;
4038             i++;
4039             if (i == (ssize_t) argc)
4040               ThrowMogrifyException(OptionError,"MissingArgument",option);
4041             break;
4042           }
4043         if (LocaleCompare("clut",option+1) == 0)
4044           break;
4045         if (LocaleCompare("coalesce",option+1) == 0)
4046           break;
4047         if (LocaleCompare("colorize",option+1) == 0)
4048           {
4049             if (*option == '+')
4050               break;
4051             i++;
4052             if (i == (ssize_t) argc)
4053               ThrowMogrifyException(OptionError,"MissingArgument",option);
4054             if (IsGeometry(argv[i]) == MagickFalse)
4055               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4056             break;
4057           }
4058         if (LocaleCompare("color-matrix",option+1) == 0)
4059           {
4060             KernelInfo
4061               *kernel_info;
4062
4063             if (*option == '+')
4064               break;
4065             i++;
4066             if (i == (ssize_t) (argc-1))
4067               ThrowMogrifyException(OptionError,"MissingArgument",option);
4068             kernel_info=AcquireKernelInfo(argv[i]);
4069             if (kernel_info == (KernelInfo *) NULL)
4070               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4071             kernel_info=DestroyKernelInfo(kernel_info);
4072             break;
4073           }
4074         if (LocaleCompare("colors",option+1) == 0)
4075           {
4076             if (*option == '+')
4077               break;
4078             i++;
4079             if (i == (ssize_t) argc)
4080               ThrowMogrifyException(OptionError,"MissingArgument",option);
4081             if (IsGeometry(argv[i]) == MagickFalse)
4082               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4083             break;
4084           }
4085         if (LocaleCompare("colorspace",option+1) == 0)
4086           {
4087             ssize_t
4088               colorspace;
4089
4090             if (*option == '+')
4091               break;
4092             i++;
4093             if (i == (ssize_t) argc)
4094               ThrowMogrifyException(OptionError,"MissingArgument",option);
4095             colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4096               argv[i]);
4097             if (colorspace < 0)
4098               ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4099                 argv[i]);
4100             break;
4101           }
4102         if (LocaleCompare("combine",option+1) == 0)
4103           break;
4104         if (LocaleCompare("comment",option+1) == 0)
4105           {
4106             if (*option == '+')
4107               break;
4108             i++;
4109             if (i == (ssize_t) argc)
4110               ThrowMogrifyException(OptionError,"MissingArgument",option);
4111             break;
4112           }
4113         if (LocaleCompare("composite",option+1) == 0)
4114           break;
4115         if (LocaleCompare("compress",option+1) == 0)
4116           {
4117             ssize_t
4118               compress;
4119
4120             if (*option == '+')
4121               break;
4122             i++;
4123             if (i == (ssize_t) argc)
4124               ThrowMogrifyException(OptionError,"MissingArgument",option);
4125             compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
4126               argv[i]);
4127             if (compress < 0)
4128               ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4129                 argv[i]);
4130             break;
4131           }
4132         if (LocaleCompare("concurrent",option+1) == 0)
4133           break;
4134         if (LocaleCompare("contrast",option+1) == 0)
4135           break;
4136         if (LocaleCompare("contrast-stretch",option+1) == 0)
4137           {
4138             i++;
4139             if (i == (ssize_t) argc)
4140               ThrowMogrifyException(OptionError,"MissingArgument",option);
4141             if (IsGeometry(argv[i]) == MagickFalse)
4142               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4143             break;
4144           }
4145         if (LocaleCompare("convolve",option+1) == 0)
4146           {
4147             KernelInfo
4148               *kernel_info;
4149
4150             if (*option == '+')
4151               break;
4152             i++;
4153             if (i == (ssize_t) argc)
4154               ThrowMogrifyException(OptionError,"MissingArgument",option);
4155             kernel_info=AcquireKernelInfo(argv[i]);
4156             if (kernel_info == (KernelInfo *) NULL)
4157               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4158             kernel_info=DestroyKernelInfo(kernel_info);
4159             break;
4160           }
4161         if (LocaleCompare("crop",option+1) == 0)
4162           {
4163             if (*option == '+')
4164               break;
4165             i++;
4166             if (i == (ssize_t) argc)
4167               ThrowMogrifyException(OptionError,"MissingArgument",option);
4168             if (IsGeometry(argv[i]) == MagickFalse)
4169               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4170             break;
4171           }
4172         if (LocaleCompare("cycle",option+1) == 0)
4173           {
4174             if (*option == '+')
4175               break;
4176             i++;
4177             if (i == (ssize_t) argc)
4178               ThrowMogrifyException(OptionError,"MissingArgument",option);
4179             if (IsGeometry(argv[i]) == MagickFalse)
4180               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4181             break;
4182           }
4183         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4184       }
4185       case 'd':
4186       {
4187         if (LocaleCompare("decipher",option+1) == 0)
4188           {
4189             if (*option == '+')
4190               break;
4191             i++;
4192             if (i == (ssize_t) (argc-1))
4193               ThrowMogrifyException(OptionError,"MissingArgument",option);
4194             break;
4195           }
4196         if (LocaleCompare("deconstruct",option+1) == 0)
4197           break;
4198         if (LocaleCompare("debug",option+1) == 0)
4199           {
4200             ssize_t
4201               event;
4202
4203             if (*option == '+')
4204               break;
4205             i++;
4206             if (i == (ssize_t) argc)
4207               ThrowMogrifyException(OptionError,"MissingArgument",option);
4208             event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
4209             if (event < 0)
4210               ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4211                 argv[i]);
4212             (void) SetLogEventMask(argv[i]);
4213             break;
4214           }
4215         if (LocaleCompare("define",option+1) == 0)
4216           {
4217             i++;
4218             if (i == (ssize_t) argc)
4219               ThrowMogrifyException(OptionError,"MissingArgument",option);
4220             if (*option == '+')
4221               {
4222                 const char
4223                   *define;
4224
4225                 define=GetImageOption(image_info,argv[i]);
4226                 if (define == (const char *) NULL)
4227                   ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4228                 break;
4229               }
4230             break;
4231           }
4232         if (LocaleCompare("delay",option+1) == 0)
4233           {
4234             if (*option == '+')
4235               break;
4236             i++;
4237             if (i == (ssize_t) argc)
4238               ThrowMogrifyException(OptionError,"MissingArgument",option);
4239             if (IsGeometry(argv[i]) == MagickFalse)
4240               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4241             break;
4242           }
4243         if (LocaleCompare("delete",option+1) == 0)
4244           {
4245             if (*option == '+')
4246               break;
4247             i++;
4248             if (i == (ssize_t) (argc-1))
4249               ThrowMogrifyException(OptionError,"MissingArgument",option);
4250             if (IsGeometry(argv[i]) == MagickFalse)
4251               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4252             break;
4253           }
4254         if (LocaleCompare("density",option+1) == 0)
4255           {
4256             if (*option == '+')
4257               break;
4258             i++;
4259             if (i == (ssize_t) argc)
4260               ThrowMogrifyException(OptionError,"MissingArgument",option);
4261             if (IsGeometry(argv[i]) == MagickFalse)
4262               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4263             break;
4264           }
4265         if (LocaleCompare("depth",option+1) == 0)
4266           {
4267             if (*option == '+')
4268               break;
4269             i++;
4270             if (i == (ssize_t) argc)
4271               ThrowMogrifyException(OptionError,"MissingArgument",option);
4272             if (IsGeometry(argv[i]) == MagickFalse)
4273               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4274             break;
4275           }
4276         if (LocaleCompare("deskew",option+1) == 0)
4277           {
4278             if (*option == '+')
4279               break;
4280             i++;
4281             if (i == (ssize_t) argc)
4282               ThrowMogrifyException(OptionError,"MissingArgument",option);
4283             if (IsGeometry(argv[i]) == MagickFalse)
4284               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4285             break;
4286           }
4287         if (LocaleCompare("despeckle",option+1) == 0)
4288           break;
4289         if (LocaleCompare("dft",option+1) == 0)
4290           break;
4291         if (LocaleCompare("direction",option+1) == 0)
4292           {
4293             ssize_t
4294               direction;
4295
4296             if (*option == '+')
4297               break;
4298             i++;
4299             if (i == (ssize_t) argc)
4300               ThrowMogrifyException(OptionError,"MissingArgument",option);
4301             direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
4302               argv[i]);
4303             if (direction < 0)
4304               ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4305                 argv[i]);
4306             break;
4307           }
4308         if (LocaleCompare("display",option+1) == 0)
4309           {
4310             if (*option == '+')
4311               break;
4312             i++;
4313             if (i == (ssize_t) argc)
4314               ThrowMogrifyException(OptionError,"MissingArgument",option);
4315             break;
4316           }
4317         if (LocaleCompare("dispose",option+1) == 0)
4318           {
4319             ssize_t
4320               dispose;
4321
4322             if (*option == '+')
4323               break;
4324             i++;
4325             if (i == (ssize_t) argc)
4326               ThrowMogrifyException(OptionError,"MissingArgument",option);
4327             dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
4328             if (dispose < 0)
4329               ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4330                 argv[i]);
4331             break;
4332           }
4333         if (LocaleCompare("distort",option+1) == 0)
4334           {
4335             ssize_t
4336               op;
4337
4338             i++;
4339             if (i == (ssize_t) argc)
4340               ThrowMogrifyException(OptionError,"MissingArgument",option);
4341             op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
4342             if (op < 0)
4343               ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4344                 argv[i]);
4345             i++;
4346             if (i == (ssize_t) (argc-1))
4347               ThrowMogrifyException(OptionError,"MissingArgument",option);
4348             break;
4349           }
4350         if (LocaleCompare("dither",option+1) == 0)
4351           {
4352             ssize_t
4353               method;
4354
4355             if (*option == '+')
4356               break;
4357             i++;
4358             if (i == (ssize_t) argc)
4359               ThrowMogrifyException(OptionError,"MissingArgument",option);
4360             method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
4361             if (method < 0)
4362               ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4363                 argv[i]);
4364             break;
4365           }
4366         if (LocaleCompare("draw",option+1) == 0)
4367           {
4368             if (*option == '+')
4369               break;
4370             i++;
4371             if (i == (ssize_t) argc)
4372               ThrowMogrifyException(OptionError,"MissingArgument",option);
4373             break;
4374           }
4375         if (LocaleCompare("duplicate",option+1) == 0)
4376           {
4377             if (*option == '+')
4378               break;
4379             i++;
4380             if (i == (ssize_t) (argc-1))
4381               ThrowMogrifyException(OptionError,"MissingArgument",option);
4382             if (IsGeometry(argv[i]) == MagickFalse)
4383               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4384             break;
4385           }
4386         if (LocaleCompare("duration",option+1) == 0)
4387           {
4388             if (*option == '+')
4389               break;
4390             i++;
4391             if (i == (ssize_t) (argc-1))
4392               ThrowMogrifyException(OptionError,"MissingArgument",option);
4393             if (IsGeometry(argv[i]) == MagickFalse)
4394               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4395             break;
4396           }
4397         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4398       }
4399       case 'e':
4400       {
4401         if (LocaleCompare("edge",option+1) == 0)
4402           {
4403             if (*option == '+')
4404               break;
4405             i++;
4406             if (i == (ssize_t) argc)
4407               ThrowMogrifyException(OptionError,"MissingArgument",option);
4408             if (IsGeometry(argv[i]) == MagickFalse)
4409               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4410             break;
4411           }
4412         if (LocaleCompare("emboss",option+1) == 0)
4413           {
4414             if (*option == '+')
4415               break;
4416             i++;
4417             if (i == (ssize_t) argc)
4418               ThrowMogrifyException(OptionError,"MissingArgument",option);
4419             if (IsGeometry(argv[i]) == MagickFalse)
4420               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4421             break;
4422           }
4423         if (LocaleCompare("encipher",option+1) == 0)
4424           {
4425             if (*option == '+')
4426               break;
4427             i++;
4428             if (i == (ssize_t) argc)
4429               ThrowMogrifyException(OptionError,"MissingArgument",option);
4430             break;
4431           }
4432         if (LocaleCompare("encoding",option+1) == 0)
4433           {
4434             if (*option == '+')
4435               break;
4436             i++;
4437             if (i == (ssize_t) argc)
4438               ThrowMogrifyException(OptionError,"MissingArgument",option);
4439             break;
4440           }
4441         if (LocaleCompare("endian",option+1) == 0)
4442           {
4443             ssize_t
4444               endian;
4445
4446             if (*option == '+')
4447               break;
4448             i++;
4449             if (i == (ssize_t) argc)
4450               ThrowMogrifyException(OptionError,"MissingArgument",option);
4451             endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
4452             if (endian < 0)
4453               ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4454                 argv[i]);
4455             break;
4456           }
4457         if (LocaleCompare("enhance",option+1) == 0)
4458           break;
4459         if (LocaleCompare("equalize",option+1) == 0)
4460           break;
4461         if (LocaleCompare("evaluate",option+1) == 0)
4462           {
4463             ssize_t
4464               op;
4465
4466             if (*option == '+')
4467               break;
4468             i++;
4469             if (i == (ssize_t) argc)
4470               ThrowMogrifyException(OptionError,"MissingArgument",option);
4471             op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4472             if (op < 0)
4473               ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4474                 argv[i]);
4475             i++;
4476             if (i == (ssize_t) (argc-1))
4477               ThrowMogrifyException(OptionError,"MissingArgument",option);
4478             if (IsGeometry(argv[i]) == MagickFalse)
4479               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4480             break;
4481           }
4482         if (LocaleCompare("evaluate-sequence",option+1) == 0)
4483           {
4484             ssize_t
4485               op;
4486
4487             if (*option == '+')
4488               break;
4489             i++;
4490             if (i == (ssize_t) argc)
4491               ThrowMogrifyException(OptionError,"MissingArgument",option);
4492             op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4493             if (op < 0)
4494               ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4495                 argv[i]);
4496             break;
4497           }
4498         if (LocaleCompare("extent",option+1) == 0)
4499           {
4500             if (*option == '+')
4501               break;
4502             i++;
4503             if (i == (ssize_t) argc)
4504               ThrowMogrifyException(OptionError,"MissingArgument",option);
4505             if (IsGeometry(argv[i]) == MagickFalse)
4506               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4507             break;
4508           }
4509         if (LocaleCompare("extract",option+1) == 0)
4510           {
4511             if (*option == '+')
4512               break;
4513             i++;
4514             if (i == (ssize_t) argc)
4515               ThrowMogrifyException(OptionError,"MissingArgument",option);
4516             if (IsGeometry(argv[i]) == MagickFalse)
4517               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4518             break;
4519           }
4520         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4521       }
4522       case 'f':
4523       {
4524         if (LocaleCompare("family",option+1) == 0)
4525           {
4526             if (*option == '+')
4527               break;
4528             i++;
4529             if (i == (ssize_t) (argc-1))
4530               ThrowMogrifyException(OptionError,"MissingArgument",option);
4531             break;
4532           }
4533         if (LocaleCompare("fill",option+1) == 0)
4534           {
4535             if (*option == '+')
4536               break;
4537             i++;
4538             if (i == (ssize_t) argc)
4539               ThrowMogrifyException(OptionError,"MissingArgument",option);
4540             break;
4541           }
4542         if (LocaleCompare("filter",option+1) == 0)
4543           {
4544             ssize_t
4545               filter;
4546
4547             if (*option == '+')
4548               break;
4549             i++;
4550             if (i == (ssize_t) argc)
4551               ThrowMogrifyException(OptionError,"MissingArgument",option);
4552             filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
4553             if (filter < 0)
4554               ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4555                 argv[i]);
4556             break;
4557           }
4558         if (LocaleCompare("flatten",option+1) == 0)
4559           break;
4560         if (LocaleCompare("flip",option+1) == 0)
4561           break;
4562         if (LocaleCompare("flop",option+1) == 0)
4563           break;
4564         if (LocaleCompare("floodfill",option+1) == 0)
4565           {
4566             if (*option == '+')
4567               break;
4568             i++;
4569             if (i == (ssize_t) argc)
4570               ThrowMogrifyException(OptionError,"MissingArgument",option);
4571             if (IsGeometry(argv[i]) == MagickFalse)
4572               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4573             i++;
4574             if (i == (ssize_t) argc)
4575               ThrowMogrifyException(OptionError,"MissingArgument",option);
4576             break;
4577           }
4578         if (LocaleCompare("font",option+1) == 0)
4579           {
4580             if (*option == '+')
4581               break;
4582             i++;
4583             if (i == (ssize_t) argc)
4584               ThrowMogrifyException(OptionError,"MissingArgument",option);
4585             break;
4586           }
4587         if (LocaleCompare("format",option+1) == 0)
4588           {
4589             (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4590             (void) CloneString(&format,(char *) NULL);
4591             if (*option == '+')
4592               break;
4593             i++;
4594             if (i == (ssize_t) argc)
4595               ThrowMogrifyException(OptionError,"MissingArgument",option);
4596             (void) CloneString(&format,argv[i]);
4597             (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4598             (void) ConcatenateMagickString(image_info->filename,":",
4599               MaxTextExtent);
4600             (void) SetImageInfo(image_info,0,exception);
4601             if (*image_info->magick == '\0')
4602               ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4603                 format);
4604             break;
4605           }
4606         if (LocaleCompare("frame",option+1) == 0)
4607           {
4608             if (*option == '+')
4609               break;
4610             i++;
4611             if (i == (ssize_t) argc)
4612               ThrowMogrifyException(OptionError,"MissingArgument",option);
4613             if (IsGeometry(argv[i]) == MagickFalse)
4614               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4615             break;
4616           }
4617         if (LocaleCompare("function",option+1) == 0)
4618           {
4619             ssize_t
4620               op;
4621
4622             if (*option == '+')
4623               break;
4624             i++;
4625             if (i == (ssize_t) argc)
4626               ThrowMogrifyException(OptionError,"MissingArgument",option);
4627             op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
4628             if (op < 0)
4629               ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4630              i++;
4631              if (i == (ssize_t) (argc-1))
4632                ThrowMogrifyException(OptionError,"MissingArgument",option);
4633             break;
4634           }
4635         if (LocaleCompare("fuzz",option+1) == 0)
4636           {
4637             if (*option == '+')
4638               break;
4639             i++;
4640             if (i == (ssize_t) argc)
4641               ThrowMogrifyException(OptionError,"MissingArgument",option);
4642             if (IsGeometry(argv[i]) == MagickFalse)
4643               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4644             break;
4645           }
4646         if (LocaleCompare("fx",option+1) == 0)
4647           {
4648             if (*option == '+')
4649               break;
4650             i++;
4651             if (i == (ssize_t) (argc-1))
4652               ThrowMogrifyException(OptionError,"MissingArgument",option);
4653             break;
4654           }
4655         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4656       }
4657       case 'g':
4658       {
4659         if (LocaleCompare("gamma",option+1) == 0)
4660           {
4661             i++;
4662             if (i == (ssize_t) argc)
4663               ThrowMogrifyException(OptionError,"MissingArgument",option);
4664             if (IsGeometry(argv[i]) == MagickFalse)
4665               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4666             break;
4667           }
4668         if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4669             (LocaleCompare("gaussian",option+1) == 0))
4670           {
4671             i++;
4672             if (i == (ssize_t) argc)
4673               ThrowMogrifyException(OptionError,"MissingArgument",option);
4674             if (IsGeometry(argv[i]) == MagickFalse)
4675               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4676             break;
4677           }
4678         if (LocaleCompare("geometry",option+1) == 0)
4679           {
4680             if (*option == '+')
4681               break;
4682             i++;
4683             if (i == (ssize_t) argc)
4684               ThrowMogrifyException(OptionError,"MissingArgument",option);
4685             if (IsGeometry(argv[i]) == MagickFalse)
4686               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4687             break;
4688           }
4689         if (LocaleCompare("gravity",option+1) == 0)
4690           {
4691             ssize_t
4692               gravity;
4693
4694             if (*option == '+')
4695               break;
4696             i++;
4697             if (i == (ssize_t) argc)
4698               ThrowMogrifyException(OptionError,"MissingArgument",option);
4699             gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
4700             if (gravity < 0)
4701               ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4702                 argv[i]);
4703             break;
4704           }
4705         if (LocaleCompare("green-primary",option+1) == 0)
4706           {
4707             if (*option == '+')
4708               break;
4709             i++;
4710             if (i == (ssize_t) argc)
4711               ThrowMogrifyException(OptionError,"MissingArgument",option);
4712             if (IsGeometry(argv[i]) == MagickFalse)
4713               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4714             break;
4715           }
4716         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4717       }
4718       case 'h':
4719       {
4720         if (LocaleCompare("hald-clut",option+1) == 0)
4721           break;
4722         if ((LocaleCompare("help",option+1) == 0) ||
4723             (LocaleCompare("-help",option+1) == 0))
4724           return(MogrifyUsage());
4725         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4726       }
4727       case 'i':
4728       {
4729         if (LocaleCompare("identify",option+1) == 0)
4730           break;
4731         if (LocaleCompare("idft",option+1) == 0)
4732           break;
4733         if (LocaleCompare("implode",option+1) == 0)
4734           {
4735             if (*option == '+')
4736               break;
4737             i++;
4738             if (i == (ssize_t) argc)
4739               ThrowMogrifyException(OptionError,"MissingArgument",option);
4740             if (IsGeometry(argv[i]) == MagickFalse)
4741               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4742             break;
4743           }
4744         if (LocaleCompare("intent",option+1) == 0)
4745           {
4746             ssize_t
4747               intent;
4748
4749             if (*option == '+')
4750               break;
4751             i++;
4752             if (i == (ssize_t) (argc-1))
4753               ThrowMogrifyException(OptionError,"MissingArgument",option);
4754             intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
4755             if (intent < 0)
4756               ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4757                 argv[i]);
4758             break;
4759           }
4760         if (LocaleCompare("interlace",option+1) == 0)
4761           {
4762             ssize_t
4763               interlace;
4764
4765             if (*option == '+')
4766               break;
4767             i++;
4768             if (i == (ssize_t) argc)
4769               ThrowMogrifyException(OptionError,"MissingArgument",option);
4770             interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
4771               argv[i]);
4772             if (interlace < 0)
4773               ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4774                 argv[i]);
4775             break;
4776           }
4777         if (LocaleCompare("interline-spacing",option+1) == 0)
4778           {
4779             if (*option == '+')
4780               break;
4781             i++;
4782             if (i == (ssize_t) (argc-1))
4783               ThrowMogrifyException(OptionError,"MissingArgument",option);
4784             if (IsGeometry(argv[i]) == MagickFalse)
4785               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4786             break;
4787           }
4788         if (LocaleCompare("interpolate",option+1) == 0)
4789           {
4790             ssize_t
4791               interpolate;
4792
4793             if (*option == '+')
4794               break;
4795             i++;
4796             if (i == (ssize_t) argc)
4797               ThrowMogrifyException(OptionError,"MissingArgument",option);
4798             interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
4799               argv[i]);
4800             if (interpolate < 0)
4801               ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4802                 argv[i]);
4803             break;
4804           }
4805         if (LocaleCompare("interword-spacing",option+1) == 0)
4806           {
4807             if (*option == '+')
4808               break;
4809             i++;
4810             if (i == (ssize_t) (argc-1))
4811               ThrowMogrifyException(OptionError,"MissingArgument",option);
4812             if (IsGeometry(argv[i]) == MagickFalse)
4813               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4814             break;
4815           }
4816         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4817       }
4818       case 'k':
4819       {
4820         if (LocaleCompare("kerning",option+1) == 0)
4821           {
4822             if (*option == '+')
4823               break;
4824             i++;
4825             if (i == (ssize_t) (argc-1))
4826               ThrowMogrifyException(OptionError,"MissingArgument",option);
4827             if (IsGeometry(argv[i]) == MagickFalse)
4828               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4829             break;
4830           }
4831         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4832       }
4833       case 'l':
4834       {
4835         if (LocaleCompare("label",option+1) == 0)
4836           {
4837             if (*option == '+')
4838               break;
4839             i++;
4840             if (i == (ssize_t) argc)
4841               ThrowMogrifyException(OptionError,"MissingArgument",option);
4842             break;
4843           }
4844         if (LocaleCompare("lat",option+1) == 0)
4845           {
4846             if (*option == '+')
4847               break;
4848             i++;
4849             if (i == (ssize_t) argc)
4850               ThrowMogrifyException(OptionError,"MissingArgument",option);
4851             if (IsGeometry(argv[i]) == MagickFalse)
4852               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4853           }
4854         if (LocaleCompare("layers",option+1) == 0)
4855           {
4856             ssize_t
4857               type;
4858
4859             if (*option == '+')
4860               break;
4861             i++;
4862             if (i == (ssize_t) (argc-1))
4863               ThrowMogrifyException(OptionError,"MissingArgument",option);
4864             type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
4865             if (type < 0)
4866               ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4867                 argv[i]);
4868             break;
4869           }
4870         if (LocaleCompare("level",option+1) == 0)
4871           {
4872             i++;
4873             if (i == (ssize_t) argc)
4874               ThrowMogrifyException(OptionError,"MissingArgument",option);
4875             if (IsGeometry(argv[i]) == MagickFalse)
4876               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4877             break;
4878           }
4879         if (LocaleCompare("level-colors",option+1) == 0)
4880           {
4881             i++;
4882             if (i == (ssize_t) argc)
4883               ThrowMogrifyException(OptionError,"MissingArgument",option);
4884             break;
4885           }
4886         if (LocaleCompare("linewidth",option+1) == 0)
4887           {
4888             if (*option == '+')
4889               break;
4890             i++;
4891             if (i == (ssize_t) argc)
4892               ThrowMogrifyException(OptionError,"MissingArgument",option);
4893             if (IsGeometry(argv[i]) == MagickFalse)
4894               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4895             break;
4896           }
4897         if (LocaleCompare("limit",option+1) == 0)
4898           {
4899             char
4900               *p;
4901
4902             double
4903               value;
4904
4905             ssize_t
4906               resource;
4907
4908             if (*option == '+')
4909               break;
4910             i++;
4911             if (i == (ssize_t) argc)
4912               ThrowMogrifyException(OptionError,"MissingArgument",option);
4913             resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
4914               argv[i]);
4915             if (resource < 0)
4916               ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4917                 argv[i]);
4918             i++;
4919             if (i == (ssize_t) argc)
4920               ThrowMogrifyException(OptionError,"MissingArgument",option);
4921             value=InterpretLocaleValue(argv[i],&p);
4922             (void) value;
4923             if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4924               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4925             break;
4926           }
4927         if (LocaleCompare("liquid-rescale",option+1) == 0)
4928           {
4929             i++;
4930             if (i == (ssize_t) argc)
4931               ThrowMogrifyException(OptionError,"MissingArgument",option);
4932             if (IsGeometry(argv[i]) == MagickFalse)
4933               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4934             break;
4935           }
4936         if (LocaleCompare("list",option+1) == 0)
4937           {
4938             ssize_t
4939               list;
4940
4941             if (*option == '+')
4942               break;
4943             i++;
4944             if (i == (ssize_t) argc)
4945               ThrowMogrifyException(OptionError,"MissingArgument",option);
4946             list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
4947             if (list < 0)
4948               ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
4949             status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
4950               argv+j,exception);
4951             return(status != 0 ? MagickFalse : MagickTrue);
4952           }
4953         if (LocaleCompare("log",option+1) == 0)
4954           {
4955             if (*option == '+')
4956               break;
4957             i++;
4958             if ((i == (ssize_t) argc) ||
4959                 (strchr(argv[i],'%') == (char *) NULL))
4960               ThrowMogrifyException(OptionError,"MissingArgument",option);
4961             break;
4962           }
4963         if (LocaleCompare("loop",option+1) == 0)
4964           {
4965             if (*option == '+')
4966               break;
4967             i++;
4968             if (i == (ssize_t) argc)
4969               ThrowMogrifyException(OptionError,"MissingArgument",option);
4970             if (IsGeometry(argv[i]) == MagickFalse)
4971               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4972             break;
4973           }
4974         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4975       }
4976       case 'm':
4977       {
4978         if (LocaleCompare("map",option+1) == 0)
4979           {
4980             global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4981             if (*option == '+')
4982               break;
4983             i++;
4984             if (i == (ssize_t) argc)
4985               ThrowMogrifyException(OptionError,"MissingArgument",option);
4986             break;
4987           }
4988         if (LocaleCompare("mask",option+1) == 0)
4989           {
4990             if (*option == '+')
4991               break;
4992             i++;
4993             if (i == (ssize_t) argc)
4994               ThrowMogrifyException(OptionError,"MissingArgument",option);
4995             break;
4996           }
4997         if (LocaleCompare("matte",option+1) == 0)
4998           break;
4999         if (LocaleCompare("mattecolor",option+1) == 0)
5000           {
5001             if (*option == '+')
5002               break;
5003             i++;
5004             if (i == (ssize_t) argc)
5005               ThrowMogrifyException(OptionError,"MissingArgument",option);
5006             break;
5007           }
5008         if (LocaleCompare("maximum",option+1) == 0)
5009           break;
5010         if (LocaleCompare("minimum",option+1) == 0)
5011           break;
5012         if (LocaleCompare("modulate",option+1) == 0)
5013           {
5014             if (*option == '+')
5015               break;
5016             i++;
5017             if (i == (ssize_t) argc)
5018               ThrowMogrifyException(OptionError,"MissingArgument",option);
5019             if (IsGeometry(argv[i]) == MagickFalse)
5020               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5021             break;
5022           }
5023         if (LocaleCompare("median",option+1) == 0)
5024           {
5025             if (*option == '+')
5026               break;
5027             i++;
5028             if (i == (ssize_t) argc)
5029               ThrowMogrifyException(OptionError,"MissingArgument",option);
5030             if (IsGeometry(argv[i]) == MagickFalse)
5031               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5032             break;
5033           }
5034         if (LocaleCompare("mode",option+1) == 0)
5035           {
5036             if (*option == '+')
5037               break;
5038             i++;
5039             if (i == (ssize_t) argc)
5040               ThrowMogrifyException(OptionError,"MissingArgument",option);
5041             if (IsGeometry(argv[i]) == MagickFalse)
5042               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5043             break;
5044           }
5045         if (LocaleCompare("monitor",option+1) == 0)
5046           break;
5047         if (LocaleCompare("monochrome",option+1) == 0)
5048           break;
5049         if (LocaleCompare("morph",option+1) == 0)
5050           {
5051             if (*option == '+')
5052               break;
5053             i++;
5054             if (i == (ssize_t) (argc-1))
5055               ThrowMogrifyException(OptionError,"MissingArgument",option);
5056             if (IsGeometry(argv[i]) == MagickFalse)
5057               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5058             break;
5059           }
5060         if (LocaleCompare("morphology",option+1) == 0)
5061           {
5062             char
5063               token[MaxTextExtent];
5064
5065             KernelInfo
5066               *kernel_info;
5067
5068             ssize_t
5069               op;
5070
5071             i++;
5072             if (i == (ssize_t) argc)
5073               ThrowMogrifyException(OptionError,"MissingArgument",option);
5074             GetMagickToken(argv[i],NULL,token);
5075             op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
5076             if (op < 0)
5077               ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
5078                 token);
5079             i++;
5080             if (i == (ssize_t) (argc-1))
5081               ThrowMogrifyException(OptionError,"MissingArgument",option);
5082             kernel_info=AcquireKernelInfo(argv[i]);
5083             if (kernel_info == (KernelInfo *) NULL)
5084               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5085             kernel_info=DestroyKernelInfo(kernel_info);
5086             break;
5087           }
5088         if (LocaleCompare("mosaic",option+1) == 0)
5089           break;
5090         if (LocaleCompare("motion-blur",option+1) == 0)
5091           {
5092             if (*option == '+')
5093               break;
5094             i++;
5095             if (i == (ssize_t) argc)
5096               ThrowMogrifyException(OptionError,"MissingArgument",option);
5097             if (IsGeometry(argv[i]) == MagickFalse)
5098               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5099             break;
5100           }
5101         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5102       }
5103       case 'n':
5104       {
5105         if (LocaleCompare("negate",option+1) == 0)
5106           break;
5107         if (LocaleCompare("noise",option+1) == 0)
5108           {
5109             i++;
5110             if (i == (ssize_t) argc)
5111               ThrowMogrifyException(OptionError,"MissingArgument",option);
5112             if (*option == '+')
5113               {
5114                 ssize_t
5115                   noise;
5116
5117                 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
5118                 if (noise < 0)
5119                   ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5120                     argv[i]);
5121                 break;
5122               }
5123             if (IsGeometry(argv[i]) == MagickFalse)
5124               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5125             break;
5126           }
5127         if (LocaleCompare("noop",option+1) == 0)
5128           break;
5129         if (LocaleCompare("normalize",option+1) == 0)
5130           break;
5131         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5132       }
5133       case 'o':
5134       {
5135         if (LocaleCompare("opaque",option+1) == 0)
5136           {
5137             i++;
5138             if (i == (ssize_t) argc)
5139               ThrowMogrifyException(OptionError,"MissingArgument",option);
5140             break;
5141           }
5142         if (LocaleCompare("ordered-dither",option+1) == 0)
5143           {
5144             if (*option == '+')
5145               break;
5146             i++;
5147             if (i == (ssize_t) argc)
5148               ThrowMogrifyException(OptionError,"MissingArgument",option);
5149             break;
5150           }
5151         if (LocaleCompare("orient",option+1) == 0)
5152           {
5153             ssize_t
5154               orientation;
5155
5156             orientation=UndefinedOrientation;
5157             if (*option == '+')
5158               break;
5159             i++;
5160             if (i == (ssize_t) (argc-1))
5161               ThrowMogrifyException(OptionError,"MissingArgument",option);
5162             orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
5163               argv[i]);
5164             if (orientation < 0)
5165               ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5166                 argv[i]);
5167             break;
5168           }
5169         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5170       }
5171       case 'p':
5172       {
5173         if (LocaleCompare("page",option+1) == 0)
5174           {
5175             if (*option == '+')
5176               break;
5177             i++;
5178             if (i == (ssize_t) argc)
5179               ThrowMogrifyException(OptionError,"MissingArgument",option);
5180             break;
5181           }
5182         if (LocaleCompare("paint",option+1) == 0)
5183           {
5184             if (*option == '+')
5185               break;
5186             i++;
5187             if (i == (ssize_t) argc)
5188               ThrowMogrifyException(OptionError,"MissingArgument",option);
5189             if (IsGeometry(argv[i]) == MagickFalse)
5190               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5191             break;
5192           }
5193         if (LocaleCompare("path",option+1) == 0)
5194           {
5195             (void) CloneString(&path,(char *) NULL);
5196             if (*option == '+')
5197               break;
5198             i++;
5199             if (i == (ssize_t) argc)
5200               ThrowMogrifyException(OptionError,"MissingArgument",option);
5201             (void) CloneString(&path,argv[i]);
5202             break;
5203           }
5204         if (LocaleCompare("pointsize",option+1) == 0)
5205           {
5206             if (*option == '+')
5207               break;
5208             i++;
5209             if (i == (ssize_t) argc)
5210               ThrowMogrifyException(OptionError,"MissingArgument",option);
5211             if (IsGeometry(argv[i]) == MagickFalse)
5212               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5213             break;
5214           }
5215         if (LocaleCompare("polaroid",option+1) == 0)
5216           {
5217             if (*option == '+')
5218               break;
5219             i++;
5220             if (i == (ssize_t) argc)
5221               ThrowMogrifyException(OptionError,"MissingArgument",option);
5222             if (IsGeometry(argv[i]) == MagickFalse)
5223               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5224             break;
5225           }
5226         if (LocaleCompare("posterize",option+1) == 0)
5227           {
5228             if (*option == '+')
5229               break;
5230             i++;
5231             if (i == (ssize_t) argc)
5232               ThrowMogrifyException(OptionError,"MissingArgument",option);
5233             if (IsGeometry(argv[i]) == MagickFalse)
5234               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5235             break;
5236           }
5237         if (LocaleCompare("precision",option+1) == 0)
5238           {
5239             if (*option == '+')
5240               break;
5241             i++;
5242             if (i == (ssize_t) argc)
5243               ThrowMogrifyException(OptionError,"MissingArgument",option);
5244             if (IsGeometry(argv[i]) == MagickFalse)
5245               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5246             break;
5247           }
5248         if (LocaleCompare("print",option+1) == 0)
5249           {
5250             if (*option == '+')
5251               break;
5252             i++;
5253             if (i == (ssize_t) argc)
5254               ThrowMogrifyException(OptionError,"MissingArgument",option);
5255             break;
5256           }
5257         if (LocaleCompare("process",option+1) == 0)
5258           {
5259             if (*option == '+')
5260               break;
5261             i++;
5262             if (i == (ssize_t) (argc-1))
5263               ThrowMogrifyException(OptionError,"MissingArgument",option);
5264             break;
5265           }
5266         if (LocaleCompare("profile",option+1) == 0)
5267           {
5268             i++;
5269             if (i == (ssize_t) argc)
5270               ThrowMogrifyException(OptionError,"MissingArgument",option);
5271             break;
5272           }
5273         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5274       }
5275       case 'q':
5276       {
5277         if (LocaleCompare("quality",option+1) == 0)
5278           {
5279             if (*option == '+')
5280               break;
5281             i++;
5282             if (i == (ssize_t) argc)
5283               ThrowMogrifyException(OptionError,"MissingArgument",option);
5284             if (IsGeometry(argv[i]) == MagickFalse)
5285               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5286             break;
5287           }
5288         if (LocaleCompare("quantize",option+1) == 0)
5289           {
5290             ssize_t
5291               colorspace;
5292
5293             if (*option == '+')
5294               break;
5295             i++;
5296             if (i == (ssize_t) (argc-1))
5297               ThrowMogrifyException(OptionError,"MissingArgument",option);
5298             colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
5299               argv[i]);
5300             if (colorspace < 0)
5301               ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5302                 argv[i]);
5303             break;
5304           }
5305         if (LocaleCompare("quiet",option+1) == 0)
5306           break;
5307         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5308       }
5309       case 'r':
5310       {
5311         if (LocaleCompare("radial-blur",option+1) == 0)
5312           {
5313             i++;
5314             if (i == (ssize_t) argc)
5315               ThrowMogrifyException(OptionError,"MissingArgument",option);
5316             if (IsGeometry(argv[i]) == MagickFalse)
5317               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5318             break;
5319           }
5320         if (LocaleCompare("raise",option+1) == 0)
5321           {
5322             i++;
5323             if (i == (ssize_t) argc)
5324               ThrowMogrifyException(OptionError,"MissingArgument",option);
5325             if (IsGeometry(argv[i]) == MagickFalse)
5326               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5327             break;
5328           }
5329         if (LocaleCompare("random-threshold",option+1) == 0)
5330           {
5331             if (*option == '+')
5332               break;
5333             i++;
5334             if (i == (ssize_t) argc)
5335               ThrowMogrifyException(OptionError,"MissingArgument",option);
5336             if (IsGeometry(argv[i]) == MagickFalse)
5337               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5338             break;
5339           }
5340         if (LocaleCompare("recolor",option+1) == 0)
5341           {
5342             if (*option == '+')
5343               break;
5344             i++;
5345             if (i == (ssize_t) (argc-1))
5346               ThrowMogrifyException(OptionError,"MissingArgument",option);
5347             if (IsGeometry(argv[i]) == MagickFalse)
5348               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5349             break;
5350           }
5351         if (LocaleCompare("red-primary",option+1) == 0)
5352           {
5353             if (*option == '+')
5354               break;
5355             i++;
5356             if (i == (ssize_t) argc)
5357               ThrowMogrifyException(OptionError,"MissingArgument",option);
5358             if (IsGeometry(argv[i]) == MagickFalse)
5359               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5360           }
5361         if (LocaleCompare("regard-warnings",option+1) == 0)
5362           break;
5363         if (LocaleCompare("region",option+1) == 0)
5364           {
5365             if (*option == '+')
5366               break;
5367             i++;
5368             if (i == (ssize_t) argc)
5369               ThrowMogrifyException(OptionError,"MissingArgument",option);
5370             if (IsGeometry(argv[i]) == MagickFalse)
5371               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5372             break;
5373           }
5374         if (LocaleCompare("remap",option+1) == 0)
5375           {
5376             if (*option == '+')
5377               break;
5378             i++;
5379             if (i == (ssize_t) (argc-1))
5380               ThrowMogrifyException(OptionError,"MissingArgument",option);
5381             break;
5382           }
5383         if (LocaleCompare("render",option+1) == 0)
5384           break;
5385         if (LocaleCompare("repage",option+1) == 0)
5386           {
5387             if (*option == '+')
5388               break;
5389             i++;
5390             if (i == (ssize_t) argc)
5391               ThrowMogrifyException(OptionError,"MissingArgument",option);
5392             if (IsGeometry(argv[i]) == MagickFalse)
5393               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5394             break;
5395           }
5396         if (LocaleCompare("resample",option+1) == 0)
5397           {
5398             if (*option == '+')
5399               break;
5400             i++;
5401             if (i == (ssize_t) argc)
5402               ThrowMogrifyException(OptionError,"MissingArgument",option);
5403             if (IsGeometry(argv[i]) == MagickFalse)
5404               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5405             break;
5406           }
5407         if (LocaleCompare("resize",option+1) == 0)
5408           {
5409             if (*option == '+')
5410               break;
5411             i++;
5412             if (i == (ssize_t) argc)
5413               ThrowMogrifyException(OptionError,"MissingArgument",option);
5414             if (IsGeometry(argv[i]) == MagickFalse)
5415               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5416             break;
5417           }
5418         if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5419           {
5420             respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5421             break;
5422           }
5423         if (LocaleCompare("reverse",option+1) == 0)
5424           break;
5425         if (LocaleCompare("roll",option+1) == 0)
5426           {
5427             if (*option == '+')
5428               break;
5429             i++;
5430             if (i == (ssize_t) argc)
5431               ThrowMogrifyException(OptionError,"MissingArgument",option);
5432             if (IsGeometry(argv[i]) == MagickFalse)
5433               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5434             break;
5435           }
5436         if (LocaleCompare("rotate",option+1) == 0)
5437           {
5438             i++;
5439             if (i == (ssize_t) argc)
5440               ThrowMogrifyException(OptionError,"MissingArgument",option);
5441             if (IsGeometry(argv[i]) == MagickFalse)
5442               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5443             break;
5444           }
5445         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5446       }
5447       case 's':
5448       {
5449         if (LocaleCompare("sample",option+1) == 0)
5450           {
5451             if (*option == '+')
5452               break;
5453             i++;
5454             if (i == (ssize_t) argc)
5455               ThrowMogrifyException(OptionError,"MissingArgument",option);
5456             if (IsGeometry(argv[i]) == MagickFalse)
5457               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5458             break;
5459           }
5460         if (LocaleCompare("sampling-factor",option+1) == 0)
5461           {
5462             if (*option == '+')
5463               break;
5464             i++;
5465             if (i == (ssize_t) argc)
5466               ThrowMogrifyException(OptionError,"MissingArgument",option);
5467             if (IsGeometry(argv[i]) == MagickFalse)
5468               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5469             break;
5470           }
5471         if (LocaleCompare("scale",option+1) == 0)
5472           {
5473             if (*option == '+')
5474               break;
5475             i++;
5476             if (i == (ssize_t) argc)
5477               ThrowMogrifyException(OptionError,"MissingArgument",option);
5478             if (IsGeometry(argv[i]) == MagickFalse)
5479               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5480             break;
5481           }
5482         if (LocaleCompare("scene",option+1) == 0)
5483           {
5484             if (*option == '+')
5485               break;
5486             i++;
5487             if (i == (ssize_t) argc)
5488               ThrowMogrifyException(OptionError,"MissingArgument",option);
5489             if (IsGeometry(argv[i]) == MagickFalse)
5490               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5491             break;
5492           }
5493         if (LocaleCompare("seed",option+1) == 0)
5494           {
5495             if (*option == '+')
5496               break;
5497             i++;
5498             if (i == (ssize_t) argc)
5499               ThrowMogrifyException(OptionError,"MissingArgument",option);
5500             if (IsGeometry(argv[i]) == MagickFalse)
5501               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5502             break;
5503           }
5504         if (LocaleCompare("segment",option+1) == 0)
5505           {
5506             if (*option == '+')
5507               break;
5508             i++;
5509             if (i == (ssize_t) argc)
5510               ThrowMogrifyException(OptionError,"MissingArgument",option);
5511             if (IsGeometry(argv[i]) == MagickFalse)
5512               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5513             break;
5514           }
5515         if (LocaleCompare("selective-blur",option+1) == 0)
5516           {
5517             i++;
5518             if (i == (ssize_t) argc)
5519               ThrowMogrifyException(OptionError,"MissingArgument",option);
5520             if (IsGeometry(argv[i]) == MagickFalse)
5521               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5522             break;
5523           }
5524         if (LocaleCompare("separate",option+1) == 0)
5525           break;
5526         if (LocaleCompare("sepia-tone",option+1) == 0)
5527           {
5528             if (*option == '+')
5529               break;
5530             i++;
5531             if (i == (ssize_t) argc)
5532               ThrowMogrifyException(OptionError,"MissingArgument",option);
5533             if (IsGeometry(argv[i]) == MagickFalse)
5534               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5535             break;
5536           }
5537         if (LocaleCompare("set",option+1) == 0)
5538           {
5539             i++;
5540             if (i == (ssize_t) argc)
5541               ThrowMogrifyException(OptionError,"MissingArgument",option);
5542             if (*option == '+')
5543               break;
5544             i++;
5545             if (i == (ssize_t) argc)
5546               ThrowMogrifyException(OptionError,"MissingArgument",option);
5547             break;
5548           }
5549         if (LocaleCompare("shade",option+1) == 0)
5550           {
5551             i++;
5552             if (i == (ssize_t) argc)
5553               ThrowMogrifyException(OptionError,"MissingArgument",option);
5554             if (IsGeometry(argv[i]) == MagickFalse)
5555               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5556             break;
5557           }
5558         if (LocaleCompare("shadow",option+1) == 0)
5559           {
5560             if (*option == '+')
5561               break;
5562             i++;
5563             if (i == (ssize_t) argc)
5564               ThrowMogrifyException(OptionError,"MissingArgument",option);
5565             if (IsGeometry(argv[i]) == MagickFalse)
5566               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5567             break;
5568           }
5569         if (LocaleCompare("sharpen",option+1) == 0)
5570           {
5571             i++;
5572             if (i == (ssize_t) argc)
5573               ThrowMogrifyException(OptionError,"MissingArgument",option);
5574             if (IsGeometry(argv[i]) == MagickFalse)
5575               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5576             break;
5577           }
5578         if (LocaleCompare("shave",option+1) == 0)
5579           {
5580             if (*option == '+')
5581               break;
5582             i++;
5583             if (i == (ssize_t) argc)
5584               ThrowMogrifyException(OptionError,"MissingArgument",option);
5585             if (IsGeometry(argv[i]) == MagickFalse)
5586               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5587             break;
5588           }
5589         if (LocaleCompare("shear",option+1) == 0)
5590           {
5591             i++;
5592             if (i == (ssize_t) argc)
5593               ThrowMogrifyException(OptionError,"MissingArgument",option);
5594             if (IsGeometry(argv[i]) == MagickFalse)
5595               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5596             break;
5597           }
5598         if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5599           {
5600             i++;
5601             if (i == (ssize_t) (argc-1))
5602               ThrowMogrifyException(OptionError,"MissingArgument",option);
5603             if (IsGeometry(argv[i]) == MagickFalse)
5604               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5605             break;
5606           }
5607         if (LocaleCompare("size",option+1) == 0)
5608           {
5609             if (*option == '+')
5610               break;
5611             i++;
5612             if (i == (ssize_t) argc)
5613               ThrowMogrifyException(OptionError,"MissingArgument",option);
5614             if (IsGeometry(argv[i]) == MagickFalse)
5615               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5616             break;
5617           }
5618         if (LocaleCompare("sketch",option+1) == 0)
5619           {
5620             if (*option == '+')
5621               break;
5622             i++;
5623             if (i == (ssize_t) argc)
5624               ThrowMogrifyException(OptionError,"MissingArgument",option);
5625             if (IsGeometry(argv[i]) == MagickFalse)
5626               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5627             break;
5628           }
5629         if (LocaleCompare("smush",option+1) == 0)
5630           {
5631             i++;
5632             if (i == (ssize_t) argc)
5633               ThrowMogrifyException(OptionError,"MissingArgument",option);
5634             if (IsGeometry(argv[i]) == MagickFalse)
5635               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5636             i++;
5637             break;
5638           }
5639         if (LocaleCompare("solarize",option+1) == 0)
5640           {
5641             if (*option == '+')
5642               break;
5643             i++;
5644             if (i == (ssize_t) argc)
5645               ThrowMogrifyException(OptionError,"MissingArgument",option);
5646             if (IsGeometry(argv[i]) == MagickFalse)
5647               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5648             break;
5649           }
5650         if (LocaleCompare("sparse-color",option+1) == 0)
5651           {
5652             ssize_t
5653               op;
5654
5655             i++;
5656             if (i == (ssize_t) argc)
5657               ThrowMogrifyException(OptionError,"MissingArgument",option);
5658             op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5659             if (op < 0)
5660               ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5661                 argv[i]);
5662             i++;
5663             if (i == (ssize_t) (argc-1))
5664               ThrowMogrifyException(OptionError,"MissingArgument",option);
5665             break;
5666           }
5667         if (LocaleCompare("spread",option+1) == 0)
5668           {
5669             if (*option == '+')
5670               break;
5671             i++;
5672             if (i == (ssize_t) argc)
5673               ThrowMogrifyException(OptionError,"MissingArgument",option);
5674             if (IsGeometry(argv[i]) == MagickFalse)
5675               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5676             break;
5677           }
5678         if (LocaleCompare("statistic",option+1) == 0)
5679           {
5680             ssize_t
5681               op;
5682
5683             if (*option == '+')
5684               break;
5685             i++;
5686             if (i == (ssize_t) argc)
5687               ThrowMogrifyException(OptionError,"MissingArgument",option);
5688             op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
5689             if (op < 0)
5690               ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5691                 argv[i]);
5692             i++;
5693             if (i == (ssize_t) (argc-1))
5694               ThrowMogrifyException(OptionError,"MissingArgument",option);
5695             if (IsGeometry(argv[i]) == MagickFalse)
5696               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5697             break;
5698           }
5699         if (LocaleCompare("stretch",option+1) == 0)
5700           {
5701             ssize_t
5702               stretch;
5703
5704             if (*option == '+')
5705               break;
5706             i++;
5707             if (i == (ssize_t) (argc-1))
5708               ThrowMogrifyException(OptionError,"MissingArgument",option);
5709             stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
5710             if (stretch < 0)
5711               ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5712                 argv[i]);
5713             break;
5714           }
5715         if (LocaleCompare("strip",option+1) == 0)
5716           break;
5717         if (LocaleCompare("stroke",option+1) == 0)
5718           {
5719             if (*option == '+')
5720               break;
5721             i++;
5722             if (i == (ssize_t) argc)
5723               ThrowMogrifyException(OptionError,"MissingArgument",option);
5724             break;
5725           }
5726         if (LocaleCompare("strokewidth",option+1) == 0)
5727           {
5728             if (*option == '+')
5729               break;
5730             i++;
5731             if (i == (ssize_t) argc)
5732               ThrowMogrifyException(OptionError,"MissingArgument",option);
5733             if (IsGeometry(argv[i]) == MagickFalse)
5734               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5735             break;
5736           }
5737         if (LocaleCompare("style",option+1) == 0)
5738           {
5739             ssize_t
5740               style;
5741
5742             if (*option == '+')
5743               break;
5744             i++;
5745             if (i == (ssize_t) (argc-1))
5746               ThrowMogrifyException(OptionError,"MissingArgument",option);
5747             style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
5748             if (style < 0)
5749               ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5750                 argv[i]);
5751             break;
5752           }
5753         if (LocaleCompare("swap",option+1) == 0)
5754           {
5755             if (*option == '+')
5756               break;
5757             i++;
5758             if (i == (ssize_t) (argc-1))
5759               ThrowMogrifyException(OptionError,"MissingArgument",option);
5760             if (IsGeometry(argv[i]) == MagickFalse)
5761               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5762             break;
5763           }
5764         if (LocaleCompare("swirl",option+1) == 0)
5765           {
5766             if (*option == '+')
5767               break;
5768             i++;
5769             if (i == (ssize_t) argc)
5770               ThrowMogrifyException(OptionError,"MissingArgument",option);
5771             if (IsGeometry(argv[i]) == MagickFalse)
5772               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5773             break;
5774           }
5775         if (LocaleCompare("synchronize",option+1) == 0)
5776           break;
5777         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5778       }
5779       case 't':
5780       {
5781         if (LocaleCompare("taint",option+1) == 0)
5782           break;
5783         if (LocaleCompare("texture",option+1) == 0)
5784           {
5785             if (*option == '+')
5786               break;
5787             i++;
5788             if (i == (ssize_t) argc)
5789               ThrowMogrifyException(OptionError,"MissingArgument",option);
5790             break;
5791           }
5792         if (LocaleCompare("tile",option+1) == 0)
5793           {
5794             if (*option == '+')
5795               break;
5796             i++;
5797             if (i == (ssize_t) (argc-1))
5798               ThrowMogrifyException(OptionError,"MissingArgument",option);
5799             break;
5800           }
5801         if (LocaleCompare("tile-offset",option+1) == 0)
5802           {
5803             if (*option == '+')
5804               break;
5805             i++;
5806             if (i == (ssize_t) argc)
5807               ThrowMogrifyException(OptionError,"MissingArgument",option);
5808             if (IsGeometry(argv[i]) == MagickFalse)
5809               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5810             break;
5811           }
5812         if (LocaleCompare("tint",option+1) == 0)
5813           {
5814             if (*option == '+')
5815               break;
5816             i++;
5817             if (i == (ssize_t) (argc-1))
5818               ThrowMogrifyException(OptionError,"MissingArgument",option);
5819             if (IsGeometry(argv[i]) == MagickFalse)
5820               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5821             break;
5822           }
5823         if (LocaleCompare("transform",option+1) == 0)
5824           break;
5825         if (LocaleCompare("transpose",option+1) == 0)
5826           break;
5827         if (LocaleCompare("transverse",option+1) == 0)
5828           break;
5829         if (LocaleCompare("threshold",option+1) == 0)
5830           {
5831             if (*option == '+')
5832               break;
5833             i++;
5834             if (i == (ssize_t) argc)
5835               ThrowMogrifyException(OptionError,"MissingArgument",option);
5836             if (IsGeometry(argv[i]) == MagickFalse)
5837               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5838             break;
5839           }
5840         if (LocaleCompare("thumbnail",option+1) == 0)
5841           {
5842             if (*option == '+')
5843               break;
5844             i++;
5845             if (i == (ssize_t) argc)
5846               ThrowMogrifyException(OptionError,"MissingArgument",option);
5847             if (IsGeometry(argv[i]) == MagickFalse)
5848               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5849             break;
5850           }
5851         if (LocaleCompare("transparent",option+1) == 0)
5852           {
5853             i++;
5854             if (i == (ssize_t) argc)
5855               ThrowMogrifyException(OptionError,"MissingArgument",option);
5856             break;
5857           }
5858         if (LocaleCompare("transparent-color",option+1) == 0)
5859           {
5860             if (*option == '+')
5861               break;
5862             i++;
5863             if (i == (ssize_t) (argc-1))
5864               ThrowMogrifyException(OptionError,"MissingArgument",option);
5865             break;
5866           }
5867         if (LocaleCompare("treedepth",option+1) == 0)
5868           {
5869             if (*option == '+')
5870               break;
5871             i++;
5872             if (i == (ssize_t) argc)
5873               ThrowMogrifyException(OptionError,"MissingArgument",option);
5874             if (IsGeometry(argv[i]) == MagickFalse)
5875               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5876             break;
5877           }
5878         if (LocaleCompare("trim",option+1) == 0)
5879           break;
5880         if (LocaleCompare("type",option+1) == 0)
5881           {
5882             ssize_t
5883               type;
5884
5885             if (*option == '+')
5886               break;
5887             i++;
5888             if (i == (ssize_t) argc)
5889               ThrowMogrifyException(OptionError,"MissingArgument",option);
5890             type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
5891             if (type < 0)
5892               ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5893                 argv[i]);
5894             break;
5895           }
5896         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5897       }
5898       case 'u':
5899       {
5900         if (LocaleCompare("undercolor",option+1) == 0)
5901           {
5902             if (*option == '+')
5903               break;
5904             i++;
5905             if (i == (ssize_t) argc)
5906               ThrowMogrifyException(OptionError,"MissingArgument",option);
5907             break;
5908           }
5909         if (LocaleCompare("unique-colors",option+1) == 0)
5910           break;
5911         if (LocaleCompare("units",option+1) == 0)
5912           {
5913             ssize_t
5914               units;
5915
5916             if (*option == '+')
5917               break;
5918             i++;
5919             if (i == (ssize_t) argc)
5920               ThrowMogrifyException(OptionError,"MissingArgument",option);
5921             units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
5922               argv[i]);
5923             if (units < 0)
5924               ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5925                 argv[i]);
5926             break;
5927           }
5928         if (LocaleCompare("unsharp",option+1) == 0)
5929           {
5930             i++;
5931             if (i == (ssize_t) argc)
5932               ThrowMogrifyException(OptionError,"MissingArgument",option);
5933             if (IsGeometry(argv[i]) == MagickFalse)
5934               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5935             break;
5936           }
5937         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5938       }
5939       case 'v':
5940       {
5941         if (LocaleCompare("verbose",option+1) == 0)
5942           {
5943             image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5944             break;
5945           }
5946         if ((LocaleCompare("version",option+1) == 0) ||
5947             (LocaleCompare("-version",option+1) == 0))
5948           {
5949             (void) FormatLocaleFile(stdout,"Version: %s\n",
5950               GetMagickVersion((size_t *) NULL));
5951             (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5952               GetMagickCopyright());
5953             (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5954               GetMagickFeatures());
5955             break;
5956           }
5957         if (LocaleCompare("view",option+1) == 0)
5958           {
5959             if (*option == '+')
5960               break;
5961             i++;
5962             if (i == (ssize_t) argc)
5963               ThrowMogrifyException(OptionError,"MissingArgument",option);
5964             break;
5965           }
5966         if (LocaleCompare("vignette",option+1) == 0)
5967           {
5968             if (*option == '+')
5969               break;
5970             i++;
5971             if (i == (ssize_t) argc)
5972               ThrowMogrifyException(OptionError,"MissingArgument",option);
5973             if (IsGeometry(argv[i]) == MagickFalse)
5974               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5975             break;
5976           }
5977         if (LocaleCompare("virtual-pixel",option+1) == 0)
5978           {
5979             ssize_t
5980               method;
5981
5982             if (*option == '+')
5983               break;
5984             i++;
5985             if (i == (ssize_t) argc)
5986               ThrowMogrifyException(OptionError,"MissingArgument",option);
5987             method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
5988               argv[i]);
5989             if (method < 0)
5990               ThrowMogrifyException(OptionError,
5991                 "UnrecognizedVirtualPixelMethod",argv[i]);
5992             break;
5993           }
5994         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5995       }
5996       case 'w':
5997       {
5998         if (LocaleCompare("wave",option+1) == 0)
5999           {
6000             i++;
6001             if (i == (ssize_t) argc)
6002               ThrowMogrifyException(OptionError,"MissingArgument",option);
6003             if (IsGeometry(argv[i]) == MagickFalse)
6004               ThrowMogrifyInvalidArgumentException(option,argv[i]);
6005             break;
6006           }
6007         if (LocaleCompare("weight",option+1) == 0)
6008           {
6009             if (*option == '+')
6010               break;
6011             i++;
6012             if (i == (ssize_t) (argc-1))
6013               ThrowMogrifyException(OptionError,"MissingArgument",option);
6014             break;
6015           }
6016         if (LocaleCompare("white-point",option+1) == 0)
6017           {
6018             if (*option == '+')
6019               break;
6020             i++;
6021             if (i == (ssize_t) argc)
6022               ThrowMogrifyException(OptionError,"MissingArgument",option);
6023             if (IsGeometry(argv[i]) == MagickFalse)
6024               ThrowMogrifyInvalidArgumentException(option,argv[i]);
6025             break;
6026           }
6027         if (LocaleCompare("white-threshold",option+1) == 0)
6028           {
6029             if (*option == '+')
6030               break;
6031             i++;
6032             if (i == (ssize_t) argc)
6033               ThrowMogrifyException(OptionError,"MissingArgument",option);
6034             if (IsGeometry(argv[i]) == MagickFalse)
6035               ThrowMogrifyInvalidArgumentException(option,argv[i]);
6036             break;
6037           }
6038         if (LocaleCompare("write",option+1) == 0)
6039           {
6040             i++;
6041             if (i == (ssize_t) (argc-1))
6042               ThrowMogrifyException(OptionError,"MissingArgument",option);
6043             break;
6044           }
6045         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6046       }
6047       case '?':
6048         break;
6049       default:
6050         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6051     }
6052     fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6053       FireOptionFlag) == 0 ?  MagickFalse : MagickTrue;
6054     if (fire != MagickFalse)
6055       FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6056   }
6057   if (k != 0)
6058     ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6059   if (i != (ssize_t) argc)
6060     ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6061   DestroyMogrify();
6062   return(status != 0 ? MagickTrue : MagickFalse);
6063 }
6064 \f
6065 /*
6066 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6067 %                                                                             %
6068 %                                                                             %
6069 %                                                                             %
6070 +     M o g r i f y I m a g e I n f o                                         %
6071 %                                                                             %
6072 %                                                                             %
6073 %                                                                             %
6074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6075 %
6076 %  MogrifyImageInfo() applies image processing settings to the image as
6077 %  prescribed by command line options.
6078 %
6079 %  The format of the MogrifyImageInfo method is:
6080 %
6081 %      MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6082 %        const char **argv,ExceptionInfo *exception)
6083 %
6084 %  A description of each parameter follows:
6085 %
6086 %    o image_info: the image info..
6087 %
6088 %    o argc: Specifies a pointer to an integer describing the number of
6089 %      elements in the argument vector.
6090 %
6091 %    o argv: Specifies a pointer to a text array containing the command line
6092 %      arguments.
6093 %
6094 %    o exception: return any errors or warnings in this structure.
6095 %
6096 */
6097 WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6098   const int argc,const char **argv,ExceptionInfo *exception)
6099 {
6100   const char
6101     *option;
6102
6103   GeometryInfo
6104     geometry_info;
6105
6106   ssize_t
6107     count;
6108
6109   register ssize_t
6110     i;
6111
6112   /*
6113     Initialize method variables.
6114   */
6115   assert(image_info != (ImageInfo *) NULL);
6116   assert(image_info->signature == MagickSignature);
6117   if (image_info->debug != MagickFalse)
6118     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6119       image_info->filename);
6120   if (argc < 0)
6121     return(MagickTrue);
6122   /*
6123     Set the image settings.
6124   */
6125   for (i=0; i < (ssize_t) argc; i++)
6126   {
6127     option=argv[i];
6128     if (IsCommandOption(option) == MagickFalse)
6129       continue;
6130     count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
6131     count=MagickMax(count,0L);
6132     if ((i+count) >= (ssize_t) argc)
6133       break;
6134     switch (*(option+1))
6135     {
6136       case 'a':
6137       {
6138         if (LocaleCompare("adjoin",option+1) == 0)
6139           {
6140             image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6141             break;
6142           }
6143         if (LocaleCompare("antialias",option+1) == 0)
6144           {
6145             image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6146             break;
6147           }
6148         if (LocaleCompare("attenuate",option+1) == 0)
6149           {
6150             if (*option == '+')
6151               {
6152                 (void) DeleteImageOption(image_info,option+1);
6153                 break;
6154               }
6155             (void) SetImageOption(image_info,option+1,argv[i+1]);
6156             break;
6157           }
6158         if (LocaleCompare("authenticate",option+1) == 0)
6159           {
6160             if (*option == '+')
6161               (void) CloneString(&image_info->authenticate,(char *) NULL);
6162             else
6163               (void) CloneString(&image_info->authenticate,argv[i+1]);
6164             break;
6165           }
6166         break;
6167       }
6168       case 'b':
6169       {
6170         if (LocaleCompare("background",option+1) == 0)
6171           {
6172             if (*option == '+')
6173               {
6174                 (void) DeleteImageOption(image_info,option+1);
6175                 (void) QueryColorDatabase(MogrifyBackgroundColor,
6176                   &image_info->background_color,exception);
6177                 break;
6178               }
6179             (void) SetImageOption(image_info,option+1,argv[i+1]);
6180             (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6181               exception);
6182             break;
6183           }
6184         if (LocaleCompare("bias",option+1) == 0)
6185           {
6186             if (*option == '+')
6187               {
6188                 (void) SetImageOption(image_info,option+1,"0.0");
6189                 break;
6190               }
6191             (void) SetImageOption(image_info,option+1,argv[i+1]);
6192             break;
6193           }
6194         if (LocaleCompare("black-point-compensation",option+1) == 0)
6195           {
6196             if (*option == '+')
6197               {
6198                 (void) SetImageOption(image_info,option+1,"false");
6199                 break;
6200               }
6201             (void) SetImageOption(image_info,option+1,"true");
6202             break;
6203           }
6204         if (LocaleCompare("blue-primary",option+1) == 0)
6205           {
6206             if (*option == '+')
6207               {
6208                 (void) SetImageOption(image_info,option+1,"0.0");
6209                 break;
6210               }
6211             (void) SetImageOption(image_info,option+1,argv[i+1]);
6212             break;
6213           }
6214         if (LocaleCompare("bordercolor",option+1) == 0)
6215           {
6216             if (*option == '+')
6217               {
6218                 (void) DeleteImageOption(image_info,option+1);
6219                 (void) QueryColorDatabase(MogrifyBorderColor,
6220                   &image_info->border_color,exception);
6221                 break;
6222               }
6223             (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6224               exception);
6225             (void) SetImageOption(image_info,option+1,argv[i+1]);
6226             break;
6227           }
6228         if (LocaleCompare("box",option+1) == 0)
6229           {
6230             if (*option == '+')
6231               {
6232                 (void) SetImageOption(image_info,"undercolor","none");
6233                 break;
6234               }
6235             (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6236             break;
6237           }
6238         break;
6239       }
6240       case 'c':
6241       {
6242         if (LocaleCompare("cache",option+1) == 0)
6243           {
6244             MagickSizeType
6245               limit;
6246
6247             limit=MagickResourceInfinity;
6248             if (LocaleCompare("unlimited",argv[i+1]) != 0)
6249               limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
6250             (void) SetMagickResourceLimit(MemoryResource,limit);
6251             (void) SetMagickResourceLimit(MapResource,2*limit);
6252             break;
6253           }
6254         if (LocaleCompare("caption",option+1) == 0)
6255           {
6256             if (*option == '+')
6257               {
6258                 (void) DeleteImageOption(image_info,option+1);
6259                 break;
6260               }
6261             (void) SetImageOption(image_info,option+1,argv[i+1]);
6262             break;
6263           }
6264         if (LocaleCompare("channel",option+1) == 0)
6265           {
6266             if (*option == '+')
6267               {
6268                 image_info->channel=DefaultChannels;
6269                 break;
6270               }
6271             image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6272             break;
6273           }
6274         if (LocaleCompare("colors",option+1) == 0)
6275           {
6276             image_info->colors=StringToUnsignedLong(argv[i+1]);
6277             break;
6278           }
6279         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               }
6287             image_info->colorspace=(ColorspaceType) ParseCommandOption(
6288               MagickColorspaceOptions,MagickFalse,argv[i+1]);
6289             (void) SetImageOption(image_info,option+1,argv[i+1]);
6290             break;
6291           }
6292         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               }
6320             image_info->compression=(CompressionType) ParseCommandOption(
6321               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               }
6390             image_info->depth=StringToUnsignedLong(argv[i+1]);
6391             break;
6392           }
6393         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           }
6403         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;
6430                 (void) SetImageOption(image_info,option+1,"none");
6431                 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               }
6459             image_info->endian=(EndianType) ParseCommandOption(
6460               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,'%'))
6519               if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
6520                 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               }
6532             image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
6533               1.0);
6534             (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               }
6583             image_info->interlace=(InterlaceType) ParseCommandOption(
6584               MagickInterlaceOptions,MagickFalse,argv[i+1]);
6585             (void) SetImageOption(image_info,option+1,argv[i+1]);
6586             break;
6587           }
6588         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           }
6598         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;
6656             type=(ResourceType) ParseCommandOption(MagickResourceOptions,
6657               MagickFalse,argv[i+1]);
6658             limit=MagickResourceInfinity;
6659             if (LocaleCompare("unlimited",argv[i+2]) != 0)
6660               limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
6661             (void) SetMagickResourceLimit(type,limit);
6662             break;
6663           }
6664         if (LocaleCompare("list",option+1) == 0)
6665           {
6666             ssize_t
6667               list;
6668
6669             /*
6670               Display configuration list.
6671             */
6672             list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
6673             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               {
6747                 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
6748                   exception);
6749                 break;
6750               }
6751             }
6752             break;
6753           }
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]);
6790                 (void) QueryColorDatabase(MogrifyMatteColor,
6791                   &image_info->matte_color,exception);
6792                 break;
6793               }
6794             (void) SetImageOption(image_info,option+1,argv[i+1]);
6795             (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6796               exception);
6797             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               }
6822             image_info->orientation=(OrientationType) ParseCommandOption(
6823               MagickOrientationOptions,MagickFalse,argv[i+1]);
6824             (void) SetImageOption(image_info,option+1,argv[i+1]);
6825             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);
6858             (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
6859               (unsigned long) geometry.width,(unsigned long) geometry.height);
6860             if (((flags & XValue) != 0) || ((flags & YValue) != 0))
6861               (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
6862                 (unsigned long) geometry.width,(unsigned long) geometry.height,
6863                 (long) geometry.x,(long) geometry.y);
6864             (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           }
6892         if (LocaleCompare("precision",option+1) == 0)
6893           {
6894             (void) SetMagickPrecision(StringToInteger(argv[i+1]));
6895             break;
6896           }
6897         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               }
6907             image_info->preview_type=(PreviewType) ParseCommandOption(
6908               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               }
6926             image_info->quality=StringToUnsignedLong(argv[i+1]);
6927             (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               }
6993             image_info->scene=StringToUnsignedLong(argv[i+1]);
6994             (void) SetImageOption(image_info,option+1,argv[i+1]);
6995             break;
6996           }
6997         if (LocaleCompare("seed",option+1) == 0)
6998           {
6999             size_t
7000               seed;
7001
7002             if (*option == '+')
7003               {
7004                 seed=(size_t) time((time_t *) NULL);
7005                 SeedPseudoRandomGenerator(seed);
7006                 break;
7007               }
7008             seed=StringToUnsignedLong(argv[i+1]);
7009             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           }
7043         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           }
7053         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               {
7092                 (void) QueryColorDatabase("none",&image_info->transparent_color,                  exception);
7093                 (void) SetImageOption(image_info,option+1,"none");
7094                 break;
7095               }
7096             (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7097               exception);
7098             (void) SetImageOption(image_info,option+1,argv[i+1]);
7099             break;
7100           }
7101         if (LocaleCompare("type",option+1) == 0)
7102           {
7103             if (*option == '+')
7104               {
7105                 image_info->type=UndefinedType;
7106                 (void) SetImageOption(image_info,option+1,"undefined");
7107                 break;
7108               }
7109             image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
7110               MagickFalse,argv[i+1]);
7111             (void) SetImageOption(image_info,option+1,argv[i+1]);
7112             break;
7113           }
7114         break;
7115       }
7116       case 'u':
7117       {
7118         if (LocaleCompare("undercolor",option+1) == 0)
7119           {
7120             if (*option == '+')
7121               {
7122                 (void) DeleteImageOption(image_info,option+1);
7123                 break;
7124               }
7125             (void) SetImageOption(image_info,option+1,argv[i+1]);
7126             break;
7127           }
7128         if (LocaleCompare("units",option+1) == 0)
7129           {
7130             if (*option == '+')
7131               {
7132                 image_info->units=UndefinedResolution;
7133                 (void) SetImageOption(image_info,option+1,"undefined");
7134                 break;
7135               }
7136             image_info->units=(ResolutionType) ParseCommandOption(
7137               MagickResolutionOptions,MagickFalse,argv[i+1]);
7138             (void) SetImageOption(image_info,option+1,argv[i+1]);
7139             break;
7140           }
7141         break;
7142       }
7143       case 'v':
7144       {
7145         if (LocaleCompare("verbose",option+1) == 0)
7146           {
7147             if (*option == '+')
7148               {
7149                 image_info->verbose=MagickFalse;
7150                 break;
7151               }
7152             image_info->verbose=MagickTrue;
7153             image_info->ping=MagickFalse;
7154             break;
7155           }
7156         if (LocaleCompare("view",option+1) == 0)
7157           {
7158             if (*option == '+')
7159               {
7160                 if (image_info->view != (char *) NULL)
7161                   image_info->view=DestroyString(image_info->view);
7162                 break;
7163               }
7164             (void) CloneString(&image_info->view,argv[i+1]);
7165             break;
7166           }
7167         if (LocaleCompare("virtual-pixel",option+1) == 0)
7168           {
7169             if (*option == '+')
7170               {
7171                 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7172                 (void) SetImageOption(image_info,option+1,"undefined");
7173                 break;
7174               }
7175             image_info->virtual_pixel_method=(VirtualPixelMethod)
7176               ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
7177               argv[i+1]);
7178             (void) SetImageOption(image_info,option+1,argv[i+1]);
7179             break;
7180           }
7181         break;
7182       }
7183       case 'w':
7184       {
7185         if (LocaleCompare("white-point",option+1) == 0)
7186           {
7187             if (*option == '+')
7188               {
7189                 (void) SetImageOption(image_info,option+1,"0.0");
7190                 break;
7191               }
7192             (void) SetImageOption(image_info,option+1,argv[i+1]);
7193             break;
7194           }
7195         break;
7196       }
7197       default:
7198         break;
7199     }
7200     i+=count;
7201   }
7202   return(MagickTrue);
7203 }
7204 \f
7205 /*
7206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7207 %                                                                             %
7208 %                                                                             %
7209 %                                                                             %
7210 +     M o g r i f y I m a g e L i s t                                         %
7211 %                                                                             %
7212 %                                                                             %
7213 %                                                                             %
7214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7215 %
7216 %  MogrifyImageList() applies any command line options that might affect the
7217 %  entire image list (e.g. -append, -coalesce, etc.).
7218 %
7219 %  The format of the MogrifyImage method is:
7220 %
7221 %      MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7222 %        const char **argv,Image **images,ExceptionInfo *exception)
7223 %
7224 %  A description of each parameter follows:
7225 %
7226 %    o image_info: the image info..
7227 %
7228 %    o argc: Specifies a pointer to an integer describing the number of
7229 %      elements in the argument vector.
7230 %
7231 %    o argv: Specifies a pointer to a text array containing the command line
7232 %      arguments.
7233 %
7234 %    o images: pointer to pointer of the first image in image list.
7235 %
7236 %    o exception: return any errors or warnings in this structure.
7237 %
7238 */
7239 WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7240   const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7241 {
7242   const char
7243     *option;
7244
7245   ImageInfo
7246     *mogrify_info;
7247
7248   MagickStatusType
7249     status;
7250
7251   PixelInterpolateMethod
7252    interpolate_method;
7253
7254   QuantizeInfo
7255     *quantize_info;
7256
7257   register ssize_t
7258     i;
7259
7260   ssize_t
7261     count,
7262     index;
7263
7264   /*
7265     Apply options to the image list.
7266   */
7267   assert(image_info != (ImageInfo *) NULL);
7268   assert(image_info->signature == MagickSignature);
7269   assert(images != (Image **) NULL);
7270   assert((*images)->previous == (Image *) NULL);
7271   assert((*images)->signature == MagickSignature);
7272   if ((*images)->debug != MagickFalse)
7273     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7274       (*images)->filename);
7275   if ((argc <= 0) || (*argv == (char *) NULL))
7276     return(MagickTrue);
7277   interpolate_method=UndefinedInterpolatePixel;
7278   mogrify_info=CloneImageInfo(image_info);
7279   quantize_info=AcquireQuantizeInfo(mogrify_info);
7280   status=MagickTrue;
7281   for (i=0; i < (ssize_t) argc; i++)
7282   {
7283     if (*images == (Image *) NULL)
7284       break;
7285     option=argv[i];
7286     if (IsCommandOption(option) == MagickFalse)
7287       continue;
7288     count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
7289     count=MagickMax(count,0L);
7290     if ((i+count) >= (ssize_t) argc)
7291       break;
7292     status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
7293     switch (*(option+1))
7294     {
7295       case 'a':
7296       {
7297         if (LocaleCompare("affinity",option+1) == 0)
7298           {
7299             (void) SyncImagesSettings(mogrify_info,*images);
7300             if (*option == '+')
7301               {
7302                 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7303                   exception);
7304                 break;
7305               }
7306             i++;
7307             break;
7308           }
7309         if (LocaleCompare("append",option+1) == 0)
7310           {
7311             Image
7312               *append_image;
7313
7314             (void) SyncImagesSettings(mogrify_info,*images);
7315             append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7316               MagickFalse,exception);
7317             if (append_image == (Image *) NULL)
7318               {
7319                 status=MagickFalse;
7320                 break;
7321               }
7322             *images=DestroyImageList(*images);
7323             *images=append_image;
7324             break;
7325           }
7326         if (LocaleCompare("average",option+1) == 0)
7327           {
7328             Image
7329               *average_image;
7330
7331             /*
7332               Average an image sequence (deprecated).
7333             */
7334             (void) SyncImagesSettings(mogrify_info,*images);
7335             average_image=EvaluateImages(*images,MeanEvaluateOperator,
7336               exception);
7337             if (average_image == (Image *) NULL)
7338               {
7339                 status=MagickFalse;
7340                 break;
7341               }
7342             *images=DestroyImageList(*images);
7343             *images=average_image;
7344             break;
7345           }
7346         break;
7347       }
7348       case 'c':
7349       {
7350         if (LocaleCompare("channel",option+1) == 0)
7351           {
7352             ChannelType
7353               channel;
7354
7355             if (*option == '+')
7356               {
7357                 channel=DefaultChannels;
7358                 break;
7359               }
7360             channel=(ChannelType) ParseChannelOption(argv[i+1]);
7361             SetPixelChannelMap(*images,channel);
7362             break;
7363           }
7364         if (LocaleCompare("clut",option+1) == 0)
7365           {
7366             Image
7367               *clut_image,
7368               *image;
7369
7370             (void) SyncImagesSettings(mogrify_info,*images);
7371             image=RemoveFirstImageFromList(images);
7372             clut_image=RemoveFirstImageFromList(images);
7373             if (clut_image == (Image *) NULL)
7374               {
7375                 status=MagickFalse;
7376                 break;
7377               }
7378             (void) ClutImage(image,clut_image,interpolate_method,exception);
7379             clut_image=DestroyImage(clut_image);
7380             *images=DestroyImageList(*images);
7381             *images=image;
7382             break;
7383           }
7384         if (LocaleCompare("coalesce",option+1) == 0)
7385           {
7386             Image
7387               *coalesce_image;
7388
7389             (void) SyncImagesSettings(mogrify_info,*images);
7390             coalesce_image=CoalesceImages(*images,exception);
7391             if (coalesce_image == (Image *) NULL)
7392               {
7393                 status=MagickFalse;
7394                 break;
7395               }
7396             *images=DestroyImageList(*images);
7397             *images=coalesce_image;
7398             break;
7399           }
7400         if (LocaleCompare("combine",option+1) == 0)
7401           {
7402             Image
7403               *combine_image;
7404
7405             (void) SyncImagesSettings(mogrify_info,*images);
7406             combine_image=CombineImages(*images,exception);
7407             if (combine_image == (Image *) NULL)
7408               {
7409                 status=MagickFalse;
7410                 break;
7411               }
7412             *images=DestroyImageList(*images);
7413             *images=combine_image;
7414             break;
7415           }
7416         if (LocaleCompare("composite",option+1) == 0)
7417           {
7418             Image
7419               *mask_image,
7420               *composite_image,
7421               *image;
7422
7423             RectangleInfo
7424               geometry;
7425
7426             (void) SyncImagesSettings(mogrify_info,*images);
7427             image=RemoveFirstImageFromList(images);
7428             composite_image=RemoveFirstImageFromList(images);
7429             if (composite_image == (Image *) NULL)
7430               {
7431                 status=MagickFalse;
7432                 break;
7433               }
7434             (void) TransformImage(&composite_image,(char *) NULL,
7435               composite_image->geometry);
7436             SetGeometry(composite_image,&geometry);
7437             (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7438             GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7439               &geometry);
7440             mask_image=RemoveFirstImageFromList(images);
7441             if (mask_image != (Image *) NULL)
7442               {
7443                 if ((image->compose == DisplaceCompositeOp) ||
7444                     (image->compose == DistortCompositeOp))
7445                   {
7446                     /*
7447                       Merge Y displacement into X displacement image.
7448                     */
7449                     (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7450                       mask_image,0,0);
7451                     mask_image=DestroyImage(mask_image);
7452                   }
7453                 else
7454                   {
7455                     /*
7456                       Set a blending mask for the composition.
7457                       Posible error, what if image->mask already set.
7458                     */
7459                     image->mask=mask_image;
7460                     (void) NegateImage(image->mask,MagickFalse,exception);
7461                   }
7462               }
7463             (void) CompositeImage(image,image->compose,composite_image,
7464               geometry.x,geometry.y);
7465             if (mask_image != (Image *) NULL)
7466               mask_image=image->mask=DestroyImage(image->mask);
7467             composite_image=DestroyImage(composite_image);
7468             InheritException(exception,&image->exception);
7469             *images=DestroyImageList(*images);
7470             *images=image;
7471             break;
7472           }
7473         break;
7474       }
7475       case 'd':
7476       {
7477         if (LocaleCompare("deconstruct",option+1) == 0)
7478           {
7479             Image
7480               *deconstruct_image;
7481
7482             (void) SyncImagesSettings(mogrify_info,*images);
7483             deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
7484               exception);
7485             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;
7510             quantize_info->dither_method=(DitherMethod) ParseCommandOption(
7511               MagickDitherOptions,MagickFalse,argv[i+1]);
7512             break;
7513           }
7514         if (LocaleCompare("duplicate",option+1) == 0)
7515           {
7516             Image
7517               *duplicate_images;
7518
7519             if (*option == '+')
7520               duplicate_images=DuplicateImages(*images,1,"-1",exception);
7521             else
7522               {
7523                 const char
7524                   *p;
7525
7526                 size_t
7527                   number_duplicates;
7528
7529                 number_duplicates=(size_t) StringToLong(argv[i+1]);
7530                 p=strchr(argv[i+1],',');
7531                 if (p == (const char *) NULL)
7532                   duplicate_images=DuplicateImages(*images,number_duplicates,
7533                     "-1",exception);
7534                 else
7535                   duplicate_images=DuplicateImages(*images,number_duplicates,p,
7536                     exception);
7537               }
7538             AppendImageToList(images, duplicate_images);
7539             (void) SyncImagesSettings(mogrify_info,*images);
7540             break;
7541           }
7542         break;
7543       }
7544       case 'e':
7545       {
7546         if (LocaleCompare("evaluate-sequence",option+1) == 0)
7547           {
7548             Image
7549               *evaluate_image;
7550
7551             MagickEvaluateOperator
7552               op;
7553
7554             (void) SyncImageSettings(mogrify_info,*images);
7555             op=(MagickEvaluateOperator) ParseCommandOption(
7556               MagickEvaluateOptions,MagickFalse,argv[i+1]);
7557             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       }
7569       case 'f':
7570       {
7571         if (LocaleCompare("fft",option+1) == 0)
7572           {
7573             Image
7574               *fourier_image;
7575
7576             /*
7577               Implements the discrete Fourier transform (DFT).
7578             */
7579             (void) SyncImageSettings(mogrify_info,*images);
7580             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           }
7588         if (LocaleCompare("flatten",option+1) == 0)
7589           {
7590             Image
7591               *flatten_image;
7592
7593             (void) SyncImagesSettings(mogrify_info,*images);
7594             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
7606             (void) SyncImagesSettings(mogrify_info,*images);
7607             fx_image=FxImage(*images,argv[i+1],exception);
7608             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
7627             (void) SyncImagesSettings(mogrify_info,*images);
7628             image=RemoveFirstImageFromList(images);
7629             hald_image=RemoveFirstImageFromList(images);
7630             if (hald_image == (Image *) NULL)
7631               {
7632                 status=MagickFalse;
7633                 break;
7634               }
7635             (void) HaldClutImage(image,hald_image,exception);
7636             hald_image=DestroyImage(hald_image);
7637             if (*images != (Image *) NULL)
7638               *images=DestroyImageList(*images);
7639             *images=image;
7640             break;
7641           }
7642         break;
7643       }
7644       case 'i':
7645       {
7646         if (LocaleCompare("ift",option+1) == 0)
7647           {
7648             Image
7649               *fourier_image,
7650               *magnitude_image,
7651               *phase_image;
7652
7653             /*
7654               Implements the inverse fourier discrete Fourier transform (DFT).
7655             */
7656             (void) SyncImagesSettings(mogrify_info,*images);
7657             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);
7666             if (fourier_image == (Image *) NULL)
7667               break;
7668             if (*images != (Image *) NULL)
7669               *images=DestroyImage(*images);
7670             *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 != '+')
7681               index=(ssize_t) StringToLong(argv[i+1]);
7682             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
7694               if (index == (ssize_t) GetImageListLength(*images))
7695                 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           }
7711         if (LocaleCompare("interpolate",option+1) == 0)
7712           {
7713             interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7714               MagickInterpolateOptions,MagickFalse,argv[i+1]);
7715             break;
7716           }
7717         break;
7718       }
7719       case 'l':
7720       {
7721         if (LocaleCompare("layers",option+1) == 0)
7722           {
7723             Image
7724               *layers;
7725
7726             ImageLayerMethod
7727               method;
7728
7729             (void) SyncImagesSettings(mogrify_info,*images);
7730             layers=(Image *) NULL;
7731             method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
7732               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               {
7745                 layers=CompareImagesLayers(*images,method,exception);
7746                 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                   }
7797                 *images=DestroyImageList(*images);
7798                 *images=layers;
7799                 layers=OptimizeImageLayers(*images,exception);
7800                 if (layers == (Image *) NULL)
7801                   {
7802                     status=MagickFalse;
7803                     break;
7804                   }
7805                 *images=DestroyImageList(*images);
7806                 *images=layers;
7807                 layers=(Image *) NULL;
7808                 OptimizeImageTransparency(*images,exception);
7809                 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7810                   exception);
7811                 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;
7870                 option=GetImageOption(mogrify_info,"compose");
7871                 if (option != (const char *) NULL)
7872                   compose=(CompositeOperator) ParseCommandOption(
7873                     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;
7882             InheritException(exception,&layers->exception);
7883             *images=DestroyImageList(*images);
7884             *images=layers;
7885             break;
7886           }
7887         break;
7888       }
7889       case 'm':
7890       {
7891         if (LocaleCompare("map",option+1) == 0)
7892           {
7893             (void) SyncImagesSettings(mogrify_info,*images);
7894             if (*option == '+')
7895               {
7896                 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7897                   exception);
7898                 break;
7899               }
7900             i++;
7901             break;
7902           }
7903         if (LocaleCompare("maximum",option+1) == 0)
7904           {
7905             Image
7906               *maximum_image;
7907
7908             /*
7909               Maximum image sequence (deprecated).
7910             */
7911             (void) SyncImagesSettings(mogrify_info,*images);
7912             maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
7913             if (maximum_image == (Image *) NULL)
7914               {
7915                 status=MagickFalse;
7916                 break;
7917               }
7918             *images=DestroyImageList(*images);
7919             *images=maximum_image;
7920             break;
7921           }
7922         if (LocaleCompare("minimum",option+1) == 0)
7923           {
7924             Image
7925               *minimum_image;
7926
7927             /*
7928               Minimum image sequence (deprecated).
7929             */
7930             (void) SyncImagesSettings(mogrify_info,*images);
7931             minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
7932             if (minimum_image == (Image *) NULL)
7933               {
7934                 status=MagickFalse;
7935                 break;
7936               }
7937             *images=DestroyImageList(*images);
7938             *images=minimum_image;
7939             break;
7940           }
7941         if (LocaleCompare("morph",option+1) == 0)
7942           {
7943             Image
7944               *morph_image;
7945
7946             (void) SyncImagesSettings(mogrify_info,*images);
7947             morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
7948               exception);
7949             if (morph_image == (Image *) NULL)
7950               {
7951                 status=MagickFalse;
7952                 break;
7953               }
7954             *images=DestroyImageList(*images);
7955             *images=morph_image;
7956             break;
7957           }
7958         if (LocaleCompare("mosaic",option+1) == 0)
7959           {
7960             Image
7961               *mosaic_image;
7962
7963             (void) SyncImagesSettings(mogrify_info,*images);
7964             mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7965             if (mosaic_image == (Image *) NULL)
7966               {
7967                 status=MagickFalse;
7968                 break;
7969               }
7970             *images=DestroyImageList(*images);
7971             *images=mosaic_image;
7972             break;
7973           }
7974         break;
7975       }
7976       case 'p':
7977       {
7978         if (LocaleCompare("print",option+1) == 0)
7979           {
7980             char
7981               *string;
7982
7983             (void) SyncImagesSettings(mogrify_info,*images);
7984             string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7985               exception);
7986             if (string == (char *) NULL)
7987               break;
7988             (void) FormatLocaleFile(stdout,"%s",string);
7989             string=DestroyString(string);
7990           }
7991         if (LocaleCompare("process",option+1) == 0)
7992           {
7993             char
7994               **arguments;
7995
7996             int
7997               j,
7998               number_arguments;
7999
8000             (void) SyncImagesSettings(mogrify_info,*images);
8001             arguments=StringToArgv(argv[i+1],&number_arguments);
8002             if (arguments == (char **) NULL)
8003               break;
8004             if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8005               {
8006                 char
8007                   breaker,
8008                   quote,
8009                   *token;
8010
8011                 const char
8012                   *arguments;
8013
8014                 int
8015                   next,
8016                   status;
8017
8018                 size_t
8019                   length;
8020
8021                 TokenInfo
8022                   *token_info;
8023
8024                 /*
8025                   Support old style syntax, filter="-option arg".
8026                 */
8027                 length=strlen(argv[i+1]);
8028                 token=(char *) NULL;
8029                 if (~length >= (MaxTextExtent-1))
8030                   token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8031                     sizeof(*token));
8032                 if (token == (char *) NULL)
8033                   break;
8034                 next=0;
8035                 arguments=argv[i+1];
8036                 token_info=AcquireTokenInfo();
8037                 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8038                   "\"",'\0',&breaker,&next,&quote);
8039                 token_info=DestroyTokenInfo(token_info);
8040                 if (status == 0)
8041                   {
8042                     const char
8043                       *argv;
8044
8045                     argv=(&(arguments[next]));
8046                     (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8047                       exception);
8048                   }
8049                 token=DestroyString(token);
8050                 break;
8051               }
8052             (void) SubstituteString(&arguments[1],"-","");
8053             (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8054               number_arguments-2,(const char **) arguments+2,exception);
8055             for (j=0; j < number_arguments; j++)
8056               arguments[j]=DestroyString(arguments[j]);
8057             arguments=(char **) RelinquishMagickMemory(arguments);
8058             break;
8059           }
8060         break;
8061       }
8062       case 'r':
8063       {
8064         if (LocaleCompare("reverse",option+1) == 0)
8065           {
8066             ReverseImageList(images);
8067             InheritException(exception,&(*images)->exception);
8068             break;
8069           }
8070         break;
8071       }
8072       case 's':
8073       {
8074         if (LocaleCompare("smush",option+1) == 0)
8075           {
8076             Image
8077               *smush_image;
8078
8079             ssize_t
8080               offset;
8081
8082             (void) SyncImagesSettings(mogrify_info,*images);
8083             offset=(ssize_t) StringToLong(argv[i+1]);
8084             smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8085               MagickFalse,offset,exception);
8086             if (smush_image == (Image *) NULL)
8087               {
8088                 status=MagickFalse;
8089                 break;
8090               }
8091             *images=DestroyImageList(*images);
8092             *images=smush_image;
8093             break;
8094           }
8095         if (LocaleCompare("swap",option+1) == 0)
8096           {
8097             Image
8098               *p,
8099               *q,
8100               *swap;
8101
8102             ssize_t
8103               swap_index;
8104
8105             index=(-1);
8106             swap_index=(-2);
8107             if (*option != '+')
8108               {
8109                 GeometryInfo
8110                   geometry_info;
8111
8112                 MagickStatusType
8113                   flags;
8114
8115                 swap_index=(-1);
8116                 flags=ParseGeometry(argv[i+1],&geometry_info);
8117                 index=(ssize_t) geometry_info.rho;
8118                 if ((flags & SigmaValue) != 0)
8119                   swap_index=(ssize_t) geometry_info.sigma;
8120               }
8121             p=GetImageFromList(*images,index);
8122             q=GetImageFromList(*images,swap_index);
8123             if ((p == (Image *) NULL) || (q == (Image *) NULL))
8124               {
8125                 (void) ThrowMagickException(exception,GetMagickModule(),
8126                   OptionError,"NoSuchImage","`%s'",(*images)->filename);
8127                 status=MagickFalse;
8128                 break;
8129               }
8130             if (p == q)
8131               break;
8132             swap=CloneImage(p,0,0,MagickTrue,exception);
8133             ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8134             ReplaceImageInList(&q,swap);
8135             *images=GetFirstImageInList(q);
8136             break;
8137           }
8138         break;
8139       }
8140       case 'w':
8141       {
8142         if (LocaleCompare("write",option+1) == 0)
8143           {
8144             char
8145               key[MaxTextExtent];
8146
8147             Image
8148               *write_images;
8149
8150             ImageInfo
8151               *write_info;
8152
8153             (void) SyncImagesSettings(mogrify_info,*images);
8154             (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8155             (void) DeleteImageRegistry(key);
8156             write_images=(*images);
8157             if (*option == '+')
8158               write_images=CloneImageList(*images,exception);
8159             write_info=CloneImageInfo(mogrify_info);
8160             status&=WriteImages(write_info,write_images,argv[i+1],exception);
8161             write_info=DestroyImageInfo(write_info);
8162             if (*option == '+')
8163               write_images=DestroyImageList(write_images);
8164             break;
8165           }
8166         break;
8167       }
8168       default:
8169         break;
8170     }
8171     i+=count;
8172   }
8173   quantize_info=DestroyQuantizeInfo(quantize_info);
8174   mogrify_info=DestroyImageInfo(mogrify_info);
8175   status&=MogrifyImageInfo(image_info,argc,argv,exception);
8176   return(status != 0 ? MagickTrue : MagickFalse);
8177 }
8178 \f
8179 /*
8180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8181 %                                                                             %
8182 %                                                                             %
8183 %                                                                             %
8184 +     M o g r i f y I m a g e s                                               %
8185 %                                                                             %
8186 %                                                                             %
8187 %                                                                             %
8188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8189 %
8190 %  MogrifyImages() applies image processing options to a sequence of images as
8191 %  prescribed by command line options.
8192 %
8193 %  The format of the MogrifyImage method is:
8194 %
8195 %      MagickBooleanType MogrifyImages(ImageInfo *image_info,
8196 %        const MagickBooleanType post,const int argc,const char **argv,
8197 %        Image **images,Exceptioninfo *exception)
8198 %
8199 %  A description of each parameter follows:
8200 %
8201 %    o image_info: the image info..
8202 %
8203 %    o post: If true, post process image list operators otherwise pre-process.
8204 %
8205 %    o argc: Specifies a pointer to an integer describing the number of
8206 %      elements in the argument vector.
8207 %
8208 %    o argv: Specifies a pointer to a text array containing the command line
8209 %      arguments.
8210 %
8211 %    o images: pointer to a pointer of the first image in image list.
8212 %
8213 %    o exception: return any errors or warnings in this structure.
8214 %
8215 */
8216 WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8217   const MagickBooleanType post,const int argc,const char **argv,
8218   Image **images,ExceptionInfo *exception)
8219 {
8220 #define MogrifyImageTag  "Mogrify/Image"
8221
8222   MagickStatusType
8223     status;
8224
8225   MagickBooleanType
8226     proceed;
8227
8228   size_t
8229     n;
8230
8231   register ssize_t
8232     i;
8233
8234   assert(image_info != (ImageInfo *) NULL);
8235   assert(image_info->signature == MagickSignature);
8236   if (images == (Image **) NULL)
8237     return(MogrifyImage(image_info,argc,argv,images,exception));
8238   assert((*images)->previous == (Image *) NULL);
8239   assert((*images)->signature == MagickSignature);
8240   if ((*images)->debug != MagickFalse)
8241     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8242       (*images)->filename);
8243   if ((argc <= 0) || (*argv == (char *) NULL))
8244     return(MagickTrue);
8245   (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8246     (void *) NULL);
8247   status=0;
8248
8249 #if 0
8250   (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8251     post?"post":"pre");
8252 #endif
8253
8254   /*
8255     Pre-process multi-image sequence operators
8256   */
8257   if (post == MagickFalse)
8258     status&=MogrifyImageList(image_info,argc,argv,images,exception);
8259   /*
8260     For each image, process simple single image operators
8261   */
8262   i=0;
8263   n=GetImageListLength(*images);
8264   for ( ; ; )
8265   {
8266 #if 0
8267   (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8268     GetImageIndexInList(*images),(long)GetImageListLength(*images));
8269 #endif
8270     status&=MogrifyImage(image_info,argc,argv,images,exception);
8271     proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
8272     if (proceed == MagickFalse)
8273       break;
8274     if ( (*images)->next == (Image *) NULL )
8275       break;
8276     *images=(*images)->next;
8277     i++;
8278   }
8279   assert( *images != (Image *) NULL );
8280 #if 0
8281   (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8282     GetImageIndexInList(*images),(long)GetImageListLength(*images));
8283 #endif
8284
8285   /*
8286     Post-process, multi-image sequence operators
8287   */
8288   *images=GetFirstImageInList(*images);
8289   if (post != MagickFalse)
8290     status&=MogrifyImageList(image_info,argc,argv,images,exception);
8291   return(status != 0 ? MagickTrue : MagickFalse);
8292 }