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