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