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