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