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