blob: 6dbdfa48a04f0d5bfd2dfb2b27cd0d98158d5d52 [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*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
54#include "MagickCore/thread-private.h"
55#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000056
57/*
cristy154fa9d2011-08-05 14:25:15 +000058 Constant declaration.
59*/
cristy3a557c02011-08-06 19:48:02 +000060static const char
cristy638895a2011-08-06 23:19:14 +000061 MogrifyBackgroundColor[] = "#ffffff", /* white */
62 MogrifyBorderColor[] = "#dfdfdf", /* gray */
63 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000064
65/*
cristy3ed852e2009-09-05 21:47:34 +000066 Define declarations.
67*/
68#define UndefinedCompressionQuality 0UL
69
70/*
cristy3ed852e2009-09-05 21:47:34 +000071%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% %
73% %
74% %
cristy5063d812010-10-19 16:28:10 +000075% 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 +000076% %
77% %
78% %
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80%
81% MagickCommandGenesis() applies image processing options to an image as
82% prescribed by command line options.
83%
84% The format of the MagickCommandGenesis method is:
85%
86% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000087% MagickCommand command,int argc,char **argv,char **metadata,
88% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000089%
90% A description of each parameter follows:
91%
92% o image_info: the image info.
93%
cristy5063d812010-10-19 16:28:10 +000094% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000095% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000096% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
97% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000098%
99% o argc: Specifies a pointer to an integer describing the number of
100% elements in the argument vector.
101%
102% o argv: Specifies a pointer to a text array containing the command line
103% arguments.
104%
cristy5063d812010-10-19 16:28:10 +0000105% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000106%
107% o exception: return any errors or warnings in this structure.
108%
109*/
110WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
111 MagickCommand command,int argc,char **argv,char **metadata,
112 ExceptionInfo *exception)
113{
114 char
115 *option;
116
117 double
118 duration,
119 elapsed_time,
120 user_time;
121
cristy3980b0d2009-10-25 14:37:13 +0000122 MagickBooleanType
123 concurrent,
124 regard_warnings,
125 status;
126
cristybb503372010-05-27 20:51:26 +0000127 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000128 i;
129
130 TimerInfo
131 *timer;
132
cristybb503372010-05-27 20:51:26 +0000133 size_t
cristy3980b0d2009-10-25 14:37:13 +0000134 iterations;
135
cristyd0a94fa2010-03-12 14:18:11 +0000136 (void) setlocale(LC_ALL,"");
137 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000138 concurrent=MagickFalse;
139 duration=(-1.0);
140 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000141 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000142 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000143 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000144 {
145 option=argv[i];
146 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
147 continue;
148 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000149 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000150 if (LocaleCompare("concurrent",option+1) == 0)
151 concurrent=MagickTrue;
152 if (LocaleCompare("debug",option+1) == 0)
153 (void) SetLogEventMask(argv[++i]);
154 if (LocaleCompare("duration",option+1) == 0)
cristyc1acd842011-05-19 23:05:47 +0000155 duration=InterpretLocaleValue(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000156 if (LocaleCompare("regard-warnings",option+1) == 0)
157 regard_warnings=MagickTrue;
158 }
159 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000160 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000161 {
cristybb503372010-05-27 20:51:26 +0000162 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000163 {
cristy33557d72009-11-06 00:54:33 +0000164 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000165 continue;
166 if (duration > 0)
167 {
168 if (GetElapsedTime(timer) > duration)
169 continue;
170 (void) ContinueTimer(timer);
171 }
172 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000173 if (exception->severity != UndefinedException)
174 {
175 if ((exception->severity > ErrorException) ||
176 (regard_warnings != MagickFalse))
177 status=MagickTrue;
178 CatchException(exception);
179 }
cristy3d1a5512009-10-25 21:23:27 +0000180 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000181 {
182 (void) fputs(*metadata,stdout);
183 (void) fputc('\n',stdout);
184 *metadata=DestroyString(*metadata);
185 }
186 }
187 }
cristyceae09d2009-10-28 17:18:47 +0000188 else
189 {
190 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000191#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000192 # pragma omp parallel for shared(status)
193#endif
cristybb503372010-05-27 20:51:26 +0000194 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000195 {
cristy33557d72009-11-06 00:54:33 +0000196 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000197 continue;
198 if (duration > 0)
199 {
200 if (GetElapsedTime(timer) > duration)
201 continue;
202 (void) ContinueTimer(timer);
203 }
204 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000205#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000206 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000207#endif
208 {
209 if (exception->severity != UndefinedException)
210 {
211 if ((exception->severity > ErrorException) ||
212 (regard_warnings != MagickFalse))
213 status=MagickTrue;
214 CatchException(exception);
215 }
216 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
217 {
218 (void) fputs(*metadata,stdout);
219 (void) fputc('\n',stdout);
220 *metadata=DestroyString(*metadata);
221 }
222 }
223 }
224 }
cristy3980b0d2009-10-25 14:37:13 +0000225 if (iterations > 1)
226 {
227 elapsed_time=GetElapsedTime(timer);
228 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000229 (void) FormatLocaleFile(stderr,
cristye8c25f92010-06-03 00:53:06 +0000230 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
231 iterations,1.0*iterations/elapsed_time,user_time,(double)
232 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
233 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000234 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000235 }
236 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000237 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000238}
239
240/*
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242% %
243% %
244% %
cristy3ed852e2009-09-05 21:47:34 +0000245+ M o g r i f y I m a g e %
246% %
247% %
248% %
249%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250%
anthonye9c27192011-03-27 08:07:06 +0000251% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000252% image that may be part of a large list, but also handles any 'region'
253% image handling.
anthonye9c27192011-03-27 08:07:06 +0000254%
255% The image in the list may be modified in three different ways...
256%
257% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
258% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
259% * replace by a list of images (only the -separate option!)
260%
261% In each case the result is returned into the list, and a pointer to the
262% modified image (last image added if replaced by a list of images) is
263% returned.
264%
265% ASIDE: The -crop is present but restricted to non-tile single image crops
266%
267% This means if all the images are being processed (such as by
268% MogrifyImages(), next image to be processed will be as per the pointer
269% (*image)->next. Also the image list may grow as a result of some specific
270% operations but as images are never merged or deleted, it will never shrink
271% in length. Typically the list will remain the same length.
272%
273% WARNING: As the image pointed to may be replaced, the first image in the
274% list may also change. GetFirstImageInList() should be used by caller if
275% they wish return the Image pointer to the first image in list.
276%
cristy3ed852e2009-09-05 21:47:34 +0000277%
278% The format of the MogrifyImage method is:
279%
280% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
281% const char **argv,Image **image)
282%
283% A description of each parameter follows:
284%
285% o image_info: the image info..
286%
287% o argc: Specifies a pointer to an integer describing the number of
288% elements in the argument vector.
289%
290% o argv: Specifies a pointer to a text array containing the command line
291% arguments.
292%
293% o image: the image.
294%
295% o exception: return any errors or warnings in this structure.
296%
297*/
298
cristy4c08aed2011-07-01 19:47:50 +0000299/*
300** GetImageCache() will read an image into a image cache if not already
301** present then return the image that is in the cache under that filename.
302*/
anthonydf8ebac2011-04-27 09:03:19 +0000303static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
304 ExceptionInfo *exception)
305{
306 char
307 key[MaxTextExtent];
308
309 ExceptionInfo
310 *sans_exception;
311
312 Image
313 *image;
314
315 ImageInfo
316 *read_info;
317
cristyb51dff52011-05-19 16:55:47 +0000318 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000319 sans_exception=AcquireExceptionInfo();
320 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
321 sans_exception=DestroyExceptionInfo(sans_exception);
322 if (image != (Image *) NULL)
323 return(image);
324 read_info=CloneImageInfo(image_info);
325 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
326 image=ReadImage(read_info,exception);
327 read_info=DestroyImageInfo(read_info);
328 if (image != (Image *) NULL)
329 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
330 return(image);
331}
332
cristy3ed852e2009-09-05 21:47:34 +0000333static MagickBooleanType IsPathWritable(const char *path)
334{
335 if (IsPathAccessible(path) == MagickFalse)
336 return(MagickFalse);
337 if (access(path,W_OK) != 0)
338 return(MagickFalse);
339 return(MagickTrue);
340}
341
cristybb503372010-05-27 20:51:26 +0000342static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000343{
344 if (x > y)
345 return(x);
346 return(y);
347}
348
anthonydf8ebac2011-04-27 09:03:19 +0000349static MagickBooleanType MonitorProgress(const char *text,
350 const MagickOffsetType offset,const MagickSizeType extent,
351 void *wand_unused(client_data))
352{
353 char
354 message[MaxTextExtent],
355 tag[MaxTextExtent];
356
357 const char
358 *locale_message;
359
360 register char
361 *p;
362
363 if (extent < 2)
364 return(MagickTrue);
365 (void) CopyMagickMemory(tag,text,MaxTextExtent);
366 p=strrchr(tag,'/');
367 if (p != (char *) NULL)
368 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000369 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000370 locale_message=GetLocaleMessage(message);
371 if (locale_message == message)
372 locale_message=tag;
373 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000374 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
375 locale_message,(long) offset,(unsigned long) extent,(long)
376 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000377 else
cristyb51dff52011-05-19 16:55:47 +0000378 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000379 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
380 (100L*offset/(extent-1)));
381 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000382 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000383 (void) fflush(stderr);
384 return(MagickTrue);
385}
386
cristy3884f692011-07-08 18:00:18 +0000387static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000388 const SparseColorMethod method,const char *arguments,
389 const MagickBooleanType color_from_image,ExceptionInfo *exception)
390{
anthonydf8ebac2011-04-27 09:03:19 +0000391 char
392 token[MaxTextExtent];
393
394 const char
395 *p;
396
397 double
398 *sparse_arguments;
399
anthonydf8ebac2011-04-27 09:03:19 +0000400 Image
401 *sparse_image;
402
cristy4c08aed2011-07-01 19:47:50 +0000403 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000404 color;
405
406 MagickBooleanType
407 error;
408
cristy5f09d852011-05-29 01:39:29 +0000409 register size_t
410 x;
411
412 size_t
413 number_arguments,
414 number_colors;
415
cristy28474bf2011-09-11 23:32:52 +0000416 /*
417 SparseColorOption() parses the complex -sparse-color argument into an
418 an array of floating point values then calls SparseColorImage().
419 Argument is a complex mix of floating-point pixel coodinates, and color
420 specifications (or direct floating point numbers). The number of floats
421 needed to represent a color varies depending on the current channel
422 setting.
423 */
anthonydf8ebac2011-04-27 09:03:19 +0000424 assert(image != (Image *) NULL);
425 assert(image->signature == MagickSignature);
426 if (image->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
428 assert(exception != (ExceptionInfo *) NULL);
429 assert(exception->signature == MagickSignature);
430 /*
431 Limit channels according to image - and add up number of color channel.
432 */
anthonydf8ebac2011-04-27 09:03:19 +0000433 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000434 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000435 number_colors++;
cristyed231572011-07-14 02:18:59 +0000436 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000437 number_colors++;
cristyed231572011-07-14 02:18:59 +0000438 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000439 number_colors++;
cristyed231572011-07-14 02:18:59 +0000440 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000441 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000442 number_colors++;
cristyed231572011-07-14 02:18:59 +0000443 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000444 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000445 number_colors++;
446
447 /*
448 Read string, to determine number of arguments needed,
449 */
450 p=arguments;
451 x=0;
452 while( *p != '\0' )
453 {
454 GetMagickToken(p,&p,token);
455 if ( token[0] == ',' ) continue;
456 if ( isalpha((int) token[0]) || token[0] == '#' ) {
457 if ( color_from_image ) {
458 (void) ThrowMagickException(exception,GetMagickModule(),
459 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
460 "Color arg given, when colors are coming from image");
461 return( (Image *)NULL);
462 }
463 x += number_colors; /* color argument */
464 }
465 else {
466 x++; /* floating point argument */
467 }
468 }
469 error=MagickTrue;
470 if ( color_from_image ) {
471 /* just the control points are being given */
472 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
473 number_arguments=(x/2)*(2+number_colors);
474 }
475 else {
476 /* control points and color values */
477 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
478 number_arguments=x;
479 }
480 if ( error ) {
481 (void) ThrowMagickException(exception,GetMagickModule(),
482 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
483 "Invalid number of Arguments");
484 return( (Image *)NULL);
485 }
486
487 /* Allocate and fill in the floating point arguments */
488 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
489 sizeof(*sparse_arguments));
490 if (sparse_arguments == (double *) NULL) {
491 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
492 "MemoryAllocationFailed","%s","SparseColorOption");
493 return( (Image *)NULL);
494 }
495 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
496 sizeof(*sparse_arguments));
497 p=arguments;
498 x=0;
499 while( *p != '\0' && x < number_arguments ) {
500 /* X coordinate */
501 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
502 if ( token[0] == '\0' ) break;
503 if ( isalpha((int) token[0]) || token[0] == '#' ) {
504 (void) ThrowMagickException(exception,GetMagickModule(),
505 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
506 "Color found, instead of X-coord");
507 error = MagickTrue;
508 break;
509 }
cristyc1acd842011-05-19 23:05:47 +0000510 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000511 /* Y coordinate */
512 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
513 if ( token[0] == '\0' ) break;
514 if ( isalpha((int) token[0]) || token[0] == '#' ) {
515 (void) ThrowMagickException(exception,GetMagickModule(),
516 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
517 "Color found, instead of Y-coord");
518 error = MagickTrue;
519 break;
520 }
cristyc1acd842011-05-19 23:05:47 +0000521 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000522 /* color values for this control point */
523#if 0
524 if ( (color_from_image ) {
525 /* get color from image */
526 /* HOW??? */
527 }
528 else
529#endif
530 {
531 /* color name or function given in string argument */
532 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
533 if ( token[0] == '\0' ) break;
534 if ( isalpha((int) token[0]) || token[0] == '#' ) {
535 /* Color string given */
536 (void) QueryMagickColor(token,&color,exception);
cristyed231572011-07-14 02:18:59 +0000537 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000538 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000539 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000540 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000541 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000542 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000543 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000544 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000545 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000546 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000547 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000548 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000549 }
550 else {
551 /* Colors given as a set of floating point values - experimental */
552 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000553 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000554 {
anthonydf8ebac2011-04-27 09:03:19 +0000555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristyc1acd842011-05-19 23:05:47 +0000558 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000559 token[0] = ','; /* used this token - get another */
560 }
cristyed231572011-07-14 02:18:59 +0000561 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000562 {
anthonydf8ebac2011-04-27 09:03:19 +0000563 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
564 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
565 break;
cristyc1acd842011-05-19 23:05:47 +0000566 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000567 token[0] = ','; /* used this token - get another */
568 }
cristyed231572011-07-14 02:18:59 +0000569 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000570 {
anthonydf8ebac2011-04-27 09:03:19 +0000571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristyc1acd842011-05-19 23:05:47 +0000574 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
cristyed231572011-07-14 02:18:59 +0000577 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000578 (image->colorspace == CMYKColorspace))
579 {
anthonydf8ebac2011-04-27 09:03:19 +0000580 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
581 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
582 break;
cristyc1acd842011-05-19 23:05:47 +0000583 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000584 token[0] = ','; /* used this token - get another */
585 }
cristyed231572011-07-14 02:18:59 +0000586 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000587 (image->matte != MagickFalse))
588 {
anthonydf8ebac2011-04-27 09:03:19 +0000589 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
590 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
591 break;
cristyc1acd842011-05-19 23:05:47 +0000592 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000593 token[0] = ','; /* used this token - get another */
594 }
595 }
596 }
597 }
598 if ( number_arguments != x && !error ) {
599 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
600 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
601 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
602 return( (Image *)NULL);
603 }
604 if ( error )
605 return( (Image *)NULL);
606
607 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000608 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
609 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000610 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
611 return( sparse_image );
612}
613
cristy3ed852e2009-09-05 21:47:34 +0000614WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
615 const char **argv,Image **image,ExceptionInfo *exception)
616{
anthonydf8ebac2011-04-27 09:03:19 +0000617 ChannelType
618 channel;
619
620 const char
621 *format,
622 *option;
623
624 DrawInfo
625 *draw_info;
626
627 GeometryInfo
628 geometry_info;
629
cristy3ed852e2009-09-05 21:47:34 +0000630 Image
631 *region_image;
632
anthonydf8ebac2011-04-27 09:03:19 +0000633 ImageInfo
634 *mogrify_info;
635
cristyebbcfea2011-02-25 02:43:54 +0000636 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000637 status;
638
cristy4c08aed2011-07-01 19:47:50 +0000639 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000640 fill;
cristy3ed852e2009-09-05 21:47:34 +0000641
anthonydf8ebac2011-04-27 09:03:19 +0000642 MagickStatusType
643 flags;
644
cristy28474bf2011-09-11 23:32:52 +0000645 PixelInterpolateMethod
646 interpolate_method;
647
anthonydf8ebac2011-04-27 09:03:19 +0000648 QuantizeInfo
649 *quantize_info;
650
651 RectangleInfo
652 geometry,
653 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000654
cristybb503372010-05-27 20:51:26 +0000655 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000656 i;
657
658 /*
659 Initialize method variables.
660 */
661 assert(image_info != (const ImageInfo *) NULL);
662 assert(image_info->signature == MagickSignature);
663 assert(image != (Image **) NULL);
664 assert((*image)->signature == MagickSignature);
665 if ((*image)->debug != MagickFalse)
666 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
667 if (argc < 0)
668 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000669 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000670 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
671 quantize_info=AcquireQuantizeInfo(mogrify_info);
672 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000673 GetPixelInfo(*image,&fill);
674 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
cristy28474bf2011-09-11 23:32:52 +0000675 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000676 channel=mogrify_info->channel;
677 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000678 SetGeometry(*image,&region_geometry);
679 region_image=NewImageList();
680 /*
681 Transmogrify the image.
682 */
cristybb503372010-05-27 20:51:26 +0000683 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000684 {
anthonydf8ebac2011-04-27 09:03:19 +0000685 Image
686 *mogrify_image;
687
anthonye9c27192011-03-27 08:07:06 +0000688 ssize_t
689 count;
690
anthonydf8ebac2011-04-27 09:03:19 +0000691 option=argv[i];
692 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000693 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000694 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
695 0L);
cristycee97112010-05-28 00:44:52 +0000696 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000697 break;
cristy6b3da3a2010-06-20 02:21:46 +0000698 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000699 mogrify_image=(Image *)NULL;
700 switch (*(option+1))
701 {
702 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000703 {
anthonydf8ebac2011-04-27 09:03:19 +0000704 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000705 {
anthonydf8ebac2011-04-27 09:03:19 +0000706 /*
707 Adaptive blur image.
708 */
709 (void) SyncImageSettings(mogrify_info,*image);
710 flags=ParseGeometry(argv[i+1],&geometry_info);
711 if ((flags & SigmaValue) == 0)
712 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000713 if ((flags & XiValue) == 0)
714 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000715 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000716 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000717 break;
cristy3ed852e2009-09-05 21:47:34 +0000718 }
anthonydf8ebac2011-04-27 09:03:19 +0000719 if (LocaleCompare("adaptive-resize",option+1) == 0)
720 {
721 /*
722 Adaptive resize image.
723 */
724 (void) SyncImageSettings(mogrify_info,*image);
725 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
726 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy28474bf2011-09-11 23:32:52 +0000727 geometry.height,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000728 break;
729 }
730 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
731 {
732 /*
733 Adaptive sharpen image.
734 */
735 (void) SyncImageSettings(mogrify_info,*image);
736 flags=ParseGeometry(argv[i+1],&geometry_info);
737 if ((flags & SigmaValue) == 0)
738 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000739 if ((flags & XiValue) == 0)
740 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000741 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000742 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000743 break;
744 }
745 if (LocaleCompare("affine",option+1) == 0)
746 {
747 /*
748 Affine matrix.
749 */
750 if (*option == '+')
751 {
752 GetAffineMatrix(&draw_info->affine);
753 break;
754 }
755 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
756 break;
757 }
758 if (LocaleCompare("alpha",option+1) == 0)
759 {
760 AlphaChannelType
761 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000762
anthonydf8ebac2011-04-27 09:03:19 +0000763 (void) SyncImageSettings(mogrify_info,*image);
764 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
765 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000766 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000767 break;
768 }
769 if (LocaleCompare("annotate",option+1) == 0)
770 {
771 char
772 *text,
773 geometry[MaxTextExtent];
774
775 /*
776 Annotate image.
777 */
778 (void) SyncImageSettings(mogrify_info,*image);
779 SetGeometryInfo(&geometry_info);
780 flags=ParseGeometry(argv[i+1],&geometry_info);
781 if ((flags & SigmaValue) == 0)
782 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000783 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
784 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000785 if (text == (char *) NULL)
786 break;
787 (void) CloneString(&draw_info->text,text);
788 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000789 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000790 geometry_info.xi,geometry_info.psi);
791 (void) CloneString(&draw_info->geometry,geometry);
792 draw_info->affine.sx=cos(DegreesToRadians(
793 fmod(geometry_info.rho,360.0)));
794 draw_info->affine.rx=sin(DegreesToRadians(
795 fmod(geometry_info.rho,360.0)));
796 draw_info->affine.ry=(-sin(DegreesToRadians(
797 fmod(geometry_info.sigma,360.0))));
798 draw_info->affine.sy=cos(DegreesToRadians(
799 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000800 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000801 break;
802 }
803 if (LocaleCompare("antialias",option+1) == 0)
804 {
805 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
806 MagickFalse;
807 draw_info->text_antialias=(*option == '-') ? MagickTrue :
808 MagickFalse;
809 break;
810 }
811 if (LocaleCompare("auto-gamma",option+1) == 0)
812 {
813 /*
814 Auto Adjust Gamma of image based on its mean
815 */
816 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000817 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000818 break;
819 }
820 if (LocaleCompare("auto-level",option+1) == 0)
821 {
822 /*
823 Perfectly Normalize (max/min stretch) the image
824 */
825 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000826 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000827 break;
828 }
829 if (LocaleCompare("auto-orient",option+1) == 0)
830 {
831 (void) SyncImageSettings(mogrify_info,*image);
832 switch ((*image)->orientation)
833 {
834 case TopRightOrientation:
835 {
836 mogrify_image=FlopImage(*image,exception);
837 break;
838 }
839 case BottomRightOrientation:
840 {
841 mogrify_image=RotateImage(*image,180.0,exception);
842 break;
843 }
844 case BottomLeftOrientation:
845 {
846 mogrify_image=FlipImage(*image,exception);
847 break;
848 }
849 case LeftTopOrientation:
850 {
851 mogrify_image=TransposeImage(*image,exception);
852 break;
853 }
854 case RightTopOrientation:
855 {
856 mogrify_image=RotateImage(*image,90.0,exception);
857 break;
858 }
859 case RightBottomOrientation:
860 {
861 mogrify_image=TransverseImage(*image,exception);
862 break;
863 }
864 case LeftBottomOrientation:
865 {
866 mogrify_image=RotateImage(*image,270.0,exception);
867 break;
868 }
869 default:
870 break;
871 }
872 if (mogrify_image != (Image *) NULL)
873 mogrify_image->orientation=TopLeftOrientation;
874 break;
875 }
876 break;
877 }
878 case 'b':
879 {
880 if (LocaleCompare("black-threshold",option+1) == 0)
881 {
882 /*
883 Black threshold image.
884 */
885 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000886 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000887 InheritException(exception,&(*image)->exception);
888 break;
889 }
890 if (LocaleCompare("blue-shift",option+1) == 0)
891 {
892 /*
893 Blue shift image.
894 */
895 (void) SyncImageSettings(mogrify_info,*image);
896 geometry_info.rho=1.5;
897 if (*option == '-')
898 flags=ParseGeometry(argv[i+1],&geometry_info);
899 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
900 break;
901 }
902 if (LocaleCompare("blur",option+1) == 0)
903 {
904 /*
905 Gaussian blur image.
906 */
907 (void) SyncImageSettings(mogrify_info,*image);
908 flags=ParseGeometry(argv[i+1],&geometry_info);
909 if ((flags & SigmaValue) == 0)
910 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000911 if ((flags & XiValue) == 0)
912 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000913 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000914 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000915 break;
916 }
917 if (LocaleCompare("border",option+1) == 0)
918 {
919 /*
920 Surround image with a border of solid color.
921 */
922 (void) SyncImageSettings(mogrify_info,*image);
923 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
924 if ((flags & SigmaValue) == 0)
925 geometry.height=geometry.width;
926 mogrify_image=BorderImage(*image,&geometry,exception);
927 break;
928 }
929 if (LocaleCompare("bordercolor",option+1) == 0)
930 {
931 if (*option == '+')
932 {
cristy05c0c9a2011-09-05 23:16:13 +0000933 (void) QueryColorDatabase(MogrifyBorderColor,
934 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000935 break;
936 }
937 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
938 exception);
939 break;
940 }
941 if (LocaleCompare("box",option+1) == 0)
942 {
943 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
944 exception);
945 break;
946 }
947 if (LocaleCompare("brightness-contrast",option+1) == 0)
948 {
949 double
950 brightness,
951 contrast;
952
953 GeometryInfo
954 geometry_info;
955
956 MagickStatusType
957 flags;
958
959 /*
960 Brightness / contrast image.
961 */
962 (void) SyncImageSettings(mogrify_info,*image);
963 flags=ParseGeometry(argv[i+1],&geometry_info);
964 brightness=geometry_info.rho;
965 contrast=0.0;
966 if ((flags & SigmaValue) != 0)
967 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000968 (void) BrightnessContrastImage(*image,brightness,contrast,
969 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000970 InheritException(exception,&(*image)->exception);
971 break;
972 }
973 break;
974 }
975 case 'c':
976 {
977 if (LocaleCompare("cdl",option+1) == 0)
978 {
979 char
980 *color_correction_collection;
981
982 /*
983 Color correct with a color decision list.
984 */
985 (void) SyncImageSettings(mogrify_info,*image);
986 color_correction_collection=FileToString(argv[i+1],~0,exception);
987 if (color_correction_collection == (char *) NULL)
988 break;
cristy1bfa9f02011-08-11 02:35:43 +0000989 (void) ColorDecisionListImage(*image,color_correction_collection,
990 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000991 InheritException(exception,&(*image)->exception);
992 break;
993 }
994 if (LocaleCompare("channel",option+1) == 0)
995 {
996 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000997 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000998 else
cristyfa806a72011-07-04 02:06:13 +0000999 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00001000 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001001 break;
1002 }
1003 if (LocaleCompare("charcoal",option+1) == 0)
1004 {
1005 /*
1006 Charcoal image.
1007 */
1008 (void) SyncImageSettings(mogrify_info,*image);
1009 flags=ParseGeometry(argv[i+1],&geometry_info);
1010 if ((flags & SigmaValue) == 0)
1011 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001012 if ((flags & XiValue) == 0)
1013 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001014 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001015 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001016 break;
1017 }
1018 if (LocaleCompare("chop",option+1) == 0)
1019 {
1020 /*
1021 Chop the image.
1022 */
1023 (void) SyncImageSettings(mogrify_info,*image);
1024 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1025 mogrify_image=ChopImage(*image,&geometry,exception);
1026 break;
1027 }
1028 if (LocaleCompare("clamp",option+1) == 0)
1029 {
1030 /*
1031 Clamp image.
1032 */
1033 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001034 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001035 InheritException(exception,&(*image)->exception);
1036 break;
1037 }
1038 if (LocaleCompare("clip",option+1) == 0)
1039 {
1040 (void) SyncImageSettings(mogrify_info,*image);
1041 if (*option == '+')
1042 {
cristy018f07f2011-09-04 21:15:19 +00001043 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001044 break;
1045 }
cristy018f07f2011-09-04 21:15:19 +00001046 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001047 break;
1048 }
1049 if (LocaleCompare("clip-mask",option+1) == 0)
1050 {
1051 CacheView
1052 *mask_view;
1053
1054 Image
1055 *mask_image;
1056
cristy4c08aed2011-07-01 19:47:50 +00001057 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001058 *restrict q;
1059
1060 register ssize_t
1061 x;
1062
1063 ssize_t
1064 y;
1065
1066 (void) SyncImageSettings(mogrify_info,*image);
1067 if (*option == '+')
1068 {
1069 /*
1070 Remove a mask.
1071 */
cristy018f07f2011-09-04 21:15:19 +00001072 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001073 break;
1074 }
1075 /*
1076 Set the image mask.
1077 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1078 */
1079 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1080 if (mask_image == (Image *) NULL)
1081 break;
cristy574cc262011-08-05 01:23:58 +00001082 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001083 return(MagickFalse);
1084 mask_view=AcquireCacheView(mask_image);
1085 for (y=0; y < (ssize_t) mask_image->rows; y++)
1086 {
1087 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1088 exception);
cristyacd2ed22011-08-30 01:44:23 +00001089 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001090 break;
1091 for (x=0; x < (ssize_t) mask_image->columns; x++)
1092 {
1093 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001094 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1095 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1096 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1097 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001098 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001099 }
1100 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1101 break;
1102 }
1103 mask_view=DestroyCacheView(mask_view);
1104 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001105 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001106 InheritException(exception,&(*image)->exception);
1107 break;
1108 }
1109 if (LocaleCompare("clip-path",option+1) == 0)
1110 {
1111 (void) SyncImageSettings(mogrify_info,*image);
1112 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001113 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001114 break;
1115 }
1116 if (LocaleCompare("colorize",option+1) == 0)
1117 {
1118 /*
1119 Colorize the image.
1120 */
1121 (void) SyncImageSettings(mogrify_info,*image);
1122 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1123 exception);
1124 break;
1125 }
1126 if (LocaleCompare("color-matrix",option+1) == 0)
1127 {
1128 KernelInfo
1129 *kernel;
1130
1131 (void) SyncImageSettings(mogrify_info,*image);
1132 kernel=AcquireKernelInfo(argv[i+1]);
1133 if (kernel == (KernelInfo *) NULL)
1134 break;
1135 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1136 kernel=DestroyKernelInfo(kernel);
1137 break;
1138 }
1139 if (LocaleCompare("colors",option+1) == 0)
1140 {
1141 /*
1142 Reduce the number of colors in the image.
1143 */
1144 (void) SyncImageSettings(mogrify_info,*image);
1145 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1146 if (quantize_info->number_colors == 0)
1147 break;
1148 if (((*image)->storage_class == DirectClass) ||
1149 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001150 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001151 else
cristy018f07f2011-09-04 21:15:19 +00001152 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001153 break;
1154 }
1155 if (LocaleCompare("colorspace",option+1) == 0)
1156 {
1157 ColorspaceType
1158 colorspace;
1159
1160 (void) SyncImageSettings(mogrify_info,*image);
1161 if (*option == '+')
1162 {
1163 (void) TransformImageColorspace(*image,RGBColorspace);
1164 InheritException(exception,&(*image)->exception);
1165 break;
1166 }
1167 colorspace=(ColorspaceType) ParseCommandOption(
1168 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1169 (void) TransformImageColorspace(*image,colorspace);
1170 InheritException(exception,&(*image)->exception);
1171 break;
1172 }
1173 if (LocaleCompare("contrast",option+1) == 0)
1174 {
1175 (void) SyncImageSettings(mogrify_info,*image);
1176 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001177 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001178 break;
1179 }
1180 if (LocaleCompare("contrast-stretch",option+1) == 0)
1181 {
1182 double
1183 black_point,
1184 white_point;
1185
1186 MagickStatusType
1187 flags;
1188
1189 /*
1190 Contrast stretch image.
1191 */
1192 (void) SyncImageSettings(mogrify_info,*image);
1193 flags=ParseGeometry(argv[i+1],&geometry_info);
1194 black_point=geometry_info.rho;
1195 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1196 black_point;
1197 if ((flags & PercentValue) != 0)
1198 {
1199 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1200 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1201 }
1202 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1203 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001204 (void) ContrastStretchImage(*image,black_point,white_point,
1205 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001206 InheritException(exception,&(*image)->exception);
1207 break;
1208 }
1209 if (LocaleCompare("convolve",option+1) == 0)
1210 {
anthonydf8ebac2011-04-27 09:03:19 +00001211 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001212 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001213
anthonydf8ebac2011-04-27 09:03:19 +00001214 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001215 kernel_info=AcquireKernelInfo(argv[i+1]);
1216 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001217 break;
cristy0a922382011-07-16 15:30:34 +00001218 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001219 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001220 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001221 break;
1222 }
1223 if (LocaleCompare("crop",option+1) == 0)
1224 {
1225 /*
1226 Crop a image to a smaller size
1227 */
1228 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001229 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001230 break;
1231 }
1232 if (LocaleCompare("cycle",option+1) == 0)
1233 {
1234 /*
1235 Cycle an image colormap.
1236 */
1237 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00001238 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1239 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001240 break;
1241 }
1242 break;
1243 }
1244 case 'd':
1245 {
1246 if (LocaleCompare("decipher",option+1) == 0)
1247 {
1248 StringInfo
1249 *passkey;
1250
1251 /*
1252 Decipher pixels.
1253 */
1254 (void) SyncImageSettings(mogrify_info,*image);
1255 passkey=FileToStringInfo(argv[i+1],~0,exception);
1256 if (passkey != (StringInfo *) NULL)
1257 {
1258 (void) PasskeyDecipherImage(*image,passkey,exception);
1259 passkey=DestroyStringInfo(passkey);
1260 }
1261 break;
1262 }
1263 if (LocaleCompare("density",option+1) == 0)
1264 {
1265 /*
1266 Set image density.
1267 */
1268 (void) CloneString(&draw_info->density,argv[i+1]);
1269 break;
1270 }
1271 if (LocaleCompare("depth",option+1) == 0)
1272 {
1273 (void) SyncImageSettings(mogrify_info,*image);
1274 if (*option == '+')
1275 {
1276 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1277 break;
1278 }
1279 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1280 break;
1281 }
1282 if (LocaleCompare("deskew",option+1) == 0)
1283 {
1284 double
1285 threshold;
1286
1287 /*
1288 Straighten the image.
1289 */
1290 (void) SyncImageSettings(mogrify_info,*image);
1291 if (*option == '+')
1292 threshold=40.0*QuantumRange/100.0;
1293 else
1294 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1295 mogrify_image=DeskewImage(*image,threshold,exception);
1296 break;
1297 }
1298 if (LocaleCompare("despeckle",option+1) == 0)
1299 {
1300 /*
1301 Reduce the speckles within an image.
1302 */
1303 (void) SyncImageSettings(mogrify_info,*image);
1304 mogrify_image=DespeckleImage(*image,exception);
1305 break;
1306 }
1307 if (LocaleCompare("display",option+1) == 0)
1308 {
1309 (void) CloneString(&draw_info->server_name,argv[i+1]);
1310 break;
1311 }
1312 if (LocaleCompare("distort",option+1) == 0)
1313 {
1314 char
1315 *args,
1316 token[MaxTextExtent];
1317
1318 const char
1319 *p;
1320
1321 DistortImageMethod
1322 method;
1323
1324 double
1325 *arguments;
1326
1327 register ssize_t
1328 x;
1329
1330 size_t
1331 number_arguments;
1332
1333 /*
1334 Distort image.
1335 */
1336 (void) SyncImageSettings(mogrify_info,*image);
1337 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1338 MagickFalse,argv[i+1]);
1339 if ( method == ResizeDistortion )
1340 {
1341 /* Special Case - Argument is actually a resize geometry!
1342 ** Convert that to an appropriate distortion argument array.
1343 */
1344 double
1345 resize_args[2];
1346 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1347 exception);
1348 resize_args[0]=(double)geometry.width;
1349 resize_args[1]=(double)geometry.height;
1350 mogrify_image=DistortImage(*image,method,(size_t)2,
1351 resize_args,MagickTrue,exception);
1352 break;
1353 }
cristy018f07f2011-09-04 21:15:19 +00001354 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1355 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001356 if (args == (char *) NULL)
1357 break;
1358 p=(char *) args;
1359 for (x=0; *p != '\0'; x++)
1360 {
1361 GetMagickToken(p,&p,token);
1362 if (*token == ',')
1363 GetMagickToken(p,&p,token);
1364 }
1365 number_arguments=(size_t) x;
1366 arguments=(double *) AcquireQuantumMemory(number_arguments,
1367 sizeof(*arguments));
1368 if (arguments == (double *) NULL)
1369 ThrowWandFatalException(ResourceLimitFatalError,
1370 "MemoryAllocationFailed",(*image)->filename);
1371 (void) ResetMagickMemory(arguments,0,number_arguments*
1372 sizeof(*arguments));
1373 p=(char *) args;
1374 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1375 {
1376 GetMagickToken(p,&p,token);
1377 if (*token == ',')
1378 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001379 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001380 }
1381 args=DestroyString(args);
1382 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1383 (*option == '+') ? MagickTrue : MagickFalse,exception);
1384 arguments=(double *) RelinquishMagickMemory(arguments);
1385 break;
1386 }
1387 if (LocaleCompare("dither",option+1) == 0)
1388 {
1389 if (*option == '+')
1390 {
1391 quantize_info->dither=MagickFalse;
1392 break;
1393 }
1394 quantize_info->dither=MagickTrue;
1395 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1396 MagickDitherOptions,MagickFalse,argv[i+1]);
1397 if (quantize_info->dither_method == NoDitherMethod)
1398 quantize_info->dither=MagickFalse;
1399 break;
1400 }
1401 if (LocaleCompare("draw",option+1) == 0)
1402 {
1403 /*
1404 Draw image.
1405 */
1406 (void) SyncImageSettings(mogrify_info,*image);
1407 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001408 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001409 break;
1410 }
1411 break;
1412 }
1413 case 'e':
1414 {
1415 if (LocaleCompare("edge",option+1) == 0)
1416 {
1417 /*
1418 Enhance edges in the image.
1419 */
1420 (void) SyncImageSettings(mogrify_info,*image);
1421 flags=ParseGeometry(argv[i+1],&geometry_info);
1422 if ((flags & SigmaValue) == 0)
1423 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001424 mogrify_image=EdgeImage(*image,geometry_info.rho,
1425 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001426 break;
1427 }
1428 if (LocaleCompare("emboss",option+1) == 0)
1429 {
1430 /*
1431 Gaussian embossen image.
1432 */
1433 (void) SyncImageSettings(mogrify_info,*image);
1434 flags=ParseGeometry(argv[i+1],&geometry_info);
1435 if ((flags & SigmaValue) == 0)
1436 geometry_info.sigma=1.0;
1437 mogrify_image=EmbossImage(*image,geometry_info.rho,
1438 geometry_info.sigma,exception);
1439 break;
1440 }
1441 if (LocaleCompare("encipher",option+1) == 0)
1442 {
1443 StringInfo
1444 *passkey;
1445
1446 /*
1447 Encipher pixels.
1448 */
1449 (void) SyncImageSettings(mogrify_info,*image);
1450 passkey=FileToStringInfo(argv[i+1],~0,exception);
1451 if (passkey != (StringInfo *) NULL)
1452 {
1453 (void) PasskeyEncipherImage(*image,passkey,exception);
1454 passkey=DestroyStringInfo(passkey);
1455 }
1456 break;
1457 }
1458 if (LocaleCompare("encoding",option+1) == 0)
1459 {
1460 (void) CloneString(&draw_info->encoding,argv[i+1]);
1461 break;
1462 }
1463 if (LocaleCompare("enhance",option+1) == 0)
1464 {
1465 /*
1466 Enhance image.
1467 */
1468 (void) SyncImageSettings(mogrify_info,*image);
1469 mogrify_image=EnhanceImage(*image,exception);
1470 break;
1471 }
1472 if (LocaleCompare("equalize",option+1) == 0)
1473 {
1474 /*
1475 Equalize image.
1476 */
1477 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001478 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001479 break;
1480 }
1481 if (LocaleCompare("evaluate",option+1) == 0)
1482 {
1483 double
1484 constant;
1485
1486 MagickEvaluateOperator
1487 op;
1488
1489 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001490 op=(MagickEvaluateOperator) ParseCommandOption(
1491 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001492 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001493 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001494 break;
1495 }
1496 if (LocaleCompare("extent",option+1) == 0)
1497 {
1498 /*
1499 Set the image extent.
1500 */
1501 (void) SyncImageSettings(mogrify_info,*image);
1502 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1503 if (geometry.width == 0)
1504 geometry.width=(*image)->columns;
1505 if (geometry.height == 0)
1506 geometry.height=(*image)->rows;
1507 mogrify_image=ExtentImage(*image,&geometry,exception);
1508 break;
1509 }
1510 break;
1511 }
1512 case 'f':
1513 {
1514 if (LocaleCompare("family",option+1) == 0)
1515 {
1516 if (*option == '+')
1517 {
1518 if (draw_info->family != (char *) NULL)
1519 draw_info->family=DestroyString(draw_info->family);
1520 break;
1521 }
1522 (void) CloneString(&draw_info->family,argv[i+1]);
1523 break;
1524 }
1525 if (LocaleCompare("features",option+1) == 0)
1526 {
1527 if (*option == '+')
1528 {
1529 (void) DeleteImageArtifact(*image,"identify:features");
1530 break;
1531 }
1532 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1533 break;
1534 }
1535 if (LocaleCompare("fill",option+1) == 0)
1536 {
1537 ExceptionInfo
1538 *sans;
1539
cristy4c08aed2011-07-01 19:47:50 +00001540 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001541 if (*option == '+')
1542 {
1543 (void) QueryMagickColor("none",&fill,exception);
1544 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1545 if (draw_info->fill_pattern != (Image *) NULL)
1546 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1547 break;
1548 }
1549 sans=AcquireExceptionInfo();
1550 (void) QueryMagickColor(argv[i+1],&fill,sans);
1551 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1552 sans=DestroyExceptionInfo(sans);
1553 if (status == MagickFalse)
1554 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1555 exception);
1556 break;
1557 }
1558 if (LocaleCompare("flip",option+1) == 0)
1559 {
1560 /*
1561 Flip image scanlines.
1562 */
1563 (void) SyncImageSettings(mogrify_info,*image);
1564 mogrify_image=FlipImage(*image,exception);
1565 break;
1566 }
anthonydf8ebac2011-04-27 09:03:19 +00001567 if (LocaleCompare("floodfill",option+1) == 0)
1568 {
cristy4c08aed2011-07-01 19:47:50 +00001569 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001570 target;
1571
1572 /*
1573 Floodfill image.
1574 */
1575 (void) SyncImageSettings(mogrify_info,*image);
1576 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1577 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001578 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001579 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001580 break;
1581 }
anthony3d2f4862011-05-01 13:48:16 +00001582 if (LocaleCompare("flop",option+1) == 0)
1583 {
1584 /*
1585 Flop image scanlines.
1586 */
1587 (void) SyncImageSettings(mogrify_info,*image);
1588 mogrify_image=FlopImage(*image,exception);
1589 break;
1590 }
anthonydf8ebac2011-04-27 09:03:19 +00001591 if (LocaleCompare("font",option+1) == 0)
1592 {
1593 if (*option == '+')
1594 {
1595 if (draw_info->font != (char *) NULL)
1596 draw_info->font=DestroyString(draw_info->font);
1597 break;
1598 }
1599 (void) CloneString(&draw_info->font,argv[i+1]);
1600 break;
1601 }
1602 if (LocaleCompare("format",option+1) == 0)
1603 {
1604 format=argv[i+1];
1605 break;
1606 }
1607 if (LocaleCompare("frame",option+1) == 0)
1608 {
1609 FrameInfo
1610 frame_info;
1611
1612 /*
1613 Surround image with an ornamental border.
1614 */
1615 (void) SyncImageSettings(mogrify_info,*image);
1616 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1617 frame_info.width=geometry.width;
1618 frame_info.height=geometry.height;
1619 if ((flags & HeightValue) == 0)
1620 frame_info.height=geometry.width;
1621 frame_info.outer_bevel=geometry.x;
1622 frame_info.inner_bevel=geometry.y;
1623 frame_info.x=(ssize_t) frame_info.width;
1624 frame_info.y=(ssize_t) frame_info.height;
1625 frame_info.width=(*image)->columns+2*frame_info.width;
1626 frame_info.height=(*image)->rows+2*frame_info.height;
1627 mogrify_image=FrameImage(*image,&frame_info,exception);
1628 break;
1629 }
1630 if (LocaleCompare("function",option+1) == 0)
1631 {
1632 char
1633 *arguments,
1634 token[MaxTextExtent];
1635
1636 const char
1637 *p;
1638
1639 double
1640 *parameters;
1641
1642 MagickFunction
1643 function;
1644
1645 register ssize_t
1646 x;
1647
1648 size_t
1649 number_parameters;
1650
1651 /*
1652 Function Modify Image Values
1653 */
1654 (void) SyncImageSettings(mogrify_info,*image);
1655 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1656 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001657 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1658 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001659 if (arguments == (char *) NULL)
1660 break;
1661 p=(char *) arguments;
1662 for (x=0; *p != '\0'; x++)
1663 {
1664 GetMagickToken(p,&p,token);
1665 if (*token == ',')
1666 GetMagickToken(p,&p,token);
1667 }
1668 number_parameters=(size_t) x;
1669 parameters=(double *) AcquireQuantumMemory(number_parameters,
1670 sizeof(*parameters));
1671 if (parameters == (double *) NULL)
1672 ThrowWandFatalException(ResourceLimitFatalError,
1673 "MemoryAllocationFailed",(*image)->filename);
1674 (void) ResetMagickMemory(parameters,0,number_parameters*
1675 sizeof(*parameters));
1676 p=(char *) arguments;
1677 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1678 {
1679 GetMagickToken(p,&p,token);
1680 if (*token == ',')
1681 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001682 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001683 }
1684 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001685 (void) FunctionImage(*image,function,number_parameters,parameters,
1686 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001687 parameters=(double *) RelinquishMagickMemory(parameters);
1688 break;
1689 }
1690 break;
1691 }
1692 case 'g':
1693 {
1694 if (LocaleCompare("gamma",option+1) == 0)
1695 {
1696 /*
1697 Gamma image.
1698 */
1699 (void) SyncImageSettings(mogrify_info,*image);
1700 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001701 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001702 else
cristyb3e7c6c2011-07-24 01:43:55 +00001703 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1704 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001705 break;
1706 }
1707 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1708 (LocaleCompare("gaussian",option+1) == 0))
1709 {
1710 /*
1711 Gaussian blur image.
1712 */
1713 (void) SyncImageSettings(mogrify_info,*image);
1714 flags=ParseGeometry(argv[i+1],&geometry_info);
1715 if ((flags & SigmaValue) == 0)
1716 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001717 if ((flags & XiValue) == 0)
1718 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001719 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001720 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001721 break;
1722 }
1723 if (LocaleCompare("geometry",option+1) == 0)
1724 {
1725 /*
1726 Record Image offset, Resize last image.
1727 */
1728 (void) SyncImageSettings(mogrify_info,*image);
1729 if (*option == '+')
1730 {
1731 if ((*image)->geometry != (char *) NULL)
1732 (*image)->geometry=DestroyString((*image)->geometry);
1733 break;
1734 }
1735 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1736 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1737 (void) CloneString(&(*image)->geometry,argv[i+1]);
1738 else
1739 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1740 (*image)->filter,(*image)->blur,exception);
1741 break;
1742 }
1743 if (LocaleCompare("gravity",option+1) == 0)
1744 {
1745 if (*option == '+')
1746 {
1747 draw_info->gravity=UndefinedGravity;
1748 break;
1749 }
1750 draw_info->gravity=(GravityType) ParseCommandOption(
1751 MagickGravityOptions,MagickFalse,argv[i+1]);
1752 break;
1753 }
1754 break;
1755 }
1756 case 'h':
1757 {
1758 if (LocaleCompare("highlight-color",option+1) == 0)
1759 {
1760 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1761 break;
1762 }
1763 break;
1764 }
1765 case 'i':
1766 {
1767 if (LocaleCompare("identify",option+1) == 0)
1768 {
1769 char
1770 *text;
1771
1772 (void) SyncImageSettings(mogrify_info,*image);
1773 if (format == (char *) NULL)
1774 {
cristya4037272011-08-28 15:11:39 +00001775 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1776 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001777 break;
1778 }
cristy018f07f2011-09-04 21:15:19 +00001779 text=InterpretImageProperties(mogrify_info,*image,format,
1780 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001781 if (text == (char *) NULL)
1782 break;
1783 (void) fputs(text,stdout);
1784 (void) fputc('\n',stdout);
1785 text=DestroyString(text);
1786 break;
1787 }
1788 if (LocaleCompare("implode",option+1) == 0)
1789 {
1790 /*
1791 Implode image.
1792 */
1793 (void) SyncImageSettings(mogrify_info,*image);
1794 (void) ParseGeometry(argv[i+1],&geometry_info);
1795 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1796 break;
1797 }
1798 if (LocaleCompare("interline-spacing",option+1) == 0)
1799 {
1800 if (*option == '+')
1801 (void) ParseGeometry("0",&geometry_info);
1802 else
1803 (void) ParseGeometry(argv[i+1],&geometry_info);
1804 draw_info->interline_spacing=geometry_info.rho;
1805 break;
1806 }
cristy28474bf2011-09-11 23:32:52 +00001807 if (LocaleCompare("interpolate",option+1) == 0)
1808 {
1809 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1810 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1811 break;
1812 }
anthonydf8ebac2011-04-27 09:03:19 +00001813 if (LocaleCompare("interword-spacing",option+1) == 0)
1814 {
1815 if (*option == '+')
1816 (void) ParseGeometry("0",&geometry_info);
1817 else
1818 (void) ParseGeometry(argv[i+1],&geometry_info);
1819 draw_info->interword_spacing=geometry_info.rho;
1820 break;
1821 }
1822 break;
1823 }
1824 case 'k':
1825 {
1826 if (LocaleCompare("kerning",option+1) == 0)
1827 {
1828 if (*option == '+')
1829 (void) ParseGeometry("0",&geometry_info);
1830 else
1831 (void) ParseGeometry(argv[i+1],&geometry_info);
1832 draw_info->kerning=geometry_info.rho;
1833 break;
1834 }
1835 break;
1836 }
1837 case 'l':
1838 {
1839 if (LocaleCompare("lat",option+1) == 0)
1840 {
1841 /*
1842 Local adaptive threshold image.
1843 */
1844 (void) SyncImageSettings(mogrify_info,*image);
1845 flags=ParseGeometry(argv[i+1],&geometry_info);
1846 if ((flags & PercentValue) != 0)
1847 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1848 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001849 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001850 geometry_info.xi,exception);
1851 break;
1852 }
1853 if (LocaleCompare("level",option+1) == 0)
1854 {
1855 MagickRealType
1856 black_point,
1857 gamma,
1858 white_point;
1859
1860 MagickStatusType
1861 flags;
1862
1863 /*
1864 Parse levels.
1865 */
1866 (void) SyncImageSettings(mogrify_info,*image);
1867 flags=ParseGeometry(argv[i+1],&geometry_info);
1868 black_point=geometry_info.rho;
1869 white_point=(MagickRealType) QuantumRange;
1870 if ((flags & SigmaValue) != 0)
1871 white_point=geometry_info.sigma;
1872 gamma=1.0;
1873 if ((flags & XiValue) != 0)
1874 gamma=geometry_info.xi;
1875 if ((flags & PercentValue) != 0)
1876 {
1877 black_point*=(MagickRealType) (QuantumRange/100.0);
1878 white_point*=(MagickRealType) (QuantumRange/100.0);
1879 }
1880 if ((flags & SigmaValue) == 0)
1881 white_point=(MagickRealType) QuantumRange-black_point;
1882 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001883 (void) LevelizeImage(*image,black_point,white_point,gamma,
1884 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001885 else
cristy01e9afd2011-08-10 17:38:41 +00001886 (void) LevelImage(*image,black_point,white_point,gamma,
1887 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001888 InheritException(exception,&(*image)->exception);
1889 break;
1890 }
1891 if (LocaleCompare("level-colors",option+1) == 0)
1892 {
1893 char
1894 token[MaxTextExtent];
1895
1896 const char
1897 *p;
1898
cristy4c08aed2011-07-01 19:47:50 +00001899 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001900 black_point,
1901 white_point;
1902
1903 p=(const char *) argv[i+1];
1904 GetMagickToken(p,&p,token); /* get black point color */
1905 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1906 (void) QueryMagickColor(token,&black_point,exception);
1907 else
1908 (void) QueryMagickColor("#000000",&black_point,exception);
1909 if (isalpha((int) token[0]) || (token[0] == '#'))
1910 GetMagickToken(p,&p,token);
1911 if (*token == '\0')
1912 white_point=black_point; /* set everything to that color */
1913 else
1914 {
1915 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1916 GetMagickToken(p,&p,token); /* Get white point color. */
1917 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1918 (void) QueryMagickColor(token,&white_point,exception);
1919 else
1920 (void) QueryMagickColor("#ffffff",&white_point,exception);
1921 }
cristy490408a2011-07-07 14:42:05 +00001922 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001923 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001924 break;
1925 }
1926 if (LocaleCompare("linear-stretch",option+1) == 0)
1927 {
1928 double
1929 black_point,
1930 white_point;
1931
1932 MagickStatusType
1933 flags;
1934
1935 (void) SyncImageSettings(mogrify_info,*image);
1936 flags=ParseGeometry(argv[i+1],&geometry_info);
1937 black_point=geometry_info.rho;
1938 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1939 if ((flags & SigmaValue) != 0)
1940 white_point=geometry_info.sigma;
1941 if ((flags & PercentValue) != 0)
1942 {
1943 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1944 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1945 }
1946 if ((flags & SigmaValue) == 0)
1947 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1948 black_point;
cristy33bd5152011-08-24 01:42:24 +00001949 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001950 InheritException(exception,&(*image)->exception);
1951 break;
1952 }
1953 if (LocaleCompare("linewidth",option+1) == 0)
1954 {
cristyc1acd842011-05-19 23:05:47 +00001955 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1956 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001957 break;
1958 }
1959 if (LocaleCompare("liquid-rescale",option+1) == 0)
1960 {
1961 /*
1962 Liquid rescale image.
1963 */
1964 (void) SyncImageSettings(mogrify_info,*image);
1965 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1966 if ((flags & XValue) == 0)
1967 geometry.x=1;
1968 if ((flags & YValue) == 0)
1969 geometry.y=0;
1970 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1971 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1972 break;
1973 }
1974 if (LocaleCompare("lowlight-color",option+1) == 0)
1975 {
1976 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1977 break;
1978 }
1979 break;
1980 }
1981 case 'm':
1982 {
1983 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001984 {
cristy3ed852e2009-09-05 21:47:34 +00001985 Image
anthonydf8ebac2011-04-27 09:03:19 +00001986 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001987
anthonydf8ebac2011-04-27 09:03:19 +00001988 /*
1989 Transform image colors to match this set of colors.
1990 */
1991 (void) SyncImageSettings(mogrify_info,*image);
1992 if (*option == '+')
1993 break;
1994 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1995 if (remap_image == (Image *) NULL)
1996 break;
cristy018f07f2011-09-04 21:15:19 +00001997 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001998 remap_image=DestroyImage(remap_image);
1999 break;
2000 }
2001 if (LocaleCompare("mask",option+1) == 0)
2002 {
2003 Image
2004 *mask;
2005
2006 (void) SyncImageSettings(mogrify_info,*image);
2007 if (*option == '+')
2008 {
2009 /*
2010 Remove a mask.
2011 */
cristy018f07f2011-09-04 21:15:19 +00002012 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002013 break;
2014 }
2015 /*
2016 Set the image mask.
2017 */
2018 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2019 if (mask == (Image *) NULL)
2020 break;
cristy018f07f2011-09-04 21:15:19 +00002021 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002022 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002023 break;
2024 }
2025 if (LocaleCompare("matte",option+1) == 0)
2026 {
2027 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002028 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002029 break;
2030 }
2031 if (LocaleCompare("median",option+1) == 0)
2032 {
2033 /*
2034 Median filter image.
2035 */
2036 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002037 flags=ParseGeometry(argv[i+1],&geometry_info);
2038 if ((flags & SigmaValue) == 0)
2039 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002040 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002041 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002042 break;
2043 }
2044 if (LocaleCompare("mode",option+1) == 0)
2045 {
2046 /*
2047 Mode image.
2048 */
2049 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002050 flags=ParseGeometry(argv[i+1],&geometry_info);
2051 if ((flags & SigmaValue) == 0)
2052 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002053 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002054 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002055 break;
2056 }
2057 if (LocaleCompare("modulate",option+1) == 0)
2058 {
2059 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002060 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002061 break;
2062 }
2063 if (LocaleCompare("monitor",option+1) == 0)
2064 {
2065 if (*option == '+')
2066 {
2067 (void) SetImageProgressMonitor(*image,
2068 (MagickProgressMonitor) NULL,(void *) NULL);
2069 break;
2070 }
2071 (void) SetImageProgressMonitor(*image,MonitorProgress,
2072 (void *) NULL);
2073 break;
2074 }
2075 if (LocaleCompare("monochrome",option+1) == 0)
2076 {
2077 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00002078 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002079 break;
2080 }
2081 if (LocaleCompare("morphology",option+1) == 0)
2082 {
2083 char
2084 token[MaxTextExtent];
2085
2086 const char
2087 *p;
2088
2089 KernelInfo
2090 *kernel;
2091
2092 MorphologyMethod
2093 method;
2094
2095 ssize_t
2096 iterations;
2097
2098 /*
2099 Morphological Image Operation
2100 */
2101 (void) SyncImageSettings(mogrify_info,*image);
2102 p=argv[i+1];
2103 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002104 method=(MorphologyMethod) ParseCommandOption(
2105 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002106 iterations=1L;
2107 GetMagickToken(p,&p,token);
2108 if ((*p == ':') || (*p == ','))
2109 GetMagickToken(p,&p,token);
2110 if ((*p != '\0'))
2111 iterations=(ssize_t) StringToLong(p);
2112 kernel=AcquireKernelInfo(argv[i+2]);
2113 if (kernel == (KernelInfo *) NULL)
2114 {
2115 (void) ThrowMagickException(exception,GetMagickModule(),
2116 OptionError,"UnabletoParseKernel","morphology");
2117 status=MagickFalse;
2118 break;
2119 }
cristyf4ad9df2011-07-08 16:49:03 +00002120 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2121 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002122 kernel=DestroyKernelInfo(kernel);
2123 break;
2124 }
2125 if (LocaleCompare("motion-blur",option+1) == 0)
2126 {
2127 /*
2128 Motion blur image.
2129 */
2130 (void) SyncImageSettings(mogrify_info,*image);
2131 flags=ParseGeometry(argv[i+1],&geometry_info);
2132 if ((flags & SigmaValue) == 0)
2133 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002134 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002135 geometry_info.sigma,geometry_info.xi,geometry_info.psi,
2136 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002137 break;
2138 }
2139 break;
2140 }
2141 case 'n':
2142 {
2143 if (LocaleCompare("negate",option+1) == 0)
2144 {
2145 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002146 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002147 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002148 break;
2149 }
2150 if (LocaleCompare("noise",option+1) == 0)
2151 {
2152 (void) SyncImageSettings(mogrify_info,*image);
2153 if (*option == '-')
2154 {
cristyf36cbcb2011-09-07 13:28:22 +00002155 flags=ParseGeometry(argv[i+1],&geometry_info);
2156 if ((flags & SigmaValue) == 0)
2157 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002158 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002159 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002160 }
2161 else
2162 {
2163 NoiseType
2164 noise;
2165
2166 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2167 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002168 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002169 }
2170 break;
2171 }
2172 if (LocaleCompare("normalize",option+1) == 0)
2173 {
2174 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002175 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002176 break;
2177 }
2178 break;
2179 }
2180 case 'o':
2181 {
2182 if (LocaleCompare("opaque",option+1) == 0)
2183 {
cristy4c08aed2011-07-01 19:47:50 +00002184 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002185 target;
2186
2187 (void) SyncImageSettings(mogrify_info,*image);
2188 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002189 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002190 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002191 break;
2192 }
2193 if (LocaleCompare("ordered-dither",option+1) == 0)
2194 {
2195 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002196 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002197 break;
2198 }
2199 break;
2200 }
2201 case 'p':
2202 {
2203 if (LocaleCompare("paint",option+1) == 0)
2204 {
anthonydf8ebac2011-04-27 09:03:19 +00002205 (void) SyncImageSettings(mogrify_info,*image);
2206 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002207 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2208 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002209 break;
2210 }
2211 if (LocaleCompare("pen",option+1) == 0)
2212 {
2213 if (*option == '+')
2214 {
2215 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2216 break;
2217 }
2218 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2219 break;
2220 }
2221 if (LocaleCompare("pointsize",option+1) == 0)
2222 {
2223 if (*option == '+')
2224 (void) ParseGeometry("12",&geometry_info);
2225 else
2226 (void) ParseGeometry(argv[i+1],&geometry_info);
2227 draw_info->pointsize=geometry_info.rho;
2228 break;
2229 }
2230 if (LocaleCompare("polaroid",option+1) == 0)
2231 {
2232 double
2233 angle;
2234
2235 RandomInfo
2236 *random_info;
2237
2238 /*
2239 Simulate a Polaroid picture.
2240 */
2241 (void) SyncImageSettings(mogrify_info,*image);
2242 random_info=AcquireRandomInfo();
2243 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2244 random_info=DestroyRandomInfo(random_info);
2245 if (*option == '-')
2246 {
2247 SetGeometryInfo(&geometry_info);
2248 flags=ParseGeometry(argv[i+1],&geometry_info);
2249 angle=geometry_info.rho;
2250 }
cristy5c4e2582011-09-11 19:21:03 +00002251 mogrify_image=PolaroidImage(*image,draw_info,angle,
cristy28474bf2011-09-11 23:32:52 +00002252 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002253 break;
2254 }
2255 if (LocaleCompare("posterize",option+1) == 0)
2256 {
2257 /*
2258 Posterize image.
2259 */
2260 (void) SyncImageSettings(mogrify_info,*image);
2261 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002262 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002263 break;
2264 }
2265 if (LocaleCompare("preview",option+1) == 0)
2266 {
2267 PreviewType
2268 preview_type;
2269
2270 /*
2271 Preview image.
2272 */
2273 (void) SyncImageSettings(mogrify_info,*image);
2274 if (*option == '+')
2275 preview_type=UndefinedPreview;
2276 else
cristy28474bf2011-09-11 23:32:52 +00002277 preview_type=(PreviewType) ParseCommandOption(
2278 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002279 mogrify_image=PreviewImage(*image,preview_type,exception);
2280 break;
2281 }
2282 if (LocaleCompare("profile",option+1) == 0)
2283 {
2284 const char
2285 *name;
2286
2287 const StringInfo
2288 *profile;
2289
2290 Image
2291 *profile_image;
2292
2293 ImageInfo
2294 *profile_info;
2295
2296 (void) SyncImageSettings(mogrify_info,*image);
2297 if (*option == '+')
2298 {
2299 /*
2300 Remove a profile from the image.
2301 */
2302 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2303 NULL,0,MagickTrue);
2304 InheritException(exception,&(*image)->exception);
2305 break;
2306 }
2307 /*
2308 Associate a profile with the image.
2309 */
2310 profile_info=CloneImageInfo(mogrify_info);
2311 profile=GetImageProfile(*image,"iptc");
2312 if (profile != (StringInfo *) NULL)
2313 profile_info->profile=(void *) CloneStringInfo(profile);
2314 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2315 profile_info=DestroyImageInfo(profile_info);
2316 if (profile_image == (Image *) NULL)
2317 {
2318 StringInfo
2319 *profile;
2320
2321 profile_info=CloneImageInfo(mogrify_info);
2322 (void) CopyMagickString(profile_info->filename,argv[i+1],
2323 MaxTextExtent);
2324 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2325 if (profile != (StringInfo *) NULL)
2326 {
2327 (void) ProfileImage(*image,profile_info->magick,
2328 GetStringInfoDatum(profile),(size_t)
2329 GetStringInfoLength(profile),MagickFalse);
2330 profile=DestroyStringInfo(profile);
2331 }
2332 profile_info=DestroyImageInfo(profile_info);
2333 break;
2334 }
2335 ResetImageProfileIterator(profile_image);
2336 name=GetNextImageProfile(profile_image);
2337 while (name != (const char *) NULL)
2338 {
2339 profile=GetImageProfile(profile_image,name);
2340 if (profile != (StringInfo *) NULL)
2341 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2342 (size_t) GetStringInfoLength(profile),MagickFalse);
2343 name=GetNextImageProfile(profile_image);
2344 }
2345 profile_image=DestroyImage(profile_image);
2346 break;
2347 }
2348 break;
2349 }
2350 case 'q':
2351 {
2352 if (LocaleCompare("quantize",option+1) == 0)
2353 {
2354 if (*option == '+')
2355 {
2356 quantize_info->colorspace=UndefinedColorspace;
2357 break;
2358 }
2359 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2360 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2361 break;
2362 }
2363 break;
2364 }
2365 case 'r':
2366 {
2367 if (LocaleCompare("radial-blur",option+1) == 0)
2368 {
2369 /*
2370 Radial blur image.
2371 */
2372 (void) SyncImageSettings(mogrify_info,*image);
cristy6435bd92011-09-10 02:10:07 +00002373 flags=ParseGeometry(argv[i+1],&geometry_info);
2374 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2375 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002376 break;
2377 }
2378 if (LocaleCompare("raise",option+1) == 0)
2379 {
2380 /*
2381 Surround image with a raise of solid color.
2382 */
2383 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2384 if ((flags & SigmaValue) == 0)
2385 geometry.height=geometry.width;
2386 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002387 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002388 break;
2389 }
2390 if (LocaleCompare("random-threshold",option+1) == 0)
2391 {
2392 /*
2393 Threshold image.
2394 */
2395 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002396 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002397 break;
2398 }
2399 if (LocaleCompare("recolor",option+1) == 0)
2400 {
2401 KernelInfo
2402 *kernel;
2403
2404 (void) SyncImageSettings(mogrify_info,*image);
2405 kernel=AcquireKernelInfo(argv[i+1]);
2406 if (kernel == (KernelInfo *) NULL)
2407 break;
2408 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2409 kernel=DestroyKernelInfo(kernel);
2410 break;
2411 }
2412 if (LocaleCompare("region",option+1) == 0)
2413 {
2414 (void) SyncImageSettings(mogrify_info,*image);
2415 if (region_image != (Image *) NULL)
2416 {
2417 /*
2418 Composite region.
2419 */
2420 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002421 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2422 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002423 InheritException(exception,&region_image->exception);
2424 *image=DestroyImage(*image);
2425 *image=region_image;
2426 region_image = (Image *) NULL;
2427 }
2428 if (*option == '+')
2429 break;
2430 /*
2431 Apply transformations to a selected region of the image.
2432 */
cristy3ed852e2009-09-05 21:47:34 +00002433 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2434 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002435 mogrify_image=CropImage(*image,&region_geometry,exception);
2436 if (mogrify_image == (Image *) NULL)
2437 break;
2438 region_image=(*image);
2439 *image=mogrify_image;
2440 mogrify_image=(Image *) NULL;
2441 break;
cristy3ed852e2009-09-05 21:47:34 +00002442 }
anthonydf8ebac2011-04-27 09:03:19 +00002443 if (LocaleCompare("render",option+1) == 0)
2444 {
2445 (void) SyncImageSettings(mogrify_info,*image);
2446 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2447 break;
2448 }
2449 if (LocaleCompare("remap",option+1) == 0)
2450 {
2451 Image
2452 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002453
anthonydf8ebac2011-04-27 09:03:19 +00002454 /*
2455 Transform image colors to match this set of colors.
2456 */
2457 (void) SyncImageSettings(mogrify_info,*image);
2458 if (*option == '+')
2459 break;
2460 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2461 if (remap_image == (Image *) NULL)
2462 break;
cristy018f07f2011-09-04 21:15:19 +00002463 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002464 remap_image=DestroyImage(remap_image);
2465 break;
2466 }
2467 if (LocaleCompare("repage",option+1) == 0)
2468 {
2469 if (*option == '+')
2470 {
2471 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2472 break;
2473 }
2474 (void) ResetImagePage(*image,argv[i+1]);
2475 InheritException(exception,&(*image)->exception);
2476 break;
2477 }
2478 if (LocaleCompare("resample",option+1) == 0)
2479 {
2480 /*
2481 Resample image.
2482 */
2483 (void) SyncImageSettings(mogrify_info,*image);
2484 flags=ParseGeometry(argv[i+1],&geometry_info);
2485 if ((flags & SigmaValue) == 0)
2486 geometry_info.sigma=geometry_info.rho;
2487 mogrify_image=ResampleImage(*image,geometry_info.rho,
2488 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2489 break;
2490 }
2491 if (LocaleCompare("resize",option+1) == 0)
2492 {
2493 /*
2494 Resize image.
2495 */
2496 (void) SyncImageSettings(mogrify_info,*image);
2497 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2498 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2499 (*image)->filter,(*image)->blur,exception);
2500 break;
2501 }
2502 if (LocaleCompare("roll",option+1) == 0)
2503 {
2504 /*
2505 Roll image.
2506 */
2507 (void) SyncImageSettings(mogrify_info,*image);
2508 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2509 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2510 break;
2511 }
2512 if (LocaleCompare("rotate",option+1) == 0)
2513 {
2514 char
2515 *geometry;
2516
2517 /*
2518 Check for conditional image rotation.
2519 */
2520 (void) SyncImageSettings(mogrify_info,*image);
2521 if (strchr(argv[i+1],'>') != (char *) NULL)
2522 if ((*image)->columns <= (*image)->rows)
2523 break;
2524 if (strchr(argv[i+1],'<') != (char *) NULL)
2525 if ((*image)->columns >= (*image)->rows)
2526 break;
2527 /*
2528 Rotate image.
2529 */
2530 geometry=ConstantString(argv[i+1]);
2531 (void) SubstituteString(&geometry,">","");
2532 (void) SubstituteString(&geometry,"<","");
2533 (void) ParseGeometry(geometry,&geometry_info);
2534 geometry=DestroyString(geometry);
2535 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2536 break;
2537 }
2538 break;
2539 }
2540 case 's':
2541 {
2542 if (LocaleCompare("sample",option+1) == 0)
2543 {
2544 /*
2545 Sample image with pixel replication.
2546 */
2547 (void) SyncImageSettings(mogrify_info,*image);
2548 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2549 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2550 exception);
2551 break;
2552 }
2553 if (LocaleCompare("scale",option+1) == 0)
2554 {
2555 /*
2556 Resize image.
2557 */
2558 (void) SyncImageSettings(mogrify_info,*image);
2559 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2560 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2561 exception);
2562 break;
2563 }
2564 if (LocaleCompare("selective-blur",option+1) == 0)
2565 {
2566 /*
2567 Selectively blur pixels within a contrast threshold.
2568 */
2569 (void) SyncImageSettings(mogrify_info,*image);
2570 flags=ParseGeometry(argv[i+1],&geometry_info);
2571 if ((flags & PercentValue) != 0)
2572 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002573 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002574 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002575 break;
2576 }
2577 if (LocaleCompare("separate",option+1) == 0)
2578 {
2579 /*
2580 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002581 */
2582 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002583 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002584 break;
2585 }
2586 if (LocaleCompare("sepia-tone",option+1) == 0)
2587 {
2588 double
2589 threshold;
2590
2591 /*
2592 Sepia-tone image.
2593 */
2594 (void) SyncImageSettings(mogrify_info,*image);
2595 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2596 mogrify_image=SepiaToneImage(*image,threshold,exception);
2597 break;
2598 }
2599 if (LocaleCompare("segment",option+1) == 0)
2600 {
2601 /*
2602 Segment image.
2603 */
2604 (void) SyncImageSettings(mogrify_info,*image);
2605 flags=ParseGeometry(argv[i+1],&geometry_info);
2606 if ((flags & SigmaValue) == 0)
2607 geometry_info.sigma=1.0;
2608 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002609 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2610 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002611 break;
2612 }
2613 if (LocaleCompare("set",option+1) == 0)
2614 {
2615 char
2616 *value;
2617
2618 /*
2619 Set image option.
2620 */
2621 if (*option == '+')
2622 {
2623 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2624 (void) DeleteImageRegistry(argv[i+1]+9);
2625 else
2626 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2627 {
2628 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2629 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2630 }
2631 else
2632 (void) DeleteImageProperty(*image,argv[i+1]);
2633 break;
2634 }
cristy018f07f2011-09-04 21:15:19 +00002635 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2636 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002637 if (value == (char *) NULL)
2638 break;
2639 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2640 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2641 exception);
2642 else
2643 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2644 {
2645 (void) SetImageOption(image_info,argv[i+1]+7,value);
2646 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2647 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2648 }
2649 else
2650 (void) SetImageProperty(*image,argv[i+1],value);
2651 value=DestroyString(value);
2652 break;
2653 }
2654 if (LocaleCompare("shade",option+1) == 0)
2655 {
2656 /*
2657 Shade image.
2658 */
2659 (void) SyncImageSettings(mogrify_info,*image);
2660 flags=ParseGeometry(argv[i+1],&geometry_info);
2661 if ((flags & SigmaValue) == 0)
2662 geometry_info.sigma=1.0;
2663 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2664 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2665 break;
2666 }
2667 if (LocaleCompare("shadow",option+1) == 0)
2668 {
2669 /*
2670 Shadow image.
2671 */
2672 (void) SyncImageSettings(mogrify_info,*image);
2673 flags=ParseGeometry(argv[i+1],&geometry_info);
2674 if ((flags & SigmaValue) == 0)
2675 geometry_info.sigma=1.0;
2676 if ((flags & XiValue) == 0)
2677 geometry_info.xi=4.0;
2678 if ((flags & PsiValue) == 0)
2679 geometry_info.psi=4.0;
2680 mogrify_image=ShadowImage(*image,geometry_info.rho,
2681 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2682 ceil(geometry_info.psi-0.5),exception);
2683 break;
2684 }
2685 if (LocaleCompare("sharpen",option+1) == 0)
2686 {
2687 /*
2688 Sharpen image.
2689 */
2690 (void) SyncImageSettings(mogrify_info,*image);
2691 flags=ParseGeometry(argv[i+1],&geometry_info);
2692 if ((flags & SigmaValue) == 0)
2693 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002694 if ((flags & XiValue) == 0)
2695 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002696 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002697 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002698 break;
2699 }
2700 if (LocaleCompare("shave",option+1) == 0)
2701 {
2702 /*
2703 Shave the image edges.
2704 */
2705 (void) SyncImageSettings(mogrify_info,*image);
2706 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2707 mogrify_image=ShaveImage(*image,&geometry,exception);
2708 break;
2709 }
2710 if (LocaleCompare("shear",option+1) == 0)
2711 {
2712 /*
2713 Shear image.
2714 */
2715 (void) SyncImageSettings(mogrify_info,*image);
2716 flags=ParseGeometry(argv[i+1],&geometry_info);
2717 if ((flags & SigmaValue) == 0)
2718 geometry_info.sigma=geometry_info.rho;
2719 mogrify_image=ShearImage(*image,geometry_info.rho,
2720 geometry_info.sigma,exception);
2721 break;
2722 }
2723 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2724 {
2725 /*
2726 Sigmoidal non-linearity contrast control.
2727 */
2728 (void) SyncImageSettings(mogrify_info,*image);
2729 flags=ParseGeometry(argv[i+1],&geometry_info);
2730 if ((flags & SigmaValue) == 0)
2731 geometry_info.sigma=(double) QuantumRange/2.0;
2732 if ((flags & PercentValue) != 0)
2733 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2734 100.0;
cristy9ee60942011-07-06 14:54:38 +00002735 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002736 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2737 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002738 break;
2739 }
2740 if (LocaleCompare("sketch",option+1) == 0)
2741 {
2742 /*
2743 Sketch image.
2744 */
2745 (void) SyncImageSettings(mogrify_info,*image);
2746 flags=ParseGeometry(argv[i+1],&geometry_info);
2747 if ((flags & SigmaValue) == 0)
2748 geometry_info.sigma=1.0;
2749 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002750 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002751 break;
2752 }
2753 if (LocaleCompare("solarize",option+1) == 0)
2754 {
2755 double
2756 threshold;
2757
2758 (void) SyncImageSettings(mogrify_info,*image);
2759 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002760 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002761 break;
2762 }
2763 if (LocaleCompare("sparse-color",option+1) == 0)
2764 {
2765 SparseColorMethod
2766 method;
2767
2768 char
2769 *arguments;
2770
2771 /*
2772 Sparse Color Interpolated Gradient
2773 */
2774 (void) SyncImageSettings(mogrify_info,*image);
2775 method=(SparseColorMethod) ParseCommandOption(
2776 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002777 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2778 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002779 if (arguments == (char *) NULL)
2780 break;
cristy3884f692011-07-08 18:00:18 +00002781 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002782 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2783 arguments=DestroyString(arguments);
2784 break;
2785 }
2786 if (LocaleCompare("splice",option+1) == 0)
2787 {
2788 /*
2789 Splice a solid color into the image.
2790 */
2791 (void) SyncImageSettings(mogrify_info,*image);
2792 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2793 mogrify_image=SpliceImage(*image,&geometry,exception);
2794 break;
2795 }
2796 if (LocaleCompare("spread",option+1) == 0)
2797 {
2798 /*
2799 Spread an image.
2800 */
2801 (void) SyncImageSettings(mogrify_info,*image);
2802 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002803 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002804 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002805 break;
2806 }
2807 if (LocaleCompare("statistic",option+1) == 0)
2808 {
2809 StatisticType
2810 type;
2811
2812 (void) SyncImageSettings(mogrify_info,*image);
2813 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2814 MagickFalse,argv[i+1]);
2815 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002816 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2817 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002818 break;
2819 }
2820 if (LocaleCompare("stretch",option+1) == 0)
2821 {
2822 if (*option == '+')
2823 {
2824 draw_info->stretch=UndefinedStretch;
2825 break;
2826 }
2827 draw_info->stretch=(StretchType) ParseCommandOption(
2828 MagickStretchOptions,MagickFalse,argv[i+1]);
2829 break;
2830 }
2831 if (LocaleCompare("strip",option+1) == 0)
2832 {
2833 /*
2834 Strip image of profiles and comments.
2835 */
2836 (void) SyncImageSettings(mogrify_info,*image);
2837 (void) StripImage(*image);
2838 InheritException(exception,&(*image)->exception);
2839 break;
2840 }
2841 if (LocaleCompare("stroke",option+1) == 0)
2842 {
2843 ExceptionInfo
2844 *sans;
2845
2846 if (*option == '+')
2847 {
2848 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2849 if (draw_info->stroke_pattern != (Image *) NULL)
2850 draw_info->stroke_pattern=DestroyImage(
2851 draw_info->stroke_pattern);
2852 break;
2853 }
2854 sans=AcquireExceptionInfo();
2855 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2856 sans=DestroyExceptionInfo(sans);
2857 if (status == MagickFalse)
2858 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2859 exception);
2860 break;
2861 }
2862 if (LocaleCompare("strokewidth",option+1) == 0)
2863 {
cristyc1acd842011-05-19 23:05:47 +00002864 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2865 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002866 break;
2867 }
2868 if (LocaleCompare("style",option+1) == 0)
2869 {
2870 if (*option == '+')
2871 {
2872 draw_info->style=UndefinedStyle;
2873 break;
2874 }
2875 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2876 MagickFalse,argv[i+1]);
2877 break;
2878 }
2879 if (LocaleCompare("swirl",option+1) == 0)
2880 {
2881 /*
2882 Swirl image.
2883 */
2884 (void) SyncImageSettings(mogrify_info,*image);
2885 (void) ParseGeometry(argv[i+1],&geometry_info);
2886 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2887 break;
2888 }
2889 break;
2890 }
2891 case 't':
2892 {
2893 if (LocaleCompare("threshold",option+1) == 0)
2894 {
2895 double
2896 threshold;
2897
2898 /*
2899 Threshold image.
2900 */
2901 (void) SyncImageSettings(mogrify_info,*image);
2902 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002903 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002904 else
2905 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002906 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002907 InheritException(exception,&(*image)->exception);
2908 break;
2909 }
2910 if (LocaleCompare("thumbnail",option+1) == 0)
2911 {
2912 /*
2913 Thumbnail image.
2914 */
2915 (void) SyncImageSettings(mogrify_info,*image);
2916 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2917 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2918 exception);
2919 break;
2920 }
2921 if (LocaleCompare("tile",option+1) == 0)
2922 {
2923 if (*option == '+')
2924 {
2925 if (draw_info->fill_pattern != (Image *) NULL)
2926 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2927 break;
2928 }
2929 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2930 exception);
2931 break;
2932 }
2933 if (LocaleCompare("tint",option+1) == 0)
2934 {
2935 /*
2936 Tint the image.
2937 */
2938 (void) SyncImageSettings(mogrify_info,*image);
cristy28474bf2011-09-11 23:32:52 +00002939 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002940 break;
2941 }
2942 if (LocaleCompare("transform",option+1) == 0)
2943 {
2944 /*
2945 Affine transform image.
2946 */
2947 (void) SyncImageSettings(mogrify_info,*image);
2948 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2949 exception);
2950 break;
2951 }
2952 if (LocaleCompare("transparent",option+1) == 0)
2953 {
cristy4c08aed2011-07-01 19:47:50 +00002954 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002955 target;
2956
2957 (void) SyncImageSettings(mogrify_info,*image);
2958 (void) QueryMagickColor(argv[i+1],&target,exception);
2959 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002960 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2961 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002962 break;
2963 }
2964 if (LocaleCompare("transpose",option+1) == 0)
2965 {
2966 /*
2967 Transpose image scanlines.
2968 */
2969 (void) SyncImageSettings(mogrify_info,*image);
2970 mogrify_image=TransposeImage(*image,exception);
2971 break;
2972 }
2973 if (LocaleCompare("transverse",option+1) == 0)
2974 {
2975 /*
2976 Transverse image scanlines.
2977 */
2978 (void) SyncImageSettings(mogrify_info,*image);
2979 mogrify_image=TransverseImage(*image,exception);
2980 break;
2981 }
2982 if (LocaleCompare("treedepth",option+1) == 0)
2983 {
2984 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2985 break;
2986 }
2987 if (LocaleCompare("trim",option+1) == 0)
2988 {
2989 /*
2990 Trim image.
2991 */
2992 (void) SyncImageSettings(mogrify_info,*image);
2993 mogrify_image=TrimImage(*image,exception);
2994 break;
2995 }
2996 if (LocaleCompare("type",option+1) == 0)
2997 {
2998 ImageType
2999 type;
3000
3001 (void) SyncImageSettings(mogrify_info,*image);
3002 if (*option == '+')
3003 type=UndefinedType;
3004 else
3005 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3006 argv[i+1]);
3007 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003008 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003009 break;
3010 }
3011 break;
3012 }
3013 case 'u':
3014 {
3015 if (LocaleCompare("undercolor",option+1) == 0)
3016 {
3017 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3018 exception);
3019 break;
3020 }
3021 if (LocaleCompare("unique",option+1) == 0)
3022 {
3023 if (*option == '+')
3024 {
3025 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3026 break;
3027 }
3028 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3029 (void) SetImageArtifact(*image,"verbose","true");
3030 break;
3031 }
3032 if (LocaleCompare("unique-colors",option+1) == 0)
3033 {
3034 /*
3035 Unique image colors.
3036 */
3037 (void) SyncImageSettings(mogrify_info,*image);
3038 mogrify_image=UniqueImageColors(*image,exception);
3039 break;
3040 }
3041 if (LocaleCompare("unsharp",option+1) == 0)
3042 {
3043 /*
3044 Unsharp mask image.
3045 */
3046 (void) SyncImageSettings(mogrify_info,*image);
3047 flags=ParseGeometry(argv[i+1],&geometry_info);
3048 if ((flags & SigmaValue) == 0)
3049 geometry_info.sigma=1.0;
3050 if ((flags & XiValue) == 0)
3051 geometry_info.xi=1.0;
3052 if ((flags & PsiValue) == 0)
3053 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003054 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3055 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003056 break;
3057 }
3058 break;
3059 }
3060 case 'v':
3061 {
3062 if (LocaleCompare("verbose",option+1) == 0)
3063 {
3064 (void) SetImageArtifact(*image,option+1,
3065 *option == '+' ? "false" : "true");
3066 break;
3067 }
3068 if (LocaleCompare("vignette",option+1) == 0)
3069 {
3070 /*
3071 Vignette image.
3072 */
3073 (void) SyncImageSettings(mogrify_info,*image);
3074 flags=ParseGeometry(argv[i+1],&geometry_info);
3075 if ((flags & SigmaValue) == 0)
3076 geometry_info.sigma=1.0;
3077 if ((flags & XiValue) == 0)
3078 geometry_info.xi=0.1*(*image)->columns;
3079 if ((flags & PsiValue) == 0)
3080 geometry_info.psi=0.1*(*image)->rows;
3081 mogrify_image=VignetteImage(*image,geometry_info.rho,
3082 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3083 ceil(geometry_info.psi-0.5),exception);
3084 break;
3085 }
3086 if (LocaleCompare("virtual-pixel",option+1) == 0)
3087 {
3088 if (*option == '+')
3089 {
3090 (void) SetImageVirtualPixelMethod(*image,
3091 UndefinedVirtualPixelMethod);
3092 break;
3093 }
3094 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3095 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3096 argv[i+1]));
3097 break;
3098 }
3099 break;
3100 }
3101 case 'w':
3102 {
3103 if (LocaleCompare("wave",option+1) == 0)
3104 {
3105 /*
3106 Wave image.
3107 */
3108 (void) SyncImageSettings(mogrify_info,*image);
3109 flags=ParseGeometry(argv[i+1],&geometry_info);
3110 if ((flags & SigmaValue) == 0)
3111 geometry_info.sigma=1.0;
3112 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003113 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003114 break;
3115 }
3116 if (LocaleCompare("weight",option+1) == 0)
3117 {
3118 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3119 if (LocaleCompare(argv[i+1],"all") == 0)
3120 draw_info->weight=0;
3121 if (LocaleCompare(argv[i+1],"bold") == 0)
3122 draw_info->weight=700;
3123 if (LocaleCompare(argv[i+1],"bolder") == 0)
3124 if (draw_info->weight <= 800)
3125 draw_info->weight+=100;
3126 if (LocaleCompare(argv[i+1],"lighter") == 0)
3127 if (draw_info->weight >= 100)
3128 draw_info->weight-=100;
3129 if (LocaleCompare(argv[i+1],"normal") == 0)
3130 draw_info->weight=400;
3131 break;
3132 }
3133 if (LocaleCompare("white-threshold",option+1) == 0)
3134 {
3135 /*
3136 White threshold image.
3137 */
3138 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003139 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003140 InheritException(exception,&(*image)->exception);
3141 break;
3142 }
3143 break;
3144 }
3145 default:
3146 break;
3147 }
3148 /*
3149 Replace current image with any image that was generated
3150 */
3151 if (mogrify_image != (Image *) NULL)
3152 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003153 i+=count;
3154 }
3155 if (region_image != (Image *) NULL)
3156 {
anthonydf8ebac2011-04-27 09:03:19 +00003157 /*
3158 Composite transformed region onto image.
3159 */
cristy6b3da3a2010-06-20 02:21:46 +00003160 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003161 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003162 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3163 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003164 InheritException(exception,&region_image->exception);
3165 *image=DestroyImage(*image);
3166 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003167 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003168 }
3169 /*
3170 Free resources.
3171 */
anthonydf8ebac2011-04-27 09:03:19 +00003172 quantize_info=DestroyQuantizeInfo(quantize_info);
3173 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003174 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003175 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003176 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003177 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003178}
3179
3180/*
3181%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3182% %
3183% %
3184% %
cristy5063d812010-10-19 16:28:10 +00003185+ 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 +00003186% %
3187% %
3188% %
3189%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3190%
3191% MogrifyImageCommand() transforms an image or a sequence of images. These
3192% transforms include image scaling, image rotation, color reduction, and
3193% others. The transmogrified image overwrites the original image.
3194%
3195% The format of the MogrifyImageCommand method is:
3196%
3197% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3198% const char **argv,char **metadata,ExceptionInfo *exception)
3199%
3200% A description of each parameter follows:
3201%
3202% o image_info: the image info.
3203%
3204% o argc: the number of elements in the argument vector.
3205%
3206% o argv: A text array containing the command line arguments.
3207%
3208% o metadata: any metadata is returned here.
3209%
3210% o exception: return any errors or warnings in this structure.
3211%
3212*/
3213
3214static MagickBooleanType MogrifyUsage(void)
3215{
3216 static const char
3217 *miscellaneous[]=
3218 {
3219 "-debug events display copious debugging information",
3220 "-help print program options",
3221 "-list type print a list of supported option arguments",
3222 "-log format format of debugging information",
3223 "-version print version information",
3224 (char *) NULL
3225 },
3226 *operators[]=
3227 {
3228 "-adaptive-blur geometry",
3229 " adaptively blur pixels; decrease effect near edges",
3230 "-adaptive-resize geometry",
3231 " adaptively resize image using 'mesh' interpolation",
3232 "-adaptive-sharpen geometry",
3233 " adaptively sharpen pixels; increase effect near edges",
3234 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3235 " transparent, extract, background, or shape",
3236 "-annotate geometry text",
3237 " annotate the image with text",
3238 "-auto-gamma automagically adjust gamma level of image",
3239 "-auto-level automagically adjust color levels of image",
3240 "-auto-orient automagically orient (rotate) image",
3241 "-bench iterations measure performance",
3242 "-black-threshold value",
3243 " force all pixels below the threshold into black",
3244 "-blue-shift simulate a scene at nighttime in the moonlight",
3245 "-blur geometry reduce image noise and reduce detail levels",
3246 "-border geometry surround image with a border of color",
3247 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003248 "-brightness-contrast geometry",
3249 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003250 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003251 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003252 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003253 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003254 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003255 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003256 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003257 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003258 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003259 "-contrast enhance or reduce the image contrast",
3260 "-contrast-stretch geometry",
3261 " improve contrast by `stretching' the intensity range",
3262 "-convolve coefficients",
3263 " apply a convolution kernel to the image",
3264 "-cycle amount cycle the image colormap",
3265 "-decipher filename convert cipher pixels to plain pixels",
3266 "-deskew threshold straighten an image",
3267 "-despeckle reduce the speckles within an image",
3268 "-distort method args",
3269 " distort images according to given method ad args",
3270 "-draw string annotate the image with a graphic primitive",
3271 "-edge radius apply a filter to detect edges in the image",
3272 "-encipher filename convert plain pixels to cipher pixels",
3273 "-emboss radius emboss an image",
3274 "-enhance apply a digital filter to enhance a noisy image",
3275 "-equalize perform histogram equalization to an image",
3276 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003277 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003278 "-extent geometry set the image size",
3279 "-extract geometry extract area from image",
3280 "-fft implements the discrete Fourier transform (DFT)",
3281 "-flip flip image vertically",
3282 "-floodfill geometry color",
3283 " floodfill the image with color",
3284 "-flop flop image horizontally",
3285 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003286 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003287 " apply function over image values",
3288 "-gamma value level of gamma correction",
3289 "-gaussian-blur geometry",
3290 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003291 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003292 "-identify identify the format and characteristics of the image",
3293 "-ift implements the inverse discrete Fourier transform (DFT)",
3294 "-implode amount implode image pixels about the center",
3295 "-lat geometry local adaptive thresholding",
3296 "-layers method optimize, merge, or compare image layers",
3297 "-level value adjust the level of image contrast",
3298 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003299 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003300 "-linear-stretch geometry",
3301 " improve contrast by `stretching with saturation'",
3302 "-liquid-rescale geometry",
3303 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003304 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003305 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003306 "-modulate value vary the brightness, saturation, and hue",
3307 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003308 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003309 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003310 "-motion-blur geometry",
3311 " simulate motion blur",
3312 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003313 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003314 "-normalize transform image to span the full range of colors",
3315 "-opaque color change this color to the fill color",
3316 "-ordered-dither NxN",
3317 " add a noise pattern to the image with specific",
3318 " amplitudes",
3319 "-paint radius simulate an oil painting",
3320 "-polaroid angle simulate a Polaroid picture",
3321 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003322 "-profile filename add, delete, or apply an image profile",
3323 "-quantize colorspace reduce colors in this colorspace",
3324 "-radial-blur angle radial blur the image",
3325 "-raise value lighten/darken image edges to create a 3-D effect",
3326 "-random-threshold low,high",
3327 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003328 "-region geometry apply options to a portion of the image",
3329 "-render render vector graphics",
3330 "-repage geometry size and location of an image canvas",
3331 "-resample geometry change the resolution of an image",
3332 "-resize geometry resize the image",
3333 "-roll geometry roll an image vertically or horizontally",
3334 "-rotate degrees apply Paeth rotation to the image",
3335 "-sample geometry scale image with pixel sampling",
3336 "-scale geometry scale the image",
3337 "-segment values segment an image",
3338 "-selective-blur geometry",
3339 " selectively blur pixels within a contrast threshold",
3340 "-sepia-tone threshold",
3341 " simulate a sepia-toned photo",
3342 "-set property value set an image property",
3343 "-shade degrees shade the image using a distant light source",
3344 "-shadow geometry simulate an image shadow",
3345 "-sharpen geometry sharpen the image",
3346 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003347 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003348 "-sigmoidal-contrast geometry",
3349 " increase the contrast without saturating highlights or shadows",
3350 "-sketch geometry simulate a pencil sketch",
3351 "-solarize threshold negate all pixels above the threshold level",
3352 "-sparse-color method args",
3353 " fill in a image based on a few color points",
3354 "-splice geometry splice the background color into the image",
3355 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003356 "-statistic type radius",
3357 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003358 "-strip strip image of all profiles and comments",
3359 "-swirl degrees swirl image pixels about the center",
3360 "-threshold value threshold the image",
3361 "-thumbnail geometry create a thumbnail of the image",
3362 "-tile filename tile image when filling a graphic primitive",
3363 "-tint value tint the image with the fill color",
3364 "-transform affine transform image",
3365 "-transparent color make this color transparent within the image",
3366 "-transpose flip image vertically and rotate 90 degrees",
3367 "-transverse flop image horizontally and rotate 270 degrees",
3368 "-trim trim image edges",
3369 "-type type image type",
3370 "-unique-colors discard all but one of any pixel color",
3371 "-unsharp geometry sharpen the image",
3372 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003373 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003374 "-white-threshold value",
3375 " force all pixels above the threshold into white",
3376 (char *) NULL
3377 },
3378 *sequence_operators[]=
3379 {
cristy4285d782011-02-09 20:12:28 +00003380 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003381 "-clut apply a color lookup table to the image",
3382 "-coalesce merge a sequence of images",
3383 "-combine combine a sequence of images",
3384 "-composite composite image",
3385 "-crop geometry cut out a rectangular region of the image",
3386 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003387 "-evaluate-sequence operator",
3388 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003389 "-flatten flatten a sequence of images",
3390 "-fx expression apply mathematical expression to an image channel(s)",
3391 "-hald-clut apply a Hald color lookup table to the image",
3392 "-morph value morph an image sequence",
3393 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003394 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003395 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003396 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003397 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003398 "-write filename write images to this file",
3399 (char *) NULL
3400 },
3401 *settings[]=
3402 {
3403 "-adjoin join images into a single multi-image file",
3404 "-affine matrix affine transform matrix",
3405 "-alpha option activate, deactivate, reset, or set the alpha channel",
3406 "-antialias remove pixel-aliasing",
3407 "-authenticate password",
3408 " decipher image with this password",
3409 "-attenuate value lessen (or intensify) when adding noise to an image",
3410 "-background color background color",
3411 "-bias value add bias when convolving an image",
3412 "-black-point-compensation",
3413 " use black point compensation",
3414 "-blue-primary point chromaticity blue primary point",
3415 "-bordercolor color border color",
3416 "-caption string assign a caption to an image",
3417 "-channel type apply option to select image channels",
3418 "-colors value preferred number of colors in the image",
3419 "-colorspace type alternate image colorspace",
3420 "-comment string annotate image with comment",
3421 "-compose operator set image composite operator",
3422 "-compress type type of pixel compression when writing the image",
3423 "-define format:option",
3424 " define one or more image format options",
3425 "-delay value display the next image after pausing",
3426 "-density geometry horizontal and vertical density of the image",
3427 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003428 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003429 "-display server get image or font from this X server",
3430 "-dispose method layer disposal method",
3431 "-dither method apply error diffusion to image",
3432 "-encoding type text encoding type",
3433 "-endian type endianness (MSB or LSB) of the image",
3434 "-family name render text with this font family",
3435 "-fill color color to use when filling a graphic primitive",
3436 "-filter type use this filter when resizing an image",
3437 "-font name render text with this font",
3438 "-format \"string\" output formatted image characteristics",
3439 "-fuzz distance colors within this distance are considered equal",
3440 "-gravity type horizontal and vertical text placement",
3441 "-green-primary point chromaticity green primary point",
3442 "-intent type type of rendering intent when managing the image color",
3443 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003444 "-interline-spacing value",
3445 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003446 "-interpolate method pixel color interpolation method",
3447 "-interword-spacing value",
3448 " set the space between two words",
3449 "-kerning value set the space between two letters",
3450 "-label string assign a label to an image",
3451 "-limit type value pixel cache resource limit",
3452 "-loop iterations add Netscape loop extension to your GIF animation",
3453 "-mask filename associate a mask with the image",
3454 "-mattecolor color frame color",
3455 "-monitor monitor progress",
3456 "-orient type image orientation",
3457 "-page geometry size and location of an image canvas (setting)",
3458 "-ping efficiently determine image attributes",
3459 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003460 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003461 "-preview type image preview type",
3462 "-quality value JPEG/MIFF/PNG compression level",
3463 "-quiet suppress all warning messages",
3464 "-red-primary point chromaticity red primary point",
3465 "-regard-warnings pay attention to warning messages",
3466 "-remap filename transform image colors to match this set of colors",
3467 "-respect-parentheses settings remain in effect until parenthesis boundary",
3468 "-sampling-factor geometry",
3469 " horizontal and vertical sampling factor",
3470 "-scene value image scene number",
3471 "-seed value seed a new sequence of pseudo-random numbers",
3472 "-size geometry width and height of image",
3473 "-stretch type render text with this font stretch",
3474 "-stroke color graphic primitive stroke color",
3475 "-strokewidth value graphic primitive stroke width",
3476 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003477 "-synchronize synchronize image to storage device",
3478 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003479 "-texture filename name of texture to tile onto the image background",
3480 "-tile-offset geometry",
3481 " tile offset",
3482 "-treedepth value color tree depth",
3483 "-transparent-color color",
3484 " transparent color",
3485 "-undercolor color annotation bounding box color",
3486 "-units type the units of image resolution",
3487 "-verbose print detailed information about the image",
3488 "-view FlashPix viewing transforms",
3489 "-virtual-pixel method",
3490 " virtual pixel access method",
3491 "-weight type render text with this font weight",
3492 "-white-point point chromaticity white point",
3493 (char *) NULL
3494 },
3495 *stack_operators[]=
3496 {
anthonyb69c4b32011-03-23 04:37:44 +00003497 "-delete indexes delete the image from the image sequence",
3498 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003499 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003500 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003501 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003502 "-swap indexes swap two images in the image sequence",
3503 (char *) NULL
3504 };
3505
3506 const char
3507 **p;
3508
cristybb503372010-05-27 20:51:26 +00003509 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003510 (void) printf("Copyright: %s\n",GetMagickCopyright());
3511 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003512 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3513 GetClientName());
3514 (void) printf("\nImage Settings:\n");
3515 for (p=settings; *p != (char *) NULL; p++)
3516 (void) printf(" %s\n",*p);
3517 (void) printf("\nImage Operators:\n");
3518 for (p=operators; *p != (char *) NULL; p++)
3519 (void) printf(" %s\n",*p);
3520 (void) printf("\nImage Sequence Operators:\n");
3521 for (p=sequence_operators; *p != (char *) NULL; p++)
3522 (void) printf(" %s\n",*p);
3523 (void) printf("\nImage Stack Operators:\n");
3524 for (p=stack_operators; *p != (char *) NULL; p++)
3525 (void) printf(" %s\n",*p);
3526 (void) printf("\nMiscellaneous Options:\n");
3527 for (p=miscellaneous; *p != (char *) NULL; p++)
3528 (void) printf(" %s\n",*p);
3529 (void) printf(
3530 "\nBy default, the image format of `file' is determined by its magic\n");
3531 (void) printf(
3532 "number. To specify a particular image format, precede the filename\n");
3533 (void) printf(
3534 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3535 (void) printf(
3536 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3537 (void) printf("'-' for standard input or output.\n");
3538 return(MagickFalse);
3539}
3540
3541WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3542 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3543{
3544#define DestroyMogrify() \
3545{ \
3546 if (format != (char *) NULL) \
3547 format=DestroyString(format); \
3548 if (path != (char *) NULL) \
3549 path=DestroyString(path); \
3550 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003551 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003552 argv[i]=DestroyString(argv[i]); \
3553 argv=(char **) RelinquishMagickMemory(argv); \
3554}
3555#define ThrowMogrifyException(asperity,tag,option) \
3556{ \
3557 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3558 option); \
3559 DestroyMogrify(); \
3560 return(MagickFalse); \
3561}
3562#define ThrowMogrifyInvalidArgumentException(option,argument) \
3563{ \
3564 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3565 "InvalidArgument","`%s': %s",argument,option); \
3566 DestroyMogrify(); \
3567 return(MagickFalse); \
3568}
3569
3570 char
3571 *format,
3572 *option,
3573 *path;
3574
3575 Image
3576 *image;
3577
3578 ImageStack
3579 image_stack[MaxImageStackDepth+1];
3580
cristy3ed852e2009-09-05 21:47:34 +00003581 MagickBooleanType
3582 global_colormap;
3583
3584 MagickBooleanType
3585 fire,
cristyebbcfea2011-02-25 02:43:54 +00003586 pend,
3587 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003588
3589 MagickStatusType
3590 status;
3591
cristyebbcfea2011-02-25 02:43:54 +00003592 register ssize_t
3593 i;
3594
3595 ssize_t
3596 j,
3597 k;
3598
cristy3ed852e2009-09-05 21:47:34 +00003599 /*
3600 Set defaults.
3601 */
3602 assert(image_info != (ImageInfo *) NULL);
3603 assert(image_info->signature == MagickSignature);
3604 if (image_info->debug != MagickFalse)
3605 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3606 assert(exception != (ExceptionInfo *) NULL);
3607 if (argc == 2)
3608 {
3609 option=argv[1];
3610 if ((LocaleCompare("version",option+1) == 0) ||
3611 (LocaleCompare("-version",option+1) == 0))
3612 {
cristyb51dff52011-05-19 16:55:47 +00003613 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003614 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003615 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3616 GetMagickCopyright());
3617 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3618 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003619 return(MagickFalse);
3620 }
3621 }
3622 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003623 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003624 format=(char *) NULL;
3625 path=(char *) NULL;
3626 global_colormap=MagickFalse;
3627 k=0;
3628 j=1;
3629 NewImageStack();
3630 option=(char *) NULL;
3631 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003632 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003633 status=MagickTrue;
3634 /*
3635 Parse command line.
3636 */
3637 ReadCommandlLine(argc,&argv);
3638 status=ExpandFilenames(&argc,&argv);
3639 if (status == MagickFalse)
3640 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3641 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003642 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003643 {
3644 option=argv[i];
3645 if (LocaleCompare(option,"(") == 0)
3646 {
3647 FireImageStack(MagickFalse,MagickTrue,pend);
3648 if (k == MaxImageStackDepth)
3649 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3650 option);
3651 PushImageStack();
3652 continue;
3653 }
3654 if (LocaleCompare(option,")") == 0)
3655 {
3656 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3657 if (k == 0)
3658 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3659 PopImageStack();
3660 continue;
3661 }
cristy042ee782011-04-22 18:48:30 +00003662 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003663 {
3664 char
3665 backup_filename[MaxTextExtent],
3666 *filename;
3667
3668 Image
3669 *images;
3670
3671 /*
3672 Option is a file name: begin by reading image from specified file.
3673 */
3674 FireImageStack(MagickFalse,MagickFalse,pend);
3675 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003676 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003677 filename=argv[++i];
3678 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3679 images=ReadImages(image_info,exception);
3680 status&=(images != (Image *) NULL) &&
3681 (exception->severity < ErrorException);
3682 if (images == (Image *) NULL)
3683 continue;
cristydaa76602010-06-30 13:05:11 +00003684 if (format != (char *) NULL)
3685 (void) CopyMagickString(images->filename,images->magick_filename,
3686 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003687 if (path != (char *) NULL)
3688 {
3689 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003690 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003691 path,*DirectorySeparator,filename);
3692 }
3693 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003694 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003695 AppendImageStack(images);
3696 FinalizeImageSettings(image_info,image,MagickFalse);
3697 if (global_colormap != MagickFalse)
3698 {
3699 QuantizeInfo
3700 *quantize_info;
3701
3702 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003703 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003704 quantize_info=DestroyQuantizeInfo(quantize_info);
3705 }
3706 *backup_filename='\0';
3707 if ((LocaleCompare(image->filename,"-") != 0) &&
3708 (IsPathWritable(image->filename) != MagickFalse))
3709 {
cristybb503372010-05-27 20:51:26 +00003710 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003711 i;
3712
3713 /*
3714 Rename image file as backup.
3715 */
3716 (void) CopyMagickString(backup_filename,image->filename,
3717 MaxTextExtent);
3718 for (i=0; i < 6; i++)
3719 {
3720 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3721 if (IsPathAccessible(backup_filename) == MagickFalse)
3722 break;
3723 }
3724 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3725 (rename(image->filename,backup_filename) != 0))
3726 *backup_filename='\0';
3727 }
3728 /*
3729 Write transmogrified image to disk.
3730 */
3731 image_info->synchronize=MagickTrue;
3732 status&=WriteImages(image_info,image,image->filename,exception);
3733 if ((status == MagickFalse) && (*backup_filename != '\0'))
3734 (void) remove(backup_filename);
3735 RemoveAllImageStack();
3736 continue;
3737 }
3738 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3739 switch (*(option+1))
3740 {
3741 case 'a':
3742 {
3743 if (LocaleCompare("adaptive-blur",option+1) == 0)
3744 {
3745 i++;
cristybb503372010-05-27 20:51:26 +00003746 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003747 ThrowMogrifyException(OptionError,"MissingArgument",option);
3748 if (IsGeometry(argv[i]) == MagickFalse)
3749 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3750 break;
3751 }
3752 if (LocaleCompare("adaptive-resize",option+1) == 0)
3753 {
3754 i++;
cristybb503372010-05-27 20:51:26 +00003755 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003756 ThrowMogrifyException(OptionError,"MissingArgument",option);
3757 if (IsGeometry(argv[i]) == MagickFalse)
3758 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3759 break;
3760 }
3761 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3762 {
3763 i++;
cristybb503372010-05-27 20:51:26 +00003764 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003765 ThrowMogrifyException(OptionError,"MissingArgument",option);
3766 if (IsGeometry(argv[i]) == MagickFalse)
3767 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3768 break;
3769 }
3770 if (LocaleCompare("affine",option+1) == 0)
3771 {
3772 if (*option == '+')
3773 break;
3774 i++;
cristybb503372010-05-27 20:51:26 +00003775 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003776 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003777 break;
3778 }
3779 if (LocaleCompare("alpha",option+1) == 0)
3780 {
cristybb503372010-05-27 20:51:26 +00003781 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003782 type;
3783
3784 if (*option == '+')
3785 break;
3786 i++;
cristybb503372010-05-27 20:51:26 +00003787 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003788 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003789 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003790 if (type < 0)
3791 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3792 argv[i]);
3793 break;
3794 }
3795 if (LocaleCompare("annotate",option+1) == 0)
3796 {
3797 if (*option == '+')
3798 break;
3799 i++;
cristybb503372010-05-27 20:51:26 +00003800 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003801 ThrowMogrifyException(OptionError,"MissingArgument",option);
3802 if (IsGeometry(argv[i]) == MagickFalse)
3803 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003804 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003805 ThrowMogrifyException(OptionError,"MissingArgument",option);
3806 i++;
3807 break;
3808 }
3809 if (LocaleCompare("antialias",option+1) == 0)
3810 break;
3811 if (LocaleCompare("append",option+1) == 0)
3812 break;
3813 if (LocaleCompare("attenuate",option+1) == 0)
3814 {
3815 if (*option == '+')
3816 break;
3817 i++;
cristybb503372010-05-27 20:51:26 +00003818 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003819 ThrowMogrifyException(OptionError,"MissingArgument",option);
3820 if (IsGeometry(argv[i]) == MagickFalse)
3821 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3822 break;
3823 }
3824 if (LocaleCompare("authenticate",option+1) == 0)
3825 {
3826 if (*option == '+')
3827 break;
3828 i++;
cristybb503372010-05-27 20:51:26 +00003829 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003830 ThrowMogrifyException(OptionError,"MissingArgument",option);
3831 break;
3832 }
3833 if (LocaleCompare("auto-gamma",option+1) == 0)
3834 break;
3835 if (LocaleCompare("auto-level",option+1) == 0)
3836 break;
3837 if (LocaleCompare("auto-orient",option+1) == 0)
3838 break;
3839 if (LocaleCompare("average",option+1) == 0)
3840 break;
3841 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3842 }
3843 case 'b':
3844 {
3845 if (LocaleCompare("background",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("bias",option+1) == 0)
3855 {
3856 if (*option == '+')
3857 break;
3858 i++;
cristybb503372010-05-27 20:51:26 +00003859 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003860 ThrowMogrifyException(OptionError,"MissingArgument",option);
3861 if (IsGeometry(argv[i]) == MagickFalse)
3862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3863 break;
3864 }
3865 if (LocaleCompare("black-point-compensation",option+1) == 0)
3866 break;
3867 if (LocaleCompare("black-threshold",option+1) == 0)
3868 {
3869 if (*option == '+')
3870 break;
3871 i++;
cristybb503372010-05-27 20:51:26 +00003872 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003873 ThrowMogrifyException(OptionError,"MissingArgument",option);
3874 if (IsGeometry(argv[i]) == MagickFalse)
3875 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3876 break;
3877 }
3878 if (LocaleCompare("blue-primary",option+1) == 0)
3879 {
3880 if (*option == '+')
3881 break;
3882 i++;
cristybb503372010-05-27 20:51:26 +00003883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003884 ThrowMogrifyException(OptionError,"MissingArgument",option);
3885 if (IsGeometry(argv[i]) == MagickFalse)
3886 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3887 break;
3888 }
3889 if (LocaleCompare("blue-shift",option+1) == 0)
3890 {
3891 i++;
cristybb503372010-05-27 20:51:26 +00003892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003893 ThrowMogrifyException(OptionError,"MissingArgument",option);
3894 if (IsGeometry(argv[i]) == MagickFalse)
3895 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3896 break;
3897 }
3898 if (LocaleCompare("blur",option+1) == 0)
3899 {
3900 i++;
cristybb503372010-05-27 20:51:26 +00003901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003902 ThrowMogrifyException(OptionError,"MissingArgument",option);
3903 if (IsGeometry(argv[i]) == MagickFalse)
3904 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3905 break;
3906 }
3907 if (LocaleCompare("border",option+1) == 0)
3908 {
3909 if (*option == '+')
3910 break;
3911 i++;
cristybb503372010-05-27 20:51:26 +00003912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003913 ThrowMogrifyException(OptionError,"MissingArgument",option);
3914 if (IsGeometry(argv[i]) == MagickFalse)
3915 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3916 break;
3917 }
3918 if (LocaleCompare("bordercolor",option+1) == 0)
3919 {
3920 if (*option == '+')
3921 break;
3922 i++;
cristybb503372010-05-27 20:51:26 +00003923 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003924 ThrowMogrifyException(OptionError,"MissingArgument",option);
3925 break;
3926 }
3927 if (LocaleCompare("box",option+1) == 0)
3928 {
3929 if (*option == '+')
3930 break;
3931 i++;
cristybb503372010-05-27 20:51:26 +00003932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003933 ThrowMogrifyException(OptionError,"MissingArgument",option);
3934 break;
3935 }
cristya28d6b82010-01-11 20:03:47 +00003936 if (LocaleCompare("brightness-contrast",option+1) == 0)
3937 {
3938 i++;
cristybb503372010-05-27 20:51:26 +00003939 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003940 ThrowMogrifyException(OptionError,"MissingArgument",option);
3941 if (IsGeometry(argv[i]) == MagickFalse)
3942 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3943 break;
3944 }
cristy3ed852e2009-09-05 21:47:34 +00003945 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3946 }
3947 case 'c':
3948 {
3949 if (LocaleCompare("cache",option+1) == 0)
3950 {
3951 if (*option == '+')
3952 break;
3953 i++;
cristybb503372010-05-27 20:51:26 +00003954 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003955 ThrowMogrifyException(OptionError,"MissingArgument",option);
3956 if (IsGeometry(argv[i]) == MagickFalse)
3957 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3958 break;
3959 }
3960 if (LocaleCompare("caption",option+1) == 0)
3961 {
3962 if (*option == '+')
3963 break;
3964 i++;
cristybb503372010-05-27 20:51:26 +00003965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003966 ThrowMogrifyException(OptionError,"MissingArgument",option);
3967 break;
3968 }
3969 if (LocaleCompare("channel",option+1) == 0)
3970 {
cristybb503372010-05-27 20:51:26 +00003971 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003972 channel;
3973
3974 if (*option == '+')
3975 break;
3976 i++;
cristybb503372010-05-27 20:51:26 +00003977 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003978 ThrowMogrifyException(OptionError,"MissingArgument",option);
3979 channel=ParseChannelOption(argv[i]);
3980 if (channel < 0)
3981 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3982 argv[i]);
3983 break;
3984 }
3985 if (LocaleCompare("cdl",option+1) == 0)
3986 {
3987 if (*option == '+')
3988 break;
3989 i++;
cristybb503372010-05-27 20:51:26 +00003990 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003991 ThrowMogrifyException(OptionError,"MissingArgument",option);
3992 break;
3993 }
3994 if (LocaleCompare("charcoal",option+1) == 0)
3995 {
3996 if (*option == '+')
3997 break;
3998 i++;
cristybb503372010-05-27 20:51:26 +00003999 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004000 ThrowMogrifyException(OptionError,"MissingArgument",option);
4001 if (IsGeometry(argv[i]) == MagickFalse)
4002 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4003 break;
4004 }
4005 if (LocaleCompare("chop",option+1) == 0)
4006 {
4007 if (*option == '+')
4008 break;
4009 i++;
cristybb503372010-05-27 20:51:26 +00004010 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004011 ThrowMogrifyException(OptionError,"MissingArgument",option);
4012 if (IsGeometry(argv[i]) == MagickFalse)
4013 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4014 break;
4015 }
cristy1eb45dd2009-09-25 16:38:06 +00004016 if (LocaleCompare("clamp",option+1) == 0)
4017 break;
4018 if (LocaleCompare("clip",option+1) == 0)
4019 break;
cristy3ed852e2009-09-05 21:47:34 +00004020 if (LocaleCompare("clip-mask",option+1) == 0)
4021 {
4022 if (*option == '+')
4023 break;
4024 i++;
cristybb503372010-05-27 20:51:26 +00004025 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004026 ThrowMogrifyException(OptionError,"MissingArgument",option);
4027 break;
4028 }
4029 if (LocaleCompare("clut",option+1) == 0)
4030 break;
4031 if (LocaleCompare("coalesce",option+1) == 0)
4032 break;
4033 if (LocaleCompare("colorize",option+1) == 0)
4034 {
4035 if (*option == '+')
4036 break;
4037 i++;
cristybb503372010-05-27 20:51:26 +00004038 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004039 ThrowMogrifyException(OptionError,"MissingArgument",option);
4040 if (IsGeometry(argv[i]) == MagickFalse)
4041 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4042 break;
4043 }
cristye6365592010-04-02 17:31:23 +00004044 if (LocaleCompare("color-matrix",option+1) == 0)
4045 {
cristyb6bd4ad2010-08-08 01:12:27 +00004046 KernelInfo
4047 *kernel_info;
4048
cristye6365592010-04-02 17:31:23 +00004049 if (*option == '+')
4050 break;
4051 i++;
cristybb503372010-05-27 20:51:26 +00004052 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004053 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004054 kernel_info=AcquireKernelInfo(argv[i]);
4055 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004056 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004057 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004058 break;
4059 }
cristy3ed852e2009-09-05 21:47:34 +00004060 if (LocaleCompare("colors",option+1) == 0)
4061 {
4062 if (*option == '+')
4063 break;
4064 i++;
cristybb503372010-05-27 20:51:26 +00004065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004066 ThrowMogrifyException(OptionError,"MissingArgument",option);
4067 if (IsGeometry(argv[i]) == MagickFalse)
4068 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4069 break;
4070 }
4071 if (LocaleCompare("colorspace",option+1) == 0)
4072 {
cristybb503372010-05-27 20:51:26 +00004073 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004074 colorspace;
4075
4076 if (*option == '+')
4077 break;
4078 i++;
cristybb503372010-05-27 20:51:26 +00004079 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004080 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004081 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004082 argv[i]);
4083 if (colorspace < 0)
4084 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4085 argv[i]);
4086 break;
4087 }
4088 if (LocaleCompare("combine",option+1) == 0)
4089 break;
4090 if (LocaleCompare("comment",option+1) == 0)
4091 {
4092 if (*option == '+')
4093 break;
4094 i++;
cristybb503372010-05-27 20:51:26 +00004095 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004096 ThrowMogrifyException(OptionError,"MissingArgument",option);
4097 break;
4098 }
4099 if (LocaleCompare("composite",option+1) == 0)
4100 break;
4101 if (LocaleCompare("compress",option+1) == 0)
4102 {
cristybb503372010-05-27 20:51:26 +00004103 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004104 compress;
4105
4106 if (*option == '+')
4107 break;
4108 i++;
cristybb503372010-05-27 20:51:26 +00004109 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004110 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004111 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004112 argv[i]);
4113 if (compress < 0)
4114 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4115 argv[i]);
4116 break;
4117 }
cristy22879752009-10-25 23:55:40 +00004118 if (LocaleCompare("concurrent",option+1) == 0)
4119 break;
cristy3ed852e2009-09-05 21:47:34 +00004120 if (LocaleCompare("contrast",option+1) == 0)
4121 break;
4122 if (LocaleCompare("contrast-stretch",option+1) == 0)
4123 {
4124 i++;
cristybb503372010-05-27 20:51:26 +00004125 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004126 ThrowMogrifyException(OptionError,"MissingArgument",option);
4127 if (IsGeometry(argv[i]) == MagickFalse)
4128 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4129 break;
4130 }
4131 if (LocaleCompare("convolve",option+1) == 0)
4132 {
cristyb6bd4ad2010-08-08 01:12:27 +00004133 KernelInfo
4134 *kernel_info;
4135
cristy3ed852e2009-09-05 21:47:34 +00004136 if (*option == '+')
4137 break;
4138 i++;
cristybb503372010-05-27 20:51:26 +00004139 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004140 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004141 kernel_info=AcquireKernelInfo(argv[i]);
4142 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004143 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004144 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004145 break;
4146 }
4147 if (LocaleCompare("crop",option+1) == 0)
4148 {
4149 if (*option == '+')
4150 break;
4151 i++;
cristybb503372010-05-27 20:51:26 +00004152 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004153 ThrowMogrifyException(OptionError,"MissingArgument",option);
4154 if (IsGeometry(argv[i]) == MagickFalse)
4155 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4156 break;
4157 }
4158 if (LocaleCompare("cycle",option+1) == 0)
4159 {
4160 if (*option == '+')
4161 break;
4162 i++;
cristybb503372010-05-27 20:51:26 +00004163 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004164 ThrowMogrifyException(OptionError,"MissingArgument",option);
4165 if (IsGeometry(argv[i]) == MagickFalse)
4166 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4167 break;
4168 }
4169 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4170 }
4171 case 'd':
4172 {
4173 if (LocaleCompare("decipher",option+1) == 0)
4174 {
4175 if (*option == '+')
4176 break;
4177 i++;
cristybb503372010-05-27 20:51:26 +00004178 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004179 ThrowMogrifyException(OptionError,"MissingArgument",option);
4180 break;
4181 }
4182 if (LocaleCompare("deconstruct",option+1) == 0)
4183 break;
4184 if (LocaleCompare("debug",option+1) == 0)
4185 {
cristybb503372010-05-27 20:51:26 +00004186 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004187 event;
4188
4189 if (*option == '+')
4190 break;
4191 i++;
cristybb503372010-05-27 20:51:26 +00004192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004193 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004194 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004195 if (event < 0)
4196 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4197 argv[i]);
4198 (void) SetLogEventMask(argv[i]);
4199 break;
4200 }
4201 if (LocaleCompare("define",option+1) == 0)
4202 {
4203 i++;
cristybb503372010-05-27 20:51:26 +00004204 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004205 ThrowMogrifyException(OptionError,"MissingArgument",option);
4206 if (*option == '+')
4207 {
4208 const char
4209 *define;
4210
4211 define=GetImageOption(image_info,argv[i]);
4212 if (define == (const char *) NULL)
4213 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4214 break;
4215 }
4216 break;
4217 }
4218 if (LocaleCompare("delay",option+1) == 0)
4219 {
4220 if (*option == '+')
4221 break;
4222 i++;
cristybb503372010-05-27 20:51:26 +00004223 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004224 ThrowMogrifyException(OptionError,"MissingArgument",option);
4225 if (IsGeometry(argv[i]) == MagickFalse)
4226 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4227 break;
4228 }
cristyecb10ff2011-03-22 13:14:03 +00004229 if (LocaleCompare("delete",option+1) == 0)
4230 {
4231 if (*option == '+')
4232 break;
4233 i++;
4234 if (i == (ssize_t) (argc-1))
4235 ThrowMogrifyException(OptionError,"MissingArgument",option);
4236 if (IsGeometry(argv[i]) == MagickFalse)
4237 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4238 break;
4239 }
cristy3ed852e2009-09-05 21:47:34 +00004240 if (LocaleCompare("density",option+1) == 0)
4241 {
4242 if (*option == '+')
4243 break;
4244 i++;
cristybb503372010-05-27 20:51:26 +00004245 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004246 ThrowMogrifyException(OptionError,"MissingArgument",option);
4247 if (IsGeometry(argv[i]) == MagickFalse)
4248 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4249 break;
4250 }
4251 if (LocaleCompare("depth",option+1) == 0)
4252 {
4253 if (*option == '+')
4254 break;
4255 i++;
cristybb503372010-05-27 20:51:26 +00004256 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004257 ThrowMogrifyException(OptionError,"MissingArgument",option);
4258 if (IsGeometry(argv[i]) == MagickFalse)
4259 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4260 break;
4261 }
4262 if (LocaleCompare("deskew",option+1) == 0)
4263 {
4264 if (*option == '+')
4265 break;
4266 i++;
cristybb503372010-05-27 20:51:26 +00004267 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004268 ThrowMogrifyException(OptionError,"MissingArgument",option);
4269 if (IsGeometry(argv[i]) == MagickFalse)
4270 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4271 break;
4272 }
4273 if (LocaleCompare("despeckle",option+1) == 0)
4274 break;
4275 if (LocaleCompare("dft",option+1) == 0)
4276 break;
cristyc9b12952010-03-28 01:12:28 +00004277 if (LocaleCompare("direction",option+1) == 0)
4278 {
cristybb503372010-05-27 20:51:26 +00004279 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004280 direction;
4281
4282 if (*option == '+')
4283 break;
4284 i++;
cristybb503372010-05-27 20:51:26 +00004285 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004286 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004287 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004288 argv[i]);
4289 if (direction < 0)
4290 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4291 argv[i]);
4292 break;
4293 }
cristy3ed852e2009-09-05 21:47:34 +00004294 if (LocaleCompare("display",option+1) == 0)
4295 {
4296 if (*option == '+')
4297 break;
4298 i++;
cristybb503372010-05-27 20:51:26 +00004299 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004300 ThrowMogrifyException(OptionError,"MissingArgument",option);
4301 break;
4302 }
4303 if (LocaleCompare("dispose",option+1) == 0)
4304 {
cristybb503372010-05-27 20:51:26 +00004305 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004306 dispose;
4307
4308 if (*option == '+')
4309 break;
4310 i++;
cristybb503372010-05-27 20:51:26 +00004311 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004312 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004313 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004314 if (dispose < 0)
4315 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4316 argv[i]);
4317 break;
4318 }
4319 if (LocaleCompare("distort",option+1) == 0)
4320 {
cristybb503372010-05-27 20:51:26 +00004321 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004322 op;
4323
4324 i++;
cristybb503372010-05-27 20:51:26 +00004325 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004326 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004327 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004328 if (op < 0)
4329 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4330 argv[i]);
4331 i++;
cristybb503372010-05-27 20:51:26 +00004332 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004333 ThrowMogrifyException(OptionError,"MissingArgument",option);
4334 break;
4335 }
4336 if (LocaleCompare("dither",option+1) == 0)
4337 {
cristybb503372010-05-27 20:51:26 +00004338 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004339 method;
4340
4341 if (*option == '+')
4342 break;
4343 i++;
cristybb503372010-05-27 20:51:26 +00004344 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004345 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004346 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004347 if (method < 0)
4348 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4349 argv[i]);
4350 break;
4351 }
4352 if (LocaleCompare("draw",option+1) == 0)
4353 {
4354 if (*option == '+')
4355 break;
4356 i++;
cristybb503372010-05-27 20:51:26 +00004357 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004358 ThrowMogrifyException(OptionError,"MissingArgument",option);
4359 break;
4360 }
cristyecb10ff2011-03-22 13:14:03 +00004361 if (LocaleCompare("duplicate",option+1) == 0)
4362 {
4363 if (*option == '+')
4364 break;
4365 i++;
4366 if (i == (ssize_t) (argc-1))
4367 ThrowMogrifyException(OptionError,"MissingArgument",option);
4368 if (IsGeometry(argv[i]) == MagickFalse)
4369 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4370 break;
4371 }
cristy22879752009-10-25 23:55:40 +00004372 if (LocaleCompare("duration",option+1) == 0)
4373 {
4374 if (*option == '+')
4375 break;
4376 i++;
cristybb503372010-05-27 20:51:26 +00004377 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004378 ThrowMogrifyException(OptionError,"MissingArgument",option);
4379 if (IsGeometry(argv[i]) == MagickFalse)
4380 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4381 break;
4382 }
cristy3ed852e2009-09-05 21:47:34 +00004383 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4384 }
4385 case 'e':
4386 {
4387 if (LocaleCompare("edge",option+1) == 0)
4388 {
4389 if (*option == '+')
4390 break;
4391 i++;
cristybb503372010-05-27 20:51:26 +00004392 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004393 ThrowMogrifyException(OptionError,"MissingArgument",option);
4394 if (IsGeometry(argv[i]) == MagickFalse)
4395 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4396 break;
4397 }
4398 if (LocaleCompare("emboss",option+1) == 0)
4399 {
4400 if (*option == '+')
4401 break;
4402 i++;
cristybb503372010-05-27 20:51:26 +00004403 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004404 ThrowMogrifyException(OptionError,"MissingArgument",option);
4405 if (IsGeometry(argv[i]) == MagickFalse)
4406 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4407 break;
4408 }
4409 if (LocaleCompare("encipher",option+1) == 0)
4410 {
4411 if (*option == '+')
4412 break;
4413 i++;
cristybb503372010-05-27 20:51:26 +00004414 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004415 ThrowMogrifyException(OptionError,"MissingArgument",option);
4416 break;
4417 }
4418 if (LocaleCompare("encoding",option+1) == 0)
4419 {
4420 if (*option == '+')
4421 break;
4422 i++;
cristybb503372010-05-27 20:51:26 +00004423 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004424 ThrowMogrifyException(OptionError,"MissingArgument",option);
4425 break;
4426 }
4427 if (LocaleCompare("endian",option+1) == 0)
4428 {
cristybb503372010-05-27 20:51:26 +00004429 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004430 endian;
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);
cristy042ee782011-04-22 18:48:30 +00004437 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004438 if (endian < 0)
4439 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4440 argv[i]);
4441 break;
4442 }
4443 if (LocaleCompare("enhance",option+1) == 0)
4444 break;
4445 if (LocaleCompare("equalize",option+1) == 0)
4446 break;
4447 if (LocaleCompare("evaluate",option+1) == 0)
4448 {
cristybb503372010-05-27 20:51:26 +00004449 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004450 op;
4451
4452 if (*option == '+')
4453 break;
4454 i++;
cristybb503372010-05-27 20:51:26 +00004455 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004456 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004457 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004458 if (op < 0)
4459 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4460 argv[i]);
4461 i++;
cristybb503372010-05-27 20:51:26 +00004462 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004463 ThrowMogrifyException(OptionError,"MissingArgument",option);
4464 if (IsGeometry(argv[i]) == MagickFalse)
4465 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4466 break;
4467 }
cristyd18ae7c2010-03-07 17:39:52 +00004468 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4469 {
cristybb503372010-05-27 20:51:26 +00004470 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004471 op;
4472
4473 if (*option == '+')
4474 break;
4475 i++;
cristybb503372010-05-27 20:51:26 +00004476 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004477 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004478 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004479 if (op < 0)
4480 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4481 argv[i]);
4482 break;
4483 }
cristy3ed852e2009-09-05 21:47:34 +00004484 if (LocaleCompare("extent",option+1) == 0)
4485 {
4486 if (*option == '+')
4487 break;
4488 i++;
cristybb503372010-05-27 20:51:26 +00004489 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004490 ThrowMogrifyException(OptionError,"MissingArgument",option);
4491 if (IsGeometry(argv[i]) == MagickFalse)
4492 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4493 break;
4494 }
4495 if (LocaleCompare("extract",option+1) == 0)
4496 {
4497 if (*option == '+')
4498 break;
4499 i++;
cristybb503372010-05-27 20:51:26 +00004500 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004501 ThrowMogrifyException(OptionError,"MissingArgument",option);
4502 if (IsGeometry(argv[i]) == MagickFalse)
4503 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4504 break;
4505 }
4506 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4507 }
4508 case 'f':
4509 {
4510 if (LocaleCompare("family",option+1) == 0)
4511 {
4512 if (*option == '+')
4513 break;
4514 i++;
cristybb503372010-05-27 20:51:26 +00004515 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004516 ThrowMogrifyException(OptionError,"MissingArgument",option);
4517 break;
4518 }
4519 if (LocaleCompare("fill",option+1) == 0)
4520 {
4521 if (*option == '+')
4522 break;
4523 i++;
cristybb503372010-05-27 20:51:26 +00004524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004525 ThrowMogrifyException(OptionError,"MissingArgument",option);
4526 break;
4527 }
4528 if (LocaleCompare("filter",option+1) == 0)
4529 {
cristybb503372010-05-27 20:51:26 +00004530 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004531 filter;
4532
4533 if (*option == '+')
4534 break;
4535 i++;
cristybb503372010-05-27 20:51:26 +00004536 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004537 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004538 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004539 if (filter < 0)
4540 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4541 argv[i]);
4542 break;
4543 }
4544 if (LocaleCompare("flatten",option+1) == 0)
4545 break;
4546 if (LocaleCompare("flip",option+1) == 0)
4547 break;
4548 if (LocaleCompare("flop",option+1) == 0)
4549 break;
4550 if (LocaleCompare("floodfill",option+1) == 0)
4551 {
4552 if (*option == '+')
4553 break;
4554 i++;
cristybb503372010-05-27 20:51:26 +00004555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004556 ThrowMogrifyException(OptionError,"MissingArgument",option);
4557 if (IsGeometry(argv[i]) == MagickFalse)
4558 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4559 i++;
cristybb503372010-05-27 20:51:26 +00004560 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004561 ThrowMogrifyException(OptionError,"MissingArgument",option);
4562 break;
4563 }
4564 if (LocaleCompare("font",option+1) == 0)
4565 {
4566 if (*option == '+')
4567 break;
4568 i++;
cristybb503372010-05-27 20:51:26 +00004569 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004570 ThrowMogrifyException(OptionError,"MissingArgument",option);
4571 break;
4572 }
4573 if (LocaleCompare("format",option+1) == 0)
4574 {
4575 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4576 (void) CloneString(&format,(char *) NULL);
4577 if (*option == '+')
4578 break;
4579 i++;
cristybb503372010-05-27 20:51:26 +00004580 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004581 ThrowMogrifyException(OptionError,"MissingArgument",option);
4582 (void) CloneString(&format,argv[i]);
4583 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4584 (void) ConcatenateMagickString(image_info->filename,":",
4585 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004586 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004587 if (*image_info->magick == '\0')
4588 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4589 format);
4590 break;
4591 }
4592 if (LocaleCompare("frame",option+1) == 0)
4593 {
4594 if (*option == '+')
4595 break;
4596 i++;
cristybb503372010-05-27 20:51:26 +00004597 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004598 ThrowMogrifyException(OptionError,"MissingArgument",option);
4599 if (IsGeometry(argv[i]) == MagickFalse)
4600 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4601 break;
4602 }
4603 if (LocaleCompare("function",option+1) == 0)
4604 {
cristybb503372010-05-27 20:51:26 +00004605 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004606 op;
4607
4608 if (*option == '+')
4609 break;
4610 i++;
cristybb503372010-05-27 20:51:26 +00004611 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004612 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004613 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004614 if (op < 0)
4615 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4616 i++;
cristybb503372010-05-27 20:51:26 +00004617 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004618 ThrowMogrifyException(OptionError,"MissingArgument",option);
4619 break;
4620 }
4621 if (LocaleCompare("fuzz",option+1) == 0)
4622 {
4623 if (*option == '+')
4624 break;
4625 i++;
cristybb503372010-05-27 20:51:26 +00004626 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004627 ThrowMogrifyException(OptionError,"MissingArgument",option);
4628 if (IsGeometry(argv[i]) == MagickFalse)
4629 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4630 break;
4631 }
4632 if (LocaleCompare("fx",option+1) == 0)
4633 {
4634 if (*option == '+')
4635 break;
4636 i++;
cristybb503372010-05-27 20:51:26 +00004637 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004638 ThrowMogrifyException(OptionError,"MissingArgument",option);
4639 break;
4640 }
4641 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4642 }
4643 case 'g':
4644 {
4645 if (LocaleCompare("gamma",option+1) == 0)
4646 {
4647 i++;
cristybb503372010-05-27 20:51:26 +00004648 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004649 ThrowMogrifyException(OptionError,"MissingArgument",option);
4650 if (IsGeometry(argv[i]) == MagickFalse)
4651 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4652 break;
4653 }
4654 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4655 (LocaleCompare("gaussian",option+1) == 0))
4656 {
4657 i++;
cristybb503372010-05-27 20:51:26 +00004658 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004659 ThrowMogrifyException(OptionError,"MissingArgument",option);
4660 if (IsGeometry(argv[i]) == MagickFalse)
4661 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4662 break;
4663 }
4664 if (LocaleCompare("geometry",option+1) == 0)
4665 {
4666 if (*option == '+')
4667 break;
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("gravity",option+1) == 0)
4676 {
cristybb503372010-05-27 20:51:26 +00004677 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004678 gravity;
4679
4680 if (*option == '+')
4681 break;
4682 i++;
cristybb503372010-05-27 20:51:26 +00004683 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004684 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004685 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004686 if (gravity < 0)
4687 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4688 argv[i]);
4689 break;
4690 }
4691 if (LocaleCompare("green-primary",option+1) == 0)
4692 {
4693 if (*option == '+')
4694 break;
4695 i++;
cristybb503372010-05-27 20:51:26 +00004696 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004697 ThrowMogrifyException(OptionError,"MissingArgument",option);
4698 if (IsGeometry(argv[i]) == MagickFalse)
4699 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4700 break;
4701 }
4702 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4703 }
4704 case 'h':
4705 {
4706 if (LocaleCompare("hald-clut",option+1) == 0)
4707 break;
4708 if ((LocaleCompare("help",option+1) == 0) ||
4709 (LocaleCompare("-help",option+1) == 0))
4710 return(MogrifyUsage());
4711 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4712 }
4713 case 'i':
4714 {
4715 if (LocaleCompare("identify",option+1) == 0)
4716 break;
4717 if (LocaleCompare("idft",option+1) == 0)
4718 break;
4719 if (LocaleCompare("implode",option+1) == 0)
4720 {
4721 if (*option == '+')
4722 break;
4723 i++;
cristybb503372010-05-27 20:51:26 +00004724 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004725 ThrowMogrifyException(OptionError,"MissingArgument",option);
4726 if (IsGeometry(argv[i]) == MagickFalse)
4727 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4728 break;
4729 }
4730 if (LocaleCompare("intent",option+1) == 0)
4731 {
cristybb503372010-05-27 20:51:26 +00004732 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004733 intent;
4734
4735 if (*option == '+')
4736 break;
4737 i++;
cristybb503372010-05-27 20:51:26 +00004738 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004739 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004740 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004741 if (intent < 0)
4742 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4743 argv[i]);
4744 break;
4745 }
4746 if (LocaleCompare("interlace",option+1) == 0)
4747 {
cristybb503372010-05-27 20:51:26 +00004748 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004749 interlace;
4750
4751 if (*option == '+')
4752 break;
4753 i++;
cristybb503372010-05-27 20:51:26 +00004754 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004755 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004756 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004757 argv[i]);
4758 if (interlace < 0)
4759 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4760 argv[i]);
4761 break;
4762 }
cristyb32b90a2009-09-07 21:45:48 +00004763 if (LocaleCompare("interline-spacing",option+1) == 0)
4764 {
4765 if (*option == '+')
4766 break;
4767 i++;
cristybb503372010-05-27 20:51:26 +00004768 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004769 ThrowMogrifyException(OptionError,"MissingArgument",option);
4770 if (IsGeometry(argv[i]) == MagickFalse)
4771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4772 break;
4773 }
cristy3ed852e2009-09-05 21:47:34 +00004774 if (LocaleCompare("interpolate",option+1) == 0)
4775 {
cristybb503372010-05-27 20:51:26 +00004776 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004777 interpolate;
4778
4779 if (*option == '+')
4780 break;
4781 i++;
cristybb503372010-05-27 20:51:26 +00004782 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004783 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004784 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004785 argv[i]);
4786 if (interpolate < 0)
4787 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4788 argv[i]);
4789 break;
4790 }
4791 if (LocaleCompare("interword-spacing",option+1) == 0)
4792 {
4793 if (*option == '+')
4794 break;
4795 i++;
cristybb503372010-05-27 20:51:26 +00004796 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004797 ThrowMogrifyException(OptionError,"MissingArgument",option);
4798 if (IsGeometry(argv[i]) == MagickFalse)
4799 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4800 break;
4801 }
4802 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4803 }
4804 case 'k':
4805 {
4806 if (LocaleCompare("kerning",option+1) == 0)
4807 {
4808 if (*option == '+')
4809 break;
4810 i++;
cristybb503372010-05-27 20:51:26 +00004811 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004812 ThrowMogrifyException(OptionError,"MissingArgument",option);
4813 if (IsGeometry(argv[i]) == MagickFalse)
4814 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4815 break;
4816 }
4817 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4818 }
4819 case 'l':
4820 {
4821 if (LocaleCompare("label",option+1) == 0)
4822 {
4823 if (*option == '+')
4824 break;
4825 i++;
cristybb503372010-05-27 20:51:26 +00004826 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004827 ThrowMogrifyException(OptionError,"MissingArgument",option);
4828 break;
4829 }
4830 if (LocaleCompare("lat",option+1) == 0)
4831 {
4832 if (*option == '+')
4833 break;
4834 i++;
cristybb503372010-05-27 20:51:26 +00004835 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004836 ThrowMogrifyException(OptionError,"MissingArgument",option);
4837 if (IsGeometry(argv[i]) == MagickFalse)
4838 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4839 }
4840 if (LocaleCompare("layers",option+1) == 0)
4841 {
cristybb503372010-05-27 20:51:26 +00004842 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004843 type;
4844
4845 if (*option == '+')
4846 break;
4847 i++;
cristybb503372010-05-27 20:51:26 +00004848 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004849 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004850 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004851 if (type < 0)
4852 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4853 argv[i]);
4854 break;
4855 }
4856 if (LocaleCompare("level",option+1) == 0)
4857 {
4858 i++;
cristybb503372010-05-27 20:51:26 +00004859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004860 ThrowMogrifyException(OptionError,"MissingArgument",option);
4861 if (IsGeometry(argv[i]) == MagickFalse)
4862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4863 break;
4864 }
4865 if (LocaleCompare("level-colors",option+1) == 0)
4866 {
4867 i++;
cristybb503372010-05-27 20:51:26 +00004868 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004869 ThrowMogrifyException(OptionError,"MissingArgument",option);
4870 break;
4871 }
4872 if (LocaleCompare("linewidth",option+1) == 0)
4873 {
4874 if (*option == '+')
4875 break;
4876 i++;
cristybb503372010-05-27 20:51:26 +00004877 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004878 ThrowMogrifyException(OptionError,"MissingArgument",option);
4879 if (IsGeometry(argv[i]) == MagickFalse)
4880 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4881 break;
4882 }
4883 if (LocaleCompare("limit",option+1) == 0)
4884 {
4885 char
4886 *p;
4887
4888 double
4889 value;
4890
cristybb503372010-05-27 20:51:26 +00004891 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004892 resource;
4893
4894 if (*option == '+')
4895 break;
4896 i++;
cristybb503372010-05-27 20:51:26 +00004897 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004898 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004899 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004900 argv[i]);
4901 if (resource < 0)
4902 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4903 argv[i]);
4904 i++;
cristybb503372010-05-27 20:51:26 +00004905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004906 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004907 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004908 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004909 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4910 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4911 break;
4912 }
4913 if (LocaleCompare("liquid-rescale",option+1) == 0)
4914 {
4915 i++;
cristybb503372010-05-27 20:51:26 +00004916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004917 ThrowMogrifyException(OptionError,"MissingArgument",option);
4918 if (IsGeometry(argv[i]) == MagickFalse)
4919 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4920 break;
4921 }
4922 if (LocaleCompare("list",option+1) == 0)
4923 {
cristybb503372010-05-27 20:51:26 +00004924 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004925 list;
4926
4927 if (*option == '+')
4928 break;
4929 i++;
cristybb503372010-05-27 20:51:26 +00004930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004931 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004932 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004933 if (list < 0)
4934 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004935 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004936 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004937 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004938 }
4939 if (LocaleCompare("log",option+1) == 0)
4940 {
4941 if (*option == '+')
4942 break;
4943 i++;
cristybb503372010-05-27 20:51:26 +00004944 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004945 (strchr(argv[i],'%') == (char *) NULL))
4946 ThrowMogrifyException(OptionError,"MissingArgument",option);
4947 break;
4948 }
4949 if (LocaleCompare("loop",option+1) == 0)
4950 {
4951 if (*option == '+')
4952 break;
4953 i++;
cristybb503372010-05-27 20:51:26 +00004954 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004955 ThrowMogrifyException(OptionError,"MissingArgument",option);
4956 if (IsGeometry(argv[i]) == MagickFalse)
4957 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4958 break;
4959 }
4960 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4961 }
4962 case 'm':
4963 {
4964 if (LocaleCompare("map",option+1) == 0)
4965 {
4966 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4967 if (*option == '+')
4968 break;
4969 i++;
cristybb503372010-05-27 20:51:26 +00004970 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004971 ThrowMogrifyException(OptionError,"MissingArgument",option);
4972 break;
4973 }
4974 if (LocaleCompare("mask",option+1) == 0)
4975 {
4976 if (*option == '+')
4977 break;
4978 i++;
cristybb503372010-05-27 20:51:26 +00004979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004980 ThrowMogrifyException(OptionError,"MissingArgument",option);
4981 break;
4982 }
4983 if (LocaleCompare("matte",option+1) == 0)
4984 break;
4985 if (LocaleCompare("mattecolor",option+1) == 0)
4986 {
4987 if (*option == '+')
4988 break;
4989 i++;
cristybb503372010-05-27 20:51:26 +00004990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004991 ThrowMogrifyException(OptionError,"MissingArgument",option);
4992 break;
4993 }
cristyf40785b2010-03-06 02:27:27 +00004994 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004995 break;
cristyf40785b2010-03-06 02:27:27 +00004996 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004997 break;
cristy3ed852e2009-09-05 21:47:34 +00004998 if (LocaleCompare("modulate",option+1) == 0)
4999 {
5000 if (*option == '+')
5001 break;
5002 i++;
cristybb503372010-05-27 20:51:26 +00005003 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005004 ThrowMogrifyException(OptionError,"MissingArgument",option);
5005 if (IsGeometry(argv[i]) == MagickFalse)
5006 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5007 break;
5008 }
5009 if (LocaleCompare("median",option+1) == 0)
5010 {
5011 if (*option == '+')
5012 break;
5013 i++;
cristybb503372010-05-27 20:51:26 +00005014 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005015 ThrowMogrifyException(OptionError,"MissingArgument",option);
5016 if (IsGeometry(argv[i]) == MagickFalse)
5017 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5018 break;
5019 }
cristy69ec32d2011-02-27 23:57:09 +00005020 if (LocaleCompare("mode",option+1) == 0)
5021 {
5022 if (*option == '+')
5023 break;
5024 i++;
5025 if (i == (ssize_t) argc)
5026 ThrowMogrifyException(OptionError,"MissingArgument",option);
5027 if (IsGeometry(argv[i]) == MagickFalse)
5028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5029 break;
5030 }
cristy3ed852e2009-09-05 21:47:34 +00005031 if (LocaleCompare("monitor",option+1) == 0)
5032 break;
5033 if (LocaleCompare("monochrome",option+1) == 0)
5034 break;
5035 if (LocaleCompare("morph",option+1) == 0)
5036 {
5037 if (*option == '+')
5038 break;
5039 i++;
cristybb503372010-05-27 20:51:26 +00005040 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005041 ThrowMogrifyException(OptionError,"MissingArgument",option);
5042 if (IsGeometry(argv[i]) == MagickFalse)
5043 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5044 break;
5045 }
anthony29188a82010-01-22 10:12:34 +00005046 if (LocaleCompare("morphology",option+1) == 0)
5047 {
anthony29188a82010-01-22 10:12:34 +00005048 char
5049 token[MaxTextExtent];
5050
cristyb6bd4ad2010-08-08 01:12:27 +00005051 KernelInfo
5052 *kernel_info;
5053
5054 ssize_t
5055 op;
5056
anthony29188a82010-01-22 10:12:34 +00005057 i++;
cristybb503372010-05-27 20:51:26 +00005058 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005059 ThrowMogrifyException(OptionError,"MissingArgument",option);
5060 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005061 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005062 if (op < 0)
5063 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005064 token);
anthony29188a82010-01-22 10:12:34 +00005065 i++;
cristybb503372010-05-27 20:51:26 +00005066 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005067 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005068 kernel_info=AcquireKernelInfo(argv[i]);
5069 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005070 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005071 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005072 break;
5073 }
cristy3ed852e2009-09-05 21:47:34 +00005074 if (LocaleCompare("mosaic",option+1) == 0)
5075 break;
5076 if (LocaleCompare("motion-blur",option+1) == 0)
5077 {
5078 if (*option == '+')
5079 break;
5080 i++;
cristybb503372010-05-27 20:51:26 +00005081 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005082 ThrowMogrifyException(OptionError,"MissingArgument",option);
5083 if (IsGeometry(argv[i]) == MagickFalse)
5084 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5085 break;
5086 }
5087 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5088 }
5089 case 'n':
5090 {
5091 if (LocaleCompare("negate",option+1) == 0)
5092 break;
5093 if (LocaleCompare("noise",option+1) == 0)
5094 {
5095 i++;
cristybb503372010-05-27 20:51:26 +00005096 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005097 ThrowMogrifyException(OptionError,"MissingArgument",option);
5098 if (*option == '+')
5099 {
cristybb503372010-05-27 20:51:26 +00005100 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005101 noise;
5102
cristy042ee782011-04-22 18:48:30 +00005103 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005104 if (noise < 0)
5105 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5106 argv[i]);
5107 break;
5108 }
5109 if (IsGeometry(argv[i]) == MagickFalse)
5110 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5111 break;
5112 }
5113 if (LocaleCompare("noop",option+1) == 0)
5114 break;
5115 if (LocaleCompare("normalize",option+1) == 0)
5116 break;
5117 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5118 }
5119 case 'o':
5120 {
5121 if (LocaleCompare("opaque",option+1) == 0)
5122 {
cristy3ed852e2009-09-05 21:47:34 +00005123 i++;
cristybb503372010-05-27 20:51:26 +00005124 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005125 ThrowMogrifyException(OptionError,"MissingArgument",option);
5126 break;
5127 }
5128 if (LocaleCompare("ordered-dither",option+1) == 0)
5129 {
5130 if (*option == '+')
5131 break;
5132 i++;
cristybb503372010-05-27 20:51:26 +00005133 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005134 ThrowMogrifyException(OptionError,"MissingArgument",option);
5135 break;
5136 }
5137 if (LocaleCompare("orient",option+1) == 0)
5138 {
cristybb503372010-05-27 20:51:26 +00005139 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005140 orientation;
5141
5142 orientation=UndefinedOrientation;
5143 if (*option == '+')
5144 break;
5145 i++;
cristybb503372010-05-27 20:51:26 +00005146 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005147 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005148 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005149 argv[i]);
5150 if (orientation < 0)
5151 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5152 argv[i]);
5153 break;
5154 }
5155 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5156 }
5157 case 'p':
5158 {
5159 if (LocaleCompare("page",option+1) == 0)
5160 {
5161 if (*option == '+')
5162 break;
5163 i++;
cristybb503372010-05-27 20:51:26 +00005164 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005165 ThrowMogrifyException(OptionError,"MissingArgument",option);
5166 break;
5167 }
5168 if (LocaleCompare("paint",option+1) == 0)
5169 {
5170 if (*option == '+')
5171 break;
5172 i++;
cristybb503372010-05-27 20:51:26 +00005173 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005174 ThrowMogrifyException(OptionError,"MissingArgument",option);
5175 if (IsGeometry(argv[i]) == MagickFalse)
5176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5177 break;
5178 }
5179 if (LocaleCompare("path",option+1) == 0)
5180 {
5181 (void) CloneString(&path,(char *) NULL);
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 (void) CloneString(&path,argv[i]);
5188 break;
5189 }
5190 if (LocaleCompare("pointsize",option+1) == 0)
5191 {
5192 if (*option == '+')
5193 break;
5194 i++;
cristybb503372010-05-27 20:51:26 +00005195 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005196 ThrowMogrifyException(OptionError,"MissingArgument",option);
5197 if (IsGeometry(argv[i]) == MagickFalse)
5198 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5199 break;
5200 }
5201 if (LocaleCompare("polaroid",option+1) == 0)
5202 {
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 if (IsGeometry(argv[i]) == MagickFalse)
5209 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5210 break;
5211 }
5212 if (LocaleCompare("posterize",option+1) == 0)
5213 {
5214 if (*option == '+')
5215 break;
5216 i++;
cristybb503372010-05-27 20:51:26 +00005217 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005218 ThrowMogrifyException(OptionError,"MissingArgument",option);
5219 if (IsGeometry(argv[i]) == MagickFalse)
5220 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5221 break;
5222 }
cristye7f51092010-01-17 00:39:37 +00005223 if (LocaleCompare("precision",option+1) == 0)
5224 {
5225 if (*option == '+')
5226 break;
5227 i++;
cristybb503372010-05-27 20:51:26 +00005228 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005229 ThrowMogrifyException(OptionError,"MissingArgument",option);
5230 if (IsGeometry(argv[i]) == MagickFalse)
5231 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5232 break;
5233 }
cristy3ed852e2009-09-05 21:47:34 +00005234 if (LocaleCompare("print",option+1) == 0)
5235 {
5236 if (*option == '+')
5237 break;
5238 i++;
cristybb503372010-05-27 20:51:26 +00005239 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005240 ThrowMogrifyException(OptionError,"MissingArgument",option);
5241 break;
5242 }
5243 if (LocaleCompare("process",option+1) == 0)
5244 {
5245 if (*option == '+')
5246 break;
5247 i++;
cristybb503372010-05-27 20:51:26 +00005248 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005249 ThrowMogrifyException(OptionError,"MissingArgument",option);
5250 break;
5251 }
5252 if (LocaleCompare("profile",option+1) == 0)
5253 {
5254 i++;
cristybb503372010-05-27 20:51:26 +00005255 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005256 ThrowMogrifyException(OptionError,"MissingArgument",option);
5257 break;
5258 }
5259 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5260 }
5261 case 'q':
5262 {
5263 if (LocaleCompare("quality",option+1) == 0)
5264 {
5265 if (*option == '+')
5266 break;
5267 i++;
cristybb503372010-05-27 20:51:26 +00005268 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005269 ThrowMogrifyException(OptionError,"MissingArgument",option);
5270 if (IsGeometry(argv[i]) == MagickFalse)
5271 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5272 break;
5273 }
5274 if (LocaleCompare("quantize",option+1) == 0)
5275 {
cristybb503372010-05-27 20:51:26 +00005276 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005277 colorspace;
5278
5279 if (*option == '+')
5280 break;
5281 i++;
cristybb503372010-05-27 20:51:26 +00005282 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005283 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005284 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005285 argv[i]);
5286 if (colorspace < 0)
5287 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5288 argv[i]);
5289 break;
5290 }
5291 if (LocaleCompare("quiet",option+1) == 0)
5292 break;
5293 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5294 }
5295 case 'r':
5296 {
5297 if (LocaleCompare("radial-blur",option+1) == 0)
5298 {
5299 i++;
cristybb503372010-05-27 20:51:26 +00005300 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005301 ThrowMogrifyException(OptionError,"MissingArgument",option);
5302 if (IsGeometry(argv[i]) == MagickFalse)
5303 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5304 break;
5305 }
5306 if (LocaleCompare("raise",option+1) == 0)
5307 {
5308 i++;
cristybb503372010-05-27 20:51:26 +00005309 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005310 ThrowMogrifyException(OptionError,"MissingArgument",option);
5311 if (IsGeometry(argv[i]) == MagickFalse)
5312 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5313 break;
5314 }
5315 if (LocaleCompare("random-threshold",option+1) == 0)
5316 {
5317 if (*option == '+')
5318 break;
5319 i++;
cristybb503372010-05-27 20:51:26 +00005320 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005321 ThrowMogrifyException(OptionError,"MissingArgument",option);
5322 if (IsGeometry(argv[i]) == MagickFalse)
5323 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5324 break;
5325 }
cristye6365592010-04-02 17:31:23 +00005326 if (LocaleCompare("recolor",option+1) == 0)
5327 {
5328 if (*option == '+')
5329 break;
5330 i++;
cristybb503372010-05-27 20:51:26 +00005331 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005332 ThrowMogrifyException(OptionError,"MissingArgument",option);
5333 if (IsGeometry(argv[i]) == MagickFalse)
5334 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5335 break;
5336 }
cristy3ed852e2009-09-05 21:47:34 +00005337 if (LocaleCompare("red-primary",option+1) == 0)
5338 {
5339 if (*option == '+')
5340 break;
5341 i++;
cristybb503372010-05-27 20:51:26 +00005342 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005343 ThrowMogrifyException(OptionError,"MissingArgument",option);
5344 if (IsGeometry(argv[i]) == MagickFalse)
5345 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5346 }
cristy9f2083a2010-04-22 19:48:05 +00005347 if (LocaleCompare("regard-warnings",option+1) == 0)
5348 break;
cristy3ed852e2009-09-05 21:47:34 +00005349 if (LocaleCompare("region",option+1) == 0)
5350 {
5351 if (*option == '+')
5352 break;
5353 i++;
cristybb503372010-05-27 20:51:26 +00005354 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005355 ThrowMogrifyException(OptionError,"MissingArgument",option);
5356 if (IsGeometry(argv[i]) == MagickFalse)
5357 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5358 break;
5359 }
cristyf0c78232010-03-15 12:53:40 +00005360 if (LocaleCompare("remap",option+1) == 0)
5361 {
5362 if (*option == '+')
5363 break;
5364 i++;
cristybb503372010-05-27 20:51:26 +00005365 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005366 ThrowMogrifyException(OptionError,"MissingArgument",option);
5367 break;
5368 }
cristy3ed852e2009-09-05 21:47:34 +00005369 if (LocaleCompare("render",option+1) == 0)
5370 break;
5371 if (LocaleCompare("repage",option+1) == 0)
5372 {
5373 if (*option == '+')
5374 break;
5375 i++;
cristybb503372010-05-27 20:51:26 +00005376 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005377 ThrowMogrifyException(OptionError,"MissingArgument",option);
5378 if (IsGeometry(argv[i]) == MagickFalse)
5379 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5380 break;
5381 }
5382 if (LocaleCompare("resample",option+1) == 0)
5383 {
5384 if (*option == '+')
5385 break;
5386 i++;
cristybb503372010-05-27 20:51:26 +00005387 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005388 ThrowMogrifyException(OptionError,"MissingArgument",option);
5389 if (IsGeometry(argv[i]) == MagickFalse)
5390 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5391 break;
5392 }
5393 if (LocaleCompare("resize",option+1) == 0)
5394 {
5395 if (*option == '+')
5396 break;
5397 i++;
cristybb503372010-05-27 20:51:26 +00005398 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005399 ThrowMogrifyException(OptionError,"MissingArgument",option);
5400 if (IsGeometry(argv[i]) == MagickFalse)
5401 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5402 break;
5403 }
cristyebbcfea2011-02-25 02:43:54 +00005404 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5405 {
5406 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5407 break;
5408 }
cristy3ed852e2009-09-05 21:47:34 +00005409 if (LocaleCompare("reverse",option+1) == 0)
5410 break;
5411 if (LocaleCompare("roll",option+1) == 0)
5412 {
5413 if (*option == '+')
5414 break;
5415 i++;
cristybb503372010-05-27 20:51:26 +00005416 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005417 ThrowMogrifyException(OptionError,"MissingArgument",option);
5418 if (IsGeometry(argv[i]) == MagickFalse)
5419 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5420 break;
5421 }
5422 if (LocaleCompare("rotate",option+1) == 0)
5423 {
5424 i++;
cristybb503372010-05-27 20:51:26 +00005425 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005426 ThrowMogrifyException(OptionError,"MissingArgument",option);
5427 if (IsGeometry(argv[i]) == MagickFalse)
5428 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5429 break;
5430 }
5431 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5432 }
5433 case 's':
5434 {
5435 if (LocaleCompare("sample",option+1) == 0)
5436 {
5437 if (*option == '+')
5438 break;
5439 i++;
cristybb503372010-05-27 20:51:26 +00005440 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005441 ThrowMogrifyException(OptionError,"MissingArgument",option);
5442 if (IsGeometry(argv[i]) == MagickFalse)
5443 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5444 break;
5445 }
5446 if (LocaleCompare("sampling-factor",option+1) == 0)
5447 {
5448 if (*option == '+')
5449 break;
5450 i++;
cristybb503372010-05-27 20:51:26 +00005451 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005452 ThrowMogrifyException(OptionError,"MissingArgument",option);
5453 if (IsGeometry(argv[i]) == MagickFalse)
5454 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5455 break;
5456 }
5457 if (LocaleCompare("scale",option+1) == 0)
5458 {
5459 if (*option == '+')
5460 break;
5461 i++;
cristybb503372010-05-27 20:51:26 +00005462 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005463 ThrowMogrifyException(OptionError,"MissingArgument",option);
5464 if (IsGeometry(argv[i]) == MagickFalse)
5465 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5466 break;
5467 }
5468 if (LocaleCompare("scene",option+1) == 0)
5469 {
5470 if (*option == '+')
5471 break;
5472 i++;
cristybb503372010-05-27 20:51:26 +00005473 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005474 ThrowMogrifyException(OptionError,"MissingArgument",option);
5475 if (IsGeometry(argv[i]) == MagickFalse)
5476 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5477 break;
5478 }
5479 if (LocaleCompare("seed",option+1) == 0)
5480 {
5481 if (*option == '+')
5482 break;
5483 i++;
cristybb503372010-05-27 20:51:26 +00005484 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005485 ThrowMogrifyException(OptionError,"MissingArgument",option);
5486 if (IsGeometry(argv[i]) == MagickFalse)
5487 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5488 break;
5489 }
5490 if (LocaleCompare("segment",option+1) == 0)
5491 {
5492 if (*option == '+')
5493 break;
5494 i++;
cristybb503372010-05-27 20:51:26 +00005495 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005496 ThrowMogrifyException(OptionError,"MissingArgument",option);
5497 if (IsGeometry(argv[i]) == MagickFalse)
5498 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5499 break;
5500 }
5501 if (LocaleCompare("selective-blur",option+1) == 0)
5502 {
5503 i++;
cristybb503372010-05-27 20:51:26 +00005504 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005505 ThrowMogrifyException(OptionError,"MissingArgument",option);
5506 if (IsGeometry(argv[i]) == MagickFalse)
5507 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5508 break;
5509 }
5510 if (LocaleCompare("separate",option+1) == 0)
5511 break;
5512 if (LocaleCompare("sepia-tone",option+1) == 0)
5513 {
5514 if (*option == '+')
5515 break;
5516 i++;
cristybb503372010-05-27 20:51:26 +00005517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005518 ThrowMogrifyException(OptionError,"MissingArgument",option);
5519 if (IsGeometry(argv[i]) == MagickFalse)
5520 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5521 break;
5522 }
5523 if (LocaleCompare("set",option+1) == 0)
5524 {
5525 i++;
cristybb503372010-05-27 20:51:26 +00005526 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005527 ThrowMogrifyException(OptionError,"MissingArgument",option);
5528 if (*option == '+')
5529 break;
5530 i++;
cristybb503372010-05-27 20:51:26 +00005531 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005532 ThrowMogrifyException(OptionError,"MissingArgument",option);
5533 break;
5534 }
5535 if (LocaleCompare("shade",option+1) == 0)
5536 {
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("shadow",option+1) == 0)
5545 {
5546 if (*option == '+')
5547 break;
5548 i++;
cristybb503372010-05-27 20:51:26 +00005549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005550 ThrowMogrifyException(OptionError,"MissingArgument",option);
5551 if (IsGeometry(argv[i]) == MagickFalse)
5552 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5553 break;
5554 }
5555 if (LocaleCompare("sharpen",option+1) == 0)
5556 {
5557 i++;
cristybb503372010-05-27 20:51:26 +00005558 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005559 ThrowMogrifyException(OptionError,"MissingArgument",option);
5560 if (IsGeometry(argv[i]) == MagickFalse)
5561 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5562 break;
5563 }
5564 if (LocaleCompare("shave",option+1) == 0)
5565 {
5566 if (*option == '+')
5567 break;
5568 i++;
cristybb503372010-05-27 20:51:26 +00005569 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005570 ThrowMogrifyException(OptionError,"MissingArgument",option);
5571 if (IsGeometry(argv[i]) == MagickFalse)
5572 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5573 break;
5574 }
5575 if (LocaleCompare("shear",option+1) == 0)
5576 {
5577 i++;
cristybb503372010-05-27 20:51:26 +00005578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005579 ThrowMogrifyException(OptionError,"MissingArgument",option);
5580 if (IsGeometry(argv[i]) == MagickFalse)
5581 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5582 break;
5583 }
5584 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5585 {
5586 i++;
cristybb503372010-05-27 20:51:26 +00005587 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005588 ThrowMogrifyException(OptionError,"MissingArgument",option);
5589 if (IsGeometry(argv[i]) == MagickFalse)
5590 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5591 break;
5592 }
5593 if (LocaleCompare("size",option+1) == 0)
5594 {
5595 if (*option == '+')
5596 break;
5597 i++;
cristybb503372010-05-27 20:51:26 +00005598 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005599 ThrowMogrifyException(OptionError,"MissingArgument",option);
5600 if (IsGeometry(argv[i]) == MagickFalse)
5601 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5602 break;
5603 }
5604 if (LocaleCompare("sketch",option+1) == 0)
5605 {
5606 if (*option == '+')
5607 break;
5608 i++;
cristybb503372010-05-27 20:51:26 +00005609 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005610 ThrowMogrifyException(OptionError,"MissingArgument",option);
5611 if (IsGeometry(argv[i]) == MagickFalse)
5612 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5613 break;
5614 }
cristy4285d782011-02-09 20:12:28 +00005615 if (LocaleCompare("smush",option+1) == 0)
5616 {
cristy4285d782011-02-09 20:12:28 +00005617 i++;
5618 if (i == (ssize_t) argc)
5619 ThrowMogrifyException(OptionError,"MissingArgument",option);
5620 if (IsGeometry(argv[i]) == MagickFalse)
5621 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005622 i++;
5623 break;
5624 }
cristy3ed852e2009-09-05 21:47:34 +00005625 if (LocaleCompare("solarize",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 }
5636 if (LocaleCompare("sparse-color",option+1) == 0)
5637 {
cristybb503372010-05-27 20:51:26 +00005638 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005639 op;
5640
5641 i++;
cristybb503372010-05-27 20:51:26 +00005642 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005643 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005644 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005645 if (op < 0)
5646 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5647 argv[i]);
5648 i++;
cristybb503372010-05-27 20:51:26 +00005649 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005650 ThrowMogrifyException(OptionError,"MissingArgument",option);
5651 break;
5652 }
5653 if (LocaleCompare("spread",option+1) == 0)
5654 {
5655 if (*option == '+')
5656 break;
5657 i++;
cristybb503372010-05-27 20:51:26 +00005658 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005659 ThrowMogrifyException(OptionError,"MissingArgument",option);
5660 if (IsGeometry(argv[i]) == MagickFalse)
5661 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5662 break;
5663 }
cristy0834d642011-03-18 18:26:08 +00005664 if (LocaleCompare("statistic",option+1) == 0)
5665 {
5666 ssize_t
5667 op;
5668
5669 if (*option == '+')
5670 break;
5671 i++;
5672 if (i == (ssize_t) argc)
5673 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005674 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005675 if (op < 0)
5676 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5677 argv[i]);
5678 i++;
5679 if (i == (ssize_t) (argc-1))
5680 ThrowMogrifyException(OptionError,"MissingArgument",option);
5681 if (IsGeometry(argv[i]) == MagickFalse)
5682 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5683 break;
5684 }
cristy3ed852e2009-09-05 21:47:34 +00005685 if (LocaleCompare("stretch",option+1) == 0)
5686 {
cristybb503372010-05-27 20:51:26 +00005687 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005688 stretch;
5689
5690 if (*option == '+')
5691 break;
5692 i++;
cristybb503372010-05-27 20:51:26 +00005693 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005694 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005695 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005696 if (stretch < 0)
5697 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5698 argv[i]);
5699 break;
5700 }
5701 if (LocaleCompare("strip",option+1) == 0)
5702 break;
5703 if (LocaleCompare("stroke",option+1) == 0)
5704 {
5705 if (*option == '+')
5706 break;
5707 i++;
cristybb503372010-05-27 20:51:26 +00005708 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005709 ThrowMogrifyException(OptionError,"MissingArgument",option);
5710 break;
5711 }
5712 if (LocaleCompare("strokewidth",option+1) == 0)
5713 {
5714 if (*option == '+')
5715 break;
5716 i++;
cristybb503372010-05-27 20:51:26 +00005717 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005718 ThrowMogrifyException(OptionError,"MissingArgument",option);
5719 if (IsGeometry(argv[i]) == MagickFalse)
5720 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5721 break;
5722 }
5723 if (LocaleCompare("style",option+1) == 0)
5724 {
cristybb503372010-05-27 20:51:26 +00005725 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005726 style;
5727
5728 if (*option == '+')
5729 break;
5730 i++;
cristybb503372010-05-27 20:51:26 +00005731 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005732 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005733 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005734 if (style < 0)
5735 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5736 argv[i]);
5737 break;
5738 }
cristyecb10ff2011-03-22 13:14:03 +00005739 if (LocaleCompare("swap",option+1) == 0)
5740 {
5741 if (*option == '+')
5742 break;
5743 i++;
5744 if (i == (ssize_t) (argc-1))
5745 ThrowMogrifyException(OptionError,"MissingArgument",option);
5746 if (IsGeometry(argv[i]) == MagickFalse)
5747 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5748 break;
5749 }
cristy3ed852e2009-09-05 21:47:34 +00005750 if (LocaleCompare("swirl",option+1) == 0)
5751 {
5752 if (*option == '+')
5753 break;
5754 i++;
cristybb503372010-05-27 20:51:26 +00005755 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005756 ThrowMogrifyException(OptionError,"MissingArgument",option);
5757 if (IsGeometry(argv[i]) == MagickFalse)
5758 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5759 break;
5760 }
cristyd9a29192010-10-16 16:49:53 +00005761 if (LocaleCompare("synchronize",option+1) == 0)
5762 break;
cristy3ed852e2009-09-05 21:47:34 +00005763 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5764 }
5765 case 't':
5766 {
5767 if (LocaleCompare("taint",option+1) == 0)
5768 break;
5769 if (LocaleCompare("texture",option+1) == 0)
5770 {
5771 if (*option == '+')
5772 break;
5773 i++;
cristybb503372010-05-27 20:51:26 +00005774 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005775 ThrowMogrifyException(OptionError,"MissingArgument",option);
5776 break;
5777 }
5778 if (LocaleCompare("tile",option+1) == 0)
5779 {
5780 if (*option == '+')
5781 break;
5782 i++;
cristybb503372010-05-27 20:51:26 +00005783 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005784 ThrowMogrifyException(OptionError,"MissingArgument",option);
5785 break;
5786 }
5787 if (LocaleCompare("tile-offset",option+1) == 0)
5788 {
5789 if (*option == '+')
5790 break;
5791 i++;
cristybb503372010-05-27 20:51:26 +00005792 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005793 ThrowMogrifyException(OptionError,"MissingArgument",option);
5794 if (IsGeometry(argv[i]) == MagickFalse)
5795 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5796 break;
5797 }
5798 if (LocaleCompare("tint",option+1) == 0)
5799 {
5800 if (*option == '+')
5801 break;
5802 i++;
cristybb503372010-05-27 20:51:26 +00005803 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005804 ThrowMogrifyException(OptionError,"MissingArgument",option);
5805 if (IsGeometry(argv[i]) == MagickFalse)
5806 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5807 break;
5808 }
5809 if (LocaleCompare("transform",option+1) == 0)
5810 break;
5811 if (LocaleCompare("transpose",option+1) == 0)
5812 break;
5813 if (LocaleCompare("transverse",option+1) == 0)
5814 break;
5815 if (LocaleCompare("threshold",option+1) == 0)
5816 {
5817 if (*option == '+')
5818 break;
5819 i++;
cristybb503372010-05-27 20:51:26 +00005820 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005821 ThrowMogrifyException(OptionError,"MissingArgument",option);
5822 if (IsGeometry(argv[i]) == MagickFalse)
5823 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5824 break;
5825 }
5826 if (LocaleCompare("thumbnail",option+1) == 0)
5827 {
5828 if (*option == '+')
5829 break;
5830 i++;
cristybb503372010-05-27 20:51:26 +00005831 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005832 ThrowMogrifyException(OptionError,"MissingArgument",option);
5833 if (IsGeometry(argv[i]) == MagickFalse)
5834 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5835 break;
5836 }
5837 if (LocaleCompare("transparent",option+1) == 0)
5838 {
5839 i++;
cristybb503372010-05-27 20:51:26 +00005840 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005841 ThrowMogrifyException(OptionError,"MissingArgument",option);
5842 break;
5843 }
5844 if (LocaleCompare("transparent-color",option+1) == 0)
5845 {
5846 if (*option == '+')
5847 break;
5848 i++;
cristybb503372010-05-27 20:51:26 +00005849 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005850 ThrowMogrifyException(OptionError,"MissingArgument",option);
5851 break;
5852 }
5853 if (LocaleCompare("treedepth",option+1) == 0)
5854 {
5855 if (*option == '+')
5856 break;
5857 i++;
cristybb503372010-05-27 20:51:26 +00005858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005859 ThrowMogrifyException(OptionError,"MissingArgument",option);
5860 if (IsGeometry(argv[i]) == MagickFalse)
5861 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5862 break;
5863 }
5864 if (LocaleCompare("trim",option+1) == 0)
5865 break;
5866 if (LocaleCompare("type",option+1) == 0)
5867 {
cristybb503372010-05-27 20:51:26 +00005868 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005869 type;
5870
5871 if (*option == '+')
5872 break;
5873 i++;
cristybb503372010-05-27 20:51:26 +00005874 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005875 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005876 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005877 if (type < 0)
5878 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5879 argv[i]);
5880 break;
5881 }
5882 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5883 }
5884 case 'u':
5885 {
5886 if (LocaleCompare("undercolor",option+1) == 0)
5887 {
5888 if (*option == '+')
5889 break;
5890 i++;
cristybb503372010-05-27 20:51:26 +00005891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005892 ThrowMogrifyException(OptionError,"MissingArgument",option);
5893 break;
5894 }
5895 if (LocaleCompare("unique-colors",option+1) == 0)
5896 break;
5897 if (LocaleCompare("units",option+1) == 0)
5898 {
cristybb503372010-05-27 20:51:26 +00005899 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005900 units;
5901
5902 if (*option == '+')
5903 break;
5904 i++;
cristybb503372010-05-27 20:51:26 +00005905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005906 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005907 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005908 argv[i]);
5909 if (units < 0)
5910 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5911 argv[i]);
5912 break;
5913 }
5914 if (LocaleCompare("unsharp",option+1) == 0)
5915 {
5916 i++;
cristybb503372010-05-27 20:51:26 +00005917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005918 ThrowMogrifyException(OptionError,"MissingArgument",option);
5919 if (IsGeometry(argv[i]) == MagickFalse)
5920 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5921 break;
5922 }
5923 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5924 }
5925 case 'v':
5926 {
5927 if (LocaleCompare("verbose",option+1) == 0)
5928 {
5929 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5930 break;
5931 }
5932 if ((LocaleCompare("version",option+1) == 0) ||
5933 (LocaleCompare("-version",option+1) == 0))
5934 {
cristyb51dff52011-05-19 16:55:47 +00005935 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005936 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005937 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5938 GetMagickCopyright());
5939 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5940 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005941 break;
5942 }
5943 if (LocaleCompare("view",option+1) == 0)
5944 {
5945 if (*option == '+')
5946 break;
5947 i++;
cristybb503372010-05-27 20:51:26 +00005948 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005949 ThrowMogrifyException(OptionError,"MissingArgument",option);
5950 break;
5951 }
5952 if (LocaleCompare("vignette",option+1) == 0)
5953 {
5954 if (*option == '+')
5955 break;
5956 i++;
cristybb503372010-05-27 20:51:26 +00005957 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005958 ThrowMogrifyException(OptionError,"MissingArgument",option);
5959 if (IsGeometry(argv[i]) == MagickFalse)
5960 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5961 break;
5962 }
5963 if (LocaleCompare("virtual-pixel",option+1) == 0)
5964 {
cristybb503372010-05-27 20:51:26 +00005965 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005966 method;
5967
5968 if (*option == '+')
5969 break;
5970 i++;
cristybb503372010-05-27 20:51:26 +00005971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005972 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005973 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005974 argv[i]);
5975 if (method < 0)
5976 ThrowMogrifyException(OptionError,
5977 "UnrecognizedVirtualPixelMethod",argv[i]);
5978 break;
5979 }
5980 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5981 }
5982 case 'w':
5983 {
5984 if (LocaleCompare("wave",option+1) == 0)
5985 {
5986 i++;
cristybb503372010-05-27 20:51:26 +00005987 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005988 ThrowMogrifyException(OptionError,"MissingArgument",option);
5989 if (IsGeometry(argv[i]) == MagickFalse)
5990 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5991 break;
5992 }
5993 if (LocaleCompare("weight",option+1) == 0)
5994 {
5995 if (*option == '+')
5996 break;
5997 i++;
cristybb503372010-05-27 20:51:26 +00005998 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005999 ThrowMogrifyException(OptionError,"MissingArgument",option);
6000 break;
6001 }
6002 if (LocaleCompare("white-point",option+1) == 0)
6003 {
6004 if (*option == '+')
6005 break;
6006 i++;
cristybb503372010-05-27 20:51:26 +00006007 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006008 ThrowMogrifyException(OptionError,"MissingArgument",option);
6009 if (IsGeometry(argv[i]) == MagickFalse)
6010 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6011 break;
6012 }
6013 if (LocaleCompare("white-threshold",option+1) == 0)
6014 {
6015 if (*option == '+')
6016 break;
6017 i++;
cristybb503372010-05-27 20:51:26 +00006018 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006019 ThrowMogrifyException(OptionError,"MissingArgument",option);
6020 if (IsGeometry(argv[i]) == MagickFalse)
6021 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6022 break;
6023 }
6024 if (LocaleCompare("write",option+1) == 0)
6025 {
6026 i++;
cristybb503372010-05-27 20:51:26 +00006027 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006028 ThrowMogrifyException(OptionError,"MissingArgument",option);
6029 break;
6030 }
6031 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6032 }
6033 case '?':
6034 break;
6035 default:
6036 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6037 }
cristy042ee782011-04-22 18:48:30 +00006038 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6039 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006040 if (fire != MagickFalse)
6041 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6042 }
6043 if (k != 0)
6044 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006045 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006046 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6047 DestroyMogrify();
6048 return(status != 0 ? MagickTrue : MagickFalse);
6049}
6050
6051/*
6052%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6053% %
6054% %
6055% %
6056+ M o g r i f y I m a g e I n f o %
6057% %
6058% %
6059% %
6060%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6061%
6062% MogrifyImageInfo() applies image processing settings to the image as
6063% prescribed by command line options.
6064%
6065% The format of the MogrifyImageInfo method is:
6066%
6067% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6068% const char **argv,ExceptionInfo *exception)
6069%
6070% A description of each parameter follows:
6071%
6072% o image_info: the image info..
6073%
6074% o argc: Specifies a pointer to an integer describing the number of
6075% elements in the argument vector.
6076%
6077% o argv: Specifies a pointer to a text array containing the command line
6078% arguments.
6079%
6080% o exception: return any errors or warnings in this structure.
6081%
6082*/
6083WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6084 const int argc,const char **argv,ExceptionInfo *exception)
6085{
6086 const char
6087 *option;
6088
6089 GeometryInfo
6090 geometry_info;
6091
cristybb503372010-05-27 20:51:26 +00006092 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006093 count;
6094
cristybb503372010-05-27 20:51:26 +00006095 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006096 i;
6097
6098 /*
6099 Initialize method variables.
6100 */
6101 assert(image_info != (ImageInfo *) NULL);
6102 assert(image_info->signature == MagickSignature);
6103 if (image_info->debug != MagickFalse)
6104 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6105 image_info->filename);
6106 if (argc < 0)
6107 return(MagickTrue);
6108 /*
6109 Set the image settings.
6110 */
cristybb503372010-05-27 20:51:26 +00006111 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006112 {
6113 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006114 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006115 continue;
cristy042ee782011-04-22 18:48:30 +00006116 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006117 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006118 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006119 break;
6120 switch (*(option+1))
6121 {
6122 case 'a':
6123 {
6124 if (LocaleCompare("adjoin",option+1) == 0)
6125 {
6126 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6127 break;
6128 }
6129 if (LocaleCompare("antialias",option+1) == 0)
6130 {
6131 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6132 break;
6133 }
6134 if (LocaleCompare("attenuate",option+1) == 0)
6135 {
6136 if (*option == '+')
6137 {
6138 (void) DeleteImageOption(image_info,option+1);
6139 break;
6140 }
6141 (void) SetImageOption(image_info,option+1,argv[i+1]);
6142 break;
6143 }
6144 if (LocaleCompare("authenticate",option+1) == 0)
6145 {
6146 if (*option == '+')
6147 (void) CloneString(&image_info->authenticate,(char *) NULL);
6148 else
6149 (void) CloneString(&image_info->authenticate,argv[i+1]);
6150 break;
6151 }
6152 break;
6153 }
6154 case 'b':
6155 {
6156 if (LocaleCompare("background",option+1) == 0)
6157 {
6158 if (*option == '+')
6159 {
6160 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006161 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006162 &image_info->background_color,exception);
6163 break;
6164 }
6165 (void) SetImageOption(image_info,option+1,argv[i+1]);
6166 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6167 exception);
6168 break;
6169 }
6170 if (LocaleCompare("bias",option+1) == 0)
6171 {
6172 if (*option == '+')
6173 {
6174 (void) SetImageOption(image_info,option+1,"0.0");
6175 break;
6176 }
6177 (void) SetImageOption(image_info,option+1,argv[i+1]);
6178 break;
6179 }
6180 if (LocaleCompare("black-point-compensation",option+1) == 0)
6181 {
6182 if (*option == '+')
6183 {
6184 (void) SetImageOption(image_info,option+1,"false");
6185 break;
6186 }
6187 (void) SetImageOption(image_info,option+1,"true");
6188 break;
6189 }
6190 if (LocaleCompare("blue-primary",option+1) == 0)
6191 {
6192 if (*option == '+')
6193 {
6194 (void) SetImageOption(image_info,option+1,"0.0");
6195 break;
6196 }
6197 (void) SetImageOption(image_info,option+1,argv[i+1]);
6198 break;
6199 }
6200 if (LocaleCompare("bordercolor",option+1) == 0)
6201 {
6202 if (*option == '+')
6203 {
6204 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006205 (void) QueryColorDatabase(MogrifyBorderColor,
6206 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006207 break;
6208 }
6209 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6210 exception);
6211 (void) SetImageOption(image_info,option+1,argv[i+1]);
6212 break;
6213 }
6214 if (LocaleCompare("box",option+1) == 0)
6215 {
6216 if (*option == '+')
6217 {
6218 (void) SetImageOption(image_info,"undercolor","none");
6219 break;
6220 }
6221 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6222 break;
6223 }
6224 break;
6225 }
6226 case 'c':
6227 {
6228 if (LocaleCompare("cache",option+1) == 0)
6229 {
6230 MagickSizeType
6231 limit;
6232
6233 limit=MagickResourceInfinity;
6234 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006235 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006236 (void) SetMagickResourceLimit(MemoryResource,limit);
6237 (void) SetMagickResourceLimit(MapResource,2*limit);
6238 break;
6239 }
6240 if (LocaleCompare("caption",option+1) == 0)
6241 {
6242 if (*option == '+')
6243 {
6244 (void) DeleteImageOption(image_info,option+1);
6245 break;
6246 }
6247 (void) SetImageOption(image_info,option+1,argv[i+1]);
6248 break;
6249 }
6250 if (LocaleCompare("channel",option+1) == 0)
6251 {
6252 if (*option == '+')
6253 {
6254 image_info->channel=DefaultChannels;
6255 break;
6256 }
6257 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6258 break;
6259 }
6260 if (LocaleCompare("colors",option+1) == 0)
6261 {
cristye27293e2009-12-18 02:53:20 +00006262 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006263 break;
6264 }
6265 if (LocaleCompare("colorspace",option+1) == 0)
6266 {
6267 if (*option == '+')
6268 {
6269 image_info->colorspace=UndefinedColorspace;
6270 (void) SetImageOption(image_info,option+1,"undefined");
6271 break;
6272 }
cristy042ee782011-04-22 18:48:30 +00006273 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006274 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6275 (void) SetImageOption(image_info,option+1,argv[i+1]);
6276 break;
6277 }
cristy3ed852e2009-09-05 21:47:34 +00006278 if (LocaleCompare("comment",option+1) == 0)
6279 {
6280 if (*option == '+')
6281 {
6282 (void) DeleteImageOption(image_info,option+1);
6283 break;
6284 }
6285 (void) SetImageOption(image_info,option+1,argv[i+1]);
6286 break;
6287 }
6288 if (LocaleCompare("compose",option+1) == 0)
6289 {
6290 if (*option == '+')
6291 {
6292 (void) SetImageOption(image_info,option+1,"undefined");
6293 break;
6294 }
6295 (void) SetImageOption(image_info,option+1,argv[i+1]);
6296 break;
6297 }
6298 if (LocaleCompare("compress",option+1) == 0)
6299 {
6300 if (*option == '+')
6301 {
6302 image_info->compression=UndefinedCompression;
6303 (void) SetImageOption(image_info,option+1,"undefined");
6304 break;
6305 }
cristy042ee782011-04-22 18:48:30 +00006306 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006307 MagickCompressOptions,MagickFalse,argv[i+1]);
6308 (void) SetImageOption(image_info,option+1,argv[i+1]);
6309 break;
6310 }
6311 break;
6312 }
6313 case 'd':
6314 {
6315 if (LocaleCompare("debug",option+1) == 0)
6316 {
6317 if (*option == '+')
6318 (void) SetLogEventMask("none");
6319 else
6320 (void) SetLogEventMask(argv[i+1]);
6321 image_info->debug=IsEventLogging();
6322 break;
6323 }
6324 if (LocaleCompare("define",option+1) == 0)
6325 {
6326 if (*option == '+')
6327 {
6328 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6329 (void) DeleteImageRegistry(argv[i+1]+9);
6330 else
6331 (void) DeleteImageOption(image_info,argv[i+1]);
6332 break;
6333 }
6334 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6335 {
6336 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6337 exception);
6338 break;
6339 }
6340 (void) DefineImageOption(image_info,argv[i+1]);
6341 break;
6342 }
6343 if (LocaleCompare("delay",option+1) == 0)
6344 {
6345 if (*option == '+')
6346 {
6347 (void) SetImageOption(image_info,option+1,"0");
6348 break;
6349 }
6350 (void) SetImageOption(image_info,option+1,argv[i+1]);
6351 break;
6352 }
6353 if (LocaleCompare("density",option+1) == 0)
6354 {
6355 /*
6356 Set image density.
6357 */
6358 if (*option == '+')
6359 {
6360 if (image_info->density != (char *) NULL)
6361 image_info->density=DestroyString(image_info->density);
6362 (void) SetImageOption(image_info,option+1,"72");
6363 break;
6364 }
6365 (void) CloneString(&image_info->density,argv[i+1]);
6366 (void) SetImageOption(image_info,option+1,argv[i+1]);
6367 break;
6368 }
6369 if (LocaleCompare("depth",option+1) == 0)
6370 {
6371 if (*option == '+')
6372 {
6373 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6374 break;
6375 }
cristye27293e2009-12-18 02:53:20 +00006376 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006377 break;
6378 }
cristyc9b12952010-03-28 01:12:28 +00006379 if (LocaleCompare("direction",option+1) == 0)
6380 {
6381 if (*option == '+')
6382 {
6383 (void) SetImageOption(image_info,option+1,"undefined");
6384 break;
6385 }
6386 (void) SetImageOption(image_info,option+1,argv[i+1]);
6387 break;
6388 }
cristy3ed852e2009-09-05 21:47:34 +00006389 if (LocaleCompare("display",option+1) == 0)
6390 {
6391 if (*option == '+')
6392 {
6393 if (image_info->server_name != (char *) NULL)
6394 image_info->server_name=DestroyString(
6395 image_info->server_name);
6396 break;
6397 }
6398 (void) CloneString(&image_info->server_name,argv[i+1]);
6399 break;
6400 }
6401 if (LocaleCompare("dispose",option+1) == 0)
6402 {
6403 if (*option == '+')
6404 {
6405 (void) SetImageOption(image_info,option+1,"undefined");
6406 break;
6407 }
6408 (void) SetImageOption(image_info,option+1,argv[i+1]);
6409 break;
6410 }
6411 if (LocaleCompare("dither",option+1) == 0)
6412 {
6413 if (*option == '+')
6414 {
6415 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006416 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006417 break;
6418 }
6419 (void) SetImageOption(image_info,option+1,argv[i+1]);
6420 image_info->dither=MagickTrue;
6421 break;
6422 }
6423 break;
6424 }
6425 case 'e':
6426 {
6427 if (LocaleCompare("encoding",option+1) == 0)
6428 {
6429 if (*option == '+')
6430 {
6431 (void) SetImageOption(image_info,option+1,"undefined");
6432 break;
6433 }
6434 (void) SetImageOption(image_info,option+1,argv[i+1]);
6435 break;
6436 }
6437 if (LocaleCompare("endian",option+1) == 0)
6438 {
6439 if (*option == '+')
6440 {
6441 image_info->endian=UndefinedEndian;
6442 (void) SetImageOption(image_info,option+1,"undefined");
6443 break;
6444 }
cristy042ee782011-04-22 18:48:30 +00006445 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006446 MagickEndianOptions,MagickFalse,argv[i+1]);
6447 (void) SetImageOption(image_info,option+1,argv[i+1]);
6448 break;
6449 }
6450 if (LocaleCompare("extract",option+1) == 0)
6451 {
6452 /*
6453 Set image extract geometry.
6454 */
6455 if (*option == '+')
6456 {
6457 if (image_info->extract != (char *) NULL)
6458 image_info->extract=DestroyString(image_info->extract);
6459 break;
6460 }
6461 (void) CloneString(&image_info->extract,argv[i+1]);
6462 break;
6463 }
6464 break;
6465 }
6466 case 'f':
6467 {
6468 if (LocaleCompare("fill",option+1) == 0)
6469 {
6470 if (*option == '+')
6471 {
6472 (void) SetImageOption(image_info,option+1,"none");
6473 break;
6474 }
6475 (void) SetImageOption(image_info,option+1,argv[i+1]);
6476 break;
6477 }
6478 if (LocaleCompare("filter",option+1) == 0)
6479 {
6480 if (*option == '+')
6481 {
6482 (void) SetImageOption(image_info,option+1,"undefined");
6483 break;
6484 }
6485 (void) SetImageOption(image_info,option+1,argv[i+1]);
6486 break;
6487 }
6488 if (LocaleCompare("font",option+1) == 0)
6489 {
6490 if (*option == '+')
6491 {
6492 if (image_info->font != (char *) NULL)
6493 image_info->font=DestroyString(image_info->font);
6494 break;
6495 }
6496 (void) CloneString(&image_info->font,argv[i+1]);
6497 break;
6498 }
6499 if (LocaleCompare("format",option+1) == 0)
6500 {
6501 register const char
6502 *q;
6503
6504 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006505 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006506 image_info->ping=MagickFalse;
6507 (void) SetImageOption(image_info,option+1,argv[i+1]);
6508 break;
6509 }
6510 if (LocaleCompare("fuzz",option+1) == 0)
6511 {
6512 if (*option == '+')
6513 {
6514 image_info->fuzz=0.0;
6515 (void) SetImageOption(image_info,option+1,"0");
6516 break;
6517 }
cristyf2f27272009-12-17 14:48:46 +00006518 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006519 1.0);
6520 (void) SetImageOption(image_info,option+1,argv[i+1]);
6521 break;
6522 }
6523 break;
6524 }
6525 case 'g':
6526 {
6527 if (LocaleCompare("gravity",option+1) == 0)
6528 {
6529 if (*option == '+')
6530 {
6531 (void) SetImageOption(image_info,option+1,"undefined");
6532 break;
6533 }
6534 (void) SetImageOption(image_info,option+1,argv[i+1]);
6535 break;
6536 }
6537 if (LocaleCompare("green-primary",option+1) == 0)
6538 {
6539 if (*option == '+')
6540 {
6541 (void) SetImageOption(image_info,option+1,"0.0");
6542 break;
6543 }
6544 (void) SetImageOption(image_info,option+1,argv[i+1]);
6545 break;
6546 }
6547 break;
6548 }
6549 case 'i':
6550 {
6551 if (LocaleCompare("intent",option+1) == 0)
6552 {
6553 if (*option == '+')
6554 {
6555 (void) SetImageOption(image_info,option+1,"undefined");
6556 break;
6557 }
6558 (void) SetImageOption(image_info,option+1,argv[i+1]);
6559 break;
6560 }
6561 if (LocaleCompare("interlace",option+1) == 0)
6562 {
6563 if (*option == '+')
6564 {
6565 image_info->interlace=UndefinedInterlace;
6566 (void) SetImageOption(image_info,option+1,"undefined");
6567 break;
6568 }
cristy042ee782011-04-22 18:48:30 +00006569 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006570 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6571 (void) SetImageOption(image_info,option+1,argv[i+1]);
6572 break;
6573 }
cristyb32b90a2009-09-07 21:45:48 +00006574 if (LocaleCompare("interline-spacing",option+1) == 0)
6575 {
6576 if (*option == '+')
6577 {
6578 (void) SetImageOption(image_info,option+1,"undefined");
6579 break;
6580 }
6581 (void) SetImageOption(image_info,option+1,argv[i+1]);
6582 break;
6583 }
cristy3ed852e2009-09-05 21:47:34 +00006584 if (LocaleCompare("interpolate",option+1) == 0)
6585 {
6586 if (*option == '+')
6587 {
6588 (void) SetImageOption(image_info,option+1,"undefined");
6589 break;
6590 }
6591 (void) SetImageOption(image_info,option+1,argv[i+1]);
6592 break;
6593 }
6594 if (LocaleCompare("interword-spacing",option+1) == 0)
6595 {
6596 if (*option == '+')
6597 {
6598 (void) SetImageOption(image_info,option+1,"undefined");
6599 break;
6600 }
6601 (void) SetImageOption(image_info,option+1,argv[i+1]);
6602 break;
6603 }
6604 break;
6605 }
6606 case 'k':
6607 {
6608 if (LocaleCompare("kerning",option+1) == 0)
6609 {
6610 if (*option == '+')
6611 {
6612 (void) SetImageOption(image_info,option+1,"undefined");
6613 break;
6614 }
6615 (void) SetImageOption(image_info,option+1,argv[i+1]);
6616 break;
6617 }
6618 break;
6619 }
6620 case 'l':
6621 {
6622 if (LocaleCompare("label",option+1) == 0)
6623 {
6624 if (*option == '+')
6625 {
6626 (void) DeleteImageOption(image_info,option+1);
6627 break;
6628 }
6629 (void) SetImageOption(image_info,option+1,argv[i+1]);
6630 break;
6631 }
6632 if (LocaleCompare("limit",option+1) == 0)
6633 {
6634 MagickSizeType
6635 limit;
6636
6637 ResourceType
6638 type;
6639
6640 if (*option == '+')
6641 break;
cristy042ee782011-04-22 18:48:30 +00006642 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006643 MagickFalse,argv[i+1]);
6644 limit=MagickResourceInfinity;
6645 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006646 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006647 (void) SetMagickResourceLimit(type,limit);
6648 break;
6649 }
6650 if (LocaleCompare("list",option+1) == 0)
6651 {
cristybb503372010-05-27 20:51:26 +00006652 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006653 list;
6654
6655 /*
6656 Display configuration list.
6657 */
cristy042ee782011-04-22 18:48:30 +00006658 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006659 switch (list)
6660 {
6661 case MagickCoderOptions:
6662 {
6663 (void) ListCoderInfo((FILE *) NULL,exception);
6664 break;
6665 }
6666 case MagickColorOptions:
6667 {
6668 (void) ListColorInfo((FILE *) NULL,exception);
6669 break;
6670 }
6671 case MagickConfigureOptions:
6672 {
6673 (void) ListConfigureInfo((FILE *) NULL,exception);
6674 break;
6675 }
6676 case MagickDelegateOptions:
6677 {
6678 (void) ListDelegateInfo((FILE *) NULL,exception);
6679 break;
6680 }
6681 case MagickFontOptions:
6682 {
6683 (void) ListTypeInfo((FILE *) NULL,exception);
6684 break;
6685 }
6686 case MagickFormatOptions:
6687 {
6688 (void) ListMagickInfo((FILE *) NULL,exception);
6689 break;
6690 }
6691 case MagickLocaleOptions:
6692 {
6693 (void) ListLocaleInfo((FILE *) NULL,exception);
6694 break;
6695 }
6696 case MagickLogOptions:
6697 {
6698 (void) ListLogInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickMagicOptions:
6702 {
6703 (void) ListMagicInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickMimeOptions:
6707 {
6708 (void) ListMimeInfo((FILE *) NULL,exception);
6709 break;
6710 }
6711 case MagickModuleOptions:
6712 {
6713 (void) ListModuleInfo((FILE *) NULL,exception);
6714 break;
6715 }
6716 case MagickPolicyOptions:
6717 {
6718 (void) ListPolicyInfo((FILE *) NULL,exception);
6719 break;
6720 }
6721 case MagickResourceOptions:
6722 {
6723 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6724 break;
6725 }
6726 case MagickThresholdOptions:
6727 {
6728 (void) ListThresholdMaps((FILE *) NULL,exception);
6729 break;
6730 }
6731 default:
6732 {
cristy042ee782011-04-22 18:48:30 +00006733 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006734 exception);
6735 break;
6736 }
6737 }
cristyaeb2cbc2010-05-07 13:28:58 +00006738 break;
cristy3ed852e2009-09-05 21:47:34 +00006739 }
6740 if (LocaleCompare("log",option+1) == 0)
6741 {
6742 if (*option == '+')
6743 break;
6744 (void) SetLogFormat(argv[i+1]);
6745 break;
6746 }
6747 if (LocaleCompare("loop",option+1) == 0)
6748 {
6749 if (*option == '+')
6750 {
6751 (void) SetImageOption(image_info,option+1,"0");
6752 break;
6753 }
6754 (void) SetImageOption(image_info,option+1,argv[i+1]);
6755 break;
6756 }
6757 break;
6758 }
6759 case 'm':
6760 {
6761 if (LocaleCompare("matte",option+1) == 0)
6762 {
6763 if (*option == '+')
6764 {
6765 (void) SetImageOption(image_info,option+1,"false");
6766 break;
6767 }
6768 (void) SetImageOption(image_info,option+1,"true");
6769 break;
6770 }
6771 if (LocaleCompare("mattecolor",option+1) == 0)
6772 {
6773 if (*option == '+')
6774 {
6775 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006776 (void) QueryColorDatabase(MogrifyMatteColor,
6777 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006778 break;
6779 }
6780 (void) SetImageOption(image_info,option+1,argv[i+1]);
6781 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6782 exception);
6783 break;
6784 }
6785 if (LocaleCompare("monitor",option+1) == 0)
6786 {
6787 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6788 (void *) NULL);
6789 break;
6790 }
6791 if (LocaleCompare("monochrome",option+1) == 0)
6792 {
6793 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6794 break;
6795 }
6796 break;
6797 }
6798 case 'o':
6799 {
6800 if (LocaleCompare("orient",option+1) == 0)
6801 {
6802 if (*option == '+')
6803 {
6804 image_info->orientation=UndefinedOrientation;
6805 (void) SetImageOption(image_info,option+1,"undefined");
6806 break;
6807 }
cristy042ee782011-04-22 18:48:30 +00006808 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006809 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006810 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006811 break;
6812 }
6813 }
6814 case 'p':
6815 {
6816 if (LocaleCompare("page",option+1) == 0)
6817 {
6818 char
6819 *canonical_page,
6820 page[MaxTextExtent];
6821
6822 const char
6823 *image_option;
6824
6825 MagickStatusType
6826 flags;
6827
6828 RectangleInfo
6829 geometry;
6830
6831 if (*option == '+')
6832 {
6833 (void) DeleteImageOption(image_info,option+1);
6834 (void) CloneString(&image_info->page,(char *) NULL);
6835 break;
6836 }
6837 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6838 image_option=GetImageOption(image_info,"page");
6839 if (image_option != (const char *) NULL)
6840 flags=ParseAbsoluteGeometry(image_option,&geometry);
6841 canonical_page=GetPageGeometry(argv[i+1]);
6842 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6843 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006844 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006845 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006846 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006847 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006848 (unsigned long) geometry.width,(unsigned long) geometry.height,
6849 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006850 (void) SetImageOption(image_info,option+1,page);
6851 (void) CloneString(&image_info->page,page);
6852 break;
6853 }
6854 if (LocaleCompare("pen",option+1) == 0)
6855 {
6856 if (*option == '+')
6857 {
6858 (void) SetImageOption(image_info,option+1,"none");
6859 break;
6860 }
6861 (void) SetImageOption(image_info,option+1,argv[i+1]);
6862 break;
6863 }
6864 if (LocaleCompare("ping",option+1) == 0)
6865 {
6866 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6867 break;
6868 }
6869 if (LocaleCompare("pointsize",option+1) == 0)
6870 {
6871 if (*option == '+')
6872 geometry_info.rho=0.0;
6873 else
6874 (void) ParseGeometry(argv[i+1],&geometry_info);
6875 image_info->pointsize=geometry_info.rho;
6876 break;
6877 }
cristye7f51092010-01-17 00:39:37 +00006878 if (LocaleCompare("precision",option+1) == 0)
6879 {
cristybf2766a2010-01-17 03:33:23 +00006880 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006881 break;
6882 }
cristy3ed852e2009-09-05 21:47:34 +00006883 if (LocaleCompare("preview",option+1) == 0)
6884 {
6885 /*
6886 Preview image.
6887 */
6888 if (*option == '+')
6889 {
6890 image_info->preview_type=UndefinedPreview;
6891 break;
6892 }
cristy042ee782011-04-22 18:48:30 +00006893 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006894 MagickPreviewOptions,MagickFalse,argv[i+1]);
6895 break;
6896 }
6897 break;
6898 }
6899 case 'q':
6900 {
6901 if (LocaleCompare("quality",option+1) == 0)
6902 {
6903 /*
6904 Set image compression quality.
6905 */
6906 if (*option == '+')
6907 {
6908 image_info->quality=UndefinedCompressionQuality;
6909 (void) SetImageOption(image_info,option+1,"0");
6910 break;
6911 }
cristye27293e2009-12-18 02:53:20 +00006912 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006913 (void) SetImageOption(image_info,option+1,argv[i+1]);
6914 break;
6915 }
6916 if (LocaleCompare("quiet",option+1) == 0)
6917 {
6918 static WarningHandler
6919 warning_handler = (WarningHandler) NULL;
6920
6921 if (*option == '+')
6922 {
6923 /*
6924 Restore error or warning messages.
6925 */
6926 warning_handler=SetWarningHandler(warning_handler);
6927 break;
6928 }
6929 /*
6930 Suppress error or warning messages.
6931 */
6932 warning_handler=SetWarningHandler((WarningHandler) NULL);
6933 break;
6934 }
6935 break;
6936 }
6937 case 'r':
6938 {
6939 if (LocaleCompare("red-primary",option+1) == 0)
6940 {
6941 if (*option == '+')
6942 {
6943 (void) SetImageOption(image_info,option+1,"0.0");
6944 break;
6945 }
6946 (void) SetImageOption(image_info,option+1,argv[i+1]);
6947 break;
6948 }
6949 break;
6950 }
6951 case 's':
6952 {
6953 if (LocaleCompare("sampling-factor",option+1) == 0)
6954 {
6955 /*
6956 Set image sampling factor.
6957 */
6958 if (*option == '+')
6959 {
6960 if (image_info->sampling_factor != (char *) NULL)
6961 image_info->sampling_factor=DestroyString(
6962 image_info->sampling_factor);
6963 break;
6964 }
6965 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6966 break;
6967 }
6968 if (LocaleCompare("scene",option+1) == 0)
6969 {
6970 /*
6971 Set image scene.
6972 */
6973 if (*option == '+')
6974 {
6975 image_info->scene=0;
6976 (void) SetImageOption(image_info,option+1,"0");
6977 break;
6978 }
cristye27293e2009-12-18 02:53:20 +00006979 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006980 (void) SetImageOption(image_info,option+1,argv[i+1]);
6981 break;
6982 }
6983 if (LocaleCompare("seed",option+1) == 0)
6984 {
cristybb503372010-05-27 20:51:26 +00006985 size_t
cristy3ed852e2009-09-05 21:47:34 +00006986 seed;
6987
6988 if (*option == '+')
6989 {
cristybb503372010-05-27 20:51:26 +00006990 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006991 SeedPseudoRandomGenerator(seed);
6992 break;
6993 }
cristye27293e2009-12-18 02:53:20 +00006994 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006995 SeedPseudoRandomGenerator(seed);
6996 break;
6997 }
6998 if (LocaleCompare("size",option+1) == 0)
6999 {
7000 if (*option == '+')
7001 {
7002 if (image_info->size != (char *) NULL)
7003 image_info->size=DestroyString(image_info->size);
7004 break;
7005 }
7006 (void) CloneString(&image_info->size,argv[i+1]);
7007 break;
7008 }
7009 if (LocaleCompare("stroke",option+1) == 0)
7010 {
7011 if (*option == '+')
7012 {
7013 (void) SetImageOption(image_info,option+1,"none");
7014 break;
7015 }
7016 (void) SetImageOption(image_info,option+1,argv[i+1]);
7017 break;
7018 }
7019 if (LocaleCompare("strokewidth",option+1) == 0)
7020 {
7021 if (*option == '+')
7022 {
7023 (void) SetImageOption(image_info,option+1,"0");
7024 break;
7025 }
7026 (void) SetImageOption(image_info,option+1,argv[i+1]);
7027 break;
7028 }
cristyd9a29192010-10-16 16:49:53 +00007029 if (LocaleCompare("synchronize",option+1) == 0)
7030 {
7031 if (*option == '+')
7032 {
7033 image_info->synchronize=MagickFalse;
7034 break;
7035 }
7036 image_info->synchronize=MagickTrue;
7037 break;
7038 }
cristy3ed852e2009-09-05 21:47:34 +00007039 break;
7040 }
7041 case 't':
7042 {
7043 if (LocaleCompare("taint",option+1) == 0)
7044 {
7045 if (*option == '+')
7046 {
7047 (void) SetImageOption(image_info,option+1,"false");
7048 break;
7049 }
7050 (void) SetImageOption(image_info,option+1,"true");
7051 break;
7052 }
7053 if (LocaleCompare("texture",option+1) == 0)
7054 {
7055 if (*option == '+')
7056 {
7057 if (image_info->texture != (char *) NULL)
7058 image_info->texture=DestroyString(image_info->texture);
7059 break;
7060 }
7061 (void) CloneString(&image_info->texture,argv[i+1]);
7062 break;
7063 }
7064 if (LocaleCompare("tile-offset",option+1) == 0)
7065 {
7066 if (*option == '+')
7067 {
7068 (void) SetImageOption(image_info,option+1,"0");
7069 break;
7070 }
7071 (void) SetImageOption(image_info,option+1,argv[i+1]);
7072 break;
7073 }
7074 if (LocaleCompare("transparent-color",option+1) == 0)
7075 {
7076 if (*option == '+')
7077 {
7078 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7079 (void) SetImageOption(image_info,option+1,"none");
7080 break;
7081 }
7082 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7083 exception);
7084 (void) SetImageOption(image_info,option+1,argv[i+1]);
7085 break;
7086 }
7087 if (LocaleCompare("type",option+1) == 0)
7088 {
7089 if (*option == '+')
7090 {
cristy5f1c1ff2010-12-23 21:38:06 +00007091 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007092 (void) SetImageOption(image_info,option+1,"undefined");
7093 break;
7094 }
cristy042ee782011-04-22 18:48:30 +00007095 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007096 MagickFalse,argv[i+1]);
7097 (void) SetImageOption(image_info,option+1,argv[i+1]);
7098 break;
7099 }
7100 break;
7101 }
7102 case 'u':
7103 {
7104 if (LocaleCompare("undercolor",option+1) == 0)
7105 {
7106 if (*option == '+')
7107 {
7108 (void) DeleteImageOption(image_info,option+1);
7109 break;
7110 }
7111 (void) SetImageOption(image_info,option+1,argv[i+1]);
7112 break;
7113 }
7114 if (LocaleCompare("units",option+1) == 0)
7115 {
7116 if (*option == '+')
7117 {
7118 image_info->units=UndefinedResolution;
7119 (void) SetImageOption(image_info,option+1,"undefined");
7120 break;
7121 }
cristy042ee782011-04-22 18:48:30 +00007122 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007123 MagickResolutionOptions,MagickFalse,argv[i+1]);
7124 (void) SetImageOption(image_info,option+1,argv[i+1]);
7125 break;
7126 }
7127 break;
7128 }
7129 case 'v':
7130 {
7131 if (LocaleCompare("verbose",option+1) == 0)
7132 {
7133 if (*option == '+')
7134 {
7135 image_info->verbose=MagickFalse;
7136 break;
7137 }
7138 image_info->verbose=MagickTrue;
7139 image_info->ping=MagickFalse;
7140 break;
7141 }
7142 if (LocaleCompare("view",option+1) == 0)
7143 {
7144 if (*option == '+')
7145 {
7146 if (image_info->view != (char *) NULL)
7147 image_info->view=DestroyString(image_info->view);
7148 break;
7149 }
7150 (void) CloneString(&image_info->view,argv[i+1]);
7151 break;
7152 }
7153 if (LocaleCompare("virtual-pixel",option+1) == 0)
7154 {
7155 if (*option == '+')
7156 {
7157 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7158 (void) SetImageOption(image_info,option+1,"undefined");
7159 break;
7160 }
7161 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007162 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007163 argv[i+1]);
7164 (void) SetImageOption(image_info,option+1,argv[i+1]);
7165 break;
7166 }
7167 break;
7168 }
7169 case 'w':
7170 {
7171 if (LocaleCompare("white-point",option+1) == 0)
7172 {
7173 if (*option == '+')
7174 {
7175 (void) SetImageOption(image_info,option+1,"0.0");
7176 break;
7177 }
7178 (void) SetImageOption(image_info,option+1,argv[i+1]);
7179 break;
7180 }
7181 break;
7182 }
7183 default:
7184 break;
7185 }
7186 i+=count;
7187 }
7188 return(MagickTrue);
7189}
7190
7191/*
7192%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7193% %
7194% %
7195% %
7196+ M o g r i f y I m a g e L i s t %
7197% %
7198% %
7199% %
7200%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7201%
7202% MogrifyImageList() applies any command line options that might affect the
7203% entire image list (e.g. -append, -coalesce, etc.).
7204%
7205% The format of the MogrifyImage method is:
7206%
7207% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7208% const char **argv,Image **images,ExceptionInfo *exception)
7209%
7210% A description of each parameter follows:
7211%
7212% o image_info: the image info..
7213%
7214% o argc: Specifies a pointer to an integer describing the number of
7215% elements in the argument vector.
7216%
7217% o argv: Specifies a pointer to a text array containing the command line
7218% arguments.
7219%
anthonye9c27192011-03-27 08:07:06 +00007220% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007221%
7222% o exception: return any errors or warnings in this structure.
7223%
7224*/
7225WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7226 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7227{
cristy3ed852e2009-09-05 21:47:34 +00007228 const char
7229 *option;
7230
cristy6b3da3a2010-06-20 02:21:46 +00007231 ImageInfo
7232 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007233
7234 MagickStatusType
7235 status;
7236
cristy28474bf2011-09-11 23:32:52 +00007237 PixelInterpolateMethod
7238 interpolate_method;
7239
cristy3ed852e2009-09-05 21:47:34 +00007240 QuantizeInfo
7241 *quantize_info;
7242
cristybb503372010-05-27 20:51:26 +00007243 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007244 i;
7245
cristy6b3da3a2010-06-20 02:21:46 +00007246 ssize_t
7247 count,
7248 index;
7249
cristy3ed852e2009-09-05 21:47:34 +00007250 /*
7251 Apply options to the image list.
7252 */
7253 assert(image_info != (ImageInfo *) NULL);
7254 assert(image_info->signature == MagickSignature);
7255 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007256 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007257 assert((*images)->signature == MagickSignature);
7258 if ((*images)->debug != MagickFalse)
7259 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7260 (*images)->filename);
7261 if ((argc <= 0) || (*argv == (char *) NULL))
7262 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007263 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007264 mogrify_info=CloneImageInfo(image_info);
7265 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007266 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007267 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007268 {
cristy74fe8f12009-10-03 19:09:01 +00007269 if (*images == (Image *) NULL)
7270 break;
cristy3ed852e2009-09-05 21:47:34 +00007271 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007272 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007273 continue;
cristy042ee782011-04-22 18:48:30 +00007274 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007275 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007276 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007277 break;
cristy6b3da3a2010-06-20 02:21:46 +00007278 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007279 switch (*(option+1))
7280 {
7281 case 'a':
7282 {
7283 if (LocaleCompare("affinity",option+1) == 0)
7284 {
cristy6b3da3a2010-06-20 02:21:46 +00007285 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007286 if (*option == '+')
7287 {
cristy018f07f2011-09-04 21:15:19 +00007288 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7289 exception);
cristy3ed852e2009-09-05 21:47:34 +00007290 break;
7291 }
7292 i++;
7293 break;
7294 }
7295 if (LocaleCompare("append",option+1) == 0)
7296 {
7297 Image
7298 *append_image;
7299
cristy6b3da3a2010-06-20 02:21:46 +00007300 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007301 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7302 MagickFalse,exception);
7303 if (append_image == (Image *) NULL)
7304 {
7305 status=MagickFalse;
7306 break;
7307 }
7308 *images=DestroyImageList(*images);
7309 *images=append_image;
7310 break;
7311 }
7312 if (LocaleCompare("average",option+1) == 0)
7313 {
7314 Image
7315 *average_image;
7316
cristyd18ae7c2010-03-07 17:39:52 +00007317 /*
7318 Average an image sequence (deprecated).
7319 */
cristy6b3da3a2010-06-20 02:21:46 +00007320 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007321 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7322 exception);
cristy3ed852e2009-09-05 21:47:34 +00007323 if (average_image == (Image *) NULL)
7324 {
7325 status=MagickFalse;
7326 break;
7327 }
7328 *images=DestroyImageList(*images);
7329 *images=average_image;
7330 break;
7331 }
7332 break;
7333 }
7334 case 'c':
7335 {
7336 if (LocaleCompare("channel",option+1) == 0)
7337 {
cristyf4ad9df2011-07-08 16:49:03 +00007338 ChannelType
7339 channel;
7340
cristy3ed852e2009-09-05 21:47:34 +00007341 if (*option == '+')
7342 {
7343 channel=DefaultChannels;
7344 break;
7345 }
7346 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007347 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007348 break;
7349 }
7350 if (LocaleCompare("clut",option+1) == 0)
7351 {
7352 Image
7353 *clut_image,
7354 *image;
7355
cristy6b3da3a2010-06-20 02:21:46 +00007356 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007357 image=RemoveFirstImageFromList(images);
7358 clut_image=RemoveFirstImageFromList(images);
7359 if (clut_image == (Image *) NULL)
7360 {
7361 status=MagickFalse;
7362 break;
7363 }
cristy28474bf2011-09-11 23:32:52 +00007364 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007365 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007366 *images=DestroyImageList(*images);
7367 *images=image;
7368 break;
7369 }
7370 if (LocaleCompare("coalesce",option+1) == 0)
7371 {
7372 Image
7373 *coalesce_image;
7374
cristy6b3da3a2010-06-20 02:21:46 +00007375 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007376 coalesce_image=CoalesceImages(*images,exception);
7377 if (coalesce_image == (Image *) NULL)
7378 {
7379 status=MagickFalse;
7380 break;
7381 }
7382 *images=DestroyImageList(*images);
7383 *images=coalesce_image;
7384 break;
7385 }
7386 if (LocaleCompare("combine",option+1) == 0)
7387 {
7388 Image
7389 *combine_image;
7390
cristy6b3da3a2010-06-20 02:21:46 +00007391 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007392 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007393 if (combine_image == (Image *) NULL)
7394 {
7395 status=MagickFalse;
7396 break;
7397 }
7398 *images=DestroyImageList(*images);
7399 *images=combine_image;
7400 break;
7401 }
7402 if (LocaleCompare("composite",option+1) == 0)
7403 {
7404 Image
7405 *mask_image,
7406 *composite_image,
7407 *image;
7408
7409 RectangleInfo
7410 geometry;
7411
cristy6b3da3a2010-06-20 02:21:46 +00007412 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007413 image=RemoveFirstImageFromList(images);
7414 composite_image=RemoveFirstImageFromList(images);
7415 if (composite_image == (Image *) NULL)
7416 {
7417 status=MagickFalse;
7418 break;
7419 }
7420 (void) TransformImage(&composite_image,(char *) NULL,
7421 composite_image->geometry);
7422 SetGeometry(composite_image,&geometry);
7423 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7424 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7425 &geometry);
7426 mask_image=RemoveFirstImageFromList(images);
7427 if (mask_image != (Image *) NULL)
7428 {
7429 if ((image->compose == DisplaceCompositeOp) ||
7430 (image->compose == DistortCompositeOp))
7431 {
7432 /*
7433 Merge Y displacement into X displacement image.
7434 */
7435 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7436 mask_image,0,0);
7437 mask_image=DestroyImage(mask_image);
7438 }
7439 else
7440 {
7441 /*
7442 Set a blending mask for the composition.
cristy28474bf2011-09-11 23:32:52 +00007443 Posible error, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007444 */
7445 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007446 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007447 }
7448 }
cristyf4ad9df2011-07-08 16:49:03 +00007449 (void) CompositeImage(image,image->compose,composite_image,
7450 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007451 if (mask_image != (Image *) NULL)
7452 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007453 composite_image=DestroyImage(composite_image);
7454 InheritException(exception,&image->exception);
7455 *images=DestroyImageList(*images);
7456 *images=image;
7457 break;
7458 }
cristy3ed852e2009-09-05 21:47:34 +00007459 break;
7460 }
7461 case 'd':
7462 {
7463 if (LocaleCompare("deconstruct",option+1) == 0)
7464 {
7465 Image
7466 *deconstruct_image;
7467
cristy6b3da3a2010-06-20 02:21:46 +00007468 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007469 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007470 exception);
cristy3ed852e2009-09-05 21:47:34 +00007471 if (deconstruct_image == (Image *) NULL)
7472 {
7473 status=MagickFalse;
7474 break;
7475 }
7476 *images=DestroyImageList(*images);
7477 *images=deconstruct_image;
7478 break;
7479 }
7480 if (LocaleCompare("delete",option+1) == 0)
7481 {
7482 if (*option == '+')
7483 DeleteImages(images,"-1",exception);
7484 else
7485 DeleteImages(images,argv[i+1],exception);
7486 break;
7487 }
7488 if (LocaleCompare("dither",option+1) == 0)
7489 {
7490 if (*option == '+')
7491 {
7492 quantize_info->dither=MagickFalse;
7493 break;
7494 }
7495 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007496 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007497 MagickDitherOptions,MagickFalse,argv[i+1]);
7498 break;
7499 }
cristyecb10ff2011-03-22 13:14:03 +00007500 if (LocaleCompare("duplicate",option+1) == 0)
7501 {
cristy72988482011-03-29 16:34:38 +00007502 Image
7503 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007504
anthony2b6bcae2011-03-23 13:05:34 +00007505 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007506 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7507 else
7508 {
7509 const char
7510 *p;
7511
anthony2b6bcae2011-03-23 13:05:34 +00007512 size_t
7513 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007514
anthony2b6bcae2011-03-23 13:05:34 +00007515 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007516 p=strchr(argv[i+1],',');
7517 if (p == (const char *) NULL)
7518 duplicate_images=DuplicateImages(*images,number_duplicates,
7519 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007520 else
cristy72988482011-03-29 16:34:38 +00007521 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7522 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007523 }
7524 AppendImageToList(images, duplicate_images);
7525 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007526 break;
7527 }
cristy3ed852e2009-09-05 21:47:34 +00007528 break;
7529 }
cristyd18ae7c2010-03-07 17:39:52 +00007530 case 'e':
7531 {
7532 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7533 {
7534 Image
7535 *evaluate_image;
7536
7537 MagickEvaluateOperator
7538 op;
7539
cristy6b3da3a2010-06-20 02:21:46 +00007540 (void) SyncImageSettings(mogrify_info,*images);
cristy28474bf2011-09-11 23:32:52 +00007541 op=(MagickEvaluateOperator) ParseCommandOption(
7542 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007543 evaluate_image=EvaluateImages(*images,op,exception);
7544 if (evaluate_image == (Image *) NULL)
7545 {
7546 status=MagickFalse;
7547 break;
7548 }
7549 *images=DestroyImageList(*images);
7550 *images=evaluate_image;
7551 break;
7552 }
7553 break;
7554 }
cristy3ed852e2009-09-05 21:47:34 +00007555 case 'f':
7556 {
cristyf0a247f2009-10-04 00:20:03 +00007557 if (LocaleCompare("fft",option+1) == 0)
7558 {
7559 Image
7560 *fourier_image;
7561
7562 /*
7563 Implements the discrete Fourier transform (DFT).
7564 */
cristy6b3da3a2010-06-20 02:21:46 +00007565 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007566 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7567 MagickTrue : MagickFalse,exception);
7568 if (fourier_image == (Image *) NULL)
7569 break;
7570 *images=DestroyImage(*images);
7571 *images=fourier_image;
7572 break;
7573 }
cristy3ed852e2009-09-05 21:47:34 +00007574 if (LocaleCompare("flatten",option+1) == 0)
7575 {
7576 Image
7577 *flatten_image;
7578
cristy6b3da3a2010-06-20 02:21:46 +00007579 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007580 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7581 if (flatten_image == (Image *) NULL)
7582 break;
7583 *images=DestroyImageList(*images);
7584 *images=flatten_image;
7585 break;
7586 }
7587 if (LocaleCompare("fx",option+1) == 0)
7588 {
7589 Image
7590 *fx_image;
7591
cristy6b3da3a2010-06-20 02:21:46 +00007592 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007593 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007594 if (fx_image == (Image *) NULL)
7595 {
7596 status=MagickFalse;
7597 break;
7598 }
7599 *images=DestroyImageList(*images);
7600 *images=fx_image;
7601 break;
7602 }
7603 break;
7604 }
7605 case 'h':
7606 {
7607 if (LocaleCompare("hald-clut",option+1) == 0)
7608 {
7609 Image
7610 *hald_image,
7611 *image;
7612
cristy6b3da3a2010-06-20 02:21:46 +00007613 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007614 image=RemoveFirstImageFromList(images);
7615 hald_image=RemoveFirstImageFromList(images);
7616 if (hald_image == (Image *) NULL)
7617 {
7618 status=MagickFalse;
7619 break;
7620 }
cristy7c0a0a42011-08-23 17:57:25 +00007621 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007622 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007623 if (*images != (Image *) NULL)
7624 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007625 *images=image;
7626 break;
7627 }
7628 break;
7629 }
7630 case 'i':
7631 {
7632 if (LocaleCompare("ift",option+1) == 0)
7633 {
7634 Image
cristy8587f882009-11-13 20:28:49 +00007635 *fourier_image,
7636 *magnitude_image,
7637 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007638
7639 /*
7640 Implements the inverse fourier discrete Fourier transform (DFT).
7641 */
cristy6b3da3a2010-06-20 02:21:46 +00007642 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007643 magnitude_image=RemoveFirstImageFromList(images);
7644 phase_image=RemoveFirstImageFromList(images);
7645 if (phase_image == (Image *) NULL)
7646 {
7647 status=MagickFalse;
7648 break;
7649 }
7650 fourier_image=InverseFourierTransformImage(magnitude_image,
7651 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007652 if (fourier_image == (Image *) NULL)
7653 break;
cristy0aff6ea2009-11-14 01:40:53 +00007654 if (*images != (Image *) NULL)
7655 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007656 *images=fourier_image;
7657 break;
7658 }
7659 if (LocaleCompare("insert",option+1) == 0)
7660 {
7661 Image
7662 *p,
7663 *q;
7664
7665 index=0;
7666 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007667 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007668 p=RemoveLastImageFromList(images);
7669 if (p == (Image *) NULL)
7670 {
7671 (void) ThrowMagickException(exception,GetMagickModule(),
7672 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7673 status=MagickFalse;
7674 break;
7675 }
7676 q=p;
7677 if (index == 0)
7678 PrependImageToList(images,q);
7679 else
cristybb503372010-05-27 20:51:26 +00007680 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007681 AppendImageToList(images,q);
7682 else
7683 {
7684 q=GetImageFromList(*images,index-1);
7685 if (q == (Image *) NULL)
7686 {
7687 (void) ThrowMagickException(exception,GetMagickModule(),
7688 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7689 status=MagickFalse;
7690 break;
7691 }
7692 InsertImageInList(&q,p);
7693 }
7694 *images=GetFirstImageInList(q);
7695 break;
7696 }
cristy28474bf2011-09-11 23:32:52 +00007697 if (LocaleCompare("interpolate",option+1) == 0)
7698 {
7699 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7700 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7701 break;
7702 }
cristy3ed852e2009-09-05 21:47:34 +00007703 break;
7704 }
7705 case 'l':
7706 {
7707 if (LocaleCompare("layers",option+1) == 0)
7708 {
7709 Image
7710 *layers;
7711
7712 ImageLayerMethod
7713 method;
7714
cristy6b3da3a2010-06-20 02:21:46 +00007715 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007716 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007717 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007718 MagickFalse,argv[i+1]);
7719 switch (method)
7720 {
7721 case CoalesceLayer:
7722 {
7723 layers=CoalesceImages(*images,exception);
7724 break;
7725 }
7726 case CompareAnyLayer:
7727 case CompareClearLayer:
7728 case CompareOverlayLayer:
7729 default:
7730 {
cristy8a9106f2011-07-05 14:39:26 +00007731 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007732 break;
7733 }
7734 case MergeLayer:
7735 case FlattenLayer:
7736 case MosaicLayer:
7737 case TrimBoundsLayer:
7738 {
7739 layers=MergeImageLayers(*images,method,exception);
7740 break;
7741 }
7742 case DisposeLayer:
7743 {
7744 layers=DisposeImages(*images,exception);
7745 break;
7746 }
7747 case OptimizeImageLayer:
7748 {
7749 layers=OptimizeImageLayers(*images,exception);
7750 break;
7751 }
7752 case OptimizePlusLayer:
7753 {
7754 layers=OptimizePlusImageLayers(*images,exception);
7755 break;
7756 }
7757 case OptimizeTransLayer:
7758 {
7759 OptimizeImageTransparency(*images,exception);
7760 break;
7761 }
7762 case RemoveDupsLayer:
7763 {
7764 RemoveDuplicateLayers(images,exception);
7765 break;
7766 }
7767 case RemoveZeroLayer:
7768 {
7769 RemoveZeroDelayLayers(images,exception);
7770 break;
7771 }
7772 case OptimizeLayer:
7773 {
7774 /*
7775 General Purpose, GIF Animation Optimizer.
7776 */
7777 layers=CoalesceImages(*images,exception);
7778 if (layers == (Image *) NULL)
7779 {
7780 status=MagickFalse;
7781 break;
7782 }
cristy3ed852e2009-09-05 21:47:34 +00007783 *images=DestroyImageList(*images);
7784 *images=layers;
7785 layers=OptimizeImageLayers(*images,exception);
7786 if (layers == (Image *) NULL)
7787 {
7788 status=MagickFalse;
7789 break;
7790 }
cristy3ed852e2009-09-05 21:47:34 +00007791 *images=DestroyImageList(*images);
7792 *images=layers;
7793 layers=(Image *) NULL;
7794 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007795 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7796 exception);
cristy3ed852e2009-09-05 21:47:34 +00007797 break;
7798 }
7799 case CompositeLayer:
7800 {
7801 CompositeOperator
7802 compose;
7803
7804 Image
7805 *source;
7806
7807 RectangleInfo
7808 geometry;
7809
7810 /*
7811 Split image sequence at the first 'NULL:' image.
7812 */
7813 source=(*images);
7814 while (source != (Image *) NULL)
7815 {
7816 source=GetNextImageInList(source);
7817 if ((source != (Image *) NULL) &&
7818 (LocaleCompare(source->magick,"NULL") == 0))
7819 break;
7820 }
7821 if (source != (Image *) NULL)
7822 {
7823 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7824 (GetNextImageInList(source) == (Image *) NULL))
7825 source=(Image *) NULL;
7826 else
7827 {
7828 /*
7829 Separate the two lists, junk the null: image.
7830 */
7831 source=SplitImageList(source->previous);
7832 DeleteImageFromList(&source);
7833 }
7834 }
7835 if (source == (Image *) NULL)
7836 {
7837 (void) ThrowMagickException(exception,GetMagickModule(),
7838 OptionError,"MissingNullSeparator","layers Composite");
7839 status=MagickFalse;
7840 break;
7841 }
7842 /*
7843 Adjust offset with gravity and virtual canvas.
7844 */
7845 SetGeometry(*images,&geometry);
7846 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7847 geometry.width=source->page.width != 0 ?
7848 source->page.width : source->columns;
7849 geometry.height=source->page.height != 0 ?
7850 source->page.height : source->rows;
7851 GravityAdjustGeometry((*images)->page.width != 0 ?
7852 (*images)->page.width : (*images)->columns,
7853 (*images)->page.height != 0 ? (*images)->page.height :
7854 (*images)->rows,(*images)->gravity,&geometry);
7855 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007856 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007857 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007858 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007859 MagickComposeOptions,MagickFalse,option);
7860 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7861 exception);
7862 source=DestroyImageList(source);
7863 break;
7864 }
7865 }
7866 if (layers == (Image *) NULL)
7867 break;
7868 InheritException(exception,&layers->exception);
7869 *images=DestroyImageList(*images);
7870 *images=layers;
7871 break;
7872 }
7873 break;
7874 }
7875 case 'm':
7876 {
7877 if (LocaleCompare("map",option+1) == 0)
7878 {
cristy6b3da3a2010-06-20 02:21:46 +00007879 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007880 if (*option == '+')
7881 {
cristy018f07f2011-09-04 21:15:19 +00007882 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7883 exception);
cristy3ed852e2009-09-05 21:47:34 +00007884 break;
7885 }
7886 i++;
7887 break;
7888 }
cristyf40785b2010-03-06 02:27:27 +00007889 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007890 {
7891 Image
cristyf40785b2010-03-06 02:27:27 +00007892 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007893
cristyd18ae7c2010-03-07 17:39:52 +00007894 /*
7895 Maximum image sequence (deprecated).
7896 */
cristy6b3da3a2010-06-20 02:21:46 +00007897 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007898 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007899 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007900 {
7901 status=MagickFalse;
7902 break;
7903 }
7904 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007905 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007906 break;
7907 }
cristyf40785b2010-03-06 02:27:27 +00007908 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007909 {
7910 Image
cristyf40785b2010-03-06 02:27:27 +00007911 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007912
cristyd18ae7c2010-03-07 17:39:52 +00007913 /*
7914 Minimum image sequence (deprecated).
7915 */
cristy6b3da3a2010-06-20 02:21:46 +00007916 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007917 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007918 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007919 {
7920 status=MagickFalse;
7921 break;
7922 }
7923 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007924 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007925 break;
7926 }
cristy3ed852e2009-09-05 21:47:34 +00007927 if (LocaleCompare("morph",option+1) == 0)
7928 {
7929 Image
7930 *morph_image;
7931
cristy6b3da3a2010-06-20 02:21:46 +00007932 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007933 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007934 exception);
7935 if (morph_image == (Image *) NULL)
7936 {
7937 status=MagickFalse;
7938 break;
7939 }
7940 *images=DestroyImageList(*images);
7941 *images=morph_image;
7942 break;
7943 }
7944 if (LocaleCompare("mosaic",option+1) == 0)
7945 {
7946 Image
7947 *mosaic_image;
7948
cristy6b3da3a2010-06-20 02:21:46 +00007949 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007950 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7951 if (mosaic_image == (Image *) NULL)
7952 {
7953 status=MagickFalse;
7954 break;
7955 }
7956 *images=DestroyImageList(*images);
7957 *images=mosaic_image;
7958 break;
7959 }
7960 break;
7961 }
7962 case 'p':
7963 {
7964 if (LocaleCompare("print",option+1) == 0)
7965 {
7966 char
7967 *string;
7968
cristy6b3da3a2010-06-20 02:21:46 +00007969 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007970 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7971 exception);
cristy3ed852e2009-09-05 21:47:34 +00007972 if (string == (char *) NULL)
7973 break;
cristyb51dff52011-05-19 16:55:47 +00007974 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007975 string=DestroyString(string);
7976 }
7977 if (LocaleCompare("process",option+1) == 0)
7978 {
7979 char
7980 **arguments;
7981
7982 int
7983 j,
7984 number_arguments;
7985
cristy6b3da3a2010-06-20 02:21:46 +00007986 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007987 arguments=StringToArgv(argv[i+1],&number_arguments);
7988 if (arguments == (char **) NULL)
7989 break;
7990 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7991 {
7992 char
7993 breaker,
7994 quote,
7995 *token;
7996
7997 const char
7998 *arguments;
7999
8000 int
8001 next,
8002 status;
8003
8004 size_t
8005 length;
8006
8007 TokenInfo
8008 *token_info;
8009
8010 /*
8011 Support old style syntax, filter="-option arg".
8012 */
8013 length=strlen(argv[i+1]);
8014 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008015 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008016 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8017 sizeof(*token));
8018 if (token == (char *) NULL)
8019 break;
8020 next=0;
8021 arguments=argv[i+1];
8022 token_info=AcquireTokenInfo();
8023 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8024 "\"",'\0',&breaker,&next,&quote);
8025 token_info=DestroyTokenInfo(token_info);
8026 if (status == 0)
8027 {
8028 const char
8029 *argv;
8030
8031 argv=(&(arguments[next]));
8032 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8033 exception);
8034 }
8035 token=DestroyString(token);
8036 break;
8037 }
cristy91c0da22010-05-02 01:44:07 +00008038 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008039 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8040 number_arguments-2,(const char **) arguments+2,exception);
8041 for (j=0; j < number_arguments; j++)
8042 arguments[j]=DestroyString(arguments[j]);
8043 arguments=(char **) RelinquishMagickMemory(arguments);
8044 break;
8045 }
8046 break;
8047 }
8048 case 'r':
8049 {
8050 if (LocaleCompare("reverse",option+1) == 0)
8051 {
8052 ReverseImageList(images);
8053 InheritException(exception,&(*images)->exception);
8054 break;
8055 }
8056 break;
8057 }
8058 case 's':
8059 {
cristy4285d782011-02-09 20:12:28 +00008060 if (LocaleCompare("smush",option+1) == 0)
8061 {
8062 Image
8063 *smush_image;
8064
8065 ssize_t
8066 offset;
8067
8068 (void) SyncImagesSettings(mogrify_info,*images);
8069 offset=(ssize_t) StringToLong(argv[i+1]);
8070 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8071 MagickFalse,offset,exception);
8072 if (smush_image == (Image *) NULL)
8073 {
8074 status=MagickFalse;
8075 break;
8076 }
8077 *images=DestroyImageList(*images);
8078 *images=smush_image;
8079 break;
8080 }
cristy3ed852e2009-09-05 21:47:34 +00008081 if (LocaleCompare("swap",option+1) == 0)
8082 {
8083 Image
8084 *p,
8085 *q,
8086 *swap;
8087
cristybb503372010-05-27 20:51:26 +00008088 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008089 swap_index;
8090
8091 index=(-1);
8092 swap_index=(-2);
8093 if (*option != '+')
8094 {
8095 GeometryInfo
8096 geometry_info;
8097
8098 MagickStatusType
8099 flags;
8100
8101 swap_index=(-1);
8102 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008103 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008104 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008105 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008106 }
8107 p=GetImageFromList(*images,index);
8108 q=GetImageFromList(*images,swap_index);
8109 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8110 {
8111 (void) ThrowMagickException(exception,GetMagickModule(),
8112 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8113 status=MagickFalse;
8114 break;
8115 }
8116 if (p == q)
8117 break;
8118 swap=CloneImage(p,0,0,MagickTrue,exception);
8119 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8120 ReplaceImageInList(&q,swap);
8121 *images=GetFirstImageInList(q);
8122 break;
8123 }
8124 break;
8125 }
8126 case 'w':
8127 {
8128 if (LocaleCompare("write",option+1) == 0)
8129 {
cristy071dd7b2010-04-09 13:04:54 +00008130 char
cristy06609ee2010-03-17 20:21:27 +00008131 key[MaxTextExtent];
8132
cristy3ed852e2009-09-05 21:47:34 +00008133 Image
8134 *write_images;
8135
8136 ImageInfo
8137 *write_info;
8138
cristy6b3da3a2010-06-20 02:21:46 +00008139 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008140 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008141 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008142 write_images=(*images);
8143 if (*option == '+')
8144 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008145 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008146 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8147 write_info=DestroyImageInfo(write_info);
8148 if (*option == '+')
8149 write_images=DestroyImageList(write_images);
8150 break;
8151 }
8152 break;
8153 }
8154 default:
8155 break;
8156 }
8157 i+=count;
8158 }
8159 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008160 mogrify_info=DestroyImageInfo(mogrify_info);
8161 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008162 return(status != 0 ? MagickTrue : MagickFalse);
8163}
8164
8165/*
8166%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8167% %
8168% %
8169% %
8170+ M o g r i f y I m a g e s %
8171% %
8172% %
8173% %
8174%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8175%
8176% MogrifyImages() applies image processing options to a sequence of images as
8177% prescribed by command line options.
8178%
8179% The format of the MogrifyImage method is:
8180%
8181% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8182% const MagickBooleanType post,const int argc,const char **argv,
8183% Image **images,Exceptioninfo *exception)
8184%
8185% A description of each parameter follows:
8186%
8187% o image_info: the image info..
8188%
8189% o post: If true, post process image list operators otherwise pre-process.
8190%
8191% o argc: Specifies a pointer to an integer describing the number of
8192% elements in the argument vector.
8193%
8194% o argv: Specifies a pointer to a text array containing the command line
8195% arguments.
8196%
anthonye9c27192011-03-27 08:07:06 +00008197% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008198%
8199% o exception: return any errors or warnings in this structure.
8200%
8201*/
8202WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8203 const MagickBooleanType post,const int argc,const char **argv,
8204 Image **images,ExceptionInfo *exception)
8205{
8206#define MogrifyImageTag "Mogrify/Image"
8207
anthonye9c27192011-03-27 08:07:06 +00008208 MagickStatusType
8209 status;
cristy3ed852e2009-09-05 21:47:34 +00008210
cristy0e9f9c12010-02-11 03:00:47 +00008211 MagickBooleanType
8212 proceed;
8213
anthonye9c27192011-03-27 08:07:06 +00008214 size_t
8215 n;
cristy3ed852e2009-09-05 21:47:34 +00008216
cristybb503372010-05-27 20:51:26 +00008217 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008218 i;
8219
cristy3ed852e2009-09-05 21:47:34 +00008220 assert(image_info != (ImageInfo *) NULL);
8221 assert(image_info->signature == MagickSignature);
8222 if (images == (Image **) NULL)
8223 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008224 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008225 assert((*images)->signature == MagickSignature);
8226 if ((*images)->debug != MagickFalse)
8227 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8228 (*images)->filename);
8229 if ((argc <= 0) || (*argv == (char *) NULL))
8230 return(MagickTrue);
8231 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8232 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008233 status=0;
anthonye9c27192011-03-27 08:07:06 +00008234
anthonyce2716b2011-04-22 09:51:34 +00008235#if 0
cristy1e604812011-05-19 18:07:50 +00008236 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8237 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008238#endif
8239
anthonye9c27192011-03-27 08:07:06 +00008240 /*
8241 Pre-process multi-image sequence operators
8242 */
cristy3ed852e2009-09-05 21:47:34 +00008243 if (post == MagickFalse)
8244 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008245 /*
8246 For each image, process simple single image operators
8247 */
8248 i=0;
8249 n=GetImageListLength(*images);
8250 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008251 {
anthonyce2716b2011-04-22 09:51:34 +00008252#if 0
cristy1e604812011-05-19 18:07:50 +00008253 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8254 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008255#endif
anthonye9c27192011-03-27 08:07:06 +00008256 status&=MogrifyImage(image_info,argc,argv,images,exception);
8257 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008258 if (proceed == MagickFalse)
8259 break;
anthonye9c27192011-03-27 08:07:06 +00008260 if ( (*images)->next == (Image *) NULL )
8261 break;
8262 *images=(*images)->next;
8263 i++;
cristy3ed852e2009-09-05 21:47:34 +00008264 }
anthonye9c27192011-03-27 08:07:06 +00008265 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008266#if 0
cristy1e604812011-05-19 18:07:50 +00008267 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8268 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008269#endif
anthonye9c27192011-03-27 08:07:06 +00008270
8271 /*
8272 Post-process, multi-image sequence operators
8273 */
8274 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008275 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008276 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008277 return(status != 0 ? MagickTrue : MagickFalse);
8278}