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