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