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,
2543  exception);
2544  break;
2545  }
2546  if (LocaleCompare("raise",option+1) == 0)
2547  {
2548  /*
2549  Surround image with a raise of solid color.
2550  */
2551  flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2552  (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2553  MagickFalse,exception);
2554  break;
2555  }
2556  if (LocaleCompare("random-threshold",option+1) == 0)
2557  {
2558  /*
2559  Threshold image.
2560  */
2561  double
2562  min_threshold,
2563  max_threshold;
2564 
2565  (void) SyncImageSettings(mogrify_info,*image,exception);
2566  min_threshold=0.0;
2567  max_threshold=(double) QuantumRange;
2568  flags=ParseGeometry(argv[i+1],&geometry_info);
2569  min_threshold=geometry_info.rho;
2570  max_threshold=geometry_info.sigma;
2571  if ((flags & SigmaValue) == 0)
2572  max_threshold=min_threshold;
2573  if (strchr(argv[i+1],'%') != (char *) NULL)
2574  {
2575  max_threshold*=(double) (0.01*QuantumRange);
2576  min_threshold*=(double) (0.01*QuantumRange);
2577  }
2578  (void) RandomThresholdImage(*image,min_threshold,max_threshold,
2579  exception);
2580  break;
2581  }
2582  if (LocaleCompare("read-mask",option+1) == 0)
2583  {
2584  Image
2585  *mask;
2586 
2587  (void) SyncImageSettings(mogrify_info,*image,exception);
2588  if (*option == '+')
2589  {
2590  /*
2591  Remove a mask.
2592  */
2593  (void) SetImageMask(*image,ReadPixelMask,(Image *) NULL,
2594  exception);
2595  break;
2596  }
2597  /*
2598  Set the image mask.
2599  */
2600  mask=GetImageCache(mogrify_info,argv[i+1],exception);
2601  if (mask == (Image *) NULL)
2602  break;
2603  (void) SetImageMask(*image,ReadPixelMask,mask,exception);
2604  mask=DestroyImage(mask);
2605  break;
2606  }
2607  if (LocaleCompare("region",option+1) == 0)
2608  {
2609  /*
2610  Apply read mask as defined by a region geometry.
2611  */
2612  (void) SyncImageSettings(mogrify_info,*image,exception);
2613  if (*option == '+')
2614  {
2615  (void) SetImageRegionMask(*image,WritePixelMask,
2616  (const RectangleInfo *) NULL,exception);
2617  break;
2618  }
2619  (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2620  (void) SetImageRegionMask(*image,WritePixelMask,&geometry,
2621  exception);
2622  break;
2623  }
2624  if (LocaleCompare("render",option+1) == 0)
2625  {
2626  (void) SyncImageSettings(mogrify_info,*image,exception);
2627  draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2628  break;
2629  }
2630  if (LocaleCompare("remap",option+1) == 0)
2631  {
2632  Image
2633  *remap_image;
2634 
2635  /*
2636  Transform image colors to match this set of colors.
2637  */
2638  (void) SyncImageSettings(mogrify_info,*image,exception);
2639  if (*option == '+')
2640  break;
2641  remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2642  if (remap_image == (Image *) NULL)
2643  break;
2644  (void) RemapImage(quantize_info,*image,remap_image,exception);
2645  remap_image=DestroyImage(remap_image);
2646  break;
2647  }
2648  if (LocaleCompare("repage",option+1) == 0)
2649  {
2650  if (*option == '+')
2651  {
2652  (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2653  break;
2654  }
2655  (void) ResetImagePage(*image,argv[i+1]);
2656  break;
2657  }
2658  if (LocaleCompare("resample",option+1) == 0)
2659  {
2660  /*
2661  Resample image.
2662  */
2663  (void) SyncImageSettings(mogrify_info,*image,exception);
2664  flags=ParseGeometry(argv[i+1],&geometry_info);
2665  if ((flags & SigmaValue) == 0)
2666  geometry_info.sigma=geometry_info.rho;
2667  mogrify_image=ResampleImage(*image,geometry_info.rho,
2668  geometry_info.sigma,(*image)->filter,exception);
2669  break;
2670  }
2671  if (LocaleCompare("resize",option+1) == 0)
2672  {
2673  /*
2674  Resize image.
2675  */
2676  (void) SyncImageSettings(mogrify_info,*image,exception);
2677  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2678  mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2679  (*image)->filter,exception);
2680  break;
2681  }
2682  if (LocaleCompare("roll",option+1) == 0)
2683  {
2684  /*
2685  Roll image.
2686  */
2687  (void) SyncImageSettings(mogrify_info,*image,exception);
2688  flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2689  if ((flags & PercentValue) != 0)
2690  {
2691  geometry.x*=(double) (*image)->columns/100.0;
2692  geometry.y*=(double) (*image)->rows/100.0;
2693  }
2694  mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2695  break;
2696  }
2697  if (LocaleCompare("rotate",option+1) == 0)
2698  {
2699  char
2700  *rotation;
2701 
2702  /*
2703  Check for conditional image rotation.
2704  */
2705  (void) SyncImageSettings(mogrify_info,*image,exception);
2706  if (strchr(argv[i+1],'>') != (char *) NULL)
2707  if ((*image)->columns <= (*image)->rows)
2708  break;
2709  if (strchr(argv[i+1],'<') != (char *) NULL)
2710  if ((*image)->columns >= (*image)->rows)
2711  break;
2712  /*
2713  Rotate image.
2714  */
2715  rotation=ConstantString(argv[i+1]);
2716  (void) SubstituteString(&rotation,">","");
2717  (void) SubstituteString(&rotation,"<","");
2718  (void) ParseGeometry(rotation,&geometry_info);
2719  rotation=DestroyString(rotation);
2720  mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2721  break;
2722  }
2723  break;
2724  }
2725  case 's':
2726  {
2727  if (LocaleCompare("sample",option+1) == 0)
2728  {
2729  /*
2730  Sample image with pixel replication.
2731  */
2732  (void) SyncImageSettings(mogrify_info,*image,exception);
2733  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2734  mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2735  exception);
2736  break;
2737  }
2738  if (LocaleCompare("scale",option+1) == 0)
2739  {
2740  /*
2741  Resize image.
2742  */
2743  (void) SyncImageSettings(mogrify_info,*image,exception);
2744  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2745  mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2746  exception);
2747  break;
2748  }
2749  if (LocaleCompare("selective-blur",option+1) == 0)
2750  {
2751  /*
2752  Selectively blur pixels within a contrast threshold.
2753  */
2754  (void) SyncImageSettings(mogrify_info,*image,exception);
2755  flags=ParseGeometry(argv[i+1],&geometry_info);
2756  if ((flags & PercentValue) != 0)
2757  geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2758  mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2759  geometry_info.sigma,geometry_info.xi,exception);
2760  break;
2761  }
2762  if (LocaleCompare("separate",option+1) == 0)
2763  {
2764  /*
2765  Break channels into separate images.
2766  */
2767  (void) SyncImageSettings(mogrify_info,*image,exception);
2768  mogrify_image=SeparateImages(*image,exception);
2769  break;
2770  }
2771  if (LocaleCompare("sepia-tone",option+1) == 0)
2772  {
2773  double
2774  threshold;
2775 
2776  /*
2777  Sepia-tone image.
2778  */
2779  (void) SyncImageSettings(mogrify_info,*image,exception);
2780  threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2781  1.0);
2782  mogrify_image=SepiaToneImage(*image,threshold,exception);
2783  break;
2784  }
2785  if (LocaleCompare("segment",option+1) == 0)
2786  {
2787  /*
2788  Segment image.
2789  */
2790  (void) SyncImageSettings(mogrify_info,*image,exception);
2791  flags=ParseGeometry(argv[i+1],&geometry_info);
2792  if ((flags & SigmaValue) == 0)
2793  geometry_info.sigma=1.0;
2794  (void) SegmentImage(*image,(*image)->colorspace,
2795  mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2796  exception);
2797  break;
2798  }
2799  if (LocaleCompare("set",option+1) == 0)
2800  {
2801  char
2802  *value;
2803 
2804  /*
2805  Set image option.
2806  */
2807  if (*option == '+')
2808  {
2809  if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2810  (void) DeleteImageRegistry(argv[i+1]+9);
2811  else
2812  if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2813  {
2814  (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2815  (void) DeleteImageArtifact(*image,argv[i+1]+7);
2816  }
2817  else
2818  (void) DeleteImageProperty(*image,argv[i+1]);
2819  break;
2820  }
2821  value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2822  exception);
2823  if (value == (char *) NULL)
2824  break;
2825  if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2826  (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2827  exception);
2828  else
2829  if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2830  {
2831  (void) SetImageOption(image_info,argv[i+1]+7,value);
2832  (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2833  (void) SetImageArtifact(*image,argv[i+1]+7,value);
2834  }
2835  else
2836  (void) SetImageProperty(*image,argv[i+1],value,exception);
2837  value=DestroyString(value);
2838  break;
2839  }
2840  if (LocaleCompare("shade",option+1) == 0)
2841  {
2842  /*
2843  Shade image.
2844  */
2845  (void) SyncImageSettings(mogrify_info,*image,exception);
2846  flags=ParseGeometry(argv[i+1],&geometry_info);
2847  if ((flags & SigmaValue) == 0)
2848  geometry_info.sigma=1.0;
2849  mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2850  MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2851  break;
2852  }
2853  if (LocaleCompare("shadow",option+1) == 0)
2854  {
2855  /*
2856  Shadow image.
2857  */
2858  (void) SyncImageSettings(mogrify_info,*image,exception);
2859  flags=ParseGeometry(argv[i+1],&geometry_info);
2860  if ((flags & SigmaValue) == 0)
2861  geometry_info.sigma=1.0;
2862  if ((flags & XiValue) == 0)
2863  geometry_info.xi=4.0;
2864  if ((flags & PsiValue) == 0)
2865  geometry_info.psi=4.0;
2866  mogrify_image=ShadowImage(*image,geometry_info.rho,
2867  geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),
2868  (ssize_t) ceil(geometry_info.psi-0.5),exception);
2869  break;
2870  }
2871  if (LocaleCompare("sharpen",option+1) == 0)
2872  {
2873  /*
2874  Sharpen image.
2875  */
2876  (void) SyncImageSettings(mogrify_info,*image,exception);
2877  flags=ParseGeometry(argv[i+1],&geometry_info);
2878  if ((flags & SigmaValue) == 0)
2879  geometry_info.sigma=1.0;
2880  if ((flags & XiValue) == 0)
2881  geometry_info.xi=0.0;
2882  mogrify_image=SharpenImage(*image,geometry_info.rho,
2883  geometry_info.sigma,exception);
2884  break;
2885  }
2886  if (LocaleCompare("shave",option+1) == 0)
2887  {
2888  /*
2889  Shave the image edges.
2890  */
2891  (void) SyncImageSettings(mogrify_info,*image,exception);
2892  flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2893  mogrify_image=ShaveImage(*image,&geometry,exception);
2894  break;
2895  }
2896  if (LocaleCompare("shear",option+1) == 0)
2897  {
2898  /*
2899  Shear image.
2900  */
2901  (void) SyncImageSettings(mogrify_info,*image,exception);
2902  flags=ParseGeometry(argv[i+1],&geometry_info);
2903  if ((flags & SigmaValue) == 0)
2904  geometry_info.sigma=geometry_info.rho;
2905  mogrify_image=ShearImage(*image,geometry_info.rho,
2906  geometry_info.sigma,exception);
2907  break;
2908  }
2909  if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2910  {
2911  /*
2912  Sigmoidal non-linearity contrast control.
2913  */
2914  (void) SyncImageSettings(mogrify_info,*image,exception);
2915  flags=ParseGeometry(argv[i+1],&geometry_info);
2916  if ((flags & SigmaValue) == 0)
2917  geometry_info.sigma=(double) QuantumRange/2.0;
2918  if ((flags & PercentValue) != 0)
2919  geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2920  100.0;
2921  (void) SigmoidalContrastImage(*image,(*option == '-') ?
2922  MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2923  exception);
2924  break;
2925  }
2926  if (LocaleCompare("sketch",option+1) == 0)
2927  {
2928  /*
2929  Sketch image.
2930  */
2931  (void) SyncImageSettings(mogrify_info,*image,exception);
2932  flags=ParseGeometry(argv[i+1],&geometry_info);
2933  if ((flags & SigmaValue) == 0)
2934  geometry_info.sigma=1.0;
2935  mogrify_image=SketchImage(*image,geometry_info.rho,
2936  geometry_info.sigma,geometry_info.xi,exception);
2937  break;
2938  }
2939  if (LocaleCompare("solarize",option+1) == 0)
2940  {
2941  double
2942  threshold;
2943 
2944  (void) SyncImageSettings(mogrify_info,*image,exception);
2945  threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2946  1.0);
2947  (void) SolarizeImage(*image,threshold,exception);
2948  break;
2949  }
2950  if (LocaleCompare("sparse-color",option+1) == 0)
2951  {
2952  SparseColorMethod
2953  method;
2954 
2955  char
2956  *arguments;
2957 
2958  /*
2959  Sparse Color Interpolated Gradient
2960  */
2961  (void) SyncImageSettings(mogrify_info,*image,exception);
2962  method=(SparseColorMethod) ParseCommandOption(
2963  MagickSparseColorOptions,MagickFalse,argv[i+1]);
2964  arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2965  exception);
2966  if (arguments == (char *) NULL)
2967  break;
2968  mogrify_image=SparseColorOption(*image,method,arguments,
2969  option[0] == '+' ? MagickTrue : MagickFalse,exception);
2970  arguments=DestroyString(arguments);
2971  break;
2972  }
2973  if (LocaleCompare("splice",option+1) == 0)
2974  {
2975  /*
2976  Splice a solid color into the image.
2977  */
2978  (void) SyncImageSettings(mogrify_info,*image,exception);
2979  (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2980  mogrify_image=SpliceImage(*image,&geometry,exception);
2981  break;
2982  }
2983  if (LocaleCompare("spread",option+1) == 0)
2984  {
2985  /*
2986  Spread an image.
2987  */
2988  (void) SyncImageSettings(mogrify_info,*image,exception);
2989  (void) ParseGeometry(argv[i+1],&geometry_info);
2990  mogrify_image=SpreadImage(*image,interpolate_method,
2991  geometry_info.rho,exception);
2992  break;
2993  }
2994  if (LocaleCompare("statistic",option+1) == 0)
2995  {
2996  StatisticType
2997  type;
2998 
2999  (void) SyncImageSettings(mogrify_info,*image,exception);
3000  type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
3001  MagickFalse,argv[i+1]);
3002  (void) ParseGeometry(argv[i+2],&geometry_info);
3003  mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
3004  (size_t) geometry_info.sigma,exception);
3005  break;
3006  }
3007  if (LocaleCompare("stretch",option+1) == 0)
3008  {
3009  if (*option == '+')
3010  {
3011  draw_info->stretch=UndefinedStretch;
3012  break;
3013  }
3014  draw_info->stretch=(StretchType) ParseCommandOption(
3015  MagickStretchOptions,MagickFalse,argv[i+1]);
3016  break;
3017  }
3018  if (LocaleCompare("strip",option+1) == 0)
3019  {
3020  /*
3021  Strip image of profiles and comments.
3022  */
3023  (void) SyncImageSettings(mogrify_info,*image,exception);
3024  (void) StripImage(*image,exception);
3025  break;
3026  }
3027  if (LocaleCompare("stroke",option+1) == 0)
3028  {
3029  ExceptionInfo
3030  *sans;
3031 
3032  PixelInfo
3033  color;
3034 
3035  if (*option == '+')
3036  {
3037  (void) QueryColorCompliance("none",AllCompliance,
3038  &draw_info->stroke,exception);
3039  if (draw_info->stroke_pattern != (Image *) NULL)
3040  draw_info->stroke_pattern=DestroyImage(
3041  draw_info->stroke_pattern);
3042  break;
3043  }
3044  sans=AcquireExceptionInfo();
3045  status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
3046  sans=DestroyExceptionInfo(sans);
3047  if (status == MagickFalse)
3048  draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
3049  exception);
3050  else
3051  draw_info->stroke=color;
3052  break;
3053  }
3054  if (LocaleCompare("strokewidth",option+1) == 0)
3055  {
3056  draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
3057  break;
3058  }
3059  if (LocaleCompare("style",option+1) == 0)
3060  {
3061  if (*option == '+')
3062  {
3063  draw_info->style=UndefinedStyle;
3064  break;
3065  }
3066  draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
3067  MagickFalse,argv[i+1]);
3068  break;
3069  }
3070  if (LocaleCompare("swirl",option+1) == 0)
3071  {
3072  /*
3073  Swirl image.
3074  */
3075  (void) SyncImageSettings(mogrify_info,*image,exception);
3076  (void) ParseGeometry(argv[i+1],&geometry_info);
3077  mogrify_image=SwirlImage(*image,geometry_info.rho,
3078  interpolate_method,exception);
3079  break;
3080  }
3081  break;
3082  }
3083  case 't':
3084  {
3085  if (LocaleCompare("threshold",option+1) == 0)
3086  {
3087  double
3088  threshold;
3089 
3090  /*
3091  Threshold image.
3092  */
3093  (void) SyncImageSettings(mogrify_info,*image,exception);
3094  if (*option == '+')
3095  threshold=(double) QuantumRange/2;
3096  else
3097  threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
3098  1.0);
3099  (void) BilevelImage(*image,threshold,exception);
3100  break;
3101  }
3102  if (LocaleCompare("thumbnail",option+1) == 0)
3103  {
3104  /*
3105  Thumbnail image.
3106  */
3107  (void) SyncImageSettings(mogrify_info,*image,exception);
3108  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3109  mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
3110  exception);
3111  break;
3112  }
3113  if (LocaleCompare("tile",option+1) == 0)
3114  {
3115  if (*option == '+')
3116  {
3117  if (draw_info->fill_pattern != (Image *) NULL)
3118  draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3119  break;
3120  }
3121  draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
3122  exception);
3123  break;
3124  }
3125  if (LocaleCompare("tint",option+1) == 0)
3126  {
3127  /*
3128  Tint the image.
3129  */
3130  (void) SyncImageSettings(mogrify_info,*image,exception);
3131  mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
3132  break;
3133  }
3134  if (LocaleCompare("transform",option+1) == 0)
3135  {
3136  /*
3137  Affine transform image.
3138  */
3139  (void) SyncImageSettings(mogrify_info,*image,exception);
3140  mogrify_image=AffineTransformImage(*image,&draw_info->affine,
3141  exception);
3142  break;
3143  }
3144  if (LocaleCompare("transparent",option+1) == 0)
3145  {
3146  PixelInfo
3147  target;
3148 
3149  (void) SyncImageSettings(mogrify_info,*image,exception);
3150  (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
3151  exception);
3152  (void) TransparentPaintImage(*image,&target,(Quantum)
3153  TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
3154  exception);
3155  break;
3156  }
3157  if (LocaleCompare("transpose",option+1) == 0)
3158  {
3159  /*
3160  Transpose image scanlines.
3161  */
3162  (void) SyncImageSettings(mogrify_info,*image,exception);
3163  mogrify_image=TransposeImage(*image,exception);
3164  break;
3165  }
3166  if (LocaleCompare("transverse",option+1) == 0)
3167  {
3168  /*
3169  Transverse image scanlines.
3170  */
3171  (void) SyncImageSettings(mogrify_info,*image,exception);
3172  mogrify_image=TransverseImage(*image,exception);
3173  break;
3174  }
3175  if (LocaleCompare("treedepth",option+1) == 0)
3176  {
3177  quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3178  break;
3179  }
3180  if (LocaleCompare("trim",option+1) == 0)
3181  {
3182  /*
3183  Trim image.
3184  */
3185  (void) SyncImageSettings(mogrify_info,*image,exception);
3186  mogrify_image=TrimImage(*image,exception);
3187  break;
3188  }
3189  if (LocaleCompare("type",option+1) == 0)
3190  {
3191  ImageType
3192  type;
3193 
3194  (void) SyncImageSettings(mogrify_info,*image,exception);
3195  if (*option == '+')
3196  type=UndefinedType;
3197  else
3198  type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3199  argv[i+1]);
3200  (*image)->type=UndefinedType;
3201  (void) SetImageType(*image,type,exception);
3202  break;
3203  }
3204  break;
3205  }
3206  case 'u':
3207  {
3208  if (LocaleCompare("undercolor",option+1) == 0)
3209  {
3210  (void) QueryColorCompliance(argv[i+1],AllCompliance,
3211  &draw_info->undercolor,exception);
3212  break;
3213  }
3214  if (LocaleCompare("unique",option+1) == 0)
3215  {
3216  if (*option == '+')
3217  {
3218  (void) DeleteImageArtifact(*image,"identify:unique-colors");
3219  break;
3220  }
3221  (void) SetImageArtifact(*image,"identify:unique-colors","true");
3222  (void) SetImageArtifact(*image,"verbose","true");
3223  break;
3224  }
3225  if (LocaleCompare("unique-colors",option+1) == 0)
3226  {
3227  /*
3228  Unique image colors.
3229  */
3230  (void) SyncImageSettings(mogrify_info,*image,exception);
3231  mogrify_image=UniqueImageColors(*image,exception);
3232  break;
3233  }
3234  if (LocaleCompare("unsharp",option+1) == 0)
3235  {
3236  /*
3237  Unsharp mask image.
3238  */
3239  (void) SyncImageSettings(mogrify_info,*image,exception);
3240  flags=ParseGeometry(argv[i+1],&geometry_info);
3241  if ((flags & SigmaValue) == 0)
3242  geometry_info.sigma=1.0;
3243  if ((flags & XiValue) == 0)
3244  geometry_info.xi=1.0;
3245  if ((flags & PsiValue) == 0)
3246  geometry_info.psi=0.05;
3247  mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3248  geometry_info.sigma,geometry_info.xi,geometry_info.psi,
3249  exception);
3250  break;
3251  }
3252  break;
3253  }
3254  case 'v':
3255  {
3256  if (LocaleCompare("verbose",option+1) == 0)
3257  {
3258  (void) SetImageArtifact(*image,option+1,
3259  *option == '+' ? "false" : "true");
3260  break;
3261  }
3262  if (LocaleCompare("vignette",option+1) == 0)
3263  {
3264  /*
3265  Vignette image.
3266  */
3267  (void) SyncImageSettings(mogrify_info,*image,exception);
3268  flags=ParseGeometry(argv[i+1],&geometry_info);
3269  if ((flags & SigmaValue) == 0)
3270  geometry_info.sigma=1.0;
3271  if ((flags & XiValue) == 0)
3272  geometry_info.xi=0.1*(*image)->columns;
3273  if ((flags & PsiValue) == 0)
3274  geometry_info.psi=0.1*(*image)->rows;
3275  if ((flags & PercentValue) != 0)
3276  {
3277  geometry_info.xi*=(double) (*image)->columns/100.0;
3278  geometry_info.psi*=(double) (*image)->rows/100.0;
3279  }
3280  mogrify_image=VignetteImage(*image,geometry_info.rho,
3281  geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),
3282  (ssize_t) ceil(geometry_info.psi-0.5),exception);
3283  break;
3284  }
3285  if (LocaleCompare("virtual-pixel",option+1) == 0)
3286  {
3287  if (*option == '+')
3288  {
3289  (void) SetImageVirtualPixelMethod(*image,
3290  UndefinedVirtualPixelMethod,exception);
3291  break;
3292  }
3293  (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3294  ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3295  argv[i+1]),exception);
3296  break;
3297  }
3298  break;
3299  }
3300  case 'w':
3301  {
3302  if (LocaleCompare("wave",option+1) == 0)
3303  {
3304  /*
3305  Wave image.
3306  */
3307  (void) SyncImageSettings(mogrify_info,*image,exception);
3308  flags=ParseGeometry(argv[i+1],&geometry_info);
3309  if ((flags & SigmaValue) == 0)
3310  geometry_info.sigma=1.0;
3311  mogrify_image=WaveImage(*image,geometry_info.rho,
3312  geometry_info.sigma,interpolate_method,exception);
3313  break;
3314  }
3315  if (LocaleCompare("wavelet-denoise",option+1) == 0)
3316  {
3317  /*
3318  Wavelet denoise image.
3319  */
3320  (void) SyncImageSettings(mogrify_info,*image,exception);
3321  flags=ParseGeometry(argv[i+1],&geometry_info);
3322  if ((flags & PercentValue) != 0)
3323  {
3324  geometry_info.rho=QuantumRange*geometry_info.rho/100.0;
3325  geometry_info.sigma=QuantumRange*geometry_info.sigma/100.0;
3326  }
3327  if ((flags & SigmaValue) == 0)
3328  geometry_info.sigma=0.0;
3329  mogrify_image=WaveletDenoiseImage(*image,geometry_info.rho,
3330  geometry_info.sigma,exception);
3331  break;
3332  }
3333  if (LocaleCompare("weight",option+1) == 0)
3334  {
3335  ssize_t
3336  weight;
3337 
3338  weight=ParseCommandOption(MagickWeightOptions,MagickFalse,
3339  argv[i+1]);
3340  if (weight == -1)
3341  weight=(ssize_t) StringToUnsignedLong(argv[i+1]);
3342  draw_info->weight=(size_t) weight;
3343  break;
3344  }
3345  if (LocaleCompare("white-threshold",option+1) == 0)
3346  {
3347  /*
3348  White threshold image.
3349  */
3350  (void) SyncImageSettings(mogrify_info,*image,exception);
3351  (void) WhiteThresholdImage(*image,argv[i+1],exception);
3352  break;
3353  }
3354  if (LocaleCompare("write-mask",option+1) == 0)
3355  {
3356  Image
3357  *mask;
3358 
3359  (void) SyncImageSettings(mogrify_info,*image,exception);
3360  if (*option == '+')
3361  {
3362  /*
3363  Remove a mask.
3364  */
3365  (void) SetImageMask(*image,WritePixelMask,(Image *) NULL,
3366  exception);
3367  break;
3368  }
3369  /*
3370  Set the image mask.
3371  */
3372  mask=GetImageCache(mogrify_info,argv[i+1],exception);
3373  if (mask == (Image *) NULL)
3374  break;
3375  (void) SetImageMask(*image,WritePixelMask,mask,exception);
3376  mask=DestroyImage(mask);
3377  break;
3378  }
3379  break;
3380  }
3381  default:
3382  break;
3383  }
3384  /*
3385  Replace current image with any image that was generated
3386  */
3387  if (mogrify_image != (Image *) NULL)
3388  ReplaceImageInListReturnLast(image,mogrify_image);
3389  i+=count;
3390  }
3391  /*
3392  Free resources.
3393  */
3394  quantize_info=DestroyQuantizeInfo(quantize_info);
3395  draw_info=DestroyDrawInfo(draw_info);
3396  mogrify_info=DestroyImageInfo(mogrify_info);
3397  status=(MagickStatusType) (exception->severity < ErrorException ? 1 : 0);
3398  return(status == 0 ? MagickFalse : MagickTrue);
3399 }
3400 
3401 /*
3402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3403 % %
3404 % %
3405 % %
3406 + M o g r i f y I m a g e C o m m a n d %
3407 % %
3408 % %
3409 % %
3410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3411 %
3412 % MogrifyImageCommand() transforms an image or a sequence of images. These
3413 % transforms include image scaling, image rotation, color reduction, and
3414 % others. The transmogrified image overwrites the original image.
3415 %
3416 % The format of the MogrifyImageCommand method is:
3417 %
3418 % MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3419 % const char **argv,char **metadata,ExceptionInfo *exception)
3420 %
3421 % A description of each parameter follows:
3422 %
3423 % o image_info: the image info.
3424 %
3425 % o argc: the number of elements in the argument vector.
3426 %
3427 % o argv: A text array containing the command line arguments.
3428 %
3429 % o metadata: any metadata is returned here.
3430 %
3431 % o exception: return any errors or warnings in this structure.
3432 %
3433 */
3434 
3435 static MagickBooleanType MogrifyUsage(void)
3436 {
3437  static const char
3438  *channel_operators[]=
3439  {
3440  "-channel-fx expression",
3441  " exchange, extract, or transfer one or more image channels",
3442  "-separate separate an image channel into a grayscale image",
3443  (char *) NULL
3444  },
3445  *miscellaneous[]=
3446  {
3447  "-debug events display copious debugging information",
3448  "-distribute-cache port",
3449  " distributed pixel cache spanning one or more servers",
3450  "-help print program options",
3451  "-list type print a list of supported option arguments",
3452  "-log format format of debugging information",
3453  "-version print version information",
3454  (char *) NULL
3455  },
3456  *operators[]=
3457  {
3458  "-adaptive-blur geometry",
3459  " adaptively blur pixels; decrease effect near edges",
3460  "-adaptive-resize geometry",
3461  " adaptively resize image using 'mesh' interpolation",
3462  "-adaptive-sharpen geometry",
3463  " adaptively sharpen pixels; increase effect near edges",
3464  "-alpha option on, activate, off, deactivate, set, opaque, copy",
3465  " transparent, extract, background, or shape",
3466  "-annotate geometry text",
3467  " annotate the image with text",
3468  "-auto-gamma automagically adjust gamma level of image",
3469  "-auto-level automagically adjust color levels of image",
3470  "-auto-orient automagically orient (rotate) image",
3471  "-auto-threshold method",
3472  " automatically perform image thresholding",
3473  "-bench iterations measure performance",
3474  "-black-threshold value",
3475  " force all pixels below the threshold into black",
3476  "-blue-shift simulate a scene at nighttime in the moonlight",
3477  "-blur geometry reduce image noise and reduce detail levels",
3478  "-border geometry surround image with a border of color",
3479  "-bordercolor color border color",
3480  "-brightness-contrast geometry",
3481  " improve brightness / contrast of the image",
3482  "-canny geometry detect edges in the image",
3483  "-cdl filename color correct with a color decision list",
3484  "-channel mask set the image channel mask",
3485  "-charcoal geometry simulate a charcoal drawing",
3486  "-chop geometry remove pixels from the image interior",
3487  "-clamp keep pixel values in range (0-QuantumRange)",
3488  "-clip clip along the first path from the 8BIM profile",
3489  "-clip-mask filename associate a clip mask with the image",
3490  "-clip-path id clip along a named path from the 8BIM profile",
3491  "-colorize value colorize the image with the fill color",
3492  "-color-matrix matrix apply color correction to the image",
3493  "-connected-components connectivity",
3494  " connected-components uniquely labeled",
3495  "-contrast enhance or reduce the image contrast",
3496  "-contrast-stretch geometry",
3497  " improve contrast by 'stretching' the intensity range",
3498  "-convolve coefficients",
3499  " apply a convolution kernel to the image",
3500  "-cycle amount cycle the image colormap",
3501  "-decipher filename convert cipher pixels to plain pixels",
3502  "-deskew threshold straighten an image",
3503  "-despeckle reduce the speckles within an image",
3504  "-distort method args",
3505  " distort images according to given method ad args",
3506  "-draw string annotate the image with a graphic primitive",
3507  "-edge radius apply a filter to detect edges in the image",
3508  "-encipher filename convert plain pixels to cipher pixels",
3509  "-emboss radius emboss an image",
3510  "-enhance apply a digital filter to enhance a noisy image",
3511  "-equalize perform histogram equalization to an image",
3512  "-evaluate operator value",
3513  " evaluate an arithmetic, relational, or logical expression",
3514  "-extent geometry set the image size",
3515  "-extract geometry extract area from image",
3516  "-fft implements the discrete Fourier transform (DFT)",
3517  "-flip flip image vertically",
3518  "-floodfill geometry color",
3519  " floodfill the image with color",
3520  "-flop flop image horizontally",
3521  "-frame geometry surround image with an ornamental border",
3522  "-function name parameters",
3523  " apply function over image values",
3524  "-gamma value level of gamma correction",
3525  "-gaussian-blur geometry",
3526  " reduce image noise and reduce detail levels",
3527  "-geometry geometry preferred size or location of the image",
3528  "-grayscale method convert image to grayscale",
3529  "-hough-lines geometry",
3530  " identify lines in the image",
3531  "-identify identify the format and characteristics of the image",
3532  "-ift implements the inverse discrete Fourier transform (DFT)",
3533  "-implode amount implode image pixels about the center",
3534  "-interpolative-resize geometry",
3535  " resize image using interpolation",
3536  "-kuwahara geometry edge preserving noise reduction filter",
3537  "-lat geometry local adaptive thresholding",
3538  "-level value adjust the level of image contrast",
3539  "-level-colors color,color",
3540  " level image with the given colors",
3541  "-linear-stretch geometry",
3542  " improve contrast by 'stretching with saturation'",
3543  "-liquid-rescale geometry",
3544  " rescale image with seam-carving",
3545  "-local-contrast geometry",
3546  " enhance local contrast",
3547  "-magnify double the size of the image with pixel art scaling",
3548  "-mean-shift geometry delineate arbitrarily shaped clusters in the image",
3549  "-median geometry apply a median filter to the image",
3550  "-mode geometry make each pixel the 'predominant color' of the",
3551  " neighborhood",
3552  "-modulate value vary the brightness, saturation, and hue",
3553  "-monochrome transform image to black and white",
3554  "-morphology method kernel",
3555  " apply a morphology method to the image",
3556  "-motion-blur geometry",
3557  " simulate motion blur",
3558  "-negate replace every pixel with its complementary color ",
3559  "-noise geometry add or reduce noise in an image",
3560  "-normalize transform image to span the full range of colors",
3561  "-opaque color change this color to the fill color",
3562  "-ordered-dither NxN",
3563  " add a noise pattern to the image with specific",
3564  " amplitudes",
3565  "-paint radius simulate an oil painting",
3566  "-perceptible epsilon",
3567  " pixel value less than |epsilon| become epsilon or",
3568  " -epsilon",
3569  "-polaroid angle simulate a Polaroid picture",
3570  "-posterize levels reduce the image to a limited number of color levels",
3571  "-profile filename add, delete, or apply an image profile",
3572  "-quantize colorspace reduce colors in this colorspace",
3573  "-raise value lighten/darken image edges to create a 3-D effect",
3574  "-random-threshold low,high",
3575  " random threshold the image",
3576  "-region geometry apply options to a portion of the image",
3577  "-render render vector graphics",
3578  "-repage geometry size and location of an image canvas",
3579  "-resample geometry change the resolution of an image",
3580  "-resize geometry resize the image",
3581  "-roll geometry roll an image vertically or horizontally",
3582  "-rotate degrees apply Paeth rotation to the image",
3583  "-rotational-blur angle",
3584  " rotational blur the image",
3585  "-sample geometry scale image with pixel sampling",
3586  "-scale geometry scale the image",
3587  "-segment values segment an image",
3588  "-selective-blur geometry",
3589  " selectively blur pixels within a contrast threshold",
3590  "-sepia-tone threshold",
3591  " simulate a sepia-toned photo",
3592  "-set property value set an image property",
3593  "-shade degrees shade the image using a distant light source",
3594  "-shadow geometry simulate an image shadow",
3595  "-sharpen geometry sharpen the image",
3596  "-shave geometry shave pixels from the image edges",
3597  "-shear geometry slide one edge of the image along the X or Y axis",
3598  "-sigmoidal-contrast geometry",
3599  " increase the contrast without saturating highlights or",
3600  " shadows",
3601  "-sketch geometry simulate a pencil sketch",
3602  "-solarize threshold negate all pixels above the threshold level",
3603  "-sparse-color method args",
3604  " fill in a image based on a few color points",
3605  "-splice geometry splice the background color into the image",
3606  "-spread radius displace image pixels by a random amount",
3607  "-statistic type radius",
3608  " replace each pixel with corresponding statistic from the neighborhood",
3609  "-strip strip image of all profiles and comments",
3610  "-swirl degrees swirl image pixels about the center",
3611  "-threshold value threshold the image",
3612  "-thumbnail geometry create a thumbnail of the image",
3613  "-tile filename tile image when filling a graphic primitive",
3614  "-tint value tint the image with the fill color",
3615  "-transform affine transform image",
3616  "-transparent color make this color transparent within the image",
3617  "-transpose flip image vertically and rotate 90 degrees",
3618  "-transverse flop image horizontally and rotate 270 degrees",
3619  "-trim trim image edges",
3620  "-type type image type",
3621  "-unique-colors discard all but one of any pixel color",
3622  "-unsharp geometry sharpen the image",
3623  "-vignette geometry soften the edges of the image in vignette style",
3624  "-wave geometry alter an image along a sine wave",
3625  "-wavelet-denoise threshold",
3626  " removes noise from the image using a wavelet transform",
3627  "-white-threshold value",
3628  " force all pixels above the threshold into white",
3629  (char *) NULL
3630  },
3631  *sequence_operators[]=
3632  {
3633  "-affinity filename transform image colors to match this set of colors",
3634  "-append append an image sequence",
3635  "-clut apply a color lookup table to the image",
3636  "-coalesce merge a sequence of images",
3637  "-combine combine a sequence of images",
3638  "-compare mathematically and visually annotate the difference between an image and its reconstruction",
3639  "-complex operator perform complex mathematics on an image sequence",
3640  "-composite composite image",
3641  "-copy geometry offset",
3642  " copy pixels from one area of an image to another",
3643  "-crop geometry cut out a rectangular region of the image",
3644  "-deconstruct break down an image sequence into constituent parts",
3645  "-evaluate-sequence operator",
3646  " evaluate an arithmetic, relational, or logical expression",
3647  "-flatten flatten a sequence of images",
3648  "-fx expression apply mathematical expression to an image channel(s)",
3649  "-hald-clut apply a Hald color lookup table to the image",
3650  "-layers method optimize, merge, or compare image layers",
3651  "-morph value morph an image sequence",
3652  "-mosaic create a mosaic from an image sequence",
3653  "-poly terms build a polynomial from the image sequence and the corresponding",
3654  " terms (coefficients and degree pairs).",
3655  "-print string interpret string and print to console",
3656  "-process arguments process the image with a custom image filter",
3657  "-smush geometry smush an image sequence together",
3658  "-write filename write images to this file",
3659  (char *) NULL
3660  },
3661  *settings[]=
3662  {
3663  "-adjoin join images into a single multi-image file",
3664  "-affine matrix affine transform matrix",
3665  "-alpha option activate, deactivate, reset, or set the alpha channel",
3666  "-antialias remove pixel-aliasing",
3667  "-authenticate password",
3668  " decipher image with this password",
3669  "-attenuate value lessen (or intensify) when adding noise to an image",
3670  "-background color background color",
3671  "-bias value add bias when convolving an image",
3672  "-black-point-compensation",
3673  " use black point compensation",
3674  "-blue-primary point chromaticity blue primary point",
3675  "-bordercolor color border color",
3676  "-caption string assign a caption to an image",
3677  "-colors value preferred number of colors in the image",
3678  "-colorspace type alternate image colorspace",
3679  "-comment string annotate image with comment",
3680  "-compose operator set image composite operator",
3681  "-compress type type of pixel compression when writing the image",
3682  "-define format:option=value",
3683  " define one or more image format options",
3684  "-delay value display the next image after pausing",
3685  "-density geometry horizontal and vertical density of the image",
3686  "-depth value image depth",
3687  "-direction type render text right-to-left or left-to-right",
3688  "-display server get image or font from this X server",
3689  "-dispose method layer disposal method",
3690  "-dither method apply error diffusion to image",
3691  "-encoding type text encoding type",
3692  "-endian type endianness (MSB or LSB) of the image",
3693  "-family name render text with this font family",
3694  "-features distance analyze image features (e.g. contrast, correlation)",
3695  "-fill color color to use when filling a graphic primitive",
3696  "-filter type use this filter when resizing an image",
3697  "-font name render text with this font",
3698  "-format \"string\" output formatted image characteristics",
3699  "-fuzz distance colors within this distance are considered equal",
3700  "-gravity type horizontal and vertical text placement",
3701  "-green-primary point chromaticity green primary point",
3702  "-intensity method method to generate an intensity value from a pixel",
3703  "-intent type type of rendering intent when managing the image color",
3704  "-interlace type type of image interlacing scheme",
3705  "-interline-spacing value",
3706  " set the space between two text lines",
3707  "-interpolate method pixel color interpolation method",
3708  "-interword-spacing value",
3709  " set the space between two words",
3710  "-kerning value set the space between two letters",
3711  "-label string assign a label to an image",
3712  "-limit type value pixel cache resource limit",
3713  "-loop iterations add Netscape loop extension to your GIF animation",
3714  "-matte store matte channel if the image has one",
3715  "-mattecolor color frame color",
3716  "-monitor monitor progress",
3717  "-orient type image orientation",
3718  "-page geometry size and location of an image canvas (setting)",
3719  "-path path write images to this path on disk",
3720  "-ping efficiently determine image attributes",
3721  "-pointsize value font point size",
3722  "-precision value maximum number of significant digits to print",
3723  "-preview type image preview type",
3724  "-quality value JPEG/MIFF/PNG compression level",
3725  "-quiet suppress all warning messages",
3726  "-read-mask filename associate a read mask with the image",
3727  "-red-primary point chromaticity red primary point",
3728  "-regard-warnings pay attention to warning messages",
3729  "-remap filename transform image colors to match this set of colors",
3730  "-respect-parentheses settings remain in effect until parenthesis boundary",
3731  "-sampling-factor geometry",
3732  " horizontal and vertical sampling factor",
3733  "-scene value image scene number",
3734  "-seed value seed a new sequence of pseudo-random numbers",
3735  "-size geometry width and height of image",
3736  "-stretch type render text with this font stretch",
3737  "-stroke color graphic primitive stroke color",
3738  "-strokewidth value graphic primitive stroke width",
3739  "-style type render text with this font style",
3740  "-synchronize synchronize image to storage device",
3741  "-taint declare the image as modified",
3742  "-texture filename name of texture to tile onto the image background",
3743  "-tile-offset geometry",
3744  " tile offset",
3745  "-treedepth value color tree depth",
3746  "-transparent-color color",
3747  " transparent color",
3748  "-undercolor color annotation bounding box color",
3749  "-units type the units of image resolution",
3750  "-verbose print detailed information about the image",
3751  "-view FlashPix viewing transforms",
3752  "-virtual-pixel method",
3753  " virtual pixel access method",
3754  "-weight type render text with this font weight",
3755  "-white-point point chromaticity white point",
3756  "-write-mask filename associate a write mask with the image",
3757  (char *) NULL
3758  },
3759  *stack_operators[]=
3760  {
3761  "-delete indexes delete the image from the image sequence",
3762  "-duplicate count,indexes",
3763  " duplicate an image one or more times",
3764  "-insert index insert last image into the image sequence",
3765  "-reverse reverse image sequence",
3766  "-swap indexes swap two images in the image sequence",
3767  (char *) NULL
3768  };
3769 
3770  const char
3771  **p;
3772 
3773  ListMagickVersion(stdout);
3774  (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3775  GetClientName());
3776  (void) printf("\nImage Settings:\n");
3777  for (p=settings; *p != (char *) NULL; p++)
3778  (void) printf(" %s\n",*p);
3779  (void) printf("\nImage Operators:\n");
3780  for (p=operators; *p != (char *) NULL; p++)
3781  (void) printf(" %s\n",*p);
3782  (void) printf("\nImage Channel Operators:\n");
3783  for (p=channel_operators; *p != (char *) NULL; p++)
3784  (void) printf(" %s\n",*p);
3785  (void) printf("\nImage Sequence Operators:\n");
3786  for (p=sequence_operators; *p != (char *) NULL; p++)
3787  (void) printf(" %s\n",*p);
3788  (void) printf("\nImage Stack Operators:\n");
3789  for (p=stack_operators; *p != (char *) NULL; p++)
3790  (void) printf(" %s\n",*p);
3791  (void) printf("\nMiscellaneous Options:\n");
3792  for (p=miscellaneous; *p != (char *) NULL; p++)
3793  (void) printf(" %s\n",*p);
3794  (void) printf(
3795  "\nBy default, the image format of 'file' is determined by its magic\n");
3796  (void) printf(
3797  "number. To specify a particular image format, precede the filename\n");
3798  (void) printf(
3799  "with an image format name and a colon (i.e. ps:image) or specify the\n");
3800  (void) printf(
3801  "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3802  (void) printf("'-' for standard input or output.\n");
3803  return(MagickFalse);
3804 }
3805 
3806 WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3807  int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3808 {
3809 #define DestroyMogrify() \
3810 { \
3811  if (format != (char *) NULL) \
3812  format=DestroyString(format); \
3813  if (path != (char *) NULL) \
3814  path=DestroyString(path); \
3815  DestroyImageStack(); \
3816  for (i=0; i < (ssize_t) argc; i++) \
3817  argv[i]=DestroyString(argv[i]); \
3818  argv=(char **) RelinquishMagickMemory(argv); \
3819 }
3820 #define ThrowMogrifyException(asperity,tag,option) \
3821 { \
3822  (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3823  option); \
3824  DestroyMogrify(); \
3825  return(MagickFalse); \
3826 }
3827 #define ThrowMogrifyInvalidArgumentException(option,argument) \
3828 { \
3829  (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3830  "InvalidArgument","'%s': %s",argument,option); \
3831  DestroyMogrify(); \
3832  return(MagickFalse); \
3833 }
3834 
3835  char
3836  *format,
3837  *option,
3838  *path;
3839 
3840  Image
3841  *image;
3842 
3843  ImageStack
3844  image_stack[MaxImageStackDepth+1];
3845 
3846  MagickBooleanType
3847  global_colormap;
3848 
3849  MagickBooleanType
3850  fire,
3851  pend,
3852  respect_parenthesis;
3853 
3854  MagickStatusType
3855  status;
3856 
3857  register ssize_t
3858  i;
3859 
3860  ssize_t
3861  j,
3862  k;
3863 
3864  wand_unreferenced(metadata);
3865 
3866  /*
3867  Set defaults.
3868  */
3869  assert(image_info != (ImageInfo *) NULL);
3870  assert(image_info->signature == MagickCoreSignature);
3871  if (image_info->debug != MagickFalse)
3872  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3873  assert(exception != (ExceptionInfo *) NULL);
3874  if (argc == 2)
3875  {
3876  option=argv[1];
3877  if ((LocaleCompare("version",option+1) == 0) ||
3878  (LocaleCompare("-version",option+1) == 0))
3879  {
3880  ListMagickVersion(stdout);
3881  return(MagickTrue);
3882  }
3883  }
3884  if (argc < 2)
3885  return(MogrifyUsage());
3886  format=(char *) NULL;
3887  path=(char *) NULL;
3888  global_colormap=MagickFalse;
3889  k=0;
3890  j=1;
3891  NewImageStack();
3892  option=(char *) NULL;
3893  pend=MagickFalse;
3894  respect_parenthesis=MagickFalse;
3895  status=MagickTrue;
3896  /*
3897  Parse command line.
3898  */
3899  ReadCommandlLine(argc,&argv);
3900  status=ExpandFilenames(&argc,&argv);
3901  if (status == MagickFalse)
3902  ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3903  GetExceptionMessage(errno));
3904  for (i=1; i < (ssize_t) argc; i++)
3905  {
3906  option=argv[i];
3907  if (LocaleCompare(option,"(") == 0)
3908  {
3909  FireImageStack(MagickFalse,MagickTrue,pend);
3910  if (k == MaxImageStackDepth)
3911  ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3912  option);
3913  PushImageStack();
3914  continue;
3915  }
3916  if (LocaleCompare(option,")") == 0)
3917  {
3918  FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3919  if (k == 0)
3920  ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3921  PopImageStack();
3922  continue;
3923  }
3924  if (IsCommandOption(option) == MagickFalse)
3925  {
3926  char
3927  backup_filename[MagickPathExtent],
3928  *filename;
3929 
3930  Image
3931  *images;
3932 
3933  struct stat
3934  properties;
3935 
3936  /*
3937  Option is a file name: begin by reading image from specified file.
3938  */
3939  FireImageStack(MagickFalse,MagickFalse,pend);
3940  filename=argv[i];
3941  if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
3942  filename=argv[++i];
3943  images=ReadImages(image_info,filename,exception);
3944  status&=(images != (Image *) NULL) &&
3945  (exception->severity < ErrorException);
3946  if (images == (Image *) NULL)
3947  continue;
3948  properties=(*GetBlobProperties(images));
3949  if (format != (char *) NULL)
3950  (void) CopyMagickString(images->filename,images->magick_filename,
3952  if (path != (char *) NULL)
3953  {
3954  GetPathComponent(option,TailPath,filename);
3955  (void) FormatLocaleString(images->filename,MagickPathExtent,
3956  "%s%c%s",path,*DirectorySeparator,filename);
3957  }
3958  if (format != (char *) NULL)
3959  AppendImageFormat(format,images->filename);
3960  AppendImageStack(images);
3961  FinalizeImageSettings(image_info,image,MagickFalse);
3962  if (global_colormap != MagickFalse)
3963  {
3964  QuantizeInfo
3965  *quantize_info;
3966 
3967  quantize_info=AcquireQuantizeInfo(image_info);
3968  (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
3969  quantize_info=DestroyQuantizeInfo(quantize_info);
3970  }
3971  *backup_filename='\0';
3972  if ((LocaleCompare(image->filename,"-") != 0) &&
3973  (IsPathWritable(image->filename) != MagickFalse))
3974  {
3975  /*
3976  Rename image file as backup.
3977  */
3978  (void) CopyMagickString(backup_filename,image->filename,
3980  for (j=0; j < 6; j++)
3981  {
3982  (void) ConcatenateMagickString(backup_filename,"~",
3984  if (IsPathAccessible(backup_filename) == MagickFalse)
3985  break;
3986  }
3987  if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3988  (rename_utf8(image->filename,backup_filename) != 0))
3989  *backup_filename='\0';
3990  }
3991  /*
3992  Write transmogrified image to disk.
3993  */
3994  image_info->synchronize=MagickTrue;
3995  status&=WriteImages(image_info,image,image->filename,exception);
3996  if (status != MagickFalse)
3997  {
3998 #if defined(MAGICKCORE_HAVE_UTIME)
3999  {
4000  MagickBooleanType
4001  preserve_timestamp;
4002 
4003  preserve_timestamp=IsStringTrue(GetImageOption(image_info,
4004  "preserve-timestamp"));
4005  if (preserve_timestamp != MagickFalse)
4006  {
4007  struct utimbuf
4008  timestamp;
4009 
4010  timestamp.actime=properties.st_atime;
4011  timestamp.modtime=properties.st_mtime;
4012  (void) utime(image->filename,&timestamp);
4013  }
4014  }
4015 #endif
4016  if (*backup_filename != '\0')
4017  (void) remove_utf8(backup_filename);
4018  }
4020  continue;
4021  }
4022  pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4023  switch (*(option+1))
4024  {
4025  case 'a':
4026  {
4027  if (LocaleCompare("adaptive-blur",option+1) == 0)
4028  {
4029  i++;
4030  if (i == (ssize_t) argc)
4031  ThrowMogrifyException(OptionError,"MissingArgument",option);
4032  if (IsGeometry(argv[i]) == MagickFalse)
4033  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4034  break;
4035  }
4036  if (LocaleCompare("adaptive-resize",option+1) == 0)
4037  {
4038  i++;
4039  if (i == (ssize_t) argc)
4040  ThrowMogrifyException(OptionError,"MissingArgument",option);
4041  if (IsGeometry(argv[i]) == MagickFalse)
4042  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4043  break;
4044  }
4045  if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4046  {
4047  i++;
4048  if (i == (ssize_t) argc)
4049  ThrowMogrifyException(OptionError,"MissingArgument",option);
4050  if (IsGeometry(argv[i]) == MagickFalse)
4051  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4052  break;
4053  }
4054  if (LocaleCompare("affine",option+1) == 0)
4055  {
4056  if (*option == '+')
4057  break;
4058  i++;
4059  if (i == (ssize_t) argc)
4060  ThrowMogrifyException(OptionError,"MissingArgument",option);
4061  break;
4062  }
4063  if (LocaleCompare("alpha",option+1) == 0)
4064  {
4065  ssize_t
4066  type;
4067 
4068  if (*option == '+')
4069  break;
4070  i++;
4071  if (i == (ssize_t) argc)
4072  ThrowMogrifyException(OptionError,"MissingArgument",option);
4073  type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,
4074  argv[i]);
4075  if (type < 0)
4076  ThrowMogrifyException(OptionError,
4077  "UnrecognizedAlphaChannelOption",argv[i]);
4078  break;
4079  }
4080  if (LocaleCompare("annotate",option+1) == 0)
4081  {
4082  if (*option == '+')
4083  break;
4084  i++;
4085  if (i == (ssize_t) argc)
4086  ThrowMogrifyException(OptionError,"MissingArgument",option);
4087  if (IsGeometry(argv[i]) == MagickFalse)
4088  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4089  if (i == (ssize_t) argc)
4090  ThrowMogrifyException(OptionError,"MissingArgument",option);
4091  i++;
4092  break;
4093  }
4094  if (LocaleCompare("antialias",option+1) == 0)
4095  break;
4096  if (LocaleCompare("append",option+1) == 0)
4097  break;
4098  if (LocaleCompare("attenuate",option+1) == 0)
4099  {
4100  if (*option == '+')
4101  break;
4102  i++;
4103  if (i == (ssize_t) argc)
4104  ThrowMogrifyException(OptionError,"MissingArgument",option);
4105  if (IsGeometry(argv[i]) == MagickFalse)
4106  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4107  break;
4108  }
4109  if (LocaleCompare("authenticate",option+1) == 0)
4110  {
4111  if (*option == '+')
4112  break;
4113  i++;
4114  if (i == (ssize_t) argc)
4115  ThrowMogrifyException(OptionError,"MissingArgument",option);
4116  break;
4117  }
4118  if (LocaleCompare("auto-gamma",option+1) == 0)
4119  break;
4120  if (LocaleCompare("auto-level",option+1) == 0)
4121  break;
4122  if (LocaleCompare("auto-orient",option+1) == 0)
4123  break;
4124  if (LocaleCompare("auto-threshold",option+1) == 0)
4125  {
4126  ssize_t
4127  method;
4128 
4129  if (*option == '+')
4130  break;
4131  i++;
4132  if (i == (ssize_t) argc)
4133  ThrowMogrifyException(OptionError,"MissingArgument",option);
4134  method=ParseCommandOption(MagickAutoThresholdOptions,MagickFalse,
4135  argv[i]);
4136  if (method < 0)
4137  ThrowMogrifyException(OptionError,"UnrecognizedThresholdMethod",
4138  argv[i]);
4139  break;
4140  }
4141  if (LocaleCompare("average",option+1) == 0)
4142  break;
4143  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4144  }
4145  case 'b':
4146  {
4147  if (LocaleCompare("background",option+1) == 0)
4148  {
4149  if (*option == '+')
4150  break;
4151  i++;
4152  if (i == (ssize_t) argc)
4153  ThrowMogrifyException(OptionError,"MissingArgument",option);
4154  break;
4155  }
4156  if (LocaleCompare("bias",option+1) == 0)
4157  {
4158  if (*option == '+')
4159  break;
4160  i++;
4161  if (i == (ssize_t) argc)
4162  ThrowMogrifyException(OptionError,"MissingArgument",option);
4163  if (IsGeometry(argv[i]) == MagickFalse)
4164  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4165  break;
4166  }
4167  if (LocaleCompare("black-point-compensation",option+1) == 0)
4168  break;
4169  if (LocaleCompare("black-threshold",option+1) == 0)
4170  {
4171  if (*option == '+')
4172  break;
4173  i++;
4174  if (i == (ssize_t) argc)
4175  ThrowMogrifyException(OptionError,"MissingArgument",option);
4176  if (IsGeometry(argv[i]) == MagickFalse)
4177  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4178  break;
4179  }
4180  if (LocaleCompare("blue-primary",option+1) == 0)
4181  {
4182  if (*option == '+')
4183  break;
4184  i++;
4185  if (i == (ssize_t) argc)
4186  ThrowMogrifyException(OptionError,"MissingArgument",option);
4187  if (IsGeometry(argv[i]) == MagickFalse)
4188  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4189  break;
4190  }
4191  if (LocaleCompare("blue-shift",option+1) == 0)
4192  {
4193  i++;
4194  if (i == (ssize_t) argc)
4195  ThrowMogrifyException(OptionError,"MissingArgument",option);
4196  if (IsGeometry(argv[i]) == MagickFalse)
4197  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4198  break;
4199  }
4200  if (LocaleCompare("blur",option+1) == 0)
4201  {
4202  i++;
4203  if (i == (ssize_t) argc)
4204  ThrowMogrifyException(OptionError,"MissingArgument",option);
4205  if (IsGeometry(argv[i]) == MagickFalse)
4206  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4207  break;
4208  }
4209  if (LocaleCompare("border",option+1) == 0)
4210  {
4211  if (*option == '+')
4212  break;
4213  i++;
4214  if (i == (ssize_t) argc)
4215  ThrowMogrifyException(OptionError,"MissingArgument",option);
4216  if (IsGeometry(argv[i]) == MagickFalse)
4217  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4218  break;
4219  }
4220  if (LocaleCompare("bordercolor",option+1) == 0)
4221  {
4222  if (*option == '+')
4223  break;
4224  i++;
4225  if (i == (ssize_t) argc)
4226  ThrowMogrifyException(OptionError,"MissingArgument",option);
4227  break;
4228  }
4229  if (LocaleCompare("box",option+1) == 0)
4230  {
4231  if (*option == '+')
4232  break;
4233  i++;
4234  if (i == (ssize_t) argc)
4235  ThrowMogrifyException(OptionError,"MissingArgument",option);
4236  break;
4237  }
4238  if (LocaleCompare("brightness-contrast",option+1) == 0)
4239  {
4240  i++;
4241  if (i == (ssize_t) argc)
4242  ThrowMogrifyException(OptionError,"MissingArgument",option);
4243  if (IsGeometry(argv[i]) == MagickFalse)
4244  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4245  break;
4246  }
4247  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4248  }
4249  case 'c':
4250  {
4251  if (LocaleCompare("cache",option+1) == 0)
4252  {
4253  if (*option == '+')
4254  break;
4255  i++;
4256  if (i == (ssize_t) argc)
4257  ThrowMogrifyException(OptionError,"MissingArgument",option);
4258  if (IsGeometry(argv[i]) == MagickFalse)
4259  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4260  break;
4261  }
4262  if (LocaleCompare("canny",option+1) == 0)
4263  {
4264  if (*option == '+')
4265  break;
4266  i++;
4267  if (i == (ssize_t) argc)
4268  ThrowMogrifyException(OptionError,"MissingArgument",option);
4269  if (IsGeometry(argv[i]) == MagickFalse)
4270  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4271  break;
4272  }
4273  if (LocaleCompare("caption",option+1) == 0)
4274  {
4275  if (*option == '+')
4276  break;
4277  i++;
4278  if (i == (ssize_t) argc)
4279  ThrowMogrifyException(OptionError,"MissingArgument",option);
4280  break;
4281  }
4282  if (LocaleCompare("channel",option+1) == 0)
4283  {
4284  ssize_t
4285  channel;
4286 
4287  if (*option == '+')
4288  break;
4289  i++;
4290  if (i == (ssize_t) argc)
4291  ThrowMogrifyException(OptionError,"MissingArgument",option);
4292  channel=ParseChannelOption(argv[i]);
4293  if (channel < 0)
4294  ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4295  argv[i]);
4296  break;
4297  }
4298  if (LocaleCompare("channel-fx",option+1) == 0)
4299  {
4300  ssize_t
4301  channel;
4302 
4303  if (*option == '+')
4304  break;
4305  i++;
4306  if (i == (ssize_t) argc)
4307  ThrowMogrifyException(OptionError,"MissingArgument",option);
4308  channel=ParsePixelChannelOption(argv[i]);
4309  if (channel < 0)
4310  ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4311  argv[i]);
4312  break;
4313  }
4314  if (LocaleCompare("cdl",option+1) == 0)
4315  {
4316  if (*option == '+')
4317  break;
4318  i++;
4319  if (i == (ssize_t) argc)
4320  ThrowMogrifyException(OptionError,"MissingArgument",option);
4321  break;
4322  }
4323  if (LocaleCompare("charcoal",option+1) == 0)
4324  {
4325  if (*option == '+')
4326  break;
4327  i++;
4328  if (i == (ssize_t) argc)
4329  ThrowMogrifyException(OptionError,"MissingArgument",option);
4330  if (IsGeometry(argv[i]) == MagickFalse)
4331  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4332  break;
4333  }
4334  if (LocaleCompare("chop",option+1) == 0)
4335  {
4336  if (*option == '+')
4337  break;
4338  i++;
4339  if (i == (ssize_t) argc)
4340  ThrowMogrifyException(OptionError,"MissingArgument",option);
4341  if (IsGeometry(argv[i]) == MagickFalse)
4342  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4343  break;
4344  }
4345  if (LocaleCompare("clamp",option+1) == 0)
4346  break;
4347  if (LocaleCompare("clip",option+1) == 0)
4348  break;
4349  if (LocaleCompare("clip-mask",option+1) == 0)
4350  {
4351  if (*option == '+')
4352  break;
4353  i++;
4354  if (i == (ssize_t) argc)
4355  ThrowMogrifyException(OptionError,"MissingArgument",option);
4356  break;
4357  }
4358  if (LocaleCompare("clut",option+1) == 0)
4359  break;
4360  if (LocaleCompare("coalesce",option+1) == 0)
4361  break;
4362  if (LocaleCompare("colorize",option+1) == 0)
4363  {
4364  if (*option == '+')
4365  break;
4366  i++;
4367  if (i == (ssize_t) argc)
4368  ThrowMogrifyException(OptionError,"MissingArgument",option);
4369  if (IsGeometry(argv[i]) == MagickFalse)
4370  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4371  break;
4372  }
4373  if (LocaleCompare("color-matrix",option+1) == 0)
4374  {
4375  KernelInfo
4376  *kernel_info;
4377 
4378  if (*option == '+')
4379  break;
4380  i++;
4381  if (i == (ssize_t) argc)
4382  ThrowMogrifyException(OptionError,"MissingArgument",option);
4383  kernel_info=AcquireKernelInfo(argv[i],exception);
4384  if (kernel_info == (KernelInfo *) NULL)
4385  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4386  kernel_info=DestroyKernelInfo(kernel_info);
4387  break;
4388  }
4389  if (LocaleCompare("colors",option+1) == 0)
4390  {
4391  if (*option == '+')
4392  break;
4393  i++;
4394  if (i == (ssize_t) argc)
4395  ThrowMogrifyException(OptionError,"MissingArgument",option);
4396  if (IsGeometry(argv[i]) == MagickFalse)
4397  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4398  break;
4399  }
4400  if (LocaleCompare("colorspace",option+1) == 0)
4401  {
4402  ssize_t
4403  colorspace;
4404 
4405  if (*option == '+')
4406  break;
4407  i++;
4408  if (i == (ssize_t) argc)
4409  ThrowMogrifyException(OptionError,"MissingArgument",option);
4410  colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4411  argv[i]);
4412  if (colorspace < 0)
4413  ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4414  argv[i]);
4415  break;
4416  }
4417  if (LocaleCompare("combine",option+1) == 0)
4418  {
4419  ssize_t
4420  colorspace;
4421 
4422  if (*option == '+')
4423  break;
4424  i++;
4425  if (i == (ssize_t) argc)
4426  ThrowMogrifyException(OptionError,"MissingArgument",option);
4427  colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4428  argv[i]);
4429  if (colorspace < 0)
4430  ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4431  argv[i]);
4432  break;
4433  }
4434  if (LocaleCompare("compare",option+1) == 0)
4435  break;
4436  if (LocaleCompare("comment",option+1) == 0)
4437  {
4438  if (*option == '+')
4439  break;
4440  i++;
4441  if (i == (ssize_t) argc)
4442  ThrowMogrifyException(OptionError,"MissingArgument",option);
4443  break;
4444  }
4445  if (LocaleCompare("composite",option+1) == 0)
4446  break;
4447  if (LocaleCompare("compress",option+1) == 0)
4448  {
4449  ssize_t
4450  compress;
4451 
4452  if (*option == '+')
4453  break;
4454  i++;
4455  if (i == (ssize_t) argc)
4456  ThrowMogrifyException(OptionError,"MissingArgument",option);
4457  compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
4458  argv[i]);
4459  if (compress < 0)
4460  ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4461  argv[i]);
4462  break;
4463  }
4464  if (LocaleCompare("concurrent",option+1) == 0)
4465  break;
4466  if (LocaleCompare("connected-components",option+1) == 0)
4467  {
4468  i++;
4469  if (i == (ssize_t) argc)
4470  ThrowMogrifyException(OptionError,"MissingArgument",option);
4471  if (IsGeometry(argv[i]) == MagickFalse)
4472  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4473  break;
4474  }
4475  if (LocaleCompare("contrast",option+1) == 0)
4476  break;
4477  if (LocaleCompare("contrast-stretch",option+1) == 0)
4478  {
4479  i++;
4480  if (i == (ssize_t) argc)
4481  ThrowMogrifyException(OptionError,"MissingArgument",option);
4482  if (IsGeometry(argv[i]) == MagickFalse)
4483  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4484  break;
4485  }
4486  if (LocaleCompare("convolve",option+1) == 0)
4487  {
4488  KernelInfo
4489  *kernel_info;
4490 
4491  if (*option == '+')
4492  break;
4493  i++;
4494  if (i == (ssize_t) argc)
4495  ThrowMogrifyException(OptionError,"MissingArgument",option);
4496  kernel_info=AcquireKernelInfo(argv[i],exception);
4497  if (kernel_info == (KernelInfo *) NULL)
4498  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4499  kernel_info=DestroyKernelInfo(kernel_info);
4500  break;
4501  }
4502  if (LocaleCompare("copy",option+1) == 0)
4503  {
4504  if (*option == '+')
4505  break;
4506  i++;
4507  if (i == (ssize_t) argc)
4508  ThrowMogrifyException(OptionError,"MissingArgument",option);
4509  if (IsGeometry(argv[i]) == MagickFalse)
4510  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4511  i++;
4512  if (i == (ssize_t) argc)
4513  ThrowMogrifyException(OptionError,"MissingArgument",option);
4514  if (IsGeometry(argv[i]) == MagickFalse)
4515  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4516  break;
4517  }
4518  if (LocaleCompare("crop",option+1) == 0)
4519  {
4520  if (*option == '+')
4521  break;
4522  i++;
4523  if (i == (ssize_t) argc)
4524  ThrowMogrifyException(OptionError,"MissingArgument",option);
4525  if (IsGeometry(argv[i]) == MagickFalse)
4526  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4527  break;
4528  }
4529  if (LocaleCompare("cycle",option+1) == 0)
4530  {
4531  if (*option == '+')
4532  break;
4533  i++;
4534  if (i == (ssize_t) argc)
4535  ThrowMogrifyException(OptionError,"MissingArgument",option);
4536  if (IsGeometry(argv[i]) == MagickFalse)
4537  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4538  break;
4539  }
4540  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4541  }
4542  case 'd':
4543  {
4544  if (LocaleCompare("decipher",option+1) == 0)
4545  {
4546  if (*option == '+')
4547  break;
4548  i++;
4549  if (i == (ssize_t) argc)
4550  ThrowMogrifyException(OptionError,"MissingArgument",option);
4551  break;
4552  }
4553  if (LocaleCompare("deconstruct",option+1) == 0)
4554  break;
4555  if (LocaleCompare("debug",option+1) == 0)
4556  {
4557  ssize_t
4558  event;
4559 
4560  if (*option == '+')
4561  break;
4562  i++;
4563  if (i == (ssize_t) argc)
4564  ThrowMogrifyException(OptionError,"MissingArgument",option);
4565  event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
4566  if (event < 0)
4567  ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4568  argv[i]);
4569  (void) SetLogEventMask(argv[i]);
4570  break;
4571  }
4572  if (LocaleCompare("define",option+1) == 0)
4573  {
4574  i++;
4575  if (i == (ssize_t) argc)
4576  ThrowMogrifyException(OptionError,"MissingArgument",option);
4577  if (*option == '+')
4578  {
4579  const char
4580  *define;
4581 
4582  define=GetImageOption(image_info,argv[i]);
4583  if (define == (const char *) NULL)
4584  ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4585  break;
4586  }
4587  break;
4588  }
4589  if (LocaleCompare("delay",option+1) == 0)
4590  {
4591  if (*option == '+')
4592  break;
4593  i++;
4594  if (i == (ssize_t) argc)
4595  ThrowMogrifyException(OptionError,"MissingArgument",option);
4596  if (IsGeometry(argv[i]) == MagickFalse)
4597  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4598  break;
4599  }
4600  if (LocaleCompare("delete",option+1) == 0)
4601  {
4602  if (*option == '+')
4603  break;
4604  i++;
4605  if (i == (ssize_t) argc)
4606  ThrowMogrifyException(OptionError,"MissingArgument",option);
4607  if (IsGeometry(argv[i]) == MagickFalse)
4608  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4609  break;
4610  }
4611  if (LocaleCompare("density",option+1) == 0)
4612  {
4613  if (*option == '+')
4614  break;
4615  i++;
4616  if (i == (ssize_t) argc)
4617  ThrowMogrifyException(OptionError,"MissingArgument",option);
4618  if (IsGeometry(argv[i]) == MagickFalse)
4619  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4620  break;
4621  }
4622  if (LocaleCompare("depth",option+1) == 0)
4623  {
4624  if (*option == '+')
4625  break;
4626  i++;
4627  if (i == (ssize_t) argc)
4628  ThrowMogrifyException(OptionError,"MissingArgument",option);
4629  if (IsGeometry(argv[i]) == MagickFalse)
4630  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4631  break;
4632  }
4633  if (LocaleCompare("deskew",option+1) == 0)
4634  {
4635  if (*option == '+')
4636  break;
4637  i++;
4638  if (i == (ssize_t) argc)
4639  ThrowMogrifyException(OptionError,"MissingArgument",option);
4640  if (IsGeometry(argv[i]) == MagickFalse)
4641  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4642  break;
4643  }
4644  if (LocaleCompare("despeckle",option+1) == 0)
4645  break;
4646  if (LocaleCompare("dft",option+1) == 0)
4647  break;
4648  if (LocaleCompare("direction",option+1) == 0)
4649  {
4650  ssize_t
4651  direction;
4652 
4653  if (*option == '+')
4654  break;
4655  i++;
4656  if (i == (ssize_t) argc)
4657  ThrowMogrifyException(OptionError,"MissingArgument",option);
4658  direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
4659  argv[i]);
4660  if (direction < 0)
4661  ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4662  argv[i]);
4663  break;
4664  }
4665  if (LocaleCompare("display",option+1) == 0)
4666  {
4667  if (*option == '+')
4668  break;
4669  i++;
4670  if (i == (ssize_t) argc)
4671  ThrowMogrifyException(OptionError,"MissingArgument",option);
4672  break;
4673  }
4674  if (LocaleCompare("dispose",option+1) == 0)
4675  {
4676  ssize_t
4677  dispose;
4678 
4679  if (*option == '+')
4680  break;
4681  i++;
4682  if (i == (ssize_t) argc)
4683  ThrowMogrifyException(OptionError,"MissingArgument",option);
4684  dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,
4685  argv[i]);
4686  if (dispose < 0)
4687  ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4688  argv[i]);
4689  break;
4690  }
4691  if (LocaleCompare("distort",option+1) == 0)
4692  {
4693  ssize_t
4694  op;
4695 
4696  i++;
4697  if (i == (ssize_t) argc)
4698  ThrowMogrifyException(OptionError,"MissingArgument",option);
4699  op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
4700  if (op < 0)
4701  ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4702  argv[i]);
4703  i++;
4704  if (i == (ssize_t) argc)
4705  ThrowMogrifyException(OptionError,"MissingArgument",option);
4706  break;
4707  }
4708  if (LocaleCompare("dither",option+1) == 0)
4709  {
4710  ssize_t
4711  method;
4712 
4713  if (*option == '+')
4714  break;
4715  i++;
4716  if (i == (ssize_t) argc)
4717  ThrowMogrifyException(OptionError,"MissingArgument",option);
4718  method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
4719  if (method < 0)
4720  ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4721  argv[i]);
4722  break;
4723  }
4724  if (LocaleCompare("draw",option+1) == 0)
4725  {
4726  if (*option == '+')
4727  break;
4728  i++;
4729  if (i == (ssize_t) argc)
4730  ThrowMogrifyException(OptionError,"MissingArgument",option);
4731  break;
4732  }
4733  if (LocaleCompare("duplicate",option+1) == 0)
4734  {
4735  if (*option == '+')
4736  break;
4737  i++;
4738  if (i == (ssize_t) argc)
4739  ThrowMogrifyException(OptionError,"MissingArgument",option);
4740  if (IsGeometry(argv[i]) == MagickFalse)
4741  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4742  break;
4743  }
4744  if (LocaleCompare("duration",option+1) == 0)
4745  {
4746  if (*option == '+')
4747  break;
4748  i++;
4749  if (i == (ssize_t) argc)
4750  ThrowMogrifyException(OptionError,"MissingArgument",option);
4751  if (IsGeometry(argv[i]) == MagickFalse)
4752  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4753  break;
4754  }
4755  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4756  }
4757  case 'e':
4758  {
4759  if (LocaleCompare("edge",option+1) == 0)
4760  {
4761  if (*option == '+')
4762  break;
4763  i++;
4764  if (i == (ssize_t) argc)
4765  ThrowMogrifyException(OptionError,"MissingArgument",option);
4766  if (IsGeometry(argv[i]) == MagickFalse)
4767  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4768  break;
4769  }
4770  if (LocaleCompare("emboss",option+1) == 0)
4771  {
4772  if (*option == '+')
4773  break;
4774  i++;
4775  if (i == (ssize_t) argc)
4776  ThrowMogrifyException(OptionError,"MissingArgument",option);
4777  if (IsGeometry(argv[i]) == MagickFalse)
4778  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4779  break;
4780  }
4781  if (LocaleCompare("encipher",option+1) == 0)
4782  {
4783  if (*option == '+')
4784  break;
4785  i++;
4786  if (i == (ssize_t) argc)
4787  ThrowMogrifyException(OptionError,"MissingArgument",option);
4788  break;
4789  }
4790  if (LocaleCompare("encoding",option+1) == 0)
4791  {
4792  if (*option == '+')
4793  break;
4794  i++;
4795  if (i == (ssize_t) argc)
4796  ThrowMogrifyException(OptionError,"MissingArgument",option);
4797  break;
4798  }
4799  if (LocaleCompare("endian",option+1) == 0)
4800  {
4801  ssize_t
4802  endian;
4803 
4804  if (*option == '+')
4805  break;
4806  i++;
4807  if (i == (ssize_t) argc)
4808  ThrowMogrifyException(OptionError,"MissingArgument",option);
4809  endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
4810  if (endian < 0)
4811  ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4812  argv[i]);
4813  break;
4814  }
4815  if (LocaleCompare("enhance",option+1) == 0)
4816  break;
4817  if (LocaleCompare("equalize",option+1) == 0)
4818  break;
4819  if (LocaleCompare("evaluate",option+1) == 0)
4820  {
4821  ssize_t
4822  op;
4823 
4824  if (*option == '+')
4825  break;
4826  i++;
4827  if (i == (ssize_t) argc)
4828  ThrowMogrifyException(OptionError,"MissingArgument",option);
4829  op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4830  if (op < 0)
4831  ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4832  argv[i]);
4833  i++;
4834  if (i == (ssize_t) argc)
4835  ThrowMogrifyException(OptionError,"MissingArgument",option);
4836  if (IsGeometry(argv[i]) == MagickFalse)
4837  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4838  break;
4839  }
4840  if (LocaleCompare("evaluate-sequence",option+1) == 0)
4841  {
4842  ssize_t
4843  op;
4844 
4845  if (*option == '+')
4846  break;
4847  i++;
4848  if (i == (ssize_t) argc)
4849  ThrowMogrifyException(OptionError,"MissingArgument",option);
4850  op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4851  if (op < 0)
4852  ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4853  argv[i]);
4854  break;
4855  }
4856  if (LocaleCompare("extent",option+1) == 0)
4857  {
4858  if (*option == '+')
4859  break;
4860  i++;
4861  if (i == (ssize_t) argc)
4862  ThrowMogrifyException(OptionError,"MissingArgument",option);
4863  if (IsGeometry(argv[i]) == MagickFalse)
4864  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4865  break;
4866  }
4867  if (LocaleCompare("extract",option+1) == 0)
4868  {
4869  if (*option == '+')
4870  break;
4871  i++;
4872  if (i == (ssize_t) argc)
4873  ThrowMogrifyException(OptionError,"MissingArgument",option);
4874  if (IsGeometry(argv[i]) == MagickFalse)
4875  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4876  break;
4877  }
4878  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4879  }
4880  case 'f':
4881  {
4882  if (LocaleCompare("family",option+1) == 0)
4883  {
4884  if (*option == '+')
4885  break;
4886  i++;
4887  if (i == (ssize_t) argc)
4888  ThrowMogrifyException(OptionError,"MissingArgument",option);
4889  break;
4890  }
4891  if (LocaleCompare("features",option+1) == 0)
4892  {
4893  if (*option == '+')
4894  break;
4895  i++;
4896  if (i == (ssize_t) argc)
4897  ThrowMogrifyException(OptionError,"MissingArgument",option);
4898  if (IsGeometry(argv[i]) == MagickFalse)
4899  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4900  break;
4901  }
4902  if (LocaleCompare("fill",option+1) == 0)
4903  {
4904  if (*option == '+')
4905  break;
4906  i++;
4907  if (i == (ssize_t) argc)
4908  ThrowMogrifyException(OptionError,"MissingArgument",option);
4909  break;
4910  }
4911  if (LocaleCompare("filter",option+1) == 0)
4912  {
4913  ssize_t
4914  filter;
4915 
4916  if (*option == '+')
4917  break;
4918  i++;
4919  if (i == (ssize_t) argc)
4920  ThrowMogrifyException(OptionError,"MissingArgument",option);
4921  filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
4922  if (filter < 0)
4923  ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4924  argv[i]);
4925  break;
4926  }
4927  if (LocaleCompare("flatten",option+1) == 0)
4928  break;
4929  if (LocaleCompare("flip",option+1) == 0)
4930  break;
4931  if (LocaleCompare("flop",option+1) == 0)
4932  break;
4933  if (LocaleCompare("floodfill",option+1) == 0)
4934  {
4935  if (*option == '+')
4936  break;
4937  i++;
4938  if (i == (ssize_t) argc)
4939  ThrowMogrifyException(OptionError,"MissingArgument",option);
4940  if (IsGeometry(argv[i]) == MagickFalse)
4941  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4942  i++;
4943  if (i == (ssize_t) argc)
4944  ThrowMogrifyException(OptionError,"MissingArgument",option);
4945  break;
4946  }
4947  if (LocaleCompare("font",option+1) == 0)
4948  {
4949  if (*option == '+')
4950  break;
4951  i++;
4952  if (i == (ssize_t) argc)
4953  ThrowMogrifyException(OptionError,"MissingArgument",option);
4954  break;
4955  }
4956  if (LocaleCompare("format",option+1) == 0)
4957  {
4958  (void) CopyMagickString(argv[i]+1,"sans",MagickPathExtent);
4959  (void) CloneString(&format,(char *) NULL);
4960  if (*option == '+')
4961  break;
4962  i++;
4963  if (i == (ssize_t) argc)
4964  ThrowMogrifyException(OptionError,"MissingArgument",option);
4965  (void) CloneString(&format,argv[i]);
4966  (void) CopyMagickString(image_info->filename,format,
4968  (void) ConcatenateMagickString(image_info->filename,":",
4970  (void) SetImageInfo(image_info,0,exception);
4971  if (*image_info->magick == '\0')
4972  ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4973  format);
4974  break;
4975  }
4976  if (LocaleCompare("frame",option+1) == 0)
4977  {
4978  if (*option == '+')
4979  break;
4980  i++;
4981  if (i == (ssize_t) argc)
4982  ThrowMogrifyException(OptionError,"MissingArgument",option);
4983  if (IsGeometry(argv[i]) == MagickFalse)
4984  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4985  break;
4986  }
4987  if (LocaleCompare("function",option+1) == 0)
4988  {
4989  ssize_t
4990  op;
4991 
4992  if (*option == '+')
4993  break;
4994  i++;
4995  if (i == (ssize_t) argc)
4996  ThrowMogrifyException(OptionError,"MissingArgument",option);
4997  op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
4998  if (op < 0)
4999  ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
5000  i++;
5001  if (i == (ssize_t) argc)
5002  ThrowMogrifyException(OptionError,"MissingArgument",option);
5003  break;
5004  }
5005  if (LocaleCompare("fuzz",option+1) == 0)
5006  {
5007  if (*option == '+')
5008  break;
5009  i++;
5010  if (i == (ssize_t) argc)
5011  ThrowMogrifyException(OptionError,"MissingArgument",option);
5012  if (IsGeometry(argv[i]) == MagickFalse)
5013  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5014  break;
5015  }
5016  if (LocaleCompare("fx",option+1) == 0)
5017  {
5018  if (*option == '+')
5019  break;
5020  i++;
5021  if (i == (ssize_t) argc)
5022  ThrowMogrifyException(OptionError,"MissingArgument",option);
5023  break;
5024  }
5025  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5026  }
5027  case 'g':
5028  {
5029  if (LocaleCompare("gamma",option+1) == 0)
5030  {
5031  i++;
5032  if (i == (ssize_t) argc)
5033  ThrowMogrifyException(OptionError,"MissingArgument",option);
5034  if (IsGeometry(argv[i]) == MagickFalse)
5035  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5036  break;
5037  }
5038  if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5039  (LocaleCompare("gaussian",option+1) == 0))
5040  {
5041  i++;
5042  if (i == (ssize_t) argc)
5043  ThrowMogrifyException(OptionError,"MissingArgument",option);
5044  if (IsGeometry(argv[i]) == MagickFalse)
5045  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5046  break;
5047  }
5048  if (LocaleCompare("geometry",option+1) == 0)
5049  {
5050  if (*option == '+')
5051  break;
5052  i++;
5053  if (i == (ssize_t) argc)
5054  ThrowMogrifyException(OptionError,"MissingArgument",option);
5055  if (IsGeometry(argv[i]) == MagickFalse)
5056  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5057  break;
5058  }
5059  if (LocaleCompare("gravity",option+1) == 0)
5060  {
5061  ssize_t
5062  gravity;
5063 
5064  if (*option == '+')
5065  break;
5066  i++;
5067  if (i == (ssize_t) argc)
5068  ThrowMogrifyException(OptionError,"MissingArgument",option);
5069  gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
5070  argv[i]);
5071  if (gravity < 0)
5072  ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5073  argv[i]);
5074  break;
5075  }
5076  if (LocaleCompare("grayscale",option+1) == 0)
5077  {
5078  ssize_t
5079  method;
5080 
5081  if (*option == '+')
5082  break;
5083  i++;
5084  if (i == (ssize_t) argc)
5085  ThrowMogrifyException(OptionError,"MissingArgument",option);
5086  method=ParseCommandOption(MagickPixelIntensityOptions,MagickFalse,
5087  argv[i]);
5088  if (method < 0)
5089  ThrowMogrifyException(OptionError,"UnrecognizedIntensityMethod",
5090  argv[i]);
5091  break;
5092  }
5093  if (LocaleCompare("green-primary",option+1) == 0)
5094  {
5095  if (*option == '+')
5096  break;
5097  i++;
5098  if (i == (ssize_t) argc)
5099  ThrowMogrifyException(OptionError,"MissingArgument",option);
5100  if (IsGeometry(argv[i]) == MagickFalse)
5101  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5102  break;
5103  }
5104  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5105  }
5106  case 'h':
5107  {
5108  if (LocaleCompare("hald-clut",option+1) == 0)
5109  break;
5110  if ((LocaleCompare("help",option+1) == 0) ||
5111  (LocaleCompare("-help",option+1) == 0))
5112  return(MogrifyUsage());
5113  if (LocaleCompare("hough-lines",option+1) == 0)
5114  {
5115  if (*option == '+')
5116  break;
5117  i++;
5118  if (i == (ssize_t) argc)
5119  ThrowMogrifyException(OptionError,"MissingArgument",option);
5120  if (IsGeometry(argv[i]) == MagickFalse)
5121  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5122  break;
5123  }
5124  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5125  }
5126  case 'i':
5127  {
5128  if (LocaleCompare("identify",option+1) == 0)
5129  break;
5130  if (LocaleCompare("idft",option+1) == 0)
5131  break;
5132  if (LocaleCompare("implode",option+1) == 0)
5133  {
5134  if (*option == '+')
5135  break;
5136  i++;
5137  if (i == (ssize_t) argc)
5138  ThrowMogrifyException(OptionError,"MissingArgument",option);
5139  if (IsGeometry(argv[i]) == MagickFalse)
5140  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5141  break;
5142  }
5143  if (LocaleCompare("intensity",option+1) == 0)
5144  {
5145  ssize_t
5146  intensity;
5147 
5148  if (*option == '+')
5149  break;
5150  i++;
5151  if (i == (ssize_t) argc)
5152  ThrowMogrifyException(OptionError,"MissingArgument",option);
5153  intensity=ParseCommandOption(MagickPixelIntensityOptions,
5154  MagickFalse,argv[i]);
5155  if (intensity < 0)
5156  ThrowMogrifyException(OptionError,
5157  "UnrecognizedPixelIntensityMethod",argv[i]);
5158  break;
5159  }
5160  if (LocaleCompare("intent",option+1) == 0)
5161  {
5162  ssize_t
5163  intent;
5164 
5165  if (*option == '+')
5166  break;
5167  i++;
5168  if (i == (ssize_t) argc)
5169  ThrowMogrifyException(OptionError,"MissingArgument",option);
5170  intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
5171  if (intent < 0)
5172  ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5173  argv[i]);
5174  break;
5175  }
5176  if (LocaleCompare("interlace",option+1) == 0)
5177  {
5178  ssize_t
5179  interlace;
5180 
5181  if (*option == '+')
5182  break;
5183  i++;
5184  if (i == (ssize_t) argc)
5185  ThrowMogrifyException(OptionError,"MissingArgument",option);
5186  interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
5187  argv[i]);
5188  if (interlace < 0)
5189  ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5190  argv[i]);
5191  break;
5192  }
5193  if (LocaleCompare("interline-spacing",option+1) == 0)
5194  {
5195  if (*option == '+')
5196  break;
5197  i++;
5198  if (i == (ssize_t) argc)
5199  ThrowMogrifyException(OptionError,"MissingArgument",option);
5200  if (IsGeometry(argv[i]) == MagickFalse)
5201  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5202  break;
5203  }
5204  if (LocaleCompare("interpolate",option+1) == 0)
5205  {
5206  ssize_t
5207  interpolate;
5208 
5209  if (*option == '+')
5210  break;
5211  i++;
5212  if (i == (ssize_t) argc)
5213  ThrowMogrifyException(OptionError,"MissingArgument",option);
5214  interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
5215  argv[i]);
5216  if (interpolate < 0)
5217  ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5218  argv[i]);
5219  break;
5220  }
5221  if (LocaleCompare("interword-spacing",option+1) == 0)
5222  {
5223  if (*option == '+')
5224  break;
5225  i++;
5226  if (i == (ssize_t) argc)
5227  ThrowMogrifyException(OptionError,"MissingArgument",option);
5228  if (IsGeometry(argv[i]) == MagickFalse)
5229  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5230  break;
5231  }
5232  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5233  }
5234  case 'k':
5235  {
5236  if (LocaleCompare("kerning",option+1) == 0)
5237  {
5238  if (*option == '+')
5239  break;
5240  i++;
5241  if (i == (ssize_t) argc)
5242  ThrowMogrifyException(OptionError,"MissingArgument",option);
5243  if (IsGeometry(argv[i]) == MagickFalse)
5244  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5245  break;
5246  }
5247  if (LocaleCompare("kuwahara",option+1) == 0)
5248  {
5249  i++;
5250  if (i == (ssize_t) argc)
5251  ThrowMogrifyException(OptionError,"MissingArgument",option);
5252  if (IsGeometry(argv[i]) == MagickFalse)
5253  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5254  break;
5255  }
5256  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5257  }
5258  case 'l':
5259  {
5260  if (LocaleCompare("label",option+1) == 0)
5261  {
5262  if (*option == '+')
5263  break;
5264  i++;
5265  if (i == (ssize_t) argc)
5266  ThrowMogrifyException(OptionError,"MissingArgument",option);
5267  break;
5268  }
5269  if (LocaleCompare("lat",option+1) == 0)
5270  {
5271  if (*option == '+')
5272  break;
5273  i++;
5274  if (i == (ssize_t) argc)
5275  ThrowMogrifyException(OptionError,"MissingArgument",option);
5276  if (IsGeometry(argv[i]) == MagickFalse)
5277  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5278  }
5279  if (LocaleCompare("layers",option+1) == 0)
5280  {
5281  ssize_t
5282  type;
5283 
5284  if (*option == '+')
5285  break;
5286  i++;
5287  if (i == (ssize_t) argc)
5288  ThrowMogrifyException(OptionError,"MissingArgument",option);
5289  type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
5290  if (type < 0)
5291  ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5292  argv[i]);
5293  break;
5294  }
5295  if (LocaleCompare("level",option+1) == 0)
5296  {
5297  i++;
5298  if (i == (ssize_t) argc)
5299  ThrowMogrifyException(OptionError,"MissingArgument",option);
5300  if (IsGeometry(argv[i]) == MagickFalse)
5301  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5302  break;
5303  }
5304  if (LocaleCompare("level-colors",option+1) == 0)
5305  {
5306  i++;
5307  if (i == (ssize_t) argc)
5308  ThrowMogrifyException(OptionError,"MissingArgument",option);
5309  break;
5310  }
5311  if (LocaleCompare("limit",option+1) == 0)
5312  {
5313  char
5314  *p;
5315 
5316  double
5317  value;
5318 
5319  ssize_t
5320  resource;
5321 
5322  if (*option == '+')
5323  break;
5324  i++;
5325  if (i == (ssize_t) argc)
5326  ThrowMogrifyException(OptionError,"MissingArgument",option);
5327  resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
5328  argv[i]);
5329  if (resource < 0)
5330  ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5331  argv[i]);
5332  i++;
5333  if (i == (ssize_t) argc)
5334  ThrowMogrifyException(OptionError,"MissingArgument",option);
5335  value=StringToDouble(argv[i],&p);
5336  (void) value;
5337  if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5338  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5339  break;
5340  }
5341  if (LocaleCompare("liquid-rescale",option+1) == 0)
5342  {
5343  i++;
5344  if (i == (ssize_t) argc)
5345  ThrowMogrifyException(OptionError,"MissingArgument",option);
5346  if (IsGeometry(argv[i]) == MagickFalse)
5347  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5348  break;
5349  }
5350  if (LocaleCompare("list",option+1) == 0)
5351  {
5352  ssize_t
5353  list;
5354 
5355  if (*option == '+')
5356  break;
5357  i++;
5358  if (i == (ssize_t) argc)
5359  ThrowMogrifyException(OptionError,"MissingArgument",option);
5360  list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
5361  if (list < 0)
5362  ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
5363  status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
5364  argv+j,exception);
5365  return(status == 0 ? MagickTrue : MagickFalse);
5366  }
5367  if (LocaleCompare("log",option+1) == 0)
5368  {
5369  if (*option == '+')
5370  break;
5371  i++;
5372  if ((i == (ssize_t) argc) ||
5373  (strchr(argv[i],'%') == (char *) NULL))
5374  ThrowMogrifyException(OptionError,"MissingArgument",option);
5375  break;
5376  }
5377  if (LocaleCompare("loop",option+1) == 0)
5378  {
5379  if (*option == '+')
5380  break;
5381  i++;
5382  if (i == (ssize_t) argc)
5383  ThrowMogrifyException(OptionError,"MissingArgument",option);
5384  if (IsGeometry(argv[i]) == MagickFalse)
5385  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5386  break;
5387  }
5388  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5389  }
5390  case 'm':
5391  {
5392  if (LocaleCompare("map",option+1) == 0)
5393  {
5394  global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5395  if (*option == '+')
5396  break;
5397  i++;
5398  if (i == (ssize_t) argc)
5399  ThrowMogrifyException(OptionError,"MissingArgument",option);
5400  break;
5401  }
5402  if (LocaleCompare("mask",option+1) == 0)
5403  {
5404  if (*option == '+')
5405  break;
5406  i++;
5407  if (i == (ssize_t) argc)
5408  ThrowMogrifyException(OptionError,"MissingArgument",option);
5409  break;
5410  }
5411  if (LocaleCompare("matte",option+1) == 0)
5412  break;
5413  if (LocaleCompare("mattecolor",option+1) == 0)
5414  {
5415  if (*option == '+')
5416  break;
5417  i++;
5418  if (i == (ssize_t) argc)
5419  ThrowMogrifyException(OptionError,"MissingArgument",option);
5420  break;
5421  }
5422  if (LocaleCompare("maximum",option+1) == 0)
5423  break;
5424  if (LocaleCompare("mean-shift",option+1) == 0)
5425  {
5426  if (*option == '+')
5427  break;
5428  i++;
5429  if (i == (ssize_t) argc)
5430  ThrowMogrifyException(OptionError,"MissingArgument",option);
5431  if (IsGeometry(argv[i]) == MagickFalse)
5432  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5433  break;
5434  }
5435  if (LocaleCompare("median",option+1) == 0)
5436  {
5437  if (*option == '+')
5438  break;
5439  i++;
5440  if (i == (ssize_t) argc)
5441  ThrowMogrifyException(OptionError,"MissingArgument",option);
5442  if (IsGeometry(argv[i]) == MagickFalse)
5443  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5444  break;
5445  }
5446  if (LocaleCompare("metric",option+1) == 0)
5447  {
5448  ssize_t
5449  type;
5450 
5451  if (*option == '+')
5452  break;
5453  i++;
5454  if (i == (ssize_t) argc)
5455  ThrowMogrifyException(OptionError,"MissingArgument",option);
5456  type=ParseCommandOption(MagickMetricOptions,MagickTrue,argv[i]);
5457  if (type < 0)
5458  ThrowMogrifyException(OptionError,"UnrecognizedMetricType",
5459  argv[i]);
5460  break;
5461  }
5462  if (LocaleCompare("minimum",option+1) == 0)
5463  break;
5464  if (LocaleCompare("modulate",option+1) == 0)
5465  {
5466  if (*option == '+')
5467  break;
5468  i++;
5469  if (i == (ssize_t) argc)
5470  ThrowMogrifyException(OptionError,"MissingArgument",option);
5471  if (IsGeometry(argv[i]) == MagickFalse)
5472  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5473  break;
5474  }
5475  if (LocaleCompare("mode",option+1) == 0)
5476  {
5477  if (*option == '+')
5478  break;
5479  i++;
5480  if (i == (ssize_t) argc)
5481  ThrowMogrifyException(OptionError,"MissingArgument",option);
5482  if (IsGeometry(argv[i]) == MagickFalse)
5483  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5484  break;
5485  }
5486  if (LocaleCompare("monitor",option+1) == 0)
5487  break;
5488  if (LocaleCompare("monochrome",option+1) == 0)
5489  break;
5490  if (LocaleCompare("morph",option+1) == 0)
5491  {
5492  if (*option == '+')
5493  break;
5494  i++;
5495  if (i == (ssize_t) argc)
5496  ThrowMogrifyException(OptionError,"MissingArgument",option);
5497  if (IsGeometry(argv[i]) == MagickFalse)
5498  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5499  break;
5500  }
5501  if (LocaleCompare("morphology",option+1) == 0)
5502  {
5503  char
5504  token[MagickPathExtent];
5505 
5506  KernelInfo
5507  *kernel_info;
5508 
5509  ssize_t
5510  op;
5511 
5512  i++;
5513  if (i == (ssize_t) argc)
5514  ThrowMogrifyException(OptionError,"MissingArgument",option);
5515  GetNextToken(argv[i],(const char **) NULL,MagickPathExtent,token);
5516  op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
5517  if (op < 0)
5518  ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
5519  token);
5520  i++;
5521  if (i == (ssize_t) argc)
5522  ThrowMogrifyException(OptionError,"MissingArgument",option);
5523  kernel_info=AcquireKernelInfo(argv[i],exception);
5524  if (kernel_info == (KernelInfo *) NULL)
5525  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5526  kernel_info=DestroyKernelInfo(kernel_info);
5527  break;
5528  }
5529  if (LocaleCompare("mosaic",option+1) == 0)
5530  break;
5531  if (LocaleCompare("motion-blur",option+1) == 0)
5532  {
5533  if (*option == '+')
5534  break;
5535  i++;
5536  if (i == (ssize_t) argc)
5537  ThrowMogrifyException(OptionError,"MissingArgument",option);
5538  if (IsGeometry(argv[i]) == MagickFalse)
5539  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5540  break;
5541  }
5542  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5543  }
5544  case 'n':
5545  {
5546  if (LocaleCompare("negate",option+1) == 0)
5547  break;
5548  if (LocaleCompare("noise",option+1) == 0)
5549  {
5550  i++;
5551  if (i == (ssize_t) argc)
5552  ThrowMogrifyException(OptionError,"MissingArgument",option);
5553  if (*option == '+')
5554  {
5555  ssize_t
5556  noise;
5557 
5558  noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,
5559  argv[i]);
5560  if (noise < 0)
5561  ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5562  argv[i]);
5563  break;
5564  }
5565  if (IsGeometry(argv[i]) == MagickFalse)
5566  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5567  break;
5568  }
5569  if (LocaleCompare("noop",option+1) == 0)
5570  break;
5571  if (LocaleCompare("normalize",option+1) == 0)
5572  break;
5573  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5574  }
5575  case 'o':
5576  {
5577  if (LocaleCompare("opaque",option+1) == 0)
5578  {
5579  i++;
5580  if (i == (ssize_t) argc)
5581  ThrowMogrifyException(OptionError,"MissingArgument",option);
5582  break;
5583  }
5584  if (LocaleCompare("ordered-dither",option+1) == 0)
5585  {
5586  if (*option == '+')
5587  break;
5588  i++;
5589  if (i == (ssize_t) argc)
5590  ThrowMogrifyException(OptionError,"MissingArgument",option);
5591  break;
5592  }
5593  if (LocaleCompare("orient",option+1) == 0)
5594  {
5595  ssize_t
5596  orientation;
5597 
5598  orientation=UndefinedOrientation;
5599  if (*option == '+')
5600  break;
5601  i++;
5602  if (i == (ssize_t) argc)
5603  ThrowMogrifyException(OptionError,"MissingArgument",option);
5604  orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
5605  argv[i]);
5606  if (orientation < 0)
5607  ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5608  argv[i]);
5609  break;
5610  }
5611  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5612  }
5613  case 'p':
5614  {
5615  if (LocaleCompare("page",option+1) == 0)
5616  {
5617  if (*option == '+')
5618  break;
5619  i++;
5620  if (i == (ssize_t) argc)
5621  ThrowMogrifyException(OptionError,"MissingArgument",option);
5622  break;
5623  }
5624  if (LocaleCompare("paint",option+1) == 0)
5625  {
5626  if (*option == '+')
5627  break;
5628  i++;
5629  if (i == (ssize_t) argc)
5630  ThrowMogrifyException(OptionError,"MissingArgument",option);
5631  if (IsGeometry(argv[i]) == MagickFalse)
5632  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5633  break;
5634  }
5635  if (LocaleCompare("path",option+1) == 0)
5636  {
5637  (void) CloneString(&path,(char *) NULL);
5638  if (*option == '+')
5639  break;
5640  i++;
5641  if (i == (ssize_t) argc)
5642  ThrowMogrifyException(OptionError,"MissingArgument",option);
5643  (void) CloneString(&path,argv[i]);
5644  break;
5645  }
5646  if (LocaleCompare("perceptible",option+1) == 0)
5647  {
5648  if (*option == '+')
5649  break;
5650  i++;
5651  if (i == (ssize_t) argc)
5652  ThrowMogrifyException(OptionError,"MissingArgument",option);
5653  if (IsGeometry(argv[i]) == MagickFalse)
5654  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5655  break;
5656  }
5657  if (LocaleCompare("pointsize",option+1) == 0)
5658  {
5659  if (*option == '+')
5660  break;
5661  i++;
5662  if (i == (ssize_t) argc)
5663  ThrowMogrifyException(OptionError,"MissingArgument",option);
5664  if (IsGeometry(argv[i]) == MagickFalse)
5665  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5666  break;
5667  }
5668  if (LocaleCompare("polaroid",option+1) == 0)
5669  {
5670  if (*option == '+')
5671  break;
5672  i++;
5673  if (i == (ssize_t) argc)
5674  ThrowMogrifyException(OptionError,"MissingArgument",option);
5675  if (IsGeometry(argv[i]) == MagickFalse)
5676  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5677  break;
5678  }
5679  if (LocaleCompare("poly",option+1) == 0)
5680  {
5681  if (*option == '+')
5682  break;
5683  i++;
5684  if (i == (ssize_t) argc)
5685  ThrowMogrifyException(OptionError,"MissingArgument",option);
5686  if (IsGeometry(argv[i]) == MagickFalse)
5687  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5688  break;
5689  }
5690  if (LocaleCompare("posterize",option+1) == 0)
5691  {
5692  if (*option == '+')
5693  break;
5694  i++;
5695  if (i == (ssize_t) argc)
5696  ThrowMogrifyException(OptionError,"MissingArgument",option);
5697  if (IsGeometry(argv[i]) == MagickFalse)
5698  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5699  break;
5700  }
5701  if (LocaleCompare("precision",option+1) == 0)
5702  {
5703  if (*option == '+')
5704  break;
5705  i++;
5706  if (i == (ssize_t) argc)
5707  ThrowMogrifyException(OptionError,"MissingArgument",option);
5708  if (IsGeometry(argv[i]) == MagickFalse)
5709  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5710  break;
5711  }
5712  if (LocaleCompare("print",option+1) == 0)
5713  {
5714  if (*option == '+')
5715  break;
5716  i++;
5717  if (i == (ssize_t) argc)
5718  ThrowMogrifyException(OptionError,"MissingArgument",option);
5719  break;
5720  }
5721  if (LocaleCompare("process",option+1) == 0)
5722  {
5723  if (*option == '+')
5724  break;
5725  i++;
5726  if (i == (ssize_t) argc)
5727  ThrowMogrifyException(OptionError,"MissingArgument",option);
5728  break;
5729  }
5730  if (LocaleCompare("profile",option+1) == 0)
5731  {
5732  i++;
5733  if (i == (ssize_t) argc)
5734  ThrowMogrifyException(OptionError,"MissingArgument",option);
5735  break;
5736  }
5737  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5738  }
5739  case 'q':
5740  {
5741  if (LocaleCompare("quality",option+1) == 0)
5742  {
5743  if (*option == '+')
5744  break;
5745  i++;
5746  if (i == (ssize_t) argc)
5747  ThrowMogrifyException(OptionError,"MissingArgument",option);
5748  if (IsGeometry(argv[i]) == MagickFalse)
5749  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5750  break;
5751  }
5752  if (LocaleCompare("quantize",option+1) == 0)
5753  {
5754  ssize_t
5755  colorspace;
5756 
5757  if (*option == '+')
5758  break;
5759  i++;
5760  if (i == (ssize_t) argc)
5761  ThrowMogrifyException(OptionError,"MissingArgument",option);
5762  colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
5763  argv[i]);
5764  if (colorspace < 0)
5765  ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5766  argv[i]);
5767  break;
5768  }
5769  if (LocaleCompare("quiet",option+1) == 0)
5770  break;
5771  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5772  }
5773  case 'r':
5774  {
5775  if (LocaleCompare("rotational-blur",option+1) == 0)
5776  {
5777  i++;
5778  if (i == (ssize_t) argc)
5779  ThrowMogrifyException(OptionError,"MissingArgument",option);
5780  if (IsGeometry(argv[i]) == MagickFalse)
5781  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5782  break;
5783  }
5784  if (LocaleCompare("raise",option+1) == 0)
5785  {
5786  i++;
5787  if (i == (ssize_t) argc)
5788  ThrowMogrifyException(OptionError,"MissingArgument",option);
5789  if (IsGeometry(argv[i]) == MagickFalse)
5790  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5791  break;
5792  }
5793  if (LocaleCompare("random-threshold",option+1) == 0)
5794  {
5795  if (*option == '+')
5796  break;
5797  i++;
5798  if (i == (ssize_t) argc)
5799  ThrowMogrifyException(OptionError,"MissingArgument",option);
5800  if (IsGeometry(argv[i]) == MagickFalse)
5801  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5802  break;
5803  }
5804  if (LocaleCompare("read-mask",option+1) == 0)
5805  {
5806  if (*option == '+')
5807  break;
5808  i++;
5809  if (i == (ssize_t) argc)
5810  ThrowMogrifyException(OptionError,"MissingArgument",option);
5811  break;
5812  }
5813  if (LocaleCompare("red-primary",option+1) == 0)
5814  {
5815  if (*option == '+')
5816  break;
5817  i++;
5818  if (i == (ssize_t) argc)
5819  ThrowMogrifyException(OptionError,"MissingArgument",option);
5820  if (IsGeometry(argv[i]) == MagickFalse)
5821  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5822  }
5823  if (LocaleCompare("regard-warnings",option+1) == 0)
5824  break;
5825  if (LocaleCompare("region",option+1) == 0)
5826  {
5827  if (*option == '+')
5828  break;
5829  i++;
5830  if (i == (ssize_t) argc)
5831  ThrowMogrifyException(OptionError,"MissingArgument",option);
5832  if (IsGeometry(argv[i]) == MagickFalse)
5833  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5834  break;
5835  }
5836  if (LocaleCompare("remap",option+1) == 0)
5837  {
5838  if (*option == '+')
5839  break;
5840  i++;
5841  if (i == (ssize_t) argc)
5842  ThrowMogrifyException(OptionError,"MissingArgument",option);
5843  break;
5844  }
5845  if (LocaleCompare("render",option+1) == 0)
5846  break;
5847  if (LocaleCompare("repage",option+1) == 0)
5848  {
5849  if (*option == '+')
5850  break;
5851  i++;
5852  if (i == (ssize_t) argc)
5853  ThrowMogrifyException(OptionError,"MissingArgument",option);
5854  if (IsGeometry(argv[i]) == MagickFalse)
5855  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5856  break;
5857  }
5858  if (LocaleCompare("resample",option+1) == 0)
5859  {
5860  if (*option == '+')
5861  break;
5862  i++;
5863  if (i == (ssize_t) argc)
5864  ThrowMogrifyException(OptionError,"MissingArgument",option);
5865  if (IsGeometry(argv[i]) == MagickFalse)
5866  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5867  break;
5868  }
5869  if (LocaleCompare("resize",option+1) == 0)
5870  {
5871  if (*option == '+')
5872  break;
5873  i++;
5874  if (i == (ssize_t) argc)
5875  ThrowMogrifyException(OptionError,"MissingArgument",option);
5876  if (IsGeometry(argv[i]) == MagickFalse)
5877  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5878  break;
5879  }
5880  if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5881  {
5882  respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5883  break;
5884  }
5885  if (LocaleCompare("reverse",option+1) == 0)
5886  break;
5887  if (LocaleCompare("roll",option+1) == 0)
5888  {
5889  if (*option == '+')
5890  break;
5891  i++;
5892  if (i == (ssize_t) argc)
5893  ThrowMogrifyException(OptionError,"MissingArgument",option);
5894  if (IsGeometry(argv[i]) == MagickFalse)
5895  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5896  break;
5897  }
5898  if (LocaleCompare("rotate",option+1) == 0)
5899  {
5900  i++;
5901  if (i == (ssize_t) argc)
5902  ThrowMogrifyException(OptionError,"MissingArgument",option);
5903  if (IsGeometry(argv[i]) == MagickFalse)
5904  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5905  break;
5906  }
5907  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5908  }
5909  case 's':
5910  {
5911  if (LocaleCompare("sample",option+1) == 0)
5912  {
5913  if (*option == '+')
5914  break;
5915  i++;
5916  if (i == (ssize_t) argc)
5917  ThrowMogrifyException(OptionError,"MissingArgument",option);
5918  if (IsGeometry(argv[i]) == MagickFalse)
5919  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5920  break;
5921  }
5922  if (LocaleCompare("sampling-factor",option+1) == 0)
5923  {
5924  if (*option == '+')
5925  break;
5926  i++;
5927  if (i == (ssize_t) argc)
5928  ThrowMogrifyException(OptionError,"MissingArgument",option);
5929  if (IsGeometry(argv[i]) == MagickFalse)
5930  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5931  break;
5932  }
5933  if (LocaleCompare("scale",option+1) == 0)
5934  {
5935  if (*option == '+')
5936  break;
5937  i++;
5938  if (i == (ssize_t) argc)
5939  ThrowMogrifyException(OptionError,"MissingArgument",option);
5940  if (IsGeometry(argv[i]) == MagickFalse)
5941  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5942  break;
5943  }
5944  if (LocaleCompare("scene",option+1) == 0)
5945  {
5946  if (*option == '+')
5947  break;
5948  i++;
5949  if (i == (ssize_t) argc)
5950  ThrowMogrifyException(OptionError,"MissingArgument",option);
5951  if (IsGeometry(argv[i]) == MagickFalse)
5952  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5953  break;
5954  }
5955  if (LocaleCompare("seed",option+1) == 0)
5956  {
5957  if (*option == '+')
5958  break;
5959  i++;
5960  if (i == (ssize_t) argc)
5961  ThrowMogrifyException(OptionError,"MissingArgument",option);
5962  if (IsGeometry(argv[i]) == MagickFalse)
5963  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5964  break;
5965  }
5966  if (LocaleCompare("segment",option+1) == 0)
5967  {
5968  if (*option == '+')
5969  break;
5970  i++;
5971  if (i == (ssize_t) argc)
5972  ThrowMogrifyException(OptionError,"MissingArgument",option);
5973  if (IsGeometry(argv[i]) == MagickFalse)
5974  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5975  break;
5976  }
5977  if (LocaleCompare("selective-blur",option+1) == 0)
5978  {
5979  i++;
5980  if (i == (ssize_t) argc)
5981  ThrowMogrifyException(OptionError,"MissingArgument",option);
5982  if (IsGeometry(argv[i]) == MagickFalse)
5983  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5984  break;
5985  }
5986  if (LocaleCompare("separate",option+1) == 0)
5987  break;
5988  if (LocaleCompare("sepia-tone",option+1) == 0)
5989  {
5990  if (*option == '+')
5991  break;
5992  i++;
5993  if (i == (ssize_t) argc)
5994  ThrowMogrifyException(OptionError,"MissingArgument",option);
5995  if (IsGeometry(argv[i]) == MagickFalse)
5996  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5997  break;
5998  }
5999  if (LocaleCompare("set",option+1) == 0)
6000  {
6001  i++;
6002  if (i == (ssize_t) argc)
6003  ThrowMogrifyException(OptionError,"MissingArgument",option);
6004  if (*option == '+')
6005  break;
6006  i++;
6007  if (i == (ssize_t) argc)
6008  ThrowMogrifyException(OptionError,"MissingArgument",option);
6009  break;
6010  }
6011  if (LocaleCompare("shade",option+1) == 0)
6012  {
6013  i++;
6014  if (i == (ssize_t) argc)
6015  ThrowMogrifyException(OptionError,"MissingArgument",option);
6016  if (IsGeometry(argv[i]) == MagickFalse)
6017  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6018  break;
6019  }
6020  if (LocaleCompare("shadow",option+1) == 0)
6021  {
6022  if (*option == '+')
6023  break;
6024  i++;
6025  if (i == (ssize_t) argc)
6026  ThrowMogrifyException(OptionError,"MissingArgument",option);
6027  if (IsGeometry(argv[i]) == MagickFalse)
6028  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6029  break;
6030  }
6031  if (LocaleCompare("sharpen",option+1) == 0)
6032  {
6033  i++;
6034  if (i == (ssize_t) argc)
6035  ThrowMogrifyException(OptionError,"MissingArgument",option);
6036  if (IsGeometry(argv[i]) == MagickFalse)
6037  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6038  break;
6039  }
6040  if (LocaleCompare("shave",option+1) == 0)
6041  {
6042  if (*option == '+')
6043  break;
6044  i++;
6045  if (i == (ssize_t) argc)
6046  ThrowMogrifyException(OptionError,"MissingArgument",option);
6047  if (IsGeometry(argv[i]) == MagickFalse)
6048  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6049  break;
6050  }
6051  if (LocaleCompare("shear",option+1) == 0)
6052  {
6053  i++;
6054  if (i == (ssize_t) argc)
6055  ThrowMogrifyException(OptionError,"MissingArgument",option);
6056  if (IsGeometry(argv[i]) == MagickFalse)
6057  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6058  break;
6059  }
6060  if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
6061  {
6062  i++;
6063  if (i == (ssize_t) argc)
6064  ThrowMogrifyException(OptionError,"MissingArgument",option);
6065  if (IsGeometry(argv[i]) == MagickFalse)
6066  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6067  break;
6068  }
6069  if (LocaleCompare("size",option+1) == 0)
6070  {
6071  if (*option == '+')
6072  break;
6073  i++;
6074  if (i == (ssize_t) argc)
6075  ThrowMogrifyException(OptionError,"MissingArgument",option);
6076  if (IsGeometry(argv[i]) == MagickFalse)
6077  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6078  break;
6079  }
6080  if (LocaleCompare("sketch",option+1) == 0)
6081  {
6082  if (*option == '+')
6083  break;
6084  i++;
6085  if (i == (ssize_t) argc)
6086  ThrowMogrifyException(OptionError,"MissingArgument",option);
6087  if (IsGeometry(argv[i]) == MagickFalse)
6088  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6089  break;
6090  }
6091  if (LocaleCompare("smush",option+1) == 0)
6092  {
6093  i++;
6094  if (i == (ssize_t) argc)
6095  ThrowMogrifyException(OptionError,"MissingArgument",option);
6096  if (IsGeometry(argv[i]) == MagickFalse)
6097  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6098  i++;
6099  break;
6100  }
6101  if (LocaleCompare("solarize",option+1) == 0)
6102  {
6103  if (*option == '+')
6104  break;
6105  i++;
6106  if (i == (ssize_t) argc)
6107  ThrowMogrifyException(OptionError,"MissingArgument",option);
6108  if (IsGeometry(argv[i]) == MagickFalse)
6109  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6110  break;
6111  }
6112  if (LocaleCompare("sparse-color",option+1) == 0)
6113  {
6114  ssize_t
6115  op;
6116 
6117  i++;
6118  if (i == (ssize_t) argc)
6119  ThrowMogrifyException(OptionError,"MissingArgument",option);
6120  op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
6121  if (op < 0)
6122  ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
6123  argv[i]);
6124  i++;
6125  if (i == (ssize_t) argc)
6126  ThrowMogrifyException(OptionError,"MissingArgument",option);
6127  break;
6128  }
6129  if (LocaleCompare("splice",option+1) == 0)
6130  {
6131  if (*option == '+')
6132  break;
6133  i++;
6134  if (i == (ssize_t) argc)
6135  ThrowMogrifyException(OptionError,"MissingArgument",option);
6136  if (IsGeometry(argv[i]) == MagickFalse)
6137  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6138  break;
6139  }
6140  if (LocaleCompare("spread",option+1) == 0)
6141  {
6142  if (*option == '+')
6143  break;
6144  i++;
6145  if (i == (ssize_t) argc)
6146  ThrowMogrifyException(OptionError,"MissingArgument",option);
6147  if (IsGeometry(argv[i]) == MagickFalse)
6148  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6149  break;
6150  }
6151  if (LocaleCompare("statistic",option+1) == 0)
6152  {
6153  ssize_t
6154  op;
6155 
6156  if (*option == '+')
6157  break;
6158  i++;
6159  if (i == (ssize_t) argc)
6160  ThrowMogrifyException(OptionError,"MissingArgument",option);
6161  op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
6162  if (op < 0)
6163  ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
6164  argv[i]);
6165  i++;
6166  if (i == (ssize_t) argc)
6167  ThrowMogrifyException(OptionError,"MissingArgument",option);
6168  if (IsGeometry(argv[i]) == MagickFalse)
6169  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6170  break;
6171  }
6172  if (LocaleCompare("stretch",option+1) == 0)
6173  {
6174  ssize_t
6175  stretch;
6176 
6177  if (*option == '+')
6178  break;
6179  i++;
6180  if (i == (ssize_t) argc)
6181  ThrowMogrifyException(OptionError,"MissingArgument",option);
6182  stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,
6183  argv[i]);
6184  if (stretch < 0)
6185  ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6186  argv[i]);
6187  break;
6188  }
6189  if (LocaleCompare("strip",option+1) == 0)
6190  break;
6191  if (LocaleCompare("stroke",option+1) == 0)
6192  {
6193  if (*option == '+')
6194  break;
6195  i++;
6196  if (i == (ssize_t) argc)
6197  ThrowMogrifyException(OptionError,"MissingArgument",option);
6198  break;
6199  }
6200  if (LocaleCompare("strokewidth",option+1) == 0)
6201  {
6202  if (*option == '+')
6203  break;
6204  i++;
6205  if (i == (ssize_t) argc)
6206  ThrowMogrifyException(OptionError,"MissingArgument",option);
6207  if (IsGeometry(argv[i]) == MagickFalse)
6208  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6209  break;
6210  }
6211  if (LocaleCompare("style",option+1) == 0)
6212  {
6213  ssize_t
6214  style;
6215 
6216  if (*option == '+')
6217  break;
6218  i++;
6219  if (i == (ssize_t) argc)
6220  ThrowMogrifyException(OptionError,"MissingArgument",option);
6221  style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
6222  if (style < 0)
6223  ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6224  argv[i]);
6225  break;
6226  }
6227  if (LocaleCompare("swap",option+1) == 0)
6228  {
6229  if (*option == '+')
6230  break;
6231  i++;
6232  if (i == (ssize_t) argc)
6233  ThrowMogrifyException(OptionError,"MissingArgument",option);
6234  if (IsGeometry(argv[i]) == MagickFalse)
6235  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6236  break;
6237  }
6238  if (LocaleCompare("swirl",option+1) == 0)
6239  {
6240  if (*option == '+')
6241  break;
6242  i++;
6243  if (i == (ssize_t) argc)
6244  ThrowMogrifyException(OptionError,"MissingArgument",option);
6245  if (IsGeometry(argv[i]) == MagickFalse)
6246  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6247  break;
6248  }
6249  if (LocaleCompare("synchronize",option+1) == 0)
6250  break;
6251  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6252  }
6253  case 't':
6254  {
6255  if (LocaleCompare("taint",option+1) == 0)
6256  break;
6257  if (LocaleCompare("texture",option+1) == 0)
6258  {
6259  if (*option == '+')
6260  break;
6261  i++;
6262  if (i == (ssize_t) argc)
6263  ThrowMogrifyException(OptionError,"MissingArgument",option);
6264  break;
6265  }
6266  if (LocaleCompare("tile",option+1) == 0)
6267  {
6268  if (*option == '+')
6269  break;
6270  i++;
6271  if (i == (ssize_t) argc)
6272  ThrowMogrifyException(OptionError,"MissingArgument",option);
6273  break;
6274  }
6275  if (LocaleCompare("tile-offset",option+1) == 0)
6276  {
6277  if (*option == '+')
6278  break;
6279  i++;
6280  if (i == (ssize_t) argc)
6281  ThrowMogrifyException(OptionError,"MissingArgument",option);
6282  if (IsGeometry(argv[i]) == MagickFalse)
6283  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6284  break;
6285  }
6286  if (LocaleCompare("tint",option+1) == 0)
6287  {
6288  if (*option == '+')
6289  break;
6290  i++;
6291  if (i == (ssize_t) argc)
6292  ThrowMogrifyException(OptionError,"MissingArgument",option);
6293  if (IsGeometry(argv[i]) == MagickFalse)
6294  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6295  break;
6296  }
6297  if (LocaleCompare("transform",option+1) == 0)
6298  break;
6299  if (LocaleCompare("transpose",option+1) == 0)
6300  break;
6301  if (LocaleCompare("transverse",option+1) == 0)
6302  break;
6303  if (LocaleCompare("threshold",option+1) == 0)
6304  {
6305  if (*option == '+')
6306  break;
6307  i++;
6308  if (i == (ssize_t) argc)
6309  ThrowMogrifyException(OptionError,"MissingArgument",option);
6310  if (IsGeometry(argv[i]) == MagickFalse)
6311  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6312  break;
6313  }
6314  if (LocaleCompare("thumbnail",option+1) == 0)
6315  {
6316  if (*option == '+')
6317  break;
6318  i++;
6319  if (i == (ssize_t) argc)
6320  ThrowMogrifyException(OptionError,"MissingArgument",option);
6321  if (IsGeometry(argv[i]) == MagickFalse)
6322  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6323  break;
6324  }
6325  if (LocaleCompare("transparent",option+1) == 0)
6326  {
6327  i++;
6328  if (i == (ssize_t) argc)
6329  ThrowMogrifyException(OptionError,"MissingArgument",option);
6330  break;
6331  }
6332  if (LocaleCompare("transparent-color",option+1) == 0)
6333  {
6334  if (*option == '+')
6335  break;
6336  i++;
6337  if (i == (ssize_t) argc)
6338  ThrowMogrifyException(OptionError,"MissingArgument",option);
6339  break;
6340  }
6341  if (LocaleCompare("treedepth",option+1) == 0)
6342  {
6343  if (*option == '+')
6344  break;
6345  i++;
6346  if (i == (ssize_t) argc)
6347  ThrowMogrifyException(OptionError,"MissingArgument",option);
6348  if (IsGeometry(argv[i]) == MagickFalse)
6349  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6350  break;
6351  }
6352  if (LocaleCompare("trim",option+1) == 0)
6353  break;
6354  if (LocaleCompare("type",option+1) == 0)
6355  {
6356  ssize_t
6357  type;
6358 
6359  if (*option == '+')
6360  break;
6361  i++;
6362  if (i == (ssize_t) argc)
6363  ThrowMogrifyException(OptionError,"MissingArgument",option);
6364  type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
6365  if (type < 0)
6366  ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6367  argv[i]);
6368  break;
6369  }
6370  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6371  }
6372  case 'u':
6373  {
6374  if (LocaleCompare("undercolor",option+1) == 0)
6375  {
6376  if (*option == '+')
6377  break;
6378  i++;
6379  if (i == (ssize_t) argc)
6380  ThrowMogrifyException(OptionError,"MissingArgument",option);
6381  break;
6382  }
6383  if (LocaleCompare("unique-colors",option+1) == 0)
6384  break;
6385  if (LocaleCompare("units",option+1) == 0)
6386  {
6387  ssize_t
6388  units;
6389 
6390  if (*option == '+')
6391  break;
6392  i++;
6393  if (i == (ssize_t) argc)
6394  ThrowMogrifyException(OptionError,"MissingArgument",option);
6395  units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
6396  argv[i]);
6397  if (units < 0)
6398  ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6399  argv[i]);
6400  break;
6401  }
6402  if (LocaleCompare("unsharp",option+1) == 0)
6403  {
6404  i++;
6405  if (i == (ssize_t) argc)
6406  ThrowMogrifyException(OptionError,"MissingArgument",option);
6407  if (IsGeometry(argv[i]) == MagickFalse)
6408  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6409  break;
6410  }
6411  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6412  }
6413  case 'v':
6414  {
6415  if (LocaleCompare("verbose",option+1) == 0)
6416  {
6417  image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6418  break;
6419  }
6420  if ((LocaleCompare("version",option+1) == 0) ||
6421  (LocaleCompare("-version",option+1) == 0))
6422  {
6423  ListMagickVersion(stdout);
6424  break;
6425  }
6426  if (LocaleCompare("vignette",option+1) == 0)
6427  {
6428  if (*option == '+')
6429  break;
6430  i++;
6431  if (i == (ssize_t) argc)
6432  ThrowMogrifyException(OptionError,"MissingArgument",option);
6433  if (IsGeometry(argv[i]) == MagickFalse)
6434  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6435  break;
6436  }
6437  if (LocaleCompare("virtual-pixel",option+1) == 0)
6438  {
6439  ssize_t
6440  method;
6441 
6442  if (*option == '+')
6443  break;
6444  i++;
6445  if (i == (ssize_t) argc)
6446  ThrowMogrifyException(OptionError,"MissingArgument",option);
6447  method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
6448  argv[i]);
6449  if (method < 0)
6450  ThrowMogrifyException(OptionError,
6451  "UnrecognizedVirtualPixelMethod",argv[i]);
6452  break;
6453  }
6454  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6455  }
6456  case 'w':
6457  {
6458  if (LocaleCompare("wave",option+1) == 0)
6459  {
6460  i++;
6461  if (i == (ssize_t) argc)
6462  ThrowMogrifyException(OptionError,"MissingArgument",option);
6463  if (IsGeometry(argv[i]) == MagickFalse)
6464  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6465  break;
6466  }
6467  if (LocaleCompare("wavelet-denoise",option+1) == 0)
6468  {
6469  i++;
6470  if (i == (ssize_t) argc)
6471  ThrowMogrifyException(OptionError,"MissingArgument",option);
6472  if (IsGeometry(argv[i]) == MagickFalse)
6473  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6474  break;
6475  }
6476  if (LocaleCompare("weight",option+1) == 0)
6477  {
6478  if (*option == '+')
6479  break;
6480  i++;
6481  if (i == (ssize_t) argc)
6482  ThrowMogrifyException(OptionError,"MissingArgument",option);
6483  break;
6484  }
6485  if (LocaleCompare("white-point",option+1) == 0)
6486  {
6487  if (*option == '+')
6488  break;
6489  i++;
6490  if (i == (ssize_t) argc)
6491  ThrowMogrifyException(OptionError,"MissingArgument",option);
6492  if (IsGeometry(argv[i]) == MagickFalse)
6493  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6494  break;
6495  }
6496  if (LocaleCompare("white-threshold",option+1) == 0)
6497  {
6498  if (*option == '+')
6499  break;
6500  i++;
6501  if (i == (ssize_t) argc)
6502  ThrowMogrifyException(OptionError,"MissingArgument",option);
6503  if (IsGeometry(argv[i]) == MagickFalse)
6504  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6505  break;
6506  }
6507  if (LocaleCompare("write",option+1) == 0)
6508  {
6509  i++;
6510  if (i == (ssize_t) argc)
6511  ThrowMogrifyException(OptionError,"MissingArgument",option);
6512  break;
6513  }
6514  if (LocaleCompare("write-mask",option+1) == 0)
6515  {
6516  if (*option == '+')
6517  break;
6518  i++;
6519  if (i == (ssize_t) argc)
6520  ThrowMogrifyException(OptionError,"MissingArgument",option);
6521  break;
6522  }
6523  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6524  }
6525  case '?':
6526  break;
6527  default:
6528  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6529  }
6530  fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6531  FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
6532  if (fire != MagickFalse)
6533  FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6534  }
6535  if (k != 0)
6536  ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6537  if (i != (ssize_t) argc)
6538  ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6539  DestroyMogrify();
6540  return(status != 0 ? MagickTrue : MagickFalse);
6541 }
6542 
6543 /*
6544 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6545 % %
6546 % %
6547 % %
6548 + M o g r i f y I m a g e I n f o %
6549 % %
6550 % %
6551 % %
6552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6553 %
6554 % MogrifyImageInfo() applies image processing settings to the image as
6555 % prescribed by command line options.
6556 %
6557 % The format of the MogrifyImageInfo method is:
6558 %
6559 % MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6560 % const char **argv,ExceptionInfo *exception)
6561 %
6562 % A description of each parameter follows:
6563 %
6564 % o image_info: the image info..
6565 %
6566 % o argc: Specifies a pointer to an integer describing the number of
6567 % elements in the argument vector.
6568 %
6569 % o argv: Specifies a pointer to a text array containing the command line
6570 % arguments.
6571 %
6572 % o exception: return any errors or warnings in this structure.
6573 %
6574 */
6575 WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6576  const int argc,const char **argv,ExceptionInfo *exception)
6577 {
6578  const char
6579  *option;
6580 
6581  GeometryInfo
6582  geometry_info;
6583 
6584  ssize_t
6585  count;
6586 
6587  register ssize_t
6588  i;
6589 
6590  /*
6591  Initialize method variables.
6592  */
6593  assert(image_info != (ImageInfo *) NULL);
6594  assert(image_info->signature == MagickCoreSignature);
6595  if (image_info->debug != MagickFalse)
6596  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6597  image_info->filename);
6598  if (argc < 0)
6599  return(MagickTrue);
6600  /*
6601  Set the image settings.
6602  */
6603  for (i=0; i < (ssize_t) argc; i++)
6604  {
6605  option=argv[i];
6606  if (IsCommandOption(option) == MagickFalse)
6607  continue;
6608  count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
6609  count=MagickMax(count,0L);
6610  if ((i+count) >= (ssize_t) argc)
6611  break;
6612  switch (*(option+1))
6613  {
6614  case 'a':
6615  {
6616  if (LocaleCompare("adjoin",option+1) == 0)
6617  {
6618  image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6619  break;
6620  }
6621  if (LocaleCompare("antialias",option+1) == 0)
6622  {
6623  image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6624  break;
6625  }
6626  if (LocaleCompare("authenticate",option+1) == 0)
6627  {
6628  if (*option == '+')
6629  (void) DeleteImageOption(image_info,option+1);
6630  else
6631  (void) SetImageOption(image_info,option+1,argv[i+1]);
6632  break;
6633  }
6634  break;
6635  }
6636  case 'b':
6637  {
6638  if (LocaleCompare("background",option+1) == 0)
6639  {
6640  if (*option == '+')
6641  {
6642  (void) DeleteImageOption(image_info,option+1);
6643  (void) QueryColorCompliance(MogrifyBackgroundColor,
6644  AllCompliance,&image_info->background_color,exception);
6645  break;
6646  }
6647  (void) SetImageOption(image_info,option+1,argv[i+1]);
6648  (void) QueryColorCompliance(argv[i+1],AllCompliance,
6649  &image_info->background_color,exception);
6650  break;
6651  }
6652  if (LocaleCompare("bias",option+1) == 0)
6653  {
6654  if (*option == '+')
6655  {
6656  (void) SetImageOption(image_info,"convolve:bias","0.0");
6657  break;
6658  }
6659  (void) SetImageOption(image_info,"convolve:bias",argv[i+1]);
6660  break;
6661  }
6662  if (LocaleCompare("black-point-compensation",option+1) == 0)
6663  {
6664  if (*option == '+')
6665  {
6666  (void) SetImageOption(image_info,option+1,"false");
6667  break;
6668  }
6669  (void) SetImageOption(image_info,option+1,"true");
6670  break;
6671  }
6672  if (LocaleCompare("blue-primary",option+1) == 0)
6673  {
6674  if (*option == '+')
6675  {
6676  (void) SetImageOption(image_info,option+1,"0.0");
6677  break;
6678  }
6679  (void) SetImageOption(image_info,option+1,argv[i+1]);
6680  break;
6681  }
6682  if (LocaleCompare("bordercolor",option+1) == 0)
6683  {
6684  if (*option == '+')
6685  {
6686  (void) DeleteImageOption(image_info,option+1);
6687  (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
6688  &image_info->border_color,exception);
6689  break;
6690  }
6691  (void) QueryColorCompliance(argv[i+1],AllCompliance,
6692  &image_info->border_color,exception);
6693  (void) SetImageOption(image_info,option+1,argv[i+1]);
6694  break;
6695  }
6696  if (LocaleCompare("box",option+1) == 0)
6697  {
6698  if (*option == '+')
6699  {
6700  (void) SetImageOption(image_info,"undercolor","none");
6701  break;
6702  }
6703  (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6704  break;
6705  }
6706  break;
6707  }
6708  case 'c':
6709  {
6710  if (LocaleCompare("cache",option+1) == 0)
6711  {
6712  MagickSizeType
6713  limit;
6714 
6715  limit=MagickResourceInfinity;
6716  if (LocaleCompare("unlimited",argv[i+1]) != 0)
6717  limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6718  100.0);
6719  (void) SetMagickResourceLimit(MemoryResource,limit);
6720  (void) SetMagickResourceLimit(MapResource,2*limit);
6721  break;
6722  }
6723  if (LocaleCompare("caption",option+1) == 0)
6724  {
6725  if (*option == '+')
6726  {
6727  (void) DeleteImageOption(image_info,option+1);
6728  break;
6729  }
6730  (void) SetImageOption(image_info,option+1,argv[i+1]);
6731  break;
6732  }
6733  if (LocaleCompare("colorspace",option+1) == 0)
6734  {
6735  if (*option == '+')
6736  {
6737  image_info->colorspace=UndefinedColorspace;
6738  (void) SetImageOption(image_info,option+1,"undefined");
6739  break;
6740  }
6741  image_info->colorspace=(ColorspaceType) ParseCommandOption(
6742  MagickColorspaceOptions,MagickFalse,argv[i+1]);
6743  (void) SetImageOption(image_info,option+1,argv[i+1]);
6744  break;
6745  }
6746  if (LocaleCompare("comment",option+1) == 0)
6747  {
6748  if (*option == '+')
6749  {
6750  (void) DeleteImageOption(image_info,option+1);
6751  break;
6752  }
6753  (void) SetImageOption(image_info,option+1,argv[i+1]);
6754  break;
6755  }
6756  if (LocaleCompare("compose",option+1) == 0)
6757  {
6758  if (*option == '+')
6759  {
6760  (void) SetImageOption(image_info,option+1,"undefined");
6761  break;
6762  }
6763  (void) SetImageOption(image_info,option+1,argv[i+1]);
6764  break;
6765  }
6766  if (LocaleCompare("compress",option+1) == 0)
6767  {
6768  if (*option == '+')
6769  {
6770  image_info->compression=UndefinedCompression;
6771  (void) SetImageOption(image_info,option+1,"undefined");
6772  break;
6773  }
6774  image_info->compression=(CompressionType) ParseCommandOption(
6775  MagickCompressOptions,MagickFalse,argv[i+1]);
6776  (void) SetImageOption(image_info,option+1,argv[i+1]);
6777  break;
6778  }
6779  break;
6780  }
6781  case 'd':
6782  {
6783  if (LocaleCompare("debug",option+1) == 0)
6784  {
6785  if (*option == '+')
6786  (void) SetLogEventMask("none");
6787  else
6788  (void) SetLogEventMask(argv[i+1]);
6789  image_info->debug=IsEventLogging();
6790  break;
6791  }
6792  if (LocaleCompare("define",option+1) == 0)
6793  {
6794  if (*option == '+')
6795  {
6796  if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6797  (void) DeleteImageRegistry(argv[i+1]+9);
6798  else
6799  (void) DeleteImageOption(image_info,argv[i+1]);
6800  break;
6801  }
6802  if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6803  {
6804  (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6805  exception);
6806  break;
6807  }
6808  (void) DefineImageOption(image_info,argv[i+1]);
6809  break;
6810  }
6811  if (LocaleCompare("delay",option+1) == 0)
6812  {
6813  if (*option == '+')
6814  {
6815  (void) SetImageOption(image_info,option+1,"0");
6816  break;
6817  }
6818  (void) SetImageOption(image_info,option+1,argv[i+1]);
6819  break;
6820  }
6821  if (LocaleCompare("density",option+1) == 0)
6822  {
6823  /*
6824  Set image density.
6825  */
6826  if (*option == '+')
6827  {
6828  if (image_info->density != (char *) NULL)
6829  image_info->density=DestroyString(image_info->density);
6830  (void) SetImageOption(image_info,option+1,"72");
6831  break;
6832  }
6833  (void) CloneString(&image_info->density,argv[i+1]);
6834  (void) SetImageOption(image_info,option+1,argv[i+1]);
6835  break;
6836  }
6837  if (LocaleCompare("depth",option+1) == 0)
6838  {
6839  if (*option == '+')
6840  {
6841  image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6842  break;
6843  }
6844  image_info->depth=StringToUnsignedLong(argv[i+1]);
6845  break;
6846  }
6847  if (LocaleCompare("direction",option+1) == 0)
6848  {
6849  if (*option == '+')
6850  {
6851  (void) SetImageOption(image_info,option+1,"undefined");
6852  break;
6853  }
6854  (void) SetImageOption(image_info,option+1,argv[i+1]);
6855  break;
6856  }
6857  if (LocaleCompare("display",option+1) == 0)
6858  {
6859  if (*option == '+')
6860  {
6861  if (image_info->server_name != (char *) NULL)
6862  image_info->server_name=DestroyString(
6863  image_info->server_name);
6864  break;
6865  }
6866  (void) CloneString(&image_info->server_name,argv[i+1]);
6867  break;
6868  }
6869  if (LocaleCompare("dispose",option+1) == 0)
6870  {
6871  if (*option == '+')
6872  {
6873  (void) SetImageOption(image_info,option+1,"undefined");
6874  break;
6875  }
6876  (void) SetImageOption(image_info,option+1,argv[i+1]);
6877  break;
6878  }
6879  if (LocaleCompare("dither",option+1) == 0)
6880  {
6881  if (*option == '+')
6882  {
6883  image_info->dither=MagickFalse;
6884  (void) SetImageOption(image_info,option+1,"none");
6885  break;
6886  }
6887  (void) SetImageOption(image_info,option+1,argv[i+1]);
6888  image_info->dither=MagickTrue;
6889  break;
6890  }
6891  break;
6892  }
6893  case 'e':
6894  {
6895  if (LocaleCompare("encoding",option+1) == 0)
6896  {
6897  if (*option == '+')
6898  {
6899  (void) SetImageOption(image_info,option+1,"undefined");
6900  break;
6901  }
6902  (void) SetImageOption(image_info,option+1,argv[i+1]);
6903  break;
6904  }
6905  if (LocaleCompare("endian",option+1) == 0)
6906  {
6907  if (*option == '+')
6908  {
6909  image_info->endian=UndefinedEndian;
6910  (void) SetImageOption(image_info,option+1,"undefined");
6911  break;
6912  }
6913  image_info->endian=(EndianType) ParseCommandOption(
6914  MagickEndianOptions,MagickFalse,argv[i+1]);
6915  (void) SetImageOption(image_info,option+1,argv[i+1]);
6916  break;
6917  }
6918  if (LocaleCompare("extract",option+1) == 0)
6919  {
6920  /*
6921  Set image extract geometry.
6922  */
6923  if (*option == '+')
6924  {
6925  if (image_info->extract != (char *) NULL)
6926  image_info->extract=DestroyString(image_info->extract);
6927  break;
6928  }
6929  (void) CloneString(&image_info->extract,argv[i+1]);
6930  break;
6931  }
6932  break;
6933  }
6934  case 'f':
6935  {
6936  if (LocaleCompare("family",option+1) == 0)
6937  {
6938  if (*option != '+')
6939  (void) SetImageOption(image_info,option+1,argv[i+1]);
6940  break;
6941  }
6942  if (LocaleCompare("fill",option+1) == 0)
6943  {
6944  if (*option == '+')
6945  {
6946  (void) SetImageOption(image_info,option+1,"none");
6947  break;
6948  }
6949  (void) SetImageOption(image_info,option+1,argv[i+1]);
6950  break;
6951  }
6952  if (LocaleCompare("filter",option+1) == 0)
6953  {
6954  if (*option == '+')
6955  {
6956  (void) SetImageOption(image_info,option+1,"undefined");
6957  break;
6958  }
6959  (void) SetImageOption(image_info,option+1,argv[i+1]);
6960  break;
6961  }
6962  if (LocaleCompare("font",option+1) == 0)
6963  {
6964  if (*option == '+')
6965  {
6966  if (image_info->font != (char *) NULL)
6967  image_info->font=DestroyString(image_info->font);
6968  break;
6969  }
6970  (void) CloneString(&image_info->font,argv[i+1]);
6971  break;
6972  }
6973  if (LocaleCompare("format",option+1) == 0)
6974  {
6975  register const char
6976  *q;
6977 
6978  for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6979  if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
6980  image_info->ping=MagickFalse;
6981  (void) SetImageOption(image_info,option+1,argv[i+1]);
6982  break;
6983  }
6984  if (LocaleCompare("fuzz",option+1) == 0)
6985  {
6986  if (*option == '+')
6987  {
6988  image_info->fuzz=0.0;
6989  (void) SetImageOption(image_info,option+1,"0");
6990  break;
6991  }
6992  image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6993  QuantumRange+1.0);
6994  (void) SetImageOption(image_info,option+1,argv[i+1]);
6995  break;
6996  }
6997  break;
6998  }
6999  case 'g':
7000  {
7001  if (LocaleCompare("gravity",option+1) == 0)
7002  {
7003  if (*option == '+')
7004  {
7005  (void) SetImageOption(image_info,option+1,<