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