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