MagickWand  7.0.3
mogrify.c
Go to the documentation of this file.
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % %
6 % M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7 % MM MM O O G R R I F Y Y %
8 % M M M O O G GGG RRRR I FFF Y %
9 % M M O O G G R R I F Y %
10 % M M OOO GGGG R R IIIII F Y %
11 % %
12 % %
13 % MagickWand Module Methods %
14 % %
15 % Software Design %
16 % Cristy %
17 % March 2000 %
18 % %
19 % %
20 % Copyright 1999-2019 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
22 % %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
25 % %
26 % https://imagemagick.org/script/license.php %
27 % %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
33 % %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 % Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37 % draw on, flip, join, re-sample, and much more. This tool is similiar to
38 % convert except that the original image file is overwritten (unless you
39 % change the file suffix with the -format option) with any changes you
40 % request.
41 %
42 */
43 
44 /*
45  Include declarations.
46 */
47 #include "MagickWand/studio.h"
48 #include "MagickWand/MagickWand.h"
51 #include "MagickCore/blob-private.h"
52 #include "MagickCore/composite-private.h"
53 #include "MagickCore/image-private.h"
54 #include "MagickCore/monitor-private.h"
55 #include "MagickCore/string-private.h"
56 #include "MagickCore/thread-private.h"
57 #include "MagickCore/timer-private.h"
58 #include "MagickCore/utility-private.h"
59 #if defined(MAGICKCORE_HAVE_UTIME_H)
60 #include <utime.h>
61 #endif
62 
63 /*
64  Constant declaration.
65 */
66 static const char
67  MogrifyAlphaColor[] = "#bdbdbd", /* gray */
68  MogrifyBackgroundColor[] = "#ffffff", /* white */
69  MogrifyBorderColor[] = "#dfdfdf"; /* gray */
70 
71 /*
72  Define declarations.
73 */
74 #define UndefinedCompressionQuality 0UL
75 
76 /*
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 % %
79 % %
80 % %
81 % M a g i c k C o m m a n d G e n e s i s %
82 % %
83 % %
84 % %
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 %
87 % MagickCommandGenesis() applies image processing options to an image as
88 % prescribed by command line options.
89 %
90 % It wiil look for special options like "-debug", "-bench", and
91 % "-distribute-cache" that needs to be applied even before the main
92 % processing begins, and may completely overrule normal command processing.
93 % Such 'Genesis' Options can only be given on the CLI, (not in a script)
94 % and are typically ignored (as they have been handled) if seen later.
95 %
96 % The format of the MagickCommandGenesis method is:
97 %
98 % MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
99 % MagickCommand command,int argc,char **argv,char **metadata,
100 % ExceptionInfo *exception)
101 %
102 % A description of each parameter follows:
103 %
104 % o image_info: the image info.
105 %
106 % o command: Choose from ConvertImageCommand, IdentifyImageCommand,
107 % MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
108 % ConjureImageCommand, StreamImageCommand, ImportImageCommand,
109 % DisplayImageCommand, or AnimateImageCommand.
110 %
111 % o argc: Specifies a pointer to an integer describing the number of
112 % elements in the argument vector.
113 %
114 % o argv: Specifies a pointer to a text array containing the command line
115 % arguments.
116 %
117 % o metadata: any metadata is returned here.
118 %
119 % o exception: return any errors or warnings in this structure.
120 %
121 */
122 WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
123  MagickCommand command,int argc,char **argv,char **metadata,
124  ExceptionInfo *exception)
125 {
126  char
127  client_name[MaxTextExtent],
128  *option;
129 
130  double
131  duration,
132  serial;
133 
134  MagickBooleanType
135  concurrent,
136  regard_warnings,
137  status;
138 
139  register ssize_t
140  i;
141 
142  size_t
143  iterations,
144  number_threads;
145 
146  ssize_t
147  n;
148 
149  (void) setlocale(LC_ALL,"");
150  (void) setlocale(LC_NUMERIC,"C");
151  GetPathComponent(argv[0],TailPath,client_name);
152  (void) SetClientName(client_name);
153  concurrent=MagickFalse;
154  duration=(-1.0);
155  iterations=1;
156  status=MagickTrue;
157  regard_warnings=MagickFalse;
158  for (i=1; i < (ssize_t) (argc-1); i++)
159  {
160  option=argv[i];
161  if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
162  continue;
163  if (LocaleCompare("-bench",option) == 0)
164  iterations=StringToUnsignedLong(argv[++i]);
165  if (LocaleCompare("-concurrent",option) == 0)
166  concurrent=MagickTrue;
167  if (LocaleCompare("-debug",option) == 0)
168  (void) SetLogEventMask(argv[++i]);
169  if (LocaleCompare("-distribute-cache",option) == 0)
170  {
171  DistributePixelCacheServer(StringToInteger(argv[++i]),exception);
172  exit(0);
173  }
174  if (LocaleCompare("-duration",option) == 0)
175  duration=StringToDouble(argv[++i],(char **) NULL);
176  if (LocaleCompare("-regard-warnings",option) == 0)
177  regard_warnings=MagickTrue;
178  }
179  if (iterations == 1)
180  {
181  char
182  *text;
183 
184  text=(char *) NULL;
185  status=command(image_info,argc,argv,&text,exception);
186  if (exception->severity != UndefinedException)
187  {
188  if ((exception->severity > ErrorException) ||
189  (regard_warnings != MagickFalse))
190  status=MagickFalse;
191  CatchException(exception);
192  }
193  if (text != (char *) NULL)
194  {
195  if (metadata != (char **) NULL)
196  (void) ConcatenateString(&(*metadata),text);
197  text=DestroyString(text);
198  }
199  return(status);
200  }
201  number_threads=GetOpenMPMaximumThreads();
202  serial=0.0;
203  for (n=1; n <= (ssize_t) number_threads; n++)
204  {
205  double
206  e,
207  parallel,
208  user_time;
209 
210  TimerInfo
211  *timer;
212 
213  (void) SetMagickResourceLimit(ThreadResource,(MagickSizeType) n);
214  timer=AcquireTimerInfo();
215  if (concurrent == MagickFalse)
216  {
217  for (i=0; i < (ssize_t) iterations; i++)
218  {
219  char
220  *text;
221 
222  text=(char *) NULL;
223  if (status == MagickFalse)
224  continue;
225  if (duration > 0)
226  {
227  if (GetElapsedTime(timer) > duration)
228  continue;
229  (void) ContinueTimer(timer);
230  }
231  status=command(image_info,argc,argv,&text,exception);
232  if (exception->severity != UndefinedException)
233  {
234  if ((exception->severity > ErrorException) ||
235  (regard_warnings != MagickFalse))
236  status=MagickFalse;
237  CatchException(exception);
238  }
239  if (text != (char *) NULL)
240  {
241  if (metadata != (char **) NULL)
242  (void) ConcatenateString(&(*metadata),text);
243  text=DestroyString(text);
244  }
245  }
246  }
247  else
248  {
249  SetOpenMPNested(1);
250 #if defined(MAGICKCORE_OPENMP_SUPPORT)
251  # pragma omp parallel for shared(status)
252 #endif
253  for (i=0; i < (ssize_t) iterations; i++)
254  {
255  char
256  *text;
257 
258  text=(char *) NULL;
259  if (status == MagickFalse)
260  continue;
261  if (duration > 0)
262  {
263  if (GetElapsedTime(timer) > duration)
264  continue;
265  (void) ContinueTimer(timer);
266  }
267  status=command(image_info,argc,argv,&text,exception);
268 #if defined(MAGICKCORE_OPENMP_SUPPORT)
269  # pragma omp critical (MagickCore_MagickCommandGenesis)
270 #endif
271  {
272  if (exception->severity != UndefinedException)
273  {
274  if ((exception->severity > ErrorException) ||
275  (regard_warnings != MagickFalse))
276  status=MagickFalse;
277  CatchException(exception);
278  }
279  if (text != (char *) NULL)
280  {
281  if (metadata != (char **) NULL)
282  (void) ConcatenateString(&(*metadata),text);
283  text=DestroyString(text);
284  }
285  }
286  }
287  }
288  user_time=GetUserTime(timer);
289  parallel=GetElapsedTime(timer);
290  e=1.0;
291  if (n == 1)
292  serial=parallel;
293  else
294  e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
295  (double) n)))-(1.0/(double) n))/(1.0-1.0/(double) n);
296  (void) FormatLocaleFile(stderr,
297  " Performance[%.20g]: %.20gi %0.3fips %0.6fe %0.6fu %lu:%02lu.%03lu\n",
298  (double) n,(double) iterations,(double) iterations/parallel,e,user_time,
299  (unsigned long) (parallel/60.0),(unsigned long) floor(fmod(parallel,
300  60.0)),(unsigned long) (1000.0*(parallel-floor(parallel))+0.5));
301  timer=DestroyTimerInfo(timer);
302  }
303  return(status);
304 }
305 
306 /*
307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308 % %
309 % %
310 % %
311 + M o g r i f y I m a g e %
312 % %
313 % %
314 % %
315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 %
317 % MogrifyImage() applies simple single image processing options to a single
318 % image that may be part of a large list, but also handles any 'region'
319 % image handling.
320 %
321 % The image in the list may be modified in three different ways...
322 %
323 % * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
324 % * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
325 % * replace by a list of images (only the -separate option!)
326 %
327 % In each case the result is returned into the list, and a pointer to the
328 % modified image (last image added if replaced by a list of images) is
329 % returned.
330 %
331 % ASIDE: The -crop is present but restricted to non-tile single image crops
332 %
333 % This means if all the images are being processed (such as by
334 % MogrifyImages(), next image to be processed will be as per the pointer
335 % (*image)->next. Also the image list may grow as a result of some specific
336 % operations but as images are never merged or deleted, it will never shrink
337 % in length. Typically the list will remain the same length.
338 %
339 % WARNING: As the image pointed to may be replaced, the first image in the
340 % list may also change. GetFirstImageInList() should be used by caller if
341 % they wish return the Image pointer to the first image in list.
342 %
343 %
344 % The format of the MogrifyImage method is:
345 %
346 % MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
347 % const char **argv,Image **image)
348 %
349 % A description of each parameter follows:
350 %
351 % o image_info: the image info..
352 %
353 % o argc: Specifies a pointer to an integer describing the number of
354 % elements in the argument vector.
355 %
356 % o argv: Specifies a pointer to a text array containing the command line
357 % arguments.
358 %
359 % o image: the image.
360 %
361 % o exception: return any errors or warnings in this structure.
362 %
363 */
364 
365 static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
366  ExceptionInfo *exception)
367 {
368  char
369  key[MagickPathExtent];
370 
371  ExceptionInfo
372  *sans_exception;
373 
374  Image
375  *image;
376 
377  ImageInfo
378  *read_info;
379 
380  /*
381  Read an image into a image cache (for repeated usage) if not already in
382  cache. Then return the image that is in the cache.
383  */
384  (void) FormatLocaleString(key,MagickPathExtent,"cache:%s",path);
385  sans_exception=AcquireExceptionInfo();
386  image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
387  sans_exception=DestroyExceptionInfo(sans_exception);
388  if (image != (Image *) NULL)
389  return(image);
390  read_info=CloneImageInfo(image_info);
391  (void) CopyMagickString(read_info->filename,path,MagickPathExtent);
392  image=ReadImage(read_info,exception);
393  read_info=DestroyImageInfo(read_info);
394  if (image != (Image *) NULL)
395  (void) SetImageRegistry(ImageRegistryType,key,image,exception);
396  return(image);
397 }
398 
399 static inline MagickBooleanType IsPathWritable(const char *path)
400 {
401  if (IsPathAccessible(path) == MagickFalse)
402  return(MagickFalse);
403  if (access_utf8(path,W_OK) != 0)
404  return(MagickFalse);
405  return(MagickTrue);
406 }
407 
408 static MagickBooleanType MonitorProgress(const char *text,
409  const MagickOffsetType offset,const MagickSizeType extent,
410  void *wand_unused(client_data))
411 {
412  char
413  message[MagickPathExtent],
414  tag[MagickPathExtent];
415 
416  const char
417  *locale_message;
418 
419  register char
420  *p;
421 
422  magick_unreferenced(client_data);
423 
424  if ((extent <= 1) || (offset < 0) || (offset >= (MagickOffsetType) extent))
425  return(MagickTrue);
426  if ((offset != (MagickOffsetType) (extent-1)) && ((offset % 50) != 0))
427  return(MagickTrue);
428  (void) CopyMagickString(tag,text,MagickPathExtent);
429  p=strrchr(tag,'/');
430  if (p != (char *) NULL)
431  *p='\0';
432  (void) FormatLocaleString(message,MagickPathExtent,"Monitor/%s",tag);
433  locale_message=GetLocaleMessage(message);
434  if (locale_message == message)
435  locale_message=tag;
436  if (p == (char *) NULL)
437  (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
438  locale_message,(long) offset,(unsigned long) extent,(long)
439  (100L*offset/(extent-1)));
440  else
441  (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
442  locale_message,p+1,(long) offset,(unsigned long) extent,(long)
443  (100L*offset/(extent-1)));
444  if (offset == (MagickOffsetType) (extent-1))
445  (void) FormatLocaleFile(stderr,"\n");
446  (void) fflush(stderr);
447  return(MagickTrue);
448 }
449 
450 static Image *SparseColorOption(const Image *image,
451  const SparseColorMethod method,const char *arguments,
452  const MagickBooleanType color_from_image,ExceptionInfo *exception)
453 {
454  char
455  token[MagickPathExtent];
456 
457  const char
458  *p;
459 
460  double
461  *sparse_arguments;
462 
463  Image
464  *sparse_image;
465 
466  PixelInfo
467  color;
468 
469  MagickBooleanType
470  error;
471 
472  register size_t
473  x;
474 
475  size_t
476  number_arguments,
477  number_colors;
478 
479  /*
480  SparseColorOption() parses the complex -sparse-color argument into an an
481  array of floating point values then calls SparseColorImage(). Argument is
482  a complex mix of floating-point pixel coodinates, and color specifications
483  (or direct floating point numbers). The number of floats needed to
484  represent a color varies depending on the current channel setting.
485  */
486  assert(image != (Image *) NULL);
487  assert(image->signature == MagickCoreSignature);
488  if (image->debug != MagickFalse)
489  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
490  assert(exception != (ExceptionInfo *) NULL);
491  assert(exception->signature == MagickCoreSignature);
492  /*
493  Limit channels according to image - and add up number of color channel.
494  */
495  number_colors=0;
496  if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
497  number_colors++;
498  if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
499  number_colors++;
500  if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
501  number_colors++;
502  if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
503  (image->colorspace == CMYKColorspace))
504  number_colors++;
505  if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
506  (image->alpha_trait != UndefinedPixelTrait))
507  number_colors++;
508 
509  /*
510  Read string, to determine number of arguments needed,
511  */
512  p=arguments;
513  x=0;
514  while( *p != '\0' )
515  {
516  GetNextToken(p,&p,MagickPathExtent,token);
517  if ( token[0] == ',' ) continue;
518  if ( isalpha((int) token[0]) || token[0] == '#' ) {
519  if ( color_from_image ) {
520  (void) ThrowMagickException(exception,GetMagickModule(),
521  OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
522  "Color arg given, when colors are coming from image");
523  return( (Image *) NULL);
524  }
525  x += number_colors; /* color argument */
526  }
527  else {
528  x++; /* floating point argument */
529  }
530  }
531  error=MagickTrue;
532  if ( color_from_image ) {
533  /* just the control points are being given */
534  error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
535  number_arguments=(x/2)*(2+number_colors);
536  }
537  else {
538  /* control points and color values */
539  error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
540  number_arguments=x;
541  }
542  if ( error ) {
543  (void) ThrowMagickException(exception,GetMagickModule(),
544  OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
545  "Invalid number of Arguments");
546  return( (Image *) NULL);
547  }
548 
549  /* Allocate and fill in the floating point arguments */
550  sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
551  sizeof(*sparse_arguments));
552  if (sparse_arguments == (double *) NULL) {
553  (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
554  " MemoryAllocationFailed\n""%s","SparseColorOption");
555  return( (Image *) NULL);
556  }
557  (void) memset(sparse_arguments,0,number_arguments*
558  sizeof(*sparse_arguments));
559  p=arguments;
560  x=0;
561  while( *p != '\0' && x < number_arguments ) {
562  /* X coordinate */
563  token[0]=','; while ( token[0] == ',' ) GetNextToken(p,&p,MagickPathExtent,token);
564  if ( token[0] == '\0' ) break;
565  if ( isalpha((int) token[0]) || token[0] == '#' ) {
566  (void) ThrowMagickException(exception,GetMagickModule(),
567  OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
568  "Color found, instead of X-coord");
569  error = MagickTrue;
570  break;
571  }
572  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
573  /* Y coordinate */
574  token[0]=','; while ( token[0] == ',' ) GetNextToken(p,&p,MagickPathExtent,token);
575  if ( token[0] == '\0' ) break;
576  if ( isalpha((int) token[0]) || token[0] == '#' ) {
577  (void) ThrowMagickException(exception,GetMagickModule(),
578  OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
579  "Color found, instead of Y-coord");
580  error = MagickTrue;
581  break;
582  }
583  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
584  /* color values for this control point */
585 #if 0
586  if ( (color_from_image ) {
587  /* get color from image */
588  /* HOW??? */
589  }
590  else
591 #endif
592  {
593  /* color name or function given in string argument */
594  token[0]=','; while ( token[0] == ',' ) GetNextToken(p,&p,MagickPathExtent,token);
595  if ( token[0] == '\0' ) break;
596  if ( isalpha((int) token[0]) || token[0] == '#' ) {
597  /* Color string given */
598  (void) QueryColorCompliance(token,AllCompliance,&color,exception);
599  if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
600  sparse_arguments[x++] = QuantumScale*color.red;
601  if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
602  sparse_arguments[x++] = QuantumScale*color.green;
603  if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
604  sparse_arguments[x++] = QuantumScale*color.blue;
605  if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
606  (image->colorspace == CMYKColorspace))
607  sparse_arguments[x++] = QuantumScale*color.black;
608  if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
609  (image->alpha_trait != UndefinedPixelTrait))
610  sparse_arguments[x++] = QuantumScale*color.alpha;
611  }
612  else {
613  /* Colors given as a set of floating point values - experimental */
614  /* NB: token contains the first floating point value to use! */
615  if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
616  {
617  while ( token[0] == ',' ) GetNextToken(p,&p,MagickPathExtent,token);
618  if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
619  break;
620  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
621  token[0] = ','; /* used this token - get another */
622  }
623  if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
624  {
625  while ( token[0] == ',' ) GetNextToken(p,&p,MagickPathExtent,token);
626  if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
627  break;
628  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
629  token[0] = ','; /* used this token - get another */
630  }
631  if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
632  {
633  while ( token[0] == ',' ) GetNextToken(p,&p,MagickPathExtent,token);
634  if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
635  break;
636  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
637  token[0] = ','; /* used this token - get another */
638  }
639  if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
640  (image->colorspace == CMYKColorspace))
641  {
642  while ( token[0] == ',' ) GetNextToken(p,&p,MagickPathExtent,token);
643  if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
644  break;
645  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
646  token[0] = ','; /* used this token - get another */
647  }
648  if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
649  (image->alpha_trait != UndefinedPixelTrait))
650  {
651  while ( token[0] == ',' ) GetNextToken(p,&p,MagickPathExtent,token);
652  if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
653  break;
654  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
655  token[0] = ','; /* used this token - get another */
656  }
657  }
658  }
659  }
660  if ( number_arguments != x && !error ) {
661  (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
662  " InvalidArgument","'%s': %s","sparse-color","Argument Parsing Error");
663  sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
664  return( (Image *) NULL);
665  }
666  if ( error )
667  return( (Image *) NULL);
668 
669  /* Call the Interpolation function with the parsed arguments */
670  sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
671  exception);
672  sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
673  return( sparse_image );
674 }
675 
676 WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
677  const char **argv,Image **image,ExceptionInfo *exception)
678 {
679  CompositeOperator
680  compose;
681 
682  const char
683  *format,
684  *option;
685 
686  double
687  attenuate;
688 
689  DrawInfo
690  *draw_info;
691 
692  GeometryInfo
693  geometry_info;
694 
695  ImageInfo
696  *mogrify_info;
697 
698  MagickStatusType
699  status;
700 
701  PixelInfo
702  fill;
703 
704  MagickStatusType
705  flags;
706 
707  PixelInterpolateMethod
708  interpolate_method;
709 
710  QuantizeInfo
711  *quantize_info;
712 
713  RectangleInfo
714  geometry,
715  region_geometry;
716 
717  register ssize_t
718  i;
719 
720  /*
721  Initialize method variables.
722  */
723  assert(image_info != (const ImageInfo *) NULL);
724  assert(image_info->signature == MagickCoreSignature);
725  assert(image != (Image **) NULL);
726  assert((*image)->signature == MagickCoreSignature);
727  if ((*image)->debug != MagickFalse)
728  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
729  if (argc < 0)
730  return(MagickTrue);
731  mogrify_info=CloneImageInfo(image_info);
732  draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
733  quantize_info=AcquireQuantizeInfo(mogrify_info);
734  SetGeometryInfo(&geometry_info);
735  GetPixelInfo(*image,&fill);
736  fill=(*image)->background_color;
737  attenuate=1.0;
738  compose=(*image)->compose;
739  interpolate_method=UndefinedInterpolatePixel;
740  format=GetImageOption(mogrify_info,"format");
741  SetGeometry(*image,&region_geometry);
742  /*
743  Transmogrify the image.
744  */
745  for (i=0; i < (ssize_t) argc; i++)
746  {
747  Image
748  *mogrify_image;
749 
750  ssize_t
751  count;
752 
753  option=argv[i];
754  if (IsCommandOption(option) == MagickFalse)
755  continue;
756  count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
757  0L);
758  if ((i+count) >= (ssize_t) argc)
759  break;
760  status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
761  mogrify_image=(Image *) NULL;
762  switch (*(option+1))
763  {
764  case 'a':
765  {
766  if (LocaleCompare("adaptive-blur",option+1) == 0)
767  {
768  /*
769  Adaptive blur image.
770  */
771  (void) SyncImageSettings(mogrify_info,*image,exception);
772  flags=ParseGeometry(argv[i+1],&geometry_info);
773  if ((flags & SigmaValue) == 0)
774  geometry_info.sigma=1.0;
775  mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
776  geometry_info.sigma,exception);
777  break;
778  }
779  if (LocaleCompare("adaptive-resize",option+1) == 0)
780  {
781  /*
782  Adaptive resize image.
783  */
784  (void) SyncImageSettings(mogrify_info,*image,exception);
785  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
786  mogrify_image=AdaptiveResizeImage(*image,geometry.width,
787  geometry.height,exception);
788  break;
789  }
790  if (LocaleCompare("adaptive-sharpen",option+1) == 0)
791  {
792  /*
793  Adaptive sharpen image.
794  */
795  (void) SyncImageSettings(mogrify_info,*image,exception);
796  flags=ParseGeometry(argv[i+1],&geometry_info);
797  if ((flags & SigmaValue) == 0)
798  geometry_info.sigma=1.0;
799  mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
800  geometry_info.sigma,exception);
801  break;
802  }
803  if (LocaleCompare("affine",option+1) == 0)
804  {
805  /*
806  Affine matrix.
807  */
808  if (*option == '+')
809  {
810  GetAffineMatrix(&draw_info->affine);
811  break;
812  }
813  (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
814  break;
815  }
816  if (LocaleCompare("alpha",option+1) == 0)
817  {
818  AlphaChannelOption
819  alpha_type;
820 
821  (void) SyncImageSettings(mogrify_info,*image,exception);
822  alpha_type=(AlphaChannelOption) ParseCommandOption(
823  MagickAlphaChannelOptions,MagickFalse,argv[i+1]);
824  (void) SetImageAlphaChannel(*image,alpha_type,exception);
825  break;
826  }
827  if (LocaleCompare("annotate",option+1) == 0)
828  {
829  char
830  *text,
831  geometry_str[MagickPathExtent];
832 
833  /*
834  Annotate image.
835  */
836  (void) SyncImageSettings(mogrify_info,*image,exception);
837  SetGeometryInfo(&geometry_info);
838  flags=ParseGeometry(argv[i+1],&geometry_info);
839  if ((flags & SigmaValue) == 0)
840  geometry_info.sigma=geometry_info.rho;
841  text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
842  exception);
843  if (text == (char *) NULL)
844  break;
845  (void) CloneString(&draw_info->text,text);
846  text=DestroyString(text);
847  (void) FormatLocaleString(geometry_str,MagickPathExtent,"%+f%+f",
848  geometry_info.xi,geometry_info.psi);
849  (void) CloneString(&draw_info->geometry,geometry_str);
850  draw_info->affine.sx=cos(DegreesToRadians(
851  fmod(geometry_info.rho,360.0)));
852  draw_info->affine.rx=sin(DegreesToRadians(
853  fmod(geometry_info.rho,360.0)));
854  draw_info->affine.ry=(-sin(DegreesToRadians(
855  fmod(geometry_info.sigma,360.0))));
856  draw_info->affine.sy=cos(DegreesToRadians(
857  fmod(geometry_info.sigma,360.0)));
858  (void) AnnotateImage(*image,draw_info,exception);
859  break;
860  }
861  if (LocaleCompare("antialias",option+1) == 0)
862  {
863  draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
864  MagickFalse;
865  draw_info->text_antialias=(*option == '-') ? MagickTrue :
866  MagickFalse;
867  break;
868  }
869  if (LocaleCompare("attenuate",option+1) == 0)
870  {
871  if (*option == '+')
872  {
873  attenuate=1.0;
874  break;
875  }
876  attenuate=StringToDouble(argv[i+1],(char **) NULL);
877  break;
878  }
879  if (LocaleCompare("auto-gamma",option+1) == 0)
880  {
881  /*
882  Auto Adjust Gamma of image based on its mean
883  */
884  (void) SyncImageSettings(mogrify_info,*image,exception);
885  (void) AutoGammaImage(*image,exception);
886  break;
887  }
888  if (LocaleCompare("auto-level",option+1) == 0)
889  {
890  /*
891  Perfectly Normalize (max/min stretch) the image
892  */
893  (void) SyncImageSettings(mogrify_info,*image,exception);
894  (void) AutoLevelImage(*image,exception);
895  break;
896  }
897  if (LocaleCompare("auto-orient",option+1) == 0)
898  {
899  (void) SyncImageSettings(mogrify_info,*image,exception);
900  mogrify_image=AutoOrientImage(*image,(*image)->orientation,
901  exception);
902  break;
903  }
904  if (LocaleCompare("auto-threshold",option+1) == 0)
905  {
906  AutoThresholdMethod
907  method;
908 
909  (void) SyncImageSettings(mogrify_info,*image,exception);
910  method=(AutoThresholdMethod) ParseCommandOption(
911  MagickAutoThresholdOptions,MagickFalse,argv[i+1]);
912  (void) AutoThresholdImage(*image,method,exception);
913  break;
914  }
915  break;
916  }
917  case 'b':
918  {
919  if (LocaleCompare("black-threshold",option+1) == 0)
920  {
921  /*
922  Black threshold image.
923  */
924  (void) SyncImageSettings(mogrify_info,*image,exception);
925  (void) BlackThresholdImage(*image,argv[i+1],exception);
926  break;
927  }
928  if (LocaleCompare("blue-shift",option+1) == 0)
929  {
930  /*
931  Blue shift image.
932  */
933  (void) SyncImageSettings(mogrify_info,*image,exception);
934  geometry_info.rho=1.5;
935  if (*option == '-')
936  flags=ParseGeometry(argv[i+1],&geometry_info);
937  mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
938  break;
939  }
940  if (LocaleCompare("blur",option+1) == 0)
941  {
942  /*
943  Gaussian blur image.
944  */
945  (void) SyncImageSettings(mogrify_info,*image,exception);
946  flags=ParseGeometry(argv[i+1],&geometry_info);
947  if ((flags & SigmaValue) == 0)
948  geometry_info.sigma=1.0;
949  if ((flags & XiValue) == 0)
950  geometry_info.xi=0.0;
951  mogrify_image=BlurImage(*image,geometry_info.rho,
952  geometry_info.sigma,exception);
953  break;
954  }
955  if (LocaleCompare("border",option+1) == 0)
956  {
957  /*
958  Surround image with a border of solid color.
959  */
960  (void) SyncImageSettings(mogrify_info,*image,exception);
961  flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
962  mogrify_image=BorderImage(*image,&geometry,compose,exception);
963  break;
964  }
965  if (LocaleCompare("bordercolor",option+1) == 0)
966  {
967  if (*option == '+')
968  {
969  (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
970  &draw_info->border_color,exception);
971  break;
972  }
973  (void) QueryColorCompliance(argv[i+1],AllCompliance,
974  &draw_info->border_color,exception);
975  break;
976  }
977  if (LocaleCompare("box",option+1) == 0)
978  {
979  (void) QueryColorCompliance(argv[i+1],AllCompliance,
980  &draw_info->undercolor,exception);
981  break;
982  }
983  if (LocaleCompare("brightness-contrast",option+1) == 0)
984  {
985  double
986  brightness,
987  contrast;
988 
989  /*
990  Brightness / contrast image.
991  */
992  (void) SyncImageSettings(mogrify_info,*image,exception);
993  flags=ParseGeometry(argv[i+1],&geometry_info);
994  brightness=geometry_info.rho;
995  contrast=0.0;
996  if ((flags & SigmaValue) != 0)
997  contrast=geometry_info.sigma;
998  (void) BrightnessContrastImage(*image,brightness,contrast,
999  exception);
1000  break;
1001  }
1002  break;
1003  }
1004  case 'c':
1005  {
1006  if (LocaleCompare("canny",option+1) == 0)
1007  {
1008  /*
1009  Detect edges in the image.
1010  */
1011  (void) SyncImageSettings(mogrify_info,*image,exception);
1012  flags=ParseGeometry(argv[i+1],&geometry_info);
1013  if ((flags & SigmaValue) == 0)
1014  geometry_info.sigma=1.0;
1015  if ((flags & XiValue) == 0)
1016  geometry_info.xi=0.10;
1017  if ((flags & PsiValue) == 0)
1018  geometry_info.psi=0.30;
1019  if ((flags & PercentValue) != 0)
1020  {
1021  geometry_info.xi/=100.0;
1022  geometry_info.psi/=100.0;
1023  }
1024  mogrify_image=CannyEdgeImage(*image,geometry_info.rho,
1025  geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
1026  break;
1027  }
1028  if (LocaleCompare("cdl",option+1) == 0)
1029  {
1030  char
1031  *color_correction_collection;
1032 
1033  /*
1034  Color correct with a color decision list.
1035  */
1036  (void) SyncImageSettings(mogrify_info,*image,exception);
1037  color_correction_collection=FileToString(argv[i+1],~0UL,exception);
1038  if (color_correction_collection == (char *) NULL)
1039  break;
1040  (void) ColorDecisionListImage(*image,color_correction_collection,
1041  exception);
1042  break;
1043  }
1044  if (LocaleCompare("channel",option+1) == 0)
1045  {
1046  ChannelType
1047  channel;
1048 
1049  (void) SyncImageSettings(mogrify_info,*image,exception);
1050  if (*option == '+')
1051  {
1052  (void) SetPixelChannelMask(*image,DefaultChannels);
1053  break;
1054  }
1055  channel=(ChannelType) ParseChannelOption(argv[i+1]);
1056  (void) SetPixelChannelMask(*image,channel);
1057  break;
1058  }
1059  if (LocaleCompare("charcoal",option+1) == 0)
1060  {
1061  /*
1062  Charcoal image.
1063  */
1064  (void) SyncImageSettings(mogrify_info,*image,exception);
1065  flags=ParseGeometry(argv[i+1],&geometry_info);
1066  if ((flags & SigmaValue) == 0)
1067  geometry_info.sigma=1.0;
1068  if ((flags & XiValue) == 0)
1069  geometry_info.xi=1.0;
1070  mogrify_image=CharcoalImage(*image,geometry_info.rho,
1071  geometry_info.sigma,exception);
1072  break;
1073  }
1074  if (LocaleCompare("chop",option+1) == 0)
1075  {
1076  /*
1077  Chop the image.
1078  */
1079  (void) SyncImageSettings(mogrify_info,*image,exception);
1080  (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1081  mogrify_image=ChopImage(*image,&geometry,exception);
1082  break;
1083  }
1084  if (LocaleCompare("clahe",option+1) == 0)
1085  {
1086  /*
1087  Contrast limited adaptive histogram equalization.
1088  */
1089  (void) SyncImageSettings(mogrify_info,*image,exception);
1090  flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1091  flags=ParseGeometry(argv[i+1],&geometry_info);
1092  (void) CLAHEImage(*image,geometry.width,geometry.height,
1093  (size_t) geometry.x,geometry_info.psi,exception);
1094  break;
1095  }
1096  if (LocaleCompare("clip",option+1) == 0)
1097  {
1098  (void) SyncImageSettings(mogrify_info,*image,exception);
1099  if (*option == '+')
1100  {
1101  (void) SetImageMask(*image,WritePixelMask,(Image *) NULL,
1102  exception);
1103  break;
1104  }
1105  (void) ClipImage(*image,exception);
1106  break;
1107  }
1108  if (LocaleCompare("clip-mask",option+1) == 0)
1109  {
1110  Image
1111  *clip_mask;
1112 
1113  (void) SyncImageSettings(mogrify_info,*image,exception);
1114  if (*option == '+')
1115  {
1116  /*
1117  Remove a mask.
1118  */
1119  (void) SetImageMask(*image,WritePixelMask,(Image *) NULL,
1120  exception);
1121  break;
1122  }
1123  /*
1124  Set the image mask.
1125  */
1126  clip_mask=GetImageCache(mogrify_info,argv[i+1],exception);
1127  if (clip_mask == (Image *) NULL)
1128  break;
1129  (void) SetImageMask(*image,WritePixelMask,clip_mask,exception);
1130  clip_mask=DestroyImage(clip_mask);
1131  break;
1132  }
1133  if (LocaleCompare("clip-path",option+1) == 0)
1134  {
1135  (void) SyncImageSettings(mogrify_info,*image,exception);
1136  (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1137  MagickFalse,exception);
1138  break;
1139  }
1140  if (LocaleCompare("colorize",option+1) == 0)
1141  {
1142  /*
1143  Colorize the image.
1144  */
1145  (void) SyncImageSettings(mogrify_info,*image,exception);
1146  mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
1147  break;
1148  }
1149  if (LocaleCompare("color-matrix",option+1) == 0)
1150  {
1151  KernelInfo
1152  *kernel;
1153 
1154  (void) SyncImageSettings(mogrify_info,*image,exception);
1155  kernel=AcquireKernelInfo(argv[i+1],exception);
1156  if (kernel == (KernelInfo *) NULL)
1157  break;
1158  /* FUTURE: check on size of the matrix */
1159  mogrify_image=ColorMatrixImage(*image,kernel,exception);
1160  kernel=DestroyKernelInfo(kernel);
1161  break;
1162  }
1163  if (LocaleCompare("colors",option+1) == 0)
1164  {
1165  /*
1166  Reduce the number of colors in the image.
1167  */
1168  (void) SyncImageSettings(mogrify_info,*image,exception);
1169  quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1170  if (quantize_info->number_colors == 0)
1171  break;
1172  if (((*image)->storage_class == DirectClass) ||
1173  (*image)->colors > quantize_info->number_colors)
1174  (void) QuantizeImage(quantize_info,*image,exception);
1175  else
1176  (void) CompressImageColormap(*image,exception);
1177  break;
1178  }
1179  if (LocaleCompare("colorspace",option+1) == 0)
1180  {
1181  ColorspaceType
1182  colorspace;
1183 
1184  (void) SyncImageSettings(mogrify_info,*image,exception);
1185  if (*option == '+')
1186  {
1187  (void) TransformImageColorspace(*image,sRGBColorspace,
1188  exception);
1189  break;
1190  }
1191  colorspace=(ColorspaceType) ParseCommandOption(
1192  MagickColorspaceOptions,MagickFalse,argv[i+1]);
1193  (void) TransformImageColorspace(*image,colorspace,exception);
1194  break;
1195  }
1196  if (LocaleCompare("compose",option+1) == 0)
1197  {
1198  (void) SyncImageSettings(mogrify_info,*image,exception);
1199  compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1200  MagickFalse,argv[i+1]);
1201  break;
1202  }
1203  if (LocaleCompare("connected-components",option+1) == 0)
1204  {
1205  (void) SyncImageSettings(mogrify_info,*image,exception);
1206  mogrify_image=ConnectedComponentsImage(*image,(size_t)
1207  StringToInteger(argv[i+1]),(CCObjectInfo **) NULL,exception);
1208  break;
1209  }
1210  if (LocaleCompare("contrast",option+1) == 0)
1211  {
1212  (void) SyncImageSettings(mogrify_info,*image,exception);
1213  (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1214  MagickFalse,exception);
1215  break;
1216  }
1217  if (LocaleCompare("contrast-stretch",option+1) == 0)
1218  {
1219  double
1220  black_point,
1221  white_point;
1222 
1223  /*
1224  Contrast stretch image.
1225  */
1226  (void) SyncImageSettings(mogrify_info,*image,exception);
1227  flags=ParseGeometry(argv[i+1],&geometry_info);
1228  black_point=geometry_info.rho;
1229  white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1230  black_point;
1231  if ((flags & PercentValue) != 0)
1232  {
1233  black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1234  white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1235  }
1236  white_point=(double) (*image)->columns*(*image)->rows-
1237  white_point;
1238  (void) ContrastStretchImage(*image,black_point,white_point,
1239  exception);
1240  break;
1241  }
1242  if (LocaleCompare("convolve",option+1) == 0)
1243  {
1244  double
1245  gamma;
1246 
1247  KernelInfo
1248  *kernel_info;
1249 
1250  register ssize_t
1251  j;
1252 
1253  size_t
1254  extent;
1255 
1256  (void) SyncImageSettings(mogrify_info,*image,exception);
1257  kernel_info=AcquireKernelInfo(argv[i+1],exception);
1258  if (kernel_info == (KernelInfo *) NULL)
1259  break;
1260  extent=kernel_info->width*kernel_info->height;
1261  gamma=0.0;
1262  for (j=0; j < (ssize_t) extent; j++)
1263  gamma+=kernel_info->values[j];
1264  gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1265  for (j=0; j < (ssize_t) extent; j++)
1266  kernel_info->values[j]*=gamma;
1267  mogrify_image=MorphologyImage(*image,CorrelateMorphology,1,
1268  kernel_info,exception);
1269  kernel_info=DestroyKernelInfo(kernel_info);
1270  break;
1271  }
1272  if (LocaleCompare("crop",option+1) == 0)
1273  {
1274  /*
1275  Crop a image to a smaller size
1276  */
1277  (void) SyncImageSettings(mogrify_info,*image,exception);
1278  mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1279  break;
1280  }
1281  if (LocaleCompare("cycle",option+1) == 0)
1282  {
1283  /*
1284  Cycle an image colormap.
1285  */
1286  (void) SyncImageSettings(mogrify_info,*image,exception);
1287  (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1288  exception);
1289  break;
1290  }
1291  break;
1292  }
1293  case 'd':
1294  {
1295  if (LocaleCompare("decipher",option+1) == 0)
1296  {
1297  StringInfo
1298  *passkey;
1299 
1300  /*
1301  Decipher pixels.
1302  */
1303  (void) SyncImageSettings(mogrify_info,*image,exception);
1304  passkey=FileToStringInfo(argv[i+1],~0UL,exception);
1305  if (passkey != (StringInfo *) NULL)
1306  {
1307  (void) PasskeyDecipherImage(*image,passkey,exception);
1308  passkey=DestroyStringInfo(passkey);
1309  }
1310  break;
1311  }
1312  if (LocaleCompare("density",option+1) == 0)
1313  {
1314  /*
1315  Set image density.
1316  */
1317  (void) CloneString(&draw_info->density,argv[i+1]);
1318  break;
1319  }
1320  if (LocaleCompare("depth",option+1) == 0)
1321  {
1322  (void) SyncImageSettings(mogrify_info,*image,exception);
1323  if (*option == '+')
1324  {
1325  (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
1326  break;
1327  }
1328  (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1329  exception);
1330  break;
1331  }
1332  if (LocaleCompare("deskew",option+1) == 0)
1333  {
1334  double
1335  threshold;
1336 
1337  /*
1338  Straighten the image.
1339  */
1340  (void) SyncImageSettings(mogrify_info,*image,exception);
1341  if (*option == '+')
1342  threshold=40.0*QuantumRange/100.0;
1343  else
1344  threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1345  1.0);
1346  mogrify_image=DeskewImage(*image,threshold,exception);
1347  break;
1348  }
1349  if (LocaleCompare("despeckle",option+1) == 0)
1350  {
1351  /*
1352  Reduce the speckles within an image.
1353  */
1354  (void) SyncImageSettings(mogrify_info,*image,exception);
1355  mogrify_image=DespeckleImage(*image,exception);
1356  break;
1357  }
1358  if (LocaleCompare("display",option+1) == 0)
1359  {
1360  (void) CloneString(&draw_info->server_name,argv[i+1]);
1361  break;
1362  }
1363  if (LocaleCompare("distort",option+1) == 0)
1364  {
1365  char
1366  *args,
1367  token[MagickPathExtent];
1368 
1369  const char
1370  *p;
1371 
1372  DistortMethod
1373  method;
1374 
1375  double
1376  *arguments;
1377 
1378  register ssize_t
1379  x;
1380 
1381  size_t
1382  number_arguments;
1383 
1384  /*
1385  Distort image.
1386  */
1387  (void) SyncImageSettings(mogrify_info,*image,exception);
1388  method=(DistortMethod) ParseCommandOption(MagickDistortOptions,
1389  MagickFalse,argv[i+1]);
1390  if (method == ResizeDistortion)
1391  {
1392  double
1393  resize_args[2];
1394 
1395  /*
1396  Special Case - Argument is actually a resize geometry!
1397  Convert that to an appropriate distortion argument array.
1398  */
1399  (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1400  exception);
1401  resize_args[0]=(double) geometry.width;
1402  resize_args[1]=(double) geometry.height;
1403  mogrify_image=DistortImage(*image,method,(size_t)2,
1404  resize_args,MagickTrue,exception);
1405  break;
1406  }
1407  args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1408  exception);
1409  if (args == (char *) NULL)
1410  break;
1411  p=(char *) args;
1412  for (x=0; *p != '\0'; x++)
1413  {
1414  GetNextToken(p,&p,MagickPathExtent,token);
1415  if (*token == ',')
1416  GetNextToken(p,&p,MagickPathExtent,token);
1417  }
1418  number_arguments=(size_t) x;
1419  arguments=(double *) AcquireQuantumMemory(number_arguments,
1420  sizeof(*arguments));
1421  if (arguments == (double *) NULL)
1422  ThrowWandFatalException(ResourceLimitFatalError,
1423  "MemoryAllocationFailed",(*image)->filename);
1424  (void) memset(arguments,0,number_arguments*
1425  sizeof(*arguments));
1426  p=(char *) args;
1427  for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1428  {
1429  GetNextToken(p,&p,MagickPathExtent,token);
1430  if (*token == ',')
1431  GetNextToken(p,&p,MagickPathExtent,token);
1432  arguments[x]=StringToDouble(token,(char **) NULL);
1433  }
1434  args=DestroyString(args);
1435  mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1436  (*option == '+') ? MagickTrue : MagickFalse,exception);
1437  arguments=(double *) RelinquishMagickMemory(arguments);
1438  break;
1439  }
1440  if (LocaleCompare("dither",option+1) == 0)
1441  {
1442  if (*option == '+')
1443  {
1444  quantize_info->dither_method=NoDitherMethod;
1445  break;
1446  }
1447  quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1448  MagickDitherOptions,MagickFalse,argv[i+1]);
1449  break;
1450  }
1451  if (LocaleCompare("draw",option+1) == 0)
1452  {
1453  /*
1454  Draw image.
1455  */
1456  (void) SyncImageSettings(mogrify_info,*image,exception);
1457  (void) CloneString(&draw_info->primitive,argv[i+1]);
1458  (void) DrawImage(*image,draw_info,exception);
1459  break;
1460  }
1461  break;
1462  }
1463  case 'e':
1464  {
1465  if (LocaleCompare("edge",option+1) == 0)
1466  {
1467  /*
1468  Enhance edges in the image.
1469  */
1470  (void) SyncImageSettings(mogrify_info,*image,exception);
1471  flags=ParseGeometry(argv[i+1],&geometry_info);
1472  mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1473  break;
1474  }
1475  if (LocaleCompare("emboss",option+1) == 0)
1476  {
1477  /*
1478  Emboss image.
1479  */
1480  (void) SyncImageSettings(mogrify_info,*image,exception);
1481  flags=ParseGeometry(argv[i+1],&geometry_info);
1482  if ((flags & SigmaValue) == 0)
1483  geometry_info.sigma=1.0;
1484  mogrify_image=EmbossImage(*image,geometry_info.rho,
1485  geometry_info.sigma,exception);
1486  break;
1487  }
1488  if (LocaleCompare("encipher",option+1) == 0)
1489  {
1490  StringInfo
1491  *passkey;
1492 
1493  /*
1494  Encipher pixels.
1495  */
1496  (void) SyncImageSettings(mogrify_info,*image,exception);
1497  passkey=FileToStringInfo(argv[i+1],~0UL,exception);
1498  if (passkey != (StringInfo *) NULL)
1499  {
1500  (void) PasskeyEncipherImage(*image,passkey,exception);
1501  passkey=DestroyStringInfo(passkey);
1502  }
1503  break;
1504  }
1505  if (LocaleCompare("encoding",option+1) == 0)
1506  {
1507  (void) CloneString(&draw_info->encoding,argv[i+1]);
1508  break;
1509  }
1510  if (LocaleCompare("enhance",option+1) == 0)
1511  {
1512  /*
1513  Enhance image.
1514  */
1515  (void) SyncImageSettings(mogrify_info,*image,exception);
1516  mogrify_image=EnhanceImage(*image,exception);
1517  break;
1518  }
1519  if (LocaleCompare("equalize",option+1) == 0)
1520  {
1521  /*
1522  Equalize image.
1523  */
1524  (void) SyncImageSettings(mogrify_info,*image,exception);
1525  (void) EqualizeImage(*image,exception);
1526  break;
1527  }
1528  if (LocaleCompare("evaluate",option+1) == 0)
1529  {
1530  double
1531  constant;
1532 
1533  MagickEvaluateOperator
1534  op;
1535 
1536  (void) SyncImageSettings(mogrify_info,*image,exception);
1537  op=(MagickEvaluateOperator) ParseCommandOption(
1538  MagickEvaluateOptions,MagickFalse,argv[i+1]);
1539  constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1540  1.0);
1541  (void) EvaluateImage(*image,op,constant,exception);
1542  break;
1543  }
1544  if (LocaleCompare("extent",option+1) == 0)
1545  {
1546  /*
1547  Set the image extent.
1548  */
1549  (void) SyncImageSettings(mogrify_info,*image,exception);
1550  flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1551  if (geometry.width == 0)
1552  geometry.width=(*image)->columns;
1553  if (geometry.height == 0)
1554  geometry.height=(*image)->rows;
1555  mogrify_image=ExtentImage(*image,&geometry,exception);
1556  break;
1557  }
1558  break;
1559  }
1560  case 'f':
1561  {
1562  if (LocaleCompare("family",option+1) == 0)
1563  {
1564  if (*option == '+')
1565  {
1566  if (draw_info->family != (char *) NULL)
1567  draw_info->family=DestroyString(draw_info->family);
1568  break;
1569  }
1570  (void) CloneString(&draw_info->family,argv[i+1]);
1571  break;
1572  }
1573  if (LocaleCompare("features",option+1) == 0)
1574  {
1575  if (*option == '+')
1576  {
1577  (void) DeleteImageArtifact(*image,"identify:features");
1578  break;
1579  }
1580  (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1581  (void) SetImageArtifact(*image,"verbose","true");
1582  break;
1583  }
1584  if (LocaleCompare("fill",option+1) == 0)
1585  {
1586  ExceptionInfo
1587  *sans;
1588 
1589  PixelInfo
1590  color;
1591 
1592  GetPixelInfo(*image,&fill);
1593  if (*option == '+')
1594  {
1595  (void) QueryColorCompliance("none",AllCompliance,&fill,
1596  exception);
1597  draw_info->fill=fill;
1598  if (draw_info->fill_pattern != (Image *) NULL)
1599  draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1600  break;
1601  }
1602  sans=AcquireExceptionInfo();
1603  status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
1604  sans=DestroyExceptionInfo(sans);
1605  if (status == MagickFalse)
1606  draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1607  exception);
1608  else
1609  draw_info->fill=fill=color;
1610  break;
1611  }
1612  if (LocaleCompare("flip",option+1) == 0)
1613  {
1614  /*
1615  Flip image scanlines.
1616  */
1617  (void) SyncImageSettings(mogrify_info,*image,exception);
1618  mogrify_image=FlipImage(*image,exception);
1619  break;
1620  }
1621  if (LocaleCompare("floodfill",option+1) == 0)
1622  {
1623  PixelInfo
1624  target;
1625 
1626  /*
1627  Floodfill image.
1628  */
1629  (void) SyncImageSettings(mogrify_info,*image,exception);
1630  (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1631  (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
1632  exception);
1633  (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
1634  geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
1635  break;
1636  }
1637  if (LocaleCompare("flop",option+1) == 0)
1638  {
1639  /*
1640  Flop image scanlines.
1641  */
1642  (void) SyncImageSettings(mogrify_info,*image,exception);
1643  mogrify_image=FlopImage(*image,exception);
1644  break;
1645  }
1646  if (LocaleCompare("font",option+1) == 0)
1647  {
1648  if (*option == '+')
1649  {
1650  if (draw_info->font != (char *) NULL)
1651  draw_info->font=DestroyString(draw_info->font);
1652  break;
1653  }
1654  (void) CloneString(&draw_info->font,argv[i+1]);
1655  break;
1656  }
1657  if (LocaleCompare("format",option+1) == 0)
1658  {
1659  format=argv[i+1];
1660  break;
1661  }
1662  if (LocaleCompare("frame",option+1) == 0)
1663  {
1664  FrameInfo
1665  frame_info;
1666 
1667  /*
1668  Surround image with an ornamental border.
1669  */
1670  (void) SyncImageSettings(mogrify_info,*image,exception);
1671  flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1672  frame_info.width=geometry.width;
1673  frame_info.height=geometry.height;
1674  frame_info.outer_bevel=geometry.x;
1675  frame_info.inner_bevel=geometry.y;
1676  frame_info.x=(ssize_t) frame_info.width;
1677  frame_info.y=(ssize_t) frame_info.height;
1678  frame_info.width=(*image)->columns+2*frame_info.width;
1679  frame_info.height=(*image)->rows+2*frame_info.height;
1680  mogrify_image=FrameImage(*image,&frame_info,compose,exception);
1681  break;
1682  }
1683  if (LocaleCompare("function",option+1) == 0)
1684  {
1685  char
1686  *arguments,
1687  token[MagickPathExtent];
1688 
1689  const char
1690  *p;
1691 
1692  double
1693  *parameters;
1694 
1695  MagickFunction
1696  function;
1697 
1698  register ssize_t
1699  x;
1700 
1701  size_t
1702  number_parameters;
1703 
1704  /*
1705  Function Modify Image Values
1706  */
1707  (void) SyncImageSettings(mogrify_info,*image,exception);
1708  function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1709  MagickFalse,argv[i+1]);
1710  arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1711  exception);
1712  if (arguments == (char *) NULL)
1713  break;
1714  p=(char *) arguments;
1715  for (x=0; *p != '\0'; x++)
1716  {
1717  GetNextToken(p,&p,MagickPathExtent,token);
1718  if (*token == ',')
1719  GetNextToken(p,&p,MagickPathExtent,token);
1720  }
1721  number_parameters=(size_t) x;
1722  parameters=(double *) AcquireQuantumMemory(number_parameters,
1723  sizeof(*parameters));
1724  if (parameters == (double *) NULL)
1725  ThrowWandFatalException(ResourceLimitFatalError,
1726  "MemoryAllocationFailed",(*image)->filename);
1727  (void) memset(parameters,0,number_parameters*
1728  sizeof(*parameters));
1729  p=(char *) arguments;
1730  for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1731  {
1732  GetNextToken(p,&p,MagickPathExtent,token);
1733  if (*token == ',')
1734  GetNextToken(p,&p,MagickPathExtent,token);
1735  parameters[x]=StringToDouble(token,(char **) NULL);
1736  }
1737  arguments=DestroyString(arguments);
1738  (void) FunctionImage(*image,function,number_parameters,parameters,
1739  exception);
1740  parameters=(double *) RelinquishMagickMemory(parameters);
1741  break;
1742  }
1743  break;
1744  }
1745  case 'g':
1746  {
1747  if (LocaleCompare("gamma",option+1) == 0)
1748  {
1749  /*
1750  Gamma image.
1751  */
1752  (void) SyncImageSettings(mogrify_info,*image,exception);
1753  if (*option == '+')
1754  (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
1755  else
1756  (void) GammaImage(*image,StringToDouble(argv[i+1],(char **) NULL),
1757  exception);
1758  break;
1759  }
1760  if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1761  (LocaleCompare("gaussian",option+1) == 0))
1762  {
1763  /*
1764  Gaussian blur image.
1765  */
1766  (void) SyncImageSettings(mogrify_info,*image,exception);
1767  flags=ParseGeometry(argv[i+1],&geometry_info);
1768  if ((flags & SigmaValue) == 0)
1769  geometry_info.sigma=1.0;
1770  mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1771  geometry_info.sigma,exception);
1772  break;
1773  }
1774  if (LocaleCompare("geometry",option+1) == 0)
1775  {
1776  /*
1777  Record Image offset, Resize last image.
1778  */
1779  (void) SyncImageSettings(mogrify_info,*image,exception);
1780  if (*option == '+')
1781  {
1782  if ((*image)->geometry != (char *) NULL)
1783  (*image)->geometry=DestroyString((*image)->geometry);
1784  break;
1785  }
1786  flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1787  if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1788  (void) CloneString(&(*image)->geometry,argv[i+1]);
1789  else
1790  mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1791  (*image)->filter,exception);
1792  break;
1793  }
1794  if (LocaleCompare("gravity",option+1) == 0)
1795  {
1796  if (*option == '+')
1797  {
1798  draw_info->gravity=UndefinedGravity;
1799  break;
1800  }
1801  draw_info->gravity=(GravityType) ParseCommandOption(
1802  MagickGravityOptions,MagickFalse,argv[i+1]);
1803  break;
1804  }
1805  if (LocaleCompare("grayscale",option+1) == 0)
1806  {
1807  PixelIntensityMethod
1808  method;
1809 
1810  (void) SyncImageSettings(mogrify_info,*image,exception);
1811  method=(PixelIntensityMethod) ParseCommandOption(
1812  MagickPixelIntensityOptions,MagickFalse,argv[i+1]);
1813  (void) GrayscaleImage(*image,method,exception);
1814  break;
1815  }
1816  break;
1817  }
1818  case 'h':
1819  {
1820  if (LocaleCompare("highlight-color",option+1) == 0)
1821  {
1822  (void) SetImageArtifact(*image,"compare:highlight-color",argv[i+1]);
1823  break;
1824  }
1825  if (LocaleCompare("hough-lines",option+1) == 0)
1826  {
1827  /*
1828  Detect edges in the image.
1829  */
1830  (void) SyncImageSettings(mogrify_info,*image,exception);
1831  flags=ParseGeometry(argv[i+1],&geometry_info);
1832  if ((flags & SigmaValue) == 0)
1833  geometry_info.sigma=geometry_info.rho;
1834  if ((flags & XiValue) == 0)
1835  geometry_info.xi=40;
1836  mogrify_image=HoughLineImage(*image,(size_t) geometry_info.rho,
1837  (size_t) geometry_info.sigma,(size_t) geometry_info.xi,exception);
1838  break;
1839  }
1840  break;
1841  }
1842  case 'i':
1843  {
1844  if (LocaleCompare("identify",option+1) == 0)
1845  {
1846  char
1847  *text;
1848 
1849  (void) SyncImageSettings(mogrify_info,*image,exception);
1850  if (format == (char *) NULL)
1851  {
1852  (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1853  exception);
1854  break;
1855  }
1856  text=InterpretImageProperties(mogrify_info,*image,format,
1857  exception);
1858  if (text == (char *) NULL)
1859  break;
1860  (void) fputs(text,stdout);
1861  text=DestroyString(text);
1862  break;
1863  }
1864  if (LocaleCompare("implode",option+1) == 0)
1865  {
1866  /*
1867  Implode image.
1868  */
1869  (void) SyncImageSettings(mogrify_info,*image,exception);
1870  (void) ParseGeometry(argv[i+1],&geometry_info);
1871  mogrify_image=ImplodeImage(*image,geometry_info.rho,
1872  interpolate_method,exception);
1873  break;
1874  }
1875  if (LocaleCompare("interline-spacing",option+1) == 0)
1876  {
1877  if (*option == '+')
1878  (void) ParseGeometry("0",&geometry_info);
1879  else
1880  (void) ParseGeometry(argv[i+1],&geometry_info);
1881  draw_info->interline_spacing=geometry_info.rho;
1882  break;
1883  }
1884  if (LocaleCompare("interpolate",option+1) == 0)
1885  {
1886  interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1887  MagickInterpolateOptions,MagickFalse,argv[i+1]);
1888  break;
1889  }
1890  if (LocaleCompare("interword-spacing",option+1) == 0)
1891  {
1892  if (*option == '+')
1893  (void) ParseGeometry("0",&geometry_info);
1894  else
1895  (void) ParseGeometry(argv[i+1],&geometry_info);
1896  draw_info->interword_spacing=geometry_info.rho;
1897  break;
1898  }
1899  if (LocaleCompare("interpolative-resize",option+1) == 0)
1900  {
1901  /*
1902  Interpolative resize image.
1903  */
1904  (void) SyncImageSettings(mogrify_info,*image,exception);
1905  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1906  mogrify_image=InterpolativeResizeImage(*image,geometry.width,
1907  geometry.height,interpolate_method,exception);
1908  break;
1909  }
1910  break;
1911  }
1912  case 'k':
1913  {
1914  if (LocaleCompare("kerning",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->kerning=geometry_info.rho;
1921  break;
1922  }
1923  if (LocaleCompare("kuwahara",option+1) == 0)
1924  {
1925  /*
1926  Edge preserving blur.
1927  */
1928  (void) SyncImageSettings(mogrify_info,*image,exception);
1929  flags=ParseGeometry(argv[i+1],&geometry_info);
1930  if ((flags & SigmaValue) == 0)
1931  geometry_info.sigma=geometry_info.rho-0.5;
1932  mogrify_image=KuwaharaImage(*image,geometry_info.rho,
1933  geometry_info.sigma,exception);
1934  break;
1935  }
1936  break;
1937  }
1938  case 'l':
1939  {
1940  if (LocaleCompare("lat",option+1) == 0)
1941  {
1942  /*
1943  Local adaptive threshold image.
1944  */
1945  (void) SyncImageSettings(mogrify_info,*image,exception);
1946  flags=ParseGeometry(argv[i+1],&geometry_info);
1947  if ((flags & PercentValue) != 0)
1948  geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1949  mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1950  geometry_info.rho,(size_t) geometry_info.sigma,(double)
1951  geometry_info.xi,exception);
1952  break;
1953  }
1954  if (LocaleCompare("level",option+1) == 0)
1955  {
1956  double
1957  black_point,
1958  gamma,
1959  white_point;
1960 
1961  /*
1962  Parse levels.
1963  */
1964  (void) SyncImageSettings(mogrify_info,*image,exception);
1965  flags=ParseGeometry(argv[i+1],&geometry_info);
1966  black_point=geometry_info.rho;
1967  white_point=(double) QuantumRange;
1968  if ((flags & SigmaValue) != 0)
1969  white_point=geometry_info.sigma;
1970  gamma=1.0;
1971  if ((flags & XiValue) != 0)
1972  gamma=geometry_info.xi;
1973  if ((flags & PercentValue) != 0)
1974  {
1975  black_point*=(double) (QuantumRange/100.0);
1976  white_point*=(double) (QuantumRange/100.0);
1977  }
1978  if ((flags & SigmaValue) == 0)
1979  white_point=(double) QuantumRange-black_point;
1980  if ((*option == '+') || ((flags & AspectValue) != 0))
1981  (void) LevelizeImage(*image,black_point,white_point,gamma,
1982  exception);
1983  else
1984  (void) LevelImage(*image,black_point,white_point,gamma,
1985  exception);
1986  break;
1987  }
1988  if (LocaleCompare("level-colors",option+1) == 0)
1989  {
1990  char
1991  token[MagickPathExtent];
1992 
1993  const char
1994  *p;
1995 
1996  PixelInfo
1997  black_point,
1998  white_point;
1999 
2000  p=(const char *) argv[i+1];
2001  GetNextToken(p,&p,MagickPathExtent,token); /* get black point color */
2002  if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
2003  (void) QueryColorCompliance(token,AllCompliance,
2004  &black_point,exception);
2005  else
2006  (void) QueryColorCompliance("#000000",AllCompliance,
2007  &black_point,exception);
2008  if (isalpha((int) token[0]) || (token[0] == '#'))
2009  GetNextToken(p,&p,MagickPathExtent,token);
2010  if (*token == '\0')
2011  white_point=black_point; /* set everything to that color */
2012  else
2013  {
2014  if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
2015  GetNextToken(p,&p,MagickPathExtent,token); /* Get white point color. */
2016  if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
2017  (void) QueryColorCompliance(token,AllCompliance,
2018  &white_point,exception);
2019  else
2020  (void) QueryColorCompliance("#ffffff",AllCompliance,
2021  &white_point,exception);
2022  }
2023  (void) LevelImageColors(*image,&black_point,&white_point,
2024  *option == '+' ? MagickTrue : MagickFalse,exception);
2025  break;
2026  }
2027  if (LocaleCompare("linear-stretch",option+1) == 0)
2028  {
2029  double
2030  black_point,
2031  white_point;
2032 
2033  (void) SyncImageSettings(mogrify_info,*image,exception);
2034  flags=ParseGeometry(argv[i+1],&geometry_info);
2035  black_point=geometry_info.rho;
2036  white_point=(double) (*image)->columns*(*image)->rows;
2037  if ((flags & SigmaValue) != 0)
2038  white_point=geometry_info.sigma;
2039  if ((flags & PercentValue) != 0)
2040  {
2041  black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2042  white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2043  }
2044  if ((flags & SigmaValue) == 0)
2045  white_point=(double) (*image)->columns*(*image)->rows-
2046  black_point;
2047  (void) LinearStretchImage(*image,black_point,white_point,exception);
2048  break;
2049  }
2050  if (LocaleCompare("liquid-rescale",option+1) == 0)
2051  {
2052  /*
2053  Liquid rescale image.
2054  */
2055  (void) SyncImageSettings(mogrify_info,*image,exception);
2056  flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2057  if ((flags & XValue) == 0)
2058  geometry.x=1;
2059  if ((flags & YValue) == 0)
2060  geometry.y=0;
2061  mogrify_image=LiquidRescaleImage(*image,geometry.width,
2062  geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2063  break;
2064  }
2065  if (LocaleCompare("local-contrast",option+1) == 0)
2066  {
2067  (void) SyncImageSettings(mogrify_info,*image,exception);
2068  flags=ParseGeometry(argv[i+1],&geometry_info);
2069  if ((flags & RhoValue) == 0)
2070  geometry_info.rho=10;
2071  if ((flags & SigmaValue) == 0)
2072  geometry_info.sigma=12.5;
2073  mogrify_image=LocalContrastImage(*image,geometry_info.rho,
2074  geometry_info.sigma,exception);
2075  break;
2076  }
2077  if (LocaleCompare("lowlight-color",option+1) == 0)
2078  {
2079  (void) SetImageArtifact(*image,"compare:lowlight-color",argv[i+1]);
2080  break;
2081  }
2082  break;
2083  }
2084  case 'm':
2085  {
2086  if (LocaleCompare("magnify",option+1) == 0)
2087  {
2088  /*
2089  Double image size.
2090  */
2091  (void) SyncImageSettings(mogrify_info,*image,exception);
2092  mogrify_image=MagnifyImage(*image,exception);
2093  break;
2094  }
2095  if (LocaleCompare("map",option+1) == 0)
2096  {
2097  Image
2098  *remap_image;
2099 
2100  /*
2101  Transform image colors to match this set of colors.
2102  */
2103  (void) SyncImageSettings(mogrify_info,*image,exception);
2104  if (*option == '+')
2105  break;
2106  remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2107  if (remap_image == (Image *) NULL)
2108  break;
2109  (void) RemapImage(quantize_info,*image,remap_image,exception);
2110  remap_image=DestroyImage(remap_image);
2111  break;
2112  }
2113  if (LocaleCompare("mask",option+1) == 0)
2114  {
2115  Image
2116  *mask;
2117 
2118  (void) SyncImageSettings(mogrify_info,*image,exception);
2119  if (*option == '+')
2120  {
2121  /*
2122  Remove a mask.
2123  */
2124  (void) SetImageMask(*image,WritePixelMask,(Image *) NULL,
2125  exception);
2126  break;
2127  }
2128  /*
2129  Set the image mask.
2130  */
2131  mask=GetImageCache(mogrify_info,argv[i+1],exception);
2132  if (mask == (Image *) NULL)
2133  break;
2134  (void) SetImageMask(*image,WritePixelMask,mask,exception);
2135  mask=DestroyImage(mask);
2136  break;
2137  }
2138  if (LocaleCompare("matte",option+1) == 0)
2139  {
2140  (void) SetImageAlphaChannel(*image,(*option == '-') ?
2141  SetAlphaChannel : DeactivateAlphaChannel,exception);
2142  break;
2143  }
2144  if (LocaleCompare("mean-shift",option+1) == 0)
2145  {
2146  /*
2147  Detect edges in the image.
2148  */
2149  (void) SyncImageSettings(mogrify_info,*image,exception);
2150  flags=ParseGeometry(argv[i+1],&geometry_info);
2151  if ((flags & SigmaValue) == 0)
2152  geometry_info.sigma=geometry_info.rho;
2153  if ((flags & XiValue) == 0)
2154  geometry_info.xi=0.10*QuantumRange;
2155  if ((flags & PercentValue) != 0)
2156  geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2157  mogrify_image=MeanShiftImage(*image,(size_t) geometry_info.rho,
2158  (size_t) geometry_info.sigma,geometry_info.xi,exception);
2159  break;
2160  }
2161  if (LocaleCompare("median",option+1) == 0)
2162  {
2163  /*
2164  Median filter image.
2165  */
2166  (void) SyncImageSettings(mogrify_info,*image,exception);
2167  flags=ParseGeometry(argv[i+1],&geometry_info);
2168  if ((flags & SigmaValue) == 0)
2169  geometry_info.sigma=geometry_info.rho;
2170  mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2171  geometry_info.rho,(size_t) geometry_info.sigma,exception);
2172  break;
2173  }
2174  if (LocaleCompare("mode",option+1) == 0)
2175  {
2176  /*
2177  Mode image.
2178  */
2179  (void) SyncImageSettings(mogrify_info,*image,exception);
2180  flags=ParseGeometry(argv[i+1],&geometry_info);
2181  if ((flags & SigmaValue) == 0)
2182  geometry_info.sigma=geometry_info.rho;
2183  mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2184  geometry_info.rho,(size_t) geometry_info.sigma,exception);
2185  break;
2186  }
2187  if (LocaleCompare("modulate",option+1) == 0)
2188  {
2189  (void) SyncImageSettings(mogrify_info,*image,exception);
2190  (void) ModulateImage(*image,argv[i+1],exception);
2191  break;
2192  }
2193  if (LocaleCompare("moments",option+1) == 0)
2194  {
2195  if (*option == '+')
2196  {
2197  (void) DeleteImageArtifact(*image,"identify:moments");
2198  break;
2199  }
2200  (void) SetImageArtifact(*image,"identify:moments",argv[i+1]);
2201  (void) SetImageArtifact(*image,"verbose","true");
2202  break;
2203  }
2204  if (LocaleCompare("monitor",option+1) == 0)
2205  {
2206  if (*option == '+')
2207  {
2208  (void) SetImageProgressMonitor(*image,
2209  (MagickProgressMonitor) NULL,(void *) NULL);
2210  break;
2211  }
2212  (void) SetImageProgressMonitor(*image,MonitorProgress,
2213  (void *) NULL);
2214  break;
2215  }
2216  if (LocaleCompare("monochrome",option+1) == 0)
2217  {
2218  (void) SyncImageSettings(mogrify_info,*image,exception);
2219  (void) SetImageType(*image,BilevelType,exception);
2220  break;
2221  }
2222  if (LocaleCompare("morphology",option+1) == 0)
2223  {
2224  char
2225  token[MagickPathExtent];
2226 
2227  const char
2228  *p;
2229 
2230  KernelInfo
2231  *kernel;
2232 
2233  MorphologyMethod
2234  method;
2235 
2236  ssize_t
2237  iterations;
2238 
2239  /*
2240  Morphological Image Operation
2241  */
2242  (void) SyncImageSettings(mogrify_info,*image,exception);
2243  p=argv[i+1];
2244  GetNextToken(p,&p,MagickPathExtent,token);
2245  method=(MorphologyMethod) ParseCommandOption(
2246  MagickMorphologyOptions,MagickFalse,token);
2247  iterations=1L;
2248  GetNextToken(p,&p,MagickPathExtent,token);
2249  if ((*p == ':') || (*p == ','))
2250  GetNextToken(p,&p,MagickPathExtent,token);
2251  if ((*p != '\0'))
2252  iterations=(ssize_t) StringToLong(p);
2253  kernel=AcquireKernelInfo(argv[i+2],exception);
2254  if (kernel == (KernelInfo *) NULL)
2255  {
2256  (void) ThrowMagickException(exception,GetMagickModule(),
2257  OptionError,"UnabletoParseKernel","morphology");
2258  status=MagickFalse;
2259  break;
2260  }
2261  mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2262  exception);
2263  kernel=DestroyKernelInfo(kernel);
2264  break;
2265  }
2266  if (LocaleCompare("motion-blur",option+1) == 0)
2267  {
2268  /*
2269  Motion blur image.
2270  */
2271  (void) SyncImageSettings(mogrify_info,*image,exception);
2272  flags=ParseGeometry(argv[i+1],&geometry_info);
2273  if ((flags & SigmaValue) == 0)
2274  geometry_info.sigma=1.0;
2275  mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2276  geometry_info.sigma,geometry_info.xi,exception);
2277  break;
2278  }
2279  break;
2280  }
2281  case 'n':
2282  {
2283  if (LocaleCompare("negate",option+1) == 0)
2284  {
2285  (void) SyncImageSettings(mogrify_info,*image,exception);
2286  (void) NegateImage(*image,*option == '+' ? MagickTrue :
2287  MagickFalse,exception);
2288  break;
2289  }
2290  if (LocaleCompare("noise",option+1) == 0)
2291  {
2292  (void) SyncImageSettings(mogrify_info,*image,exception);
2293  if (*option == '-')
2294  {
2295  flags=ParseGeometry(argv[i+1],&geometry_info);
2296  if ((flags & SigmaValue) == 0)
2297  geometry_info.sigma=geometry_info.rho;
2298  mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2299  geometry_info.rho,(size_t) geometry_info.sigma,exception);
2300  }
2301  else
2302  {
2303  NoiseType
2304  noise;
2305 
2306  noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2307  MagickFalse,argv[i+1]);
2308  mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
2309  }
2310  break;
2311  }
2312  if (LocaleCompare("normalize",option+1) == 0)
2313  {
2314  (void) SyncImageSettings(mogrify_info,*image,exception);
2315  (void) NormalizeImage(*image,exception);
2316  break;
2317  }
2318  break;
2319  }
2320  case 'o':
2321  {
2322  if (LocaleCompare("opaque",option+1) == 0)
2323  {
2324  PixelInfo
2325  target;
2326 
2327  (void) SyncImageSettings(mogrify_info,*image,exception);
2328  (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
2329  exception);
2330  (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2331  MagickFalse : MagickTrue,exception);
2332  break;
2333  }
2334  if (LocaleCompare("ordered-dither",option+1) == 0)
2335  {
2336  (void) SyncImageSettings(mogrify_info,*image,exception);
2337  (void) OrderedDitherImage(*image,argv[i+1],exception);
2338  break;
2339  }
2340  break;
2341  }
2342  case 'p':
2343  {
2344  if (LocaleCompare("paint",option+1) == 0)
2345  {
2346  (void) SyncImageSettings(mogrify_info,*image,exception);
2347  (void) ParseGeometry(argv[i+1],&geometry_info);
2348  mogrify_image=OilPaintImage(*image,geometry_info.rho,
2349  geometry_info.sigma,exception);
2350  break;
2351  }
2352  if (LocaleCompare("perceptible",option+1) == 0)
2353  {
2354  /*
2355  Perceptible image.
2356  */
2357  (void) SyncImageSettings(mogrify_info,*image,exception);
2358  (void) PerceptibleImage(*image,StringToDouble(argv[i+1],
2359  (char **) NULL),exception);
2360  break;
2361  }
2362  if (LocaleCompare("pointsize",option+1) == 0)
2363  {
2364  if (*option == '+')
2365  (void) ParseGeometry("12",&geometry_info);
2366  else
2367  (void) ParseGeometry(argv[i+1],&geometry_info);
2368  draw_info->pointsize=geometry_info.rho;
2369  break;
2370  }
2371  if (LocaleCompare("polaroid",option+1) == 0)
2372  {
2373  const char
2374  *caption;
2375 
2376  double
2377  angle;
2378 
2379  RandomInfo
2380  *random_info;
2381 
2382  /*
2383  Simulate a Polaroid picture.
2384  */
2385  (void) SyncImageSettings(mogrify_info,*image,exception);
2386  random_info=AcquireRandomInfo();
2387  angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2388  random_info=DestroyRandomInfo(random_info);
2389  if (*option == '-')
2390  {
2391  SetGeometryInfo(&geometry_info);
2392  flags=ParseGeometry(argv[i+1],&geometry_info);
2393  angle=geometry_info.rho;
2394  }
2395  caption=GetImageProperty(*image,"caption",exception);
2396  mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
2397  interpolate_method,exception);
2398  break;
2399  }
2400  if (LocaleCompare("posterize",option+1) == 0)
2401  {
2402  /*
2403  Posterize image.
2404  */
2405  (void) SyncImageSettings(mogrify_info,*image,exception);
2406  (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2407  quantize_info->dither_method,exception);
2408  break;
2409  }
2410  if (LocaleCompare("preview",option+1) == 0)
2411  {
2412  PreviewType
2413  preview_type;
2414 
2415  /*
2416  Preview image.
2417  */
2418  (void) SyncImageSettings(mogrify_info,*image,exception);
2419  if (*option == '+')
2420  preview_type=UndefinedPreview;
2421  else
2422  preview_type=(PreviewType) ParseCommandOption(
2423  MagickPreviewOptions,MagickFalse,argv[i+1]);
2424  mogrify_image=PreviewImage(*image,preview_type,exception);
2425  break;
2426  }
2427  if (LocaleCompare("profile",option+1) == 0)
2428  {
2429  const char
2430  *name;
2431 
2432  const StringInfo
2433  *profile;
2434 
2435  Image
2436  *profile_image;
2437 
2438  ImageInfo
2439  *profile_info;
2440 
2441  (void) SyncImageSettings(mogrify_info,*image,exception);
2442  if (*option == '+')
2443  {
2444  /*
2445  Remove a profile from the image.
2446  */
2447  (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2448  NULL,0,exception);
2449  break;
2450  }
2451  /*
2452  Associate a profile with the image.
2453  */
2454  profile_info=CloneImageInfo(mogrify_info);
2455  profile=GetImageProfile(*image,"iptc");
2456  if (profile != (StringInfo *) NULL)
2457  profile_info->profile=(void *) CloneStringInfo(profile);
2458  profile_image=GetImageCache(profile_info,argv[i+1],exception);
2459  profile_info=DestroyImageInfo(profile_info);
2460  if (profile_image == (Image *) NULL)
2461  {
2462  StringInfo
2463  *file_data;
2464 
2465  profile_info=CloneImageInfo(mogrify_info);
2466  (void) CopyMagickString(profile_info->filename,argv[i+1],
2468  file_data=FileToStringInfo(profile_info->filename,~0UL,
2469  exception);
2470  if (file_data != (StringInfo *) NULL)
2471  {
2472  (void) SetImageInfo(profile_info,0,exception);
2473  (void) ProfileImage(*image,profile_info->magick,
2474  GetStringInfoDatum(file_data),
2475  GetStringInfoLength(file_data),exception);
2476  file_data=DestroyStringInfo(file_data);
2477  }
2478  profile_info=DestroyImageInfo(profile_info);
2479  break;
2480  }
2481  ResetImageProfileIterator(profile_image);
2482  name=GetNextImageProfile(profile_image);
2483  while (name != (const char *) NULL)
2484  {
2485  profile=GetImageProfile(profile_image,name);
2486  if (profile != (StringInfo *) NULL)
2487  (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2488  (size_t) GetStringInfoLength(profile),exception);
2489  name=GetNextImageProfile(profile_image);
2490  }
2491  profile_image=DestroyImage(profile_image);
2492  break;
2493  }
2494  break;
2495  }
2496  case 'q':
2497  {
2498  if (LocaleCompare("quantize",option+1) == 0)
2499  {
2500  if (*option == '+')
2501  {
2502  quantize_info->colorspace=UndefinedColorspace;
2503  break;
2504  }
2505  quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2506  MagickColorspaceOptions,MagickFalse,argv[i+1]);
2507  break;
2508  }
2509  break;
2510  }
2511  case 'r':
2512  {
2513  if (LocaleCompare("rotational-blur",option+1) == 0)
2514  {
2515  /*
2516  Rotational blur image.
2517  */
2518  (void) SyncImageSettings(mogrify_info,*image,exception);
2519  flags=ParseGeometry(argv[i+1],&geometry_info);
2520  mogrify_image=RotationalBlurImage(*image,geometry_info.rho,
2521  exception);
2522  break;
2523  }
2524  if (LocaleCompare("raise",option+1) == 0)
2525  {
2526  /*
2527  Surround image with a raise of solid color.
2528  */
2529  flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2530  (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2531  MagickFalse,exception);
2532  break;
2533  }
2534  if (LocaleCompare("random-threshold",option+1) == 0)
2535  {
2536  /*
2537  Random threshold image.
2538  */
2539  double
2540  min_threshold,
2541  max_threshold;
2542 
2543  (void) SyncImageSettings(mogrify_info,*image,exception);
2544  min_threshold=0.0;
2545  max_threshold=(double) QuantumRange;
2546  flags=ParseGeometry(argv[i+1],&geometry_info);
2547  min_threshold=geometry_info.rho;
2548  max_threshold=geometry_info.sigma;
2549  if ((flags & SigmaValue) == 0)
2550  max_threshold=min_threshold;
2551  if (strchr(argv[i+1],'%') != (char *) NULL)
2552  {
2553  max_threshold*=(double) (0.01*QuantumRange);
2554  min_threshold*=(double) (0.01*QuantumRange);
2555  }
2556  (void) RandomThresholdImage(*image,min_threshold,max_threshold,
2557  exception);
2558  break;
2559  }
2560  if (LocaleCompare("range-threshold",option+1) == 0)
2561  {
2562  /*
2563  Range threshold image.
2564  */
2565  (void) SyncImageSettings(mogrify_info,*image,exception);
2566  flags=ParseGeometry(argv[i+1],&geometry_info);
2567  if ((flags & SigmaValue) == 0)
2568  geometry_info.sigma=geometry_info.rho;
2569  if ((flags & XiValue) == 0)
2570  geometry_info.xi=geometry_info.sigma;
2571  if ((flags & PsiValue) == 0)
2572  geometry_info.psi=geometry_info.xi;
2573  if (strchr(argv[i+1],'%') != (char *) NULL)
2574  {
2575  geometry_info.rho*=(double) (0.01*QuantumRange);
2576  geometry_info.sigma*=(double) (0.01*QuantumRange);
2577  geometry_info.xi*=(double) (0.01*QuantumRange);
2578  geometry_info.psi*=(double) (0.01*QuantumRange);
2579  }
2580  (void) RangeThresholdImage(*image,geometry_info.rho,
2581  geometry_info.sigma,geometry_info.xi,geometry_info.psi,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  " -channel-fx expression\n"
3442  " exchange, extract, or transfer one or more image channels\n"
3443  " -separate separate an image channel into a grayscale image",
3444  miscellaneous[] =
3445  " -debug events display copious debugging information\n"
3446  " -distribute-cache port\n"
3447  " distributed pixel cache spanning one or more servers\n"
3448  " -help print program options\n"
3449  " -list type print a list of supported option arguments\n"
3450  " -log format format of debugging information\n"
3451  " -version print version information",
3452  operators[] =
3453  " -adaptive-blur geometry\n"
3454  " adaptively blur pixels; decrease effect near edges\n"
3455  " -adaptive-resize geometry\n"
3456  " adaptively resize image using 'mesh' interpolation\n"
3457  " -adaptive-sharpen geometry\n"
3458  " adaptively sharpen pixels; increase effect near edges\n"
3459  " -alpha option on, activate, off, deactivate, set, opaque, copy\n"
3460  " transparent, extract, background, or shape\n"
3461  " -annotate geometry text\n"
3462  " annotate the image with text\n"
3463  " -auto-gamma automagically adjust gamma level of image\n"
3464  " -auto-level automagically adjust color levels of image\n"
3465  " -auto-orient automagically orient (rotate) image\n"
3466  " -auto-threshold method\n"
3467  " automatically perform image thresholding\n"
3468  " -bench iterations measure performance\n"
3469  " -black-threshold value\n"
3470  " force all pixels below the threshold into black\n"
3471  " -blue-shift simulate a scene at nighttime in the moonlight\n"
3472  " -blur geometry reduce image noise and reduce detail levels\n"
3473  " -border geometry surround image with a border of color\n"
3474  " -bordercolor color border color\n"
3475  " -brightness-contrast geometry\n"
3476  " improve brightness / contrast of the image\n"
3477  " -canny geometry detect edges in the image\n"
3478  " -cdl filename color correct with a color decision list\n"
3479  " -channel mask set the image channel mask\n"
3480  " -charcoal geometry simulate a charcoal drawing\n"
3481  " -chop geometry remove pixels from the image interior\n"
3482  " -clahe geometry contrast limited adaptive histogram equalization\n"
3483  " -clamp keep pixel values in range (0-QuantumRange)\n"
3484  " -clip clip along the first path from the 8BIM profile\n"
3485  " -clip-mask filename associate a clip mask with the image\n"
3486  " -clip-path id clip along a named path from the 8BIM profile\n"
3487  " -colorize value colorize the image with the fill color\n"
3488  " -color-matrix matrix apply color correction to the image\n"
3489  " -connected-components connectivity\n"
3490  " connected-components uniquely labeled\n"
3491  " -contrast enhance or reduce the image contrast\n"
3492  " -contrast-stretch geometry\n"
3493  " improve contrast by 'stretching' the intensity range\n"
3494  " -convolve coefficients\n"
3495  " apply a convolution kernel to the image\n"
3496  " -cycle amount cycle the image colormap\n"
3497  " -decipher filename convert cipher pixels to plain pixels\n"
3498  " -deskew threshold straighten an image\n"
3499  " -despeckle reduce the speckles within an image\n"
3500  " -distort method args\n"
3501  " distort images according to given method ad args\n"
3502  " -draw string annotate the image with a graphic primitive\n"
3503  " -edge radius apply a filter to detect edges in the image\n"
3504  " -encipher filename convert plain pixels to cipher pixels\n"
3505  " -emboss radius emboss an image\n"
3506  " -enhance apply a digital filter to enhance a noisy image\n"
3507  " -equalize perform histogram equalization to an image\n"
3508  " -evaluate operator value\n"
3509  " evaluate an arithmetic, relational, or logical expression\n"
3510  " -extent geometry set the image size\n"
3511  " -extract geometry extract area from image\n"
3512  " -fft implements the discrete Fourier transform (DFT)\n"
3513  " -flip flip image vertically\n"
3514  " -floodfill geometry color\n"
3515  " floodfill the image with color\n"
3516  " -flop flop image horizontally\n"
3517  " -frame geometry surround image with an ornamental border\n"
3518  " -function name parameters\n"
3519  " apply function over image values\n"
3520  " -gamma value level of gamma correction\n"
3521  " -gaussian-blur geometry\n"
3522  " reduce image noise and reduce detail levels\n"
3523  " -geometry geometry preferred size or location of the image\n"
3524  " -grayscale method convert image to grayscale\n"
3525  " -hough-lines geometry\n"
3526  " identify lines in the image\n"
3527  " -identify identify the format and characteristics of the image\n"
3528  " -ift implements the inverse discrete Fourier transform (DFT)\n"
3529  " -implode amount implode image pixels about the center\n"
3530  " -interpolative-resize geometry\n"
3531  " resize image using interpolation\n"
3532  " -kuwahara geometry edge preserving noise reduction filter\n"
3533  " -lat geometry local adaptive thresholding\n"
3534  " -level value adjust the level of image contrast\n"
3535  " -level-colors color,color\n"
3536  " level image with the given colors\n"
3537  " -linear-stretch geometry\n"
3538  " improve contrast by 'stretching with saturation'\n"
3539  " -liquid-rescale geometry\n"
3540  " rescale image with seam-carving\n"
3541  " -local-contrast geometry\n"
3542  " enhance local contrast\n"
3543  " -magnify double the size of the image with pixel art scaling\n"
3544  " -mean-shift geometry delineate arbitrarily shaped clusters in the image\n"
3545  " -median geometry apply a median filter to the image\n"
3546  " -mode geometry make each pixel the 'predominant color' of the\n"
3547  " neighborhood\n"
3548  " -modulate value vary the brightness, saturation, and hue\n"
3549  " -monochrome transform image to black and white\n"
3550  " -morphology method kernel\n"
3551  " apply a morphology method to the image\n"
3552  " -motion-blur geometry\n"
3553  " simulate motion blur\n"
3554  " -negate replace every pixel with its complementary color \n"
3555  " -noise geometry add or reduce noise in an image\n"
3556  " -normalize transform image to span the full range of colors\n"
3557  " -opaque color change this color to the fill color\n"
3558  " -ordered-dither NxN\n"
3559  " add a noise pattern to the image with specific\n"
3560  " amplitudes\n"
3561  " -paint radius simulate an oil painting\n"
3562  " -perceptible epsilon\n"
3563  " pixel value less than |epsilon| become epsilon or\n"
3564  " -epsilon\n"
3565  " -polaroid angle simulate a Polaroid picture\n"
3566  " -posterize levels reduce the image to a limited number of color levels\n"
3567  " -profile filename add, delete, or apply an image profile\n"
3568  " -quantize colorspace reduce colors in this colorspace\n"
3569  " -raise value lighten/darken image edges to create a 3-D effect\n"
3570  " -random-threshold low,high\n"
3571  " random threshold the image\n"
3572  " -range-threshold values\n"
3573  " perform either hard or soft thresholding within some range of values in an image\n"
3574  " -region geometry apply options to a portion of the image\n"
3575  " -render render vector graphics\n"
3576  " -repage geometry size and location of an image canvas\n"
3577  " -resample geometry change the resolution of an image\n"
3578  " -resize geometry resize the image\n"
3579  " -roll geometry roll an image vertically or horizontally\n"
3580  " -rotate degrees apply Paeth rotation to the image\n"
3581  " -rotational-blur angle\n"
3582  " rotational blur the image\n"
3583  " -sample geometry scale image with pixel sampling\n"
3584  " -scale geometry scale the image\n"
3585  " -segment values segment an image\n"
3586  " -selective-blur geometry\n"
3587  " selectively blur pixels within a contrast threshold\n"
3588  " -sepia-tone threshold\n"
3589  " simulate a sepia-toned photo\n"
3590  " -set property value set an image property\n"
3591  " -shade degrees shade the image using a distant light source\n"
3592  " -shadow geometry simulate an image shadow\n"
3593  " -sharpen geometry sharpen the image\n"
3594  " -shave geometry shave pixels from the image edges\n"
3595  " -shear geometry slide one edge of the image along the X or Y axis\n"
3596  " -sigmoidal-contrast geometry\n"
3597  " increase the contrast without saturating highlights or\n"
3598  " shadows\n"
3599  " -sketch geometry simulate a pencil sketch\n"
3600  " -solarize threshold negate all pixels above the threshold level\n"
3601  " -sparse-color method args\n"
3602  " fill in a image based on a few color points\n"
3603  " -splice geometry splice the background color into the image\n"
3604  " -spread radius displace image pixels by a random amount\n"
3605  " -statistic type radius\n"
3606  " replace each pixel with corresponding statistic from the neighborhood\n"
3607  " -strip strip image of all profiles and comments\n"
3608  " -swirl degrees swirl image pixels about the center\n"
3609  " -threshold value threshold the image\n"
3610  " -thumbnail geometry create a thumbnail of the image\n"
3611  " -tile filename tile image when filling a graphic primitive\n"
3612  " -tint value tint the image with the fill color\n"
3613  " -transform affine transform image\n"
3614  " -transparent color make this color transparent within the image\n"
3615  " -transpose flip image vertically and rotate 90 degrees\n"
3616  " -transverse flop image horizontally and rotate 270 degrees\n"
3617  " -trim trim image edges\n"
3618  " -type type image type\n"
3619  " -unique-colors discard all but one of any pixel color\n"
3620  " -unsharp geometry sharpen the image\n"
3621  " -vignette geometry soften the edges of the image in vignette style\n"
3622  " -wave geometry alter an image along a sine wave\n"
3623  " -wavelet-denoise threshold\n"
3624  " removes noise from the image using a wavelet transform\n"
3625  " -white-threshold value\n"
3626  " force all pixels above the threshold into white",
3627  sequence_operators[] =
3628  " -affinity filename transform image colors to match this set of colors\n"
3629  " -append append an image sequence\n"
3630  " -clut apply a color lookup table to the image\n"
3631  " -coalesce merge a sequence of images\n"
3632  " -combine combine a sequence of images\n"
3633  " -compare mathematically and visually annotate the difference between an image and its reconstruction\n"
3634  " -complex operator perform complex mathematics on an image sequence\n"
3635  " -composite composite image\n"
3636  " -copy geometry offset\n"
3637  " copy pixels from one area of an image to another\n"
3638  " -crop geometry cut out a rectangular region of the image\n"
3639  " -deconstruct break down an image sequence into constituent parts\n"
3640  " -evaluate-sequence operator\n"
3641  " evaluate an arithmetic, relational, or logical expression\n"
3642  " -flatten flatten a sequence of images\n"
3643  " -fx expression apply mathematical expression to an image channel(s)\n"
3644  " -hald-clut apply a Hald color lookup table to the image\n"
3645  " -layers method optimize, merge, or compare image layers\n"
3646  " -morph value morph an image sequence\n"
3647  " -mosaic create a mosaic from an image sequence\n"
3648  " -poly terms build a polynomial from the image sequence and the corresponding\n"
3649  " terms (coefficients and degree pairs).\n"
3650  " -print string interpret string and print to console\n"
3651  " -process arguments process the image with a custom image filter\n"
3652  " -smush geometry smush an image sequence together\n"
3653  " -write filename write images to this file",
3654  settings[] =
3655  " -adjoin join images into a single multi-image file\n"
3656  " -affine matrix affine transform matrix\n"
3657  " -alpha option activate, deactivate, reset, or set the alpha channel\n"
3658  " -antialias remove pixel-aliasing\n"
3659  " -authenticate password\n"
3660  " decipher image with this password\n"
3661  " -attenuate value lessen (or intensify) when adding noise to an image\n"
3662  " -background color background color\n"
3663  " -bias value add bias when convolving an image\n"
3664  " -black-point-compensation\n"
3665  " use black point compensation\n"
3666  " -blue-primary point chromaticity blue primary point\n"
3667  " -bordercolor color border color\n"
3668  " -caption string assign a caption to an image\n"
3669  " -colors value preferred number of colors in the image\n"
3670  " -colorspace type alternate image colorspace\n"
3671  " -comment string annotate image with comment\n"
3672  " -compose operator set image composite operator\n"
3673  " -compress type type of pixel compression when writing the image\n"
3674  " -define format:option=value\n"
3675  " define one or more image format options\n"
3676  " -delay value display the next image after pausing\n"
3677  " -density geometry horizontal and vertical density of the image\n"
3678  " -depth value image depth\n"
3679  " -direction type render text right-to-left or left-to-right\n"
3680  " -display server get image or font from this X server\n"
3681  " -dispose method layer disposal method\n"
3682  " -dither method apply error diffusion to image\n"
3683  " -encoding type text encoding type\n"
3684  " -endian type endianness (MSB or LSB) of the image\n"
3685  " -family name render text with this font family\n"
3686  " -features distance analyze image features (e.g. contrast, correlation)\n"
3687  " -fill color color to use when filling a graphic primitive\n"
3688  " -filter type use this filter when resizing an image\n"
3689  " -font name render text with this font\n"
3690  " -format \"string\" output formatted image characteristics\n"
3691  " -fuzz distance colors within this distance are considered equal\n"
3692  " -gravity type horizontal and vertical text placement\n"
3693  " -green-primary point chromaticity green primary point\n"
3694  " -intensity method method to generate an intensity value from a pixel\n"
3695  " -intent type type of rendering intent when managing the image color\n"
3696  " -interlace type type of image interlacing scheme\n"
3697  " -interline-spacing value\n"
3698  " set the space between two text lines\n"
3699  " -interpolate method pixel color interpolation method\n"
3700  " -interword-spacing value\n"
3701  " set the space between two words\n"
3702  " -kerning value set the space between two letters\n"
3703  " -label string assign a label to an image\n"
3704  " -limit type value pixel cache resource limit\n"
3705  " -loop iterations add Netscape loop extension to your GIF animation\n"
3706  " -matte store matte channel if the image has one\n"
3707  " -mattecolor color frame color\n"
3708  " -monitor monitor progress\n"
3709  " -orient type image orientation\n"
3710  " -page geometry size and location of an image canvas (setting)\n"
3711  " -path path write images to this path on disk\n"
3712  " -ping efficiently determine image attributes\n"
3713  " -pointsize value font point size\n"
3714  " -precision value maximum number of significant digits to print\n"
3715  " -preview type image preview type\n"
3716  " -quality value JPEG/MIFF/PNG compression level\n"
3717  " -quiet suppress all warning messages\n"
3718  " -read-mask filename associate a read mask with the image\n"
3719  " -red-primary point chromaticity red primary point\n"
3720  " -regard-warnings pay attention to warning messages\n"
3721  " -remap filename transform image colors to match this set of colors\n"
3722  " -respect-parentheses settings remain in effect until parenthesis boundary\n"
3723  " -sampling-factor geometry\n"
3724  " horizontal and vertical sampling factor\n"
3725  " -scene value image scene number\n"
3726  " -seed value seed a new sequence of pseudo-random numbers\n"
3727  " -size geometry width and height of image\n"
3728  " -stretch type render text with this font stretch\n"
3729  " -stroke color graphic primitive stroke color\n"
3730  " -strokewidth value graphic primitive stroke width\n"
3731  " -style type render text with this font style\n"
3732  " -synchronize synchronize image to storage device\n"
3733  " -taint declare the image as modified\n"
3734  " -texture filename name of texture to tile onto the image background\n"
3735  " -tile-offset geometry\n"
3736  " tile offset\n"
3737  " -treedepth value color tree depth\n"
3738  " -transparent-color color\n"
3739  " transparent color\n"
3740  " -undercolor color annotation bounding box color\n"
3741  " -units type the units of image resolution\n"
3742  " -verbose print detailed information about the image\n"
3743  " -view FlashPix viewing transforms\n"
3744  " -virtual-pixel method\n"
3745  " virtual pixel access method\n"
3746  " -weight type render text with this font weight\n"
3747  " -white-point point chromaticity white point\n"
3748  " -write-mask filename associate a write mask with the image",
3749  stack_operators[] =
3750  " -delete indexes delete the image from the image sequence\n"
3751  " -duplicate count,indexes\n"
3752  " duplicate an image one or more times\n"
3753  " -insert index insert last image into the image sequence\n"
3754  " -reverse reverse image sequence\n"
3755  " -swap indexes swap two images in the image sequence";
3756 
3757  ListMagickVersion(stdout);
3758  (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3759  GetClientName());
3760  (void) printf("\nImage Settings:\n");
3761  (void) puts(settings);
3762  (void) printf("\nImage Operators:\n");
3763  (void) puts(operators);
3764  (void) printf("\nImage Channel Operators:\n");
3765  (void) puts(channel_operators);
3766  (void) printf("\nImage Sequence Operators:\n");
3767  (void) puts(sequence_operators);
3768  (void) printf("\nImage Stack Operators:\n");
3769  (void) puts(stack_operators);
3770  (void) printf("\nMiscellaneous Options:\n");
3771  (void) puts(miscellaneous);
3772  (void) printf(
3773  "\nBy default, the image format of 'file' is determined by its magic\n");
3774  (void) printf(
3775  "number. To specify a particular image format, precede the filename\n");
3776  (void) printf(
3777  "with an image format name and a colon (i.e. ps:image) or specify the\n");
3778  (void) printf(
3779  "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3780  (void) printf("'-' for standard input or output.\n");
3781  return(MagickFalse);
3782 }
3783 
3784 WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3785  int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3786 {
3787 #define DestroyMogrify() \
3788 { \
3789  if (format != (char *) NULL) \
3790  format=DestroyString(format); \
3791  if (path != (char *) NULL) \
3792  path=DestroyString(path); \
3793  DestroyImageStack(); \
3794  for (i=0; i < (ssize_t) argc; i++) \
3795  argv[i]=DestroyString(argv[i]); \
3796  argv=(char **) RelinquishMagickMemory(argv); \
3797 }
3798 #define ThrowMogrifyException(asperity,tag,option) \
3799 { \
3800  (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3801  option); \
3802  DestroyMogrify(); \
3803  return(MagickFalse); \
3804 }
3805 #define ThrowMogrifyInvalidArgumentException(option,argument) \
3806 { \
3807  (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3808  "InvalidArgument","'%s': %s",argument,option); \
3809  DestroyMogrify(); \
3810  return(MagickFalse); \
3811 }
3812 
3813  char
3814  *format,
3815  *option,
3816  *path;
3817 
3818  Image
3819  *image;
3820 
3821  ImageStack
3822  image_stack[MaxImageStackDepth+1];
3823 
3824  MagickBooleanType
3825  global_colormap;
3826 
3827  MagickBooleanType
3828  fire,
3829  pend,
3830  respect_parenthesis;
3831 
3832  MagickStatusType
3833  status;
3834 
3835  register ssize_t
3836  i;
3837 
3838  ssize_t
3839  j,
3840  k;
3841 
3842  wand_unreferenced(metadata);
3843 
3844  /*
3845  Set defaults.
3846  */
3847  assert(image_info != (ImageInfo *) NULL);
3848  assert(image_info->signature == MagickCoreSignature);
3849  if (image_info->debug != MagickFalse)
3850  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3851  assert(exception != (ExceptionInfo *) NULL);
3852  if (argc == 2)
3853  {
3854  option=argv[1];
3855  if ((LocaleCompare("version",option+1) == 0) ||
3856  (LocaleCompare("-version",option+1) == 0))
3857  {
3858  ListMagickVersion(stdout);
3859  return(MagickTrue);
3860  }
3861  }
3862  if (argc < 2)
3863  return(MogrifyUsage());
3864  format=(char *) NULL;
3865  path=(char *) NULL;
3866  global_colormap=MagickFalse;
3867  k=0;
3868  j=1;
3869  NewImageStack();
3870  option=(char *) NULL;
3871  pend=MagickFalse;
3872  respect_parenthesis=MagickFalse;
3873  status=MagickTrue;
3874  /*
3875  Parse command line.
3876  */
3877  ReadCommandlLine(argc,&argv);
3878  status=ExpandFilenames(&argc,&argv);
3879  if (status == MagickFalse)
3880  ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3881  GetExceptionMessage(errno));
3882  for (i=1; i < (ssize_t) argc; i++)
3883  {
3884  option=argv[i];
3885  if (LocaleCompare(option,"(") == 0)
3886  {
3887  FireImageStack(MagickFalse,MagickTrue,pend);
3888  if (k == MaxImageStackDepth)
3889  ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3890  option);
3891  PushImageStack();
3892  continue;
3893  }
3894  if (LocaleCompare(option,")") == 0)
3895  {
3896  FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3897  if (k == 0)
3898  ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3899  PopImageStack();
3900  continue;
3901  }
3902  if (IsCommandOption(option) == MagickFalse)
3903  {
3904  char
3905  backup_filename[MagickPathExtent],
3906  *filename;
3907 
3908  Image
3909  *images;
3910 
3911  struct stat
3912  properties;
3913 
3914  /*
3915  Option is a file name: begin by reading image from specified file.
3916  */
3917  FireImageStack(MagickFalse,MagickFalse,pend);
3918  filename=argv[i];
3919  if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
3920  filename=argv[++i];
3921  images=ReadImages(image_info,filename,exception);
3922  status&=(images != (Image *) NULL) &&
3923  (exception->severity < ErrorException);
3924  if (images == (Image *) NULL)
3925  continue;
3926  properties=(*GetBlobProperties(images));
3927  if (format != (char *) NULL)
3928  (void) CopyMagickString(images->filename,images->magick_filename,
3930  if (path != (char *) NULL)
3931  {
3932  GetPathComponent(option,TailPath,filename);
3933  (void) FormatLocaleString(images->filename,MagickPathExtent,
3934  "%s%c%s",path,*DirectorySeparator,filename);
3935  }
3936  if (format != (char *) NULL)
3937  AppendImageFormat(format,images->filename);
3938  AppendImageStack(images);
3939  FinalizeImageSettings(image_info,image,MagickFalse);
3940  if (global_colormap != MagickFalse)
3941  {
3942  QuantizeInfo
3943  *quantize_info;
3944 
3945  quantize_info=AcquireQuantizeInfo(image_info);
3946  (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
3947  quantize_info=DestroyQuantizeInfo(quantize_info);
3948  }
3949  *backup_filename='\0';
3950  if ((LocaleCompare(image->filename,"-") != 0) &&
3951  (IsPathWritable(image->filename) != MagickFalse))
3952  {
3953  /*
3954  Rename image file as backup.
3955  */
3956  (void) CopyMagickString(backup_filename,image->filename,
3958  for (j=0; j < 6; j++)
3959  {
3960  (void) ConcatenateMagickString(backup_filename,"~",
3962  if (IsPathAccessible(backup_filename) == MagickFalse)
3963  break;
3964  }
3965  if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3966  (rename_utf8(image->filename,backup_filename) != 0))
3967  *backup_filename='\0';
3968  }
3969  /*
3970  Write transmogrified image to disk.
3971  */
3972  image_info->synchronize=MagickTrue;
3973  status&=WriteImages(image_info,image,image->filename,exception);
3974  if (status != MagickFalse)
3975  {
3976 #if defined(MAGICKCORE_HAVE_UTIME)
3977  {
3978  MagickBooleanType
3979  preserve_timestamp;
3980 
3981  preserve_timestamp=IsStringTrue(GetImageOption(image_info,
3982  "preserve-timestamp"));
3983  if (preserve_timestamp != MagickFalse)
3984  {
3985  struct utimbuf
3986  timestamp;
3987 
3988  timestamp.actime=properties.st_atime;
3989  timestamp.modtime=properties.st_mtime;
3990  (void) utime(image->filename,&timestamp);
3991  }
3992  }
3993 #endif
3994  if (*backup_filename != '\0')
3995  (void) remove_utf8(backup_filename);
3996  }
3998  continue;
3999  }
4000  pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4001  switch (*(option+1))
4002  {
4003  case 'a':
4004  {
4005  if (LocaleCompare("adaptive-blur",option+1) == 0)
4006  {
4007  i++;
4008  if (i == (ssize_t) argc)
4009  ThrowMogrifyException(OptionError,"MissingArgument",option);
4010  if (IsGeometry(argv[i]) == MagickFalse)
4011  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4012  break;
4013  }
4014  if (LocaleCompare("adaptive-resize",option+1) == 0)
4015  {
4016  i++;
4017  if (i == (ssize_t) argc)
4018  ThrowMogrifyException(OptionError,"MissingArgument",option);
4019  if (IsGeometry(argv[i]) == MagickFalse)
4020  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4021  break;
4022  }
4023  if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4024  {
4025  i++;
4026  if (i == (ssize_t) argc)
4027  ThrowMogrifyException(OptionError,"MissingArgument",option);
4028  if (IsGeometry(argv[i]) == MagickFalse)
4029  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4030  break;
4031  }
4032  if (LocaleCompare("affine",option+1) == 0)
4033  {
4034  if (*option == '+')
4035  break;
4036  i++;
4037  if (i == (ssize_t) argc)
4038  ThrowMogrifyException(OptionError,"MissingArgument",option);
4039  break;
4040  }
4041  if (LocaleCompare("alpha",option+1) == 0)
4042  {
4043  ssize_t
4044  type;
4045 
4046  if (*option == '+')
4047  break;
4048  i++;
4049  if (i == (ssize_t) argc)
4050  ThrowMogrifyException(OptionError,"MissingArgument",option);
4051  type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,
4052  argv[i]);
4053  if (type < 0)
4054  ThrowMogrifyException(OptionError,
4055  "UnrecognizedAlphaChannelOption",argv[i]);
4056  break;
4057  }
4058  if (LocaleCompare("annotate",option+1) == 0)
4059  {
4060  if (*option == '+')
4061  break;
4062  i++;
4063  if (i == (ssize_t) argc)
4064  ThrowMogrifyException(OptionError,"MissingArgument",option);
4065  if (IsGeometry(argv[i]) == MagickFalse)
4066  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4067  if (i == (ssize_t) argc)
4068  ThrowMogrifyException(OptionError,"MissingArgument",option);
4069  i++;
4070  break;
4071  }
4072  if (LocaleCompare("antialias",option+1) == 0)
4073  break;
4074  if (LocaleCompare("append",option+1) == 0)
4075  break;
4076  if (LocaleCompare("attenuate",option+1) == 0)
4077  {
4078  if (*option == '+')
4079  break;
4080  i++;
4081  if (i == (ssize_t) argc)
4082  ThrowMogrifyException(OptionError,"MissingArgument",option);
4083  if (IsGeometry(argv[i]) == MagickFalse)
4084  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4085  break;
4086  }
4087  if (LocaleCompare("authenticate",option+1) == 0)
4088  {
4089  if (*option == '+')
4090  break;
4091  i++;
4092  if (i == (ssize_t) argc)
4093  ThrowMogrifyException(OptionError,"MissingArgument",option);
4094  break;
4095  }
4096  if (LocaleCompare("auto-gamma",option+1) == 0)
4097  break;
4098  if (LocaleCompare("auto-level",option+1) == 0)
4099  break;
4100  if (LocaleCompare("auto-orient",option+1) == 0)
4101  break;
4102  if (LocaleCompare("auto-threshold",option+1) == 0)
4103  {
4104  ssize_t
4105  method;
4106 
4107  if (*option == '+')
4108  break;
4109  i++;
4110  if (i == (ssize_t) argc)
4111  ThrowMogrifyException(OptionError,"MissingArgument",option);
4112  method=ParseCommandOption(MagickAutoThresholdOptions,MagickFalse,
4113  argv[i]);
4114  if (method < 0)
4115  ThrowMogrifyException(OptionError,"UnrecognizedThresholdMethod",
4116  argv[i]);
4117  break;
4118  }
4119  if (LocaleCompare("average",option+1) == 0)
4120  break;
4121  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4122  }
4123  case 'b':
4124  {
4125  if (LocaleCompare("background",option+1) == 0)
4126  {
4127  if (*option == '+')
4128  break;
4129  i++;
4130  if (i == (ssize_t) argc)
4131  ThrowMogrifyException(OptionError,"MissingArgument",option);
4132  break;
4133  }
4134  if (LocaleCompare("bias",option+1) == 0)
4135  {
4136  if (*option == '+')
4137  break;
4138  i++;
4139  if (i == (ssize_t) argc)
4140  ThrowMogrifyException(OptionError,"MissingArgument",option);
4141  if (IsGeometry(argv[i]) == MagickFalse)
4142  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4143  break;
4144  }
4145  if (LocaleCompare("black-point-compensation",option+1) == 0)
4146  break;
4147  if (LocaleCompare("black-threshold",option+1) == 0)
4148  {
4149  if (*option == '+')
4150  break;
4151  i++;
4152  if (i == (ssize_t) argc)
4153  ThrowMogrifyException(OptionError,"MissingArgument",option);
4154  if (IsGeometry(argv[i]) == MagickFalse)
4155  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4156  break;
4157  }
4158  if (LocaleCompare("blue-primary",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("blue-shift",option+1) == 0)
4170  {
4171  i++;
4172  if (i == (ssize_t) argc)
4173  ThrowMogrifyException(OptionError,"MissingArgument",option);
4174  if (IsGeometry(argv[i]) == MagickFalse)
4175  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4176  break;
4177  }
4178  if (LocaleCompare("blur",option+1) == 0)
4179  {
4180  i++;
4181  if (i == (ssize_t) argc)
4182  ThrowMogrifyException(OptionError,"MissingArgument",option);
4183  if (IsGeometry(argv[i]) == MagickFalse)
4184  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4185  break;
4186  }
4187  if (LocaleCompare("border",option+1) == 0)
4188  {
4189  if (*option == '+')
4190  break;
4191  i++;
4192  if (i == (ssize_t) argc)
4193  ThrowMogrifyException(OptionError,"MissingArgument",option);
4194  if (IsGeometry(argv[i]) == MagickFalse)
4195  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4196  break;
4197  }
4198  if (LocaleCompare("bordercolor",option+1) == 0)
4199  {
4200  if (*option == '+')
4201  break;
4202  i++;
4203  if (i == (ssize_t) argc)
4204  ThrowMogrifyException(OptionError,"MissingArgument",option);
4205  break;
4206  }
4207  if (LocaleCompare("box",option+1) == 0)
4208  {
4209  if (*option == '+')
4210  break;
4211  i++;
4212  if (i == (ssize_t) argc)
4213  ThrowMogrifyException(OptionError,"MissingArgument",option);
4214  break;
4215  }
4216  if (LocaleCompare("brightness-contrast",option+1) == 0)
4217  {
4218  i++;
4219  if (i == (ssize_t) argc)
4220  ThrowMogrifyException(OptionError,"MissingArgument",option);
4221  if (IsGeometry(argv[i]) == MagickFalse)
4222  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4223  break;
4224  }
4225  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4226  }
4227  case 'c':
4228  {
4229  if (LocaleCompare("cache",option+1) == 0)
4230  {
4231  if (*option == '+')
4232  break;
4233  i++;
4234  if (i == (ssize_t) argc)
4235  ThrowMogrifyException(OptionError,"MissingArgument",option);
4236  if (IsGeometry(argv[i]) == MagickFalse)
4237  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4238  break;
4239  }
4240  if (LocaleCompare("canny",option+1) == 0)
4241  {
4242  if (*option == '+')
4243  break;
4244  i++;
4245  if (i == (ssize_t) argc)
4246  ThrowMogrifyException(OptionError,"MissingArgument",option);
4247  if (IsGeometry(argv[i]) == MagickFalse)
4248  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4249  break;
4250  }
4251  if (LocaleCompare("caption",option+1) == 0)
4252  {
4253  if (*option == '+')
4254  break;
4255  i++;
4256  if (i == (ssize_t) argc)
4257  ThrowMogrifyException(OptionError,"MissingArgument",option);
4258  break;
4259  }
4260  if (LocaleCompare("channel",option+1) == 0)
4261  {
4262  ssize_t
4263  channel;
4264 
4265  if (*option == '+')
4266  break;
4267  i++;
4268  if (i == (ssize_t) argc)
4269  ThrowMogrifyException(OptionError,"MissingArgument",option);
4270  channel=ParseChannelOption(argv[i]);
4271  if (channel < 0)
4272  ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4273  argv[i]);
4274  break;
4275  }
4276  if (LocaleCompare("channel-fx",option+1) == 0)
4277  {
4278  ssize_t
4279  channel;
4280 
4281  if (*option == '+')
4282  break;
4283  i++;
4284  if (i == (ssize_t) argc)
4285  ThrowMogrifyException(OptionError,"MissingArgument",option);
4286  channel=ParsePixelChannelOption(argv[i]);
4287  if (channel < 0)
4288  ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4289  argv[i]);
4290  break;
4291  }
4292  if (LocaleCompare("cdl",option+1) == 0)
4293  {
4294  if (*option == '+')
4295  break;
4296  i++;
4297  if (i == (ssize_t) argc)
4298  ThrowMogrifyException(OptionError,"MissingArgument",option);
4299  break;
4300  }
4301  if (LocaleCompare("charcoal",option+1) == 0)
4302  {
4303  if (*option == '+')
4304  break;
4305  i++;
4306  if (i == (ssize_t) argc)
4307  ThrowMogrifyException(OptionError,"MissingArgument",option);
4308  if (IsGeometry(argv[i]) == MagickFalse)
4309  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4310  break;
4311  }
4312  if (LocaleCompare("chop",option+1) == 0)
4313  {
4314  if (*option == '+')
4315  break;
4316  i++;
4317  if (i == (ssize_t) argc)
4318  ThrowMogrifyException(OptionError,"MissingArgument",option);
4319  if (IsGeometry(argv[i]) == MagickFalse)
4320  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4321  break;
4322  }
4323  if (LocaleCompare("clahe",option+1) == 0)
4324  {
4325  if (*option == '+')
4326  break;
4327  i++;
4328  if (i == (ssize_t) argc)
4329  ThrowMogrifyException(OptionError,"MissingArgument",option);
4330  if (IsGeometry(argv[i]) == MagickFalse)
4331  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4332  break;
4333  }
4334  if (LocaleCompare("clamp",option+1) == 0)
4335  break;
4336  if (LocaleCompare("clip",option+1) == 0)
4337  break;
4338  if (LocaleCompare("clip-mask",option+1) == 0)
4339  {
4340  if (*option == '+')
4341  break;
4342  i++;
4343  if (i == (ssize_t) argc)
4344  ThrowMogrifyException(OptionError,"MissingArgument",option);
4345  break;
4346  }
4347  if (LocaleCompare("clut",option+1) == 0)
4348  break;
4349  if (LocaleCompare("coalesce",option+1) == 0)
4350  break;
4351  if (LocaleCompare("colorize",option+1) == 0)
4352  {
4353  if (*option == '+')
4354  break;
4355  i++;
4356  if (i == (ssize_t) argc)
4357  ThrowMogrifyException(OptionError,"MissingArgument",option);
4358  if (IsGeometry(argv[i]) == MagickFalse)
4359  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4360  break;
4361  }
4362  if (LocaleCompare("color-matrix",option+1) == 0)
4363  {
4364  KernelInfo
4365  *kernel_info;
4366 
4367  if (*option == '+')
4368  break;
4369  i++;
4370  if (i == (ssize_t) argc)
4371  ThrowMogrifyException(OptionError,"MissingArgument",option);
4372  kernel_info=AcquireKernelInfo(argv[i],exception);
4373  if (kernel_info == (KernelInfo *) NULL)
4374  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4375  kernel_info=DestroyKernelInfo(kernel_info);
4376  break;
4377  }
4378  if (LocaleCompare("colors",option+1) == 0)
4379  {
4380  if (*option == '+')
4381  break;
4382  i++;
4383  if (i == (ssize_t) argc)
4384  ThrowMogrifyException(OptionError,"MissingArgument",option);
4385  if (IsGeometry(argv[i]) == MagickFalse)
4386  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4387  break;
4388  }
4389  if (LocaleCompare("colorspace",option+1) == 0)
4390  {
4391  ssize_t
4392  colorspace;
4393 
4394  if (*option == '+')
4395  break;
4396  i++;
4397  if (i == (ssize_t) argc)
4398  ThrowMogrifyException(OptionError,"MissingArgument",option);
4399  colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4400  argv[i]);
4401  if (colorspace < 0)
4402  ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4403  argv[i]);
4404  break;
4405  }
4406  if (LocaleCompare("combine",option+1) == 0)
4407  {
4408  ssize_t
4409  colorspace;
4410 
4411  if (*option == '+')
4412  break;
4413  i++;
4414  if (i == (ssize_t) argc)
4415  ThrowMogrifyException(OptionError,"MissingArgument",option);
4416  colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4417  argv[i]);
4418  if (colorspace < 0)
4419  ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4420  argv[i]);
4421  break;
4422  }
4423  if (LocaleCompare("compare",option+1) == 0)
4424  break;
4425  if (LocaleCompare("comment",option+1) == 0)
4426  {
4427  if (*option == '+')
4428  break;
4429  i++;
4430  if (i == (ssize_t) argc)
4431  ThrowMogrifyException(OptionError,"MissingArgument",option);
4432  break;
4433  }
4434  if (LocaleCompare("composite",option+1) == 0)
4435  break;
4436  if (LocaleCompare("compress",option+1) == 0)
4437  {
4438  ssize_t
4439  compress;
4440 
4441  if (*option == '+')
4442  break;
4443  i++;
4444  if (i == (ssize_t) argc)
4445  ThrowMogrifyException(OptionError,"MissingArgument",option);
4446  compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
4447  argv[i]);
4448  if (compress < 0)
4449  ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4450  argv[i]);
4451  break;
4452  }
4453  if (LocaleCompare("concurrent",option+1) == 0)
4454  break;
4455  if (LocaleCompare("connected-components",option+1) == 0)
4456  {
4457  i++;
4458  if (i == (ssize_t) argc)
4459  ThrowMogrifyException(OptionError,"MissingArgument",option);
4460  if (IsGeometry(argv[i]) == MagickFalse)
4461  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4462  break;
4463  }
4464  if (LocaleCompare("contrast",option+1) == 0)
4465  break;
4466  if (LocaleCompare("contrast-stretch",option+1) == 0)
4467  {
4468  i++;
4469  if (i == (ssize_t) argc)
4470  ThrowMogrifyException(OptionError,"MissingArgument",option);
4471  if (IsGeometry(argv[i]) == MagickFalse)
4472  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4473  break;
4474  }
4475  if (LocaleCompare("convolve",option+1) == 0)
4476  {
4477  KernelInfo
4478  *kernel_info;
4479 
4480  if (*option == '+')
4481  break;
4482  i++;
4483  if (i == (ssize_t) argc)
4484  ThrowMogrifyException(OptionError,"MissingArgument",option);
4485  kernel_info=AcquireKernelInfo(argv[i],exception);
4486  if (kernel_info == (KernelInfo *) NULL)
4487  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4488  kernel_info=DestroyKernelInfo(kernel_info);
4489  break;
4490  }
4491  if (LocaleCompare("copy",option+1) == 0)
4492  {
4493  if (*option == '+')
4494  break;
4495  i++;
4496  if (i == (ssize_t) argc)
4497  ThrowMogrifyException(OptionError,"MissingArgument",option);
4498  if (IsGeometry(argv[i]) == MagickFalse)
4499  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4500  i++;
4501  if (i == (ssize_t) argc)
4502  ThrowMogrifyException(OptionError,"MissingArgument",option);
4503  if (IsGeometry(argv[i]) == MagickFalse)
4504  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4505  break;
4506  }
4507  if (LocaleCompare("crop",option+1) == 0)
4508  {
4509  if (*option == '+')
4510  break;
4511  i++;
4512  if (i == (ssize_t) argc)
4513  ThrowMogrifyException(OptionError,"MissingArgument",option);
4514  if (IsGeometry(argv[i]) == MagickFalse)
4515  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4516  break;
4517  }
4518  if (LocaleCompare("cycle",option+1) == 0)
4519  {
4520  if (*option == '+')
4521  break;
4522  i++;
4523  if (i == (ssize_t) argc)
4524  ThrowMogrifyException(OptionError,"MissingArgument",option);
4525  if (IsGeometry(argv[i]) == MagickFalse)
4526  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4527  break;
4528  }
4529  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4530  }
4531  case 'd':
4532  {
4533  if (LocaleCompare("decipher",option+1) == 0)
4534  {
4535  if (*option == '+')
4536  break;
4537  i++;
4538  if (i == (ssize_t) argc)
4539  ThrowMogrifyException(OptionError,"MissingArgument",option);
4540  break;
4541  }
4542  if (LocaleCompare("deconstruct",option+1) == 0)
4543  break;
4544  if (LocaleCompare("debug",option+1) == 0)
4545  {
4546  ssize_t
4547  event;
4548 
4549  if (*option == '+')
4550  break;
4551  i++;
4552  if (i == (ssize_t) argc)
4553  ThrowMogrifyException(OptionError,"MissingArgument",option);
4554  event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
4555  if (event < 0)
4556  ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4557  argv[i]);
4558  (void) SetLogEventMask(argv[i]);
4559  break;
4560  }
4561  if (LocaleCompare("define",option+1) == 0)
4562  {
4563  i++;
4564  if (i == (ssize_t) argc)
4565  ThrowMogrifyException(OptionError,"MissingArgument",option);
4566  if (*option == '+')
4567  {
4568  const char
4569  *define;
4570 
4571  define=GetImageOption(image_info,argv[i]);
4572  if (define == (const char *) NULL)
4573  ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4574  break;
4575  }
4576  break;
4577  }
4578  if (LocaleCompare("delay",option+1) == 0)
4579  {
4580  if (*option == '+')
4581  break;
4582  i++;
4583  if (i == (ssize_t) argc)
4584  ThrowMogrifyException(OptionError,"MissingArgument",option);
4585  if (IsGeometry(argv[i]) == MagickFalse)
4586  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4587  break;
4588  }
4589  if (LocaleCompare("delete",option+1) == 0)
4590  {
4591  if (*option == '+')
4592  break;
4593  i++;
4594  if (i == (ssize_t) argc)
4595  ThrowMogrifyException(OptionError,"MissingArgument",option);
4596  if (IsGeometry(argv[i]) == MagickFalse)
4597  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4598  break;
4599  }
4600  if (LocaleCompare("density",option+1) == 0)
4601  {
4602  if (*option == '+')
4603  break;
4604  i++;
4605  if (i == (ssize_t) argc)
4606  ThrowMogrifyException(OptionError,"MissingArgument",option);
4607  if (IsGeometry(argv[i]) == MagickFalse)
4608  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4609  break;
4610  }
4611  if (LocaleCompare("depth",option+1) == 0)
4612  {
4613  if (*option == '+')
4614  break;
4615  i++;
4616  if (i == (ssize_t) argc)
4617  ThrowMogrifyException(OptionError,"MissingArgument",option);
4618  if (IsGeometry(argv[i]) == MagickFalse)
4619  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4620  break;
4621  }
4622  if (LocaleCompare("deskew",option+1) == 0)
4623  {
4624  if (*option == '+')
4625  break;
4626  i++;
4627  if (i == (ssize_t) argc)
4628  ThrowMogrifyException(OptionError,"MissingArgument",option);
4629  if (IsGeometry(argv[i]) == MagickFalse)
4630  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4631  break;
4632  }
4633  if (LocaleCompare("despeckle",option+1) == 0)
4634  break;
4635  if (LocaleCompare("dft",option+1) == 0)
4636  break;
4637  if (LocaleCompare("direction",option+1) == 0)
4638  {
4639  ssize_t
4640  direction;
4641 
4642  if (*option == '+')
4643  break;
4644  i++;
4645  if (i == (ssize_t) argc)
4646  ThrowMogrifyException(OptionError,"MissingArgument",option);
4647  direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
4648  argv[i]);
4649  if (direction < 0)
4650  ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4651  argv[i]);
4652  break;
4653  }
4654  if (LocaleCompare("display",option+1) == 0)
4655  {
4656  if (*option == '+')
4657  break;
4658  i++;
4659  if (i == (ssize_t) argc)
4660  ThrowMogrifyException(OptionError,"MissingArgument",option);
4661  break;
4662  }
4663  if (LocaleCompare("dispose",option+1) == 0)
4664  {
4665  ssize_t
4666  dispose;
4667 
4668  if (*option == '+')
4669  break;
4670  i++;
4671  if (i == (ssize_t) argc)
4672  ThrowMogrifyException(OptionError,"MissingArgument",option);
4673  dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,
4674  argv[i]);
4675  if (dispose < 0)
4676  ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4677  argv[i]);
4678  break;
4679  }
4680  if (LocaleCompare("distort",option+1) == 0)
4681  {
4682  ssize_t
4683  op;
4684 
4685  i++;
4686  if (i == (ssize_t) argc)
4687  ThrowMogrifyException(OptionError,"MissingArgument",option);
4688  op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
4689  if (op < 0)
4690  ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4691  argv[i]);
4692  i++;
4693  if (i == (ssize_t) argc)
4694  ThrowMogrifyException(OptionError,"MissingArgument",option);
4695  break;
4696  }
4697  if (LocaleCompare("dither",option+1) == 0)
4698  {
4699  ssize_t
4700  method;
4701 
4702  if (*option == '+')
4703  break;
4704  i++;
4705  if (i == (ssize_t) argc)
4706  ThrowMogrifyException(OptionError,"MissingArgument",option);
4707  method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
4708  if (method < 0)
4709  ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4710  argv[i]);
4711  break;
4712  }
4713  if (LocaleCompare("draw",option+1) == 0)
4714  {
4715  if (*option == '+')
4716  break;
4717  i++;
4718  if (i == (ssize_t) argc)
4719  ThrowMogrifyException(OptionError,"MissingArgument",option);
4720  break;
4721  }
4722  if (LocaleCompare("duplicate",option+1) == 0)
4723  {
4724  if (*option == '+')
4725  break;
4726  i++;
4727  if (i == (ssize_t) argc)
4728  ThrowMogrifyException(OptionError,"MissingArgument",option);
4729  if (IsGeometry(argv[i]) == MagickFalse)
4730  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4731  break;
4732  }
4733  if (LocaleCompare("duration",option+1) == 0)
4734  {
4735  if (*option == '+')
4736  break;
4737  i++;
4738  if (i == (ssize_t) argc)
4739  ThrowMogrifyException(OptionError,"MissingArgument",option);
4740  if (IsGeometry(argv[i]) == MagickFalse)
4741  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4742  break;
4743  }
4744  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4745  }
4746  case 'e':
4747  {
4748  if (LocaleCompare("edge",option+1) == 0)
4749  {
4750  if (*option == '+')
4751  break;
4752  i++;
4753  if (i == (ssize_t) argc)
4754  ThrowMogrifyException(OptionError,"MissingArgument",option);
4755  if (IsGeometry(argv[i]) == MagickFalse)
4756  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4757  break;
4758  }
4759  if (LocaleCompare("emboss",option+1) == 0)
4760  {
4761  if (*option == '+')
4762  break;
4763  i++;
4764  if (i == (ssize_t) argc)
4765  ThrowMogrifyException(OptionError,"MissingArgument",option);
4766  if (IsGeometry(argv[i]) == MagickFalse)
4767  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4768  break;
4769  }
4770  if (LocaleCompare("encipher",option+1) == 0)
4771  {
4772  if (*option == '+')
4773  break;
4774  i++;
4775  if (i == (ssize_t) argc)
4776  ThrowMogrifyException(OptionError,"MissingArgument",option);
4777  break;
4778  }
4779  if (LocaleCompare("encoding",option+1) == 0)
4780  {
4781  if (*option == '+')
4782  break;
4783  i++;
4784  if (i == (ssize_t) argc)
4785  ThrowMogrifyException(OptionError,"MissingArgument",option);
4786  break;
4787  }
4788  if (LocaleCompare("endian",option+1) == 0)
4789  {
4790  ssize_t
4791  endian;
4792 
4793  if (*option == '+')
4794  break;
4795  i++;
4796  if (i == (ssize_t) argc)
4797  ThrowMogrifyException(OptionError,"MissingArgument",option);
4798  endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
4799  if (endian < 0)
4800  ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4801  argv[i]);
4802  break;
4803  }
4804  if (LocaleCompare("enhance",option+1) == 0)
4805  break;
4806  if (LocaleCompare("equalize",option+1) == 0)
4807  break;
4808  if (LocaleCompare("evaluate",option+1) == 0)
4809  {
4810  ssize_t
4811  op;
4812 
4813  if (*option == '+')
4814  break;
4815  i++;
4816  if (i == (ssize_t) argc)
4817  ThrowMogrifyException(OptionError,"MissingArgument",option);
4818  op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4819  if (op < 0)
4820  ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4821  argv[i]);
4822  i++;
4823  if (i == (ssize_t) argc)
4824  ThrowMogrifyException(OptionError,"MissingArgument",option);
4825  if (IsGeometry(argv[i]) == MagickFalse)
4826  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4827  break;
4828  }
4829  if (LocaleCompare("evaluate-sequence",option+1) == 0)
4830  {
4831  ssize_t
4832  op;
4833 
4834  if (*option == '+')
4835  break;
4836  i++;
4837  if (i == (ssize_t) argc)
4838  ThrowMogrifyException(OptionError,"MissingArgument",option);
4839  op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4840  if (op < 0)
4841  ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4842  argv[i]);
4843  break;
4844  }
4845  if (LocaleCompare("extent",option+1) == 0)
4846  {
4847  if (*option == '+')
4848  break;
4849  i++;
4850  if (i == (ssize_t) argc)
4851  ThrowMogrifyException(OptionError,"MissingArgument",option);
4852  if (IsGeometry(argv[i]) == MagickFalse)
4853  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4854  break;
4855  }
4856  if (LocaleCompare("extract",option+1) == 0)
4857  {
4858  if (*option == '+')
4859  break;
4860  i++;
4861  if (i == (ssize_t) argc)
4862  ThrowMogrifyException(OptionError,"MissingArgument",option);
4863  if (IsGeometry(argv[i]) == MagickFalse)
4864  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4865  break;
4866  }
4867  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4868  }
4869  case 'f':
4870  {
4871  if (LocaleCompare("family",option+1) == 0)
4872  {
4873  if (*option == '+')
4874  break;
4875  i++;
4876  if (i == (ssize_t) argc)
4877  ThrowMogrifyException(OptionError,"MissingArgument",option);
4878  break;
4879  }
4880  if (LocaleCompare("features",option+1) == 0)
4881  {
4882  if (*option == '+')
4883  break;
4884  i++;
4885  if (i == (ssize_t) argc)
4886  ThrowMogrifyException(OptionError,"MissingArgument",option);
4887  if (IsGeometry(argv[i]) == MagickFalse)
4888  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4889  break;
4890  }
4891  if (LocaleCompare("fill",option+1) == 0)
4892  {
4893  if (*option == '+')
4894  break;
4895  i++;
4896  if (i == (ssize_t) argc)
4897  ThrowMogrifyException(OptionError,"MissingArgument",option);
4898  break;
4899  }
4900  if (LocaleCompare("filter",option+1) == 0)
4901  {
4902  ssize_t
4903  filter;
4904 
4905  if (*option == '+')
4906  break;
4907  i++;
4908  if (i == (ssize_t) argc)
4909  ThrowMogrifyException(OptionError,"MissingArgument",option);
4910  filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
4911  if (filter < 0)
4912  ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4913  argv[i]);
4914  break;
4915  }
4916  if (LocaleCompare("flatten",option+1) == 0)
4917  break;
4918  if (LocaleCompare("flip",option+1) == 0)
4919  break;
4920  if (LocaleCompare("flop",option+1) == 0)
4921  break;
4922  if (LocaleCompare("floodfill",option+1) == 0)
4923  {
4924  if (*option == '+')
4925  break;
4926  i++;
4927  if (i == (ssize_t) argc)
4928  ThrowMogrifyException(OptionError,"MissingArgument",option);
4929  if (IsGeometry(argv[i]) == MagickFalse)
4930  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4931  i++;
4932  if (i == (ssize_t) argc)
4933  ThrowMogrifyException(OptionError,"MissingArgument",option);
4934  break;
4935  }
4936  if (LocaleCompare("font",option+1) == 0)
4937  {
4938  if (*option == '+')
4939  break;
4940  i++;
4941  if (i == (ssize_t) argc)
4942  ThrowMogrifyException(OptionError,"MissingArgument",option);
4943  break;
4944  }
4945  if (LocaleCompare("format",option+1) == 0)
4946  {
4947  (void) CopyMagickString(argv[i]+1,"sans",MagickPathExtent);
4948  (void) CloneString(&format,(char *) NULL);
4949  if (*option == '+')
4950  break;
4951  i++;
4952  if (i == (ssize_t) argc)
4953  ThrowMogrifyException(OptionError,"MissingArgument",option);
4954  (void) CloneString(&format,argv[i]);
4955  (void) CopyMagickString(image_info->filename,format,
4957  (void) ConcatenateMagickString(image_info->filename,":",
4959  (void) SetImageInfo(image_info,0,exception);
4960  if (*image_info->magick == '\0')
4961  ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4962  format);
4963  break;
4964  }
4965  if (LocaleCompare("frame",option+1) == 0)
4966  {
4967  if (*option == '+')
4968  break;
4969  i++;
4970  if (i == (ssize_t) argc)
4971  ThrowMogrifyException(OptionError,"MissingArgument",option);
4972  if (IsGeometry(argv[i]) == MagickFalse)
4973  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4974  break;
4975  }
4976  if (LocaleCompare("function",option+1) == 0)
4977  {
4978  ssize_t
4979  op;
4980 
4981  if (*option == '+')
4982  break;
4983  i++;
4984  if (i == (ssize_t) argc)
4985  ThrowMogrifyException(OptionError,"MissingArgument",option);
4986  op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
4987  if (op < 0)
4988  ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4989  i++;
4990  if (i == (ssize_t) argc)
4991  ThrowMogrifyException(OptionError,"MissingArgument",option);
4992  break;
4993  }
4994  if (LocaleCompare("fuzz",option+1) == 0)
4995  {
4996  if (*option == '+')
4997  break;
4998  i++;
4999  if (i == (ssize_t) argc)
5000  ThrowMogrifyException(OptionError,"MissingArgument",option);
5001  if (IsGeometry(argv[i]) == MagickFalse)
5002  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5003  break;
5004  }
5005  if (LocaleCompare("fx",option+1) == 0)
5006  {
5007  if (*option == '+')
5008  break;
5009  i++;
5010  if (i == (ssize_t) argc)
5011  ThrowMogrifyException(OptionError,"MissingArgument",option);
5012  break;
5013  }
5014  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5015  }
5016  case 'g':
5017  {
5018  if (LocaleCompare("gamma",option+1) == 0)
5019  {
5020  i++;
5021  if (i == (ssize_t) argc)
5022  ThrowMogrifyException(OptionError,"MissingArgument",option);
5023  if (IsGeometry(argv[i]) == MagickFalse)
5024  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5025  break;
5026  }
5027  if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5028  (LocaleCompare("gaussian",option+1) == 0))
5029  {
5030  i++;
5031  if (i == (ssize_t) argc)
5032  ThrowMogrifyException(OptionError,"MissingArgument",option);
5033  if (IsGeometry(argv[i]) == MagickFalse)
5034  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5035  break;
5036  }
5037  if (LocaleCompare("geometry",option+1) == 0)
5038  {
5039  if (*option == '+')
5040  break;
5041  i++;
5042  if (i == (ssize_t) argc)
5043  ThrowMogrifyException(OptionError,"MissingArgument",option);
5044  if (IsGeometry(argv[i]) == MagickFalse)
5045  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5046  break;
5047  }
5048  if (LocaleCompare("gravity",option+1) == 0)
5049  {
5050  ssize_t
5051  gravity;
5052 
5053  if (*option == '+')
5054  break;
5055  i++;
5056  if (i == (ssize_t) argc)
5057  ThrowMogrifyException(OptionError,"MissingArgument",option);
5058  gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
5059  argv[i]);
5060  if (gravity < 0)
5061  ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5062  argv[i]);
5063  break;
5064  }
5065  if (LocaleCompare("grayscale",option+1) == 0)
5066  {
5067  ssize_t
5068  method;
5069 
5070  if (*option == '+')
5071  break;
5072  i++;
5073  if (i == (ssize_t) argc)
5074  ThrowMogrifyException(OptionError,"MissingArgument",option);
5075  method=ParseCommandOption(MagickPixelIntensityOptions,MagickFalse,
5076  argv[i]);
5077  if (method < 0)
5078  ThrowMogrifyException(OptionError,"UnrecognizedIntensityMethod",
5079  argv[i]);
5080  break;
5081  }
5082  if (LocaleCompare("green-primary",option+1) == 0)
5083  {
5084  if (*option == '+')
5085  break;
5086  i++;
5087  if (i == (ssize_t) argc)
5088  ThrowMogrifyException(OptionError,"MissingArgument",option);
5089  if (IsGeometry(argv[i]) == MagickFalse)
5090  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5091  break;
5092  }
5093  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5094  }
5095  case 'h':
5096  {
5097  if (LocaleCompare("hald-clut",option+1) == 0)
5098  break;
5099  if ((LocaleCompare("help",option+1) == 0) ||
5100  (LocaleCompare("-help",option+1) == 0))
5101  return(MogrifyUsage());
5102  if (LocaleCompare("hough-lines",option+1) == 0)
5103  {
5104  if (*option == '+')
5105  break;
5106  i++;
5107  if (i == (ssize_t) argc)
5108  ThrowMogrifyException(OptionError,"MissingArgument",option);
5109  if (IsGeometry(argv[i]) == MagickFalse)
5110  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5111  break;
5112  }
5113  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5114  }
5115  case 'i':
5116  {
5117  if (LocaleCompare("identify",option+1) == 0)
5118  break;
5119  if (LocaleCompare("idft",option+1) == 0)
5120  break;
5121  if (LocaleCompare("implode",option+1) == 0)
5122  {
5123  if (*option == '+')
5124  break;
5125  i++;
5126  if (i == (ssize_t) argc)
5127  ThrowMogrifyException(OptionError,"MissingArgument",option);
5128  if (IsGeometry(argv[i]) == MagickFalse)
5129  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5130  break;
5131  }
5132  if (LocaleCompare("intensity",option+1) == 0)
5133  {
5134  ssize_t
5135  intensity;
5136 
5137  if (*option == '+')
5138  break;
5139  i++;
5140  if (i == (ssize_t) argc)
5141  ThrowMogrifyException(OptionError,"MissingArgument",option);
5142  intensity=ParseCommandOption(MagickPixelIntensityOptions,
5143  MagickFalse,argv[i]);
5144  if (intensity < 0)
5145  ThrowMogrifyException(OptionError,
5146  "UnrecognizedPixelIntensityMethod",argv[i]);
5147  break;
5148  }
5149  if (LocaleCompare("intent",option+1) == 0)
5150  {
5151  ssize_t
5152  intent;
5153 
5154  if (*option == '+')
5155  break;
5156  i++;
5157  if (i == (ssize_t) argc)
5158  ThrowMogrifyException(OptionError,"MissingArgument",option);
5159  intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
5160  if (intent < 0)
5161  ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5162  argv[i]);
5163  break;
5164  }
5165  if (LocaleCompare("interlace",option+1) == 0)
5166  {
5167  ssize_t
5168  interlace;
5169 
5170  if (*option == '+')
5171  break;
5172  i++;
5173  if (i == (ssize_t) argc)
5174  ThrowMogrifyException(OptionError,"MissingArgument",option);
5175  interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
5176  argv[i]);
5177  if (interlace < 0)
5178  ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5179  argv[i]);
5180  break;
5181  }
5182  if (LocaleCompare("interline-spacing",option+1) == 0)
5183  {
5184  if (*option == '+')
5185  break;
5186  i++;
5187  if (i == (ssize_t) argc)
5188  ThrowMogrifyException(OptionError,"MissingArgument",option);
5189  if (IsGeometry(argv[i]) == MagickFalse)
5190  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5191  break;
5192  }
5193  if (LocaleCompare("interpolate",option+1) == 0)
5194  {
5195  ssize_t
5196  interpolate;
5197 
5198  if (*option == '+')
5199  break;
5200  i++;
5201  if (i == (ssize_t) argc)
5202  ThrowMogrifyException(OptionError,"MissingArgument",option);
5203  interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
5204  argv[i]);
5205  if (interpolate < 0)
5206  ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5207  argv[i]);
5208  break;
5209  }
5210  if (LocaleCompare("interword-spacing",option+1) == 0)
5211  {
5212  if (*option == '+')
5213  break;
5214  i++;
5215  if (i == (ssize_t) argc)
5216  ThrowMogrifyException(OptionError,"MissingArgument",option);
5217  if (IsGeometry(argv[i]) == MagickFalse)
5218  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5219  break;
5220  }
5221  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5222  }
5223  case 'k':
5224  {
5225  if (LocaleCompare("kerning",option+1) == 0)
5226  {
5227  if (*option == '+')
5228  break;
5229  i++;
5230  if (i == (ssize_t) argc)
5231  ThrowMogrifyException(OptionError,"MissingArgument",option);
5232  if (IsGeometry(argv[i]) == MagickFalse)
5233  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5234  break;
5235  }
5236  if (LocaleCompare("kuwahara",option+1) == 0)
5237  {
5238  i++;
5239  if (i == (ssize_t) argc)
5240  ThrowMogrifyException(OptionError,"MissingArgument",option);
5241  if (IsGeometry(argv[i]) == MagickFalse)
5242  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5243  break;
5244  }
5245  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5246  }
5247  case 'l':
5248  {
5249  if (LocaleCompare("label",option+1) == 0)
5250  {
5251  if (*option == '+')
5252  break;
5253  i++;
5254  if (i == (ssize_t) argc)
5255  ThrowMogrifyException(OptionError,"MissingArgument",option);
5256  break;
5257  }
5258  if (LocaleCompare("lat",option+1) == 0)
5259  {
5260  if (*option == '+')
5261  break;
5262  i++;
5263  if (i == (ssize_t) argc)
5264  ThrowMogrifyException(OptionError,"MissingArgument",option);
5265  if (IsGeometry(argv[i]) == MagickFalse)
5266  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5267  }
5268  if (LocaleCompare("layers",option+1) == 0)
5269  {
5270  ssize_t
5271  type;
5272 
5273  if (*option == '+')
5274  break;
5275  i++;
5276  if (i == (ssize_t) argc)
5277  ThrowMogrifyException(OptionError,"MissingArgument",option);
5278  type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
5279  if (type < 0)
5280  ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5281  argv[i]);
5282  break;
5283  }
5284  if (LocaleCompare("level",option+1) == 0)
5285  {
5286  i++;
5287  if (i == (ssize_t) argc)
5288  ThrowMogrifyException(OptionError,"MissingArgument",option);
5289  if (IsGeometry(argv[i]) == MagickFalse)
5290  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5291  break;
5292  }
5293  if (LocaleCompare("level-colors",option+1) == 0)
5294  {
5295  i++;
5296  if (i == (ssize_t) argc)
5297  ThrowMogrifyException(OptionError,"MissingArgument",option);
5298  break;
5299  }
5300  if (LocaleCompare("limit",option+1) == 0)
5301  {
5302  char
5303  *p;
5304 
5305  double
5306  value;
5307 
5308  ssize_t
5309  resource;
5310 
5311  if (*option == '+')
5312  break;
5313  i++;
5314  if (i == (ssize_t) argc)
5315  ThrowMogrifyException(OptionError,"MissingArgument",option);
5316  resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
5317  argv[i]);
5318  if (resource < 0)
5319  ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5320  argv[i]);
5321  i++;
5322  if (i == (ssize_t) argc)
5323  ThrowMogrifyException(OptionError,"MissingArgument",option);
5324  value=StringToDouble(argv[i],&p);
5325  (void) value;
5326  if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5327  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5328  break;
5329  }
5330  if (LocaleCompare("liquid-rescale",option+1) == 0)
5331  {
5332  i++;
5333  if (i == (ssize_t) argc)
5334  ThrowMogrifyException(OptionError,"MissingArgument",option);
5335  if (IsGeometry(argv[i]) == MagickFalse)
5336  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5337  break;
5338  }
5339  if (LocaleCompare("list",option+1) == 0)
5340  {
5341  ssize_t
5342  list;
5343 
5344  if (*option == '+')
5345  break;
5346  i++;
5347  if (i == (ssize_t) argc)
5348  ThrowMogrifyException(OptionError,"MissingArgument",option);
5349  list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
5350  if (list < 0)
5351  ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
5352  status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
5353  argv+j,exception);
5354  return(status == 0 ? MagickFalse : MagickTrue);
5355  }
5356  if (LocaleCompare("log",option+1) == 0)
5357  {
5358  if (*option == '+')
5359  break;
5360  i++;
5361  if ((i == (ssize_t) argc) ||
5362  (strchr(argv[i],'%') == (char *) NULL))
5363  ThrowMogrifyException(OptionError,"MissingArgument",option);
5364  break;
5365  }
5366  if (LocaleCompare("loop",option+1) == 0)
5367  {
5368  if (*option == '+')
5369  break;
5370  i++;
5371  if (i == (ssize_t) argc)
5372  ThrowMogrifyException(OptionError,"MissingArgument",option);
5373  if (IsGeometry(argv[i]) == MagickFalse)
5374  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5375  break;
5376  }
5377  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5378  }
5379  case 'm':
5380  {
5381  if (LocaleCompare("magnify",option+1) == 0)
5382  break;
5383  if (LocaleCompare("map",option+1) == 0)
5384  {
5385  global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5386  if (*option == '+')
5387  break;
5388  i++;
5389  if (i == (ssize_t) argc)
5390  ThrowMogrifyException(OptionError,"MissingArgument",option);
5391  break;
5392  }
5393  if (LocaleCompare("mask",option+1) == 0)
5394  {
5395  if (*option == '+')
5396  break;
5397  i++;
5398  if (i == (ssize_t) argc)
5399  ThrowMogrifyException(OptionError,"MissingArgument",option);
5400  break;
5401  }
5402  if (LocaleCompare("matte",option+1) == 0)
5403  break;
5404  if (LocaleCompare("mattecolor",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("maximum",option+1) == 0)
5414  break;
5415  if (LocaleCompare("mean-shift",option+1) == 0)
5416  {
5417  if (*option == '+')
5418  break;
5419  i++;
5420  if (i == (ssize_t) argc)
5421  ThrowMogrifyException(OptionError,"MissingArgument",option);
5422  if (IsGeometry(argv[i]) == MagickFalse)
5423  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5424  break;
5425  }
5426  if (LocaleCompare("median",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("metric",option+1) == 0)
5438  {
5439  ssize_t
5440  type;
5441 
5442  if (*option == '+')
5443  break;
5444  i++;
5445  if (i == (ssize_t) argc)
5446  ThrowMogrifyException(OptionError,"MissingArgument",option);
5447  type=ParseCommandOption(MagickMetricOptions,MagickTrue,argv[i]);
5448  if (type < 0)
5449  ThrowMogrifyException(OptionError,"UnrecognizedMetricType",
5450  argv[i]);
5451  break;
5452  }
5453  if (LocaleCompare("minimum",option+1) == 0)
5454  break;
5455  if (LocaleCompare("modulate",option+1) == 0)
5456  {
5457  if (*option == '+')
5458  break;
5459  i++;
5460  if (i == (ssize_t) argc)
5461  ThrowMogrifyException(OptionError,"MissingArgument",option);
5462  if (IsGeometry(argv[i]) == MagickFalse)
5463  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5464  break;
5465  }
5466  if (LocaleCompare("mode",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("monitor",option+1) == 0)
5478  break;
5479  if (LocaleCompare("monochrome",option+1) == 0)
5480  break;
5481  if (LocaleCompare("morph",option+1) == 0)
5482  {
5483  if (*option == '+')
5484  break;
5485  i++;
5486  if (i == (ssize_t) argc)
5487  ThrowMogrifyException(OptionError,"MissingArgument",option);
5488  if (IsGeometry(argv[i]) == MagickFalse)
5489  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5490  break;
5491  }
5492  if (LocaleCompare("morphology",option+1) == 0)
5493  {
5494  char
5495  token[MagickPathExtent];
5496 
5497  KernelInfo
5498  *kernel_info;
5499 
5500  ssize_t
5501  op;
5502 
5503  i++;
5504  if (i == (ssize_t) argc)
5505  ThrowMogrifyException(OptionError,"MissingArgument",option);
5506  GetNextToken(argv[i],(const char **) NULL,MagickPathExtent,token);
5507  op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
5508  if (op < 0)
5509  ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
5510  token);
5511  i++;
5512  if (i == (ssize_t) argc)
5513  ThrowMogrifyException(OptionError,"MissingArgument",option);
5514  kernel_info=AcquireKernelInfo(argv[i],exception);
5515  if (kernel_info == (KernelInfo *) NULL)
5516  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5517  kernel_info=DestroyKernelInfo(kernel_info);
5518  break;
5519  }
5520  if (LocaleCompare("mosaic",option+1) == 0)
5521  break;
5522  if (LocaleCompare("motion-blur",option+1) == 0)
5523  {
5524  if (*option == '+')
5525  break;
5526  i++;
5527  if (i == (ssize_t) argc)
5528  ThrowMogrifyException(OptionError,"MissingArgument",option);
5529  if (IsGeometry(argv[i]) == MagickFalse)
5530  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5531  break;
5532  }
5533  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5534  }
5535  case 'n':
5536  {
5537  if (LocaleCompare("negate",option+1) == 0)
5538  break;
5539  if (LocaleCompare("noise",option+1) == 0)
5540  {
5541  i++;
5542  if (i == (ssize_t) argc)
5543  ThrowMogrifyException(OptionError,"MissingArgument",option);
5544  if (*option == '+')
5545  {
5546  ssize_t
5547  noise;
5548 
5549  noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,
5550  argv[i]);
5551  if (noise < 0)
5552  ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5553  argv[i]);
5554  break;
5555  }
5556  if (IsGeometry(argv[i]) == MagickFalse)
5557  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5558  break;
5559  }
5560  if (LocaleCompare("noop",option+1) == 0)
5561  break;
5562  if (LocaleCompare("normalize",option+1) == 0)
5563  break;
5564  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5565  }
5566  case 'o':
5567  {
5568  if (LocaleCompare("opaque",option+1) == 0)
5569  {
5570  i++;
5571  if (i == (ssize_t) argc)
5572  ThrowMogrifyException(OptionError,"MissingArgument",option);
5573  break;
5574  }
5575  if (LocaleCompare("ordered-dither",option+1) == 0)
5576  {
5577  if (*option == '+')
5578  break;
5579  i++;
5580  if (i == (ssize_t) argc)
5581  ThrowMogrifyException(OptionError,"MissingArgument",option);
5582  break;
5583  }
5584  if (LocaleCompare("orient",option+1) == 0)
5585  {
5586  ssize_t
5587  orientation;
5588 
5589  orientation=UndefinedOrientation;
5590  if (*option == '+')
5591  break;
5592  i++;
5593  if (i == (ssize_t) argc)
5594  ThrowMogrifyException(OptionError,"MissingArgument",option);
5595  orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
5596  argv[i]);
5597  if (orientation < 0)
5598  ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5599  argv[i]);
5600  break;
5601  }
5602  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5603  }
5604  case 'p':
5605  {
5606  if (LocaleCompare("page",option+1) == 0)
5607  {
5608  if (*option == '+')
5609  break;
5610  i++;
5611  if (i == (ssize_t) argc)
5612  ThrowMogrifyException(OptionError,"MissingArgument",option);
5613  break;
5614  }
5615  if (LocaleCompare("paint",option+1) == 0)
5616  {
5617  if (*option == '+')
5618  break;
5619  i++;
5620  if (i == (ssize_t) argc)
5621  ThrowMogrifyException(OptionError,"MissingArgument",option);
5622  if (IsGeometry(argv[i]) == MagickFalse)
5623  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5624  break;
5625  }
5626  if (LocaleCompare("path",option+1) == 0)
5627  {
5628  (void) CloneString(&path,(char *) NULL);
5629  if (*option == '+')
5630  break;
5631  i++;
5632  if (i == (ssize_t) argc)
5633  ThrowMogrifyException(OptionError,"MissingArgument",option);
5634  (void) CloneString(&path,argv[i]);
5635  break;
5636  }
5637  if (LocaleCompare("perceptible",option+1) == 0)
5638  {
5639  if (*option == '+')
5640  break;
5641  i++;
5642  if (i == (ssize_t) argc)
5643  ThrowMogrifyException(OptionError,"MissingArgument",option);
5644  if (IsGeometry(argv[i]) == MagickFalse)
5645  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5646  break;
5647  }
5648  if (LocaleCompare("pointsize",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("polaroid",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("poly",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("posterize",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("precision",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("print",option+1) == 0)
5704  {
5705  if (*option == '+')
5706  break;
5707  i++;
5708  if (i == (ssize_t) argc)
5709  ThrowMogrifyException(OptionError,"MissingArgument",option);
5710  break;
5711  }
5712  if (LocaleCompare("process",option+1) == 0)
5713  {
5714  if (*option == '+')
5715  break;
5716  i++;
5717  if (i == (ssize_t) argc)
5718  ThrowMogrifyException(OptionError,"MissingArgument",option);
5719  break;
5720  }
5721  if (LocaleCompare("profile",option+1) == 0)
5722  {
5723  i++;
5724  if (i == (ssize_t) argc)
5725  ThrowMogrifyException(OptionError,"MissingArgument",option);
5726  break;
5727  }
5728  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5729  }
5730  case 'q':
5731  {
5732  if (LocaleCompare("quality",option+1) == 0)
5733  {
5734  if (*option == '+')
5735  break;
5736  i++;
5737  if (i == (ssize_t) argc)
5738  ThrowMogrifyException(OptionError,"MissingArgument",option);
5739  if (IsGeometry(argv[i]) == MagickFalse)
5740  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5741  break;
5742  }
5743  if (LocaleCompare("quantize",option+1) == 0)
5744  {
5745  ssize_t
5746  colorspace;
5747 
5748  if (*option == '+')
5749  break;
5750  i++;
5751  if (i == (ssize_t) argc)
5752  ThrowMogrifyException(OptionError,"MissingArgument",option);
5753  colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
5754  argv[i]);
5755  if (colorspace < 0)
5756  ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5757  argv[i]);
5758  break;
5759  }
5760  if (LocaleCompare("quiet",option+1) == 0)
5761  break;
5762  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5763  }
5764  case 'r':
5765  {
5766  if (LocaleCompare("rotational-blur",option+1) == 0)
5767  {
5768  i++;
5769  if (i == (ssize_t) argc)
5770  ThrowMogrifyException(OptionError,"MissingArgument",option);
5771  if (IsGeometry(argv[i]) == MagickFalse)
5772  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5773  break;
5774  }
5775  if (LocaleCompare("raise",option+1) == 0)
5776  {
5777  i++;
5778  if (i == (ssize_t) argc)
5779  ThrowMogrifyException(OptionError,"MissingArgument",option);
5780  if (IsGeometry(argv[i]) == MagickFalse)
5781  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5782  break;
5783  }
5784  if (LocaleCompare("random-threshold",option+1) == 0)
5785  {
5786  if (*option == '+')
5787  break;
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("range-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