MagickWand  6.9.12-73
Convert, Edit, Or Compose Bitmap Images
 All Data Structures
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 1999-2021 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
22 % %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
25 % %
26 % https://imagemagick.org/script/license.php %
27 % %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
33 % %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 % Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37 % draw on, flip, join, re-sample, and much more. This tool is similar to
38 % convert except that the original image file is overwritten (unless you
39 % change the file suffix with the -format option) with any changes you
40 % request.
41 %
42 */
43 
44 /*
45  Include declarations.
46 */
47 #include "wand/studio.h"
48 #include "wand/MagickWand.h"
49 #include "wand/magick-wand-private.h"
50 #include "wand/mogrify-private.h"
51 #include "magick/blob-private.h"
52 #include "magick/color-private.h"
53 #include "magick/image-private.h"
54 #include "magick/monitor-private.h"
55 #include "magick/pixel-private.h"
56 #include "magick/thread-private.h"
57 #include "magick/string-private.h"
58 #include "magick/timer-private.h"
59 #include "magick/utility-private.h"
60 #if defined(MAGICKCORE_HAVE_UTIME_H)
61 #include <utime.h>
62 #endif
63 
64 /*
65  Define declarations.
66 */
67 #define UndefinedCompressionQuality 0UL
68 
69 /*
70  Constant declaration.
71 */
72 static const char
73  MogrifyBackgroundColor[] = "#fff", /* white */
74  MogrifyBorderColor[] = "#dfdfdf", /* sRGB gray */
75  MogrifyMatteColor[] = "#bdbdbd"; /* slightly darker gray */
76 
77 /*
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % %
80 % %
81 % %
82 % M a g i c k C o m m a n d G e n e s i s %
83 % %
84 % %
85 % %
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 %
88 % MagickCommandGenesis() applies image processing options to an image as
89 % prescribed by command line options.
90 %
91 % The format of the MagickCommandGenesis method is:
92 %
93 % MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
94 % MagickCommand command,int argc,char **argv,char **metadata,
95 % ExceptionInfo *exception)
96 %
97 % A description of each parameter follows:
98 %
99 % o image_info: the image info.
100 %
101 % o command: Choose from ConvertImageCommand, IdentifyImageCommand,
102 % MogrifyImageCommand, CompositeImageCommand, CompareImageCommand,
103 % ConjureImageCommand, StreamImageCommand, ImportImageCommand,
104 % DisplayImageCommand, or AnimateImageCommand.
105 %
106 % o argc: Specifies a pointer to an integer describing the number of
107 % elements in the argument vector.
108 %
109 % o argv: Specifies a pointer to a text array containing the command line
110 % arguments.
111 %
112 % o metadata: any metadata is returned here.
113 %
114 % o exception: return any errors or warnings in this structure.
115 %
116 */
117 WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
118  MagickCommand command,int argc,char **argv,char **metadata,
119  ExceptionInfo *exception)
120 {
121  char
122  *option;
123 
124  double
125  duration,
126  serial;
127 
128  MagickBooleanType
129  concurrent,
130  regard_warnings,
131  status;
132 
133  ssize_t
134  i;
135 
136  size_t
137  iterations,
138  number_threads;
139 
140  ssize_t
141  n;
142 
143  (void) setlocale(LC_ALL,"");
144  (void) setlocale(LC_NUMERIC,"C");
145  concurrent=MagickFalse;
146  duration=(-1.0);
147  iterations=1;
148  status=MagickTrue;
149  regard_warnings=MagickFalse;
150  for (i=1; i < (ssize_t) (argc-1); i++)
151  {
152  option=argv[i];
153  if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
154  continue;
155  if (LocaleCompare("bench",option+1) == 0)
156  iterations=StringToUnsignedLong(argv[++i]);
157  if (LocaleCompare("concurrent",option+1) == 0)
158  concurrent=MagickTrue;
159  if (LocaleCompare("debug",option+1) == 0)
160  (void) SetLogEventMask(argv[++i]);
161  if (LocaleCompare("distribute-cache",option+1) == 0)
162  {
163  DistributePixelCacheServer(StringToInteger(argv[++i]),exception);
164  exit(0);
165  }
166  if (LocaleCompare("duration",option+1) == 0)
167  duration=StringToDouble(argv[++i],(char **) NULL);
168  if (LocaleCompare("regard-warnings",option+1) == 0)
169  regard_warnings=MagickTrue;
170  }
171  if (iterations == 1)
172  {
173  status=command(image_info,argc,argv,metadata,exception);
174  if (exception->severity != UndefinedException)
175  {
176  if ((exception->severity > ErrorException) ||
177  (regard_warnings != MagickFalse))
178  status=MagickFalse;
179  CatchException(exception);
180  }
181  if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
182  {
183  (void) fputs(*metadata,stdout);
184  *metadata=DestroyString(*metadata);
185  }
186  return(status);
187  }
188  number_threads=GetOpenMPMaximumThreads();
189  serial=0.0;
190  for (n=1; n <= (ssize_t) number_threads; n++)
191  {
192  double
193  e,
194  parallel,
195  user_time;
196 
197  TimerInfo
198  *timer;
199 
200  (void) SetMagickResourceLimit(ThreadResource,(MagickSizeType) n);
201  timer=AcquireTimerInfo();
202  if (concurrent == MagickFalse)
203  {
204  for (i=0; i < (ssize_t) iterations; i++)
205  {
206  if (status == MagickFalse)
207  continue;
208  if (duration > 0)
209  {
210  if (GetElapsedTime(timer) > duration)
211  continue;
212  (void) ContinueTimer(timer);
213  }
214  status=command(image_info,argc,argv,metadata,exception);
215  if (exception->severity != UndefinedException)
216  {
217  if ((exception->severity > ErrorException) ||
218  (regard_warnings != MagickFalse))
219  status=MagickFalse;
220  CatchException(exception);
221  }
222  if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
223  {
224  (void) fputs(*metadata,stdout);
225  *metadata=DestroyString(*metadata);
226  }
227  }
228  }
229  else
230  {
231  SetOpenMPNested(1);
232 #if defined(MAGICKCORE_OPENMP_SUPPORT)
233  # pragma omp parallel for shared(status)
234 #endif
235  for (i=0; i < (ssize_t) iterations; i++)
236  {
237  if (status == MagickFalse)
238  continue;
239  if (duration > 0)
240  {
241  if (GetElapsedTime(timer) > duration)
242  continue;
243  (void) ContinueTimer(timer);
244  }
245  status=command(image_info,argc,argv,metadata,exception);
246 #if defined(MAGICKCORE_OPENMP_SUPPORT)
247  # pragma omp critical (MagickCore_MagickCommandGenesis)
248 #endif
249  {
250  if (exception->severity != UndefinedException)
251  {
252  if ((exception->severity > ErrorException) ||
253  (regard_warnings != MagickFalse))
254  status=MagickFalse;
255  CatchException(exception);
256  }
257  if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
258  {
259  (void) fputs(*metadata,stdout);
260  *metadata=DestroyString(*metadata);
261  }
262  }
263  }
264  }
265  user_time=GetUserTime(timer);
266  parallel=GetElapsedTime(timer);
267  e=1.0;
268  if (n == 1)
269  serial=parallel;
270  else
271  e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
272  (double) n)))-(1.0/(double) n))/(1.0-1.0/(double) n);
273  (void) FormatLocaleFile(stderr,
274  " Performance[%.20g]: %.20gi %0.3fips %0.6fe %0.6fu %lu:%02lu.%03lu\n",
275  (double) n,(double) iterations,(double) iterations/parallel,e,user_time,
276  (unsigned long) (parallel/60.0),(unsigned long) floor(fmod(parallel,
277  60.0)),(unsigned long) (1000.0*(parallel-floor(parallel))+0.5));
278  timer=DestroyTimerInfo(timer);
279  }
280  return(status);
281 }
282 
283 /*
284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 % %
286 % %
287 % %
288 + M o g r i f y I m a g e %
289 % %
290 % %
291 % %
292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293 %
294 % MogrifyImage() applies simple single image processing options to a single
295 % image that may be part of a large list, but also handles any 'region'
296 % image handling.
297 %
298 % The image in the list may be modified in three different ways...
299 %
300 % * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
301 % * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
302 % * replace by a list of images (only the -separate option!)
303 %
304 % In each case the result is returned into the list, and a pointer to the
305 % modified image (last image added if replaced by a list of images) is
306 % returned.
307 %
308 % ASIDE: The -crop is present but restricted to non-tile single image crops
309 %
310 % This means if all the images are being processed (such as by
311 % MogrifyImages(), next image to be processed will be as per the pointer
312 % (*image)->next. Also the image list may grow as a result of some specific
313 % operations but as images are never merged or deleted, it will never shrink
314 % in length. Typically the list will remain the same length.
315 %
316 % WARNING: As the image pointed to may be replaced, the first image in the
317 % list may also change. GetFirstImageInList() should be used by caller if
318 % they wish return the Image pointer to the first image in list.
319 %
320 %
321 % The format of the MogrifyImage method is:
322 %
323 % MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
324 % const char **argv,Image **image)
325 %
326 % A description of each parameter follows:
327 %
328 % o image_info: the image info..
329 %
330 % o argc: Specifies a pointer to an integer describing the number of
331 % elements in the argument vector.
332 %
333 % o argv: Specifies a pointer to a text array containing the command line
334 % arguments.
335 %
336 % o image: the image.
337 %
338 % o exception: return any errors or warnings in this structure.
339 %
340 */
341 
342 static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
343  ExceptionInfo *exception)
344 {
345  char
346  key[MaxTextExtent];
347 
348  ExceptionInfo
349  *sans_exception;
350 
351  Image
352  *image;
353 
354  ImageInfo
355  *read_info;
356 
357  /*
358  Read an image into a image cache if not already present. Return the image
359  that is in the cache under that filename.
360  */
361  (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
362  sans_exception=AcquireExceptionInfo();
363  image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
364  sans_exception=DestroyExceptionInfo(sans_exception);
365  if (image != (Image *) NULL)
366  return(image);
367  read_info=CloneImageInfo(image_info);
368  (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
369  image=ReadImage(read_info,exception);
370  read_info=DestroyImageInfo(read_info);
371  if (image != (Image *) NULL)
372  (void) SetImageRegistry(ImageRegistryType,key,image,exception);
373  return(image);
374 }
375 
376 static inline MagickBooleanType IsPathWritable(const char *path)
377 {
378  if (IsPathAccessible(path) == MagickFalse)
379  return(MagickFalse);
380  if (access_utf8(path,W_OK) != 0)
381  return(MagickFalse);
382  return(MagickTrue);
383 }
384 
385 static MagickBooleanType MonitorProgress(const char *text,
386  const MagickOffsetType offset,const MagickSizeType extent,
387  void *wand_unused(client_data))
388 {
389  char
390  message[MaxTextExtent],
391  tag[MaxTextExtent];
392 
393  const char
394  *locale_message;
395 
396  char
397  *p;
398 
399  wand_unreferenced(client_data);
400 
401  (void) CopyMagickString(tag,text == (const char *) NULL ? "null" : text,
402  MaxTextExtent);
403  p=strrchr(tag,'/');
404  if (p != (char *) NULL)
405  *p='\0';
406  (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
407  locale_message=GetLocaleMessage(message);
408  if (locale_message == message)
409  locale_message=tag;
410  if (p == (char *) NULL)
411  (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
412  locale_message,(long) offset,(unsigned long) extent,(long)
413  (100.0*offset*PerceptibleReciprocal(extent-1.0)));
414  else
415  (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
416  locale_message,p+1,(long) offset,(unsigned long) extent,(long)
417  (100.0*offset*PerceptibleReciprocal(extent-1.0)));
418  if (offset == (MagickOffsetType) (extent-1))
419  (void) FormatLocaleFile(stderr,"\n");
420  (void) fflush(stderr);
421  return(MagickTrue);
422 }
423 
424 static Image *SparseColorOption(const Image *image,const ChannelType channel,
425  const SparseColorMethod method,const char *arguments,
426  const MagickBooleanType color_from_image,ExceptionInfo *exception)
427 {
428  ChannelType
429  channels;
430 
431  char
432  token[MaxTextExtent];
433 
434  const char
435  *p;
436 
437  double
438  *sparse_arguments;
439 
440  Image
441  *sparse_image;
442 
443  MagickBooleanType
444  error;
445 
446  MagickPixelPacket
447  color;
448 
449  size_t
450  x;
451 
452  size_t
453  number_arguments,
454  number_colors;
455 
456  /*
457  SparseColorOption() parses the complex -sparse-color argument into an an
458  array of floating point values then calls SparseColorImage(). Argument is
459  a complex mix of floating-point pixel coordinates, and color specifications
460  (or direct floating point numbers). The number of floats needed to
461  represent a color varies depending on the current channel setting.
462  */
463  assert(image != (Image *) NULL);
464  assert(image->signature == MagickCoreSignature);
465  assert(exception != (ExceptionInfo *) NULL);
466  assert(exception->signature == MagickCoreSignature);
467  if (IsEventLogging() != MagickFalse)
468  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
469  /*
470  Limit channels according to image - and add up number of color channel.
471  */
472  channels=channel;
473  if (image->colorspace != CMYKColorspace)
474  channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
475  if (image->matte == MagickFalse)
476  channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
477  number_colors=0;
478  if ((channels & RedChannel) != 0)
479  number_colors++;
480  if ((channels & GreenChannel) != 0)
481  number_colors++;
482  if ((channels & BlueChannel) != 0)
483  number_colors++;
484  if ((channels & IndexChannel) != 0)
485  number_colors++;
486  if ((channels & OpacityChannel) != 0)
487  number_colors++;
488 
489  /*
490  Read string, to determine number of arguments needed,
491  */
492  p=arguments;
493  x=0;
494  while( *p != '\0' )
495  {
496  (void) GetNextToken(p,&p,MaxTextExtent,token);
497  if ( *token == ',' ) continue;
498  if ( isalpha((int) ((unsigned char) *token)) || *token == '#' ) {
499  if ( color_from_image ) {
500  (void) ThrowMagickException(exception,GetMagickModule(),
501  OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
502  "Color arg given, when colors are coming from image");
503  return( (Image *) NULL);
504  }
505  x += number_colors; /* color argument */
506  }
507  else {
508  x++; /* floating point argument */
509  }
510  }
511  error=MagickTrue;
512  if ( color_from_image ) {
513  /* just the control points are being given */
514  error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
515  number_arguments=(x/2)*(2+number_colors);
516  }
517  else {
518  /* control points and color values */
519  error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
520  number_arguments=x;
521  }
522  if ( error ) {
523  (void) ThrowMagickException(exception,GetMagickModule(),
524  OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
525  "Invalid number of Arguments");
526  return( (Image *) NULL);
527  }
528 
529  /* Allocate and fill in the floating point arguments */
530  sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
531  sizeof(*sparse_arguments));
532  if (sparse_arguments == (double *) NULL) {
533  (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
534  " MemoryAllocationFailed\n""%s","SparseColorOption");
535  return( (Image *) NULL);
536  }
537  (void) memset(sparse_arguments,0,number_arguments*
538  sizeof(*sparse_arguments));
539  p=arguments;
540  x=0;
541  while( *p != '\0' && x < number_arguments ) {
542  /* X coordinate */
543  *token=',';
544  while ( *token == ',' )
545  (void) GetNextToken(p,&p,MaxTextExtent,token);
546  if ( *token == '\0' ) break;
547  if ( isalpha((int) ((unsigned char) *token)) || *token == '#' ) {
548  (void) ThrowMagickException(exception,GetMagickModule(),
549  OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
550  "Color found, instead of X-coord");
551  error = MagickTrue;
552  break;
553  }
554  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
555  /* Y coordinate */
556  *token=','; while ( *token == ',' ) GetNextToken(p,&p,MaxTextExtent,token);
557  if ( *token == '\0' ) break;
558  if ( isalpha((int) ((unsigned char) *token)) || *token == '#' ) {
559  (void) ThrowMagickException(exception,GetMagickModule(),
560  OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
561  "Color found, instead of Y-coord");
562  error = MagickTrue;
563  break;
564  }
565  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
566  /* color values for this control point */
567 #if 0
568  if ( (color_from_image ) {
569  /* get color from image */
570  /* HOW??? */
571  }
572  else
573 #endif
574  {
575  /* color name or function given in string argument */
576  *token=',';
577  while ( *token == ',' )
578  (void) GetNextToken(p,&p,MaxTextExtent,token);
579  if ( *token == '\0' ) break;
580  if ( isalpha((int) ((unsigned char) *token)) || *token == '#' ) {
581  /* Color string given */
582  (void) QueryMagickColor(token,&color,exception);
583  if ( channels & RedChannel )
584  sparse_arguments[x++] = QuantumScale*color.red;
585  if ( channels & GreenChannel )
586  sparse_arguments[x++] = QuantumScale*color.green;
587  if ( channels & BlueChannel )
588  sparse_arguments[x++] = QuantumScale*color.blue;
589  if ( channels & IndexChannel )
590  sparse_arguments[x++] = QuantumScale*color.index;
591  if ( channels & OpacityChannel )
592  sparse_arguments[x++] = QuantumScale*color.opacity;
593  }
594  else {
595  /* Colors given as a set of floating point values - experimental */
596  /* NB: token contains the first floating point value to use! */
597  if ( channels & RedChannel ) {
598  while ( *token == ',' )
599  (void) GetNextToken(p,&p,MaxTextExtent,token);
600  if ( *token == '\0' || isalpha((int) ((unsigned char) *token)) || *token == '#' )
601  break;
602  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
603  *token = ','; /* used this token - get another */
604  }
605  if ( channels & GreenChannel ) {
606  while ( *token == ',' )
607  (void) GetNextToken(p,&p,MaxTextExtent,token);
608  if ( *token == '\0' || isalpha((int) ((unsigned char) *token)) || *token == '#' )
609  break;
610  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
611  *token = ','; /* used this token - get another */
612  }
613  if ( channels & BlueChannel ) {
614  while ( *token == ',' )
615  (void) GetNextToken(p,&p,MaxTextExtent,token);
616  if ( *token == '\0' || isalpha((int) ((unsigned char) *token)) || *token == '#' )
617  break;
618  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
619  *token = ','; /* used this token - get another */
620  }
621  if ( channels & IndexChannel ) {
622  while ( *token == ',' )
623  (void) GetNextToken(p,&p,MaxTextExtent,token);
624  if ( *token == '\0' || isalpha((int) ((unsigned char) *token)) || *token == '#' )
625  break;
626  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
627  *token = ','; /* used this token - get another */
628  }
629  if ( channels & OpacityChannel ) {
630  while ( *token == ',' )
631  (void) GetNextToken(p,&p,MaxTextExtent,token);
632  if ( *token == '\0' || isalpha((int) ((unsigned char) *token)) || *token == '#' )
633  break;
634  sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
635  *token = ','; /* used this token - get another */
636  }
637  }
638  }
639  }
640  if ( number_arguments != x && !error ) {
641  (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
642  " InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
643  sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
644  return( (Image *) NULL);
645  }
646  if ( error )
647  return( (Image *) NULL);
648 
649  /* Call the Interpolation function with the parsed arguments */
650  sparse_image=SparseColorImage(image,channels,method,number_arguments,
651  sparse_arguments,exception);
652  sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
653  return( sparse_image );
654 }
655 
656 WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
657  const char **argv,Image **image,ExceptionInfo *exception)
658 {
659  ChannelType
660  channel;
661 
662  const char
663  *format,
664  *option;
665 
666  DrawInfo
667  *draw_info;
668 
669  GeometryInfo
670  geometry_info;
671 
672  Image
673  *region_image;
674 
675  ImageInfo
676  *mogrify_info;
677 
678  MagickStatusType
679  status;
680 
681  MagickPixelPacket
682  fill;
683 
684  MagickStatusType
685  flags;
686 
687  QuantizeInfo
688  *quantize_info;
689 
690  RectangleInfo
691  geometry,
692  region_geometry;
693 
694  ssize_t
695  i;
696 
697  /*
698  Initialize method variables.
699  */
700  assert(image_info != (const ImageInfo *) NULL);
701  assert(image_info->signature == MagickCoreSignature);
702  assert(image != (Image **) NULL);
703  assert((*image)->signature == MagickCoreSignature);
704  if (IsEventLogging() != MagickFalse)
705  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
706  if (argc < 0)
707  return(MagickTrue);
708  mogrify_info=CloneImageInfo(image_info);
709  draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
710  quantize_info=AcquireQuantizeInfo(mogrify_info);
711  SetGeometryInfo(&geometry_info);
712  GetMagickPixelPacket(*image,&fill);
713  SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
714  &fill);
715  channel=mogrify_info->channel;
716  format=GetImageOption(mogrify_info,"format");
717  SetGeometry(*image,&region_geometry);
718  region_image=NewImageList();
719  /*
720  Transmogrify the image.
721  */
722  for (i=0; i < (ssize_t) argc; i++)
723  {
724  Image
725  *mogrify_image;
726 
727  ssize_t
728  count;
729 
730  option=argv[i];
731  if (IsCommandOption(option) == MagickFalse)
732  continue;
733  count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
734  0L);
735  if ((i+count) >= (ssize_t) argc)
736  break;
737  status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
738  mogrify_image=(Image *) NULL;
739  switch (*(option+1))
740  {
741  case 'a':
742  {
743  if (LocaleCompare("adaptive-blur",option+1) == 0)
744  {
745  /*
746  Adaptive blur image.
747  */
748  (void) SyncImageSettings(mogrify_info,*image);
749  flags=ParseGeometry(argv[i+1],&geometry_info);
750  if ((flags & SigmaValue) == 0)
751  geometry_info.sigma=1.0;
752  mogrify_image=AdaptiveBlurImageChannel(*image,channel,
753  geometry_info.rho,geometry_info.sigma,exception);
754  break;
755  }
756  if (LocaleCompare("adaptive-resize",option+1) == 0)
757  {
758  /*
759  Adaptive resize image.
760  */
761  (void) SyncImageSettings(mogrify_info,*image);
762  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
763  mogrify_image=AdaptiveResizeImage(*image,geometry.width,
764  geometry.height,exception);
765  break;
766  }
767  if (LocaleCompare("adaptive-sharpen",option+1) == 0)
768  {
769  /*
770  Adaptive sharpen image.
771  */
772  (void) SyncImageSettings(mogrify_info,*image);
773  flags=ParseGeometry(argv[i+1],&geometry_info);
774  if ((flags & SigmaValue) == 0)
775  geometry_info.sigma=1.0;
776  mogrify_image=AdaptiveSharpenImageChannel(*image,channel,
777  geometry_info.rho,geometry_info.sigma,exception);
778  break;
779  }
780  if (LocaleCompare("affine",option+1) == 0)
781  {
782  /*
783  Affine matrix.
784  */
785  if (*option == '+')
786  {
787  GetAffineMatrix(&draw_info->affine);
788  break;
789  }
790  (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
791  break;
792  }
793  if (LocaleCompare("alpha",option+1) == 0)
794  {
795  AlphaChannelType
796  alpha_type;
797 
798  (void) SyncImageSettings(mogrify_info,*image);
799  alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
800  MagickFalse,argv[i+1]);
801  (void) SetImageAlphaChannel(*image,alpha_type);
802  InheritException(exception,&(*image)->exception);
803  break;
804  }
805  if (LocaleCompare("annotate",option+1) == 0)
806  {
807  char
808  *text,
809  geometry[MaxTextExtent];
810 
811  /*
812  Annotate image.
813  */
814  (void) SyncImageSettings(mogrify_info,*image);
815  SetGeometryInfo(&geometry_info);
816  flags=ParseGeometry(argv[i+1],&geometry_info);
817  if ((flags & SigmaValue) == 0)
818  geometry_info.sigma=geometry_info.rho;
819  text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
820  InheritException(exception,&(*image)->exception);
821  if (text == (char *) NULL)
822  break;
823  (void) CloneString(&draw_info->text,text);
824  text=DestroyString(text);
825  (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
826  geometry_info.xi,geometry_info.psi);
827  (void) CloneString(&draw_info->geometry,geometry);
828  draw_info->affine.sx=cos(DegreesToRadians(
829  fmod(geometry_info.rho,360.0)));
830  draw_info->affine.rx=sin(DegreesToRadians(
831  fmod(geometry_info.rho,360.0)));
832  draw_info->affine.ry=(-sin(DegreesToRadians(
833  fmod(geometry_info.sigma,360.0))));
834  draw_info->affine.sy=cos(DegreesToRadians(
835  fmod(geometry_info.sigma,360.0)));
836  (void) AnnotateImage(*image,draw_info);
837  InheritException(exception,&(*image)->exception);
838  break;
839  }
840  if (LocaleCompare("antialias",option+1) == 0)
841  {
842  draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
843  MagickFalse;
844  draw_info->text_antialias=(*option == '-') ? MagickTrue :
845  MagickFalse;
846  break;
847  }
848  if (LocaleCompare("auto-gamma",option+1) == 0)
849  {
850  /*
851  Auto Adjust Gamma of image based on its mean
852  */
853  (void) SyncImageSettings(mogrify_info,*image);
854  (void) AutoGammaImageChannel(*image,channel);
855  break;
856  }
857  if (LocaleCompare("auto-level",option+1) == 0)
858  {
859  /*
860  Perfectly Normalize (max/min stretch) the image
861  */
862  (void) SyncImageSettings(mogrify_info,*image);
863  (void) AutoLevelImageChannel(*image,channel);
864  break;
865  }
866  if (LocaleCompare("auto-orient",option+1) == 0)
867  {
868  (void) SyncImageSettings(mogrify_info,*image);
869  mogrify_image=AutoOrientImage(*image,(*image)->orientation,
870  exception);
871  break;
872  }
873  break;
874  }
875  case 'b':
876  {
877  if (LocaleCompare("black-threshold",option+1) == 0)
878  {
879  /*
880  Black threshold image.
881  */
882  (void) SyncImageSettings(mogrify_info,*image);
883  (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
884  exception);
885  InheritException(exception,&(*image)->exception);
886  break;
887  }
888  if (LocaleCompare("blue-shift",option+1) == 0)
889  {
890  /*
891  Blue shift image.
892  */
893  (void) SyncImageSettings(mogrify_info,*image);
894  geometry_info.rho=1.5;
895  if (*option == '-')
896  flags=ParseGeometry(argv[i+1],&geometry_info);
897  mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
898  break;
899  }
900  if (LocaleCompare("blur",option+1) == 0)
901  {
902  /*
903  Gaussian blur image.
904  */
905  (void) SyncImageSettings(mogrify_info,*image);
906  flags=ParseGeometry(argv[i+1],&geometry_info);
907  if ((flags & SigmaValue) == 0)
908  geometry_info.sigma=1.0;
909  mogrify_image=BlurImageChannel(*image,channel,geometry_info.rho,
910  geometry_info.sigma,exception);
911  break;
912  }
913  if (LocaleCompare("border",option+1) == 0)
914  {
915  /*
916  Surround image with a border of solid color.
917  */
918  (void) SyncImageSettings(mogrify_info,*image);
919  flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
920  mogrify_image=BorderImage(*image,&geometry,exception);
921  break;
922  }
923  if (LocaleCompare("bordercolor",option+1) == 0)
924  {
925  if (*option == '+')
926  {
927  (void) QueryColorDatabase(MogrifyBorderColor,
928  &draw_info->border_color,exception);
929  break;
930  }
931  (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
932  exception);
933  break;
934  }
935  if (LocaleCompare("box",option+1) == 0)
936  {
937  (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
938  exception);
939  break;
940  }
941  if (LocaleCompare("brightness-contrast",option+1) == 0)
942  {
943  double
944  brightness,
945  contrast;
946 
947  GeometryInfo
948  geometry_info;
949 
950  MagickStatusType
951  flags;
952 
953  /*
954  Brightness / contrast image.
955  */
956  (void) SyncImageSettings(mogrify_info,*image);
957  flags=ParseGeometry(argv[i+1],&geometry_info);
958  brightness=geometry_info.rho;
959  contrast=0.0;
960  if ((flags & SigmaValue) != 0)
961  contrast=geometry_info.sigma;
962  (void) BrightnessContrastImageChannel(*image,channel,brightness,
963  contrast);
964  InheritException(exception,&(*image)->exception);
965  break;
966  }
967  break;
968  }
969  case 'c':
970  {
971  if (LocaleCompare("canny",option+1) == 0)
972  {
973  /*
974  Detect edges in the image.
975  */
976  (void) SyncImageSettings(mogrify_info,*image);
977  flags=ParseGeometry(argv[i+1],&geometry_info);
978  if ((flags & SigmaValue) == 0)
979  geometry_info.sigma=1.0;
980  if ((flags & XiValue) == 0)
981  geometry_info.xi=0.10;
982  if ((flags & PsiValue) == 0)
983  geometry_info.psi=0.30;
984  if ((flags & PercentValue) != 0)
985  {
986  geometry_info.xi/=100.0;
987  geometry_info.psi/=100.0;
988  }
989  mogrify_image=CannyEdgeImage(*image,geometry_info.rho,
990  geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
991  break;
992  }
993  if (LocaleCompare("cdl",option+1) == 0)
994  {
995  char
996  *color_correction_collection;
997 
998  /*
999  Color correct with a color decision list.
1000  */
1001  (void) SyncImageSettings(mogrify_info,*image);
1002  color_correction_collection=FileToString(argv[i+1],~0UL,exception);
1003  if (color_correction_collection == (char *) NULL)
1004  break;
1005  (void) ColorDecisionListImage(*image,color_correction_collection);
1006  InheritException(exception,&(*image)->exception);
1007  break;
1008  }
1009  if (LocaleCompare("channel",option+1) == 0)
1010  {
1011  if (*option == '+')
1012  channel=DefaultChannels;
1013  else
1014  channel=(ChannelType) ParseChannelOption(argv[i+1]);
1015  break;
1016  }
1017  if (LocaleCompare("charcoal",option+1) == 0)
1018  {
1019  /*
1020  Charcoal image.
1021  */
1022  (void) SyncImageSettings(mogrify_info,*image);
1023  flags=ParseGeometry(argv[i+1],&geometry_info);
1024  if ((flags & SigmaValue) == 0)
1025  geometry_info.sigma=1.0;
1026  mogrify_image=CharcoalImage(*image,geometry_info.rho,
1027  geometry_info.sigma,exception);
1028  break;
1029  }
1030  if (LocaleCompare("chop",option+1) == 0)
1031  {
1032  /*
1033  Chop the image.
1034  */
1035  (void) SyncImageSettings(mogrify_info,*image);
1036  (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1037  mogrify_image=ChopImage(*image,&geometry,exception);
1038  break;
1039  }
1040  if (LocaleCompare("clamp",option+1) == 0)
1041  {
1042  /*
1043  Clamp image.
1044  */
1045  (void) SyncImageSettings(mogrify_info,*image);
1046  (void) ClampImageChannel(*image,channel);
1047  InheritException(exception,&(*image)->exception);
1048  break;
1049  }
1050  if (LocaleCompare("clip",option+1) == 0)
1051  {
1052  (void) SyncImageSettings(mogrify_info,*image);
1053  if (*option == '+')
1054  {
1055  (void) SetImageClipMask(*image,(Image *) NULL);
1056  InheritException(exception,&(*image)->exception);
1057  break;
1058  }
1059  (void) ClipImage(*image);
1060  InheritException(exception,&(*image)->exception);
1061  break;
1062  }
1063  if (LocaleCompare("clip-mask",option+1) == 0)
1064  {
1065  CacheView
1066  *mask_view;
1067 
1068  Image
1069  *mask_image;
1070 
1071  PixelPacket
1072  *magick_restrict q;
1073 
1074  ssize_t
1075  x;
1076 
1077  ssize_t
1078  y;
1079 
1080  (void) SyncImageSettings(mogrify_info,*image);
1081  if (*option == '+')
1082  {
1083  /*
1084  Remove a mask.
1085  */
1086  (void) SetImageMask(*image,(Image *) NULL);
1087  InheritException(exception,&(*image)->exception);
1088  break;
1089  }
1090  /*
1091  Set the image mask.
1092  FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1093  */
1094  mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1095  if (mask_image == (Image *) NULL)
1096  break;
1097  if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1098  return(MagickFalse);
1099  mask_view=AcquireAuthenticCacheView(mask_image,exception);
1100  for (y=0; y < (ssize_t) mask_image->rows; y++)
1101  {
1102  q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1103  exception);
1104  if (q == (PixelPacket *) NULL)
1105  break;
1106  for (x=0; x < (ssize_t) mask_image->columns; x++)
1107  {
1108  if (mask_image->matte == MagickFalse)
1109  SetPixelOpacity(q,ClampToQuantum(GetPixelIntensity(mask_image,
1110  q)));
1111  SetPixelRed(q,GetPixelOpacity(q));
1112  SetPixelGreen(q,GetPixelOpacity(q));
1113  SetPixelBlue(q,GetPixelOpacity(q));
1114  q++;
1115  }
1116  if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1117  break;
1118  }
1119  mask_view=DestroyCacheView(mask_view);
1120  mask_image->matte=MagickTrue;
1121  (void) SetImageClipMask(*image,mask_image);
1122  mask_image=DestroyImage(mask_image);
1123  InheritException(exception,&(*image)->exception);
1124  break;
1125  }
1126  if (LocaleCompare("clip-path",option+1) == 0)
1127  {
1128  (void) SyncImageSettings(mogrify_info,*image);
1129  (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1130  MagickFalse);
1131  InheritException(exception,&(*image)->exception);
1132  break;
1133  }
1134  if (LocaleCompare("colorize",option+1) == 0)
1135  {
1136  /*
1137  Colorize the image.
1138  */
1139  (void) SyncImageSettings(mogrify_info,*image);
1140  mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1141  exception);
1142  break;
1143  }
1144  if (LocaleCompare("color-matrix",option+1) == 0)
1145  {
1146  KernelInfo
1147  *kernel;
1148 
1149  (void) SyncImageSettings(mogrify_info,*image);
1150  kernel=AcquireKernelInfo(argv[i+1]);
1151  if (kernel == (KernelInfo *) NULL)
1152  break;
1153  mogrify_image=ColorMatrixImage(*image,kernel,exception);
1154  kernel=DestroyKernelInfo(kernel);
1155  break;
1156  }
1157  if (LocaleCompare("colors",option+1) == 0)
1158  {
1159  /*
1160  Reduce the number of colors in the image.
1161  */
1162  (void) SyncImageSettings(mogrify_info,*image);
1163  quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1164  if (quantize_info->number_colors == 0)
1165  break;
1166  if (((*image)->storage_class == DirectClass) ||
1167  (*image)->colors > quantize_info->number_colors)
1168  (void) QuantizeImage(quantize_info,*image);
1169  else
1170  (void) CompressImageColormap(*image);
1171  InheritException(exception,&(*image)->exception);
1172  break;
1173  }
1174  if (LocaleCompare("colorspace",option+1) == 0)
1175  {
1176  ColorspaceType
1177  colorspace;
1178 
1179  (void) SyncImageSettings(mogrify_info,*image);
1180  if (*option == '+')
1181  {
1182  (void) TransformImageColorspace(*image,sRGBColorspace);
1183  InheritException(exception,&(*image)->exception);
1184  break;
1185  }
1186  colorspace=(ColorspaceType) ParseCommandOption(
1187  MagickColorspaceOptions,MagickFalse,argv[i+1]);
1188  (void) TransformImageColorspace(*image,colorspace);
1189  InheritException(exception,&(*image)->exception);
1190  break;
1191  }
1192  if (LocaleCompare("connected-components",option+1) == 0)
1193  {
1194  (void) SyncImageSettings(mogrify_info,*image);
1195  mogrify_image=ConnectedComponentsImage(*image,
1196  (size_t) StringToInteger(argv[i+1]),exception);
1197  break;
1198  }
1199  if (LocaleCompare("contrast",option+1) == 0)
1200  {
1201  (void) SyncImageSettings(mogrify_info,*image);
1202  (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1203  MagickFalse);
1204  InheritException(exception,&(*image)->exception);
1205  break;
1206  }
1207  if (LocaleCompare("contrast-stretch",option+1) == 0)
1208  {
1209  double
1210  black_point,
1211  white_point;
1212 
1213  MagickStatusType
1214  flags;
1215 
1216  /*
1217  Contrast stretch image.
1218  */
1219  (void) SyncImageSettings(mogrify_info,*image);
1220  flags=ParseGeometry(argv[i+1],&geometry_info);
1221  black_point=geometry_info.rho;
1222  white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1223  black_point;
1224  if ((flags & PercentValue) != 0)
1225  {
1226  black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1227  white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1228  }
1229  white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1230  white_point;
1231  (void) ContrastStretchImageChannel(*image,channel,black_point,
1232  white_point);
1233  InheritException(exception,&(*image)->exception);
1234  break;
1235  }
1236  if (LocaleCompare("convolve",option+1) == 0)
1237  {
1238  double
1239  gamma;
1240 
1241  KernelInfo
1242  *kernel_info;
1243 
1244  ssize_t
1245  j;
1246 
1247  size_t
1248  extent;
1249 
1250  (void) SyncImageSettings(mogrify_info,*image);
1251  kernel_info=AcquireKernelInfo(argv[i+1]);
1252  if (kernel_info == (KernelInfo *) NULL)
1253  break;
1254  extent=kernel_info->width*kernel_info->height;
1255  gamma=0.0;
1256  for (j=0; j < (ssize_t) extent; j++)
1257  gamma+=kernel_info->values[j];
1258  gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1259  for (j=0; j < (ssize_t) extent; j++)
1260  kernel_info->values[j]*=gamma;
1261  mogrify_image=MorphologyImage(*image,CorrelateMorphology,1,
1262  kernel_info,exception);
1263  kernel_info=DestroyKernelInfo(kernel_info);
1264  break;
1265  }
1266  if (LocaleCompare("crop",option+1) == 0)
1267  {
1268  /*
1269  Crop a image to a smaller size
1270  */
1271  (void) SyncImageSettings(mogrify_info,*image);
1272 #if 0
1273  flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1274  if (((geometry.width != 0) || (geometry.height != 0)) &&
1275  ((flags & XValue) == 0) && ((flags & YValue) == 0))
1276  break;
1277 #endif
1278 #if 0
1279  mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1280  mogrify_image->next = mogrify_image->previous = (Image *) NULL;
1281  (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1282  InheritException(exception,&mogrify_image->exception);
1283 #else
1284  mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1285 #endif
1286  break;
1287  }
1288  if (LocaleCompare("cycle",option+1) == 0)
1289  {
1290  /*
1291  Cycle an image colormap.
1292  */
1293  (void) SyncImageSettings(mogrify_info,*image);
1294  (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1295  InheritException(exception,&(*image)->exception);
1296  break;
1297  }
1298  break;
1299  }
1300  case 'd':
1301  {
1302  if (LocaleCompare("decipher",option+1) == 0)
1303  {
1304  StringInfo
1305  *passkey;
1306 
1307  /*
1308  Decipher pixels.
1309  */
1310  (void) SyncImageSettings(mogrify_info,*image);
1311  passkey=FileToStringInfo(argv[i+1],~0UL,exception);
1312  if (passkey != (StringInfo *) NULL)
1313  {
1314  (void) PasskeyDecipherImage(*image,passkey,exception);
1315  passkey=DestroyStringInfo(passkey);
1316  }
1317  break;
1318  }
1319  if (LocaleCompare("density",option+1) == 0)
1320  {
1321  /*
1322  Set image density.
1323  */
1324  (void) CloneString(&draw_info->density,argv[i+1]);
1325  break;
1326  }
1327  if (LocaleCompare("depth",option+1) == 0)
1328  {
1329  (void) SyncImageSettings(mogrify_info,*image);
1330  if (*option == '+')
1331  {
1332  (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1333  break;
1334  }
1335  (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1336  break;
1337  }
1338  if (LocaleCompare("deskew",option+1) == 0)
1339  {
1340  double
1341  threshold;
1342 
1343  /*
1344  Straighten the image.
1345  */
1346  (void) SyncImageSettings(mogrify_info,*image);
1347  if (*option == '+')
1348  threshold=40.0*QuantumRange/100.0;
1349  else
1350  threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1351  1.0);
1352  mogrify_image=DeskewImage(*image,threshold,exception);
1353  break;
1354  }
1355  if (LocaleCompare("despeckle",option+1) == 0)
1356  {
1357  /*
1358  Reduce the speckles within an image.
1359  */
1360  (void) SyncImageSettings(mogrify_info,*image);
1361  mogrify_image=DespeckleImage(*image,exception);
1362  break;
1363  }
1364  if (LocaleCompare("display",option+1) == 0)
1365  {
1366  (void) CloneString(&draw_info->server_name,argv[i+1]);
1367  break;
1368  }
1369  if (LocaleCompare("distort",option+1) == 0)
1370  {
1371  char
1372  *args,
1373  token[MaxTextExtent];
1374 
1375  const char
1376  *p;
1377 
1378  DistortImageMethod
1379  method;
1380 
1381  double
1382  *arguments;
1383 
1384  ssize_t
1385  x;
1386 
1387  size_t
1388  number_arguments;
1389 
1390  /*
1391  Distort image.
1392  */
1393  (void) SyncImageSettings(mogrify_info,*image);
1394  method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1395  MagickFalse,argv[i+1]);
1396  if (method == ResizeDistortion)
1397  {
1398  double
1399  resize_args[2];
1400 
1401  /*
1402  Resize distortion.
1403  */
1404  (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1405  exception);
1406  resize_args[0]=(double) geometry.width;
1407  resize_args[1]=(double) geometry.height;
1408  mogrify_image=DistortImage(*image,method,(size_t) 2,
1409  resize_args,MagickTrue,exception);
1410  break;
1411  }
1412  args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1413  InheritException(exception,&(*image)->exception);
1414  if (args == (char *) NULL)
1415  break;
1416  p=(char *) args;
1417  for (x=0; *p != '\0'; x++)
1418  {
1419  (void) GetNextToken(p,&p,MaxTextExtent,token);
1420  if (*token == ',')
1421  (void) GetNextToken(p,&p,MaxTextExtent,token);
1422  }
1423  number_arguments=(size_t) x;
1424  arguments=(double *) AcquireQuantumMemory(number_arguments,
1425  sizeof(*arguments));
1426  if (arguments == (double *) NULL)
1427  ThrowWandFatalException(ResourceLimitFatalError,
1428  "MemoryAllocationFailed",(*image)->filename);
1429  (void) memset(arguments,0,number_arguments*sizeof(*arguments));
1430  p=(char *) args;
1431  for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1432  {
1433  (void) GetNextToken(p,&p,MaxTextExtent,token);
1434  if (*token == ',')
1435  (void) GetNextToken(p,&p,MaxTextExtent,token);
1436  arguments[x]=StringToDouble(token,(char **) NULL);
1437  }
1438  args=DestroyString(args);
1439  mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1440  (*option == '+') ? MagickTrue : MagickFalse,exception);
1441  arguments=(double *) RelinquishMagickMemory(arguments);
1442  break;
1443  }
1444  if (LocaleCompare("dither",option+1) == 0)
1445  {
1446  if (*option == '+')
1447  {
1448  quantize_info->dither=MagickFalse;
1449  break;
1450  }
1451  quantize_info->dither=MagickTrue;
1452  quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1453  MagickDitherOptions,MagickFalse,argv[i+1]);
1454  if (quantize_info->dither_method == NoDitherMethod)
1455  quantize_info->dither=MagickFalse;
1456  break;
1457  }
1458  if (LocaleCompare("draw",option+1) == 0)
1459  {
1460  /*
1461  Draw image.
1462  */
1463  (void) SyncImageSettings(mogrify_info,*image);
1464  (void) CloneString(&draw_info->primitive,argv[i+1]);
1465  (void) DrawImage(*image,draw_info);
1466  InheritException(exception,&(*image)->exception);
1467  break;
1468  }
1469  break;
1470  }
1471  case 'e':
1472  {
1473  if (LocaleCompare("edge",option+1) == 0)
1474  {
1475  /*
1476  Enhance edges in the image.
1477  */
1478  (void) SyncImageSettings(mogrify_info,*image);
1479  flags=ParseGeometry(argv[i+1],&geometry_info);
1480  if ((flags & SigmaValue) == 0)
1481  geometry_info.sigma=1.0;
1482  mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1483  break;
1484  }
1485  if (LocaleCompare("emboss",option+1) == 0)
1486  {
1487  /*
1488  Gaussian embossen image.
1489  */
1490  (void) SyncImageSettings(mogrify_info,*image);
1491  flags=ParseGeometry(argv[i+1],&geometry_info);
1492  if ((flags & SigmaValue) == 0)
1493  geometry_info.sigma=1.0;
1494  mogrify_image=EmbossImage(*image,geometry_info.rho,
1495  geometry_info.sigma,exception);
1496  break;
1497  }
1498  if (LocaleCompare("encipher",option+1) == 0)
1499  {
1500  StringInfo
1501  *passkey;
1502 
1503  /*
1504  Encipher pixels.
1505  */
1506  (void) SyncImageSettings(mogrify_info,*image);
1507  passkey=FileToStringInfo(argv[i+1],~0UL,exception);
1508  if (passkey != (StringInfo *) NULL)
1509  {
1510  (void) PasskeyEncipherImage(*image,passkey,exception);
1511  passkey=DestroyStringInfo(passkey);
1512  }
1513  break;
1514  }
1515  if (LocaleCompare("encoding",option+1) == 0)
1516  {
1517  (void) CloneString(&draw_info->encoding,argv[i+1]);
1518  break;
1519  }
1520  if (LocaleCompare("enhance",option+1) == 0)
1521  {
1522  /*
1523  Enhance image.
1524  */
1525  (void) SyncImageSettings(mogrify_info,*image);
1526  mogrify_image=EnhanceImage(*image,exception);
1527  break;
1528  }
1529  if (LocaleCompare("equalize",option+1) == 0)
1530  {
1531  /*
1532  Equalize image.
1533  */
1534  (void) SyncImageSettings(mogrify_info,*image);
1535  (void) EqualizeImageChannel(*image,channel);
1536  InheritException(exception,&(*image)->exception);
1537  break;
1538  }
1539  if (LocaleCompare("evaluate",option+1) == 0)
1540  {
1541  double
1542  constant;
1543 
1544  MagickEvaluateOperator
1545  op;
1546 
1547  (void) SyncImageSettings(mogrify_info,*image);
1548  op=(MagickEvaluateOperator) ParseCommandOption(
1549  MagickEvaluateOptions,MagickFalse,argv[i+1]);
1550  constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1551  1.0);
1552  (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1553  break;
1554  }
1555  if (LocaleCompare("extent",option+1) == 0)
1556  {
1557  /*
1558  Set the image extent.
1559  */
1560  (void) SyncImageSettings(mogrify_info,*image);
1561  flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1562  if (geometry.width == 0)
1563  geometry.width=(*image)->columns;
1564  if (geometry.height == 0)
1565  geometry.height=(*image)->rows;
1566  mogrify_image=ExtentImage(*image,&geometry,exception);
1567  break;
1568  }
1569  break;
1570  }
1571  case 'f':
1572  {
1573  if (LocaleCompare("family",option+1) == 0)
1574  {
1575  if (*option == '+')
1576  {
1577  if (draw_info->family != (char *) NULL)
1578  draw_info->family=DestroyString(draw_info->family);
1579  break;
1580  }
1581  (void) SetImageOption(image_info,option+1,argv[i+1]);
1582  (void) CloneString(&draw_info->family,argv[i+1]);
1583  break;
1584  }
1585  if (LocaleCompare("features",option+1) == 0)
1586  {
1587  if (*option == '+')
1588  {
1589  (void) DeleteImageArtifact(*image,"identify:features");
1590  break;
1591  }
1592  (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1593  (void) SetImageArtifact(*image,"verbose","true");
1594  break;
1595  }
1596  if (LocaleCompare("fill",option+1) == 0)
1597  {
1598  ExceptionInfo
1599  *sans;
1600 
1601  GetMagickPixelPacket(*image,&fill);
1602  if (*option == '+')
1603  {
1604  (void) QueryMagickColor("none",&fill,exception);
1605  (void) QueryColorDatabase("none",&draw_info->fill,exception);
1606  if (draw_info->fill_pattern != (Image *) NULL)
1607  draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1608  break;
1609  }
1610  sans=AcquireExceptionInfo();
1611  (void) QueryMagickColor(argv[i+1],&fill,sans);
1612  status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1613  sans=DestroyExceptionInfo(sans);
1614  if (status == MagickFalse)
1615  draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1616  exception);
1617  break;
1618  }
1619  if (LocaleCompare("flip",option+1) == 0)
1620  {
1621  /*
1622  Flip image scanlines.
1623  */
1624  (void) SyncImageSettings(mogrify_info,*image);
1625  mogrify_image=FlipImage(*image,exception);
1626  break;
1627  }
1628  if (LocaleCompare("floodfill",option+1) == 0)
1629  {
1630  MagickPixelPacket
1631  target;
1632 
1633  /*
1634  Floodfill image.
1635  */
1636  (void) SyncImageSettings(mogrify_info,*image);
1637  (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1638  (void) QueryMagickColor(argv[i+2],&target,exception);
1639  (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1640  geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1641  InheritException(exception,&(*image)->exception);
1642  break;
1643  }
1644  if (LocaleCompare("flop",option+1) == 0)
1645  {
1646  /*
1647  Flop image scanlines.
1648  */
1649  (void) SyncImageSettings(mogrify_info,*image);
1650  mogrify_image=FlopImage(*image,exception);
1651  break;
1652  }
1653  if (LocaleCompare("font",option+1) == 0)
1654  {
1655  if (*option == '+')
1656  {
1657  if (draw_info->font != (char *) NULL)
1658  draw_info->font=DestroyString(draw_info->font);
1659  break;
1660  }
1661  (void) CloneString(&draw_info->font,argv[i+1]);
1662  break;
1663  }
1664  if (LocaleCompare("format",option+1) == 0)
1665  {
1666  format=argv[i+1];
1667  break;
1668  }
1669  if (LocaleCompare("frame",option+1) == 0)
1670  {
1671  FrameInfo
1672  frame_info;
1673 
1674  /*
1675  Surround image with an ornamental border.
1676  */
1677  (void) SyncImageSettings(mogrify_info,*image);
1678  flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1679  frame_info.width=geometry.width;
1680  frame_info.height=geometry.height;
1681  frame_info.outer_bevel=geometry.x;
1682  frame_info.inner_bevel=geometry.y;
1683  frame_info.x=(ssize_t) frame_info.width;
1684  frame_info.y=(ssize_t) frame_info.height;
1685  frame_info.width=(*image)->columns+2*frame_info.width;
1686  frame_info.height=(*image)->rows+2*frame_info.height;
1687  mogrify_image=FrameImage(*image,&frame_info,exception);
1688  break;
1689  }
1690  if (LocaleCompare("function",option+1) == 0)
1691  {
1692  char
1693  *arguments,
1694  token[MaxTextExtent];
1695 
1696  const char
1697  *p;
1698 
1699  double
1700  *parameters;
1701 
1702  MagickFunction
1703  function;
1704 
1705  ssize_t
1706  x;
1707 
1708  size_t
1709  number_parameters;
1710 
1711  /*
1712  Function Modify Image Values
1713  */
1714  (void) SyncImageSettings(mogrify_info,*image);
1715  function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1716  MagickFalse,argv[i+1]);
1717  arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1718  InheritException(exception,&(*image)->exception);
1719  if (arguments == (char *) NULL)
1720  break;
1721  p=(char *) arguments;
1722  for (x=0; *p != '\0'; x++)
1723  {
1724  (void) GetNextToken(p,&p,MaxTextExtent,token);
1725  if (*token == ',')
1726  (void) GetNextToken(p,&p,MaxTextExtent,token);
1727  }
1728  number_parameters=(size_t) x;
1729  parameters=(double *) AcquireQuantumMemory(number_parameters,
1730  sizeof(*parameters));
1731  if (parameters == (double *) NULL)
1732  ThrowWandFatalException(ResourceLimitFatalError,
1733  "MemoryAllocationFailed",(*image)->filename);
1734  (void) memset(parameters,0,number_parameters*
1735  sizeof(*parameters));
1736  p=(char *) arguments;
1737  for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1738  {
1739  (void) GetNextToken(p,&p,MaxTextExtent,token);
1740  if (*token == ',')
1741  (void) GetNextToken(p,&p,MaxTextExtent,token);
1742  parameters[x]=StringToDouble(token,(char **) NULL);
1743  }
1744  arguments=DestroyString(arguments);
1745  (void) FunctionImageChannel(*image,channel,function,
1746  number_parameters,parameters,exception);
1747  parameters=(double *) RelinquishMagickMemory(parameters);
1748  break;
1749  }
1750  break;
1751  }
1752  case 'g':
1753  {
1754  if (LocaleCompare("gamma",option+1) == 0)
1755  {
1756  /*
1757  Gamma image.
1758  */
1759  (void) SyncImageSettings(mogrify_info,*image);
1760  if (*option == '+')
1761  (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
1762  else
1763  {
1764  if (strchr(argv[i+1],',') != (char *) NULL)
1765  (void) GammaImage(*image,argv[i+1]);
1766  else
1767  (void) GammaImageChannel(*image,channel,
1768  StringToDouble(argv[i+1],(char **) NULL));
1769  InheritException(exception,&(*image)->exception);
1770  }
1771  break;
1772  }
1773  if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1774  (LocaleCompare("gaussian",option+1) == 0))
1775  {
1776  /*
1777  Gaussian blur image.
1778  */
1779  (void) SyncImageSettings(mogrify_info,*image);
1780  flags=ParseGeometry(argv[i+1],&geometry_info);
1781  if ((flags & SigmaValue) == 0)
1782  geometry_info.sigma=1.0;
1783  mogrify_image=GaussianBlurImageChannel(*image,channel,
1784  geometry_info.rho,geometry_info.sigma,exception);
1785  break;
1786  }
1787  if (LocaleCompare("geometry",option+1) == 0)
1788  {
1789  /*
1790  Record Image offset, Resize last image.
1791  */
1792  (void) SyncImageSettings(mogrify_info,*image);
1793  if (*option == '+')
1794  {
1795  if ((*image)->geometry != (char *) NULL)
1796  (*image)->geometry=DestroyString((*image)->geometry);
1797  break;
1798  }
1799  flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1800  if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1801  (void) CloneString(&(*image)->geometry,argv[i+1]);
1802  else
1803  mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1804  (*image)->filter,(*image)->blur,exception);
1805  break;
1806  }
1807  if (LocaleCompare("gravity",option+1) == 0)
1808  {
1809  if (*option == '+')
1810  {
1811  draw_info->gravity=UndefinedGravity;
1812  break;
1813  }
1814  draw_info->gravity=(GravityType) ParseCommandOption(
1815  MagickGravityOptions,MagickFalse,argv[i+1]);
1816  break;
1817  }
1818  if (LocaleCompare("grayscale",option+1) == 0)
1819  {
1820  PixelIntensityMethod
1821  method;
1822 
1823  (void) SyncImagesSettings(mogrify_info,*image);
1824  method=(PixelIntensityMethod) ParseCommandOption(
1825  MagickPixelIntensityOptions,MagickFalse,argv[i+1]);
1826  (void) GrayscaleImage(*image,method);
1827  InheritException(exception,&(*image)->exception);
1828  break;
1829  }
1830  break;
1831  }
1832  case 'h':
1833  {
1834  if (LocaleCompare("highlight-color",option+1) == 0)
1835  {
1836  (void) SetImageArtifact(*image,"compare:highlight-color",argv[i+1]);
1837  break;
1838  }
1839  if (LocaleCompare("hough-lines",option+1) == 0)
1840  {
1841  /*
1842  Identify lines in the image.
1843  */
1844  (void) SyncImageSettings(mogrify_info,*image);
1845  flags=ParseGeometry(argv[i+1],&geometry_info);
1846  if ((flags & SigmaValue) == 0)
1847  geometry_info.sigma=geometry_info.rho;
1848  if ((flags & XiValue) == 0)
1849  geometry_info.xi=40;
1850  mogrify_image=HoughLineImage(*image,(size_t) geometry_info.rho,
1851  (size_t) geometry_info.sigma,(size_t) geometry_info.xi,exception);
1852  break;
1853  }
1854  break;
1855  }
1856  case 'i':
1857  {
1858  if (LocaleCompare("identify",option+1) == 0)
1859  {
1860  char
1861  *text;
1862 
1863  (void) SyncImageSettings(mogrify_info,*image);
1864  if (format == (char *) NULL)
1865  {
1866  (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1867  InheritException(exception,&(*image)->exception);
1868  break;
1869  }
1870  text=InterpretImageProperties(mogrify_info,*image,format);
1871  InheritException(exception,&(*image)->exception);
1872  if (text == (char *) NULL)
1873  break;
1874  (void) fputs(text,stdout);
1875  text=DestroyString(text);
1876  break;
1877  }
1878  if (LocaleCompare("implode",option+1) == 0)
1879  {
1880  /*
1881  Implode image.
1882  */
1883  (void) SyncImageSettings(mogrify_info,*image);
1884  (void) ParseGeometry(argv[i+1],&geometry_info);
1885  mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1886  break;
1887  }
1888  if (LocaleCompare("interline-spacing",option+1) == 0)
1889  {
1890  if (*option == '+')
1891  (void) ParseGeometry("0",&geometry_info);
1892  else
1893  (void) ParseGeometry(argv[i+1],&geometry_info);
1894  draw_info->interline_spacing=geometry_info.rho;
1895  break;
1896  }
1897  if (LocaleCompare("interword-spacing",option+1) == 0)
1898  {
1899  if (*option == '+')
1900  (void) ParseGeometry("0",&geometry_info);
1901  else
1902  (void) ParseGeometry(argv[i+1],&geometry_info);
1903  draw_info->interword_spacing=geometry_info.rho;
1904  break;
1905  }
1906  if (LocaleCompare("interpolative-resize",option+1) == 0)
1907  {
1908  /*
1909  Resize image using 'point sampled' interpolation
1910  */
1911  (void) SyncImageSettings(mogrify_info,*image);
1912  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1913  mogrify_image=InterpolativeResizeImage(*image,geometry.width,
1914  geometry.height,(*image)->interpolate,exception);
1915  break;
1916  }
1917  break;
1918  }
1919  case 'k':
1920  {
1921  if (LocaleCompare("kerning",option+1) == 0)
1922  {
1923  if (*option == '+')
1924  (void) ParseGeometry("0",&geometry_info);
1925  else
1926  (void) ParseGeometry(argv[i+1],&geometry_info);
1927  draw_info->kerning=geometry_info.rho;
1928  break;
1929  }
1930  if (LocaleCompare("kuwahara",option+1) == 0)
1931  {
1932  /*
1933  Edge preserving blur.
1934  */
1935  (void) SyncImageSettings(mogrify_info,*image);
1936  flags=ParseGeometry(argv[i+1],&geometry_info);
1937  if ((flags & SigmaValue) == 0)
1938  geometry_info.sigma=geometry_info.rho-0.5;
1939  mogrify_image=KuwaharaImageChannel(*image,channel,geometry_info.rho,
1940  geometry_info.sigma,exception);
1941  break;
1942  }
1943  break;
1944  }
1945  case 'l':
1946  {
1947  if (LocaleCompare("lat",option+1) == 0)
1948  {
1949  /*
1950  Local adaptive threshold image.
1951  */
1952  (void) SyncImageSettings(mogrify_info,*image);
1953  flags=ParseGeometry(argv[i+1],&geometry_info);
1954  if ((flags & SigmaValue) == 0)
1955  geometry_info.sigma=1.0;
1956  if ((flags & PercentValue) != 0)
1957  geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1958  mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1959  geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1960  geometry_info.xi,exception);
1961  break;
1962  }
1963  if (LocaleCompare("level",option+1) == 0)
1964  {
1965  MagickRealType
1966  black_point,
1967  gamma,
1968  white_point;
1969 
1970  MagickStatusType
1971  flags;
1972 
1973  /*
1974  Parse levels.
1975  */
1976  (void) SyncImageSettings(mogrify_info,*image);
1977  flags=ParseGeometry(argv[i+1],&geometry_info);
1978  black_point=geometry_info.rho;
1979  white_point=(MagickRealType) QuantumRange;
1980  if ((flags & SigmaValue) != 0)
1981  white_point=geometry_info.sigma;
1982  gamma=1.0;
1983  if ((flags & XiValue) != 0)
1984  gamma=geometry_info.xi;
1985  if ((flags & PercentValue) != 0)
1986  {
1987  black_point*=(MagickRealType) (QuantumRange/100.0);
1988  white_point*=(MagickRealType) (QuantumRange/100.0);
1989  }
1990  if ((flags & SigmaValue) == 0)
1991  white_point=(MagickRealType) QuantumRange-black_point;
1992  if ((*option == '+') || ((flags & AspectValue) != 0))
1993  (void) LevelizeImageChannel(*image,channel,black_point,
1994  white_point,gamma);
1995  else
1996  (void) LevelImageChannel(*image,channel,black_point,white_point,
1997  gamma);
1998  InheritException(exception,&(*image)->exception);
1999  break;
2000  }
2001  if (LocaleCompare("level-colors",option+1) == 0)
2002  {
2003  char
2004  token[MaxTextExtent];
2005 
2006  const char
2007  *p;
2008 
2009  MagickPixelPacket
2010  black_point,
2011  white_point;
2012 
2013  p=(const char *) argv[i+1];
2014  (void) GetNextToken(p,&p,MaxTextExtent,token); /* get black point color */
2015  if ((isalpha((int) ((unsigned char) *token)) != 0) || ((*token == '#') != 0))
2016  (void) QueryMagickColor(token,&black_point,exception);
2017  else
2018  (void) QueryMagickColor("#000000",&black_point,exception);
2019  if (isalpha((int) ((unsigned char) *token)) || (*token == '#'))
2020  (void) GetNextToken(p,&p,MaxTextExtent,token);
2021  if (*token == '\0')
2022  white_point=black_point; /* set everything to that color */
2023  else
2024  {
2025  if ((isalpha((int) ((unsigned char) *token)) == 0) && ((*token == '#') == 0))
2026  (void) GetNextToken(p,&p,MaxTextExtent,token); /* Get white point color. */
2027  if ((isalpha((int) ((unsigned char) *token)) != 0) || ((*token == '#') != 0))
2028  (void) QueryMagickColor(token,&white_point,exception);
2029  else
2030  (void) QueryMagickColor("#ffffff",&white_point,exception);
2031  }
2032  (void) LevelColorsImageChannel(*image,channel,&black_point,
2033  &white_point,*option == '+' ? MagickTrue : MagickFalse);
2034  break;
2035  }
2036  if (LocaleCompare("linear-stretch",option+1) == 0)
2037  {
2038  double
2039  black_point,
2040  white_point;
2041 
2042  MagickStatusType
2043  flags;
2044 
2045  (void) SyncImageSettings(mogrify_info,*image);
2046  flags=ParseGeometry(argv[i+1],&geometry_info);
2047  black_point=geometry_info.rho;
2048  white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2049  if ((flags & SigmaValue) != 0)
2050  white_point=geometry_info.sigma;
2051  if ((flags & PercentValue) != 0)
2052  {
2053  black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2054  white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2055  }
2056  if ((flags & SigmaValue) == 0)
2057  white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2058  black_point;
2059  (void) LinearStretchImage(*image,black_point,white_point);
2060  InheritException(exception,&(*image)->exception);
2061  break;
2062  }
2063  if (LocaleCompare("linewidth",option+1) == 0)
2064  {
2065  draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
2066  break;
2067  }
2068  if (LocaleCompare("liquid-rescale",option+1) == 0)
2069  {
2070  /*
2071  Liquid rescale image.
2072  */
2073  (void) SyncImageSettings(mogrify_info,*image);
2074  flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2075  if ((flags & XValue) == 0)
2076  geometry.x=1;
2077  if ((flags & YValue) == 0)
2078  geometry.y=0;
2079  mogrify_image=LiquidRescaleImage(*image,geometry.width,
2080  geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2081  break;
2082  }
2083  if (LocaleCompare("local-contrast",option+1) == 0)
2084  {
2085  MagickStatusType
2086  flags;
2087 
2088  (void) SyncImageSettings(mogrify_info,*image);
2089  flags=ParseGeometry(argv[i+1],&geometry_info);
2090  if ((flags & RhoValue) == 0)
2091  geometry_info.rho=10;
2092  if ((flags & SigmaValue) == 0)
2093  geometry_info.sigma=12.5;
2094  mogrify_image=LocalContrastImage(*image,geometry_info.rho,
2095  geometry_info.sigma,exception);
2096  break;
2097  }
2098  if (LocaleCompare("lowlight-color",option+1) == 0)
2099  {
2100  (void) SetImageArtifact(*image,"compare:lowlight-color",argv[i+1]);
2101  break;
2102  }
2103  break;
2104  }
2105  case 'm':
2106  {
2107  if (LocaleCompare("magnify",option+1) == 0)
2108  {
2109  /*
2110  Double image size.
2111  */
2112  (void) SyncImageSettings(mogrify_info,*image);
2113  mogrify_image=MagnifyImage(*image,exception);
2114  break;
2115  }
2116  if (LocaleCompare("map",option+1) == 0)
2117  {
2118  Image
2119  *remap_image;
2120 
2121  /*
2122  Transform image colors to match this set of colors.
2123  */
2124  (void) SyncImageSettings(mogrify_info,*image);
2125  if (*option == '+')
2126  break;
2127  remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2128  if (remap_image == (Image *) NULL)
2129  break;
2130  (void) RemapImage(quantize_info,*image,remap_image);
2131  InheritException(exception,&(*image)->exception);
2132  remap_image=DestroyImage(remap_image);
2133  break;
2134  }
2135  if (LocaleCompare("mask",option+1) == 0)
2136  {
2137  Image
2138  *mask;
2139 
2140  (void) SyncImageSettings(mogrify_info,*image);
2141  if (*option == '+')
2142  {
2143  /*
2144  Remove a mask.
2145  */
2146  (void) SetImageMask(*image,(Image *) NULL);
2147  InheritException(exception,&(*image)->exception);
2148  break;
2149  }
2150  /*
2151  Set the image mask.
2152  */
2153  mask=GetImageCache(mogrify_info,argv[i+1],exception);
2154  if (mask == (Image *) NULL)
2155  break;
2156  (void) SetImageMask(*image,mask);
2157  mask=DestroyImage(mask);
2158  InheritException(exception,&(*image)->exception);
2159  break;
2160  }
2161  if (LocaleCompare("matte",option+1) == 0)
2162  {
2163  (void) SetImageAlphaChannel(*image,(*option == '-') ?
2164  SetAlphaChannel : DeactivateAlphaChannel );
2165  InheritException(exception,&(*image)->exception);
2166  break;
2167  }
2168  if (LocaleCompare("mean-shift",option+1) == 0)
2169  {
2170  /*
2171  Delineate arbitrarily shaped clusters in the image.
2172  */
2173  (void) SyncImageSettings(mogrify_info,*image);
2174  flags=ParseGeometry(argv[i+1],&geometry_info);
2175  if ((flags & SigmaValue) == 0)
2176  geometry_info.sigma=geometry_info.rho;
2177  if ((flags & XiValue) == 0)
2178  geometry_info.xi=0.10*QuantumRange;
2179  if ((flags & PercentValue) != 0)
2180  geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2181  mogrify_image=MeanShiftImage(*image,(size_t) geometry_info.rho,
2182  (size_t) geometry_info.sigma,geometry_info.xi,exception);
2183  break;
2184  }
2185  if (LocaleCompare("median",option+1) == 0)
2186  {
2187  /*
2188  Median filter image.
2189  */
2190  (void) SyncImageSettings(mogrify_info,*image);
2191  (void) ParseGeometry(argv[i+1],&geometry_info);
2192  mogrify_image=StatisticImageChannel(*image,channel,MedianStatistic,
2193  (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2194  break;
2195  }
2196  if (LocaleCompare("mode",option+1) == 0)
2197  {
2198  /*
2199  Mode image.
2200  */
2201  (void) SyncImageSettings(mogrify_info,*image);
2202  (void) ParseGeometry(argv[i+1],&geometry_info);
2203  mogrify_image=StatisticImageChannel(*image,channel,ModeStatistic,
2204  (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2205  break;
2206  }
2207  if (LocaleCompare("modulate",option+1) == 0)
2208  {
2209  (void) SyncImageSettings(mogrify_info,*image);
2210  (void) ModulateImage(*image,argv[i+1]);
2211  InheritException(exception,&(*image)->exception);
2212  break;
2213  }
2214  if (LocaleCompare("moments",option+1) == 0)
2215  {
2216  if (*option == '+')
2217  {
2218  (void) DeleteImageArtifact(*image,"identify:moments");
2219  break;
2220  }
2221  (void) SetImageArtifact(*image,"identify:moments",argv[i+1]);
2222  (void) SetImageArtifact(*image,"verbose","true");
2223  break;
2224  }
2225  if (LocaleCompare("monitor",option+1) == 0)
2226  {
2227  if (*option == '+')
2228  {
2229  (void) SetImageProgressMonitor(*image,
2230  (MagickProgressMonitor) NULL,(void *) NULL);
2231  break;
2232  }
2233  (void) SetImageProgressMonitor(*image,MonitorProgress,
2234  (void *) NULL);
2235  break;
2236  }
2237  if (LocaleCompare("monochrome",option+1) == 0)
2238  {
2239  (void) SyncImageSettings(mogrify_info,*image);
2240  (void) SetImageType(*image,BilevelType);
2241  InheritException(exception,&(*image)->exception);
2242  break;
2243  }
2244  if (LocaleCompare("morphology",option+1) == 0)
2245  {
2246  char
2247  token[MaxTextExtent];
2248 
2249  const char
2250  *p;
2251 
2252  KernelInfo
2253  *kernel;
2254 
2255  MorphologyMethod
2256  method;
2257 
2258  ssize_t
2259  iterations;
2260 
2261  /*
2262  Morphological Image Operation
2263  */
2264  (void) SyncImageSettings(mogrify_info,*image);
2265  p=argv[i+1];
2266  (void) GetNextToken(p,&p,MaxTextExtent,token);
2267  method=(MorphologyMethod) ParseCommandOption(
2268  MagickMorphologyOptions,MagickFalse,token);
2269  iterations=1L;
2270  (void) GetNextToken(p,&p,MaxTextExtent,token);
2271  if ((*p == ':') || (*p == ','))
2272  (void) GetNextToken(p,&p,MaxTextExtent,token);
2273  if ((*p != '\0'))
2274  iterations=(ssize_t) StringToLong(p);
2275  kernel=AcquireKernelInfo(argv[i+2]);
2276  if (kernel == (KernelInfo *) NULL)
2277  {
2278  (void) ThrowMagickException(exception,GetMagickModule(),
2279  OptionError,"UnabletoParseKernel","morphology");
2280  status=MagickFalse;
2281  break;
2282  }
2283  mogrify_image=MorphologyImageChannel(*image,channel,method,
2284  iterations,kernel,exception);
2285  kernel=DestroyKernelInfo(kernel);
2286  break;
2287  }
2288  if (LocaleCompare("motion-blur",option+1) == 0)
2289  {
2290  /*
2291  Motion blur image.
2292  */
2293  (void) SyncImageSettings(mogrify_info,*image);
2294  flags=ParseGeometry(argv[i+1],&geometry_info);
2295  if ((flags & SigmaValue) == 0)
2296  geometry_info.sigma=1.0;
2297  mogrify_image=MotionBlurImageChannel(*image,channel,
2298  geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2299  break;
2300  }
2301  break;
2302  }
2303  case 'n':
2304  {
2305  if (LocaleCompare("negate",option+1) == 0)
2306  {
2307  (void) SyncImageSettings(mogrify_info,*image);
2308  (void) NegateImageChannel(*image,channel,*option == '+' ?
2309  MagickTrue : MagickFalse);
2310  InheritException(exception,&(*image)->exception);
2311  break;
2312  }
2313  if (LocaleCompare("noise",option+1) == 0)
2314  {
2315  (void) SyncImageSettings(mogrify_info,*image);
2316  if (*option == '-')
2317  {
2318  flags=ParseGeometry(argv[i+1],&geometry_info);
2319  if ((flags & SigmaValue) == 0)
2320  geometry_info.sigma=geometry_info.rho;
2321  mogrify_image=StatisticImageChannel(*image,channel,
2322  NonpeakStatistic,(size_t) geometry_info.rho,(size_t)
2323  geometry_info.sigma,exception);
2324  }
2325  else
2326  {
2327  NoiseType
2328  noise;
2329 
2330  noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2331  MagickFalse,argv[i+1]);
2332  mogrify_image=AddNoiseImageChannel(*image,channel,noise,
2333  exception);
2334  }
2335  break;
2336  }
2337  if (LocaleCompare("normalize",option+1) == 0)
2338  {
2339  (void) SyncImageSettings(mogrify_info,*image);
2340  (void) NormalizeImageChannel(*image,channel);
2341  InheritException(exception,&(*image)->exception);
2342  break;
2343  }
2344  break;
2345  }
2346  case 'o':
2347  {
2348  if (LocaleCompare("opaque",option+1) == 0)
2349  {
2350  MagickPixelPacket
2351  target;
2352 
2353  (void) SyncImageSettings(mogrify_info,*image);
2354  (void) QueryMagickColor(argv[i+1],&target,exception);
2355  (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2356  *option == '-' ? MagickFalse : MagickTrue);
2357  break;
2358  }
2359  if (LocaleCompare("ordered-dither",option+1) == 0)
2360  {
2361  (void) SyncImageSettings(mogrify_info,*image);
2362  (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2363  exception);
2364  break;
2365  }
2366  break;
2367  }
2368  case 'p':
2369  {
2370  if (LocaleCompare("paint",option+1) == 0)
2371  {
2372  (void) SyncImageSettings(mogrify_info,*image);
2373  (void) ParseGeometry(argv[i+1],&geometry_info);
2374  mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
2375  break;
2376  }
2377  if (LocaleCompare("pen",option+1) == 0)
2378  {
2379  if (*option == '+')
2380  {
2381  (void) QueryColorDatabase("none",&draw_info->fill,exception);
2382  break;
2383  }
2384  (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2385  break;
2386  }
2387  if (LocaleCompare("perceptible",option+1) == 0)
2388  {
2389  /*
2390  Perceptible image.
2391  */
2392  (void) SyncImageSettings(mogrify_info,*image);
2393  (void) PerceptibleImageChannel(*image,channel,StringToDouble(
2394  argv[i+1],(char **) NULL));
2395  InheritException(exception,&(*image)->exception);
2396  break;
2397  }
2398  if (LocaleCompare("pointsize",option+1) == 0)
2399  {
2400  if (*option == '+')
2401  (void) ParseGeometry("12",&geometry_info);
2402  else
2403  (void) ParseGeometry(argv[i+1],&geometry_info);
2404  draw_info->pointsize=geometry_info.rho;
2405  break;
2406  }
2407  if (LocaleCompare("polaroid",option+1) == 0)
2408  {
2409  double
2410  angle;
2411 
2412  RandomInfo
2413  *random_info;
2414 
2415  /*
2416  Simulate a Polaroid picture.
2417  */
2418  (void) SyncImageSettings(mogrify_info,*image);
2419  random_info=AcquireRandomInfo();
2420  angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2421  random_info=DestroyRandomInfo(random_info);
2422  if (*option == '-')
2423  {
2424  SetGeometryInfo(&geometry_info);
2425  flags=ParseGeometry(argv[i+1],&geometry_info);
2426  angle=geometry_info.rho;
2427  }
2428  mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2429  break;
2430  }
2431  if (LocaleCompare("posterize",option+1) == 0)
2432  {
2433  /*
2434  Posterize image.
2435  */
2436  (void) SyncImageSettings(mogrify_info,*image);
2437  (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2438  quantize_info->dither);
2439  InheritException(exception,&(*image)->exception);
2440  break;
2441  }
2442  if (LocaleCompare("preview",option+1) == 0)
2443  {
2444  PreviewType
2445  preview_type;
2446 
2447  /*
2448  Preview image.
2449  */
2450  (void) SyncImageSettings(mogrify_info,*image);
2451  if (*option == '+')
2452  preview_type=UndefinedPreview;
2453  else
2454  preview_type=(PreviewType) ParseCommandOption(
2455  MagickPreviewOptions,MagickFalse,argv[i+1]);
2456  mogrify_image=PreviewImage(*image,preview_type,exception);
2457  break;
2458  }
2459  if (LocaleCompare("profile",option+1) == 0)
2460  {
2461  const char
2462  *name;
2463 
2464  const StringInfo
2465  *profile;
2466 
2467  ExceptionInfo
2468  *sans_exception;
2469 
2470  Image
2471  *profile_image;
2472 
2473  ImageInfo
2474  *profile_info;
2475 
2476  (void) SyncImageSettings(mogrify_info,*image);
2477  if (*option == '+')
2478  {
2479  /*
2480  Remove a profile from the image.
2481  */
2482  (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2483  NULL,0,MagickTrue);
2484  InheritException(exception,&(*image)->exception);
2485  break;
2486  }
2487  /*
2488  Associate a profile with the image.
2489  */
2490  profile_info=CloneImageInfo(mogrify_info);
2491  profile=GetImageProfile(*image,"iptc");
2492  if (profile != (StringInfo *) NULL)
2493  profile_info->profile=(void *) CloneStringInfo(profile);
2494  sans_exception=AcquireExceptionInfo();
2495  profile_image=GetImageCache(profile_info,argv[i+1],sans_exception);
2496  sans_exception=DestroyExceptionInfo(sans_exception);
2497  profile_info=DestroyImageInfo(profile_info);
2498  if (profile_image == (Image *) NULL)
2499  {
2500  StringInfo
2501  *profile;
2502 
2503  profile_info=CloneImageInfo(mogrify_info);
2504  (void) CopyMagickString(profile_info->filename,argv[i+1],
2505  MaxTextExtent);
2506  profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2507  if (profile != (StringInfo *) NULL)
2508  {
2509  (void) SetImageInfo(profile_info,0,exception);
2510  (void) ProfileImage(*image,profile_info->magick,
2511  GetStringInfoDatum(profile),(size_t)
2512  GetStringInfoLength(profile),MagickFalse);
2513  profile=DestroyStringInfo(profile);
2514  }
2515  profile_info=DestroyImageInfo(profile_info);
2516  break;
2517  }
2518  ResetImageProfileIterator(profile_image);
2519  name=GetNextImageProfile(profile_image);
2520  while (name != (const char *) NULL)
2521  {
2522  profile=GetImageProfile(profile_image,name);
2523  if (profile != (StringInfo *) NULL)
2524  (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2525  (size_t) GetStringInfoLength(profile),MagickFalse);
2526  name=GetNextImageProfile(profile_image);
2527  }
2528  profile_image=DestroyImage(profile_image);
2529  break;
2530  }
2531  break;
2532  }
2533  case 'q':
2534  {
2535  if (LocaleCompare("quantize",option+1) == 0)
2536  {
2537  if (*option == '+')
2538  {
2539  quantize_info->colorspace=UndefinedColorspace;
2540  break;
2541  }
2542  quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2543  MagickColorspaceOptions,MagickFalse,argv[i+1]);
2544  break;
2545  }
2546  break;
2547  }
2548  case 'r':
2549  {
2550  if (LocaleCompare("radial-blur",option+1) == 0 ||
2551  LocaleCompare("rotational-blur",option+1) == 0)
2552  {
2553  /*
2554  Radial blur image.
2555  */
2556  (void) SyncImageSettings(mogrify_info,*image);
2557  mogrify_image=RotationalBlurImageChannel(*image,channel,
2558  StringToDouble(argv[i+1],(char **) NULL),exception);
2559  break;
2560  }
2561  if (LocaleCompare("raise",option+1) == 0)
2562  {
2563  /*
2564  Surround image with a raise of solid color.
2565  */
2566  flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2567  (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2568  MagickFalse);
2569  InheritException(exception,&(*image)->exception);
2570  break;
2571  }
2572  if (LocaleCompare("random-threshold",option+1) == 0)
2573  {
2574  /*
2575  Threshold image.
2576  */
2577  (void) SyncImageSettings(mogrify_info,*image);
2578  (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2579  exception);
2580  break;
2581  }
2582  if (LocaleCompare("recolor",option+1) == 0)
2583  {
2584  KernelInfo
2585  *kernel;
2586 
2587  (void) SyncImageSettings(mogrify_info,*image);
2588  kernel=AcquireKernelInfo(argv[i+1]);
2589  if (kernel == (KernelInfo *) NULL)
2590  break;
2591  mogrify_image=ColorMatrixImage(*image,kernel,exception);
2592  kernel=DestroyKernelInfo(kernel);
2593  break;
2594  }
2595  if (LocaleCompare("region",option+1) == 0)
2596  {
2597  (void) SyncImageSettings(mogrify_info,*image);
2598  if (region_image != (Image *) NULL)
2599  {
2600  /*
2601  Composite region.
2602  */
2603  (void) CompositeImage(region_image,region_image->matte !=
2604  MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2605  region_geometry.x,region_geometry.y);
2606  InheritException(exception,&region_image->exception);
2607  *image=DestroyImage(*image);
2608  *image=region_image;
2609  region_image=(Image *) NULL;
2610  }
2611  if (*option == '+')
2612  break;
2613  /*
2614  Apply transformations to a selected region of the image.
2615  */
2616  (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2617  exception);
2618  mogrify_image=CropImage(*image,&region_geometry,exception);
2619  if (mogrify_image == (Image *) NULL)
2620  break;
2621  region_image=(*image);
2622  *image=mogrify_image;
2623  mogrify_image=(Image *) NULL;
2624  break;
2625  }
2626  if (LocaleCompare("render",option+1) == 0)
2627  {
2628  (void) SyncImageSettings(mogrify_info,*image);
2629  draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2630  break;
2631  }
2632  if (LocaleCompare("remap",option+1) == 0)
2633  {
2634  Image
2635  *remap_image;
2636 
2637  /*
2638  Transform image colors to match this set of colors.
2639  */
2640  (void) SyncImageSettings(mogrify_info,*image);
2641  if (*option == '+')
2642  break;
2643  remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2644  if (remap_image == (Image *) NULL)
2645  break;
2646  (void) RemapImage(quantize_info,*image,remap_image);
2647  InheritException(exception,&(*image)->exception);
2648  remap_image=DestroyImage(remap_image);
2649  break;
2650  }
2651  if (LocaleCompare("repage",option+1) == 0)
2652  {
2653  if (*option == '+')
2654  {
2655  (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2656  break;
2657  }
2658  (void) ResetImagePage(*image,argv[i+1]);
2659  InheritException(exception,&(*image)->exception);
2660  break;
2661  }
2662  if (LocaleCompare("resample",option+1) == 0)
2663  {
2664  /*
2665  Resample image.
2666  */
2667  (void) SyncImageSettings(mogrify_info,*image);
2668  flags=ParseGeometry(argv[i+1],&geometry_info);
2669  if ((flags & SigmaValue) == 0)
2670  geometry_info.sigma=geometry_info.rho;
2671  mogrify_image=ResampleImage(*image,geometry_info.rho,
2672  geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2673  break;
2674  }
2675  if (LocaleCompare("resize",option+1) == 0)
2676  {
2677  /*
2678  Resize image.
2679  */
2680  (void) SyncImageSettings(mogrify_info,*image);
2681  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2682  mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2683  (*image)->filter,(*image)->blur,exception);
2684  break;
2685  }
2686  if (LocaleCompare("roll",option+1) == 0)
2687  {
2688  /*
2689  Roll image.
2690  */
2691  (void) SyncImageSettings(mogrify_info,*image);
2692  flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2693  if ((flags & PercentValue) != 0)
2694  {
2695  geometry.x*=(double) (*image)->columns/100.0;
2696  geometry.y*=(double) (*image)->rows/100.0;
2697  }
2698  mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2699  break;
2700  }
2701  if (LocaleCompare("rotate",option+1) == 0)
2702  {
2703  char
2704  *geometry;
2705 
2706  /*
2707  Check for conditional image rotation.
2708  */
2709  (void) SyncImageSettings(mogrify_info,*image);
2710  if (strchr(argv[i+1],'>') != (char *) NULL)
2711  if ((*image)->columns <= (*image)->rows)
2712  break;
2713  if (strchr(argv[i+1],'<') != (char *) NULL)
2714  if ((*image)->columns >= (*image)->rows)
2715  break;
2716  /*
2717  Rotate image.
2718  */
2719  geometry=ConstantString(argv[i+1]);
2720  (void) SubstituteString(&geometry,">","");
2721  (void) SubstituteString(&geometry,"<","");
2722  (void) ParseGeometry(geometry,&geometry_info);
2723  geometry=DestroyString(geometry);
2724  mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2725  break;
2726  }
2727  break;
2728  }
2729  case 's':
2730  {
2731  if (LocaleCompare("sample",option+1) == 0)
2732  {
2733  /*
2734  Sample image with pixel replication.
2735  */
2736  (void) SyncImageSettings(mogrify_info,*image);
2737  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2738  mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2739  exception);
2740  break;
2741  }
2742  if (LocaleCompare("scale",option+1) == 0)
2743  {
2744  /*
2745  Resize image.
2746  */
2747  (void) SyncImageSettings(mogrify_info,*image);
2748  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2749  mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2750  exception);
2751  break;
2752  }
2753  if (LocaleCompare("selective-blur",option+1) == 0)
2754  {
2755  /*
2756  Selectively blur pixels within a contrast threshold.
2757  */
2758  (void) SyncImageSettings(mogrify_info,*image);
2759  flags=ParseGeometry(argv[i+1],&geometry_info);
2760  if ((flags & PercentValue) != 0)
2761  geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2762  mogrify_image=SelectiveBlurImageChannel(*image,channel,
2763  geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2764  break;
2765  }
2766  if (LocaleCompare("separate",option+1) == 0)
2767  {
2768  /*
2769  Break channels into separate images.
2770  WARNING: This can generate multiple images!
2771  */
2772  (void) SyncImageSettings(mogrify_info,*image);
2773  mogrify_image=SeparateImages(*image,channel,exception);
2774  break;
2775  }
2776  if (LocaleCompare("sepia-tone",option+1) == 0)
2777  {
2778  double
2779  threshold;
2780 
2781  /*
2782  Sepia-tone image.
2783  */
2784  (void) SyncImageSettings(mogrify_info,*image);
2785  threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2786  1.0);
2787  mogrify_image=SepiaToneImage(*image,threshold,exception);
2788  break;
2789  }
2790  if (LocaleCompare("segment",option+1) == 0)
2791  {
2792  /*
2793  Segment image.
2794  */
2795  (void) SyncImageSettings(mogrify_info,*image);
2796  flags=ParseGeometry(argv[i+1],&geometry_info);
2797  if ((flags & SigmaValue) == 0)
2798  geometry_info.sigma=1.0;
2799  (void) SegmentImage(*image,(*image)->colorspace,
2800  mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2801  InheritException(exception,&(*image)->exception);
2802  break;
2803  }
2804  if (LocaleCompare("set",option+1) == 0)
2805  {
2806  char
2807  *value;
2808 
2809  /*
2810  Set image option.
2811  */
2812  if (*option == '+')
2813  {
2814  if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2815  (void) DeleteImageRegistry(argv[i+1]+9);
2816  else
2817  if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2818  {
2819  (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2820  (void) DeleteImageArtifact(*image,argv[i+1]+7);
2821  }
2822  else
2823  (void) DeleteImageProperty(*image,argv[i+1]);
2824  break;
2825  }
2826  value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2827  InheritException(exception,&(*image)->exception);
2828  if (value == (char *) NULL)
2829  break;
2830  if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2831  (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2832  exception);
2833  else
2834  if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2835  {
2836  (void) SetImageOption(image_info,argv[i+1]+7,value);
2837  (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2838  (void) SetImageArtifact(*image,argv[i+1]+7,value);
2839  }
2840  else
2841  (void) SetImageProperty(*image,argv[i+1],value);
2842  value=DestroyString(value);
2843  break;
2844  }
2845  if (LocaleCompare("shade",option+1) == 0)
2846  {
2847  /*
2848  Shade image.
2849  */
2850  (void) SyncImageSettings(mogrify_info,*image);
2851  flags=ParseGeometry(argv[i+1],&geometry_info);
2852  if ((flags & SigmaValue) == 0)
2853  geometry_info.sigma=1.0;
2854  mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2855  MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2856  break;
2857  }
2858  if (LocaleCompare("shadow",option+1) == 0)
2859  {
2860  /*
2861  Shadow image.
2862  */
2863  (void) SyncImageSettings(mogrify_info,*image);
2864  flags=ParseGeometry(argv[i+1],&geometry_info);
2865  if ((flags & SigmaValue) == 0)
2866  geometry_info.sigma=1.0;
2867  if ((flags & XiValue) == 0)
2868  geometry_info.xi=4.0;
2869  if ((flags & PsiValue) == 0)
2870  geometry_info.psi=4.0;
2871  mogrify_image=ShadowImage(*image,geometry_info.rho,
2872  geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2873  ceil(geometry_info.psi-0.5),exception);
2874  break;
2875  }
2876  if (LocaleCompare("sharpen",option+1) == 0)
2877  {
2878  /*
2879  Sharpen image.
2880  */
2881  (void) SyncImageSettings(mogrify_info,*image);
2882  flags=ParseGeometry(argv[i+1],&geometry_info);
2883  if ((flags & SigmaValue) == 0)
2884  geometry_info.sigma=1.0;
2885  mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2886  geometry_info.sigma,exception);
2887  break;
2888  }
2889  if (LocaleCompare("shave",option+1) == 0)
2890  {
2891  /*
2892  Shave the image edges.
2893  */
2894  (void) SyncImageSettings(mogrify_info,*image);
2895  flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2896  mogrify_image=ShaveImage(*image,&geometry,exception);
2897  break;
2898  }
2899  if (LocaleCompare("shear",option+1) == 0)
2900  {
2901  /*
2902  Shear image.
2903  */
2904  (void) SyncImageSettings(mogrify_info,*image);
2905  flags=ParseGeometry(argv[i+1],&geometry_info);
2906  if ((flags & SigmaValue) == 0)
2907  geometry_info.sigma=geometry_info.rho;
2908  mogrify_image=ShearImage(*image,geometry_info.rho,
2909  geometry_info.sigma,exception);
2910  break;
2911  }
2912  if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2913  {
2914  /*
2915  Sigmoidal non-linearity contrast control.
2916  */
2917  (void) SyncImageSettings(mogrify_info,*image);
2918  flags=ParseGeometry(argv[i+1],&geometry_info);
2919  if ((flags & SigmaValue) == 0)
2920  geometry_info.sigma=(double) QuantumRange/2.0;
2921  if ((flags & PercentValue) != 0)
2922  geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2923  100.0;
2924  (void) SigmoidalContrastImageChannel(*image,channel,
2925  (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
2926  geometry_info.sigma);
2927  InheritException(exception,&(*image)->exception);
2928  break;
2929  }
2930  if (LocaleCompare("sketch",option+1) == 0)
2931  {
2932  /*
2933  Sketch image.
2934  */
2935  (void) SyncImageSettings(mogrify_info,*image);
2936  flags=ParseGeometry(argv[i+1],&geometry_info);
2937  if ((flags & SigmaValue) == 0)
2938  geometry_info.sigma=1.0;
2939  mogrify_image=SketchImage(*image,geometry_info.rho,
2940  geometry_info.sigma,geometry_info.xi,exception);
2941  break;
2942  }
2943  if (LocaleCompare("solarize",option+1) == 0)
2944  {
2945  double
2946  threshold;
2947 
2948  (void) SyncImageSettings(mogrify_info,*image);
2949  threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2950  1.0);
2951  (void) SolarizeImageChannel(*image,channel,threshold,exception);
2952  break;
2953  }
2954  if (LocaleCompare("sparse-color",option+1) == 0)
2955  {
2956  SparseColorMethod
2957  method;
2958 
2959  char
2960  *arguments;
2961 
2962  /*
2963  Sparse Color Interpolated Gradient
2964  */
2965  (void) SyncImageSettings(mogrify_info,*image);
2966  method=(SparseColorMethod) ParseCommandOption(
2967  MagickSparseColorOptions,MagickFalse,argv[i+1]);
2968  arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2969  InheritException(exception,&(*image)->exception);
2970  if (arguments == (char *) NULL)
2971  break;
2972  mogrify_image=SparseColorOption(*image,channel,method,arguments,
2973  option[0] == '+' ? MagickTrue : MagickFalse,exception);
2974  arguments=DestroyString(arguments);
2975  break;
2976  }
2977  if (LocaleCompare("splice",option+1) == 0)
2978  {
2979  /*
2980  Splice a solid color into the image.
2981  */
2982  (void) SyncImageSettings(mogrify_info,*image);
2983  (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2984  mogrify_image=SpliceImage(*image,&geometry,exception);
2985  break;
2986  }
2987  if (LocaleCompare("spread",option+1) == 0)
2988  {
2989  /*
2990  Spread an image.
2991  */
2992  (void) SyncImageSettings(mogrify_info,*image);
2993  (void) ParseGeometry(argv[i+1],&geometry_info);
2994  mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2995  break;
2996  }
2997  if (LocaleCompare("statistic",option+1) == 0)
2998  {
2999  StatisticType
3000  type;
3001 
3002  (void) SyncImageSettings(mogrify_info,*image);
3003  type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
3004  MagickFalse,argv[i+1]);
3005  (void) ParseGeometry(argv[i+2],&geometry_info);
3006  mogrify_image=StatisticImageChannel(*image,channel,type,(size_t)
3007  geometry_info.rho,(size_t) geometry_info.sigma,exception);
3008  break;
3009  }
3010  if (LocaleCompare("stretch",option+1) == 0)
3011  {
3012  if (*option == '+')
3013  {
3014  draw_info->stretch=UndefinedStretch;
3015  break;
3016  }
3017  draw_info->stretch=(StretchType) ParseCommandOption(
3018  MagickStretchOptions,MagickFalse,argv[i+1]);
3019  break;
3020  }
3021  if (LocaleCompare("strip",option+1) == 0)
3022  {
3023  /*
3024  Strip image of profiles and comments.
3025  */
3026  (void) SyncImageSettings(mogrify_info,*image);
3027  (void) StripImage(*image);
3028  InheritException(exception,&(*image)->exception);
3029  break;
3030  }
3031  if (LocaleCompare("stroke",option+1) == 0)
3032  {
3033  ExceptionInfo
3034  *sans;
3035 
3036  if (*option == '+')
3037  {
3038  (void) QueryColorDatabase("none",&draw_info->stroke,exception);
3039  if (draw_info->stroke_pattern != (Image *) NULL)
3040  draw_info->stroke_pattern=DestroyImage(
3041  draw_info->stroke_pattern);
3042  break;
3043  }
3044  sans=AcquireExceptionInfo();
3045  status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
3046  sans=DestroyExceptionInfo(sans);
3047  if (status == MagickFalse)
3048  draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
3049  exception);
3050  break;
3051  }
3052  if (LocaleCompare("strokewidth",option+1) == 0)
3053  {
3054  draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
3055  break;
3056  }
3057  if (LocaleCompare("style",option+1) == 0)
3058  {
3059  if (*option == '+')
3060  {
3061  draw_info->style=UndefinedStyle;
3062  break;
3063  }
3064  draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
3065  MagickFalse,argv[i+1]);
3066  break;
3067  }
3068  if (LocaleCompare("swirl",option+1) == 0)
3069  {
3070  /*
3071  Swirl image.
3072  */
3073  (void) SyncImageSettings(mogrify_info,*image);
3074  (void) ParseGeometry(argv[i+1],&geometry_info);
3075  mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
3076  break;
3077  }
3078  break;
3079  }
3080  case 't':
3081  {
3082  if (LocaleCompare("threshold",option+1) == 0)
3083  {
3084  double
3085  threshold;
3086 
3087  /*
3088  Threshold image.
3089  */
3090  (void) SyncImageSettings(mogrify_info,*image);
3091  if (*option == '+')
3092  threshold=(double) QuantumRange/2;
3093  else
3094  threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
3095  1.0);
3096  (void) BilevelImageChannel(*image,channel,threshold);
3097  InheritException(exception,&(*image)->exception);
3098  break;
3099  }
3100  if (LocaleCompare("thumbnail",option+1) == 0)
3101  {
3102  /*
3103  Thumbnail image.
3104  */
3105  (void) SyncImageSettings(mogrify_info,*image);
3106  (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
3107  mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
3108  exception);
3109  break;
3110  }
3111  if (LocaleCompare("tile",option+1) == 0)
3112  {
3113  if (*option == '+')
3114  {
3115  if (draw_info->fill_pattern != (Image *) NULL)
3116  draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3117  break;
3118  }
3119  draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
3120  exception);
3121  break;
3122  }
3123  if (LocaleCompare("tint",option+1) == 0)
3124  {
3125  /*
3126  Tint the image.
3127  */
3128  (void) SyncImageSettings(mogrify_info,*image);
3129  mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
3130  break;
3131  }
3132  if (LocaleCompare("transform",option+1) == 0)
3133  {
3134  /*
3135  Affine transform image.
3136  */
3137  (void) SyncImageSettings(mogrify_info,*image);
3138  mogrify_image=AffineTransformImage(*image,&draw_info->affine,
3139  exception);
3140  break;
3141  }
3142  if (LocaleCompare("transparent",option+1) == 0)
3143  {
3144  MagickPixelPacket
3145  target;
3146 
3147  (void) SyncImageSettings(mogrify_info,*image);
3148  (void) QueryMagickColor(argv[i+1],&target,exception);
3149  (void) TransparentPaintImage(*image,&target,(Quantum)
3150  TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
3151  InheritException(exception,&(*image)->exception);
3152  break;
3153  }
3154  if (LocaleCompare("transpose",option+1) == 0)
3155  {
3156  /*
3157  Transpose image scanlines.
3158  */
3159  (void) SyncImageSettings(mogrify_info,*image);
3160  mogrify_image=TransposeImage(*image,exception);
3161  break;
3162  }
3163  if (LocaleCompare("transverse",option+1) == 0)
3164  {
3165  /*
3166  Transverse image scanlines.
3167  */
3168  (void) SyncImageSettings(mogrify_info,*image);
3169  mogrify_image=TransverseImage(*image,exception);
3170  break;
3171  }
3172  if (LocaleCompare("treedepth",option+1) == 0)
3173  {
3174  quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3175  break;
3176  }
3177  if (LocaleCompare("trim",option+1) == 0)
3178  {
3179  /*
3180  Trim image.
3181  */
3182  (void) SyncImageSettings(mogrify_info,*image);
3183  mogrify_image=TrimImage(*image,exception);
3184  break;
3185  }
3186  if (LocaleCompare("type",option+1) == 0)
3187  {
3188  ImageType
3189  type;
3190 
3191  (void) SyncImageSettings(mogrify_info,*image);
3192  if (*option == '+')
3193  type=UndefinedType;
3194  else
3195  type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3196  argv[i+1]);
3197  (*image)->type=UndefinedType;
3198  (void) SetImageType(*image,type);
3199  InheritException(exception,&(*image)->exception);
3200  break;
3201  }
3202  break;
3203  }
3204  case 'u':
3205  {
3206  if (LocaleCompare("undercolor",option+1) == 0)
3207  {
3208  (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3209  exception);
3210  break;
3211  }
3212  if (LocaleCompare("unique",option+1) == 0)
3213  {
3214  if (*option == '+')
3215  {
3216  (void) DeleteImageArtifact(*image,"identify:unique-colors");
3217  break;
3218  }
3219  (void) SetImageArtifact(*image,"identify:unique-colors","true");
3220  (void) SetImageArtifact(*image,"verbose","true");
3221  break;
3222  }
3223  if (LocaleCompare("unique-colors",option+1) == 0)
3224  {
3225  /*
3226  Unique image colors.
3227  */
3228  (void) SyncImageSettings(mogrify_info,*image);
3229  mogrify_image=UniqueImageColors(*image,exception);
3230  break;
3231  }
3232  if (LocaleCompare("unsharp",option+1) == 0)
3233  {
3234  /*
3235  Unsharp mask image.
3236  */
3237  (void) SyncImageSettings(mogrify_info,*image);
3238  flags=ParseGeometry(argv[i+1],&geometry_info);
3239  if ((flags & SigmaValue) == 0)
3240  geometry_info.sigma=1.0;
3241  if ((flags & XiValue) == 0)
3242  geometry_info.xi=1.0;
3243  if ((flags & PsiValue) == 0)
3244  geometry_info.psi=0.05;
3245  mogrify_image=UnsharpMaskImageChannel(*image,channel,
3246  geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3247  geometry_info.psi,exception);
3248  break;
3249  }
3250  break;
3251  }
3252  case 'v':
3253  {
3254  if (LocaleCompare("verbose",option+1) == 0)
3255  {
3256  (void) SetImageArtifact(*image,option+1,
3257  *option == '+' ? "false" : "true");
3258  break;
3259  }
3260  if (LocaleCompare("vignette",option+1) == 0)
3261  {
3262  /*
3263  Vignette image.
3264  */
3265  (void) SyncImageSettings(mogrify_info,*image);
3266  flags=ParseGeometry(argv[i+1],&geometry_info);
3267  if ((flags & SigmaValue) == 0)
3268  geometry_info.sigma=1.0;
3269  if ((flags & XiValue) == 0)
3270  geometry_info.xi=0.1*(*image)->columns;
3271  if ((flags & PsiValue) == 0)
3272  geometry_info.psi=0.1*(*image)->rows;
3273  if ((flags & PercentValue) != 0)
3274  {
3275  geometry_info.xi*=(double) (*image)->columns/100.0;
3276  geometry_info.psi*=(double) (*image)->rows/100.0;
3277  }
3278  mogrify_image=VignetteImage(*image,geometry_info.rho,
3279  geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3280  ceil(geometry_info.psi-0.5),exception);
3281  break;
3282  }
3283  if (LocaleCompare("virtual-pixel",option+1) == 0)
3284  {
3285  if (*option == '+')
3286  {
3287  (void) SetImageVirtualPixelMethod(*image,
3288  UndefinedVirtualPixelMethod);
3289  break;
3290  }
3291  (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3292  ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3293  argv[i+1]));
3294  break;
3295  }
3296  break;
3297  }
3298  case 'w':
3299  {
3300  if (LocaleCompare("wave",option+1) == 0)
3301  {
3302  /*
3303  Wave image.
3304  */
3305  (void) SyncImageSettings(mogrify_info,*image);
3306  flags=ParseGeometry(argv[i+1],&geometry_info);
3307  if ((flags & SigmaValue) == 0)
3308  geometry_info.sigma=1.0;
3309  mogrify_image=WaveImage(*image,geometry_info.rho,
3310  geometry_info.sigma,exception);
3311  break;
3312  }
3313  if (LocaleCompare("wavelet-denoise",option+1) == 0)
3314  {
3315  /*
3316  Wavelet denoise image.
3317  */
3318  (void) SyncImageSettings(mogrify_info,*image);
3319  flags=ParseGeometry(argv[i+1],&geometry_info);
3320  if ((flags & PercentValue) != 0)
3321  {
3322  geometry_info.rho=QuantumRange*geometry_info.rho/100.0;
3323  geometry_info.sigma=QuantumRange*geometry_info.sigma/100.0;
3324  }
3325  if ((flags & SigmaValue) == 0)
3326  geometry_info.sigma=0.0;
3327  mogrify_image=WaveletDenoiseImage(*image,geometry_info.rho,
3328  geometry_info.sigma,exception);
3329  break;
3330  }
3331  if (LocaleCompare("weight",option+1) == 0)
3332  {
3333  ssize_t
3334  weight;
3335 
3336  weight=ParseCommandOption(MagickWeightOptions,MagickFalse,
3337  argv[i+1]);
3338  if (weight == -1)
3339  weight=(ssize_t) StringToUnsignedLong(argv[i+1]);
3340  draw_info->weight=(size_t) weight;
3341  break;
3342  }
3343  if (LocaleCompare("white-threshold",option+1) == 0)
3344  {
3345  /*
3346  White threshold image.
3347  */
3348  (void) SyncImageSettings(mogrify_info,*image);
3349  (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3350  exception);
3351  InheritException(exception,&(*image)->exception);
3352  break;
3353  }
3354  break;
3355  }
3356  default:
3357  break;
3358  }
3359  /*
3360  Replace current image with any image that was generated.
3361  */
3362  if (mogrify_image != (Image *) NULL)
3363  ReplaceImageInListReturnLast(image,mogrify_image);
3364  i+=count;
3365  }
3366  if (region_image != (Image *) NULL)
3367  {
3368  /*
3369  Composite transformed region onto image.
3370  */
3371  (void) SyncImageSettings(mogrify_info,*image);
3372  (void) CompositeImage(region_image,region_image->matte != MagickFalse ?
3373  CopyCompositeOp : OverCompositeOp,*image,region_geometry.x,
3374  region_geometry.y);
3375  InheritException(exception,&region_image->exception);
3376  *image=DestroyImage(*image);
3377  *image=region_image;
3378  region_image = (Image *) NULL;
3379  }
3380  /*
3381  Free resources.
3382  */
3383  quantize_info=DestroyQuantizeInfo(quantize_info);
3384  draw_info=DestroyDrawInfo(draw_info);
3385  mogrify_info=DestroyImageInfo(mogrify_info);
3386  status=(MagickStatusType) (exception->severity < ErrorException ? 1 : 0);
3387  return(status == 0 ? MagickFalse : MagickTrue);
3388 }
3389 
3390 /*
3391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3392 % %
3393 % %
3394 % %
3395 + M o g r i f y I m a g e C o m m a n d %
3396 % %
3397 % %
3398 % %
3399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3400 %
3401 % MogrifyImageCommand() transforms an image or a sequence of images. These
3402 % transforms include image scaling, image rotation, color reduction, and
3403 % others. The transmogrified image overwrites the original image.
3404 %
3405 % The format of the MogrifyImageCommand method is:
3406 %
3407 % MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3408 % const char **argv,char **metadata,ExceptionInfo *exception)
3409 %
3410 % A description of each parameter follows:
3411 %
3412 % o image_info: the image info.
3413 %
3414 % o argc: the number of elements in the argument vector.
3415 %
3416 % o argv: A text array containing the command line arguments.
3417 %
3418 % o metadata: any metadata is returned here.
3419 %
3420 % o exception: return any errors or warnings in this structure.
3421 %
3422 */
3423 
3424 static MagickBooleanType MogrifyUsage(void)
3425 {
3426  static const char
3427  miscellaneous[] =
3428  " -debug events display copious debugging information\n"
3429  " -distribute-cache port\n"
3430  " distributed pixel cache spanning one or more servers\n"
3431  " -help print program options\n"
3432  " -list type print a list of supported option arguments\n"
3433  " -log format format of debugging information\n"
3434  " -version print version information",
3435  operators[] =
3436  " -adaptive-blur geometry\n"
3437  " adaptively blur pixels; decrease effect near edges\n"
3438  " -adaptive-resize geometry\n"
3439  " adaptively resize image using 'mesh' interpolation\n"
3440  " -adaptive-sharpen geometry\n"
3441  " adaptively sharpen pixels; increase effect near edges\n"
3442  " -alpha option on, activate, off, deactivate, set, opaque, copy\n"
3443  " transparent, extract, background, or shape\n"
3444  " -annotate geometry text\n"
3445  " annotate the image with text\n"
3446  " -auto-gamma automagically adjust gamma level of image\n"
3447  " -auto-level automagically adjust color levels of image\n"
3448  " -auto-orient automagically orient (rotate) image\n"
3449  " -bench iterations measure performance\n"
3450  " -black-threshold value\n"
3451  " force all pixels below the threshold into black\n"
3452  " -blue-shift simulate a scene at nighttime in the moonlight\n"
3453  " -blur geometry reduce image noise and reduce detail levels\n"
3454  " -border geometry surround image with a border of color\n"
3455  " -bordercolor color border color\n"
3456  " -brightness-contrast geometry\n"
3457  " improve brightness / contrast of the image\n"
3458  " -canny geometry detect edges in the image\n"
3459  " -cdl filename color correct with a color decision list\n"
3460  " -charcoal radius simulate a charcoal drawing\n"
3461  " -chop geometry remove pixels from the image interior\n"
3462  " -clamp keep pixel values in range (0-QuantumRange)\n"
3463  " -clip clip along the first path from the 8BIM profile\n"
3464  " -clip-mask filename associate a clip mask with the image\n"
3465  " -clip-path id clip along a named path from the 8BIM profile\n"
3466  " -colorize value colorize the image with the fill color\n"
3467  " -color-matrix matrix apply color correction to the image\n"
3468  " -connected-components connectivity\n"
3469  " connected-components uniquely labeled\n"
3470  " -contrast enhance or reduce the image contrast\n"
3471  " -contrast-stretch geometry\n"
3472  " improve contrast by `stretching' the intensity range\n"
3473  " -convolve coefficients\n"
3474  " apply a convolution kernel to the image\n"
3475  " -cycle amount cycle the image colormap\n"
3476  " -decipher filename convert cipher pixels to plain pixels\n"
3477  " -deskew threshold straighten an image\n"
3478  " -despeckle reduce the speckles within an image\n"
3479  " -distort method args\n"
3480  " distort images according to given method ad args\n"
3481  " -draw string annotate the image with a graphic primitive\n"
3482  " -edge radius apply a filter to detect edges in the image\n"
3483  " -encipher filename convert plain pixels to cipher pixels\n"
3484  " -emboss radius emboss an image\n"
3485  " -enhance apply a digital filter to enhance a noisy image\n"
3486  " -equalize perform histogram equalization to an image\n"
3487  " -evaluate operator value\n"
3488  " evaluate an arithmetic, relational, or logical expression\n"
3489  " -extent geometry set the image size\n"
3490  " -extract geometry extract area from image\n"
3491  " -hough-lines geometry\n"
3492  " identify lines in the image\n"
3493  " -features distance analyze image features (e.g. contrast, correlation)\n"
3494  " -fft implements the discrete Fourier transform (DFT)\n"
3495  " -flip flip image vertically\n"
3496  " -floodfill geometry color\n"
3497  " floodfill the image with color\n"
3498  " -flop flop image horizontally\n"
3499  " -frame geometry surround image with an ornamental border\n"
3500  " -function name parameters\n"
3501  " apply function over image values\n"
3502  " -gamma value level of gamma correction\n"
3503  " -gaussian-blur geometry\n"
3504  " reduce image noise and reduce detail levels\n"
3505  " -geometry geometry preferred size or location of the image\n"
3506  " -grayscale method convert image to grayscale\n"
3507  " -help print program options\n"
3508  " -identify identify the format and characteristics of the image\n"
3509  " -ift implements the inverse discrete Fourier transform (DFT)\n"
3510  " -implode amount implode image pixels about the center\n"
3511  " -kuwahara geometry edge preserving noise reduction filter\n"
3512  " -lat geometry local adaptive thresholding\n"
3513  " -layers method optimize, merge, or compare image layers\n"
3514  " -level value adjust the level of image contrast\n"
3515  " -level-colors color,color\n"
3516  " level image with the given colors\n"
3517  " -linear-stretch geometry\n"
3518  " improve contrast by `stretching with saturation'\n"
3519  " -liquid-rescale geometry\n"
3520  " rescale image with seam-carving\n"
3521  " -local-contrast geometry\n"
3522  " enhance local contrast\n"
3523  " -magnify double the size of the image with pixel art scaling\n"
3524  " -mean-shift geometry delineate arbitrarily shaped clusters in the image\n"
3525  " -median geometry apply a median filter to the image\n"
3526  " -mode geometry make each pixel the 'predominant color' of the\n"
3527  " neighborhood\n"
3528  " -modulate value vary the brightness, saturation, and hue\n"
3529  " -monochrome transform image to black and white\n"
3530  " -morphology method kernel\n"
3531  " apply a morphology method to the image\n"
3532  " -motion-blur geometry\n"
3533  " simulate motion blur\n"
3534  " -negate replace every pixel with its complementary color \n"
3535  " -noise geometry add or reduce noise in an image\n"
3536  " -normalize transform image to span the full range of colors\n"
3537  " -opaque color change this color to the fill color\n"
3538  " -ordered-dither NxN\n"
3539  " add a noise pattern to the image with specific\n"
3540  " amplitudes\n"
3541  " -paint radius simulate an oil painting\n"
3542  " -perceptible epsilon\n"
3543  " pixel value less than |epsilon| become epsilon or\n"
3544  " -epsilon\n"
3545  " -polaroid angle simulate a Polaroid picture\n"
3546  " -posterize levels reduce the image to a limited number of color levels\n"
3547  " -profile filename add, delete, or apply an image profile\n"
3548  " -quantize colorspace reduce colors in this colorspace\n"
3549  " -radial-blur angle radial blur the image\n"
3550  " -raise value lighten/darken image edges to create a 3-D effect\n"
3551  " -random-threshold low,high\n"
3552  " random threshold the image\n"
3553  " -region geometry apply options to a portion of the image\n"
3554  " -render render vector graphics\n"
3555  " -resample geometry change the resolution of an image\n"
3556  " -resize geometry resize the image\n"
3557  " -roll geometry roll an image vertically or horizontally\n"
3558  " -rotate degrees apply Paeth rotation to the image\n"
3559  " -sample geometry scale image with pixel sampling\n"
3560  " -scale geometry scale the image\n"
3561  " -segment values segment an image\n"
3562  " -selective-blur geometry\n"
3563  " selectively blur pixels within a contrast threshold\n"
3564  " -sepia-tone threshold\n"
3565  " simulate a sepia-toned photo\n"
3566  " -set property value set an image property\n"
3567  " -shade degrees shade the image using a distant light source\n"
3568  " -shadow geometry simulate an image shadow\n"
3569  " -sharpen geometry sharpen the image\n"
3570  " -shave geometry shave pixels from the image edges\n"
3571  " -shear geometry slide one edge of the image along the X or Y axis\n"
3572  " -sigmoidal-contrast geometry\n"
3573  " increase the contrast without saturating highlights or\n"
3574  " shadows\n"
3575  " -sketch geometry simulate a pencil sketch\n"
3576  " -solarize threshold negate all pixels above the threshold level\n"
3577  " -sparse-color method args\n"
3578  " fill in a image based on a few color points\n"
3579  " -splice geometry splice the background color into the image\n"
3580  " -spread radius displace image pixels by a random amount\n"
3581  " -statistic type radius\n"
3582  " replace each pixel with corresponding statistic from the neighborhood\n"
3583  " -strip strip image of all profiles and comments\n"
3584  " -swirl degrees swirl image pixels about the center\n"
3585  " -threshold value threshold the image\n"
3586  " -thumbnail geometry create a thumbnail of the image\n"
3587  " -tile filename tile image when filling a graphic primitive\n"
3588  " -tint value tint the image with the fill color\n"
3589  " -transform affine transform image\n"
3590  " -transparent color make this color transparent within the image\n"
3591  " -transpose flip image vertically and rotate 90 degrees\n"
3592  " -transverse flop image horizontally and rotate 270 degrees\n"
3593  " -trim trim image edges\n"
3594  " -type type image type\n"
3595  " -unique-colors discard all but one of any pixel color\n"
3596  " -unsharp geometry sharpen the image\n"
3597  " -vignette geometry soften the edges of the image in vignette style\n"
3598  " -wave geometry alter an image along a sine wave\n"
3599  " -wavelet-denoise threshold\n"
3600  " removes noise from the image using a wavelet transform\n"
3601  " -white-threshold value\n"
3602  " force all pixels above the threshold into white",
3603  sequence_operators[] =
3604  " -affinity filename transform image colors to match this set of colors\n"
3605  " -append append an image sequence\n"
3606  " -clut apply a color lookup table to the image\n"
3607  " -coalesce merge a sequence of images\n"
3608  " -combine combine a sequence of images\n"
3609  " -compare mathematically and visually annotate the difference between an image and its reconstruction\n"
3610  " -complex operator perform complex mathematics on an image sequence\n"
3611  " -composite composite image\n"
3612  " -copy geometry offset\n"
3613  " copy pixels from one area of an image to another\n"
3614  " -crop geometry cut out a rectangular region of the image\n"
3615  " -deconstruct break down an image sequence into constituent parts\n"
3616  " -evaluate-sequence operator\n"
3617  " evaluate an arithmetic, relational, or logical expression\n"
3618  " -flatten flatten a sequence of images\n"
3619  " -fx expression apply mathematical expression to an image channel(s)\n"
3620  " -hald-clut apply a Hald color lookup table to the image\n"
3621  " -layers method optimize, merge, or compare image layers\n"
3622  " -morph value morph an image sequence\n"
3623  " -mosaic create a mosaic from an image sequence\n"
3624  " -poly terms build a polynomial from the image sequence and the corresponding\n"
3625  " terms (coefficients and degree pairs).\n"
3626  " -print string interpret string and print to console\n"
3627  " -process arguments process the image with a custom image filter\n"
3628  " -separate separate an image channel into a grayscale image\n"
3629  " -smush geometry smush an image sequence together\n"
3630  " -write filename write images to this file",
3631  settings[] =
3632  " -adjoin join images into a single multi-image file\n"
3633  " -affine matrix affine transform matrix\n"
3634  " -alpha option activate, deactivate, reset, or set the alpha channel\n"
3635  " -antialias remove pixel-aliasing\n"
3636  " -authenticate password\n"
3637  " decipher image with this password\n"
3638  " -attenuate value lessen (or intensify) when adding noise to an image\n"
3639  " -background color background color\n"
3640  " -bias value add bias when convolving an image\n"
3641  " -black-point-compensation\n"
3642  " use black point compensation\n"
3643  " -blue-primary point chromaticity blue primary point\n"
3644  " -bordercolor color border color\n"
3645  " -caption string assign a caption to an image\n"
3646  " -cdl filename color correct with a color decision list\n"
3647  " -channel type apply option to select image channels\n"
3648  " -colors value preferred number of colors in the image\n"
3649  " -colorspace type alternate image colorspace\n"
3650  " -comment string annotate image with comment\n"
3651  " -compose operator set image composite operator\n"
3652  " -compress type type of pixel compression when writing the image\n"
3653  " -decipher filename convert cipher pixels to plain pixels\n"
3654  " -define format:option\n"
3655  " define one or more image format options\n"
3656  " -delay value display the next image after pausing\n"
3657  " -density geometry horizontal and vertical density of the image\n"
3658  " -depth value image depth\n"
3659  " -direction type render text right-to-left or left-to-right\n"
3660  " -display server get image or font from this X server\n"
3661  " -dispose method layer disposal method\n"
3662  " -dither method apply error diffusion to image\n"
3663  " -encipher filename convert plain pixels to cipher pixels\n"
3664  " -encoding type text encoding type\n"
3665  " -endian type endianness (MSB or LSB) of the image\n"
3666  " -family name render text with this font family\n"
3667  " -features distance analyze image features (e.g. contrast, correlation)\n"
3668  " -fill color color to use when filling a graphic primitive\n"
3669  " -filter type use this filter when resizing an image\n"
3670  " -flatten flatten a sequence of images\n"
3671  " -font name render text with this font\n"
3672  " -format \"string\" output formatted image characteristics\n"
3673  " -function name apply a function to the image\n"
3674  " -fuzz distance colors within this distance are considered equal\n"
3675  " -gravity type horizontal and vertical text placement\n"
3676  " -green-primary point chromaticity green primary point\n"
3677  " -intensity method method to generate intensity value from pixel\n"
3678  " -intent type type of rendering intent when managing the image color\n"
3679  " -interlace type type of image interlacing scheme\n"
3680  " -interline-spacing value\n"
3681  " set the space between two text lines\n"
3682  " -interpolate method pixel color interpolation method\n"
3683  " -interword-spacing value\n"
3684  " set the space between two words\n"
3685  " -kerning value set the space between two letters\n"
3686  " -label string assign a label to an image\n"
3687  " -limit type value pixel cache resource limit\n"
3688  " -loop iterations add Netscape loop extension to your GIF animation\n"
3689  " -mask filename associate a mask with the image\n"
3690  " -matte store matte channel if the image has one\n"
3691  " -mattecolor color frame color\n"
3692  " -monitor monitor progress\n"
3693  " -morphology method kernel\n"
3694  " apply a morphology method to the image\n"
3695  " -orient type image orientation\n"
3696  " -page geometry size and location of an image canvas (setting)\n"
3697  " -path path write images to this path on disk\n"
3698  " -ping efficiently determine image attributes\n"
3699  " -pointsize value font point size\n"
3700  " -precision value maximum number of significant digits to print\n"
3701  " -preview type image preview type\n"
3702  " -quality value JPEG/MIFF/PNG compression level\n"
3703  " -quiet suppress all warning messages\n"
3704  " -red-primary point chromaticity red primary point\n"
3705  " -regard-warnings pay attention to warning messages\n"
3706  " -remap filename transform image colors to match this set of colors\n"
3707  " -repage geometry size and location of an image canvas\n"
3708  " -respect-parentheses settings remain in effect until parenthesis boundary\n"
3709  " -sampling-factor geometry\n"
3710  " horizontal and vertical sampling factor\n"
3711  " -scene value image scene number\n"
3712  " -seed value seed a new sequence of pseudo-random numbers\n"
3713  " -size geometry width and height of image\n"
3714  " -stretch type render text with this font stretch\n"
3715  " -stroke color graphic primitive stroke color\n"
3716  " -strokewidth value graphic primitive stroke width\n"
3717  " -style type render text with this font style\n"
3718  " -synchronize synchronize image to storage device\n"
3719  " -taint declare the image as modified\n"
3720  " -texture filename name of texture to tile onto the image background\n"
3721  " -tile-offset geometry\n"
3722  " tile offset\n"
3723  " -treedepth value color tree depth\n"
3724  " -transparent-color color\n"
3725  " transparent color\n"
3726  " -undercolor color annotation bounding box color\n"
3727  " -units type the units of image resolution\n"
3728  " -verbose print detailed information about the image\n"
3729  " -view FlashPix viewing transforms\n"
3730  " -virtual-pixel method\n"
3731  " virtual pixel access method\n"
3732  " -weight type render text with this font weight\n"
3733  " -white-point point chromaticity white point",
3734  stack_operators[] =
3735  " -delete indexes delete the image from the image sequence\n"
3736  " -duplicate count,indexes\n"
3737  " duplicate an image one or more times\n"
3738  " -insert index insert last image into the image sequence\n"
3739  " -reverse reverse image sequence\n"
3740  " -swap indexes swap two images in the image sequence";
3741 
3742  ListMagickVersion(stdout);
3743  (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3744  GetClientName());
3745  (void) printf("\nImage Settings:\n");
3746  (void) puts(settings);
3747  (void) printf("\nImage Operators:\n");
3748  (void) puts(operators);
3749  (void) printf("\nImage Sequence Operators:\n");
3750  (void) puts(sequence_operators);
3751  (void) printf("\nImage Stack Operators:\n");
3752  (void) puts(stack_operators);
3753  (void) printf("\nMiscellaneous Options:\n");
3754  (void) puts(miscellaneous);
3755  (void) printf(
3756  "\nBy default, the image format of `file' is determined by its magic\n");
3757  (void) printf(
3758  "number. To specify a particular image format, precede the filename\n");
3759  (void) printf(
3760  "with an image format name and a colon (i.e. ps:image) or specify the\n");
3761  (void) printf(
3762  "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3763  (void) printf("'-' for standard input or output.\n");
3764  return(MagickTrue);
3765 }
3766 
3767 WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3768  int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3769 {
3770 #define DestroyMogrify() \
3771 { \
3772  if (format != (char *) NULL) \
3773  format=DestroyString(format); \
3774  if (path != (char *) NULL) \
3775  path=DestroyString(path); \
3776  DestroyImageStack(); \
3777  for (i=0; i < (ssize_t) argc; i++) \
3778  argv[i]=DestroyString(argv[i]); \
3779  argv=(char **) RelinquishMagickMemory(argv); \
3780 }
3781 #define ThrowMogrifyException(asperity,tag,option) \
3782 { \
3783  (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3784  option); \
3785  DestroyMogrify(); \
3786  return(MagickFalse); \
3787 }
3788 #define ThrowMogrifyInvalidArgumentException(option,argument) \
3789 { \
3790  (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3791  "InvalidArgument","`%s': %s",argument,option); \
3792  DestroyMogrify(); \
3793  return(MagickFalse); \
3794 }
3795 
3796  char
3797  *format,
3798  *option,
3799  *path;
3800 
3801  Image
3802  *image;
3803 
3804  ImageStack
3805  image_stack[MaxImageStackDepth+1];
3806 
3807  MagickBooleanType
3808  global_colormap;
3809 
3810  MagickBooleanType
3811  fire,
3812  pend,
3813  respect_parenthesis;
3814 
3815  MagickStatusType
3816  status;
3817 
3818  ssize_t
3819  i;
3820 
3821  ssize_t
3822  j,
3823  k;
3824 
3825  wand_unreferenced(metadata);
3826 
3827  /*
3828  Set defaults.
3829  */
3830  assert(image_info != (ImageInfo *) NULL);
3831  assert(image_info->signature == MagickCoreSignature);
3832  assert(exception != (ExceptionInfo *) NULL);
3833  if (IsEventLogging() != MagickFalse)
3834  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3835  if (argc == 2)
3836  {
3837  option=argv[1];
3838  if ((LocaleCompare("version",option+1) == 0) ||
3839  (LocaleCompare("-version",option+1) == 0))
3840  {
3841  ListMagickVersion(stdout);
3842  return(MagickTrue);
3843  }
3844  }
3845  if (argc < 2)
3846  return(MogrifyUsage());
3847  format=(char *) NULL;
3848  path=(char *) NULL;
3849  global_colormap=MagickFalse;
3850  k=0;
3851  j=1;
3852  NewImageStack();
3853  option=(char *) NULL;
3854  pend=MagickFalse;
3855  respect_parenthesis=MagickFalse;
3856  status=MagickTrue;
3857  /*
3858  Parse command line.
3859  */
3860  ReadCommandlLine(argc,&argv);
3861  status=ExpandFilenames(&argc,&argv);
3862  if (status == MagickFalse)
3863  ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3864  GetExceptionMessage(errno));
3865  for (i=1; i < (ssize_t) argc; i++)
3866  {
3867  option=argv[i];
3868  if (LocaleCompare(option,"(") == 0)
3869  {
3870  FireImageStack(MagickFalse,MagickTrue,pend);
3871  if (k == MaxImageStackDepth)
3872  ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3873  option);
3874  PushImageStack();
3875  continue;
3876  }
3877  if (LocaleCompare(option,")") == 0)
3878  {
3879  FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3880  if (k == 0)
3881  ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3882  PopImageStack();
3883  continue;
3884  }
3885  if (IsCommandOption(option) == MagickFalse)
3886  {
3887  char
3888  backup_filename[MaxTextExtent],
3889  *filename,
3890  magic[MagickPathExtent];
3891 
3892  Image
3893  *images;
3894 
3895  struct stat
3896  properties;
3897 
3898  /*
3899  Option is a file name: begin by reading image from specified file.
3900  */
3901  FireImageStack(MagickFalse,MagickFalse,pend);
3902  filename=argv[i];
3903  if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
3904  filename=argv[++i];
3905  (void) SetImageOption(image_info,"filename",filename);
3906  (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3907  images=ReadImages(image_info,exception);
3908  status&=(images != (Image *) NULL) &&
3909  (exception->severity < ErrorException);
3910  if (images == (Image *) NULL)
3911  continue;
3912  properties=(*GetBlobProperties(images));
3913  if (format != (char *) NULL)
3914  GetPathComponent(images->magick_filename,BasePathSansCompressExtension,
3915  images->filename);
3916  if (path != (char *) NULL)
3917  {
3918  GetPathComponent(option,TailPath,filename);
3919  (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
3920  path,*DirectorySeparator,filename);
3921  }
3922  if (format != (char *) NULL)
3923  AppendImageFormat(format,images->filename);
3924  AppendImageStack(images);
3925  FinalizeImageSettings(image_info,image,MagickFalse);
3926  if (image == (Image *) NULL)
3927  continue;
3928  if (global_colormap != MagickFalse)
3929  {
3930  QuantizeInfo
3931  *quantize_info;
3932 
3933  quantize_info=AcquireQuantizeInfo(image_info);
3934  (void) RemapImages(quantize_info,images,(Image *) NULL);
3935  quantize_info=DestroyQuantizeInfo(quantize_info);
3936  }
3937  *backup_filename='\0';
3938  *magic='\0';
3939  GetPathComponent(filename,MagickPath,magic);
3940  if (*magic != '\0')
3941  {
3942  char
3943  filename[MagickPathExtent];
3944 
3945  if (format != (char *) NULL)
3946  (void) CopyMagickString(magic,format,MagickPathExtent);
3947  (void) FormatLocaleString(filename,MagickPathExtent,"%s:%s",magic,
3948  image->filename);
3949  (void) CopyMagickString(image->filename,filename,MagickPathExtent);
3950  }
3951  if ((LocaleCompare(image->filename,"-") != 0) &&
3952  (IsPathWritable(image->filename) != MagickFalse))
3953  {
3954  ssize_t
3955  i;
3956 
3957  /*
3958  Rename image file as backup.
3959  */
3960  (void) CopyMagickString(backup_filename,image->filename,
3961  MaxTextExtent);
3962  for (i=0; i < 6; i++)
3963  {
3964  (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3965  if (IsPathAccessible(backup_filename) == MagickFalse)
3966  break;
3967  }
3968  if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3969  (rename_utf8(image->filename,backup_filename) != 0))
3970  *backup_filename='\0';
3971  }
3972  /*
3973  Write transmogrified image to disk.
3974  */
3975  image_info->synchronize=MagickTrue;
3976  status&=WriteImages(image_info,image,image->filename,exception);
3977  if (status != MagickFalse)
3978  {
3979 #if defined(MAGICKCORE_HAVE_UTIME)
3980  {
3981  MagickBooleanType
3982  preserve_timestamp;
3983 
3984  preserve_timestamp=IsStringTrue(GetImageOption(image_info,
3985  "preserve-timestamp"));
3986  if (preserve_timestamp != MagickFalse)
3987  {
3988  struct utimbuf
3989  timestamp;
3990 
3991  timestamp.actime=properties.st_atime;
3992  timestamp.modtime=properties.st_mtime;
3993  (void) utime(image->filename,&timestamp);
3994  }
3995  }
3996 #endif
3997  if (*backup_filename != '\0')
3998  (void) remove_utf8(backup_filename);
3999  }
4000  else
4001  if (*backup_filename != '\0')
4002  (void) rename_utf8(backup_filename,image->filename);
4003  RemoveAllImageStack();
4004  continue;
4005  }
4006  pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4007  switch (*(option+1))
4008  {
4009  case 'a':
4010  {
4011  if (LocaleCompare("adaptive-blur",option+1) == 0)
4012  {
4013  i++;
4014  if (i == (ssize_t) argc)
4015  ThrowMogrifyException(OptionError,"MissingArgument",option);
4016  if (IsGeometry(argv[i]) == MagickFalse)
4017  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4018  break;
4019  }
4020  if (LocaleCompare("adaptive-resize",option+1) == 0)
4021  {
4022  i++;
4023  if (i == (ssize_t) argc)
4024  ThrowMogrifyException(OptionError,"MissingArgument",option);
4025  if (IsGeometry(argv[i]) == MagickFalse)
4026  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4027  break;
4028  }
4029  if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4030  {
4031  i++;
4032  if (i == (ssize_t) argc)
4033  ThrowMogrifyException(OptionError,"MissingArgument",option);
4034  if (IsGeometry(argv[i]) == MagickFalse)
4035  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4036  break;
4037  }
4038  if (LocaleCompare("affine",option+1) == 0)
4039  {
4040  if (*option == '+')
4041  break;
4042  i++;
4043  if (i == (ssize_t) argc)
4044  ThrowMogrifyException(OptionError,"MissingArgument",option);
4045  if (IsGeometry(argv[i]) == MagickFalse)
4046  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4047  break;
4048  }
4049  if (LocaleCompare("alpha",option+1) == 0)
4050  {
4051  ssize_t
4052  type;
4053 
4054  if (*option == '+')
4055  break;
4056  i++;
4057  if (i == (ssize_t) argc)
4058  ThrowMogrifyException(OptionError,"MissingArgument",option);
4059  type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
4060  if (type < 0)
4061  ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4062  argv[i]);
4063  break;
4064  }
4065  if (LocaleCompare("annotate",option+1) == 0)
4066  {
4067  if (*option == '+')
4068  break;
4069  i++;
4070  if (i == (ssize_t) argc)
4071  ThrowMogrifyException(OptionError,"MissingArgument",option);
4072  if (IsGeometry(argv[i]) == MagickFalse)
4073  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4074  if (i == (ssize_t) argc)
4075  ThrowMogrifyException(OptionError,"MissingArgument",option);
4076  i++;
4077  break;
4078  }
4079  if (LocaleCompare("antialias",option+1) == 0)
4080  break;
4081  if (LocaleCompare("append",option+1) == 0)
4082  break;
4083  if (LocaleCompare("attenuate",option+1) == 0)
4084  {
4085  if (*option == '+')
4086  break;
4087  i++;
4088  if (i == (ssize_t) argc)
4089  ThrowMogrifyException(OptionError,"MissingArgument",option);
4090  if (IsGeometry(argv[i]) == MagickFalse)
4091  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4092  break;
4093  }
4094  if (LocaleCompare("authenticate",option+1) == 0)
4095  {
4096  if (*option == '+')
4097  break;
4098  i++;
4099  if (i == (ssize_t) argc)
4100  ThrowMogrifyException(OptionError,"MissingArgument",option);
4101  break;
4102  }
4103  if (LocaleCompare("auto-gamma",option+1) == 0)
4104  break;
4105  if (LocaleCompare("auto-level",option+1) == 0)
4106  break;
4107  if (LocaleCompare("auto-orient",option+1) == 0)
4108  break;
4109  if (LocaleCompare("average",option+1) == 0)
4110  break;
4111  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4112  }
4113  case 'b':
4114  {
4115  if (LocaleCompare("background",option+1) == 0)
4116  {
4117  if (*option == '+')
4118  break;
4119  i++;
4120  if (i == (ssize_t) argc)
4121  ThrowMogrifyException(OptionError,"MissingArgument",option);
4122  break;
4123  }
4124  if (LocaleCompare("bias",option+1) == 0)
4125  {
4126  if (*option == '+')
4127  break;
4128  i++;
4129  if (i == (ssize_t) argc)
4130  ThrowMogrifyException(OptionError,"MissingArgument",option);
4131  if (IsGeometry(argv[i]) == MagickFalse)
4132  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4133  break;
4134  }
4135  if (LocaleCompare("black-point-compensation",option+1) == 0)
4136  break;
4137  if (LocaleCompare("black-threshold",option+1) == 0)
4138  {
4139  if (*option == '+')
4140  break;
4141  i++;
4142  if (i == (ssize_t) argc)
4143  ThrowMogrifyException(OptionError,"MissingArgument",option);
4144  if (IsGeometry(argv[i]) == MagickFalse)
4145  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4146  break;
4147  }
4148  if (LocaleCompare("blue-primary",option+1) == 0)
4149  {
4150  if (*option == '+')
4151  break;
4152  i++;
4153  if (i == (ssize_t) argc)
4154  ThrowMogrifyException(OptionError,"MissingArgument",option);
4155  if (IsGeometry(argv[i]) == MagickFalse)
4156  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4157  break;
4158  }
4159  if (LocaleCompare("blue-shift",option+1) == 0)
4160  {
4161  i++;
4162  if (i == (ssize_t) argc)
4163  ThrowMogrifyException(OptionError,"MissingArgument",option);
4164  if (IsGeometry(argv[i]) == MagickFalse)
4165  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4166  break;
4167  }
4168  if (LocaleCompare("blur",option+1) == 0)
4169  {
4170  i++;
4171  if (i == (ssize_t) argc)
4172  ThrowMogrifyException(OptionError,"MissingArgument",option);
4173  if (IsGeometry(argv[i]) == MagickFalse)
4174  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4175  break;
4176  }
4177  if (LocaleCompare("border",option+1) == 0)
4178  {
4179  if (*option == '+')
4180  break;
4181  i++;
4182  if (i == (ssize_t) argc)
4183  ThrowMogrifyException(OptionError,"MissingArgument",option);
4184  if (IsGeometry(argv[i]) == MagickFalse)
4185  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4186  break;
4187  }
4188  if (LocaleCompare("bordercolor",option+1) == 0)
4189  {
4190  if (*option == '+')
4191  break;
4192  i++;
4193  if (i == (ssize_t) argc)
4194  ThrowMogrifyException(OptionError,"MissingArgument",option);
4195  break;
4196  }
4197  if (LocaleCompare("box",option+1) == 0)
4198  {
4199  if (*option == '+')
4200  break;
4201  i++;
4202  if (i == (ssize_t) argc)
4203  ThrowMogrifyException(OptionError,"MissingArgument",option);
4204  break;
4205  }
4206  if (LocaleCompare("brightness-contrast",option+1) == 0)
4207  {
4208  i++;
4209  if (i == (ssize_t) argc)
4210  ThrowMogrifyException(OptionError,"MissingArgument",option);
4211  if (IsGeometry(argv[i]) == MagickFalse)
4212  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4213  break;
4214  }
4215  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4216  }
4217  case 'c':
4218  {
4219  if (LocaleCompare("cache",option+1) == 0)
4220  {
4221  if (*option == '+')
4222  break;
4223  i++;
4224  if (i == (ssize_t) argc)
4225  ThrowMogrifyException(OptionError,"MissingArgument",option);
4226  if (IsGeometry(argv[i]) == MagickFalse)
4227  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4228  break;
4229  }
4230  if (LocaleCompare("canny",option+1) == 0)
4231  {
4232  if (*option == '+')
4233  break;
4234  i++;
4235  if (i == (ssize_t) argc)
4236  ThrowMogrifyException(OptionError,"MissingArgument",option);
4237  if (IsGeometry(argv[i]) == MagickFalse)
4238  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4239  break;
4240  }
4241  if (LocaleCompare("caption",option+1) == 0)
4242  {
4243  if (*option == '+')
4244  break;
4245  i++;
4246  if (i == (ssize_t) argc)
4247  ThrowMogrifyException(OptionError,"MissingArgument",option);
4248  break;
4249  }
4250  if (LocaleCompare("channel",option+1) == 0)
4251  {
4252  ssize_t
4253  channel;
4254 
4255  if (*option == '+')
4256  break;
4257  i++;
4258  if (i == (ssize_t) argc)
4259  ThrowMogrifyException(OptionError,"MissingArgument",option);
4260  channel=ParseChannelOption(argv[i]);
4261  if (channel < 0)
4262  ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4263  argv[i]);
4264  break;
4265  }
4266  if (LocaleCompare("cdl",option+1) == 0)
4267  {
4268  if (*option == '+')
4269  break;
4270  i++;
4271  if (i == (ssize_t) argc)
4272  ThrowMogrifyException(OptionError,"MissingArgument",option);
4273  break;
4274  }
4275  if (LocaleCompare("charcoal",option+1) == 0)
4276  {
4277  if (*option == '+')
4278  break;
4279  i++;
4280  if (i == (ssize_t) argc)
4281  ThrowMogrifyException(OptionError,"MissingArgument",option);
4282  if (IsGeometry(argv[i]) == MagickFalse)
4283  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4284  break;
4285  }
4286  if (LocaleCompare("chop",option+1) == 0)
4287  {
4288  if (*option == '+')
4289  break;
4290  i++;
4291  if (i == (ssize_t) argc)
4292  ThrowMogrifyException(OptionError,"MissingArgument",option);
4293  if (IsGeometry(argv[i]) == MagickFalse)
4294  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4295  break;
4296  }
4297  if (LocaleCompare("clamp",option+1) == 0)
4298  break;
4299  if (LocaleCompare("clip",option+1) == 0)
4300  break;
4301  if (LocaleCompare("clip-mask",option+1) == 0)
4302  {
4303  if (*option == '+')
4304  break;
4305  i++;
4306  if (i == (ssize_t) argc)
4307  ThrowMogrifyException(OptionError,"MissingArgument",option);
4308  break;
4309  }
4310  if (LocaleCompare("clut",option+1) == 0)
4311  break;
4312  if (LocaleCompare("coalesce",option+1) == 0)
4313  break;
4314  if (LocaleCompare("colorize",option+1) == 0)
4315  {
4316  if (*option == '+')
4317  break;
4318  i++;
4319  if (i == (ssize_t) argc)
4320  ThrowMogrifyException(OptionError,"MissingArgument",option);
4321  if (IsGeometry(argv[i]) == MagickFalse)
4322  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4323  break;
4324  }
4325  if (LocaleCompare("color-matrix",option+1) == 0)
4326  {
4327  KernelInfo
4328  *kernel_info;
4329 
4330  if (*option == '+')
4331  break;
4332  i++;
4333  if (i == (ssize_t) argc)
4334  ThrowMogrifyException(OptionError,"MissingArgument",option);
4335  kernel_info=AcquireKernelInfo(argv[i]);
4336  if (kernel_info == (KernelInfo *) NULL)
4337  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4338  kernel_info=DestroyKernelInfo(kernel_info);
4339  break;
4340  }
4341  if (LocaleCompare("colors",option+1) == 0)
4342  {
4343  if (*option == '+')
4344  break;
4345  i++;
4346  if (i == (ssize_t) argc)
4347  ThrowMogrifyException(OptionError,"MissingArgument",option);
4348  if (IsGeometry(argv[i]) == MagickFalse)
4349  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4350  break;
4351  }
4352  if (LocaleCompare("colorspace",option+1) == 0)
4353  {
4354  ssize_t
4355  colorspace;
4356 
4357  if (*option == '+')
4358  break;
4359  i++;
4360  if (i == (ssize_t) argc)
4361  ThrowMogrifyException(OptionError,"MissingArgument",option);
4362  colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4363  argv[i]);
4364  if (colorspace < 0)
4365  ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4366  argv[i]);
4367  break;
4368  }
4369  if (LocaleCompare("combine",option+1) == 0)
4370  {
4371  if (*option == '-')
4372  break;
4373  i++;
4374  if (i == (ssize_t) argc)
4375  ThrowMogrifyException(OptionError,"MissingArgument",option);
4376  break;
4377  }
4378  if (LocaleCompare("comment",option+1) == 0)
4379  {
4380  if (*option == '+')
4381  break;
4382  i++;
4383  if (i == (ssize_t) argc)
4384  ThrowMogrifyException(OptionError,"MissingArgument",option);
4385  break;
4386  }
4387  if (LocaleCompare("compare",option+1) == 0)
4388  break;
4389  if (LocaleCompare("complex",option+1) == 0)
4390  {
4391  ssize_t
4392  op;
4393 
4394  if (*option == '+')
4395  break;
4396  i++;
4397  if (i == (ssize_t) argc)
4398  ThrowMogrifyException(OptionError,"MissingArgument",option);
4399  op=ParseCommandOption(MagickComplexOptions,MagickFalse,argv[i]);
4400  if (op < 0)
4401  ThrowMogrifyException(OptionError,"UnrecognizedComplexOperator",
4402  argv[i]);
4403  break;
4404  }
4405  if (LocaleCompare("compose",option+1) == 0)
4406  {
4407  ssize_t
4408  compose;
4409 
4410  if (*option == '+')
4411  break;
4412  i++;
4413  if (i == (ssize_t) argc)
4414  ThrowMogrifyException(OptionError,"MissingArgument",option);
4415  compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
4416  argv[i]);
4417  if (compose < 0)
4418  ThrowMogrifyException(OptionError,"UnrecognizedComposeOperator",
4419  argv[i]);
4420  break;
4421  }
4422  if (LocaleCompare("composite",option+1) == 0)
4423  break;
4424  if (LocaleCompare("compress",option+1) == 0)
4425  {
4426  ssize_t
4427  compress;
4428 
4429  if (*option == '+')
4430  break;
4431  i++;
4432  if (i == (ssize_t) argc)
4433  ThrowMogrifyException(OptionError,"MissingArgument",option);
4434  compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
4435  argv[i]);
4436  if (compress < 0)
4437  ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4438  argv[i]);
4439  break;
4440  }
4441  if (LocaleCompare("concurrent",option+1) == 0)
4442  break;
4443  if (LocaleCompare("connected-components",option+1) == 0)
4444  {
4445  i++;
4446  if (i == (ssize_t) argc)
4447  ThrowMogrifyException(OptionError,"MissingArgument",option);
4448  if (IsGeometry(argv[i]) == MagickFalse)
4449  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4450  break;
4451  }
4452  if (LocaleCompare("contrast",option+1) == 0)
4453  break;
4454  if (LocaleCompare("contrast-stretch",option+1) == 0)
4455  {
4456  i++;
4457  if (i == (ssize_t) argc)
4458  ThrowMogrifyException(OptionError,"MissingArgument",option);
4459  if (IsGeometry(argv[i]) == MagickFalse)
4460  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4461  break;
4462  }
4463  if (LocaleCompare("convolve",option+1) == 0)
4464  {
4465  KernelInfo
4466  *kernel_info;
4467 
4468  if (*option == '+')
4469  break;
4470  i++;
4471  if (i == (ssize_t) argc)
4472  ThrowMogrifyException(OptionError,"MissingArgument",option);
4473  kernel_info=AcquireKernelInfo(argv[i]);
4474  if (kernel_info == (KernelInfo *) NULL)
4475  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4476  kernel_info=DestroyKernelInfo(kernel_info);
4477  break;
4478  }
4479  if (LocaleCompare("copy",option+1) == 0)
4480  {
4481  if (*option == '+')
4482  break;
4483  i++;
4484  if (i == (ssize_t) argc)
4485  ThrowMogrifyException(OptionError,"MissingArgument",option);
4486  if (IsGeometry(argv[i]) == MagickFalse)
4487  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4488  i++;
4489  if (i == (ssize_t) argc)
4490  ThrowMogrifyException(OptionError,"MissingArgument",option);
4491  if (IsGeometry(argv[i]) == MagickFalse)
4492  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4493  break;
4494  }
4495  if (LocaleCompare("crop",option+1) == 0)
4496  {
4497  if (*option == '+')
4498  break;
4499  i++;
4500  if (i == (ssize_t) argc)
4501  ThrowMogrifyException(OptionError,"MissingArgument",option);
4502  if (IsGeometry(argv[i]) == MagickFalse)
4503  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4504  break;
4505  }
4506  if (LocaleCompare("cycle",option+1) == 0)
4507  {
4508  if (*option == '+')
4509  break;
4510  i++;
4511  if (i == (ssize_t) argc)
4512  ThrowMogrifyException(OptionError,"MissingArgument",option);
4513  if (IsGeometry(argv[i]) == MagickFalse)
4514  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4515  break;
4516  }
4517  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4518  }
4519  case 'd':
4520  {
4521  if (LocaleCompare("decipher",option+1) == 0)
4522  {
4523  if (*option == '+')
4524  break;
4525  i++;
4526  if (i == (ssize_t) argc)
4527  ThrowMogrifyException(OptionError,"MissingArgument",option);
4528  break;
4529  }
4530  if (LocaleCompare("deconstruct",option+1) == 0)
4531  break;
4532  if (LocaleCompare("debug",option+1) == 0)
4533  {
4534  ssize_t
4535  event;
4536 
4537  if (*option == '+')
4538  break;
4539  i++;
4540  if (i == (ssize_t) argc)
4541  ThrowMogrifyException(OptionError,"MissingArgument",option);
4542  event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
4543  if (event < 0)
4544  ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4545  argv[i]);
4546  (void) SetLogEventMask(argv[i]);
4547  break;
4548  }
4549  if (LocaleCompare("define",option+1) == 0)
4550  {
4551  i++;
4552  if (i == (ssize_t) argc)
4553  ThrowMogrifyException(OptionError,"MissingArgument",option);
4554  if (*option == '+')
4555  {
4556  const char
4557  *define;
4558 
4559  define=GetImageOption(image_info,argv[i]);
4560  if (define == (const char *) NULL)
4561  ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4562  break;
4563  }
4564  break;
4565  }
4566  if (LocaleCompare("delay",option+1) == 0)
4567  {
4568  if (*option == '+')
4569  break;
4570  i++;
4571  if (i == (ssize_t) argc)
4572  ThrowMogrifyException(OptionError,"MissingArgument",option);
4573  if (IsGeometry(argv[i]) == MagickFalse)
4574  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4575  break;
4576  }
4577  if (LocaleCompare("delete",option+1) == 0)
4578  {
4579  if (*option == '+')
4580  break;
4581  i++;
4582  if (i == (ssize_t) argc)
4583  ThrowMogrifyException(OptionError,"MissingArgument",option);
4584  if (LocaleNCompare(argv[i],"registry:",9) == 0)
4585  {
4586  (void) DeleteImageRegistry(argv[i]+9);
4587  break;
4588  }
4589  if (IsGeometry(argv[i]) == MagickFalse)
4590  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4591  break;
4592  }
4593  if (LocaleCompare("density",option+1) == 0)
4594  {
4595  if (*option == '+')
4596  break;
4597  i++;
4598  if (i == (ssize_t) argc)
4599  ThrowMogrifyException(OptionError,"MissingArgument",option);
4600  if (IsGeometry(argv[i]) == MagickFalse)
4601  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4602  break;
4603  }
4604  if (LocaleCompare("depth",option+1) == 0)
4605  {
4606  if (*option == '+')
4607  break;
4608  i++;
4609  if (i == (ssize_t) argc)
4610  ThrowMogrifyException(OptionError,"MissingArgument",option);
4611  if (IsGeometry(argv[i]) == MagickFalse)
4612  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4613  break;
4614  }
4615  if (LocaleCompare("deskew",option+1) == 0)
4616  {
4617  if (*option == '+')
4618  break;
4619  i++;
4620  if (i == (ssize_t) argc)
4621  ThrowMogrifyException(OptionError,"MissingArgument",option);
4622  if (IsGeometry(argv[i]) == MagickFalse)
4623  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4624  break;
4625  }
4626  if (LocaleCompare("despeckle",option+1) == 0)
4627  break;
4628  if (LocaleCompare("dft",option+1) == 0)
4629  break;
4630  if (LocaleCompare("direction",option+1) == 0)
4631  {
4632  ssize_t
4633  direction;
4634 
4635  if (*option == '+')
4636  break;
4637  i++;
4638  if (i == (ssize_t) argc)
4639  ThrowMogrifyException(OptionError,"MissingArgument",option);
4640  direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
4641  argv[i]);
4642  if (direction < 0)
4643  ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4644  argv[i]);
4645  break;
4646  }
4647  if (LocaleCompare("display",option+1) == 0)
4648  {
4649  if (*option == '+')
4650  break;
4651  i++;
4652  if (i == (ssize_t) argc)
4653  ThrowMogrifyException(OptionError,"MissingArgument",option);
4654  break;
4655  }
4656  if (LocaleCompare("dispose",option+1) == 0)
4657  {
4658  ssize_t
4659  dispose;
4660 
4661  if (*option == '+')
4662  break;
4663  i++;
4664  if (i == (ssize_t) argc)
4665  ThrowMogrifyException(OptionError,"MissingArgument",option);
4666  dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,
4667  argv[i]);
4668  if (dispose < 0)
4669  ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4670  argv[i]);
4671  break;
4672  }
4673  if (LocaleCompare("distort",option+1) == 0)
4674  {
4675  ssize_t
4676  op;
4677 
4678  i++;
4679  if (i == (ssize_t) argc)
4680  ThrowMogrifyException(OptionError,"MissingArgument",option);
4681  op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
4682  if (op < 0)
4683  ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4684  argv[i]);
4685  i++;
4686  if (i == (ssize_t) argc)
4687  ThrowMogrifyException(OptionError,"MissingArgument",option);
4688  break;
4689  }
4690  if (LocaleCompare("dither",option+1) == 0)
4691  {
4692  ssize_t
4693  method;
4694 
4695  if (*option == '+')
4696  break;
4697  i++;
4698  if (i == (ssize_t) argc)
4699  ThrowMogrifyException(OptionError,"MissingArgument",option);
4700  method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
4701  if (method < 0)
4702  ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4703  argv[i]);
4704  break;
4705  }
4706  if (LocaleCompare("draw",option+1) == 0)
4707  {
4708  if (*option == '+')
4709  break;
4710  i++;
4711  if (i == (ssize_t) argc)
4712  ThrowMogrifyException(OptionError,"MissingArgument",option);
4713  break;
4714  }
4715  if (LocaleCompare("duplicate",option+1) == 0)
4716  {
4717  if (*option == '+')
4718  break;
4719  i++;
4720  if (i == (ssize_t) argc)
4721  ThrowMogrifyException(OptionError,"MissingArgument",option);
4722  if (IsGeometry(argv[i]) == MagickFalse)
4723  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4724  break;
4725  }
4726  if (LocaleCompare("duration",option+1) == 0)
4727  {
4728  if (*option == '+')
4729  break;
4730  i++;
4731  if (i == (ssize_t) argc)
4732  ThrowMogrifyException(OptionError,"MissingArgument",option);
4733  if (IsGeometry(argv[i]) == MagickFalse)
4734  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4735  break;
4736  }
4737  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4738  }
4739  case 'e':
4740  {
4741  if (LocaleCompare("edge",option+1) == 0)
4742  {
4743  if (*option == '+')
4744  break;
4745  i++;
4746  if (i == (ssize_t) argc)
4747  ThrowMogrifyException(OptionError,"MissingArgument",option);
4748  if (IsGeometry(argv[i]) == MagickFalse)
4749  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4750  break;
4751  }
4752  if (LocaleCompare("emboss",option+1) == 0)
4753  {
4754  if (*option == '+')
4755  break;
4756  i++;
4757  if (i == (ssize_t) argc)
4758  ThrowMogrifyException(OptionError,"MissingArgument",option);
4759  if (IsGeometry(argv[i]) == MagickFalse)
4760  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4761  break;
4762  }
4763  if (LocaleCompare("encipher",option+1) == 0)
4764  {
4765  if (*option == '+')
4766  break;
4767  i++;
4768  if (i == (ssize_t) argc)
4769  ThrowMogrifyException(OptionError,"MissingArgument",option);
4770  break;
4771  }
4772  if (LocaleCompare("encoding",option+1) == 0)
4773  {
4774  if (*option == '+')
4775  break;
4776  i++;
4777  if (i == (ssize_t) argc)
4778  ThrowMogrifyException(OptionError,"MissingArgument",option);
4779  break;
4780  }
4781  if (LocaleCompare("endian",option+1) == 0)
4782  {
4783  ssize_t
4784  endian;
4785 
4786  if (*option == '+')
4787  break;
4788  i++;
4789  if (i == (ssize_t) argc)
4790  ThrowMogrifyException(OptionError,"MissingArgument",option);
4791  endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
4792  if (endian < 0)
4793  ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4794  argv[i]);
4795  break;
4796  }
4797  if (LocaleCompare("enhance",option+1) == 0)
4798  break;
4799  if (LocaleCompare("equalize",option+1) == 0)
4800  break;
4801  if (LocaleCompare("evaluate",option+1) == 0)
4802  {
4803  ssize_t
4804  op;
4805 
4806  if (*option == '+')
4807  break;
4808  i++;
4809  if (i == (ssize_t) argc)
4810  ThrowMogrifyException(OptionError,"MissingArgument",option);
4811  op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4812  if (op < 0)
4813  ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4814  argv[i]);
4815  i++;
4816  if (i == (ssize_t) argc)
4817  ThrowMogrifyException(OptionError,"MissingArgument",option);
4818  if (IsGeometry(argv[i]) == MagickFalse)
4819  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4820  break;
4821  }
4822  if (LocaleCompare("evaluate-sequence",option+1) == 0)
4823  {
4824  ssize_t
4825  op;
4826 
4827  if (*option == '+')
4828  break;
4829  i++;
4830  if (i == (ssize_t) argc)
4831  ThrowMogrifyException(OptionError,"MissingArgument",option);
4832  op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4833  if (op < 0)
4834  ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4835  argv[i]);
4836  break;
4837  }
4838  if (LocaleCompare("extent",option+1) == 0)
4839  {
4840  if (*option == '+')
4841  break;
4842  i++;
4843  if (i == (ssize_t) argc)
4844  ThrowMogrifyException(OptionError,"MissingArgument",option);
4845  if (IsGeometry(argv[i]) == MagickFalse)
4846  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4847  break;
4848  }
4849  if (LocaleCompare("extract",option+1) == 0)
4850  {
4851  if (*option == '+')
4852  break;
4853  i++;
4854  if (i == (ssize_t) argc)
4855  ThrowMogrifyException(OptionError,"MissingArgument",option);
4856  if (IsGeometry(argv[i]) == MagickFalse)
4857  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4858  break;
4859  }
4860  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4861  }
4862  case 'f':
4863  {
4864  if (LocaleCompare("family",option+1) == 0)
4865  {
4866  if (*option == '+')
4867  break;
4868  i++;
4869  if (i == (ssize_t) argc)
4870  ThrowMogrifyException(OptionError,"MissingArgument",option);
4871  break;
4872  }
4873  if (LocaleCompare("features",option+1) == 0)
4874  {
4875  if (*option == '+')
4876  break;
4877  i++;
4878  if (i == (ssize_t) argc)
4879  ThrowMogrifyException(OptionError,"MissingArgument",option);
4880  if (IsGeometry(argv[i]) == MagickFalse)
4881  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4882  break;
4883  }
4884  if (LocaleCompare("fill",option+1) == 0)
4885  {
4886  if (*option == '+')
4887  break;
4888  i++;
4889  if (i == (ssize_t) argc)
4890  ThrowMogrifyException(OptionError,"MissingArgument",option);
4891  break;
4892  }
4893  if (LocaleCompare("filter",option+1) == 0)
4894  {
4895  ssize_t
4896  filter;
4897 
4898  if (*option == '+')
4899  break;
4900  i++;
4901  if (i == (ssize_t) argc)
4902  ThrowMogrifyException(OptionError,"MissingArgument",option);
4903  filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
4904  if (filter < 0)
4905  ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4906  argv[i]);
4907  break;
4908  }
4909  if (LocaleCompare("flatten",option+1) == 0)
4910  break;
4911  if (LocaleCompare("flip",option+1) == 0)
4912  break;
4913  if (LocaleCompare("flop",option+1) == 0)
4914  break;
4915  if (LocaleCompare("floodfill",option+1) == 0)
4916  {
4917  if (*option == '+')
4918  break;
4919  i++;
4920  if (i == (ssize_t) argc)
4921  ThrowMogrifyException(OptionError,"MissingArgument",option);
4922  if (IsGeometry(argv[i]) == MagickFalse)
4923  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4924  i++;
4925  if (i == (ssize_t) argc)
4926  ThrowMogrifyException(OptionError,"MissingArgument",option);
4927  break;
4928  }
4929  if (LocaleCompare("font",option+1) == 0)
4930  {
4931  if (*option == '+')
4932  break;
4933  i++;
4934  if (i == (ssize_t) argc)
4935  ThrowMogrifyException(OptionError,"MissingArgument",option);
4936  break;
4937  }
4938  if (LocaleCompare("format",option+1) == 0)
4939  {
4940  (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4941  (void) CloneString(&format,(char *) NULL);
4942  if (*option == '+')
4943  break;
4944  i++;
4945  if (i == (ssize_t) argc)
4946  ThrowMogrifyException(OptionError,"MissingArgument",option);
4947  (void) CloneString(&format,argv[i]);
4948  (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4949  (void) ConcatenateMagickString(image_info->filename,":",
4950  MaxTextExtent);
4951  (void) SetImageInfo(image_info,0,exception);
4952  if (*image_info->magick == '\0')
4953  ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4954  format);
4955  break;
4956  }
4957  if (LocaleCompare("frame",option+1) == 0)
4958  {
4959  if (*option == '+')
4960  break;
4961  i++;
4962  if (i == (ssize_t) argc)
4963  ThrowMogrifyException(OptionError,"MissingArgument",option);
4964  if (IsGeometry(argv[i]) == MagickFalse)
4965  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4966  break;
4967  }
4968  if (LocaleCompare("function",option+1) == 0)
4969  {
4970  ssize_t
4971  op;
4972 
4973  if (*option == '+')
4974  break;
4975  i++;
4976  if (i == (ssize_t) argc)
4977  ThrowMogrifyException(OptionError,"MissingArgument",option);
4978  op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
4979  if (op < 0)
4980  ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4981  i++;
4982  if (i == (ssize_t) argc)
4983  ThrowMogrifyException(OptionError,"MissingArgument",option);
4984  break;
4985  }
4986  if (LocaleCompare("fuzz",option+1) == 0)
4987  {
4988  if (*option == '+')
4989  break;
4990  i++;
4991  if (i == (ssize_t) argc)
4992  ThrowMogrifyException(OptionError,"MissingArgument",option);
4993  if (IsGeometry(argv[i]) == MagickFalse)
4994  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4995  break;
4996  }
4997  if (LocaleCompare("fx",option+1) == 0)
4998  {
4999  if (*option == '+')
5000  break;
5001  i++;
5002  if (i == (ssize_t) argc)
5003  ThrowMogrifyException(OptionError,"MissingArgument",option);
5004  break;
5005  }
5006  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5007  }
5008  case 'g':
5009  {
5010  if (LocaleCompare("gamma",option+1) == 0)
5011  {
5012  i++;
5013  if (i == (ssize_t) argc)
5014  ThrowMogrifyException(OptionError,"MissingArgument",option);
5015  if (IsGeometry(argv[i]) == MagickFalse)
5016  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5017  break;
5018  }
5019  if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5020  (LocaleCompare("gaussian",option+1) == 0))
5021  {
5022  i++;
5023  if (i == (ssize_t) argc)
5024  ThrowMogrifyException(OptionError,"MissingArgument",option);
5025  if (IsGeometry(argv[i]) == MagickFalse)
5026  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5027  break;
5028  }
5029  if (LocaleCompare("geometry",option+1) == 0)
5030  {
5031  if (*option == '+')
5032  break;
5033  i++;
5034  if (i == (ssize_t) argc)
5035  ThrowMogrifyException(OptionError,"MissingArgument",option);
5036  if (IsGeometry(argv[i]) == MagickFalse)
5037  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5038  break;
5039  }
5040  if (LocaleCompare("gravity",option+1) == 0)
5041  {
5042  ssize_t
5043  gravity;
5044 
5045  if (*option == '+')
5046  break;
5047  i++;
5048  if (i == (ssize_t) argc)
5049  ThrowMogrifyException(OptionError,"MissingArgument",option);
5050  gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
5051  argv[i]);
5052  if (gravity < 0)
5053  ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5054  argv[i]);
5055  break;
5056  }
5057  if (LocaleCompare("grayscale",option+1) == 0)
5058  {
5059  ssize_t
5060  method;
5061 
5062  if (*option == '+')
5063  break;
5064  i++;
5065  if (i == (ssize_t) argc)
5066  ThrowMogrifyException(OptionError,"MissingArgument",option);
5067  method=ParseCommandOption(MagickPixelIntensityOptions,MagickFalse,
5068  argv[i]);
5069  if (method < 0)
5070  ThrowMogrifyException(OptionError,"UnrecognizedIntensityMethod",
5071  argv[i]);
5072  break;
5073  }
5074  if (LocaleCompare("green-primary",option+1) == 0)
5075  {
5076  if (*option == '+')
5077  break;
5078  i++;
5079  if (i == (ssize_t) argc)
5080  ThrowMogrifyException(OptionError,"MissingArgument",option);
5081  if (IsGeometry(argv[i]) == MagickFalse)
5082  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5083  break;
5084  }
5085  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5086  }
5087  case 'h':
5088  {
5089  if (LocaleCompare("hald-clut",option+1) == 0)
5090  break;
5091  if (LocaleCompare("hough-lines",option+1) == 0)
5092  {
5093  if (*option == '+')
5094  break;
5095  i++;
5096  if (i == (ssize_t) argc)
5097  ThrowMogrifyException(OptionError,"MissingArgument",option);
5098  if (IsGeometry(argv[i]) == MagickFalse)
5099  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5100  break;
5101  }
5102  if ((LocaleCompare("help",option+1) == 0) ||
5103  (LocaleCompare("-help",option+1) == 0))
5104  {
5105  DestroyMogrify();
5106  return(MogrifyUsage());
5107  }
5108  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5109  }
5110  case 'i':
5111  {
5112  if (LocaleCompare("identify",option+1) == 0)
5113  break;
5114  if (LocaleCompare("idft",option+1) == 0)
5115  break;
5116  if (LocaleCompare("implode",option+1) == 0)
5117  {
5118  if (*option == '+')
5119  break;
5120  i++;
5121  if (i == (ssize_t) argc)
5122  ThrowMogrifyException(OptionError,"MissingArgument",option);
5123  if (IsGeometry(argv[i]) == MagickFalse)
5124  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5125  break;
5126  }
5127  if (LocaleCompare("intensity",option+1) == 0)
5128  {
5129  ssize_t
5130  intensity;
5131 
5132  if (*option == '+')
5133  break;
5134  i++;
5135  if (i == (ssize_t) argc)
5136  ThrowMogrifyException(OptionError,"MissingArgument",option);
5137  intensity=ParseCommandOption(MagickPixelIntensityOptions,
5138  MagickFalse,argv[i]);
5139  if (intensity < 0)
5140  ThrowMogrifyException(OptionError,
5141  "UnrecognizedPixelIntensityMethod",argv[i]);
5142  break;
5143  }
5144  if (LocaleCompare("intent",option+1) == 0)
5145  {
5146  ssize_t
5147  intent;
5148 
5149  if (*option == '+')
5150  break;
5151  i++;
5152  if (i == (ssize_t) argc)
5153  ThrowMogrifyException(OptionError,"MissingArgument",option);
5154  intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
5155  if (intent < 0)
5156  ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5157  argv[i]);
5158  break;
5159  }
5160  if (LocaleCompare("interlace",option+1) == 0)
5161  {
5162  ssize_t
5163  interlace;
5164 
5165  if (*option == '+')
5166  break;
5167  i++;
5168  if (i == (ssize_t) argc)
5169  ThrowMogrifyException(OptionError,"MissingArgument",option);
5170  interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
5171  argv[i]);
5172  if (interlace < 0)
5173  ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5174  argv[i]);
5175  break;
5176  }
5177  if (LocaleCompare("interline-spacing",option+1) == 0)
5178  {
5179  if (*option == '+')
5180  break;
5181  i++;
5182  if (i == (ssize_t) argc)
5183  ThrowMogrifyException(OptionError,"MissingArgument",option);
5184  if (IsGeometry(argv[i]) == MagickFalse)
5185  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5186  break;
5187  }
5188  if (LocaleCompare("interpolate",option+1) == 0)
5189  {
5190  ssize_t
5191  interpolate;
5192 
5193  if (*option == '+')
5194  break;
5195  i++;
5196  if (i == (ssize_t) argc)
5197  ThrowMogrifyException(OptionError,"MissingArgument",option);
5198  interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
5199  argv[i]);
5200  if (interpolate < 0)
5201  ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5202  argv[i]);
5203  break;
5204  }
5205  if (LocaleCompare("interword-spacing",option+1) == 0)
5206  {
5207  if (*option == '+')
5208  break;
5209  i++;
5210  if (i == (ssize_t) argc)
5211  ThrowMogrifyException(OptionError,"MissingArgument",option);
5212  if (IsGeometry(argv[i]) == MagickFalse)
5213  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5214  break;
5215  }
5216  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5217  }
5218  case 'k':
5219  {
5220  if (LocaleCompare("kerning",option+1) == 0)
5221  {
5222  if (*option == '+')
5223  break;
5224  i++;
5225  if (i == (ssize_t) argc)
5226  ThrowMogrifyException(OptionError,"MissingArgument",option);
5227  if (IsGeometry(argv[i]) == MagickFalse)
5228  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5229  break;
5230  }
5231  if (LocaleCompare("kuwahara",option+1) == 0)
5232  {
5233  i++;
5234  if (i == (ssize_t) argc)
5235  ThrowMogrifyException(OptionError,"MissingArgument",option);
5236  if (IsGeometry(argv[i]) == MagickFalse)
5237  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5238  break;
5239  }
5240  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5241  }
5242  case 'l':
5243  {
5244  if (LocaleCompare("label",option+1) == 0)
5245  {
5246  if (*option == '+')
5247  break;
5248  i++;
5249  if (i == (ssize_t) argc)
5250  ThrowMogrifyException(OptionError,"MissingArgument",option);
5251  break;
5252  }
5253  if (LocaleCompare("lat",option+1) == 0)
5254  {
5255  if (*option == '+')
5256  break;
5257  i++;
5258  if (i == (ssize_t) argc)
5259  ThrowMogrifyException(OptionError,"MissingArgument",option);
5260  if (IsGeometry(argv[i]) == MagickFalse)
5261  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5262  break;
5263  }
5264  if (LocaleCompare("layers",option+1) == 0)
5265  {
5266  ssize_t
5267  type;
5268 
5269  if (*option == '+')
5270  break;
5271  i++;
5272  if (i == (ssize_t) argc)
5273  ThrowMogrifyException(OptionError,"MissingArgument",option);
5274  type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
5275  if (type < 0)
5276  ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5277  argv[i]);
5278  break;
5279  }
5280  if (LocaleCompare("level",option+1) == 0)
5281  {
5282  i++;
5283  if (i == (ssize_t) argc)
5284  ThrowMogrifyException(OptionError,"MissingArgument",option);
5285  if (IsGeometry(argv[i]) == MagickFalse)
5286  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5287  break;
5288  }
5289  if (LocaleCompare("level-colors",option+1) == 0)
5290  {
5291  i++;
5292  if (i == (ssize_t) argc)
5293  ThrowMogrifyException(OptionError,"MissingArgument",option);
5294  break;
5295  }
5296  if (LocaleCompare("linewidth",option+1) == 0)
5297  {
5298  if (*option == '+')
5299  break;
5300  i++;
5301  if (i == (ssize_t) argc)
5302  ThrowMogrifyException(OptionError,"MissingArgument",option);
5303  if (IsGeometry(argv[i]) == MagickFalse)
5304  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5305  break;
5306  }
5307  if (LocaleCompare("limit",option+1) == 0)
5308  {
5309  char
5310  *p;
5311 
5312  double
5313  value;
5314 
5315  ssize_t
5316  resource;
5317 
5318  if (*option == '+')
5319  break;
5320  i++;
5321  if (i == (ssize_t) argc)
5322  ThrowMogrifyException(OptionError,"MissingArgument",option);
5323  resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
5324  argv[i]);
5325  if (resource < 0)
5326  ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5327  argv[i]);
5328  i++;
5329  if (i == (ssize_t) argc)
5330  ThrowMogrifyException(OptionError,"MissingArgument",option);
5331  value=StringToDouble(argv[i],&p);
5332  (void) value;
5333  if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5334  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5335  break;
5336  }
5337  if (LocaleCompare("liquid-rescale",option+1) == 0)
5338  {
5339  i++;
5340  if (i == (ssize_t) argc)
5341  ThrowMogrifyException(OptionError,"MissingArgument",option);
5342  if (IsGeometry(argv[i]) == MagickFalse)
5343  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5344  break;
5345  }
5346  if (LocaleCompare("list",option+1) == 0)
5347  {
5348  ssize_t
5349  list;
5350 
5351  if (*option == '+')
5352  break;
5353  i++;
5354  if (i == (ssize_t) argc)
5355  ThrowMogrifyException(OptionError,"MissingArgument",option);
5356  list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
5357  if (list < 0)
5358  ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
5359  status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
5360  argv+j,exception);
5361  return(status == 0 ? MagickFalse : MagickTrue);
5362  }
5363  if (LocaleCompare("local-contrast",option+1) == 0)
5364  {
5365  i++;
5366  if (i == (ssize_t) argc)
5367  ThrowMogrifyException(OptionError,"MissingArgument",option);
5368  if (IsGeometry(argv[i]) == MagickFalse)
5369  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5370  break;
5371  }
5372  if (LocaleCompare("log",option+1) == 0)
5373  {
5374  if (*option == '+')
5375  break;
5376  i++;
5377  if ((i == (ssize_t) argc) ||
5378  (strchr(argv[i],'%') == (char *) NULL))
5379  ThrowMogrifyException(OptionError,"MissingArgument",option);
5380  break;
5381  }
5382  if (LocaleCompare("loop",option+1) == 0)
5383  {
5384  if (*option == '+')
5385  break;
5386  i++;
5387  if (i == (ssize_t) argc)
5388  ThrowMogrifyException(OptionError,"MissingArgument",option);
5389  if (IsGeometry(argv[i]) == MagickFalse)
5390  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5391  break;
5392  }
5393  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5394  }
5395  case 'm':
5396  {
5397  if (LocaleCompare("magnify",option+1) == 0)
5398  break;
5399  if (LocaleCompare("map",option+1) == 0)
5400  {
5401  global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5402  if (*option == '+')
5403  break;
5404  i++;
5405  if (i == (ssize_t) argc)
5406  ThrowMogrifyException(OptionError,"MissingArgument",option);
5407  break;
5408  }
5409  if (LocaleCompare("mask",option+1) == 0)
5410  {
5411  if (*option == '+')
5412  break;
5413  i++;
5414  if (i == (ssize_t) argc)
5415  ThrowMogrifyException(OptionError,"MissingArgument",option);
5416  break;
5417  }
5418  if (LocaleCompare("matte",option+1) == 0)
5419  break;
5420  if (LocaleCompare("mattecolor",option+1) == 0)
5421  {
5422  if (*option == '+')
5423  break;
5424  i++;
5425  if (i == (ssize_t) argc)
5426  ThrowMogrifyException(OptionError,"MissingArgument",option);
5427  break;
5428  }
5429  if (LocaleCompare("metric",option+1) == 0)
5430  {
5431  ssize_t
5432  type;
5433 
5434  if (*option == '+')
5435  break;
5436  i++;
5437  if (i == (ssize_t) argc)
5438  ThrowMogrifyException(OptionError,"MissingArgument",option);
5439  type=ParseCommandOption(MagickMetricOptions,MagickTrue,argv[i]);
5440  if (type < 0)
5441  ThrowMogrifyException(OptionError,"UnrecognizedMetricType",
5442  argv[i]);
5443  break;
5444  }
5445  if (LocaleCompare("maximum",option+1) == 0)
5446  break;
5447  if (LocaleCompare("mean-shift",option+1) == 0)
5448  {
5449  if (*option == '+')
5450  break;
5451  i++;
5452  if (i == (ssize_t) argc)
5453  ThrowMogrifyException(OptionError,"MissingArgument",option);
5454  if (IsGeometry(argv[i]) == MagickFalse)
5455  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5456  break;
5457  }
5458  if (LocaleCompare("median",option+1) == 0)
5459  {
5460  if (*option == '+')
5461  break;
5462  i++;
5463  if (i == (ssize_t) argc)
5464  ThrowMogrifyException(OptionError,"MissingArgument",option);
5465  if (IsGeometry(argv[i]) == MagickFalse)
5466  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5467  break;
5468  }
5469  if (LocaleCompare("minimum",option+1) == 0)
5470  break;
5471  if (LocaleCompare("modulate",option+1) == 0)
5472  {
5473  if (*option == '+')
5474  break;
5475  i++;
5476  if (i == (ssize_t) argc)
5477  ThrowMogrifyException(OptionError,"MissingArgument",option);
5478  if (IsGeometry(argv[i]) == MagickFalse)
5479  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5480  break;
5481  }
5482  if (LocaleCompare("mode",option+1) == 0)
5483  {
5484  if (*option == '+')
5485  break;
5486  i++;
5487  if (i == (ssize_t) argc)
5488  ThrowMogrifyException(OptionError,"MissingArgument",option);
5489  if (IsGeometry(argv[i]) == MagickFalse)
5490  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5491  break;
5492  }
5493  if (LocaleCompare("monitor",option+1) == 0)
5494  break;
5495  if (LocaleCompare("monochrome",option+1) == 0)
5496  break;
5497  if (LocaleCompare("morph",option+1) == 0)
5498  {
5499  if (*option == '+')
5500  break;
5501  i++;
5502  if (i == (ssize_t) argc)
5503  ThrowMogrifyException(OptionError,"MissingArgument",option);
5504  if (IsGeometry(argv[i]) == MagickFalse)
5505  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5506  break;
5507  }
5508  if (LocaleCompare("morphology",option+1) == 0)
5509  {
5510  char
5511  token[MaxTextExtent];
5512 
5513  KernelInfo
5514  *kernel_info;
5515 
5516  ssize_t
5517  op;
5518 
5519  i++;
5520  if (i == (ssize_t) argc)
5521  ThrowMogrifyException(OptionError,"MissingArgument",option);
5522  (void) GetNextToken(argv[i],(const char **) NULL,MaxTextExtent,token);
5523  op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
5524  if (op < 0)
5525  ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
5526  token);
5527  i++;
5528  if (i == (ssize_t) argc)
5529  ThrowMogrifyException(OptionError,"MissingArgument",option);
5530  kernel_info=AcquireKernelInfo(argv[i]);
5531  if (kernel_info == (KernelInfo *) NULL)
5532  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5533  kernel_info=DestroyKernelInfo(kernel_info);
5534  break;
5535  }
5536  if (LocaleCompare("mosaic",option+1) == 0)
5537  break;
5538  if (LocaleCompare("motion-blur",option+1) == 0)
5539  {
5540  if (*option == '+')
5541  break;
5542  i++;
5543  if (i == (ssize_t) argc)
5544  ThrowMogrifyException(OptionError,"MissingArgument",option);
5545  if (IsGeometry(argv[i]) == MagickFalse)
5546  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5547  break;
5548  }
5549  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5550  }
5551  case 'n':
5552  {
5553  if (LocaleCompare("negate",option+1) == 0)
5554  break;
5555  if (LocaleCompare("noise",option+1) == 0)
5556  {
5557  i++;
5558  if (i == (ssize_t) argc)
5559  ThrowMogrifyException(OptionError,"MissingArgument",option);
5560  if (*option == '+')
5561  {
5562  ssize_t
5563  noise;
5564 
5565  noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
5566  if (noise < 0)
5567  ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5568  argv[i]);
5569  break;
5570  }
5571  if (IsGeometry(argv[i]) == MagickFalse)
5572  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5573  break;
5574  }
5575  if (LocaleCompare("noop",option+1) == 0)
5576  break;
5577  if (LocaleCompare("normalize",option+1) == 0)
5578  break;
5579  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5580  }
5581  case 'o':
5582  {
5583  if (LocaleCompare("opaque",option+1) == 0)
5584  {
5585  i++;
5586  if (i == (ssize_t) argc)
5587  ThrowMogrifyException(OptionError,"MissingArgument",option);
5588  break;
5589  }
5590  if (LocaleCompare("ordered-dither",option+1) == 0)
5591  {
5592  if (*option == '+')
5593  break;
5594  i++;
5595  if (i == (ssize_t) argc)
5596  ThrowMogrifyException(OptionError,"MissingArgument",option);
5597  break;
5598  }
5599  if (LocaleCompare("orient",option+1) == 0)
5600  {
5601  ssize_t
5602  orientation;
5603 
5604  orientation=UndefinedOrientation;
5605  if (*option == '+')
5606  break;
5607  i++;
5608  if (i == (ssize_t) argc)
5609  ThrowMogrifyException(OptionError,"MissingArgument",option);
5610  orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
5611  argv[i]);
5612  if (orientation < 0)
5613  ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5614  argv[i]);
5615  break;
5616  }
5617  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5618  }
5619  case 'p':
5620  {
5621  if (LocaleCompare("page",option+1) == 0)
5622  {
5623  if (*option == '+')
5624  break;
5625  i++;
5626  if (i == (ssize_t) argc)
5627  ThrowMogrifyException(OptionError,"MissingArgument",option);
5628  break;
5629  }
5630  if (LocaleCompare("paint",option+1) == 0)
5631  {
5632  if (*option == '+')
5633  break;
5634  i++;
5635  if (i == (ssize_t) argc)
5636  ThrowMogrifyException(OptionError,"MissingArgument",option);
5637  if (IsGeometry(argv[i]) == MagickFalse)
5638  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5639  break;
5640  }
5641  if (LocaleCompare("path",option+1) == 0)
5642  {
5643  (void) CloneString(&path,(char *) NULL);
5644  if (*option == '+')
5645  break;
5646  i++;
5647  if (i == (ssize_t) argc)
5648  ThrowMogrifyException(OptionError,"MissingArgument",option);
5649  (void) CloneString(&path,argv[i]);
5650  break;
5651  }
5652  if (LocaleCompare("perceptible",option+1) == 0)
5653  {
5654  if (*option == '+')
5655  break;
5656  i++;
5657  if (i == (ssize_t) argc)
5658  ThrowMogrifyException(OptionError,"MissingArgument",option);
5659  if (IsGeometry(argv[i]) == MagickFalse)
5660  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5661  break;
5662  }
5663  if (LocaleCompare("pointsize",option+1) == 0)
5664  {
5665  if (*option == '+')
5666  break;
5667  i++;
5668  if (i == (ssize_t) argc)
5669  ThrowMogrifyException(OptionError,"MissingArgument",option);
5670  if (IsGeometry(argv[i]) == MagickFalse)
5671  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5672  break;
5673  }
5674  if (LocaleCompare("polaroid",option+1) == 0)
5675  {
5676  if (*option == '+')
5677  break;
5678  i++;
5679  if (i == (ssize_t) argc)
5680  ThrowMogrifyException(OptionError,"MissingArgument",option);
5681  if (IsGeometry(argv[i]) == MagickFalse)
5682  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5683  break;
5684  }
5685  if (LocaleCompare("poly",option+1) == 0)
5686  {
5687  if (*option == '+')
5688  break;
5689  i++;
5690  if (i == (ssize_t) argc)
5691  ThrowMogrifyException(OptionError,"MissingArgument",option);
5692  if (IsGeometry(argv[i]) == MagickFalse)
5693  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5694  break;
5695  }
5696  if (LocaleCompare("posterize",option+1) == 0)
5697  {
5698  if (*option == '+')
5699  break;
5700  i++;
5701  if (i == (ssize_t) argc)
5702  ThrowMogrifyException(OptionError,"MissingArgument",option);
5703  if (IsGeometry(argv[i]) == MagickFalse)
5704  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5705  break;
5706  }
5707  if (LocaleCompare("precision",option+1) == 0)
5708  {
5709  if (*option == '+')
5710  break;
5711  i++;
5712  if (i == (ssize_t) argc)
5713  ThrowMogrifyException(OptionError,"MissingArgument",option);
5714  if (IsGeometry(argv[i]) == MagickFalse)
5715  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5716  break;
5717  }
5718  if (LocaleCompare("print",option+1) == 0)
5719  {
5720  if (*option == '+')
5721  break;
5722  i++;
5723  if (i == (ssize_t) argc)
5724  ThrowMogrifyException(OptionError,"MissingArgument",option);
5725  break;
5726  }
5727  if (LocaleCompare("process",option+1) == 0)
5728  {
5729  if (*option == '+')
5730  break;
5731  i++;
5732  if (i == (ssize_t) argc)
5733  ThrowMogrifyException(OptionError,"MissingArgument",option);
5734  break;
5735  }
5736  if (LocaleCompare("profile",option+1) == 0)
5737  {
5738  i++;
5739  if (i == (ssize_t) argc)
5740  ThrowMogrifyException(OptionError,"MissingArgument",option);
5741  break;
5742  }
5743  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5744  }
5745  case 'q':
5746  {
5747  if (LocaleCompare("quality",option+1) == 0)
5748  {
5749  if (*option == '+')
5750  break;
5751  i++;
5752  if (i == (ssize_t) argc)
5753  ThrowMogrifyException(OptionError,"MissingArgument",option);
5754  if (IsGeometry(argv[i]) == MagickFalse)
5755  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5756  break;
5757  }
5758  if (LocaleCompare("quantize",option+1) == 0)
5759  {
5760  ssize_t
5761  colorspace;
5762 
5763  if (*option == '+')
5764  break;
5765  i++;
5766  if (i == (ssize_t) argc)
5767  ThrowMogrifyException(OptionError,"MissingArgument",option);
5768  colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
5769  argv[i]);
5770  if (colorspace < 0)
5771  ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5772  argv[i]);
5773  break;
5774  }
5775  if (LocaleCompare("quiet",option+1) == 0)
5776  break;
5777  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5778  }
5779  case 'r':
5780  {
5781  if (LocaleCompare("radial-blur",option+1) == 0 ||
5782  LocaleCompare("rotational-blur",option+1) == 0)
5783  {
5784  i++;
5785  if (i == (ssize_t) argc)
5786  ThrowMogrifyException(OptionError,"MissingArgument",option);
5787  if (IsGeometry(argv[i]) == MagickFalse)
5788  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5789  break;
5790  }
5791  if (LocaleCompare("raise",option+1) == 0)
5792  {
5793  i++;
5794  if (i == (ssize_t) argc)
5795  ThrowMogrifyException(OptionError,"MissingArgument",option);
5796  if (IsGeometry(argv[i]) == MagickFalse)
5797  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5798  break;
5799  }
5800  if (LocaleCompare("random-threshold",option+1) == 0)
5801  {
5802  if (*option == '+')
5803  break;
5804  i++;
5805  if (i == (ssize_t) argc)
5806  ThrowMogrifyException(OptionError,"MissingArgument",option);
5807  if (IsGeometry(argv[i]) == MagickFalse)
5808  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5809  break;
5810  }
5811  if (LocaleCompare("recolor",option+1) == 0)
5812  {
5813  if (*option == '+')
5814  break;
5815  i++;
5816  if (i == (ssize_t) argc)
5817  ThrowMogrifyException(OptionError,"MissingArgument",option);
5818  if (IsGeometry(argv[i]) == MagickFalse)
5819  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5820  break;
5821  }
5822  if (LocaleCompare("red-primary",option+1) == 0)
5823  {
5824  if (*option == '+')
5825  break;
5826  i++;
5827  if (i == (ssize_t) argc)
5828  ThrowMogrifyException(OptionError,"MissingArgument",option);
5829  if (IsGeometry(argv[i]) == MagickFalse)
5830  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5831  }
5832  if (LocaleCompare("regard-warnings",option+1) == 0)
5833  break;
5834  if (LocaleCompare("region",option+1) == 0)
5835  {
5836  if (*option == '+')
5837  break;
5838  i++;
5839  if (i == (ssize_t) argc)
5840  ThrowMogrifyException(OptionError,"MissingArgument",option);
5841  if (IsGeometry(argv[i]) == MagickFalse)
5842  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5843  break;
5844  }
5845  if (LocaleCompare("remap",option+1) == 0)
5846  {
5847  if (*option == '+')
5848  break;
5849  i++;
5850  if (i == (ssize_t) argc)
5851  ThrowMogrifyException(OptionError,"MissingArgument",option);
5852  break;
5853  }
5854  if (LocaleCompare("render",option+1) == 0)
5855  break;
5856  if (LocaleCompare("repage",option+1) == 0)
5857  {
5858  if (*option == '+')
5859  break;
5860  i++;
5861  if (i == (ssize_t) argc)
5862  ThrowMogrifyException(OptionError,"MissingArgument",option);
5863  if (IsGeometry(argv[i]) == MagickFalse)
5864  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5865  break;
5866  }
5867  if (LocaleCompare("resample",option+1) == 0)
5868  {
5869  if (*option == '+')
5870  break;
5871  i++;
5872  if (i == (ssize_t) argc)
5873  ThrowMogrifyException(OptionError,"MissingArgument",option);
5874  if (IsGeometry(argv[i]) == MagickFalse)
5875  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5876  break;
5877  }
5878  if (LocaleCompare("resize",option+1) == 0)
5879  {
5880  if (*option == '+')
5881  break;
5882  i++;
5883  if (i == (ssize_t) argc)
5884  ThrowMogrifyException(OptionError,"MissingArgument",option);
5885  if (IsGeometry(argv[i]) == MagickFalse)
5886  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5887  break;
5888  }
5889  if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5890  {
5891  respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5892  break;
5893  }
5894  if (LocaleCompare("reverse",option+1) == 0)
5895  break;
5896  if (LocaleCompare("roll",option+1) == 0)
5897  {
5898  if (*option == '+')
5899  break;
5900  i++;
5901  if (i == (ssize_t) argc)
5902  ThrowMogrifyException(OptionError,"MissingArgument",option);
5903  if (IsGeometry(argv[i]) == MagickFalse)
5904  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5905  break;
5906  }
5907  if (LocaleCompare("rotate",option+1) == 0)
5908  {
5909  i++;
5910  if (i == (ssize_t) argc)
5911  ThrowMogrifyException(OptionError,"MissingArgument",option);
5912  if (IsGeometry(argv[i]) == MagickFalse)
5913  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5914  break;
5915  }
5916  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5917  }
5918  case 's':
5919  {
5920  if (LocaleCompare("sample",option+1) == 0)
5921  {
5922  if (*option == '+')
5923  break;
5924  i++;
5925  if (i == (ssize_t) argc)
5926  ThrowMogrifyException(OptionError,"MissingArgument",option);
5927  if (IsGeometry(argv[i]) == MagickFalse)
5928  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5929  break;
5930  }
5931  if (LocaleCompare("sampling-factor",option+1) == 0)
5932  {
5933  if (*option == '+')
5934  break;
5935  i++;
5936  if (i == (ssize_t) argc)
5937  ThrowMogrifyException(OptionError,"MissingArgument",option);
5938  if (IsGeometry(argv[i]) == MagickFalse)
5939  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5940  break;
5941  }
5942  if (LocaleCompare("scale",option+1) == 0)
5943  {
5944  if (*option == '+')
5945  break;
5946  i++;
5947  if (i == (ssize_t) argc)
5948  ThrowMogrifyException(OptionError,"MissingArgument",option);
5949  if (IsGeometry(argv[i]) == MagickFalse)
5950  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5951  break;
5952  }
5953  if (LocaleCompare("scene",option+1) == 0)
5954  {
5955  if (*option == '+')
5956  break;
5957  i++;
5958  if (i == (ssize_t) argc)
5959  ThrowMogrifyException(OptionError,"MissingArgument",option);
5960  if (IsGeometry(argv[i]) == MagickFalse)
5961  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5962  break;
5963  }
5964  if (LocaleCompare("seed",option+1) == 0)
5965  {
5966  if (*option == '+')
5967  break;
5968  i++;
5969  if (i == (ssize_t) argc)
5970  ThrowMogrifyException(OptionError,"MissingArgument",option);
5971  if (IsGeometry(argv[i]) == MagickFalse)
5972  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5973  break;
5974  }
5975  if (LocaleCompare("segment",option+1) == 0)
5976  {
5977  if (*option == '+')
5978  break;
5979  i++;
5980  if (i == (ssize_t) argc)
5981  ThrowMogrifyException(OptionError,"MissingArgument",option);
5982  if (IsGeometry(argv[i]) == MagickFalse)
5983  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5984  break;
5985  }
5986  if (LocaleCompare("selective-blur",option+1) == 0)
5987  {
5988  i++;
5989  if (i == (ssize_t) argc)
5990  ThrowMogrifyException(OptionError,"MissingArgument",option);
5991  if (IsGeometry(argv[i]) == MagickFalse)
5992  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5993  break;
5994  }
5995  if (LocaleCompare("separate",option+1) == 0)
5996  break;
5997  if (LocaleCompare("sepia-tone",option+1) == 0)
5998  {
5999  if (*option == '+')
6000  break;
6001  i++;
6002  if (i == (ssize_t) argc)
6003  ThrowMogrifyException(OptionError,"MissingArgument",option);
6004  if (IsGeometry(argv[i]) == MagickFalse)
6005  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6006  break;
6007  }
6008  if (LocaleCompare("set",option+1) == 0)
6009  {
6010  i++;
6011  if (i == (ssize_t) argc)
6012  ThrowMogrifyException(OptionError,"MissingArgument",option);
6013  if (*option == '+')
6014  break;
6015  i++;
6016  if (i == (ssize_t) argc)
6017  ThrowMogrifyException(OptionError,"MissingArgument",option);
6018  break;
6019  }
6020  if (LocaleCompare("shade",option+1) == 0)
6021  {
6022  i++;
6023  if (i == (ssize_t) argc)
6024  ThrowMogrifyException(OptionError,"MissingArgument",option);
6025  if (IsGeometry(argv[i]) == MagickFalse)
6026  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6027  break;
6028  }
6029  if (LocaleCompare("shadow",option+1) == 0)
6030  {
6031  if (*option == '+')
6032  break;
6033  i++;
6034  if (i == (ssize_t) argc)
6035  ThrowMogrifyException(OptionError,"MissingArgument",option);
6036  if (IsGeometry(argv[i]) == MagickFalse)
6037  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6038  break;
6039  }
6040  if (LocaleCompare("sharpen",option+1) == 0)
6041  {
6042  i++;
6043  if (i == (ssize_t) argc)
6044  ThrowMogrifyException(OptionError,"MissingArgument",option);
6045  if (IsGeometry(argv[i]) == MagickFalse)
6046  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6047  break;
6048  }
6049  if (LocaleCompare("shave",option+1) == 0)
6050  {
6051  if (*option == '+')
6052  break;
6053  i++;
6054  if (i == (ssize_t) argc)
6055  ThrowMogrifyException(OptionError,"MissingArgument",option);
6056  if (IsGeometry(argv[i]) == MagickFalse)
6057  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6058  break;
6059  }
6060  if (LocaleCompare("shear",option+1) == 0)
6061  {
6062  i++;
6063  if (i == (ssize_t) argc)
6064  ThrowMogrifyException(OptionError,"MissingArgument",option);
6065  if (IsGeometry(argv[i]) == MagickFalse)
6066  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6067  break;
6068  }
6069  if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
6070  {
6071  i++;
6072  if (i == (ssize_t) argc)
6073  ThrowMogrifyException(OptionError,"MissingArgument",option);
6074  if (IsGeometry(argv[i]) == MagickFalse)
6075  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6076  break;
6077  }
6078  if (LocaleCompare("size",option+1) == 0)
6079  {
6080  if (*option == '+')
6081  break;
6082  i++;
6083  if (i == (ssize_t) argc)
6084  ThrowMogrifyException(OptionError,"MissingArgument",option);
6085  if (IsGeometry(argv[i]) == MagickFalse)
6086  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6087  break;
6088  }
6089  if (LocaleCompare("sketch",option+1) == 0)
6090  {
6091  if (*option == '+')
6092  break;
6093  i++;
6094  if (i == (ssize_t) argc)
6095  ThrowMogrifyException(OptionError,"MissingArgument",option);
6096  if (IsGeometry(argv[i]) == MagickFalse)
6097  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6098  break;
6099  }
6100  if (LocaleCompare("smush",option+1) == 0)
6101  {
6102  i++;
6103  if (i == (ssize_t) argc)
6104  ThrowMogrifyException(OptionError,"MissingArgument",option);
6105  if (IsGeometry(argv[i]) == MagickFalse)
6106  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6107  i++;
6108  break;
6109  }
6110  if (LocaleCompare("solarize",option+1) == 0)
6111  {
6112  if (*option == '+')
6113  break;
6114  i++;
6115  if (i == (ssize_t) argc)
6116  ThrowMogrifyException(OptionError,"MissingArgument",option);
6117  if (IsGeometry(argv[i]) == MagickFalse)
6118  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6119  break;
6120  }
6121  if (LocaleCompare("sparse-color",option+1) == 0)
6122  {
6123  ssize_t
6124  op;
6125 
6126  i++;
6127  if (i == (ssize_t) argc)
6128  ThrowMogrifyException(OptionError,"MissingArgument",option);
6129  op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
6130  if (op < 0)
6131  ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
6132  argv[i]);
6133  i++;
6134  if (i == (ssize_t) argc)
6135  ThrowMogrifyException(OptionError,"MissingArgument",option);
6136  break;
6137  }
6138  if (LocaleCompare("splice",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("spread",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("statistic",option+1) == 0)
6161  {
6162  ssize_t
6163  op;
6164 
6165  if (*option == '+')
6166  break;
6167  i++;
6168  if (i == (ssize_t) argc)
6169  ThrowMogrifyException(OptionError,"MissingArgument",option);
6170  op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
6171  if (op < 0)
6172  ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
6173  argv[i]);
6174  i++;
6175  if (i == (ssize_t) argc)
6176  ThrowMogrifyException(OptionError,"MissingArgument",option);
6177  if (IsGeometry(argv[i]) == MagickFalse)
6178  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6179  break;
6180  }
6181  if (LocaleCompare("stretch",option+1) == 0)
6182  {
6183  ssize_t
6184  stretch;
6185 
6186  if (*option == '+')
6187  break;
6188  i++;
6189  if (i == (ssize_t) argc)
6190  ThrowMogrifyException(OptionError,"MissingArgument",option);
6191  stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
6192  if (stretch < 0)
6193  ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6194  argv[i]);
6195  break;
6196  }
6197  if (LocaleCompare("strip",option+1) == 0)
6198  break;
6199  if (LocaleCompare("stroke",option+1) == 0)
6200  {
6201  if (*option == '+')
6202  break;
6203  i++;
6204  if (i == (ssize_t) argc)
6205  ThrowMogrifyException(OptionError,"MissingArgument",option);
6206  break;
6207  }
6208  if (LocaleCompare("strokewidth",option+1) == 0)
6209  {
6210  if (*option == '+')
6211  break;
6212  i++;
6213  if (i == (ssize_t) argc)
6214  ThrowMogrifyException(OptionError,"MissingArgument",option);
6215  if (IsGeometry(argv[i]) == MagickFalse)
6216  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6217  break;
6218  }
6219  if (LocaleCompare("style",option+1) == 0)
6220  {
6221  ssize_t
6222  style;
6223 
6224  if (*option == '+')
6225  break;
6226  i++;
6227  if (i == (ssize_t) argc)
6228  ThrowMogrifyException(OptionError,"MissingArgument",option);
6229  style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
6230  if (style < 0)
6231  ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6232  argv[i]);
6233  break;
6234  }
6235  if (LocaleCompare("swap",option+1) == 0)
6236  {
6237  if (*option == '+')
6238  break;
6239  i++;
6240  if (i == (ssize_t) argc)
6241  ThrowMogrifyException(OptionError,"MissingArgument",option);
6242  if (IsGeometry(argv[i]) == MagickFalse)
6243  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6244  break;
6245  }
6246  if (LocaleCompare("swirl",option+1) == 0)
6247  {
6248  if (*option == '+')
6249  break;
6250  i++;
6251  if (i == (ssize_t) argc)
6252  ThrowMogrifyException(OptionError,"MissingArgument",option);
6253  if (IsGeometry(argv[i]) == MagickFalse)
6254  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6255  break;
6256  }
6257  if (LocaleCompare("synchronize",option+1) == 0)
6258  break;
6259  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6260  }
6261  case 't':
6262  {
6263  if (LocaleCompare("taint",option+1) == 0)
6264  break;
6265  if (LocaleCompare("texture",option+1) == 0)
6266  {
6267  if (*option == '+')
6268  break;
6269  i++;
6270  if (i == (ssize_t) argc)
6271  ThrowMogrifyException(OptionError,"MissingArgument",option);
6272  break;
6273  }
6274  if (LocaleCompare("tile",option+1) == 0)
6275  {
6276  if (*option == '+')
6277  break;
6278  i++;
6279  if (i == (ssize_t) argc)
6280  ThrowMogrifyException(OptionError,"MissingArgument",option);
6281  break;
6282  }
6283  if (LocaleCompare("tile-offset",option+1) == 0)
6284  {
6285  if (*option == '+')
6286  break;
6287  i++;
6288  if (i == (ssize_t) argc)
6289  ThrowMogrifyException(OptionError,"MissingArgument",option);
6290  if (IsGeometry(argv[i]) == MagickFalse)
6291  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6292  break;
6293  }
6294  if (LocaleCompare("tint",option+1) == 0)
6295  {
6296  if (*option == '+')
6297  break;
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  break;
6304  }
6305  if (LocaleCompare("transform",option+1) == 0)
6306  break;
6307  if (LocaleCompare("transpose",option+1) == 0)
6308  break;
6309  if (LocaleCompare("transverse",option+1) == 0)
6310  break;
6311  if (LocaleCompare("threshold",option+1) == 0)
6312  {
6313  if (*option == '+')
6314  break;
6315  i++;
6316  if (i == (ssize_t) argc)
6317  ThrowMogrifyException(OptionError,"MissingArgument",option);
6318  if (IsGeometry(argv[i]) == MagickFalse)
6319  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6320  break;
6321  }
6322  if (LocaleCompare("thumbnail",option+1) == 0)
6323  {
6324  if (*option == '+')
6325  break;
6326  i++;
6327  if (i == (ssize_t) argc)
6328  ThrowMogrifyException(OptionError,"MissingArgument",option);
6329  if (IsGeometry(argv[i]) == MagickFalse)
6330  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6331  break;
6332  }
6333  if (LocaleCompare("transparent",option+1) == 0)
6334  {
6335  i++;
6336  if (i == (ssize_t) argc)
6337  ThrowMogrifyException(OptionError,"MissingArgument",option);
6338  break;
6339  }
6340  if (LocaleCompare("transparent-color",option+1) == 0)
6341  {
6342  if (*option == '+')
6343  break;
6344  i++;
6345  if (i == (ssize_t) argc)
6346  ThrowMogrifyException(OptionError,"MissingArgument",option);
6347  break;
6348  }
6349  if (LocaleCompare("treedepth",option+1) == 0)
6350  {
6351  if (*option == '+')
6352  break;
6353  i++;
6354  if (i == (ssize_t) argc)
6355  ThrowMogrifyException(OptionError,"MissingArgument",option);
6356  if (IsGeometry(argv[i]) == MagickFalse)
6357  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6358  break;
6359  }
6360  if (LocaleCompare("trim",option+1) == 0)
6361  break;
6362  if (LocaleCompare("type",option+1) == 0)
6363  {
6364  ssize_t
6365  type;
6366 
6367  if (*option == '+')
6368  break;
6369  i++;
6370  if (i == (ssize_t) argc)
6371  ThrowMogrifyException(OptionError,"MissingArgument",option);
6372  type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
6373  if (type < 0)
6374  ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6375  argv[i]);
6376  break;
6377  }
6378  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6379  }
6380  case 'u':
6381  {
6382  if (LocaleCompare("undercolor",option+1) == 0)
6383  {
6384  if (*option == '+')
6385  break;
6386  i++;
6387  if (i == (ssize_t) argc)
6388  ThrowMogrifyException(OptionError,"MissingArgument",option);
6389  break;
6390  }
6391  if (LocaleCompare("unique-colors",option+1) == 0)
6392  break;
6393  if (LocaleCompare("units",option+1) == 0)
6394  {
6395  ssize_t
6396  units;
6397 
6398  if (*option == '+')
6399  break;
6400  i++;
6401  if (i == (ssize_t) argc)
6402  ThrowMogrifyException(OptionError,"MissingArgument",option);
6403  units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
6404  argv[i]);
6405  if (units < 0)
6406  ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6407  argv[i]);
6408  break;
6409  }
6410  if (LocaleCompare("unsharp",option+1) == 0)
6411  {
6412  i++;
6413  if (i == (ssize_t) argc)
6414  ThrowMogrifyException(OptionError,"MissingArgument",option);
6415  if (IsGeometry(argv[i]) == MagickFalse)
6416  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6417  break;
6418  }
6419  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6420  }
6421  case 'v':
6422  {
6423  if (LocaleCompare("verbose",option+1) == 0)
6424  {
6425  image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6426  break;
6427  }
6428  if ((LocaleCompare("version",option+1) == 0) ||
6429  (LocaleCompare("-version",option+1) == 0))
6430  {
6431  ListMagickVersion(stdout);
6432  break;
6433  }
6434  if (LocaleCompare("view",option+1) == 0)
6435  {
6436  if (*option == '+')
6437  break;
6438  i++;
6439  if (i == (ssize_t) argc)
6440  ThrowMogrifyException(OptionError,"MissingArgument",option);
6441  break;
6442  }
6443  if (LocaleCompare("vignette",option+1) == 0)
6444  {
6445  if (*option == '+')
6446  break;
6447  i++;
6448  if (i == (ssize_t) argc)
6449  ThrowMogrifyException(OptionError,"MissingArgument",option);
6450  if (IsGeometry(argv[i]) == MagickFalse)
6451  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6452  break;
6453  }
6454  if (LocaleCompare("virtual-pixel",option+1) == 0)
6455  {
6456  ssize_t
6457  method;
6458 
6459  if (*option == '+')
6460  break;
6461  i++;
6462  if (i == (ssize_t) argc)
6463  ThrowMogrifyException(OptionError,"MissingArgument",option);
6464  method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
6465  argv[i]);
6466  if (method < 0)
6467  ThrowMogrifyException(OptionError,
6468  "UnrecognizedVirtualPixelMethod",argv[i]);
6469  break;
6470  }
6471  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6472  }
6473  case 'w':
6474  {
6475  if (LocaleCompare("wave",option+1) == 0)
6476  {
6477  i++;
6478  if (i == (ssize_t) argc)
6479  ThrowMogrifyException(OptionError,"MissingArgument",option);
6480  if (IsGeometry(argv[i]) == MagickFalse)
6481  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6482  break;
6483  }
6484  if (LocaleCompare("wavelet-denoise",option+1) == 0)
6485  {
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("weight",option+1) == 0)
6494  {
6495  if (*option == '+')
6496  break;
6497  i++;
6498  if (i == (ssize_t) argc)
6499  ThrowMogrifyException(OptionError,"MissingArgument",option);
6500  break;
6501  }
6502  if (LocaleCompare("white-point",option+1) == 0)
6503  {
6504  if (*option == '+')
6505  break;
6506  i++;
6507  if (i == (ssize_t) argc)
6508  ThrowMogrifyException(OptionError,"MissingArgument",option);
6509  if (IsGeometry(argv[i]) == MagickFalse)
6510  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6511  break;
6512  }
6513  if (LocaleCompare("white-threshold",option+1) == 0)
6514  {
6515  if (*option == '+')
6516  break;
6517  i++;
6518  if (i == (ssize_t) argc)
6519  ThrowMogrifyException(OptionError,"MissingArgument",option);
6520  if (IsGeometry(argv[i]) == MagickFalse)
6521  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6522  break;
6523  }
6524  if (LocaleCompare("write",option+1) == 0)
6525  {
6526  i++;
6527  if (i == (ssize_t) argc)
6528  ThrowMogrifyException(OptionError,"MissingArgument",option);
6529  break;
6530  }
6531  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6532  }
6533  case '?':
6534  break;
6535  default:
6536  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6537  }
6538  fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6539  FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
6540  if (fire != MagickFalse)
6541  FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6542  }
6543  if (k != 0)
6544  ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6545  if (i != (ssize_t) argc)
6546  ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6547  DestroyMogrify();
6548  return(status != 0 ? MagickTrue : MagickFalse);
6549 }
6550 
6551 /*
6552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6553 % %
6554 % %
6555 % %
6556 + M o g r i f y I m a g e I n f o %
6557 % %
6558 % %
6559 % %
6560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6561 %
6562 % MogrifyImageInfo() applies image processing settings to the image as
6563 % prescribed by command line options.
6564 %
6565 % The format of the MogrifyImageInfo method is:
6566 %
6567 % MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6568 % const char **argv,ExceptionInfo *exception)
6569 %
6570 % A description of each parameter follows:
6571 %
6572 % o image_info: the image info..
6573 %
6574 % o argc: Specifies a pointer to an integer describing the number of
6575 % elements in the argument vector.
6576 %
6577 % o argv: Specifies a pointer to a text array containing the command line
6578 % arguments.
6579 %
6580 % o exception: return any errors or warnings in this structure.
6581 %
6582 */
6583 WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6584  const int argc,const char **argv,ExceptionInfo *exception)
6585 {
6586  const char
6587  *option;
6588 
6589  GeometryInfo
6590  geometry_info;
6591 
6592  ssize_t
6593  count;
6594 
6595  ssize_t
6596  i;
6597 
6598  /*
6599  Initialize method variables.
6600  */
6601  assert(image_info != (ImageInfo *) NULL);
6602  assert(image_info->signature == MagickCoreSignature);
6603  if (IsEventLogging() != MagickFalse)
6604  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6605  image_info->filename);
6606  if (argc < 0)
6607  return(MagickTrue);
6608  /*
6609  Set the image settings.
6610  */
6611  for (i=0; i < (ssize_t) argc; i++)
6612  {
6613  option=argv[i];
6614  if (IsCommandOption(option) == MagickFalse)
6615  continue;
6616  count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
6617  count=MagickMax(count,0L);
6618  if ((i+count) >= (ssize_t) argc)
6619  break;
6620  switch (*(option+1))
6621  {
6622  case 'a':
6623  {
6624  if (LocaleCompare("adjoin",option+1) == 0)
6625  {
6626  image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6627  break;
6628  }
6629  if (LocaleCompare("antialias",option+1) == 0)
6630  {
6631  image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6632  break;
6633  }
6634  if (LocaleCompare("attenuate",option+1) == 0)
6635  {
6636  if (*option == '+')
6637  {
6638  (void) DeleteImageOption(image_info,option+1);
6639  break;
6640  }
6641  (void) SetImageOption(image_info,option+1,argv[i+1]);
6642  break;
6643  }
6644  if (LocaleCompare("authenticate",option+1) == 0)
6645  {
6646  if (*option == '+')
6647  (void) CloneString(&image_info->authenticate,(char *) NULL);
6648  else
6649  (void) CloneString(&image_info->authenticate,argv[i+1]);
6650  break;
6651  }
6652  break;
6653  }
6654  case 'b':
6655  {
6656  if (LocaleCompare("background",option+1) == 0)
6657  {
6658  if (*option == '+')
6659  {
6660  (void) DeleteImageOption(image_info,option+1);
6661  (void) QueryColorDatabase(MogrifyBackgroundColor,
6662  &image_info->background_color,exception);
6663  break;
6664  }
6665  (void) SetImageOption(image_info,option+1,argv[i+1]);
6666  (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6667  exception);
6668  break;
6669  }
6670  if (LocaleCompare("bias",option+1) == 0)
6671  {
6672  if (*option == '+')
6673  {
6674  (void) SetImageOption(image_info,option+1,"0.0");
6675  break;
6676  }
6677  (void) SetImageOption(image_info,option+1,argv[i+1]);
6678  break;
6679  }
6680  if (LocaleCompare("black-point-compensation",option+1) == 0)
6681  {
6682  if (*option == '+')
6683  {
6684  (void) SetImageOption(image_info,option+1,"false");
6685  break;
6686  }
6687  (void) SetImageOption(image_info,option+1,"true");
6688  break;
6689  }
6690  if (LocaleCompare("blue-primary",option+1) == 0)
6691  {
6692  if (*option == '+')
6693  {
6694  (void) SetImageOption(image_info,option+1,"0.0");
6695  break;
6696  }
6697  (void) SetImageOption(image_info,option+1,argv[i+1]);
6698  break;
6699  }
6700  if (LocaleCompare("bordercolor",option+1) == 0)
6701  {
6702  if (*option == '+')
6703  {
6704  (void) DeleteImageOption(image_info,option+1);
6705  (void) QueryColorDatabase(MogrifyBorderColor,
6706  &image_info->border_color,exception);
6707  break;
6708  }
6709  (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6710  exception);
6711  (void) SetImageOption(image_info,option+1,argv[i+1]);
6712  break;
6713  }
6714  if (LocaleCompare("box",option+1) == 0)
6715  {
6716  if (*option == '+')
6717  {
6718  (void) SetImageOption(image_info,"undercolor","none");
6719  break;
6720  }
6721  (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6722  break;
6723  }
6724  break;
6725  }
6726  case 'c':
6727  {
6728  if (LocaleCompare("cache",option+1) == 0)
6729  {
6730  MagickSizeType
6731  limit;
6732 
6733  limit=MagickResourceInfinity;
6734  if (LocaleCompare("unlimited",argv[i+1]) != 0)
6735  limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],100.0);
6736  (void) SetMagickResourceLimit(MemoryResource,limit);
6737  (void) SetMagickResourceLimit(MapResource,2*limit);
6738  break;
6739  }
6740  if (LocaleCompare("caption",option+1) == 0)
6741  {
6742  if (*option == '+')
6743  {
6744  (void) DeleteImageOption(image_info,option+1);
6745  break;
6746  }
6747  (void) SetImageOption(image_info,option+1,argv[i+1]);
6748  break;
6749  }
6750  if (LocaleCompare("channel",option+1) == 0)
6751  {
6752  if (*option == '+')
6753  {
6754  image_info->channel=DefaultChannels;
6755  break;
6756  }
6757  image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6758  break;
6759  }
6760  if (LocaleCompare("colors",option+1) == 0)
6761  {
6762  image_info->colors=StringToUnsignedLong(argv[i+1]);
6763  break;
6764  }
6765  if (LocaleCompare("colorspace",option+1) == 0)
6766  {
6767  if (*option == '+')
6768  {
6769  image_info->colorspace=UndefinedColorspace;
6770  (void) SetImageOption(image_info,option+1,"undefined");
6771  break;
6772  }
6773  image_info->colorspace=(ColorspaceType) ParseCommandOption(
6774  MagickColorspaceOptions,MagickFalse,argv[i+1]);
6775  (void) SetImageOption(image_info,option+1,argv[i+1]);
6776  break;
6777  }
6778  if (LocaleCompare("comment",option+1) == 0)
6779  {
6780  if (*option == '+')
6781  {
6782  (void) DeleteImageOption(image_info,option+1);
6783  break;
6784  }
6785  (void) SetImageOption(image_info,option+1,argv[i+1]);
6786  break;
6787  }
6788  if (LocaleCompare("compose",option+1) == 0)
6789  {
6790  if (*option == '+')
6791  {
6792  (void) SetImageOption(image_info,option+1,"undefined");
6793  break;
6794  }
6795  (void) SetImageOption(image_info,option+1,argv[i+1]);
6796  break;
6797  }
6798  if (LocaleCompare("compress",option+1) == 0)
6799  {
6800  if (*option == '+')
6801  {
6802  image_info->compression=UndefinedCompression;
6803  (void) SetImageOption(image_info,option+1,"undefined");
6804  break;
6805  }
6806  image_info->compression=(CompressionType) ParseCommandOption(
6807  MagickCompressOptions,MagickFalse,argv[i+1]);
6808  (void) SetImageOption(image_info,option+1,argv[i+1]);
6809  break;
6810  }
6811  break;
6812  }
6813  case 'd':
6814  {
6815  if (LocaleCompare("debug",option+1) == 0)
6816  {
6817  if (*option == '+')
6818  (void) SetLogEventMask("none");
6819  else
6820  (void) SetLogEventMask(argv[i+1]);
6821  image_info->debug=IsEventLogging();
6822  break;
6823  }
6824  if (LocaleCompare("define",option+1) == 0)
6825  {
6826  if (*option == '+')
6827  {
6828  if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6829  (void) DeleteImageRegistry(argv[i+1]+9);
6830  else
6831  (void) DeleteImageOption(image_info,argv[i+1]);
6832  break;
6833  }
6834  if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6835  {
6836  (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6837  exception);
6838  break;
6839  }
6840  (void) DefineImageOption(image_info,argv[i+1]);
6841  break;
6842  }
6843  if (LocaleCompare("delay",option+1) == 0)
6844  {
6845  if (*option == '+')
6846  {
6847  (void) SetImageOption(image_info,option+1,"0");
6848  break;
6849  }
6850  (void) SetImageOption(image_info,option+1,argv[i+1]);
6851  break;
6852  }
6853  if (LocaleCompare("density",option+1) == 0)
6854  {
6855  /*
6856  Set image density.
6857  */
6858  if (*option == '+')
6859  {
6860  if (image_info->density != (char *) NULL)
6861  image_info->density=DestroyString(image_info->density);
6862  (void) SetImageOption(image_info,option+1,"72");
6863  break;
6864  }
6865  (void) CloneString(&image_info->density,argv[i+1]);
6866  (void) SetImageOption(image_info,option+1,argv[i+1]);
6867  break;
6868  }
6869  if (LocaleCompare("depth",option+1) == 0)
6870  {
6871  if (*option == '+')
6872  {
6873  image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6874  break;
6875  }
6876  image_info->depth=StringToUnsignedLong(argv[i+1]);
6877  break;
6878  }
6879  if (LocaleCompare("direction",option+1) == 0)
6880  {
6881  if (*option == '+')
6882  {
6883  (void) SetImageOption(image_info,option+1,"undefined");
6884  break;
6885  }
6886  (void) SetImageOption(image_info,option+1,argv[i+1]);
6887  break;
6888  }
6889  if (LocaleCompare("display",option+1) == 0)
6890  {
6891  if (*option == '+')
6892  {
6893  if (image_info->server_name != (char *) NULL)
6894  image_info->server_name=DestroyString(
6895  image_info->server_name);
6896  break;
6897  }
6898  (void) CloneString(&image_info->server_name,argv[i+1]);
6899  break;
6900  }
6901  if (LocaleCompare("dispose",option+1) == 0)
6902  {
6903  if (*option == '+')
6904  {
6905  (void) SetImageOption(image_info,option+1,"undefined");
6906  break;
6907  }
6908  (void) SetImageOption(image_info,option+1,argv[i+1]);
6909  break;
6910  }
6911  if (LocaleCompare("dither",option+1) == 0)
6912  {
6913  if (*option == '+')
6914  {
6915  image_info->dither=MagickFalse;
6916  (void) SetImageOption(image_info,option+1,"none");
6917  break;
6918  }
6919  (void) SetImageOption(image_info,option+1,argv[i+1]);
6920  image_info->dither=MagickTrue;
6921  break;
6922  }
6923  break;
6924  }
6925  case 'e':
6926  {
6927  if (LocaleCompare("encoding",option+1) == 0)
6928  {
6929  if (*option == '+')
6930  {
6931  (void) SetImageOption(image_info,option+1,"undefined");
6932  break;
6933  }
6934  (void) SetImageOption(image_info,option+1,argv[i+1]);
6935  break;
6936  }
6937  if (LocaleCompare("endian",option+1) == 0)
6938  {
6939  if (*option == '+')
6940  {
6941  image_info->endian=UndefinedEndian;
6942  (void) SetImageOption(image_info,option+1,"undefined");
6943  break;
6944  }
6945  image_info->endian=(EndianType) ParseCommandOption(
6946  MagickEndianOptions,MagickFalse,argv[i+1]);
6947  (void) SetImageOption(image_info,option+1,argv[i+1]);
6948  break;
6949  }
6950  if (LocaleCompare("extract",option+1) == 0)
6951  {
6952  /*
6953  Set image extract geometry.
6954  */
6955  if (*option == '+')
6956  {
6957  if (image_info->extract != (char *) NULL)
6958  image_info->extract=DestroyString(image_info->extract);
6959  break;
6960  }
6961  (void) CloneString(&image_info->extract,argv[i+1]);
6962  break;
6963  }
6964  break;
6965  }
6966  case 'f':
6967  {
6968  if (LocaleCompare("family",option+1) == 0)
6969  {
6970  if (*option != '+')
6971  (void) SetImageOption(image_info,option+1,argv[i+1]);
6972  break;
6973  }
6974  if (LocaleCompare("fill",option+1) == 0)
6975  {
6976  if (*option == '+')
6977  {
6978  (void) SetImageOption(image_info,option+1,"none");
6979  break;
6980  }
6981  (void) SetImageOption(image_info,option+1,argv[i+1]);
6982  break;
6983  }
6984  if (LocaleCompare("filter",option+1) == 0)
6985  {
6986  if (*option == '+')
6987  {
6988  (void) SetImageOption(image_info,option+1,"undefined");
6989  break;
6990  }
6991  (void) SetImageOption(image_info,option+1,argv[i+1]);
6992  break;
6993  }
6994  if (LocaleCompare("font",option+1) == 0)
6995  {
6996  if (*option == '+')
6997  {
6998  if (image_info->font != (char *) NULL)
6999  image_info->font=DestroyString(image_info->font);
7000  break;
7001  }
7002  (void) CloneString(&image_info->font,argv[i+1]);
7003  break;
7004  }
7005  if (LocaleCompare("format",option+1) == 0)
7006  {
7007  (void) SetImageOption(image_info,option+1,argv[i+1]);
7008  break;
7009  }
7010  if (LocaleCompare("fuzz",option+1) == 0)
7011  {
7012  if (*option == '+')
7013  {
7014  image_info->fuzz=0.0;
7015  (void) SetImageOption(image_info,option+1,"0");
7016  break;
7017  }
7018  image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
7019  QuantumRange+1.0);
7020  (void) SetImageOption(image_info,option+1,argv[i+1]);
7021  break;
7022  }
7023  break;
7024  }
7025  case 'g':
7026  {
7027  if (LocaleCompare("gravity",option+1) == 0)
7028  {
7029  if (*option == '+')
7030  {
7031  (void) SetImageOption(image_info,option+1,"undefined");
7032  break;
7033  }
7034  (void) SetImageOption(image_info,option+1,argv[i+1]);
7035  break;
7036  }
7037  if (LocaleCompare("green-primary",option+1) == 0)
7038  {
7039  if (*option == '+')
7040  {
7041  (void) SetImageOption(image_info,option+1,"0.0");
7042  break;
7043  }
7044  (void) SetImageOption(image_info,option+1,argv[i+1]);
7045  break;
7046  }
7047  break;
7048  }
7049  case 'i':
7050  {
7051  if (LocaleCompare("intensity",option+1) == 0)
7052  {
7053  if (*option == '+')
7054  {
7055  (void) SetImageOption(image_info,option+1,"undefined");
7056  break;
7057  }
7058  (void) SetImageOption(image_info,option+1,argv[i+1]);
7059  break;
7060  }
7061  if (LocaleCompare("intent",option+1) == 0)
7062  {
7063  if (*option == '+')
7064  {
7065  (void) SetImageOption(image_info,option+1,"undefined");
7066  break;
7067  }
7068  (void) SetImageOption(image_info,option+1,argv[i+1]);
7069  break;
7070  }
7071  if (LocaleCompare("interlace",option+1) == 0)
7072  {
7073  if (*option == '+')
7074  {
7075  image_info->interlace=UndefinedInterlace;
7076  (void) SetImageOption(image_info,option+1,"undefined");
7077  break;
7078  }
7079  image_info->interlace=(InterlaceType) ParseCommandOption(
7080  MagickInterlaceOptions,MagickFalse,argv[i+1]);
7081  (void) SetImageOption(image_info,option+1,argv[i+1]);
7082  break;
7083  }
7084  if (LocaleCompare("interline-spacing",option+1) == 0)
7085  {
7086  if (*option == '+')
7087  {
7088  (void) SetImageOption(image_info,option+1,"undefined");
7089  break;
7090  }
7091  (void) SetImageOption(image_info,option+1,argv[i+1]);
7092  break;
7093  }
7094  if (LocaleCompare("interpolate",option+1) == 0)
7095  {
7096  if (*option == '+')
7097  {
7098  (void) SetImageOption(image_info,option+1,"undefined");
7099  break;
7100  }
7101  (void) SetImageOption(image_info,option+1,argv[i+1]);
7102  break;
7103  }
7104  if (LocaleCompare("interword-spacing",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  break;
7115  }
7116  case 'k':
7117  {
7118  if (LocaleCompare("kerning",option+1) == 0)
7119  {
7120  if (*option == '+')
7121  {
7122  (void) SetImageOption(image_info,option+1,"undefined");
7123  break;
7124  }
7125  (void) SetImageOption(image_info,option+1,argv[i+1]);
7126  break;
7127  }
7128  break;
7129  }
7130  case 'l':
7131  {
7132  if (LocaleCompare("label",option+1) == 0)
7133  {
7134  if (*option == '+')
7135  {
7136  (void) DeleteImageOption(image_info,option+1);
7137  break;
7138  }
7139  (void) SetImageOption(image_info,option+1,argv[i+1]);
7140  break;
7141  }
7142  if (LocaleCompare("limit",option+1) == 0)
7143  {
7144  MagickSizeType
7145  limit;
7146 
7147  ResourceType
7148  type;
7149 
7150  if (*option == '+')
7151  break;
7152  type=(ResourceType) ParseCommandOption(MagickResourceOptions,
7153  MagickFalse,argv[i+1]);
7154  limit=MagickResourceInfinity;
7155  if (LocaleCompare("unlimited",argv[i+2]) != 0)
7156  limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
7157  (void) SetMagickResourceLimit(type,limit);
7158  break;
7159  }
7160  if (LocaleCompare("list",option+1) == 0)
7161  {
7162  ssize_t
7163  list;
7164 
7165  /*
7166  Display configuration list.
7167  */
7168  list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
7169  switch (list)
7170  {
7171  case MagickCoderOptions:
7172  {
7173  (void) ListCoderInfo((FILE *) NULL,exception);
7174  break;
7175  }
7176  case MagickColorOptions:
7177  {
7178  (void) ListColorInfo((FILE *) NULL,exception);
7179  break;
7180  }
7181  case MagickConfigureOptions:
7182  {
7183  (void) ListConfigureInfo((FILE *) NULL,exception);
7184  break;
7185  }
7186  case MagickDelegateOptions:
7187  {
7188  (void) ListDelegateInfo((FILE *) NULL,exception);
7189  break;
7190  }
7191  case MagickFontOptions:
7192  {
7193  (void) ListTypeInfo((FILE *) NULL,exception);
7194  break;
7195  }
7196  case MagickFormatOptions:
7197  {
7198  (void) ListMagickInfo((FILE *) NULL,exception);
7199  break;
7200  }
7201  case MagickLocaleOptions:
7202  {
7203  (void) ListLocaleInfo((FILE *) NULL,exception);
7204  break;
7205  }
7206  case MagickLogOptions:
7207  {
7208  (void) ListLogInfo((FILE *) NULL,exception);
7209  break;
7210  }
7211  case MagickMagicOptions:
7212  {
7213  (void) ListMagicInfo((FILE *) NULL,exception);
7214  break;
7215  }
7216  case MagickMimeOptions:
7217  {
7218  (void) ListMimeInfo((FILE *) NULL,exception);
7219  break;
7220  }
7221  case MagickModuleOptions:
7222  {
7223  (void) ListModuleInfo((FILE *) NULL,exception);
7224  break;
7225  }
7226  case MagickPolicyOptions:
7227  {
7228  (void) ListPolicyInfo((FILE *) NULL,exception);
7229  break;
7230  }
7231  case MagickResourceOptions:
7232  {
7233  (void) ListMagickResourceInfo((FILE *) NULL,exception);
7234  break;
7235  }
7236  case MagickThresholdOptions:
7237  {
7238  (void) ListThresholdMaps((FILE *) NULL,exception);
7239  break;
7240  }
7241  default:
7242  {
7243  (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
7244  exception);
7245  break;
7246  }
7247  }
7248  break;
7249  }
7250  if (LocaleCompare("log",option+1) == 0)
7251  {
7252  if (*option == '+')
7253  break;
7254  (void) SetLogFormat(argv[i+1]);
7255  break;
7256  }
7257  if (LocaleCompare("loop",option+1) == 0)
7258  {
7259  if (*option == '+')
7260  {
7261  (void) SetImageOption(image_info,option+1,"0");
7262  break;
7263  }
7264  (void) SetImageOption(image_info,option+1,argv[i+1]);
7265  break;
7266  }
7267  break;
7268  }
7269  case 'm':
7270  {
7271  if (LocaleCompare("matte",option+1) == 0)
7272  {
7273  if (*option == '+')
7274  {
7275  (void) SetImageOption(image_info,option+1,"false");
7276  break;
7277  }
7278  (void) SetImageOption(image_info,option+1,"true");
7279  break;
7280  }
7281  if (LocaleCompare("mattecolor",option+1) == 0)
7282  {
7283  if (*option == '+')
7284  {
7285  (void) SetImageOption(image_info,option+1,argv[i+1]);
7286  (void) QueryColorDatabase(MogrifyMatteColor,
7287  &image_info->matte_color,exception);
7288  break;
7289  }
7290  (void) SetImageOption(image_info,option+1,argv[i+1]);
7291  (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7292  exception);
7293  break;
7294  }
7295  if (LocaleCompare("metric",option+1) == 0)
7296  {
7297  if (*option == '+')
7298  {
7299  (void) DeleteImageOption(image_info,option+1);
7300  break;
7301  }
7302  (void) SetImageOption(image_info,option+1,argv[i+1]);
7303  break;
7304  }
7305  if (LocaleCompare("monitor",option+1) == 0)
7306  {
7307  (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7308  (void *) NULL);
7309  break;
7310  }
7311  if (LocaleCompare("monochrome",option+1) == 0)
7312  {
7313  image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7314  break;
7315  }
7316  break;
7317  }
7318  case 'o':
7319  {
7320  if (LocaleCompare("orient",option+1) == 0)
7321  {
7322  if (*option == '+')
7323  {
7324  image_info->orientation=UndefinedOrientation;
7325  (void) SetImageOption(image_info,option+1,"undefined");
7326  break;
7327  }
7328  image_info->orientation=(OrientationType) ParseCommandOption(
7329  MagickOrientationOptions,MagickFalse,argv[i+1]);
7330  (void) SetImageOption(image_info,option+1,argv[i+1]);
7331  break;
7332  }
7333  }
7334  case 'p':
7335  {
7336  if (LocaleCompare("page",option+1) == 0)
7337  {
7338  char
7339  *canonical_page,
7340  page[MaxTextExtent];
7341 
7342  const char
7343  *image_option;
7344 
7345  MagickStatusType
7346  flags;
7347 
7348  RectangleInfo
7349  geometry;
7350 
7351  if (*option == '+')
7352  {
7353  (void) DeleteImageOption(image_info,option+1);
7354  (void) CloneString(&image_info->page,(char *) NULL);
7355  break;
7356  }
7357  (void) memset(&geometry,0,sizeof(geometry));
7358  image_option=GetImageOption(image_info,"page");
7359  if (image_option != (const char *) NULL)
7360  (void) ParseAbsoluteGeometry(image_option,&geometry);
7361  canonical_page=GetPageGeometry(argv[i+1]);
7362  flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7363  canonical_page=DestroyString(canonical_page);
7364  (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
7365  (unsigned long) geometry.width,(unsigned long) geometry.height);
7366  if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7367  (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
7368  (unsigned long) geometry.width,(unsigned long) geometry.height,
7369  (long) geometry.x,(long) geometry.y);
7370  (void) SetImageOption(image_info,option+1,page);
7371  (void) CloneString(&image_info->page,page);
7372  break;
7373  }
7374  if (LocaleCompare("pen",option+1) == 0)
7375  {
7376  if (*option == '+')
7377  {
7378  (void) SetImageOption(image_info,option+1,"none");
7379  break;
7380  }
7381  (void) SetImageOption(image_info,option+1,argv[i+1]);
7382  break;
7383  }
7384  if (LocaleCompare("ping",option+1) == 0)
7385  {
7386  image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7387  break;
7388  }
7389  if (LocaleCompare("pointsize",option+1) == 0)
7390  {
7391  if (*option == '+')
7392  geometry_info.rho=0.0;
7393  else
7394  (void) ParseGeometry(argv[i+1],&geometry_info);
7395  image_info->pointsize=geometry_info.rho;
7396  break;
7397  }
7398  if (LocaleCompare("precision",option+1) == 0)
7399  {
7400  (void) SetMagickPrecision(StringToInteger(argv[i+1]));
7401  break;
7402  }
7403  if (LocaleCompare("preview",option+1) == 0)
7404  {
7405  /*
7406  Preview image.
7407  */
7408  if (*option == '+')
7409  {
7410  image_info->preview_type=UndefinedPreview;
7411  break;
7412  }
7413  image_info->preview_type=(PreviewType) ParseCommandOption(
7414  MagickPreviewOptions,MagickFalse,argv[i+1]);
7415  break;
7416  }
7417  break;
7418  }
7419  case 'q':
7420  {
7421  if (LocaleCompare("quality",option+1) == 0)
7422  {
7423  /*
7424  Set image compression quality.
7425  */
7426  if (*option == '+')
7427  {
7428  image_info->quality=UndefinedCompressionQuality;
7429  (void) SetImageOption(image_info,option+1,"0");
7430  break;
7431  }
7432  image_info->quality=StringToUnsignedLong(argv[i+1]);
7433  (void) SetImageOption(image_info,option+1,argv[i+1]);
7434  break;
7435  }
7436  if (LocaleCompare("quiet",option+1) == 0)
7437  {
7438  static WarningHandler
7439  warning_handler = (WarningHandler) NULL;
7440 
7441  if (*option == '+')
7442  {
7443  /*
7444  Restore error or warning messages.
7445  */
7446  warning_handler=SetWarningHandler(warning_handler);
7447  break;
7448  }
7449  /*
7450  Suppress error or warning messages.
7451  */
7452  warning_handler=SetWarningHandler((WarningHandler) NULL);
7453  break;
7454  }
7455  break;
7456  }
7457  case 'r':
7458  {
7459  if (LocaleCompare("red-primary",option+1) == 0)
7460  {
7461  if (*option == '+')
7462  {
7463  (void) SetImageOption(image_info,option+1,"0.0");
7464  break;
7465  }
7466  (void) SetImageOption(image_info,option+1,argv[i+1]);
7467  break;
7468  }
7469  break;
7470  }
7471  case 's':
7472  {
7473  if (LocaleCompare("sampling-factor",option+1) == 0)
7474  {
7475  /*
7476  Set image sampling factor.
7477  */
7478  if (*option == '+')
7479  {
7480  if (image_info->sampling_factor != (char *) NULL)
7481  image_info->sampling_factor=DestroyString(
7482  image_info->sampling_factor);
7483  break;
7484  }
7485  (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7486  break;
7487  }
7488  if (LocaleCompare("scene",option+1) == 0)
7489  {
7490  /*
7491  Set image scene.
7492  */
7493  if (*option == '+')
7494  {
7495  image_info->scene=0;
7496  (void) SetImageOption(image_info,option+1,"0");
7497  break;
7498  }
7499  image_info->scene=StringToUnsignedLong(argv[i+1]);
7500  (void) SetImageOption(image_info,option+1,argv[i+1]);
7501  break;
7502  }
7503  if (LocaleCompare("seed",option+1) == 0)
7504  {
7505  unsigned long
7506  seed;
7507 
7508  if (*option == '+')
7509  {
7510  seed=(unsigned long) time((time_t *) NULL);
7511  SetRandomSecretKey(seed);
7512  break;
7513  }
7514  seed=StringToUnsignedLong(argv[i+1]);
7515  SetRandomSecretKey(seed);
7516  break;
7517  }
7518  if (LocaleCompare("size",option+1) == 0)
7519  {
7520  if (*option == '+')
7521  {
7522  if (image_info->size != (char *) NULL)
7523  image_info->size=DestroyString(image_info->size);
7524  break;
7525  }
7526  (void) CloneString(&image_info->size,argv[i+1]);
7527  break;
7528  }
7529  if (LocaleCompare("stroke",option+1) == 0)
7530  {
7531  if (*option == '+')
7532  (void) SetImageOption(image_info,option+1,"none");
7533  else
7534  (void) SetImageOption(image_info,option+1,argv[i+1]);
7535  break;
7536  }
7537  if (LocaleCompare("strokewidth",option+1) == 0)
7538  {
7539  if (*option == '+')
7540  (void) SetImageOption(image_info,option+1,"0");
7541  else
7542  (void) SetImageOption(image_info,option+1,argv[i+1]);
7543  break;
7544  }
7545  if (LocaleCompare("style",option+1) == 0)
7546  {
7547  if (*option == '+')
7548  (void) SetImageOption(image_info,option+1,"none");
7549  else
7550  (void) SetImageOption(image_info,option+1,argv[i+1]);
7551  break;
7552  }
7553  if (LocaleCompare("synchronize",option+1) == 0)
7554  {
7555  if (*option == '+')
7556  {
7557  image_info->synchronize=MagickFalse;
7558  break;
7559  }
7560  image_info->synchronize=MagickTrue;
7561  break;
7562  }
7563  break;
7564  }
7565  case 't':
7566  {
7567  if (LocaleCompare("taint",option+1) == 0)
7568  {
7569  if (*option == '+')
7570  {
7571  (void) SetImageOption(image_info,option+1,"false");
7572  break;
7573  }
7574  (void) SetImageOption(image_info,option+1,"true");
7575  break;
7576  }
7577  if (LocaleCompare("texture",option+1) == 0)
7578  {
7579  if (*option == '+')
7580  {
7581  if (image_info->texture != (char *) NULL)
7582  image_info->texture=DestroyString(image_info->texture);
7583  break;
7584  }
7585  (void) CloneString(&image_info->texture,argv[i+1]);
7586  break;
7587  }
7588  if (LocaleCompare("tile-offset",option+1) == 0)
7589  {
7590  if (*option == '+')
7591  {
7592  (void) SetImageOption(image_info,option+1,"0");
7593  break;
7594  }
7595  (void) SetImageOption(image_info,option+1,argv[i+1]);
7596  break;
7597  }
7598  if (LocaleCompare("transparent-color",option+1) == 0)
7599  {
7600  if (*option == '+')
7601  {
7602  (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7603  (void) SetImageOption(image_info,option+1,"none");
7604  break;
7605  }
7606  (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7607  exception);
7608  (void) SetImageOption(image_info,option+1,argv[i+1]);
7609  break;
7610  }
7611  if (LocaleCompare("type",option+1) == 0)
7612  {
7613  if (*option == '+')
7614  {
7615  image_info->type=UndefinedType;
7616  (void) SetImageOption(image_info,option+1,"undefined");
7617  break;
7618  }
7619  image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
7620  MagickFalse,argv[i+1]);
7621  (void) SetImageOption(image_info,option+1,argv[i+1]);
7622  break;
7623  }
7624  break;
7625  }
7626  case 'u':
7627  {
7628  if (LocaleCompare("undercolor",option+1) == 0)
7629  {
7630  if (*option == '+')
7631  {
7632  (void) DeleteImageOption(image_info,option+1);
7633  break;
7634  }
7635  (void) SetImageOption(image_info,option+1,argv[i+1]);
7636  break;
7637  }
7638  if (LocaleCompare("units",option+1) == 0)
7639  {
7640  if (*option == '+')
7641  {
7642  image_info->units=UndefinedResolution;
7643  (void) SetImageOption(image_info,option+1,"undefined");
7644  break;
7645  }
7646  image_info->units=(ResolutionType) ParseCommandOption(
7647  MagickResolutionOptions,MagickFalse,argv[i+1]);
7648  (void) SetImageOption(image_info,option+1,argv[i+1]);
7649  break;
7650  }
7651  break;
7652  }
7653  case 'v':
7654  {
7655  if (LocaleCompare("verbose",option+1) == 0)
7656  {
7657  if (*option == '+')
7658  {
7659  image_info->verbose=MagickFalse;
7660  break;
7661  }
7662  image_info->verbose=MagickTrue;
7663  image_info->ping=MagickFalse;
7664  break;
7665  }
7666  if (LocaleCompare("view",option+1) == 0)
7667  {
7668  if (*option == '+')
7669  {
7670  if (image_info->view != (char *) NULL)
7671  image_info->view=DestroyString(image_info->view);
7672  break;
7673  }
7674  (void) CloneString(&image_info->view,argv[i+1]);
7675  break;
7676  }
7677  if (LocaleCompare("virtual-pixel",option+1) == 0)
7678  {
7679  if (*option == '+')
7680  {
7681  image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7682  (void) SetImageOption(image_info,option+1,"undefined");
7683  break;
7684  }
7685  image_info->virtual_pixel_method=(VirtualPixelMethod)
7686  ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
7687  argv[i+1]);
7688  (void) SetImageOption(image_info,option+1,argv[i+1]);
7689  break;
7690  }
7691  break;
7692  }
7693  case 'w':
7694  {
7695  if (LocaleCompare("weight",option+1) == 0)
7696  {
7697  if (*option == '+')
7698  (void) SetImageOption(image_info,option+1,"0");
7699  else
7700  (void) SetImageOption(image_info,option+1,argv[i+1]);
7701  break;
7702  }
7703  if (LocaleCompare("white-point",option+1) == 0)
7704  {
7705  if (*option == '+')
7706  {
7707  (void) SetImageOption(image_info,option+1,"0.0");
7708  break;
7709  }
7710  (void) SetImageOption(image_info,option+1,argv[i+1]);
7711  break;
7712  }
7713  break;
7714  }
7715  default:
7716  break;
7717  }
7718  i+=count;
7719  }
7720  return(MagickTrue);
7721 }
7722 
7723 /*
7724 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7725 % %
7726 % %
7727 % %
7728 + M o g r i f y I m a g e L i s t %
7729 % %
7730 % %
7731 % %
7732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7733 %
7734 % MogrifyImageList() applies any command line options that might affect the
7735 % entire image list (e.g. -append, -coalesce, etc.).
7736 %
7737 % The format of the MogrifyImage method is:
7738 %
7739 % MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7740 % const char **argv,Image **images,ExceptionInfo *exception)
7741 %
7742 % A description of each parameter follows:
7743 %
7744 % o image_info: the image info..
7745 %
7746 % o argc: Specifies a pointer to an integer describing the number of
7747 % elements in the argument vector.
7748 %
7749 % o argv: Specifies a pointer to a text array containing the command line
7750 % arguments.
7751 %
7752 % o images: pointer to pointer of the first image in image list.
7753 %
7754 % o exception: return any errors or warnings in this structure.
7755 %
7756 */
7757 WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7758  const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7759 {
7760  ChannelType
7761  channel;
7762 
7763  const char
7764  *option;
7765 
7766  ImageInfo
7767  *mogrify_info;
7768 
7769  MagickStatusType
7770  status;
7771 
7772  QuantizeInfo
7773  *quantize_info;
7774 
7775  ssize_t
7776  i;
7777 
7778  ssize_t
7779  count,
7780  index;
7781 
7782  /*
7783  Apply options to the image list.
7784  */
7785  assert(image_info != (ImageInfo *) NULL);
7786  assert(image_info->signature == MagickCoreSignature);
7787  assert(images != (Image **) NULL);
7788  assert((*images)->previous == (Image *) NULL);
7789  assert((*images)->signature == MagickCoreSignature);
7790  if (IsEventLogging() != MagickFalse)
7791  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7792  (*images)->filename);
7793  if ((argc <= 0) || (*argv == (char *) NULL))
7794  return(MagickTrue);
7795  mogrify_info=CloneImageInfo(image_info);
7796  quantize_info=AcquireQuantizeInfo(mogrify_info);
7797  channel=mogrify_info->channel;
7798  status=MagickTrue;
7799  for (i=0; i < (ssize_t) argc; i++)
7800  {
7801  if (*images == (Image *) NULL)
7802  break;
7803  option=argv[i];
7804  if (IsCommandOption(option) == MagickFalse)
7805  continue;
7806  count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
7807  count=MagickMax(count,0L);
7808  if ((i+count) >= (ssize_t) argc)
7809  break;
7810  status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
7811  switch (*(option+1))
7812  {
7813  case 'a':
7814  {
7815  if (LocaleCompare("affinity",option+1) == 0)
7816  {
7817  (void) SyncImagesSettings(mogrify_info,*images);
7818  if (*option == '+')
7819  {
7820  (void) RemapImages(quantize_info,*images,(Image *) NULL);
7821  InheritException(exception,&(*images)->exception);
7822  break;
7823  }
7824  i++;
7825  break;
7826  }
7827  if (LocaleCompare("append",option+1) == 0)
7828  {
7829  Image
7830  *append_image;
7831 
7832  (void) SyncImagesSettings(mogrify_info,*images);
7833  append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7834  MagickFalse,exception);
7835  if (append_image == (Image *) NULL)
7836  {
7837  status=MagickFalse;
7838  break;
7839  }
7840  *images=DestroyImageList(*images);
7841  *images=append_image;
7842  break;
7843  }
7844  if (LocaleCompare("average",option+1) == 0)
7845  {
7846  Image
7847  *average_image;
7848 
7849  /*
7850  Average an image sequence (deprecated).
7851  */
7852  (void) SyncImagesSettings(mogrify_info,*images);
7853  average_image=EvaluateImages(*images,MeanEvaluateOperator,
7854  exception);
7855  if (average_image == (Image *) NULL)
7856  {
7857  status=MagickFalse;
7858  break;
7859  }
7860  *images=DestroyImageList(*images);
7861  *images=average_image;
7862  break;
7863  }
7864  break;
7865  }
7866  case 'c':
7867  {
7868  if (LocaleCompare("channel",option+1) == 0)
7869  {
7870  if (*option == '+')
7871  {
7872  channel=DefaultChannels;
7873  break;
7874  }
7875  channel=(ChannelType) ParseChannelOption(argv[i+1]);
7876  break;
7877  }
7878  if (LocaleCompare("clut",option+1) == 0)
7879  {
7880  Image
7881  *clut_image,
7882  *image;
7883 
7884  (void) SyncImagesSettings(mogrify_info,*images);
7885  image=RemoveFirstImageFromList(images);
7886  clut_image=RemoveFirstImageFromList(images);
7887  if (clut_image == (Image *) NULL)
7888  {
7889  (void) ThrowMagickException(exception,GetMagickModule(),
7890  OptionError,"ImageSequenceRequired","`%s'",option);
7891  image=DestroyImage(image);
7892  status=MagickFalse;
7893  break;
7894  }
7895  (void) ClutImageChannel(image,channel,clut_image);
7896  clut_image=DestroyImage(clut_image);
7897  InheritException(exception,&image->exception);
7898  *images=DestroyImageList(*images);
7899  *images=image;
7900  break;
7901  }
7902  if (LocaleCompare("coalesce",option+1) == 0)
7903  {
7904  Image
7905  *coalesce_image;
7906 
7907  (void) SyncImagesSettings(mogrify_info,*images);
7908  coalesce_image=CoalesceImages(*images,exception);
7909  if (coalesce_image == (Image *) NULL)
7910  {
7911  status=MagickFalse;
7912  break;
7913  }
7914  *images=DestroyImageList(*images);
7915  *images=coalesce_image;
7916  break;
7917  }
7918  if (LocaleCompare("combine",option+1) == 0)
7919  {
7920  Image
7921  *combine_image;
7922 
7923  (void) SyncImagesSettings(mogrify_info,*images);
7924  combine_image=CombineImages(*images,channel,exception);
7925  if (combine_image == (Image *) NULL)
7926  {
7927  status=MagickFalse;
7928  break;
7929  }
7930  *images=DestroyImageList(*images);
7931  *images=combine_image;
7932  break;
7933  }
7934  if (LocaleCompare("compare",option+1) == 0)
7935  {
7936  double
7937  distortion;
7938 
7939  Image
7940  *difference_image,
7941  *image,
7942  *reconstruct_image;
7943 
7944  MetricType
7945  metric;
7946 
7947  /*
7948  Mathematically and visually annotate the difference between an
7949  image and its reconstruction.
7950  */
7951  (void) SyncImagesSettings(mogrify_info,*images);
7952  image=RemoveFirstImageFromList(images);
7953  reconstruct_image=RemoveFirstImageFromList(images);
7954  if (reconstruct_image == (Image *) NULL)
7955  {
7956  (void) ThrowMagickException(exception,GetMagickModule(),
7957  OptionError,"ImageSequenceRequired","`%s'",option);
7958  image=DestroyImage(image);
7959  status=MagickFalse;
7960  break;
7961  }
7962  metric=UndefinedMetric;
7963  option=GetImageOption(image_info,"metric");
7964  if (option != (const char *) NULL)
7965  metric=(MetricType) ParseCommandOption(MagickMetricOptions,
7966  MagickFalse,option);
7967  difference_image=CompareImageChannels(image,reconstruct_image,
7968  channel,metric,&distortion,exception);
7969  if (difference_image == (Image *) NULL)
7970  break;
7971  reconstruct_image=DestroyImage(reconstruct_image);
7972  image=DestroyImage(image);
7973  if (*images != (Image *) NULL)
7974  *images=DestroyImageList(*images);
7975  *images=difference_image;
7976  break;
7977  }
7978  if (LocaleCompare("complex",option+1) == 0)
7979  {
7980  ComplexOperator
7981  op;
7982 
7983  Image
7984  *complex_images;
7985 
7986  (void) SyncImageSettings(mogrify_info,*images);
7987  op=(ComplexOperator) ParseCommandOption(MagickComplexOptions,
7988  MagickFalse,argv[i+1]);
7989  complex_images=ComplexImages(*images,op,exception);
7990  if (complex_images == (Image *) NULL)
7991  {
7992  status=MagickFalse;
7993  break;
7994  }
7995  *images=DestroyImageList(*images);
7996  *images=complex_images;
7997  break;
7998  }
7999  if (LocaleCompare("composite",option+1) == 0)
8000  {
8001  Image
8002  *mask_image,
8003  *composite_image,
8004  *image;
8005 
8006  RectangleInfo
8007  geometry;
8008 
8009  (void) SyncImagesSettings(mogrify_info,*images);
8010  image=RemoveFirstImageFromList(images);
8011  composite_image=RemoveFirstImageFromList(images);
8012  if (composite_image == (Image *) NULL)
8013  {
8014  (void) ThrowMagickException(exception,GetMagickModule(),
8015  OptionError,"ImageSequenceRequired","`%s'",option);
8016  image=DestroyImage(image);
8017  status=MagickFalse;
8018  break;
8019  }
8020  (void) TransformImage(&composite_image,(char *) NULL,
8021  composite_image->geometry);
8022  SetGeometry(composite_image,&geometry);
8023  (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
8024  GravityAdjustGeometry(image->columns,image->rows,image->gravity,
8025  &geometry);
8026  mask_image=RemoveFirstImageFromList(images);
8027  if (mask_image != (Image *) NULL)
8028  {
8029  if ((image->compose == DisplaceCompositeOp) ||
8030  (image->compose == DistortCompositeOp))
8031  {
8032  /*
8033  Merge Y displacement into X displacement image.
8034  */
8035  (void) CompositeImage(composite_image,CopyGreenCompositeOp,
8036  mask_image,0,0);
8037  mask_image=DestroyImage(mask_image);
8038  }
8039  else
8040  {
8041  /*
8042  Set a blending mask for the composition.
8043  */
8044  if (image->mask != (Image *) NULL)
8045  image->mask=DestroyImage(image->mask);
8046  image->mask=mask_image;
8047  (void) NegateImage(image->mask,MagickFalse);
8048  }
8049  }
8050  (void) CompositeImageChannel(image,channel,image->compose,
8051  composite_image,geometry.x,geometry.y);
8052  if (mask_image != (Image *) NULL)
8053  {
8054  image->mask=DestroyImage(image->mask);
8055  mask_image=image->mask;
8056  }
8057  composite_image=DestroyImage(composite_image);
8058  InheritException(exception,&image->exception);
8059  *images=DestroyImageList(*images);
8060  *images=image;
8061  break;
8062  }
8063  if (LocaleCompare("copy",option+1) == 0)
8064  {
8065  Image
8066  *source_image;
8067 
8068  OffsetInfo
8069  offset;
8070 
8071  RectangleInfo
8072  geometry;
8073 
8074  /*
8075  Copy image pixels.
8076  */
8077  (void) SyncImageSettings(mogrify_info,*images);
8078  (void) ParsePageGeometry(*images,argv[i+2],&geometry,exception);
8079  offset.x=geometry.x;
8080  offset.y=geometry.y;
8081  source_image=(*images);
8082  if (source_image->next != (Image *) NULL)
8083  source_image=source_image->next;
8084  (void) ParsePageGeometry(source_image,argv[i+1],&geometry,
8085  exception);
8086  status=CopyImagePixels(*images,source_image,&geometry,&offset,
8087  exception);
8088  break;
8089  }
8090  break;
8091  }
8092  case 'd':
8093  {
8094  if (LocaleCompare("deconstruct",option+1) == 0)
8095  {
8096  Image
8097  *deconstruct_image;
8098 
8099  (void) SyncImagesSettings(mogrify_info,*images);
8100  deconstruct_image=DeconstructImages(*images,exception);
8101  if (deconstruct_image == (Image *) NULL)
8102  {
8103  status=MagickFalse;
8104  break;
8105  }
8106  *images=DestroyImageList(*images);
8107  *images=deconstruct_image;
8108  break;
8109  }
8110  if (LocaleCompare("delete",option+1) == 0)
8111  {
8112  if (*option == '+')
8113  DeleteImages(images,"-1",exception);
8114  else
8115  DeleteImages(images,argv[i+1],exception);
8116  break;
8117  }
8118  if (LocaleCompare("dither",option+1) == 0)
8119  {
8120  if (*option == '+')
8121  {
8122  quantize_info->dither=MagickFalse;
8123  break;
8124  }
8125  quantize_info->dither=MagickTrue;
8126  quantize_info->dither_method=(DitherMethod) ParseCommandOption(
8127  MagickDitherOptions,MagickFalse,argv[i+1]);
8128  break;
8129  }
8130  if (LocaleCompare("duplicate",option+1) == 0)
8131  {
8132  Image
8133  *duplicate_images;
8134 
8135  if (*option == '+')
8136  duplicate_images=DuplicateImages(*images,1,"-1",exception);
8137  else
8138  {
8139  const char
8140  *p;
8141 
8142  size_t
8143  number_duplicates;
8144 
8145  number_duplicates=(size_t) StringToLong(argv[i+1]);
8146  p=strchr(argv[i+1],',');
8147  if (p == (const char *) NULL)
8148  duplicate_images=DuplicateImages(*images,number_duplicates,
8149  "-1",exception);
8150  else
8151  duplicate_images=DuplicateImages(*images,number_duplicates,
8152  p+1,exception);
8153  }
8154  AppendImageToList(images, duplicate_images);
8155  (void) SyncImagesSettings(mogrify_info,*images);
8156  break;
8157  }
8158  break;
8159  }
8160  case 'e':
8161  {
8162  if (LocaleCompare("evaluate-sequence",option+1) == 0)
8163  {
8164  Image
8165  *evaluate_image;
8166 
8167  MagickEvaluateOperator
8168  op;
8169 
8170  (void) SyncImageSettings(mogrify_info,*images);
8171  op=(MagickEvaluateOperator) ParseCommandOption(
8172  MagickEvaluateOptions,MagickFalse,argv[i+1]);
8173  evaluate_image=EvaluateImages(*images,op,exception);
8174  if (evaluate_image == (Image *) NULL)
8175  {
8176  status=MagickFalse;
8177  break;
8178  }
8179  *images=DestroyImageList(*images);
8180  *images=evaluate_image;
8181  break;
8182  }
8183  break;
8184  }
8185  case 'f':
8186  {
8187  if (LocaleCompare("fft",option+1) == 0)
8188  {
8189  Image
8190  *fourier_image;
8191 
8192  /*
8193  Implements the discrete Fourier transform (DFT).
8194  */
8195  (void) SyncImageSettings(mogrify_info,*images);
8196  fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
8197  MagickTrue : MagickFalse,exception);
8198  if (fourier_image == (Image *) NULL)
8199  break;
8200  *images=DestroyImageList(*images);
8201  *images=fourier_image;
8202  break;
8203  }
8204  if (LocaleCompare("flatten",option+1) == 0)
8205  {
8206  Image
8207  *flatten_image;
8208 
8209  (void) SyncImagesSettings(mogrify_info,*images);
8210  flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
8211  if (flatten_image == (Image *) NULL)
8212  break;
8213  *images=DestroyImageList(*images);
8214  *images=flatten_image;
8215  break;
8216  }
8217  if (LocaleCompare("fx",option+1) == 0)
8218  {
8219  Image
8220  *fx_image;
8221 
8222  (void) SyncImagesSettings(mogrify_info,*images);
8223  fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
8224  if (fx_image == (Image *) NULL)
8225  {
8226  status=MagickFalse;
8227  break;
8228  }
8229  *images=DestroyImageList(*images);
8230  *images=fx_image;
8231  break;
8232  }
8233  break;
8234  }
8235  case 'h':
8236  {
8237  if (LocaleCompare("hald-clut",option+1) == 0)
8238  {
8239  Image
8240  *hald_image,
8241  *image;
8242 
8243  (void) SyncImagesSettings(mogrify_info,*images);
8244  image=RemoveFirstImageFromList(images);
8245  hald_image=RemoveFirstImageFromList(images);
8246  if (hald_image == (Image *) NULL)
8247  {
8248  (void) ThrowMagickException(exception,GetMagickModule(),
8249  OptionError,"ImageSequenceRequired","`%s'",option);
8250  image=DestroyImage(image);
8251  status=MagickFalse;
8252  break;
8253  }
8254  (void) HaldClutImageChannel(image,channel,hald_image);
8255  hald_image=DestroyImage(hald_image);
8256  InheritException(exception,&image->exception);
8257  if (*images != (Image *) NULL)
8258  *images=DestroyImageList(*images);
8259  *images=image;
8260  break;
8261  }
8262  break;
8263  }
8264  case 'i':
8265  {
8266  if (LocaleCompare("ift",option+1) == 0)
8267  {
8268  Image
8269  *fourier_image,
8270  *magnitude_image,
8271  *phase_image;
8272 
8273  /*
8274  Implements the inverse fourier discrete Fourier transform (DFT).
8275  */
8276  (void) SyncImagesSettings(mogrify_info,*images);
8277  magnitude_image=RemoveFirstImageFromList(images);
8278  phase_image=RemoveFirstImageFromList(images);
8279  if (phase_image == (Image *) NULL)
8280  {
8281  (void) ThrowMagickException(exception,GetMagickModule(),
8282  OptionError,"ImageSequenceRequired","`%s'",option);
8283  magnitude_image=DestroyImage(magnitude_image);
8284  status=MagickFalse;
8285  break;
8286  }
8287  fourier_image=InverseFourierTransformImage(magnitude_image,
8288  phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
8289  magnitude_image=DestroyImage(magnitude_image);
8290  phase_image=DestroyImage(phase_image);
8291  if (fourier_image == (Image *) NULL)
8292  break;
8293  if (*images != (Image *) NULL)
8294  *images=DestroyImageList(*images);
8295  *images=fourier_image;
8296  break;
8297  }
8298  if (LocaleCompare("insert",option+1) == 0)
8299  {
8300  Image
8301  *p,
8302  *q;
8303 
8304  index=0;
8305  if (*option != '+')
8306  index=(ssize_t) StringToLong(argv[i+1]);
8307  p=RemoveLastImageFromList(images);
8308  if (p == (Image *) NULL)
8309  {
8310  (void) ThrowMagickException(exception,GetMagickModule(),
8311  OptionError,"NoSuchImage","`%s'",argv[i+1]);
8312  status=MagickFalse;
8313  break;
8314  }
8315  q=p;
8316  if (index == 0)
8317  PrependImageToList(images,q);
8318  else
8319  if (index == (ssize_t) GetImageListLength(*images))
8320  AppendImageToList(images,q);
8321  else
8322  {
8323  q=GetImageFromList(*images,index-1);
8324  if (q == (Image *) NULL)
8325  {
8326  p=DestroyImage(p);
8327  (void) ThrowMagickException(exception,GetMagickModule(),
8328  OptionError,"NoSuchImage","`%s'",argv[i+1]);
8329  status=MagickFalse;
8330  break;
8331  }
8332  InsertImageInList(&q,p);
8333  }
8334  *images=GetFirstImageInList(q);
8335  break;
8336  }
8337  break;
8338  }
8339  case 'l':
8340  {
8341  if (LocaleCompare("layers",option+1) == 0)
8342  {
8343  Image
8344  *layers;
8345 
8346  ImageLayerMethod
8347  method;
8348 
8349  (void) SyncImagesSettings(mogrify_info,*images);
8350  layers=(Image *) NULL;
8351  method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
8352  MagickFalse,argv[i+1]);
8353  switch (method)
8354  {
8355  case CoalesceLayer:
8356  {
8357  layers=CoalesceImages(*images,exception);
8358  break;
8359  }
8360  case CompareAnyLayer:
8361  case CompareClearLayer:
8362  case CompareOverlayLayer:
8363  default:
8364  {
8365  layers=CompareImageLayers(*images,method,exception);
8366  break;
8367  }
8368  case MergeLayer:
8369  case FlattenLayer:
8370  case MosaicLayer:
8371  case TrimBoundsLayer:
8372  {
8373  layers=MergeImageLayers(*images,method,exception);
8374  break;
8375  }
8376  case DisposeLayer:
8377  {
8378  layers=DisposeImages(*images,exception);
8379  break;
8380  }
8381  case OptimizeImageLayer:
8382  {
8383  layers=OptimizeImageLayers(*images,exception);
8384  break;
8385  }
8386  case OptimizePlusLayer:
8387  {
8388  layers=OptimizePlusImageLayers(*images,exception);
8389  break;
8390  }
8391  case OptimizeTransLayer:
8392  {
8393  OptimizeImageTransparency(*images,exception);
8394  break;
8395  }
8396  case RemoveDupsLayer:
8397  {
8398  RemoveDuplicateLayers(images,exception);
8399  break;
8400  }
8401  case RemoveZeroLayer:
8402  {
8403  RemoveZeroDelayLayers(images,exception);
8404  break;
8405  }
8406  case OptimizeLayer:
8407  {
8408  /*
8409  General Purpose, GIF Animation Optimizer.
8410  */
8411  layers=CoalesceImages(*images,exception);
8412  if (layers == (Image *) NULL)
8413  {
8414  status=MagickFalse;
8415  break;
8416  }
8417  InheritException(exception,&layers->exception);
8418  *images=DestroyImageList(*images);
8419  *images=layers;
8420  layers=OptimizeImageLayers(*images,exception);
8421  if (layers == (Image *) NULL)
8422  {
8423  status=MagickFalse;
8424  break;
8425  }
8426  InheritException(exception,&layers->exception);
8427  *images=DestroyImageList(*images);
8428  *images=layers;
8429  layers=(Image *) NULL;
8430  OptimizeImageTransparency(*images,exception);
8431  InheritException(exception,&(*images)->exception);
8432  (void) RemapImages(quantize_info,*images,(Image *) NULL);
8433  break;
8434  }
8435  case CompositeLayer:
8436  {
8437  CompositeOperator
8438  compose;
8439 
8440  Image
8441  *source;
8442 
8443  RectangleInfo
8444  geometry;
8445 
8446  /*
8447  Split image sequence at the first 'NULL:' image.
8448  */
8449  source=(*images);
8450  while (source != (Image *) NULL)
8451  {
8452  source=GetNextImageInList(source);
8453  if ((source != (Image *) NULL) &&
8454  (LocaleCompare(source->magick,"NULL") == 0))
8455  break;
8456  }
8457  if (source != (Image *) NULL)
8458  {
8459  if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8460  (GetNextImageInList(source) == (Image *) NULL))
8461  source=(Image *) NULL;
8462  else
8463  {
8464  /*
8465  Separate the two lists, junk the null: image.
8466  */
8467  source=SplitImageList(source->previous);
8468  DeleteImageFromList(&source);
8469  }
8470  }
8471  if (source == (Image *) NULL)
8472  {
8473  (void) ThrowMagickException(exception,GetMagickModule(),
8474  OptionError,"MissingNullSeparator","layers Composite");
8475  status=MagickFalse;
8476  break;
8477  }
8478  /*
8479  Adjust offset with gravity and virtual canvas.
8480  */
8481  SetGeometry(*images,&geometry);
8482  (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8483  geometry.width=source->page.width != 0 ?
8484  source->page.width : source->columns;
8485  geometry.height=source->page.height != 0 ?
8486  source->page.height : source->rows;
8487  GravityAdjustGeometry((*images)->page.width != 0 ?
8488  (*images)->page.width : (*images)->columns,
8489  (*images)->page.height != 0 ? (*images)->page.height :
8490  (*images)->rows,(*images)->gravity,&geometry);
8491  compose=OverCompositeOp;
8492  option=GetImageOption(mogrify_info,"compose");
8493  if (option != (const char *) NULL)
8494  compose=(CompositeOperator) ParseCommandOption(
8495  MagickComposeOptions,MagickFalse,option);
8496  CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8497  exception);
8498  source=DestroyImageList(source);
8499  break;
8500  }
8501  }
8502  if (layers == (Image *) NULL)
8503  break;
8504  InheritException(exception,&layers->exception);
8505  *images=DestroyImageList(*images);
8506  *images=layers;
8507  break;
8508  }
8509  break;
8510  }
8511  case 'm':
8512  {
8513  if (LocaleCompare("map",option+1) == 0)
8514  {
8515  (void) SyncImagesSettings(mogrify_info,*images);
8516  if (*option == '+')
8517  {
8518  (void) RemapImages(quantize_info,*images,(Image *) NULL);
8519  InheritException(exception,&(*images)->exception);
8520  break;
8521  }
8522  i++;
8523  break;
8524  }
8525  if (LocaleCompare("maximum",option+1) == 0)
8526  {
8527  Image
8528  *maximum_image;
8529 
8530  /*
8531  Maximum image sequence (deprecated).
8532  */
8533  (void) SyncImagesSettings(mogrify_info,*images);
8534  maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
8535  if (maximum_image == (Image *) NULL)
8536  {
8537  status=MagickFalse;
8538  break;
8539  }
8540  *images=DestroyImageList(*images);
8541  *images=maximum_image;
8542  break;
8543  }
8544  if (LocaleCompare("minimum",option+1) == 0)
8545  {
8546  Image
8547  *minimum_image;
8548 
8549  /*
8550  Minimum image sequence (deprecated).
8551  */
8552  (void) SyncImagesSettings(mogrify_info,*images);
8553  minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
8554  if (minimum_image == (Image *) NULL)
8555  {
8556  status=MagickFalse;
8557  break;
8558  }
8559  *images=DestroyImageList(*images);
8560  *images=minimum_image;
8561  break;
8562  }
8563  if (LocaleCompare("morph",option+1) == 0)
8564  {
8565  Image
8566  *morph_image;
8567 
8568  (void) SyncImagesSettings(mogrify_info,*images);
8569  morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
8570  exception);
8571  if (morph_image == (Image *) NULL)
8572  {
8573  status=MagickFalse;
8574  break;
8575  }
8576  *images=DestroyImageList(*images);
8577  *images=morph_image;
8578  break;
8579  }
8580  if (LocaleCompare("mosaic",option+1) == 0)
8581  {
8582  Image
8583  *mosaic_image;
8584 
8585  (void) SyncImagesSettings(mogrify_info,*images);
8586  mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8587  if (mosaic_image == (Image *) NULL)
8588  {
8589  status=MagickFalse;
8590  break;
8591  }
8592  *images=DestroyImageList(*images);
8593  *images=mosaic_image;
8594  break;
8595  }
8596  break;
8597  }
8598  case 'p':
8599  {
8600  if (LocaleCompare("poly",option+1) == 0)
8601  {
8602  char
8603  *args,
8604  token[MaxTextExtent];
8605 
8606  const char
8607  *p;
8608 
8609  double
8610  *arguments;
8611 
8612  Image
8613  *polynomial_image;
8614 
8615  ssize_t
8616  x;
8617 
8618  size_t
8619  number_arguments;
8620 
8621  /*
8622  Polynomial image.
8623  */
8624  (void) SyncImageSettings(mogrify_info,*images);
8625  args=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
8626  InheritException(exception,&(*images)->exception);
8627  if (args == (char *) NULL)
8628  break;
8629  p=(char *) args;
8630  for (x=0; *p != '\0'; x++)
8631  {
8632  (void) GetNextToken(p,&p,MaxTextExtent,token);
8633  if (*token == ',')
8634  (void) GetNextToken(p,&p,MaxTextExtent,token);
8635  }
8636  number_arguments=(size_t) x;
8637  arguments=(double *) AcquireQuantumMemory(number_arguments,
8638  sizeof(*arguments));
8639  if (arguments == (double *) NULL)
8640  ThrowWandFatalException(ResourceLimitFatalError,
8641  "MemoryAllocationFailed",(*images)->filename);
8642  (void) memset(arguments,0,number_arguments*
8643  sizeof(*arguments));
8644  p=(char *) args;
8645  for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
8646  {
8647  (void) GetNextToken(p,&p,MaxTextExtent,token);
8648  if (*token == ',')
8649  (void) GetNextToken(p,&p,MaxTextExtent,token);
8650  arguments[x]=StringToDouble(token,(char **) NULL);
8651  }
8652  args=DestroyString(args);
8653  polynomial_image=PolynomialImageChannel(*images,channel,
8654  number_arguments >> 1,arguments,exception);
8655  arguments=(double *) RelinquishMagickMemory(arguments);
8656  if (polynomial_image == (Image *) NULL)
8657  {
8658  status=MagickFalse;
8659  break;
8660  }
8661  *images=DestroyImageList(*images);
8662  *images=polynomial_image;
8663  break;
8664  }
8665  if (LocaleCompare("print",option+1) == 0)
8666  {
8667  char
8668  *string;
8669 
8670  (void) SyncImagesSettings(mogrify_info,*images);
8671  string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
8672  if (string == (char *) NULL)
8673  break;
8674  InheritException(exception,&(*images)->exception);
8675  (void) FormatLocaleFile(stdout,"%s",string);
8676  string=DestroyString(string);
8677  }
8678  if (LocaleCompare("process",option+1) == 0)
8679  {
8680  char
8681  **arguments;
8682 
8683  int
8684  j,
8685  number_arguments;
8686 
8687  (void) SyncImagesSettings(mogrify_info,*images);
8688  arguments=StringToArgv(argv[i+1],&number_arguments);
8689  if (arguments == (char **) NULL)
8690  break;
8691  if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8692  {
8693  char
8694  breaker,
8695  quote,
8696  *token;
8697 
8698  const char
8699  *arguments;
8700 
8701  int
8702  next,
8703  status;
8704 
8705  size_t
8706  length;
8707 
8708  TokenInfo
8709  *token_info;
8710 
8711  /*
8712  Support old style syntax, filter="-option arg".
8713  */
8714  length=strlen(argv[i+1]);
8715  token=(char *) NULL;
8716  if (~length >= (MaxTextExtent-1))
8717  token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8718  sizeof(*token));
8719  if (token == (char *) NULL)
8720  break;
8721  next=0;
8722  arguments=argv[i+1];
8723  token_info=AcquireTokenInfo();
8724  status=Tokenizer(token_info,0,token,length,arguments,"","=",
8725  "\"",'\0',&breaker,&next,&quote);
8726  token_info=DestroyTokenInfo(token_info);
8727  if (status == 0)
8728  {
8729  const char
8730  *argv;
8731 
8732  argv=(&(arguments[next]));
8733  (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8734  exception);
8735  }
8736  token=DestroyString(token);
8737  break;
8738  }
8739  (void) SubstituteString(&arguments[1],"-","");
8740  (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8741  number_arguments-2,(const char **) arguments+2,exception);
8742  for (j=0; j < number_arguments; j++)
8743  arguments[j]=DestroyString(arguments[j]);
8744  arguments=(char **) RelinquishMagickMemory(arguments);
8745  break;
8746  }
8747  break;
8748  }
8749  case 'r':
8750  {
8751  if (LocaleCompare("reverse",option+1) == 0)
8752  {
8753  ReverseImageList(images);
8754  InheritException(exception,&(*images)->exception);
8755  break;
8756  }
8757  break;
8758  }
8759  case 's':
8760  {
8761  if (LocaleCompare("smush",option+1) == 0)
8762  {
8763  Image
8764  *smush_image;
8765 
8766  ssize_t
8767  offset;
8768 
8769  (void) SyncImagesSettings(mogrify_info,*images);
8770  offset=(ssize_t) StringToLong(argv[i+1]);
8771  smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8772  MagickFalse,offset,exception);
8773  if (smush_image == (Image *) NULL)
8774  {
8775  status=MagickFalse;
8776  break;
8777  }
8778  *images=DestroyImageList(*images);
8779  *images=smush_image;
8780  break;
8781  }
8782  if (LocaleCompare("swap",option+1) == 0)
8783  {
8784  Image
8785  *p,
8786  *q,
8787  *u,
8788  *v;
8789 
8790  ssize_t
8791  swap_index;
8792 
8793  index=(-1);
8794  swap_index=(-2);
8795  if (*option != '+')
8796  {
8797  GeometryInfo
8798  geometry_info;
8799 
8800  MagickStatusType
8801  flags;
8802 
8803  swap_index=(-1);
8804  flags=ParseGeometry(argv[i+1],&geometry_info);
8805  index=(ssize_t) geometry_info.rho;
8806  if ((flags & SigmaValue) != 0)
8807  swap_index=(ssize_t) geometry_info.sigma;
8808  }
8809  p=GetImageFromList(*images,index);
8810  q=GetImageFromList(*images,swap_index);
8811  if ((p == (Image *) NULL) || (q == (Image *) NULL))
8812  {
8813  (void) ThrowMagickException(exception,GetMagickModule(),
8814  OptionError,"NoSuchImage","`%s'",(*images)->filename);
8815  status=MagickFalse;
8816  break;
8817  }
8818  if (p == q)
8819  break;
8820  u=CloneImage(p,0,0,MagickTrue,exception);
8821  if (u == (Image *) NULL)
8822  break;
8823  v=CloneImage(q,0,0,MagickTrue,exception);
8824  if (v == (Image *) NULL)
8825  {
8826  u=DestroyImage(u);
8827  break;
8828  }
8829  ReplaceImageInList(&p,v);
8830  ReplaceImageInList(&q,u);
8831  *images=GetFirstImageInList(q);
8832  break;
8833  }
8834  break;
8835  }
8836  case 'w':
8837  {
8838  if (LocaleCompare("write",option+1) == 0)
8839  {
8840  char
8841  key[MaxTextExtent];
8842 
8843  Image
8844  *write_images;
8845 
8846  ImageInfo
8847  *write_info;
8848 
8849  (void) SyncImagesSettings(mogrify_info,*images);
8850  (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8851  (void) DeleteImageRegistry(key);
8852  write_images=CloneImageList(*images,exception);
8853  write_info=CloneImageInfo(mogrify_info);
8854  status&=WriteImages(write_info,write_images,argv[i+1],exception);
8855  write_info=DestroyImageInfo(write_info);
8856  write_images=DestroyImageList(write_images);
8857  break;
8858  }
8859  break;
8860  }
8861  default:
8862  break;
8863  }
8864  i+=count;
8865  }
8866  quantize_info=DestroyQuantizeInfo(quantize_info);
8867  mogrify_info=DestroyImageInfo(mogrify_info);
8868  status&=MogrifyImageInfo(image_info,argc,argv,exception);
8869  return(status != 0 ? MagickTrue : MagickFalse);
8870 }
8871 
8872 /*
8873 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8874 % %
8875 % %
8876 % %
8877 + M o g r i f y I m a g e s %
8878 % %
8879 % %
8880 % %
8881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8882 %
8883 % MogrifyImages() applies image processing options to a sequence of images as
8884 % prescribed by command line options.
8885 %
8886 % The format of the MogrifyImage method is:
8887 %
8888 % MagickBooleanType MogrifyImages(ImageInfo *image_info,
8889 % const MagickBooleanType post,const int argc,const char **argv,
8890 % Image **images,Exceptioninfo *exception)
8891 %
8892 % A description of each parameter follows:
8893 %
8894 % o image_info: the image info..
8895 %
8896 % o post: If true, post process image list operators otherwise pre-process.
8897 %
8898 % o argc: Specifies a pointer to an integer describing the number of
8899 % elements in the argument vector.
8900 %
8901 % o argv: Specifies a pointer to a text array containing the command line
8902 % arguments.
8903 %
8904 % o images: pointer to a pointer of the first image in image list.
8905 %
8906 % o exception: return any errors or warnings in this structure.
8907 %
8908 */
8909 WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8910  const MagickBooleanType post,const int argc,const char **argv,
8911  Image **images,ExceptionInfo *exception)
8912 {
8913 #define MogrifyImageTag "Mogrify/Image"
8914 
8915  MagickStatusType
8916  status;
8917 
8918  MagickBooleanType
8919  proceed;
8920 
8921  size_t
8922  n;
8923 
8924  ssize_t
8925  i;
8926 
8927  assert(image_info != (ImageInfo *) NULL);
8928  assert(image_info->signature == MagickCoreSignature);
8929  if (images == (Image **) NULL)
8930  return(MogrifyImage(image_info,argc,argv,images,exception));
8931  assert((*images)->previous == (Image *) NULL);
8932  assert((*images)->signature == MagickCoreSignature);
8933  if (IsEventLogging() != MagickFalse)
8934  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8935  (*images)->filename);
8936  if ((argc <= 0) || (*argv == (char *) NULL))
8937  return(MagickTrue);
8938  (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8939  (void *) NULL);
8940  status=MagickTrue;
8941 #if 0
8942  (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8943  post?"post":"pre");
8944 #endif
8945  /*
8946  Pre-process multi-image sequence operators
8947  */
8948  if (post == MagickFalse)
8949  status&=MogrifyImageList(image_info,argc,argv,images,exception);
8950  /*
8951  For each image, process simple single image operators
8952  */
8953  i=0;
8954  n=GetImageListLength(*images);
8955  for (;;)
8956  {
8957 #if 0
8958  (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8959  GetImageIndexInList(*images),(long)GetImageListLength(*images));
8960 #endif
8961  status&=MogrifyImage(image_info,argc,argv,images,exception);
8962  proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
8963  if (proceed == MagickFalse)
8964  break;
8965  if ((*images)->next == (Image *) NULL)
8966  break;
8967  *images=(*images)->next;
8968  i++;
8969  }
8970  assert(*images != (Image *) NULL);
8971 #if 0
8972  (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8973  GetImageIndexInList(*images),(long)GetImageListLength(*images));
8974 #endif
8975  /*
8976  Post-process, multi-image sequence operators
8977  */
8978  *images=GetFirstImageInList(*images);
8979  if (post != MagickFalse)
8980  status&=MogrifyImageList(image_info,argc,argv,images,exception);
8981  return(status != 0 ? MagickTrue : MagickFalse);
8982 }