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