]> granicus.if.org Git - imagemagick/blob - MagickWand/mogrify.c
(no commit message)
[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) QueryMagickColorCompliance(token,AllCompliance,&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) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
939                   &draw_info->border_color,exception);
940                 break;
941               }
942             (void) QueryColorCompliance(argv[i+1],AllCompliance,
943               &draw_info->border_color,exception);
944             break;
945           }
946         if (LocaleCompare("box",option+1) == 0)
947           {
948             (void) QueryColorCompliance(argv[i+1],AllCompliance,
949               &draw_info->undercolor,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) QueryMagickColorCompliance("none",AllCompliance,&fill,
1556                   exception);
1557                 (void) QueryColorCompliance("none",AllCompliance,
1558                   &draw_info->fill,exception);
1559                 if (draw_info->fill_pattern != (Image *) NULL)
1560                   draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1561                 break;
1562               }
1563             sans=AcquireExceptionInfo();
1564             (void) QueryMagickColorCompliance(argv[i+1],AllCompliance,&fill,
1565               sans);
1566             status=QueryColorCompliance(argv[i+1],AllCompliance,
1567               &draw_info->fill,sans);
1568             sans=DestroyExceptionInfo(sans);
1569             if (status == MagickFalse)
1570               draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1571                 exception);
1572             break;
1573           }
1574         if (LocaleCompare("flip",option+1) == 0)
1575           {
1576             /*
1577               Flip image scanlines.
1578             */
1579             (void) SyncImageSettings(mogrify_info,*image);
1580             mogrify_image=FlipImage(*image,exception);
1581             break;
1582           }
1583         if (LocaleCompare("floodfill",option+1) == 0)
1584           {
1585             PixelInfo
1586               target;
1587
1588             /*
1589               Floodfill image.
1590             */
1591             (void) SyncImageSettings(mogrify_info,*image);
1592             (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1593             (void) QueryMagickColorCompliance(argv[i+2],AllCompliance,&target,
1594               exception);
1595             (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
1596               geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
1597             break;
1598           }
1599         if (LocaleCompare("flop",option+1) == 0)
1600           {
1601             /*
1602               Flop image scanlines.
1603             */
1604             (void) SyncImageSettings(mogrify_info,*image);
1605             mogrify_image=FlopImage(*image,exception);
1606             break;
1607           }
1608         if (LocaleCompare("font",option+1) == 0)
1609           {
1610             if (*option == '+')
1611               {
1612                 if (draw_info->font != (char *) NULL)
1613                   draw_info->font=DestroyString(draw_info->font);
1614                 break;
1615               }
1616             (void) CloneString(&draw_info->font,argv[i+1]);
1617             break;
1618           }
1619         if (LocaleCompare("format",option+1) == 0)
1620           {
1621             format=argv[i+1];
1622             break;
1623           }
1624         if (LocaleCompare("frame",option+1) == 0)
1625           {
1626             FrameInfo
1627               frame_info;
1628
1629             /*
1630               Surround image with an ornamental border.
1631             */
1632             (void) SyncImageSettings(mogrify_info,*image);
1633             flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1634             frame_info.width=geometry.width;
1635             frame_info.height=geometry.height;
1636             if ((flags & HeightValue) == 0)
1637               frame_info.height=geometry.width;
1638             frame_info.outer_bevel=geometry.x;
1639             frame_info.inner_bevel=geometry.y;
1640             frame_info.x=(ssize_t) frame_info.width;
1641             frame_info.y=(ssize_t) frame_info.height;
1642             frame_info.width=(*image)->columns+2*frame_info.width;
1643             frame_info.height=(*image)->rows+2*frame_info.height;
1644             mogrify_image=FrameImage(*image,&frame_info,compose,exception);
1645             break;
1646           }
1647         if (LocaleCompare("function",option+1) == 0)
1648           {
1649             char
1650               *arguments,
1651               token[MaxTextExtent];
1652
1653             const char
1654               *p;
1655
1656             double
1657               *parameters;
1658
1659             MagickFunction
1660               function;
1661
1662             register ssize_t
1663               x;
1664
1665             size_t
1666               number_parameters;
1667
1668             /*
1669               Function Modify Image Values
1670             */
1671             (void) SyncImageSettings(mogrify_info,*image);
1672             function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1673               MagickFalse,argv[i+1]);
1674             arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1675               exception);
1676             if (arguments == (char *) NULL)
1677               break;
1678             p=(char *) arguments;
1679             for (x=0; *p != '\0'; x++)
1680             {
1681               GetMagickToken(p,&p,token);
1682               if (*token == ',')
1683                 GetMagickToken(p,&p,token);
1684             }
1685             number_parameters=(size_t) x;
1686             parameters=(double *) AcquireQuantumMemory(number_parameters,
1687               sizeof(*parameters));
1688             if (parameters == (double *) NULL)
1689               ThrowWandFatalException(ResourceLimitFatalError,
1690                 "MemoryAllocationFailed",(*image)->filename);
1691             (void) ResetMagickMemory(parameters,0,number_parameters*
1692               sizeof(*parameters));
1693             p=(char *) arguments;
1694             for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1695             {
1696               GetMagickToken(p,&p,token);
1697               if (*token == ',')
1698                 GetMagickToken(p,&p,token);
1699               parameters[x]=InterpretLocaleValue(token,(char **) NULL);
1700             }
1701             arguments=DestroyString(arguments);
1702             (void) FunctionImage(*image,function,number_parameters,parameters,
1703               exception);
1704             parameters=(double *) RelinquishMagickMemory(parameters);
1705             break;
1706           }
1707         break;
1708       }
1709       case 'g':
1710       {
1711         if (LocaleCompare("gamma",option+1) == 0)
1712           {
1713             /*
1714               Gamma image.
1715             */
1716             (void) SyncImageSettings(mogrify_info,*image);
1717             if (*option == '+')
1718               (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
1719             else
1720               (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1721                 (char **) NULL),exception);
1722             break;
1723           }
1724         if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1725             (LocaleCompare("gaussian",option+1) == 0))
1726           {
1727             /*
1728               Gaussian blur image.
1729             */
1730             (void) SyncImageSettings(mogrify_info,*image);
1731             flags=ParseGeometry(argv[i+1],&geometry_info);
1732             if ((flags & SigmaValue) == 0)
1733               geometry_info.sigma=1.0;
1734             if ((flags & XiValue) == 0)
1735               geometry_info.xi=0.0;
1736             mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1737               geometry_info.sigma,geometry_info.xi,exception);
1738             break;
1739           }
1740         if (LocaleCompare("geometry",option+1) == 0)
1741           {
1742               /*
1743                 Record Image offset, Resize last image.
1744               */
1745             (void) SyncImageSettings(mogrify_info,*image);
1746             if (*option == '+')
1747               {
1748                 if ((*image)->geometry != (char *) NULL)
1749                   (*image)->geometry=DestroyString((*image)->geometry);
1750                 break;
1751               }
1752             flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1753             if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1754               (void) CloneString(&(*image)->geometry,argv[i+1]);
1755             else
1756               mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1757                 (*image)->filter,(*image)->blur,exception);
1758             break;
1759           }
1760         if (LocaleCompare("gravity",option+1) == 0)
1761           {
1762             if (*option == '+')
1763               {
1764                 draw_info->gravity=UndefinedGravity;
1765                 break;
1766               }
1767             draw_info->gravity=(GravityType) ParseCommandOption(
1768               MagickGravityOptions,MagickFalse,argv[i+1]);
1769             break;
1770           }
1771         break;
1772       }
1773       case 'h':
1774       {
1775         if (LocaleCompare("highlight-color",option+1) == 0)
1776           {
1777             (void) SetImageArtifact(*image,option+1,argv[i+1]);
1778             break;
1779           }
1780         break;
1781       }
1782       case 'i':
1783       {
1784         if (LocaleCompare("identify",option+1) == 0)
1785           {
1786             char
1787               *text;
1788
1789             (void) SyncImageSettings(mogrify_info,*image);
1790             if (format == (char *) NULL)
1791               {
1792                 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1793                   exception);
1794                 break;
1795               }
1796             text=InterpretImageProperties(mogrify_info,*image,format,
1797               exception);
1798             if (text == (char *) NULL)
1799               break;
1800             (void) fputs(text,stdout);
1801             (void) fputc('\n',stdout);
1802             text=DestroyString(text);
1803             break;
1804           }
1805         if (LocaleCompare("implode",option+1) == 0)
1806           {
1807             /*
1808               Implode image.
1809             */
1810             (void) SyncImageSettings(mogrify_info,*image);
1811             (void) ParseGeometry(argv[i+1],&geometry_info);
1812             mogrify_image=ImplodeImage(*image,geometry_info.rho,
1813               interpolate_method,exception);
1814             break;
1815           }
1816         if (LocaleCompare("interline-spacing",option+1) == 0)
1817           {
1818             if (*option == '+')
1819               (void) ParseGeometry("0",&geometry_info);
1820             else
1821               (void) ParseGeometry(argv[i+1],&geometry_info);
1822             draw_info->interline_spacing=geometry_info.rho;
1823             break;
1824           }
1825         if (LocaleCompare("interpolate",option+1) == 0)
1826           {
1827             interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1828               MagickInterpolateOptions,MagickFalse,argv[i+1]);
1829             break;
1830           }
1831         if (LocaleCompare("interword-spacing",option+1) == 0)
1832           {
1833             if (*option == '+')
1834               (void) ParseGeometry("0",&geometry_info);
1835             else
1836               (void) ParseGeometry(argv[i+1],&geometry_info);
1837             draw_info->interword_spacing=geometry_info.rho;
1838             break;
1839           }
1840         break;
1841       }
1842       case 'k':
1843       {
1844         if (LocaleCompare("kerning",option+1) == 0)
1845           {
1846             if (*option == '+')
1847               (void) ParseGeometry("0",&geometry_info);
1848             else
1849               (void) ParseGeometry(argv[i+1],&geometry_info);
1850             draw_info->kerning=geometry_info.rho;
1851             break;
1852           }
1853         break;
1854       }
1855       case 'l':
1856       {
1857         if (LocaleCompare("lat",option+1) == 0)
1858           {
1859             /*
1860               Local adaptive threshold image.
1861             */
1862             (void) SyncImageSettings(mogrify_info,*image);
1863             flags=ParseGeometry(argv[i+1],&geometry_info);
1864             if ((flags & PercentValue) != 0)
1865               geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1866             mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1867               geometry_info.rho,(size_t) geometry_info.sigma,(double)
1868               geometry_info.xi,exception);
1869             break;
1870           }
1871         if (LocaleCompare("level",option+1) == 0)
1872           {
1873             MagickRealType
1874               black_point,
1875               gamma,
1876               white_point;
1877
1878             MagickStatusType
1879               flags;
1880
1881             /*
1882               Parse levels.
1883             */
1884             (void) SyncImageSettings(mogrify_info,*image);
1885             flags=ParseGeometry(argv[i+1],&geometry_info);
1886             black_point=geometry_info.rho;
1887             white_point=(MagickRealType) QuantumRange;
1888             if ((flags & SigmaValue) != 0)
1889               white_point=geometry_info.sigma;
1890             gamma=1.0;
1891             if ((flags & XiValue) != 0)
1892               gamma=geometry_info.xi;
1893             if ((flags & PercentValue) != 0)
1894               {
1895                 black_point*=(MagickRealType) (QuantumRange/100.0);
1896                 white_point*=(MagickRealType) (QuantumRange/100.0);
1897               }
1898             if ((flags & SigmaValue) == 0)
1899               white_point=(MagickRealType) QuantumRange-black_point;
1900             if ((*option == '+') || ((flags & AspectValue) != 0))
1901               (void) LevelizeImage(*image,black_point,white_point,gamma,
1902                 exception);
1903             else
1904               (void) LevelImage(*image,black_point,white_point,gamma,
1905                 exception);
1906             InheritException(exception,&(*image)->exception);
1907             break;
1908           }
1909         if (LocaleCompare("level-colors",option+1) == 0)
1910           {
1911             char
1912               token[MaxTextExtent];
1913
1914             const char
1915               *p;
1916
1917             PixelInfo
1918               black_point,
1919               white_point;
1920
1921             p=(const char *) argv[i+1];
1922             GetMagickToken(p,&p,token);  /* get black point color */
1923             if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1924               (void) QueryMagickColorCompliance(token,AllCompliance,
1925                 &black_point,exception);
1926             else
1927               (void) QueryMagickColorCompliance("#000000",AllCompliance,
1928                 &black_point,exception);
1929             if (isalpha((int) token[0]) || (token[0] == '#'))
1930               GetMagickToken(p,&p,token);
1931             if (*token == '\0')
1932               white_point=black_point; /* set everything to that color */
1933             else
1934               {
1935                 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1936                   GetMagickToken(p,&p,token); /* Get white point color. */
1937                 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1938                   (void) QueryMagickColorCompliance(token,AllCompliance,
1939                     &white_point,exception);
1940                 else
1941                   (void) QueryMagickColorCompliance("#ffffff",AllCompliance,
1942                     &white_point,exception);
1943               }
1944             (void) LevelImageColors(*image,&black_point,&white_point,
1945               *option == '+' ? MagickTrue : MagickFalse,exception);
1946             break;
1947           }
1948         if (LocaleCompare("linear-stretch",option+1) == 0)
1949           {
1950             double
1951               black_point,
1952               white_point;
1953
1954             MagickStatusType
1955               flags;
1956
1957             (void) SyncImageSettings(mogrify_info,*image);
1958             flags=ParseGeometry(argv[i+1],&geometry_info);
1959             black_point=geometry_info.rho;
1960             white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1961             if ((flags & SigmaValue) != 0)
1962               white_point=geometry_info.sigma;
1963             if ((flags & PercentValue) != 0)
1964               {
1965                 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1966                 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1967               }
1968             if ((flags & SigmaValue) == 0)
1969               white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1970                 black_point;
1971             (void) LinearStretchImage(*image,black_point,white_point,exception);
1972             InheritException(exception,&(*image)->exception);
1973             break;
1974           }
1975         if (LocaleCompare("linewidth",option+1) == 0)
1976           {
1977             draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1978               (char **) NULL);
1979             break;
1980           }
1981         if (LocaleCompare("liquid-rescale",option+1) == 0)
1982           {
1983             /*
1984               Liquid rescale image.
1985             */
1986             (void) SyncImageSettings(mogrify_info,*image);
1987             flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1988             if ((flags & XValue) == 0)
1989               geometry.x=1;
1990             if ((flags & YValue) == 0)
1991               geometry.y=0;
1992             mogrify_image=LiquidRescaleImage(*image,geometry.width,
1993               geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1994             break;
1995           }
1996         if (LocaleCompare("lowlight-color",option+1) == 0)
1997           {
1998             (void) SetImageArtifact(*image,option+1,argv[i+1]);
1999             break;
2000           }
2001         break;
2002       }
2003       case 'm':
2004       {
2005         if (LocaleCompare("map",option+1) == 0)
2006           {
2007             Image
2008               *remap_image;
2009
2010             /*
2011               Transform image colors to match this set of colors.
2012             */
2013             (void) SyncImageSettings(mogrify_info,*image);
2014             if (*option == '+')
2015               break;
2016             remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2017             if (remap_image == (Image *) NULL)
2018               break;
2019             (void) RemapImage(quantize_info,*image,remap_image,exception);
2020             remap_image=DestroyImage(remap_image);
2021             break;
2022           }
2023         if (LocaleCompare("mask",option+1) == 0)
2024           {
2025             Image
2026               *mask;
2027
2028             (void) SyncImageSettings(mogrify_info,*image);
2029             if (*option == '+')
2030               {
2031                 /*
2032                   Remove a mask.
2033                 */
2034                 (void) SetImageMask(*image,(Image *) NULL,exception);
2035                 break;
2036               }
2037             /*
2038               Set the image mask.
2039             */
2040             mask=GetImageCache(mogrify_info,argv[i+1],exception);
2041             if (mask == (Image *) NULL)
2042               break;
2043             (void) SetImageMask(*image,mask,exception);
2044             mask=DestroyImage(mask);
2045             break;
2046           }
2047         if (LocaleCompare("matte",option+1) == 0)
2048           {
2049             (void) SetImageAlphaChannel(*image,(*option == '-') ?
2050               SetAlphaChannel : DeactivateAlphaChannel,exception);
2051             break;
2052           }
2053         if (LocaleCompare("median",option+1) == 0)
2054           {
2055             /*
2056               Median filter image.
2057             */
2058             (void) SyncImageSettings(mogrify_info,*image);
2059             flags=ParseGeometry(argv[i+1],&geometry_info);
2060             if ((flags & SigmaValue) == 0)
2061               geometry_info.sigma=geometry_info.rho;
2062             mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2063               geometry_info.rho,(size_t) geometry_info.sigma,exception);
2064             break;
2065           }
2066         if (LocaleCompare("mode",option+1) == 0)
2067           {
2068             /*
2069               Mode image.
2070             */
2071             (void) SyncImageSettings(mogrify_info,*image);
2072             flags=ParseGeometry(argv[i+1],&geometry_info);
2073             if ((flags & SigmaValue) == 0)
2074               geometry_info.sigma=geometry_info.rho;
2075             mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2076               geometry_info.rho,(size_t) geometry_info.sigma,exception);
2077             break;
2078           }
2079         if (LocaleCompare("modulate",option+1) == 0)
2080           {
2081             (void) SyncImageSettings(mogrify_info,*image);
2082             (void) ModulateImage(*image,argv[i+1],exception);
2083             break;
2084           }
2085         if (LocaleCompare("monitor",option+1) == 0)
2086           {
2087             if (*option == '+')
2088               {
2089                 (void) SetImageProgressMonitor(*image,
2090                   (MagickProgressMonitor) NULL,(void *) NULL);
2091                 break;
2092               }
2093             (void) SetImageProgressMonitor(*image,MonitorProgress,
2094               (void *) NULL);
2095             break;
2096           }
2097         if (LocaleCompare("monochrome",option+1) == 0)
2098           {
2099             (void) SyncImageSettings(mogrify_info,*image);
2100             (void) SetImageType(*image,BilevelType,exception);
2101             break;
2102           }
2103         if (LocaleCompare("morphology",option+1) == 0)
2104           {
2105             char
2106               token[MaxTextExtent];
2107
2108             const char
2109               *p;
2110
2111             KernelInfo
2112               *kernel;
2113
2114             MorphologyMethod
2115               method;
2116
2117             ssize_t
2118               iterations;
2119
2120             /*
2121               Morphological Image Operation
2122             */
2123             (void) SyncImageSettings(mogrify_info,*image);
2124             p=argv[i+1];
2125             GetMagickToken(p,&p,token);
2126             method=(MorphologyMethod) ParseCommandOption(
2127               MagickMorphologyOptions,MagickFalse,token);
2128             iterations=1L;
2129             GetMagickToken(p,&p,token);
2130             if ((*p == ':') || (*p == ','))
2131               GetMagickToken(p,&p,token);
2132             if ((*p != '\0'))
2133               iterations=(ssize_t) StringToLong(p);
2134             kernel=AcquireKernelInfo(argv[i+2]);
2135             if (kernel == (KernelInfo *) NULL)
2136               {
2137                 (void) ThrowMagickException(exception,GetMagickModule(),
2138                   OptionError,"UnabletoParseKernel","morphology");
2139                 status=MagickFalse;
2140                 break;
2141               }
2142             mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2143               exception);
2144             kernel=DestroyKernelInfo(kernel);
2145             break;
2146           }
2147         if (LocaleCompare("motion-blur",option+1) == 0)
2148           {
2149             /*
2150               Motion blur image.
2151             */
2152             (void) SyncImageSettings(mogrify_info,*image);
2153             flags=ParseGeometry(argv[i+1],&geometry_info);
2154             if ((flags & SigmaValue) == 0)
2155               geometry_info.sigma=1.0;
2156             mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2157               geometry_info.sigma,geometry_info.xi,geometry_info.psi,
2158               exception);
2159             break;
2160           }
2161         break;
2162       }
2163       case 'n':
2164       {
2165         if (LocaleCompare("negate",option+1) == 0)
2166           {
2167             (void) SyncImageSettings(mogrify_info,*image);
2168             (void) NegateImage(*image,*option == '+' ? MagickTrue :
2169               MagickFalse,exception);
2170             break;
2171           }
2172         if (LocaleCompare("noise",option+1) == 0)
2173           {
2174             (void) SyncImageSettings(mogrify_info,*image);
2175             if (*option == '-')
2176               {
2177                 flags=ParseGeometry(argv[i+1],&geometry_info);
2178                 if ((flags & SigmaValue) == 0)
2179                   geometry_info.sigma=geometry_info.rho;
2180                 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2181                   geometry_info.rho,(size_t) geometry_info.sigma,exception);
2182               }
2183             else
2184               {
2185                 NoiseType
2186                   noise;
2187
2188                 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2189                   MagickFalse,argv[i+1]);
2190                 mogrify_image=AddNoiseImage(*image,noise,exception);
2191               }
2192             break;
2193           }
2194         if (LocaleCompare("normalize",option+1) == 0)
2195           {
2196             (void) SyncImageSettings(mogrify_info,*image);
2197             (void) NormalizeImage(*image,exception);
2198             break;
2199           }
2200         break;
2201       }
2202       case 'o':
2203       {
2204         if (LocaleCompare("opaque",option+1) == 0)
2205           {
2206             PixelInfo
2207               target;
2208
2209             (void) SyncImageSettings(mogrify_info,*image);
2210             (void) QueryMagickColorCompliance(argv[i+1],AllCompliance,&target,
2211               exception);
2212             (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2213               MagickFalse : MagickTrue,exception);
2214             break;
2215           }
2216         if (LocaleCompare("ordered-dither",option+1) == 0)
2217           {
2218             (void) SyncImageSettings(mogrify_info,*image);
2219             (void) OrderedPosterizeImage(*image,argv[i+1],exception);
2220             break;
2221           }
2222         break;
2223       }
2224       case 'p':
2225       {
2226         if (LocaleCompare("paint",option+1) == 0)
2227           {
2228             (void) SyncImageSettings(mogrify_info,*image);
2229             (void) ParseGeometry(argv[i+1],&geometry_info);
2230             mogrify_image=OilPaintImage(*image,geometry_info.rho,
2231               geometry_info.sigma,exception);
2232             break;
2233           }
2234         if (LocaleCompare("pen",option+1) == 0)
2235           {
2236             if (*option == '+')
2237               {
2238                 (void) QueryColorCompliance("none",AllCompliance,
2239                   &draw_info->fill,exception);
2240                 break;
2241               }
2242             (void) QueryColorCompliance(argv[i+1],AllCompliance,
2243               &draw_info->fill,exception);
2244             break;
2245           }
2246         if (LocaleCompare("pointsize",option+1) == 0)
2247           {
2248             if (*option == '+')
2249               (void) ParseGeometry("12",&geometry_info);
2250             else
2251               (void) ParseGeometry(argv[i+1],&geometry_info);
2252             draw_info->pointsize=geometry_info.rho;
2253             break;
2254           }
2255         if (LocaleCompare("polaroid",option+1) == 0)
2256           {
2257             double
2258               angle;
2259
2260             RandomInfo
2261               *random_info;
2262
2263             /*
2264               Simulate a Polaroid picture.
2265             */
2266             (void) SyncImageSettings(mogrify_info,*image);
2267             random_info=AcquireRandomInfo();
2268             angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2269             random_info=DestroyRandomInfo(random_info);
2270             if (*option == '-')
2271               {
2272                 SetGeometryInfo(&geometry_info);
2273                 flags=ParseGeometry(argv[i+1],&geometry_info);
2274                 angle=geometry_info.rho;
2275               }
2276             mogrify_image=PolaroidImage(*image,draw_info,angle,
2277               interpolate_method,exception);
2278             break;
2279           }
2280         if (LocaleCompare("posterize",option+1) == 0)
2281           {
2282             /*
2283               Posterize image.
2284             */
2285             (void) SyncImageSettings(mogrify_info,*image);
2286             (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2287               quantize_info->dither,exception);
2288             break;
2289           }
2290         if (LocaleCompare("preview",option+1) == 0)
2291           {
2292             PreviewType
2293               preview_type;
2294
2295             /*
2296               Preview image.
2297             */
2298             (void) SyncImageSettings(mogrify_info,*image);
2299             if (*option == '+')
2300               preview_type=UndefinedPreview;
2301             else
2302               preview_type=(PreviewType) ParseCommandOption(
2303                 MagickPreviewOptions,MagickFalse,argv[i+1]);
2304             mogrify_image=PreviewImage(*image,preview_type,exception);
2305             break;
2306           }
2307         if (LocaleCompare("profile",option+1) == 0)
2308           {
2309             const char
2310               *name;
2311
2312             const StringInfo
2313               *profile;
2314
2315             Image
2316               *profile_image;
2317
2318             ImageInfo
2319               *profile_info;
2320
2321             (void) SyncImageSettings(mogrify_info,*image);
2322             if (*option == '+')
2323               {
2324                 /*
2325                   Remove a profile from the image.
2326                 */
2327                 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2328                   NULL,0,MagickTrue);
2329                 InheritException(exception,&(*image)->exception);
2330                 break;
2331               }
2332             /*
2333               Associate a profile with the image.
2334             */
2335             profile_info=CloneImageInfo(mogrify_info);
2336             profile=GetImageProfile(*image,"iptc");
2337             if (profile != (StringInfo *) NULL)
2338               profile_info->profile=(void *) CloneStringInfo(profile);
2339             profile_image=GetImageCache(profile_info,argv[i+1],exception);
2340             profile_info=DestroyImageInfo(profile_info);
2341             if (profile_image == (Image *) NULL)
2342               {
2343                 StringInfo
2344                   *profile;
2345
2346                 profile_info=CloneImageInfo(mogrify_info);
2347                 (void) CopyMagickString(profile_info->filename,argv[i+1],
2348                   MaxTextExtent);
2349                 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2350                 if (profile != (StringInfo *) NULL)
2351                   {
2352                     (void) ProfileImage(*image,profile_info->magick,
2353                       GetStringInfoDatum(profile),(size_t)
2354                       GetStringInfoLength(profile),MagickFalse);
2355                     profile=DestroyStringInfo(profile);
2356                   }
2357                 profile_info=DestroyImageInfo(profile_info);
2358                 break;
2359               }
2360             ResetImageProfileIterator(profile_image);
2361             name=GetNextImageProfile(profile_image);
2362             while (name != (const char *) NULL)
2363             {
2364               profile=GetImageProfile(profile_image,name);
2365               if (profile != (StringInfo *) NULL)
2366                 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2367                   (size_t) GetStringInfoLength(profile),MagickFalse);
2368               name=GetNextImageProfile(profile_image);
2369             }
2370             profile_image=DestroyImage(profile_image);
2371             break;
2372           }
2373         break;
2374       }
2375       case 'q':
2376       {
2377         if (LocaleCompare("quantize",option+1) == 0)
2378           {
2379             if (*option == '+')
2380               {
2381                 quantize_info->colorspace=UndefinedColorspace;
2382                 break;
2383               }
2384             quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2385               MagickColorspaceOptions,MagickFalse,argv[i+1]);
2386             break;
2387           }
2388         break;
2389       }
2390       case 'r':
2391       {
2392         if (LocaleCompare("radial-blur",option+1) == 0)
2393           {
2394             /*
2395               Radial blur image.
2396             */
2397             (void) SyncImageSettings(mogrify_info,*image);
2398             flags=ParseGeometry(argv[i+1],&geometry_info);
2399             mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2400               geometry_info.sigma,exception);
2401             break;
2402           }
2403         if (LocaleCompare("raise",option+1) == 0)
2404           {
2405             /*
2406               Surround image with a raise of solid color.
2407             */
2408             flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2409             if ((flags & SigmaValue) == 0)
2410               geometry.height=geometry.width;
2411             (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2412               MagickFalse,exception);
2413             break;
2414           }
2415         if (LocaleCompare("random-threshold",option+1) == 0)
2416           {
2417             /*
2418               Threshold image.
2419             */
2420             (void) SyncImageSettings(mogrify_info,*image);
2421             (void) RandomThresholdImage(*image,argv[i+1],exception);
2422             break;
2423           }
2424         if (LocaleCompare("recolor",option+1) == 0)
2425           {
2426             KernelInfo
2427               *kernel;
2428
2429             (void) SyncImageSettings(mogrify_info,*image);
2430             kernel=AcquireKernelInfo(argv[i+1]);
2431             if (kernel == (KernelInfo *) NULL)
2432               break;
2433             mogrify_image=ColorMatrixImage(*image,kernel,exception);
2434             kernel=DestroyKernelInfo(kernel);
2435             break;
2436           }
2437         if (LocaleCompare("region",option+1) == 0)
2438           {
2439             (void) SyncImageSettings(mogrify_info,*image);
2440             if (region_image != (Image *) NULL)
2441               {
2442                 /*
2443                   Composite region.
2444                 */
2445                 (void) CompositeImage(region_image,region_image->matte !=
2446                    MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2447                    region_geometry.x,region_geometry.y);
2448                 InheritException(exception,&region_image->exception);
2449                 *image=DestroyImage(*image);
2450                 *image=region_image;
2451                 region_image = (Image *) NULL;
2452               }
2453             if (*option == '+')
2454               break;
2455             /*
2456               Apply transformations to a selected region of the image.
2457             */
2458             (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2459               exception);
2460             mogrify_image=CropImage(*image,&region_geometry,exception);
2461             if (mogrify_image == (Image *) NULL)
2462               break;
2463             region_image=(*image);
2464             *image=mogrify_image;
2465             mogrify_image=(Image *) NULL;
2466             break;
2467           }
2468         if (LocaleCompare("render",option+1) == 0)
2469           {
2470             (void) SyncImageSettings(mogrify_info,*image);
2471             draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2472             break;
2473           }
2474         if (LocaleCompare("remap",option+1) == 0)
2475           {
2476             Image
2477               *remap_image;
2478
2479             /*
2480               Transform image colors to match this set of colors.
2481             */
2482             (void) SyncImageSettings(mogrify_info,*image);
2483             if (*option == '+')
2484               break;
2485             remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2486             if (remap_image == (Image *) NULL)
2487               break;
2488             (void) RemapImage(quantize_info,*image,remap_image,exception);
2489             remap_image=DestroyImage(remap_image);
2490             break;
2491           }
2492         if (LocaleCompare("repage",option+1) == 0)
2493           {
2494             if (*option == '+')
2495               {
2496                 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2497                 break;
2498               }
2499             (void) ResetImagePage(*image,argv[i+1]);
2500             InheritException(exception,&(*image)->exception);
2501             break;
2502           }
2503         if (LocaleCompare("resample",option+1) == 0)
2504           {
2505             /*
2506               Resample image.
2507             */
2508             (void) SyncImageSettings(mogrify_info,*image);
2509             flags=ParseGeometry(argv[i+1],&geometry_info);
2510             if ((flags & SigmaValue) == 0)
2511               geometry_info.sigma=geometry_info.rho;
2512             mogrify_image=ResampleImage(*image,geometry_info.rho,
2513               geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2514             break;
2515           }
2516         if (LocaleCompare("resize",option+1) == 0)
2517           {
2518             /*
2519               Resize image.
2520             */
2521             (void) SyncImageSettings(mogrify_info,*image);
2522             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2523             mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2524               (*image)->filter,(*image)->blur,exception);
2525             break;
2526           }
2527         if (LocaleCompare("roll",option+1) == 0)
2528           {
2529             /*
2530               Roll image.
2531             */
2532             (void) SyncImageSettings(mogrify_info,*image);
2533             (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2534             mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2535             break;
2536           }
2537         if (LocaleCompare("rotate",option+1) == 0)
2538           {
2539             char
2540               *geometry;
2541
2542             /*
2543               Check for conditional image rotation.
2544             */
2545             (void) SyncImageSettings(mogrify_info,*image);
2546             if (strchr(argv[i+1],'>') != (char *) NULL)
2547               if ((*image)->columns <= (*image)->rows)
2548                 break;
2549             if (strchr(argv[i+1],'<') != (char *) NULL)
2550               if ((*image)->columns >= (*image)->rows)
2551                 break;
2552             /*
2553               Rotate image.
2554             */
2555             geometry=ConstantString(argv[i+1]);
2556             (void) SubstituteString(&geometry,">","");
2557             (void) SubstituteString(&geometry,"<","");
2558             (void) ParseGeometry(geometry,&geometry_info);
2559             geometry=DestroyString(geometry);
2560             mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2561             break;
2562           }
2563         break;
2564       }
2565       case 's':
2566       {
2567         if (LocaleCompare("sample",option+1) == 0)
2568           {
2569             /*
2570               Sample image with pixel replication.
2571             */
2572             (void) SyncImageSettings(mogrify_info,*image);
2573             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2574             mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2575               exception);
2576             break;
2577           }
2578         if (LocaleCompare("scale",option+1) == 0)
2579           {
2580             /*
2581               Resize image.
2582             */
2583             (void) SyncImageSettings(mogrify_info,*image);
2584             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2585             mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2586               exception);
2587             break;
2588           }
2589         if (LocaleCompare("selective-blur",option+1) == 0)
2590           {
2591             /*
2592               Selectively blur pixels within a contrast threshold.
2593             */
2594             (void) SyncImageSettings(mogrify_info,*image);
2595             flags=ParseGeometry(argv[i+1],&geometry_info);
2596             if ((flags & PercentValue) != 0)
2597               geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2598             mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2599               geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
2600             break;
2601           }
2602         if (LocaleCompare("separate",option+1) == 0)
2603           {
2604             /*
2605               Break channels into separate images.
2606             */
2607             (void) SyncImageSettings(mogrify_info,*image);
2608             mogrify_image=SeparateImages(*image,exception);
2609             break;
2610           }
2611         if (LocaleCompare("sepia-tone",option+1) == 0)
2612           {
2613             double
2614               threshold;
2615
2616             /*
2617               Sepia-tone image.
2618             */
2619             (void) SyncImageSettings(mogrify_info,*image);
2620             threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2621             mogrify_image=SepiaToneImage(*image,threshold,exception);
2622             break;
2623           }
2624         if (LocaleCompare("segment",option+1) == 0)
2625           {
2626             /*
2627               Segment image.
2628             */
2629             (void) SyncImageSettings(mogrify_info,*image);
2630             flags=ParseGeometry(argv[i+1],&geometry_info);
2631             if ((flags & SigmaValue) == 0)
2632               geometry_info.sigma=1.0;
2633             (void) SegmentImage(*image,(*image)->colorspace,
2634               mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2635               exception);
2636             break;
2637           }
2638         if (LocaleCompare("set",option+1) == 0)
2639           {
2640             char
2641               *value;
2642
2643             /*
2644               Set image option.
2645             */
2646             if (*option == '+')
2647               {
2648                 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2649                   (void) DeleteImageRegistry(argv[i+1]+9);
2650                 else
2651                   if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2652                     {
2653                       (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2654                       (void) DeleteImageArtifact(*image,argv[i+1]+7);
2655                     }
2656                   else
2657                     (void) DeleteImageProperty(*image,argv[i+1]);
2658                 break;
2659               }
2660             value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2661               exception);
2662             if (value == (char *) NULL)
2663               break;
2664             if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2665               (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2666                 exception);
2667             else
2668               if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2669                 {
2670                   (void) SetImageOption(image_info,argv[i+1]+7,value);
2671                   (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2672                   (void) SetImageArtifact(*image,argv[i+1]+7,value);
2673                 }
2674               else
2675                 (void) SetImageProperty(*image,argv[i+1],value);
2676             value=DestroyString(value);
2677             break;
2678           }
2679         if (LocaleCompare("shade",option+1) == 0)
2680           {
2681             /*
2682               Shade image.
2683             */
2684             (void) SyncImageSettings(mogrify_info,*image);
2685             flags=ParseGeometry(argv[i+1],&geometry_info);
2686             if ((flags & SigmaValue) == 0)
2687               geometry_info.sigma=1.0;
2688             mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2689               MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2690             break;
2691           }
2692         if (LocaleCompare("shadow",option+1) == 0)
2693           {
2694             /*
2695               Shadow image.
2696             */
2697             (void) SyncImageSettings(mogrify_info,*image);
2698             flags=ParseGeometry(argv[i+1],&geometry_info);
2699             if ((flags & SigmaValue) == 0)
2700               geometry_info.sigma=1.0;
2701             if ((flags & XiValue) == 0)
2702               geometry_info.xi=4.0;
2703             if ((flags & PsiValue) == 0)
2704               geometry_info.psi=4.0;
2705             mogrify_image=ShadowImage(*image,geometry_info.rho,
2706               geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2707               ceil(geometry_info.psi-0.5),exception);
2708             break;
2709           }
2710         if (LocaleCompare("sharpen",option+1) == 0)
2711           {
2712             /*
2713               Sharpen image.
2714             */
2715             (void) SyncImageSettings(mogrify_info,*image);
2716             flags=ParseGeometry(argv[i+1],&geometry_info);
2717             if ((flags & SigmaValue) == 0)
2718               geometry_info.sigma=1.0;
2719             if ((flags & XiValue) == 0)
2720               geometry_info.xi=0.0;
2721             mogrify_image=SharpenImage(*image,geometry_info.rho,
2722               geometry_info.sigma,geometry_info.xi,exception);
2723             break;
2724           }
2725         if (LocaleCompare("shave",option+1) == 0)
2726           {
2727             /*
2728               Shave the image edges.
2729             */
2730             (void) SyncImageSettings(mogrify_info,*image);
2731             flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2732             mogrify_image=ShaveImage(*image,&geometry,exception);
2733             break;
2734           }
2735         if (LocaleCompare("shear",option+1) == 0)
2736           {
2737             /*
2738               Shear image.
2739             */
2740             (void) SyncImageSettings(mogrify_info,*image);
2741             flags=ParseGeometry(argv[i+1],&geometry_info);
2742             if ((flags & SigmaValue) == 0)
2743               geometry_info.sigma=geometry_info.rho;
2744             mogrify_image=ShearImage(*image,geometry_info.rho,
2745               geometry_info.sigma,exception);
2746             break;
2747           }
2748         if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2749           {
2750             /*
2751               Sigmoidal non-linearity contrast control.
2752             */
2753             (void) SyncImageSettings(mogrify_info,*image);
2754             flags=ParseGeometry(argv[i+1],&geometry_info);
2755             if ((flags & SigmaValue) == 0)
2756               geometry_info.sigma=(double) QuantumRange/2.0;
2757             if ((flags & PercentValue) != 0)
2758               geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2759                 100.0;
2760             (void) SigmoidalContrastImage(*image,(*option == '-') ?
2761               MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2762               exception);
2763             break;
2764           }
2765         if (LocaleCompare("sketch",option+1) == 0)
2766           {
2767             /*
2768               Sketch image.
2769             */
2770             (void) SyncImageSettings(mogrify_info,*image);
2771             flags=ParseGeometry(argv[i+1],&geometry_info);
2772             if ((flags & SigmaValue) == 0)
2773               geometry_info.sigma=1.0;
2774             mogrify_image=SketchImage(*image,geometry_info.rho,
2775               geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
2776             break;
2777           }
2778         if (LocaleCompare("solarize",option+1) == 0)
2779           {
2780             double
2781               threshold;
2782
2783             (void) SyncImageSettings(mogrify_info,*image);
2784             threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2785             (void) SolarizeImage(*image,threshold,exception);
2786             break;
2787           }
2788         if (LocaleCompare("sparse-color",option+1) == 0)
2789           {
2790             SparseColorMethod
2791               method;
2792
2793             char
2794               *arguments;
2795
2796             /*
2797               Sparse Color Interpolated Gradient
2798             */
2799             (void) SyncImageSettings(mogrify_info,*image);
2800             method=(SparseColorMethod) ParseCommandOption(
2801               MagickSparseColorOptions,MagickFalse,argv[i+1]);
2802             arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2803               exception);
2804             if (arguments == (char *) NULL)
2805               break;
2806             mogrify_image=SparseColorOption(*image,method,arguments,
2807               option[0] == '+' ? MagickTrue : MagickFalse,exception);
2808             arguments=DestroyString(arguments);
2809             break;
2810           }
2811         if (LocaleCompare("splice",option+1) == 0)
2812           {
2813             /*
2814               Splice a solid color into the image.
2815             */
2816             (void) SyncImageSettings(mogrify_info,*image);
2817             (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2818             mogrify_image=SpliceImage(*image,&geometry,exception);
2819             break;
2820           }
2821         if (LocaleCompare("spread",option+1) == 0)
2822           {
2823             /*
2824               Spread an image.
2825             */
2826             (void) SyncImageSettings(mogrify_info,*image);
2827             (void) ParseGeometry(argv[i+1],&geometry_info);
2828             mogrify_image=SpreadImage(*image,geometry_info.rho,
2829               interpolate_method,exception);
2830             break;
2831           }
2832         if (LocaleCompare("statistic",option+1) == 0)
2833           {
2834             StatisticType
2835               type;
2836
2837             (void) SyncImageSettings(mogrify_info,*image);
2838             type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2839               MagickFalse,argv[i+1]);
2840             (void) ParseGeometry(argv[i+2],&geometry_info);
2841             mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2842               (size_t) geometry_info.sigma,exception);
2843             break;
2844           }
2845         if (LocaleCompare("stretch",option+1) == 0)
2846           {
2847             if (*option == '+')
2848               {
2849                 draw_info->stretch=UndefinedStretch;
2850                 break;
2851               }
2852             draw_info->stretch=(StretchType) ParseCommandOption(
2853               MagickStretchOptions,MagickFalse,argv[i+1]);
2854             break;
2855           }
2856         if (LocaleCompare("strip",option+1) == 0)
2857           {
2858             /*
2859               Strip image of profiles and comments.
2860             */
2861             (void) SyncImageSettings(mogrify_info,*image);
2862             (void) StripImage(*image);
2863             InheritException(exception,&(*image)->exception);
2864             break;
2865           }
2866         if (LocaleCompare("stroke",option+1) == 0)
2867           {
2868             ExceptionInfo
2869               *sans;
2870
2871             if (*option == '+')
2872               {
2873                 (void) QueryColorCompliance("none",AllCompliance,
2874                   &draw_info->stroke,exception);
2875                 if (draw_info->stroke_pattern != (Image *) NULL)
2876                   draw_info->stroke_pattern=DestroyImage(
2877                     draw_info->stroke_pattern);
2878                 break;
2879               }
2880             sans=AcquireExceptionInfo();
2881             status=QueryColorCompliance(argv[i+1],AllCompliance,
2882               &draw_info->stroke,sans);
2883             sans=DestroyExceptionInfo(sans);
2884             if (status == MagickFalse)
2885               draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2886                 exception);
2887             break;
2888           }
2889         if (LocaleCompare("strokewidth",option+1) == 0)
2890           {
2891             draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2892               (char **) NULL);
2893             break;
2894           }
2895         if (LocaleCompare("style",option+1) == 0)
2896           {
2897             if (*option == '+')
2898               {
2899                 draw_info->style=UndefinedStyle;
2900                 break;
2901               }
2902             draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2903               MagickFalse,argv[i+1]);
2904             break;
2905           }
2906         if (LocaleCompare("swirl",option+1) == 0)
2907           {
2908             /*
2909               Swirl image.
2910             */
2911             (void) SyncImageSettings(mogrify_info,*image);
2912             (void) ParseGeometry(argv[i+1],&geometry_info);
2913             mogrify_image=SwirlImage(*image,geometry_info.rho,
2914               interpolate_method,exception);
2915             break;
2916           }
2917         break;
2918       }
2919       case 't':
2920       {
2921         if (LocaleCompare("threshold",option+1) == 0)
2922           {
2923             double
2924               threshold;
2925
2926             /*
2927               Threshold image.
2928             */
2929             (void) SyncImageSettings(mogrify_info,*image);
2930             if (*option == '+')
2931               threshold=(double) QuantumRange/2;
2932             else
2933               threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2934             (void) BilevelImage(*image,threshold);
2935             InheritException(exception,&(*image)->exception);
2936             break;
2937           }
2938         if (LocaleCompare("thumbnail",option+1) == 0)
2939           {
2940             /*
2941               Thumbnail image.
2942             */
2943             (void) SyncImageSettings(mogrify_info,*image);
2944             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2945             mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2946               exception);
2947             break;
2948           }
2949         if (LocaleCompare("tile",option+1) == 0)
2950           {
2951             if (*option == '+')
2952               {
2953                 if (draw_info->fill_pattern != (Image *) NULL)
2954                   draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2955                 break;
2956               }
2957             draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2958               exception);
2959             break;
2960           }
2961         if (LocaleCompare("tint",option+1) == 0)
2962           {
2963             /*
2964               Tint the image.
2965             */
2966             (void) SyncImageSettings(mogrify_info,*image);
2967             mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
2968             break;
2969           }
2970         if (LocaleCompare("transform",option+1) == 0)
2971           {
2972             /*
2973               Affine transform image.
2974             */
2975             (void) SyncImageSettings(mogrify_info,*image);
2976             mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2977               exception);
2978             break;
2979           }
2980         if (LocaleCompare("transparent",option+1) == 0)
2981           {
2982             PixelInfo
2983               target;
2984
2985             (void) SyncImageSettings(mogrify_info,*image);
2986             (void) QueryMagickColorCompliance(argv[i+1],AllCompliance,&target,
2987               exception);
2988             (void) TransparentPaintImage(*image,&target,(Quantum)
2989               TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2990               &(*image)->exception);
2991             break;
2992           }
2993         if (LocaleCompare("transpose",option+1) == 0)
2994           {
2995             /*
2996               Transpose image scanlines.
2997             */
2998             (void) SyncImageSettings(mogrify_info,*image);
2999             mogrify_image=TransposeImage(*image,exception);
3000             break;
3001           }
3002         if (LocaleCompare("transverse",option+1) == 0)
3003           {
3004             /*
3005               Transverse image scanlines.
3006             */
3007             (void) SyncImageSettings(mogrify_info,*image);
3008             mogrify_image=TransverseImage(*image,exception);
3009             break;
3010           }
3011         if (LocaleCompare("treedepth",option+1) == 0)
3012           {
3013             quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3014             break;
3015           }
3016         if (LocaleCompare("trim",option+1) == 0)
3017           {
3018             /*
3019               Trim image.
3020             */
3021             (void) SyncImageSettings(mogrify_info,*image);
3022             mogrify_image=TrimImage(*image,exception);
3023             break;
3024           }
3025         if (LocaleCompare("type",option+1) == 0)
3026           {
3027             ImageType
3028               type;
3029
3030             (void) SyncImageSettings(mogrify_info,*image);
3031             if (*option == '+')
3032               type=UndefinedType;
3033             else
3034               type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3035                 argv[i+1]);
3036             (*image)->type=UndefinedType;
3037             (void) SetImageType(*image,type,exception);
3038             break;
3039           }
3040         break;
3041       }
3042       case 'u':
3043       {
3044         if (LocaleCompare("undercolor",option+1) == 0)
3045           {
3046             (void) QueryColorCompliance(argv[i+1],AllCompliance,
3047               &draw_info->undercolor,exception);
3048             break;
3049           }
3050         if (LocaleCompare("unique",option+1) == 0)
3051           {
3052             if (*option == '+')
3053               {
3054                 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3055                 break;
3056               }
3057             (void) SetImageArtifact(*image,"identify:unique-colors","true");
3058             (void) SetImageArtifact(*image,"verbose","true");
3059             break;
3060           }
3061         if (LocaleCompare("unique-colors",option+1) == 0)
3062           {
3063             /*
3064               Unique image colors.
3065             */
3066             (void) SyncImageSettings(mogrify_info,*image);
3067             mogrify_image=UniqueImageColors(*image,exception);
3068             break;
3069           }
3070         if (LocaleCompare("unsharp",option+1) == 0)
3071           {
3072             /*
3073               Unsharp mask image.
3074             */
3075             (void) SyncImageSettings(mogrify_info,*image);
3076             flags=ParseGeometry(argv[i+1],&geometry_info);
3077             if ((flags & SigmaValue) == 0)
3078               geometry_info.sigma=1.0;
3079             if ((flags & XiValue) == 0)
3080               geometry_info.xi=1.0;
3081             if ((flags & PsiValue) == 0)
3082               geometry_info.psi=0.05;
3083             mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3084               geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
3085             break;
3086           }
3087         break;
3088       }
3089       case 'v':
3090       {
3091         if (LocaleCompare("verbose",option+1) == 0)
3092           {
3093             (void) SetImageArtifact(*image,option+1,
3094               *option == '+' ? "false" : "true");
3095             break;
3096           }
3097         if (LocaleCompare("vignette",option+1) == 0)
3098           {
3099             /*
3100               Vignette image.
3101             */
3102             (void) SyncImageSettings(mogrify_info,*image);
3103             flags=ParseGeometry(argv[i+1],&geometry_info);
3104             if ((flags & SigmaValue) == 0)
3105               geometry_info.sigma=1.0;
3106             if ((flags & XiValue) == 0)
3107               geometry_info.xi=0.1*(*image)->columns;
3108             if ((flags & PsiValue) == 0)
3109               geometry_info.psi=0.1*(*image)->rows;
3110             mogrify_image=VignetteImage(*image,geometry_info.rho,
3111               geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3112               ceil(geometry_info.psi-0.5),exception);
3113             break;
3114           }
3115         if (LocaleCompare("virtual-pixel",option+1) == 0)
3116           {
3117             if (*option == '+')
3118               {
3119                 (void) SetImageVirtualPixelMethod(*image,
3120                   UndefinedVirtualPixelMethod);
3121                 break;
3122               }
3123             (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3124               ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3125               argv[i+1]));
3126             break;
3127           }
3128         break;
3129       }
3130       case 'w':
3131       {
3132         if (LocaleCompare("wave",option+1) == 0)
3133           {
3134             /*
3135               Wave image.
3136             */
3137             (void) SyncImageSettings(mogrify_info,*image);
3138             flags=ParseGeometry(argv[i+1],&geometry_info);
3139             if ((flags & SigmaValue) == 0)
3140               geometry_info.sigma=1.0;
3141             mogrify_image=WaveImage(*image,geometry_info.rho,
3142               geometry_info.sigma,interpolate_method,exception);
3143             break;
3144           }
3145         if (LocaleCompare("weight",option+1) == 0)
3146           {
3147             draw_info->weight=StringToUnsignedLong(argv[i+1]);
3148             if (LocaleCompare(argv[i+1],"all") == 0)
3149               draw_info->weight=0;
3150             if (LocaleCompare(argv[i+1],"bold") == 0)
3151               draw_info->weight=700;
3152             if (LocaleCompare(argv[i+1],"bolder") == 0)
3153               if (draw_info->weight <= 800)
3154                 draw_info->weight+=100;
3155             if (LocaleCompare(argv[i+1],"lighter") == 0)
3156               if (draw_info->weight >= 100)
3157                 draw_info->weight-=100;
3158             if (LocaleCompare(argv[i+1],"normal") == 0)
3159               draw_info->weight=400;
3160             break;
3161           }
3162         if (LocaleCompare("white-threshold",option+1) == 0)
3163           {
3164             /*
3165               White threshold image.
3166             */
3167             (void) SyncImageSettings(mogrify_info,*image);
3168             (void) WhiteThresholdImage(*image,argv[i+1],exception);
3169             InheritException(exception,&(*image)->exception);
3170             break;
3171           }
3172         break;
3173       }
3174       default:
3175         break;
3176     }
3177     /*
3178        Replace current image with any image that was generated
3179     */
3180     if (mogrify_image != (Image *) NULL)
3181       ReplaceImageInListReturnLast(image,mogrify_image);
3182     i+=count;
3183   }
3184   if (region_image != (Image *) NULL)
3185     {
3186       /*
3187         Composite transformed region onto image.
3188       */
3189       (void) SyncImageSettings(mogrify_info,*image);
3190       (void) CompositeImage(region_image,region_image->matte !=
3191          MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3192          region_geometry.x,region_geometry.y);
3193       InheritException(exception,&region_image->exception);
3194       *image=DestroyImage(*image);
3195       *image=region_image;
3196       region_image = (Image *) NULL;
3197     }
3198   /*
3199     Free resources.
3200   */
3201   quantize_info=DestroyQuantizeInfo(quantize_info);
3202   draw_info=DestroyDrawInfo(draw_info);
3203   mogrify_info=DestroyImageInfo(mogrify_info);
3204   status=(MagickStatusType) ((*image)->exception.severity ==
3205     UndefinedException ? 1 : 0);
3206   return(status == 0 ? MagickFalse : MagickTrue);
3207 }
3208 \f
3209 /*
3210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3211 %                                                                             %
3212 %                                                                             %
3213 %                                                                             %
3214 +    M o g r i f y I m a g e C o m m a n d                                    %
3215 %                                                                             %
3216 %                                                                             %
3217 %                                                                             %
3218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3219 %
3220 %  MogrifyImageCommand() transforms an image or a sequence of images. These
3221 %  transforms include image scaling, image rotation, color reduction, and
3222 %  others. The transmogrified image overwrites the original image.
3223 %
3224 %  The format of the MogrifyImageCommand method is:
3225 %
3226 %      MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3227 %        const char **argv,char **metadata,ExceptionInfo *exception)
3228 %
3229 %  A description of each parameter follows:
3230 %
3231 %    o image_info: the image info.
3232 %
3233 %    o argc: the number of elements in the argument vector.
3234 %
3235 %    o argv: A text array containing the command line arguments.
3236 %
3237 %    o metadata: any metadata is returned here.
3238 %
3239 %    o exception: return any errors or warnings in this structure.
3240 %
3241 */
3242
3243 static MagickBooleanType MogrifyUsage(void)
3244 {
3245   static const char
3246     *miscellaneous[]=
3247     {
3248       "-debug events        display copious debugging information",
3249       "-help                print program options",
3250       "-list type           print a list of supported option arguments",
3251       "-log format          format of debugging information",
3252       "-version             print version information",
3253       (char *) NULL
3254     },
3255     *operators[]=
3256     {
3257       "-adaptive-blur geometry",
3258       "                     adaptively blur pixels; decrease effect near edges",
3259       "-adaptive-resize geometry",
3260       "                     adaptively resize image using 'mesh' interpolation",
3261       "-adaptive-sharpen geometry",
3262       "                     adaptively sharpen pixels; increase effect near edges",
3263       "-alpha option        on, activate, off, deactivate, set, opaque, copy",
3264       "                     transparent, extract, background, or shape",
3265       "-annotate geometry text",
3266       "                     annotate the image with text",
3267       "-auto-gamma          automagically adjust gamma level of image",
3268       "-auto-level          automagically adjust color levels of image",
3269       "-auto-orient         automagically orient (rotate) image",
3270       "-bench iterations    measure performance",
3271       "-black-threshold value",
3272       "                     force all pixels below the threshold into black",
3273       "-blue-shift          simulate a scene at nighttime in the moonlight",
3274       "-blur geometry       reduce image noise and reduce detail levels",
3275       "-border geometry     surround image with a border of color",
3276       "-bordercolor color   border color",
3277       "-brightness-contrast geometry",
3278       "                     improve brightness / contrast of the image",
3279       "-cdl filename        color correct with a color decision list",
3280       "-charcoal geometry   simulate a charcoal drawing",
3281       "-chop geometry       remove pixels from the image interior",
3282       "-clamp               restrict pixel range from 0 to the quantum depth",
3283       "-clip                clip along the first path from the 8BIM profile",
3284       "-clip-mask filename  associate a clip mask with the image",
3285       "-clip-path id        clip along a named path from the 8BIM profile",
3286       "-colorize value      colorize the image with the fill color",
3287       "-color-matrix matrix apply color correction to the image",
3288       "-contrast            enhance or reduce the image contrast",
3289       "-contrast-stretch geometry",
3290       "                     improve contrast by `stretching' the intensity range",
3291       "-convolve coefficients",
3292       "                     apply a convolution kernel to the image",
3293       "-cycle amount        cycle the image colormap",
3294       "-decipher filename   convert cipher pixels to plain pixels",
3295       "-deskew threshold    straighten an image",
3296       "-despeckle           reduce the speckles within an image",
3297       "-distort method args",
3298       "                     distort images according to given method ad args",
3299       "-draw string         annotate the image with a graphic primitive",
3300       "-edge radius         apply a filter to detect edges in the image",
3301       "-encipher filename   convert plain pixels to cipher pixels",
3302       "-emboss radius       emboss an image",
3303       "-enhance             apply a digital filter to enhance a noisy image",
3304       "-equalize            perform histogram equalization to an image",
3305       "-evaluate operator value",
3306       "                     evaluate an arithmetic, relational, or logical expression",
3307       "-extent geometry     set the image size",
3308       "-extract geometry    extract area from image",
3309       "-fft                 implements the discrete Fourier transform (DFT)",
3310       "-flip                flip image vertically",
3311       "-floodfill geometry color",
3312       "                     floodfill the image with color",
3313       "-flop                flop image horizontally",
3314       "-frame geometry      surround image with an ornamental border",
3315       "-function name parameters",
3316       "                     apply function over image values",
3317       "-gamma value         level of gamma correction",
3318       "-gaussian-blur geometry",
3319       "                     reduce image noise and reduce detail levels",
3320       "-geometry geometry   preferred size or location of the image",
3321       "-identify            identify the format and characteristics of the image",
3322       "-ift                 implements the inverse discrete Fourier transform (DFT)",
3323       "-implode amount      implode image pixels about the center",
3324       "-lat geometry        local adaptive thresholding",
3325       "-layers method       optimize, merge,  or compare image layers",
3326       "-level value         adjust the level of image contrast",
3327       "-level-colors color,color",
3328       "                     level image with the given colors",
3329       "-linear-stretch geometry",
3330       "                     improve contrast by `stretching with saturation'",
3331       "-liquid-rescale geometry",
3332       "                     rescale image with seam-carving",
3333       "-median geometry     apply a median filter to the image",
3334       "-mode geometry       make each pixel the 'predominant color' of the neighborhood",
3335       "-modulate value      vary the brightness, saturation, and hue",
3336       "-monochrome          transform image to black and white",
3337       "-morphology method kernel",
3338       "                     apply a morphology method to the image",
3339       "-motion-blur geometry",
3340       "                     simulate motion blur",
3341       "-negate              replace every pixel with its complementary color ",
3342       "-noise geometry      add or reduce noise in an image",
3343       "-normalize           transform image to span the full range of colors",
3344       "-opaque color        change this color to the fill color",
3345       "-ordered-dither NxN",
3346       "                     add a noise pattern to the image with specific",
3347       "                     amplitudes",
3348       "-paint radius        simulate an oil painting",
3349       "-polaroid angle      simulate a Polaroid picture",
3350       "-posterize levels    reduce the image to a limited number of color levels",
3351       "-profile filename    add, delete, or apply an image profile",
3352       "-quantize colorspace reduce colors in this colorspace",
3353       "-radial-blur angle   radial blur the image",
3354       "-raise value         lighten/darken image edges to create a 3-D effect",
3355       "-random-threshold low,high",
3356       "                     random threshold the image",
3357       "-region geometry     apply options to a portion of the image",
3358       "-render              render vector graphics",
3359       "-repage geometry     size and location of an image canvas",
3360       "-resample geometry   change the resolution of an image",
3361       "-resize geometry     resize the image",
3362       "-roll geometry       roll an image vertically or horizontally",
3363       "-rotate degrees      apply Paeth rotation to the image",
3364       "-sample geometry     scale image with pixel sampling",
3365       "-scale geometry      scale the image",
3366       "-segment values      segment an image",
3367       "-selective-blur geometry",
3368       "                     selectively blur pixels within a contrast threshold",
3369       "-sepia-tone threshold",
3370       "                     simulate a sepia-toned photo",
3371       "-set property value  set an image property",
3372       "-shade degrees       shade the image using a distant light source",
3373       "-shadow geometry     simulate an image shadow",
3374       "-sharpen geometry    sharpen the image",
3375       "-shave geometry      shave pixels from the image edges",
3376       "-shear geometry      slide one edge of the image along the X or Y axis",
3377       "-sigmoidal-contrast geometry",
3378       "                     increase the contrast without saturating highlights or shadows",
3379       "-sketch geometry     simulate a pencil sketch",
3380       "-solarize threshold  negate all pixels above the threshold level",
3381       "-sparse-color method args",
3382       "                     fill in a image based on a few color points",
3383       "-splice geometry     splice the background color into the image",
3384       "-spread radius       displace image pixels by a random amount",
3385       "-statistic type radius",
3386       "                     replace each pixel with corresponding statistic from the neighborhood",
3387       "-strip               strip image of all profiles and comments",
3388       "-swirl degrees       swirl image pixels about the center",
3389       "-threshold value     threshold the image",
3390       "-thumbnail geometry  create a thumbnail of the image",
3391       "-tile filename       tile image when filling a graphic primitive",
3392       "-tint value          tint the image with the fill color",
3393       "-transform           affine transform image",
3394       "-transparent color   make this color transparent within the image",
3395       "-transpose           flip image vertically and rotate 90 degrees",
3396       "-transverse          flop image horizontally and rotate 270 degrees",
3397       "-trim                trim image edges",
3398       "-type type           image type",
3399       "-unique-colors       discard all but one of any pixel color",
3400       "-unsharp geometry    sharpen the image",
3401       "-vignette geometry   soften the edges of the image in vignette style",
3402       "-wave geometry       alter an image along a sine wave",
3403       "-white-threshold value",
3404       "                     force all pixels above the threshold into white",
3405       (char *) NULL
3406     },
3407     *sequence_operators[]=
3408     {
3409       "-append              append an image sequence",
3410       "-clut                apply a color lookup table to the image",
3411       "-coalesce            merge a sequence of images",
3412       "-combine             combine a sequence of images",
3413       "-composite           composite image",
3414       "-crop geometry       cut out a rectangular region of the image",
3415       "-deconstruct         break down an image sequence into constituent parts",
3416       "-evaluate-sequence operator",
3417       "                     evaluate an arithmetic, relational, or logical expression",
3418       "-flatten             flatten a sequence of images",
3419       "-fx expression       apply mathematical expression to an image channel(s)",
3420       "-hald-clut           apply a Hald color lookup table to the image",
3421       "-morph value         morph an image sequence",
3422       "-mosaic              create a mosaic from an image sequence",
3423       "-print string        interpret string and print to console",
3424       "-process arguments   process the image with a custom image filter",
3425       "-separate            separate an image channel into a grayscale image",
3426       "-smush geometry      smush an image sequence together",
3427       "-write filename      write images to this file",
3428       (char *) NULL
3429     },
3430     *settings[]=
3431     {
3432       "-adjoin              join images into a single multi-image file",
3433       "-affine matrix       affine transform matrix",
3434       "-alpha option        activate, deactivate, reset, or set the alpha channel",
3435       "-antialias           remove pixel-aliasing",
3436       "-authenticate password",
3437       "                     decipher image with this password",
3438       "-attenuate value     lessen (or intensify) when adding noise to an image",
3439       "-background color    background color",
3440       "-bias value          add bias when convolving an image",
3441       "-black-point-compensation",
3442       "                     use black point compensation",
3443       "-blue-primary point  chromaticity blue primary point",
3444       "-bordercolor color   border color",
3445       "-caption string      assign a caption to an image",
3446       "-channel type        apply option to select image channels",
3447       "-colors value        preferred number of colors in the image",
3448       "-colorspace type     alternate image colorspace",
3449       "-comment string      annotate image with comment",
3450       "-compose operator    set image composite operator",
3451       "-compress type       type of pixel compression when writing the image",
3452       "-define format:option",
3453       "                     define one or more image format options",
3454       "-delay value         display the next image after pausing",
3455       "-density geometry    horizontal and vertical density of the image",
3456       "-depth value         image depth",
3457       "-direction type      render text right-to-left or left-to-right",
3458       "-display server      get image or font from this X server",
3459       "-dispose method      layer disposal method",
3460       "-dither method       apply error diffusion to image",
3461       "-encoding type       text encoding type",
3462       "-endian type         endianness (MSB or LSB) of the image",
3463       "-family name         render text with this font family",
3464       "-fill color          color to use when filling a graphic primitive",
3465       "-filter type         use this filter when resizing an image",
3466       "-font name           render text with this font",
3467       "-format \"string\"     output formatted image characteristics",
3468       "-fuzz distance       colors within this distance are considered equal",
3469       "-gravity type        horizontal and vertical text placement",
3470       "-green-primary point chromaticity green primary point",
3471       "-intent type         type of rendering intent when managing the image color",
3472       "-interlace type      type of image interlacing scheme",
3473       "-interline-spacing value",
3474       "                     set the space between two text lines",
3475       "-interpolate method  pixel color interpolation method",
3476       "-interword-spacing value",
3477       "                     set the space between two words",
3478       "-kerning value       set the space between two letters",
3479       "-label string        assign a label to an image",
3480       "-limit type value    pixel cache resource limit",
3481       "-loop iterations     add Netscape loop extension to your GIF animation",
3482       "-mask filename       associate a mask with the image",
3483       "-mattecolor color    frame color",
3484       "-monitor             monitor progress",
3485       "-orient type         image orientation",
3486       "-page geometry       size and location of an image canvas (setting)",
3487       "-ping                efficiently determine image attributes",
3488       "-pointsize value     font point size",
3489       "-precision value     maximum number of significant digits to print",
3490       "-preview type        image preview type",
3491       "-quality value       JPEG/MIFF/PNG compression level",
3492       "-quiet               suppress all warning messages",
3493       "-red-primary point   chromaticity red primary point",
3494       "-regard-warnings     pay attention to warning messages",
3495       "-remap filename      transform image colors to match this set of colors",
3496       "-respect-parentheses settings remain in effect until parenthesis boundary",
3497       "-sampling-factor geometry",
3498       "                     horizontal and vertical sampling factor",
3499       "-scene value         image scene number",
3500       "-seed value          seed a new sequence of pseudo-random numbers",
3501       "-size geometry       width and height of image",
3502       "-stretch type        render text with this font stretch",
3503       "-stroke color        graphic primitive stroke color",
3504       "-strokewidth value   graphic primitive stroke width",
3505       "-style type          render text with this font style",
3506       "-synchronize         synchronize image to storage device",
3507       "-taint               declare the image as modified",
3508       "-texture filename    name of texture to tile onto the image background",
3509       "-tile-offset geometry",
3510       "                     tile offset",
3511       "-treedepth value     color tree depth",
3512       "-transparent-color color",
3513       "                     transparent color",
3514       "-undercolor color    annotation bounding box color",
3515       "-units type          the units of image resolution",
3516       "-verbose             print detailed information about the image",
3517       "-view                FlashPix viewing transforms",
3518       "-virtual-pixel method",
3519       "                     virtual pixel access method",
3520       "-weight type         render text with this font weight",
3521       "-white-point point   chromaticity white point",
3522       (char *) NULL
3523     },
3524     *stack_operators[]=
3525     {
3526       "-delete indexes      delete the image from the image sequence",
3527       "-duplicate count,indexes",
3528       "                     duplicate an image one or more times",
3529       "-insert index        insert last image into the image sequence",
3530       "-reverse             reverse image sequence",
3531       "-swap indexes        swap two images in the image sequence",
3532       (char *) NULL
3533     };
3534
3535   const char
3536     **p;
3537
3538   (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
3539   (void) printf("Copyright: %s\n",GetMagickCopyright());
3540   (void) printf("Features: %s\n\n",GetMagickFeatures());
3541   (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3542     GetClientName());
3543   (void) printf("\nImage Settings:\n");
3544   for (p=settings; *p != (char *) NULL; p++)
3545     (void) printf("  %s\n",*p);
3546   (void) printf("\nImage Operators:\n");
3547   for (p=operators; *p != (char *) NULL; p++)
3548     (void) printf("  %s\n",*p);
3549   (void) printf("\nImage Sequence Operators:\n");
3550   for (p=sequence_operators; *p != (char *) NULL; p++)
3551     (void) printf("  %s\n",*p);
3552   (void) printf("\nImage Stack Operators:\n");
3553   for (p=stack_operators; *p != (char *) NULL; p++)
3554     (void) printf("  %s\n",*p);
3555   (void) printf("\nMiscellaneous Options:\n");
3556   for (p=miscellaneous; *p != (char *) NULL; p++)
3557     (void) printf("  %s\n",*p);
3558   (void) printf(
3559     "\nBy default, the image format of `file' is determined by its magic\n");
3560   (void) printf(
3561     "number.  To specify a particular image format, precede the filename\n");
3562   (void) printf(
3563     "with an image format name and a colon (i.e. ps:image) or specify the\n");
3564   (void) printf(
3565     "image type as the filename suffix (i.e. image.ps).  Specify 'file' as\n");
3566   (void) printf("'-' for standard input or output.\n");
3567   return(MagickFalse);
3568 }
3569
3570 WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3571   int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3572 {
3573 #define DestroyMogrify() \
3574 { \
3575   if (format != (char *) NULL) \
3576     format=DestroyString(format); \
3577   if (path != (char *) NULL) \
3578     path=DestroyString(path); \
3579   DestroyImageStack(); \
3580   for (i=0; i < (ssize_t) argc; i++) \
3581     argv[i]=DestroyString(argv[i]); \
3582   argv=(char **) RelinquishMagickMemory(argv); \
3583 }
3584 #define ThrowMogrifyException(asperity,tag,option) \
3585 { \
3586   (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3587     option); \
3588   DestroyMogrify(); \
3589   return(MagickFalse); \
3590 }
3591 #define ThrowMogrifyInvalidArgumentException(option,argument) \
3592 { \
3593   (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3594     "InvalidArgument","`%s': %s",argument,option); \
3595   DestroyMogrify(); \
3596   return(MagickFalse); \
3597 }
3598
3599   char
3600     *format,
3601     *option,
3602     *path;
3603
3604   Image
3605     *image;
3606
3607   ImageStack
3608     image_stack[MaxImageStackDepth+1];
3609
3610   MagickBooleanType
3611     global_colormap;
3612
3613   MagickBooleanType
3614     fire,
3615     pend,
3616     respect_parenthesis;
3617
3618   MagickStatusType
3619     status;
3620
3621   register ssize_t
3622     i;
3623
3624   ssize_t
3625     j,
3626     k;
3627
3628   /*
3629     Set defaults.
3630   */
3631   assert(image_info != (ImageInfo *) NULL);
3632   assert(image_info->signature == MagickSignature);
3633   if (image_info->debug != MagickFalse)
3634     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3635   assert(exception != (ExceptionInfo *) NULL);
3636   if (argc == 2)
3637     {
3638       option=argv[1];
3639       if ((LocaleCompare("version",option+1) == 0) ||
3640           (LocaleCompare("-version",option+1) == 0))
3641         {
3642           (void) FormatLocaleFile(stdout,"Version: %s\n",
3643             GetMagickVersion((size_t *) NULL));
3644           (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3645             GetMagickCopyright());
3646           (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3647             GetMagickFeatures());
3648           return(MagickFalse);
3649         }
3650     }
3651   if (argc < 2)
3652     return(MogrifyUsage());
3653   format=(char *) NULL;
3654   path=(char *) NULL;
3655   global_colormap=MagickFalse;
3656   k=0;
3657   j=1;
3658   NewImageStack();
3659   option=(char *) NULL;
3660   pend=MagickFalse;
3661   respect_parenthesis=MagickFalse;
3662   status=MagickTrue;
3663   /*
3664     Parse command line.
3665   */
3666   ReadCommandlLine(argc,&argv);
3667   status=ExpandFilenames(&argc,&argv);
3668   if (status == MagickFalse)
3669     ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3670       GetExceptionMessage(errno));
3671   for (i=1; i < (ssize_t) argc; i++)
3672   {
3673     option=argv[i];
3674     if (LocaleCompare(option,"(") == 0)
3675       {
3676         FireImageStack(MagickFalse,MagickTrue,pend);
3677         if (k == MaxImageStackDepth)
3678           ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3679             option);
3680         PushImageStack();
3681         continue;
3682       }
3683     if (LocaleCompare(option,")") == 0)
3684       {
3685         FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3686         if (k == 0)
3687           ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3688         PopImageStack();
3689         continue;
3690       }
3691     if (IsCommandOption(option) == MagickFalse)
3692       {
3693         char
3694           backup_filename[MaxTextExtent],
3695           *filename;
3696
3697         Image
3698           *images;
3699
3700         /*
3701           Option is a file name: begin by reading image from specified file.
3702         */
3703         FireImageStack(MagickFalse,MagickFalse,pend);
3704         filename=argv[i];
3705         if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
3706           filename=argv[++i];
3707         (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3708         images=ReadImages(image_info,exception);
3709         status&=(images != (Image *) NULL) &&
3710           (exception->severity < ErrorException);
3711         if (images == (Image *) NULL)
3712           continue;
3713         if (format != (char *) NULL)
3714           (void) CopyMagickString(images->filename,images->magick_filename,
3715             MaxTextExtent);
3716         if (path != (char *) NULL)
3717           {
3718             GetPathComponent(option,TailPath,filename);
3719             (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
3720               path,*DirectorySeparator,filename);
3721           }
3722         if (format != (char *) NULL)
3723           AppendImageFormat(format,images->filename);
3724         AppendImageStack(images);
3725         FinalizeImageSettings(image_info,image,MagickFalse);
3726         if (global_colormap != MagickFalse)
3727           {
3728             QuantizeInfo
3729               *quantize_info;
3730
3731             quantize_info=AcquireQuantizeInfo(image_info);
3732             (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
3733             quantize_info=DestroyQuantizeInfo(quantize_info);
3734           }
3735         *backup_filename='\0';
3736         if ((LocaleCompare(image->filename,"-") != 0) &&
3737             (IsPathWritable(image->filename) != MagickFalse))
3738           {
3739             register ssize_t
3740               i;
3741
3742             /*
3743               Rename image file as backup.
3744             */
3745             (void) CopyMagickString(backup_filename,image->filename,
3746               MaxTextExtent);
3747             for (i=0; i < 6; i++)
3748             {
3749               (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3750               if (IsPathAccessible(backup_filename) == MagickFalse)
3751                 break;
3752             }
3753             if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3754                 (rename_utf8(image->filename,backup_filename) != 0))
3755               *backup_filename='\0';
3756           }
3757         /*
3758           Write transmogrified image to disk.
3759         */
3760         image_info->synchronize=MagickTrue;
3761         status&=WriteImages(image_info,image,image->filename,exception);
3762         if ((status == MagickFalse) && (*backup_filename != '\0'))
3763           (void) remove_utf8(backup_filename);
3764         RemoveAllImageStack();
3765         continue;
3766       }
3767     pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3768     switch (*(option+1))
3769     {
3770       case 'a':
3771       {
3772         if (LocaleCompare("adaptive-blur",option+1) == 0)
3773           {
3774             i++;
3775             if (i == (ssize_t) argc)
3776               ThrowMogrifyException(OptionError,"MissingArgument",option);
3777             if (IsGeometry(argv[i]) == MagickFalse)
3778               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3779             break;
3780           }
3781         if (LocaleCompare("adaptive-resize",option+1) == 0)
3782           {
3783             i++;
3784             if (i == (ssize_t) argc)
3785               ThrowMogrifyException(OptionError,"MissingArgument",option);
3786             if (IsGeometry(argv[i]) == MagickFalse)
3787               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3788             break;
3789           }
3790         if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3791           {
3792             i++;
3793             if (i == (ssize_t) argc)
3794               ThrowMogrifyException(OptionError,"MissingArgument",option);
3795             if (IsGeometry(argv[i]) == MagickFalse)
3796               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3797             break;
3798           }
3799         if (LocaleCompare("affine",option+1) == 0)
3800           {
3801             if (*option == '+')
3802               break;
3803             i++;
3804             if (i == (ssize_t) argc)
3805               ThrowMogrifyException(OptionError,"MissingArgument",option);
3806             break;
3807           }
3808         if (LocaleCompare("alpha",option+1) == 0)
3809           {
3810             ssize_t
3811               type;
3812
3813             if (*option == '+')
3814               break;
3815             i++;
3816             if (i == (ssize_t) argc)
3817               ThrowMogrifyException(OptionError,"MissingArgument",option);
3818             type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
3819             if (type < 0)
3820               ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3821                 argv[i]);
3822             break;
3823           }
3824         if (LocaleCompare("annotate",option+1) == 0)
3825           {
3826             if (*option == '+')
3827               break;
3828             i++;
3829             if (i == (ssize_t) argc)
3830               ThrowMogrifyException(OptionError,"MissingArgument",option);
3831             if (IsGeometry(argv[i]) == MagickFalse)
3832               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3833             if (i == (ssize_t) argc)
3834               ThrowMogrifyException(OptionError,"MissingArgument",option);
3835             i++;
3836             break;
3837           }
3838         if (LocaleCompare("antialias",option+1) == 0)
3839           break;
3840         if (LocaleCompare("append",option+1) == 0)
3841           break;
3842         if (LocaleCompare("attenuate",option+1) == 0)
3843           {
3844             if (*option == '+')
3845               break;
3846             i++;
3847             if (i == (ssize_t) (argc-1))
3848               ThrowMogrifyException(OptionError,"MissingArgument",option);
3849             if (IsGeometry(argv[i]) == MagickFalse)
3850               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3851             break;
3852           }
3853         if (LocaleCompare("authenticate",option+1) == 0)
3854           {
3855             if (*option == '+')
3856               break;
3857             i++;
3858             if (i == (ssize_t) argc)
3859               ThrowMogrifyException(OptionError,"MissingArgument",option);
3860             break;
3861           }
3862         if (LocaleCompare("auto-gamma",option+1) == 0)
3863           break;
3864         if (LocaleCompare("auto-level",option+1) == 0)
3865           break;
3866         if (LocaleCompare("auto-orient",option+1) == 0)
3867           break;
3868         if (LocaleCompare("average",option+1) == 0)
3869           break;
3870         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3871       }
3872       case 'b':
3873       {
3874         if (LocaleCompare("background",option+1) == 0)
3875           {
3876             if (*option == '+')
3877               break;
3878             i++;
3879             if (i == (ssize_t) argc)
3880               ThrowMogrifyException(OptionError,"MissingArgument",option);
3881             break;
3882           }
3883         if (LocaleCompare("bias",option+1) == 0)
3884           {
3885             if (*option == '+')
3886               break;
3887             i++;
3888             if (i == (ssize_t) (argc-1))
3889               ThrowMogrifyException(OptionError,"MissingArgument",option);
3890             if (IsGeometry(argv[i]) == MagickFalse)
3891               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3892             break;
3893           }
3894         if (LocaleCompare("black-point-compensation",option+1) == 0)
3895           break;
3896         if (LocaleCompare("black-threshold",option+1) == 0)
3897           {
3898             if (*option == '+')
3899               break;
3900             i++;
3901             if (i == (ssize_t) argc)
3902               ThrowMogrifyException(OptionError,"MissingArgument",option);
3903             if (IsGeometry(argv[i]) == MagickFalse)
3904               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3905             break;
3906           }
3907         if (LocaleCompare("blue-primary",option+1) == 0)
3908           {
3909             if (*option == '+')
3910               break;
3911             i++;
3912             if (i == (ssize_t) argc)
3913               ThrowMogrifyException(OptionError,"MissingArgument",option);
3914             if (IsGeometry(argv[i]) == MagickFalse)
3915               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3916             break;
3917           }
3918         if (LocaleCompare("blue-shift",option+1) == 0)
3919           {
3920             i++;
3921             if (i == (ssize_t) argc)
3922               ThrowMogrifyException(OptionError,"MissingArgument",option);
3923             if (IsGeometry(argv[i]) == MagickFalse)
3924               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3925             break;
3926           }
3927         if (LocaleCompare("blur",option+1) == 0)
3928           {
3929             i++;
3930             if (i == (ssize_t) argc)
3931               ThrowMogrifyException(OptionError,"MissingArgument",option);
3932             if (IsGeometry(argv[i]) == MagickFalse)
3933               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3934             break;
3935           }
3936         if (LocaleCompare("border",option+1) == 0)
3937           {
3938             if (*option == '+')
3939               break;
3940             i++;
3941             if (i == (ssize_t) argc)
3942               ThrowMogrifyException(OptionError,"MissingArgument",option);
3943             if (IsGeometry(argv[i]) == MagickFalse)
3944               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3945             break;
3946           }
3947         if (LocaleCompare("bordercolor",option+1) == 0)
3948           {
3949             if (*option == '+')
3950               break;
3951             i++;
3952             if (i == (ssize_t) argc)
3953               ThrowMogrifyException(OptionError,"MissingArgument",option);
3954             break;
3955           }
3956         if (LocaleCompare("box",option+1) == 0)
3957           {
3958             if (*option == '+')
3959               break;
3960             i++;
3961             if (i == (ssize_t) argc)
3962               ThrowMogrifyException(OptionError,"MissingArgument",option);
3963             break;
3964           }
3965         if (LocaleCompare("brightness-contrast",option+1) == 0)
3966           {
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         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3975       }
3976       case 'c':
3977       {
3978         if (LocaleCompare("cache",option+1) == 0)
3979           {
3980             if (*option == '+')
3981               break;
3982             i++;
3983             if (i == (ssize_t) argc)
3984               ThrowMogrifyException(OptionError,"MissingArgument",option);
3985             if (IsGeometry(argv[i]) == MagickFalse)
3986               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3987             break;
3988           }
3989         if (LocaleCompare("caption",option+1) == 0)
3990           {
3991             if (*option == '+')
3992               break;
3993             i++;
3994             if (i == (ssize_t) argc)
3995               ThrowMogrifyException(OptionError,"MissingArgument",option);
3996             break;
3997           }
3998         if (LocaleCompare("channel",option+1) == 0)
3999           {
4000             ssize_t
4001               channel;
4002
4003             if (*option == '+')
4004               break;
4005             i++;
4006             if (i == (ssize_t) (argc-1))
4007               ThrowMogrifyException(OptionError,"MissingArgument",option);
4008             channel=ParseChannelOption(argv[i]);
4009             if (channel < 0)
4010               ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4011                 argv[i]);
4012             break;
4013           }
4014         if (LocaleCompare("cdl",option+1) == 0)
4015           {
4016             if (*option == '+')
4017               break;
4018             i++;
4019             if (i == (ssize_t) (argc-1))
4020               ThrowMogrifyException(OptionError,"MissingArgument",option);
4021             break;
4022           }
4023         if (LocaleCompare("charcoal",option+1) == 0)
4024           {
4025             if (*option == '+')
4026               break;
4027             i++;
4028             if (i == (ssize_t) argc)
4029               ThrowMogrifyException(OptionError,"MissingArgument",option);
4030             if (IsGeometry(argv[i]) == MagickFalse)
4031               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4032             break;
4033           }
4034         if (LocaleCompare("chop",option+1) == 0)
4035           {
4036             if (*option == '+')
4037               break;
4038             i++;
4039             if (i == (ssize_t) argc)
4040               ThrowMogrifyException(OptionError,"MissingArgument",option);
4041             if (IsGeometry(argv[i]) == MagickFalse)
4042               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4043             break;
4044           }
4045         if (LocaleCompare("clamp",option+1) == 0)
4046           break;
4047         if (LocaleCompare("clip",option+1) == 0)
4048           break;
4049         if (LocaleCompare("clip-mask",option+1) == 0)
4050           {
4051             if (*option == '+')
4052               break;
4053             i++;
4054             if (i == (ssize_t) argc)
4055               ThrowMogrifyException(OptionError,"MissingArgument",option);
4056             break;
4057           }
4058         if (LocaleCompare("clut",option+1) == 0)
4059           break;
4060         if (LocaleCompare("coalesce",option+1) == 0)
4061           break;
4062         if (LocaleCompare("colorize",option+1) == 0)
4063           {
4064             if (*option == '+')
4065               break;
4066             i++;
4067             if (i == (ssize_t) argc)
4068               ThrowMogrifyException(OptionError,"MissingArgument",option);
4069             if (IsGeometry(argv[i]) == MagickFalse)
4070               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4071             break;
4072           }
4073         if (LocaleCompare("color-matrix",option+1) == 0)
4074           {
4075             KernelInfo
4076               *kernel_info;
4077
4078             if (*option == '+')
4079               break;
4080             i++;
4081             if (i == (ssize_t) (argc-1))
4082               ThrowMogrifyException(OptionError,"MissingArgument",option);
4083             kernel_info=AcquireKernelInfo(argv[i]);
4084             if (kernel_info == (KernelInfo *) NULL)
4085               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4086             kernel_info=DestroyKernelInfo(kernel_info);
4087             break;
4088           }
4089         if (LocaleCompare("colors",option+1) == 0)
4090           {
4091             if (*option == '+')
4092               break;
4093             i++;
4094             if (i == (ssize_t) argc)
4095               ThrowMogrifyException(OptionError,"MissingArgument",option);
4096             if (IsGeometry(argv[i]) == MagickFalse)
4097               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4098             break;
4099           }
4100         if (LocaleCompare("colorspace",option+1) == 0)
4101           {
4102             ssize_t
4103               colorspace;
4104
4105             if (*option == '+')
4106               break;
4107             i++;
4108             if (i == (ssize_t) argc)
4109               ThrowMogrifyException(OptionError,"MissingArgument",option);
4110             colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4111               argv[i]);
4112             if (colorspace < 0)
4113               ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4114                 argv[i]);
4115             break;
4116           }
4117         if (LocaleCompare("combine",option+1) == 0)
4118           break;
4119         if (LocaleCompare("comment",option+1) == 0)
4120           {
4121             if (*option == '+')
4122               break;
4123             i++;
4124             if (i == (ssize_t) argc)
4125               ThrowMogrifyException(OptionError,"MissingArgument",option);
4126             break;
4127           }
4128         if (LocaleCompare("composite",option+1) == 0)
4129           break;
4130         if (LocaleCompare("compress",option+1) == 0)
4131           {
4132             ssize_t
4133               compress;
4134
4135             if (*option == '+')
4136               break;
4137             i++;
4138             if (i == (ssize_t) argc)
4139               ThrowMogrifyException(OptionError,"MissingArgument",option);
4140             compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
4141               argv[i]);
4142             if (compress < 0)
4143               ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4144                 argv[i]);
4145             break;
4146           }
4147         if (LocaleCompare("concurrent",option+1) == 0)
4148           break;
4149         if (LocaleCompare("contrast",option+1) == 0)
4150           break;
4151         if (LocaleCompare("contrast-stretch",option+1) == 0)
4152           {
4153             i++;
4154             if (i == (ssize_t) argc)
4155               ThrowMogrifyException(OptionError,"MissingArgument",option);
4156             if (IsGeometry(argv[i]) == MagickFalse)
4157               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4158             break;
4159           }
4160         if (LocaleCompare("convolve",option+1) == 0)
4161           {
4162             KernelInfo
4163               *kernel_info;
4164
4165             if (*option == '+')
4166               break;
4167             i++;
4168             if (i == (ssize_t) argc)
4169               ThrowMogrifyException(OptionError,"MissingArgument",option);
4170             kernel_info=AcquireKernelInfo(argv[i]);
4171             if (kernel_info == (KernelInfo *) NULL)
4172               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4173             kernel_info=DestroyKernelInfo(kernel_info);
4174             break;
4175           }
4176         if (LocaleCompare("crop",option+1) == 0)
4177           {
4178             if (*option == '+')
4179               break;
4180             i++;
4181             if (i == (ssize_t) argc)
4182               ThrowMogrifyException(OptionError,"MissingArgument",option);
4183             if (IsGeometry(argv[i]) == MagickFalse)
4184               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4185             break;
4186           }
4187         if (LocaleCompare("cycle",option+1) == 0)
4188           {
4189             if (*option == '+')
4190               break;
4191             i++;
4192             if (i == (ssize_t) argc)
4193               ThrowMogrifyException(OptionError,"MissingArgument",option);
4194             if (IsGeometry(argv[i]) == MagickFalse)
4195               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4196             break;
4197           }
4198         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4199       }
4200       case 'd':
4201       {
4202         if (LocaleCompare("decipher",option+1) == 0)
4203           {
4204             if (*option == '+')
4205               break;
4206             i++;
4207             if (i == (ssize_t) (argc-1))
4208               ThrowMogrifyException(OptionError,"MissingArgument",option);
4209             break;
4210           }
4211         if (LocaleCompare("deconstruct",option+1) == 0)
4212           break;
4213         if (LocaleCompare("debug",option+1) == 0)
4214           {
4215             ssize_t
4216               event;
4217
4218             if (*option == '+')
4219               break;
4220             i++;
4221             if (i == (ssize_t) argc)
4222               ThrowMogrifyException(OptionError,"MissingArgument",option);
4223             event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
4224             if (event < 0)
4225               ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4226                 argv[i]);
4227             (void) SetLogEventMask(argv[i]);
4228             break;
4229           }
4230         if (LocaleCompare("define",option+1) == 0)
4231           {
4232             i++;
4233             if (i == (ssize_t) argc)
4234               ThrowMogrifyException(OptionError,"MissingArgument",option);
4235             if (*option == '+')
4236               {
4237                 const char
4238                   *define;
4239
4240                 define=GetImageOption(image_info,argv[i]);
4241                 if (define == (const char *) NULL)
4242                   ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4243                 break;
4244               }
4245             break;
4246           }
4247         if (LocaleCompare("delay",option+1) == 0)
4248           {
4249             if (*option == '+')
4250               break;
4251             i++;
4252             if (i == (ssize_t) argc)
4253               ThrowMogrifyException(OptionError,"MissingArgument",option);
4254             if (IsGeometry(argv[i]) == MagickFalse)
4255               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4256             break;
4257           }
4258         if (LocaleCompare("delete",option+1) == 0)
4259           {
4260             if (*option == '+')
4261               break;
4262             i++;
4263             if (i == (ssize_t) (argc-1))
4264               ThrowMogrifyException(OptionError,"MissingArgument",option);
4265             if (IsGeometry(argv[i]) == MagickFalse)
4266               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4267             break;
4268           }
4269         if (LocaleCompare("density",option+1) == 0)
4270           {
4271             if (*option == '+')
4272               break;
4273             i++;
4274             if (i == (ssize_t) argc)
4275               ThrowMogrifyException(OptionError,"MissingArgument",option);
4276             if (IsGeometry(argv[i]) == MagickFalse)
4277               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4278             break;
4279           }
4280         if (LocaleCompare("depth",option+1) == 0)
4281           {
4282             if (*option == '+')
4283               break;
4284             i++;
4285             if (i == (ssize_t) argc)
4286               ThrowMogrifyException(OptionError,"MissingArgument",option);
4287             if (IsGeometry(argv[i]) == MagickFalse)
4288               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4289             break;
4290           }
4291         if (LocaleCompare("deskew",option+1) == 0)
4292           {
4293             if (*option == '+')
4294               break;
4295             i++;
4296             if (i == (ssize_t) argc)
4297               ThrowMogrifyException(OptionError,"MissingArgument",option);
4298             if (IsGeometry(argv[i]) == MagickFalse)
4299               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4300             break;
4301           }
4302         if (LocaleCompare("despeckle",option+1) == 0)
4303           break;
4304         if (LocaleCompare("dft",option+1) == 0)
4305           break;
4306         if (LocaleCompare("direction",option+1) == 0)
4307           {
4308             ssize_t
4309               direction;
4310
4311             if (*option == '+')
4312               break;
4313             i++;
4314             if (i == (ssize_t) argc)
4315               ThrowMogrifyException(OptionError,"MissingArgument",option);
4316             direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
4317               argv[i]);
4318             if (direction < 0)
4319               ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4320                 argv[i]);
4321             break;
4322           }
4323         if (LocaleCompare("display",option+1) == 0)
4324           {
4325             if (*option == '+')
4326               break;
4327             i++;
4328             if (i == (ssize_t) argc)
4329               ThrowMogrifyException(OptionError,"MissingArgument",option);
4330             break;
4331           }
4332         if (LocaleCompare("dispose",option+1) == 0)
4333           {
4334             ssize_t
4335               dispose;
4336
4337             if (*option == '+')
4338               break;
4339             i++;
4340             if (i == (ssize_t) argc)
4341               ThrowMogrifyException(OptionError,"MissingArgument",option);
4342             dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
4343             if (dispose < 0)
4344               ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4345                 argv[i]);
4346             break;
4347           }
4348         if (LocaleCompare("distort",option+1) == 0)
4349           {
4350             ssize_t
4351               op;
4352
4353             i++;
4354             if (i == (ssize_t) argc)
4355               ThrowMogrifyException(OptionError,"MissingArgument",option);
4356             op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
4357             if (op < 0)
4358               ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4359                 argv[i]);
4360             i++;
4361             if (i == (ssize_t) (argc-1))
4362               ThrowMogrifyException(OptionError,"MissingArgument",option);
4363             break;
4364           }
4365         if (LocaleCompare("dither",option+1) == 0)
4366           {
4367             ssize_t
4368               method;
4369
4370             if (*option == '+')
4371               break;
4372             i++;
4373             if (i == (ssize_t) argc)
4374               ThrowMogrifyException(OptionError,"MissingArgument",option);
4375             method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
4376             if (method < 0)
4377               ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4378                 argv[i]);
4379             break;
4380           }
4381         if (LocaleCompare("draw",option+1) == 0)
4382           {
4383             if (*option == '+')
4384               break;
4385             i++;
4386             if (i == (ssize_t) argc)
4387               ThrowMogrifyException(OptionError,"MissingArgument",option);
4388             break;
4389           }
4390         if (LocaleCompare("duplicate",option+1) == 0)
4391           {
4392             if (*option == '+')
4393               break;
4394             i++;
4395             if (i == (ssize_t) (argc-1))
4396               ThrowMogrifyException(OptionError,"MissingArgument",option);
4397             if (IsGeometry(argv[i]) == MagickFalse)
4398               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4399             break;
4400           }
4401         if (LocaleCompare("duration",option+1) == 0)
4402           {
4403             if (*option == '+')
4404               break;
4405             i++;
4406             if (i == (ssize_t) (argc-1))
4407               ThrowMogrifyException(OptionError,"MissingArgument",option);
4408             if (IsGeometry(argv[i]) == MagickFalse)
4409               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4410             break;
4411           }
4412         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4413       }
4414       case 'e':
4415       {
4416         if (LocaleCompare("edge",option+1) == 0)
4417           {
4418             if (*option == '+')
4419               break;
4420             i++;
4421             if (i == (ssize_t) argc)
4422               ThrowMogrifyException(OptionError,"MissingArgument",option);
4423             if (IsGeometry(argv[i]) == MagickFalse)
4424               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4425             break;
4426           }
4427         if (LocaleCompare("emboss",option+1) == 0)
4428           {
4429             if (*option == '+')
4430               break;
4431             i++;
4432             if (i == (ssize_t) argc)
4433               ThrowMogrifyException(OptionError,"MissingArgument",option);
4434             if (IsGeometry(argv[i]) == MagickFalse)
4435               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4436             break;
4437           }
4438         if (LocaleCompare("encipher",option+1) == 0)
4439           {
4440             if (*option == '+')
4441               break;
4442             i++;
4443             if (i == (ssize_t) argc)
4444               ThrowMogrifyException(OptionError,"MissingArgument",option);
4445             break;
4446           }
4447         if (LocaleCompare("encoding",option+1) == 0)
4448           {
4449             if (*option == '+')
4450               break;
4451             i++;
4452             if (i == (ssize_t) argc)
4453               ThrowMogrifyException(OptionError,"MissingArgument",option);
4454             break;
4455           }
4456         if (LocaleCompare("endian",option+1) == 0)
4457           {
4458             ssize_t
4459               endian;
4460
4461             if (*option == '+')
4462               break;
4463             i++;
4464             if (i == (ssize_t) argc)
4465               ThrowMogrifyException(OptionError,"MissingArgument",option);
4466             endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
4467             if (endian < 0)
4468               ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4469                 argv[i]);
4470             break;
4471           }
4472         if (LocaleCompare("enhance",option+1) == 0)
4473           break;
4474         if (LocaleCompare("equalize",option+1) == 0)
4475           break;
4476         if (LocaleCompare("evaluate",option+1) == 0)
4477           {
4478             ssize_t
4479               op;
4480
4481             if (*option == '+')
4482               break;
4483             i++;
4484             if (i == (ssize_t) argc)
4485               ThrowMogrifyException(OptionError,"MissingArgument",option);
4486             op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4487             if (op < 0)
4488               ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4489                 argv[i]);
4490             i++;
4491             if (i == (ssize_t) (argc-1))
4492               ThrowMogrifyException(OptionError,"MissingArgument",option);
4493             if (IsGeometry(argv[i]) == MagickFalse)
4494               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4495             break;
4496           }
4497         if (LocaleCompare("evaluate-sequence",option+1) == 0)
4498           {
4499             ssize_t
4500               op;
4501
4502             if (*option == '+')
4503               break;
4504             i++;
4505             if (i == (ssize_t) argc)
4506               ThrowMogrifyException(OptionError,"MissingArgument",option);
4507             op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4508             if (op < 0)
4509               ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4510                 argv[i]);
4511             break;
4512           }
4513         if (LocaleCompare("extent",option+1) == 0)
4514           {
4515             if (*option == '+')
4516               break;
4517             i++;
4518             if (i == (ssize_t) argc)
4519               ThrowMogrifyException(OptionError,"MissingArgument",option);
4520             if (IsGeometry(argv[i]) == MagickFalse)
4521               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4522             break;
4523           }
4524         if (LocaleCompare("extract",option+1) == 0)
4525           {
4526             if (*option == '+')
4527               break;
4528             i++;
4529             if (i == (ssize_t) argc)
4530               ThrowMogrifyException(OptionError,"MissingArgument",option);
4531             if (IsGeometry(argv[i]) == MagickFalse)
4532               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4533             break;
4534           }
4535         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4536       }
4537       case 'f':
4538       {
4539         if (LocaleCompare("family",option+1) == 0)
4540           {
4541             if (*option == '+')
4542               break;
4543             i++;
4544             if (i == (ssize_t) (argc-1))
4545               ThrowMogrifyException(OptionError,"MissingArgument",option);
4546             break;
4547           }
4548         if (LocaleCompare("fill",option+1) == 0)
4549           {
4550             if (*option == '+')
4551               break;
4552             i++;
4553             if (i == (ssize_t) argc)
4554               ThrowMogrifyException(OptionError,"MissingArgument",option);
4555             break;
4556           }
4557         if (LocaleCompare("filter",option+1) == 0)
4558           {
4559             ssize_t
4560               filter;
4561
4562             if (*option == '+')
4563               break;
4564             i++;
4565             if (i == (ssize_t) argc)
4566               ThrowMogrifyException(OptionError,"MissingArgument",option);
4567             filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
4568             if (filter < 0)
4569               ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4570                 argv[i]);
4571             break;
4572           }
4573         if (LocaleCompare("flatten",option+1) == 0)
4574           break;
4575         if (LocaleCompare("flip",option+1) == 0)
4576           break;
4577         if (LocaleCompare("flop",option+1) == 0)
4578           break;
4579         if (LocaleCompare("floodfill",option+1) == 0)
4580           {
4581             if (*option == '+')
4582               break;
4583             i++;
4584             if (i == (ssize_t) argc)
4585               ThrowMogrifyException(OptionError,"MissingArgument",option);
4586             if (IsGeometry(argv[i]) == MagickFalse)
4587               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4588             i++;
4589             if (i == (ssize_t) argc)
4590               ThrowMogrifyException(OptionError,"MissingArgument",option);
4591             break;
4592           }
4593         if (LocaleCompare("font",option+1) == 0)
4594           {
4595             if (*option == '+')
4596               break;
4597             i++;
4598             if (i == (ssize_t) argc)
4599               ThrowMogrifyException(OptionError,"MissingArgument",option);
4600             break;
4601           }
4602         if (LocaleCompare("format",option+1) == 0)
4603           {
4604             (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4605             (void) CloneString(&format,(char *) NULL);
4606             if (*option == '+')
4607               break;
4608             i++;
4609             if (i == (ssize_t) argc)
4610               ThrowMogrifyException(OptionError,"MissingArgument",option);
4611             (void) CloneString(&format,argv[i]);
4612             (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4613             (void) ConcatenateMagickString(image_info->filename,":",
4614               MaxTextExtent);
4615             (void) SetImageInfo(image_info,0,exception);
4616             if (*image_info->magick == '\0')
4617               ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4618                 format);
4619             break;
4620           }
4621         if (LocaleCompare("frame",option+1) == 0)
4622           {
4623             if (*option == '+')
4624               break;
4625             i++;
4626             if (i == (ssize_t) argc)
4627               ThrowMogrifyException(OptionError,"MissingArgument",option);
4628             if (IsGeometry(argv[i]) == MagickFalse)
4629               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4630             break;
4631           }
4632         if (LocaleCompare("function",option+1) == 0)
4633           {
4634             ssize_t
4635               op;
4636
4637             if (*option == '+')
4638               break;
4639             i++;
4640             if (i == (ssize_t) argc)
4641               ThrowMogrifyException(OptionError,"MissingArgument",option);
4642             op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
4643             if (op < 0)
4644               ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4645              i++;
4646              if (i == (ssize_t) (argc-1))
4647                ThrowMogrifyException(OptionError,"MissingArgument",option);
4648             break;
4649           }
4650         if (LocaleCompare("fuzz",option+1) == 0)
4651           {
4652             if (*option == '+')
4653               break;
4654             i++;
4655             if (i == (ssize_t) argc)
4656               ThrowMogrifyException(OptionError,"MissingArgument",option);
4657             if (IsGeometry(argv[i]) == MagickFalse)
4658               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4659             break;
4660           }
4661         if (LocaleCompare("fx",option+1) == 0)
4662           {
4663             if (*option == '+')
4664               break;
4665             i++;
4666             if (i == (ssize_t) (argc-1))
4667               ThrowMogrifyException(OptionError,"MissingArgument",option);
4668             break;
4669           }
4670         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4671       }
4672       case 'g':
4673       {
4674         if (LocaleCompare("gamma",option+1) == 0)
4675           {
4676             i++;
4677             if (i == (ssize_t) argc)
4678               ThrowMogrifyException(OptionError,"MissingArgument",option);
4679             if (IsGeometry(argv[i]) == MagickFalse)
4680               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4681             break;
4682           }
4683         if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4684             (LocaleCompare("gaussian",option+1) == 0))
4685           {
4686             i++;
4687             if (i == (ssize_t) argc)
4688               ThrowMogrifyException(OptionError,"MissingArgument",option);
4689             if (IsGeometry(argv[i]) == MagickFalse)
4690               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4691             break;
4692           }
4693         if (LocaleCompare("geometry",option+1) == 0)
4694           {
4695             if (*option == '+')
4696               break;
4697             i++;
4698             if (i == (ssize_t) argc)
4699               ThrowMogrifyException(OptionError,"MissingArgument",option);
4700             if (IsGeometry(argv[i]) == MagickFalse)
4701               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4702             break;
4703           }
4704         if (LocaleCompare("gravity",option+1) == 0)
4705           {
4706             ssize_t
4707               gravity;
4708
4709             if (*option == '+')
4710               break;
4711             i++;
4712             if (i == (ssize_t) argc)
4713               ThrowMogrifyException(OptionError,"MissingArgument",option);
4714             gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
4715             if (gravity < 0)
4716               ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4717                 argv[i]);
4718             break;
4719           }
4720         if (LocaleCompare("green-primary",option+1) == 0)
4721           {
4722             if (*option == '+')
4723               break;
4724             i++;
4725             if (i == (ssize_t) argc)
4726               ThrowMogrifyException(OptionError,"MissingArgument",option);
4727             if (IsGeometry(argv[i]) == MagickFalse)
4728               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4729             break;
4730           }
4731         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4732       }
4733       case 'h':
4734       {
4735         if (LocaleCompare("hald-clut",option+1) == 0)
4736           break;
4737         if ((LocaleCompare("help",option+1) == 0) ||
4738             (LocaleCompare("-help",option+1) == 0))
4739           return(MogrifyUsage());
4740         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4741       }
4742       case 'i':
4743       {
4744         if (LocaleCompare("identify",option+1) == 0)
4745           break;
4746         if (LocaleCompare("idft",option+1) == 0)
4747           break;
4748         if (LocaleCompare("implode",option+1) == 0)
4749           {
4750             if (*option == '+')
4751               break;
4752             i++;
4753             if (i == (ssize_t) argc)
4754               ThrowMogrifyException(OptionError,"MissingArgument",option);
4755             if (IsGeometry(argv[i]) == MagickFalse)
4756               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4757             break;
4758           }
4759         if (LocaleCompare("intent",option+1) == 0)
4760           {
4761             ssize_t
4762               intent;
4763
4764             if (*option == '+')
4765               break;
4766             i++;
4767             if (i == (ssize_t) (argc-1))
4768               ThrowMogrifyException(OptionError,"MissingArgument",option);
4769             intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
4770             if (intent < 0)
4771               ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4772                 argv[i]);
4773             break;
4774           }
4775         if (LocaleCompare("interlace",option+1) == 0)
4776           {
4777             ssize_t
4778               interlace;
4779
4780             if (*option == '+')
4781               break;
4782             i++;
4783             if (i == (ssize_t) argc)
4784               ThrowMogrifyException(OptionError,"MissingArgument",option);
4785             interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
4786               argv[i]);
4787             if (interlace < 0)
4788               ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4789                 argv[i]);
4790             break;
4791           }
4792         if (LocaleCompare("interline-spacing",option+1) == 0)
4793           {
4794             if (*option == '+')
4795               break;
4796             i++;
4797             if (i == (ssize_t) (argc-1))
4798               ThrowMogrifyException(OptionError,"MissingArgument",option);
4799             if (IsGeometry(argv[i]) == MagickFalse)
4800               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4801             break;
4802           }
4803         if (LocaleCompare("interpolate",option+1) == 0)
4804           {
4805             ssize_t
4806               interpolate;
4807
4808             if (*option == '+')
4809               break;
4810             i++;
4811             if (i == (ssize_t) argc)
4812               ThrowMogrifyException(OptionError,"MissingArgument",option);
4813             interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
4814               argv[i]);
4815             if (interpolate < 0)
4816               ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4817                 argv[i]);
4818             break;
4819           }
4820         if (LocaleCompare("interword-spacing",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 'k':
4834       {
4835         if (LocaleCompare("kerning",option+1) == 0)
4836           {
4837             if (*option == '+')
4838               break;
4839             i++;
4840             if (i == (ssize_t) (argc-1))
4841               ThrowMogrifyException(OptionError,"MissingArgument",option);
4842             if (IsGeometry(argv[i]) == MagickFalse)
4843               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4844             break;
4845           }
4846         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4847       }
4848       case 'l':
4849       {
4850         if (LocaleCompare("label",option+1) == 0)
4851           {
4852             if (*option == '+')
4853               break;
4854             i++;
4855             if (i == (ssize_t) argc)
4856               ThrowMogrifyException(OptionError,"MissingArgument",option);
4857             break;
4858           }
4859         if (LocaleCompare("lat",option+1) == 0)
4860           {
4861             if (*option == '+')
4862               break;
4863             i++;
4864             if (i == (ssize_t) argc)
4865               ThrowMogrifyException(OptionError,"MissingArgument",option);
4866             if (IsGeometry(argv[i]) == MagickFalse)
4867               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4868           }
4869         if (LocaleCompare("layers",option+1) == 0)
4870           {
4871             ssize_t
4872               type;
4873
4874             if (*option == '+')
4875               break;
4876             i++;
4877             if (i == (ssize_t) (argc-1))
4878               ThrowMogrifyException(OptionError,"MissingArgument",option);
4879             type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
4880             if (type < 0)
4881               ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4882                 argv[i]);
4883             break;
4884           }
4885         if (LocaleCompare("level",option+1) == 0)
4886           {
4887             i++;
4888             if (i == (ssize_t) argc)
4889               ThrowMogrifyException(OptionError,"MissingArgument",option);
4890             if (IsGeometry(argv[i]) == MagickFalse)
4891               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4892             break;
4893           }
4894         if (LocaleCompare("level-colors",option+1) == 0)
4895           {
4896             i++;
4897             if (i == (ssize_t) argc)
4898               ThrowMogrifyException(OptionError,"MissingArgument",option);
4899             break;
4900           }
4901         if (LocaleCompare("linewidth",option+1) == 0)
4902           {
4903             if (*option == '+')
4904               break;
4905             i++;
4906             if (i == (ssize_t) argc)
4907               ThrowMogrifyException(OptionError,"MissingArgument",option);
4908             if (IsGeometry(argv[i]) == MagickFalse)
4909               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4910             break;
4911           }
4912         if (LocaleCompare("limit",option+1) == 0)
4913           {
4914             char
4915               *p;
4916
4917             double
4918               value;
4919
4920             ssize_t
4921               resource;
4922
4923             if (*option == '+')
4924               break;
4925             i++;
4926             if (i == (ssize_t) argc)
4927               ThrowMogrifyException(OptionError,"MissingArgument",option);
4928             resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
4929               argv[i]);
4930             if (resource < 0)
4931               ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4932                 argv[i]);
4933             i++;
4934             if (i == (ssize_t) argc)
4935               ThrowMogrifyException(OptionError,"MissingArgument",option);
4936             value=InterpretLocaleValue(argv[i],&p);
4937             (void) value;
4938             if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4939               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4940             break;
4941           }
4942         if (LocaleCompare("liquid-rescale",option+1) == 0)
4943           {
4944             i++;
4945             if (i == (ssize_t) argc)
4946               ThrowMogrifyException(OptionError,"MissingArgument",option);
4947             if (IsGeometry(argv[i]) == MagickFalse)
4948               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4949             break;
4950           }
4951         if (LocaleCompare("list",option+1) == 0)
4952           {
4953             ssize_t
4954               list;
4955
4956             if (*option == '+')
4957               break;
4958             i++;
4959             if (i == (ssize_t) argc)
4960               ThrowMogrifyException(OptionError,"MissingArgument",option);
4961             list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
4962             if (list < 0)
4963               ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
4964             status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
4965               argv+j,exception);
4966             return(status != 0 ? MagickFalse : MagickTrue);
4967           }
4968         if (LocaleCompare("log",option+1) == 0)
4969           {
4970             if (*option == '+')
4971               break;
4972             i++;
4973             if ((i == (ssize_t) argc) ||
4974                 (strchr(argv[i],'%') == (char *) NULL))
4975               ThrowMogrifyException(OptionError,"MissingArgument",option);
4976             break;
4977           }
4978         if (LocaleCompare("loop",option+1) == 0)
4979           {
4980             if (*option == '+')
4981               break;
4982             i++;
4983             if (i == (ssize_t) argc)
4984               ThrowMogrifyException(OptionError,"MissingArgument",option);
4985             if (IsGeometry(argv[i]) == MagickFalse)
4986               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4987             break;
4988           }
4989         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4990       }
4991       case 'm':
4992       {
4993         if (LocaleCompare("map",option+1) == 0)
4994           {
4995             global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4996             if (*option == '+')
4997               break;
4998             i++;
4999             if (i == (ssize_t) argc)
5000               ThrowMogrifyException(OptionError,"MissingArgument",option);
5001             break;
5002           }
5003         if (LocaleCompare("mask",option+1) == 0)
5004           {
5005             if (*option == '+')
5006               break;
5007             i++;
5008             if (i == (ssize_t) argc)
5009               ThrowMogrifyException(OptionError,"MissingArgument",option);
5010             break;
5011           }
5012         if (LocaleCompare("matte",option+1) == 0)
5013           break;
5014         if (LocaleCompare("mattecolor",option+1) == 0)
5015           {
5016             if (*option == '+')
5017               break;
5018             i++;
5019             if (i == (ssize_t) argc)
5020               ThrowMogrifyException(OptionError,"MissingArgument",option);
5021             break;
5022           }
5023         if (LocaleCompare("maximum",option+1) == 0)
5024           break;
5025         if (LocaleCompare("minimum",option+1) == 0)
5026           break;
5027         if (LocaleCompare("modulate",option+1) == 0)
5028           {
5029             if (*option == '+')
5030               break;
5031             i++;
5032             if (i == (ssize_t) argc)
5033               ThrowMogrifyException(OptionError,"MissingArgument",option);
5034             if (IsGeometry(argv[i]) == MagickFalse)
5035               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5036             break;
5037           }
5038         if (LocaleCompare("median",option+1) == 0)
5039           {
5040             if (*option == '+')
5041               break;
5042             i++;
5043             if (i == (ssize_t) argc)
5044               ThrowMogrifyException(OptionError,"MissingArgument",option);
5045             if (IsGeometry(argv[i]) == MagickFalse)
5046               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5047             break;
5048           }
5049         if (LocaleCompare("mode",option+1) == 0)
5050           {
5051             if (*option == '+')
5052               break;
5053             i++;
5054             if (i == (ssize_t) argc)
5055               ThrowMogrifyException(OptionError,"MissingArgument",option);
5056             if (IsGeometry(argv[i]) == MagickFalse)
5057               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5058             break;
5059           }
5060         if (LocaleCompare("monitor",option+1) == 0)
5061           break;
5062         if (LocaleCompare("monochrome",option+1) == 0)
5063           break;
5064         if (LocaleCompare("morph",option+1) == 0)
5065           {
5066             if (*option == '+')
5067               break;
5068             i++;
5069             if (i == (ssize_t) (argc-1))
5070               ThrowMogrifyException(OptionError,"MissingArgument",option);
5071             if (IsGeometry(argv[i]) == MagickFalse)
5072               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5073             break;
5074           }
5075         if (LocaleCompare("morphology",option+1) == 0)
5076           {
5077             char
5078               token[MaxTextExtent];
5079
5080             KernelInfo
5081               *kernel_info;
5082
5083             ssize_t
5084               op;
5085
5086             i++;
5087             if (i == (ssize_t) argc)
5088               ThrowMogrifyException(OptionError,"MissingArgument",option);
5089             GetMagickToken(argv[i],NULL,token);
5090             op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
5091             if (op < 0)
5092               ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
5093                 token);
5094             i++;
5095             if (i == (ssize_t) (argc-1))
5096               ThrowMogrifyException(OptionError,"MissingArgument",option);
5097             kernel_info=AcquireKernelInfo(argv[i]);
5098             if (kernel_info == (KernelInfo *) NULL)
5099               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5100             kernel_info=DestroyKernelInfo(kernel_info);
5101             break;
5102           }
5103         if (LocaleCompare("mosaic",option+1) == 0)
5104           break;
5105         if (LocaleCompare("motion-blur",option+1) == 0)
5106           {
5107             if (*option == '+')
5108               break;
5109             i++;
5110             if (i == (ssize_t) argc)
5111               ThrowMogrifyException(OptionError,"MissingArgument",option);
5112             if (IsGeometry(argv[i]) == MagickFalse)
5113               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5114             break;
5115           }
5116         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5117       }
5118       case 'n':
5119       {
5120         if (LocaleCompare("negate",option+1) == 0)
5121           break;
5122         if (LocaleCompare("noise",option+1) == 0)
5123           {
5124             i++;
5125             if (i == (ssize_t) argc)
5126               ThrowMogrifyException(OptionError,"MissingArgument",option);
5127             if (*option == '+')
5128               {
5129                 ssize_t
5130                   noise;
5131
5132                 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
5133                 if (noise < 0)
5134                   ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5135                     argv[i]);
5136                 break;
5137               }
5138             if (IsGeometry(argv[i]) == MagickFalse)
5139               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5140             break;
5141           }
5142         if (LocaleCompare("noop",option+1) == 0)
5143           break;
5144         if (LocaleCompare("normalize",option+1) == 0)
5145           break;
5146         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5147       }
5148       case 'o':
5149       {
5150         if (LocaleCompare("opaque",option+1) == 0)
5151           {
5152             i++;
5153             if (i == (ssize_t) argc)
5154               ThrowMogrifyException(OptionError,"MissingArgument",option);
5155             break;
5156           }
5157         if (LocaleCompare("ordered-dither",option+1) == 0)
5158           {
5159             if (*option == '+')
5160               break;
5161             i++;
5162             if (i == (ssize_t) argc)
5163               ThrowMogrifyException(OptionError,"MissingArgument",option);
5164             break;
5165           }
5166         if (LocaleCompare("orient",option+1) == 0)
5167           {
5168             ssize_t
5169               orientation;
5170
5171             orientation=UndefinedOrientation;
5172             if (*option == '+')
5173               break;
5174             i++;
5175             if (i == (ssize_t) (argc-1))
5176               ThrowMogrifyException(OptionError,"MissingArgument",option);
5177             orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
5178               argv[i]);
5179             if (orientation < 0)
5180               ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5181                 argv[i]);
5182             break;
5183           }
5184         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5185       }
5186       case 'p':
5187       {
5188         if (LocaleCompare("page",option+1) == 0)
5189           {
5190             if (*option == '+')
5191               break;
5192             i++;
5193             if (i == (ssize_t) argc)
5194               ThrowMogrifyException(OptionError,"MissingArgument",option);
5195             break;
5196           }
5197         if (LocaleCompare("paint",option+1) == 0)
5198           {
5199             if (*option == '+')
5200               break;
5201             i++;
5202             if (i == (ssize_t) argc)
5203               ThrowMogrifyException(OptionError,"MissingArgument",option);
5204             if (IsGeometry(argv[i]) == MagickFalse)
5205               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5206             break;
5207           }
5208         if (LocaleCompare("path",option+1) == 0)
5209           {
5210             (void) CloneString(&path,(char *) NULL);
5211             if (*option == '+')
5212               break;
5213             i++;
5214             if (i == (ssize_t) argc)
5215               ThrowMogrifyException(OptionError,"MissingArgument",option);
5216             (void) CloneString(&path,argv[i]);
5217             break;
5218           }
5219         if (LocaleCompare("pointsize",option+1) == 0)
5220           {
5221             if (*option == '+')
5222               break;
5223             i++;
5224             if (i == (ssize_t) argc)
5225               ThrowMogrifyException(OptionError,"MissingArgument",option);
5226             if (IsGeometry(argv[i]) == MagickFalse)
5227               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5228             break;
5229           }
5230         if (LocaleCompare("polaroid",option+1) == 0)
5231           {
5232             if (*option == '+')
5233               break;
5234             i++;
5235             if (i == (ssize_t) argc)
5236               ThrowMogrifyException(OptionError,"MissingArgument",option);
5237             if (IsGeometry(argv[i]) == MagickFalse)
5238               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5239             break;
5240           }
5241         if (LocaleCompare("posterize",option+1) == 0)
5242           {
5243             if (*option == '+')
5244               break;
5245             i++;
5246             if (i == (ssize_t) argc)
5247               ThrowMogrifyException(OptionError,"MissingArgument",option);
5248             if (IsGeometry(argv[i]) == MagickFalse)
5249               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5250             break;
5251           }
5252         if (LocaleCompare("precision",option+1) == 0)
5253           {
5254             if (*option == '+')
5255               break;
5256             i++;
5257             if (i == (ssize_t) argc)
5258               ThrowMogrifyException(OptionError,"MissingArgument",option);
5259             if (IsGeometry(argv[i]) == MagickFalse)
5260               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5261             break;
5262           }
5263         if (LocaleCompare("print",option+1) == 0)
5264           {
5265             if (*option == '+')
5266               break;
5267             i++;
5268             if (i == (ssize_t) argc)
5269               ThrowMogrifyException(OptionError,"MissingArgument",option);
5270             break;
5271           }
5272         if (LocaleCompare("process",option+1) == 0)
5273           {
5274             if (*option == '+')
5275               break;
5276             i++;
5277             if (i == (ssize_t) (argc-1))
5278               ThrowMogrifyException(OptionError,"MissingArgument",option);
5279             break;
5280           }
5281         if (LocaleCompare("profile",option+1) == 0)
5282           {
5283             i++;
5284             if (i == (ssize_t) argc)
5285               ThrowMogrifyException(OptionError,"MissingArgument",option);
5286             break;
5287           }
5288         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5289       }
5290       case 'q':
5291       {
5292         if (LocaleCompare("quality",option+1) == 0)
5293           {
5294             if (*option == '+')
5295               break;
5296             i++;
5297             if (i == (ssize_t) argc)
5298               ThrowMogrifyException(OptionError,"MissingArgument",option);
5299             if (IsGeometry(argv[i]) == MagickFalse)
5300               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5301             break;
5302           }
5303         if (LocaleCompare("quantize",option+1) == 0)
5304           {
5305             ssize_t
5306               colorspace;
5307
5308             if (*option == '+')
5309               break;
5310             i++;
5311             if (i == (ssize_t) (argc-1))
5312               ThrowMogrifyException(OptionError,"MissingArgument",option);
5313             colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
5314               argv[i]);
5315             if (colorspace < 0)
5316               ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5317                 argv[i]);
5318             break;
5319           }
5320         if (LocaleCompare("quiet",option+1) == 0)
5321           break;
5322         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5323       }
5324       case 'r':
5325       {
5326         if (LocaleCompare("radial-blur",option+1) == 0)
5327           {
5328             i++;
5329             if (i == (ssize_t) argc)
5330               ThrowMogrifyException(OptionError,"MissingArgument",option);
5331             if (IsGeometry(argv[i]) == MagickFalse)
5332               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5333             break;
5334           }
5335         if (LocaleCompare("raise",option+1) == 0)
5336           {
5337             i++;
5338             if (i == (ssize_t) argc)
5339               ThrowMogrifyException(OptionError,"MissingArgument",option);
5340             if (IsGeometry(argv[i]) == MagickFalse)
5341               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5342             break;
5343           }
5344         if (LocaleCompare("random-threshold",option+1) == 0)
5345           {
5346             if (*option == '+')
5347               break;
5348             i++;
5349             if (i == (ssize_t) argc)
5350               ThrowMogrifyException(OptionError,"MissingArgument",option);
5351             if (IsGeometry(argv[i]) == MagickFalse)
5352               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5353             break;
5354           }
5355         if (LocaleCompare("recolor",option+1) == 0)
5356           {
5357             if (*option == '+')
5358               break;
5359             i++;
5360             if (i == (ssize_t) (argc-1))
5361               ThrowMogrifyException(OptionError,"MissingArgument",option);
5362             if (IsGeometry(argv[i]) == MagickFalse)
5363               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5364             break;
5365           }
5366         if (LocaleCompare("red-primary",option+1) == 0)
5367           {
5368             if (*option == '+')
5369               break;
5370             i++;
5371             if (i == (ssize_t) argc)
5372               ThrowMogrifyException(OptionError,"MissingArgument",option);
5373             if (IsGeometry(argv[i]) == MagickFalse)
5374               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5375           }
5376         if (LocaleCompare("regard-warnings",option+1) == 0)
5377           break;
5378         if (LocaleCompare("region",option+1) == 0)
5379           {
5380             if (*option == '+')
5381               break;
5382             i++;
5383             if (i == (ssize_t) argc)
5384               ThrowMogrifyException(OptionError,"MissingArgument",option);
5385             if (IsGeometry(argv[i]) == MagickFalse)
5386               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5387             break;
5388           }
5389         if (LocaleCompare("remap",option+1) == 0)
5390           {
5391             if (*option == '+')
5392               break;
5393             i++;
5394             if (i == (ssize_t) (argc-1))
5395               ThrowMogrifyException(OptionError,"MissingArgument",option);
5396             break;
5397           }
5398         if (LocaleCompare("render",option+1) == 0)
5399           break;
5400         if (LocaleCompare("repage",option+1) == 0)
5401           {
5402             if (*option == '+')
5403               break;
5404             i++;
5405             if (i == (ssize_t) argc)
5406               ThrowMogrifyException(OptionError,"MissingArgument",option);
5407             if (IsGeometry(argv[i]) == MagickFalse)
5408               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5409             break;
5410           }
5411         if (LocaleCompare("resample",option+1) == 0)
5412           {
5413             if (*option == '+')
5414               break;
5415             i++;
5416             if (i == (ssize_t) argc)
5417               ThrowMogrifyException(OptionError,"MissingArgument",option);
5418             if (IsGeometry(argv[i]) == MagickFalse)
5419               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5420             break;
5421           }
5422         if (LocaleCompare("resize",option+1) == 0)
5423           {
5424             if (*option == '+')
5425               break;
5426             i++;
5427             if (i == (ssize_t) argc)
5428               ThrowMogrifyException(OptionError,"MissingArgument",option);
5429             if (IsGeometry(argv[i]) == MagickFalse)
5430               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5431             break;
5432           }
5433         if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5434           {
5435             respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5436             break;
5437           }
5438         if (LocaleCompare("reverse",option+1) == 0)
5439           break;
5440         if (LocaleCompare("roll",option+1) == 0)
5441           {
5442             if (*option == '+')
5443               break;
5444             i++;
5445             if (i == (ssize_t) argc)
5446               ThrowMogrifyException(OptionError,"MissingArgument",option);
5447             if (IsGeometry(argv[i]) == MagickFalse)
5448               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5449             break;
5450           }
5451         if (LocaleCompare("rotate",option+1) == 0)
5452           {
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         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5461       }
5462       case 's':
5463       {
5464         if (LocaleCompare("sample",option+1) == 0)
5465           {
5466             if (*option == '+')
5467               break;
5468             i++;
5469             if (i == (ssize_t) argc)
5470               ThrowMogrifyException(OptionError,"MissingArgument",option);
5471             if (IsGeometry(argv[i]) == MagickFalse)
5472               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5473             break;
5474           }
5475         if (LocaleCompare("sampling-factor",option+1) == 0)
5476           {
5477             if (*option == '+')
5478               break;
5479             i++;
5480             if (i == (ssize_t) argc)
5481               ThrowMogrifyException(OptionError,"MissingArgument",option);
5482             if (IsGeometry(argv[i]) == MagickFalse)
5483               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5484             break;
5485           }
5486         if (LocaleCompare("scale",option+1) == 0)
5487           {
5488             if (*option == '+')
5489               break;
5490             i++;
5491             if (i == (ssize_t) argc)
5492               ThrowMogrifyException(OptionError,"MissingArgument",option);
5493             if (IsGeometry(argv[i]) == MagickFalse)
5494               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5495             break;
5496           }
5497         if (LocaleCompare("scene",option+1) == 0)
5498           {
5499             if (*option == '+')
5500               break;
5501             i++;
5502             if (i == (ssize_t) argc)
5503               ThrowMogrifyException(OptionError,"MissingArgument",option);
5504             if (IsGeometry(argv[i]) == MagickFalse)
5505               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5506             break;
5507           }
5508         if (LocaleCompare("seed",option+1) == 0)
5509           {
5510             if (*option == '+')
5511               break;
5512             i++;
5513             if (i == (ssize_t) argc)
5514               ThrowMogrifyException(OptionError,"MissingArgument",option);
5515             if (IsGeometry(argv[i]) == MagickFalse)
5516               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5517             break;
5518           }
5519         if (LocaleCompare("segment",option+1) == 0)
5520           {
5521             if (*option == '+')
5522               break;
5523             i++;
5524             if (i == (ssize_t) argc)
5525               ThrowMogrifyException(OptionError,"MissingArgument",option);
5526             if (IsGeometry(argv[i]) == MagickFalse)
5527               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5528             break;
5529           }
5530         if (LocaleCompare("selective-blur",option+1) == 0)
5531           {
5532             i++;
5533             if (i == (ssize_t) argc)
5534               ThrowMogrifyException(OptionError,"MissingArgument",option);
5535             if (IsGeometry(argv[i]) == MagickFalse)
5536               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5537             break;
5538           }
5539         if (LocaleCompare("separate",option+1) == 0)
5540           break;
5541         if (LocaleCompare("sepia-tone",option+1) == 0)
5542           {
5543             if (*option == '+')
5544               break;
5545             i++;
5546             if (i == (ssize_t) argc)
5547               ThrowMogrifyException(OptionError,"MissingArgument",option);
5548             if (IsGeometry(argv[i]) == MagickFalse)
5549               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5550             break;
5551           }
5552         if (LocaleCompare("set",option+1) == 0)
5553           {
5554             i++;
5555             if (i == (ssize_t) argc)
5556               ThrowMogrifyException(OptionError,"MissingArgument",option);
5557             if (*option == '+')
5558               break;
5559             i++;
5560             if (i == (ssize_t) argc)
5561               ThrowMogrifyException(OptionError,"MissingArgument",option);
5562             break;
5563           }
5564         if (LocaleCompare("shade",option+1) == 0)
5565           {
5566             i++;
5567             if (i == (ssize_t) argc)
5568               ThrowMogrifyException(OptionError,"MissingArgument",option);
5569             if (IsGeometry(argv[i]) == MagickFalse)
5570               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5571             break;
5572           }
5573         if (LocaleCompare("shadow",option+1) == 0)
5574           {
5575             if (*option == '+')
5576               break;
5577             i++;
5578             if (i == (ssize_t) argc)
5579               ThrowMogrifyException(OptionError,"MissingArgument",option);
5580             if (IsGeometry(argv[i]) == MagickFalse)
5581               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5582             break;
5583           }
5584         if (LocaleCompare("sharpen",option+1) == 0)
5585           {
5586             i++;
5587             if (i == (ssize_t) argc)
5588               ThrowMogrifyException(OptionError,"MissingArgument",option);
5589             if (IsGeometry(argv[i]) == MagickFalse)
5590               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5591             break;
5592           }
5593         if (LocaleCompare("shave",option+1) == 0)
5594           {
5595             if (*option == '+')
5596               break;
5597             i++;
5598             if (i == (ssize_t) argc)
5599               ThrowMogrifyException(OptionError,"MissingArgument",option);
5600             if (IsGeometry(argv[i]) == MagickFalse)
5601               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5602             break;
5603           }
5604         if (LocaleCompare("shear",option+1) == 0)
5605           {
5606             i++;
5607             if (i == (ssize_t) argc)
5608               ThrowMogrifyException(OptionError,"MissingArgument",option);
5609             if (IsGeometry(argv[i]) == MagickFalse)
5610               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5611             break;
5612           }
5613         if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5614           {
5615             i++;
5616             if (i == (ssize_t) (argc-1))
5617               ThrowMogrifyException(OptionError,"MissingArgument",option);
5618             if (IsGeometry(argv[i]) == MagickFalse)
5619               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5620             break;
5621           }
5622         if (LocaleCompare("size",option+1) == 0)
5623           {
5624             if (*option == '+')
5625               break;
5626             i++;
5627             if (i == (ssize_t) argc)
5628               ThrowMogrifyException(OptionError,"MissingArgument",option);
5629             if (IsGeometry(argv[i]) == MagickFalse)
5630               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5631             break;
5632           }
5633         if (LocaleCompare("sketch",option+1) == 0)
5634           {
5635             if (*option == '+')
5636               break;
5637             i++;
5638             if (i == (ssize_t) argc)
5639               ThrowMogrifyException(OptionError,"MissingArgument",option);
5640             if (IsGeometry(argv[i]) == MagickFalse)
5641               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5642             break;
5643           }
5644         if (LocaleCompare("smush",option+1) == 0)
5645           {
5646             i++;
5647             if (i == (ssize_t) argc)
5648               ThrowMogrifyException(OptionError,"MissingArgument",option);
5649             if (IsGeometry(argv[i]) == MagickFalse)
5650               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5651             i++;
5652             break;
5653           }
5654         if (LocaleCompare("solarize",option+1) == 0)
5655           {
5656             if (*option == '+')
5657               break;
5658             i++;
5659             if (i == (ssize_t) argc)
5660               ThrowMogrifyException(OptionError,"MissingArgument",option);
5661             if (IsGeometry(argv[i]) == MagickFalse)
5662               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5663             break;
5664           }
5665         if (LocaleCompare("sparse-color",option+1) == 0)
5666           {
5667             ssize_t
5668               op;
5669
5670             i++;
5671             if (i == (ssize_t) argc)
5672               ThrowMogrifyException(OptionError,"MissingArgument",option);
5673             op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5674             if (op < 0)
5675               ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5676                 argv[i]);
5677             i++;
5678             if (i == (ssize_t) (argc-1))
5679               ThrowMogrifyException(OptionError,"MissingArgument",option);
5680             break;
5681           }
5682         if (LocaleCompare("spread",option+1) == 0)
5683           {
5684             if (*option == '+')
5685               break;
5686             i++;
5687             if (i == (ssize_t) argc)
5688               ThrowMogrifyException(OptionError,"MissingArgument",option);
5689             if (IsGeometry(argv[i]) == MagickFalse)
5690               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5691             break;
5692           }
5693         if (LocaleCompare("statistic",option+1) == 0)
5694           {
5695             ssize_t
5696               op;
5697
5698             if (*option == '+')
5699               break;
5700             i++;
5701             if (i == (ssize_t) argc)
5702               ThrowMogrifyException(OptionError,"MissingArgument",option);
5703             op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
5704             if (op < 0)
5705               ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5706                 argv[i]);
5707             i++;
5708             if (i == (ssize_t) (argc-1))
5709               ThrowMogrifyException(OptionError,"MissingArgument",option);
5710             if (IsGeometry(argv[i]) == MagickFalse)
5711               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5712             break;
5713           }
5714         if (LocaleCompare("stretch",option+1) == 0)
5715           {
5716             ssize_t
5717               stretch;
5718
5719             if (*option == '+')
5720               break;
5721             i++;
5722             if (i == (ssize_t) (argc-1))
5723               ThrowMogrifyException(OptionError,"MissingArgument",option);
5724             stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
5725             if (stretch < 0)
5726               ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5727                 argv[i]);
5728             break;
5729           }
5730         if (LocaleCompare("strip",option+1) == 0)
5731           break;
5732         if (LocaleCompare("stroke",option+1) == 0)
5733           {
5734             if (*option == '+')
5735               break;
5736             i++;
5737             if (i == (ssize_t) argc)
5738               ThrowMogrifyException(OptionError,"MissingArgument",option);
5739             break;
5740           }
5741         if (LocaleCompare("strokewidth",option+1) == 0)
5742           {
5743             if (*option == '+')
5744               break;
5745             i++;
5746             if (i == (ssize_t) argc)
5747               ThrowMogrifyException(OptionError,"MissingArgument",option);
5748             if (IsGeometry(argv[i]) == MagickFalse)
5749               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5750             break;
5751           }
5752         if (LocaleCompare("style",option+1) == 0)
5753           {
5754             ssize_t
5755               style;
5756
5757             if (*option == '+')
5758               break;
5759             i++;
5760             if (i == (ssize_t) (argc-1))
5761               ThrowMogrifyException(OptionError,"MissingArgument",option);
5762             style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
5763             if (style < 0)
5764               ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5765                 argv[i]);
5766             break;
5767           }
5768         if (LocaleCompare("swap",option+1) == 0)
5769           {
5770             if (*option == '+')
5771               break;
5772             i++;
5773             if (i == (ssize_t) (argc-1))
5774               ThrowMogrifyException(OptionError,"MissingArgument",option);
5775             if (IsGeometry(argv[i]) == MagickFalse)
5776               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5777             break;
5778           }
5779         if (LocaleCompare("swirl",option+1) == 0)
5780           {
5781             if (*option == '+')
5782               break;
5783             i++;
5784             if (i == (ssize_t) argc)
5785               ThrowMogrifyException(OptionError,"MissingArgument",option);
5786             if (IsGeometry(argv[i]) == MagickFalse)
5787               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5788             break;
5789           }
5790         if (LocaleCompare("synchronize",option+1) == 0)
5791           break;
5792         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5793       }
5794       case 't':
5795       {
5796         if (LocaleCompare("taint",option+1) == 0)
5797           break;
5798         if (LocaleCompare("texture",option+1) == 0)
5799           {
5800             if (*option == '+')
5801               break;
5802             i++;
5803             if (i == (ssize_t) argc)
5804               ThrowMogrifyException(OptionError,"MissingArgument",option);
5805             break;
5806           }
5807         if (LocaleCompare("tile",option+1) == 0)
5808           {
5809             if (*option == '+')
5810               break;
5811             i++;
5812             if (i == (ssize_t) (argc-1))
5813               ThrowMogrifyException(OptionError,"MissingArgument",option);
5814             break;
5815           }
5816         if (LocaleCompare("tile-offset",option+1) == 0)
5817           {
5818             if (*option == '+')
5819               break;
5820             i++;
5821             if (i == (ssize_t) argc)
5822               ThrowMogrifyException(OptionError,"MissingArgument",option);
5823             if (IsGeometry(argv[i]) == MagickFalse)
5824               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5825             break;
5826           }
5827         if (LocaleCompare("tint",option+1) == 0)
5828           {
5829             if (*option == '+')
5830               break;
5831             i++;
5832             if (i == (ssize_t) (argc-1))
5833               ThrowMogrifyException(OptionError,"MissingArgument",option);
5834             if (IsGeometry(argv[i]) == MagickFalse)
5835               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5836             break;
5837           }
5838         if (LocaleCompare("transform",option+1) == 0)
5839           break;
5840         if (LocaleCompare("transpose",option+1) == 0)
5841           break;
5842         if (LocaleCompare("transverse",option+1) == 0)
5843           break;
5844         if (LocaleCompare("threshold",option+1) == 0)
5845           {
5846             if (*option == '+')
5847               break;
5848             i++;
5849             if (i == (ssize_t) argc)
5850               ThrowMogrifyException(OptionError,"MissingArgument",option);
5851             if (IsGeometry(argv[i]) == MagickFalse)
5852               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5853             break;
5854           }
5855         if (LocaleCompare("thumbnail",option+1) == 0)
5856           {
5857             if (*option == '+')
5858               break;
5859             i++;
5860             if (i == (ssize_t) argc)
5861               ThrowMogrifyException(OptionError,"MissingArgument",option);
5862             if (IsGeometry(argv[i]) == MagickFalse)
5863               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5864             break;
5865           }
5866         if (LocaleCompare("transparent",option+1) == 0)
5867           {
5868             i++;
5869             if (i == (ssize_t) argc)
5870               ThrowMogrifyException(OptionError,"MissingArgument",option);
5871             break;
5872           }
5873         if (LocaleCompare("transparent-color",option+1) == 0)
5874           {
5875             if (*option == '+')
5876               break;
5877             i++;
5878             if (i == (ssize_t) (argc-1))
5879               ThrowMogrifyException(OptionError,"MissingArgument",option);
5880             break;
5881           }
5882         if (LocaleCompare("treedepth",option+1) == 0)
5883           {
5884             if (*option == '+')
5885               break;
5886             i++;
5887             if (i == (ssize_t) argc)
5888               ThrowMogrifyException(OptionError,"MissingArgument",option);
5889             if (IsGeometry(argv[i]) == MagickFalse)
5890               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5891             break;
5892           }
5893         if (LocaleCompare("trim",option+1) == 0)
5894           break;
5895         if (LocaleCompare("type",option+1) == 0)
5896           {
5897             ssize_t
5898               type;
5899
5900             if (*option == '+')
5901               break;
5902             i++;
5903             if (i == (ssize_t) argc)
5904               ThrowMogrifyException(OptionError,"MissingArgument",option);
5905             type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
5906             if (type < 0)
5907               ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5908                 argv[i]);
5909             break;
5910           }
5911         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5912       }
5913       case 'u':
5914       {
5915         if (LocaleCompare("undercolor",option+1) == 0)
5916           {
5917             if (*option == '+')
5918               break;
5919             i++;
5920             if (i == (ssize_t) argc)
5921               ThrowMogrifyException(OptionError,"MissingArgument",option);
5922             break;
5923           }
5924         if (LocaleCompare("unique-colors",option+1) == 0)
5925           break;
5926         if (LocaleCompare("units",option+1) == 0)
5927           {
5928             ssize_t
5929               units;
5930
5931             if (*option == '+')
5932               break;
5933             i++;
5934             if (i == (ssize_t) argc)
5935               ThrowMogrifyException(OptionError,"MissingArgument",option);
5936             units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
5937               argv[i]);
5938             if (units < 0)
5939               ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5940                 argv[i]);
5941             break;
5942           }
5943         if (LocaleCompare("unsharp",option+1) == 0)
5944           {
5945             i++;
5946             if (i == (ssize_t) argc)
5947               ThrowMogrifyException(OptionError,"MissingArgument",option);
5948             if (IsGeometry(argv[i]) == MagickFalse)
5949               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5950             break;
5951           }
5952         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5953       }
5954       case 'v':
5955       {
5956         if (LocaleCompare("verbose",option+1) == 0)
5957           {
5958             image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5959             break;
5960           }
5961         if ((LocaleCompare("version",option+1) == 0) ||
5962             (LocaleCompare("-version",option+1) == 0))
5963           {
5964             (void) FormatLocaleFile(stdout,"Version: %s\n",
5965               GetMagickVersion((size_t *) NULL));
5966             (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5967               GetMagickCopyright());
5968             (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5969               GetMagickFeatures());
5970             break;
5971           }
5972         if (LocaleCompare("view",option+1) == 0)
5973           {
5974             if (*option == '+')
5975               break;
5976             i++;
5977             if (i == (ssize_t) argc)
5978               ThrowMogrifyException(OptionError,"MissingArgument",option);
5979             break;
5980           }
5981         if (LocaleCompare("vignette",option+1) == 0)
5982           {
5983             if (*option == '+')
5984               break;
5985             i++;
5986             if (i == (ssize_t) argc)
5987               ThrowMogrifyException(OptionError,"MissingArgument",option);
5988             if (IsGeometry(argv[i]) == MagickFalse)
5989               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5990             break;
5991           }
5992         if (LocaleCompare("virtual-pixel",option+1) == 0)
5993           {
5994             ssize_t
5995               method;
5996
5997             if (*option == '+')
5998               break;
5999             i++;
6000             if (i == (ssize_t) argc)
6001               ThrowMogrifyException(OptionError,"MissingArgument",option);
6002             method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
6003               argv[i]);
6004             if (method < 0)
6005               ThrowMogrifyException(OptionError,
6006                 "UnrecognizedVirtualPixelMethod",argv[i]);
6007             break;
6008           }
6009         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6010       }
6011       case 'w':
6012       {
6013         if (LocaleCompare("wave",option+1) == 0)
6014           {
6015             i++;
6016             if (i == (ssize_t) argc)
6017               ThrowMogrifyException(OptionError,"MissingArgument",option);
6018             if (IsGeometry(argv[i]) == MagickFalse)
6019               ThrowMogrifyInvalidArgumentException(option,argv[i]);
6020             break;
6021           }
6022         if (LocaleCompare("weight",option+1) == 0)
6023           {
6024             if (*option == '+')
6025               break;
6026             i++;
6027             if (i == (ssize_t) (argc-1))
6028               ThrowMogrifyException(OptionError,"MissingArgument",option);
6029             break;
6030           }
6031         if (LocaleCompare("white-point",option+1) == 0)
6032           {
6033             if (*option == '+')
6034               break;
6035             i++;
6036             if (i == (ssize_t) argc)
6037               ThrowMogrifyException(OptionError,"MissingArgument",option);
6038             if (IsGeometry(argv[i]) == MagickFalse)
6039               ThrowMogrifyInvalidArgumentException(option,argv[i]);
6040             break;
6041           }
6042         if (LocaleCompare("white-threshold",option+1) == 0)
6043           {
6044             if (*option == '+')
6045               break;
6046             i++;
6047             if (i == (ssize_t) argc)
6048               ThrowMogrifyException(OptionError,"MissingArgument",option);
6049             if (IsGeometry(argv[i]) == MagickFalse)
6050               ThrowMogrifyInvalidArgumentException(option,argv[i]);
6051             break;
6052           }
6053         if (LocaleCompare("write",option+1) == 0)
6054           {
6055             i++;
6056             if (i == (ssize_t) (argc-1))
6057               ThrowMogrifyException(OptionError,"MissingArgument",option);
6058             break;
6059           }
6060         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6061       }
6062       case '?':
6063         break;
6064       default:
6065         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6066     }
6067     fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6068       FireOptionFlag) == 0 ?  MagickFalse : MagickTrue;
6069     if (fire != MagickFalse)
6070       FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6071   }
6072   if (k != 0)
6073     ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6074   if (i != (ssize_t) argc)
6075     ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6076   DestroyMogrify();
6077   return(status != 0 ? MagickTrue : MagickFalse);
6078 }
6079 \f
6080 /*
6081 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6082 %                                                                             %
6083 %                                                                             %
6084 %                                                                             %
6085 +     M o g r i f y I m a g e I n f o                                         %
6086 %                                                                             %
6087 %                                                                             %
6088 %                                                                             %
6089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6090 %
6091 %  MogrifyImageInfo() applies image processing settings to the image as
6092 %  prescribed by command line options.
6093 %
6094 %  The format of the MogrifyImageInfo method is:
6095 %
6096 %      MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6097 %        const char **argv,ExceptionInfo *exception)
6098 %
6099 %  A description of each parameter follows:
6100 %
6101 %    o image_info: the image info..
6102 %
6103 %    o argc: Specifies a pointer to an integer describing the number of
6104 %      elements in the argument vector.
6105 %
6106 %    o argv: Specifies a pointer to a text array containing the command line
6107 %      arguments.
6108 %
6109 %    o exception: return any errors or warnings in this structure.
6110 %
6111 */
6112 WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6113   const int argc,const char **argv,ExceptionInfo *exception)
6114 {
6115   const char
6116     *option;
6117
6118   GeometryInfo
6119     geometry_info;
6120
6121   ssize_t
6122     count;
6123
6124   register ssize_t
6125     i;
6126
6127   /*
6128     Initialize method variables.
6129   */
6130   assert(image_info != (ImageInfo *) NULL);
6131   assert(image_info->signature == MagickSignature);
6132   if (image_info->debug != MagickFalse)
6133     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6134       image_info->filename);
6135   if (argc < 0)
6136     return(MagickTrue);
6137   /*
6138     Set the image settings.
6139   */
6140   for (i=0; i < (ssize_t) argc; i++)
6141   {
6142     option=argv[i];
6143     if (IsCommandOption(option) == MagickFalse)
6144       continue;
6145     count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
6146     count=MagickMax(count,0L);
6147     if ((i+count) >= (ssize_t) argc)
6148       break;
6149     switch (*(option+1))
6150     {
6151       case 'a':
6152       {
6153         if (LocaleCompare("adjoin",option+1) == 0)
6154           {
6155             image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6156             break;
6157           }
6158         if (LocaleCompare("antialias",option+1) == 0)
6159           {
6160             image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6161             break;
6162           }
6163         if (LocaleCompare("attenuate",option+1) == 0)
6164           {
6165             if (*option == '+')
6166               {
6167                 (void) DeleteImageOption(image_info,option+1);
6168                 break;
6169               }
6170             (void) SetImageOption(image_info,option+1,argv[i+1]);
6171             break;
6172           }
6173         if (LocaleCompare("authenticate",option+1) == 0)
6174           {
6175             if (*option == '+')
6176               (void) CloneString(&image_info->authenticate,(char *) NULL);
6177             else
6178               (void) CloneString(&image_info->authenticate,argv[i+1]);
6179             break;
6180           }
6181         break;
6182       }
6183       case 'b':
6184       {
6185         if (LocaleCompare("background",option+1) == 0)
6186           {
6187             if (*option == '+')
6188               {
6189                 (void) DeleteImageOption(image_info,option+1);
6190                 (void) QueryColorCompliance(MogrifyBackgroundColor,
6191                   AllCompliance,&image_info->background_color,exception);
6192                 break;
6193               }
6194             (void) SetImageOption(image_info,option+1,argv[i+1]);
6195             (void) QueryColorCompliance(argv[i+1],AllCompliance,
6196               &image_info->background_color,exception);
6197             break;
6198           }
6199         if (LocaleCompare("bias",option+1) == 0)
6200           {
6201             if (*option == '+')
6202               {
6203                 (void) SetImageOption(image_info,option+1,"0.0");
6204                 break;
6205               }
6206             (void) SetImageOption(image_info,option+1,argv[i+1]);
6207             break;
6208           }
6209         if (LocaleCompare("black-point-compensation",option+1) == 0)
6210           {
6211             if (*option == '+')
6212               {
6213                 (void) SetImageOption(image_info,option+1,"false");
6214                 break;
6215               }
6216             (void) SetImageOption(image_info,option+1,"true");
6217             break;
6218           }
6219         if (LocaleCompare("blue-primary",option+1) == 0)
6220           {
6221             if (*option == '+')
6222               {
6223                 (void) SetImageOption(image_info,option+1,"0.0");
6224                 break;
6225               }
6226             (void) SetImageOption(image_info,option+1,argv[i+1]);
6227             break;
6228           }
6229         if (LocaleCompare("bordercolor",option+1) == 0)
6230           {
6231             if (*option == '+')
6232               {
6233                 (void) DeleteImageOption(image_info,option+1);
6234                 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
6235                   &image_info->border_color,exception);
6236                 break;
6237               }
6238             (void) QueryColorCompliance(argv[i+1],AllCompliance,
6239               &image_info->border_color,exception);
6240             (void) SetImageOption(image_info,option+1,argv[i+1]);
6241             break;
6242           }
6243         if (LocaleCompare("box",option+1) == 0)
6244           {
6245             if (*option == '+')
6246               {
6247                 (void) SetImageOption(image_info,"undercolor","none");
6248                 break;
6249               }
6250             (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6251             break;
6252           }
6253         break;
6254       }
6255       case 'c':
6256       {
6257         if (LocaleCompare("cache",option+1) == 0)
6258           {
6259             MagickSizeType
6260               limit;
6261
6262             limit=MagickResourceInfinity;
6263             if (LocaleCompare("unlimited",argv[i+1]) != 0)
6264               limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
6265             (void) SetMagickResourceLimit(MemoryResource,limit);
6266             (void) SetMagickResourceLimit(MapResource,2*limit);
6267             break;
6268           }
6269         if (LocaleCompare("caption",option+1) == 0)
6270           {
6271             if (*option == '+')
6272               {
6273                 (void) DeleteImageOption(image_info,option+1);
6274                 break;
6275               }
6276             (void) SetImageOption(image_info,option+1,argv[i+1]);
6277             break;
6278           }
6279         if (LocaleCompare("channel",option+1) == 0)
6280           {
6281             if (*option == '+')
6282               {
6283                 image_info->channel=DefaultChannels;
6284                 break;
6285               }
6286             image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6287             break;
6288           }
6289         if (LocaleCompare("colors",option+1) == 0)
6290           {
6291             image_info->colors=StringToUnsignedLong(argv[i+1]);
6292             break;
6293           }
6294         if (LocaleCompare("colorspace",option+1) == 0)
6295           {
6296             if (*option == '+')
6297               {
6298                 image_info->colorspace=UndefinedColorspace;
6299                 (void) SetImageOption(image_info,option+1,"undefined");
6300                 break;
6301               }
6302             image_info->colorspace=(ColorspaceType) ParseCommandOption(
6303               MagickColorspaceOptions,MagickFalse,argv[i+1]);
6304             (void) SetImageOption(image_info,option+1,argv[i+1]);
6305             break;
6306           }
6307         if (LocaleCompare("comment",option+1) == 0)
6308           {
6309             if (*option == '+')
6310               {
6311                 (void) DeleteImageOption(image_info,option+1);
6312                 break;
6313               }
6314             (void) SetImageOption(image_info,option+1,argv[i+1]);
6315             break;
6316           }
6317         if (LocaleCompare("compose",option+1) == 0)
6318           {
6319             if (*option == '+')
6320               {
6321                 (void) SetImageOption(image_info,option+1,"undefined");
6322                 break;
6323               }
6324             (void) SetImageOption(image_info,option+1,argv[i+1]);
6325             break;
6326           }
6327         if (LocaleCompare("compress",option+1) == 0)
6328           {
6329             if (*option == '+')
6330               {
6331                 image_info->compression=UndefinedCompression;
6332                 (void) SetImageOption(image_info,option+1,"undefined");
6333                 break;
6334               }
6335             image_info->compression=(CompressionType) ParseCommandOption(
6336               MagickCompressOptions,MagickFalse,argv[i+1]);
6337             (void) SetImageOption(image_info,option+1,argv[i+1]);
6338             break;
6339           }
6340         break;
6341       }
6342       case 'd':
6343       {
6344         if (LocaleCompare("debug",option+1) == 0)
6345           {
6346             if (*option == '+')
6347               (void) SetLogEventMask("none");
6348             else
6349               (void) SetLogEventMask(argv[i+1]);
6350             image_info->debug=IsEventLogging();
6351             break;
6352           }
6353         if (LocaleCompare("define",option+1) == 0)
6354           {
6355             if (*option == '+')
6356               {
6357                 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6358                   (void) DeleteImageRegistry(argv[i+1]+9);
6359                 else
6360                   (void) DeleteImageOption(image_info,argv[i+1]);
6361                 break;
6362               }
6363             if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6364               {
6365                 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6366                   exception);
6367                 break;
6368               }
6369             (void) DefineImageOption(image_info,argv[i+1]);
6370             break;
6371           }
6372         if (LocaleCompare("delay",option+1) == 0)
6373           {
6374             if (*option == '+')
6375               {
6376                 (void) SetImageOption(image_info,option+1,"0");
6377                 break;
6378               }
6379             (void) SetImageOption(image_info,option+1,argv[i+1]);
6380             break;
6381           }
6382         if (LocaleCompare("density",option+1) == 0)
6383           {
6384             /*
6385               Set image density.
6386             */
6387             if (*option == '+')
6388               {
6389                 if (image_info->density != (char *) NULL)
6390                   image_info->density=DestroyString(image_info->density);
6391                 (void) SetImageOption(image_info,option+1,"72");
6392                 break;
6393               }
6394             (void) CloneString(&image_info->density,argv[i+1]);
6395             (void) SetImageOption(image_info,option+1,argv[i+1]);
6396             break;
6397           }
6398         if (LocaleCompare("depth",option+1) == 0)
6399           {
6400             if (*option == '+')
6401               {
6402                 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6403                 break;
6404               }
6405             image_info->depth=StringToUnsignedLong(argv[i+1]);
6406             break;
6407           }
6408         if (LocaleCompare("direction",option+1) == 0)
6409           {
6410             if (*option == '+')
6411               {
6412                 (void) SetImageOption(image_info,option+1,"undefined");
6413                 break;
6414               }
6415             (void) SetImageOption(image_info,option+1,argv[i+1]);
6416             break;
6417           }
6418         if (LocaleCompare("display",option+1) == 0)
6419           {
6420             if (*option == '+')
6421               {
6422                 if (image_info->server_name != (char *) NULL)
6423                   image_info->server_name=DestroyString(
6424                     image_info->server_name);
6425                 break;
6426               }
6427             (void) CloneString(&image_info->server_name,argv[i+1]);
6428             break;
6429           }
6430         if (LocaleCompare("dispose",option+1) == 0)
6431           {
6432             if (*option == '+')
6433               {
6434                 (void) SetImageOption(image_info,option+1,"undefined");
6435                 break;
6436               }
6437             (void) SetImageOption(image_info,option+1,argv[i+1]);
6438             break;
6439           }
6440         if (LocaleCompare("dither",option+1) == 0)
6441           {
6442             if (*option == '+')
6443               {
6444                 image_info->dither=MagickFalse;
6445                 (void) SetImageOption(image_info,option+1,"none");
6446                 break;
6447               }
6448             (void) SetImageOption(image_info,option+1,argv[i+1]);
6449             image_info->dither=MagickTrue;
6450             break;
6451           }
6452         break;
6453       }
6454       case 'e':
6455       {
6456         if (LocaleCompare("encoding",option+1) == 0)
6457           {
6458             if (*option == '+')
6459               {
6460                 (void) SetImageOption(image_info,option+1,"undefined");
6461                 break;
6462               }
6463             (void) SetImageOption(image_info,option+1,argv[i+1]);
6464             break;
6465           }
6466         if (LocaleCompare("endian",option+1) == 0)
6467           {
6468             if (*option == '+')
6469               {
6470                 image_info->endian=UndefinedEndian;
6471                 (void) SetImageOption(image_info,option+1,"undefined");
6472                 break;
6473               }
6474             image_info->endian=(EndianType) ParseCommandOption(
6475               MagickEndianOptions,MagickFalse,argv[i+1]);
6476             (void) SetImageOption(image_info,option+1,argv[i+1]);
6477             break;
6478           }
6479         if (LocaleCompare("extract",option+1) == 0)
6480           {
6481             /*
6482               Set image extract geometry.
6483             */
6484             if (*option == '+')
6485               {
6486                 if (image_info->extract != (char *) NULL)
6487                   image_info->extract=DestroyString(image_info->extract);
6488                 break;
6489               }
6490             (void) CloneString(&image_info->extract,argv[i+1]);
6491             break;
6492           }
6493         break;
6494       }
6495       case 'f':
6496       {
6497         if (LocaleCompare("fill",option+1) == 0)
6498           {
6499             if (*option == '+')
6500               {
6501                 (void) SetImageOption(image_info,option+1,"none");
6502                 break;
6503               }
6504             (void) SetImageOption(image_info,option+1,argv[i+1]);
6505             break;
6506           }
6507         if (LocaleCompare("filter",option+1) == 0)
6508           {
6509             if (*option == '+')
6510               {
6511                 (void) SetImageOption(image_info,option+1,"undefined");
6512                 break;
6513               }
6514             (void) SetImageOption(image_info,option+1,argv[i+1]);
6515             break;
6516           }
6517         if (LocaleCompare("font",option+1) == 0)
6518           {
6519             if (*option == '+')
6520               {
6521                 if (image_info->font != (char *) NULL)
6522                   image_info->font=DestroyString(image_info->font);
6523                 break;
6524               }
6525             (void) CloneString(&image_info->font,argv[i+1]);
6526             break;
6527           }
6528         if (LocaleCompare("format",option+1) == 0)
6529           {
6530             register const char
6531               *q;
6532
6533             for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6534               if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
6535                 image_info->ping=MagickFalse;
6536             (void) SetImageOption(image_info,option+1,argv[i+1]);
6537             break;
6538           }
6539         if (LocaleCompare("fuzz",option+1) == 0)
6540           {
6541             if (*option == '+')
6542               {
6543                 image_info->fuzz=0.0;
6544                 (void) SetImageOption(image_info,option+1,"0");
6545                 break;
6546               }
6547             image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
6548               1.0);
6549             (void) SetImageOption(image_info,option+1,argv[i+1]);
6550             break;
6551           }
6552         break;
6553       }
6554       case 'g':
6555       {
6556         if (LocaleCompare("gravity",option+1) == 0)
6557           {
6558             if (*option == '+')
6559               {
6560                 (void) SetImageOption(image_info,option+1,"undefined");
6561                 break;
6562               }
6563             (void) SetImageOption(image_info,option+1,argv[i+1]);
6564             break;
6565           }
6566         if (LocaleCompare("green-primary",option+1) == 0)
6567           {
6568             if (*option == '+')
6569               {
6570                 (void) SetImageOption(image_info,option+1,"0.0");
6571                 break;
6572               }
6573             (void) SetImageOption(image_info,option+1,argv[i+1]);
6574             break;
6575           }
6576         break;
6577       }
6578       case 'i':
6579       {
6580         if (LocaleCompare("intent",option+1) == 0)
6581           {
6582             if (*option == '+')
6583               {
6584                 (void) SetImageOption(image_info,option+1,"undefined");
6585                 break;
6586               }
6587             (void) SetImageOption(image_info,option+1,argv[i+1]);
6588             break;
6589           }
6590         if (LocaleCompare("interlace",option+1) == 0)
6591           {
6592             if (*option == '+')
6593               {
6594                 image_info->interlace=UndefinedInterlace;
6595                 (void) SetImageOption(image_info,option+1,"undefined");
6596                 break;
6597               }
6598             image_info->interlace=(InterlaceType) ParseCommandOption(
6599               MagickInterlaceOptions,MagickFalse,argv[i+1]);
6600             (void) SetImageOption(image_info,option+1,argv[i+1]);
6601             break;
6602           }
6603         if (LocaleCompare("interline-spacing",option+1) == 0)
6604           {
6605             if (*option == '+')
6606               {
6607                 (void) SetImageOption(image_info,option+1,"undefined");
6608                 break;
6609               }
6610             (void) SetImageOption(image_info,option+1,argv[i+1]);
6611             break;
6612           }
6613         if (LocaleCompare("interpolate",option+1) == 0)
6614           {
6615             if (*option == '+')
6616               {
6617                 (void) SetImageOption(image_info,option+1,"undefined");
6618                 break;
6619               }
6620             (void) SetImageOption(image_info,option+1,argv[i+1]);
6621             break;
6622           }
6623         if (LocaleCompare("interword-spacing",option+1) == 0)
6624           {
6625             if (*option == '+')
6626               {
6627                 (void) SetImageOption(image_info,option+1,"undefined");
6628                 break;
6629               }
6630             (void) SetImageOption(image_info,option+1,argv[i+1]);
6631             break;
6632           }
6633         break;
6634       }
6635       case 'k':
6636       {
6637         if (LocaleCompare("kerning",option+1) == 0)
6638           {
6639             if (*option == '+')
6640               {
6641                 (void) SetImageOption(image_info,option+1,"undefined");
6642                 break;
6643               }
6644             (void) SetImageOption(image_info,option+1,argv[i+1]);
6645             break;
6646           }
6647         break;
6648       }
6649       case 'l':
6650       {
6651         if (LocaleCompare("label",option+1) == 0)
6652           {
6653             if (*option == '+')
6654               {
6655                 (void) DeleteImageOption(image_info,option+1);
6656                 break;
6657               }
6658             (void) SetImageOption(image_info,option+1,argv[i+1]);
6659             break;
6660           }
6661         if (LocaleCompare("limit",option+1) == 0)
6662           {
6663             MagickSizeType
6664               limit;
6665
6666             ResourceType
6667               type;
6668
6669             if (*option == '+')
6670               break;
6671             type=(ResourceType) ParseCommandOption(MagickResourceOptions,
6672               MagickFalse,argv[i+1]);
6673             limit=MagickResourceInfinity;
6674             if (LocaleCompare("unlimited",argv[i+2]) != 0)
6675               limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
6676             (void) SetMagickResourceLimit(type,limit);
6677             break;
6678           }
6679         if (LocaleCompare("list",option+1) == 0)
6680           {
6681             ssize_t
6682               list;
6683
6684             /*
6685               Display configuration list.
6686             */
6687             list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
6688             switch (list)
6689             {
6690               case MagickCoderOptions:
6691               {
6692                 (void) ListCoderInfo((FILE *) NULL,exception);
6693                 break;
6694               }
6695               case MagickColorOptions:
6696               {
6697                 (void) ListColorInfo((FILE *) NULL,exception);
6698                 break;
6699               }
6700               case MagickConfigureOptions:
6701               {
6702                 (void) ListConfigureInfo((FILE *) NULL,exception);
6703                 break;
6704               }
6705               case MagickDelegateOptions:
6706               {
6707                 (void) ListDelegateInfo((FILE *) NULL,exception);
6708                 break;
6709               }
6710               case MagickFontOptions:
6711               {
6712                 (void) ListTypeInfo((FILE *) NULL,exception);
6713                 break;
6714               }
6715               case MagickFormatOptions:
6716               {
6717                 (void) ListMagickInfo((FILE *) NULL,exception);
6718                 break;
6719               }
6720               case MagickLocaleOptions:
6721               {
6722                 (void) ListLocaleInfo((FILE *) NULL,exception);
6723                 break;
6724               }
6725               case MagickLogOptions:
6726               {
6727                 (void) ListLogInfo((FILE *) NULL,exception);
6728                 break;
6729               }
6730               case MagickMagicOptions:
6731               {
6732                 (void) ListMagicInfo((FILE *) NULL,exception);
6733                 break;
6734               }
6735               case MagickMimeOptions:
6736               {
6737                 (void) ListMimeInfo((FILE *) NULL,exception);
6738                 break;
6739               }
6740               case MagickModuleOptions:
6741               {
6742                 (void) ListModuleInfo((FILE *) NULL,exception);
6743                 break;
6744               }
6745               case MagickPolicyOptions:
6746               {
6747                 (void) ListPolicyInfo((FILE *) NULL,exception);
6748                 break;
6749               }
6750               case MagickResourceOptions:
6751               {
6752                 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6753                 break;
6754               }
6755               case MagickThresholdOptions:
6756               {
6757                 (void) ListThresholdMaps((FILE *) NULL,exception);
6758                 break;
6759               }
6760               default:
6761               {
6762                 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
6763                   exception);
6764                 break;
6765               }
6766             }
6767             break;
6768           }
6769         if (LocaleCompare("log",option+1) == 0)
6770           {
6771             if (*option == '+')
6772               break;
6773             (void) SetLogFormat(argv[i+1]);
6774             break;
6775           }
6776         if (LocaleCompare("loop",option+1) == 0)
6777           {
6778             if (*option == '+')
6779               {
6780                 (void) SetImageOption(image_info,option+1,"0");
6781                 break;
6782               }
6783             (void) SetImageOption(image_info,option+1,argv[i+1]);
6784             break;
6785           }
6786         break;
6787       }
6788       case 'm':
6789       {
6790         if (LocaleCompare("matte",option+1) == 0)
6791           {
6792             if (*option == '+')
6793               {
6794                 (void) SetImageOption(image_info,option+1,"false");
6795                 break;
6796               }
6797             (void) SetImageOption(image_info,option+1,"true");
6798             break;
6799           }
6800         if (LocaleCompare("mattecolor",option+1) == 0)
6801           {
6802             if (*option == '+')
6803               {
6804                 (void) SetImageOption(image_info,option+1,argv[i+1]);
6805                 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
6806                   &image_info->matte_color,exception);
6807                 break;
6808               }
6809             (void) SetImageOption(image_info,option+1,argv[i+1]);
6810             (void) QueryColorCompliance(argv[i+1],AllCompliance,
6811               &image_info->matte_color,exception);
6812             break;
6813           }
6814         if (LocaleCompare("monitor",option+1) == 0)
6815           {
6816             (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6817               (void *) NULL);
6818             break;
6819           }
6820         if (LocaleCompare("monochrome",option+1) == 0)
6821           {
6822             image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6823             break;
6824           }
6825         break;
6826       }
6827       case 'o':
6828       {
6829         if (LocaleCompare("orient",option+1) == 0)
6830           {
6831             if (*option == '+')
6832               {
6833                 image_info->orientation=UndefinedOrientation;
6834                 (void) SetImageOption(image_info,option+1,"undefined");
6835                 break;
6836               }
6837             image_info->orientation=(OrientationType) ParseCommandOption(
6838               MagickOrientationOptions,MagickFalse,argv[i+1]);
6839             (void) SetImageOption(image_info,option+1,argv[i+1]);
6840             break;
6841           }
6842       }
6843       case 'p':
6844       {
6845         if (LocaleCompare("page",option+1) == 0)
6846           {
6847             char
6848               *canonical_page,
6849               page[MaxTextExtent];
6850
6851             const char
6852               *image_option;
6853
6854             MagickStatusType
6855               flags;
6856
6857             RectangleInfo
6858               geometry;
6859
6860             if (*option == '+')
6861               {
6862                 (void) DeleteImageOption(image_info,option+1);
6863                 (void) CloneString(&image_info->page,(char *) NULL);
6864                 break;
6865               }
6866             (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6867             image_option=GetImageOption(image_info,"page");
6868             if (image_option != (const char *) NULL)
6869               flags=ParseAbsoluteGeometry(image_option,&geometry);
6870             canonical_page=GetPageGeometry(argv[i+1]);
6871             flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6872             canonical_page=DestroyString(canonical_page);
6873             (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
6874               (unsigned long) geometry.width,(unsigned long) geometry.height);
6875             if (((flags & XValue) != 0) || ((flags & YValue) != 0))
6876               (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
6877                 (unsigned long) geometry.width,(unsigned long) geometry.height,
6878                 (long) geometry.x,(long) geometry.y);
6879             (void) SetImageOption(image_info,option+1,page);
6880             (void) CloneString(&image_info->page,page);
6881             break;
6882           }
6883         if (LocaleCompare("pen",option+1) == 0)
6884           {
6885             if (*option == '+')
6886               {
6887                 (void) SetImageOption(image_info,option+1,"none");
6888                 break;
6889               }
6890             (void) SetImageOption(image_info,option+1,argv[i+1]);
6891             break;
6892           }
6893         if (LocaleCompare("ping",option+1) == 0)
6894           {
6895             image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6896             break;
6897           }
6898         if (LocaleCompare("pointsize",option+1) == 0)
6899           {
6900             if (*option == '+')
6901               geometry_info.rho=0.0;
6902             else
6903               (void) ParseGeometry(argv[i+1],&geometry_info);
6904             image_info->pointsize=geometry_info.rho;
6905             break;
6906           }
6907         if (LocaleCompare("precision",option+1) == 0)
6908           {
6909             (void) SetMagickPrecision(StringToInteger(argv[i+1]));
6910             break;
6911           }
6912         if (LocaleCompare("preview",option+1) == 0)
6913           {
6914             /*
6915               Preview image.
6916             */
6917             if (*option == '+')
6918               {
6919                 image_info->preview_type=UndefinedPreview;
6920                 break;
6921               }
6922             image_info->preview_type=(PreviewType) ParseCommandOption(
6923               MagickPreviewOptions,MagickFalse,argv[i+1]);
6924             break;
6925           }
6926         break;
6927       }
6928       case 'q':
6929       {
6930         if (LocaleCompare("quality",option+1) == 0)
6931           {
6932             /*
6933               Set image compression quality.
6934             */
6935             if (*option == '+')
6936               {
6937                 image_info->quality=UndefinedCompressionQuality;
6938                 (void) SetImageOption(image_info,option+1,"0");
6939                 break;
6940               }
6941             image_info->quality=StringToUnsignedLong(argv[i+1]);
6942             (void) SetImageOption(image_info,option+1,argv[i+1]);
6943             break;
6944           }
6945         if (LocaleCompare("quiet",option+1) == 0)
6946           {
6947             static WarningHandler
6948               warning_handler = (WarningHandler) NULL;
6949
6950             if (*option == '+')
6951               {
6952                 /*
6953                   Restore error or warning messages.
6954                 */
6955                 warning_handler=SetWarningHandler(warning_handler);
6956                 break;
6957               }
6958             /*
6959               Suppress error or warning messages.
6960             */
6961             warning_handler=SetWarningHandler((WarningHandler) NULL);
6962             break;
6963           }
6964         break;
6965       }
6966       case 'r':
6967       {
6968         if (LocaleCompare("red-primary",option+1) == 0)
6969           {
6970             if (*option == '+')
6971               {
6972                 (void) SetImageOption(image_info,option+1,"0.0");
6973                 break;
6974               }
6975             (void) SetImageOption(image_info,option+1,argv[i+1]);
6976             break;
6977           }
6978         break;
6979       }
6980       case 's':
6981       {
6982         if (LocaleCompare("sampling-factor",option+1) == 0)
6983           {
6984             /*
6985               Set image sampling factor.
6986             */
6987             if (*option == '+')
6988               {
6989                 if (image_info->sampling_factor != (char *) NULL)
6990                   image_info->sampling_factor=DestroyString(
6991                     image_info->sampling_factor);
6992                 break;
6993               }
6994             (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6995             break;
6996           }
6997         if (LocaleCompare("scene",option+1) == 0)
6998           {
6999             /*
7000               Set image scene.
7001             */
7002             if (*option == '+')
7003               {
7004                 image_info->scene=0;
7005                 (void) SetImageOption(image_info,option+1,"0");
7006                 break;
7007               }
7008             image_info->scene=StringToUnsignedLong(argv[i+1]);
7009             (void) SetImageOption(image_info,option+1,argv[i+1]);
7010             break;
7011           }
7012         if (LocaleCompare("seed",option+1) == 0)
7013           {
7014             size_t
7015               seed;
7016
7017             if (*option == '+')
7018               {
7019                 seed=(size_t) time((time_t *) NULL);
7020                 SeedPseudoRandomGenerator(seed);
7021                 break;
7022               }
7023             seed=StringToUnsignedLong(argv[i+1]);
7024             SeedPseudoRandomGenerator(seed);
7025             break;
7026           }
7027         if (LocaleCompare("size",option+1) == 0)
7028           {
7029             if (*option == '+')
7030               {
7031                 if (image_info->size != (char *) NULL)
7032                   image_info->size=DestroyString(image_info->size);
7033                 break;
7034               }
7035             (void) CloneString(&image_info->size,argv[i+1]);
7036             break;
7037           }
7038         if (LocaleCompare("stroke",option+1) == 0)
7039           {
7040             if (*option == '+')
7041               {
7042                 (void) SetImageOption(image_info,option+1,"none");
7043                 break;
7044               }
7045             (void) SetImageOption(image_info,option+1,argv[i+1]);
7046             break;
7047           }
7048         if (LocaleCompare("strokewidth",option+1) == 0)
7049           {
7050             if (*option == '+')
7051               {
7052                 (void) SetImageOption(image_info,option+1,"0");
7053                 break;
7054               }
7055             (void) SetImageOption(image_info,option+1,argv[i+1]);
7056             break;
7057           }
7058         if (LocaleCompare("synchronize",option+1) == 0)
7059           {
7060             if (*option == '+')
7061               {
7062                 image_info->synchronize=MagickFalse;
7063                 break;
7064               }
7065             image_info->synchronize=MagickTrue;
7066             break;
7067           }
7068         break;
7069       }
7070       case 't':
7071       {
7072         if (LocaleCompare("taint",option+1) == 0)
7073           {
7074             if (*option == '+')
7075               {
7076                 (void) SetImageOption(image_info,option+1,"false");
7077                 break;
7078               }
7079             (void) SetImageOption(image_info,option+1,"true");
7080             break;
7081           }
7082         if (LocaleCompare("texture",option+1) == 0)
7083           {
7084             if (*option == '+')
7085               {
7086                 if (image_info->texture != (char *) NULL)
7087                   image_info->texture=DestroyString(image_info->texture);
7088                 break;
7089               }
7090             (void) CloneString(&image_info->texture,argv[i+1]);
7091             break;
7092           }
7093         if (LocaleCompare("tile-offset",option+1) == 0)
7094           {
7095             if (*option == '+')
7096               {
7097                 (void) SetImageOption(image_info,option+1,"0");
7098                 break;
7099               }
7100             (void) SetImageOption(image_info,option+1,argv[i+1]);
7101             break;
7102           }
7103         if (LocaleCompare("transparent-color",option+1) == 0)
7104           {
7105             if (*option == '+')
7106               {
7107                 (void) QueryColorCompliance("none",AllCompliance,
7108                   &image_info->transparent_color,exception);
7109                 (void) SetImageOption(image_info,option+1,"none");
7110                 break;
7111               }
7112             (void) QueryColorCompliance(argv[i+1],AllCompliance,
7113               &image_info->transparent_color,exception);
7114             (void) SetImageOption(image_info,option+1,argv[i+1]);
7115             break;
7116           }
7117         if (LocaleCompare("type",option+1) == 0)
7118           {
7119             if (*option == '+')
7120               {
7121                 image_info->type=UndefinedType;
7122                 (void) SetImageOption(image_info,option+1,"undefined");
7123                 break;
7124               }
7125             image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
7126               MagickFalse,argv[i+1]);
7127             (void) SetImageOption(image_info,option+1,argv[i+1]);
7128             break;
7129           }
7130         break;
7131       }
7132       case 'u':
7133       {
7134         if (LocaleCompare("undercolor",option+1) == 0)
7135           {
7136             if (*option == '+')
7137               {
7138                 (void) DeleteImageOption(image_info,option+1);
7139                 break;
7140               }
7141             (void) SetImageOption(image_info,option+1,argv[i+1]);
7142             break;
7143           }
7144         if (LocaleCompare("units",option+1) == 0)
7145           {
7146             if (*option == '+')
7147               {
7148                 image_info->units=UndefinedResolution;
7149                 (void) SetImageOption(image_info,option+1,"undefined");
7150                 break;
7151               }
7152             image_info->units=(ResolutionType) ParseCommandOption(
7153               MagickResolutionOptions,MagickFalse,argv[i+1]);
7154             (void) SetImageOption(image_info,option+1,argv[i+1]);
7155             break;
7156           }
7157         break;
7158       }
7159       case 'v':
7160       {
7161         if (LocaleCompare("verbose",option+1) == 0)
7162           {
7163             if (*option == '+')
7164               {
7165                 image_info->verbose=MagickFalse;
7166                 break;
7167               }
7168             image_info->verbose=MagickTrue;
7169             image_info->ping=MagickFalse;
7170             break;
7171           }
7172         if (LocaleCompare("view",option+1) == 0)
7173           {
7174             if (*option == '+')
7175               {
7176                 if (image_info->view != (char *) NULL)
7177                   image_info->view=DestroyString(image_info->view);
7178                 break;
7179               }
7180             (void) CloneString(&image_info->view,argv[i+1]);
7181             break;
7182           }
7183         if (LocaleCompare("virtual-pixel",option+1) == 0)
7184           {
7185             if (*option == '+')
7186               {
7187                 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7188                 (void) SetImageOption(image_info,option+1,"undefined");
7189                 break;
7190               }
7191             image_info->virtual_pixel_method=(VirtualPixelMethod)
7192               ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
7193               argv[i+1]);
7194             (void) SetImageOption(image_info,option+1,argv[i+1]);
7195             break;
7196           }
7197         break;
7198       }
7199       case 'w':
7200       {
7201         if (LocaleCompare("white-point",option+1) == 0)
7202           {
7203             if (*option == '+')
7204               {
7205                 (void) SetImageOption(image_info,option+1,"0.0");
7206                 break;
7207               }
7208             (void) SetImageOption(image_info,option+1,argv[i+1]);
7209             break;
7210           }
7211         break;
7212       }
7213       default:
7214         break;
7215     }
7216     i+=count;
7217   }
7218   return(MagickTrue);
7219 }
7220 \f
7221 /*
7222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7223 %                                                                             %
7224 %                                                                             %
7225 %                                                                             %
7226 +     M o g r i f y I m a g e L i s t                                         %
7227 %                                                                             %
7228 %                                                                             %
7229 %                                                                             %
7230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7231 %
7232 %  MogrifyImageList() applies any command line options that might affect the
7233 %  entire image list (e.g. -append, -coalesce, etc.).
7234 %
7235 %  The format of the MogrifyImage method is:
7236 %
7237 %      MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7238 %        const char **argv,Image **images,ExceptionInfo *exception)
7239 %
7240 %  A description of each parameter follows:
7241 %
7242 %    o image_info: the image info..
7243 %
7244 %    o argc: Specifies a pointer to an integer describing the number of
7245 %      elements in the argument vector.
7246 %
7247 %    o argv: Specifies a pointer to a text array containing the command line
7248 %      arguments.
7249 %
7250 %    o images: pointer to pointer of the first image in image list.
7251 %
7252 %    o exception: return any errors or warnings in this structure.
7253 %
7254 */
7255 WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7256   const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7257 {
7258   const char
7259     *option;
7260
7261   ImageInfo
7262     *mogrify_info;
7263
7264   MagickStatusType
7265     status;
7266
7267   PixelInterpolateMethod
7268    interpolate_method;
7269
7270   QuantizeInfo
7271     *quantize_info;
7272
7273   register ssize_t
7274     i;
7275
7276   ssize_t
7277     count,
7278     index;
7279
7280   /*
7281     Apply options to the image list.
7282   */
7283   assert(image_info != (ImageInfo *) NULL);
7284   assert(image_info->signature == MagickSignature);
7285   assert(images != (Image **) NULL);
7286   assert((*images)->previous == (Image *) NULL);
7287   assert((*images)->signature == MagickSignature);
7288   if ((*images)->debug != MagickFalse)
7289     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7290       (*images)->filename);
7291   if ((argc <= 0) || (*argv == (char *) NULL))
7292     return(MagickTrue);
7293   interpolate_method=UndefinedInterpolatePixel;
7294   mogrify_info=CloneImageInfo(image_info);
7295   quantize_info=AcquireQuantizeInfo(mogrify_info);
7296   status=MagickTrue;
7297   for (i=0; i < (ssize_t) argc; i++)
7298   {
7299     if (*images == (Image *) NULL)
7300       break;
7301     option=argv[i];
7302     if (IsCommandOption(option) == MagickFalse)
7303       continue;
7304     count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
7305     count=MagickMax(count,0L);
7306     if ((i+count) >= (ssize_t) argc)
7307       break;
7308     status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
7309     switch (*(option+1))
7310     {
7311       case 'a':
7312       {
7313         if (LocaleCompare("affinity",option+1) == 0)
7314           {
7315             (void) SyncImagesSettings(mogrify_info,*images);
7316             if (*option == '+')
7317               {
7318                 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7319                   exception);
7320                 break;
7321               }
7322             i++;
7323             break;
7324           }
7325         if (LocaleCompare("append",option+1) == 0)
7326           {
7327             Image
7328               *append_image;
7329
7330             (void) SyncImagesSettings(mogrify_info,*images);
7331             append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7332               MagickFalse,exception);
7333             if (append_image == (Image *) NULL)
7334               {
7335                 status=MagickFalse;
7336                 break;
7337               }
7338             *images=DestroyImageList(*images);
7339             *images=append_image;
7340             break;
7341           }
7342         if (LocaleCompare("average",option+1) == 0)
7343           {
7344             Image
7345               *average_image;
7346
7347             /*
7348               Average an image sequence (deprecated).
7349             */
7350             (void) SyncImagesSettings(mogrify_info,*images);
7351             average_image=EvaluateImages(*images,MeanEvaluateOperator,
7352               exception);
7353             if (average_image == (Image *) NULL)
7354               {
7355                 status=MagickFalse;
7356                 break;
7357               }
7358             *images=DestroyImageList(*images);
7359             *images=average_image;
7360             break;
7361           }
7362         break;
7363       }
7364       case 'c':
7365       {
7366         if (LocaleCompare("channel",option+1) == 0)
7367           {
7368             ChannelType
7369               channel;
7370
7371             if (*option == '+')
7372               {
7373                 channel=DefaultChannels;
7374                 break;
7375               }
7376             channel=(ChannelType) ParseChannelOption(argv[i+1]);
7377             SetPixelChannelMap(*images,channel);
7378             break;
7379           }
7380         if (LocaleCompare("clut",option+1) == 0)
7381           {
7382             Image
7383               *clut_image,
7384               *image;
7385
7386             (void) SyncImagesSettings(mogrify_info,*images);
7387             image=RemoveFirstImageFromList(images);
7388             clut_image=RemoveFirstImageFromList(images);
7389             if (clut_image == (Image *) NULL)
7390               {
7391                 status=MagickFalse;
7392                 break;
7393               }
7394             (void) ClutImage(image,clut_image,interpolate_method,exception);
7395             clut_image=DestroyImage(clut_image);
7396             *images=DestroyImageList(*images);
7397             *images=image;
7398             break;
7399           }
7400         if (LocaleCompare("coalesce",option+1) == 0)
7401           {
7402             Image
7403               *coalesce_image;
7404
7405             (void) SyncImagesSettings(mogrify_info,*images);
7406             coalesce_image=CoalesceImages(*images,exception);
7407             if (coalesce_image == (Image *) NULL)
7408               {
7409                 status=MagickFalse;
7410                 break;
7411               }
7412             *images=DestroyImageList(*images);
7413             *images=coalesce_image;
7414             break;
7415           }
7416         if (LocaleCompare("combine",option+1) == 0)
7417           {
7418             Image
7419               *combine_image;
7420
7421             (void) SyncImagesSettings(mogrify_info,*images);
7422             combine_image=CombineImages(*images,exception);
7423             if (combine_image == (Image *) NULL)
7424               {
7425                 status=MagickFalse;
7426                 break;
7427               }
7428             *images=DestroyImageList(*images);
7429             *images=combine_image;
7430             break;
7431           }
7432         if (LocaleCompare("composite",option+1) == 0)
7433           {
7434             Image
7435               *mask_image,
7436               *composite_image,
7437               *image;
7438
7439             RectangleInfo
7440               geometry;
7441
7442             (void) SyncImagesSettings(mogrify_info,*images);
7443             image=RemoveFirstImageFromList(images);
7444             composite_image=RemoveFirstImageFromList(images);
7445             if (composite_image == (Image *) NULL)
7446               {
7447                 status=MagickFalse;
7448                 break;
7449               }
7450             (void) TransformImage(&composite_image,(char *) NULL,
7451               composite_image->geometry);
7452             SetGeometry(composite_image,&geometry);
7453             (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7454             GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7455               &geometry);
7456             mask_image=RemoveFirstImageFromList(images);
7457             if (mask_image != (Image *) NULL)
7458               {
7459                 if ((image->compose == DisplaceCompositeOp) ||
7460                     (image->compose == DistortCompositeOp))
7461                   {
7462                     /*
7463                       Merge Y displacement into X displacement image.
7464                     */
7465                     (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7466                       mask_image,0,0);
7467                     mask_image=DestroyImage(mask_image);
7468                   }
7469                 else
7470                   {
7471                     /*
7472                       Set a blending mask for the composition.
7473                       Posible error, what if image->mask already set.
7474                     */
7475                     image->mask=mask_image;
7476                     (void) NegateImage(image->mask,MagickFalse,exception);
7477                   }
7478               }
7479             (void) CompositeImage(image,image->compose,composite_image,
7480               geometry.x,geometry.y);
7481             if (mask_image != (Image *) NULL)
7482               mask_image=image->mask=DestroyImage(image->mask);
7483             composite_image=DestroyImage(composite_image);
7484             InheritException(exception,&image->exception);
7485             *images=DestroyImageList(*images);
7486             *images=image;
7487             break;
7488           }
7489         break;
7490       }
7491       case 'd':
7492       {
7493         if (LocaleCompare("deconstruct",option+1) == 0)
7494           {
7495             Image
7496               *deconstruct_image;
7497
7498             (void) SyncImagesSettings(mogrify_info,*images);
7499             deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
7500               exception);
7501             if (deconstruct_image == (Image *) NULL)
7502               {
7503                 status=MagickFalse;
7504                 break;
7505               }
7506             *images=DestroyImageList(*images);
7507             *images=deconstruct_image;
7508             break;
7509           }
7510         if (LocaleCompare("delete",option+1) == 0)
7511           {
7512             if (*option == '+')
7513               DeleteImages(images,"-1",exception);
7514             else
7515               DeleteImages(images,argv[i+1],exception);
7516             break;
7517           }
7518         if (LocaleCompare("dither",option+1) == 0)
7519           {
7520             if (*option == '+')
7521               {
7522                 quantize_info->dither=MagickFalse;
7523                 break;
7524               }
7525             quantize_info->dither=MagickTrue;
7526             quantize_info->dither_method=(DitherMethod) ParseCommandOption(
7527               MagickDitherOptions,MagickFalse,argv[i+1]);
7528             break;
7529           }
7530         if (LocaleCompare("duplicate",option+1) == 0)
7531           {
7532             Image
7533               *duplicate_images;
7534
7535             if (*option == '+')
7536               duplicate_images=DuplicateImages(*images,1,"-1",exception);
7537             else
7538               {
7539                 const char
7540                   *p;
7541
7542                 size_t
7543                   number_duplicates;
7544
7545                 number_duplicates=(size_t) StringToLong(argv[i+1]);
7546                 p=strchr(argv[i+1],',');
7547                 if (p == (const char *) NULL)
7548                   duplicate_images=DuplicateImages(*images,number_duplicates,
7549                     "-1",exception);
7550                 else
7551                   duplicate_images=DuplicateImages(*images,number_duplicates,p,
7552                     exception);
7553               }
7554             AppendImageToList(images, duplicate_images);
7555             (void) SyncImagesSettings(mogrify_info,*images);
7556             break;
7557           }
7558         break;
7559       }
7560       case 'e':
7561       {
7562         if (LocaleCompare("evaluate-sequence",option+1) == 0)
7563           {
7564             Image
7565               *evaluate_image;
7566
7567             MagickEvaluateOperator
7568               op;
7569
7570             (void) SyncImageSettings(mogrify_info,*images);
7571             op=(MagickEvaluateOperator) ParseCommandOption(
7572               MagickEvaluateOptions,MagickFalse,argv[i+1]);
7573             evaluate_image=EvaluateImages(*images,op,exception);
7574             if (evaluate_image == (Image *) NULL)
7575               {
7576                 status=MagickFalse;
7577                 break;
7578               }
7579             *images=DestroyImageList(*images);
7580             *images=evaluate_image;
7581             break;
7582           }
7583         break;
7584       }
7585       case 'f':
7586       {
7587         if (LocaleCompare("fft",option+1) == 0)
7588           {
7589             Image
7590               *fourier_image;
7591
7592             /*
7593               Implements the discrete Fourier transform (DFT).
7594             */
7595             (void) SyncImageSettings(mogrify_info,*images);
7596             fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7597               MagickTrue : MagickFalse,exception);
7598             if (fourier_image == (Image *) NULL)
7599               break;
7600             *images=DestroyImage(*images);
7601             *images=fourier_image;
7602             break;
7603           }
7604         if (LocaleCompare("flatten",option+1) == 0)
7605           {
7606             Image
7607               *flatten_image;
7608
7609             (void) SyncImagesSettings(mogrify_info,*images);
7610             flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7611             if (flatten_image == (Image *) NULL)
7612               break;
7613             *images=DestroyImageList(*images);
7614             *images=flatten_image;
7615             break;
7616           }
7617         if (LocaleCompare("fx",option+1) == 0)
7618           {
7619             Image
7620               *fx_image;
7621
7622             (void) SyncImagesSettings(mogrify_info,*images);
7623             fx_image=FxImage(*images,argv[i+1],exception);
7624             if (fx_image == (Image *) NULL)
7625               {
7626                 status=MagickFalse;
7627                 break;
7628               }
7629             *images=DestroyImageList(*images);
7630             *images=fx_image;
7631             break;
7632           }
7633         break;
7634       }
7635       case 'h':
7636       {
7637         if (LocaleCompare("hald-clut",option+1) == 0)
7638           {
7639             Image
7640               *hald_image,
7641               *image;
7642
7643             (void) SyncImagesSettings(mogrify_info,*images);
7644             image=RemoveFirstImageFromList(images);
7645             hald_image=RemoveFirstImageFromList(images);
7646             if (hald_image == (Image *) NULL)
7647               {
7648                 status=MagickFalse;
7649                 break;
7650               }
7651             (void) HaldClutImage(image,hald_image,exception);
7652             hald_image=DestroyImage(hald_image);
7653             if (*images != (Image *) NULL)
7654               *images=DestroyImageList(*images);
7655             *images=image;
7656             break;
7657           }
7658         break;
7659       }
7660       case 'i':
7661       {
7662         if (LocaleCompare("ift",option+1) == 0)
7663           {
7664             Image
7665               *fourier_image,
7666               *magnitude_image,
7667               *phase_image;
7668
7669             /*
7670               Implements the inverse fourier discrete Fourier transform (DFT).
7671             */
7672             (void) SyncImagesSettings(mogrify_info,*images);
7673             magnitude_image=RemoveFirstImageFromList(images);
7674             phase_image=RemoveFirstImageFromList(images);
7675             if (phase_image == (Image *) NULL)
7676               {
7677                 status=MagickFalse;
7678                 break;
7679               }
7680             fourier_image=InverseFourierTransformImage(magnitude_image,
7681               phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
7682             if (fourier_image == (Image *) NULL)
7683               break;
7684             if (*images != (Image *) NULL)
7685               *images=DestroyImage(*images);
7686             *images=fourier_image;
7687             break;
7688           }
7689         if (LocaleCompare("insert",option+1) == 0)
7690           {
7691             Image
7692               *p,
7693               *q;
7694
7695             index=0;
7696             if (*option != '+')
7697               index=(ssize_t) StringToLong(argv[i+1]);
7698             p=RemoveLastImageFromList(images);
7699             if (p == (Image *) NULL)
7700               {
7701                 (void) ThrowMagickException(exception,GetMagickModule(),
7702                   OptionError,"NoSuchImage","`%s'",argv[i+1]);
7703                 status=MagickFalse;
7704                 break;
7705               }
7706             q=p;
7707             if (index == 0)
7708               PrependImageToList(images,q);
7709             else
7710               if (index == (ssize_t) GetImageListLength(*images))
7711                 AppendImageToList(images,q);
7712               else
7713                 {
7714                    q=GetImageFromList(*images,index-1);
7715                    if (q == (Image *) NULL)
7716                      {
7717                        (void) ThrowMagickException(exception,GetMagickModule(),
7718                          OptionError,"NoSuchImage","`%s'",argv[i+1]);
7719                        status=MagickFalse;
7720                        break;
7721                      }
7722                   InsertImageInList(&q,p);
7723                 }
7724             *images=GetFirstImageInList(q);
7725             break;
7726           }
7727         if (LocaleCompare("interpolate",option+1) == 0)
7728           {
7729             interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7730               MagickInterpolateOptions,MagickFalse,argv[i+1]);
7731             break;
7732           }
7733         break;
7734       }
7735       case 'l':
7736       {
7737         if (LocaleCompare("layers",option+1) == 0)
7738           {
7739             Image
7740               *layers;
7741
7742             ImageLayerMethod
7743               method;
7744
7745             (void) SyncImagesSettings(mogrify_info,*images);
7746             layers=(Image *) NULL;
7747             method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
7748               MagickFalse,argv[i+1]);
7749             switch (method)
7750             {
7751               case CoalesceLayer:
7752               {
7753                 layers=CoalesceImages(*images,exception);
7754                 break;
7755               }
7756               case CompareAnyLayer:
7757               case CompareClearLayer:
7758               case CompareOverlayLayer:
7759               default:
7760               {
7761                 layers=CompareImagesLayers(*images,method,exception);
7762                 break;
7763               }
7764               case MergeLayer:
7765               case FlattenLayer:
7766               case MosaicLayer:
7767               case TrimBoundsLayer:
7768               {
7769                 layers=MergeImageLayers(*images,method,exception);
7770                 break;
7771               }
7772               case DisposeLayer:
7773               {
7774                 layers=DisposeImages(*images,exception);
7775                 break;
7776               }
7777               case OptimizeImageLayer:
7778               {
7779                 layers=OptimizeImageLayers(*images,exception);
7780                 break;
7781               }
7782               case OptimizePlusLayer:
7783               {
7784                 layers=OptimizePlusImageLayers(*images,exception);
7785                 break;
7786               }
7787               case OptimizeTransLayer:
7788               {
7789                 OptimizeImageTransparency(*images,exception);
7790                 break;
7791               }
7792               case RemoveDupsLayer:
7793               {
7794                 RemoveDuplicateLayers(images,exception);
7795                 break;
7796               }
7797               case RemoveZeroLayer:
7798               {
7799                 RemoveZeroDelayLayers(images,exception);
7800                 break;
7801               }
7802               case OptimizeLayer:
7803               {
7804                 /*
7805                   General Purpose, GIF Animation Optimizer.
7806                 */
7807                 layers=CoalesceImages(*images,exception);
7808                 if (layers == (Image *) NULL)
7809                   {
7810                     status=MagickFalse;
7811                     break;
7812                   }
7813                 *images=DestroyImageList(*images);
7814                 *images=layers;
7815                 layers=OptimizeImageLayers(*images,exception);
7816                 if (layers == (Image *) NULL)
7817                   {
7818                     status=MagickFalse;
7819                     break;
7820                   }
7821                 *images=DestroyImageList(*images);
7822                 *images=layers;
7823                 layers=(Image *) NULL;
7824                 OptimizeImageTransparency(*images,exception);
7825                 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7826                   exception);
7827                 break;
7828               }
7829               case CompositeLayer:
7830               {
7831                 CompositeOperator
7832                   compose;
7833
7834                 Image
7835                   *source;
7836
7837                 RectangleInfo
7838                   geometry;
7839
7840                 /*
7841                   Split image sequence at the first 'NULL:' image.
7842                 */
7843                 source=(*images);
7844                 while (source != (Image *) NULL)
7845                 {
7846                   source=GetNextImageInList(source);
7847                   if ((source != (Image *) NULL) &&
7848                       (LocaleCompare(source->magick,"NULL") == 0))
7849                     break;
7850                 }
7851                 if (source != (Image *) NULL)
7852                   {
7853                     if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7854                         (GetNextImageInList(source) == (Image *) NULL))
7855                       source=(Image *) NULL;
7856                     else
7857                       {
7858                         /*
7859                           Separate the two lists, junk the null: image.
7860                         */
7861                         source=SplitImageList(source->previous);
7862                         DeleteImageFromList(&source);
7863                       }
7864                   }
7865                 if (source == (Image *) NULL)
7866                   {
7867                     (void) ThrowMagickException(exception,GetMagickModule(),
7868                       OptionError,"MissingNullSeparator","layers Composite");
7869                     status=MagickFalse;
7870                     break;
7871                   }
7872                 /*
7873                   Adjust offset with gravity and virtual canvas.
7874                 */
7875                 SetGeometry(*images,&geometry);
7876                 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7877                 geometry.width=source->page.width != 0 ?
7878                   source->page.width : source->columns;
7879                 geometry.height=source->page.height != 0 ?
7880                  source->page.height : source->rows;
7881                 GravityAdjustGeometry((*images)->page.width != 0 ?
7882                   (*images)->page.width : (*images)->columns,
7883                   (*images)->page.height != 0 ? (*images)->page.height :
7884                   (*images)->rows,(*images)->gravity,&geometry);
7885                 compose=OverCompositeOp;
7886                 option=GetImageOption(mogrify_info,"compose");
7887                 if (option != (const char *) NULL)
7888                   compose=(CompositeOperator) ParseCommandOption(
7889                     MagickComposeOptions,MagickFalse,option);
7890                 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7891                   exception);
7892                 source=DestroyImageList(source);
7893                 break;
7894               }
7895             }
7896             if (layers == (Image *) NULL)
7897               break;
7898             InheritException(exception,&layers->exception);
7899             *images=DestroyImageList(*images);
7900             *images=layers;
7901             break;
7902           }
7903         break;
7904       }
7905       case 'm':
7906       {
7907         if (LocaleCompare("map",option+1) == 0)
7908           {
7909             (void) SyncImagesSettings(mogrify_info,*images);
7910             if (*option == '+')
7911               {
7912                 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7913                   exception);
7914                 break;
7915               }
7916             i++;
7917             break;
7918           }
7919         if (LocaleCompare("maximum",option+1) == 0)
7920           {
7921             Image
7922               *maximum_image;
7923
7924             /*
7925               Maximum image sequence (deprecated).
7926             */
7927             (void) SyncImagesSettings(mogrify_info,*images);
7928             maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
7929             if (maximum_image == (Image *) NULL)
7930               {
7931                 status=MagickFalse;
7932                 break;
7933               }
7934             *images=DestroyImageList(*images);
7935             *images=maximum_image;
7936             break;
7937           }
7938         if (LocaleCompare("minimum",option+1) == 0)
7939           {
7940             Image
7941               *minimum_image;
7942
7943             /*
7944               Minimum image sequence (deprecated).
7945             */
7946             (void) SyncImagesSettings(mogrify_info,*images);
7947             minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
7948             if (minimum_image == (Image *) NULL)
7949               {
7950                 status=MagickFalse;
7951                 break;
7952               }
7953             *images=DestroyImageList(*images);
7954             *images=minimum_image;
7955             break;
7956           }
7957         if (LocaleCompare("morph",option+1) == 0)
7958           {
7959             Image
7960               *morph_image;
7961
7962             (void) SyncImagesSettings(mogrify_info,*images);
7963             morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
7964               exception);
7965             if (morph_image == (Image *) NULL)
7966               {
7967                 status=MagickFalse;
7968                 break;
7969               }
7970             *images=DestroyImageList(*images);
7971             *images=morph_image;
7972             break;
7973           }
7974         if (LocaleCompare("mosaic",option+1) == 0)
7975           {
7976             Image
7977               *mosaic_image;
7978
7979             (void) SyncImagesSettings(mogrify_info,*images);
7980             mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7981             if (mosaic_image == (Image *) NULL)
7982               {
7983                 status=MagickFalse;
7984                 break;
7985               }
7986             *images=DestroyImageList(*images);
7987             *images=mosaic_image;
7988             break;
7989           }
7990         break;
7991       }
7992       case 'p':
7993       {
7994         if (LocaleCompare("print",option+1) == 0)
7995           {
7996             char
7997               *string;
7998
7999             (void) SyncImagesSettings(mogrify_info,*images);
8000             string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
8001               exception);
8002             if (string == (char *) NULL)
8003               break;
8004             (void) FormatLocaleFile(stdout,"%s",string);
8005             string=DestroyString(string);
8006           }
8007         if (LocaleCompare("process",option+1) == 0)
8008           {
8009             char
8010               **arguments;
8011
8012             int
8013               j,
8014               number_arguments;
8015
8016             (void) SyncImagesSettings(mogrify_info,*images);
8017             arguments=StringToArgv(argv[i+1],&number_arguments);
8018             if (arguments == (char **) NULL)
8019               break;
8020             if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8021               {
8022                 char
8023                   breaker,
8024                   quote,
8025                   *token;
8026
8027                 const char
8028                   *arguments;
8029
8030                 int
8031                   next,
8032                   status;
8033
8034                 size_t
8035                   length;
8036
8037                 TokenInfo
8038                   *token_info;
8039
8040                 /*
8041                   Support old style syntax, filter="-option arg".
8042                 */
8043                 length=strlen(argv[i+1]);
8044                 token=(char *) NULL;
8045                 if (~length >= (MaxTextExtent-1))
8046                   token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8047                     sizeof(*token));
8048                 if (token == (char *) NULL)
8049                   break;
8050                 next=0;
8051                 arguments=argv[i+1];
8052                 token_info=AcquireTokenInfo();
8053                 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8054                   "\"",'\0',&breaker,&next,&quote);
8055                 token_info=DestroyTokenInfo(token_info);
8056                 if (status == 0)
8057                   {
8058                     const char
8059                       *argv;
8060
8061                     argv=(&(arguments[next]));
8062                     (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8063                       exception);
8064                   }
8065                 token=DestroyString(token);
8066                 break;
8067               }
8068             (void) SubstituteString(&arguments[1],"-","");
8069             (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8070               number_arguments-2,(const char **) arguments+2,exception);
8071             for (j=0; j < number_arguments; j++)
8072               arguments[j]=DestroyString(arguments[j]);
8073             arguments=(char **) RelinquishMagickMemory(arguments);
8074             break;
8075           }
8076         break;
8077       }
8078       case 'r':
8079       {
8080         if (LocaleCompare("reverse",option+1) == 0)
8081           {
8082             ReverseImageList(images);
8083             InheritException(exception,&(*images)->exception);
8084             break;
8085           }
8086         break;
8087       }
8088       case 's':
8089       {
8090         if (LocaleCompare("smush",option+1) == 0)
8091           {
8092             Image
8093               *smush_image;
8094
8095             ssize_t
8096               offset;
8097
8098             (void) SyncImagesSettings(mogrify_info,*images);
8099             offset=(ssize_t) StringToLong(argv[i+1]);
8100             smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8101               MagickFalse,offset,exception);
8102             if (smush_image == (Image *) NULL)
8103               {
8104                 status=MagickFalse;
8105                 break;
8106               }
8107             *images=DestroyImageList(*images);
8108             *images=smush_image;
8109             break;
8110           }
8111         if (LocaleCompare("swap",option+1) == 0)
8112           {
8113             Image
8114               *p,
8115               *q,
8116               *swap;
8117
8118             ssize_t
8119               swap_index;
8120
8121             index=(-1);
8122             swap_index=(-2);
8123             if (*option != '+')
8124               {
8125                 GeometryInfo
8126                   geometry_info;
8127
8128                 MagickStatusType
8129                   flags;
8130
8131                 swap_index=(-1);
8132                 flags=ParseGeometry(argv[i+1],&geometry_info);
8133                 index=(ssize_t) geometry_info.rho;
8134                 if ((flags & SigmaValue) != 0)
8135                   swap_index=(ssize_t) geometry_info.sigma;
8136               }
8137             p=GetImageFromList(*images,index);
8138             q=GetImageFromList(*images,swap_index);
8139             if ((p == (Image *) NULL) || (q == (Image *) NULL))
8140               {
8141                 (void) ThrowMagickException(exception,GetMagickModule(),
8142                   OptionError,"NoSuchImage","`%s'",(*images)->filename);
8143                 status=MagickFalse;
8144                 break;
8145               }
8146             if (p == q)
8147               break;
8148             swap=CloneImage(p,0,0,MagickTrue,exception);
8149             ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8150             ReplaceImageInList(&q,swap);
8151             *images=GetFirstImageInList(q);
8152             break;
8153           }
8154         break;
8155       }
8156       case 'w':
8157       {
8158         if (LocaleCompare("write",option+1) == 0)
8159           {
8160             char
8161               key[MaxTextExtent];
8162
8163             Image
8164               *write_images;
8165
8166             ImageInfo
8167               *write_info;
8168
8169             (void) SyncImagesSettings(mogrify_info,*images);
8170             (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8171             (void) DeleteImageRegistry(key);
8172             write_images=(*images);
8173             if (*option == '+')
8174               write_images=CloneImageList(*images,exception);
8175             write_info=CloneImageInfo(mogrify_info);
8176             status&=WriteImages(write_info,write_images,argv[i+1],exception);
8177             write_info=DestroyImageInfo(write_info);
8178             if (*option == '+')
8179               write_images=DestroyImageList(write_images);
8180             break;
8181           }
8182         break;
8183       }
8184       default:
8185         break;
8186     }
8187     i+=count;
8188   }
8189   quantize_info=DestroyQuantizeInfo(quantize_info);
8190   mogrify_info=DestroyImageInfo(mogrify_info);
8191   status&=MogrifyImageInfo(image_info,argc,argv,exception);
8192   return(status != 0 ? MagickTrue : MagickFalse);
8193 }
8194 \f
8195 /*
8196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8197 %                                                                             %
8198 %                                                                             %
8199 %                                                                             %
8200 +     M o g r i f y I m a g e s                                               %
8201 %                                                                             %
8202 %                                                                             %
8203 %                                                                             %
8204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8205 %
8206 %  MogrifyImages() applies image processing options to a sequence of images as
8207 %  prescribed by command line options.
8208 %
8209 %  The format of the MogrifyImage method is:
8210 %
8211 %      MagickBooleanType MogrifyImages(ImageInfo *image_info,
8212 %        const MagickBooleanType post,const int argc,const char **argv,
8213 %        Image **images,Exceptioninfo *exception)
8214 %
8215 %  A description of each parameter follows:
8216 %
8217 %    o image_info: the image info..
8218 %
8219 %    o post: If true, post process image list operators otherwise pre-process.
8220 %
8221 %    o argc: Specifies a pointer to an integer describing the number of
8222 %      elements in the argument vector.
8223 %
8224 %    o argv: Specifies a pointer to a text array containing the command line
8225 %      arguments.
8226 %
8227 %    o images: pointer to a pointer of the first image in image list.
8228 %
8229 %    o exception: return any errors or warnings in this structure.
8230 %
8231 */
8232 WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8233   const MagickBooleanType post,const int argc,const char **argv,
8234   Image **images,ExceptionInfo *exception)
8235 {
8236 #define MogrifyImageTag  "Mogrify/Image"
8237
8238   MagickStatusType
8239     status;
8240
8241   MagickBooleanType
8242     proceed;
8243
8244   size_t
8245     n;
8246
8247   register ssize_t
8248     i;
8249
8250   assert(image_info != (ImageInfo *) NULL);
8251   assert(image_info->signature == MagickSignature);
8252   if (images == (Image **) NULL)
8253     return(MogrifyImage(image_info,argc,argv,images,exception));
8254   assert((*images)->previous == (Image *) NULL);
8255   assert((*images)->signature == MagickSignature);
8256   if ((*images)->debug != MagickFalse)
8257     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8258       (*images)->filename);
8259   if ((argc <= 0) || (*argv == (char *) NULL))
8260     return(MagickTrue);
8261   (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8262     (void *) NULL);
8263   status=0;
8264
8265 #if 0
8266   (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8267     post?"post":"pre");
8268 #endif
8269
8270   /*
8271     Pre-process multi-image sequence operators
8272   */
8273   if (post == MagickFalse)
8274     status&=MogrifyImageList(image_info,argc,argv,images,exception);
8275   /*
8276     For each image, process simple single image operators
8277   */
8278   i=0;
8279   n=GetImageListLength(*images);
8280   for ( ; ; )
8281   {
8282 #if 0
8283   (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8284     GetImageIndexInList(*images),(long)GetImageListLength(*images));
8285 #endif
8286     status&=MogrifyImage(image_info,argc,argv,images,exception);
8287     proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
8288     if (proceed == MagickFalse)
8289       break;
8290     if ( (*images)->next == (Image *) NULL )
8291       break;
8292     *images=(*images)->next;
8293     i++;
8294   }
8295   assert( *images != (Image *) NULL );
8296 #if 0
8297   (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8298     GetImageIndexInList(*images),(long)GetImageListLength(*images));
8299 #endif
8300
8301   /*
8302     Post-process, multi-image sequence operators
8303   */
8304   *images=GetFirstImageInList(*images);
8305   if (post != MagickFalse)
8306     status&=MogrifyImageList(image_info,argc,argv,images,exception);
8307   return(status != 0 ? MagickTrue : MagickFalse);
8308 }