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