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