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