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