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