blob: ff236a01132b392d04f835d25a5491e08f835dd3 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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% http://www.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
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
47#include "wand/studio.h"
48#include "wand/MagickWand.h"
49#include "wand/mogrify-private.h"
cristy0e9f9c12010-02-11 03:00:47 +000050#include "magick/monitor-private.h"
cristy3980b0d2009-10-25 14:37:13 +000051#include "magick/thread-private.h"
cristyf2f27272009-12-17 14:48:46 +000052#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000053
54/*
55 Define declarations.
56*/
57#define UndefinedCompressionQuality 0UL
58
59/*
anthonydf8ebac2011-04-27 09:03:19 +000060 Constant declaration.
61*/
62static const char
63 BackgroundColor[] = "#fff", /* white */
64 BorderColor[] = "#dfdfdf", /* gray */
65 MatteColor[] = "#bdbdbd"; /* gray */
66
67/*
cristy3ed852e2009-09-05 21:47:34 +000068%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% %
70% %
71% %
cristy5063d812010-10-19 16:28:10 +000072% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000073% %
74% %
75% %
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77%
78% MagickCommandGenesis() applies image processing options to an image as
79% prescribed by command line options.
80%
81% The format of the MagickCommandGenesis method is:
82%
83% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000084% MagickCommand command,int argc,char **argv,char **metadata,
85% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000086%
87% A description of each parameter follows:
88%
89% o image_info: the image info.
90%
cristy5063d812010-10-19 16:28:10 +000091% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
92% MogrifyImageCommand, CompositeImageCommand, CompareImageCommand,
93% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
94% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000095%
96% o argc: Specifies a pointer to an integer describing the number of
97% elements in the argument vector.
98%
99% o argv: Specifies a pointer to a text array containing the command line
100% arguments.
101%
cristy5063d812010-10-19 16:28:10 +0000102% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000103%
104% o exception: return any errors or warnings in this structure.
105%
106*/
107WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
108 MagickCommand command,int argc,char **argv,char **metadata,
109 ExceptionInfo *exception)
110{
111 char
112 *option;
113
114 double
115 duration,
116 elapsed_time,
117 user_time;
118
cristy3980b0d2009-10-25 14:37:13 +0000119 MagickBooleanType
120 concurrent,
121 regard_warnings,
122 status;
123
cristybb503372010-05-27 20:51:26 +0000124 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000125 i;
126
127 TimerInfo
128 *timer;
129
cristybb503372010-05-27 20:51:26 +0000130 size_t
cristy3980b0d2009-10-25 14:37:13 +0000131 iterations;
132
cristyd0a94fa2010-03-12 14:18:11 +0000133 (void) setlocale(LC_ALL,"");
134 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000135 concurrent=MagickFalse;
136 duration=(-1.0);
137 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000138 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000139 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000140 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000141 {
142 option=argv[i];
143 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
144 continue;
145 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000146 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000147 if (LocaleCompare("concurrent",option+1) == 0)
148 concurrent=MagickTrue;
149 if (LocaleCompare("debug",option+1) == 0)
150 (void) SetLogEventMask(argv[++i]);
151 if (LocaleCompare("duration",option+1) == 0)
cristyb51dff52011-05-19 16:55:47 +0000152 duration=LocaleToDouble(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000153 if (LocaleCompare("regard-warnings",option+1) == 0)
154 regard_warnings=MagickTrue;
155 }
156 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000157 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000158 {
cristybb503372010-05-27 20:51:26 +0000159 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000160 {
cristy33557d72009-11-06 00:54:33 +0000161 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000162 continue;
163 if (duration > 0)
164 {
165 if (GetElapsedTime(timer) > duration)
166 continue;
167 (void) ContinueTimer(timer);
168 }
169 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000170 if (exception->severity != UndefinedException)
171 {
172 if ((exception->severity > ErrorException) ||
173 (regard_warnings != MagickFalse))
174 status=MagickTrue;
175 CatchException(exception);
176 }
cristy3d1a5512009-10-25 21:23:27 +0000177 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000178 {
179 (void) fputs(*metadata,stdout);
180 (void) fputc('\n',stdout);
181 *metadata=DestroyString(*metadata);
182 }
183 }
184 }
cristyceae09d2009-10-28 17:18:47 +0000185 else
186 {
187 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000188#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000189 # pragma omp parallel for shared(status)
190#endif
cristybb503372010-05-27 20:51:26 +0000191 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000192 {
cristy33557d72009-11-06 00:54:33 +0000193 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000194 continue;
195 if (duration > 0)
196 {
197 if (GetElapsedTime(timer) > duration)
198 continue;
199 (void) ContinueTimer(timer);
200 }
201 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000202#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000203 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000204#endif
205 {
206 if (exception->severity != UndefinedException)
207 {
208 if ((exception->severity > ErrorException) ||
209 (regard_warnings != MagickFalse))
210 status=MagickTrue;
211 CatchException(exception);
212 }
213 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
214 {
215 (void) fputs(*metadata,stdout);
216 (void) fputc('\n',stdout);
217 *metadata=DestroyString(*metadata);
218 }
219 }
220 }
221 }
cristy3980b0d2009-10-25 14:37:13 +0000222 if (iterations > 1)
223 {
224 elapsed_time=GetElapsedTime(timer);
225 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000226 (void) FormatLocaleFile(stderr,
cristye8c25f92010-06-03 00:53:06 +0000227 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
228 iterations,1.0*iterations/elapsed_time,user_time,(double)
229 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
230 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000231 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000232 }
233 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000234 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000235}
236
237/*
238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239% %
240% %
241% %
cristy3ed852e2009-09-05 21:47:34 +0000242+ M o g r i f y I m a g e %
243% %
244% %
245% %
246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247%
anthonye9c27192011-03-27 08:07:06 +0000248% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000249% image that may be part of a large list, but also handles any 'region'
250% image handling.
anthonye9c27192011-03-27 08:07:06 +0000251%
252% The image in the list may be modified in three different ways...
253%
254% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
255% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
256% * replace by a list of images (only the -separate option!)
257%
258% In each case the result is returned into the list, and a pointer to the
259% modified image (last image added if replaced by a list of images) is
260% returned.
261%
262% ASIDE: The -crop is present but restricted to non-tile single image crops
263%
264% This means if all the images are being processed (such as by
265% MogrifyImages(), next image to be processed will be as per the pointer
266% (*image)->next. Also the image list may grow as a result of some specific
267% operations but as images are never merged or deleted, it will never shrink
268% in length. Typically the list will remain the same length.
269%
270% WARNING: As the image pointed to may be replaced, the first image in the
271% list may also change. GetFirstImageInList() should be used by caller if
272% they wish return the Image pointer to the first image in list.
273%
cristy3ed852e2009-09-05 21:47:34 +0000274%
275% The format of the MogrifyImage method is:
276%
277% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
278% const char **argv,Image **image)
279%
280% A description of each parameter follows:
281%
282% o image_info: the image info..
283%
284% o argc: Specifies a pointer to an integer describing the number of
285% elements in the argument vector.
286%
287% o argv: Specifies a pointer to a text array containing the command line
288% arguments.
289%
290% o image: the image.
291%
292% o exception: return any errors or warnings in this structure.
293%
294*/
295
anthonydf8ebac2011-04-27 09:03:19 +0000296/*
297** GetImageCache() will read an image into a image cache if not already
298** present then return the image that is in the cache under that filename.
299*/
300static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
301 ExceptionInfo *exception)
302{
303 char
304 key[MaxTextExtent];
305
306 ExceptionInfo
307 *sans_exception;
308
309 Image
310 *image;
311
312 ImageInfo
313 *read_info;
314
cristyb51dff52011-05-19 16:55:47 +0000315 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000316 sans_exception=AcquireExceptionInfo();
317 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
318 sans_exception=DestroyExceptionInfo(sans_exception);
319 if (image != (Image *) NULL)
320 return(image);
321 read_info=CloneImageInfo(image_info);
322 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
323 image=ReadImage(read_info,exception);
324 read_info=DestroyImageInfo(read_info);
325 if (image != (Image *) NULL)
326 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
327 return(image);
328}
329
cristy3ed852e2009-09-05 21:47:34 +0000330static MagickBooleanType IsPathWritable(const char *path)
331{
332 if (IsPathAccessible(path) == MagickFalse)
333 return(MagickFalse);
334 if (access(path,W_OK) != 0)
335 return(MagickFalse);
336 return(MagickTrue);
337}
338
cristybb503372010-05-27 20:51:26 +0000339static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000340{
341 if (x > y)
342 return(x);
343 return(y);
344}
345
anthonydf8ebac2011-04-27 09:03:19 +0000346static MagickBooleanType MonitorProgress(const char *text,
347 const MagickOffsetType offset,const MagickSizeType extent,
348 void *wand_unused(client_data))
349{
350 char
351 message[MaxTextExtent],
352 tag[MaxTextExtent];
353
354 const char
355 *locale_message;
356
357 register char
358 *p;
359
360 if (extent < 2)
361 return(MagickTrue);
362 (void) CopyMagickMemory(tag,text,MaxTextExtent);
363 p=strrchr(tag,'/');
364 if (p != (char *) NULL)
365 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000366 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000367 locale_message=GetLocaleMessage(message);
368 if (locale_message == message)
369 locale_message=tag;
370 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000371 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
372 locale_message,(long) offset,(unsigned long) extent,(long)
373 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000374 else
cristyb51dff52011-05-19 16:55:47 +0000375 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000376 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
377 (100L*offset/(extent-1)));
378 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000379 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000380 (void) fflush(stderr);
381 return(MagickTrue);
382}
383
384/*
anthony3d2f4862011-05-01 13:48:16 +0000385** SparseColorOption() parses the complex -sparse-color argument into an
386** an array of floating point values then calls SparseColorImage().
anthonydf8ebac2011-04-27 09:03:19 +0000387** Argument is a complex mix of floating-point pixel coodinates, and color
388** specifications (or direct floating point numbers). The number of floats
anthony3d2f4862011-05-01 13:48:16 +0000389** needed to represent a color varies depending on the current channel
anthonydf8ebac2011-04-27 09:03:19 +0000390** setting.
391*/
392static Image *SparseColorOption(const Image *image,const ChannelType channel,
393 const SparseColorMethod method,const char *arguments,
394 const MagickBooleanType color_from_image,ExceptionInfo *exception)
395{
396 ChannelType
397 channels;
398
399 char
400 token[MaxTextExtent];
401
402 const char
403 *p;
404
405 double
406 *sparse_arguments;
407
408 register size_t
409 x;
410
411 size_t
412 number_arguments;
413
414 size_t
415 number_colors;
416
417 Image
418 *sparse_image;
419
420 MagickPixelPacket
421 color;
422
423 MagickBooleanType
424 error;
425
426 assert(image != (Image *) NULL);
427 assert(image->signature == MagickSignature);
428 if (image->debug != MagickFalse)
429 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
430 assert(exception != (ExceptionInfo *) NULL);
431 assert(exception->signature == MagickSignature);
432 /*
433 Limit channels according to image - and add up number of color channel.
434 */
435 channels=channel;
436 if (image->colorspace != CMYKColorspace)
437 channels=(ChannelType) (channels & ~IndexChannel); /* no index channel */
438 if (image->matte == MagickFalse)
439 channels=(ChannelType) (channels & ~OpacityChannel); /* no alpha channel */
440 number_colors=0;
441 if ((channels & RedChannel) != 0)
442 number_colors++;
443 if ((channels & GreenChannel) != 0)
444 number_colors++;
445 if ((channels & BlueChannel) != 0)
446 number_colors++;
447 if ((channels & IndexChannel) != 0)
448 number_colors++;
449 if ((channels & OpacityChannel) != 0)
450 number_colors++;
451
452 /*
453 Read string, to determine number of arguments needed,
454 */
455 p=arguments;
456 x=0;
457 while( *p != '\0' )
458 {
459 GetMagickToken(p,&p,token);
460 if ( token[0] == ',' ) continue;
461 if ( isalpha((int) token[0]) || token[0] == '#' ) {
462 if ( color_from_image ) {
463 (void) ThrowMagickException(exception,GetMagickModule(),
464 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
465 "Color arg given, when colors are coming from image");
466 return( (Image *)NULL);
467 }
468 x += number_colors; /* color argument */
469 }
470 else {
471 x++; /* floating point argument */
472 }
473 }
474 error=MagickTrue;
475 if ( color_from_image ) {
476 /* just the control points are being given */
477 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
478 number_arguments=(x/2)*(2+number_colors);
479 }
480 else {
481 /* control points and color values */
482 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
483 number_arguments=x;
484 }
485 if ( error ) {
486 (void) ThrowMagickException(exception,GetMagickModule(),
487 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
488 "Invalid number of Arguments");
489 return( (Image *)NULL);
490 }
491
492 /* Allocate and fill in the floating point arguments */
493 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
494 sizeof(*sparse_arguments));
495 if (sparse_arguments == (double *) NULL) {
496 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
497 "MemoryAllocationFailed","%s","SparseColorOption");
498 return( (Image *)NULL);
499 }
500 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
501 sizeof(*sparse_arguments));
502 p=arguments;
503 x=0;
504 while( *p != '\0' && x < number_arguments ) {
505 /* X coordinate */
506 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
507 if ( token[0] == '\0' ) break;
508 if ( isalpha((int) token[0]) || token[0] == '#' ) {
509 (void) ThrowMagickException(exception,GetMagickModule(),
510 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
511 "Color found, instead of X-coord");
512 error = MagickTrue;
513 break;
514 }
cristyb51dff52011-05-19 16:55:47 +0000515 sparse_arguments[x++]=LocaleToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000516 /* Y coordinate */
517 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
518 if ( token[0] == '\0' ) break;
519 if ( isalpha((int) token[0]) || token[0] == '#' ) {
520 (void) ThrowMagickException(exception,GetMagickModule(),
521 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
522 "Color found, instead of Y-coord");
523 error = MagickTrue;
524 break;
525 }
cristyb51dff52011-05-19 16:55:47 +0000526 sparse_arguments[x++]=LocaleToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000527 /* color values for this control point */
528#if 0
529 if ( (color_from_image ) {
530 /* get color from image */
531 /* HOW??? */
532 }
533 else
534#endif
535 {
536 /* color name or function given in string argument */
537 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
538 if ( token[0] == '\0' ) break;
539 if ( isalpha((int) token[0]) || token[0] == '#' ) {
540 /* Color string given */
541 (void) QueryMagickColor(token,&color,exception);
542 if ( channels & RedChannel )
543 sparse_arguments[x++] = QuantumScale*color.red;
544 if ( channels & GreenChannel )
545 sparse_arguments[x++] = QuantumScale*color.green;
546 if ( channels & BlueChannel )
547 sparse_arguments[x++] = QuantumScale*color.blue;
548 if ( channels & IndexChannel )
549 sparse_arguments[x++] = QuantumScale*color.index;
550 if ( channels & OpacityChannel )
551 sparse_arguments[x++] = QuantumScale*color.opacity;
552 }
553 else {
554 /* Colors given as a set of floating point values - experimental */
555 /* NB: token contains the first floating point value to use! */
556 if ( channels & RedChannel ) {
557 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
558 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
559 break;
cristyb51dff52011-05-19 16:55:47 +0000560 sparse_arguments[x++]=LocaleToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000561 token[0] = ','; /* used this token - get another */
562 }
563 if ( channels & GreenChannel ) {
564 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
565 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
566 break;
cristyb51dff52011-05-19 16:55:47 +0000567 sparse_arguments[x++]=LocaleToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000568 token[0] = ','; /* used this token - get another */
569 }
570 if ( channels & BlueChannel ) {
571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristyb51dff52011-05-19 16:55:47 +0000574 sparse_arguments[x++]=LocaleToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
577 if ( channels & IndexChannel ) {
578 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
579 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
580 break;
cristyb51dff52011-05-19 16:55:47 +0000581 sparse_arguments[x++]=LocaleToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000582 token[0] = ','; /* used this token - get another */
583 }
584 if ( channels & OpacityChannel ) {
585 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
586 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
587 break;
cristyb51dff52011-05-19 16:55:47 +0000588 sparse_arguments[x++]=LocaleToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000589 token[0] = ','; /* used this token - get another */
590 }
591 }
592 }
593 }
594 if ( number_arguments != x && !error ) {
595 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
596 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
597 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
598 return( (Image *)NULL);
599 }
600 if ( error )
601 return( (Image *)NULL);
602
603 /* Call the Interpolation function with the parsed arguments */
604 sparse_image=SparseColorImage(image,channels,method,number_arguments,
605 sparse_arguments,exception);
606 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
607 return( sparse_image );
608}
609
cristy3ed852e2009-09-05 21:47:34 +0000610WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
611 const char **argv,Image **image,ExceptionInfo *exception)
612{
anthonydf8ebac2011-04-27 09:03:19 +0000613 ChannelType
614 channel;
615
616 const char
617 *format,
618 *option;
619
620 DrawInfo
621 *draw_info;
622
623 GeometryInfo
624 geometry_info;
625
cristy3ed852e2009-09-05 21:47:34 +0000626 Image
627 *region_image;
628
anthonydf8ebac2011-04-27 09:03:19 +0000629 ImageInfo
630 *mogrify_info;
631
cristyebbcfea2011-02-25 02:43:54 +0000632 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000633 status;
634
anthonydf8ebac2011-04-27 09:03:19 +0000635 MagickPixelPacket
636 fill;
cristy3ed852e2009-09-05 21:47:34 +0000637
anthonydf8ebac2011-04-27 09:03:19 +0000638 MagickStatusType
639 flags;
640
641 QuantizeInfo
642 *quantize_info;
643
644 RectangleInfo
645 geometry,
646 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000647
cristybb503372010-05-27 20:51:26 +0000648 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000649 i;
650
651 /*
652 Initialize method variables.
653 */
654 assert(image_info != (const ImageInfo *) NULL);
655 assert(image_info->signature == MagickSignature);
656 assert(image != (Image **) NULL);
657 assert((*image)->signature == MagickSignature);
658 if ((*image)->debug != MagickFalse)
659 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
660 if (argc < 0)
661 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000662 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000663 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
664 quantize_info=AcquireQuantizeInfo(mogrify_info);
665 SetGeometryInfo(&geometry_info);
666 GetMagickPixelPacket(*image,&fill);
667 SetMagickPixelPacket(*image,&(*image)->background_color,(IndexPacket *) NULL,
668 &fill);
669 channel=mogrify_info->channel;
670 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000671 SetGeometry(*image,&region_geometry);
672 region_image=NewImageList();
673 /*
674 Transmogrify the image.
675 */
cristybb503372010-05-27 20:51:26 +0000676 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000677 {
anthonydf8ebac2011-04-27 09:03:19 +0000678 Image
679 *mogrify_image;
680
anthonye9c27192011-03-27 08:07:06 +0000681 ssize_t
682 count;
683
anthonydf8ebac2011-04-27 09:03:19 +0000684 option=argv[i];
685 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000686 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000687 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
688 0L);
cristycee97112010-05-28 00:44:52 +0000689 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000690 break;
cristy6b3da3a2010-06-20 02:21:46 +0000691 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000692 mogrify_image=(Image *)NULL;
693 switch (*(option+1))
694 {
695 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000696 {
anthonydf8ebac2011-04-27 09:03:19 +0000697 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000698 {
anthonydf8ebac2011-04-27 09:03:19 +0000699 /*
700 Adaptive blur image.
701 */
702 (void) SyncImageSettings(mogrify_info,*image);
703 flags=ParseGeometry(argv[i+1],&geometry_info);
704 if ((flags & SigmaValue) == 0)
705 geometry_info.sigma=1.0;
706 mogrify_image=AdaptiveBlurImageChannel(*image,channel,
707 geometry_info.rho,geometry_info.sigma,exception);
708 break;
cristy3ed852e2009-09-05 21:47:34 +0000709 }
anthonydf8ebac2011-04-27 09:03:19 +0000710 if (LocaleCompare("adaptive-resize",option+1) == 0)
711 {
712 /*
713 Adaptive resize image.
714 */
715 (void) SyncImageSettings(mogrify_info,*image);
716 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
717 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
718 geometry.height,exception);
719 break;
720 }
721 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
722 {
723 /*
724 Adaptive sharpen image.
725 */
726 (void) SyncImageSettings(mogrify_info,*image);
727 flags=ParseGeometry(argv[i+1],&geometry_info);
728 if ((flags & SigmaValue) == 0)
729 geometry_info.sigma=1.0;
730 mogrify_image=AdaptiveSharpenImageChannel(*image,channel,
731 geometry_info.rho,geometry_info.sigma,exception);
732 break;
733 }
734 if (LocaleCompare("affine",option+1) == 0)
735 {
736 /*
737 Affine matrix.
738 */
739 if (*option == '+')
740 {
741 GetAffineMatrix(&draw_info->affine);
742 break;
743 }
744 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
745 break;
746 }
747 if (LocaleCompare("alpha",option+1) == 0)
748 {
749 AlphaChannelType
750 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000751
anthonydf8ebac2011-04-27 09:03:19 +0000752 (void) SyncImageSettings(mogrify_info,*image);
753 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
754 MagickFalse,argv[i+1]);
755 (void) SetImageAlphaChannel(*image,alpha_type);
756 InheritException(exception,&(*image)->exception);
757 break;
758 }
759 if (LocaleCompare("annotate",option+1) == 0)
760 {
761 char
762 *text,
763 geometry[MaxTextExtent];
764
765 /*
766 Annotate image.
767 */
768 (void) SyncImageSettings(mogrify_info,*image);
769 SetGeometryInfo(&geometry_info);
770 flags=ParseGeometry(argv[i+1],&geometry_info);
771 if ((flags & SigmaValue) == 0)
772 geometry_info.sigma=geometry_info.rho;
773 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
774 InheritException(exception,&(*image)->exception);
775 if (text == (char *) NULL)
776 break;
777 (void) CloneString(&draw_info->text,text);
778 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000779 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000780 geometry_info.xi,geometry_info.psi);
781 (void) CloneString(&draw_info->geometry,geometry);
782 draw_info->affine.sx=cos(DegreesToRadians(
783 fmod(geometry_info.rho,360.0)));
784 draw_info->affine.rx=sin(DegreesToRadians(
785 fmod(geometry_info.rho,360.0)));
786 draw_info->affine.ry=(-sin(DegreesToRadians(
787 fmod(geometry_info.sigma,360.0))));
788 draw_info->affine.sy=cos(DegreesToRadians(
789 fmod(geometry_info.sigma,360.0)));
790 (void) AnnotateImage(*image,draw_info);
791 InheritException(exception,&(*image)->exception);
792 break;
793 }
794 if (LocaleCompare("antialias",option+1) == 0)
795 {
796 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
797 MagickFalse;
798 draw_info->text_antialias=(*option == '-') ? MagickTrue :
799 MagickFalse;
800 break;
801 }
802 if (LocaleCompare("auto-gamma",option+1) == 0)
803 {
804 /*
805 Auto Adjust Gamma of image based on its mean
806 */
807 (void) SyncImageSettings(mogrify_info,*image);
808 (void) AutoGammaImageChannel(*image,channel);
809 break;
810 }
811 if (LocaleCompare("auto-level",option+1) == 0)
812 {
813 /*
814 Perfectly Normalize (max/min stretch) the image
815 */
816 (void) SyncImageSettings(mogrify_info,*image);
817 (void) AutoLevelImageChannel(*image,channel);
818 break;
819 }
820 if (LocaleCompare("auto-orient",option+1) == 0)
821 {
822 (void) SyncImageSettings(mogrify_info,*image);
823 switch ((*image)->orientation)
824 {
825 case TopRightOrientation:
826 {
827 mogrify_image=FlopImage(*image,exception);
828 break;
829 }
830 case BottomRightOrientation:
831 {
832 mogrify_image=RotateImage(*image,180.0,exception);
833 break;
834 }
835 case BottomLeftOrientation:
836 {
837 mogrify_image=FlipImage(*image,exception);
838 break;
839 }
840 case LeftTopOrientation:
841 {
842 mogrify_image=TransposeImage(*image,exception);
843 break;
844 }
845 case RightTopOrientation:
846 {
847 mogrify_image=RotateImage(*image,90.0,exception);
848 break;
849 }
850 case RightBottomOrientation:
851 {
852 mogrify_image=TransverseImage(*image,exception);
853 break;
854 }
855 case LeftBottomOrientation:
856 {
857 mogrify_image=RotateImage(*image,270.0,exception);
858 break;
859 }
860 default:
861 break;
862 }
863 if (mogrify_image != (Image *) NULL)
864 mogrify_image->orientation=TopLeftOrientation;
865 break;
866 }
867 break;
868 }
869 case 'b':
870 {
871 if (LocaleCompare("black-threshold",option+1) == 0)
872 {
873 /*
874 Black threshold image.
875 */
876 (void) SyncImageSettings(mogrify_info,*image);
877 (void) BlackThresholdImageChannel(*image,channel,argv[i+1],
878 exception);
879 InheritException(exception,&(*image)->exception);
880 break;
881 }
882 if (LocaleCompare("blue-shift",option+1) == 0)
883 {
884 /*
885 Blue shift image.
886 */
887 (void) SyncImageSettings(mogrify_info,*image);
888 geometry_info.rho=1.5;
889 if (*option == '-')
890 flags=ParseGeometry(argv[i+1],&geometry_info);
891 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
892 break;
893 }
894 if (LocaleCompare("blur",option+1) == 0)
895 {
896 /*
897 Gaussian blur image.
898 */
899 (void) SyncImageSettings(mogrify_info,*image);
900 flags=ParseGeometry(argv[i+1],&geometry_info);
901 if ((flags & SigmaValue) == 0)
902 geometry_info.sigma=1.0;
903 mogrify_image=BlurImageChannel(*image,channel,geometry_info.rho,
904 geometry_info.sigma,exception);
905 break;
906 }
907 if (LocaleCompare("border",option+1) == 0)
908 {
909 /*
910 Surround image with a border of solid color.
911 */
912 (void) SyncImageSettings(mogrify_info,*image);
913 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
914 if ((flags & SigmaValue) == 0)
915 geometry.height=geometry.width;
916 mogrify_image=BorderImage(*image,&geometry,exception);
917 break;
918 }
919 if (LocaleCompare("bordercolor",option+1) == 0)
920 {
921 if (*option == '+')
922 {
923 (void) QueryColorDatabase(BorderColor,&draw_info->border_color,
924 exception);
925 break;
926 }
927 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
928 exception);
929 break;
930 }
931 if (LocaleCompare("box",option+1) == 0)
932 {
933 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
934 exception);
935 break;
936 }
937 if (LocaleCompare("brightness-contrast",option+1) == 0)
938 {
939 double
940 brightness,
941 contrast;
942
943 GeometryInfo
944 geometry_info;
945
946 MagickStatusType
947 flags;
948
949 /*
950 Brightness / contrast image.
951 */
952 (void) SyncImageSettings(mogrify_info,*image);
953 flags=ParseGeometry(argv[i+1],&geometry_info);
954 brightness=geometry_info.rho;
955 contrast=0.0;
956 if ((flags & SigmaValue) != 0)
957 contrast=geometry_info.sigma;
958 (void) BrightnessContrastImageChannel(*image,channel,brightness,
959 contrast);
960 InheritException(exception,&(*image)->exception);
961 break;
962 }
963 break;
964 }
965 case 'c':
966 {
967 if (LocaleCompare("cdl",option+1) == 0)
968 {
969 char
970 *color_correction_collection;
971
972 /*
973 Color correct with a color decision list.
974 */
975 (void) SyncImageSettings(mogrify_info,*image);
976 color_correction_collection=FileToString(argv[i+1],~0,exception);
977 if (color_correction_collection == (char *) NULL)
978 break;
979 (void) ColorDecisionListImage(*image,color_correction_collection);
980 InheritException(exception,&(*image)->exception);
981 break;
982 }
983 if (LocaleCompare("channel",option+1) == 0)
984 {
985 if (*option == '+')
986 channel=DefaultChannels;
987 else
988 channel=(ChannelType) ParseChannelOption(argv[i+1]);
989 break;
990 }
991 if (LocaleCompare("charcoal",option+1) == 0)
992 {
993 /*
994 Charcoal image.
995 */
996 (void) SyncImageSettings(mogrify_info,*image);
997 flags=ParseGeometry(argv[i+1],&geometry_info);
998 if ((flags & SigmaValue) == 0)
999 geometry_info.sigma=1.0;
1000 mogrify_image=CharcoalImage(*image,geometry_info.rho,
1001 geometry_info.sigma,exception);
1002 break;
1003 }
1004 if (LocaleCompare("chop",option+1) == 0)
1005 {
1006 /*
1007 Chop the image.
1008 */
1009 (void) SyncImageSettings(mogrify_info,*image);
1010 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1011 mogrify_image=ChopImage(*image,&geometry,exception);
1012 break;
1013 }
1014 if (LocaleCompare("clamp",option+1) == 0)
1015 {
1016 /*
1017 Clamp image.
1018 */
1019 (void) SyncImageSettings(mogrify_info,*image);
1020 (void) ClampImageChannel(*image,channel);
1021 InheritException(exception,&(*image)->exception);
1022 break;
1023 }
1024 if (LocaleCompare("clip",option+1) == 0)
1025 {
1026 (void) SyncImageSettings(mogrify_info,*image);
1027 if (*option == '+')
1028 {
1029 (void) SetImageClipMask(*image,(Image *) NULL);
1030 InheritException(exception,&(*image)->exception);
1031 break;
1032 }
1033 (void) ClipImage(*image);
1034 InheritException(exception,&(*image)->exception);
1035 break;
1036 }
1037 if (LocaleCompare("clip-mask",option+1) == 0)
1038 {
1039 CacheView
1040 *mask_view;
1041
1042 Image
1043 *mask_image;
1044
1045 register PixelPacket
1046 *restrict q;
1047
1048 register ssize_t
1049 x;
1050
1051 ssize_t
1052 y;
1053
1054 (void) SyncImageSettings(mogrify_info,*image);
1055 if (*option == '+')
1056 {
1057 /*
1058 Remove a mask.
1059 */
1060 (void) SetImageMask(*image,(Image *) NULL);
1061 InheritException(exception,&(*image)->exception);
1062 break;
1063 }
1064 /*
1065 Set the image mask.
1066 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1067 */
1068 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1069 if (mask_image == (Image *) NULL)
1070 break;
1071 if (SetImageStorageClass(mask_image,DirectClass) == MagickFalse)
1072 return(MagickFalse);
1073 mask_view=AcquireCacheView(mask_image);
1074 for (y=0; y < (ssize_t) mask_image->rows; y++)
1075 {
1076 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1077 exception);
1078 if (q == (PixelPacket *) NULL)
1079 break;
1080 for (x=0; x < (ssize_t) mask_image->columns; x++)
1081 {
1082 if (mask_image->matte == MagickFalse)
cristy843c1722011-05-04 23:47:02 +00001083 SetOpacityPixelComponent(q,PixelIntensityToQuantum(q));
1084 SetRedPixelComponent(q,GetOpacityPixelComponent(q));
1085 SetGreenPixelComponent(q,GetOpacityPixelComponent(q));
1086 SetBluePixelComponent(q,GetOpacityPixelComponent(q));
anthonydf8ebac2011-04-27 09:03:19 +00001087 q++;
1088 }
1089 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1090 break;
1091 }
1092 mask_view=DestroyCacheView(mask_view);
1093 mask_image->matte=MagickTrue;
1094 (void) SetImageClipMask(*image,mask_image);
1095 mask_image=DestroyImage(mask_image);
1096 InheritException(exception,&(*image)->exception);
1097 break;
1098 }
1099 if (LocaleCompare("clip-path",option+1) == 0)
1100 {
1101 (void) SyncImageSettings(mogrify_info,*image);
1102 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1103 MagickFalse);
1104 InheritException(exception,&(*image)->exception);
1105 break;
1106 }
1107 if (LocaleCompare("colorize",option+1) == 0)
1108 {
1109 /*
1110 Colorize the image.
1111 */
1112 (void) SyncImageSettings(mogrify_info,*image);
1113 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1114 exception);
1115 break;
1116 }
1117 if (LocaleCompare("color-matrix",option+1) == 0)
1118 {
1119 KernelInfo
1120 *kernel;
1121
1122 (void) SyncImageSettings(mogrify_info,*image);
1123 kernel=AcquireKernelInfo(argv[i+1]);
1124 if (kernel == (KernelInfo *) NULL)
1125 break;
1126 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1127 kernel=DestroyKernelInfo(kernel);
1128 break;
1129 }
1130 if (LocaleCompare("colors",option+1) == 0)
1131 {
1132 /*
1133 Reduce the number of colors in the image.
1134 */
1135 (void) SyncImageSettings(mogrify_info,*image);
1136 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1137 if (quantize_info->number_colors == 0)
1138 break;
1139 if (((*image)->storage_class == DirectClass) ||
1140 (*image)->colors > quantize_info->number_colors)
1141 (void) QuantizeImage(quantize_info,*image);
1142 else
1143 (void) CompressImageColormap(*image);
1144 InheritException(exception,&(*image)->exception);
1145 break;
1146 }
1147 if (LocaleCompare("colorspace",option+1) == 0)
1148 {
1149 ColorspaceType
1150 colorspace;
1151
1152 (void) SyncImageSettings(mogrify_info,*image);
1153 if (*option == '+')
1154 {
1155 (void) TransformImageColorspace(*image,RGBColorspace);
1156 InheritException(exception,&(*image)->exception);
1157 break;
1158 }
1159 colorspace=(ColorspaceType) ParseCommandOption(
1160 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1161 (void) TransformImageColorspace(*image,colorspace);
1162 InheritException(exception,&(*image)->exception);
1163 break;
1164 }
1165 if (LocaleCompare("contrast",option+1) == 0)
1166 {
1167 (void) SyncImageSettings(mogrify_info,*image);
1168 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1169 MagickFalse);
1170 InheritException(exception,&(*image)->exception);
1171 break;
1172 }
1173 if (LocaleCompare("contrast-stretch",option+1) == 0)
1174 {
1175 double
1176 black_point,
1177 white_point;
1178
1179 MagickStatusType
1180 flags;
1181
1182 /*
1183 Contrast stretch image.
1184 */
1185 (void) SyncImageSettings(mogrify_info,*image);
1186 flags=ParseGeometry(argv[i+1],&geometry_info);
1187 black_point=geometry_info.rho;
1188 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1189 black_point;
1190 if ((flags & PercentValue) != 0)
1191 {
1192 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1193 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1194 }
1195 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1196 white_point;
1197 (void) ContrastStretchImageChannel(*image,channel,black_point,
1198 white_point);
1199 InheritException(exception,&(*image)->exception);
1200 break;
1201 }
1202 if (LocaleCompare("convolve",option+1) == 0)
1203 {
1204 double
1205 gamma;
1206
1207 KernelInfo
1208 *kernel;
1209
1210 register ssize_t
1211 j;
1212
1213 (void) SyncImageSettings(mogrify_info,*image);
1214 kernel=AcquireKernelInfo(argv[i+1]);
1215 if (kernel == (KernelInfo *) NULL)
1216 break;
1217 gamma=0.0;
1218 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1219 gamma+=kernel->values[j];
1220 gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
1221 for (j=0; j < (ssize_t) (kernel->width*kernel->height); j++)
1222 kernel->values[j]*=gamma;
1223 mogrify_image=FilterImageChannel(*image,channel,kernel,exception);
1224 kernel=DestroyKernelInfo(kernel);
1225 break;
1226 }
1227 if (LocaleCompare("crop",option+1) == 0)
1228 {
1229 /*
1230 Crop a image to a smaller size
1231 */
1232 (void) SyncImageSettings(mogrify_info,*image);
1233#if 0
1234 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1235 if (((geometry.width != 0) || (geometry.height != 0)) &&
1236 ((flags & XValue) == 0) && ((flags & YValue) == 0))
1237 break;
1238#endif
1239#if 0
1240 mogrify_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1241 mogrify_image->next = mogrify_image->previous = (Image *)NULL;
1242 (void) TransformImage(&mogrify_image,argv[i+1],(char *) NULL);
1243 InheritException(exception,&mogrify_image->exception);
1244#else
1245 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1246#endif
1247 break;
1248 }
1249 if (LocaleCompare("cycle",option+1) == 0)
1250 {
1251 /*
1252 Cycle an image colormap.
1253 */
1254 (void) SyncImageSettings(mogrify_info,*image);
1255 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1256 InheritException(exception,&(*image)->exception);
1257 break;
1258 }
1259 break;
1260 }
1261 case 'd':
1262 {
1263 if (LocaleCompare("decipher",option+1) == 0)
1264 {
1265 StringInfo
1266 *passkey;
1267
1268 /*
1269 Decipher pixels.
1270 */
1271 (void) SyncImageSettings(mogrify_info,*image);
1272 passkey=FileToStringInfo(argv[i+1],~0,exception);
1273 if (passkey != (StringInfo *) NULL)
1274 {
1275 (void) PasskeyDecipherImage(*image,passkey,exception);
1276 passkey=DestroyStringInfo(passkey);
1277 }
1278 break;
1279 }
1280 if (LocaleCompare("density",option+1) == 0)
1281 {
1282 /*
1283 Set image density.
1284 */
1285 (void) CloneString(&draw_info->density,argv[i+1]);
1286 break;
1287 }
1288 if (LocaleCompare("depth",option+1) == 0)
1289 {
1290 (void) SyncImageSettings(mogrify_info,*image);
1291 if (*option == '+')
1292 {
1293 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1294 break;
1295 }
1296 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1297 break;
1298 }
1299 if (LocaleCompare("deskew",option+1) == 0)
1300 {
1301 double
1302 threshold;
1303
1304 /*
1305 Straighten the image.
1306 */
1307 (void) SyncImageSettings(mogrify_info,*image);
1308 if (*option == '+')
1309 threshold=40.0*QuantumRange/100.0;
1310 else
1311 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1312 mogrify_image=DeskewImage(*image,threshold,exception);
1313 break;
1314 }
1315 if (LocaleCompare("despeckle",option+1) == 0)
1316 {
1317 /*
1318 Reduce the speckles within an image.
1319 */
1320 (void) SyncImageSettings(mogrify_info,*image);
1321 mogrify_image=DespeckleImage(*image,exception);
1322 break;
1323 }
1324 if (LocaleCompare("display",option+1) == 0)
1325 {
1326 (void) CloneString(&draw_info->server_name,argv[i+1]);
1327 break;
1328 }
1329 if (LocaleCompare("distort",option+1) == 0)
1330 {
1331 char
1332 *args,
1333 token[MaxTextExtent];
1334
1335 const char
1336 *p;
1337
1338 DistortImageMethod
1339 method;
1340
1341 double
1342 *arguments;
1343
1344 register ssize_t
1345 x;
1346
1347 size_t
1348 number_arguments;
1349
1350 /*
1351 Distort image.
1352 */
1353 (void) SyncImageSettings(mogrify_info,*image);
1354 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1355 MagickFalse,argv[i+1]);
1356 if ( method == ResizeDistortion )
1357 {
1358 /* Special Case - Argument is actually a resize geometry!
1359 ** Convert that to an appropriate distortion argument array.
1360 */
1361 double
1362 resize_args[2];
1363 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1364 exception);
1365 resize_args[0]=(double)geometry.width;
1366 resize_args[1]=(double)geometry.height;
1367 mogrify_image=DistortImage(*image,method,(size_t)2,
1368 resize_args,MagickTrue,exception);
1369 break;
1370 }
1371 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1372 InheritException(exception,&(*image)->exception);
1373 if (args == (char *) NULL)
1374 break;
1375 p=(char *) args;
1376 for (x=0; *p != '\0'; x++)
1377 {
1378 GetMagickToken(p,&p,token);
1379 if (*token == ',')
1380 GetMagickToken(p,&p,token);
1381 }
1382 number_arguments=(size_t) x;
1383 arguments=(double *) AcquireQuantumMemory(number_arguments,
1384 sizeof(*arguments));
1385 if (arguments == (double *) NULL)
1386 ThrowWandFatalException(ResourceLimitFatalError,
1387 "MemoryAllocationFailed",(*image)->filename);
1388 (void) ResetMagickMemory(arguments,0,number_arguments*
1389 sizeof(*arguments));
1390 p=(char *) args;
1391 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1392 {
1393 GetMagickToken(p,&p,token);
1394 if (*token == ',')
1395 GetMagickToken(p,&p,token);
cristyb51dff52011-05-19 16:55:47 +00001396 arguments[x]=LocaleToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001397 }
1398 args=DestroyString(args);
1399 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1400 (*option == '+') ? MagickTrue : MagickFalse,exception);
1401 arguments=(double *) RelinquishMagickMemory(arguments);
1402 break;
1403 }
1404 if (LocaleCompare("dither",option+1) == 0)
1405 {
1406 if (*option == '+')
1407 {
1408 quantize_info->dither=MagickFalse;
1409 break;
1410 }
1411 quantize_info->dither=MagickTrue;
1412 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1413 MagickDitherOptions,MagickFalse,argv[i+1]);
1414 if (quantize_info->dither_method == NoDitherMethod)
1415 quantize_info->dither=MagickFalse;
1416 break;
1417 }
1418 if (LocaleCompare("draw",option+1) == 0)
1419 {
1420 /*
1421 Draw image.
1422 */
1423 (void) SyncImageSettings(mogrify_info,*image);
1424 (void) CloneString(&draw_info->primitive,argv[i+1]);
1425 (void) DrawImage(*image,draw_info);
1426 InheritException(exception,&(*image)->exception);
1427 break;
1428 }
1429 break;
1430 }
1431 case 'e':
1432 {
1433 if (LocaleCompare("edge",option+1) == 0)
1434 {
1435 /*
1436 Enhance edges in the image.
1437 */
1438 (void) SyncImageSettings(mogrify_info,*image);
1439 flags=ParseGeometry(argv[i+1],&geometry_info);
1440 if ((flags & SigmaValue) == 0)
1441 geometry_info.sigma=1.0;
1442 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1443 break;
1444 }
1445 if (LocaleCompare("emboss",option+1) == 0)
1446 {
1447 /*
1448 Gaussian embossen image.
1449 */
1450 (void) SyncImageSettings(mogrify_info,*image);
1451 flags=ParseGeometry(argv[i+1],&geometry_info);
1452 if ((flags & SigmaValue) == 0)
1453 geometry_info.sigma=1.0;
1454 mogrify_image=EmbossImage(*image,geometry_info.rho,
1455 geometry_info.sigma,exception);
1456 break;
1457 }
1458 if (LocaleCompare("encipher",option+1) == 0)
1459 {
1460 StringInfo
1461 *passkey;
1462
1463 /*
1464 Encipher pixels.
1465 */
1466 (void) SyncImageSettings(mogrify_info,*image);
1467 passkey=FileToStringInfo(argv[i+1],~0,exception);
1468 if (passkey != (StringInfo *) NULL)
1469 {
1470 (void) PasskeyEncipherImage(*image,passkey,exception);
1471 passkey=DestroyStringInfo(passkey);
1472 }
1473 break;
1474 }
1475 if (LocaleCompare("encoding",option+1) == 0)
1476 {
1477 (void) CloneString(&draw_info->encoding,argv[i+1]);
1478 break;
1479 }
1480 if (LocaleCompare("enhance",option+1) == 0)
1481 {
1482 /*
1483 Enhance image.
1484 */
1485 (void) SyncImageSettings(mogrify_info,*image);
1486 mogrify_image=EnhanceImage(*image,exception);
1487 break;
1488 }
1489 if (LocaleCompare("equalize",option+1) == 0)
1490 {
1491 /*
1492 Equalize image.
1493 */
1494 (void) SyncImageSettings(mogrify_info,*image);
1495 (void) EqualizeImageChannel(*image,channel);
1496 InheritException(exception,&(*image)->exception);
1497 break;
1498 }
1499 if (LocaleCompare("evaluate",option+1) == 0)
1500 {
1501 double
1502 constant;
1503
1504 MagickEvaluateOperator
1505 op;
1506
1507 (void) SyncImageSettings(mogrify_info,*image);
1508 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
1509 MagickFalse,argv[i+1]);
1510 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
1511 (void) EvaluateImageChannel(*image,channel,op,constant,exception);
1512 break;
1513 }
1514 if (LocaleCompare("extent",option+1) == 0)
1515 {
1516 /*
1517 Set the image extent.
1518 */
1519 (void) SyncImageSettings(mogrify_info,*image);
1520 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1521 if (geometry.width == 0)
1522 geometry.width=(*image)->columns;
1523 if (geometry.height == 0)
1524 geometry.height=(*image)->rows;
1525 mogrify_image=ExtentImage(*image,&geometry,exception);
1526 break;
1527 }
1528 break;
1529 }
1530 case 'f':
1531 {
1532 if (LocaleCompare("family",option+1) == 0)
1533 {
1534 if (*option == '+')
1535 {
1536 if (draw_info->family != (char *) NULL)
1537 draw_info->family=DestroyString(draw_info->family);
1538 break;
1539 }
1540 (void) CloneString(&draw_info->family,argv[i+1]);
1541 break;
1542 }
1543 if (LocaleCompare("features",option+1) == 0)
1544 {
1545 if (*option == '+')
1546 {
1547 (void) DeleteImageArtifact(*image,"identify:features");
1548 break;
1549 }
1550 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1551 break;
1552 }
1553 if (LocaleCompare("fill",option+1) == 0)
1554 {
1555 ExceptionInfo
1556 *sans;
1557
1558 GetMagickPixelPacket(*image,&fill);
1559 if (*option == '+')
1560 {
1561 (void) QueryMagickColor("none",&fill,exception);
1562 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1563 if (draw_info->fill_pattern != (Image *) NULL)
1564 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1565 break;
1566 }
1567 sans=AcquireExceptionInfo();
1568 (void) QueryMagickColor(argv[i+1],&fill,sans);
1569 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1570 sans=DestroyExceptionInfo(sans);
1571 if (status == MagickFalse)
1572 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1573 exception);
1574 break;
1575 }
1576 if (LocaleCompare("flip",option+1) == 0)
1577 {
1578 /*
1579 Flip image scanlines.
1580 */
1581 (void) SyncImageSettings(mogrify_info,*image);
1582 mogrify_image=FlipImage(*image,exception);
1583 break;
1584 }
anthonydf8ebac2011-04-27 09:03:19 +00001585 if (LocaleCompare("floodfill",option+1) == 0)
1586 {
1587 MagickPixelPacket
1588 target;
1589
1590 /*
1591 Floodfill image.
1592 */
1593 (void) SyncImageSettings(mogrify_info,*image);
1594 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1595 (void) QueryMagickColor(argv[i+2],&target,exception);
1596 (void) FloodfillPaintImage(*image,channel,draw_info,&target,
1597 geometry.x,geometry.y,*option == '-' ? MagickFalse : MagickTrue);
1598 InheritException(exception,&(*image)->exception);
1599 break;
1600 }
anthony3d2f4862011-05-01 13:48:16 +00001601 if (LocaleCompare("flop",option+1) == 0)
1602 {
1603 /*
1604 Flop image scanlines.
1605 */
1606 (void) SyncImageSettings(mogrify_info,*image);
1607 mogrify_image=FlopImage(*image,exception);
1608 break;
1609 }
anthonydf8ebac2011-04-27 09:03:19 +00001610 if (LocaleCompare("font",option+1) == 0)
1611 {
1612 if (*option == '+')
1613 {
1614 if (draw_info->font != (char *) NULL)
1615 draw_info->font=DestroyString(draw_info->font);
1616 break;
1617 }
1618 (void) CloneString(&draw_info->font,argv[i+1]);
1619 break;
1620 }
1621 if (LocaleCompare("format",option+1) == 0)
1622 {
1623 format=argv[i+1];
1624 break;
1625 }
1626 if (LocaleCompare("frame",option+1) == 0)
1627 {
1628 FrameInfo
1629 frame_info;
1630
1631 /*
1632 Surround image with an ornamental border.
1633 */
1634 (void) SyncImageSettings(mogrify_info,*image);
1635 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1636 frame_info.width=geometry.width;
1637 frame_info.height=geometry.height;
1638 if ((flags & HeightValue) == 0)
1639 frame_info.height=geometry.width;
1640 frame_info.outer_bevel=geometry.x;
1641 frame_info.inner_bevel=geometry.y;
1642 frame_info.x=(ssize_t) frame_info.width;
1643 frame_info.y=(ssize_t) frame_info.height;
1644 frame_info.width=(*image)->columns+2*frame_info.width;
1645 frame_info.height=(*image)->rows+2*frame_info.height;
1646 mogrify_image=FrameImage(*image,&frame_info,exception);
1647 break;
1648 }
1649 if (LocaleCompare("function",option+1) == 0)
1650 {
1651 char
1652 *arguments,
1653 token[MaxTextExtent];
1654
1655 const char
1656 *p;
1657
1658 double
1659 *parameters;
1660
1661 MagickFunction
1662 function;
1663
1664 register ssize_t
1665 x;
1666
1667 size_t
1668 number_parameters;
1669
1670 /*
1671 Function Modify Image Values
1672 */
1673 (void) SyncImageSettings(mogrify_info,*image);
1674 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1675 MagickFalse,argv[i+1]);
1676 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1677 InheritException(exception,&(*image)->exception);
1678 if (arguments == (char *) NULL)
1679 break;
1680 p=(char *) arguments;
1681 for (x=0; *p != '\0'; x++)
1682 {
1683 GetMagickToken(p,&p,token);
1684 if (*token == ',')
1685 GetMagickToken(p,&p,token);
1686 }
1687 number_parameters=(size_t) x;
1688 parameters=(double *) AcquireQuantumMemory(number_parameters,
1689 sizeof(*parameters));
1690 if (parameters == (double *) NULL)
1691 ThrowWandFatalException(ResourceLimitFatalError,
1692 "MemoryAllocationFailed",(*image)->filename);
1693 (void) ResetMagickMemory(parameters,0,number_parameters*
1694 sizeof(*parameters));
1695 p=(char *) arguments;
1696 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1697 {
1698 GetMagickToken(p,&p,token);
1699 if (*token == ',')
1700 GetMagickToken(p,&p,token);
cristyb51dff52011-05-19 16:55:47 +00001701 parameters[x]=LocaleToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001702 }
1703 arguments=DestroyString(arguments);
1704 (void) FunctionImageChannel(*image,channel,function,
1705 number_parameters,parameters,exception);
1706 parameters=(double *) RelinquishMagickMemory(parameters);
1707 break;
1708 }
1709 break;
1710 }
1711 case 'g':
1712 {
1713 if (LocaleCompare("gamma",option+1) == 0)
1714 {
1715 /*
1716 Gamma image.
1717 */
1718 (void) SyncImageSettings(mogrify_info,*image);
1719 if (*option == '+')
cristyb51dff52011-05-19 16:55:47 +00001720 (*image)->gamma=LocaleToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001721 else
1722 {
1723 if (strchr(argv[i+1],',') != (char *) NULL)
1724 (void) GammaImage(*image,argv[i+1]);
1725 else
1726 (void) GammaImageChannel(*image,channel,
cristyb51dff52011-05-19 16:55:47 +00001727 LocaleToDouble(argv[i+1],(char **) NULL));
anthonydf8ebac2011-04-27 09:03:19 +00001728 InheritException(exception,&(*image)->exception);
1729 }
1730 break;
1731 }
1732 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1733 (LocaleCompare("gaussian",option+1) == 0))
1734 {
1735 /*
1736 Gaussian blur image.
1737 */
1738 (void) SyncImageSettings(mogrify_info,*image);
1739 flags=ParseGeometry(argv[i+1],&geometry_info);
1740 if ((flags & SigmaValue) == 0)
1741 geometry_info.sigma=1.0;
1742 mogrify_image=GaussianBlurImageChannel(*image,channel,
1743 geometry_info.rho,geometry_info.sigma,exception);
1744 break;
1745 }
1746 if (LocaleCompare("geometry",option+1) == 0)
1747 {
1748 /*
1749 Record Image offset, Resize last image.
1750 */
1751 (void) SyncImageSettings(mogrify_info,*image);
1752 if (*option == '+')
1753 {
1754 if ((*image)->geometry != (char *) NULL)
1755 (*image)->geometry=DestroyString((*image)->geometry);
1756 break;
1757 }
1758 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1759 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1760 (void) CloneString(&(*image)->geometry,argv[i+1]);
1761 else
1762 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1763 (*image)->filter,(*image)->blur,exception);
1764 break;
1765 }
1766 if (LocaleCompare("gravity",option+1) == 0)
1767 {
1768 if (*option == '+')
1769 {
1770 draw_info->gravity=UndefinedGravity;
1771 break;
1772 }
1773 draw_info->gravity=(GravityType) ParseCommandOption(
1774 MagickGravityOptions,MagickFalse,argv[i+1]);
1775 break;
1776 }
1777 break;
1778 }
1779 case 'h':
1780 {
1781 if (LocaleCompare("highlight-color",option+1) == 0)
1782 {
1783 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1784 break;
1785 }
1786 break;
1787 }
1788 case 'i':
1789 {
1790 if (LocaleCompare("identify",option+1) == 0)
1791 {
1792 char
1793 *text;
1794
1795 (void) SyncImageSettings(mogrify_info,*image);
1796 if (format == (char *) NULL)
1797 {
1798 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1799 InheritException(exception,&(*image)->exception);
1800 break;
1801 }
1802 text=InterpretImageProperties(mogrify_info,*image,format);
1803 InheritException(exception,&(*image)->exception);
1804 if (text == (char *) NULL)
1805 break;
1806 (void) fputs(text,stdout);
1807 (void) fputc('\n',stdout);
1808 text=DestroyString(text);
1809 break;
1810 }
1811 if (LocaleCompare("implode",option+1) == 0)
1812 {
1813 /*
1814 Implode image.
1815 */
1816 (void) SyncImageSettings(mogrify_info,*image);
1817 (void) ParseGeometry(argv[i+1],&geometry_info);
1818 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1819 break;
1820 }
1821 if (LocaleCompare("interline-spacing",option+1) == 0)
1822 {
1823 if (*option == '+')
1824 (void) ParseGeometry("0",&geometry_info);
1825 else
1826 (void) ParseGeometry(argv[i+1],&geometry_info);
1827 draw_info->interline_spacing=geometry_info.rho;
1828 break;
1829 }
1830 if (LocaleCompare("interword-spacing",option+1) == 0)
1831 {
1832 if (*option == '+')
1833 (void) ParseGeometry("0",&geometry_info);
1834 else
1835 (void) ParseGeometry(argv[i+1],&geometry_info);
1836 draw_info->interword_spacing=geometry_info.rho;
1837 break;
1838 }
1839 break;
1840 }
1841 case 'k':
1842 {
1843 if (LocaleCompare("kerning",option+1) == 0)
1844 {
1845 if (*option == '+')
1846 (void) ParseGeometry("0",&geometry_info);
1847 else
1848 (void) ParseGeometry(argv[i+1],&geometry_info);
1849 draw_info->kerning=geometry_info.rho;
1850 break;
1851 }
1852 break;
1853 }
1854 case 'l':
1855 {
1856 if (LocaleCompare("lat",option+1) == 0)
1857 {
1858 /*
1859 Local adaptive threshold image.
1860 */
1861 (void) SyncImageSettings(mogrify_info,*image);
1862 flags=ParseGeometry(argv[i+1],&geometry_info);
1863 if ((flags & PercentValue) != 0)
1864 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1865 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1866 geometry_info.rho,(size_t) geometry_info.sigma,(ssize_t)
1867 geometry_info.xi,exception);
1868 break;
1869 }
1870 if (LocaleCompare("level",option+1) == 0)
1871 {
1872 MagickRealType
1873 black_point,
1874 gamma,
1875 white_point;
1876
1877 MagickStatusType
1878 flags;
1879
1880 /*
1881 Parse levels.
1882 */
1883 (void) SyncImageSettings(mogrify_info,*image);
1884 flags=ParseGeometry(argv[i+1],&geometry_info);
1885 black_point=geometry_info.rho;
1886 white_point=(MagickRealType) QuantumRange;
1887 if ((flags & SigmaValue) != 0)
1888 white_point=geometry_info.sigma;
1889 gamma=1.0;
1890 if ((flags & XiValue) != 0)
1891 gamma=geometry_info.xi;
1892 if ((flags & PercentValue) != 0)
1893 {
1894 black_point*=(MagickRealType) (QuantumRange/100.0);
1895 white_point*=(MagickRealType) (QuantumRange/100.0);
1896 }
1897 if ((flags & SigmaValue) == 0)
1898 white_point=(MagickRealType) QuantumRange-black_point;
1899 if ((*option == '+') || ((flags & AspectValue) != 0))
1900 (void) LevelizeImageChannel(*image,channel,black_point,
1901 white_point,gamma);
1902 else
1903 (void) LevelImageChannel(*image,channel,black_point,white_point,
1904 gamma);
1905 InheritException(exception,&(*image)->exception);
1906 break;
1907 }
1908 if (LocaleCompare("level-colors",option+1) == 0)
1909 {
1910 char
1911 token[MaxTextExtent];
1912
1913 const char
1914 *p;
1915
1916 MagickPixelPacket
1917 black_point,
1918 white_point;
1919
1920 p=(const char *) argv[i+1];
1921 GetMagickToken(p,&p,token); /* get black point color */
1922 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1923 (void) QueryMagickColor(token,&black_point,exception);
1924 else
1925 (void) QueryMagickColor("#000000",&black_point,exception);
1926 if (isalpha((int) token[0]) || (token[0] == '#'))
1927 GetMagickToken(p,&p,token);
1928 if (*token == '\0')
1929 white_point=black_point; /* set everything to that color */
1930 else
1931 {
1932 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1933 GetMagickToken(p,&p,token); /* Get white point color. */
1934 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1935 (void) QueryMagickColor(token,&white_point,exception);
1936 else
1937 (void) QueryMagickColor("#ffffff",&white_point,exception);
1938 }
1939 (void) LevelColorsImageChannel(*image,channel,&black_point,
1940 &white_point,*option == '+' ? MagickTrue : MagickFalse);
1941 break;
1942 }
1943 if (LocaleCompare("linear-stretch",option+1) == 0)
1944 {
1945 double
1946 black_point,
1947 white_point;
1948
1949 MagickStatusType
1950 flags;
1951
1952 (void) SyncImageSettings(mogrify_info,*image);
1953 flags=ParseGeometry(argv[i+1],&geometry_info);
1954 black_point=geometry_info.rho;
1955 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1956 if ((flags & SigmaValue) != 0)
1957 white_point=geometry_info.sigma;
1958 if ((flags & PercentValue) != 0)
1959 {
1960 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1961 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1962 }
1963 if ((flags & SigmaValue) == 0)
1964 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1965 black_point;
1966 (void) LinearStretchImage(*image,black_point,white_point);
1967 InheritException(exception,&(*image)->exception);
1968 break;
1969 }
1970 if (LocaleCompare("linewidth",option+1) == 0)
1971 {
cristyb51dff52011-05-19 16:55:47 +00001972 draw_info->stroke_width=LocaleToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001973 break;
1974 }
1975 if (LocaleCompare("liquid-rescale",option+1) == 0)
1976 {
1977 /*
1978 Liquid rescale image.
1979 */
1980 (void) SyncImageSettings(mogrify_info,*image);
1981 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1982 if ((flags & XValue) == 0)
1983 geometry.x=1;
1984 if ((flags & YValue) == 0)
1985 geometry.y=0;
1986 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1987 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1988 break;
1989 }
1990 if (LocaleCompare("lowlight-color",option+1) == 0)
1991 {
1992 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1993 break;
1994 }
1995 break;
1996 }
1997 case 'm':
1998 {
1999 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002000 {
cristy3ed852e2009-09-05 21:47:34 +00002001 Image
anthonydf8ebac2011-04-27 09:03:19 +00002002 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002003
anthonydf8ebac2011-04-27 09:03:19 +00002004 /*
2005 Transform image colors to match this set of colors.
2006 */
2007 (void) SyncImageSettings(mogrify_info,*image);
2008 if (*option == '+')
2009 break;
2010 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2011 if (remap_image == (Image *) NULL)
2012 break;
2013 (void) RemapImage(quantize_info,*image,remap_image);
2014 InheritException(exception,&(*image)->exception);
2015 remap_image=DestroyImage(remap_image);
2016 break;
2017 }
2018 if (LocaleCompare("mask",option+1) == 0)
2019 {
2020 Image
2021 *mask;
2022
2023 (void) SyncImageSettings(mogrify_info,*image);
2024 if (*option == '+')
2025 {
2026 /*
2027 Remove a mask.
2028 */
2029 (void) SetImageMask(*image,(Image *) NULL);
2030 InheritException(exception,&(*image)->exception);
2031 break;
2032 }
2033 /*
2034 Set the image mask.
2035 */
2036 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2037 if (mask == (Image *) NULL)
2038 break;
2039 (void) SetImageMask(*image,mask);
2040 mask=DestroyImage(mask);
2041 InheritException(exception,&(*image)->exception);
2042 break;
2043 }
2044 if (LocaleCompare("matte",option+1) == 0)
2045 {
2046 (void) SetImageAlphaChannel(*image,(*option == '-') ?
2047 SetAlphaChannel : DeactivateAlphaChannel );
2048 InheritException(exception,&(*image)->exception);
2049 break;
2050 }
2051 if (LocaleCompare("median",option+1) == 0)
2052 {
2053 /*
2054 Median filter image.
2055 */
2056 (void) SyncImageSettings(mogrify_info,*image);
2057 (void) ParseGeometry(argv[i+1],&geometry_info);
2058 mogrify_image=StatisticImageChannel(*image,channel,MedianStatistic,
2059 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2060 break;
2061 }
2062 if (LocaleCompare("mode",option+1) == 0)
2063 {
2064 /*
2065 Mode image.
2066 */
2067 (void) SyncImageSettings(mogrify_info,*image);
2068 (void) ParseGeometry(argv[i+1],&geometry_info);
2069 mogrify_image=StatisticImageChannel(*image,channel,ModeStatistic,
2070 (size_t) geometry_info.rho,(size_t) geometry_info.rho,exception);
2071 break;
2072 }
2073 if (LocaleCompare("modulate",option+1) == 0)
2074 {
2075 (void) SyncImageSettings(mogrify_info,*image);
2076 (void) ModulateImage(*image,argv[i+1]);
2077 InheritException(exception,&(*image)->exception);
2078 break;
2079 }
2080 if (LocaleCompare("monitor",option+1) == 0)
2081 {
2082 if (*option == '+')
2083 {
2084 (void) SetImageProgressMonitor(*image,
2085 (MagickProgressMonitor) NULL,(void *) NULL);
2086 break;
2087 }
2088 (void) SetImageProgressMonitor(*image,MonitorProgress,
2089 (void *) NULL);
2090 break;
2091 }
2092 if (LocaleCompare("monochrome",option+1) == 0)
2093 {
2094 (void) SyncImageSettings(mogrify_info,*image);
2095 (void) SetImageType(*image,BilevelType);
2096 InheritException(exception,&(*image)->exception);
2097 break;
2098 }
2099 if (LocaleCompare("morphology",option+1) == 0)
2100 {
2101 char
2102 token[MaxTextExtent];
2103
2104 const char
2105 *p;
2106
2107 KernelInfo
2108 *kernel;
2109
2110 MorphologyMethod
2111 method;
2112
2113 ssize_t
2114 iterations;
2115
2116 /*
2117 Morphological Image Operation
2118 */
2119 (void) SyncImageSettings(mogrify_info,*image);
2120 p=argv[i+1];
2121 GetMagickToken(p,&p,token);
2122 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2123 MagickFalse,token);
2124 iterations=1L;
2125 GetMagickToken(p,&p,token);
2126 if ((*p == ':') || (*p == ','))
2127 GetMagickToken(p,&p,token);
2128 if ((*p != '\0'))
2129 iterations=(ssize_t) StringToLong(p);
2130 kernel=AcquireKernelInfo(argv[i+2]);
2131 if (kernel == (KernelInfo *) NULL)
2132 {
2133 (void) ThrowMagickException(exception,GetMagickModule(),
2134 OptionError,"UnabletoParseKernel","morphology");
2135 status=MagickFalse;
2136 break;
2137 }
2138 mogrify_image=MorphologyImageChannel(*image,channel,method,
2139 iterations,kernel,exception);
2140 kernel=DestroyKernelInfo(kernel);
2141 break;
2142 }
2143 if (LocaleCompare("motion-blur",option+1) == 0)
2144 {
2145 /*
2146 Motion blur image.
2147 */
2148 (void) SyncImageSettings(mogrify_info,*image);
2149 flags=ParseGeometry(argv[i+1],&geometry_info);
2150 if ((flags & SigmaValue) == 0)
2151 geometry_info.sigma=1.0;
2152 mogrify_image=MotionBlurImageChannel(*image,channel,
2153 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2154 break;
2155 }
2156 break;
2157 }
2158 case 'n':
2159 {
2160 if (LocaleCompare("negate",option+1) == 0)
2161 {
2162 (void) SyncImageSettings(mogrify_info,*image);
2163 (void) NegateImageChannel(*image,channel,*option == '+' ?
2164 MagickTrue : MagickFalse);
2165 InheritException(exception,&(*image)->exception);
2166 break;
2167 }
2168 if (LocaleCompare("noise",option+1) == 0)
2169 {
2170 (void) SyncImageSettings(mogrify_info,*image);
2171 if (*option == '-')
2172 {
2173 (void) ParseGeometry(argv[i+1],&geometry_info);
2174 mogrify_image=StatisticImageChannel(*image,channel,
2175 NonpeakStatistic,(size_t) geometry_info.rho,(size_t)
2176 geometry_info.rho,exception);
2177 }
2178 else
2179 {
2180 NoiseType
2181 noise;
2182
2183 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2184 MagickFalse,argv[i+1]);
2185 mogrify_image=AddNoiseImageChannel(*image,channel,noise,
2186 exception);
2187 }
2188 break;
2189 }
2190 if (LocaleCompare("normalize",option+1) == 0)
2191 {
2192 (void) SyncImageSettings(mogrify_info,*image);
2193 (void) NormalizeImageChannel(*image,channel);
2194 InheritException(exception,&(*image)->exception);
2195 break;
2196 }
2197 break;
2198 }
2199 case 'o':
2200 {
2201 if (LocaleCompare("opaque",option+1) == 0)
2202 {
2203 MagickPixelPacket
2204 target;
2205
2206 (void) SyncImageSettings(mogrify_info,*image);
2207 (void) QueryMagickColor(argv[i+1],&target,exception);
2208 (void) OpaquePaintImageChannel(*image,channel,&target,&fill,
2209 *option == '-' ? MagickFalse : MagickTrue);
2210 break;
2211 }
2212 if (LocaleCompare("ordered-dither",option+1) == 0)
2213 {
2214 (void) SyncImageSettings(mogrify_info,*image);
2215 (void) OrderedPosterizeImageChannel(*image,channel,argv[i+1],
2216 exception);
2217 break;
2218 }
2219 break;
2220 }
2221 case 'p':
2222 {
2223 if (LocaleCompare("paint",option+1) == 0)
2224 {
anthonydf8ebac2011-04-27 09:03:19 +00002225 (void) SyncImageSettings(mogrify_info,*image);
2226 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002227 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002228 break;
2229 }
2230 if (LocaleCompare("pen",option+1) == 0)
2231 {
2232 if (*option == '+')
2233 {
2234 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2235 break;
2236 }
2237 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2238 break;
2239 }
2240 if (LocaleCompare("pointsize",option+1) == 0)
2241 {
2242 if (*option == '+')
2243 (void) ParseGeometry("12",&geometry_info);
2244 else
2245 (void) ParseGeometry(argv[i+1],&geometry_info);
2246 draw_info->pointsize=geometry_info.rho;
2247 break;
2248 }
2249 if (LocaleCompare("polaroid",option+1) == 0)
2250 {
2251 double
2252 angle;
2253
2254 RandomInfo
2255 *random_info;
2256
2257 /*
2258 Simulate a Polaroid picture.
2259 */
2260 (void) SyncImageSettings(mogrify_info,*image);
2261 random_info=AcquireRandomInfo();
2262 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2263 random_info=DestroyRandomInfo(random_info);
2264 if (*option == '-')
2265 {
2266 SetGeometryInfo(&geometry_info);
2267 flags=ParseGeometry(argv[i+1],&geometry_info);
2268 angle=geometry_info.rho;
2269 }
2270 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2271 break;
2272 }
2273 if (LocaleCompare("posterize",option+1) == 0)
2274 {
2275 /*
2276 Posterize image.
2277 */
2278 (void) SyncImageSettings(mogrify_info,*image);
2279 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2280 quantize_info->dither);
2281 InheritException(exception,&(*image)->exception);
2282 break;
2283 }
2284 if (LocaleCompare("preview",option+1) == 0)
2285 {
2286 PreviewType
2287 preview_type;
2288
2289 /*
2290 Preview image.
2291 */
2292 (void) SyncImageSettings(mogrify_info,*image);
2293 if (*option == '+')
2294 preview_type=UndefinedPreview;
2295 else
2296 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2297 MagickFalse,argv[i+1]);
2298 mogrify_image=PreviewImage(*image,preview_type,exception);
2299 break;
2300 }
2301 if (LocaleCompare("profile",option+1) == 0)
2302 {
2303 const char
2304 *name;
2305
2306 const StringInfo
2307 *profile;
2308
2309 Image
2310 *profile_image;
2311
2312 ImageInfo
2313 *profile_info;
2314
2315 (void) SyncImageSettings(mogrify_info,*image);
2316 if (*option == '+')
2317 {
2318 /*
2319 Remove a profile from the image.
2320 */
2321 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2322 NULL,0,MagickTrue);
2323 InheritException(exception,&(*image)->exception);
2324 break;
2325 }
2326 /*
2327 Associate a profile with the image.
2328 */
2329 profile_info=CloneImageInfo(mogrify_info);
2330 profile=GetImageProfile(*image,"iptc");
2331 if (profile != (StringInfo *) NULL)
2332 profile_info->profile=(void *) CloneStringInfo(profile);
2333 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2334 profile_info=DestroyImageInfo(profile_info);
2335 if (profile_image == (Image *) NULL)
2336 {
2337 StringInfo
2338 *profile;
2339
2340 profile_info=CloneImageInfo(mogrify_info);
2341 (void) CopyMagickString(profile_info->filename,argv[i+1],
2342 MaxTextExtent);
2343 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2344 if (profile != (StringInfo *) NULL)
2345 {
2346 (void) ProfileImage(*image,profile_info->magick,
2347 GetStringInfoDatum(profile),(size_t)
2348 GetStringInfoLength(profile),MagickFalse);
2349 profile=DestroyStringInfo(profile);
2350 }
2351 profile_info=DestroyImageInfo(profile_info);
2352 break;
2353 }
2354 ResetImageProfileIterator(profile_image);
2355 name=GetNextImageProfile(profile_image);
2356 while (name != (const char *) NULL)
2357 {
2358 profile=GetImageProfile(profile_image,name);
2359 if (profile != (StringInfo *) NULL)
2360 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2361 (size_t) GetStringInfoLength(profile),MagickFalse);
2362 name=GetNextImageProfile(profile_image);
2363 }
2364 profile_image=DestroyImage(profile_image);
2365 break;
2366 }
2367 break;
2368 }
2369 case 'q':
2370 {
2371 if (LocaleCompare("quantize",option+1) == 0)
2372 {
2373 if (*option == '+')
2374 {
2375 quantize_info->colorspace=UndefinedColorspace;
2376 break;
2377 }
2378 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2379 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2380 break;
2381 }
2382 break;
2383 }
2384 case 'r':
2385 {
2386 if (LocaleCompare("radial-blur",option+1) == 0)
2387 {
2388 /*
2389 Radial blur image.
2390 */
2391 (void) SyncImageSettings(mogrify_info,*image);
2392 mogrify_image=RadialBlurImageChannel(*image,channel,
cristyb51dff52011-05-19 16:55:47 +00002393 LocaleToDouble(argv[i+1],(char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002394 break;
2395 }
2396 if (LocaleCompare("raise",option+1) == 0)
2397 {
2398 /*
2399 Surround image with a raise of solid color.
2400 */
2401 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2402 if ((flags & SigmaValue) == 0)
2403 geometry.height=geometry.width;
2404 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2405 MagickFalse);
2406 InheritException(exception,&(*image)->exception);
2407 break;
2408 }
2409 if (LocaleCompare("random-threshold",option+1) == 0)
2410 {
2411 /*
2412 Threshold image.
2413 */
2414 (void) SyncImageSettings(mogrify_info,*image);
2415 (void) RandomThresholdImageChannel(*image,channel,argv[i+1],
2416 exception);
2417 break;
2418 }
2419 if (LocaleCompare("recolor",option+1) == 0)
2420 {
2421 KernelInfo
2422 *kernel;
2423
2424 (void) SyncImageSettings(mogrify_info,*image);
2425 kernel=AcquireKernelInfo(argv[i+1]);
2426 if (kernel == (KernelInfo *) NULL)
2427 break;
2428 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2429 kernel=DestroyKernelInfo(kernel);
2430 break;
2431 }
2432 if (LocaleCompare("region",option+1) == 0)
2433 {
2434 (void) SyncImageSettings(mogrify_info,*image);
2435 if (region_image != (Image *) NULL)
2436 {
2437 /*
2438 Composite region.
2439 */
2440 (void) CompositeImage(region_image,region_image->matte !=
2441 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2442 region_geometry.x,region_geometry.y);
2443 InheritException(exception,&region_image->exception);
2444 *image=DestroyImage(*image);
2445 *image=region_image;
2446 region_image = (Image *) NULL;
2447 }
2448 if (*option == '+')
2449 break;
2450 /*
2451 Apply transformations to a selected region of the image.
2452 */
cristy3ed852e2009-09-05 21:47:34 +00002453 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2454 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002455 mogrify_image=CropImage(*image,&region_geometry,exception);
2456 if (mogrify_image == (Image *) NULL)
2457 break;
2458 region_image=(*image);
2459 *image=mogrify_image;
2460 mogrify_image=(Image *) NULL;
2461 break;
cristy3ed852e2009-09-05 21:47:34 +00002462 }
anthonydf8ebac2011-04-27 09:03:19 +00002463 if (LocaleCompare("render",option+1) == 0)
2464 {
2465 (void) SyncImageSettings(mogrify_info,*image);
2466 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2467 break;
2468 }
2469 if (LocaleCompare("remap",option+1) == 0)
2470 {
2471 Image
2472 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002473
anthonydf8ebac2011-04-27 09:03:19 +00002474 /*
2475 Transform image colors to match this set of colors.
2476 */
2477 (void) SyncImageSettings(mogrify_info,*image);
2478 if (*option == '+')
2479 break;
2480 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2481 if (remap_image == (Image *) NULL)
2482 break;
2483 (void) RemapImage(quantize_info,*image,remap_image);
2484 InheritException(exception,&(*image)->exception);
2485 remap_image=DestroyImage(remap_image);
2486 break;
2487 }
2488 if (LocaleCompare("repage",option+1) == 0)
2489 {
2490 if (*option == '+')
2491 {
2492 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2493 break;
2494 }
2495 (void) ResetImagePage(*image,argv[i+1]);
2496 InheritException(exception,&(*image)->exception);
2497 break;
2498 }
2499 if (LocaleCompare("resample",option+1) == 0)
2500 {
2501 /*
2502 Resample image.
2503 */
2504 (void) SyncImageSettings(mogrify_info,*image);
2505 flags=ParseGeometry(argv[i+1],&geometry_info);
2506 if ((flags & SigmaValue) == 0)
2507 geometry_info.sigma=geometry_info.rho;
2508 mogrify_image=ResampleImage(*image,geometry_info.rho,
2509 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2510 break;
2511 }
2512 if (LocaleCompare("resize",option+1) == 0)
2513 {
2514 /*
2515 Resize image.
2516 */
2517 (void) SyncImageSettings(mogrify_info,*image);
2518 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2519 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2520 (*image)->filter,(*image)->blur,exception);
2521 break;
2522 }
2523 if (LocaleCompare("roll",option+1) == 0)
2524 {
2525 /*
2526 Roll image.
2527 */
2528 (void) SyncImageSettings(mogrify_info,*image);
2529 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2530 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2531 break;
2532 }
2533 if (LocaleCompare("rotate",option+1) == 0)
2534 {
2535 char
2536 *geometry;
2537
2538 /*
2539 Check for conditional image rotation.
2540 */
2541 (void) SyncImageSettings(mogrify_info,*image);
2542 if (strchr(argv[i+1],'>') != (char *) NULL)
2543 if ((*image)->columns <= (*image)->rows)
2544 break;
2545 if (strchr(argv[i+1],'<') != (char *) NULL)
2546 if ((*image)->columns >= (*image)->rows)
2547 break;
2548 /*
2549 Rotate image.
2550 */
2551 geometry=ConstantString(argv[i+1]);
2552 (void) SubstituteString(&geometry,">","");
2553 (void) SubstituteString(&geometry,"<","");
2554 (void) ParseGeometry(geometry,&geometry_info);
2555 geometry=DestroyString(geometry);
2556 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2557 break;
2558 }
2559 break;
2560 }
2561 case 's':
2562 {
2563 if (LocaleCompare("sample",option+1) == 0)
2564 {
2565 /*
2566 Sample image with pixel replication.
2567 */
2568 (void) SyncImageSettings(mogrify_info,*image);
2569 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2570 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2571 exception);
2572 break;
2573 }
2574 if (LocaleCompare("scale",option+1) == 0)
2575 {
2576 /*
2577 Resize image.
2578 */
2579 (void) SyncImageSettings(mogrify_info,*image);
2580 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2581 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2582 exception);
2583 break;
2584 }
2585 if (LocaleCompare("selective-blur",option+1) == 0)
2586 {
2587 /*
2588 Selectively blur pixels within a contrast threshold.
2589 */
2590 (void) SyncImageSettings(mogrify_info,*image);
2591 flags=ParseGeometry(argv[i+1],&geometry_info);
2592 if ((flags & PercentValue) != 0)
2593 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2594 mogrify_image=SelectiveBlurImageChannel(*image,channel,
2595 geometry_info.rho,geometry_info.sigma,geometry_info.xi,exception);
2596 break;
2597 }
2598 if (LocaleCompare("separate",option+1) == 0)
2599 {
2600 /*
2601 Break channels into separate images.
2602 WARNING: This can generate multiple images!
2603 */
2604 (void) SyncImageSettings(mogrify_info,*image);
2605 mogrify_image=SeparateImages(*image,channel,exception);
2606 break;
2607 }
2608 if (LocaleCompare("sepia-tone",option+1) == 0)
2609 {
2610 double
2611 threshold;
2612
2613 /*
2614 Sepia-tone image.
2615 */
2616 (void) SyncImageSettings(mogrify_info,*image);
2617 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2618 mogrify_image=SepiaToneImage(*image,threshold,exception);
2619 break;
2620 }
2621 if (LocaleCompare("segment",option+1) == 0)
2622 {
2623 /*
2624 Segment image.
2625 */
2626 (void) SyncImageSettings(mogrify_info,*image);
2627 flags=ParseGeometry(argv[i+1],&geometry_info);
2628 if ((flags & SigmaValue) == 0)
2629 geometry_info.sigma=1.0;
2630 (void) SegmentImage(*image,(*image)->colorspace,
2631 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2632 InheritException(exception,&(*image)->exception);
2633 break;
2634 }
2635 if (LocaleCompare("set",option+1) == 0)
2636 {
2637 char
2638 *value;
2639
2640 /*
2641 Set image option.
2642 */
2643 if (*option == '+')
2644 {
2645 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2646 (void) DeleteImageRegistry(argv[i+1]+9);
2647 else
2648 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2649 {
2650 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2651 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2652 }
2653 else
2654 (void) DeleteImageProperty(*image,argv[i+1]);
2655 break;
2656 }
2657 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2658 if (value == (char *) NULL)
2659 break;
2660 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2661 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2662 exception);
2663 else
2664 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2665 {
2666 (void) SetImageOption(image_info,argv[i+1]+7,value);
2667 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2668 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2669 }
2670 else
2671 (void) SetImageProperty(*image,argv[i+1],value);
2672 value=DestroyString(value);
2673 break;
2674 }
2675 if (LocaleCompare("shade",option+1) == 0)
2676 {
2677 /*
2678 Shade image.
2679 */
2680 (void) SyncImageSettings(mogrify_info,*image);
2681 flags=ParseGeometry(argv[i+1],&geometry_info);
2682 if ((flags & SigmaValue) == 0)
2683 geometry_info.sigma=1.0;
2684 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2685 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2686 break;
2687 }
2688 if (LocaleCompare("shadow",option+1) == 0)
2689 {
2690 /*
2691 Shadow image.
2692 */
2693 (void) SyncImageSettings(mogrify_info,*image);
2694 flags=ParseGeometry(argv[i+1],&geometry_info);
2695 if ((flags & SigmaValue) == 0)
2696 geometry_info.sigma=1.0;
2697 if ((flags & XiValue) == 0)
2698 geometry_info.xi=4.0;
2699 if ((flags & PsiValue) == 0)
2700 geometry_info.psi=4.0;
2701 mogrify_image=ShadowImage(*image,geometry_info.rho,
2702 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2703 ceil(geometry_info.psi-0.5),exception);
2704 break;
2705 }
2706 if (LocaleCompare("sharpen",option+1) == 0)
2707 {
2708 /*
2709 Sharpen image.
2710 */
2711 (void) SyncImageSettings(mogrify_info,*image);
2712 flags=ParseGeometry(argv[i+1],&geometry_info);
2713 if ((flags & SigmaValue) == 0)
2714 geometry_info.sigma=1.0;
2715 mogrify_image=SharpenImageChannel(*image,channel,geometry_info.rho,
2716 geometry_info.sigma,exception);
2717 break;
2718 }
2719 if (LocaleCompare("shave",option+1) == 0)
2720 {
2721 /*
2722 Shave the image edges.
2723 */
2724 (void) SyncImageSettings(mogrify_info,*image);
2725 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2726 mogrify_image=ShaveImage(*image,&geometry,exception);
2727 break;
2728 }
2729 if (LocaleCompare("shear",option+1) == 0)
2730 {
2731 /*
2732 Shear image.
2733 */
2734 (void) SyncImageSettings(mogrify_info,*image);
2735 flags=ParseGeometry(argv[i+1],&geometry_info);
2736 if ((flags & SigmaValue) == 0)
2737 geometry_info.sigma=geometry_info.rho;
2738 mogrify_image=ShearImage(*image,geometry_info.rho,
2739 geometry_info.sigma,exception);
2740 break;
2741 }
2742 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2743 {
2744 /*
2745 Sigmoidal non-linearity contrast control.
2746 */
2747 (void) SyncImageSettings(mogrify_info,*image);
2748 flags=ParseGeometry(argv[i+1],&geometry_info);
2749 if ((flags & SigmaValue) == 0)
2750 geometry_info.sigma=(double) QuantumRange/2.0;
2751 if ((flags & PercentValue) != 0)
2752 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2753 100.0;
2754 (void) SigmoidalContrastImageChannel(*image,channel,
2755 (*option == '-') ? MagickTrue : MagickFalse,geometry_info.rho,
2756 geometry_info.sigma);
2757 InheritException(exception,&(*image)->exception);
2758 break;
2759 }
2760 if (LocaleCompare("sketch",option+1) == 0)
2761 {
2762 /*
2763 Sketch image.
2764 */
2765 (void) SyncImageSettings(mogrify_info,*image);
2766 flags=ParseGeometry(argv[i+1],&geometry_info);
2767 if ((flags & SigmaValue) == 0)
2768 geometry_info.sigma=1.0;
2769 mogrify_image=SketchImage(*image,geometry_info.rho,
2770 geometry_info.sigma,geometry_info.xi,exception);
2771 break;
2772 }
2773 if (LocaleCompare("solarize",option+1) == 0)
2774 {
2775 double
2776 threshold;
2777
2778 (void) SyncImageSettings(mogrify_info,*image);
2779 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2780 (void) SolarizeImage(*image,threshold);
2781 InheritException(exception,&(*image)->exception);
2782 break;
2783 }
2784 if (LocaleCompare("sparse-color",option+1) == 0)
2785 {
2786 SparseColorMethod
2787 method;
2788
2789 char
2790 *arguments;
2791
2792 /*
2793 Sparse Color Interpolated Gradient
2794 */
2795 (void) SyncImageSettings(mogrify_info,*image);
2796 method=(SparseColorMethod) ParseCommandOption(
2797 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2798 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2799 InheritException(exception,&(*image)->exception);
2800 if (arguments == (char *) NULL)
2801 break;
2802 mogrify_image=SparseColorOption(*image,channel,method,arguments,
2803 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2804 arguments=DestroyString(arguments);
2805 break;
2806 }
2807 if (LocaleCompare("splice",option+1) == 0)
2808 {
2809 /*
2810 Splice a solid color into the image.
2811 */
2812 (void) SyncImageSettings(mogrify_info,*image);
2813 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2814 mogrify_image=SpliceImage(*image,&geometry,exception);
2815 break;
2816 }
2817 if (LocaleCompare("spread",option+1) == 0)
2818 {
2819 /*
2820 Spread an image.
2821 */
2822 (void) SyncImageSettings(mogrify_info,*image);
2823 (void) ParseGeometry(argv[i+1],&geometry_info);
2824 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2825 break;
2826 }
2827 if (LocaleCompare("statistic",option+1) == 0)
2828 {
2829 StatisticType
2830 type;
2831
2832 (void) SyncImageSettings(mogrify_info,*image);
2833 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2834 MagickFalse,argv[i+1]);
2835 (void) ParseGeometry(argv[i+2],&geometry_info);
2836 mogrify_image=StatisticImageChannel(*image,channel,type,(size_t)
2837 geometry_info.rho,(size_t) geometry_info.sigma,exception);
2838 break;
2839 }
2840 if (LocaleCompare("stretch",option+1) == 0)
2841 {
2842 if (*option == '+')
2843 {
2844 draw_info->stretch=UndefinedStretch;
2845 break;
2846 }
2847 draw_info->stretch=(StretchType) ParseCommandOption(
2848 MagickStretchOptions,MagickFalse,argv[i+1]);
2849 break;
2850 }
2851 if (LocaleCompare("strip",option+1) == 0)
2852 {
2853 /*
2854 Strip image of profiles and comments.
2855 */
2856 (void) SyncImageSettings(mogrify_info,*image);
2857 (void) StripImage(*image);
2858 InheritException(exception,&(*image)->exception);
2859 break;
2860 }
2861 if (LocaleCompare("stroke",option+1) == 0)
2862 {
2863 ExceptionInfo
2864 *sans;
2865
2866 if (*option == '+')
2867 {
2868 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2869 if (draw_info->stroke_pattern != (Image *) NULL)
2870 draw_info->stroke_pattern=DestroyImage(
2871 draw_info->stroke_pattern);
2872 break;
2873 }
2874 sans=AcquireExceptionInfo();
2875 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2876 sans=DestroyExceptionInfo(sans);
2877 if (status == MagickFalse)
2878 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2879 exception);
2880 break;
2881 }
2882 if (LocaleCompare("strokewidth",option+1) == 0)
2883 {
cristyb51dff52011-05-19 16:55:47 +00002884 draw_info->stroke_width=LocaleToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002885 break;
2886 }
2887 if (LocaleCompare("style",option+1) == 0)
2888 {
2889 if (*option == '+')
2890 {
2891 draw_info->style=UndefinedStyle;
2892 break;
2893 }
2894 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2895 MagickFalse,argv[i+1]);
2896 break;
2897 }
2898 if (LocaleCompare("swirl",option+1) == 0)
2899 {
2900 /*
2901 Swirl image.
2902 */
2903 (void) SyncImageSettings(mogrify_info,*image);
2904 (void) ParseGeometry(argv[i+1],&geometry_info);
2905 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2906 break;
2907 }
2908 break;
2909 }
2910 case 't':
2911 {
2912 if (LocaleCompare("threshold",option+1) == 0)
2913 {
2914 double
2915 threshold;
2916
2917 /*
2918 Threshold image.
2919 */
2920 (void) SyncImageSettings(mogrify_info,*image);
2921 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002922 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002923 else
2924 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2925 (void) BilevelImageChannel(*image,channel,threshold);
2926 InheritException(exception,&(*image)->exception);
2927 break;
2928 }
2929 if (LocaleCompare("thumbnail",option+1) == 0)
2930 {
2931 /*
2932 Thumbnail image.
2933 */
2934 (void) SyncImageSettings(mogrify_info,*image);
2935 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2936 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2937 exception);
2938 break;
2939 }
2940 if (LocaleCompare("tile",option+1) == 0)
2941 {
2942 if (*option == '+')
2943 {
2944 if (draw_info->fill_pattern != (Image *) NULL)
2945 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2946 break;
2947 }
2948 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2949 exception);
2950 break;
2951 }
2952 if (LocaleCompare("tint",option+1) == 0)
2953 {
2954 /*
2955 Tint the image.
2956 */
2957 (void) SyncImageSettings(mogrify_info,*image);
2958 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2959 break;
2960 }
2961 if (LocaleCompare("transform",option+1) == 0)
2962 {
2963 /*
2964 Affine transform image.
2965 */
2966 (void) SyncImageSettings(mogrify_info,*image);
2967 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2968 exception);
2969 break;
2970 }
2971 if (LocaleCompare("transparent",option+1) == 0)
2972 {
2973 MagickPixelPacket
2974 target;
2975
2976 (void) SyncImageSettings(mogrify_info,*image);
2977 (void) QueryMagickColor(argv[i+1],&target,exception);
2978 (void) TransparentPaintImage(*image,&target,(Quantum)
2979 TransparentOpacity,*option == '-' ? MagickFalse : MagickTrue);
2980 InheritException(exception,&(*image)->exception);
2981 break;
2982 }
2983 if (LocaleCompare("transpose",option+1) == 0)
2984 {
2985 /*
2986 Transpose image scanlines.
2987 */
2988 (void) SyncImageSettings(mogrify_info,*image);
2989 mogrify_image=TransposeImage(*image,exception);
2990 break;
2991 }
2992 if (LocaleCompare("transverse",option+1) == 0)
2993 {
2994 /*
2995 Transverse image scanlines.
2996 */
2997 (void) SyncImageSettings(mogrify_info,*image);
2998 mogrify_image=TransverseImage(*image,exception);
2999 break;
3000 }
3001 if (LocaleCompare("treedepth",option+1) == 0)
3002 {
3003 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3004 break;
3005 }
3006 if (LocaleCompare("trim",option+1) == 0)
3007 {
3008 /*
3009 Trim image.
3010 */
3011 (void) SyncImageSettings(mogrify_info,*image);
3012 mogrify_image=TrimImage(*image,exception);
3013 break;
3014 }
3015 if (LocaleCompare("type",option+1) == 0)
3016 {
3017 ImageType
3018 type;
3019
3020 (void) SyncImageSettings(mogrify_info,*image);
3021 if (*option == '+')
3022 type=UndefinedType;
3023 else
3024 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3025 argv[i+1]);
3026 (*image)->type=UndefinedType;
3027 (void) SetImageType(*image,type);
3028 InheritException(exception,&(*image)->exception);
3029 break;
3030 }
3031 break;
3032 }
3033 case 'u':
3034 {
3035 if (LocaleCompare("undercolor",option+1) == 0)
3036 {
3037 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3038 exception);
3039 break;
3040 }
3041 if (LocaleCompare("unique",option+1) == 0)
3042 {
3043 if (*option == '+')
3044 {
3045 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3046 break;
3047 }
3048 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3049 (void) SetImageArtifact(*image,"verbose","true");
3050 break;
3051 }
3052 if (LocaleCompare("unique-colors",option+1) == 0)
3053 {
3054 /*
3055 Unique image colors.
3056 */
3057 (void) SyncImageSettings(mogrify_info,*image);
3058 mogrify_image=UniqueImageColors(*image,exception);
3059 break;
3060 }
3061 if (LocaleCompare("unsharp",option+1) == 0)
3062 {
3063 /*
3064 Unsharp mask image.
3065 */
3066 (void) SyncImageSettings(mogrify_info,*image);
3067 flags=ParseGeometry(argv[i+1],&geometry_info);
3068 if ((flags & SigmaValue) == 0)
3069 geometry_info.sigma=1.0;
3070 if ((flags & XiValue) == 0)
3071 geometry_info.xi=1.0;
3072 if ((flags & PsiValue) == 0)
3073 geometry_info.psi=0.05;
3074 mogrify_image=UnsharpMaskImageChannel(*image,channel,
3075 geometry_info.rho,geometry_info.sigma,geometry_info.xi,
3076 geometry_info.psi,exception);
3077 break;
3078 }
3079 break;
3080 }
3081 case 'v':
3082 {
3083 if (LocaleCompare("verbose",option+1) == 0)
3084 {
3085 (void) SetImageArtifact(*image,option+1,
3086 *option == '+' ? "false" : "true");
3087 break;
3088 }
3089 if (LocaleCompare("vignette",option+1) == 0)
3090 {
3091 /*
3092 Vignette image.
3093 */
3094 (void) SyncImageSettings(mogrify_info,*image);
3095 flags=ParseGeometry(argv[i+1],&geometry_info);
3096 if ((flags & SigmaValue) == 0)
3097 geometry_info.sigma=1.0;
3098 if ((flags & XiValue) == 0)
3099 geometry_info.xi=0.1*(*image)->columns;
3100 if ((flags & PsiValue) == 0)
3101 geometry_info.psi=0.1*(*image)->rows;
3102 mogrify_image=VignetteImage(*image,geometry_info.rho,
3103 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3104 ceil(geometry_info.psi-0.5),exception);
3105 break;
3106 }
3107 if (LocaleCompare("virtual-pixel",option+1) == 0)
3108 {
3109 if (*option == '+')
3110 {
3111 (void) SetImageVirtualPixelMethod(*image,
3112 UndefinedVirtualPixelMethod);
3113 break;
3114 }
3115 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3116 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3117 argv[i+1]));
3118 break;
3119 }
3120 break;
3121 }
3122 case 'w':
3123 {
3124 if (LocaleCompare("wave",option+1) == 0)
3125 {
3126 /*
3127 Wave image.
3128 */
3129 (void) SyncImageSettings(mogrify_info,*image);
3130 flags=ParseGeometry(argv[i+1],&geometry_info);
3131 if ((flags & SigmaValue) == 0)
3132 geometry_info.sigma=1.0;
3133 mogrify_image=WaveImage(*image,geometry_info.rho,
3134 geometry_info.sigma,exception);
3135 break;
3136 }
3137 if (LocaleCompare("weight",option+1) == 0)
3138 {
3139 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3140 if (LocaleCompare(argv[i+1],"all") == 0)
3141 draw_info->weight=0;
3142 if (LocaleCompare(argv[i+1],"bold") == 0)
3143 draw_info->weight=700;
3144 if (LocaleCompare(argv[i+1],"bolder") == 0)
3145 if (draw_info->weight <= 800)
3146 draw_info->weight+=100;
3147 if (LocaleCompare(argv[i+1],"lighter") == 0)
3148 if (draw_info->weight >= 100)
3149 draw_info->weight-=100;
3150 if (LocaleCompare(argv[i+1],"normal") == 0)
3151 draw_info->weight=400;
3152 break;
3153 }
3154 if (LocaleCompare("white-threshold",option+1) == 0)
3155 {
3156 /*
3157 White threshold image.
3158 */
3159 (void) SyncImageSettings(mogrify_info,*image);
3160 (void) WhiteThresholdImageChannel(*image,channel,argv[i+1],
3161 exception);
3162 InheritException(exception,&(*image)->exception);
3163 break;
3164 }
3165 break;
3166 }
3167 default:
3168 break;
3169 }
3170 /*
3171 Replace current image with any image that was generated
3172 */
3173 if (mogrify_image != (Image *) NULL)
3174 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003175 i+=count;
3176 }
3177 if (region_image != (Image *) NULL)
3178 {
anthonydf8ebac2011-04-27 09:03:19 +00003179 /*
3180 Composite transformed region onto image.
3181 */
cristy6b3da3a2010-06-20 02:21:46 +00003182 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003183 (void) CompositeImage(region_image,region_image->matte !=
3184 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
anthonye9c27192011-03-27 08:07:06 +00003185 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003186 InheritException(exception,&region_image->exception);
3187 *image=DestroyImage(*image);
3188 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003189 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003190 }
3191 /*
3192 Free resources.
3193 */
anthonydf8ebac2011-04-27 09:03:19 +00003194 quantize_info=DestroyQuantizeInfo(quantize_info);
3195 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003196 mogrify_info=DestroyImageInfo(mogrify_info);
cristy72988482011-03-29 16:34:38 +00003197 status=(*image)->exception.severity == UndefinedException ? 1 : 0;
3198 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003199}
3200
3201/*
3202%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3203% %
3204% %
3205% %
cristy5063d812010-10-19 16:28:10 +00003206+ M o g r i f y I m a g e C o m m a n d %
cristy3ed852e2009-09-05 21:47:34 +00003207% %
3208% %
3209% %
3210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3211%
3212% MogrifyImageCommand() transforms an image or a sequence of images. These
3213% transforms include image scaling, image rotation, color reduction, and
3214% others. The transmogrified image overwrites the original image.
3215%
3216% The format of the MogrifyImageCommand method is:
3217%
3218% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3219% const char **argv,char **metadata,ExceptionInfo *exception)
3220%
3221% A description of each parameter follows:
3222%
3223% o image_info: the image info.
3224%
3225% o argc: the number of elements in the argument vector.
3226%
3227% o argv: A text array containing the command line arguments.
3228%
3229% o metadata: any metadata is returned here.
3230%
3231% o exception: return any errors or warnings in this structure.
3232%
3233*/
3234
3235static MagickBooleanType MogrifyUsage(void)
3236{
3237 static const char
3238 *miscellaneous[]=
3239 {
3240 "-debug events display copious debugging information",
3241 "-help print program options",
3242 "-list type print a list of supported option arguments",
3243 "-log format format of debugging information",
3244 "-version print version information",
3245 (char *) NULL
3246 },
3247 *operators[]=
3248 {
3249 "-adaptive-blur geometry",
3250 " adaptively blur pixels; decrease effect near edges",
3251 "-adaptive-resize geometry",
3252 " adaptively resize image using 'mesh' interpolation",
3253 "-adaptive-sharpen geometry",
3254 " adaptively sharpen pixels; increase effect near edges",
3255 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3256 " transparent, extract, background, or shape",
3257 "-annotate geometry text",
3258 " annotate the image with text",
3259 "-auto-gamma automagically adjust gamma level of image",
3260 "-auto-level automagically adjust color levels of image",
3261 "-auto-orient automagically orient (rotate) image",
3262 "-bench iterations measure performance",
3263 "-black-threshold value",
3264 " force all pixels below the threshold into black",
3265 "-blue-shift simulate a scene at nighttime in the moonlight",
3266 "-blur geometry reduce image noise and reduce detail levels",
3267 "-border geometry surround image with a border of color",
3268 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003269 "-brightness-contrast geometry",
3270 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003271 "-cdl filename color correct with a color decision list",
3272 "-charcoal radius simulate a charcoal drawing",
3273 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003274 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003275 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003276 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003277 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003278 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003279 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003280 "-contrast enhance or reduce the image contrast",
3281 "-contrast-stretch geometry",
3282 " improve contrast by `stretching' the intensity range",
3283 "-convolve coefficients",
3284 " apply a convolution kernel to the image",
3285 "-cycle amount cycle the image colormap",
3286 "-decipher filename convert cipher pixels to plain pixels",
3287 "-deskew threshold straighten an image",
3288 "-despeckle reduce the speckles within an image",
3289 "-distort method args",
3290 " distort images according to given method ad args",
3291 "-draw string annotate the image with a graphic primitive",
3292 "-edge radius apply a filter to detect edges in the image",
3293 "-encipher filename convert plain pixels to cipher pixels",
3294 "-emboss radius emboss an image",
3295 "-enhance apply a digital filter to enhance a noisy image",
3296 "-equalize perform histogram equalization to an image",
3297 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003298 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003299 "-extent geometry set the image size",
3300 "-extract geometry extract area from image",
3301 "-fft implements the discrete Fourier transform (DFT)",
3302 "-flip flip image vertically",
3303 "-floodfill geometry color",
3304 " floodfill the image with color",
3305 "-flop flop image horizontally",
3306 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003307 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003308 " apply function over image values",
3309 "-gamma value level of gamma correction",
3310 "-gaussian-blur geometry",
3311 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003312 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003313 "-identify identify the format and characteristics of the image",
3314 "-ift implements the inverse discrete Fourier transform (DFT)",
3315 "-implode amount implode image pixels about the center",
3316 "-lat geometry local adaptive thresholding",
3317 "-layers method optimize, merge, or compare image layers",
3318 "-level value adjust the level of image contrast",
3319 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003320 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003321 "-linear-stretch geometry",
3322 " improve contrast by `stretching with saturation'",
3323 "-liquid-rescale geometry",
3324 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003325 "-median geometry apply a median filter to the image",
3326 "-mode geometry make each pixel the 'predominate color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003327 "-modulate value vary the brightness, saturation, and hue",
3328 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003329 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003330 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003331 "-motion-blur geometry",
3332 " simulate motion blur",
3333 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003334 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003335 "-normalize transform image to span the full range of colors",
3336 "-opaque color change this color to the fill color",
3337 "-ordered-dither NxN",
3338 " add a noise pattern to the image with specific",
3339 " amplitudes",
3340 "-paint radius simulate an oil painting",
3341 "-polaroid angle simulate a Polaroid picture",
3342 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003343 "-profile filename add, delete, or apply an image profile",
3344 "-quantize colorspace reduce colors in this colorspace",
3345 "-radial-blur angle radial blur the image",
3346 "-raise value lighten/darken image edges to create a 3-D effect",
3347 "-random-threshold low,high",
3348 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003349 "-region geometry apply options to a portion of the image",
3350 "-render render vector graphics",
3351 "-repage geometry size and location of an image canvas",
3352 "-resample geometry change the resolution of an image",
3353 "-resize geometry resize the image",
3354 "-roll geometry roll an image vertically or horizontally",
3355 "-rotate degrees apply Paeth rotation to the image",
3356 "-sample geometry scale image with pixel sampling",
3357 "-scale geometry scale the image",
3358 "-segment values segment an image",
3359 "-selective-blur geometry",
3360 " selectively blur pixels within a contrast threshold",
3361 "-sepia-tone threshold",
3362 " simulate a sepia-toned photo",
3363 "-set property value set an image property",
3364 "-shade degrees shade the image using a distant light source",
3365 "-shadow geometry simulate an image shadow",
3366 "-sharpen geometry sharpen the image",
3367 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003368 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003369 "-sigmoidal-contrast geometry",
3370 " increase the contrast without saturating highlights or shadows",
3371 "-sketch geometry simulate a pencil sketch",
3372 "-solarize threshold negate all pixels above the threshold level",
3373 "-sparse-color method args",
3374 " fill in a image based on a few color points",
3375 "-splice geometry splice the background color into the image",
3376 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003377 "-statistic type radius",
3378 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003379 "-strip strip image of all profiles and comments",
3380 "-swirl degrees swirl image pixels about the center",
3381 "-threshold value threshold the image",
3382 "-thumbnail geometry create a thumbnail of the image",
3383 "-tile filename tile image when filling a graphic primitive",
3384 "-tint value tint the image with the fill color",
3385 "-transform affine transform image",
3386 "-transparent color make this color transparent within the image",
3387 "-transpose flip image vertically and rotate 90 degrees",
3388 "-transverse flop image horizontally and rotate 270 degrees",
3389 "-trim trim image edges",
3390 "-type type image type",
3391 "-unique-colors discard all but one of any pixel color",
3392 "-unsharp geometry sharpen the image",
3393 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003394 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003395 "-white-threshold value",
3396 " force all pixels above the threshold into white",
3397 (char *) NULL
3398 },
3399 *sequence_operators[]=
3400 {
cristy4285d782011-02-09 20:12:28 +00003401 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003402 "-clut apply a color lookup table to the image",
3403 "-coalesce merge a sequence of images",
3404 "-combine combine a sequence of images",
3405 "-composite composite image",
3406 "-crop geometry cut out a rectangular region of the image",
3407 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003408 "-evaluate-sequence operator",
3409 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003410 "-flatten flatten a sequence of images",
3411 "-fx expression apply mathematical expression to an image channel(s)",
3412 "-hald-clut apply a Hald color lookup table to the image",
3413 "-morph value morph an image sequence",
3414 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003415 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003416 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003417 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003418 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003419 "-write filename write images to this file",
3420 (char *) NULL
3421 },
3422 *settings[]=
3423 {
3424 "-adjoin join images into a single multi-image file",
3425 "-affine matrix affine transform matrix",
3426 "-alpha option activate, deactivate, reset, or set the alpha channel",
3427 "-antialias remove pixel-aliasing",
3428 "-authenticate password",
3429 " decipher image with this password",
3430 "-attenuate value lessen (or intensify) when adding noise to an image",
3431 "-background color background color",
3432 "-bias value add bias when convolving an image",
3433 "-black-point-compensation",
3434 " use black point compensation",
3435 "-blue-primary point chromaticity blue primary point",
3436 "-bordercolor color border color",
3437 "-caption string assign a caption to an image",
3438 "-channel type apply option to select image channels",
3439 "-colors value preferred number of colors in the image",
3440 "-colorspace type alternate image colorspace",
3441 "-comment string annotate image with comment",
3442 "-compose operator set image composite operator",
3443 "-compress type type of pixel compression when writing the image",
3444 "-define format:option",
3445 " define one or more image format options",
3446 "-delay value display the next image after pausing",
3447 "-density geometry horizontal and vertical density of the image",
3448 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003449 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003450 "-display server get image or font from this X server",
3451 "-dispose method layer disposal method",
3452 "-dither method apply error diffusion to image",
3453 "-encoding type text encoding type",
3454 "-endian type endianness (MSB or LSB) of the image",
3455 "-family name render text with this font family",
3456 "-fill color color to use when filling a graphic primitive",
3457 "-filter type use this filter when resizing an image",
3458 "-font name render text with this font",
3459 "-format \"string\" output formatted image characteristics",
3460 "-fuzz distance colors within this distance are considered equal",
3461 "-gravity type horizontal and vertical text placement",
3462 "-green-primary point chromaticity green primary point",
3463 "-intent type type of rendering intent when managing the image color",
3464 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003465 "-interline-spacing value",
3466 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003467 "-interpolate method pixel color interpolation method",
3468 "-interword-spacing value",
3469 " set the space between two words",
3470 "-kerning value set the space between two letters",
3471 "-label string assign a label to an image",
3472 "-limit type value pixel cache resource limit",
3473 "-loop iterations add Netscape loop extension to your GIF animation",
3474 "-mask filename associate a mask with the image",
3475 "-mattecolor color frame color",
3476 "-monitor monitor progress",
3477 "-orient type image orientation",
3478 "-page geometry size and location of an image canvas (setting)",
3479 "-ping efficiently determine image attributes",
3480 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003481 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003482 "-preview type image preview type",
3483 "-quality value JPEG/MIFF/PNG compression level",
3484 "-quiet suppress all warning messages",
3485 "-red-primary point chromaticity red primary point",
3486 "-regard-warnings pay attention to warning messages",
3487 "-remap filename transform image colors to match this set of colors",
3488 "-respect-parentheses settings remain in effect until parenthesis boundary",
3489 "-sampling-factor geometry",
3490 " horizontal and vertical sampling factor",
3491 "-scene value image scene number",
3492 "-seed value seed a new sequence of pseudo-random numbers",
3493 "-size geometry width and height of image",
3494 "-stretch type render text with this font stretch",
3495 "-stroke color graphic primitive stroke color",
3496 "-strokewidth value graphic primitive stroke width",
3497 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003498 "-synchronize synchronize image to storage device",
3499 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003500 "-texture filename name of texture to tile onto the image background",
3501 "-tile-offset geometry",
3502 " tile offset",
3503 "-treedepth value color tree depth",
3504 "-transparent-color color",
3505 " transparent color",
3506 "-undercolor color annotation bounding box color",
3507 "-units type the units of image resolution",
3508 "-verbose print detailed information about the image",
3509 "-view FlashPix viewing transforms",
3510 "-virtual-pixel method",
3511 " virtual pixel access method",
3512 "-weight type render text with this font weight",
3513 "-white-point point chromaticity white point",
3514 (char *) NULL
3515 },
3516 *stack_operators[]=
3517 {
anthonyb69c4b32011-03-23 04:37:44 +00003518 "-delete indexes delete the image from the image sequence",
3519 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003520 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003521 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003522 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003523 "-swap indexes swap two images in the image sequence",
3524 (char *) NULL
3525 };
3526
3527 const char
3528 **p;
3529
cristybb503372010-05-27 20:51:26 +00003530 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003531 (void) printf("Copyright: %s\n",GetMagickCopyright());
3532 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003533 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3534 GetClientName());
3535 (void) printf("\nImage Settings:\n");
3536 for (p=settings; *p != (char *) NULL; p++)
3537 (void) printf(" %s\n",*p);
3538 (void) printf("\nImage Operators:\n");
3539 for (p=operators; *p != (char *) NULL; p++)
3540 (void) printf(" %s\n",*p);
3541 (void) printf("\nImage Sequence Operators:\n");
3542 for (p=sequence_operators; *p != (char *) NULL; p++)
3543 (void) printf(" %s\n",*p);
3544 (void) printf("\nImage Stack Operators:\n");
3545 for (p=stack_operators; *p != (char *) NULL; p++)
3546 (void) printf(" %s\n",*p);
3547 (void) printf("\nMiscellaneous Options:\n");
3548 for (p=miscellaneous; *p != (char *) NULL; p++)
3549 (void) printf(" %s\n",*p);
3550 (void) printf(
3551 "\nBy default, the image format of `file' is determined by its magic\n");
3552 (void) printf(
3553 "number. To specify a particular image format, precede the filename\n");
3554 (void) printf(
3555 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3556 (void) printf(
3557 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3558 (void) printf("'-' for standard input or output.\n");
3559 return(MagickFalse);
3560}
3561
3562WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3563 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3564{
3565#define DestroyMogrify() \
3566{ \
3567 if (format != (char *) NULL) \
3568 format=DestroyString(format); \
3569 if (path != (char *) NULL) \
3570 path=DestroyString(path); \
3571 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003572 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003573 argv[i]=DestroyString(argv[i]); \
3574 argv=(char **) RelinquishMagickMemory(argv); \
3575}
3576#define ThrowMogrifyException(asperity,tag,option) \
3577{ \
3578 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3579 option); \
3580 DestroyMogrify(); \
3581 return(MagickFalse); \
3582}
3583#define ThrowMogrifyInvalidArgumentException(option,argument) \
3584{ \
3585 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3586 "InvalidArgument","`%s': %s",argument,option); \
3587 DestroyMogrify(); \
3588 return(MagickFalse); \
3589}
3590
3591 char
3592 *format,
3593 *option,
3594 *path;
3595
3596 Image
3597 *image;
3598
3599 ImageStack
3600 image_stack[MaxImageStackDepth+1];
3601
cristy3ed852e2009-09-05 21:47:34 +00003602 MagickBooleanType
3603 global_colormap;
3604
3605 MagickBooleanType
3606 fire,
cristyebbcfea2011-02-25 02:43:54 +00003607 pend,
3608 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003609
3610 MagickStatusType
3611 status;
3612
cristyebbcfea2011-02-25 02:43:54 +00003613 register ssize_t
3614 i;
3615
3616 ssize_t
3617 j,
3618 k;
3619
cristy3ed852e2009-09-05 21:47:34 +00003620 /*
3621 Set defaults.
3622 */
3623 assert(image_info != (ImageInfo *) NULL);
3624 assert(image_info->signature == MagickSignature);
3625 if (image_info->debug != MagickFalse)
3626 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3627 assert(exception != (ExceptionInfo *) NULL);
3628 if (argc == 2)
3629 {
3630 option=argv[1];
3631 if ((LocaleCompare("version",option+1) == 0) ||
3632 (LocaleCompare("-version",option+1) == 0))
3633 {
cristyb51dff52011-05-19 16:55:47 +00003634 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003635 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003636 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3637 GetMagickCopyright());
3638 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3639 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003640 return(MagickFalse);
3641 }
3642 }
3643 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003644 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003645 format=(char *) NULL;
3646 path=(char *) NULL;
3647 global_colormap=MagickFalse;
3648 k=0;
3649 j=1;
3650 NewImageStack();
3651 option=(char *) NULL;
3652 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003653 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003654 status=MagickTrue;
3655 /*
3656 Parse command line.
3657 */
3658 ReadCommandlLine(argc,&argv);
3659 status=ExpandFilenames(&argc,&argv);
3660 if (status == MagickFalse)
3661 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3662 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003663 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003664 {
3665 option=argv[i];
3666 if (LocaleCompare(option,"(") == 0)
3667 {
3668 FireImageStack(MagickFalse,MagickTrue,pend);
3669 if (k == MaxImageStackDepth)
3670 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3671 option);
3672 PushImageStack();
3673 continue;
3674 }
3675 if (LocaleCompare(option,")") == 0)
3676 {
3677 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3678 if (k == 0)
3679 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3680 PopImageStack();
3681 continue;
3682 }
cristy042ee782011-04-22 18:48:30 +00003683 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003684 {
3685 char
3686 backup_filename[MaxTextExtent],
3687 *filename;
3688
3689 Image
3690 *images;
3691
3692 /*
3693 Option is a file name: begin by reading image from specified file.
3694 */
3695 FireImageStack(MagickFalse,MagickFalse,pend);
3696 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003697 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003698 filename=argv[++i];
3699 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3700 images=ReadImages(image_info,exception);
3701 status&=(images != (Image *) NULL) &&
3702 (exception->severity < ErrorException);
3703 if (images == (Image *) NULL)
3704 continue;
cristydaa76602010-06-30 13:05:11 +00003705 if (format != (char *) NULL)
3706 (void) CopyMagickString(images->filename,images->magick_filename,
3707 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003708 if (path != (char *) NULL)
3709 {
3710 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003711 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003712 path,*DirectorySeparator,filename);
3713 }
3714 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003715 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003716 AppendImageStack(images);
3717 FinalizeImageSettings(image_info,image,MagickFalse);
3718 if (global_colormap != MagickFalse)
3719 {
3720 QuantizeInfo
3721 *quantize_info;
3722
3723 quantize_info=AcquireQuantizeInfo(image_info);
3724 (void) RemapImages(quantize_info,images,(Image *) NULL);
3725 quantize_info=DestroyQuantizeInfo(quantize_info);
3726 }
3727 *backup_filename='\0';
3728 if ((LocaleCompare(image->filename,"-") != 0) &&
3729 (IsPathWritable(image->filename) != MagickFalse))
3730 {
cristybb503372010-05-27 20:51:26 +00003731 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003732 i;
3733
3734 /*
3735 Rename image file as backup.
3736 */
3737 (void) CopyMagickString(backup_filename,image->filename,
3738 MaxTextExtent);
3739 for (i=0; i < 6; i++)
3740 {
3741 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3742 if (IsPathAccessible(backup_filename) == MagickFalse)
3743 break;
3744 }
3745 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3746 (rename(image->filename,backup_filename) != 0))
3747 *backup_filename='\0';
3748 }
3749 /*
3750 Write transmogrified image to disk.
3751 */
3752 image_info->synchronize=MagickTrue;
3753 status&=WriteImages(image_info,image,image->filename,exception);
3754 if ((status == MagickFalse) && (*backup_filename != '\0'))
3755 (void) remove(backup_filename);
3756 RemoveAllImageStack();
3757 continue;
3758 }
3759 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3760 switch (*(option+1))
3761 {
3762 case 'a':
3763 {
3764 if (LocaleCompare("adaptive-blur",option+1) == 0)
3765 {
3766 i++;
cristybb503372010-05-27 20:51:26 +00003767 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003768 ThrowMogrifyException(OptionError,"MissingArgument",option);
3769 if (IsGeometry(argv[i]) == MagickFalse)
3770 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3771 break;
3772 }
3773 if (LocaleCompare("adaptive-resize",option+1) == 0)
3774 {
3775 i++;
cristybb503372010-05-27 20:51:26 +00003776 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003777 ThrowMogrifyException(OptionError,"MissingArgument",option);
3778 if (IsGeometry(argv[i]) == MagickFalse)
3779 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3780 break;
3781 }
3782 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3783 {
3784 i++;
cristybb503372010-05-27 20:51:26 +00003785 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003786 ThrowMogrifyException(OptionError,"MissingArgument",option);
3787 if (IsGeometry(argv[i]) == MagickFalse)
3788 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3789 break;
3790 }
3791 if (LocaleCompare("affine",option+1) == 0)
3792 {
3793 if (*option == '+')
3794 break;
3795 i++;
cristybb503372010-05-27 20:51:26 +00003796 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003797 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003798 break;
3799 }
3800 if (LocaleCompare("alpha",option+1) == 0)
3801 {
cristybb503372010-05-27 20:51:26 +00003802 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003803 type;
3804
3805 if (*option == '+')
3806 break;
3807 i++;
cristybb503372010-05-27 20:51:26 +00003808 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003809 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003810 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003811 if (type < 0)
3812 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3813 argv[i]);
3814 break;
3815 }
3816 if (LocaleCompare("annotate",option+1) == 0)
3817 {
3818 if (*option == '+')
3819 break;
3820 i++;
cristybb503372010-05-27 20:51:26 +00003821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003822 ThrowMogrifyException(OptionError,"MissingArgument",option);
3823 if (IsGeometry(argv[i]) == MagickFalse)
3824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003825 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003826 ThrowMogrifyException(OptionError,"MissingArgument",option);
3827 i++;
3828 break;
3829 }
3830 if (LocaleCompare("antialias",option+1) == 0)
3831 break;
3832 if (LocaleCompare("append",option+1) == 0)
3833 break;
3834 if (LocaleCompare("attenuate",option+1) == 0)
3835 {
3836 if (*option == '+')
3837 break;
3838 i++;
cristybb503372010-05-27 20:51:26 +00003839 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003840 ThrowMogrifyException(OptionError,"MissingArgument",option);
3841 if (IsGeometry(argv[i]) == MagickFalse)
3842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3843 break;
3844 }
3845 if (LocaleCompare("authenticate",option+1) == 0)
3846 {
3847 if (*option == '+')
3848 break;
3849 i++;
cristybb503372010-05-27 20:51:26 +00003850 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003851 ThrowMogrifyException(OptionError,"MissingArgument",option);
3852 break;
3853 }
3854 if (LocaleCompare("auto-gamma",option+1) == 0)
3855 break;
3856 if (LocaleCompare("auto-level",option+1) == 0)
3857 break;
3858 if (LocaleCompare("auto-orient",option+1) == 0)
3859 break;
3860 if (LocaleCompare("average",option+1) == 0)
3861 break;
3862 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3863 }
3864 case 'b':
3865 {
3866 if (LocaleCompare("background",option+1) == 0)
3867 {
3868 if (*option == '+')
3869 break;
3870 i++;
cristybb503372010-05-27 20:51:26 +00003871 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003872 ThrowMogrifyException(OptionError,"MissingArgument",option);
3873 break;
3874 }
3875 if (LocaleCompare("bias",option+1) == 0)
3876 {
3877 if (*option == '+')
3878 break;
3879 i++;
cristybb503372010-05-27 20:51:26 +00003880 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003881 ThrowMogrifyException(OptionError,"MissingArgument",option);
3882 if (IsGeometry(argv[i]) == MagickFalse)
3883 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3884 break;
3885 }
3886 if (LocaleCompare("black-point-compensation",option+1) == 0)
3887 break;
3888 if (LocaleCompare("black-threshold",option+1) == 0)
3889 {
3890 if (*option == '+')
3891 break;
3892 i++;
cristybb503372010-05-27 20:51:26 +00003893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003894 ThrowMogrifyException(OptionError,"MissingArgument",option);
3895 if (IsGeometry(argv[i]) == MagickFalse)
3896 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3897 break;
3898 }
3899 if (LocaleCompare("blue-primary",option+1) == 0)
3900 {
3901 if (*option == '+')
3902 break;
3903 i++;
cristybb503372010-05-27 20:51:26 +00003904 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003905 ThrowMogrifyException(OptionError,"MissingArgument",option);
3906 if (IsGeometry(argv[i]) == MagickFalse)
3907 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3908 break;
3909 }
3910 if (LocaleCompare("blue-shift",option+1) == 0)
3911 {
3912 i++;
cristybb503372010-05-27 20:51:26 +00003913 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003914 ThrowMogrifyException(OptionError,"MissingArgument",option);
3915 if (IsGeometry(argv[i]) == MagickFalse)
3916 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3917 break;
3918 }
3919 if (LocaleCompare("blur",option+1) == 0)
3920 {
3921 i++;
cristybb503372010-05-27 20:51:26 +00003922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003923 ThrowMogrifyException(OptionError,"MissingArgument",option);
3924 if (IsGeometry(argv[i]) == MagickFalse)
3925 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3926 break;
3927 }
3928 if (LocaleCompare("border",option+1) == 0)
3929 {
3930 if (*option == '+')
3931 break;
3932 i++;
cristybb503372010-05-27 20:51:26 +00003933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003934 ThrowMogrifyException(OptionError,"MissingArgument",option);
3935 if (IsGeometry(argv[i]) == MagickFalse)
3936 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3937 break;
3938 }
3939 if (LocaleCompare("bordercolor",option+1) == 0)
3940 {
3941 if (*option == '+')
3942 break;
3943 i++;
cristybb503372010-05-27 20:51:26 +00003944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003945 ThrowMogrifyException(OptionError,"MissingArgument",option);
3946 break;
3947 }
3948 if (LocaleCompare("box",option+1) == 0)
3949 {
3950 if (*option == '+')
3951 break;
3952 i++;
cristybb503372010-05-27 20:51:26 +00003953 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003954 ThrowMogrifyException(OptionError,"MissingArgument",option);
3955 break;
3956 }
cristya28d6b82010-01-11 20:03:47 +00003957 if (LocaleCompare("brightness-contrast",option+1) == 0)
3958 {
3959 i++;
cristybb503372010-05-27 20:51:26 +00003960 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003961 ThrowMogrifyException(OptionError,"MissingArgument",option);
3962 if (IsGeometry(argv[i]) == MagickFalse)
3963 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3964 break;
3965 }
cristy3ed852e2009-09-05 21:47:34 +00003966 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3967 }
3968 case 'c':
3969 {
3970 if (LocaleCompare("cache",option+1) == 0)
3971 {
3972 if (*option == '+')
3973 break;
3974 i++;
cristybb503372010-05-27 20:51:26 +00003975 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003976 ThrowMogrifyException(OptionError,"MissingArgument",option);
3977 if (IsGeometry(argv[i]) == MagickFalse)
3978 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3979 break;
3980 }
3981 if (LocaleCompare("caption",option+1) == 0)
3982 {
3983 if (*option == '+')
3984 break;
3985 i++;
cristybb503372010-05-27 20:51:26 +00003986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003987 ThrowMogrifyException(OptionError,"MissingArgument",option);
3988 break;
3989 }
3990 if (LocaleCompare("channel",option+1) == 0)
3991 {
cristybb503372010-05-27 20:51:26 +00003992 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003993 channel;
3994
3995 if (*option == '+')
3996 break;
3997 i++;
cristybb503372010-05-27 20:51:26 +00003998 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003999 ThrowMogrifyException(OptionError,"MissingArgument",option);
4000 channel=ParseChannelOption(argv[i]);
4001 if (channel < 0)
4002 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4003 argv[i]);
4004 break;
4005 }
4006 if (LocaleCompare("cdl",option+1) == 0)
4007 {
4008 if (*option == '+')
4009 break;
4010 i++;
cristybb503372010-05-27 20:51:26 +00004011 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004012 ThrowMogrifyException(OptionError,"MissingArgument",option);
4013 break;
4014 }
4015 if (LocaleCompare("charcoal",option+1) == 0)
4016 {
4017 if (*option == '+')
4018 break;
4019 i++;
cristybb503372010-05-27 20:51:26 +00004020 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004021 ThrowMogrifyException(OptionError,"MissingArgument",option);
4022 if (IsGeometry(argv[i]) == MagickFalse)
4023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4024 break;
4025 }
4026 if (LocaleCompare("chop",option+1) == 0)
4027 {
4028 if (*option == '+')
4029 break;
4030 i++;
cristybb503372010-05-27 20:51:26 +00004031 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004032 ThrowMogrifyException(OptionError,"MissingArgument",option);
4033 if (IsGeometry(argv[i]) == MagickFalse)
4034 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4035 break;
4036 }
cristy1eb45dd2009-09-25 16:38:06 +00004037 if (LocaleCompare("clamp",option+1) == 0)
4038 break;
4039 if (LocaleCompare("clip",option+1) == 0)
4040 break;
cristy3ed852e2009-09-05 21:47:34 +00004041 if (LocaleCompare("clip-mask",option+1) == 0)
4042 {
4043 if (*option == '+')
4044 break;
4045 i++;
cristybb503372010-05-27 20:51:26 +00004046 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004047 ThrowMogrifyException(OptionError,"MissingArgument",option);
4048 break;
4049 }
4050 if (LocaleCompare("clut",option+1) == 0)
4051 break;
4052 if (LocaleCompare("coalesce",option+1) == 0)
4053 break;
4054 if (LocaleCompare("colorize",option+1) == 0)
4055 {
4056 if (*option == '+')
4057 break;
4058 i++;
cristybb503372010-05-27 20:51:26 +00004059 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004060 ThrowMogrifyException(OptionError,"MissingArgument",option);
4061 if (IsGeometry(argv[i]) == MagickFalse)
4062 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4063 break;
4064 }
cristye6365592010-04-02 17:31:23 +00004065 if (LocaleCompare("color-matrix",option+1) == 0)
4066 {
cristyb6bd4ad2010-08-08 01:12:27 +00004067 KernelInfo
4068 *kernel_info;
4069
cristye6365592010-04-02 17:31:23 +00004070 if (*option == '+')
4071 break;
4072 i++;
cristybb503372010-05-27 20:51:26 +00004073 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004074 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004075 kernel_info=AcquireKernelInfo(argv[i]);
4076 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004077 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004078 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004079 break;
4080 }
cristy3ed852e2009-09-05 21:47:34 +00004081 if (LocaleCompare("colors",option+1) == 0)
4082 {
4083 if (*option == '+')
4084 break;
4085 i++;
cristybb503372010-05-27 20:51:26 +00004086 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004087 ThrowMogrifyException(OptionError,"MissingArgument",option);
4088 if (IsGeometry(argv[i]) == MagickFalse)
4089 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4090 break;
4091 }
4092 if (LocaleCompare("colorspace",option+1) == 0)
4093 {
cristybb503372010-05-27 20:51:26 +00004094 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004095 colorspace;
4096
4097 if (*option == '+')
4098 break;
4099 i++;
cristybb503372010-05-27 20:51:26 +00004100 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004101 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004102 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004103 argv[i]);
4104 if (colorspace < 0)
4105 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4106 argv[i]);
4107 break;
4108 }
4109 if (LocaleCompare("combine",option+1) == 0)
4110 break;
4111 if (LocaleCompare("comment",option+1) == 0)
4112 {
4113 if (*option == '+')
4114 break;
4115 i++;
cristybb503372010-05-27 20:51:26 +00004116 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004117 ThrowMogrifyException(OptionError,"MissingArgument",option);
4118 break;
4119 }
4120 if (LocaleCompare("composite",option+1) == 0)
4121 break;
4122 if (LocaleCompare("compress",option+1) == 0)
4123 {
cristybb503372010-05-27 20:51:26 +00004124 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004125 compress;
4126
4127 if (*option == '+')
4128 break;
4129 i++;
cristybb503372010-05-27 20:51:26 +00004130 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004131 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004132 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004133 argv[i]);
4134 if (compress < 0)
4135 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4136 argv[i]);
4137 break;
4138 }
cristy22879752009-10-25 23:55:40 +00004139 if (LocaleCompare("concurrent",option+1) == 0)
4140 break;
cristy3ed852e2009-09-05 21:47:34 +00004141 if (LocaleCompare("contrast",option+1) == 0)
4142 break;
4143 if (LocaleCompare("contrast-stretch",option+1) == 0)
4144 {
4145 i++;
cristybb503372010-05-27 20:51:26 +00004146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004147 ThrowMogrifyException(OptionError,"MissingArgument",option);
4148 if (IsGeometry(argv[i]) == MagickFalse)
4149 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4150 break;
4151 }
4152 if (LocaleCompare("convolve",option+1) == 0)
4153 {
cristyb6bd4ad2010-08-08 01:12:27 +00004154 KernelInfo
4155 *kernel_info;
4156
cristy3ed852e2009-09-05 21:47:34 +00004157 if (*option == '+')
4158 break;
4159 i++;
cristybb503372010-05-27 20:51:26 +00004160 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004161 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004162 kernel_info=AcquireKernelInfo(argv[i]);
4163 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004164 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004165 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004166 break;
4167 }
4168 if (LocaleCompare("crop",option+1) == 0)
4169 {
4170 if (*option == '+')
4171 break;
4172 i++;
cristybb503372010-05-27 20:51:26 +00004173 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004174 ThrowMogrifyException(OptionError,"MissingArgument",option);
4175 if (IsGeometry(argv[i]) == MagickFalse)
4176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4177 break;
4178 }
4179 if (LocaleCompare("cycle",option+1) == 0)
4180 {
4181 if (*option == '+')
4182 break;
4183 i++;
cristybb503372010-05-27 20:51:26 +00004184 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004185 ThrowMogrifyException(OptionError,"MissingArgument",option);
4186 if (IsGeometry(argv[i]) == MagickFalse)
4187 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4188 break;
4189 }
4190 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4191 }
4192 case 'd':
4193 {
4194 if (LocaleCompare("decipher",option+1) == 0)
4195 {
4196 if (*option == '+')
4197 break;
4198 i++;
cristybb503372010-05-27 20:51:26 +00004199 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004200 ThrowMogrifyException(OptionError,"MissingArgument",option);
4201 break;
4202 }
4203 if (LocaleCompare("deconstruct",option+1) == 0)
4204 break;
4205 if (LocaleCompare("debug",option+1) == 0)
4206 {
cristybb503372010-05-27 20:51:26 +00004207 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004208 event;
4209
4210 if (*option == '+')
4211 break;
4212 i++;
cristybb503372010-05-27 20:51:26 +00004213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004214 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004215 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004216 if (event < 0)
4217 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4218 argv[i]);
4219 (void) SetLogEventMask(argv[i]);
4220 break;
4221 }
4222 if (LocaleCompare("define",option+1) == 0)
4223 {
4224 i++;
cristybb503372010-05-27 20:51:26 +00004225 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004226 ThrowMogrifyException(OptionError,"MissingArgument",option);
4227 if (*option == '+')
4228 {
4229 const char
4230 *define;
4231
4232 define=GetImageOption(image_info,argv[i]);
4233 if (define == (const char *) NULL)
4234 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4235 break;
4236 }
4237 break;
4238 }
4239 if (LocaleCompare("delay",option+1) == 0)
4240 {
4241 if (*option == '+')
4242 break;
4243 i++;
cristybb503372010-05-27 20:51:26 +00004244 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004245 ThrowMogrifyException(OptionError,"MissingArgument",option);
4246 if (IsGeometry(argv[i]) == MagickFalse)
4247 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4248 break;
4249 }
cristyecb10ff2011-03-22 13:14:03 +00004250 if (LocaleCompare("delete",option+1) == 0)
4251 {
4252 if (*option == '+')
4253 break;
4254 i++;
4255 if (i == (ssize_t) (argc-1))
4256 ThrowMogrifyException(OptionError,"MissingArgument",option);
4257 if (IsGeometry(argv[i]) == MagickFalse)
4258 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4259 break;
4260 }
cristy3ed852e2009-09-05 21:47:34 +00004261 if (LocaleCompare("density",option+1) == 0)
4262 {
4263 if (*option == '+')
4264 break;
4265 i++;
cristybb503372010-05-27 20:51:26 +00004266 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004267 ThrowMogrifyException(OptionError,"MissingArgument",option);
4268 if (IsGeometry(argv[i]) == MagickFalse)
4269 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4270 break;
4271 }
4272 if (LocaleCompare("depth",option+1) == 0)
4273 {
4274 if (*option == '+')
4275 break;
4276 i++;
cristybb503372010-05-27 20:51:26 +00004277 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004278 ThrowMogrifyException(OptionError,"MissingArgument",option);
4279 if (IsGeometry(argv[i]) == MagickFalse)
4280 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4281 break;
4282 }
4283 if (LocaleCompare("deskew",option+1) == 0)
4284 {
4285 if (*option == '+')
4286 break;
4287 i++;
cristybb503372010-05-27 20:51:26 +00004288 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004289 ThrowMogrifyException(OptionError,"MissingArgument",option);
4290 if (IsGeometry(argv[i]) == MagickFalse)
4291 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4292 break;
4293 }
4294 if (LocaleCompare("despeckle",option+1) == 0)
4295 break;
4296 if (LocaleCompare("dft",option+1) == 0)
4297 break;
cristyc9b12952010-03-28 01:12:28 +00004298 if (LocaleCompare("direction",option+1) == 0)
4299 {
cristybb503372010-05-27 20:51:26 +00004300 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004301 direction;
4302
4303 if (*option == '+')
4304 break;
4305 i++;
cristybb503372010-05-27 20:51:26 +00004306 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004307 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004308 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004309 argv[i]);
4310 if (direction < 0)
4311 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4312 argv[i]);
4313 break;
4314 }
cristy3ed852e2009-09-05 21:47:34 +00004315 if (LocaleCompare("display",option+1) == 0)
4316 {
4317 if (*option == '+')
4318 break;
4319 i++;
cristybb503372010-05-27 20:51:26 +00004320 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004321 ThrowMogrifyException(OptionError,"MissingArgument",option);
4322 break;
4323 }
4324 if (LocaleCompare("dispose",option+1) == 0)
4325 {
cristybb503372010-05-27 20:51:26 +00004326 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004327 dispose;
4328
4329 if (*option == '+')
4330 break;
4331 i++;
cristybb503372010-05-27 20:51:26 +00004332 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004333 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004334 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004335 if (dispose < 0)
4336 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4337 argv[i]);
4338 break;
4339 }
4340 if (LocaleCompare("distort",option+1) == 0)
4341 {
cristybb503372010-05-27 20:51:26 +00004342 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004343 op;
4344
4345 i++;
cristybb503372010-05-27 20:51:26 +00004346 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004347 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004348 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004349 if (op < 0)
4350 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4351 argv[i]);
4352 i++;
cristybb503372010-05-27 20:51:26 +00004353 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004354 ThrowMogrifyException(OptionError,"MissingArgument",option);
4355 break;
4356 }
4357 if (LocaleCompare("dither",option+1) == 0)
4358 {
cristybb503372010-05-27 20:51:26 +00004359 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004360 method;
4361
4362 if (*option == '+')
4363 break;
4364 i++;
cristybb503372010-05-27 20:51:26 +00004365 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004366 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004367 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004368 if (method < 0)
4369 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4370 argv[i]);
4371 break;
4372 }
4373 if (LocaleCompare("draw",option+1) == 0)
4374 {
4375 if (*option == '+')
4376 break;
4377 i++;
cristybb503372010-05-27 20:51:26 +00004378 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004379 ThrowMogrifyException(OptionError,"MissingArgument",option);
4380 break;
4381 }
cristyecb10ff2011-03-22 13:14:03 +00004382 if (LocaleCompare("duplicate",option+1) == 0)
4383 {
4384 if (*option == '+')
4385 break;
4386 i++;
4387 if (i == (ssize_t) (argc-1))
4388 ThrowMogrifyException(OptionError,"MissingArgument",option);
4389 if (IsGeometry(argv[i]) == MagickFalse)
4390 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4391 break;
4392 }
cristy22879752009-10-25 23:55:40 +00004393 if (LocaleCompare("duration",option+1) == 0)
4394 {
4395 if (*option == '+')
4396 break;
4397 i++;
cristybb503372010-05-27 20:51:26 +00004398 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004399 ThrowMogrifyException(OptionError,"MissingArgument",option);
4400 if (IsGeometry(argv[i]) == MagickFalse)
4401 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4402 break;
4403 }
cristy3ed852e2009-09-05 21:47:34 +00004404 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4405 }
4406 case 'e':
4407 {
4408 if (LocaleCompare("edge",option+1) == 0)
4409 {
4410 if (*option == '+')
4411 break;
4412 i++;
cristybb503372010-05-27 20:51:26 +00004413 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004414 ThrowMogrifyException(OptionError,"MissingArgument",option);
4415 if (IsGeometry(argv[i]) == MagickFalse)
4416 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4417 break;
4418 }
4419 if (LocaleCompare("emboss",option+1) == 0)
4420 {
4421 if (*option == '+')
4422 break;
4423 i++;
cristybb503372010-05-27 20:51:26 +00004424 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004425 ThrowMogrifyException(OptionError,"MissingArgument",option);
4426 if (IsGeometry(argv[i]) == MagickFalse)
4427 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4428 break;
4429 }
4430 if (LocaleCompare("encipher",option+1) == 0)
4431 {
4432 if (*option == '+')
4433 break;
4434 i++;
cristybb503372010-05-27 20:51:26 +00004435 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004436 ThrowMogrifyException(OptionError,"MissingArgument",option);
4437 break;
4438 }
4439 if (LocaleCompare("encoding",option+1) == 0)
4440 {
4441 if (*option == '+')
4442 break;
4443 i++;
cristybb503372010-05-27 20:51:26 +00004444 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004445 ThrowMogrifyException(OptionError,"MissingArgument",option);
4446 break;
4447 }
4448 if (LocaleCompare("endian",option+1) == 0)
4449 {
cristybb503372010-05-27 20:51:26 +00004450 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004451 endian;
4452
4453 if (*option == '+')
4454 break;
4455 i++;
cristybb503372010-05-27 20:51:26 +00004456 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004457 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004458 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004459 if (endian < 0)
4460 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4461 argv[i]);
4462 break;
4463 }
4464 if (LocaleCompare("enhance",option+1) == 0)
4465 break;
4466 if (LocaleCompare("equalize",option+1) == 0)
4467 break;
4468 if (LocaleCompare("evaluate",option+1) == 0)
4469 {
cristybb503372010-05-27 20:51:26 +00004470 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004471 op;
4472
4473 if (*option == '+')
4474 break;
4475 i++;
cristybb503372010-05-27 20:51:26 +00004476 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004477 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004478 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004479 if (op < 0)
4480 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4481 argv[i]);
4482 i++;
cristybb503372010-05-27 20:51:26 +00004483 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004484 ThrowMogrifyException(OptionError,"MissingArgument",option);
4485 if (IsGeometry(argv[i]) == MagickFalse)
4486 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4487 break;
4488 }
cristyd18ae7c2010-03-07 17:39:52 +00004489 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4490 {
cristybb503372010-05-27 20:51:26 +00004491 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004492 op;
4493
4494 if (*option == '+')
4495 break;
4496 i++;
cristybb503372010-05-27 20:51:26 +00004497 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004498 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004499 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004500 if (op < 0)
4501 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4502 argv[i]);
4503 break;
4504 }
cristy3ed852e2009-09-05 21:47:34 +00004505 if (LocaleCompare("extent",option+1) == 0)
4506 {
4507 if (*option == '+')
4508 break;
4509 i++;
cristybb503372010-05-27 20:51:26 +00004510 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004511 ThrowMogrifyException(OptionError,"MissingArgument",option);
4512 if (IsGeometry(argv[i]) == MagickFalse)
4513 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4514 break;
4515 }
4516 if (LocaleCompare("extract",option+1) == 0)
4517 {
4518 if (*option == '+')
4519 break;
4520 i++;
cristybb503372010-05-27 20:51:26 +00004521 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004522 ThrowMogrifyException(OptionError,"MissingArgument",option);
4523 if (IsGeometry(argv[i]) == MagickFalse)
4524 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4525 break;
4526 }
4527 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4528 }
4529 case 'f':
4530 {
4531 if (LocaleCompare("family",option+1) == 0)
4532 {
4533 if (*option == '+')
4534 break;
4535 i++;
cristybb503372010-05-27 20:51:26 +00004536 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004537 ThrowMogrifyException(OptionError,"MissingArgument",option);
4538 break;
4539 }
4540 if (LocaleCompare("fill",option+1) == 0)
4541 {
4542 if (*option == '+')
4543 break;
4544 i++;
cristybb503372010-05-27 20:51:26 +00004545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004546 ThrowMogrifyException(OptionError,"MissingArgument",option);
4547 break;
4548 }
4549 if (LocaleCompare("filter",option+1) == 0)
4550 {
cristybb503372010-05-27 20:51:26 +00004551 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004552 filter;
4553
4554 if (*option == '+')
4555 break;
4556 i++;
cristybb503372010-05-27 20:51:26 +00004557 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004558 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004559 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004560 if (filter < 0)
4561 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4562 argv[i]);
4563 break;
4564 }
4565 if (LocaleCompare("flatten",option+1) == 0)
4566 break;
4567 if (LocaleCompare("flip",option+1) == 0)
4568 break;
4569 if (LocaleCompare("flop",option+1) == 0)
4570 break;
4571 if (LocaleCompare("floodfill",option+1) == 0)
4572 {
4573 if (*option == '+')
4574 break;
4575 i++;
cristybb503372010-05-27 20:51:26 +00004576 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004577 ThrowMogrifyException(OptionError,"MissingArgument",option);
4578 if (IsGeometry(argv[i]) == MagickFalse)
4579 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4580 i++;
cristybb503372010-05-27 20:51:26 +00004581 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004582 ThrowMogrifyException(OptionError,"MissingArgument",option);
4583 break;
4584 }
4585 if (LocaleCompare("font",option+1) == 0)
4586 {
4587 if (*option == '+')
4588 break;
4589 i++;
cristybb503372010-05-27 20:51:26 +00004590 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004591 ThrowMogrifyException(OptionError,"MissingArgument",option);
4592 break;
4593 }
4594 if (LocaleCompare("format",option+1) == 0)
4595 {
4596 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4597 (void) CloneString(&format,(char *) NULL);
4598 if (*option == '+')
4599 break;
4600 i++;
cristybb503372010-05-27 20:51:26 +00004601 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004602 ThrowMogrifyException(OptionError,"MissingArgument",option);
4603 (void) CloneString(&format,argv[i]);
4604 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4605 (void) ConcatenateMagickString(image_info->filename,":",
4606 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004607 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004608 if (*image_info->magick == '\0')
4609 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4610 format);
4611 break;
4612 }
4613 if (LocaleCompare("frame",option+1) == 0)
4614 {
4615 if (*option == '+')
4616 break;
4617 i++;
cristybb503372010-05-27 20:51:26 +00004618 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004619 ThrowMogrifyException(OptionError,"MissingArgument",option);
4620 if (IsGeometry(argv[i]) == MagickFalse)
4621 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4622 break;
4623 }
4624 if (LocaleCompare("function",option+1) == 0)
4625 {
cristybb503372010-05-27 20:51:26 +00004626 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004627 op;
4628
4629 if (*option == '+')
4630 break;
4631 i++;
cristybb503372010-05-27 20:51:26 +00004632 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004633 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004634 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004635 if (op < 0)
4636 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4637 i++;
cristybb503372010-05-27 20:51:26 +00004638 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004639 ThrowMogrifyException(OptionError,"MissingArgument",option);
4640 break;
4641 }
4642 if (LocaleCompare("fuzz",option+1) == 0)
4643 {
4644 if (*option == '+')
4645 break;
4646 i++;
cristybb503372010-05-27 20:51:26 +00004647 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004648 ThrowMogrifyException(OptionError,"MissingArgument",option);
4649 if (IsGeometry(argv[i]) == MagickFalse)
4650 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4651 break;
4652 }
4653 if (LocaleCompare("fx",option+1) == 0)
4654 {
4655 if (*option == '+')
4656 break;
4657 i++;
cristybb503372010-05-27 20:51:26 +00004658 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004659 ThrowMogrifyException(OptionError,"MissingArgument",option);
4660 break;
4661 }
4662 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4663 }
4664 case 'g':
4665 {
4666 if (LocaleCompare("gamma",option+1) == 0)
4667 {
4668 i++;
cristybb503372010-05-27 20:51:26 +00004669 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004670 ThrowMogrifyException(OptionError,"MissingArgument",option);
4671 if (IsGeometry(argv[i]) == MagickFalse)
4672 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4673 break;
4674 }
4675 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4676 (LocaleCompare("gaussian",option+1) == 0))
4677 {
4678 i++;
cristybb503372010-05-27 20:51:26 +00004679 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004680 ThrowMogrifyException(OptionError,"MissingArgument",option);
4681 if (IsGeometry(argv[i]) == MagickFalse)
4682 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4683 break;
4684 }
4685 if (LocaleCompare("geometry",option+1) == 0)
4686 {
4687 if (*option == '+')
4688 break;
4689 i++;
cristybb503372010-05-27 20:51:26 +00004690 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004691 ThrowMogrifyException(OptionError,"MissingArgument",option);
4692 if (IsGeometry(argv[i]) == MagickFalse)
4693 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4694 break;
4695 }
4696 if (LocaleCompare("gravity",option+1) == 0)
4697 {
cristybb503372010-05-27 20:51:26 +00004698 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004699 gravity;
4700
4701 if (*option == '+')
4702 break;
4703 i++;
cristybb503372010-05-27 20:51:26 +00004704 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004705 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004706 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004707 if (gravity < 0)
4708 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4709 argv[i]);
4710 break;
4711 }
4712 if (LocaleCompare("green-primary",option+1) == 0)
4713 {
4714 if (*option == '+')
4715 break;
4716 i++;
cristybb503372010-05-27 20:51:26 +00004717 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004718 ThrowMogrifyException(OptionError,"MissingArgument",option);
4719 if (IsGeometry(argv[i]) == MagickFalse)
4720 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4721 break;
4722 }
4723 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4724 }
4725 case 'h':
4726 {
4727 if (LocaleCompare("hald-clut",option+1) == 0)
4728 break;
4729 if ((LocaleCompare("help",option+1) == 0) ||
4730 (LocaleCompare("-help",option+1) == 0))
4731 return(MogrifyUsage());
4732 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4733 }
4734 case 'i':
4735 {
4736 if (LocaleCompare("identify",option+1) == 0)
4737 break;
4738 if (LocaleCompare("idft",option+1) == 0)
4739 break;
4740 if (LocaleCompare("implode",option+1) == 0)
4741 {
4742 if (*option == '+')
4743 break;
4744 i++;
cristybb503372010-05-27 20:51:26 +00004745 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004746 ThrowMogrifyException(OptionError,"MissingArgument",option);
4747 if (IsGeometry(argv[i]) == MagickFalse)
4748 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4749 break;
4750 }
4751 if (LocaleCompare("intent",option+1) == 0)
4752 {
cristybb503372010-05-27 20:51:26 +00004753 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004754 intent;
4755
4756 if (*option == '+')
4757 break;
4758 i++;
cristybb503372010-05-27 20:51:26 +00004759 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004760 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004761 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004762 if (intent < 0)
4763 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4764 argv[i]);
4765 break;
4766 }
4767 if (LocaleCompare("interlace",option+1) == 0)
4768 {
cristybb503372010-05-27 20:51:26 +00004769 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004770 interlace;
4771
4772 if (*option == '+')
4773 break;
4774 i++;
cristybb503372010-05-27 20:51:26 +00004775 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004776 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004777 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004778 argv[i]);
4779 if (interlace < 0)
4780 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4781 argv[i]);
4782 break;
4783 }
cristyb32b90a2009-09-07 21:45:48 +00004784 if (LocaleCompare("interline-spacing",option+1) == 0)
4785 {
4786 if (*option == '+')
4787 break;
4788 i++;
cristybb503372010-05-27 20:51:26 +00004789 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004790 ThrowMogrifyException(OptionError,"MissingArgument",option);
4791 if (IsGeometry(argv[i]) == MagickFalse)
4792 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4793 break;
4794 }
cristy3ed852e2009-09-05 21:47:34 +00004795 if (LocaleCompare("interpolate",option+1) == 0)
4796 {
cristybb503372010-05-27 20:51:26 +00004797 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004798 interpolate;
4799
4800 if (*option == '+')
4801 break;
4802 i++;
cristybb503372010-05-27 20:51:26 +00004803 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004804 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004805 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004806 argv[i]);
4807 if (interpolate < 0)
4808 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4809 argv[i]);
4810 break;
4811 }
4812 if (LocaleCompare("interword-spacing",option+1) == 0)
4813 {
4814 if (*option == '+')
4815 break;
4816 i++;
cristybb503372010-05-27 20:51:26 +00004817 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004818 ThrowMogrifyException(OptionError,"MissingArgument",option);
4819 if (IsGeometry(argv[i]) == MagickFalse)
4820 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4821 break;
4822 }
4823 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4824 }
4825 case 'k':
4826 {
4827 if (LocaleCompare("kerning",option+1) == 0)
4828 {
4829 if (*option == '+')
4830 break;
4831 i++;
cristybb503372010-05-27 20:51:26 +00004832 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004833 ThrowMogrifyException(OptionError,"MissingArgument",option);
4834 if (IsGeometry(argv[i]) == MagickFalse)
4835 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4836 break;
4837 }
4838 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4839 }
4840 case 'l':
4841 {
4842 if (LocaleCompare("label",option+1) == 0)
4843 {
4844 if (*option == '+')
4845 break;
4846 i++;
cristybb503372010-05-27 20:51:26 +00004847 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004848 ThrowMogrifyException(OptionError,"MissingArgument",option);
4849 break;
4850 }
4851 if (LocaleCompare("lat",option+1) == 0)
4852 {
4853 if (*option == '+')
4854 break;
4855 i++;
cristybb503372010-05-27 20:51:26 +00004856 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004857 ThrowMogrifyException(OptionError,"MissingArgument",option);
4858 if (IsGeometry(argv[i]) == MagickFalse)
4859 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4860 }
4861 if (LocaleCompare("layers",option+1) == 0)
4862 {
cristybb503372010-05-27 20:51:26 +00004863 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004864 type;
4865
4866 if (*option == '+')
4867 break;
4868 i++;
cristybb503372010-05-27 20:51:26 +00004869 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004870 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004871 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004872 if (type < 0)
4873 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4874 argv[i]);
4875 break;
4876 }
4877 if (LocaleCompare("level",option+1) == 0)
4878 {
4879 i++;
cristybb503372010-05-27 20:51:26 +00004880 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004881 ThrowMogrifyException(OptionError,"MissingArgument",option);
4882 if (IsGeometry(argv[i]) == MagickFalse)
4883 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4884 break;
4885 }
4886 if (LocaleCompare("level-colors",option+1) == 0)
4887 {
4888 i++;
cristybb503372010-05-27 20:51:26 +00004889 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004890 ThrowMogrifyException(OptionError,"MissingArgument",option);
4891 break;
4892 }
4893 if (LocaleCompare("linewidth",option+1) == 0)
4894 {
4895 if (*option == '+')
4896 break;
4897 i++;
cristybb503372010-05-27 20:51:26 +00004898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004899 ThrowMogrifyException(OptionError,"MissingArgument",option);
4900 if (IsGeometry(argv[i]) == MagickFalse)
4901 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4902 break;
4903 }
4904 if (LocaleCompare("limit",option+1) == 0)
4905 {
4906 char
4907 *p;
4908
4909 double
4910 value;
4911
cristybb503372010-05-27 20:51:26 +00004912 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004913 resource;
4914
4915 if (*option == '+')
4916 break;
4917 i++;
cristybb503372010-05-27 20:51:26 +00004918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004919 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004920 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004921 argv[i]);
4922 if (resource < 0)
4923 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4924 argv[i]);
4925 i++;
cristybb503372010-05-27 20:51:26 +00004926 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004927 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb51dff52011-05-19 16:55:47 +00004928 value=LocaleToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004929 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004930 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4931 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4932 break;
4933 }
4934 if (LocaleCompare("liquid-rescale",option+1) == 0)
4935 {
4936 i++;
cristybb503372010-05-27 20:51:26 +00004937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004938 ThrowMogrifyException(OptionError,"MissingArgument",option);
4939 if (IsGeometry(argv[i]) == MagickFalse)
4940 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4941 break;
4942 }
4943 if (LocaleCompare("list",option+1) == 0)
4944 {
cristybb503372010-05-27 20:51:26 +00004945 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004946 list;
4947
4948 if (*option == '+')
4949 break;
4950 i++;
cristybb503372010-05-27 20:51:26 +00004951 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004952 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004953 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004954 if (list < 0)
4955 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004956 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004957 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004958 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004959 }
4960 if (LocaleCompare("log",option+1) == 0)
4961 {
4962 if (*option == '+')
4963 break;
4964 i++;
cristybb503372010-05-27 20:51:26 +00004965 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004966 (strchr(argv[i],'%') == (char *) NULL))
4967 ThrowMogrifyException(OptionError,"MissingArgument",option);
4968 break;
4969 }
4970 if (LocaleCompare("loop",option+1) == 0)
4971 {
4972 if (*option == '+')
4973 break;
4974 i++;
cristybb503372010-05-27 20:51:26 +00004975 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004976 ThrowMogrifyException(OptionError,"MissingArgument",option);
4977 if (IsGeometry(argv[i]) == MagickFalse)
4978 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4979 break;
4980 }
4981 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4982 }
4983 case 'm':
4984 {
4985 if (LocaleCompare("map",option+1) == 0)
4986 {
4987 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4988 if (*option == '+')
4989 break;
4990 i++;
cristybb503372010-05-27 20:51:26 +00004991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004992 ThrowMogrifyException(OptionError,"MissingArgument",option);
4993 break;
4994 }
4995 if (LocaleCompare("mask",option+1) == 0)
4996 {
4997 if (*option == '+')
4998 break;
4999 i++;
cristybb503372010-05-27 20:51:26 +00005000 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005001 ThrowMogrifyException(OptionError,"MissingArgument",option);
5002 break;
5003 }
5004 if (LocaleCompare("matte",option+1) == 0)
5005 break;
5006 if (LocaleCompare("mattecolor",option+1) == 0)
5007 {
5008 if (*option == '+')
5009 break;
5010 i++;
cristybb503372010-05-27 20:51:26 +00005011 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005012 ThrowMogrifyException(OptionError,"MissingArgument",option);
5013 break;
5014 }
cristyf40785b2010-03-06 02:27:27 +00005015 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005016 break;
cristyf40785b2010-03-06 02:27:27 +00005017 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005018 break;
cristy3ed852e2009-09-05 21:47:34 +00005019 if (LocaleCompare("modulate",option+1) == 0)
5020 {
5021 if (*option == '+')
5022 break;
5023 i++;
cristybb503372010-05-27 20:51:26 +00005024 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005025 ThrowMogrifyException(OptionError,"MissingArgument",option);
5026 if (IsGeometry(argv[i]) == MagickFalse)
5027 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5028 break;
5029 }
5030 if (LocaleCompare("median",option+1) == 0)
5031 {
5032 if (*option == '+')
5033 break;
5034 i++;
cristybb503372010-05-27 20:51:26 +00005035 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005036 ThrowMogrifyException(OptionError,"MissingArgument",option);
5037 if (IsGeometry(argv[i]) == MagickFalse)
5038 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5039 break;
5040 }
cristy69ec32d2011-02-27 23:57:09 +00005041 if (LocaleCompare("mode",option+1) == 0)
5042 {
5043 if (*option == '+')
5044 break;
5045 i++;
5046 if (i == (ssize_t) argc)
5047 ThrowMogrifyException(OptionError,"MissingArgument",option);
5048 if (IsGeometry(argv[i]) == MagickFalse)
5049 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5050 break;
5051 }
cristy3ed852e2009-09-05 21:47:34 +00005052 if (LocaleCompare("monitor",option+1) == 0)
5053 break;
5054 if (LocaleCompare("monochrome",option+1) == 0)
5055 break;
5056 if (LocaleCompare("morph",option+1) == 0)
5057 {
5058 if (*option == '+')
5059 break;
5060 i++;
cristybb503372010-05-27 20:51:26 +00005061 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005062 ThrowMogrifyException(OptionError,"MissingArgument",option);
5063 if (IsGeometry(argv[i]) == MagickFalse)
5064 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5065 break;
5066 }
anthony29188a82010-01-22 10:12:34 +00005067 if (LocaleCompare("morphology",option+1) == 0)
5068 {
anthony29188a82010-01-22 10:12:34 +00005069 char
5070 token[MaxTextExtent];
5071
cristyb6bd4ad2010-08-08 01:12:27 +00005072 KernelInfo
5073 *kernel_info;
5074
5075 ssize_t
5076 op;
5077
anthony29188a82010-01-22 10:12:34 +00005078 i++;
cristybb503372010-05-27 20:51:26 +00005079 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005080 ThrowMogrifyException(OptionError,"MissingArgument",option);
5081 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005082 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005083 if (op < 0)
5084 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005085 token);
anthony29188a82010-01-22 10:12:34 +00005086 i++;
cristybb503372010-05-27 20:51:26 +00005087 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005088 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005089 kernel_info=AcquireKernelInfo(argv[i]);
5090 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005091 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005092 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005093 break;
5094 }
cristy3ed852e2009-09-05 21:47:34 +00005095 if (LocaleCompare("mosaic",option+1) == 0)
5096 break;
5097 if (LocaleCompare("motion-blur",option+1) == 0)
5098 {
5099 if (*option == '+')
5100 break;
5101 i++;
cristybb503372010-05-27 20:51:26 +00005102 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005103 ThrowMogrifyException(OptionError,"MissingArgument",option);
5104 if (IsGeometry(argv[i]) == MagickFalse)
5105 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5106 break;
5107 }
5108 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5109 }
5110 case 'n':
5111 {
5112 if (LocaleCompare("negate",option+1) == 0)
5113 break;
5114 if (LocaleCompare("noise",option+1) == 0)
5115 {
5116 i++;
cristybb503372010-05-27 20:51:26 +00005117 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005118 ThrowMogrifyException(OptionError,"MissingArgument",option);
5119 if (*option == '+')
5120 {
cristybb503372010-05-27 20:51:26 +00005121 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005122 noise;
5123
cristy042ee782011-04-22 18:48:30 +00005124 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005125 if (noise < 0)
5126 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5127 argv[i]);
5128 break;
5129 }
5130 if (IsGeometry(argv[i]) == MagickFalse)
5131 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5132 break;
5133 }
5134 if (LocaleCompare("noop",option+1) == 0)
5135 break;
5136 if (LocaleCompare("normalize",option+1) == 0)
5137 break;
5138 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5139 }
5140 case 'o':
5141 {
5142 if (LocaleCompare("opaque",option+1) == 0)
5143 {
cristy3ed852e2009-09-05 21:47:34 +00005144 i++;
cristybb503372010-05-27 20:51:26 +00005145 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005146 ThrowMogrifyException(OptionError,"MissingArgument",option);
5147 break;
5148 }
5149 if (LocaleCompare("ordered-dither",option+1) == 0)
5150 {
5151 if (*option == '+')
5152 break;
5153 i++;
cristybb503372010-05-27 20:51:26 +00005154 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005155 ThrowMogrifyException(OptionError,"MissingArgument",option);
5156 break;
5157 }
5158 if (LocaleCompare("orient",option+1) == 0)
5159 {
cristybb503372010-05-27 20:51:26 +00005160 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005161 orientation;
5162
5163 orientation=UndefinedOrientation;
5164 if (*option == '+')
5165 break;
5166 i++;
cristybb503372010-05-27 20:51:26 +00005167 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005168 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005169 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005170 argv[i]);
5171 if (orientation < 0)
5172 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5173 argv[i]);
5174 break;
5175 }
5176 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5177 }
5178 case 'p':
5179 {
5180 if (LocaleCompare("page",option+1) == 0)
5181 {
5182 if (*option == '+')
5183 break;
5184 i++;
cristybb503372010-05-27 20:51:26 +00005185 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005186 ThrowMogrifyException(OptionError,"MissingArgument",option);
5187 break;
5188 }
5189 if (LocaleCompare("paint",option+1) == 0)
5190 {
5191 if (*option == '+')
5192 break;
5193 i++;
cristybb503372010-05-27 20:51:26 +00005194 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005195 ThrowMogrifyException(OptionError,"MissingArgument",option);
5196 if (IsGeometry(argv[i]) == MagickFalse)
5197 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5198 break;
5199 }
5200 if (LocaleCompare("path",option+1) == 0)
5201 {
5202 (void) CloneString(&path,(char *) NULL);
5203 if (*option == '+')
5204 break;
5205 i++;
cristybb503372010-05-27 20:51:26 +00005206 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005207 ThrowMogrifyException(OptionError,"MissingArgument",option);
5208 (void) CloneString(&path,argv[i]);
5209 break;
5210 }
5211 if (LocaleCompare("pointsize",option+1) == 0)
5212 {
5213 if (*option == '+')
5214 break;
5215 i++;
cristybb503372010-05-27 20:51:26 +00005216 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005217 ThrowMogrifyException(OptionError,"MissingArgument",option);
5218 if (IsGeometry(argv[i]) == MagickFalse)
5219 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5220 break;
5221 }
5222 if (LocaleCompare("polaroid",option+1) == 0)
5223 {
5224 if (*option == '+')
5225 break;
5226 i++;
cristybb503372010-05-27 20:51:26 +00005227 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005228 ThrowMogrifyException(OptionError,"MissingArgument",option);
5229 if (IsGeometry(argv[i]) == MagickFalse)
5230 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5231 break;
5232 }
5233 if (LocaleCompare("posterize",option+1) == 0)
5234 {
5235 if (*option == '+')
5236 break;
5237 i++;
cristybb503372010-05-27 20:51:26 +00005238 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005239 ThrowMogrifyException(OptionError,"MissingArgument",option);
5240 if (IsGeometry(argv[i]) == MagickFalse)
5241 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5242 break;
5243 }
cristye7f51092010-01-17 00:39:37 +00005244 if (LocaleCompare("precision",option+1) == 0)
5245 {
5246 if (*option == '+')
5247 break;
5248 i++;
cristybb503372010-05-27 20:51:26 +00005249 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005250 ThrowMogrifyException(OptionError,"MissingArgument",option);
5251 if (IsGeometry(argv[i]) == MagickFalse)
5252 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5253 break;
5254 }
cristy3ed852e2009-09-05 21:47:34 +00005255 if (LocaleCompare("print",option+1) == 0)
5256 {
5257 if (*option == '+')
5258 break;
5259 i++;
cristybb503372010-05-27 20:51:26 +00005260 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005261 ThrowMogrifyException(OptionError,"MissingArgument",option);
5262 break;
5263 }
5264 if (LocaleCompare("process",option+1) == 0)
5265 {
5266 if (*option == '+')
5267 break;
5268 i++;
cristybb503372010-05-27 20:51:26 +00005269 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005270 ThrowMogrifyException(OptionError,"MissingArgument",option);
5271 break;
5272 }
5273 if (LocaleCompare("profile",option+1) == 0)
5274 {
5275 i++;
cristybb503372010-05-27 20:51:26 +00005276 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005277 ThrowMogrifyException(OptionError,"MissingArgument",option);
5278 break;
5279 }
5280 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5281 }
5282 case 'q':
5283 {
5284 if (LocaleCompare("quality",option+1) == 0)
5285 {
5286 if (*option == '+')
5287 break;
5288 i++;
cristybb503372010-05-27 20:51:26 +00005289 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005290 ThrowMogrifyException(OptionError,"MissingArgument",option);
5291 if (IsGeometry(argv[i]) == MagickFalse)
5292 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5293 break;
5294 }
5295 if (LocaleCompare("quantize",option+1) == 0)
5296 {
cristybb503372010-05-27 20:51:26 +00005297 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005298 colorspace;
5299
5300 if (*option == '+')
5301 break;
5302 i++;
cristybb503372010-05-27 20:51:26 +00005303 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005304 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005305 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005306 argv[i]);
5307 if (colorspace < 0)
5308 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5309 argv[i]);
5310 break;
5311 }
5312 if (LocaleCompare("quiet",option+1) == 0)
5313 break;
5314 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5315 }
5316 case 'r':
5317 {
5318 if (LocaleCompare("radial-blur",option+1) == 0)
5319 {
5320 i++;
cristybb503372010-05-27 20:51:26 +00005321 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005322 ThrowMogrifyException(OptionError,"MissingArgument",option);
5323 if (IsGeometry(argv[i]) == MagickFalse)
5324 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5325 break;
5326 }
5327 if (LocaleCompare("raise",option+1) == 0)
5328 {
5329 i++;
cristybb503372010-05-27 20:51:26 +00005330 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005331 ThrowMogrifyException(OptionError,"MissingArgument",option);
5332 if (IsGeometry(argv[i]) == MagickFalse)
5333 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5334 break;
5335 }
5336 if (LocaleCompare("random-threshold",option+1) == 0)
5337 {
5338 if (*option == '+')
5339 break;
5340 i++;
cristybb503372010-05-27 20:51:26 +00005341 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005342 ThrowMogrifyException(OptionError,"MissingArgument",option);
5343 if (IsGeometry(argv[i]) == MagickFalse)
5344 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5345 break;
5346 }
cristye6365592010-04-02 17:31:23 +00005347 if (LocaleCompare("recolor",option+1) == 0)
5348 {
5349 if (*option == '+')
5350 break;
5351 i++;
cristybb503372010-05-27 20:51:26 +00005352 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005353 ThrowMogrifyException(OptionError,"MissingArgument",option);
5354 if (IsGeometry(argv[i]) == MagickFalse)
5355 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5356 break;
5357 }
cristy3ed852e2009-09-05 21:47:34 +00005358 if (LocaleCompare("red-primary",option+1) == 0)
5359 {
5360 if (*option == '+')
5361 break;
5362 i++;
cristybb503372010-05-27 20:51:26 +00005363 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005364 ThrowMogrifyException(OptionError,"MissingArgument",option);
5365 if (IsGeometry(argv[i]) == MagickFalse)
5366 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5367 }
cristy9f2083a2010-04-22 19:48:05 +00005368 if (LocaleCompare("regard-warnings",option+1) == 0)
5369 break;
cristy3ed852e2009-09-05 21:47:34 +00005370 if (LocaleCompare("region",option+1) == 0)
5371 {
5372 if (*option == '+')
5373 break;
5374 i++;
cristybb503372010-05-27 20:51:26 +00005375 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005376 ThrowMogrifyException(OptionError,"MissingArgument",option);
5377 if (IsGeometry(argv[i]) == MagickFalse)
5378 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5379 break;
5380 }
cristyf0c78232010-03-15 12:53:40 +00005381 if (LocaleCompare("remap",option+1) == 0)
5382 {
5383 if (*option == '+')
5384 break;
5385 i++;
cristybb503372010-05-27 20:51:26 +00005386 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005387 ThrowMogrifyException(OptionError,"MissingArgument",option);
5388 break;
5389 }
cristy3ed852e2009-09-05 21:47:34 +00005390 if (LocaleCompare("render",option+1) == 0)
5391 break;
5392 if (LocaleCompare("repage",option+1) == 0)
5393 {
5394 if (*option == '+')
5395 break;
5396 i++;
cristybb503372010-05-27 20:51:26 +00005397 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005398 ThrowMogrifyException(OptionError,"MissingArgument",option);
5399 if (IsGeometry(argv[i]) == MagickFalse)
5400 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5401 break;
5402 }
5403 if (LocaleCompare("resample",option+1) == 0)
5404 {
5405 if (*option == '+')
5406 break;
5407 i++;
cristybb503372010-05-27 20:51:26 +00005408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005409 ThrowMogrifyException(OptionError,"MissingArgument",option);
5410 if (IsGeometry(argv[i]) == MagickFalse)
5411 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5412 break;
5413 }
5414 if (LocaleCompare("resize",option+1) == 0)
5415 {
5416 if (*option == '+')
5417 break;
5418 i++;
cristybb503372010-05-27 20:51:26 +00005419 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005420 ThrowMogrifyException(OptionError,"MissingArgument",option);
5421 if (IsGeometry(argv[i]) == MagickFalse)
5422 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5423 break;
5424 }
cristyebbcfea2011-02-25 02:43:54 +00005425 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5426 {
5427 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5428 break;
5429 }
cristy3ed852e2009-09-05 21:47:34 +00005430 if (LocaleCompare("reverse",option+1) == 0)
5431 break;
5432 if (LocaleCompare("roll",option+1) == 0)
5433 {
5434 if (*option == '+')
5435 break;
5436 i++;
cristybb503372010-05-27 20:51:26 +00005437 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005438 ThrowMogrifyException(OptionError,"MissingArgument",option);
5439 if (IsGeometry(argv[i]) == MagickFalse)
5440 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5441 break;
5442 }
5443 if (LocaleCompare("rotate",option+1) == 0)
5444 {
5445 i++;
cristybb503372010-05-27 20:51:26 +00005446 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005447 ThrowMogrifyException(OptionError,"MissingArgument",option);
5448 if (IsGeometry(argv[i]) == MagickFalse)
5449 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5450 break;
5451 }
5452 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5453 }
5454 case 's':
5455 {
5456 if (LocaleCompare("sample",option+1) == 0)
5457 {
5458 if (*option == '+')
5459 break;
5460 i++;
cristybb503372010-05-27 20:51:26 +00005461 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005462 ThrowMogrifyException(OptionError,"MissingArgument",option);
5463 if (IsGeometry(argv[i]) == MagickFalse)
5464 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5465 break;
5466 }
5467 if (LocaleCompare("sampling-factor",option+1) == 0)
5468 {
5469 if (*option == '+')
5470 break;
5471 i++;
cristybb503372010-05-27 20:51:26 +00005472 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005473 ThrowMogrifyException(OptionError,"MissingArgument",option);
5474 if (IsGeometry(argv[i]) == MagickFalse)
5475 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5476 break;
5477 }
5478 if (LocaleCompare("scale",option+1) == 0)
5479 {
5480 if (*option == '+')
5481 break;
5482 i++;
cristybb503372010-05-27 20:51:26 +00005483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005484 ThrowMogrifyException(OptionError,"MissingArgument",option);
5485 if (IsGeometry(argv[i]) == MagickFalse)
5486 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5487 break;
5488 }
5489 if (LocaleCompare("scene",option+1) == 0)
5490 {
5491 if (*option == '+')
5492 break;
5493 i++;
cristybb503372010-05-27 20:51:26 +00005494 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005495 ThrowMogrifyException(OptionError,"MissingArgument",option);
5496 if (IsGeometry(argv[i]) == MagickFalse)
5497 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5498 break;
5499 }
5500 if (LocaleCompare("seed",option+1) == 0)
5501 {
5502 if (*option == '+')
5503 break;
5504 i++;
cristybb503372010-05-27 20:51:26 +00005505 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005506 ThrowMogrifyException(OptionError,"MissingArgument",option);
5507 if (IsGeometry(argv[i]) == MagickFalse)
5508 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5509 break;
5510 }
5511 if (LocaleCompare("segment",option+1) == 0)
5512 {
5513 if (*option == '+')
5514 break;
5515 i++;
cristybb503372010-05-27 20:51:26 +00005516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005517 ThrowMogrifyException(OptionError,"MissingArgument",option);
5518 if (IsGeometry(argv[i]) == MagickFalse)
5519 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5520 break;
5521 }
5522 if (LocaleCompare("selective-blur",option+1) == 0)
5523 {
5524 i++;
cristybb503372010-05-27 20:51:26 +00005525 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005526 ThrowMogrifyException(OptionError,"MissingArgument",option);
5527 if (IsGeometry(argv[i]) == MagickFalse)
5528 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5529 break;
5530 }
5531 if (LocaleCompare("separate",option+1) == 0)
5532 break;
5533 if (LocaleCompare("sepia-tone",option+1) == 0)
5534 {
5535 if (*option == '+')
5536 break;
5537 i++;
cristybb503372010-05-27 20:51:26 +00005538 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005539 ThrowMogrifyException(OptionError,"MissingArgument",option);
5540 if (IsGeometry(argv[i]) == MagickFalse)
5541 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5542 break;
5543 }
5544 if (LocaleCompare("set",option+1) == 0)
5545 {
5546 i++;
cristybb503372010-05-27 20:51:26 +00005547 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005548 ThrowMogrifyException(OptionError,"MissingArgument",option);
5549 if (*option == '+')
5550 break;
5551 i++;
cristybb503372010-05-27 20:51:26 +00005552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005553 ThrowMogrifyException(OptionError,"MissingArgument",option);
5554 break;
5555 }
5556 if (LocaleCompare("shade",option+1) == 0)
5557 {
5558 i++;
cristybb503372010-05-27 20:51:26 +00005559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005560 ThrowMogrifyException(OptionError,"MissingArgument",option);
5561 if (IsGeometry(argv[i]) == MagickFalse)
5562 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5563 break;
5564 }
5565 if (LocaleCompare("shadow",option+1) == 0)
5566 {
5567 if (*option == '+')
5568 break;
5569 i++;
cristybb503372010-05-27 20:51:26 +00005570 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005571 ThrowMogrifyException(OptionError,"MissingArgument",option);
5572 if (IsGeometry(argv[i]) == MagickFalse)
5573 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5574 break;
5575 }
5576 if (LocaleCompare("sharpen",option+1) == 0)
5577 {
5578 i++;
cristybb503372010-05-27 20:51:26 +00005579 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005580 ThrowMogrifyException(OptionError,"MissingArgument",option);
5581 if (IsGeometry(argv[i]) == MagickFalse)
5582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5583 break;
5584 }
5585 if (LocaleCompare("shave",option+1) == 0)
5586 {
5587 if (*option == '+')
5588 break;
5589 i++;
cristybb503372010-05-27 20:51:26 +00005590 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005591 ThrowMogrifyException(OptionError,"MissingArgument",option);
5592 if (IsGeometry(argv[i]) == MagickFalse)
5593 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5594 break;
5595 }
5596 if (LocaleCompare("shear",option+1) == 0)
5597 {
5598 i++;
cristybb503372010-05-27 20:51:26 +00005599 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005600 ThrowMogrifyException(OptionError,"MissingArgument",option);
5601 if (IsGeometry(argv[i]) == MagickFalse)
5602 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5603 break;
5604 }
5605 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5606 {
5607 i++;
cristybb503372010-05-27 20:51:26 +00005608 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005609 ThrowMogrifyException(OptionError,"MissingArgument",option);
5610 if (IsGeometry(argv[i]) == MagickFalse)
5611 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5612 break;
5613 }
5614 if (LocaleCompare("size",option+1) == 0)
5615 {
5616 if (*option == '+')
5617 break;
5618 i++;
cristybb503372010-05-27 20:51:26 +00005619 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005620 ThrowMogrifyException(OptionError,"MissingArgument",option);
5621 if (IsGeometry(argv[i]) == MagickFalse)
5622 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5623 break;
5624 }
5625 if (LocaleCompare("sketch",option+1) == 0)
5626 {
5627 if (*option == '+')
5628 break;
5629 i++;
cristybb503372010-05-27 20:51:26 +00005630 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005631 ThrowMogrifyException(OptionError,"MissingArgument",option);
5632 if (IsGeometry(argv[i]) == MagickFalse)
5633 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5634 break;
5635 }
cristy4285d782011-02-09 20:12:28 +00005636 if (LocaleCompare("smush",option+1) == 0)
5637 {
cristy4285d782011-02-09 20:12:28 +00005638 i++;
5639 if (i == (ssize_t) argc)
5640 ThrowMogrifyException(OptionError,"MissingArgument",option);
5641 if (IsGeometry(argv[i]) == MagickFalse)
5642 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005643 i++;
5644 break;
5645 }
cristy3ed852e2009-09-05 21:47:34 +00005646 if (LocaleCompare("solarize",option+1) == 0)
5647 {
5648 if (*option == '+')
5649 break;
5650 i++;
cristybb503372010-05-27 20:51:26 +00005651 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005652 ThrowMogrifyException(OptionError,"MissingArgument",option);
5653 if (IsGeometry(argv[i]) == MagickFalse)
5654 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5655 break;
5656 }
5657 if (LocaleCompare("sparse-color",option+1) == 0)
5658 {
cristybb503372010-05-27 20:51:26 +00005659 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005660 op;
5661
5662 i++;
cristybb503372010-05-27 20:51:26 +00005663 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005664 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005665 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005666 if (op < 0)
5667 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5668 argv[i]);
5669 i++;
cristybb503372010-05-27 20:51:26 +00005670 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005671 ThrowMogrifyException(OptionError,"MissingArgument",option);
5672 break;
5673 }
5674 if (LocaleCompare("spread",option+1) == 0)
5675 {
5676 if (*option == '+')
5677 break;
5678 i++;
cristybb503372010-05-27 20:51:26 +00005679 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005680 ThrowMogrifyException(OptionError,"MissingArgument",option);
5681 if (IsGeometry(argv[i]) == MagickFalse)
5682 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5683 break;
5684 }
cristy0834d642011-03-18 18:26:08 +00005685 if (LocaleCompare("statistic",option+1) == 0)
5686 {
5687 ssize_t
5688 op;
5689
5690 if (*option == '+')
5691 break;
5692 i++;
5693 if (i == (ssize_t) argc)
5694 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005695 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005696 if (op < 0)
5697 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5698 argv[i]);
5699 i++;
5700 if (i == (ssize_t) (argc-1))
5701 ThrowMogrifyException(OptionError,"MissingArgument",option);
5702 if (IsGeometry(argv[i]) == MagickFalse)
5703 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5704 break;
5705 }
cristy3ed852e2009-09-05 21:47:34 +00005706 if (LocaleCompare("stretch",option+1) == 0)
5707 {
cristybb503372010-05-27 20:51:26 +00005708 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005709 stretch;
5710
5711 if (*option == '+')
5712 break;
5713 i++;
cristybb503372010-05-27 20:51:26 +00005714 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005715 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005716 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005717 if (stretch < 0)
5718 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5719 argv[i]);
5720 break;
5721 }
5722 if (LocaleCompare("strip",option+1) == 0)
5723 break;
5724 if (LocaleCompare("stroke",option+1) == 0)
5725 {
5726 if (*option == '+')
5727 break;
5728 i++;
cristybb503372010-05-27 20:51:26 +00005729 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005730 ThrowMogrifyException(OptionError,"MissingArgument",option);
5731 break;
5732 }
5733 if (LocaleCompare("strokewidth",option+1) == 0)
5734 {
5735 if (*option == '+')
5736 break;
5737 i++;
cristybb503372010-05-27 20:51:26 +00005738 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005739 ThrowMogrifyException(OptionError,"MissingArgument",option);
5740 if (IsGeometry(argv[i]) == MagickFalse)
5741 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5742 break;
5743 }
5744 if (LocaleCompare("style",option+1) == 0)
5745 {
cristybb503372010-05-27 20:51:26 +00005746 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005747 style;
5748
5749 if (*option == '+')
5750 break;
5751 i++;
cristybb503372010-05-27 20:51:26 +00005752 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005753 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005754 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005755 if (style < 0)
5756 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5757 argv[i]);
5758 break;
5759 }
cristyecb10ff2011-03-22 13:14:03 +00005760 if (LocaleCompare("swap",option+1) == 0)
5761 {
5762 if (*option == '+')
5763 break;
5764 i++;
5765 if (i == (ssize_t) (argc-1))
5766 ThrowMogrifyException(OptionError,"MissingArgument",option);
5767 if (IsGeometry(argv[i]) == MagickFalse)
5768 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5769 break;
5770 }
cristy3ed852e2009-09-05 21:47:34 +00005771 if (LocaleCompare("swirl",option+1) == 0)
5772 {
5773 if (*option == '+')
5774 break;
5775 i++;
cristybb503372010-05-27 20:51:26 +00005776 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005777 ThrowMogrifyException(OptionError,"MissingArgument",option);
5778 if (IsGeometry(argv[i]) == MagickFalse)
5779 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5780 break;
5781 }
cristyd9a29192010-10-16 16:49:53 +00005782 if (LocaleCompare("synchronize",option+1) == 0)
5783 break;
cristy3ed852e2009-09-05 21:47:34 +00005784 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5785 }
5786 case 't':
5787 {
5788 if (LocaleCompare("taint",option+1) == 0)
5789 break;
5790 if (LocaleCompare("texture",option+1) == 0)
5791 {
5792 if (*option == '+')
5793 break;
5794 i++;
cristybb503372010-05-27 20:51:26 +00005795 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005796 ThrowMogrifyException(OptionError,"MissingArgument",option);
5797 break;
5798 }
5799 if (LocaleCompare("tile",option+1) == 0)
5800 {
5801 if (*option == '+')
5802 break;
5803 i++;
cristybb503372010-05-27 20:51:26 +00005804 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005805 ThrowMogrifyException(OptionError,"MissingArgument",option);
5806 break;
5807 }
5808 if (LocaleCompare("tile-offset",option+1) == 0)
5809 {
5810 if (*option == '+')
5811 break;
5812 i++;
cristybb503372010-05-27 20:51:26 +00005813 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005814 ThrowMogrifyException(OptionError,"MissingArgument",option);
5815 if (IsGeometry(argv[i]) == MagickFalse)
5816 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5817 break;
5818 }
5819 if (LocaleCompare("tint",option+1) == 0)
5820 {
5821 if (*option == '+')
5822 break;
5823 i++;
cristybb503372010-05-27 20:51:26 +00005824 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005825 ThrowMogrifyException(OptionError,"MissingArgument",option);
5826 if (IsGeometry(argv[i]) == MagickFalse)
5827 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5828 break;
5829 }
5830 if (LocaleCompare("transform",option+1) == 0)
5831 break;
5832 if (LocaleCompare("transpose",option+1) == 0)
5833 break;
5834 if (LocaleCompare("transverse",option+1) == 0)
5835 break;
5836 if (LocaleCompare("threshold",option+1) == 0)
5837 {
5838 if (*option == '+')
5839 break;
5840 i++;
cristybb503372010-05-27 20:51:26 +00005841 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005842 ThrowMogrifyException(OptionError,"MissingArgument",option);
5843 if (IsGeometry(argv[i]) == MagickFalse)
5844 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5845 break;
5846 }
5847 if (LocaleCompare("thumbnail",option+1) == 0)
5848 {
5849 if (*option == '+')
5850 break;
5851 i++;
cristybb503372010-05-27 20:51:26 +00005852 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005853 ThrowMogrifyException(OptionError,"MissingArgument",option);
5854 if (IsGeometry(argv[i]) == MagickFalse)
5855 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5856 break;
5857 }
5858 if (LocaleCompare("transparent",option+1) == 0)
5859 {
5860 i++;
cristybb503372010-05-27 20:51:26 +00005861 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005862 ThrowMogrifyException(OptionError,"MissingArgument",option);
5863 break;
5864 }
5865 if (LocaleCompare("transparent-color",option+1) == 0)
5866 {
5867 if (*option == '+')
5868 break;
5869 i++;
cristybb503372010-05-27 20:51:26 +00005870 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005871 ThrowMogrifyException(OptionError,"MissingArgument",option);
5872 break;
5873 }
5874 if (LocaleCompare("treedepth",option+1) == 0)
5875 {
5876 if (*option == '+')
5877 break;
5878 i++;
cristybb503372010-05-27 20:51:26 +00005879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005880 ThrowMogrifyException(OptionError,"MissingArgument",option);
5881 if (IsGeometry(argv[i]) == MagickFalse)
5882 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5883 break;
5884 }
5885 if (LocaleCompare("trim",option+1) == 0)
5886 break;
5887 if (LocaleCompare("type",option+1) == 0)
5888 {
cristybb503372010-05-27 20:51:26 +00005889 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005890 type;
5891
5892 if (*option == '+')
5893 break;
5894 i++;
cristybb503372010-05-27 20:51:26 +00005895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005896 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005897 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005898 if (type < 0)
5899 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5900 argv[i]);
5901 break;
5902 }
5903 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5904 }
5905 case 'u':
5906 {
5907 if (LocaleCompare("undercolor",option+1) == 0)
5908 {
5909 if (*option == '+')
5910 break;
5911 i++;
cristybb503372010-05-27 20:51:26 +00005912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005913 ThrowMogrifyException(OptionError,"MissingArgument",option);
5914 break;
5915 }
5916 if (LocaleCompare("unique-colors",option+1) == 0)
5917 break;
5918 if (LocaleCompare("units",option+1) == 0)
5919 {
cristybb503372010-05-27 20:51:26 +00005920 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005921 units;
5922
5923 if (*option == '+')
5924 break;
5925 i++;
cristybb503372010-05-27 20:51:26 +00005926 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005927 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005928 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005929 argv[i]);
5930 if (units < 0)
5931 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5932 argv[i]);
5933 break;
5934 }
5935 if (LocaleCompare("unsharp",option+1) == 0)
5936 {
5937 i++;
cristybb503372010-05-27 20:51:26 +00005938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005939 ThrowMogrifyException(OptionError,"MissingArgument",option);
5940 if (IsGeometry(argv[i]) == MagickFalse)
5941 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5942 break;
5943 }
5944 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5945 }
5946 case 'v':
5947 {
5948 if (LocaleCompare("verbose",option+1) == 0)
5949 {
5950 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5951 break;
5952 }
5953 if ((LocaleCompare("version",option+1) == 0) ||
5954 (LocaleCompare("-version",option+1) == 0))
5955 {
cristyb51dff52011-05-19 16:55:47 +00005956 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005957 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005958 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5959 GetMagickCopyright());
5960 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5961 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005962 break;
5963 }
5964 if (LocaleCompare("view",option+1) == 0)
5965 {
5966 if (*option == '+')
5967 break;
5968 i++;
cristybb503372010-05-27 20:51:26 +00005969 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005970 ThrowMogrifyException(OptionError,"MissingArgument",option);
5971 break;
5972 }
5973 if (LocaleCompare("vignette",option+1) == 0)
5974 {
5975 if (*option == '+')
5976 break;
5977 i++;
cristybb503372010-05-27 20:51:26 +00005978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005979 ThrowMogrifyException(OptionError,"MissingArgument",option);
5980 if (IsGeometry(argv[i]) == MagickFalse)
5981 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5982 break;
5983 }
5984 if (LocaleCompare("virtual-pixel",option+1) == 0)
5985 {
cristybb503372010-05-27 20:51:26 +00005986 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005987 method;
5988
5989 if (*option == '+')
5990 break;
5991 i++;
cristybb503372010-05-27 20:51:26 +00005992 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005993 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005994 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005995 argv[i]);
5996 if (method < 0)
5997 ThrowMogrifyException(OptionError,
5998 "UnrecognizedVirtualPixelMethod",argv[i]);
5999 break;
6000 }
6001 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6002 }
6003 case 'w':
6004 {
6005 if (LocaleCompare("wave",option+1) == 0)
6006 {
6007 i++;
cristybb503372010-05-27 20:51:26 +00006008 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006009 ThrowMogrifyException(OptionError,"MissingArgument",option);
6010 if (IsGeometry(argv[i]) == MagickFalse)
6011 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6012 break;
6013 }
6014 if (LocaleCompare("weight",option+1) == 0)
6015 {
6016 if (*option == '+')
6017 break;
6018 i++;
cristybb503372010-05-27 20:51:26 +00006019 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006020 ThrowMogrifyException(OptionError,"MissingArgument",option);
6021 break;
6022 }
6023 if (LocaleCompare("white-point",option+1) == 0)
6024 {
6025 if (*option == '+')
6026 break;
6027 i++;
cristybb503372010-05-27 20:51:26 +00006028 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006029 ThrowMogrifyException(OptionError,"MissingArgument",option);
6030 if (IsGeometry(argv[i]) == MagickFalse)
6031 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6032 break;
6033 }
6034 if (LocaleCompare("white-threshold",option+1) == 0)
6035 {
6036 if (*option == '+')
6037 break;
6038 i++;
cristybb503372010-05-27 20:51:26 +00006039 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006040 ThrowMogrifyException(OptionError,"MissingArgument",option);
6041 if (IsGeometry(argv[i]) == MagickFalse)
6042 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6043 break;
6044 }
6045 if (LocaleCompare("write",option+1) == 0)
6046 {
6047 i++;
cristybb503372010-05-27 20:51:26 +00006048 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006049 ThrowMogrifyException(OptionError,"MissingArgument",option);
6050 break;
6051 }
6052 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6053 }
6054 case '?':
6055 break;
6056 default:
6057 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6058 }
cristy042ee782011-04-22 18:48:30 +00006059 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6060 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006061 if (fire != MagickFalse)
6062 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6063 }
6064 if (k != 0)
6065 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006066 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006067 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6068 DestroyMogrify();
6069 return(status != 0 ? MagickTrue : MagickFalse);
6070}
6071
6072/*
6073%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6074% %
6075% %
6076% %
6077+ M o g r i f y I m a g e I n f o %
6078% %
6079% %
6080% %
6081%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6082%
6083% MogrifyImageInfo() applies image processing settings to the image as
6084% prescribed by command line options.
6085%
6086% The format of the MogrifyImageInfo method is:
6087%
6088% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6089% const char **argv,ExceptionInfo *exception)
6090%
6091% A description of each parameter follows:
6092%
6093% o image_info: the image info..
6094%
6095% o argc: Specifies a pointer to an integer describing the number of
6096% elements in the argument vector.
6097%
6098% o argv: Specifies a pointer to a text array containing the command line
6099% arguments.
6100%
6101% o exception: return any errors or warnings in this structure.
6102%
6103*/
6104WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6105 const int argc,const char **argv,ExceptionInfo *exception)
6106{
6107 const char
6108 *option;
6109
6110 GeometryInfo
6111 geometry_info;
6112
cristybb503372010-05-27 20:51:26 +00006113 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006114 count;
6115
cristybb503372010-05-27 20:51:26 +00006116 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006117 i;
6118
6119 /*
6120 Initialize method variables.
6121 */
6122 assert(image_info != (ImageInfo *) NULL);
6123 assert(image_info->signature == MagickSignature);
6124 if (image_info->debug != MagickFalse)
6125 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6126 image_info->filename);
6127 if (argc < 0)
6128 return(MagickTrue);
6129 /*
6130 Set the image settings.
6131 */
cristybb503372010-05-27 20:51:26 +00006132 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006133 {
6134 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006135 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006136 continue;
cristy042ee782011-04-22 18:48:30 +00006137 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006138 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006139 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006140 break;
6141 switch (*(option+1))
6142 {
6143 case 'a':
6144 {
6145 if (LocaleCompare("adjoin",option+1) == 0)
6146 {
6147 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6148 break;
6149 }
6150 if (LocaleCompare("antialias",option+1) == 0)
6151 {
6152 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6153 break;
6154 }
6155 if (LocaleCompare("attenuate",option+1) == 0)
6156 {
6157 if (*option == '+')
6158 {
6159 (void) DeleteImageOption(image_info,option+1);
6160 break;
6161 }
6162 (void) SetImageOption(image_info,option+1,argv[i+1]);
6163 break;
6164 }
6165 if (LocaleCompare("authenticate",option+1) == 0)
6166 {
6167 if (*option == '+')
6168 (void) CloneString(&image_info->authenticate,(char *) NULL);
6169 else
6170 (void) CloneString(&image_info->authenticate,argv[i+1]);
6171 break;
6172 }
6173 break;
6174 }
6175 case 'b':
6176 {
6177 if (LocaleCompare("background",option+1) == 0)
6178 {
6179 if (*option == '+')
6180 {
6181 (void) DeleteImageOption(image_info,option+1);
6182 (void) QueryColorDatabase(BackgroundColor,
6183 &image_info->background_color,exception);
6184 break;
6185 }
6186 (void) SetImageOption(image_info,option+1,argv[i+1]);
6187 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6188 exception);
6189 break;
6190 }
6191 if (LocaleCompare("bias",option+1) == 0)
6192 {
6193 if (*option == '+')
6194 {
6195 (void) SetImageOption(image_info,option+1,"0.0");
6196 break;
6197 }
6198 (void) SetImageOption(image_info,option+1,argv[i+1]);
6199 break;
6200 }
6201 if (LocaleCompare("black-point-compensation",option+1) == 0)
6202 {
6203 if (*option == '+')
6204 {
6205 (void) SetImageOption(image_info,option+1,"false");
6206 break;
6207 }
6208 (void) SetImageOption(image_info,option+1,"true");
6209 break;
6210 }
6211 if (LocaleCompare("blue-primary",option+1) == 0)
6212 {
6213 if (*option == '+')
6214 {
6215 (void) SetImageOption(image_info,option+1,"0.0");
6216 break;
6217 }
6218 (void) SetImageOption(image_info,option+1,argv[i+1]);
6219 break;
6220 }
6221 if (LocaleCompare("bordercolor",option+1) == 0)
6222 {
6223 if (*option == '+')
6224 {
6225 (void) DeleteImageOption(image_info,option+1);
6226 (void) QueryColorDatabase(BorderColor,&image_info->border_color,
6227 exception);
6228 break;
6229 }
6230 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6231 exception);
6232 (void) SetImageOption(image_info,option+1,argv[i+1]);
6233 break;
6234 }
6235 if (LocaleCompare("box",option+1) == 0)
6236 {
6237 if (*option == '+')
6238 {
6239 (void) SetImageOption(image_info,"undercolor","none");
6240 break;
6241 }
6242 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6243 break;
6244 }
6245 break;
6246 }
6247 case 'c':
6248 {
6249 if (LocaleCompare("cache",option+1) == 0)
6250 {
6251 MagickSizeType
6252 limit;
6253
6254 limit=MagickResourceInfinity;
6255 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006256 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006257 (void) SetMagickResourceLimit(MemoryResource,limit);
6258 (void) SetMagickResourceLimit(MapResource,2*limit);
6259 break;
6260 }
6261 if (LocaleCompare("caption",option+1) == 0)
6262 {
6263 if (*option == '+')
6264 {
6265 (void) DeleteImageOption(image_info,option+1);
6266 break;
6267 }
6268 (void) SetImageOption(image_info,option+1,argv[i+1]);
6269 break;
6270 }
6271 if (LocaleCompare("channel",option+1) == 0)
6272 {
6273 if (*option == '+')
6274 {
6275 image_info->channel=DefaultChannels;
6276 break;
6277 }
6278 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6279 break;
6280 }
6281 if (LocaleCompare("colors",option+1) == 0)
6282 {
cristye27293e2009-12-18 02:53:20 +00006283 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006284 break;
6285 }
6286 if (LocaleCompare("colorspace",option+1) == 0)
6287 {
6288 if (*option == '+')
6289 {
6290 image_info->colorspace=UndefinedColorspace;
6291 (void) SetImageOption(image_info,option+1,"undefined");
6292 break;
6293 }
cristy042ee782011-04-22 18:48:30 +00006294 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006295 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6296 (void) SetImageOption(image_info,option+1,argv[i+1]);
6297 break;
6298 }
cristy3ed852e2009-09-05 21:47:34 +00006299 if (LocaleCompare("comment",option+1) == 0)
6300 {
6301 if (*option == '+')
6302 {
6303 (void) DeleteImageOption(image_info,option+1);
6304 break;
6305 }
6306 (void) SetImageOption(image_info,option+1,argv[i+1]);
6307 break;
6308 }
6309 if (LocaleCompare("compose",option+1) == 0)
6310 {
6311 if (*option == '+')
6312 {
6313 (void) SetImageOption(image_info,option+1,"undefined");
6314 break;
6315 }
6316 (void) SetImageOption(image_info,option+1,argv[i+1]);
6317 break;
6318 }
6319 if (LocaleCompare("compress",option+1) == 0)
6320 {
6321 if (*option == '+')
6322 {
6323 image_info->compression=UndefinedCompression;
6324 (void) SetImageOption(image_info,option+1,"undefined");
6325 break;
6326 }
cristy042ee782011-04-22 18:48:30 +00006327 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006328 MagickCompressOptions,MagickFalse,argv[i+1]);
6329 (void) SetImageOption(image_info,option+1,argv[i+1]);
6330 break;
6331 }
6332 break;
6333 }
6334 case 'd':
6335 {
6336 if (LocaleCompare("debug",option+1) == 0)
6337 {
6338 if (*option == '+')
6339 (void) SetLogEventMask("none");
6340 else
6341 (void) SetLogEventMask(argv[i+1]);
6342 image_info->debug=IsEventLogging();
6343 break;
6344 }
6345 if (LocaleCompare("define",option+1) == 0)
6346 {
6347 if (*option == '+')
6348 {
6349 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6350 (void) DeleteImageRegistry(argv[i+1]+9);
6351 else
6352 (void) DeleteImageOption(image_info,argv[i+1]);
6353 break;
6354 }
6355 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6356 {
6357 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6358 exception);
6359 break;
6360 }
6361 (void) DefineImageOption(image_info,argv[i+1]);
6362 break;
6363 }
6364 if (LocaleCompare("delay",option+1) == 0)
6365 {
6366 if (*option == '+')
6367 {
6368 (void) SetImageOption(image_info,option+1,"0");
6369 break;
6370 }
6371 (void) SetImageOption(image_info,option+1,argv[i+1]);
6372 break;
6373 }
6374 if (LocaleCompare("density",option+1) == 0)
6375 {
6376 /*
6377 Set image density.
6378 */
6379 if (*option == '+')
6380 {
6381 if (image_info->density != (char *) NULL)
6382 image_info->density=DestroyString(image_info->density);
6383 (void) SetImageOption(image_info,option+1,"72");
6384 break;
6385 }
6386 (void) CloneString(&image_info->density,argv[i+1]);
6387 (void) SetImageOption(image_info,option+1,argv[i+1]);
6388 break;
6389 }
6390 if (LocaleCompare("depth",option+1) == 0)
6391 {
6392 if (*option == '+')
6393 {
6394 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6395 break;
6396 }
cristye27293e2009-12-18 02:53:20 +00006397 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006398 break;
6399 }
cristyc9b12952010-03-28 01:12:28 +00006400 if (LocaleCompare("direction",option+1) == 0)
6401 {
6402 if (*option == '+')
6403 {
6404 (void) SetImageOption(image_info,option+1,"undefined");
6405 break;
6406 }
6407 (void) SetImageOption(image_info,option+1,argv[i+1]);
6408 break;
6409 }
cristy3ed852e2009-09-05 21:47:34 +00006410 if (LocaleCompare("display",option+1) == 0)
6411 {
6412 if (*option == '+')
6413 {
6414 if (image_info->server_name != (char *) NULL)
6415 image_info->server_name=DestroyString(
6416 image_info->server_name);
6417 break;
6418 }
6419 (void) CloneString(&image_info->server_name,argv[i+1]);
6420 break;
6421 }
6422 if (LocaleCompare("dispose",option+1) == 0)
6423 {
6424 if (*option == '+')
6425 {
6426 (void) SetImageOption(image_info,option+1,"undefined");
6427 break;
6428 }
6429 (void) SetImageOption(image_info,option+1,argv[i+1]);
6430 break;
6431 }
6432 if (LocaleCompare("dither",option+1) == 0)
6433 {
6434 if (*option == '+')
6435 {
6436 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006437 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006438 break;
6439 }
6440 (void) SetImageOption(image_info,option+1,argv[i+1]);
6441 image_info->dither=MagickTrue;
6442 break;
6443 }
6444 break;
6445 }
6446 case 'e':
6447 {
6448 if (LocaleCompare("encoding",option+1) == 0)
6449 {
6450 if (*option == '+')
6451 {
6452 (void) SetImageOption(image_info,option+1,"undefined");
6453 break;
6454 }
6455 (void) SetImageOption(image_info,option+1,argv[i+1]);
6456 break;
6457 }
6458 if (LocaleCompare("endian",option+1) == 0)
6459 {
6460 if (*option == '+')
6461 {
6462 image_info->endian=UndefinedEndian;
6463 (void) SetImageOption(image_info,option+1,"undefined");
6464 break;
6465 }
cristy042ee782011-04-22 18:48:30 +00006466 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006467 MagickEndianOptions,MagickFalse,argv[i+1]);
6468 (void) SetImageOption(image_info,option+1,argv[i+1]);
6469 break;
6470 }
6471 if (LocaleCompare("extract",option+1) == 0)
6472 {
6473 /*
6474 Set image extract geometry.
6475 */
6476 if (*option == '+')
6477 {
6478 if (image_info->extract != (char *) NULL)
6479 image_info->extract=DestroyString(image_info->extract);
6480 break;
6481 }
6482 (void) CloneString(&image_info->extract,argv[i+1]);
6483 break;
6484 }
6485 break;
6486 }
6487 case 'f':
6488 {
6489 if (LocaleCompare("fill",option+1) == 0)
6490 {
6491 if (*option == '+')
6492 {
6493 (void) SetImageOption(image_info,option+1,"none");
6494 break;
6495 }
6496 (void) SetImageOption(image_info,option+1,argv[i+1]);
6497 break;
6498 }
6499 if (LocaleCompare("filter",option+1) == 0)
6500 {
6501 if (*option == '+')
6502 {
6503 (void) SetImageOption(image_info,option+1,"undefined");
6504 break;
6505 }
6506 (void) SetImageOption(image_info,option+1,argv[i+1]);
6507 break;
6508 }
6509 if (LocaleCompare("font",option+1) == 0)
6510 {
6511 if (*option == '+')
6512 {
6513 if (image_info->font != (char *) NULL)
6514 image_info->font=DestroyString(image_info->font);
6515 break;
6516 }
6517 (void) CloneString(&image_info->font,argv[i+1]);
6518 break;
6519 }
6520 if (LocaleCompare("format",option+1) == 0)
6521 {
6522 register const char
6523 *q;
6524
6525 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006526 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006527 image_info->ping=MagickFalse;
6528 (void) SetImageOption(image_info,option+1,argv[i+1]);
6529 break;
6530 }
6531 if (LocaleCompare("fuzz",option+1) == 0)
6532 {
6533 if (*option == '+')
6534 {
6535 image_info->fuzz=0.0;
6536 (void) SetImageOption(image_info,option+1,"0");
6537 break;
6538 }
cristyf2f27272009-12-17 14:48:46 +00006539 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006540 1.0);
6541 (void) SetImageOption(image_info,option+1,argv[i+1]);
6542 break;
6543 }
6544 break;
6545 }
6546 case 'g':
6547 {
6548 if (LocaleCompare("gravity",option+1) == 0)
6549 {
6550 if (*option == '+')
6551 {
6552 (void) SetImageOption(image_info,option+1,"undefined");
6553 break;
6554 }
6555 (void) SetImageOption(image_info,option+1,argv[i+1]);
6556 break;
6557 }
6558 if (LocaleCompare("green-primary",option+1) == 0)
6559 {
6560 if (*option == '+')
6561 {
6562 (void) SetImageOption(image_info,option+1,"0.0");
6563 break;
6564 }
6565 (void) SetImageOption(image_info,option+1,argv[i+1]);
6566 break;
6567 }
6568 break;
6569 }
6570 case 'i':
6571 {
6572 if (LocaleCompare("intent",option+1) == 0)
6573 {
6574 if (*option == '+')
6575 {
6576 (void) SetImageOption(image_info,option+1,"undefined");
6577 break;
6578 }
6579 (void) SetImageOption(image_info,option+1,argv[i+1]);
6580 break;
6581 }
6582 if (LocaleCompare("interlace",option+1) == 0)
6583 {
6584 if (*option == '+')
6585 {
6586 image_info->interlace=UndefinedInterlace;
6587 (void) SetImageOption(image_info,option+1,"undefined");
6588 break;
6589 }
cristy042ee782011-04-22 18:48:30 +00006590 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006591 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6592 (void) SetImageOption(image_info,option+1,argv[i+1]);
6593 break;
6594 }
cristyb32b90a2009-09-07 21:45:48 +00006595 if (LocaleCompare("interline-spacing",option+1) == 0)
6596 {
6597 if (*option == '+')
6598 {
6599 (void) SetImageOption(image_info,option+1,"undefined");
6600 break;
6601 }
6602 (void) SetImageOption(image_info,option+1,argv[i+1]);
6603 break;
6604 }
cristy3ed852e2009-09-05 21:47:34 +00006605 if (LocaleCompare("interpolate",option+1) == 0)
6606 {
6607 if (*option == '+')
6608 {
6609 (void) SetImageOption(image_info,option+1,"undefined");
6610 break;
6611 }
6612 (void) SetImageOption(image_info,option+1,argv[i+1]);
6613 break;
6614 }
6615 if (LocaleCompare("interword-spacing",option+1) == 0)
6616 {
6617 if (*option == '+')
6618 {
6619 (void) SetImageOption(image_info,option+1,"undefined");
6620 break;
6621 }
6622 (void) SetImageOption(image_info,option+1,argv[i+1]);
6623 break;
6624 }
6625 break;
6626 }
6627 case 'k':
6628 {
6629 if (LocaleCompare("kerning",option+1) == 0)
6630 {
6631 if (*option == '+')
6632 {
6633 (void) SetImageOption(image_info,option+1,"undefined");
6634 break;
6635 }
6636 (void) SetImageOption(image_info,option+1,argv[i+1]);
6637 break;
6638 }
6639 break;
6640 }
6641 case 'l':
6642 {
6643 if (LocaleCompare("label",option+1) == 0)
6644 {
6645 if (*option == '+')
6646 {
6647 (void) DeleteImageOption(image_info,option+1);
6648 break;
6649 }
6650 (void) SetImageOption(image_info,option+1,argv[i+1]);
6651 break;
6652 }
6653 if (LocaleCompare("limit",option+1) == 0)
6654 {
6655 MagickSizeType
6656 limit;
6657
6658 ResourceType
6659 type;
6660
6661 if (*option == '+')
6662 break;
cristy042ee782011-04-22 18:48:30 +00006663 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006664 MagickFalse,argv[i+1]);
6665 limit=MagickResourceInfinity;
6666 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006667 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006668 (void) SetMagickResourceLimit(type,limit);
6669 break;
6670 }
6671 if (LocaleCompare("list",option+1) == 0)
6672 {
cristybb503372010-05-27 20:51:26 +00006673 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006674 list;
6675
6676 /*
6677 Display configuration list.
6678 */
cristy042ee782011-04-22 18:48:30 +00006679 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006680 switch (list)
6681 {
6682 case MagickCoderOptions:
6683 {
6684 (void) ListCoderInfo((FILE *) NULL,exception);
6685 break;
6686 }
6687 case MagickColorOptions:
6688 {
6689 (void) ListColorInfo((FILE *) NULL,exception);
6690 break;
6691 }
6692 case MagickConfigureOptions:
6693 {
6694 (void) ListConfigureInfo((FILE *) NULL,exception);
6695 break;
6696 }
6697 case MagickDelegateOptions:
6698 {
6699 (void) ListDelegateInfo((FILE *) NULL,exception);
6700 break;
6701 }
6702 case MagickFontOptions:
6703 {
6704 (void) ListTypeInfo((FILE *) NULL,exception);
6705 break;
6706 }
6707 case MagickFormatOptions:
6708 {
6709 (void) ListMagickInfo((FILE *) NULL,exception);
6710 break;
6711 }
6712 case MagickLocaleOptions:
6713 {
6714 (void) ListLocaleInfo((FILE *) NULL,exception);
6715 break;
6716 }
6717 case MagickLogOptions:
6718 {
6719 (void) ListLogInfo((FILE *) NULL,exception);
6720 break;
6721 }
6722 case MagickMagicOptions:
6723 {
6724 (void) ListMagicInfo((FILE *) NULL,exception);
6725 break;
6726 }
6727 case MagickMimeOptions:
6728 {
6729 (void) ListMimeInfo((FILE *) NULL,exception);
6730 break;
6731 }
6732 case MagickModuleOptions:
6733 {
6734 (void) ListModuleInfo((FILE *) NULL,exception);
6735 break;
6736 }
6737 case MagickPolicyOptions:
6738 {
6739 (void) ListPolicyInfo((FILE *) NULL,exception);
6740 break;
6741 }
6742 case MagickResourceOptions:
6743 {
6744 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6745 break;
6746 }
6747 case MagickThresholdOptions:
6748 {
6749 (void) ListThresholdMaps((FILE *) NULL,exception);
6750 break;
6751 }
6752 default:
6753 {
cristy042ee782011-04-22 18:48:30 +00006754 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006755 exception);
6756 break;
6757 }
6758 }
cristyaeb2cbc2010-05-07 13:28:58 +00006759 break;
cristy3ed852e2009-09-05 21:47:34 +00006760 }
6761 if (LocaleCompare("log",option+1) == 0)
6762 {
6763 if (*option == '+')
6764 break;
6765 (void) SetLogFormat(argv[i+1]);
6766 break;
6767 }
6768 if (LocaleCompare("loop",option+1) == 0)
6769 {
6770 if (*option == '+')
6771 {
6772 (void) SetImageOption(image_info,option+1,"0");
6773 break;
6774 }
6775 (void) SetImageOption(image_info,option+1,argv[i+1]);
6776 break;
6777 }
6778 break;
6779 }
6780 case 'm':
6781 {
6782 if (LocaleCompare("matte",option+1) == 0)
6783 {
6784 if (*option == '+')
6785 {
6786 (void) SetImageOption(image_info,option+1,"false");
6787 break;
6788 }
6789 (void) SetImageOption(image_info,option+1,"true");
6790 break;
6791 }
6792 if (LocaleCompare("mattecolor",option+1) == 0)
6793 {
6794 if (*option == '+')
6795 {
6796 (void) SetImageOption(image_info,option+1,argv[i+1]);
6797 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,
6798 exception);
6799 break;
6800 }
6801 (void) SetImageOption(image_info,option+1,argv[i+1]);
6802 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6803 exception);
6804 break;
6805 }
6806 if (LocaleCompare("monitor",option+1) == 0)
6807 {
6808 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6809 (void *) NULL);
6810 break;
6811 }
6812 if (LocaleCompare("monochrome",option+1) == 0)
6813 {
6814 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6815 break;
6816 }
6817 break;
6818 }
6819 case 'o':
6820 {
6821 if (LocaleCompare("orient",option+1) == 0)
6822 {
6823 if (*option == '+')
6824 {
6825 image_info->orientation=UndefinedOrientation;
6826 (void) SetImageOption(image_info,option+1,"undefined");
6827 break;
6828 }
cristy042ee782011-04-22 18:48:30 +00006829 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006830 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006831 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006832 break;
6833 }
6834 }
6835 case 'p':
6836 {
6837 if (LocaleCompare("page",option+1) == 0)
6838 {
6839 char
6840 *canonical_page,
6841 page[MaxTextExtent];
6842
6843 const char
6844 *image_option;
6845
6846 MagickStatusType
6847 flags;
6848
6849 RectangleInfo
6850 geometry;
6851
6852 if (*option == '+')
6853 {
6854 (void) DeleteImageOption(image_info,option+1);
6855 (void) CloneString(&image_info->page,(char *) NULL);
6856 break;
6857 }
6858 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6859 image_option=GetImageOption(image_info,"page");
6860 if (image_option != (const char *) NULL)
6861 flags=ParseAbsoluteGeometry(image_option,&geometry);
6862 canonical_page=GetPageGeometry(argv[i+1]);
6863 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6864 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006865 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006866 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006867 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006868 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006869 (unsigned long) geometry.width,(unsigned long) geometry.height,
6870 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006871 (void) SetImageOption(image_info,option+1,page);
6872 (void) CloneString(&image_info->page,page);
6873 break;
6874 }
6875 if (LocaleCompare("pen",option+1) == 0)
6876 {
6877 if (*option == '+')
6878 {
6879 (void) SetImageOption(image_info,option+1,"none");
6880 break;
6881 }
6882 (void) SetImageOption(image_info,option+1,argv[i+1]);
6883 break;
6884 }
6885 if (LocaleCompare("ping",option+1) == 0)
6886 {
6887 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6888 break;
6889 }
6890 if (LocaleCompare("pointsize",option+1) == 0)
6891 {
6892 if (*option == '+')
6893 geometry_info.rho=0.0;
6894 else
6895 (void) ParseGeometry(argv[i+1],&geometry_info);
6896 image_info->pointsize=geometry_info.rho;
6897 break;
6898 }
cristye7f51092010-01-17 00:39:37 +00006899 if (LocaleCompare("precision",option+1) == 0)
6900 {
cristybf2766a2010-01-17 03:33:23 +00006901 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006902 break;
6903 }
cristy3ed852e2009-09-05 21:47:34 +00006904 if (LocaleCompare("preview",option+1) == 0)
6905 {
6906 /*
6907 Preview image.
6908 */
6909 if (*option == '+')
6910 {
6911 image_info->preview_type=UndefinedPreview;
6912 break;
6913 }
cristy042ee782011-04-22 18:48:30 +00006914 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006915 MagickPreviewOptions,MagickFalse,argv[i+1]);
6916 break;
6917 }
6918 break;
6919 }
6920 case 'q':
6921 {
6922 if (LocaleCompare("quality",option+1) == 0)
6923 {
6924 /*
6925 Set image compression quality.
6926 */
6927 if (*option == '+')
6928 {
6929 image_info->quality=UndefinedCompressionQuality;
6930 (void) SetImageOption(image_info,option+1,"0");
6931 break;
6932 }
cristye27293e2009-12-18 02:53:20 +00006933 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006934 (void) SetImageOption(image_info,option+1,argv[i+1]);
6935 break;
6936 }
6937 if (LocaleCompare("quiet",option+1) == 0)
6938 {
6939 static WarningHandler
6940 warning_handler = (WarningHandler) NULL;
6941
6942 if (*option == '+')
6943 {
6944 /*
6945 Restore error or warning messages.
6946 */
6947 warning_handler=SetWarningHandler(warning_handler);
6948 break;
6949 }
6950 /*
6951 Suppress error or warning messages.
6952 */
6953 warning_handler=SetWarningHandler((WarningHandler) NULL);
6954 break;
6955 }
6956 break;
6957 }
6958 case 'r':
6959 {
6960 if (LocaleCompare("red-primary",option+1) == 0)
6961 {
6962 if (*option == '+')
6963 {
6964 (void) SetImageOption(image_info,option+1,"0.0");
6965 break;
6966 }
6967 (void) SetImageOption(image_info,option+1,argv[i+1]);
6968 break;
6969 }
6970 break;
6971 }
6972 case 's':
6973 {
6974 if (LocaleCompare("sampling-factor",option+1) == 0)
6975 {
6976 /*
6977 Set image sampling factor.
6978 */
6979 if (*option == '+')
6980 {
6981 if (image_info->sampling_factor != (char *) NULL)
6982 image_info->sampling_factor=DestroyString(
6983 image_info->sampling_factor);
6984 break;
6985 }
6986 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6987 break;
6988 }
6989 if (LocaleCompare("scene",option+1) == 0)
6990 {
6991 /*
6992 Set image scene.
6993 */
6994 if (*option == '+')
6995 {
6996 image_info->scene=0;
6997 (void) SetImageOption(image_info,option+1,"0");
6998 break;
6999 }
cristye27293e2009-12-18 02:53:20 +00007000 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007001 (void) SetImageOption(image_info,option+1,argv[i+1]);
7002 break;
7003 }
7004 if (LocaleCompare("seed",option+1) == 0)
7005 {
cristybb503372010-05-27 20:51:26 +00007006 size_t
cristy3ed852e2009-09-05 21:47:34 +00007007 seed;
7008
7009 if (*option == '+')
7010 {
cristybb503372010-05-27 20:51:26 +00007011 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007012 SeedPseudoRandomGenerator(seed);
7013 break;
7014 }
cristye27293e2009-12-18 02:53:20 +00007015 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007016 SeedPseudoRandomGenerator(seed);
7017 break;
7018 }
7019 if (LocaleCompare("size",option+1) == 0)
7020 {
7021 if (*option == '+')
7022 {
7023 if (image_info->size != (char *) NULL)
7024 image_info->size=DestroyString(image_info->size);
7025 break;
7026 }
7027 (void) CloneString(&image_info->size,argv[i+1]);
7028 break;
7029 }
7030 if (LocaleCompare("stroke",option+1) == 0)
7031 {
7032 if (*option == '+')
7033 {
7034 (void) SetImageOption(image_info,option+1,"none");
7035 break;
7036 }
7037 (void) SetImageOption(image_info,option+1,argv[i+1]);
7038 break;
7039 }
7040 if (LocaleCompare("strokewidth",option+1) == 0)
7041 {
7042 if (*option == '+')
7043 {
7044 (void) SetImageOption(image_info,option+1,"0");
7045 break;
7046 }
7047 (void) SetImageOption(image_info,option+1,argv[i+1]);
7048 break;
7049 }
cristyd9a29192010-10-16 16:49:53 +00007050 if (LocaleCompare("synchronize",option+1) == 0)
7051 {
7052 if (*option == '+')
7053 {
7054 image_info->synchronize=MagickFalse;
7055 break;
7056 }
7057 image_info->synchronize=MagickTrue;
7058 break;
7059 }
cristy3ed852e2009-09-05 21:47:34 +00007060 break;
7061 }
7062 case 't':
7063 {
7064 if (LocaleCompare("taint",option+1) == 0)
7065 {
7066 if (*option == '+')
7067 {
7068 (void) SetImageOption(image_info,option+1,"false");
7069 break;
7070 }
7071 (void) SetImageOption(image_info,option+1,"true");
7072 break;
7073 }
7074 if (LocaleCompare("texture",option+1) == 0)
7075 {
7076 if (*option == '+')
7077 {
7078 if (image_info->texture != (char *) NULL)
7079 image_info->texture=DestroyString(image_info->texture);
7080 break;
7081 }
7082 (void) CloneString(&image_info->texture,argv[i+1]);
7083 break;
7084 }
7085 if (LocaleCompare("tile-offset",option+1) == 0)
7086 {
7087 if (*option == '+')
7088 {
7089 (void) SetImageOption(image_info,option+1,"0");
7090 break;
7091 }
7092 (void) SetImageOption(image_info,option+1,argv[i+1]);
7093 break;
7094 }
7095 if (LocaleCompare("transparent-color",option+1) == 0)
7096 {
7097 if (*option == '+')
7098 {
7099 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7100 (void) SetImageOption(image_info,option+1,"none");
7101 break;
7102 }
7103 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7104 exception);
7105 (void) SetImageOption(image_info,option+1,argv[i+1]);
7106 break;
7107 }
7108 if (LocaleCompare("type",option+1) == 0)
7109 {
7110 if (*option == '+')
7111 {
cristy5f1c1ff2010-12-23 21:38:06 +00007112 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007113 (void) SetImageOption(image_info,option+1,"undefined");
7114 break;
7115 }
cristy042ee782011-04-22 18:48:30 +00007116 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007117 MagickFalse,argv[i+1]);
7118 (void) SetImageOption(image_info,option+1,argv[i+1]);
7119 break;
7120 }
7121 break;
7122 }
7123 case 'u':
7124 {
7125 if (LocaleCompare("undercolor",option+1) == 0)
7126 {
7127 if (*option == '+')
7128 {
7129 (void) DeleteImageOption(image_info,option+1);
7130 break;
7131 }
7132 (void) SetImageOption(image_info,option+1,argv[i+1]);
7133 break;
7134 }
7135 if (LocaleCompare("units",option+1) == 0)
7136 {
7137 if (*option == '+')
7138 {
7139 image_info->units=UndefinedResolution;
7140 (void) SetImageOption(image_info,option+1,"undefined");
7141 break;
7142 }
cristy042ee782011-04-22 18:48:30 +00007143 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007144 MagickResolutionOptions,MagickFalse,argv[i+1]);
7145 (void) SetImageOption(image_info,option+1,argv[i+1]);
7146 break;
7147 }
7148 break;
7149 }
7150 case 'v':
7151 {
7152 if (LocaleCompare("verbose",option+1) == 0)
7153 {
7154 if (*option == '+')
7155 {
7156 image_info->verbose=MagickFalse;
7157 break;
7158 }
7159 image_info->verbose=MagickTrue;
7160 image_info->ping=MagickFalse;
7161 break;
7162 }
7163 if (LocaleCompare("view",option+1) == 0)
7164 {
7165 if (*option == '+')
7166 {
7167 if (image_info->view != (char *) NULL)
7168 image_info->view=DestroyString(image_info->view);
7169 break;
7170 }
7171 (void) CloneString(&image_info->view,argv[i+1]);
7172 break;
7173 }
7174 if (LocaleCompare("virtual-pixel",option+1) == 0)
7175 {
7176 if (*option == '+')
7177 {
7178 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7179 (void) SetImageOption(image_info,option+1,"undefined");
7180 break;
7181 }
7182 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007183 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007184 argv[i+1]);
7185 (void) SetImageOption(image_info,option+1,argv[i+1]);
7186 break;
7187 }
7188 break;
7189 }
7190 case 'w':
7191 {
7192 if (LocaleCompare("white-point",option+1) == 0)
7193 {
7194 if (*option == '+')
7195 {
7196 (void) SetImageOption(image_info,option+1,"0.0");
7197 break;
7198 }
7199 (void) SetImageOption(image_info,option+1,argv[i+1]);
7200 break;
7201 }
7202 break;
7203 }
7204 default:
7205 break;
7206 }
7207 i+=count;
7208 }
7209 return(MagickTrue);
7210}
7211
7212/*
7213%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7214% %
7215% %
7216% %
7217+ M o g r i f y I m a g e L i s t %
7218% %
7219% %
7220% %
7221%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7222%
7223% MogrifyImageList() applies any command line options that might affect the
7224% entire image list (e.g. -append, -coalesce, etc.).
7225%
7226% The format of the MogrifyImage method is:
7227%
7228% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7229% const char **argv,Image **images,ExceptionInfo *exception)
7230%
7231% A description of each parameter follows:
7232%
7233% o image_info: the image info..
7234%
7235% o argc: Specifies a pointer to an integer describing the number of
7236% elements in the argument vector.
7237%
7238% o argv: Specifies a pointer to a text array containing the command line
7239% arguments.
7240%
anthonye9c27192011-03-27 08:07:06 +00007241% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007242%
7243% o exception: return any errors or warnings in this structure.
7244%
7245*/
7246WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7247 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7248{
7249 ChannelType
7250 channel;
7251
7252 const char
7253 *option;
7254
cristy6b3da3a2010-06-20 02:21:46 +00007255 ImageInfo
7256 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007257
7258 MagickStatusType
7259 status;
7260
7261 QuantizeInfo
7262 *quantize_info;
7263
cristybb503372010-05-27 20:51:26 +00007264 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007265 i;
7266
cristy6b3da3a2010-06-20 02:21:46 +00007267 ssize_t
7268 count,
7269 index;
7270
cristy3ed852e2009-09-05 21:47:34 +00007271 /*
7272 Apply options to the image list.
7273 */
7274 assert(image_info != (ImageInfo *) NULL);
7275 assert(image_info->signature == MagickSignature);
7276 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007277 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007278 assert((*images)->signature == MagickSignature);
7279 if ((*images)->debug != MagickFalse)
7280 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7281 (*images)->filename);
7282 if ((argc <= 0) || (*argv == (char *) NULL))
7283 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007284 mogrify_info=CloneImageInfo(image_info);
7285 quantize_info=AcquireQuantizeInfo(mogrify_info);
7286 channel=mogrify_info->channel;
cristy3ed852e2009-09-05 21:47:34 +00007287 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007288 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007289 {
cristy74fe8f12009-10-03 19:09:01 +00007290 if (*images == (Image *) NULL)
7291 break;
cristy3ed852e2009-09-05 21:47:34 +00007292 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007293 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007294 continue;
cristy042ee782011-04-22 18:48:30 +00007295 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007296 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007297 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007298 break;
cristy6b3da3a2010-06-20 02:21:46 +00007299 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007300 switch (*(option+1))
7301 {
7302 case 'a':
7303 {
7304 if (LocaleCompare("affinity",option+1) == 0)
7305 {
cristy6b3da3a2010-06-20 02:21:46 +00007306 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007307 if (*option == '+')
7308 {
7309 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7310 InheritException(exception,&(*images)->exception);
7311 break;
7312 }
7313 i++;
7314 break;
7315 }
7316 if (LocaleCompare("append",option+1) == 0)
7317 {
7318 Image
7319 *append_image;
7320
cristy6b3da3a2010-06-20 02:21:46 +00007321 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007322 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7323 MagickFalse,exception);
7324 if (append_image == (Image *) NULL)
7325 {
7326 status=MagickFalse;
7327 break;
7328 }
7329 *images=DestroyImageList(*images);
7330 *images=append_image;
7331 break;
7332 }
7333 if (LocaleCompare("average",option+1) == 0)
7334 {
7335 Image
7336 *average_image;
7337
cristyd18ae7c2010-03-07 17:39:52 +00007338 /*
7339 Average an image sequence (deprecated).
7340 */
cristy6b3da3a2010-06-20 02:21:46 +00007341 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007342 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7343 exception);
cristy3ed852e2009-09-05 21:47:34 +00007344 if (average_image == (Image *) NULL)
7345 {
7346 status=MagickFalse;
7347 break;
7348 }
7349 *images=DestroyImageList(*images);
7350 *images=average_image;
7351 break;
7352 }
7353 break;
7354 }
7355 case 'c':
7356 {
7357 if (LocaleCompare("channel",option+1) == 0)
7358 {
7359 if (*option == '+')
7360 {
7361 channel=DefaultChannels;
7362 break;
7363 }
7364 channel=(ChannelType) ParseChannelOption(argv[i+1]);
7365 break;
7366 }
7367 if (LocaleCompare("clut",option+1) == 0)
7368 {
7369 Image
7370 *clut_image,
7371 *image;
7372
cristy6b3da3a2010-06-20 02:21:46 +00007373 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007374 image=RemoveFirstImageFromList(images);
7375 clut_image=RemoveFirstImageFromList(images);
7376 if (clut_image == (Image *) NULL)
7377 {
7378 status=MagickFalse;
7379 break;
7380 }
7381 (void) ClutImageChannel(image,channel,clut_image);
7382 clut_image=DestroyImage(clut_image);
7383 InheritException(exception,&image->exception);
7384 *images=DestroyImageList(*images);
7385 *images=image;
7386 break;
7387 }
7388 if (LocaleCompare("coalesce",option+1) == 0)
7389 {
7390 Image
7391 *coalesce_image;
7392
cristy6b3da3a2010-06-20 02:21:46 +00007393 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007394 coalesce_image=CoalesceImages(*images,exception);
7395 if (coalesce_image == (Image *) NULL)
7396 {
7397 status=MagickFalse;
7398 break;
7399 }
7400 *images=DestroyImageList(*images);
7401 *images=coalesce_image;
7402 break;
7403 }
7404 if (LocaleCompare("combine",option+1) == 0)
7405 {
7406 Image
7407 *combine_image;
7408
cristy6b3da3a2010-06-20 02:21:46 +00007409 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007410 combine_image=CombineImages(*images,channel,exception);
7411 if (combine_image == (Image *) NULL)
7412 {
7413 status=MagickFalse;
7414 break;
7415 }
7416 *images=DestroyImageList(*images);
7417 *images=combine_image;
7418 break;
7419 }
7420 if (LocaleCompare("composite",option+1) == 0)
7421 {
7422 Image
7423 *mask_image,
7424 *composite_image,
7425 *image;
7426
7427 RectangleInfo
7428 geometry;
7429
cristy6b3da3a2010-06-20 02:21:46 +00007430 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007431 image=RemoveFirstImageFromList(images);
7432 composite_image=RemoveFirstImageFromList(images);
7433 if (composite_image == (Image *) NULL)
7434 {
7435 status=MagickFalse;
7436 break;
7437 }
7438 (void) TransformImage(&composite_image,(char *) NULL,
7439 composite_image->geometry);
7440 SetGeometry(composite_image,&geometry);
7441 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7442 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7443 &geometry);
7444 mask_image=RemoveFirstImageFromList(images);
7445 if (mask_image != (Image *) NULL)
7446 {
7447 if ((image->compose == DisplaceCompositeOp) ||
7448 (image->compose == DistortCompositeOp))
7449 {
7450 /*
7451 Merge Y displacement into X displacement image.
7452 */
7453 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7454 mask_image,0,0);
7455 mask_image=DestroyImage(mask_image);
7456 }
7457 else
7458 {
7459 /*
7460 Set a blending mask for the composition.
7461 */
anthonya129f702011-04-14 01:08:48 +00007462 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007463 image->mask=mask_image;
7464 (void) NegateImage(image->mask,MagickFalse);
7465 }
7466 }
7467 (void) CompositeImageChannel(image,channel,image->compose,
7468 composite_image,geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007469 if (mask_image != (Image *) NULL)
7470 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007471 composite_image=DestroyImage(composite_image);
7472 InheritException(exception,&image->exception);
7473 *images=DestroyImageList(*images);
7474 *images=image;
7475 break;
7476 }
anthony9f4f0342011-03-28 11:47:22 +00007477#if 0
7478This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007479 if (LocaleCompare("crop",option+1) == 0)
7480 {
7481 MagickStatusType
7482 flags;
7483
7484 RectangleInfo
7485 geometry;
7486
anthonye9c27192011-03-27 08:07:06 +00007487 /*
anthony9f4f0342011-03-28 11:47:22 +00007488 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007489 */
cristy6b3da3a2010-06-20 02:21:46 +00007490 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007491 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7492 if (((geometry.width == 0) && (geometry.height == 0)) ||
7493 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7494 break;
7495 (void) TransformImages(images,argv[i+1],(char *) NULL);
7496 InheritException(exception,&(*images)->exception);
7497 break;
7498 }
anthony9f4f0342011-03-28 11:47:22 +00007499#endif
cristy3ed852e2009-09-05 21:47:34 +00007500 break;
7501 }
7502 case 'd':
7503 {
7504 if (LocaleCompare("deconstruct",option+1) == 0)
7505 {
7506 Image
7507 *deconstruct_image;
7508
cristy6b3da3a2010-06-20 02:21:46 +00007509 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007510 deconstruct_image=DeconstructImages(*images,exception);
7511 if (deconstruct_image == (Image *) NULL)
7512 {
7513 status=MagickFalse;
7514 break;
7515 }
7516 *images=DestroyImageList(*images);
7517 *images=deconstruct_image;
7518 break;
7519 }
7520 if (LocaleCompare("delete",option+1) == 0)
7521 {
7522 if (*option == '+')
7523 DeleteImages(images,"-1",exception);
7524 else
7525 DeleteImages(images,argv[i+1],exception);
7526 break;
7527 }
7528 if (LocaleCompare("dither",option+1) == 0)
7529 {
7530 if (*option == '+')
7531 {
7532 quantize_info->dither=MagickFalse;
7533 break;
7534 }
7535 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007536 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007537 MagickDitherOptions,MagickFalse,argv[i+1]);
7538 break;
7539 }
cristyecb10ff2011-03-22 13:14:03 +00007540 if (LocaleCompare("duplicate",option+1) == 0)
7541 {
cristy72988482011-03-29 16:34:38 +00007542 Image
7543 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007544
anthony2b6bcae2011-03-23 13:05:34 +00007545 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007546 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7547 else
7548 {
7549 const char
7550 *p;
7551
anthony2b6bcae2011-03-23 13:05:34 +00007552 size_t
7553 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007554
anthony2b6bcae2011-03-23 13:05:34 +00007555 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007556 p=strchr(argv[i+1],',');
7557 if (p == (const char *) NULL)
7558 duplicate_images=DuplicateImages(*images,number_duplicates,
7559 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007560 else
cristy72988482011-03-29 16:34:38 +00007561 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7562 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007563 }
7564 AppendImageToList(images, duplicate_images);
7565 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007566 break;
7567 }
cristy3ed852e2009-09-05 21:47:34 +00007568 break;
7569 }
cristyd18ae7c2010-03-07 17:39:52 +00007570 case 'e':
7571 {
7572 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7573 {
7574 Image
7575 *evaluate_image;
7576
7577 MagickEvaluateOperator
7578 op;
7579
cristy6b3da3a2010-06-20 02:21:46 +00007580 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007581 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007582 MagickFalse,argv[i+1]);
7583 evaluate_image=EvaluateImages(*images,op,exception);
7584 if (evaluate_image == (Image *) NULL)
7585 {
7586 status=MagickFalse;
7587 break;
7588 }
7589 *images=DestroyImageList(*images);
7590 *images=evaluate_image;
7591 break;
7592 }
7593 break;
7594 }
cristy3ed852e2009-09-05 21:47:34 +00007595 case 'f':
7596 {
cristyf0a247f2009-10-04 00:20:03 +00007597 if (LocaleCompare("fft",option+1) == 0)
7598 {
7599 Image
7600 *fourier_image;
7601
7602 /*
7603 Implements the discrete Fourier transform (DFT).
7604 */
cristy6b3da3a2010-06-20 02:21:46 +00007605 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007606 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7607 MagickTrue : MagickFalse,exception);
7608 if (fourier_image == (Image *) NULL)
7609 break;
7610 *images=DestroyImage(*images);
7611 *images=fourier_image;
7612 break;
7613 }
cristy3ed852e2009-09-05 21:47:34 +00007614 if (LocaleCompare("flatten",option+1) == 0)
7615 {
7616 Image
7617 *flatten_image;
7618
cristy6b3da3a2010-06-20 02:21:46 +00007619 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007620 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7621 if (flatten_image == (Image *) NULL)
7622 break;
7623 *images=DestroyImageList(*images);
7624 *images=flatten_image;
7625 break;
7626 }
7627 if (LocaleCompare("fx",option+1) == 0)
7628 {
7629 Image
7630 *fx_image;
7631
cristy6b3da3a2010-06-20 02:21:46 +00007632 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007633 fx_image=FxImageChannel(*images,channel,argv[i+1],exception);
7634 if (fx_image == (Image *) NULL)
7635 {
7636 status=MagickFalse;
7637 break;
7638 }
7639 *images=DestroyImageList(*images);
7640 *images=fx_image;
7641 break;
7642 }
7643 break;
7644 }
7645 case 'h':
7646 {
7647 if (LocaleCompare("hald-clut",option+1) == 0)
7648 {
7649 Image
7650 *hald_image,
7651 *image;
7652
cristy6b3da3a2010-06-20 02:21:46 +00007653 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007654 image=RemoveFirstImageFromList(images);
7655 hald_image=RemoveFirstImageFromList(images);
7656 if (hald_image == (Image *) NULL)
7657 {
7658 status=MagickFalse;
7659 break;
7660 }
7661 (void) HaldClutImageChannel(image,channel,hald_image);
7662 hald_image=DestroyImage(hald_image);
7663 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007664 if (*images != (Image *) NULL)
7665 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007666 *images=image;
7667 break;
7668 }
7669 break;
7670 }
7671 case 'i':
7672 {
7673 if (LocaleCompare("ift",option+1) == 0)
7674 {
7675 Image
cristy8587f882009-11-13 20:28:49 +00007676 *fourier_image,
7677 *magnitude_image,
7678 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007679
7680 /*
7681 Implements the inverse fourier discrete Fourier transform (DFT).
7682 */
cristy6b3da3a2010-06-20 02:21:46 +00007683 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007684 magnitude_image=RemoveFirstImageFromList(images);
7685 phase_image=RemoveFirstImageFromList(images);
7686 if (phase_image == (Image *) NULL)
7687 {
7688 status=MagickFalse;
7689 break;
7690 }
7691 fourier_image=InverseFourierTransformImage(magnitude_image,
7692 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007693 if (fourier_image == (Image *) NULL)
7694 break;
cristy0aff6ea2009-11-14 01:40:53 +00007695 if (*images != (Image *) NULL)
7696 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007697 *images=fourier_image;
7698 break;
7699 }
7700 if (LocaleCompare("insert",option+1) == 0)
7701 {
7702 Image
7703 *p,
7704 *q;
7705
7706 index=0;
7707 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007708 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007709 p=RemoveLastImageFromList(images);
7710 if (p == (Image *) NULL)
7711 {
7712 (void) ThrowMagickException(exception,GetMagickModule(),
7713 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7714 status=MagickFalse;
7715 break;
7716 }
7717 q=p;
7718 if (index == 0)
7719 PrependImageToList(images,q);
7720 else
cristybb503372010-05-27 20:51:26 +00007721 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007722 AppendImageToList(images,q);
7723 else
7724 {
7725 q=GetImageFromList(*images,index-1);
7726 if (q == (Image *) NULL)
7727 {
7728 (void) ThrowMagickException(exception,GetMagickModule(),
7729 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7730 status=MagickFalse;
7731 break;
7732 }
7733 InsertImageInList(&q,p);
7734 }
7735 *images=GetFirstImageInList(q);
7736 break;
7737 }
7738 break;
7739 }
7740 case 'l':
7741 {
7742 if (LocaleCompare("layers",option+1) == 0)
7743 {
7744 Image
7745 *layers;
7746
7747 ImageLayerMethod
7748 method;
7749
cristy6b3da3a2010-06-20 02:21:46 +00007750 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007751 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007752 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007753 MagickFalse,argv[i+1]);
7754 switch (method)
7755 {
7756 case CoalesceLayer:
7757 {
7758 layers=CoalesceImages(*images,exception);
7759 break;
7760 }
7761 case CompareAnyLayer:
7762 case CompareClearLayer:
7763 case CompareOverlayLayer:
7764 default:
7765 {
7766 layers=CompareImageLayers(*images,method,exception);
7767 break;
7768 }
7769 case MergeLayer:
7770 case FlattenLayer:
7771 case MosaicLayer:
7772 case TrimBoundsLayer:
7773 {
7774 layers=MergeImageLayers(*images,method,exception);
7775 break;
7776 }
7777 case DisposeLayer:
7778 {
7779 layers=DisposeImages(*images,exception);
7780 break;
7781 }
7782 case OptimizeImageLayer:
7783 {
7784 layers=OptimizeImageLayers(*images,exception);
7785 break;
7786 }
7787 case OptimizePlusLayer:
7788 {
7789 layers=OptimizePlusImageLayers(*images,exception);
7790 break;
7791 }
7792 case OptimizeTransLayer:
7793 {
7794 OptimizeImageTransparency(*images,exception);
7795 break;
7796 }
7797 case RemoveDupsLayer:
7798 {
7799 RemoveDuplicateLayers(images,exception);
7800 break;
7801 }
7802 case RemoveZeroLayer:
7803 {
7804 RemoveZeroDelayLayers(images,exception);
7805 break;
7806 }
7807 case OptimizeLayer:
7808 {
7809 /*
7810 General Purpose, GIF Animation Optimizer.
7811 */
7812 layers=CoalesceImages(*images,exception);
7813 if (layers == (Image *) NULL)
7814 {
7815 status=MagickFalse;
7816 break;
7817 }
7818 InheritException(exception,&layers->exception);
7819 *images=DestroyImageList(*images);
7820 *images=layers;
7821 layers=OptimizeImageLayers(*images,exception);
7822 if (layers == (Image *) NULL)
7823 {
7824 status=MagickFalse;
7825 break;
7826 }
7827 InheritException(exception,&layers->exception);
7828 *images=DestroyImageList(*images);
7829 *images=layers;
7830 layers=(Image *) NULL;
7831 OptimizeImageTransparency(*images,exception);
7832 InheritException(exception,&(*images)->exception);
7833 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7834 break;
7835 }
7836 case CompositeLayer:
7837 {
7838 CompositeOperator
7839 compose;
7840
7841 Image
7842 *source;
7843
7844 RectangleInfo
7845 geometry;
7846
7847 /*
7848 Split image sequence at the first 'NULL:' image.
7849 */
7850 source=(*images);
7851 while (source != (Image *) NULL)
7852 {
7853 source=GetNextImageInList(source);
7854 if ((source != (Image *) NULL) &&
7855 (LocaleCompare(source->magick,"NULL") == 0))
7856 break;
7857 }
7858 if (source != (Image *) NULL)
7859 {
7860 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7861 (GetNextImageInList(source) == (Image *) NULL))
7862 source=(Image *) NULL;
7863 else
7864 {
7865 /*
7866 Separate the two lists, junk the null: image.
7867 */
7868 source=SplitImageList(source->previous);
7869 DeleteImageFromList(&source);
7870 }
7871 }
7872 if (source == (Image *) NULL)
7873 {
7874 (void) ThrowMagickException(exception,GetMagickModule(),
7875 OptionError,"MissingNullSeparator","layers Composite");
7876 status=MagickFalse;
7877 break;
7878 }
7879 /*
7880 Adjust offset with gravity and virtual canvas.
7881 */
7882 SetGeometry(*images,&geometry);
7883 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7884 geometry.width=source->page.width != 0 ?
7885 source->page.width : source->columns;
7886 geometry.height=source->page.height != 0 ?
7887 source->page.height : source->rows;
7888 GravityAdjustGeometry((*images)->page.width != 0 ?
7889 (*images)->page.width : (*images)->columns,
7890 (*images)->page.height != 0 ? (*images)->page.height :
7891 (*images)->rows,(*images)->gravity,&geometry);
7892 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007893 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007894 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007895 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007896 MagickComposeOptions,MagickFalse,option);
7897 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7898 exception);
7899 source=DestroyImageList(source);
7900 break;
7901 }
7902 }
7903 if (layers == (Image *) NULL)
7904 break;
7905 InheritException(exception,&layers->exception);
7906 *images=DestroyImageList(*images);
7907 *images=layers;
7908 break;
7909 }
7910 break;
7911 }
7912 case 'm':
7913 {
7914 if (LocaleCompare("map",option+1) == 0)
7915 {
cristy6b3da3a2010-06-20 02:21:46 +00007916 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007917 if (*option == '+')
7918 {
7919 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7920 InheritException(exception,&(*images)->exception);
7921 break;
7922 }
7923 i++;
7924 break;
7925 }
cristyf40785b2010-03-06 02:27:27 +00007926 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007927 {
7928 Image
cristyf40785b2010-03-06 02:27:27 +00007929 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007930
cristyd18ae7c2010-03-07 17:39:52 +00007931 /*
7932 Maximum image sequence (deprecated).
7933 */
cristy6b3da3a2010-06-20 02:21:46 +00007934 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007935 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007936 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007937 {
7938 status=MagickFalse;
7939 break;
7940 }
7941 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007942 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007943 break;
7944 }
cristyf40785b2010-03-06 02:27:27 +00007945 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007946 {
7947 Image
cristyf40785b2010-03-06 02:27:27 +00007948 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007949
cristyd18ae7c2010-03-07 17:39:52 +00007950 /*
7951 Minimum image sequence (deprecated).
7952 */
cristy6b3da3a2010-06-20 02:21:46 +00007953 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007954 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007955 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007956 {
7957 status=MagickFalse;
7958 break;
7959 }
7960 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007961 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007962 break;
7963 }
cristy3ed852e2009-09-05 21:47:34 +00007964 if (LocaleCompare("morph",option+1) == 0)
7965 {
7966 Image
7967 *morph_image;
7968
cristy6b3da3a2010-06-20 02:21:46 +00007969 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007970 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007971 exception);
7972 if (morph_image == (Image *) NULL)
7973 {
7974 status=MagickFalse;
7975 break;
7976 }
7977 *images=DestroyImageList(*images);
7978 *images=morph_image;
7979 break;
7980 }
7981 if (LocaleCompare("mosaic",option+1) == 0)
7982 {
7983 Image
7984 *mosaic_image;
7985
cristy6b3da3a2010-06-20 02:21:46 +00007986 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007987 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7988 if (mosaic_image == (Image *) NULL)
7989 {
7990 status=MagickFalse;
7991 break;
7992 }
7993 *images=DestroyImageList(*images);
7994 *images=mosaic_image;
7995 break;
7996 }
7997 break;
7998 }
7999 case 'p':
8000 {
8001 if (LocaleCompare("print",option+1) == 0)
8002 {
8003 char
8004 *string;
8005
cristy6b3da3a2010-06-20 02:21:46 +00008006 (void) SyncImagesSettings(mogrify_info,*images);
8007 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00008008 if (string == (char *) NULL)
8009 break;
8010 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00008011 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008012 string=DestroyString(string);
8013 }
8014 if (LocaleCompare("process",option+1) == 0)
8015 {
8016 char
8017 **arguments;
8018
8019 int
8020 j,
8021 number_arguments;
8022
cristy6b3da3a2010-06-20 02:21:46 +00008023 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008024 arguments=StringToArgv(argv[i+1],&number_arguments);
8025 if (arguments == (char **) NULL)
8026 break;
8027 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8028 {
8029 char
8030 breaker,
8031 quote,
8032 *token;
8033
8034 const char
8035 *arguments;
8036
8037 int
8038 next,
8039 status;
8040
8041 size_t
8042 length;
8043
8044 TokenInfo
8045 *token_info;
8046
8047 /*
8048 Support old style syntax, filter="-option arg".
8049 */
8050 length=strlen(argv[i+1]);
8051 token=(char *) NULL;
8052 if (~length >= MaxTextExtent)
8053 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8054 sizeof(*token));
8055 if (token == (char *) NULL)
8056 break;
8057 next=0;
8058 arguments=argv[i+1];
8059 token_info=AcquireTokenInfo();
8060 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8061 "\"",'\0',&breaker,&next,&quote);
8062 token_info=DestroyTokenInfo(token_info);
8063 if (status == 0)
8064 {
8065 const char
8066 *argv;
8067
8068 argv=(&(arguments[next]));
8069 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8070 exception);
8071 }
8072 token=DestroyString(token);
8073 break;
8074 }
cristy91c0da22010-05-02 01:44:07 +00008075 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008076 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8077 number_arguments-2,(const char **) arguments+2,exception);
8078 for (j=0; j < number_arguments; j++)
8079 arguments[j]=DestroyString(arguments[j]);
8080 arguments=(char **) RelinquishMagickMemory(arguments);
8081 break;
8082 }
8083 break;
8084 }
8085 case 'r':
8086 {
8087 if (LocaleCompare("reverse",option+1) == 0)
8088 {
8089 ReverseImageList(images);
8090 InheritException(exception,&(*images)->exception);
8091 break;
8092 }
8093 break;
8094 }
8095 case 's':
8096 {
cristy4285d782011-02-09 20:12:28 +00008097 if (LocaleCompare("smush",option+1) == 0)
8098 {
8099 Image
8100 *smush_image;
8101
8102 ssize_t
8103 offset;
8104
8105 (void) SyncImagesSettings(mogrify_info,*images);
8106 offset=(ssize_t) StringToLong(argv[i+1]);
8107 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8108 MagickFalse,offset,exception);
8109 if (smush_image == (Image *) NULL)
8110 {
8111 status=MagickFalse;
8112 break;
8113 }
8114 *images=DestroyImageList(*images);
8115 *images=smush_image;
8116 break;
8117 }
cristy3ed852e2009-09-05 21:47:34 +00008118 if (LocaleCompare("swap",option+1) == 0)
8119 {
8120 Image
8121 *p,
8122 *q,
8123 *swap;
8124
cristybb503372010-05-27 20:51:26 +00008125 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008126 swap_index;
8127
8128 index=(-1);
8129 swap_index=(-2);
8130 if (*option != '+')
8131 {
8132 GeometryInfo
8133 geometry_info;
8134
8135 MagickStatusType
8136 flags;
8137
8138 swap_index=(-1);
8139 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008140 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008141 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008142 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008143 }
8144 p=GetImageFromList(*images,index);
8145 q=GetImageFromList(*images,swap_index);
8146 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8147 {
8148 (void) ThrowMagickException(exception,GetMagickModule(),
8149 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8150 status=MagickFalse;
8151 break;
8152 }
8153 if (p == q)
8154 break;
8155 swap=CloneImage(p,0,0,MagickTrue,exception);
8156 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8157 ReplaceImageInList(&q,swap);
8158 *images=GetFirstImageInList(q);
8159 break;
8160 }
8161 break;
8162 }
8163 case 'w':
8164 {
8165 if (LocaleCompare("write",option+1) == 0)
8166 {
cristy071dd7b2010-04-09 13:04:54 +00008167 char
cristy06609ee2010-03-17 20:21:27 +00008168 key[MaxTextExtent];
8169
cristy3ed852e2009-09-05 21:47:34 +00008170 Image
8171 *write_images;
8172
8173 ImageInfo
8174 *write_info;
8175
cristy6b3da3a2010-06-20 02:21:46 +00008176 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008177 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008178 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008179 write_images=(*images);
8180 if (*option == '+')
8181 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008182 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008183 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8184 write_info=DestroyImageInfo(write_info);
8185 if (*option == '+')
8186 write_images=DestroyImageList(write_images);
8187 break;
8188 }
8189 break;
8190 }
8191 default:
8192 break;
8193 }
8194 i+=count;
8195 }
8196 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008197 mogrify_info=DestroyImageInfo(mogrify_info);
8198 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008199 return(status != 0 ? MagickTrue : MagickFalse);
8200}
8201
8202/*
8203%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8204% %
8205% %
8206% %
8207+ M o g r i f y I m a g e s %
8208% %
8209% %
8210% %
8211%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8212%
8213% MogrifyImages() applies image processing options to a sequence of images as
8214% prescribed by command line options.
8215%
8216% The format of the MogrifyImage method is:
8217%
8218% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8219% const MagickBooleanType post,const int argc,const char **argv,
8220% Image **images,Exceptioninfo *exception)
8221%
8222% A description of each parameter follows:
8223%
8224% o image_info: the image info..
8225%
8226% o post: If true, post process image list operators otherwise pre-process.
8227%
8228% o argc: Specifies a pointer to an integer describing the number of
8229% elements in the argument vector.
8230%
8231% o argv: Specifies a pointer to a text array containing the command line
8232% arguments.
8233%
anthonye9c27192011-03-27 08:07:06 +00008234% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008235%
8236% o exception: return any errors or warnings in this structure.
8237%
8238*/
8239WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8240 const MagickBooleanType post,const int argc,const char **argv,
8241 Image **images,ExceptionInfo *exception)
8242{
8243#define MogrifyImageTag "Mogrify/Image"
8244
anthonye9c27192011-03-27 08:07:06 +00008245 MagickStatusType
8246 status;
cristy3ed852e2009-09-05 21:47:34 +00008247
cristy0e9f9c12010-02-11 03:00:47 +00008248 MagickBooleanType
8249 proceed;
8250
anthonye9c27192011-03-27 08:07:06 +00008251 size_t
8252 n;
cristy3ed852e2009-09-05 21:47:34 +00008253
cristybb503372010-05-27 20:51:26 +00008254 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008255 i;
8256
cristy3ed852e2009-09-05 21:47:34 +00008257 assert(image_info != (ImageInfo *) NULL);
8258 assert(image_info->signature == MagickSignature);
8259 if (images == (Image **) NULL)
8260 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008261 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008262 assert((*images)->signature == MagickSignature);
8263 if ((*images)->debug != MagickFalse)
8264 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8265 (*images)->filename);
8266 if ((argc <= 0) || (*argv == (char *) NULL))
8267 return(MagickTrue);
8268 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8269 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008270 status=0;
anthonye9c27192011-03-27 08:07:06 +00008271
anthonyce2716b2011-04-22 09:51:34 +00008272#if 0
cristy1e604812011-05-19 18:07:50 +00008273 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8274 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008275#endif
8276
anthonye9c27192011-03-27 08:07:06 +00008277 /*
8278 Pre-process multi-image sequence operators
8279 */
cristy3ed852e2009-09-05 21:47:34 +00008280 if (post == MagickFalse)
8281 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008282 /*
8283 For each image, process simple single image operators
8284 */
8285 i=0;
8286 n=GetImageListLength(*images);
8287 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008288 {
anthonyce2716b2011-04-22 09:51:34 +00008289#if 0
cristy1e604812011-05-19 18:07:50 +00008290 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8291 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008292#endif
anthonye9c27192011-03-27 08:07:06 +00008293 status&=MogrifyImage(image_info,argc,argv,images,exception);
8294 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008295 if (proceed == MagickFalse)
8296 break;
anthonye9c27192011-03-27 08:07:06 +00008297 if ( (*images)->next == (Image *) NULL )
8298 break;
8299 *images=(*images)->next;
8300 i++;
cristy3ed852e2009-09-05 21:47:34 +00008301 }
anthonye9c27192011-03-27 08:07:06 +00008302 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008303#if 0
cristy1e604812011-05-19 18:07:50 +00008304 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8305 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008306#endif
anthonye9c27192011-03-27 08:07:06 +00008307
8308 /*
8309 Post-process, multi-image sequence operators
8310 */
8311 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008312 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008313 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008314 return(status != 0 ? MagickTrue : MagickFalse);
8315}