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