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