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