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