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