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