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