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