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