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