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