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