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