MagickWand  6.9.13-50
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/license/ %
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  SetOpenMPMaxActiveLevels(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*MagickSafeReciprocal(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*MagickSafeReciprocal(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*(double) 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*=(double) QuantumRange/100.0;
1989  white_point*=(double) 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*(double) 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=(double) QuantumRange*geometry_info.rho/100.0;
3343  geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
3344  100.0;
3345  }
3346  if ((flags & SigmaValue) == 0)
3347  geometry_info.sigma=0.0;
3348  mogrify_image=WaveletDenoiseImage(*image,geometry_info.rho,
3349  geometry_info.sigma,exception);
3350  break;
3351  }
3352  if (LocaleCompare("weight",option+1) == 0)
3353  {
3354  ssize_t
3355  weight;
3356 
3357  weight=ParseCommandOption(MagickWeightOptions,MagickFalse,
3358  argv[i+1]);
3359  if (weight == -1)
3360  weight=(ssize_t) StringToUnsignedLong(argv[i+1]);
3361  draw_info->weight=(size_t) weight;
3362  break;
3363  }
3364  if (LocaleCompare("white-threshold",option+1) == 0)
3365  {
3366  /*
3367  White threshold image.
3368  */
3369  (void) SyncImageSettings(mogrify_info,*image);
3370  (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3371  exception);
3372  InheritException(exception,&(*image)->exception);
3373  break;
3374  }
3375  break;
3376  }
3377  default:
3378  break;
3379  }
3380  /*
3381  Replace current image with any image that was generated.
3382  */
3383  if (mogrify_image != (Image *) NULL)
3384  ReplaceImageInListReturnLast(image,mogrify_image);
3385  i+=count;
3386  }
3387  if (region_image != (Image *) NULL)
3388  {
3389  /*
3390  Composite transformed region onto image.
3391  */
3392  (void) SyncImageSettings(mogrify_info,*image);
3393  (void) CompositeImage(region_image,region_image->matte != MagickFalse ?
3394  CopyCompositeOp : OverCompositeOp,*image,region_geometry.x,
3395  region_geometry.y);
3396  InheritException(exception,&region_image->exception);
3397  *image=DestroyImage(*image);
3398  *image=region_image;
3399  region_image = (Image *) NULL;
3400  }
3401  /*
3402  Free resources.
3403  */
3404  quantize_info=DestroyQuantizeInfo(quantize_info);
3405  draw_info=DestroyDrawInfo(draw_info);
3406  mogrify_info=DestroyImageInfo(mogrify_info);
3407  status=(MagickStatusType) (exception->severity < ErrorException ? 1 : 0);
3408  return(status == 0 ? MagickFalse : MagickTrue);
3409 }
3410 
3411 /*
3412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3413 % %
3414 % %
3415 % %
3416 + M o g r i f y I m a g e C o m m a n d %
3417 % %
3418 % %
3419 % %
3420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3421 %
3422 % MogrifyImageCommand() transforms an image or a sequence of images. These
3423 % transforms include image scaling, image rotation, color reduction, and
3424 % others. The transmogrified image overwrites the original image.
3425 %
3426 % The format of the MogrifyImageCommand method is:
3427 %
3428 % MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3429 % const char **argv,char **metadata,ExceptionInfo *exception)
3430 %
3431 % A description of each parameter follows:
3432 %
3433 % o image_info: the image info.
3434 %
3435 % o argc: the number of elements in the argument vector.
3436 %
3437 % o argv: A text array containing the command line arguments.
3438 %
3439 % o metadata: any metadata is returned here.
3440 %
3441 % o exception: return any errors or warnings in this structure.
3442 %
3443 */
3444 
3445 static MagickBooleanType MogrifyUsage(void)
3446 {
3447  static const char
3448  miscellaneous[] =
3449  " -debug events display copious debugging information\n"
3450  " -distribute-cache port\n"
3451  " distributed pixel cache spanning one or more servers\n"
3452  " -help print program options\n"
3453  " -list type print a list of supported option arguments\n"
3454  " -log format format of debugging information\n"
3455  " -version print version information",
3456  operators[] =
3457  " -adaptive-blur geometry\n"
3458  " adaptively blur pixels; decrease effect near edges\n"
3459  " -adaptive-resize geometry\n"
3460  " adaptively resize image using 'mesh' interpolation\n"
3461  " -adaptive-sharpen geometry\n"
3462  " adaptively sharpen pixels; increase effect near edges\n"
3463  " -alpha option on, activate, off, deactivate, set, opaque, copy\n"
3464  " transparent, extract, background, or shape\n"
3465  " -annotate geometry text\n"
3466  " annotate the image with text\n"
3467  " -auto-gamma automagically adjust gamma level of image\n"
3468  " -auto-level automagically adjust color levels of image\n"
3469  " -auto-orient automagically orient (rotate) image\n"
3470  " -bench iterations measure performance\n"
3471  " -black-threshold value\n"
3472  " force all pixels below the threshold into black\n"
3473  " -blue-shift simulate a scene at nighttime in the moonlight\n"
3474  " -blur geometry reduce image noise and reduce detail levels\n"
3475  " -border geometry surround image with a border of color\n"
3476  " -bordercolor color border color\n"
3477  " -brightness-contrast geometry\n"
3478  " improve brightness / contrast of the image\n"
3479  " -canny geometry detect edges in the image\n"
3480  " -cdl filename color correct with a color decision list\n"
3481  " -charcoal radius simulate a charcoal drawing\n"
3482  " -chop geometry remove pixels from the image interior\n"
3483  " -clamp keep pixel values in range (0-QuantumRange)\n"
3484  " -clip clip along the first path from the 8BIM profile\n"
3485  " -clip-mask filename associate a clip mask with the image\n"
3486  " -clip-path id clip along a named path from the 8BIM profile\n"
3487  " -colorize value colorize the image with the fill color\n"
3488  " -color-matrix matrix apply color correction to the image\n"
3489  " -connected-components connectivity\n"
3490  " connected-components uniquely labeled\n"
3491  " -contrast enhance or reduce the image contrast\n"
3492  " -contrast-stretch geometry\n"
3493  " improve contrast by `stretching' the intensity range\n"
3494  " -convolve coefficients\n"
3495  " apply a convolution kernel to the image\n"
3496  " -cycle amount cycle the image colormap\n"
3497  " -decipher filename convert cipher pixels to plain pixels\n"
3498  " -deskew threshold straighten an image\n"
3499  " -despeckle reduce the speckles within an image\n"
3500  " -distort method args\n"
3501  " distort images according to given method ad args\n"
3502  " -draw string annotate the image with a graphic primitive\n"
3503  " -edge radius apply a filter to detect edges in the image\n"
3504  " -encipher filename convert plain pixels to cipher pixels\n"
3505  " -emboss radius emboss an image\n"
3506  " -enhance apply a digital filter to enhance a noisy image\n"
3507  " -equalize perform histogram equalization to an image\n"
3508  " -evaluate operator value\n"
3509  " evaluate an arithmetic, relational, or logical expression\n"
3510  " -extent geometry set the image size\n"
3511  " -extract geometry extract area from image\n"
3512  " -hough-lines geometry\n"
3513  " identify lines in the image\n"
3514  " -features distance analyze image features (e.g. contrast, correlation)\n"
3515  " -fft implements the discrete Fourier transform (DFT)\n"
3516  " -flip flip image vertically\n"
3517  " -floodfill geometry color\n"
3518  " floodfill the image with color\n"
3519  " -flop flop image horizontally\n"
3520  " -frame geometry surround image with an ornamental border\n"
3521  " -function name parameters\n"
3522  " apply function over image values\n"
3523  " -gamma value level of gamma correction\n"
3524  " -gaussian-blur geometry\n"
3525  " reduce image noise and reduce detail levels\n"
3526  " -geometry geometry preferred size or location of the image\n"
3527  " -grayscale method convert image to grayscale\n"
3528  " -help print program options\n"
3529  " -identify identify the format and characteristics of the image\n"
3530  " -ift implements the inverse discrete Fourier transform (DFT)\n"
3531  " -implode amount implode image pixels about the center\n"
3532  " -kuwahara geometry edge preserving noise reduction filter\n"
3533  " -lat geometry local adaptive thresholding\n"
3534  " -layers method optimize, merge, or compare image layers\n"
3535  " -level value adjust the level of image contrast\n"
3536  " -level-colors color,color\n"
3537  " level image with the given colors\n"
3538  " -linear-stretch geometry\n"
3539  " improve contrast by `stretching with saturation'\n"
3540  " -liquid-rescale geometry\n"
3541  " rescale image with seam-carving\n"
3542  " -local-contrast geometry\n"
3543  " enhance local contrast\n"
3544  " -magnify double the size of the image with pixel art scaling\n"
3545  " -mean-shift geometry delineate arbitrarily shaped clusters in the image\n"
3546  " -median geometry apply a median filter to the image\n"
3547  " -mode geometry make each pixel the 'predominant color' of the\n"
3548  " neighborhood\n"
3549  " -modulate value vary the brightness, saturation, and hue\n"
3550  " -monochrome transform image to black and white\n"
3551  " -morphology method kernel\n"
3552  " apply a morphology method to the image\n"
3553  " -motion-blur geometry\n"
3554  " simulate motion blur\n"
3555  " -negate replace every pixel with its complementary color \n"
3556  " -noise geometry add or reduce noise in an image\n"
3557  " -normalize transform image to span the full range of colors\n"
3558  " -opaque color change this color to the fill color\n"
3559  " -ordered-dither NxN\n"
3560  " add a noise pattern to the image with specific\n"
3561  " amplitudes\n"
3562  " -paint radius simulate an oil painting\n"
3563  " -perceptible epsilon\n"
3564  " pixel value less than |epsilon| become epsilon or\n"
3565  " -epsilon\n"
3566  " -polaroid angle simulate a Polaroid picture\n"
3567  " -posterize levels reduce the image to a limited number of color levels\n"
3568  " -profile filename add, delete, or apply an image profile\n"
3569  " -quantize colorspace reduce colors in this colorspace\n"
3570  " -radial-blur angle radial blur the image\n"
3571  " -raise value lighten/darken image edges to create a 3-D effect\n"
3572  " -random-threshold low,high\n"
3573  " random threshold the image\n"
3574  " -region geometry apply options to a portion of the image\n"
3575  " -render render vector graphics\n"
3576  " -resample geometry change the resolution of an image\n"
3577  " -resize geometry resize the image\n"
3578  " -roll geometry roll an image vertically or horizontally\n"
3579  " -rotate degrees apply Paeth rotation to the image\n"
3580  " -sample geometry scale image with pixel sampling\n"
3581  " -scale geometry scale the image\n"
3582  " -segment values segment an image\n"
3583  " -selective-blur geometry\n"
3584  " selectively blur pixels within a contrast threshold\n"
3585  " -sepia-tone threshold\n"
3586  " simulate a sepia-toned photo\n"
3587  " -set property value set an image property\n"
3588  " -shade degrees shade the image using a distant light source\n"
3589  " -shadow geometry simulate an image shadow\n"
3590  " -sharpen geometry sharpen the image\n"
3591  " -shave geometry shave pixels from the image edges\n"
3592  " -shear geometry slide one edge of the image along the X or Y axis\n"
3593  " -sigmoidal-contrast geometry\n"
3594  " increase the contrast without saturating highlights or\n"
3595  " shadows\n"
3596  " -sketch geometry simulate a pencil sketch\n"
3597  " -solarize threshold negate all pixels above the threshold level\n"
3598  " -sparse-color method args\n"
3599  " fill in a image based on a few color points\n"
3600  " -splice geometry splice the background color into the image\n"
3601  " -spread radius displace image pixels by a random amount\n"
3602  " -statistic type radius\n"
3603  " replace each pixel with corresponding statistic from the neighborhood\n"
3604  " -strip strip image of all profiles and comments\n"
3605  " -swirl degrees swirl image pixels about the center\n"
3606  " -threshold value threshold the image\n"
3607  " -thumbnail geometry create a thumbnail of the image\n"
3608  " -tile filename tile image when filling a graphic primitive\n"
3609  " -tint value tint the image with the fill color\n"
3610  " -transform affine transform image\n"
3611  " -transparent color make this color transparent within the image\n"
3612  " -transpose flip image vertically and rotate 90 degrees\n"
3613  " -transverse flop image horizontally and rotate 270 degrees\n"
3614  " -trim trim image edges\n"
3615  " -type type image type\n"
3616  " -unique-colors discard all but one of any pixel color\n"
3617  " -unsharp geometry sharpen the image\n"
3618  " -vignette geometry soften the edges of the image in vignette style\n"
3619  " -wave geometry alter an image along a sine wave\n"
3620  " -wavelet-denoise threshold\n"
3621  " removes noise from the image using a wavelet transform\n"
3622  " -white-threshold value\n"
3623  " force all pixels above the threshold into white",
3624  sequence_operators[] =
3625  " -affinity filename transform image colors to match this set of colors\n"
3626  " -append append an image sequence\n"
3627  " -clut apply a color lookup table to the image\n"
3628  " -coalesce merge a sequence of images\n"
3629  " -combine combine a sequence of images\n"
3630  " -compare mathematically and visually annotate the difference between an image and its reconstruction\n"
3631  " -complex operator perform complex mathematics on an image sequence\n"
3632  " -composite composite image\n"
3633  " -copy geometry offset\n"
3634  " copy pixels from one area of an image to another\n"
3635  " -crop geometry cut out a rectangular region of the image\n"
3636  " -deconstruct break down an image sequence into constituent parts\n"
3637  " -evaluate-sequence operator\n"
3638  " evaluate an arithmetic, relational, or logical expression\n"
3639  " -flatten flatten a sequence of images\n"
3640  " -fx expression apply mathematical expression to an image channel(s)\n"
3641  " -hald-clut apply a Hald color lookup table to the image\n"
3642  " -layers method optimize, merge, or compare image layers\n"
3643  " -morph value morph an image sequence\n"
3644  " -mosaic create a mosaic from an image sequence\n"
3645  " -poly terms build a polynomial from the image sequence and the corresponding\n"
3646  " terms (coefficients and degree pairs).\n"
3647  " -print string interpret string and print to console\n"
3648  " -process arguments process the image with a custom image filter\n"
3649  " -separate separate an image channel into a grayscale image\n"
3650  " -smush geometry smush an image sequence together\n"
3651  " -write filename write images to this file",
3652  settings[] =
3653  " -adjoin join images into a single multi-image file\n"
3654  " -affine matrix affine transform matrix\n"
3655  " -alpha option activate, deactivate, reset, or set the alpha channel\n"
3656  " -antialias remove pixel-aliasing\n"
3657  " -authenticate password\n"
3658  " decipher image with this password\n"
3659  " -attenuate value lessen (or intensify) when adding noise to an image\n"
3660  " -background color background color\n"
3661  " -bias value add bias when convolving an image\n"
3662  " -black-point-compensation\n"
3663  " use black point compensation\n"
3664  " -blue-primary point chromaticity blue primary point\n"
3665  " -bordercolor color border color\n"
3666  " -caption string assign a caption to an image\n"
3667  " -cdl filename color correct with a color decision list\n"
3668  " -channel type apply option to select image channels\n"
3669  " -colors value preferred number of colors in the image\n"
3670  " -colorspace type alternate image colorspace\n"
3671  " -comment string annotate image with comment\n"
3672  " -compose operator set image composite operator\n"
3673  " -compress type type of pixel compression when writing the image\n"
3674  " -decipher filename convert cipher pixels to plain pixels\n"
3675  " -define format:option\n"
3676  " define one or more image format options\n"
3677  " -delay value display the next image after pausing\n"
3678  " -density geometry horizontal and vertical density of the image\n"
3679  " -depth value image depth\n"
3680  " -direction type render text right-to-left or left-to-right\n"
3681  " -display server get image or font from this X server\n"
3682  " -dispose method layer disposal method\n"
3683  " -dither method apply error diffusion to image\n"
3684  " -encipher filename convert plain pixels to cipher pixels\n"
3685  " -encoding type text encoding type\n"
3686  " -endian type endianness (MSB or LSB) of the image\n"
3687  " -family name render text with this font family\n"
3688  " -features distance analyze image features (e.g. contrast, correlation)\n"
3689  " -fill color color to use when filling a graphic primitive\n"
3690  " -filter type use this filter when resizing an image\n"
3691  " -flatten flatten a sequence of images\n"
3692  " -font name render text with this font\n"
3693  " -format \"string\" output formatted image characteristics\n"
3694  " -function name apply a function to the image\n"
3695  " -fuzz distance colors within this distance are considered equal\n"
3696  " -gravity type horizontal and vertical text placement\n"
3697  " -green-primary point chromaticity green primary point\n"
3698  " -intensity method method to generate intensity value from pixel\n"
3699  " -intent type type of rendering intent when managing the image color\n"
3700  " -interlace type type of image interlacing scheme\n"
3701  " -interline-spacing value\n"
3702  " set the space between two text lines\n"
3703  " -interpolate method pixel color interpolation method\n"
3704  " -interword-spacing value\n"
3705  " set the space between two words\n"
3706  " -kerning value set the space between two letters\n"
3707  " -label string assign a label to an image\n"
3708  " -limit type value pixel cache resource limit\n"
3709  " -loop iterations add Netscape loop extension to your GIF animation\n"
3710  " -mask filename associate a mask with the image\n"
3711  " -matte store matte channel if the image has one\n"
3712  " -mattecolor color frame color\n"
3713  " -monitor monitor progress\n"
3714  " -morphology method kernel\n"
3715  " apply a morphology method to the image\n"
3716  " -orient type image orientation\n"
3717  " -page geometry size and location of an image canvas (setting)\n"
3718  " -path path write images to this path on disk\n"
3719  " -ping efficiently determine image attributes\n"
3720  " -pointsize value font point size\n"
3721  " -precision value maximum number of significant digits to print\n"
3722  " -preview type image preview type\n"
3723  " -quality value JPEG/MIFF/PNG compression level\n"
3724  " -quiet suppress all warning messages\n"
3725  " -red-primary point chromaticity red primary point\n"
3726  " -regard-warnings pay attention to warning messages\n"
3727  " -remap filename transform image colors to match this set of colors\n"
3728  " -repage geometry size and location of an image canvas\n"
3729  " -respect-parentheses settings remain in effect until parenthesis boundary\n"
3730  " -sampling-factor geometry\n"
3731  " horizontal and vertical sampling factor\n"
3732  " -scene value image scene number\n"
3733  " -seed value seed a new sequence of pseudo-random numbers\n"
3734  " -size geometry width and height of image\n"
3735  " -stretch type render text with this font stretch\n"
3736  " -stroke color graphic primitive stroke color\n"
3737  " -strokewidth value graphic primitive stroke width\n"
3738  " -style type render text with this font style\n"
3739  " -synchronize synchronize image to storage device\n"
3740  " -taint declare the image as modified\n"
3741  " -texture filename name of texture to tile onto the image background\n"
3742  " -tile-offset geometry\n"
3743  " tile offset\n"
3744  " -treedepth value color tree depth\n"
3745  " -transparent-color color\n"
3746  " transparent color\n"
3747  " -undercolor color annotation bounding box color\n"
3748  " -units type the units of image resolution\n"
3749  " -verbose print detailed information about the image\n"
3750  " -view FlashPix viewing transforms\n"
3751  " -virtual-pixel method\n"
3752  " virtual pixel access method\n"
3753  " -weight type render text with this font weight\n"
3754  " -white-point point chromaticity white point",
3755  stack_operators[] =
3756  " -delete indexes delete the image from the image sequence\n"
3757  " -duplicate count,indexes\n"
3758  " duplicate an image one or more times\n"
3759  " -insert index insert last image into the image sequence\n"
3760  " -reverse reverse image sequence\n"
3761  " -swap indexes swap two images in the image sequence";
3762 
3763  ListMagickVersion(stdout);
3764  (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3765  GetClientName());
3766  (void) fprintf(stdout,"\nImage Settings:\n");
3767  (void) fputs(settings,stdout);
3768  (void) fprintf(stdout,"\nImage Operators:\n");
3769  (void) fputs(operators,stdout);
3770  (void) fprintf(stdout,"\nImage Sequence Operators:\n");
3771  (void) fputs(sequence_operators,stdout);
3772  (void) fprintf(stdout,"\nImage Stack Operators:\n");
3773  (void) fputs(stack_operators,stdout);
3774  (void) fprintf(stdout,"\nMiscellaneous Options:\n");
3775  (void) fputs(miscellaneous,stdout);
3776  (void) fprintf(stdout,
3777  "\nBy default, the image format of `file' is determined by its magic\n");
3778  (void) fprintf(stdout,
3779  "number. To specify a particular image format, precede the filename\n");
3780  (void) fprintf(stdout,
3781  "with an image format name and a colon (i.e. ps:image) or specify the\n");
3782  (void) fprintf(stdout,
3783  "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3784  (void) fprintf(stdout,"'-' for standard input or output.\n");
3785  return(MagickTrue);
3786 }
3787 
3788 WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3789  int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3790 {
3791 #define DestroyMogrify() \
3792 { \
3793  if (format != (char *) NULL) \
3794  format=DestroyString(format); \
3795  if (path != (char *) NULL) \
3796  path=DestroyString(path); \
3797  DestroyImageStack(); \
3798  for (i=0; i < (ssize_t) argc; i++) \
3799  argv[i]=DestroyString(argv[i]); \
3800  argv=(char **) RelinquishMagickMemory(argv); \
3801 }
3802 #define ThrowMogrifyException(asperity,tag,option) \
3803 { \
3804  char *message = GetExceptionMessage(errno); \
3805  (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag, \
3806  "`%s'",option == (char *) NULL ? message : option); \
3807  message=DestroyString(message); \
3808  DestroyMogrify(); \
3809  return(MagickFalse); \
3810 }
3811 #define ThrowMogrifyInvalidArgumentException(option,argument) \
3812 { \
3813  (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3814  "InvalidArgument","`%s': %s",argument,option); \
3815  DestroyMogrify(); \
3816  return(MagickFalse); \
3817 }
3818 
3819  char
3820  *format,
3821  *option,
3822  *path;
3823 
3824  Image
3825  *image;
3826 
3827  ImageStack
3828  image_stack[MaxImageStackDepth+1];
3829 
3830  MagickBooleanType
3831  global_colormap;
3832 
3833  MagickBooleanType
3834  fire,
3835  pend,
3836  respect_parenthesis;
3837 
3838  MagickStatusType
3839  status;
3840 
3841  ssize_t
3842  i;
3843 
3844  ssize_t
3845  j,
3846  k;
3847 
3848  wand_unreferenced(metadata);
3849 
3850  /*
3851  Set defaults.
3852  */
3853  assert(image_info != (ImageInfo *) NULL);
3854  assert(image_info->signature == MagickCoreSignature);
3855  assert(exception != (ExceptionInfo *) NULL);
3856  if (IsEventLogging() != MagickFalse)
3857  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3858  if (argc == 2)
3859  {
3860  option=argv[1];
3861  if ((LocaleCompare("version",option+1) == 0) ||
3862  (LocaleCompare("-version",option+1) == 0))
3863  {
3864  ListMagickVersion(stdout);
3865  return(MagickTrue);
3866  }
3867  }
3868  if (argc < 2)
3869  {
3870  (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
3871  "MissingArgument","%s","");
3872  (void) MogrifyUsage();
3873  return(MagickFalse);
3874  }
3875  format=(char *) NULL;
3876  path=(char *) NULL;
3877  global_colormap=MagickFalse;
3878  k=0;
3879  j=1;
3880  NewImageStack();
3881  option=(char *) NULL;
3882  pend=MagickFalse;
3883  respect_parenthesis=MagickFalse;
3884  status=MagickTrue;
3885  /*
3886  Parse command line.
3887  */
3888  ReadCommandlLine(argc,&argv);
3889  status=ExpandFilenames(&argc,&argv);
3890  if (status == MagickFalse)
3891  ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3892  (char *) NULL);
3893  for (i=1; i < (ssize_t) argc; i++)
3894  {
3895  option=argv[i];
3896  if (LocaleCompare(option,"(") == 0)
3897  {
3898  FireImageStack(MagickFalse,MagickTrue,pend);
3899  if (k == MaxImageStackDepth)
3900  ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3901  option);
3902  PushImageStack();
3903  continue;
3904  }
3905  if (LocaleCompare(option,")") == 0)
3906  {
3907  FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3908  if (k == 0)
3909  ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3910  PopImageStack();
3911  continue;
3912  }
3913  if (IsCommandOption(option) == MagickFalse)
3914  {
3915  char
3916  backup_filename[MaxTextExtent],
3917  *filename,
3918  magic[MagickPathExtent];
3919 
3920  Image
3921  *images;
3922 
3923  struct stat
3924  properties;
3925 
3926  /*
3927  Option is a file name: begin by reading image from specified file.
3928  */
3929  FireImageStack(MagickFalse,MagickFalse,pend);
3930  filename=argv[i];
3931  if ((LocaleCompare(filename,"--") == 0) && (i < ((ssize_t) argc-1)))
3932  filename=argv[++i];
3933  (void) SetImageOption(image_info,"filename",filename);
3934  (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3935  images=ReadImages(image_info,exception);
3936  status&=(images != (Image *) NULL) &&
3937  (exception->severity < ErrorException);
3938  if (images == (Image *) NULL)
3939  continue;
3940  properties=(*GetBlobProperties(images));
3941  if (format != (char *) NULL)
3942  GetPathComponent(images->magick_filename,BasePathSansCompressExtension,
3943  images->filename);
3944  if (path != (char *) NULL)
3945  {
3946  GetPathComponent(option,TailPath,filename);
3947  (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
3948  path,*DirectorySeparator,filename);
3949  }
3950  if (format != (char *) NULL)
3951  AppendImageFormat(format,images->filename);
3952  AppendImageStack(images);
3953  FinalizeImageSettings(image_info,image,MagickFalse);
3954  if (image == (Image *) NULL)
3955  continue;
3956  if (global_colormap != MagickFalse)
3957  {
3958  QuantizeInfo
3959  *quantize_info;
3960 
3961  quantize_info=AcquireQuantizeInfo(image_info);
3962  (void) RemapImages(quantize_info,images,(Image *) NULL);
3963  quantize_info=DestroyQuantizeInfo(quantize_info);
3964  }
3965  *backup_filename='\0';
3966  *magic='\0';
3967  GetPathComponent(filename,MagickPath,magic);
3968  if (*magic != '\0')
3969  {
3970  char
3971  filename[MagickPathExtent];
3972 
3973  if (format != (char *) NULL)
3974  (void) CopyMagickString(magic,format,MagickPathExtent);
3975  (void) FormatLocaleString(filename,MagickPathExtent,"%s:%s",magic,
3976  image->filename);
3977  (void) CopyMagickString(image->filename,filename,MagickPathExtent);
3978  }
3979  if ((LocaleCompare(image->filename,"-") != 0) &&
3980  (IsPathWritable(image->filename) != MagickFalse))
3981  {
3982  ssize_t
3983  i;
3984 
3985  /*
3986  Rename image file as backup.
3987  */
3988  (void) CopyMagickString(backup_filename,image->filename,
3989  MaxTextExtent);
3990  for (i=0; i < 6; i++)
3991  {
3992  (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3993  if (IsPathAccessible(backup_filename) == MagickFalse)
3994  break;
3995  }
3996  if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3997  (rename_utf8(image->filename,backup_filename) != 0))
3998  *backup_filename='\0';
3999  }
4000  /*
4001  Write transmogrified image to disk.
4002  */
4003  image_info->synchronize=MagickTrue;
4004  status&=WriteImages(image_info,image,image->filename,exception);
4005  if (status != MagickFalse)
4006  {
4007  MagickBooleanType
4008  preserve_timestamp;
4009 
4010  preserve_timestamp=IsStringTrue(GetImageOption(image_info,
4011  "preserve-timestamp"));
4012  if (preserve_timestamp != MagickFalse)
4013  (void) set_file_timestamp(image->filename,&properties);
4014  if (*backup_filename != '\0')
4015  (void) remove_utf8(backup_filename);
4016  }
4017  else
4018  if (*backup_filename != '\0')
4019  (void) rename_utf8(backup_filename,image->filename);
4020  RemoveAllImageStack();
4021  continue;
4022  }
4023  pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
4024  switch (*(option+1))
4025  {
4026  case 'a':
4027  {
4028  if (LocaleCompare("adaptive-blur",option+1) == 0)
4029  {
4030  i++;
4031  if (i == (ssize_t) argc)
4032  ThrowMogrifyException(OptionError,"MissingArgument",option);
4033  if (IsGeometry(argv[i]) == MagickFalse)
4034  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4035  break;
4036  }
4037  if (LocaleCompare("adaptive-resize",option+1) == 0)
4038  {
4039  i++;
4040  if (i == (ssize_t) argc)
4041  ThrowMogrifyException(OptionError,"MissingArgument",option);
4042  if (IsGeometry(argv[i]) == MagickFalse)
4043  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4044  break;
4045  }
4046  if (LocaleCompare("adaptive-sharpen",option+1) == 0)
4047  {
4048  i++;
4049  if (i == (ssize_t) argc)
4050  ThrowMogrifyException(OptionError,"MissingArgument",option);
4051  if (IsGeometry(argv[i]) == MagickFalse)
4052  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4053  break;
4054  }
4055  if (LocaleCompare("affine",option+1) == 0)
4056  {
4057  if (*option == '+')
4058  break;
4059  i++;
4060  if (i == (ssize_t) argc)
4061  ThrowMogrifyException(OptionError,"MissingArgument",option);
4062  if (IsGeometry(argv[i]) == MagickFalse)
4063  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4064  break;
4065  }
4066  if (LocaleCompare("alpha",option+1) == 0)
4067  {
4068  ssize_t
4069  type;
4070 
4071  if (*option == '+')
4072  break;
4073  i++;
4074  if (i == (ssize_t) argc)
4075  ThrowMogrifyException(OptionError,"MissingArgument",option);
4076  type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
4077  if (type < 0)
4078  ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
4079  argv[i]);
4080  break;
4081  }
4082  if (LocaleCompare("annotate",option+1) == 0)
4083  {
4084  if (*option == '+')
4085  break;
4086  i++;
4087  if (i == (ssize_t) argc)
4088  ThrowMogrifyException(OptionError,"MissingArgument",option);
4089  if (IsGeometry(argv[i]) == MagickFalse)
4090  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4091  if (i == (ssize_t) argc)
4092  ThrowMogrifyException(OptionError,"MissingArgument",option);
4093  i++;
4094  break;
4095  }
4096  if (LocaleCompare("antialias",option+1) == 0)
4097  break;
4098  if (LocaleCompare("append",option+1) == 0)
4099  break;
4100  if (LocaleCompare("attenuate",option+1) == 0)
4101  {
4102  if (*option == '+')
4103  break;
4104  i++;
4105  if (i == (ssize_t) argc)
4106  ThrowMogrifyException(OptionError,"MissingArgument",option);
4107  if (IsGeometry(argv[i]) == MagickFalse)
4108  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4109  break;
4110  }
4111  if (LocaleCompare("authenticate",option+1) == 0)
4112  {
4113  if (*option == '+')
4114  break;
4115  i++;
4116  if (i == (ssize_t) argc)
4117  ThrowMogrifyException(OptionError,"MissingArgument",option);
4118  break;
4119  }
4120  if (LocaleCompare("auto-gamma",option+1) == 0)
4121  break;
4122  if (LocaleCompare("auto-level",option+1) == 0)
4123  break;
4124  if (LocaleCompare("auto-orient",option+1) == 0)
4125  break;
4126  if (LocaleCompare("average",option+1) == 0)
4127  break;
4128  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4129  }
4130  case 'b':
4131  {
4132  if (LocaleCompare("background",option+1) == 0)
4133  {
4134  if (*option == '+')
4135  break;
4136  i++;
4137  if (i == (ssize_t) argc)
4138  ThrowMogrifyException(OptionError,"MissingArgument",option);
4139  break;
4140  }
4141  if (LocaleCompare("bias",option+1) == 0)
4142  {
4143  if (*option == '+')
4144  break;
4145  i++;
4146  if (i == (ssize_t) argc)
4147  ThrowMogrifyException(OptionError,"MissingArgument",option);
4148  if (IsGeometry(argv[i]) == MagickFalse)
4149  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4150  break;
4151  }
4152  if (LocaleCompare("black-point-compensation",option+1) == 0)
4153  break;
4154  if (LocaleCompare("black-threshold",option+1) == 0)
4155  {
4156  if (*option == '+')
4157  break;
4158  i++;
4159  if (i == (ssize_t) argc)
4160  ThrowMogrifyException(OptionError,"MissingArgument",option);
4161  if (IsGeometry(argv[i]) == MagickFalse)
4162  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4163  break;
4164  }
4165  if (LocaleCompare("blue-primary",option+1) == 0)
4166  {
4167  if (*option == '+')
4168  break;
4169  i++;
4170  if (i == (ssize_t) argc)
4171  ThrowMogrifyException(OptionError,"MissingArgument",option);
4172  if (IsGeometry(argv[i]) == MagickFalse)
4173  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4174  break;
4175  }
4176  if (LocaleCompare("blue-shift",option+1) == 0)
4177  {
4178  i++;
4179  if (i == (ssize_t) argc)
4180  ThrowMogrifyException(OptionError,"MissingArgument",option);
4181  if (IsGeometry(argv[i]) == MagickFalse)
4182  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4183  break;
4184  }
4185  if (LocaleCompare("blur",option+1) == 0)
4186  {
4187  i++;
4188  if (i == (ssize_t) argc)
4189  ThrowMogrifyException(OptionError,"MissingArgument",option);
4190  if (IsGeometry(argv[i]) == MagickFalse)
4191  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4192  break;
4193  }
4194  if (LocaleCompare("border",option+1) == 0)
4195  {
4196  if (*option == '+')
4197  break;
4198  i++;
4199  if (i == (ssize_t) argc)
4200  ThrowMogrifyException(OptionError,"MissingArgument",option);
4201  if (IsGeometry(argv[i]) == MagickFalse)
4202  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4203  break;
4204  }
4205  if (LocaleCompare("bordercolor",option+1) == 0)
4206  {
4207  if (*option == '+')
4208  break;
4209  i++;
4210  if (i == (ssize_t) argc)
4211  ThrowMogrifyException(OptionError,"MissingArgument",option);
4212  break;
4213  }
4214  if (LocaleCompare("box",option+1) == 0)
4215  {
4216  if (*option == '+')
4217  break;
4218  i++;
4219  if (i == (ssize_t) argc)
4220  ThrowMogrifyException(OptionError,"MissingArgument",option);
4221  break;
4222  }
4223  if (LocaleCompare("brightness-contrast",option+1) == 0)
4224  {
4225  i++;
4226  if (i == (ssize_t) argc)
4227  ThrowMogrifyException(OptionError,"MissingArgument",option);
4228  if (IsGeometry(argv[i]) == MagickFalse)
4229  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4230  break;
4231  }
4232  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4233  }
4234  case 'c':
4235  {
4236  if (LocaleCompare("cache",option+1) == 0)
4237  {
4238  if (*option == '+')
4239  break;
4240  i++;
4241  if (i == (ssize_t) argc)
4242  ThrowMogrifyException(OptionError,"MissingArgument",option);
4243  if (IsGeometry(argv[i]) == MagickFalse)
4244  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4245  break;
4246  }
4247  if (LocaleCompare("canny",option+1) == 0)
4248  {
4249  if (*option == '+')
4250  break;
4251  i++;
4252  if (i == (ssize_t) argc)
4253  ThrowMogrifyException(OptionError,"MissingArgument",option);
4254  if (IsGeometry(argv[i]) == MagickFalse)
4255  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4256  break;
4257  }
4258  if (LocaleCompare("caption",option+1) == 0)
4259  {
4260  if (*option == '+')
4261  break;
4262  i++;
4263  if (i == (ssize_t) argc)
4264  ThrowMogrifyException(OptionError,"MissingArgument",option);
4265  break;
4266  }
4267  if (LocaleCompare("channel",option+1) == 0)
4268  {
4269  ssize_t
4270  channel;
4271 
4272  if (*option == '+')
4273  break;
4274  i++;
4275  if (i == (ssize_t) argc)
4276  ThrowMogrifyException(OptionError,"MissingArgument",option);
4277  channel=ParseChannelOption(argv[i]);
4278  if (channel < 0)
4279  ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4280  argv[i]);
4281  break;
4282  }
4283  if (LocaleCompare("cdl",option+1) == 0)
4284  {
4285  if (*option == '+')
4286  break;
4287  i++;
4288  if (i == (ssize_t) argc)
4289  ThrowMogrifyException(OptionError,"MissingArgument",option);
4290  break;
4291  }
4292  if (LocaleCompare("charcoal",option+1) == 0)
4293  {
4294  if (*option == '+')
4295  break;
4296  i++;
4297  if (i == (ssize_t) argc)
4298  ThrowMogrifyException(OptionError,"MissingArgument",option);
4299  if (IsGeometry(argv[i]) == MagickFalse)
4300  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4301  break;
4302  }
4303  if (LocaleCompare("chop",option+1) == 0)
4304  {
4305  if (*option == '+')
4306  break;
4307  i++;
4308  if (i == (ssize_t) argc)
4309  ThrowMogrifyException(OptionError,"MissingArgument",option);
4310  if (IsGeometry(argv[i]) == MagickFalse)
4311  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4312  break;
4313  }
4314  if (LocaleCompare("clamp",option+1) == 0)
4315  break;
4316  if (LocaleCompare("clip",option+1) == 0)
4317  break;
4318  if (LocaleCompare("clip-mask",option+1) == 0)
4319  {
4320  if (*option == '+')
4321  break;
4322  i++;
4323  if (i == (ssize_t) argc)
4324  ThrowMogrifyException(OptionError,"MissingArgument",option);
4325  break;
4326  }
4327  if (LocaleCompare("clut",option+1) == 0)
4328  break;
4329  if (LocaleCompare("coalesce",option+1) == 0)
4330  break;
4331  if (LocaleCompare("colorize",option+1) == 0)
4332  {
4333  if (*option == '+')
4334  break;
4335  i++;
4336  if (i == (ssize_t) argc)
4337  ThrowMogrifyException(OptionError,"MissingArgument",option);
4338  if (IsGeometry(argv[i]) == MagickFalse)
4339  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4340  break;
4341  }
4342  if (LocaleCompare("color-matrix",option+1) == 0)
4343  {
4344  KernelInfo
4345  *kernel_info;
4346 
4347  if (*option == '+')
4348  break;
4349  i++;
4350  if (i == (ssize_t) argc)
4351  ThrowMogrifyException(OptionError,"MissingArgument",option);
4352  kernel_info=AcquireKernelInfo(argv[i]);
4353  if (kernel_info == (KernelInfo *) NULL)
4354  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4355  kernel_info=DestroyKernelInfo(kernel_info);
4356  break;
4357  }
4358  if (LocaleCompare("colors",option+1) == 0)
4359  {
4360  if (*option == '+')
4361  break;
4362  i++;
4363  if (i == (ssize_t) argc)
4364  ThrowMogrifyException(OptionError,"MissingArgument",option);
4365  if (IsGeometry(argv[i]) == MagickFalse)
4366  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4367  break;
4368  }
4369  if (LocaleCompare("colorspace",option+1) == 0)
4370  {
4371  ssize_t
4372  colorspace;
4373 
4374  if (*option == '+')
4375  break;
4376  i++;
4377  if (i == (ssize_t) argc)
4378  ThrowMogrifyException(OptionError,"MissingArgument",option);
4379  colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4380  argv[i]);
4381  if (colorspace < 0)
4382  ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4383  argv[i]);
4384  break;
4385  }
4386  if (LocaleCompare("combine",option+1) == 0)
4387  {
4388  if (*option == '-')
4389  break;
4390  i++;
4391  if (i == (ssize_t) argc)
4392  ThrowMogrifyException(OptionError,"MissingArgument",option);
4393  break;
4394  }
4395  if (LocaleCompare("comment",option+1) == 0)
4396  {
4397  if (*option == '+')
4398  break;
4399  i++;
4400  if (i == (ssize_t) argc)
4401  ThrowMogrifyException(OptionError,"MissingArgument",option);
4402  break;
4403  }
4404  if (LocaleCompare("compare",option+1) == 0)
4405  break;
4406  if (LocaleCompare("complex",option+1) == 0)
4407  {
4408  ssize_t
4409  op;
4410 
4411  if (*option == '+')
4412  break;
4413  i++;
4414  if (i == (ssize_t) argc)
4415  ThrowMogrifyException(OptionError,"MissingArgument",option);
4416  op=ParseCommandOption(MagickComplexOptions,MagickFalse,argv[i]);
4417  if (op < 0)
4418  ThrowMogrifyException(OptionError,"UnrecognizedComplexOperator",
4419  argv[i]);
4420  break;
4421  }
4422  if (LocaleCompare("compose",option+1) == 0)
4423  {
4424  ssize_t
4425  compose;
4426 
4427  if (*option == '+')
4428  break;
4429  i++;
4430  if (i == (ssize_t) argc)
4431  ThrowMogrifyException(OptionError,"MissingArgument",option);
4432  compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
4433  argv[i]);
4434  if (compose < 0)
4435  ThrowMogrifyException(OptionError,"UnrecognizedComposeOperator",
4436  argv[i]);
4437  break;
4438  }
4439  if (LocaleCompare("composite",option+1) == 0)
4440  break;
4441  if (LocaleCompare("compress",option+1) == 0)
4442  {
4443  ssize_t
4444  compress;
4445 
4446  if (*option == '+')
4447  break;
4448  i++;
4449  if (i == (ssize_t) argc)
4450  ThrowMogrifyException(OptionError,"MissingArgument",option);
4451  compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
4452  argv[i]);
4453  if (compress < 0)
4454  ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4455  argv[i]);
4456  break;
4457  }
4458  if (LocaleCompare("concurrent",option+1) == 0)
4459  break;
4460  if (LocaleCompare("connected-components",option+1) == 0)
4461  {
4462  i++;
4463  if (i == (ssize_t) argc)
4464  ThrowMogrifyException(OptionError,"MissingArgument",option);
4465  if (IsGeometry(argv[i]) == MagickFalse)
4466  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4467  break;
4468  }
4469  if (LocaleCompare("contrast",option+1) == 0)
4470  break;
4471  if (LocaleCompare("contrast-stretch",option+1) == 0)
4472  {
4473  i++;
4474  if (i == (ssize_t) argc)
4475  ThrowMogrifyException(OptionError,"MissingArgument",option);
4476  if (IsGeometry(argv[i]) == MagickFalse)
4477  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4478  break;
4479  }
4480  if (LocaleCompare("convolve",option+1) == 0)
4481  {
4482  KernelInfo
4483  *kernel_info;
4484 
4485  if (*option == '+')
4486  break;
4487  i++;
4488  if (i == (ssize_t) argc)
4489  ThrowMogrifyException(OptionError,"MissingArgument",option);
4490  kernel_info=AcquireKernelInfo(argv[i]);
4491  if (kernel_info == (KernelInfo *) NULL)
4492  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4493  kernel_info=DestroyKernelInfo(kernel_info);
4494  break;
4495  }
4496  if (LocaleCompare("copy",option+1) == 0)
4497  {
4498  if (*option == '+')
4499  break;
4500  i++;
4501  if (i == (ssize_t) argc)
4502  ThrowMogrifyException(OptionError,"MissingArgument",option);
4503  if (IsGeometry(argv[i]) == MagickFalse)
4504  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4505  i++;
4506  if (i == (ssize_t) argc)
4507  ThrowMogrifyException(OptionError,"MissingArgument",option);
4508  if (IsGeometry(argv[i]) == MagickFalse)
4509  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4510  break;
4511  }
4512  if (LocaleCompare("crop",option+1) == 0)
4513  {
4514  if (*option == '+')
4515  break;
4516  i++;
4517  if (i == (ssize_t) argc)
4518  ThrowMogrifyException(OptionError,"MissingArgument",option);
4519  if (IsGeometry(argv[i]) == MagickFalse)
4520  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4521  break;
4522  }
4523  if (LocaleCompare("cycle",option+1) == 0)
4524  {
4525  if (*option == '+')
4526  break;
4527  i++;
4528  if (i == (ssize_t) argc)
4529  ThrowMogrifyException(OptionError,"MissingArgument",option);
4530  if (IsGeometry(argv[i]) == MagickFalse)
4531  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4532  break;
4533  }
4534  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4535  }
4536  case 'd':
4537  {
4538  if (LocaleCompare("decipher",option+1) == 0)
4539  {
4540  if (*option == '+')
4541  break;
4542  i++;
4543  if (i == (ssize_t) argc)
4544  ThrowMogrifyException(OptionError,"MissingArgument",option);
4545  break;
4546  }
4547  if (LocaleCompare("deconstruct",option+1) == 0)
4548  break;
4549  if (LocaleCompare("debug",option+1) == 0)
4550  {
4551  ssize_t
4552  event;
4553 
4554  if (*option == '+')
4555  break;
4556  i++;
4557  if (i == (ssize_t) argc)
4558  ThrowMogrifyException(OptionError,"MissingArgument",option);
4559  event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
4560  if (event < 0)
4561  ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4562  argv[i]);
4563  (void) SetLogEventMask(argv[i]);
4564  break;
4565  }
4566  if (LocaleCompare("define",option+1) == 0)
4567  {
4568  i++;
4569  if (i == (ssize_t) argc)
4570  ThrowMogrifyException(OptionError,"MissingArgument",option);
4571  if (*option == '+')
4572  {
4573  const char
4574  *define;
4575 
4576  define=GetImageOption(image_info,argv[i]);
4577  if (define == (const char *) NULL)
4578  ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4579  break;
4580  }
4581  break;
4582  }
4583  if (LocaleCompare("delay",option+1) == 0)
4584  {
4585  if (*option == '+')
4586  break;
4587  i++;
4588  if (i == (ssize_t) argc)
4589  ThrowMogrifyException(OptionError,"MissingArgument",option);
4590  if (IsGeometry(argv[i]) == MagickFalse)
4591  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4592  break;
4593  }
4594  if (LocaleCompare("delete",option+1) == 0)
4595  {
4596  if (*option == '+')
4597  break;
4598  i++;
4599  if (i == (ssize_t) argc)
4600  ThrowMogrifyException(OptionError,"MissingArgument",option);
4601  if (LocaleNCompare(argv[i],"registry:",9) == 0)
4602  {
4603  (void) DeleteImageRegistry(argv[i]+9);
4604  break;
4605  }
4606  if (IsGeometry(argv[i]) == MagickFalse)
4607  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4608  break;
4609  }
4610  if (LocaleCompare("density",option+1) == 0)
4611  {
4612  if (*option == '+')
4613  break;
4614  i++;
4615  if (i == (ssize_t) argc)
4616  ThrowMogrifyException(OptionError,"MissingArgument",option);
4617  if (IsGeometry(argv[i]) == MagickFalse)
4618  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4619  break;
4620  }
4621  if (LocaleCompare("depth",option+1) == 0)
4622  {
4623  if (*option == '+')
4624  break;
4625  i++;
4626  if (i == (ssize_t) argc)
4627  ThrowMogrifyException(OptionError,"MissingArgument",option);
4628  if (IsGeometry(argv[i]) == MagickFalse)
4629  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4630  break;
4631  }
4632  if (LocaleCompare("deskew",option+1) == 0)
4633  {
4634  if (*option == '+')
4635  break;
4636  i++;
4637  if (i == (ssize_t) argc)
4638  ThrowMogrifyException(OptionError,"MissingArgument",option);
4639  if (IsGeometry(argv[i]) == MagickFalse)
4640  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4641  break;
4642  }
4643  if (LocaleCompare("despeckle",option+1) == 0)
4644  break;
4645  if (LocaleCompare("dft",option+1) == 0)
4646  break;
4647  if (LocaleCompare("direction",option+1) == 0)
4648  {
4649  ssize_t
4650  direction;
4651 
4652  if (*option == '+')
4653  break;
4654  i++;
4655  if (i == (ssize_t) argc)
4656  ThrowMogrifyException(OptionError,"MissingArgument",option);
4657  direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
4658  argv[i]);
4659  if (direction < 0)
4660  ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4661  argv[i]);
4662  break;
4663  }
4664  if (LocaleCompare("display",option+1) == 0)
4665  {
4666  if (*option == '+')
4667  break;
4668  i++;
4669  if (i == (ssize_t) argc)
4670  ThrowMogrifyException(OptionError,"MissingArgument",option);
4671  break;
4672  }
4673  if (LocaleCompare("dispose",option+1) == 0)
4674  {
4675  ssize_t
4676  dispose;
4677 
4678  if (*option == '+')
4679  break;
4680  i++;
4681  if (i == (ssize_t) argc)
4682  ThrowMogrifyException(OptionError,"MissingArgument",option);
4683  dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,
4684  argv[i]);
4685  if (dispose < 0)
4686  ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4687  argv[i]);
4688  break;
4689  }
4690  if (LocaleCompare("distort",option+1) == 0)
4691  {
4692  ssize_t
4693  op;
4694 
4695  i++;
4696  if (i == (ssize_t) argc)
4697  ThrowMogrifyException(OptionError,"MissingArgument",option);
4698  op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
4699  if (op < 0)
4700  ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4701  argv[i]);
4702  i++;
4703  if (i == (ssize_t) argc)
4704  ThrowMogrifyException(OptionError,"MissingArgument",option);
4705  break;
4706  }
4707  if (LocaleCompare("dither",option+1) == 0)
4708  {
4709  ssize_t
4710  method;
4711 
4712  if (*option == '+')
4713  break;
4714  i++;
4715  if (i == (ssize_t) argc)
4716  ThrowMogrifyException(OptionError,"MissingArgument",option);
4717  method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
4718  if (method < 0)
4719  ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4720  argv[i]);
4721  break;
4722  }
4723  if (LocaleCompare("draw",option+1) == 0)
4724  {
4725  if (*option == '+')
4726  break;
4727  i++;
4728  if (i == (ssize_t) argc)
4729  ThrowMogrifyException(OptionError,"MissingArgument",option);
4730  break;
4731  }
4732  if (LocaleCompare("duplicate",option+1) == 0)
4733  {
4734  if (*option == '+')
4735  break;
4736  i++;
4737  if (i == (ssize_t) argc)
4738  ThrowMogrifyException(OptionError,"MissingArgument",option);
4739  if (IsGeometry(argv[i]) == MagickFalse)
4740  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4741  break;
4742  }
4743  if (LocaleCompare("duration",option+1) == 0)
4744  {
4745  if (*option == '+')
4746  break;
4747  i++;
4748  if (i == (ssize_t) argc)
4749  ThrowMogrifyException(OptionError,"MissingArgument",option);
4750  if (IsGeometry(argv[i]) == MagickFalse)
4751  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4752  break;
4753  }
4754  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4755  }
4756  case 'e':
4757  {
4758  if (LocaleCompare("edge",option+1) == 0)
4759  {
4760  if (*option == '+')
4761  break;
4762  i++;
4763  if (i == (ssize_t) argc)
4764  ThrowMogrifyException(OptionError,"MissingArgument",option);
4765  if (IsGeometry(argv[i]) == MagickFalse)
4766  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4767  break;
4768  }
4769  if (LocaleCompare("emboss",option+1) == 0)
4770  {
4771  if (*option == '+')
4772  break;
4773  i++;
4774  if (i == (ssize_t) argc)
4775  ThrowMogrifyException(OptionError,"MissingArgument",option);
4776  if (IsGeometry(argv[i]) == MagickFalse)
4777  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4778  break;
4779  }
4780  if (LocaleCompare("encipher",option+1) == 0)
4781  {
4782  if (*option == '+')
4783  break;
4784  i++;
4785  if (i == (ssize_t) argc)
4786  ThrowMogrifyException(OptionError,"MissingArgument",option);
4787  break;
4788  }
4789  if (LocaleCompare("encoding",option+1) == 0)
4790  {
4791  if (*option == '+')
4792  break;
4793  i++;
4794  if (i == (ssize_t) argc)
4795  ThrowMogrifyException(OptionError,"MissingArgument",option);
4796  break;
4797  }
4798  if (LocaleCompare("endian",option+1) == 0)
4799  {
4800  ssize_t
4801  endian;
4802 
4803  if (*option == '+')
4804  break;
4805  i++;
4806  if (i == (ssize_t) argc)
4807  ThrowMogrifyException(OptionError,"MissingArgument",option);
4808  endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
4809  if (endian < 0)
4810  ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4811  argv[i]);
4812  break;
4813  }
4814  if (LocaleCompare("enhance",option+1) == 0)
4815  break;
4816  if (LocaleCompare("equalize",option+1) == 0)
4817  break;
4818  if (LocaleCompare("evaluate",option+1) == 0)
4819  {
4820  ssize_t
4821  op;
4822 
4823  if (*option == '+')
4824  break;
4825  i++;
4826  if (i == (ssize_t) argc)
4827  ThrowMogrifyException(OptionError,"MissingArgument",option);
4828  op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4829  if (op < 0)
4830  ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4831  argv[i]);
4832  i++;
4833  if (i == (ssize_t) argc)
4834  ThrowMogrifyException(OptionError,"MissingArgument",option);
4835  if (IsGeometry(argv[i]) == MagickFalse)
4836  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4837  break;
4838  }
4839  if (LocaleCompare("evaluate-sequence",option+1) == 0)
4840  {
4841  ssize_t
4842  op;
4843 
4844  if (*option == '+')
4845  break;
4846  i++;
4847  if (i == (ssize_t) argc)
4848  ThrowMogrifyException(OptionError,"MissingArgument",option);
4849  op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4850  if (op < 0)
4851  ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4852  argv[i]);
4853  break;
4854  }
4855  if (LocaleCompare("extent",option+1) == 0)
4856  {
4857  if (*option == '+')
4858  break;
4859  i++;
4860  if (i == (ssize_t) argc)
4861  ThrowMogrifyException(OptionError,"MissingArgument",option);
4862  if (IsGeometry(argv[i]) == MagickFalse)
4863  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4864  break;
4865  }
4866  if (LocaleCompare("extract",option+1) == 0)
4867  {
4868  if (*option == '+')
4869  break;
4870  i++;
4871  if (i == (ssize_t) argc)
4872  ThrowMogrifyException(OptionError,"MissingArgument",option);
4873  if (IsGeometry(argv[i]) == MagickFalse)
4874  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4875  break;
4876  }
4877  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4878  }
4879  case 'f':
4880  {
4881  if (LocaleCompare("family",option+1) == 0)
4882  {
4883  if (*option == '+')
4884  break;
4885  i++;
4886  if (i == (ssize_t) argc)
4887  ThrowMogrifyException(OptionError,"MissingArgument",option);
4888  break;
4889  }
4890  if (LocaleCompare("features",option+1) == 0)
4891  {
4892  if (*option == '+')
4893  break;
4894  i++;
4895  if (i == (ssize_t) argc)
4896  ThrowMogrifyException(OptionError,"MissingArgument",option);
4897  if (IsGeometry(argv[i]) == MagickFalse)
4898  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4899  break;
4900  }
4901  if (LocaleCompare("fill",option+1) == 0)
4902  {
4903  if (*option == '+')
4904  break;
4905  i++;
4906  if (i == (ssize_t) argc)
4907  ThrowMogrifyException(OptionError,"MissingArgument",option);
4908  break;
4909  }
4910  if (LocaleCompare("filter",option+1) == 0)
4911  {
4912  ssize_t
4913  filter;
4914 
4915  if (*option == '+')
4916  break;
4917  i++;
4918  if (i == (ssize_t) argc)
4919  ThrowMogrifyException(OptionError,"MissingArgument",option);
4920  filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
4921  if (filter < 0)
4922  ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4923  argv[i]);
4924  break;
4925  }
4926  if (LocaleCompare("flatten",option+1) == 0)
4927  break;
4928  if (LocaleCompare("flip",option+1) == 0)
4929  break;
4930  if (LocaleCompare("flop",option+1) == 0)
4931  break;
4932  if (LocaleCompare("floodfill",option+1) == 0)
4933  {
4934  if (*option == '+')
4935  break;
4936  i++;
4937  if (i == (ssize_t) argc)
4938  ThrowMogrifyException(OptionError,"MissingArgument",option);
4939  if (IsGeometry(argv[i]) == MagickFalse)
4940  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4941  i++;
4942  if (i == (ssize_t) argc)
4943  ThrowMogrifyException(OptionError,"MissingArgument",option);
4944  break;
4945  }
4946  if (LocaleCompare("font",option+1) == 0)
4947  {
4948  if (*option == '+')
4949  break;
4950  i++;
4951  if (i == (ssize_t) argc)
4952  ThrowMogrifyException(OptionError,"MissingArgument",option);
4953  break;
4954  }
4955  if (LocaleCompare("format",option+1) == 0)
4956  {
4957  (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4958  (void) CloneString(&format,(char *) NULL);
4959  if (*option == '+')
4960  break;
4961  i++;
4962  if (i == (ssize_t) argc)
4963  ThrowMogrifyException(OptionError,"MissingArgument",option);
4964  (void) CloneString(&format,argv[i]);
4965  (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4966  (void) ConcatenateMagickString(image_info->filename,":",
4967  MaxTextExtent);
4968  (void) SetImageInfo(image_info,0,exception);
4969  if (*image_info->magick == '\0')
4970  ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4971  format);
4972  break;
4973  }
4974  if (LocaleCompare("frame",option+1) == 0)
4975  {
4976  if (*option == '+')
4977  break;
4978  i++;
4979  if (i == (ssize_t) argc)
4980  ThrowMogrifyException(OptionError,"MissingArgument",option);
4981  if (IsGeometry(argv[i]) == MagickFalse)
4982  ThrowMogrifyInvalidArgumentException(option,argv[i]);
4983  break;
4984  }
4985  if (LocaleCompare("function",option+1) == 0)
4986  {
4987  ssize_t
4988  op;
4989 
4990  if (*option == '+')
4991  break;
4992  i++;
4993  if (i == (ssize_t) argc)
4994  ThrowMogrifyException(OptionError,"MissingArgument",option);
4995  op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
4996  if (op < 0)
4997  ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4998  i++;
4999  if (i == (ssize_t) argc)
5000  ThrowMogrifyException(OptionError,"MissingArgument",option);
5001  break;
5002  }
5003  if (LocaleCompare("fuzz",option+1) == 0)
5004  {
5005  if (*option == '+')
5006  break;
5007  i++;
5008  if (i == (ssize_t) argc)
5009  ThrowMogrifyException(OptionError,"MissingArgument",option);
5010  if (IsGeometry(argv[i]) == MagickFalse)
5011  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5012  break;
5013  }
5014  if (LocaleCompare("fx",option+1) == 0)
5015  {
5016  if (*option == '+')
5017  break;
5018  i++;
5019  if (i == (ssize_t) argc)
5020  ThrowMogrifyException(OptionError,"MissingArgument",option);
5021  break;
5022  }
5023  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5024  }
5025  case 'g':
5026  {
5027  if (LocaleCompare("gamma",option+1) == 0)
5028  {
5029  i++;
5030  if (i == (ssize_t) argc)
5031  ThrowMogrifyException(OptionError,"MissingArgument",option);
5032  if (IsGeometry(argv[i]) == MagickFalse)
5033  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5034  break;
5035  }
5036  if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
5037  (LocaleCompare("gaussian",option+1) == 0))
5038  {
5039  i++;
5040  if (i == (ssize_t) argc)
5041  ThrowMogrifyException(OptionError,"MissingArgument",option);
5042  if (IsGeometry(argv[i]) == MagickFalse)
5043  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5044  break;
5045  }
5046  if (LocaleCompare("geometry",option+1) == 0)
5047  {
5048  if (*option == '+')
5049  break;
5050  i++;
5051  if (i == (ssize_t) argc)
5052  ThrowMogrifyException(OptionError,"MissingArgument",option);
5053  if (IsGeometry(argv[i]) == MagickFalse)
5054  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5055  break;
5056  }
5057  if (LocaleCompare("gravity",option+1) == 0)
5058  {
5059  ssize_t
5060  gravity;
5061 
5062  if (*option == '+')
5063  break;
5064  i++;
5065  if (i == (ssize_t) argc)
5066  ThrowMogrifyException(OptionError,"MissingArgument",option);
5067  gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
5068  argv[i]);
5069  if (gravity < 0)
5070  ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
5071  argv[i]);
5072  break;
5073  }
5074  if (LocaleCompare("grayscale",option+1) == 0)
5075  {
5076  ssize_t
5077  method;
5078 
5079  if (*option == '+')
5080  break;
5081  i++;
5082  if (i == (ssize_t) argc)
5083  ThrowMogrifyException(OptionError,"MissingArgument",option);
5084  method=ParseCommandOption(MagickPixelIntensityOptions,MagickFalse,
5085  argv[i]);
5086  if (method < 0)
5087  ThrowMogrifyException(OptionError,"UnrecognizedIntensityMethod",
5088  argv[i]);
5089  break;
5090  }
5091  if (LocaleCompare("green-primary",option+1) == 0)
5092  {
5093  if (*option == '+')
5094  break;
5095  i++;
5096  if (i == (ssize_t) argc)
5097  ThrowMogrifyException(OptionError,"MissingArgument",option);
5098  if (IsGeometry(argv[i]) == MagickFalse)
5099  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5100  break;
5101  }
5102  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5103  }
5104  case 'h':
5105  {
5106  if (LocaleCompare("hald-clut",option+1) == 0)
5107  break;
5108  if (LocaleCompare("hough-lines",option+1) == 0)
5109  {
5110  if (*option == '+')
5111  break;
5112  i++;
5113  if (i == (ssize_t) argc)
5114  ThrowMogrifyException(OptionError,"MissingArgument",option);
5115  if (IsGeometry(argv[i]) == MagickFalse)
5116  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5117  break;
5118  }
5119  if ((LocaleCompare("help",option+1) == 0) ||
5120  (LocaleCompare("-help",option+1) == 0))
5121  {
5122  DestroyMogrify();
5123  return(MogrifyUsage());
5124  }
5125  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5126  }
5127  case 'i':
5128  {
5129  if (LocaleCompare("identify",option+1) == 0)
5130  break;
5131  if (LocaleCompare("idft",option+1) == 0)
5132  break;
5133  if (LocaleCompare("implode",option+1) == 0)
5134  {
5135  if (*option == '+')
5136  break;
5137  i++;
5138  if (i == (ssize_t) argc)
5139  ThrowMogrifyException(OptionError,"MissingArgument",option);
5140  if (IsGeometry(argv[i]) == MagickFalse)
5141  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5142  break;
5143  }
5144  if (LocaleCompare("intensity",option+1) == 0)
5145  {
5146  ssize_t
5147  intensity;
5148 
5149  if (*option == '+')
5150  break;
5151  i++;
5152  if (i == (ssize_t) argc)
5153  ThrowMogrifyException(OptionError,"MissingArgument",option);
5154  intensity=ParseCommandOption(MagickPixelIntensityOptions,
5155  MagickFalse,argv[i]);
5156  if (intensity < 0)
5157  ThrowMogrifyException(OptionError,
5158  "UnrecognizedPixelIntensityMethod",argv[i]);
5159  break;
5160  }
5161  if (LocaleCompare("intent",option+1) == 0)
5162  {
5163  ssize_t
5164  intent;
5165 
5166  if (*option == '+')
5167  break;
5168  i++;
5169  if (i == (ssize_t) argc)
5170  ThrowMogrifyException(OptionError,"MissingArgument",option);
5171  intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
5172  if (intent < 0)
5173  ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
5174  argv[i]);
5175  break;
5176  }
5177  if (LocaleCompare("interlace",option+1) == 0)
5178  {
5179  ssize_t
5180  interlace;
5181 
5182  if (*option == '+')
5183  break;
5184  i++;
5185  if (i == (ssize_t) argc)
5186  ThrowMogrifyException(OptionError,"MissingArgument",option);
5187  interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
5188  argv[i]);
5189  if (interlace < 0)
5190  ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
5191  argv[i]);
5192  break;
5193  }
5194  if (LocaleCompare("interline-spacing",option+1) == 0)
5195  {
5196  if (*option == '+')
5197  break;
5198  i++;
5199  if (i == (ssize_t) argc)
5200  ThrowMogrifyException(OptionError,"MissingArgument",option);
5201  if (IsGeometry(argv[i]) == MagickFalse)
5202  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5203  break;
5204  }
5205  if (LocaleCompare("interpolate",option+1) == 0)
5206  {
5207  ssize_t
5208  interpolate;
5209 
5210  if (*option == '+')
5211  break;
5212  i++;
5213  if (i == (ssize_t) argc)
5214  ThrowMogrifyException(OptionError,"MissingArgument",option);
5215  interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
5216  argv[i]);
5217  if (interpolate < 0)
5218  ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
5219  argv[i]);
5220  break;
5221  }
5222  if (LocaleCompare("interword-spacing",option+1) == 0)
5223  {
5224  if (*option == '+')
5225  break;
5226  i++;
5227  if (i == (ssize_t) argc)
5228  ThrowMogrifyException(OptionError,"MissingArgument",option);
5229  if (IsGeometry(argv[i]) == MagickFalse)
5230  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5231  break;
5232  }
5233  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5234  }
5235  case 'k':
5236  {
5237  if (LocaleCompare("kerning",option+1) == 0)
5238  {
5239  if (*option == '+')
5240  break;
5241  i++;
5242  if (i == (ssize_t) argc)
5243  ThrowMogrifyException(OptionError,"MissingArgument",option);
5244  if (IsGeometry(argv[i]) == MagickFalse)
5245  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5246  break;
5247  }
5248  if (LocaleCompare("kuwahara",option+1) == 0)
5249  {
5250  i++;
5251  if (i == (ssize_t) argc)
5252  ThrowMogrifyException(OptionError,"MissingArgument",option);
5253  if (IsGeometry(argv[i]) == MagickFalse)
5254  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5255  break;
5256  }
5257  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5258  }
5259  case 'l':
5260  {
5261  if (LocaleCompare("label",option+1) == 0)
5262  {
5263  if (*option == '+')
5264  break;
5265  i++;
5266  if (i == (ssize_t) argc)
5267  ThrowMogrifyException(OptionError,"MissingArgument",option);
5268  break;
5269  }
5270  if (LocaleCompare("lat",option+1) == 0)
5271  {
5272  if (*option == '+')
5273  break;
5274  i++;
5275  if (i == (ssize_t) argc)
5276  ThrowMogrifyException(OptionError,"MissingArgument",option);
5277  if (IsGeometry(argv[i]) == MagickFalse)
5278  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5279  break;
5280  }
5281  if (LocaleCompare("layers",option+1) == 0)
5282  {
5283  ssize_t
5284  type;
5285 
5286  if (*option == '+')
5287  break;
5288  i++;
5289  if (i == (ssize_t) argc)
5290  ThrowMogrifyException(OptionError,"MissingArgument",option);
5291  type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
5292  if (type < 0)
5293  ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
5294  argv[i]);
5295  break;
5296  }
5297  if (LocaleCompare("level",option+1) == 0)
5298  {
5299  i++;
5300  if (i == (ssize_t) argc)
5301  ThrowMogrifyException(OptionError,"MissingArgument",option);
5302  if (IsGeometry(argv[i]) == MagickFalse)
5303  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5304  break;
5305  }
5306  if (LocaleCompare("level-colors",option+1) == 0)
5307  {
5308  i++;
5309  if (i == (ssize_t) argc)
5310  ThrowMogrifyException(OptionError,"MissingArgument",option);
5311  break;
5312  }
5313  if (LocaleCompare("linewidth",option+1) == 0)
5314  {
5315  if (*option == '+')
5316  break;
5317  i++;
5318  if (i == (ssize_t) argc)
5319  ThrowMogrifyException(OptionError,"MissingArgument",option);
5320  if (IsGeometry(argv[i]) == MagickFalse)
5321  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5322  break;
5323  }
5324  if (LocaleCompare("limit",option+1) == 0)
5325  {
5326  char
5327  *p;
5328 
5329  double
5330  value;
5331 
5332  ssize_t
5333  resource;
5334 
5335  if (*option == '+')
5336  break;
5337  i++;
5338  if (i == (ssize_t) argc)
5339  ThrowMogrifyException(OptionError,"MissingArgument",option);
5340  resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
5341  argv[i]);
5342  if (resource < 0)
5343  ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5344  argv[i]);
5345  i++;
5346  if (i == (ssize_t) argc)
5347  ThrowMogrifyException(OptionError,"MissingArgument",option);
5348  value=StringToDouble(argv[i],&p);
5349  (void) value;
5350  if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5351  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5352  break;
5353  }
5354  if (LocaleCompare("liquid-rescale",option+1) == 0)
5355  {
5356  i++;
5357  if (i == (ssize_t) argc)
5358  ThrowMogrifyException(OptionError,"MissingArgument",option);
5359  if (IsGeometry(argv[i]) == MagickFalse)
5360  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5361  break;
5362  }
5363  if (LocaleCompare("list",option+1) == 0)
5364  {
5365  ssize_t
5366  list;
5367 
5368  if (*option == '+')
5369  break;
5370  i++;
5371  if (i == (ssize_t) argc)
5372  ThrowMogrifyException(OptionError,"MissingArgument",option);
5373  list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
5374  if (list < 0)
5375  ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
5376  status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
5377  argv+j,exception);
5378  return(status == 0 ? MagickFalse : MagickTrue);
5379  }
5380  if (LocaleCompare("local-contrast",option+1) == 0)
5381  {
5382  i++;
5383  if (i == (ssize_t) argc)
5384  ThrowMogrifyException(OptionError,"MissingArgument",option);
5385  if (IsGeometry(argv[i]) == MagickFalse)
5386  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5387  break;
5388  }
5389  if (LocaleCompare("log",option+1) == 0)
5390  {
5391  if (*option == '+')
5392  break;
5393  i++;
5394  if ((i == (ssize_t) argc) ||
5395  (strchr(argv[i],'%') == (char *) NULL))
5396  ThrowMogrifyException(OptionError,"MissingArgument",option);
5397  break;
5398  }
5399  if (LocaleCompare("loop",option+1) == 0)
5400  {
5401  if (*option == '+')
5402  break;
5403  i++;
5404  if (i == (ssize_t) argc)
5405  ThrowMogrifyException(OptionError,"MissingArgument",option);
5406  if (IsGeometry(argv[i]) == MagickFalse)
5407  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5408  break;
5409  }
5410  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5411  }
5412  case 'm':
5413  {
5414  if (LocaleCompare("magnify",option+1) == 0)
5415  break;
5416  if (LocaleCompare("map",option+1) == 0)
5417  {
5418  global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5419  if (*option == '+')
5420  break;
5421  i++;
5422  if (i == (ssize_t) argc)
5423  ThrowMogrifyException(OptionError,"MissingArgument",option);
5424  break;
5425  }
5426  if (LocaleCompare("mask",option+1) == 0)
5427  {
5428  if (*option == '+')
5429  break;
5430  i++;
5431  if (i == (ssize_t) argc)
5432  ThrowMogrifyException(OptionError,"MissingArgument",option);
5433  break;
5434  }
5435  if (LocaleCompare("matte",option+1) == 0)
5436  break;
5437  if (LocaleCompare("mattecolor",option+1) == 0)
5438  {
5439  if (*option == '+')
5440  break;
5441  i++;
5442  if (i == (ssize_t) argc)
5443  ThrowMogrifyException(OptionError,"MissingArgument",option);
5444  break;
5445  }
5446  if (LocaleCompare("metric",option+1) == 0)
5447  {
5448  ssize_t
5449  type;
5450 
5451  if (*option == '+')
5452  break;
5453  i++;
5454  if (i == (ssize_t) argc)
5455  ThrowMogrifyException(OptionError,"MissingArgument",option);
5456  type=ParseCommandOption(MagickMetricOptions,MagickTrue,argv[i]);
5457  if (type < 0)
5458  ThrowMogrifyException(OptionError,"UnrecognizedMetricType",
5459  argv[i]);
5460  break;
5461  }
5462  if (LocaleCompare("maximum",option+1) == 0)
5463  break;
5464  if (LocaleCompare("mean-shift",option+1) == 0)
5465  {
5466  if (*option == '+')
5467  break;
5468  i++;
5469  if (i == (ssize_t) argc)
5470  ThrowMogrifyException(OptionError,"MissingArgument",option);
5471  if (IsGeometry(argv[i]) == MagickFalse)
5472  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5473  break;
5474  }
5475  if (LocaleCompare("median",option+1) == 0)
5476  {
5477  if (*option == '+')
5478  break;
5479  i++;
5480  if (i == (ssize_t) argc)
5481  ThrowMogrifyException(OptionError,"MissingArgument",option);
5482  if (IsGeometry(argv[i]) == MagickFalse)
5483  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5484  break;
5485  }
5486  if (LocaleCompare("minimum",option+1) == 0)
5487  break;
5488  if (LocaleCompare("modulate",option+1) == 0)
5489  {
5490  if (*option == '+')
5491  break;
5492  i++;
5493  if (i == (ssize_t) argc)
5494  ThrowMogrifyException(OptionError,"MissingArgument",option);
5495  if (IsGeometry(argv[i]) == MagickFalse)
5496  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5497  break;
5498  }
5499  if (LocaleCompare("mode",option+1) == 0)
5500  {
5501  if (*option == '+')
5502  break;
5503  i++;
5504  if (i == (ssize_t) argc)
5505  ThrowMogrifyException(OptionError,"MissingArgument",option);
5506  if (IsGeometry(argv[i]) == MagickFalse)
5507  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5508  break;
5509  }
5510  if (LocaleCompare("monitor",option+1) == 0)
5511  break;
5512  if (LocaleCompare("monochrome",option+1) == 0)
5513  break;
5514  if (LocaleCompare("morph",option+1) == 0)
5515  {
5516  if (*option == '+')
5517  break;
5518  i++;
5519  if (i == (ssize_t) argc)
5520  ThrowMogrifyException(OptionError,"MissingArgument",option);
5521  if (IsGeometry(argv[i]) == MagickFalse)
5522  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5523  break;
5524  }
5525  if (LocaleCompare("morphology",option+1) == 0)
5526  {
5527  char
5528  token[MaxTextExtent];
5529 
5530  KernelInfo
5531  *kernel_info;
5532 
5533  ssize_t
5534  op;
5535 
5536  i++;
5537  if (i == (ssize_t) argc)
5538  ThrowMogrifyException(OptionError,"MissingArgument",option);
5539  (void) GetNextToken(argv[i],(const char **) NULL,MaxTextExtent,token);
5540  op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
5541  if (op < 0)
5542  ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
5543  token);
5544  i++;
5545  if (i == (ssize_t) argc)
5546  ThrowMogrifyException(OptionError,"MissingArgument",option);
5547  kernel_info=AcquireKernelInfo(argv[i]);
5548  if (kernel_info == (KernelInfo *) NULL)
5549  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5550  kernel_info=DestroyKernelInfo(kernel_info);
5551  break;
5552  }
5553  if (LocaleCompare("mosaic",option+1) == 0)
5554  break;
5555  if (LocaleCompare("motion-blur",option+1) == 0)
5556  {
5557  if (*option == '+')
5558  break;
5559  i++;
5560  if (i == (ssize_t) argc)
5561  ThrowMogrifyException(OptionError,"MissingArgument",option);
5562  if (IsGeometry(argv[i]) == MagickFalse)
5563  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5564  break;
5565  }
5566  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5567  }
5568  case 'n':
5569  {
5570  if (LocaleCompare("negate",option+1) == 0)
5571  break;
5572  if (LocaleCompare("noise",option+1) == 0)
5573  {
5574  i++;
5575  if (i == (ssize_t) argc)
5576  ThrowMogrifyException(OptionError,"MissingArgument",option);
5577  if (*option == '+')
5578  {
5579  ssize_t
5580  noise;
5581 
5582  noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
5583  if (noise < 0)
5584  ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5585  argv[i]);
5586  break;
5587  }
5588  if (IsGeometry(argv[i]) == MagickFalse)
5589  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5590  break;
5591  }
5592  if (LocaleCompare("noop",option+1) == 0)
5593  break;
5594  if (LocaleCompare("normalize",option+1) == 0)
5595  break;
5596  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5597  }
5598  case 'o':
5599  {
5600  if (LocaleCompare("opaque",option+1) == 0)
5601  {
5602  i++;
5603  if (i == (ssize_t) argc)
5604  ThrowMogrifyException(OptionError,"MissingArgument",option);
5605  break;
5606  }
5607  if (LocaleCompare("ordered-dither",option+1) == 0)
5608  {
5609  if (*option == '+')
5610  break;
5611  i++;
5612  if (i == (ssize_t) argc)
5613  ThrowMogrifyException(OptionError,"MissingArgument",option);
5614  break;
5615  }
5616  if (LocaleCompare("orient",option+1) == 0)
5617  {
5618  ssize_t
5619  orientation;
5620 
5621  orientation=UndefinedOrientation;
5622  if (*option == '+')
5623  break;
5624  i++;
5625  if (i == (ssize_t) argc)
5626  ThrowMogrifyException(OptionError,"MissingArgument",option);
5627  orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
5628  argv[i]);
5629  if (orientation < 0)
5630  ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5631  argv[i]);
5632  break;
5633  }
5634  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5635  }
5636  case 'p':
5637  {
5638  if (LocaleCompare("page",option+1) == 0)
5639  {
5640  if (*option == '+')
5641  break;
5642  i++;
5643  if (i == (ssize_t) argc)
5644  ThrowMogrifyException(OptionError,"MissingArgument",option);
5645  break;
5646  }
5647  if (LocaleCompare("paint",option+1) == 0)
5648  {
5649  if (*option == '+')
5650  break;
5651  i++;
5652  if (i == (ssize_t) argc)
5653  ThrowMogrifyException(OptionError,"MissingArgument",option);
5654  if (IsGeometry(argv[i]) == MagickFalse)
5655  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5656  break;
5657  }
5658  if (LocaleCompare("path",option+1) == 0)
5659  {
5660  (void) CloneString(&path,(char *) NULL);
5661  if (*option == '+')
5662  break;
5663  i++;
5664  if (i == (ssize_t) argc)
5665  ThrowMogrifyException(OptionError,"MissingArgument",option);
5666  (void) CloneString(&path,argv[i]);
5667  break;
5668  }
5669  if (LocaleCompare("perceptible",option+1) == 0)
5670  {
5671  if (*option == '+')
5672  break;
5673  i++;
5674  if (i == (ssize_t) argc)
5675  ThrowMogrifyException(OptionError,"MissingArgument",option);
5676  if (IsGeometry(argv[i]) == MagickFalse)
5677  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5678  break;
5679  }
5680  if (LocaleCompare("pointsize",option+1) == 0)
5681  {
5682  if (*option == '+')
5683  break;
5684  i++;
5685  if (i == (ssize_t) argc)
5686  ThrowMogrifyException(OptionError,"MissingArgument",option);
5687  if (IsGeometry(argv[i]) == MagickFalse)
5688  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5689  break;
5690  }
5691  if (LocaleCompare("polaroid",option+1) == 0)
5692  {
5693  if (*option == '+')
5694  break;
5695  i++;
5696  if (i == (ssize_t) argc)
5697  ThrowMogrifyException(OptionError,"MissingArgument",option);
5698  if (IsGeometry(argv[i]) == MagickFalse)
5699  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5700  break;
5701  }
5702  if (LocaleCompare("poly",option+1) == 0)
5703  {
5704  if (*option == '+')
5705  break;
5706  i++;
5707  if (i == (ssize_t) argc)
5708  ThrowMogrifyException(OptionError,"MissingArgument",option);
5709  if (IsGeometry(argv[i]) == MagickFalse)
5710  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5711  break;
5712  }
5713  if (LocaleCompare("posterize",option+1) == 0)
5714  {
5715  if (*option == '+')
5716  break;
5717  i++;
5718  if (i == (ssize_t) argc)
5719  ThrowMogrifyException(OptionError,"MissingArgument",option);
5720  if (IsGeometry(argv[i]) == MagickFalse)
5721  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5722  break;
5723  }
5724  if (LocaleCompare("precision",option+1) == 0)
5725  {
5726  if (*option == '+')
5727  break;
5728  i++;
5729  if (i == (ssize_t) argc)
5730  ThrowMogrifyException(OptionError,"MissingArgument",option);
5731  if (IsGeometry(argv[i]) == MagickFalse)
5732  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5733  break;
5734  }
5735  if (LocaleCompare("print",option+1) == 0)
5736  {
5737  if (*option == '+')
5738  break;
5739  i++;
5740  if (i == (ssize_t) argc)
5741  ThrowMogrifyException(OptionError,"MissingArgument",option);
5742  break;
5743  }
5744  if (LocaleCompare("process",option+1) == 0)
5745  {
5746  if (*option == '+')
5747  break;
5748  i++;
5749  if (i == (ssize_t) argc)
5750  ThrowMogrifyException(OptionError,"MissingArgument",option);
5751  break;
5752  }
5753  if (LocaleCompare("profile",option+1) == 0)
5754  {
5755  i++;
5756  if (i == (ssize_t) argc)
5757  ThrowMogrifyException(OptionError,"MissingArgument",option);
5758  break;
5759  }
5760  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5761  }
5762  case 'q':
5763  {
5764  if (LocaleCompare("quality",option+1) == 0)
5765  {
5766  if (*option == '+')
5767  break;
5768  i++;
5769  if (i == (ssize_t) argc)
5770  ThrowMogrifyException(OptionError,"MissingArgument",option);
5771  if (IsGeometry(argv[i]) == MagickFalse)
5772  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5773  break;
5774  }
5775  if (LocaleCompare("quantize",option+1) == 0)
5776  {
5777  ssize_t
5778  colorspace;
5779 
5780  if (*option == '+')
5781  break;
5782  i++;
5783  if (i == (ssize_t) argc)
5784  ThrowMogrifyException(OptionError,"MissingArgument",option);
5785  colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
5786  argv[i]);
5787  if (colorspace < 0)
5788  ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5789  argv[i]);
5790  break;
5791  }
5792  if (LocaleCompare("quiet",option+1) == 0)
5793  break;
5794  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5795  }
5796  case 'r':
5797  {
5798  if (LocaleCompare("radial-blur",option+1) == 0 ||
5799  LocaleCompare("rotational-blur",option+1) == 0)
5800  {
5801  i++;
5802  if (i == (ssize_t) argc)
5803  ThrowMogrifyException(OptionError,"MissingArgument",option);
5804  if (IsGeometry(argv[i]) == MagickFalse)
5805  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5806  break;
5807  }
5808  if (LocaleCompare("raise",option+1) == 0)
5809  {
5810  i++;
5811  if (i == (ssize_t) argc)
5812  ThrowMogrifyException(OptionError,"MissingArgument",option);
5813  if (IsGeometry(argv[i]) == MagickFalse)
5814  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5815  break;
5816  }
5817  if (LocaleCompare("random-threshold",option+1) == 0)
5818  {
5819  if (*option == '+')
5820  break;
5821  i++;
5822  if (i == (ssize_t) argc)
5823  ThrowMogrifyException(OptionError,"MissingArgument",option);
5824  if (IsGeometry(argv[i]) == MagickFalse)
5825  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5826  break;
5827  }
5828  if (LocaleCompare("recolor",option+1) == 0)
5829  {
5830  if (*option == '+')
5831  break;
5832  i++;
5833  if (i == (ssize_t) argc)
5834  ThrowMogrifyException(OptionError,"MissingArgument",option);
5835  if (IsGeometry(argv[i]) == MagickFalse)
5836  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5837  break;
5838  }
5839  if (LocaleCompare("red-primary",option+1) == 0)
5840  {
5841  if (*option == '+')
5842  break;
5843  i++;
5844  if (i == (ssize_t) argc)
5845  ThrowMogrifyException(OptionError,"MissingArgument",option);
5846  if (IsGeometry(argv[i]) == MagickFalse)
5847  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5848  }
5849  if (LocaleCompare("regard-warnings",option+1) == 0)
5850  break;
5851  if (LocaleCompare("region",option+1) == 0)
5852  {
5853  if (*option == '+')
5854  break;
5855  i++;
5856  if (i == (ssize_t) argc)
5857  ThrowMogrifyException(OptionError,"MissingArgument",option);
5858  if (IsGeometry(argv[i]) == MagickFalse)
5859  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5860  break;
5861  }
5862  if (LocaleCompare("remap",option+1) == 0)
5863  {
5864  if (*option == '+')
5865  break;
5866  i++;
5867  if (i == (ssize_t) argc)
5868  ThrowMogrifyException(OptionError,"MissingArgument",option);
5869  break;
5870  }
5871  if (LocaleCompare("render",option+1) == 0)
5872  break;
5873  if (LocaleCompare("repage",option+1) == 0)
5874  {
5875  if (*option == '+')
5876  break;
5877  i++;
5878  if (i == (ssize_t) argc)
5879  ThrowMogrifyException(OptionError,"MissingArgument",option);
5880  if (IsGeometry(argv[i]) == MagickFalse)
5881  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5882  break;
5883  }
5884  if (LocaleCompare("resample",option+1) == 0)
5885  {
5886  if (*option == '+')
5887  break;
5888  i++;
5889  if (i == (ssize_t) argc)
5890  ThrowMogrifyException(OptionError,"MissingArgument",option);
5891  if (IsGeometry(argv[i]) == MagickFalse)
5892  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5893  break;
5894  }
5895  if (LocaleCompare("resize",option+1) == 0)
5896  {
5897  if (*option == '+')
5898  break;
5899  i++;
5900  if (i == (ssize_t) argc)
5901  ThrowMogrifyException(OptionError,"MissingArgument",option);
5902  if (IsGeometry(argv[i]) == MagickFalse)
5903  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5904  break;
5905  }
5906  if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5907  {
5908  respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5909  break;
5910  }
5911  if (LocaleCompare("reverse",option+1) == 0)
5912  break;
5913  if (LocaleCompare("roll",option+1) == 0)
5914  {
5915  if (*option == '+')
5916  break;
5917  i++;
5918  if (i == (ssize_t) argc)
5919  ThrowMogrifyException(OptionError,"MissingArgument",option);
5920  if (IsGeometry(argv[i]) == MagickFalse)
5921  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5922  break;
5923  }
5924  if (LocaleCompare("rotate",option+1) == 0)
5925  {
5926  i++;
5927  if (i == (ssize_t) argc)
5928  ThrowMogrifyException(OptionError,"MissingArgument",option);
5929  if (IsGeometry(argv[i]) == MagickFalse)
5930  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5931  break;
5932  }
5933  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5934  }
5935  case 's':
5936  {
5937  if (LocaleCompare("sample",option+1) == 0)
5938  {
5939  if (*option == '+')
5940  break;
5941  i++;
5942  if (i == (ssize_t) argc)
5943  ThrowMogrifyException(OptionError,"MissingArgument",option);
5944  if (IsGeometry(argv[i]) == MagickFalse)
5945  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5946  break;
5947  }
5948  if (LocaleCompare("sampling-factor",option+1) == 0)
5949  {
5950  if (*option == '+')
5951  break;
5952  i++;
5953  if (i == (ssize_t) argc)
5954  ThrowMogrifyException(OptionError,"MissingArgument",option);
5955  if (IsGeometry(argv[i]) == MagickFalse)
5956  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5957  break;
5958  }
5959  if (LocaleCompare("scale",option+1) == 0)
5960  {
5961  if (*option == '+')
5962  break;
5963  i++;
5964  if (i == (ssize_t) argc)
5965  ThrowMogrifyException(OptionError,"MissingArgument",option);
5966  if (IsGeometry(argv[i]) == MagickFalse)
5967  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5968  break;
5969  }
5970  if (LocaleCompare("scene",option+1) == 0)
5971  {
5972  if (*option == '+')
5973  break;
5974  i++;
5975  if (i == (ssize_t) argc)
5976  ThrowMogrifyException(OptionError,"MissingArgument",option);
5977  if (IsGeometry(argv[i]) == MagickFalse)
5978  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5979  break;
5980  }
5981  if (LocaleCompare("seed",option+1) == 0)
5982  {
5983  if (*option == '+')
5984  break;
5985  i++;
5986  if (i == (ssize_t) argc)
5987  ThrowMogrifyException(OptionError,"MissingArgument",option);
5988  if (IsGeometry(argv[i]) == MagickFalse)
5989  ThrowMogrifyInvalidArgumentException(option,argv[i]);
5990  break;
5991  }
5992  if (LocaleCompare("segment",option+1) == 0)
5993  {
5994  if (*option == '+')
5995  break;
5996  i++;
5997  if (i == (ssize_t) argc)
5998  ThrowMogrifyException(OptionError,"MissingArgument",option);
5999  if (IsGeometry(argv[i]) == MagickFalse)
6000  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6001  break;
6002  }
6003  if (LocaleCompare("selective-blur",option+1) == 0)
6004  {
6005  i++;
6006  if (i == (ssize_t) argc)
6007  ThrowMogrifyException(OptionError,"MissingArgument",option);
6008  if (IsGeometry(argv[i]) == MagickFalse)
6009  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6010  break;
6011  }
6012  if (LocaleCompare("separate",option+1) == 0)
6013  break;
6014  if (LocaleCompare("sepia-tone",option+1) == 0)
6015  {
6016  if (*option == '+')
6017  break;
6018  i++;
6019  if (i == (ssize_t) argc)
6020  ThrowMogrifyException(OptionError,"MissingArgument",option);
6021  if (IsGeometry(argv[i]) == MagickFalse)
6022  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6023  break;
6024  }
6025  if (LocaleCompare("set",option+1) == 0)
6026  {
6027  i++;
6028  if (i == (ssize_t) argc)
6029  ThrowMogrifyException(OptionError,"MissingArgument",option);
6030  if (*option == '+')
6031  break;
6032  i++;
6033  if (i == (ssize_t) argc)
6034  ThrowMogrifyException(OptionError,"MissingArgument",option);
6035  break;
6036  }
6037  if (LocaleCompare("shade",option+1) == 0)
6038  {
6039  i++;
6040  if (i == (ssize_t) argc)
6041  ThrowMogrifyException(OptionError,"MissingArgument",option);
6042  if (IsGeometry(argv[i]) == MagickFalse)
6043  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6044  break;
6045  }
6046  if (LocaleCompare("shadow",option+1) == 0)
6047  {
6048  if (*option == '+')
6049  break;
6050  i++;
6051  if (i == (ssize_t) argc)
6052  ThrowMogrifyException(OptionError,"MissingArgument",option);
6053  if (IsGeometry(argv[i]) == MagickFalse)
6054  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6055  break;
6056  }
6057  if (LocaleCompare("sharpen",option+1) == 0)
6058  {
6059  i++;
6060  if (i == (ssize_t) argc)
6061  ThrowMogrifyException(OptionError,"MissingArgument",option);
6062  if (IsGeometry(argv[i]) == MagickFalse)
6063  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6064  break;
6065  }
6066  if (LocaleCompare("shave",option+1) == 0)
6067  {
6068  if (*option == '+')
6069  break;
6070  i++;
6071  if (i == (ssize_t) argc)
6072  ThrowMogrifyException(OptionError,"MissingArgument",option);
6073  if (IsGeometry(argv[i]) == MagickFalse)
6074  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6075  break;
6076  }
6077  if (LocaleCompare("shear",option+1) == 0)
6078  {
6079  i++;
6080  if (i == (ssize_t) argc)
6081  ThrowMogrifyException(OptionError,"MissingArgument",option);
6082  if (IsGeometry(argv[i]) == MagickFalse)
6083  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6084  break;
6085  }
6086  if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
6087  {
6088  i++;
6089  if (i == (ssize_t) argc)
6090  ThrowMogrifyException(OptionError,"MissingArgument",option);
6091  if (IsGeometry(argv[i]) == MagickFalse)
6092  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6093  break;
6094  }
6095  if (LocaleCompare("size",option+1) == 0)
6096  {
6097  if (*option == '+')
6098  break;
6099  i++;
6100  if (i == (ssize_t) argc)
6101  ThrowMogrifyException(OptionError,"MissingArgument",option);
6102  if (IsGeometry(argv[i]) == MagickFalse)
6103  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6104  break;
6105  }
6106  if (LocaleCompare("sketch",option+1) == 0)
6107  {
6108  if (*option == '+')
6109  break;
6110  i++;
6111  if (i == (ssize_t) argc)
6112  ThrowMogrifyException(OptionError,"MissingArgument",option);
6113  if (IsGeometry(argv[i]) == MagickFalse)
6114  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6115  break;
6116  }
6117  if (LocaleCompare("smush",option+1) == 0)
6118  {
6119  i++;
6120  if (i == (ssize_t) argc)
6121  ThrowMogrifyException(OptionError,"MissingArgument",option);
6122  if (IsGeometry(argv[i]) == MagickFalse)
6123  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6124  i++;
6125  break;
6126  }
6127  if (LocaleCompare("solarize",option+1) == 0)
6128  {
6129  if (*option == '+')
6130  break;
6131  i++;
6132  if (i == (ssize_t) argc)
6133  ThrowMogrifyException(OptionError,"MissingArgument",option);
6134  if (IsGeometry(argv[i]) == MagickFalse)
6135  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6136  break;
6137  }
6138  if (LocaleCompare("sparse-color",option+1) == 0)
6139  {
6140  ssize_t
6141  op;
6142 
6143  i++;
6144  if (i == (ssize_t) argc)
6145  ThrowMogrifyException(OptionError,"MissingArgument",option);
6146  op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
6147  if (op < 0)
6148  ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
6149  argv[i]);
6150  i++;
6151  if (i == (ssize_t) argc)
6152  ThrowMogrifyException(OptionError,"MissingArgument",option);
6153  break;
6154  }
6155  if (LocaleCompare("splice",option+1) == 0)
6156  {
6157  if (*option == '+')
6158  break;
6159  i++;
6160  if (i == (ssize_t) argc)
6161  ThrowMogrifyException(OptionError,"MissingArgument",option);
6162  if (IsGeometry(argv[i]) == MagickFalse)
6163  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6164  break;
6165  }
6166  if (LocaleCompare("spread",option+1) == 0)
6167  {
6168  if (*option == '+')
6169  break;
6170  i++;
6171  if (i == (ssize_t) argc)
6172  ThrowMogrifyException(OptionError,"MissingArgument",option);
6173  if (IsGeometry(argv[i]) == MagickFalse)
6174  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6175  break;
6176  }
6177  if (LocaleCompare("statistic",option+1) == 0)
6178  {
6179  ssize_t
6180  op;
6181 
6182  if (*option == '+')
6183  break;
6184  i++;
6185  if (i == (ssize_t) argc)
6186  ThrowMogrifyException(OptionError,"MissingArgument",option);
6187  op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
6188  if (op < 0)
6189  ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
6190  argv[i]);
6191  i++;
6192  if (i == (ssize_t) argc)
6193  ThrowMogrifyException(OptionError,"MissingArgument",option);
6194  if (IsGeometry(argv[i]) == MagickFalse)
6195  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6196  break;
6197  }
6198  if (LocaleCompare("stretch",option+1) == 0)
6199  {
6200  ssize_t
6201  stretch;
6202 
6203  if (*option == '+')
6204  break;
6205  i++;
6206  if (i == (ssize_t) argc)
6207  ThrowMogrifyException(OptionError,"MissingArgument",option);
6208  stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
6209  if (stretch < 0)
6210  ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6211  argv[i]);
6212  break;
6213  }
6214  if (LocaleCompare("strip",option+1) == 0)
6215  break;
6216  if (LocaleCompare("stroke",option+1) == 0)
6217  {
6218  if (*option == '+')
6219  break;
6220  i++;
6221  if (i == (ssize_t) argc)
6222  ThrowMogrifyException(OptionError,"MissingArgument",option);
6223  break;
6224  }
6225  if (LocaleCompare("strokewidth",option+1) == 0)
6226  {
6227  if (*option == '+')
6228  break;
6229  i++;
6230  if (i == (ssize_t) argc)
6231  ThrowMogrifyException(OptionError,"MissingArgument",option);
6232  if (IsGeometry(argv[i]) == MagickFalse)
6233  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6234  break;
6235  }
6236  if (LocaleCompare("style",option+1) == 0)
6237  {
6238  ssize_t
6239  style;
6240 
6241  if (*option == '+')
6242  break;
6243  i++;
6244  if (i == (ssize_t) argc)
6245  ThrowMogrifyException(OptionError,"MissingArgument",option);
6246  style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
6247  if (style < 0)
6248  ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
6249  argv[i]);
6250  break;
6251  }
6252  if (LocaleCompare("swap",option+1) == 0)
6253  {
6254  if (*option == '+')
6255  break;
6256  i++;
6257  if (i == (ssize_t) argc)
6258  ThrowMogrifyException(OptionError,"MissingArgument",option);
6259  if (IsGeometry(argv[i]) == MagickFalse)
6260  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6261  break;
6262  }
6263  if (LocaleCompare("swirl",option+1) == 0)
6264  {
6265  if (*option == '+')
6266  break;
6267  i++;
6268  if (i == (ssize_t) argc)
6269  ThrowMogrifyException(OptionError,"MissingArgument",option);
6270  if (IsGeometry(argv[i]) == MagickFalse)
6271  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6272  break;
6273  }
6274  if (LocaleCompare("synchronize",option+1) == 0)
6275  break;
6276  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6277  }
6278  case 't':
6279  {
6280  if (LocaleCompare("taint",option+1) == 0)
6281  break;
6282  if (LocaleCompare("texture",option+1) == 0)
6283  {
6284  if (*option == '+')
6285  break;
6286  i++;
6287  if (i == (ssize_t) argc)
6288  ThrowMogrifyException(OptionError,"MissingArgument",option);
6289  break;
6290  }
6291  if (LocaleCompare("tile",option+1) == 0)
6292  {
6293  if (*option == '+')
6294  break;
6295  i++;
6296  if (i == (ssize_t) argc)
6297  ThrowMogrifyException(OptionError,"MissingArgument",option);
6298  break;
6299  }
6300  if (LocaleCompare("tile-offset",option+1) == 0)
6301  {
6302  if (*option == '+')
6303  break;
6304  i++;
6305  if (i == (ssize_t) argc)
6306  ThrowMogrifyException(OptionError,"MissingArgument",option);
6307  if (IsGeometry(argv[i]) == MagickFalse)
6308  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6309  break;
6310  }
6311  if (LocaleCompare("tint",option+1) == 0)
6312  {
6313  if (*option == '+')
6314  break;
6315  i++;
6316  if (i == (ssize_t) argc)
6317  ThrowMogrifyException(OptionError,"MissingArgument",option);
6318  if (IsGeometry(argv[i]) == MagickFalse)
6319  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6320  break;
6321  }
6322  if (LocaleCompare("transform",option+1) == 0)
6323  break;
6324  if (LocaleCompare("transpose",option+1) == 0)
6325  break;
6326  if (LocaleCompare("transverse",option+1) == 0)
6327  break;
6328  if (LocaleCompare("threshold",option+1) == 0)
6329  {
6330  if (*option == '+')
6331  break;
6332  i++;
6333  if (i == (ssize_t) argc)
6334  ThrowMogrifyException(OptionError,"MissingArgument",option);
6335  if (IsGeometry(argv[i]) == MagickFalse)
6336  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6337  break;
6338  }
6339  if (LocaleCompare("thumbnail",option+1) == 0)
6340  {
6341  if (*option == '+')
6342  break;
6343  i++;
6344  if (i == (ssize_t) argc)
6345  ThrowMogrifyException(OptionError,"MissingArgument",option);
6346  if (IsGeometry(argv[i]) == MagickFalse)
6347  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6348  break;
6349  }
6350  if (LocaleCompare("transparent",option+1) == 0)
6351  {
6352  i++;
6353  if (i == (ssize_t) argc)
6354  ThrowMogrifyException(OptionError,"MissingArgument",option);
6355  break;
6356  }
6357  if (LocaleCompare("transparent-color",option+1) == 0)
6358  {
6359  if (*option == '+')
6360  break;
6361  i++;
6362  if (i == (ssize_t) argc)
6363  ThrowMogrifyException(OptionError,"MissingArgument",option);
6364  break;
6365  }
6366  if (LocaleCompare("treedepth",option+1) == 0)
6367  {
6368  if (*option == '+')
6369  break;
6370  i++;
6371  if (i == (ssize_t) argc)
6372  ThrowMogrifyException(OptionError,"MissingArgument",option);
6373  if (IsGeometry(argv[i]) == MagickFalse)
6374  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6375  break;
6376  }
6377  if (LocaleCompare("trim",option+1) == 0)
6378  break;
6379  if (LocaleCompare("type",option+1) == 0)
6380  {
6381  ssize_t
6382  type;
6383 
6384  if (*option == '+')
6385  break;
6386  i++;
6387  if (i == (ssize_t) argc)
6388  ThrowMogrifyException(OptionError,"MissingArgument",option);
6389  type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
6390  if (type < 0)
6391  ThrowMogrifyException(OptionError,"UnrecognizedImageType",
6392  argv[i]);
6393  break;
6394  }
6395  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6396  }
6397  case 'u':
6398  {
6399  if (LocaleCompare("undercolor",option+1) == 0)
6400  {
6401  if (*option == '+')
6402  break;
6403  i++;
6404  if (i == (ssize_t) argc)
6405  ThrowMogrifyException(OptionError,"MissingArgument",option);
6406  break;
6407  }
6408  if (LocaleCompare("unique-colors",option+1) == 0)
6409  break;
6410  if (LocaleCompare("units",option+1) == 0)
6411  {
6412  ssize_t
6413  units;
6414 
6415  if (*option == '+')
6416  break;
6417  i++;
6418  if (i == (ssize_t) argc)
6419  ThrowMogrifyException(OptionError,"MissingArgument",option);
6420  units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
6421  argv[i]);
6422  if (units < 0)
6423  ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6424  argv[i]);
6425  break;
6426  }
6427  if (LocaleCompare("unsharp",option+1) == 0)
6428  {
6429  i++;
6430  if (i == (ssize_t) argc)
6431  ThrowMogrifyException(OptionError,"MissingArgument",option);
6432  if (IsGeometry(argv[i]) == MagickFalse)
6433  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6434  break;
6435  }
6436  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6437  }
6438  case 'v':
6439  {
6440  if (LocaleCompare("verbose",option+1) == 0)
6441  {
6442  image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6443  break;
6444  }
6445  if ((LocaleCompare("version",option+1) == 0) ||
6446  (LocaleCompare("-version",option+1) == 0))
6447  {
6448  ListMagickVersion(stdout);
6449  break;
6450  }
6451  if (LocaleCompare("view",option+1) == 0)
6452  {
6453  if (*option == '+')
6454  break;
6455  i++;
6456  if (i == (ssize_t) argc)
6457  ThrowMogrifyException(OptionError,"MissingArgument",option);
6458  break;
6459  }
6460  if (LocaleCompare("vignette",option+1) == 0)
6461  {
6462  if (*option == '+')
6463  break;
6464  i++;
6465  if (i == (ssize_t) argc)
6466  ThrowMogrifyException(OptionError,"MissingArgument",option);
6467  if (IsGeometry(argv[i]) == MagickFalse)
6468  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6469  break;
6470  }
6471  if (LocaleCompare("virtual-pixel",option+1) == 0)
6472  {
6473  ssize_t
6474  method;
6475 
6476  if (*option == '+')
6477  break;
6478  i++;
6479  if (i == (ssize_t) argc)
6480  ThrowMogrifyException(OptionError,"MissingArgument",option);
6481  method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
6482  argv[i]);
6483  if (method < 0)
6484  ThrowMogrifyException(OptionError,
6485  "UnrecognizedVirtualPixelMethod",argv[i]);
6486  break;
6487  }
6488  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6489  }
6490  case 'w':
6491  {
6492  if (LocaleCompare("wave",option+1) == 0)
6493  {
6494  i++;
6495  if (i == (ssize_t) argc)
6496  ThrowMogrifyException(OptionError,"MissingArgument",option);
6497  if (IsGeometry(argv[i]) == MagickFalse)
6498  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6499  break;
6500  }
6501  if (LocaleCompare("wavelet-denoise",option+1) == 0)
6502  {
6503  i++;
6504  if (i == (ssize_t) argc)
6505  ThrowMogrifyException(OptionError,"MissingArgument",option);
6506  if (IsGeometry(argv[i]) == MagickFalse)
6507  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6508  break;
6509  }
6510  if (LocaleCompare("weight",option+1) == 0)
6511  {
6512  if (*option == '+')
6513  break;
6514  i++;
6515  if (i == (ssize_t) argc)
6516  ThrowMogrifyException(OptionError,"MissingArgument",option);
6517  break;
6518  }
6519  if (LocaleCompare("white-point",option+1) == 0)
6520  {
6521  if (*option == '+')
6522  break;
6523  i++;
6524  if (i == (ssize_t) argc)
6525  ThrowMogrifyException(OptionError,"MissingArgument",option);
6526  if (IsGeometry(argv[i]) == MagickFalse)
6527  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6528  break;
6529  }
6530  if (LocaleCompare("white-threshold",option+1) == 0)
6531  {
6532  if (*option == '+')
6533  break;
6534  i++;
6535  if (i == (ssize_t) argc)
6536  ThrowMogrifyException(OptionError,"MissingArgument",option);
6537  if (IsGeometry(argv[i]) == MagickFalse)
6538  ThrowMogrifyInvalidArgumentException(option,argv[i]);
6539  break;
6540  }
6541  if (LocaleCompare("write",option+1) == 0)
6542  {
6543  i++;
6544  if (i == (ssize_t) argc)
6545  ThrowMogrifyException(OptionError,"MissingArgument",option);
6546  break;
6547  }
6548  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6549  }
6550  case '?':
6551  break;
6552  default:
6553  ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6554  }
6555  fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6556  FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
6557  if (fire != MagickFalse)
6558  FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6559  }
6560  if (k != 0)
6561  ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6562  if (i != (ssize_t) argc)
6563  ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6564  DestroyMogrify();
6565  return(status != 0 ? MagickTrue : MagickFalse);
6566 }
6567 
6568 /*
6569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6570 % %
6571 % %
6572 % %
6573 + M o g r i f y I m a g e I n f o %
6574 % %
6575 % %
6576 % %
6577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6578 %
6579 % MogrifyImageInfo() applies image processing settings to the image as
6580 % prescribed by command line options.
6581 %
6582 % The format of the MogrifyImageInfo method is:
6583 %
6584 % MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6585 % const char **argv,ExceptionInfo *exception)
6586 %
6587 % A description of each parameter follows:
6588 %
6589 % o image_info: the image info..
6590 %
6591 % o argc: Specifies a pointer to an integer describing the number of
6592 % elements in the argument vector.
6593 %
6594 % o argv: Specifies a pointer to a text array containing the command line
6595 % arguments.
6596 %
6597 % o exception: return any errors or warnings in this structure.
6598 %
6599 */
6600 WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6601  const int argc,const char **argv,ExceptionInfo *exception)
6602 {
6603  const char
6604  *option;
6605 
6606  GeometryInfo
6607  geometry_info;
6608 
6609  ssize_t
6610  count;
6611 
6612  ssize_t
6613  i;
6614 
6615  /*
6616  Initialize method variables.
6617  */
6618  assert(image_info != (ImageInfo *) NULL);
6619  assert(image_info->signature == MagickCoreSignature);
6620  if (IsEventLogging() != MagickFalse)
6621  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6622  image_info->filename);
6623  if (argc < 0)
6624  return(MagickTrue);
6625  /*
6626  Set the image settings.
6627  */
6628  for (i=0; i < (ssize_t) argc; i++)
6629  {
6630  option=argv[i];
6631  if (IsCommandOption(option) == MagickFalse)
6632  continue;
6633  count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
6634  count=MagickMax(count,0L);
6635  if ((i+count) >= (ssize_t) argc)
6636  break;
6637  switch (*(option+1))
6638  {
6639  case 'a':
6640  {
6641  if (LocaleCompare("adjoin",option+1) == 0)
6642  {
6643  image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6644  break;
6645  }
6646  if (LocaleCompare("antialias",option+1) == 0)
6647  {
6648  image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6649  break;
6650  }
6651  if (LocaleCompare("attenuate",option+1) == 0)
6652  {
6653  if (*option == '+')
6654  {
6655  (void) DeleteImageOption(image_info,option+1);
6656  break;
6657  }
6658  (void) SetImageOption(image_info,option+1,argv[i+1]);
6659  break;
6660  }
6661  if (LocaleCompare("authenticate",option+1) == 0)
6662  {
6663  if (*option == '+')
6664  (void) CloneString(&image_info->authenticate,(char *) NULL);
6665  else
6666  (void) CloneString(&image_info->authenticate,argv[i+1]);
6667  break;
6668  }
6669  break;
6670  }
6671  case 'b':
6672  {
6673  if (LocaleCompare("background",option+1) == 0)
6674  {
6675  if (*option == '+')
6676  {
6677  (void) DeleteImageOption(image_info,option+1);
6678  (void) QueryColorDatabase(MogrifyBackgroundColor,
6679  &image_info->background_color,exception);
6680  break;
6681  }
6682  (void) SetImageOption(image_info,option+1,argv[i+1]);
6683  (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6684  exception);
6685  break;
6686  }
6687  if (LocaleCompare("bias",option+1) == 0)
6688  {
6689  if (*option == '+')
6690  {
6691  (void) SetImageOption(image_info,option+1,"0.0");
6692  break;
6693  }
6694  (void) SetImageOption(image_info,option+1,argv[i+1]);
6695  break;
6696  }
6697  if (LocaleCompare("black-point-compensation",option+1) == 0)
6698  {
6699  if (*option == '+')
6700  {
6701  (void) SetImageOption(image_info,option+1,"false");
6702  break;
6703  }
6704  (void) SetImageOption(image_info,option+1,"true");
6705  break;
6706  }
6707  if (LocaleCompare("blue-primary",option+1) == 0)
6708  {
6709  if (*option == '+')
6710  {
6711  (void) SetImageOption(image_info,option+1,"0.0");
6712  break;
6713  }
6714  (void) SetImageOption(image_info,option+1,argv[i+1]);
6715  break;
6716  }
6717  if (LocaleCompare("bordercolor",option+1) == 0)
6718  {
6719  if (*option == '+')
6720  {
6721  (void) DeleteImageOption(image_info,option+1);
6722  (void) QueryColorDatabase(MogrifyBorderColor,
6723  &image_info->border_color,exception);
6724  break;
6725  }
6726  (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6727  exception);
6728  (void) SetImageOption(image_info,option+1,argv[i+1]);
6729  break;
6730  }
6731  if (LocaleCompare("box",option+1) == 0)
6732  {
6733  if (*option == '+')
6734  {
6735  (void) SetImageOption(image_info,"undercolor","none");
6736  break;
6737  }
6738  (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6739  break;
6740  }
6741  break;
6742  }
6743  case 'c':
6744  {
6745  if (LocaleCompare("cache",option+1) == 0)
6746  {
6747  MagickSizeType
6748  limit;
6749 
6750  limit=MagickResourceInfinity;
6751  if (LocaleCompare("unlimited",argv[i+1]) != 0)
6752  limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],100.0);
6753  (void) SetMagickResourceLimit(MemoryResource,limit);
6754  (void) SetMagickResourceLimit(MapResource,2*limit);
6755  break;
6756  }
6757  if (LocaleCompare("caption",option+1) == 0)
6758  {
6759  if (*option == '+')
6760  {
6761  (void) DeleteImageOption(image_info,option+1);
6762  break;
6763  }
6764  (void) SetImageOption(image_info,option+1,argv[i+1]);
6765  break;
6766  }
6767  if (LocaleCompare("channel",option+1) == 0)
6768  {
6769  if (*option == '+')
6770  {
6771  image_info->channel=DefaultChannels;
6772  break;
6773  }
6774  image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6775  break;
6776  }
6777  if (LocaleCompare("colors",option+1) == 0)
6778  {
6779  image_info->colors=StringToUnsignedLong(argv[i+1]);
6780  break;
6781  }
6782  if (LocaleCompare("colorspace",option+1) == 0)
6783  {
6784  if (*option == '+')
6785  {
6786  image_info->colorspace=UndefinedColorspace;
6787  (void) SetImageOption(image_info,option+1,"undefined");
6788  break;
6789  }
6790  image_info->colorspace=(ColorspaceType) ParseCommandOption(
6791  MagickColorspaceOptions,MagickFalse,argv[i+1]);
6792  (void) SetImageOption(image_info,option+1,argv[i+1]);
6793  break;
6794  }
6795  if (LocaleCompare("comment",option+1) == 0)
6796  {
6797  if (*option == '+')
6798  {
6799  (void) DeleteImageOption(image_info,option+1);
6800  break;
6801  }
6802  (void) SetImageOption(image_info,option+1,argv[i+1]);
6803  break;
6804  }
6805  if (LocaleCompare("compose",option+1) == 0)
6806  {
6807  if (*option == '+')
6808  {
6809  (void) SetImageOption(image_info,option+1,"undefined");
6810  break;
6811  }
6812  (void) SetImageOption(image_info,option+1,argv[i+1]);
6813  break;
6814  }
6815  if (LocaleCompare("compress",option+1) == 0)
6816  {
6817  if (*option == '+')
6818  {
6819  image_info->compression=UndefinedCompression;
6820  (void) SetImageOption(image_info,option+1,"undefined");
6821  break;
6822  }
6823  image_info->compression=(CompressionType) ParseCommandOption(
6824  MagickCompressOptions,MagickFalse,argv[i+1]);
6825  (void) SetImageOption(image_info,option+1,argv[i+1]);
6826  break;
6827  }
6828  break;
6829  }
6830  case 'd':
6831  {
6832  if (LocaleCompare("debug",option+1) == 0)
6833  {
6834  if (*option == '+')
6835  (void) SetLogEventMask("none");
6836  else
6837  (void) SetLogEventMask(argv[i+1]);
6838  image_info->debug=IsEventLogging();
6839  break;
6840  }
6841  if (LocaleCompare("define",option+1) == 0)
6842  {
6843  if (*option == '+')
6844  {
6845  if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6846  (void) DeleteImageRegistry(argv[i+1]+9);
6847  else
6848  (void) DeleteImageOption(image_info,argv[i+1]);
6849  break;
6850  }
6851  if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6852  {
6853  (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6854  exception);
6855  break;
6856  }
6857  (void) DefineImageOption(image_info,argv[i+1]);
6858  break;
6859  }
6860  if (LocaleCompare("delay",option+1) == 0)
6861  {
6862  if (*option == '+')
6863  {
6864  (void) SetImageOption(image_info,option+1,"0");
6865  break;
6866  }
6867  (void) SetImageOption(image_info,option+1,argv[i+1]);
6868  break;
6869  }
6870  if (LocaleCompare("density",option+1) == 0)
6871  {
6872  /*
6873  Set image density.
6874  */
6875  if (*option == '+')
6876  {
6877  if (image_info->density != (char *) NULL)
6878  image_info->density=DestroyString(image_info->density);
6879  (void) SetImageOption(image_info,option+1,"72");
6880  break;
6881  }
6882  (void) CloneString(&image_info->density,argv[i+1]);
6883  (void) SetImageOption(image_info,option+1,argv[i+1]);
6884  break;
6885  }
6886  if (LocaleCompare("depth",option+1) == 0)
6887  {
6888  if (*option == '+')
6889  {
6890  image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6891  break;
6892  }
6893  image_info->depth=StringToUnsignedLong(argv[i+1]);
6894  break;
6895  }
6896  if (LocaleCompare("direction",option+1) == 0)
6897  {
6898  if (*option == '+')
6899  {
6900  (void) SetImageOption(image_info,option+1,"undefined");
6901  break;
6902  }
6903  (void) SetImageOption(image_info,option+1,argv[i+1]);
6904  break;
6905  }
6906  if (LocaleCompare("display",option+1) == 0)
6907  {
6908  if (*option == '+')
6909  {
6910  if (image_info->server_name != (char *) NULL)
6911  image_info->server_name=DestroyString(
6912  image_info->server_name);
6913  break;
6914  }
6915  (void) CloneString(&image_info->server_name,argv[i+1]);
6916  break;
6917  }
6918  if (LocaleCompare("dispose",option+1) == 0)
6919  {
6920  if (*option == '+')
6921  {
6922  (void) SetImageOption(image_info,option+1,"undefined");
6923  break;
6924  }
6925  (void) SetImageOption(image_info,option+1,argv[i+1]);
6926  break;
6927  }
6928  if (LocaleCompare("dither",option+1) == 0)
6929  {
6930  if (*option == '+')
6931  {
6932  image_info->dither=MagickFalse;
6933  (void) SetImageOption(image_info,option+1,"none");
6934  break;
6935  }
6936  (void) SetImageOption(image_info,option+1,argv[i+1]);
6937  image_info->dither=MagickTrue;
6938  break;
6939  }
6940  break;
6941  }
6942  case 'e':
6943  {
6944  if (LocaleCompare("encoding",option+1) == 0)
6945  {
6946  if (*option == '+')
6947  {
6948  (void) SetImageOption(image_info,option+1,"undefined");
6949  break;
6950  }
6951  (void) SetImageOption(image_info,option+1,argv[i+1]);
6952  break;
6953  }
6954  if (LocaleCompare("endian",option+1) == 0)
6955  {
6956  if (*option == '+')
6957  {
6958  image_info->endian=UndefinedEndian;
6959  (void) SetImageOption(image_info,option+1,"undefined");
6960  break;
6961  }
6962  image_info->endian=(EndianType) ParseCommandOption(
6963  MagickEndianOptions,MagickFalse,argv[i+1]);
6964  (void) SetImageOption(image_info,option+1,argv[i+1]);
6965  break;
6966  }
6967  if (LocaleCompare("extract",option+1) == 0)
6968  {
6969  /*
6970  Set image extract geometry.
6971  */
6972  if (*option == '+')
6973  {
6974  if (image_info->extract != (char *) NULL)
6975  image_info->extract=DestroyString(image_info->extract);
6976  break;
6977  }
6978  (void) CloneString(&image_info->extract,argv[i+1]);
6979  break;
6980  }
6981  break;
6982  }
6983  case 'f':
6984  {
6985  if (LocaleCompare("family",option+1) == 0)
6986  {
6987  if (*option != '+')
6988  (void) SetImageOption(image_info,option+1,argv[i+1]);
6989  break;
6990  }
6991  if (LocaleCompare("fill",option+1) == 0)
6992  {
6993  if (*option == '+')
6994  {
6995  (void) SetImageOption(image_info,option+1,"none");
6996  break;
6997  }
6998  (void) SetImageOption(image_info,option+1,argv[i+1]);
6999  break;
7000  }
7001  if (LocaleCompare("filter",option+1) == 0)
7002  {
7003  if (*option == '+')
7004  {
7005  (void) SetImageOption(image_info,option+1,"undefined");
7006  break;
7007  }
7008  (void) SetImageOption(image_info,option+1,argv[i+1]);
7009  break;
7010  }
7011  if (LocaleCompare("font",option+1) == 0)
7012  {
7013  if (*option == '+')
7014  {
7015  if (image_info->font != (char *) NULL)
7016  image_info->font=DestroyString(image_info->font);
7017  break;
7018  }
7019  (void) CloneString(&image_info->font,argv[i+1]);
7020  break;
7021  }
7022  if (LocaleCompare("format",option+1) == 0)
7023  {
7024  (void) SetImageOption(image_info,option+1,argv[i+1]);
7025  break;
7026  }
7027  if (LocaleCompare("fuzz",option+1) == 0)
7028  {
7029  if (*option == '+')
7030  {
7031  image_info->fuzz=0.0;
7032  (void) SetImageOption(image_info,option+1,"0");
7033  break;
7034  }
7035  image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
7036  QuantumRange+1.0);
7037  (void) SetImageOption(image_info,option+1,argv[i+1]);
7038  break;
7039  }
7040  break;
7041  }
7042  case 'g':
7043  {
7044  if (LocaleCompare("gravity",option+1) == 0)
7045  {
7046  if (*option == '+')
7047  {
7048  (void) SetImageOption(image_info,option+1,"undefined");
7049  break;
7050  }
7051  (void) SetImageOption(image_info,option+1,argv[i+1]);
7052  break;
7053  }
7054  if (LocaleCompare("green-primary",option+1) == 0)
7055  {
7056  if (*option == '+')
7057  {
7058  (void) SetImageOption(image_info,option+1,"0.0");
7059  break;
7060  }
7061  (void) SetImageOption(image_info,option+1,argv[i+1]);
7062  break;
7063  }
7064  break;
7065  }
7066  case 'i':
7067  {
7068  if (LocaleCompare("intensity",option+1) == 0)
7069  {
7070  if (*option == '+')
7071  {
7072  (void) SetImageOption(image_info,option+1,"undefined");
7073  break;
7074  }
7075  (void) SetImageOption(image_info,option+1,argv[i+1]);
7076  break;
7077  }
7078  if (LocaleCompare("intent",option+1) == 0)
7079  {
7080  if (*option == '+')
7081  {
7082  (void) SetImageOption(image_info,option+1,"undefined");
7083  break;
7084  }
7085  (void) SetImageOption(image_info,option+1,argv[i+1]);
7086  break;
7087  }
7088  if (LocaleCompare("interlace",option+1) == 0)
7089  {
7090  if (*option == '+')
7091  {
7092  image_info->interlace=UndefinedInterlace;
7093  (void) SetImageOption(image_info,option+1,"undefined");
7094  break;
7095  }
7096  image_info->interlace=(InterlaceType) ParseCommandOption(
7097  MagickInterlaceOptions,MagickFalse,argv[i+1]);
7098  (void) SetImageOption(image_info,option+1,argv[i+1]);
7099  break;
7100  }
7101  if (LocaleCompare("interline-spacing",option+1) == 0)
7102  {
7103  if (*option == '+')
7104  {
7105  (void) SetImageOption(image_info,option+1,"undefined");
7106  break;
7107  }
7108  (void) SetImageOption(image_info,option+1,argv[i+1]);
7109  break;
7110  }
7111  if (LocaleCompare("interpolate",option+1) == 0)
7112  {
7113  if (*option == '+')
7114  {
7115  (void) SetImageOption(image_info,option+1,"undefined");
7116  break;
7117  }
7118  (void) SetImageOption(image_info,option+1,argv[i+1]);
7119  break;
7120  }
7121  if (LocaleCompare("interword-spacing",option+1) == 0)
7122  {
7123  if (*option == '+')
7124  {
7125  (void) SetImageOption(image_info,option+1,"undefined");
7126  break;
7127  }
7128  (void) SetImageOption(image_info,option+1,argv[i+1]);
7129  break;
7130  }
7131  break;
7132  }
7133  case 'k':
7134  {
7135  if (LocaleCompare("kerning",option+1) == 0)
7136  {
7137  if (*option == '+')
7138  {
7139  (void) SetImageOption(image_info,option+1,"undefined");
7140  break;
7141  }
7142  (void) SetImageOption(image_info,option+1,argv[i+1]);
7143  break;
7144  }
7145  break;
7146  }
7147  case 'l':
7148  {
7149  if (LocaleCompare("label",option+1) == 0)
7150  {
7151  if (*option == '+')
7152  {
7153  (void) DeleteImageOption(image_info,option+1);
7154  break;
7155  }
7156  (void) SetImageOption(image_info,option+1,argv[i+1]);
7157  break;
7158  }
7159  if (LocaleCompare("limit",option+1) == 0)
7160  {
7161  MagickSizeType
7162  limit;
7163 
7164  ResourceType
7165  type;
7166 
7167  if (*option == '+')
7168  break;
7169  type=(ResourceType) ParseCommandOption(MagickResourceOptions,
7170  MagickFalse,argv[i+1]);
7171  limit=MagickResourceInfinity;
7172  if (LocaleCompare("unlimited",argv[i+2]) != 0)
7173  limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
7174  if (type == TimeResource)
7175  limit=(MagickSizeType) ParseMagickTimeToLive(argv[i+2]);
7176  (void) SetMagickResourceLimit(type,limit);
7177  break;
7178  }
7179  if (LocaleCompare("list",option+1) == 0)
7180  {
7181  ssize_t
7182  list;
7183 
7184  /*
7185  Display configuration list.
7186  */
7187  list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
7188  switch (list)
7189  {
7190  case MagickCoderOptions:
7191  {
7192  (void) ListCoderInfo((FILE *) NULL,exception);
7193  break;
7194  }
7195  case MagickColorOptions:
7196  {
7197  (void) ListColorInfo((FILE *) NULL,exception);
7198  break;
7199  }
7200  case MagickConfigureOptions:
7201  {
7202  (void) ListConfigureInfo((FILE *) NULL,exception);
7203  break;
7204  }
7205  case MagickDelegateOptions:
7206  {
7207  (void) ListDelegateInfo((FILE *) NULL,exception);
7208  break;
7209  }
7210  case MagickFontOptions:
7211  {
7212  (void) ListTypeInfo((FILE *) NULL,exception);
7213  break;
7214  }
7215  case MagickFormatOptions:
7216  {
7217  (void) ListMagickInfo((FILE *) NULL,exception);
7218  break;
7219  }
7220  case MagickLocaleOptions:
7221  {
7222  (void) ListLocaleInfo((FILE *) NULL,exception);
7223  break;
7224  }
7225  case MagickLogOptions:
7226  {
7227  (void) ListLogInfo((FILE *) NULL,exception);
7228  break;
7229  }
7230  case MagickMagicOptions:
7231  {
7232  (void) ListMagicInfo((FILE *) NULL,exception);
7233  break;
7234  }
7235  case MagickMimeOptions:
7236  {
7237  (void) ListMimeInfo((FILE *) NULL,exception);
7238  break;
7239  }
7240  case MagickModuleOptions:
7241  {
7242  (void) ListModuleInfo((FILE *) NULL,exception);
7243  break;
7244  }
7245  case MagickPagesizeOptions:
7246  {
7247  (void) ListPagesizes((FILE *) NULL,exception);
7248  break;
7249  }
7250  case MagickPolicyOptions:
7251  {
7252  (void) ListPolicyInfo((FILE *) NULL,exception);
7253  break;
7254  }
7255  case MagickResourceOptions:
7256  {
7257  (void) ListMagickResourceInfo((FILE *) NULL,exception);
7258  break;
7259  }
7260  case MagickThresholdOptions:
7261  {
7262  (void) ListThresholdMaps((FILE *) NULL,exception);
7263  break;
7264  }
7265  default:
7266  {
7267  (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
7268  exception);
7269  break;
7270  }
7271  }
7272  break;
7273  }
7274  if (LocaleCompare("log",option+1) == 0)
7275  {
7276  if (*option == '+')
7277  break;
7278  (void) SetLogFormat(argv[i+1]);
7279  break;
7280  }
7281  if (LocaleCompare("loop",option+1) == 0)
7282  {
7283  if (*option == '+')
7284  {
7285  (void) SetImageOption(image_info,option+1,"0");
7286  break;
7287  }
7288  (void) SetImageOption(image_info,option+1,argv[i+1]);
7289  break;
7290  }
7291  break;
7292  }
7293  case 'm':
7294  {
7295  if (LocaleCompare("matte",option+1) == 0)
7296  {
7297  if (*option == '+')
7298  {
7299  (void) SetImageOption(image_info,option+1,"false");
7300  break;
7301  }
7302  (void) SetImageOption(image_info,option+1,"true");
7303  break;
7304  }
7305  if (LocaleCompare("mattecolor",option+1) == 0)
7306  {
7307  if (*option == '+')
7308  {
7309  (void) SetImageOption(image_info,option+1,argv[i+1]);
7310  (void) QueryColorDatabase(MogrifyMatteColor,
7311  &image_info->matte_color,exception);
7312  break;
7313  }
7314  (void) SetImageOption(image_info,option+1,argv[i+1]);
7315  (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
7316  exception);
7317  break;
7318  }
7319  if (LocaleCompare("metric",option+1) == 0)
7320  {
7321  if (*option == '+')
7322  {
7323  (void) DeleteImageOption(image_info,option+1);
7324  break;
7325  }
7326  (void) SetImageOption(image_info,option+1,argv[i+1]);
7327  break;
7328  }
7329  if (LocaleCompare("monitor",option+1) == 0)
7330  {
7331  (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
7332  (void *) NULL);
7333  break;
7334  }
7335  if (LocaleCompare("monochrome",option+1) == 0)
7336  {
7337  image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
7338  break;
7339  }
7340  break;
7341  }
7342  case 'o':
7343  {
7344  if (LocaleCompare("orient",option+1) == 0)
7345  {
7346  if (*option == '+')
7347  {
7348  image_info->orientation=UndefinedOrientation;
7349  (void) SetImageOption(image_info,option+1,"undefined");
7350  break;
7351  }
7352  image_info->orientation=(OrientationType) ParseCommandOption(
7353  MagickOrientationOptions,MagickFalse,argv[i+1]);
7354  (void) SetImageOption(image_info,option+1,argv[i+1]);
7355  break;
7356  }
7357  break;
7358  }
7359  case 'p':
7360  {
7361  if (LocaleCompare("page",option+1) == 0)
7362  {
7363  char
7364  *canonical_page,
7365  page[MaxTextExtent];
7366 
7367  const char
7368  *image_option;
7369 
7370  MagickStatusType
7371  flags;
7372 
7373  RectangleInfo
7374  geometry;
7375 
7376  if (*option == '+')
7377  {
7378  (void) DeleteImageOption(image_info,option+1);
7379  (void) CloneString(&image_info->page,(char *) NULL);
7380  break;
7381  }
7382  (void) memset(&geometry,0,sizeof(geometry));
7383  image_option=GetImageOption(image_info,"page");
7384  if (image_option != (const char *) NULL)
7385  (void) ParseAbsoluteGeometry(image_option,&geometry);
7386  canonical_page=GetPageGeometry(argv[i+1]);
7387  flags=ParseAbsoluteGeometry(canonical_page,&geometry);
7388  canonical_page=DestroyString(canonical_page);
7389  (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
7390  (unsigned long) geometry.width,(unsigned long) geometry.height);
7391  if (((flags & XValue) != 0) || ((flags & YValue) != 0))
7392  (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
7393  (unsigned long) geometry.width,(unsigned long) geometry.height,
7394  (long) geometry.x,(long) geometry.y);
7395  (void) SetImageOption(image_info,option+1,page);
7396  (void) CloneString(&image_info->page,page);
7397  break;
7398  }
7399  if (LocaleCompare("pen",option+1) == 0)
7400  {
7401  if (*option == '+')
7402  {
7403  (void) SetImageOption(image_info,option+1,"none");
7404  break;
7405  }
7406  (void) SetImageOption(image_info,option+1,argv[i+1]);
7407  break;
7408  }
7409  if (LocaleCompare("ping",option+1) == 0)
7410  {
7411  image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
7412  break;
7413  }
7414  if (LocaleCompare("pointsize",option+1) == 0)
7415  {
7416  if (*option == '+')
7417  geometry_info.rho=0.0;
7418  else
7419  (void) ParseGeometry(argv[i+1],&geometry_info);
7420  image_info->pointsize=geometry_info.rho;
7421  break;
7422  }
7423  if (LocaleCompare("precision",option+1) == 0)
7424  {
7425  (void) SetMagickPrecision(StringToInteger(argv[i+1]));
7426  break;
7427  }
7428  if (LocaleCompare("preview",option+1) == 0)
7429  {
7430  /*
7431  Preview image.
7432  */
7433  if (*option == '+')
7434  {
7435  image_info->preview_type=UndefinedPreview;
7436  break;
7437  }
7438  image_info->preview_type=(PreviewType) ParseCommandOption(
7439  MagickPreviewOptions,MagickFalse,argv[i+1]);
7440  break;
7441  }
7442  break;
7443  }
7444  case 'q':
7445  {
7446  if (LocaleCompare("quality",option+1) == 0)
7447  {
7448  /*
7449  Set image compression quality.
7450  */
7451  if (*option == '+')
7452  {
7453  image_info->quality=UndefinedCompressionQuality;
7454  (void) SetImageOption(image_info,option+1,"0");
7455  break;
7456  }
7457  image_info->quality=StringToUnsignedLong(argv[i+1]);
7458  (void) SetImageOption(image_info,option+1,argv[i+1]);
7459  break;
7460  }
7461  if (LocaleCompare("quiet",option+1) == 0)
7462  {
7463  static WarningHandler
7464  warning_handler = (WarningHandler) NULL;
7465 
7466  if (*option == '+')
7467  {
7468  /*
7469  Restore error or warning messages.
7470  */
7471  warning_handler=SetWarningHandler(warning_handler);
7472  break;
7473  }
7474  /*
7475  Suppress error or warning messages.
7476  */
7477  warning_handler=SetWarningHandler((WarningHandler) NULL);
7478  break;
7479  }
7480  break;
7481  }
7482  case 'r':
7483  {
7484  if (LocaleCompare("red-primary",option+1) == 0)
7485  {
7486  if (*option == '+')
7487  {
7488  (void) SetImageOption(image_info,option+1,"0.0");
7489  break;
7490  }
7491  (void) SetImageOption(image_info,option+1,argv[i+1]);
7492  break;
7493  }
7494  break;
7495  }
7496  case 's':
7497  {
7498  if (LocaleCompare("sampling-factor",option+1) == 0)
7499  {
7500  /*
7501  Set image sampling factor.
7502  */
7503  if (*option == '+')
7504  {
7505  if (image_info->sampling_factor != (char *) NULL)
7506  image_info->sampling_factor=DestroyString(
7507  image_info->sampling_factor);
7508  break;
7509  }
7510  (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7511  break;
7512  }
7513  if (LocaleCompare("scene",option+1) == 0)
7514  {
7515  /*
7516  Set image scene.
7517  */
7518  if (*option == '+')
7519  {
7520  image_info->scene=0;
7521  (void) SetImageOption(image_info,option+1,"0");
7522  break;
7523  }
7524  image_info->scene=StringToUnsignedLong(argv[i+1]);
7525  (void) SetImageOption(image_info,option+1,argv[i+1]);
7526  break;
7527  }
7528  if (LocaleCompare("seed",option+1) == 0)
7529  {
7530  unsigned long
7531  seed;
7532 
7533  if (*option == '+')
7534  {
7535  seed=(unsigned long) time((time_t *) NULL);
7536  SetRandomSecretKey(seed);
7537  break;
7538  }
7539  seed=StringToUnsignedLong(argv[i+1]);
7540  SetRandomSecretKey(seed);
7541  break;
7542  }
7543  if (LocaleCompare("size",option+1) == 0)
7544  {
7545  if (*option == '+')
7546  {
7547  if (image_info->size != (char *) NULL)
7548  image_info->size=DestroyString(image_info->size);
7549  break;
7550  }
7551  (void) CloneString(&image_info->size,argv[i+1]);
7552  break;
7553  }
7554  if (LocaleCompare("stroke",option+1) == 0)
7555  {
7556  if (*option == '+')
7557  (void) SetImageOption(image_info,option+1,"none");
7558  else
7559  (void) SetImageOption(image_info,option+1,argv[i+1]);
7560  break;
7561  }
7562  if (LocaleCompare("strokewidth",option+1) == 0)
7563  {
7564  if (*option == '+')
7565  (void) SetImageOption(image_info,option+1,"0");
7566  else
7567  (void) SetImageOption(image_info,option+1,argv[i+1]);
7568  break;
7569  }
7570  if (LocaleCompare("style",option+1) == 0)
7571  {
7572  if (*option == '+')
7573  (void) SetImageOption(image_info,option+1,"none");
7574  else
7575  (void) SetImageOption(image_info,option+1,argv[i+1]);
7576  break;
7577  }
7578  if (LocaleCompare("synchronize",option+1) == 0)
7579  {
7580  if (*option == '+')
7581  {
7582  image_info->synchronize=MagickFalse;
7583  break;
7584  }
7585  image_info->synchronize=MagickTrue;
7586  break;
7587  }
7588  break;
7589  }
7590  case 't':
7591  {
7592  if (LocaleCompare("taint",option+1) == 0)
7593  {
7594  if (*option == '+')
7595  {
7596  (void) SetImageOption(image_info,option+1,"false");
7597  break;
7598  }
7599  (void) SetImageOption(image_info,option+1,"true");
7600  break;
7601  }
7602  if (LocaleCompare("texture",option+1) == 0)
7603  {
7604  if (*option == '+')
7605  {
7606  if (image_info->texture != (char *) NULL)
7607  image_info->texture=DestroyString(image_info->texture);
7608  break;
7609  }
7610  (void) CloneString(&image_info->texture,argv[i+1]);
7611  break;
7612  }
7613  if (LocaleCompare("tile-offset",option+1) == 0)
7614  {
7615  if (*option == '+')
7616  {
7617  (void) SetImageOption(image_info,option+1,"0");
7618  break;
7619  }
7620  (void) SetImageOption(image_info,option+1,argv[i+1]);
7621  break;
7622  }
7623  if (LocaleCompare("transparent-color",option+1) == 0)
7624  {
7625  if (*option == '+')
7626  {
7627  (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7628  (void) SetImageOption(image_info,option+1,"none");
7629  break;
7630  }
7631  (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7632  exception);
7633  (void) SetImageOption(image_info,option+1,argv[i+1]);
7634  break;
7635  }
7636  if (LocaleCompare("type",option+1) == 0)
7637  {
7638  if (*option == '+')
7639  {
7640  image_info->type=UndefinedType;
7641  (void) SetImageOption(image_info,option+1,"undefined");
7642  break;
7643  }
7644  image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
7645  MagickFalse,argv[i+1]);
7646  (void) SetImageOption(image_info,option+1,argv[i+1]);
7647  break;
7648  }
7649  break;
7650  }
7651  case 'u':
7652  {
7653  if (LocaleCompare("undercolor",option+1) == 0)
7654  {
7655  if (*option == '+')
7656  {
7657  (void) DeleteImageOption(image_info,option+1);
7658  break;
7659  }
7660  (void) SetImageOption(image_info,option+1,argv[i+1]);
7661  break;
7662  }
7663  if (LocaleCompare("units",option+1) == 0)
7664  {
7665  if (*option == '+')
7666  {
7667  image_info->units=UndefinedResolution;
7668  (void) SetImageOption(image_info,option+1,"undefined");
7669  break;
7670  }
7671  image_info->units=(ResolutionType) ParseCommandOption(
7672  MagickResolutionOptions,MagickFalse,argv[i+1]);
7673  (void) SetImageOption(image_info,option+1,argv[i+1]);
7674  break;
7675  }
7676  break;
7677  }
7678  case 'v':
7679  {
7680  if (LocaleCompare("verbose",option+1) == 0)
7681  {
7682  if (*option == '+')
7683  {
7684  image_info->verbose=MagickFalse;
7685  break;
7686  }
7687  image_info->verbose=MagickTrue;
7688  image_info->ping=MagickFalse;
7689  break;
7690  }
7691  if (LocaleCompare("view",option+1) == 0)
7692  {
7693  if (*option == '+')
7694  {
7695  if (image_info->view != (char *) NULL)
7696  image_info->view=DestroyString(image_info->view);
7697  break;
7698  }
7699  (void) CloneString(&image_info->view,argv[i+1]);
7700  break;
7701  }
7702  if (LocaleCompare("virtual-pixel",option+1) == 0)
7703  {
7704  if (*option == '+')
7705  {
7706  image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7707  (void) SetImageOption(image_info,option+1,"undefined");
7708  break;
7709  }
7710  image_info->virtual_pixel_method=(VirtualPixelMethod)
7711  ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
7712  argv[i+1]);
7713  (void) SetImageOption(image_info,option+1,argv[i+1]);
7714  break;
7715  }
7716  break;
7717  }
7718  case 'w':
7719  {
7720  if (LocaleCompare("weight",option+1) == 0)
7721  {
7722  if (*option == '+')
7723  (void) SetImageOption(image_info,option+1,"0");
7724  else
7725  (void) SetImageOption(image_info,option+1,argv[i+1]);
7726  break;
7727  }
7728  if (LocaleCompare("white-point",option+1) == 0)
7729  {
7730  if (*option == '+')
7731  {
7732  (void) SetImageOption(image_info,option+1,"0.0");
7733  break;
7734  }
7735  (void) SetImageOption(image_info,option+1,argv[i+1]);
7736  break;
7737  }
7738  break;
7739  }
7740  default:
7741  break;
7742  }
7743  i+=count;
7744  }
7745  return(MagickTrue);
7746 }
7747 
7748 /*
7749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7750 % %
7751 % %
7752 % %
7753 + M o g r i f y I m a g e L i s t %
7754 % %
7755 % %
7756 % %
7757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7758 %
7759 % MogrifyImageList() applies any command line options that might affect the
7760 % entire image list (e.g. -append, -coalesce, etc.).
7761 %
7762 % The format of the MogrifyImage method is:
7763 %
7764 % MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7765 % const char **argv,Image **images,ExceptionInfo *exception)
7766 %
7767 % A description of each parameter follows:
7768 %
7769 % o image_info: the image info..
7770 %
7771 % o argc: Specifies a pointer to an integer describing the number of
7772 % elements in the argument vector.
7773 %
7774 % o argv: Specifies a pointer to a text array containing the command line
7775 % arguments.
7776 %
7777 % o images: pointer to pointer of the first image in image list.
7778 %
7779 % o exception: return any errors or warnings in this structure.
7780 %
7781 */
7782 WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7783  const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7784 {
7785  ChannelType
7786  channel;
7787 
7788  const char
7789  *option;
7790 
7791  ImageInfo
7792  *mogrify_info;
7793 
7794  MagickStatusType
7795  status;
7796 
7797  QuantizeInfo
7798  *quantize_info;
7799 
7800  ssize_t
7801  i;
7802 
7803  ssize_t
7804  count,
7805  index;
7806 
7807  /*
7808  Apply options to the image list.
7809  */
7810  assert(image_info != (ImageInfo *) NULL);
7811  assert(image_info->signature == MagickCoreSignature);
7812  assert(images != (Image **) NULL);
7813  assert((*images)->previous == (Image *) NULL);
7814  assert((*images)->signature == MagickCoreSignature);
7815  if (IsEventLogging() != MagickFalse)
7816  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7817  (*images)->filename);
7818  if ((argc <= 0) || (*argv == (char *) NULL))
7819  return(MagickTrue);
7820  mogrify_info=CloneImageInfo(image_info);
7821  quantize_info=AcquireQuantizeInfo(mogrify_info);
7822  channel=mogrify_info->channel;
7823  status=MagickTrue;
7824  for (i=0; i < (ssize_t) argc; i++)
7825  {
7826  if (*images == (Image *) NULL)
7827  break;
7828  option=argv[i];
7829  if (IsCommandOption(option) == MagickFalse)
7830  continue;
7831  count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
7832  count=MagickMax(count,0L);
7833  if ((i+count) >= (ssize_t) argc)
7834  break;
7835  status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
7836  switch (*(option+1))
7837  {
7838  case 'a':
7839  {
7840  if (LocaleCompare("affinity",option+1) == 0)
7841  {
7842  (void) SyncImagesSettings(mogrify_info,*images);
7843  if (*option == '+')
7844  {
7845  (void) RemapImages(quantize_info,*images,(Image *) NULL);
7846  InheritException(exception,&(*images)->exception);
7847  break;
7848  }
7849  i++;
7850  break;
7851  }
7852  if (LocaleCompare("append",option+1) == 0)
7853  {
7854  Image
7855  *append_image;
7856 
7857  (void) SyncImagesSettings(mogrify_info,*images);
7858  append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7859  MagickFalse,exception);
7860  if (append_image == (Image *) NULL)
7861  {
7862  status=MagickFalse;
7863  break;
7864  }
7865  *images=DestroyImageList(*images);
7866  *images=append_image;
7867  break;
7868  }
7869  if (LocaleCompare("average",option+1) == 0)
7870  {
7871  Image
7872  *average_image;
7873 
7874  /*
7875  Average an image sequence (deprecated).
7876  */
7877  (void) SyncImagesSettings(mogrify_info,*images);
7878  average_image=EvaluateImages(*images,MeanEvaluateOperator,
7879  exception);
7880  if (average_image == (Image *) NULL)
7881  {
7882  status=MagickFalse;
7883  break;
7884  }
7885  *images=DestroyImageList(*images);
7886  *images=average_image;
7887  break;
7888  }
7889  break;
7890  }
7891  case 'c':
7892  {
7893  if (LocaleCompare("channel",option+1) == 0)
7894  {
7895  if (*option == '+')
7896  {
7897  channel=DefaultChannels;
7898  break;
7899  }
7900  channel=(ChannelType) ParseChannelOption(argv[i+1]);
7901  break;
7902  }
7903  if (LocaleCompare("clut",option+1) == 0)
7904  {
7905  Image
7906  *clut_image,
7907  *image;
7908 
7909  (void) SyncImagesSettings(mogrify_info,*images);
7910  image=RemoveFirstImageFromList(images);
7911  clut_image=RemoveFirstImageFromList(images);
7912  if (clut_image == (Image *) NULL)
7913  {
7914  (void) ThrowMagickException(exception,GetMagickModule(),
7915  OptionError,"ImageSequenceRequired","`%s'",option);
7916  image=DestroyImage(image);
7917  status=MagickFalse;
7918  break;
7919  }
7920  (void) ClutImageChannel(image,channel,clut_image);
7921  clut_image=DestroyImage(clut_image);
7922  InheritException(exception,&image->exception);
7923  *images=DestroyImageList(*images);
7924  *images=image;
7925  break;
7926  }
7927  if (LocaleCompare("coalesce",option+1) == 0)
7928  {
7929  Image
7930  *coalesce_image;
7931 
7932  (void) SyncImagesSettings(mogrify_info,*images);
7933  coalesce_image=CoalesceImages(*images,exception);
7934  if (coalesce_image == (Image *) NULL)
7935  {
7936  status=MagickFalse;
7937  break;
7938  }
7939  *images=DestroyImageList(*images);
7940  *images=coalesce_image;
7941  break;
7942  }
7943  if (LocaleCompare("combine",option+1) == 0)
7944  {
7945  Image
7946  *combine_image;
7947 
7948  (void) SyncImagesSettings(mogrify_info,*images);
7949  combine_image=CombineImages(*images,channel,exception);
7950  if (combine_image == (Image *) NULL)
7951  {
7952  status=MagickFalse;
7953  break;
7954  }
7955  *images=DestroyImageList(*images);
7956  *images=combine_image;
7957  break;
7958  }
7959  if (LocaleCompare("compare",option+1) == 0)
7960  {
7961  double
7962  distortion;
7963 
7964  Image
7965  *difference_image,
7966  *image,
7967  *reconstruct_image;
7968 
7969  MetricType
7970  metric;
7971 
7972  /*
7973  Mathematically and visually annotate the difference between an
7974  image and its reconstruction.
7975  */
7976  (void) SyncImagesSettings(mogrify_info,*images);
7977  image=RemoveFirstImageFromList(images);
7978  reconstruct_image=RemoveFirstImageFromList(images);
7979  if (reconstruct_image == (Image *) NULL)
7980  {
7981  (void) ThrowMagickException(exception,GetMagickModule(),
7982  OptionError,"ImageSequenceRequired","`%s'",option);
7983  image=DestroyImage(image);
7984  status=MagickFalse;
7985  break;
7986  }
7987  metric=UndefinedMetric;
7988  option=GetImageOption(image_info,"metric");
7989  if (option != (const char *) NULL)
7990  metric=(MetricType) ParseCommandOption(MagickMetricOptions,
7991  MagickFalse,option);
7992  difference_image=CompareImageChannels(image,reconstruct_image,
7993  channel,metric,&distortion,exception);
7994  if (difference_image == (Image *) NULL)
7995  break;
7996  reconstruct_image=DestroyImage(reconstruct_image);
7997  image=DestroyImage(image);
7998  if (*images != (Image *) NULL)
7999  *images=DestroyImageList(*images);
8000  *images=difference_image;
8001  break;
8002  }
8003  if (LocaleCompare("complex",option+1) == 0)
8004  {
8005  ComplexOperator
8006  op;
8007 
8008  Image
8009  *complex_images;
8010 
8011  (void) SyncImageSettings(mogrify_info,*images);
8012  op=(ComplexOperator) ParseCommandOption(MagickComplexOptions,
8013  MagickFalse,argv[i+1]);
8014  complex_images=ComplexImages(*images,op,exception);
8015  if (complex_images == (Image *) NULL)
8016  {
8017  status=MagickFalse;
8018  break;
8019  }
8020  *images=DestroyImageList(*images);
8021  *images=complex_images;
8022  break;
8023  }
8024  if (LocaleCompare("composite",option+1) == 0)
8025  {
8026  Image
8027  *mask_image,
8028  *composite_image,
8029  *image;
8030 
8031  RectangleInfo
8032  geometry;
8033 
8034  (void) SyncImagesSettings(mogrify_info,*images);
8035  image=RemoveFirstImageFromList(images);
8036  composite_image=RemoveFirstImageFromList(images);
8037  if (composite_image == (Image *) NULL)
8038  {
8039  (void) ThrowMagickException(exception,GetMagickModule(),
8040  OptionError,"ImageSequenceRequired","`%s'",option);
8041  image=DestroyImage(image);
8042  status=MagickFalse;
8043  break;
8044  }
8045  (void) TransformImage(&composite_image,(char *) NULL,
8046  composite_image->geometry);
8047  SetGeometry(composite_image,&geometry);
8048  (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
8049  GravityAdjustGeometry(image->columns,image->rows,image->gravity,
8050  &geometry);
8051  mask_image=RemoveFirstImageFromList(images);
8052  if (mask_image != (Image *) NULL)
8053  {
8054  if ((image->compose == DisplaceCompositeOp) ||
8055  (image->compose == DistortCompositeOp))
8056  {
8057  /*
8058  Merge Y displacement into X displacement image.
8059  */
8060  (void) CompositeImage(composite_image,CopyGreenCompositeOp,
8061  mask_image,0,0);
8062  mask_image=DestroyImage(mask_image);
8063  }
8064  else
8065  {
8066  /*
8067  Set a blending mask for the composition.
8068  */
8069  if (image->mask != (Image *) NULL)
8070  image->mask=DestroyImage(image->mask);
8071  image->mask=mask_image;
8072  (void) NegateImage(image->mask,MagickFalse);
8073  }
8074  }
8075  (void) CompositeImageChannel(image,channel,image->compose,
8076  composite_image,geometry.x,geometry.y);
8077  if (mask_image != (Image *) NULL)
8078  {
8079  image->mask=DestroyImage(image->mask);
8080  mask_image=image->mask;
8081  }
8082  composite_image=DestroyImage(composite_image);
8083  InheritException(exception,&image->exception);
8084  *images=DestroyImageList(*images);
8085  *images=image;
8086  break;
8087  }
8088  if (LocaleCompare("copy",option+1) == 0)
8089  {
8090  Image
8091  *source_image;
8092 
8093  OffsetInfo
8094  offset;
8095 
8096  RectangleInfo
8097  geometry;
8098 
8099  /*
8100  Copy image pixels.
8101  */
8102  (void) SyncImageSettings(mogrify_info,*images);
8103  (void) ParsePageGeometry(*images,argv[i+2],&geometry,exception);
8104  offset.x=geometry.x;
8105  offset.y=geometry.y;
8106  source_image=(*images);
8107  if (source_image->next != (Image *) NULL)
8108  source_image=source_image->next;
8109  (void) ParsePageGeometry(source_image,argv[i+1],&geometry,
8110  exception);
8111  status=CopyImagePixels(*images,source_image,&geometry,&offset,
8112  exception);
8113  break;
8114  }
8115  break;
8116  }
8117  case 'd':
8118  {
8119  if (LocaleCompare("deconstruct",option+1) == 0)
8120  {
8121  Image
8122  *deconstruct_image;
8123 
8124  (void) SyncImagesSettings(mogrify_info,*images);
8125  deconstruct_image=DeconstructImages(*images,exception);
8126  if (deconstruct_image == (Image *) NULL)
8127  {
8128  status=MagickFalse;
8129  break;
8130  }
8131  *images=DestroyImageList(*images);
8132  *images=deconstruct_image;
8133  break;
8134  }
8135  if (LocaleCompare("delete",option+1) == 0)
8136  {
8137  if (*option == '+')
8138  DeleteImages(images,"-1",exception);
8139  else
8140  DeleteImages(images,argv[i+1],exception);
8141  break;
8142  }
8143  if (LocaleCompare("dither",option+1) == 0)
8144  {
8145  if (*option == '+')
8146  {
8147  quantize_info->dither=MagickFalse;
8148  break;
8149  }
8150  quantize_info->dither=MagickTrue;
8151  quantize_info->dither_method=(DitherMethod) ParseCommandOption(
8152  MagickDitherOptions,MagickFalse,argv[i+1]);
8153  break;
8154  }
8155  if (LocaleCompare("duplicate",option+1) == 0)
8156  {
8157  Image
8158  *duplicate_images;
8159 
8160  if (*option == '+')
8161  duplicate_images=DuplicateImages(*images,1,"-1",exception);
8162  else
8163  {
8164  const char
8165  *p;
8166 
8167  size_t
8168  number_duplicates;
8169 
8170  number_duplicates=(size_t) StringToLong(argv[i+1]);
8171  p=strchr(argv[i+1],',');
8172  if (p == (const char *) NULL)
8173  duplicate_images=DuplicateImages(*images,number_duplicates,
8174  "-1",exception);
8175  else
8176  duplicate_images=DuplicateImages(*images,number_duplicates,
8177  p+1,exception);
8178  }
8179  AppendImageToList(images, duplicate_images);
8180  (void) SyncImagesSettings(mogrify_info,*images);
8181  break;
8182  }
8183  break;
8184  }
8185  case 'e':
8186  {
8187  if (LocaleCompare("evaluate-sequence",option+1) == 0)
8188  {
8189  Image
8190  *evaluate_image;
8191 
8192  MagickEvaluateOperator
8193  op;
8194 
8195  (void) SyncImageSettings(mogrify_info,*images);
8196  op=(MagickEvaluateOperator) ParseCommandOption(
8197  MagickEvaluateOptions,MagickFalse,argv[i+1]);
8198  evaluate_image=EvaluateImages(*images,op,exception);
8199  if (evaluate_image == (Image *) NULL)
8200  {
8201  status=MagickFalse;
8202  break;
8203  }
8204  *images=DestroyImageList(*images);
8205  *images=evaluate_image;
8206  break;
8207  }
8208  break;
8209  }
8210  case 'f':
8211  {
8212  if (LocaleCompare("fft",option+1) == 0)
8213  {
8214  Image
8215  *fourier_image;
8216 
8217  /*
8218  Implements the discrete Fourier transform (DFT).
8219  */
8220  (void) SyncImageSettings(mogrify_info,*images);
8221  fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
8222  MagickTrue : MagickFalse,exception);
8223  if (fourier_image == (Image *) NULL)
8224  break;
8225  *images=DestroyImageList(*images);
8226  *images=fourier_image;
8227  break;
8228  }
8229  if (LocaleCompare("flatten",option+1) == 0)
8230  {
8231  Image
8232  *flatten_image;
8233 
8234  (void) SyncImagesSettings(mogrify_info,*images);
8235  flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
8236  if (flatten_image == (Image *) NULL)
8237  break;
8238  *images=DestroyImageList(*images);
8239  *images=flatten_image;
8240  break;
8241  }
8242  if (LocaleCompare("fx",option+1) == 0)
8243  {
8244  Image
8245  *fx_image;
8246 
8247  (void) SyncImagesSettings(mogrify_info,*images);
8248  fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
8249  if (fx_image == (Image *) NULL)
8250  {
8251  status=MagickFalse;
8252  break;
8253  }
8254  *images=DestroyImageList(*images);
8255  *images=fx_image;
8256  break;
8257  }
8258  break;
8259  }
8260  case 'h':
8261  {
8262  if (LocaleCompare("hald-clut",option+1) == 0)
8263  {
8264  Image
8265  *hald_image,
8266  *image;
8267 
8268  (void) SyncImagesSettings(mogrify_info,*images);
8269  image=RemoveFirstImageFromList(images);
8270  hald_image=RemoveFirstImageFromList(images);
8271  if (hald_image == (Image *) NULL)
8272  {
8273  (void) ThrowMagickException(exception,GetMagickModule(),
8274  OptionError,"ImageSequenceRequired","`%s'",option);
8275  image=DestroyImage(image);
8276  status=MagickFalse;
8277  break;
8278  }
8279  (void) HaldClutImageChannel(image,channel,hald_image);
8280  hald_image=DestroyImage(hald_image);
8281  InheritException(exception,&image->exception);
8282  if (*images != (Image *) NULL)
8283  *images=DestroyImageList(*images);
8284  *images=image;
8285  break;
8286  }
8287  break;
8288  }
8289  case 'i':
8290  {
8291  if (LocaleCompare("ift",option+1) == 0)
8292  {
8293  Image
8294  *fourier_image,
8295  *magnitude_image,
8296  *phase_image;
8297 
8298  /*
8299  Implements the inverse fourier discrete Fourier transform (DFT).
8300  */
8301  (void) SyncImagesSettings(mogrify_info,*images);
8302  magnitude_image=RemoveFirstImageFromList(images);
8303  phase_image=RemoveFirstImageFromList(images);
8304  if (phase_image == (Image *) NULL)
8305  {
8306  (void) ThrowMagickException(exception,GetMagickModule(),
8307  OptionError,"ImageSequenceRequired","`%s'",option);
8308  magnitude_image=DestroyImage(magnitude_image);
8309  status=MagickFalse;
8310  break;
8311  }
8312  fourier_image=InverseFourierTransformImage(magnitude_image,
8313  phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
8314  magnitude_image=DestroyImage(magnitude_image);
8315  phase_image=DestroyImage(phase_image);
8316  if (fourier_image == (Image *) NULL)
8317  break;
8318  if (*images != (Image *) NULL)
8319  *images=DestroyImageList(*images);
8320  *images=fourier_image;
8321  break;
8322  }
8323  if (LocaleCompare("insert",option+1) == 0)
8324  {
8325  Image
8326  *p,
8327  *q;
8328 
8329  index=0;
8330  if (*option != '+')
8331  index=(ssize_t) StringToLong(argv[i+1]);
8332  p=RemoveLastImageFromList(images);
8333  if (p == (Image *) NULL)
8334  {
8335  (void) ThrowMagickException(exception,GetMagickModule(),
8336  OptionError,"NoSuchImage","`%s'",argv[i+1]);
8337  status=MagickFalse;
8338  break;
8339  }
8340  q=p;
8341  if (index == 0)
8342  PrependImageToList(images,q);
8343  else
8344  if (index == (ssize_t) GetImageListLength(*images))
8345  AppendImageToList(images,q);
8346  else
8347  {
8348  q=GetImageFromList(*images,index-1);
8349  if (q == (Image *) NULL)
8350  {
8351  p=DestroyImage(p);
8352  (void) ThrowMagickException(exception,GetMagickModule(),
8353  OptionError,"NoSuchImage","`%s'",argv[i+1]);
8354  status=MagickFalse;
8355  break;
8356  }
8357  InsertImageInList(&q,p);
8358  }
8359  *images=GetFirstImageInList(q);
8360  break;
8361  }
8362  break;
8363  }
8364  case 'l':
8365  {
8366  if (LocaleCompare("layers",option+1) == 0)
8367  {
8368  Image
8369  *layers;
8370 
8371  ImageLayerMethod
8372  method;
8373 
8374  (void) SyncImagesSettings(mogrify_info,*images);
8375  layers=(Image *) NULL;
8376  method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
8377  MagickFalse,argv[i+1]);
8378  switch (method)
8379  {
8380  case CoalesceLayer:
8381  {
8382  layers=CoalesceImages(*images,exception);
8383  break;
8384  }
8385  case CompareAnyLayer:
8386  case CompareClearLayer:
8387  case CompareOverlayLayer:
8388  default:
8389  {
8390  layers=CompareImageLayers(*images,method,exception);
8391  break;
8392  }
8393  case MergeLayer:
8394  case FlattenLayer:
8395  case MosaicLayer:
8396  case TrimBoundsLayer:
8397  {
8398  layers=MergeImageLayers(*images,method,exception);
8399  break;
8400  }
8401  case DisposeLayer:
8402  {
8403  layers=DisposeImages(*images,exception);
8404  break;
8405  }
8406  case OptimizeImageLayer:
8407  {
8408  layers=OptimizeImageLayers(*images,exception);
8409  break;
8410  }
8411  case OptimizePlusLayer:
8412  {
8413  layers=OptimizePlusImageLayers(*images,exception);
8414  break;
8415  }
8416  case OptimizeTransLayer:
8417  {
8418  OptimizeImageTransparency(*images,exception);
8419  break;
8420  }
8421  case RemoveDupsLayer:
8422  {
8423  RemoveDuplicateLayers(images,exception);
8424  break;
8425  }
8426  case RemoveZeroLayer:
8427  {
8428  RemoveZeroDelayLayers(images,exception);
8429  break;
8430  }
8431  case OptimizeLayer:
8432  {
8433  /*
8434  General Purpose, GIF Animation Optimizer.
8435  */
8436  layers=CoalesceImages(*images,exception);
8437  if (layers == (Image *) NULL)
8438  {
8439  status=MagickFalse;
8440  break;
8441  }
8442  InheritException(exception,&layers->exception);
8443  *images=DestroyImageList(*images);
8444  *images=layers;
8445  layers=OptimizeImageLayers(*images,exception);
8446  if (layers == (Image *) NULL)
8447  {
8448  status=MagickFalse;
8449  break;
8450  }
8451  InheritException(exception,&layers->exception);
8452  *images=DestroyImageList(*images);
8453  *images=layers;
8454  layers=(Image *) NULL;
8455  OptimizeImageTransparency(*images,exception);
8456  InheritException(exception,&(*images)->exception);
8457  (void) RemapImages(quantize_info,*images,(Image *) NULL);
8458  break;
8459  }
8460  case CompositeLayer:
8461  {
8462  CompositeOperator
8463  compose;
8464 
8465  Image
8466  *source;
8467 
8468  RectangleInfo
8469  geometry;
8470 
8471  /*
8472  Split image sequence at the first 'NULL:' image.
8473  */
8474  source=(*images);
8475  while (source != (Image *) NULL)
8476  {
8477  source=GetNextImageInList(source);
8478  if ((source != (Image *) NULL) &&
8479  (LocaleCompare(source->magick,"NULL") == 0))
8480  break;
8481  }
8482  if (source != (Image *) NULL)
8483  {
8484  if ((GetPreviousImageInList(source) == (Image *) NULL) ||
8485  (GetNextImageInList(source) == (Image *) NULL))
8486  source=(Image *) NULL;
8487  else
8488  {
8489  /*
8490  Separate the two lists, junk the null: image.
8491  */
8492  source=SplitImageList(source->previous);
8493  DeleteImageFromList(&source);
8494  }
8495  }
8496  if (source == (Image *) NULL)
8497  {
8498  (void) ThrowMagickException(exception,GetMagickModule(),
8499  OptionError,"MissingNullSeparator","layers Composite");
8500  status=MagickFalse;
8501  break;
8502  }
8503  /*
8504  Adjust offset with gravity and virtual canvas.
8505  */
8506  SetGeometry(*images,&geometry);
8507  (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
8508  geometry.width=source->page.width != 0 ?
8509  source->page.width : source->columns;
8510  geometry.height=source->page.height != 0 ?
8511  source->page.height : source->rows;
8512  GravityAdjustGeometry((*images)->page.width != 0 ?
8513  (*images)->page.width : (*images)->columns,
8514  (*images)->page.height != 0 ? (*images)->page.height :
8515  (*images)->rows,(*images)->gravity,&geometry);
8516  compose=OverCompositeOp;
8517  option=GetImageOption(mogrify_info,"compose");
8518  if (option != (const char *) NULL)
8519  compose=(CompositeOperator) ParseCommandOption(
8520  MagickComposeOptions,MagickFalse,option);
8521  CompositeLayers(*images,compose,source,geometry.x,geometry.y,
8522  exception);
8523  source=DestroyImageList(source);
8524  break;
8525  }
8526  }
8527  if (layers == (Image *) NULL)
8528  break;
8529  InheritException(exception,&layers->exception);
8530  *images=DestroyImageList(*images);
8531  *images=layers;
8532  break;
8533  }
8534  break;
8535  }
8536  case 'm':
8537  {
8538  if (LocaleCompare("map",option+1) == 0)
8539  {
8540  (void) SyncImagesSettings(mogrify_info,*images);
8541  if (*option == '+')
8542  {
8543  (void) RemapImages(quantize_info,*images,(Image *) NULL);
8544  InheritException(exception,&(*images)->exception);
8545  break;
8546  }
8547  i++;
8548  break;
8549  }
8550  if (LocaleCompare("maximum",option+1) == 0)
8551  {
8552  Image
8553  *maximum_image;
8554 
8555  /*
8556  Maximum image sequence (deprecated).
8557  */
8558  (void) SyncImagesSettings(mogrify_info,*images);
8559  maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
8560  if (maximum_image == (Image *) NULL)
8561  {
8562  status=MagickFalse;
8563  break;
8564  }
8565  *images=DestroyImageList(*images);
8566  *images=maximum_image;
8567  break;
8568  }
8569  if (LocaleCompare("minimum",option+1) == 0)
8570  {
8571  Image
8572  *minimum_image;
8573 
8574  /*
8575  Minimum image sequence (deprecated).
8576  */
8577  (void) SyncImagesSettings(mogrify_info,*images);
8578  minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
8579  if (minimum_image == (Image *) NULL)
8580  {
8581  status=MagickFalse;
8582  break;
8583  }
8584  *images=DestroyImageList(*images);
8585  *images=minimum_image;
8586  break;
8587  }
8588  if (LocaleCompare("morph",option+1) == 0)
8589  {
8590  Image
8591  *morph_image;
8592 
8593  (void) SyncImagesSettings(mogrify_info,*images);
8594  morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
8595  exception);
8596  if (morph_image == (Image *) NULL)
8597  {
8598  status=MagickFalse;
8599  break;
8600  }
8601  *images=DestroyImageList(*images);
8602  *images=morph_image;
8603  break;
8604  }
8605  if (LocaleCompare("mosaic",option+1) == 0)
8606  {
8607  Image
8608  *mosaic_image;
8609 
8610  (void) SyncImagesSettings(mogrify_info,*images);
8611  mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8612  if (mosaic_image == (Image *) NULL)
8613  {
8614  status=MagickFalse;
8615  break;
8616  }
8617  *images=DestroyImageList(*images);
8618  *images=mosaic_image;
8619  break;
8620  }
8621  break;
8622  }
8623  case 'p':
8624  {
8625  if (LocaleCompare("poly",option+1) == 0)
8626  {
8627  char
8628  *args,
8629  token[MaxTextExtent];
8630 
8631  const char
8632  *p;
8633 
8634  double
8635  *arguments;
8636 
8637  Image
8638  *polynomial_image;
8639 
8640  ssize_t
8641  x;
8642 
8643  size_t
8644  number_arguments;
8645 
8646  /*
8647  Polynomial image.
8648  */
8649  (void) SyncImageSettings(mogrify_info,*images);
8650  args=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
8651  InheritException(exception,&(*images)->exception);
8652  if (args == (char *) NULL)
8653  break;
8654  p=(char *) args;
8655  for (x=0; *p != '\0'; x++)
8656  {
8657  (void) GetNextToken(p,&p,MaxTextExtent,token);
8658  if (*token == ',')
8659  (void) GetNextToken(p,&p,MaxTextExtent,token);
8660  }
8661  number_arguments=(size_t) x;
8662  arguments=(double *) AcquireQuantumMemory(number_arguments,
8663  sizeof(*arguments));
8664  if (arguments == (double *) NULL)
8665  ThrowWandFatalException(ResourceLimitFatalError,
8666  "MemoryAllocationFailed",(*images)->filename);
8667  (void) memset(arguments,0,number_arguments*
8668  sizeof(*arguments));
8669  p=(char *) args;
8670  for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
8671  {
8672  (void) GetNextToken(p,&p,MaxTextExtent,token);
8673  if (*token == ',')
8674  (void) GetNextToken(p,&p,MaxTextExtent,token);
8675  arguments[x]=StringToDouble(token,(char **) NULL);
8676  }
8677  args=DestroyString(args);
8678  polynomial_image=PolynomialImageChannel(*images,channel,
8679  number_arguments >> 1,arguments,exception);
8680  arguments=(double *) RelinquishMagickMemory(arguments);
8681  if (polynomial_image == (Image *) NULL)
8682  {
8683  status=MagickFalse;
8684  break;
8685  }
8686  *images=DestroyImageList(*images);
8687  *images=polynomial_image;
8688  break;
8689  }
8690  if (LocaleCompare("print",option+1) == 0)
8691  {
8692  char
8693  *string;
8694 
8695  (void) SyncImagesSettings(mogrify_info,*images);
8696  string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
8697  if (string == (char *) NULL)
8698  break;
8699  InheritException(exception,&(*images)->exception);
8700  (void) FormatLocaleFile(stdout,"%s",string);
8701  string=DestroyString(string);
8702  }
8703  if (LocaleCompare("process",option+1) == 0)
8704  {
8705  char
8706  **arguments;
8707 
8708  int
8709  j,
8710  number_arguments;
8711 
8712  (void) SyncImagesSettings(mogrify_info,*images);
8713  arguments=StringToArgv(argv[i+1],&number_arguments);
8714  if ((arguments == (char **) NULL) || (number_arguments == 1))
8715  break;
8716  if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8717  {
8718  char
8719  breaker,
8720  quote,
8721  *token;
8722 
8723  const char
8724  *arguments;
8725 
8726  int
8727  next,
8728  status;
8729 
8730  size_t
8731  length;
8732 
8733  TokenInfo
8734  *token_info;
8735 
8736  /*
8737  Support old style syntax, filter="-option arg".
8738  */
8739  length=strlen(argv[i+1]);
8740  token=(char *) NULL;
8741  if (~length >= (MaxTextExtent-1))
8742  token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8743  sizeof(*token));
8744  if (token == (char *) NULL)
8745  break;
8746  next=0;
8747  arguments=argv[i+1];
8748  token_info=AcquireTokenInfo();
8749  status=Tokenizer(token_info,0,token,length,arguments,"","=",
8750  "\"",'\0',&breaker,&next,&quote);
8751  token_info=DestroyTokenInfo(token_info);
8752  if (status == 0)
8753  {
8754  const char
8755  *argv;
8756 
8757  argv=(&(arguments[next]));
8758  (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8759  exception);
8760  }
8761  token=DestroyString(token);
8762  break;
8763  }
8764  (void) SubstituteString(&arguments[1],"-","");
8765  (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8766  number_arguments-2,(const char **) arguments+2,exception);
8767  for (j=0; j < number_arguments; j++)
8768  arguments[j]=DestroyString(arguments[j]);
8769  arguments=(char **) RelinquishMagickMemory(arguments);
8770  break;
8771  }
8772  break;
8773  }
8774  case 'r':
8775  {
8776  if (LocaleCompare("reverse",option+1) == 0)
8777  {
8778  ReverseImageList(images);
8779  InheritException(exception,&(*images)->exception);
8780  break;
8781  }
8782  break;
8783  }
8784  case 's':
8785  {
8786  if (LocaleCompare("smush",option+1) == 0)
8787  {
8788  Image
8789  *smush_image;
8790 
8791  ssize_t
8792  offset;
8793 
8794  (void) SyncImagesSettings(mogrify_info,*images);
8795  offset=(ssize_t) StringToLong(argv[i+1]);
8796  smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8797  MagickFalse,offset,exception);
8798  if (smush_image == (Image *) NULL)
8799  {
8800  status=MagickFalse;
8801  break;
8802  }
8803  *images=DestroyImageList(*images);
8804  *images=smush_image;
8805  break;
8806  }
8807  if (LocaleCompare("swap",option+1) == 0)
8808  {
8809  Image
8810  *p,
8811  *q,
8812  *u,
8813  *v;
8814 
8815  ssize_t
8816  swap_index;
8817 
8818  index=(-1);
8819  swap_index=(-2);
8820  if (*option != '+')
8821  {
8822  GeometryInfo
8823  geometry_info;
8824 
8825  MagickStatusType
8826  flags;
8827 
8828  swap_index=(-1);
8829  flags=ParseGeometry(argv[i+1],&geometry_info);
8830  index=(ssize_t) geometry_info.rho;
8831  if ((flags & SigmaValue) != 0)
8832  swap_index=(ssize_t) geometry_info.sigma;
8833  }
8834  p=GetImageFromList(*images,index);
8835  q=GetImageFromList(*images,swap_index);
8836  if ((p == (Image *) NULL) || (q == (Image *) NULL))
8837  {
8838  (void) ThrowMagickException(exception,GetMagickModule(),
8839  OptionError,"InvalidImageIndex","`%s'",(*images)->filename);
8840  status=MagickFalse;
8841  break;
8842  }
8843  if (p == q)
8844  break;
8845  u=CloneImage(p,0,0,MagickTrue,exception);
8846  if (u == (Image *) NULL)
8847  break;
8848  v=CloneImage(q,0,0,MagickTrue,exception);
8849  if (v == (Image *) NULL)
8850  {
8851  u=DestroyImage(u);
8852  break;
8853  }
8854  ReplaceImageInList(&p,v);
8855  ReplaceImageInList(&q,u);
8856  *images=GetFirstImageInList(q);
8857  break;
8858  }
8859  break;
8860  }
8861  case 'w':
8862  {
8863  if (LocaleCompare("write",option+1) == 0)
8864  {
8865  char
8866  key[MaxTextExtent];
8867 
8868  Image
8869  *write_images;
8870 
8871  ImageInfo
8872  *write_info;
8873 
8874  (void) SyncImagesSettings(mogrify_info,*images);
8875  (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8876  (void) DeleteImageRegistry(key);
8877  write_images=CloneImageList(*images,exception);
8878  write_info=CloneImageInfo(mogrify_info);
8879  status&=WriteImages(write_info,write_images,argv[i+1],exception);
8880  write_info=DestroyImageInfo(write_info);
8881  write_images=DestroyImageList(write_images);
8882  break;
8883  }
8884  break;
8885  }
8886  default:
8887  break;
8888  }
8889  i+=count;
8890  }
8891  quantize_info=DestroyQuantizeInfo(quantize_info);
8892  mogrify_info=DestroyImageInfo(mogrify_info);
8893  status&=MogrifyImageInfo(image_info,argc,argv,exception);
8894  return(status != 0 ? MagickTrue : MagickFalse);
8895 }
8896 
8897 /*
8898 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8899 % %
8900 % %
8901 % %
8902 + M o g r i f y I m a g e s %
8903 % %
8904 % %
8905 % %
8906 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8907 %
8908 % MogrifyImages() applies image processing options to a sequence of images as
8909 % prescribed by command line options.
8910 %
8911 % The format of the MogrifyImage method is:
8912 %
8913 % MagickBooleanType MogrifyImages(ImageInfo *image_info,
8914 % const MagickBooleanType post,const int argc,const char **argv,
8915 % Image **images,Exceptioninfo *exception)
8916 %
8917 % A description of each parameter follows:
8918 %
8919 % o image_info: the image info..
8920 %
8921 % o post: If true, post process image list operators otherwise pre-process.
8922 %
8923 % o argc: Specifies a pointer to an integer describing the number of
8924 % elements in the argument vector.
8925 %
8926 % o argv: Specifies a pointer to a text array containing the command line
8927 % arguments.
8928 %
8929 % o images: pointer to a pointer of the first image in image list.
8930 %
8931 % o exception: return any errors or warnings in this structure.
8932 %
8933 */
8934 WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8935  const MagickBooleanType post,const int argc,const char **argv,
8936  Image **images,ExceptionInfo *exception)
8937 {
8938 #define MogrifyImageTag "Mogrify/Image"
8939 
8940  MagickStatusType
8941  status;
8942 
8943  MagickBooleanType
8944  proceed;
8945 
8946  size_t
8947  n;
8948 
8949  ssize_t
8950  i;
8951 
8952  assert(image_info != (ImageInfo *) NULL);
8953  assert(image_info->signature == MagickCoreSignature);
8954  if (images == (Image **) NULL)
8955  return(MogrifyImage(image_info,argc,argv,images,exception));
8956  assert((*images)->previous == (Image *) NULL);
8957  assert((*images)->signature == MagickCoreSignature);
8958  if (IsEventLogging() != MagickFalse)
8959  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8960  (*images)->filename);
8961  if ((argc <= 0) || (*argv == (char *) NULL))
8962  return(MagickTrue);
8963  (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8964  (void *) NULL);
8965  status=MagickTrue;
8966 #if 0
8967  (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8968  post?"post":"pre");
8969 #endif
8970  /*
8971  Pre-process multi-image sequence operators
8972  */
8973  if (post == MagickFalse)
8974  status&=MogrifyImageList(image_info,argc,argv,images,exception);
8975  /*
8976  For each image, process simple single image operators
8977  */
8978  i=0;
8979  n=GetImageListLength(*images);
8980  for (;;)
8981  {
8982 #if 0
8983  (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8984  GetImageIndexInList(*images),(long)GetImageListLength(*images));
8985 #endif
8986  status&=MogrifyImage(image_info,argc,argv,images,exception);
8987  proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
8988  if (proceed == MagickFalse)
8989  break;
8990  if ((*images)->next == (Image *) NULL)
8991  break;
8992  *images=(*images)->next;
8993  i++;
8994  }
8995  assert(*images != (Image *) NULL);
8996 #if 0
8997  (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8998  GetImageIndexInList(*images),(long)GetImageListLength(*images));
8999 #endif
9000  /*
9001  Post-process, multi-image sequence operators
9002  */
9003  *images=GetFirstImageInList(*images);
9004  if (post != MagickFalse)
9005  status&=MogrifyImageList(image_info,argc,argv,images,exception);
9006  return(status != 0 ? MagickTrue : MagickFalse);
9007 }