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