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