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