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