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