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