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