blob: 152cbc854e846b44906713e03afe8cdd57c0d1a6 [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
cristy633f0c62011-09-15 13:27:36 +0000620 CompositeOperator
621 compose;
622
anthonydf8ebac2011-04-27 09:03:19 +0000623 const char
624 *format,
625 *option;
626
627 DrawInfo
628 *draw_info;
629
630 GeometryInfo
631 geometry_info;
632
cristy3ed852e2009-09-05 21:47:34 +0000633 Image
634 *region_image;
635
anthonydf8ebac2011-04-27 09:03:19 +0000636 ImageInfo
637 *mogrify_info;
638
cristyebbcfea2011-02-25 02:43:54 +0000639 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000640 status;
641
cristy4c08aed2011-07-01 19:47:50 +0000642 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000643 fill;
cristy3ed852e2009-09-05 21:47:34 +0000644
anthonydf8ebac2011-04-27 09:03:19 +0000645 MagickStatusType
646 flags;
647
cristy28474bf2011-09-11 23:32:52 +0000648 PixelInterpolateMethod
649 interpolate_method;
650
anthonydf8ebac2011-04-27 09:03:19 +0000651 QuantizeInfo
652 *quantize_info;
653
654 RectangleInfo
655 geometry,
656 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000657
cristybb503372010-05-27 20:51:26 +0000658 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000659 i;
660
661 /*
662 Initialize method variables.
663 */
664 assert(image_info != (const ImageInfo *) NULL);
665 assert(image_info->signature == MagickSignature);
666 assert(image != (Image **) NULL);
667 assert((*image)->signature == MagickSignature);
668 if ((*image)->debug != MagickFalse)
669 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
670 if (argc < 0)
671 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000672 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000673 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
674 quantize_info=AcquireQuantizeInfo(mogrify_info);
675 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000676 GetPixelInfo(*image,&fill);
677 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
cristy633f0c62011-09-15 13:27:36 +0000678 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000679 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000680 channel=mogrify_info->channel;
681 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000682 SetGeometry(*image,&region_geometry);
683 region_image=NewImageList();
684 /*
685 Transmogrify the image.
686 */
cristybb503372010-05-27 20:51:26 +0000687 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000688 {
anthonydf8ebac2011-04-27 09:03:19 +0000689 Image
690 *mogrify_image;
691
anthonye9c27192011-03-27 08:07:06 +0000692 ssize_t
693 count;
694
anthonydf8ebac2011-04-27 09:03:19 +0000695 option=argv[i];
696 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000697 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000698 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
699 0L);
cristycee97112010-05-28 00:44:52 +0000700 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000701 break;
cristy6b3da3a2010-06-20 02:21:46 +0000702 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000703 mogrify_image=(Image *)NULL;
704 switch (*(option+1))
705 {
706 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000707 {
anthonydf8ebac2011-04-27 09:03:19 +0000708 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000709 {
anthonydf8ebac2011-04-27 09:03:19 +0000710 /*
711 Adaptive blur image.
712 */
713 (void) SyncImageSettings(mogrify_info,*image);
714 flags=ParseGeometry(argv[i+1],&geometry_info);
715 if ((flags & SigmaValue) == 0)
716 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000717 if ((flags & XiValue) == 0)
718 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000719 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000720 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000721 break;
cristy3ed852e2009-09-05 21:47:34 +0000722 }
anthonydf8ebac2011-04-27 09:03:19 +0000723 if (LocaleCompare("adaptive-resize",option+1) == 0)
724 {
725 /*
726 Adaptive resize image.
727 */
728 (void) SyncImageSettings(mogrify_info,*image);
729 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
730 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy28474bf2011-09-11 23:32:52 +0000731 geometry.height,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000732 break;
733 }
734 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
735 {
736 /*
737 Adaptive sharpen image.
738 */
739 (void) SyncImageSettings(mogrify_info,*image);
740 flags=ParseGeometry(argv[i+1],&geometry_info);
741 if ((flags & SigmaValue) == 0)
742 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000743 if ((flags & XiValue) == 0)
744 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000745 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000746 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000747 break;
748 }
749 if (LocaleCompare("affine",option+1) == 0)
750 {
751 /*
752 Affine matrix.
753 */
754 if (*option == '+')
755 {
756 GetAffineMatrix(&draw_info->affine);
757 break;
758 }
759 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
760 break;
761 }
762 if (LocaleCompare("alpha",option+1) == 0)
763 {
764 AlphaChannelType
765 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000766
anthonydf8ebac2011-04-27 09:03:19 +0000767 (void) SyncImageSettings(mogrify_info,*image);
768 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
769 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000770 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000771 break;
772 }
773 if (LocaleCompare("annotate",option+1) == 0)
774 {
775 char
776 *text,
777 geometry[MaxTextExtent];
778
779 /*
780 Annotate image.
781 */
782 (void) SyncImageSettings(mogrify_info,*image);
783 SetGeometryInfo(&geometry_info);
784 flags=ParseGeometry(argv[i+1],&geometry_info);
785 if ((flags & SigmaValue) == 0)
786 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000787 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
788 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000789 if (text == (char *) NULL)
790 break;
791 (void) CloneString(&draw_info->text,text);
792 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000793 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000794 geometry_info.xi,geometry_info.psi);
795 (void) CloneString(&draw_info->geometry,geometry);
796 draw_info->affine.sx=cos(DegreesToRadians(
797 fmod(geometry_info.rho,360.0)));
798 draw_info->affine.rx=sin(DegreesToRadians(
799 fmod(geometry_info.rho,360.0)));
800 draw_info->affine.ry=(-sin(DegreesToRadians(
801 fmod(geometry_info.sigma,360.0))));
802 draw_info->affine.sy=cos(DegreesToRadians(
803 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000804 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000805 break;
806 }
807 if (LocaleCompare("antialias",option+1) == 0)
808 {
809 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
810 MagickFalse;
811 draw_info->text_antialias=(*option == '-') ? MagickTrue :
812 MagickFalse;
813 break;
814 }
815 if (LocaleCompare("auto-gamma",option+1) == 0)
816 {
817 /*
818 Auto Adjust Gamma of image based on its mean
819 */
820 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000821 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000822 break;
823 }
824 if (LocaleCompare("auto-level",option+1) == 0)
825 {
826 /*
827 Perfectly Normalize (max/min stretch) the image
828 */
829 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000830 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000831 break;
832 }
833 if (LocaleCompare("auto-orient",option+1) == 0)
834 {
835 (void) SyncImageSettings(mogrify_info,*image);
836 switch ((*image)->orientation)
837 {
838 case TopRightOrientation:
839 {
840 mogrify_image=FlopImage(*image,exception);
841 break;
842 }
843 case BottomRightOrientation:
844 {
845 mogrify_image=RotateImage(*image,180.0,exception);
846 break;
847 }
848 case BottomLeftOrientation:
849 {
850 mogrify_image=FlipImage(*image,exception);
851 break;
852 }
853 case LeftTopOrientation:
854 {
855 mogrify_image=TransposeImage(*image,exception);
856 break;
857 }
858 case RightTopOrientation:
859 {
860 mogrify_image=RotateImage(*image,90.0,exception);
861 break;
862 }
863 case RightBottomOrientation:
864 {
865 mogrify_image=TransverseImage(*image,exception);
866 break;
867 }
868 case LeftBottomOrientation:
869 {
870 mogrify_image=RotateImage(*image,270.0,exception);
871 break;
872 }
873 default:
874 break;
875 }
876 if (mogrify_image != (Image *) NULL)
877 mogrify_image->orientation=TopLeftOrientation;
878 break;
879 }
880 break;
881 }
882 case 'b':
883 {
884 if (LocaleCompare("black-threshold",option+1) == 0)
885 {
886 /*
887 Black threshold image.
888 */
889 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000890 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000891 InheritException(exception,&(*image)->exception);
892 break;
893 }
894 if (LocaleCompare("blue-shift",option+1) == 0)
895 {
896 /*
897 Blue shift image.
898 */
899 (void) SyncImageSettings(mogrify_info,*image);
900 geometry_info.rho=1.5;
901 if (*option == '-')
902 flags=ParseGeometry(argv[i+1],&geometry_info);
903 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
904 break;
905 }
906 if (LocaleCompare("blur",option+1) == 0)
907 {
908 /*
909 Gaussian blur image.
910 */
911 (void) SyncImageSettings(mogrify_info,*image);
912 flags=ParseGeometry(argv[i+1],&geometry_info);
913 if ((flags & SigmaValue) == 0)
914 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000915 if ((flags & XiValue) == 0)
916 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000917 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000918 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000919 break;
920 }
921 if (LocaleCompare("border",option+1) == 0)
922 {
923 /*
924 Surround image with a border of solid color.
925 */
926 (void) SyncImageSettings(mogrify_info,*image);
927 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
928 if ((flags & SigmaValue) == 0)
929 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000930 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000931 break;
932 }
933 if (LocaleCompare("bordercolor",option+1) == 0)
934 {
935 if (*option == '+')
936 {
cristy05c0c9a2011-09-05 23:16:13 +0000937 (void) QueryColorDatabase(MogrifyBorderColor,
938 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000939 break;
940 }
941 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
942 exception);
943 break;
944 }
945 if (LocaleCompare("box",option+1) == 0)
946 {
947 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
948 exception);
949 break;
950 }
951 if (LocaleCompare("brightness-contrast",option+1) == 0)
952 {
953 double
954 brightness,
955 contrast;
956
957 GeometryInfo
958 geometry_info;
959
960 MagickStatusType
961 flags;
962
963 /*
964 Brightness / contrast image.
965 */
966 (void) SyncImageSettings(mogrify_info,*image);
967 flags=ParseGeometry(argv[i+1],&geometry_info);
968 brightness=geometry_info.rho;
969 contrast=0.0;
970 if ((flags & SigmaValue) != 0)
971 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000972 (void) BrightnessContrastImage(*image,brightness,contrast,
973 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000974 InheritException(exception,&(*image)->exception);
975 break;
976 }
977 break;
978 }
979 case 'c':
980 {
981 if (LocaleCompare("cdl",option+1) == 0)
982 {
983 char
984 *color_correction_collection;
985
986 /*
987 Color correct with a color decision list.
988 */
989 (void) SyncImageSettings(mogrify_info,*image);
990 color_correction_collection=FileToString(argv[i+1],~0,exception);
991 if (color_correction_collection == (char *) NULL)
992 break;
cristy1bfa9f02011-08-11 02:35:43 +0000993 (void) ColorDecisionListImage(*image,color_correction_collection,
994 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000995 InheritException(exception,&(*image)->exception);
996 break;
997 }
998 if (LocaleCompare("channel",option+1) == 0)
999 {
1000 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +00001001 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +00001002 else
cristyfa806a72011-07-04 02:06:13 +00001003 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00001004 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001005 break;
1006 }
1007 if (LocaleCompare("charcoal",option+1) == 0)
1008 {
1009 /*
1010 Charcoal image.
1011 */
1012 (void) SyncImageSettings(mogrify_info,*image);
1013 flags=ParseGeometry(argv[i+1],&geometry_info);
1014 if ((flags & SigmaValue) == 0)
1015 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001016 if ((flags & XiValue) == 0)
1017 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001018 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001019 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001020 break;
1021 }
1022 if (LocaleCompare("chop",option+1) == 0)
1023 {
1024 /*
1025 Chop the image.
1026 */
1027 (void) SyncImageSettings(mogrify_info,*image);
1028 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1029 mogrify_image=ChopImage(*image,&geometry,exception);
1030 break;
1031 }
1032 if (LocaleCompare("clamp",option+1) == 0)
1033 {
1034 /*
1035 Clamp image.
1036 */
1037 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001038 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001039 InheritException(exception,&(*image)->exception);
1040 break;
1041 }
1042 if (LocaleCompare("clip",option+1) == 0)
1043 {
1044 (void) SyncImageSettings(mogrify_info,*image);
1045 if (*option == '+')
1046 {
cristy018f07f2011-09-04 21:15:19 +00001047 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001048 break;
1049 }
cristy018f07f2011-09-04 21:15:19 +00001050 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001051 break;
1052 }
1053 if (LocaleCompare("clip-mask",option+1) == 0)
1054 {
1055 CacheView
1056 *mask_view;
1057
1058 Image
1059 *mask_image;
1060
cristy4c08aed2011-07-01 19:47:50 +00001061 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001062 *restrict q;
1063
1064 register ssize_t
1065 x;
1066
1067 ssize_t
1068 y;
1069
1070 (void) SyncImageSettings(mogrify_info,*image);
1071 if (*option == '+')
1072 {
1073 /*
1074 Remove a mask.
1075 */
cristy018f07f2011-09-04 21:15:19 +00001076 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001077 break;
1078 }
1079 /*
1080 Set the image mask.
1081 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1082 */
1083 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1084 if (mask_image == (Image *) NULL)
1085 break;
cristy574cc262011-08-05 01:23:58 +00001086 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001087 return(MagickFalse);
1088 mask_view=AcquireCacheView(mask_image);
1089 for (y=0; y < (ssize_t) mask_image->rows; y++)
1090 {
1091 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1092 exception);
cristyacd2ed22011-08-30 01:44:23 +00001093 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001094 break;
1095 for (x=0; x < (ssize_t) mask_image->columns; x++)
1096 {
1097 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001098 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1099 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1100 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1101 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001102 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001103 }
1104 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1105 break;
1106 }
1107 mask_view=DestroyCacheView(mask_view);
1108 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001109 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001110 InheritException(exception,&(*image)->exception);
1111 break;
1112 }
1113 if (LocaleCompare("clip-path",option+1) == 0)
1114 {
1115 (void) SyncImageSettings(mogrify_info,*image);
1116 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001117 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001118 break;
1119 }
1120 if (LocaleCompare("colorize",option+1) == 0)
1121 {
1122 /*
1123 Colorize the image.
1124 */
1125 (void) SyncImageSettings(mogrify_info,*image);
1126 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1127 exception);
1128 break;
1129 }
1130 if (LocaleCompare("color-matrix",option+1) == 0)
1131 {
1132 KernelInfo
1133 *kernel;
1134
1135 (void) SyncImageSettings(mogrify_info,*image);
1136 kernel=AcquireKernelInfo(argv[i+1]);
1137 if (kernel == (KernelInfo *) NULL)
1138 break;
1139 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1140 kernel=DestroyKernelInfo(kernel);
1141 break;
1142 }
1143 if (LocaleCompare("colors",option+1) == 0)
1144 {
1145 /*
1146 Reduce the number of colors in the image.
1147 */
1148 (void) SyncImageSettings(mogrify_info,*image);
1149 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1150 if (quantize_info->number_colors == 0)
1151 break;
1152 if (((*image)->storage_class == DirectClass) ||
1153 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001154 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001155 else
cristy018f07f2011-09-04 21:15:19 +00001156 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001157 break;
1158 }
1159 if (LocaleCompare("colorspace",option+1) == 0)
1160 {
1161 ColorspaceType
1162 colorspace;
1163
1164 (void) SyncImageSettings(mogrify_info,*image);
1165 if (*option == '+')
1166 {
1167 (void) TransformImageColorspace(*image,RGBColorspace);
1168 InheritException(exception,&(*image)->exception);
1169 break;
1170 }
1171 colorspace=(ColorspaceType) ParseCommandOption(
1172 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1173 (void) TransformImageColorspace(*image,colorspace);
1174 InheritException(exception,&(*image)->exception);
1175 break;
1176 }
cristy633f0c62011-09-15 13:27:36 +00001177 if (LocaleCompare("compose",option+1) == 0)
1178 {
1179 (void) SyncImageSettings(mogrify_info,*image);
1180 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1181 MagickFalse,argv[i+1]);
1182 break;
1183 }
anthonydf8ebac2011-04-27 09:03:19 +00001184 if (LocaleCompare("contrast",option+1) == 0)
1185 {
1186 (void) SyncImageSettings(mogrify_info,*image);
1187 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001188 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001189 break;
1190 }
1191 if (LocaleCompare("contrast-stretch",option+1) == 0)
1192 {
1193 double
1194 black_point,
1195 white_point;
1196
1197 MagickStatusType
1198 flags;
1199
1200 /*
1201 Contrast stretch image.
1202 */
1203 (void) SyncImageSettings(mogrify_info,*image);
1204 flags=ParseGeometry(argv[i+1],&geometry_info);
1205 black_point=geometry_info.rho;
1206 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1207 black_point;
1208 if ((flags & PercentValue) != 0)
1209 {
1210 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1211 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1212 }
1213 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1214 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001215 (void) ContrastStretchImage(*image,black_point,white_point,
1216 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001217 InheritException(exception,&(*image)->exception);
1218 break;
1219 }
1220 if (LocaleCompare("convolve",option+1) == 0)
1221 {
anthonydf8ebac2011-04-27 09:03:19 +00001222 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001223 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001224
anthonydf8ebac2011-04-27 09:03:19 +00001225 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001226 kernel_info=AcquireKernelInfo(argv[i+1]);
1227 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001228 break;
cristy0a922382011-07-16 15:30:34 +00001229 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001230 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001231 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001232 break;
1233 }
1234 if (LocaleCompare("crop",option+1) == 0)
1235 {
1236 /*
1237 Crop a image to a smaller size
1238 */
1239 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001240 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001241 break;
1242 }
1243 if (LocaleCompare("cycle",option+1) == 0)
1244 {
1245 /*
1246 Cycle an image colormap.
1247 */
1248 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00001249 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1250 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001251 break;
1252 }
1253 break;
1254 }
1255 case 'd':
1256 {
1257 if (LocaleCompare("decipher",option+1) == 0)
1258 {
1259 StringInfo
1260 *passkey;
1261
1262 /*
1263 Decipher pixels.
1264 */
1265 (void) SyncImageSettings(mogrify_info,*image);
1266 passkey=FileToStringInfo(argv[i+1],~0,exception);
1267 if (passkey != (StringInfo *) NULL)
1268 {
1269 (void) PasskeyDecipherImage(*image,passkey,exception);
1270 passkey=DestroyStringInfo(passkey);
1271 }
1272 break;
1273 }
1274 if (LocaleCompare("density",option+1) == 0)
1275 {
1276 /*
1277 Set image density.
1278 */
1279 (void) CloneString(&draw_info->density,argv[i+1]);
1280 break;
1281 }
1282 if (LocaleCompare("depth",option+1) == 0)
1283 {
1284 (void) SyncImageSettings(mogrify_info,*image);
1285 if (*option == '+')
1286 {
1287 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1288 break;
1289 }
1290 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1291 break;
1292 }
1293 if (LocaleCompare("deskew",option+1) == 0)
1294 {
1295 double
1296 threshold;
1297
1298 /*
1299 Straighten the image.
1300 */
1301 (void) SyncImageSettings(mogrify_info,*image);
1302 if (*option == '+')
1303 threshold=40.0*QuantumRange/100.0;
1304 else
1305 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1306 mogrify_image=DeskewImage(*image,threshold,exception);
1307 break;
1308 }
1309 if (LocaleCompare("despeckle",option+1) == 0)
1310 {
1311 /*
1312 Reduce the speckles within an image.
1313 */
1314 (void) SyncImageSettings(mogrify_info,*image);
1315 mogrify_image=DespeckleImage(*image,exception);
1316 break;
1317 }
1318 if (LocaleCompare("display",option+1) == 0)
1319 {
1320 (void) CloneString(&draw_info->server_name,argv[i+1]);
1321 break;
1322 }
1323 if (LocaleCompare("distort",option+1) == 0)
1324 {
1325 char
1326 *args,
1327 token[MaxTextExtent];
1328
1329 const char
1330 *p;
1331
1332 DistortImageMethod
1333 method;
1334
1335 double
1336 *arguments;
1337
1338 register ssize_t
1339 x;
1340
1341 size_t
1342 number_arguments;
1343
1344 /*
1345 Distort image.
1346 */
1347 (void) SyncImageSettings(mogrify_info,*image);
1348 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1349 MagickFalse,argv[i+1]);
1350 if ( method == ResizeDistortion )
1351 {
1352 /* Special Case - Argument is actually a resize geometry!
1353 ** Convert that to an appropriate distortion argument array.
1354 */
1355 double
1356 resize_args[2];
1357 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1358 exception);
1359 resize_args[0]=(double)geometry.width;
1360 resize_args[1]=(double)geometry.height;
1361 mogrify_image=DistortImage(*image,method,(size_t)2,
1362 resize_args,MagickTrue,exception);
1363 break;
1364 }
cristy018f07f2011-09-04 21:15:19 +00001365 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1366 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001367 if (args == (char *) NULL)
1368 break;
1369 p=(char *) args;
1370 for (x=0; *p != '\0'; x++)
1371 {
1372 GetMagickToken(p,&p,token);
1373 if (*token == ',')
1374 GetMagickToken(p,&p,token);
1375 }
1376 number_arguments=(size_t) x;
1377 arguments=(double *) AcquireQuantumMemory(number_arguments,
1378 sizeof(*arguments));
1379 if (arguments == (double *) NULL)
1380 ThrowWandFatalException(ResourceLimitFatalError,
1381 "MemoryAllocationFailed",(*image)->filename);
1382 (void) ResetMagickMemory(arguments,0,number_arguments*
1383 sizeof(*arguments));
1384 p=(char *) args;
1385 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1386 {
1387 GetMagickToken(p,&p,token);
1388 if (*token == ',')
1389 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001390 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001391 }
1392 args=DestroyString(args);
1393 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1394 (*option == '+') ? MagickTrue : MagickFalse,exception);
1395 arguments=(double *) RelinquishMagickMemory(arguments);
1396 break;
1397 }
1398 if (LocaleCompare("dither",option+1) == 0)
1399 {
1400 if (*option == '+')
1401 {
1402 quantize_info->dither=MagickFalse;
1403 break;
1404 }
1405 quantize_info->dither=MagickTrue;
1406 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1407 MagickDitherOptions,MagickFalse,argv[i+1]);
1408 if (quantize_info->dither_method == NoDitherMethod)
1409 quantize_info->dither=MagickFalse;
1410 break;
1411 }
1412 if (LocaleCompare("draw",option+1) == 0)
1413 {
1414 /*
1415 Draw image.
1416 */
1417 (void) SyncImageSettings(mogrify_info,*image);
1418 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001419 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001420 break;
1421 }
1422 break;
1423 }
1424 case 'e':
1425 {
1426 if (LocaleCompare("edge",option+1) == 0)
1427 {
1428 /*
1429 Enhance edges in the image.
1430 */
1431 (void) SyncImageSettings(mogrify_info,*image);
1432 flags=ParseGeometry(argv[i+1],&geometry_info);
1433 if ((flags & SigmaValue) == 0)
1434 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001435 mogrify_image=EdgeImage(*image,geometry_info.rho,
1436 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001437 break;
1438 }
1439 if (LocaleCompare("emboss",option+1) == 0)
1440 {
1441 /*
1442 Gaussian embossen image.
1443 */
1444 (void) SyncImageSettings(mogrify_info,*image);
1445 flags=ParseGeometry(argv[i+1],&geometry_info);
1446 if ((flags & SigmaValue) == 0)
1447 geometry_info.sigma=1.0;
1448 mogrify_image=EmbossImage(*image,geometry_info.rho,
1449 geometry_info.sigma,exception);
1450 break;
1451 }
1452 if (LocaleCompare("encipher",option+1) == 0)
1453 {
1454 StringInfo
1455 *passkey;
1456
1457 /*
1458 Encipher pixels.
1459 */
1460 (void) SyncImageSettings(mogrify_info,*image);
1461 passkey=FileToStringInfo(argv[i+1],~0,exception);
1462 if (passkey != (StringInfo *) NULL)
1463 {
1464 (void) PasskeyEncipherImage(*image,passkey,exception);
1465 passkey=DestroyStringInfo(passkey);
1466 }
1467 break;
1468 }
1469 if (LocaleCompare("encoding",option+1) == 0)
1470 {
1471 (void) CloneString(&draw_info->encoding,argv[i+1]);
1472 break;
1473 }
1474 if (LocaleCompare("enhance",option+1) == 0)
1475 {
1476 /*
1477 Enhance image.
1478 */
1479 (void) SyncImageSettings(mogrify_info,*image);
1480 mogrify_image=EnhanceImage(*image,exception);
1481 break;
1482 }
1483 if (LocaleCompare("equalize",option+1) == 0)
1484 {
1485 /*
1486 Equalize image.
1487 */
1488 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001489 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001490 break;
1491 }
1492 if (LocaleCompare("evaluate",option+1) == 0)
1493 {
1494 double
1495 constant;
1496
1497 MagickEvaluateOperator
1498 op;
1499
1500 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001501 op=(MagickEvaluateOperator) ParseCommandOption(
1502 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001503 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001504 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001505 break;
1506 }
1507 if (LocaleCompare("extent",option+1) == 0)
1508 {
1509 /*
1510 Set the image extent.
1511 */
1512 (void) SyncImageSettings(mogrify_info,*image);
1513 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1514 if (geometry.width == 0)
1515 geometry.width=(*image)->columns;
1516 if (geometry.height == 0)
1517 geometry.height=(*image)->rows;
1518 mogrify_image=ExtentImage(*image,&geometry,exception);
1519 break;
1520 }
1521 break;
1522 }
1523 case 'f':
1524 {
1525 if (LocaleCompare("family",option+1) == 0)
1526 {
1527 if (*option == '+')
1528 {
1529 if (draw_info->family != (char *) NULL)
1530 draw_info->family=DestroyString(draw_info->family);
1531 break;
1532 }
1533 (void) CloneString(&draw_info->family,argv[i+1]);
1534 break;
1535 }
1536 if (LocaleCompare("features",option+1) == 0)
1537 {
1538 if (*option == '+')
1539 {
1540 (void) DeleteImageArtifact(*image,"identify:features");
1541 break;
1542 }
1543 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1544 break;
1545 }
1546 if (LocaleCompare("fill",option+1) == 0)
1547 {
1548 ExceptionInfo
1549 *sans;
1550
cristy4c08aed2011-07-01 19:47:50 +00001551 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001552 if (*option == '+')
1553 {
1554 (void) QueryMagickColor("none",&fill,exception);
1555 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1556 if (draw_info->fill_pattern != (Image *) NULL)
1557 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1558 break;
1559 }
1560 sans=AcquireExceptionInfo();
1561 (void) QueryMagickColor(argv[i+1],&fill,sans);
1562 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1563 sans=DestroyExceptionInfo(sans);
1564 if (status == MagickFalse)
1565 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1566 exception);
1567 break;
1568 }
1569 if (LocaleCompare("flip",option+1) == 0)
1570 {
1571 /*
1572 Flip image scanlines.
1573 */
1574 (void) SyncImageSettings(mogrify_info,*image);
1575 mogrify_image=FlipImage(*image,exception);
1576 break;
1577 }
anthonydf8ebac2011-04-27 09:03:19 +00001578 if (LocaleCompare("floodfill",option+1) == 0)
1579 {
cristy4c08aed2011-07-01 19:47:50 +00001580 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001581 target;
1582
1583 /*
1584 Floodfill image.
1585 */
1586 (void) SyncImageSettings(mogrify_info,*image);
1587 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1588 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001589 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001590 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001591 break;
1592 }
anthony3d2f4862011-05-01 13:48:16 +00001593 if (LocaleCompare("flop",option+1) == 0)
1594 {
1595 /*
1596 Flop image scanlines.
1597 */
1598 (void) SyncImageSettings(mogrify_info,*image);
1599 mogrify_image=FlopImage(*image,exception);
1600 break;
1601 }
anthonydf8ebac2011-04-27 09:03:19 +00001602 if (LocaleCompare("font",option+1) == 0)
1603 {
1604 if (*option == '+')
1605 {
1606 if (draw_info->font != (char *) NULL)
1607 draw_info->font=DestroyString(draw_info->font);
1608 break;
1609 }
1610 (void) CloneString(&draw_info->font,argv[i+1]);
1611 break;
1612 }
1613 if (LocaleCompare("format",option+1) == 0)
1614 {
1615 format=argv[i+1];
1616 break;
1617 }
1618 if (LocaleCompare("frame",option+1) == 0)
1619 {
1620 FrameInfo
1621 frame_info;
1622
1623 /*
1624 Surround image with an ornamental border.
1625 */
1626 (void) SyncImageSettings(mogrify_info,*image);
1627 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1628 frame_info.width=geometry.width;
1629 frame_info.height=geometry.height;
1630 if ((flags & HeightValue) == 0)
1631 frame_info.height=geometry.width;
1632 frame_info.outer_bevel=geometry.x;
1633 frame_info.inner_bevel=geometry.y;
1634 frame_info.x=(ssize_t) frame_info.width;
1635 frame_info.y=(ssize_t) frame_info.height;
1636 frame_info.width=(*image)->columns+2*frame_info.width;
1637 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001638 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001639 break;
1640 }
1641 if (LocaleCompare("function",option+1) == 0)
1642 {
1643 char
1644 *arguments,
1645 token[MaxTextExtent];
1646
1647 const char
1648 *p;
1649
1650 double
1651 *parameters;
1652
1653 MagickFunction
1654 function;
1655
1656 register ssize_t
1657 x;
1658
1659 size_t
1660 number_parameters;
1661
1662 /*
1663 Function Modify Image Values
1664 */
1665 (void) SyncImageSettings(mogrify_info,*image);
1666 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1667 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001668 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1669 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001670 if (arguments == (char *) NULL)
1671 break;
1672 p=(char *) arguments;
1673 for (x=0; *p != '\0'; x++)
1674 {
1675 GetMagickToken(p,&p,token);
1676 if (*token == ',')
1677 GetMagickToken(p,&p,token);
1678 }
1679 number_parameters=(size_t) x;
1680 parameters=(double *) AcquireQuantumMemory(number_parameters,
1681 sizeof(*parameters));
1682 if (parameters == (double *) NULL)
1683 ThrowWandFatalException(ResourceLimitFatalError,
1684 "MemoryAllocationFailed",(*image)->filename);
1685 (void) ResetMagickMemory(parameters,0,number_parameters*
1686 sizeof(*parameters));
1687 p=(char *) arguments;
1688 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1689 {
1690 GetMagickToken(p,&p,token);
1691 if (*token == ',')
1692 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001693 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001694 }
1695 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001696 (void) FunctionImage(*image,function,number_parameters,parameters,
1697 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001698 parameters=(double *) RelinquishMagickMemory(parameters);
1699 break;
1700 }
1701 break;
1702 }
1703 case 'g':
1704 {
1705 if (LocaleCompare("gamma",option+1) == 0)
1706 {
1707 /*
1708 Gamma image.
1709 */
1710 (void) SyncImageSettings(mogrify_info,*image);
1711 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001712 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001713 else
cristyb3e7c6c2011-07-24 01:43:55 +00001714 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1715 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001716 break;
1717 }
1718 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1719 (LocaleCompare("gaussian",option+1) == 0))
1720 {
1721 /*
1722 Gaussian blur image.
1723 */
1724 (void) SyncImageSettings(mogrify_info,*image);
1725 flags=ParseGeometry(argv[i+1],&geometry_info);
1726 if ((flags & SigmaValue) == 0)
1727 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001728 if ((flags & XiValue) == 0)
1729 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001730 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001731 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001732 break;
1733 }
1734 if (LocaleCompare("geometry",option+1) == 0)
1735 {
1736 /*
1737 Record Image offset, Resize last image.
1738 */
1739 (void) SyncImageSettings(mogrify_info,*image);
1740 if (*option == '+')
1741 {
1742 if ((*image)->geometry != (char *) NULL)
1743 (*image)->geometry=DestroyString((*image)->geometry);
1744 break;
1745 }
1746 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1747 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1748 (void) CloneString(&(*image)->geometry,argv[i+1]);
1749 else
1750 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1751 (*image)->filter,(*image)->blur,exception);
1752 break;
1753 }
1754 if (LocaleCompare("gravity",option+1) == 0)
1755 {
1756 if (*option == '+')
1757 {
1758 draw_info->gravity=UndefinedGravity;
1759 break;
1760 }
1761 draw_info->gravity=(GravityType) ParseCommandOption(
1762 MagickGravityOptions,MagickFalse,argv[i+1]);
1763 break;
1764 }
1765 break;
1766 }
1767 case 'h':
1768 {
1769 if (LocaleCompare("highlight-color",option+1) == 0)
1770 {
1771 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1772 break;
1773 }
1774 break;
1775 }
1776 case 'i':
1777 {
1778 if (LocaleCompare("identify",option+1) == 0)
1779 {
1780 char
1781 *text;
1782
1783 (void) SyncImageSettings(mogrify_info,*image);
1784 if (format == (char *) NULL)
1785 {
cristya4037272011-08-28 15:11:39 +00001786 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1787 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001788 break;
1789 }
cristy018f07f2011-09-04 21:15:19 +00001790 text=InterpretImageProperties(mogrify_info,*image,format,
1791 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001792 if (text == (char *) NULL)
1793 break;
1794 (void) fputs(text,stdout);
1795 (void) fputc('\n',stdout);
1796 text=DestroyString(text);
1797 break;
1798 }
1799 if (LocaleCompare("implode",option+1) == 0)
1800 {
1801 /*
1802 Implode image.
1803 */
1804 (void) SyncImageSettings(mogrify_info,*image);
1805 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001806 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1807 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001808 break;
1809 }
1810 if (LocaleCompare("interline-spacing",option+1) == 0)
1811 {
1812 if (*option == '+')
1813 (void) ParseGeometry("0",&geometry_info);
1814 else
1815 (void) ParseGeometry(argv[i+1],&geometry_info);
1816 draw_info->interline_spacing=geometry_info.rho;
1817 break;
1818 }
cristy28474bf2011-09-11 23:32:52 +00001819 if (LocaleCompare("interpolate",option+1) == 0)
1820 {
1821 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1822 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1823 break;
1824 }
anthonydf8ebac2011-04-27 09:03:19 +00001825 if (LocaleCompare("interword-spacing",option+1) == 0)
1826 {
1827 if (*option == '+')
1828 (void) ParseGeometry("0",&geometry_info);
1829 else
1830 (void) ParseGeometry(argv[i+1],&geometry_info);
1831 draw_info->interword_spacing=geometry_info.rho;
1832 break;
1833 }
1834 break;
1835 }
1836 case 'k':
1837 {
1838 if (LocaleCompare("kerning",option+1) == 0)
1839 {
1840 if (*option == '+')
1841 (void) ParseGeometry("0",&geometry_info);
1842 else
1843 (void) ParseGeometry(argv[i+1],&geometry_info);
1844 draw_info->kerning=geometry_info.rho;
1845 break;
1846 }
1847 break;
1848 }
1849 case 'l':
1850 {
1851 if (LocaleCompare("lat",option+1) == 0)
1852 {
1853 /*
1854 Local adaptive threshold image.
1855 */
1856 (void) SyncImageSettings(mogrify_info,*image);
1857 flags=ParseGeometry(argv[i+1],&geometry_info);
1858 if ((flags & PercentValue) != 0)
1859 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1860 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001861 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001862 geometry_info.xi,exception);
1863 break;
1864 }
1865 if (LocaleCompare("level",option+1) == 0)
1866 {
1867 MagickRealType
1868 black_point,
1869 gamma,
1870 white_point;
1871
1872 MagickStatusType
1873 flags;
1874
1875 /*
1876 Parse levels.
1877 */
1878 (void) SyncImageSettings(mogrify_info,*image);
1879 flags=ParseGeometry(argv[i+1],&geometry_info);
1880 black_point=geometry_info.rho;
1881 white_point=(MagickRealType) QuantumRange;
1882 if ((flags & SigmaValue) != 0)
1883 white_point=geometry_info.sigma;
1884 gamma=1.0;
1885 if ((flags & XiValue) != 0)
1886 gamma=geometry_info.xi;
1887 if ((flags & PercentValue) != 0)
1888 {
1889 black_point*=(MagickRealType) (QuantumRange/100.0);
1890 white_point*=(MagickRealType) (QuantumRange/100.0);
1891 }
1892 if ((flags & SigmaValue) == 0)
1893 white_point=(MagickRealType) QuantumRange-black_point;
1894 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001895 (void) LevelizeImage(*image,black_point,white_point,gamma,
1896 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001897 else
cristy01e9afd2011-08-10 17:38:41 +00001898 (void) LevelImage(*image,black_point,white_point,gamma,
1899 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001900 InheritException(exception,&(*image)->exception);
1901 break;
1902 }
1903 if (LocaleCompare("level-colors",option+1) == 0)
1904 {
1905 char
1906 token[MaxTextExtent];
1907
1908 const char
1909 *p;
1910
cristy4c08aed2011-07-01 19:47:50 +00001911 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001912 black_point,
1913 white_point;
1914
1915 p=(const char *) argv[i+1];
1916 GetMagickToken(p,&p,token); /* get black point color */
1917 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1918 (void) QueryMagickColor(token,&black_point,exception);
1919 else
1920 (void) QueryMagickColor("#000000",&black_point,exception);
1921 if (isalpha((int) token[0]) || (token[0] == '#'))
1922 GetMagickToken(p,&p,token);
1923 if (*token == '\0')
1924 white_point=black_point; /* set everything to that color */
1925 else
1926 {
1927 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1928 GetMagickToken(p,&p,token); /* Get white point color. */
1929 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1930 (void) QueryMagickColor(token,&white_point,exception);
1931 else
1932 (void) QueryMagickColor("#ffffff",&white_point,exception);
1933 }
cristy490408a2011-07-07 14:42:05 +00001934 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001935 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001936 break;
1937 }
1938 if (LocaleCompare("linear-stretch",option+1) == 0)
1939 {
1940 double
1941 black_point,
1942 white_point;
1943
1944 MagickStatusType
1945 flags;
1946
1947 (void) SyncImageSettings(mogrify_info,*image);
1948 flags=ParseGeometry(argv[i+1],&geometry_info);
1949 black_point=geometry_info.rho;
1950 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1951 if ((flags & SigmaValue) != 0)
1952 white_point=geometry_info.sigma;
1953 if ((flags & PercentValue) != 0)
1954 {
1955 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1956 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1957 }
1958 if ((flags & SigmaValue) == 0)
1959 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1960 black_point;
cristy33bd5152011-08-24 01:42:24 +00001961 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001962 InheritException(exception,&(*image)->exception);
1963 break;
1964 }
1965 if (LocaleCompare("linewidth",option+1) == 0)
1966 {
cristyc1acd842011-05-19 23:05:47 +00001967 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1968 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001969 break;
1970 }
1971 if (LocaleCompare("liquid-rescale",option+1) == 0)
1972 {
1973 /*
1974 Liquid rescale image.
1975 */
1976 (void) SyncImageSettings(mogrify_info,*image);
1977 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1978 if ((flags & XValue) == 0)
1979 geometry.x=1;
1980 if ((flags & YValue) == 0)
1981 geometry.y=0;
1982 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1983 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1984 break;
1985 }
1986 if (LocaleCompare("lowlight-color",option+1) == 0)
1987 {
1988 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1989 break;
1990 }
1991 break;
1992 }
1993 case 'm':
1994 {
1995 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001996 {
cristy3ed852e2009-09-05 21:47:34 +00001997 Image
anthonydf8ebac2011-04-27 09:03:19 +00001998 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001999
anthonydf8ebac2011-04-27 09:03:19 +00002000 /*
2001 Transform image colors to match this set of colors.
2002 */
2003 (void) SyncImageSettings(mogrify_info,*image);
2004 if (*option == '+')
2005 break;
2006 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2007 if (remap_image == (Image *) NULL)
2008 break;
cristy018f07f2011-09-04 21:15:19 +00002009 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002010 remap_image=DestroyImage(remap_image);
2011 break;
2012 }
2013 if (LocaleCompare("mask",option+1) == 0)
2014 {
2015 Image
2016 *mask;
2017
2018 (void) SyncImageSettings(mogrify_info,*image);
2019 if (*option == '+')
2020 {
2021 /*
2022 Remove a mask.
2023 */
cristy018f07f2011-09-04 21:15:19 +00002024 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002025 break;
2026 }
2027 /*
2028 Set the image mask.
2029 */
2030 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2031 if (mask == (Image *) NULL)
2032 break;
cristy018f07f2011-09-04 21:15:19 +00002033 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002034 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002035 break;
2036 }
2037 if (LocaleCompare("matte",option+1) == 0)
2038 {
2039 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002040 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002041 break;
2042 }
2043 if (LocaleCompare("median",option+1) == 0)
2044 {
2045 /*
2046 Median filter image.
2047 */
2048 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002049 flags=ParseGeometry(argv[i+1],&geometry_info);
2050 if ((flags & SigmaValue) == 0)
2051 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002052 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002053 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002054 break;
2055 }
2056 if (LocaleCompare("mode",option+1) == 0)
2057 {
2058 /*
2059 Mode image.
2060 */
2061 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002062 flags=ParseGeometry(argv[i+1],&geometry_info);
2063 if ((flags & SigmaValue) == 0)
2064 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002065 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002066 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002067 break;
2068 }
2069 if (LocaleCompare("modulate",option+1) == 0)
2070 {
2071 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002072 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002073 break;
2074 }
2075 if (LocaleCompare("monitor",option+1) == 0)
2076 {
2077 if (*option == '+')
2078 {
2079 (void) SetImageProgressMonitor(*image,
2080 (MagickProgressMonitor) NULL,(void *) NULL);
2081 break;
2082 }
2083 (void) SetImageProgressMonitor(*image,MonitorProgress,
2084 (void *) NULL);
2085 break;
2086 }
2087 if (LocaleCompare("monochrome",option+1) == 0)
2088 {
2089 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00002090 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002091 break;
2092 }
2093 if (LocaleCompare("morphology",option+1) == 0)
2094 {
2095 char
2096 token[MaxTextExtent];
2097
2098 const char
2099 *p;
2100
2101 KernelInfo
2102 *kernel;
2103
2104 MorphologyMethod
2105 method;
2106
2107 ssize_t
2108 iterations;
2109
2110 /*
2111 Morphological Image Operation
2112 */
2113 (void) SyncImageSettings(mogrify_info,*image);
2114 p=argv[i+1];
2115 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002116 method=(MorphologyMethod) ParseCommandOption(
2117 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002118 iterations=1L;
2119 GetMagickToken(p,&p,token);
2120 if ((*p == ':') || (*p == ','))
2121 GetMagickToken(p,&p,token);
2122 if ((*p != '\0'))
2123 iterations=(ssize_t) StringToLong(p);
2124 kernel=AcquireKernelInfo(argv[i+2]);
2125 if (kernel == (KernelInfo *) NULL)
2126 {
2127 (void) ThrowMagickException(exception,GetMagickModule(),
2128 OptionError,"UnabletoParseKernel","morphology");
2129 status=MagickFalse;
2130 break;
2131 }
cristyf4ad9df2011-07-08 16:49:03 +00002132 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2133 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002134 kernel=DestroyKernelInfo(kernel);
2135 break;
2136 }
2137 if (LocaleCompare("motion-blur",option+1) == 0)
2138 {
2139 /*
2140 Motion blur image.
2141 */
2142 (void) SyncImageSettings(mogrify_info,*image);
2143 flags=ParseGeometry(argv[i+1],&geometry_info);
2144 if ((flags & SigmaValue) == 0)
2145 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002146 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002147 geometry_info.sigma,geometry_info.xi,geometry_info.psi,
2148 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002149 break;
2150 }
2151 break;
2152 }
2153 case 'n':
2154 {
2155 if (LocaleCompare("negate",option+1) == 0)
2156 {
2157 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002158 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002159 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002160 break;
2161 }
2162 if (LocaleCompare("noise",option+1) == 0)
2163 {
2164 (void) SyncImageSettings(mogrify_info,*image);
2165 if (*option == '-')
2166 {
cristyf36cbcb2011-09-07 13:28:22 +00002167 flags=ParseGeometry(argv[i+1],&geometry_info);
2168 if ((flags & SigmaValue) == 0)
2169 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002170 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002171 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002172 }
2173 else
2174 {
2175 NoiseType
2176 noise;
2177
2178 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2179 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002180 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002181 }
2182 break;
2183 }
2184 if (LocaleCompare("normalize",option+1) == 0)
2185 {
2186 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002187 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002188 break;
2189 }
2190 break;
2191 }
2192 case 'o':
2193 {
2194 if (LocaleCompare("opaque",option+1) == 0)
2195 {
cristy4c08aed2011-07-01 19:47:50 +00002196 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002197 target;
2198
2199 (void) SyncImageSettings(mogrify_info,*image);
2200 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002201 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002202 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002203 break;
2204 }
2205 if (LocaleCompare("ordered-dither",option+1) == 0)
2206 {
2207 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002208 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002209 break;
2210 }
2211 break;
2212 }
2213 case 'p':
2214 {
2215 if (LocaleCompare("paint",option+1) == 0)
2216 {
anthonydf8ebac2011-04-27 09:03:19 +00002217 (void) SyncImageSettings(mogrify_info,*image);
2218 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002219 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2220 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002221 break;
2222 }
2223 if (LocaleCompare("pen",option+1) == 0)
2224 {
2225 if (*option == '+')
2226 {
2227 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2228 break;
2229 }
2230 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2231 break;
2232 }
2233 if (LocaleCompare("pointsize",option+1) == 0)
2234 {
2235 if (*option == '+')
2236 (void) ParseGeometry("12",&geometry_info);
2237 else
2238 (void) ParseGeometry(argv[i+1],&geometry_info);
2239 draw_info->pointsize=geometry_info.rho;
2240 break;
2241 }
2242 if (LocaleCompare("polaroid",option+1) == 0)
2243 {
2244 double
2245 angle;
2246
2247 RandomInfo
2248 *random_info;
2249
2250 /*
2251 Simulate a Polaroid picture.
2252 */
2253 (void) SyncImageSettings(mogrify_info,*image);
2254 random_info=AcquireRandomInfo();
2255 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2256 random_info=DestroyRandomInfo(random_info);
2257 if (*option == '-')
2258 {
2259 SetGeometryInfo(&geometry_info);
2260 flags=ParseGeometry(argv[i+1],&geometry_info);
2261 angle=geometry_info.rho;
2262 }
cristy5c4e2582011-09-11 19:21:03 +00002263 mogrify_image=PolaroidImage(*image,draw_info,angle,
cristy28474bf2011-09-11 23:32:52 +00002264 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002265 break;
2266 }
2267 if (LocaleCompare("posterize",option+1) == 0)
2268 {
2269 /*
2270 Posterize image.
2271 */
2272 (void) SyncImageSettings(mogrify_info,*image);
2273 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002274 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002275 break;
2276 }
2277 if (LocaleCompare("preview",option+1) == 0)
2278 {
2279 PreviewType
2280 preview_type;
2281
2282 /*
2283 Preview image.
2284 */
2285 (void) SyncImageSettings(mogrify_info,*image);
2286 if (*option == '+')
2287 preview_type=UndefinedPreview;
2288 else
cristy28474bf2011-09-11 23:32:52 +00002289 preview_type=(PreviewType) ParseCommandOption(
2290 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002291 mogrify_image=PreviewImage(*image,preview_type,exception);
2292 break;
2293 }
2294 if (LocaleCompare("profile",option+1) == 0)
2295 {
2296 const char
2297 *name;
2298
2299 const StringInfo
2300 *profile;
2301
2302 Image
2303 *profile_image;
2304
2305 ImageInfo
2306 *profile_info;
2307
2308 (void) SyncImageSettings(mogrify_info,*image);
2309 if (*option == '+')
2310 {
2311 /*
2312 Remove a profile from the image.
2313 */
2314 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2315 NULL,0,MagickTrue);
2316 InheritException(exception,&(*image)->exception);
2317 break;
2318 }
2319 /*
2320 Associate a profile with the image.
2321 */
2322 profile_info=CloneImageInfo(mogrify_info);
2323 profile=GetImageProfile(*image,"iptc");
2324 if (profile != (StringInfo *) NULL)
2325 profile_info->profile=(void *) CloneStringInfo(profile);
2326 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2327 profile_info=DestroyImageInfo(profile_info);
2328 if (profile_image == (Image *) NULL)
2329 {
2330 StringInfo
2331 *profile;
2332
2333 profile_info=CloneImageInfo(mogrify_info);
2334 (void) CopyMagickString(profile_info->filename,argv[i+1],
2335 MaxTextExtent);
2336 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2337 if (profile != (StringInfo *) NULL)
2338 {
2339 (void) ProfileImage(*image,profile_info->magick,
2340 GetStringInfoDatum(profile),(size_t)
2341 GetStringInfoLength(profile),MagickFalse);
2342 profile=DestroyStringInfo(profile);
2343 }
2344 profile_info=DestroyImageInfo(profile_info);
2345 break;
2346 }
2347 ResetImageProfileIterator(profile_image);
2348 name=GetNextImageProfile(profile_image);
2349 while (name != (const char *) NULL)
2350 {
2351 profile=GetImageProfile(profile_image,name);
2352 if (profile != (StringInfo *) NULL)
2353 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2354 (size_t) GetStringInfoLength(profile),MagickFalse);
2355 name=GetNextImageProfile(profile_image);
2356 }
2357 profile_image=DestroyImage(profile_image);
2358 break;
2359 }
2360 break;
2361 }
2362 case 'q':
2363 {
2364 if (LocaleCompare("quantize",option+1) == 0)
2365 {
2366 if (*option == '+')
2367 {
2368 quantize_info->colorspace=UndefinedColorspace;
2369 break;
2370 }
2371 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2372 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2373 break;
2374 }
2375 break;
2376 }
2377 case 'r':
2378 {
2379 if (LocaleCompare("radial-blur",option+1) == 0)
2380 {
2381 /*
2382 Radial blur image.
2383 */
2384 (void) SyncImageSettings(mogrify_info,*image);
cristy6435bd92011-09-10 02:10:07 +00002385 flags=ParseGeometry(argv[i+1],&geometry_info);
2386 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2387 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002388 break;
2389 }
2390 if (LocaleCompare("raise",option+1) == 0)
2391 {
2392 /*
2393 Surround image with a raise of solid color.
2394 */
2395 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2396 if ((flags & SigmaValue) == 0)
2397 geometry.height=geometry.width;
2398 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002399 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002400 break;
2401 }
2402 if (LocaleCompare("random-threshold",option+1) == 0)
2403 {
2404 /*
2405 Threshold image.
2406 */
2407 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002408 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002409 break;
2410 }
2411 if (LocaleCompare("recolor",option+1) == 0)
2412 {
2413 KernelInfo
2414 *kernel;
2415
2416 (void) SyncImageSettings(mogrify_info,*image);
2417 kernel=AcquireKernelInfo(argv[i+1]);
2418 if (kernel == (KernelInfo *) NULL)
2419 break;
2420 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2421 kernel=DestroyKernelInfo(kernel);
2422 break;
2423 }
2424 if (LocaleCompare("region",option+1) == 0)
2425 {
2426 (void) SyncImageSettings(mogrify_info,*image);
2427 if (region_image != (Image *) NULL)
2428 {
2429 /*
2430 Composite region.
2431 */
2432 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002433 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2434 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002435 InheritException(exception,&region_image->exception);
2436 *image=DestroyImage(*image);
2437 *image=region_image;
2438 region_image = (Image *) NULL;
2439 }
2440 if (*option == '+')
2441 break;
2442 /*
2443 Apply transformations to a selected region of the image.
2444 */
cristy3ed852e2009-09-05 21:47:34 +00002445 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2446 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002447 mogrify_image=CropImage(*image,&region_geometry,exception);
2448 if (mogrify_image == (Image *) NULL)
2449 break;
2450 region_image=(*image);
2451 *image=mogrify_image;
2452 mogrify_image=(Image *) NULL;
2453 break;
cristy3ed852e2009-09-05 21:47:34 +00002454 }
anthonydf8ebac2011-04-27 09:03:19 +00002455 if (LocaleCompare("render",option+1) == 0)
2456 {
2457 (void) SyncImageSettings(mogrify_info,*image);
2458 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2459 break;
2460 }
2461 if (LocaleCompare("remap",option+1) == 0)
2462 {
2463 Image
2464 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002465
anthonydf8ebac2011-04-27 09:03:19 +00002466 /*
2467 Transform image colors to match this set of colors.
2468 */
2469 (void) SyncImageSettings(mogrify_info,*image);
2470 if (*option == '+')
2471 break;
2472 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2473 if (remap_image == (Image *) NULL)
2474 break;
cristy018f07f2011-09-04 21:15:19 +00002475 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002476 remap_image=DestroyImage(remap_image);
2477 break;
2478 }
2479 if (LocaleCompare("repage",option+1) == 0)
2480 {
2481 if (*option == '+')
2482 {
2483 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2484 break;
2485 }
2486 (void) ResetImagePage(*image,argv[i+1]);
2487 InheritException(exception,&(*image)->exception);
2488 break;
2489 }
2490 if (LocaleCompare("resample",option+1) == 0)
2491 {
2492 /*
2493 Resample image.
2494 */
2495 (void) SyncImageSettings(mogrify_info,*image);
2496 flags=ParseGeometry(argv[i+1],&geometry_info);
2497 if ((flags & SigmaValue) == 0)
2498 geometry_info.sigma=geometry_info.rho;
2499 mogrify_image=ResampleImage(*image,geometry_info.rho,
2500 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2501 break;
2502 }
2503 if (LocaleCompare("resize",option+1) == 0)
2504 {
2505 /*
2506 Resize image.
2507 */
2508 (void) SyncImageSettings(mogrify_info,*image);
2509 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2510 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2511 (*image)->filter,(*image)->blur,exception);
2512 break;
2513 }
2514 if (LocaleCompare("roll",option+1) == 0)
2515 {
2516 /*
2517 Roll image.
2518 */
2519 (void) SyncImageSettings(mogrify_info,*image);
2520 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2521 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2522 break;
2523 }
2524 if (LocaleCompare("rotate",option+1) == 0)
2525 {
2526 char
2527 *geometry;
2528
2529 /*
2530 Check for conditional image rotation.
2531 */
2532 (void) SyncImageSettings(mogrify_info,*image);
2533 if (strchr(argv[i+1],'>') != (char *) NULL)
2534 if ((*image)->columns <= (*image)->rows)
2535 break;
2536 if (strchr(argv[i+1],'<') != (char *) NULL)
2537 if ((*image)->columns >= (*image)->rows)
2538 break;
2539 /*
2540 Rotate image.
2541 */
2542 geometry=ConstantString(argv[i+1]);
2543 (void) SubstituteString(&geometry,">","");
2544 (void) SubstituteString(&geometry,"<","");
2545 (void) ParseGeometry(geometry,&geometry_info);
2546 geometry=DestroyString(geometry);
2547 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2548 break;
2549 }
2550 break;
2551 }
2552 case 's':
2553 {
2554 if (LocaleCompare("sample",option+1) == 0)
2555 {
2556 /*
2557 Sample image with pixel replication.
2558 */
2559 (void) SyncImageSettings(mogrify_info,*image);
2560 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2561 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2562 exception);
2563 break;
2564 }
2565 if (LocaleCompare("scale",option+1) == 0)
2566 {
2567 /*
2568 Resize image.
2569 */
2570 (void) SyncImageSettings(mogrify_info,*image);
2571 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2572 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2573 exception);
2574 break;
2575 }
2576 if (LocaleCompare("selective-blur",option+1) == 0)
2577 {
2578 /*
2579 Selectively blur pixels within a contrast threshold.
2580 */
2581 (void) SyncImageSettings(mogrify_info,*image);
2582 flags=ParseGeometry(argv[i+1],&geometry_info);
2583 if ((flags & PercentValue) != 0)
2584 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002585 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002586 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002587 break;
2588 }
2589 if (LocaleCompare("separate",option+1) == 0)
2590 {
2591 /*
2592 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002593 */
2594 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002595 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002596 break;
2597 }
2598 if (LocaleCompare("sepia-tone",option+1) == 0)
2599 {
2600 double
2601 threshold;
2602
2603 /*
2604 Sepia-tone image.
2605 */
2606 (void) SyncImageSettings(mogrify_info,*image);
2607 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2608 mogrify_image=SepiaToneImage(*image,threshold,exception);
2609 break;
2610 }
2611 if (LocaleCompare("segment",option+1) == 0)
2612 {
2613 /*
2614 Segment image.
2615 */
2616 (void) SyncImageSettings(mogrify_info,*image);
2617 flags=ParseGeometry(argv[i+1],&geometry_info);
2618 if ((flags & SigmaValue) == 0)
2619 geometry_info.sigma=1.0;
2620 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002621 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2622 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002623 break;
2624 }
2625 if (LocaleCompare("set",option+1) == 0)
2626 {
2627 char
2628 *value;
2629
2630 /*
2631 Set image option.
2632 */
2633 if (*option == '+')
2634 {
2635 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2636 (void) DeleteImageRegistry(argv[i+1]+9);
2637 else
2638 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2639 {
2640 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2641 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2642 }
2643 else
2644 (void) DeleteImageProperty(*image,argv[i+1]);
2645 break;
2646 }
cristy018f07f2011-09-04 21:15:19 +00002647 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2648 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002649 if (value == (char *) NULL)
2650 break;
2651 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2652 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2653 exception);
2654 else
2655 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2656 {
2657 (void) SetImageOption(image_info,argv[i+1]+7,value);
2658 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2659 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2660 }
2661 else
2662 (void) SetImageProperty(*image,argv[i+1],value);
2663 value=DestroyString(value);
2664 break;
2665 }
2666 if (LocaleCompare("shade",option+1) == 0)
2667 {
2668 /*
2669 Shade image.
2670 */
2671 (void) SyncImageSettings(mogrify_info,*image);
2672 flags=ParseGeometry(argv[i+1],&geometry_info);
2673 if ((flags & SigmaValue) == 0)
2674 geometry_info.sigma=1.0;
2675 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2676 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2677 break;
2678 }
2679 if (LocaleCompare("shadow",option+1) == 0)
2680 {
2681 /*
2682 Shadow image.
2683 */
2684 (void) SyncImageSettings(mogrify_info,*image);
2685 flags=ParseGeometry(argv[i+1],&geometry_info);
2686 if ((flags & SigmaValue) == 0)
2687 geometry_info.sigma=1.0;
2688 if ((flags & XiValue) == 0)
2689 geometry_info.xi=4.0;
2690 if ((flags & PsiValue) == 0)
2691 geometry_info.psi=4.0;
2692 mogrify_image=ShadowImage(*image,geometry_info.rho,
2693 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2694 ceil(geometry_info.psi-0.5),exception);
2695 break;
2696 }
2697 if (LocaleCompare("sharpen",option+1) == 0)
2698 {
2699 /*
2700 Sharpen image.
2701 */
2702 (void) SyncImageSettings(mogrify_info,*image);
2703 flags=ParseGeometry(argv[i+1],&geometry_info);
2704 if ((flags & SigmaValue) == 0)
2705 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002706 if ((flags & XiValue) == 0)
2707 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002708 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002709 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002710 break;
2711 }
2712 if (LocaleCompare("shave",option+1) == 0)
2713 {
2714 /*
2715 Shave the image edges.
2716 */
2717 (void) SyncImageSettings(mogrify_info,*image);
2718 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2719 mogrify_image=ShaveImage(*image,&geometry,exception);
2720 break;
2721 }
2722 if (LocaleCompare("shear",option+1) == 0)
2723 {
2724 /*
2725 Shear image.
2726 */
2727 (void) SyncImageSettings(mogrify_info,*image);
2728 flags=ParseGeometry(argv[i+1],&geometry_info);
2729 if ((flags & SigmaValue) == 0)
2730 geometry_info.sigma=geometry_info.rho;
2731 mogrify_image=ShearImage(*image,geometry_info.rho,
2732 geometry_info.sigma,exception);
2733 break;
2734 }
2735 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2736 {
2737 /*
2738 Sigmoidal non-linearity contrast control.
2739 */
2740 (void) SyncImageSettings(mogrify_info,*image);
2741 flags=ParseGeometry(argv[i+1],&geometry_info);
2742 if ((flags & SigmaValue) == 0)
2743 geometry_info.sigma=(double) QuantumRange/2.0;
2744 if ((flags & PercentValue) != 0)
2745 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2746 100.0;
cristy9ee60942011-07-06 14:54:38 +00002747 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002748 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2749 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002750 break;
2751 }
2752 if (LocaleCompare("sketch",option+1) == 0)
2753 {
2754 /*
2755 Sketch image.
2756 */
2757 (void) SyncImageSettings(mogrify_info,*image);
2758 flags=ParseGeometry(argv[i+1],&geometry_info);
2759 if ((flags & SigmaValue) == 0)
2760 geometry_info.sigma=1.0;
2761 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002762 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002763 break;
2764 }
2765 if (LocaleCompare("solarize",option+1) == 0)
2766 {
2767 double
2768 threshold;
2769
2770 (void) SyncImageSettings(mogrify_info,*image);
2771 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002772 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002773 break;
2774 }
2775 if (LocaleCompare("sparse-color",option+1) == 0)
2776 {
2777 SparseColorMethod
2778 method;
2779
2780 char
2781 *arguments;
2782
2783 /*
2784 Sparse Color Interpolated Gradient
2785 */
2786 (void) SyncImageSettings(mogrify_info,*image);
2787 method=(SparseColorMethod) ParseCommandOption(
2788 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002789 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2790 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002791 if (arguments == (char *) NULL)
2792 break;
cristy3884f692011-07-08 18:00:18 +00002793 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002794 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2795 arguments=DestroyString(arguments);
2796 break;
2797 }
2798 if (LocaleCompare("splice",option+1) == 0)
2799 {
2800 /*
2801 Splice a solid color into the image.
2802 */
2803 (void) SyncImageSettings(mogrify_info,*image);
2804 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2805 mogrify_image=SpliceImage(*image,&geometry,exception);
2806 break;
2807 }
2808 if (LocaleCompare("spread",option+1) == 0)
2809 {
2810 /*
2811 Spread an image.
2812 */
2813 (void) SyncImageSettings(mogrify_info,*image);
2814 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002815 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002816 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002817 break;
2818 }
2819 if (LocaleCompare("statistic",option+1) == 0)
2820 {
2821 StatisticType
2822 type;
2823
2824 (void) SyncImageSettings(mogrify_info,*image);
2825 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2826 MagickFalse,argv[i+1]);
2827 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002828 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2829 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002830 break;
2831 }
2832 if (LocaleCompare("stretch",option+1) == 0)
2833 {
2834 if (*option == '+')
2835 {
2836 draw_info->stretch=UndefinedStretch;
2837 break;
2838 }
2839 draw_info->stretch=(StretchType) ParseCommandOption(
2840 MagickStretchOptions,MagickFalse,argv[i+1]);
2841 break;
2842 }
2843 if (LocaleCompare("strip",option+1) == 0)
2844 {
2845 /*
2846 Strip image of profiles and comments.
2847 */
2848 (void) SyncImageSettings(mogrify_info,*image);
2849 (void) StripImage(*image);
2850 InheritException(exception,&(*image)->exception);
2851 break;
2852 }
2853 if (LocaleCompare("stroke",option+1) == 0)
2854 {
2855 ExceptionInfo
2856 *sans;
2857
2858 if (*option == '+')
2859 {
2860 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2861 if (draw_info->stroke_pattern != (Image *) NULL)
2862 draw_info->stroke_pattern=DestroyImage(
2863 draw_info->stroke_pattern);
2864 break;
2865 }
2866 sans=AcquireExceptionInfo();
2867 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2868 sans=DestroyExceptionInfo(sans);
2869 if (status == MagickFalse)
2870 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2871 exception);
2872 break;
2873 }
2874 if (LocaleCompare("strokewidth",option+1) == 0)
2875 {
cristyc1acd842011-05-19 23:05:47 +00002876 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2877 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002878 break;
2879 }
2880 if (LocaleCompare("style",option+1) == 0)
2881 {
2882 if (*option == '+')
2883 {
2884 draw_info->style=UndefinedStyle;
2885 break;
2886 }
2887 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2888 MagickFalse,argv[i+1]);
2889 break;
2890 }
2891 if (LocaleCompare("swirl",option+1) == 0)
2892 {
2893 /*
2894 Swirl image.
2895 */
2896 (void) SyncImageSettings(mogrify_info,*image);
2897 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002898 mogrify_image=SwirlImage(*image,geometry_info.rho,
2899 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002900 break;
2901 }
2902 break;
2903 }
2904 case 't':
2905 {
2906 if (LocaleCompare("threshold",option+1) == 0)
2907 {
2908 double
2909 threshold;
2910
2911 /*
2912 Threshold image.
2913 */
2914 (void) SyncImageSettings(mogrify_info,*image);
2915 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002916 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002917 else
2918 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002919 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002920 InheritException(exception,&(*image)->exception);
2921 break;
2922 }
2923 if (LocaleCompare("thumbnail",option+1) == 0)
2924 {
2925 /*
2926 Thumbnail image.
2927 */
2928 (void) SyncImageSettings(mogrify_info,*image);
2929 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2930 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2931 exception);
2932 break;
2933 }
2934 if (LocaleCompare("tile",option+1) == 0)
2935 {
2936 if (*option == '+')
2937 {
2938 if (draw_info->fill_pattern != (Image *) NULL)
2939 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2940 break;
2941 }
2942 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2943 exception);
2944 break;
2945 }
2946 if (LocaleCompare("tint",option+1) == 0)
2947 {
2948 /*
2949 Tint the image.
2950 */
2951 (void) SyncImageSettings(mogrify_info,*image);
cristy28474bf2011-09-11 23:32:52 +00002952 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002953 break;
2954 }
2955 if (LocaleCompare("transform",option+1) == 0)
2956 {
2957 /*
2958 Affine transform image.
2959 */
2960 (void) SyncImageSettings(mogrify_info,*image);
2961 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2962 exception);
2963 break;
2964 }
2965 if (LocaleCompare("transparent",option+1) == 0)
2966 {
cristy4c08aed2011-07-01 19:47:50 +00002967 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002968 target;
2969
2970 (void) SyncImageSettings(mogrify_info,*image);
2971 (void) QueryMagickColor(argv[i+1],&target,exception);
2972 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002973 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2974 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002975 break;
2976 }
2977 if (LocaleCompare("transpose",option+1) == 0)
2978 {
2979 /*
2980 Transpose image scanlines.
2981 */
2982 (void) SyncImageSettings(mogrify_info,*image);
2983 mogrify_image=TransposeImage(*image,exception);
2984 break;
2985 }
2986 if (LocaleCompare("transverse",option+1) == 0)
2987 {
2988 /*
2989 Transverse image scanlines.
2990 */
2991 (void) SyncImageSettings(mogrify_info,*image);
2992 mogrify_image=TransverseImage(*image,exception);
2993 break;
2994 }
2995 if (LocaleCompare("treedepth",option+1) == 0)
2996 {
2997 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2998 break;
2999 }
3000 if (LocaleCompare("trim",option+1) == 0)
3001 {
3002 /*
3003 Trim image.
3004 */
3005 (void) SyncImageSettings(mogrify_info,*image);
3006 mogrify_image=TrimImage(*image,exception);
3007 break;
3008 }
3009 if (LocaleCompare("type",option+1) == 0)
3010 {
3011 ImageType
3012 type;
3013
3014 (void) SyncImageSettings(mogrify_info,*image);
3015 if (*option == '+')
3016 type=UndefinedType;
3017 else
3018 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3019 argv[i+1]);
3020 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003021 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003022 break;
3023 }
3024 break;
3025 }
3026 case 'u':
3027 {
3028 if (LocaleCompare("undercolor",option+1) == 0)
3029 {
3030 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3031 exception);
3032 break;
3033 }
3034 if (LocaleCompare("unique",option+1) == 0)
3035 {
3036 if (*option == '+')
3037 {
3038 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3039 break;
3040 }
3041 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3042 (void) SetImageArtifact(*image,"verbose","true");
3043 break;
3044 }
3045 if (LocaleCompare("unique-colors",option+1) == 0)
3046 {
3047 /*
3048 Unique image colors.
3049 */
3050 (void) SyncImageSettings(mogrify_info,*image);
3051 mogrify_image=UniqueImageColors(*image,exception);
3052 break;
3053 }
3054 if (LocaleCompare("unsharp",option+1) == 0)
3055 {
3056 /*
3057 Unsharp mask image.
3058 */
3059 (void) SyncImageSettings(mogrify_info,*image);
3060 flags=ParseGeometry(argv[i+1],&geometry_info);
3061 if ((flags & SigmaValue) == 0)
3062 geometry_info.sigma=1.0;
3063 if ((flags & XiValue) == 0)
3064 geometry_info.xi=1.0;
3065 if ((flags & PsiValue) == 0)
3066 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003067 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3068 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003069 break;
3070 }
3071 break;
3072 }
3073 case 'v':
3074 {
3075 if (LocaleCompare("verbose",option+1) == 0)
3076 {
3077 (void) SetImageArtifact(*image,option+1,
3078 *option == '+' ? "false" : "true");
3079 break;
3080 }
3081 if (LocaleCompare("vignette",option+1) == 0)
3082 {
3083 /*
3084 Vignette image.
3085 */
3086 (void) SyncImageSettings(mogrify_info,*image);
3087 flags=ParseGeometry(argv[i+1],&geometry_info);
3088 if ((flags & SigmaValue) == 0)
3089 geometry_info.sigma=1.0;
3090 if ((flags & XiValue) == 0)
3091 geometry_info.xi=0.1*(*image)->columns;
3092 if ((flags & PsiValue) == 0)
3093 geometry_info.psi=0.1*(*image)->rows;
3094 mogrify_image=VignetteImage(*image,geometry_info.rho,
3095 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3096 ceil(geometry_info.psi-0.5),exception);
3097 break;
3098 }
3099 if (LocaleCompare("virtual-pixel",option+1) == 0)
3100 {
3101 if (*option == '+')
3102 {
3103 (void) SetImageVirtualPixelMethod(*image,
3104 UndefinedVirtualPixelMethod);
3105 break;
3106 }
3107 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3108 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3109 argv[i+1]));
3110 break;
3111 }
3112 break;
3113 }
3114 case 'w':
3115 {
3116 if (LocaleCompare("wave",option+1) == 0)
3117 {
3118 /*
3119 Wave image.
3120 */
3121 (void) SyncImageSettings(mogrify_info,*image);
3122 flags=ParseGeometry(argv[i+1],&geometry_info);
3123 if ((flags & SigmaValue) == 0)
3124 geometry_info.sigma=1.0;
3125 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003126 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003127 break;
3128 }
3129 if (LocaleCompare("weight",option+1) == 0)
3130 {
3131 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3132 if (LocaleCompare(argv[i+1],"all") == 0)
3133 draw_info->weight=0;
3134 if (LocaleCompare(argv[i+1],"bold") == 0)
3135 draw_info->weight=700;
3136 if (LocaleCompare(argv[i+1],"bolder") == 0)
3137 if (draw_info->weight <= 800)
3138 draw_info->weight+=100;
3139 if (LocaleCompare(argv[i+1],"lighter") == 0)
3140 if (draw_info->weight >= 100)
3141 draw_info->weight-=100;
3142 if (LocaleCompare(argv[i+1],"normal") == 0)
3143 draw_info->weight=400;
3144 break;
3145 }
3146 if (LocaleCompare("white-threshold",option+1) == 0)
3147 {
3148 /*
3149 White threshold image.
3150 */
3151 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003152 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003153 InheritException(exception,&(*image)->exception);
3154 break;
3155 }
3156 break;
3157 }
3158 default:
3159 break;
3160 }
3161 /*
3162 Replace current image with any image that was generated
3163 */
3164 if (mogrify_image != (Image *) NULL)
3165 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003166 i+=count;
3167 }
3168 if (region_image != (Image *) NULL)
3169 {
anthonydf8ebac2011-04-27 09:03:19 +00003170 /*
3171 Composite transformed region onto image.
3172 */
cristy6b3da3a2010-06-20 02:21:46 +00003173 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003174 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003175 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3176 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003177 InheritException(exception,&region_image->exception);
3178 *image=DestroyImage(*image);
3179 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003180 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003181 }
3182 /*
3183 Free resources.
3184 */
anthonydf8ebac2011-04-27 09:03:19 +00003185 quantize_info=DestroyQuantizeInfo(quantize_info);
3186 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003187 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003188 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003189 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003190 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003191}
3192
3193/*
3194%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3195% %
3196% %
3197% %
cristy5063d812010-10-19 16:28:10 +00003198+ 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 +00003199% %
3200% %
3201% %
3202%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3203%
3204% MogrifyImageCommand() transforms an image or a sequence of images. These
3205% transforms include image scaling, image rotation, color reduction, and
3206% others. The transmogrified image overwrites the original image.
3207%
3208% The format of the MogrifyImageCommand method is:
3209%
3210% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3211% const char **argv,char **metadata,ExceptionInfo *exception)
3212%
3213% A description of each parameter follows:
3214%
3215% o image_info: the image info.
3216%
3217% o argc: the number of elements in the argument vector.
3218%
3219% o argv: A text array containing the command line arguments.
3220%
3221% o metadata: any metadata is returned here.
3222%
3223% o exception: return any errors or warnings in this structure.
3224%
3225*/
3226
3227static MagickBooleanType MogrifyUsage(void)
3228{
3229 static const char
3230 *miscellaneous[]=
3231 {
3232 "-debug events display copious debugging information",
3233 "-help print program options",
3234 "-list type print a list of supported option arguments",
3235 "-log format format of debugging information",
3236 "-version print version information",
3237 (char *) NULL
3238 },
3239 *operators[]=
3240 {
3241 "-adaptive-blur geometry",
3242 " adaptively blur pixels; decrease effect near edges",
3243 "-adaptive-resize geometry",
3244 " adaptively resize image using 'mesh' interpolation",
3245 "-adaptive-sharpen geometry",
3246 " adaptively sharpen pixels; increase effect near edges",
3247 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3248 " transparent, extract, background, or shape",
3249 "-annotate geometry text",
3250 " annotate the image with text",
3251 "-auto-gamma automagically adjust gamma level of image",
3252 "-auto-level automagically adjust color levels of image",
3253 "-auto-orient automagically orient (rotate) image",
3254 "-bench iterations measure performance",
3255 "-black-threshold value",
3256 " force all pixels below the threshold into black",
3257 "-blue-shift simulate a scene at nighttime in the moonlight",
3258 "-blur geometry reduce image noise and reduce detail levels",
3259 "-border geometry surround image with a border of color",
3260 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003261 "-brightness-contrast geometry",
3262 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003263 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003264 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003265 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003266 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003267 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003268 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003269 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003270 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003271 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003272 "-contrast enhance or reduce the image contrast",
3273 "-contrast-stretch geometry",
3274 " improve contrast by `stretching' the intensity range",
3275 "-convolve coefficients",
3276 " apply a convolution kernel to the image",
3277 "-cycle amount cycle the image colormap",
3278 "-decipher filename convert cipher pixels to plain pixels",
3279 "-deskew threshold straighten an image",
3280 "-despeckle reduce the speckles within an image",
3281 "-distort method args",
3282 " distort images according to given method ad args",
3283 "-draw string annotate the image with a graphic primitive",
3284 "-edge radius apply a filter to detect edges in the image",
3285 "-encipher filename convert plain pixels to cipher pixels",
3286 "-emboss radius emboss an image",
3287 "-enhance apply a digital filter to enhance a noisy image",
3288 "-equalize perform histogram equalization to an image",
3289 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003290 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003291 "-extent geometry set the image size",
3292 "-extract geometry extract area from image",
3293 "-fft implements the discrete Fourier transform (DFT)",
3294 "-flip flip image vertically",
3295 "-floodfill geometry color",
3296 " floodfill the image with color",
3297 "-flop flop image horizontally",
3298 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003299 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003300 " apply function over image values",
3301 "-gamma value level of gamma correction",
3302 "-gaussian-blur geometry",
3303 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003304 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003305 "-identify identify the format and characteristics of the image",
3306 "-ift implements the inverse discrete Fourier transform (DFT)",
3307 "-implode amount implode image pixels about the center",
3308 "-lat geometry local adaptive thresholding",
3309 "-layers method optimize, merge, or compare image layers",
3310 "-level value adjust the level of image contrast",
3311 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003312 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003313 "-linear-stretch geometry",
3314 " improve contrast by `stretching with saturation'",
3315 "-liquid-rescale geometry",
3316 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003317 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003318 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003319 "-modulate value vary the brightness, saturation, and hue",
3320 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003321 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003322 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003323 "-motion-blur geometry",
3324 " simulate motion blur",
3325 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003326 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003327 "-normalize transform image to span the full range of colors",
3328 "-opaque color change this color to the fill color",
3329 "-ordered-dither NxN",
3330 " add a noise pattern to the image with specific",
3331 " amplitudes",
3332 "-paint radius simulate an oil painting",
3333 "-polaroid angle simulate a Polaroid picture",
3334 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003335 "-profile filename add, delete, or apply an image profile",
3336 "-quantize colorspace reduce colors in this colorspace",
3337 "-radial-blur angle radial blur the image",
3338 "-raise value lighten/darken image edges to create a 3-D effect",
3339 "-random-threshold low,high",
3340 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003341 "-region geometry apply options to a portion of the image",
3342 "-render render vector graphics",
3343 "-repage geometry size and location of an image canvas",
3344 "-resample geometry change the resolution of an image",
3345 "-resize geometry resize the image",
3346 "-roll geometry roll an image vertically or horizontally",
3347 "-rotate degrees apply Paeth rotation to the image",
3348 "-sample geometry scale image with pixel sampling",
3349 "-scale geometry scale the image",
3350 "-segment values segment an image",
3351 "-selective-blur geometry",
3352 " selectively blur pixels within a contrast threshold",
3353 "-sepia-tone threshold",
3354 " simulate a sepia-toned photo",
3355 "-set property value set an image property",
3356 "-shade degrees shade the image using a distant light source",
3357 "-shadow geometry simulate an image shadow",
3358 "-sharpen geometry sharpen the image",
3359 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003360 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003361 "-sigmoidal-contrast geometry",
3362 " increase the contrast without saturating highlights or shadows",
3363 "-sketch geometry simulate a pencil sketch",
3364 "-solarize threshold negate all pixels above the threshold level",
3365 "-sparse-color method args",
3366 " fill in a image based on a few color points",
3367 "-splice geometry splice the background color into the image",
3368 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003369 "-statistic type radius",
3370 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003371 "-strip strip image of all profiles and comments",
3372 "-swirl degrees swirl image pixels about the center",
3373 "-threshold value threshold the image",
3374 "-thumbnail geometry create a thumbnail of the image",
3375 "-tile filename tile image when filling a graphic primitive",
3376 "-tint value tint the image with the fill color",
3377 "-transform affine transform image",
3378 "-transparent color make this color transparent within the image",
3379 "-transpose flip image vertically and rotate 90 degrees",
3380 "-transverse flop image horizontally and rotate 270 degrees",
3381 "-trim trim image edges",
3382 "-type type image type",
3383 "-unique-colors discard all but one of any pixel color",
3384 "-unsharp geometry sharpen the image",
3385 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003386 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003387 "-white-threshold value",
3388 " force all pixels above the threshold into white",
3389 (char *) NULL
3390 },
3391 *sequence_operators[]=
3392 {
cristy4285d782011-02-09 20:12:28 +00003393 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003394 "-clut apply a color lookup table to the image",
3395 "-coalesce merge a sequence of images",
3396 "-combine combine a sequence of images",
3397 "-composite composite image",
3398 "-crop geometry cut out a rectangular region of the image",
3399 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003400 "-evaluate-sequence operator",
3401 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003402 "-flatten flatten a sequence of images",
3403 "-fx expression apply mathematical expression to an image channel(s)",
3404 "-hald-clut apply a Hald color lookup table to the image",
3405 "-morph value morph an image sequence",
3406 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003407 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003408 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003409 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003410 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003411 "-write filename write images to this file",
3412 (char *) NULL
3413 },
3414 *settings[]=
3415 {
3416 "-adjoin join images into a single multi-image file",
3417 "-affine matrix affine transform matrix",
3418 "-alpha option activate, deactivate, reset, or set the alpha channel",
3419 "-antialias remove pixel-aliasing",
3420 "-authenticate password",
3421 " decipher image with this password",
3422 "-attenuate value lessen (or intensify) when adding noise to an image",
3423 "-background color background color",
3424 "-bias value add bias when convolving an image",
3425 "-black-point-compensation",
3426 " use black point compensation",
3427 "-blue-primary point chromaticity blue primary point",
3428 "-bordercolor color border color",
3429 "-caption string assign a caption to an image",
3430 "-channel type apply option to select image channels",
3431 "-colors value preferred number of colors in the image",
3432 "-colorspace type alternate image colorspace",
3433 "-comment string annotate image with comment",
3434 "-compose operator set image composite operator",
3435 "-compress type type of pixel compression when writing the image",
3436 "-define format:option",
3437 " define one or more image format options",
3438 "-delay value display the next image after pausing",
3439 "-density geometry horizontal and vertical density of the image",
3440 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003441 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003442 "-display server get image or font from this X server",
3443 "-dispose method layer disposal method",
3444 "-dither method apply error diffusion to image",
3445 "-encoding type text encoding type",
3446 "-endian type endianness (MSB or LSB) of the image",
3447 "-family name render text with this font family",
3448 "-fill color color to use when filling a graphic primitive",
3449 "-filter type use this filter when resizing an image",
3450 "-font name render text with this font",
3451 "-format \"string\" output formatted image characteristics",
3452 "-fuzz distance colors within this distance are considered equal",
3453 "-gravity type horizontal and vertical text placement",
3454 "-green-primary point chromaticity green primary point",
3455 "-intent type type of rendering intent when managing the image color",
3456 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003457 "-interline-spacing value",
3458 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003459 "-interpolate method pixel color interpolation method",
3460 "-interword-spacing value",
3461 " set the space between two words",
3462 "-kerning value set the space between two letters",
3463 "-label string assign a label to an image",
3464 "-limit type value pixel cache resource limit",
3465 "-loop iterations add Netscape loop extension to your GIF animation",
3466 "-mask filename associate a mask with the image",
3467 "-mattecolor color frame color",
3468 "-monitor monitor progress",
3469 "-orient type image orientation",
3470 "-page geometry size and location of an image canvas (setting)",
3471 "-ping efficiently determine image attributes",
3472 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003473 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003474 "-preview type image preview type",
3475 "-quality value JPEG/MIFF/PNG compression level",
3476 "-quiet suppress all warning messages",
3477 "-red-primary point chromaticity red primary point",
3478 "-regard-warnings pay attention to warning messages",
3479 "-remap filename transform image colors to match this set of colors",
3480 "-respect-parentheses settings remain in effect until parenthesis boundary",
3481 "-sampling-factor geometry",
3482 " horizontal and vertical sampling factor",
3483 "-scene value image scene number",
3484 "-seed value seed a new sequence of pseudo-random numbers",
3485 "-size geometry width and height of image",
3486 "-stretch type render text with this font stretch",
3487 "-stroke color graphic primitive stroke color",
3488 "-strokewidth value graphic primitive stroke width",
3489 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003490 "-synchronize synchronize image to storage device",
3491 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003492 "-texture filename name of texture to tile onto the image background",
3493 "-tile-offset geometry",
3494 " tile offset",
3495 "-treedepth value color tree depth",
3496 "-transparent-color color",
3497 " transparent color",
3498 "-undercolor color annotation bounding box color",
3499 "-units type the units of image resolution",
3500 "-verbose print detailed information about the image",
3501 "-view FlashPix viewing transforms",
3502 "-virtual-pixel method",
3503 " virtual pixel access method",
3504 "-weight type render text with this font weight",
3505 "-white-point point chromaticity white point",
3506 (char *) NULL
3507 },
3508 *stack_operators[]=
3509 {
anthonyb69c4b32011-03-23 04:37:44 +00003510 "-delete indexes delete the image from the image sequence",
3511 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003512 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003513 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003514 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003515 "-swap indexes swap two images in the image sequence",
3516 (char *) NULL
3517 };
3518
3519 const char
3520 **p;
3521
cristybb503372010-05-27 20:51:26 +00003522 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003523 (void) printf("Copyright: %s\n",GetMagickCopyright());
3524 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003525 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3526 GetClientName());
3527 (void) printf("\nImage Settings:\n");
3528 for (p=settings; *p != (char *) NULL; p++)
3529 (void) printf(" %s\n",*p);
3530 (void) printf("\nImage Operators:\n");
3531 for (p=operators; *p != (char *) NULL; p++)
3532 (void) printf(" %s\n",*p);
3533 (void) printf("\nImage Sequence Operators:\n");
3534 for (p=sequence_operators; *p != (char *) NULL; p++)
3535 (void) printf(" %s\n",*p);
3536 (void) printf("\nImage Stack Operators:\n");
3537 for (p=stack_operators; *p != (char *) NULL; p++)
3538 (void) printf(" %s\n",*p);
3539 (void) printf("\nMiscellaneous Options:\n");
3540 for (p=miscellaneous; *p != (char *) NULL; p++)
3541 (void) printf(" %s\n",*p);
3542 (void) printf(
3543 "\nBy default, the image format of `file' is determined by its magic\n");
3544 (void) printf(
3545 "number. To specify a particular image format, precede the filename\n");
3546 (void) printf(
3547 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3548 (void) printf(
3549 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3550 (void) printf("'-' for standard input or output.\n");
3551 return(MagickFalse);
3552}
3553
3554WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3555 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3556{
3557#define DestroyMogrify() \
3558{ \
3559 if (format != (char *) NULL) \
3560 format=DestroyString(format); \
3561 if (path != (char *) NULL) \
3562 path=DestroyString(path); \
3563 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003564 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003565 argv[i]=DestroyString(argv[i]); \
3566 argv=(char **) RelinquishMagickMemory(argv); \
3567}
3568#define ThrowMogrifyException(asperity,tag,option) \
3569{ \
3570 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3571 option); \
3572 DestroyMogrify(); \
3573 return(MagickFalse); \
3574}
3575#define ThrowMogrifyInvalidArgumentException(option,argument) \
3576{ \
3577 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3578 "InvalidArgument","`%s': %s",argument,option); \
3579 DestroyMogrify(); \
3580 return(MagickFalse); \
3581}
3582
3583 char
3584 *format,
3585 *option,
3586 *path;
3587
3588 Image
3589 *image;
3590
3591 ImageStack
3592 image_stack[MaxImageStackDepth+1];
3593
cristy3ed852e2009-09-05 21:47:34 +00003594 MagickBooleanType
3595 global_colormap;
3596
3597 MagickBooleanType
3598 fire,
cristyebbcfea2011-02-25 02:43:54 +00003599 pend,
3600 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003601
3602 MagickStatusType
3603 status;
3604
cristyebbcfea2011-02-25 02:43:54 +00003605 register ssize_t
3606 i;
3607
3608 ssize_t
3609 j,
3610 k;
3611
cristy3ed852e2009-09-05 21:47:34 +00003612 /*
3613 Set defaults.
3614 */
3615 assert(image_info != (ImageInfo *) NULL);
3616 assert(image_info->signature == MagickSignature);
3617 if (image_info->debug != MagickFalse)
3618 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3619 assert(exception != (ExceptionInfo *) NULL);
3620 if (argc == 2)
3621 {
3622 option=argv[1];
3623 if ((LocaleCompare("version",option+1) == 0) ||
3624 (LocaleCompare("-version",option+1) == 0))
3625 {
cristyb51dff52011-05-19 16:55:47 +00003626 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003627 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003628 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3629 GetMagickCopyright());
3630 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3631 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003632 return(MagickFalse);
3633 }
3634 }
3635 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003636 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003637 format=(char *) NULL;
3638 path=(char *) NULL;
3639 global_colormap=MagickFalse;
3640 k=0;
3641 j=1;
3642 NewImageStack();
3643 option=(char *) NULL;
3644 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003645 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003646 status=MagickTrue;
3647 /*
3648 Parse command line.
3649 */
3650 ReadCommandlLine(argc,&argv);
3651 status=ExpandFilenames(&argc,&argv);
3652 if (status == MagickFalse)
3653 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3654 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003655 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003656 {
3657 option=argv[i];
3658 if (LocaleCompare(option,"(") == 0)
3659 {
3660 FireImageStack(MagickFalse,MagickTrue,pend);
3661 if (k == MaxImageStackDepth)
3662 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3663 option);
3664 PushImageStack();
3665 continue;
3666 }
3667 if (LocaleCompare(option,")") == 0)
3668 {
3669 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3670 if (k == 0)
3671 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3672 PopImageStack();
3673 continue;
3674 }
cristy042ee782011-04-22 18:48:30 +00003675 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003676 {
3677 char
3678 backup_filename[MaxTextExtent],
3679 *filename;
3680
3681 Image
3682 *images;
3683
3684 /*
3685 Option is a file name: begin by reading image from specified file.
3686 */
3687 FireImageStack(MagickFalse,MagickFalse,pend);
3688 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003689 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003690 filename=argv[++i];
3691 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3692 images=ReadImages(image_info,exception);
3693 status&=(images != (Image *) NULL) &&
3694 (exception->severity < ErrorException);
3695 if (images == (Image *) NULL)
3696 continue;
cristydaa76602010-06-30 13:05:11 +00003697 if (format != (char *) NULL)
3698 (void) CopyMagickString(images->filename,images->magick_filename,
3699 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003700 if (path != (char *) NULL)
3701 {
3702 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003703 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003704 path,*DirectorySeparator,filename);
3705 }
3706 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003707 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003708 AppendImageStack(images);
3709 FinalizeImageSettings(image_info,image,MagickFalse);
3710 if (global_colormap != MagickFalse)
3711 {
3712 QuantizeInfo
3713 *quantize_info;
3714
3715 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003716 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003717 quantize_info=DestroyQuantizeInfo(quantize_info);
3718 }
3719 *backup_filename='\0';
3720 if ((LocaleCompare(image->filename,"-") != 0) &&
3721 (IsPathWritable(image->filename) != MagickFalse))
3722 {
cristybb503372010-05-27 20:51:26 +00003723 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003724 i;
3725
3726 /*
3727 Rename image file as backup.
3728 */
3729 (void) CopyMagickString(backup_filename,image->filename,
3730 MaxTextExtent);
3731 for (i=0; i < 6; i++)
3732 {
3733 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3734 if (IsPathAccessible(backup_filename) == MagickFalse)
3735 break;
3736 }
3737 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3738 (rename(image->filename,backup_filename) != 0))
3739 *backup_filename='\0';
3740 }
3741 /*
3742 Write transmogrified image to disk.
3743 */
3744 image_info->synchronize=MagickTrue;
3745 status&=WriteImages(image_info,image,image->filename,exception);
3746 if ((status == MagickFalse) && (*backup_filename != '\0'))
3747 (void) remove(backup_filename);
3748 RemoveAllImageStack();
3749 continue;
3750 }
3751 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3752 switch (*(option+1))
3753 {
3754 case 'a':
3755 {
3756 if (LocaleCompare("adaptive-blur",option+1) == 0)
3757 {
3758 i++;
cristybb503372010-05-27 20:51:26 +00003759 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003760 ThrowMogrifyException(OptionError,"MissingArgument",option);
3761 if (IsGeometry(argv[i]) == MagickFalse)
3762 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3763 break;
3764 }
3765 if (LocaleCompare("adaptive-resize",option+1) == 0)
3766 {
3767 i++;
cristybb503372010-05-27 20:51:26 +00003768 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003769 ThrowMogrifyException(OptionError,"MissingArgument",option);
3770 if (IsGeometry(argv[i]) == MagickFalse)
3771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3772 break;
3773 }
3774 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3775 {
3776 i++;
cristybb503372010-05-27 20:51:26 +00003777 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003778 ThrowMogrifyException(OptionError,"MissingArgument",option);
3779 if (IsGeometry(argv[i]) == MagickFalse)
3780 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3781 break;
3782 }
3783 if (LocaleCompare("affine",option+1) == 0)
3784 {
3785 if (*option == '+')
3786 break;
3787 i++;
cristybb503372010-05-27 20:51:26 +00003788 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003789 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003790 break;
3791 }
3792 if (LocaleCompare("alpha",option+1) == 0)
3793 {
cristybb503372010-05-27 20:51:26 +00003794 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003795 type;
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);
cristy042ee782011-04-22 18:48:30 +00003802 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003803 if (type < 0)
3804 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3805 argv[i]);
3806 break;
3807 }
3808 if (LocaleCompare("annotate",option+1) == 0)
3809 {
3810 if (*option == '+')
3811 break;
3812 i++;
cristybb503372010-05-27 20:51:26 +00003813 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003814 ThrowMogrifyException(OptionError,"MissingArgument",option);
3815 if (IsGeometry(argv[i]) == MagickFalse)
3816 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003817 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003818 ThrowMogrifyException(OptionError,"MissingArgument",option);
3819 i++;
3820 break;
3821 }
3822 if (LocaleCompare("antialias",option+1) == 0)
3823 break;
3824 if (LocaleCompare("append",option+1) == 0)
3825 break;
3826 if (LocaleCompare("attenuate",option+1) == 0)
3827 {
3828 if (*option == '+')
3829 break;
3830 i++;
cristybb503372010-05-27 20:51:26 +00003831 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003832 ThrowMogrifyException(OptionError,"MissingArgument",option);
3833 if (IsGeometry(argv[i]) == MagickFalse)
3834 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3835 break;
3836 }
3837 if (LocaleCompare("authenticate",option+1) == 0)
3838 {
3839 if (*option == '+')
3840 break;
3841 i++;
cristybb503372010-05-27 20:51:26 +00003842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003843 ThrowMogrifyException(OptionError,"MissingArgument",option);
3844 break;
3845 }
3846 if (LocaleCompare("auto-gamma",option+1) == 0)
3847 break;
3848 if (LocaleCompare("auto-level",option+1) == 0)
3849 break;
3850 if (LocaleCompare("auto-orient",option+1) == 0)
3851 break;
3852 if (LocaleCompare("average",option+1) == 0)
3853 break;
3854 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3855 }
3856 case 'b':
3857 {
3858 if (LocaleCompare("background",option+1) == 0)
3859 {
3860 if (*option == '+')
3861 break;
3862 i++;
cristybb503372010-05-27 20:51:26 +00003863 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003864 ThrowMogrifyException(OptionError,"MissingArgument",option);
3865 break;
3866 }
3867 if (LocaleCompare("bias",option+1) == 0)
3868 {
3869 if (*option == '+')
3870 break;
3871 i++;
cristybb503372010-05-27 20:51:26 +00003872 if (i == (ssize_t) (argc-1))
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("black-point-compensation",option+1) == 0)
3879 break;
3880 if (LocaleCompare("black-threshold",option+1) == 0)
3881 {
3882 if (*option == '+')
3883 break;
3884 i++;
cristybb503372010-05-27 20:51:26 +00003885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003886 ThrowMogrifyException(OptionError,"MissingArgument",option);
3887 if (IsGeometry(argv[i]) == MagickFalse)
3888 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3889 break;
3890 }
3891 if (LocaleCompare("blue-primary",option+1) == 0)
3892 {
3893 if (*option == '+')
3894 break;
3895 i++;
cristybb503372010-05-27 20:51:26 +00003896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003897 ThrowMogrifyException(OptionError,"MissingArgument",option);
3898 if (IsGeometry(argv[i]) == MagickFalse)
3899 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3900 break;
3901 }
3902 if (LocaleCompare("blue-shift",option+1) == 0)
3903 {
3904 i++;
cristybb503372010-05-27 20:51:26 +00003905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003906 ThrowMogrifyException(OptionError,"MissingArgument",option);
3907 if (IsGeometry(argv[i]) == MagickFalse)
3908 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3909 break;
3910 }
3911 if (LocaleCompare("blur",option+1) == 0)
3912 {
3913 i++;
cristybb503372010-05-27 20:51:26 +00003914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003915 ThrowMogrifyException(OptionError,"MissingArgument",option);
3916 if (IsGeometry(argv[i]) == MagickFalse)
3917 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3918 break;
3919 }
3920 if (LocaleCompare("border",option+1) == 0)
3921 {
3922 if (*option == '+')
3923 break;
3924 i++;
cristybb503372010-05-27 20:51:26 +00003925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003926 ThrowMogrifyException(OptionError,"MissingArgument",option);
3927 if (IsGeometry(argv[i]) == MagickFalse)
3928 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3929 break;
3930 }
3931 if (LocaleCompare("bordercolor",option+1) == 0)
3932 {
3933 if (*option == '+')
3934 break;
3935 i++;
cristybb503372010-05-27 20:51:26 +00003936 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003937 ThrowMogrifyException(OptionError,"MissingArgument",option);
3938 break;
3939 }
3940 if (LocaleCompare("box",option+1) == 0)
3941 {
3942 if (*option == '+')
3943 break;
3944 i++;
cristybb503372010-05-27 20:51:26 +00003945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003946 ThrowMogrifyException(OptionError,"MissingArgument",option);
3947 break;
3948 }
cristya28d6b82010-01-11 20:03:47 +00003949 if (LocaleCompare("brightness-contrast",option+1) == 0)
3950 {
3951 i++;
cristybb503372010-05-27 20:51:26 +00003952 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003953 ThrowMogrifyException(OptionError,"MissingArgument",option);
3954 if (IsGeometry(argv[i]) == MagickFalse)
3955 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3956 break;
3957 }
cristy3ed852e2009-09-05 21:47:34 +00003958 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3959 }
3960 case 'c':
3961 {
3962 if (LocaleCompare("cache",option+1) == 0)
3963 {
3964 if (*option == '+')
3965 break;
3966 i++;
cristybb503372010-05-27 20:51:26 +00003967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003968 ThrowMogrifyException(OptionError,"MissingArgument",option);
3969 if (IsGeometry(argv[i]) == MagickFalse)
3970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3971 break;
3972 }
3973 if (LocaleCompare("caption",option+1) == 0)
3974 {
3975 if (*option == '+')
3976 break;
3977 i++;
cristybb503372010-05-27 20:51:26 +00003978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003979 ThrowMogrifyException(OptionError,"MissingArgument",option);
3980 break;
3981 }
3982 if (LocaleCompare("channel",option+1) == 0)
3983 {
cristybb503372010-05-27 20:51:26 +00003984 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003985 channel;
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 channel=ParseChannelOption(argv[i]);
3993 if (channel < 0)
3994 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3995 argv[i]);
3996 break;
3997 }
3998 if (LocaleCompare("cdl",option+1) == 0)
3999 {
4000 if (*option == '+')
4001 break;
4002 i++;
cristybb503372010-05-27 20:51:26 +00004003 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004004 ThrowMogrifyException(OptionError,"MissingArgument",option);
4005 break;
4006 }
4007 if (LocaleCompare("charcoal",option+1) == 0)
4008 {
4009 if (*option == '+')
4010 break;
4011 i++;
cristybb503372010-05-27 20:51:26 +00004012 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004013 ThrowMogrifyException(OptionError,"MissingArgument",option);
4014 if (IsGeometry(argv[i]) == MagickFalse)
4015 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4016 break;
4017 }
4018 if (LocaleCompare("chop",option+1) == 0)
4019 {
4020 if (*option == '+')
4021 break;
4022 i++;
cristybb503372010-05-27 20:51:26 +00004023 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004024 ThrowMogrifyException(OptionError,"MissingArgument",option);
4025 if (IsGeometry(argv[i]) == MagickFalse)
4026 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4027 break;
4028 }
cristy1eb45dd2009-09-25 16:38:06 +00004029 if (LocaleCompare("clamp",option+1) == 0)
4030 break;
4031 if (LocaleCompare("clip",option+1) == 0)
4032 break;
cristy3ed852e2009-09-05 21:47:34 +00004033 if (LocaleCompare("clip-mask",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 break;
4041 }
4042 if (LocaleCompare("clut",option+1) == 0)
4043 break;
4044 if (LocaleCompare("coalesce",option+1) == 0)
4045 break;
4046 if (LocaleCompare("colorize",option+1) == 0)
4047 {
4048 if (*option == '+')
4049 break;
4050 i++;
cristybb503372010-05-27 20:51:26 +00004051 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004052 ThrowMogrifyException(OptionError,"MissingArgument",option);
4053 if (IsGeometry(argv[i]) == MagickFalse)
4054 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4055 break;
4056 }
cristye6365592010-04-02 17:31:23 +00004057 if (LocaleCompare("color-matrix",option+1) == 0)
4058 {
cristyb6bd4ad2010-08-08 01:12:27 +00004059 KernelInfo
4060 *kernel_info;
4061
cristye6365592010-04-02 17:31:23 +00004062 if (*option == '+')
4063 break;
4064 i++;
cristybb503372010-05-27 20:51:26 +00004065 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004066 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004067 kernel_info=AcquireKernelInfo(argv[i]);
4068 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004069 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004070 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004071 break;
4072 }
cristy3ed852e2009-09-05 21:47:34 +00004073 if (LocaleCompare("colors",option+1) == 0)
4074 {
4075 if (*option == '+')
4076 break;
4077 i++;
cristybb503372010-05-27 20:51:26 +00004078 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004079 ThrowMogrifyException(OptionError,"MissingArgument",option);
4080 if (IsGeometry(argv[i]) == MagickFalse)
4081 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4082 break;
4083 }
4084 if (LocaleCompare("colorspace",option+1) == 0)
4085 {
cristybb503372010-05-27 20:51:26 +00004086 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004087 colorspace;
4088
4089 if (*option == '+')
4090 break;
4091 i++;
cristybb503372010-05-27 20:51:26 +00004092 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004093 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004094 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004095 argv[i]);
4096 if (colorspace < 0)
4097 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4098 argv[i]);
4099 break;
4100 }
4101 if (LocaleCompare("combine",option+1) == 0)
4102 break;
4103 if (LocaleCompare("comment",option+1) == 0)
4104 {
4105 if (*option == '+')
4106 break;
4107 i++;
cristybb503372010-05-27 20:51:26 +00004108 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004109 ThrowMogrifyException(OptionError,"MissingArgument",option);
4110 break;
4111 }
4112 if (LocaleCompare("composite",option+1) == 0)
4113 break;
4114 if (LocaleCompare("compress",option+1) == 0)
4115 {
cristybb503372010-05-27 20:51:26 +00004116 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004117 compress;
4118
4119 if (*option == '+')
4120 break;
4121 i++;
cristybb503372010-05-27 20:51:26 +00004122 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004123 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004124 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004125 argv[i]);
4126 if (compress < 0)
4127 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4128 argv[i]);
4129 break;
4130 }
cristy22879752009-10-25 23:55:40 +00004131 if (LocaleCompare("concurrent",option+1) == 0)
4132 break;
cristy3ed852e2009-09-05 21:47:34 +00004133 if (LocaleCompare("contrast",option+1) == 0)
4134 break;
4135 if (LocaleCompare("contrast-stretch",option+1) == 0)
4136 {
4137 i++;
cristybb503372010-05-27 20:51:26 +00004138 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004139 ThrowMogrifyException(OptionError,"MissingArgument",option);
4140 if (IsGeometry(argv[i]) == MagickFalse)
4141 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4142 break;
4143 }
4144 if (LocaleCompare("convolve",option+1) == 0)
4145 {
cristyb6bd4ad2010-08-08 01:12:27 +00004146 KernelInfo
4147 *kernel_info;
4148
cristy3ed852e2009-09-05 21:47:34 +00004149 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);
cristyb6bd4ad2010-08-08 01:12:27 +00004154 kernel_info=AcquireKernelInfo(argv[i]);
4155 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004156 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004157 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004158 break;
4159 }
4160 if (LocaleCompare("crop",option+1) == 0)
4161 {
4162 if (*option == '+')
4163 break;
4164 i++;
cristybb503372010-05-27 20:51:26 +00004165 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004166 ThrowMogrifyException(OptionError,"MissingArgument",option);
4167 if (IsGeometry(argv[i]) == MagickFalse)
4168 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4169 break;
4170 }
4171 if (LocaleCompare("cycle",option+1) == 0)
4172 {
4173 if (*option == '+')
4174 break;
4175 i++;
cristybb503372010-05-27 20:51:26 +00004176 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004177 ThrowMogrifyException(OptionError,"MissingArgument",option);
4178 if (IsGeometry(argv[i]) == MagickFalse)
4179 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4180 break;
4181 }
4182 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4183 }
4184 case 'd':
4185 {
4186 if (LocaleCompare("decipher",option+1) == 0)
4187 {
4188 if (*option == '+')
4189 break;
4190 i++;
cristybb503372010-05-27 20:51:26 +00004191 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004192 ThrowMogrifyException(OptionError,"MissingArgument",option);
4193 break;
4194 }
4195 if (LocaleCompare("deconstruct",option+1) == 0)
4196 break;
4197 if (LocaleCompare("debug",option+1) == 0)
4198 {
cristybb503372010-05-27 20:51:26 +00004199 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004200 event;
4201
4202 if (*option == '+')
4203 break;
4204 i++;
cristybb503372010-05-27 20:51:26 +00004205 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004206 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004207 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004208 if (event < 0)
4209 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4210 argv[i]);
4211 (void) SetLogEventMask(argv[i]);
4212 break;
4213 }
4214 if (LocaleCompare("define",option+1) == 0)
4215 {
4216 i++;
cristybb503372010-05-27 20:51:26 +00004217 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004218 ThrowMogrifyException(OptionError,"MissingArgument",option);
4219 if (*option == '+')
4220 {
4221 const char
4222 *define;
4223
4224 define=GetImageOption(image_info,argv[i]);
4225 if (define == (const char *) NULL)
4226 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4227 break;
4228 }
4229 break;
4230 }
4231 if (LocaleCompare("delay",option+1) == 0)
4232 {
4233 if (*option == '+')
4234 break;
4235 i++;
cristybb503372010-05-27 20:51:26 +00004236 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004237 ThrowMogrifyException(OptionError,"MissingArgument",option);
4238 if (IsGeometry(argv[i]) == MagickFalse)
4239 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4240 break;
4241 }
cristyecb10ff2011-03-22 13:14:03 +00004242 if (LocaleCompare("delete",option+1) == 0)
4243 {
4244 if (*option == '+')
4245 break;
4246 i++;
4247 if (i == (ssize_t) (argc-1))
4248 ThrowMogrifyException(OptionError,"MissingArgument",option);
4249 if (IsGeometry(argv[i]) == MagickFalse)
4250 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4251 break;
4252 }
cristy3ed852e2009-09-05 21:47:34 +00004253 if (LocaleCompare("density",option+1) == 0)
4254 {
4255 if (*option == '+')
4256 break;
4257 i++;
cristybb503372010-05-27 20:51:26 +00004258 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004259 ThrowMogrifyException(OptionError,"MissingArgument",option);
4260 if (IsGeometry(argv[i]) == MagickFalse)
4261 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4262 break;
4263 }
4264 if (LocaleCompare("depth",option+1) == 0)
4265 {
4266 if (*option == '+')
4267 break;
4268 i++;
cristybb503372010-05-27 20:51:26 +00004269 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004270 ThrowMogrifyException(OptionError,"MissingArgument",option);
4271 if (IsGeometry(argv[i]) == MagickFalse)
4272 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4273 break;
4274 }
4275 if (LocaleCompare("deskew",option+1) == 0)
4276 {
4277 if (*option == '+')
4278 break;
4279 i++;
cristybb503372010-05-27 20:51:26 +00004280 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004281 ThrowMogrifyException(OptionError,"MissingArgument",option);
4282 if (IsGeometry(argv[i]) == MagickFalse)
4283 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4284 break;
4285 }
4286 if (LocaleCompare("despeckle",option+1) == 0)
4287 break;
4288 if (LocaleCompare("dft",option+1) == 0)
4289 break;
cristyc9b12952010-03-28 01:12:28 +00004290 if (LocaleCompare("direction",option+1) == 0)
4291 {
cristybb503372010-05-27 20:51:26 +00004292 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004293 direction;
4294
4295 if (*option == '+')
4296 break;
4297 i++;
cristybb503372010-05-27 20:51:26 +00004298 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004299 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004300 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004301 argv[i]);
4302 if (direction < 0)
4303 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4304 argv[i]);
4305 break;
4306 }
cristy3ed852e2009-09-05 21:47:34 +00004307 if (LocaleCompare("display",option+1) == 0)
4308 {
4309 if (*option == '+')
4310 break;
4311 i++;
cristybb503372010-05-27 20:51:26 +00004312 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004313 ThrowMogrifyException(OptionError,"MissingArgument",option);
4314 break;
4315 }
4316 if (LocaleCompare("dispose",option+1) == 0)
4317 {
cristybb503372010-05-27 20:51:26 +00004318 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004319 dispose;
4320
4321 if (*option == '+')
4322 break;
4323 i++;
cristybb503372010-05-27 20:51:26 +00004324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004325 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004326 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004327 if (dispose < 0)
4328 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4329 argv[i]);
4330 break;
4331 }
4332 if (LocaleCompare("distort",option+1) == 0)
4333 {
cristybb503372010-05-27 20:51:26 +00004334 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004335 op;
4336
4337 i++;
cristybb503372010-05-27 20:51:26 +00004338 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004339 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004340 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004341 if (op < 0)
4342 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4343 argv[i]);
4344 i++;
cristybb503372010-05-27 20:51:26 +00004345 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004346 ThrowMogrifyException(OptionError,"MissingArgument",option);
4347 break;
4348 }
4349 if (LocaleCompare("dither",option+1) == 0)
4350 {
cristybb503372010-05-27 20:51:26 +00004351 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004352 method;
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);
cristy042ee782011-04-22 18:48:30 +00004359 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004360 if (method < 0)
4361 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4362 argv[i]);
4363 break;
4364 }
4365 if (LocaleCompare("draw",option+1) == 0)
4366 {
4367 if (*option == '+')
4368 break;
4369 i++;
cristybb503372010-05-27 20:51:26 +00004370 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004371 ThrowMogrifyException(OptionError,"MissingArgument",option);
4372 break;
4373 }
cristyecb10ff2011-03-22 13:14:03 +00004374 if (LocaleCompare("duplicate",option+1) == 0)
4375 {
4376 if (*option == '+')
4377 break;
4378 i++;
4379 if (i == (ssize_t) (argc-1))
4380 ThrowMogrifyException(OptionError,"MissingArgument",option);
4381 if (IsGeometry(argv[i]) == MagickFalse)
4382 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4383 break;
4384 }
cristy22879752009-10-25 23:55:40 +00004385 if (LocaleCompare("duration",option+1) == 0)
4386 {
4387 if (*option == '+')
4388 break;
4389 i++;
cristybb503372010-05-27 20:51:26 +00004390 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004391 ThrowMogrifyException(OptionError,"MissingArgument",option);
4392 if (IsGeometry(argv[i]) == MagickFalse)
4393 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4394 break;
4395 }
cristy3ed852e2009-09-05 21:47:34 +00004396 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4397 }
4398 case 'e':
4399 {
4400 if (LocaleCompare("edge",option+1) == 0)
4401 {
4402 if (*option == '+')
4403 break;
4404 i++;
cristybb503372010-05-27 20:51:26 +00004405 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004406 ThrowMogrifyException(OptionError,"MissingArgument",option);
4407 if (IsGeometry(argv[i]) == MagickFalse)
4408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4409 break;
4410 }
4411 if (LocaleCompare("emboss",option+1) == 0)
4412 {
4413 if (*option == '+')
4414 break;
4415 i++;
cristybb503372010-05-27 20:51:26 +00004416 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004417 ThrowMogrifyException(OptionError,"MissingArgument",option);
4418 if (IsGeometry(argv[i]) == MagickFalse)
4419 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4420 break;
4421 }
4422 if (LocaleCompare("encipher",option+1) == 0)
4423 {
4424 if (*option == '+')
4425 break;
4426 i++;
cristybb503372010-05-27 20:51:26 +00004427 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004428 ThrowMogrifyException(OptionError,"MissingArgument",option);
4429 break;
4430 }
4431 if (LocaleCompare("encoding",option+1) == 0)
4432 {
4433 if (*option == '+')
4434 break;
4435 i++;
cristybb503372010-05-27 20:51:26 +00004436 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004437 ThrowMogrifyException(OptionError,"MissingArgument",option);
4438 break;
4439 }
4440 if (LocaleCompare("endian",option+1) == 0)
4441 {
cristybb503372010-05-27 20:51:26 +00004442 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004443 endian;
4444
4445 if (*option == '+')
4446 break;
4447 i++;
cristybb503372010-05-27 20:51:26 +00004448 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004449 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004450 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004451 if (endian < 0)
4452 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4453 argv[i]);
4454 break;
4455 }
4456 if (LocaleCompare("enhance",option+1) == 0)
4457 break;
4458 if (LocaleCompare("equalize",option+1) == 0)
4459 break;
4460 if (LocaleCompare("evaluate",option+1) == 0)
4461 {
cristybb503372010-05-27 20:51:26 +00004462 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004463 op;
4464
4465 if (*option == '+')
4466 break;
4467 i++;
cristybb503372010-05-27 20:51:26 +00004468 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004469 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004470 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004471 if (op < 0)
4472 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4473 argv[i]);
4474 i++;
cristybb503372010-05-27 20:51:26 +00004475 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004476 ThrowMogrifyException(OptionError,"MissingArgument",option);
4477 if (IsGeometry(argv[i]) == MagickFalse)
4478 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4479 break;
4480 }
cristyd18ae7c2010-03-07 17:39:52 +00004481 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4482 {
cristybb503372010-05-27 20:51:26 +00004483 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004484 op;
4485
4486 if (*option == '+')
4487 break;
4488 i++;
cristybb503372010-05-27 20:51:26 +00004489 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004490 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004491 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004492 if (op < 0)
4493 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4494 argv[i]);
4495 break;
4496 }
cristy3ed852e2009-09-05 21:47:34 +00004497 if (LocaleCompare("extent",option+1) == 0)
4498 {
4499 if (*option == '+')
4500 break;
4501 i++;
cristybb503372010-05-27 20:51:26 +00004502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004503 ThrowMogrifyException(OptionError,"MissingArgument",option);
4504 if (IsGeometry(argv[i]) == MagickFalse)
4505 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4506 break;
4507 }
4508 if (LocaleCompare("extract",option+1) == 0)
4509 {
4510 if (*option == '+')
4511 break;
4512 i++;
cristybb503372010-05-27 20:51:26 +00004513 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004514 ThrowMogrifyException(OptionError,"MissingArgument",option);
4515 if (IsGeometry(argv[i]) == MagickFalse)
4516 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4517 break;
4518 }
4519 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4520 }
4521 case 'f':
4522 {
4523 if (LocaleCompare("family",option+1) == 0)
4524 {
4525 if (*option == '+')
4526 break;
4527 i++;
cristybb503372010-05-27 20:51:26 +00004528 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004529 ThrowMogrifyException(OptionError,"MissingArgument",option);
4530 break;
4531 }
4532 if (LocaleCompare("fill",option+1) == 0)
4533 {
4534 if (*option == '+')
4535 break;
4536 i++;
cristybb503372010-05-27 20:51:26 +00004537 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004538 ThrowMogrifyException(OptionError,"MissingArgument",option);
4539 break;
4540 }
4541 if (LocaleCompare("filter",option+1) == 0)
4542 {
cristybb503372010-05-27 20:51:26 +00004543 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004544 filter;
4545
4546 if (*option == '+')
4547 break;
4548 i++;
cristybb503372010-05-27 20:51:26 +00004549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004550 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004551 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004552 if (filter < 0)
4553 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4554 argv[i]);
4555 break;
4556 }
4557 if (LocaleCompare("flatten",option+1) == 0)
4558 break;
4559 if (LocaleCompare("flip",option+1) == 0)
4560 break;
4561 if (LocaleCompare("flop",option+1) == 0)
4562 break;
4563 if (LocaleCompare("floodfill",option+1) == 0)
4564 {
4565 if (*option == '+')
4566 break;
4567 i++;
cristybb503372010-05-27 20:51:26 +00004568 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004569 ThrowMogrifyException(OptionError,"MissingArgument",option);
4570 if (IsGeometry(argv[i]) == MagickFalse)
4571 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4572 i++;
cristybb503372010-05-27 20:51:26 +00004573 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004574 ThrowMogrifyException(OptionError,"MissingArgument",option);
4575 break;
4576 }
4577 if (LocaleCompare("font",option+1) == 0)
4578 {
4579 if (*option == '+')
4580 break;
4581 i++;
cristybb503372010-05-27 20:51:26 +00004582 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004583 ThrowMogrifyException(OptionError,"MissingArgument",option);
4584 break;
4585 }
4586 if (LocaleCompare("format",option+1) == 0)
4587 {
4588 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4589 (void) CloneString(&format,(char *) NULL);
4590 if (*option == '+')
4591 break;
4592 i++;
cristybb503372010-05-27 20:51:26 +00004593 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004594 ThrowMogrifyException(OptionError,"MissingArgument",option);
4595 (void) CloneString(&format,argv[i]);
4596 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4597 (void) ConcatenateMagickString(image_info->filename,":",
4598 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004599 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004600 if (*image_info->magick == '\0')
4601 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4602 format);
4603 break;
4604 }
4605 if (LocaleCompare("frame",option+1) == 0)
4606 {
4607 if (*option == '+')
4608 break;
4609 i++;
cristybb503372010-05-27 20:51:26 +00004610 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004611 ThrowMogrifyException(OptionError,"MissingArgument",option);
4612 if (IsGeometry(argv[i]) == MagickFalse)
4613 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4614 break;
4615 }
4616 if (LocaleCompare("function",option+1) == 0)
4617 {
cristybb503372010-05-27 20:51:26 +00004618 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004619 op;
4620
4621 if (*option == '+')
4622 break;
4623 i++;
cristybb503372010-05-27 20:51:26 +00004624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004625 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004626 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004627 if (op < 0)
4628 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4629 i++;
cristybb503372010-05-27 20:51:26 +00004630 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004631 ThrowMogrifyException(OptionError,"MissingArgument",option);
4632 break;
4633 }
4634 if (LocaleCompare("fuzz",option+1) == 0)
4635 {
4636 if (*option == '+')
4637 break;
4638 i++;
cristybb503372010-05-27 20:51:26 +00004639 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004640 ThrowMogrifyException(OptionError,"MissingArgument",option);
4641 if (IsGeometry(argv[i]) == MagickFalse)
4642 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4643 break;
4644 }
4645 if (LocaleCompare("fx",option+1) == 0)
4646 {
4647 if (*option == '+')
4648 break;
4649 i++;
cristybb503372010-05-27 20:51:26 +00004650 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004651 ThrowMogrifyException(OptionError,"MissingArgument",option);
4652 break;
4653 }
4654 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4655 }
4656 case 'g':
4657 {
4658 if (LocaleCompare("gamma",option+1) == 0)
4659 {
4660 i++;
cristybb503372010-05-27 20:51:26 +00004661 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004662 ThrowMogrifyException(OptionError,"MissingArgument",option);
4663 if (IsGeometry(argv[i]) == MagickFalse)
4664 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4665 break;
4666 }
4667 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4668 (LocaleCompare("gaussian",option+1) == 0))
4669 {
4670 i++;
cristybb503372010-05-27 20:51:26 +00004671 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004672 ThrowMogrifyException(OptionError,"MissingArgument",option);
4673 if (IsGeometry(argv[i]) == MagickFalse)
4674 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4675 break;
4676 }
4677 if (LocaleCompare("geometry",option+1) == 0)
4678 {
4679 if (*option == '+')
4680 break;
4681 i++;
cristybb503372010-05-27 20:51:26 +00004682 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004683 ThrowMogrifyException(OptionError,"MissingArgument",option);
4684 if (IsGeometry(argv[i]) == MagickFalse)
4685 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4686 break;
4687 }
4688 if (LocaleCompare("gravity",option+1) == 0)
4689 {
cristybb503372010-05-27 20:51:26 +00004690 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004691 gravity;
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);
cristy042ee782011-04-22 18:48:30 +00004698 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004699 if (gravity < 0)
4700 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4701 argv[i]);
4702 break;
4703 }
4704 if (LocaleCompare("green-primary",option+1) == 0)
4705 {
4706 if (*option == '+')
4707 break;
4708 i++;
cristybb503372010-05-27 20:51:26 +00004709 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004710 ThrowMogrifyException(OptionError,"MissingArgument",option);
4711 if (IsGeometry(argv[i]) == MagickFalse)
4712 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4713 break;
4714 }
4715 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4716 }
4717 case 'h':
4718 {
4719 if (LocaleCompare("hald-clut",option+1) == 0)
4720 break;
4721 if ((LocaleCompare("help",option+1) == 0) ||
4722 (LocaleCompare("-help",option+1) == 0))
4723 return(MogrifyUsage());
4724 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4725 }
4726 case 'i':
4727 {
4728 if (LocaleCompare("identify",option+1) == 0)
4729 break;
4730 if (LocaleCompare("idft",option+1) == 0)
4731 break;
4732 if (LocaleCompare("implode",option+1) == 0)
4733 {
4734 if (*option == '+')
4735 break;
4736 i++;
cristybb503372010-05-27 20:51:26 +00004737 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004738 ThrowMogrifyException(OptionError,"MissingArgument",option);
4739 if (IsGeometry(argv[i]) == MagickFalse)
4740 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4741 break;
4742 }
4743 if (LocaleCompare("intent",option+1) == 0)
4744 {
cristybb503372010-05-27 20:51:26 +00004745 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004746 intent;
4747
4748 if (*option == '+')
4749 break;
4750 i++;
cristybb503372010-05-27 20:51:26 +00004751 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004752 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004753 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004754 if (intent < 0)
4755 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4756 argv[i]);
4757 break;
4758 }
4759 if (LocaleCompare("interlace",option+1) == 0)
4760 {
cristybb503372010-05-27 20:51:26 +00004761 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004762 interlace;
4763
4764 if (*option == '+')
4765 break;
4766 i++;
cristybb503372010-05-27 20:51:26 +00004767 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004768 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004769 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004770 argv[i]);
4771 if (interlace < 0)
4772 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4773 argv[i]);
4774 break;
4775 }
cristyb32b90a2009-09-07 21:45:48 +00004776 if (LocaleCompare("interline-spacing",option+1) == 0)
4777 {
4778 if (*option == '+')
4779 break;
4780 i++;
cristybb503372010-05-27 20:51:26 +00004781 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004782 ThrowMogrifyException(OptionError,"MissingArgument",option);
4783 if (IsGeometry(argv[i]) == MagickFalse)
4784 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4785 break;
4786 }
cristy3ed852e2009-09-05 21:47:34 +00004787 if (LocaleCompare("interpolate",option+1) == 0)
4788 {
cristybb503372010-05-27 20:51:26 +00004789 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004790 interpolate;
4791
4792 if (*option == '+')
4793 break;
4794 i++;
cristybb503372010-05-27 20:51:26 +00004795 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004796 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004797 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004798 argv[i]);
4799 if (interpolate < 0)
4800 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4801 argv[i]);
4802 break;
4803 }
4804 if (LocaleCompare("interword-spacing",option+1) == 0)
4805 {
4806 if (*option == '+')
4807 break;
4808 i++;
cristybb503372010-05-27 20:51:26 +00004809 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004810 ThrowMogrifyException(OptionError,"MissingArgument",option);
4811 if (IsGeometry(argv[i]) == MagickFalse)
4812 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4813 break;
4814 }
4815 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4816 }
4817 case 'k':
4818 {
4819 if (LocaleCompare("kerning",option+1) == 0)
4820 {
4821 if (*option == '+')
4822 break;
4823 i++;
cristybb503372010-05-27 20:51:26 +00004824 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004825 ThrowMogrifyException(OptionError,"MissingArgument",option);
4826 if (IsGeometry(argv[i]) == MagickFalse)
4827 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4828 break;
4829 }
4830 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4831 }
4832 case 'l':
4833 {
4834 if (LocaleCompare("label",option+1) == 0)
4835 {
4836 if (*option == '+')
4837 break;
4838 i++;
cristybb503372010-05-27 20:51:26 +00004839 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004840 ThrowMogrifyException(OptionError,"MissingArgument",option);
4841 break;
4842 }
4843 if (LocaleCompare("lat",option+1) == 0)
4844 {
4845 if (*option == '+')
4846 break;
4847 i++;
cristybb503372010-05-27 20:51:26 +00004848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004849 ThrowMogrifyException(OptionError,"MissingArgument",option);
4850 if (IsGeometry(argv[i]) == MagickFalse)
4851 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4852 }
4853 if (LocaleCompare("layers",option+1) == 0)
4854 {
cristybb503372010-05-27 20:51:26 +00004855 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004856 type;
4857
4858 if (*option == '+')
4859 break;
4860 i++;
cristybb503372010-05-27 20:51:26 +00004861 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004862 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004863 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004864 if (type < 0)
4865 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4866 argv[i]);
4867 break;
4868 }
4869 if (LocaleCompare("level",option+1) == 0)
4870 {
4871 i++;
cristybb503372010-05-27 20:51:26 +00004872 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004873 ThrowMogrifyException(OptionError,"MissingArgument",option);
4874 if (IsGeometry(argv[i]) == MagickFalse)
4875 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4876 break;
4877 }
4878 if (LocaleCompare("level-colors",option+1) == 0)
4879 {
4880 i++;
cristybb503372010-05-27 20:51:26 +00004881 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004882 ThrowMogrifyException(OptionError,"MissingArgument",option);
4883 break;
4884 }
4885 if (LocaleCompare("linewidth",option+1) == 0)
4886 {
4887 if (*option == '+')
4888 break;
4889 i++;
cristybb503372010-05-27 20:51:26 +00004890 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004891 ThrowMogrifyException(OptionError,"MissingArgument",option);
4892 if (IsGeometry(argv[i]) == MagickFalse)
4893 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4894 break;
4895 }
4896 if (LocaleCompare("limit",option+1) == 0)
4897 {
4898 char
4899 *p;
4900
4901 double
4902 value;
4903
cristybb503372010-05-27 20:51:26 +00004904 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004905 resource;
4906
4907 if (*option == '+')
4908 break;
4909 i++;
cristybb503372010-05-27 20:51:26 +00004910 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004911 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004912 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004913 argv[i]);
4914 if (resource < 0)
4915 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4916 argv[i]);
4917 i++;
cristybb503372010-05-27 20:51:26 +00004918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004919 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004920 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004921 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004922 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4923 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4924 break;
4925 }
4926 if (LocaleCompare("liquid-rescale",option+1) == 0)
4927 {
4928 i++;
cristybb503372010-05-27 20:51:26 +00004929 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004930 ThrowMogrifyException(OptionError,"MissingArgument",option);
4931 if (IsGeometry(argv[i]) == MagickFalse)
4932 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4933 break;
4934 }
4935 if (LocaleCompare("list",option+1) == 0)
4936 {
cristybb503372010-05-27 20:51:26 +00004937 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004938 list;
4939
4940 if (*option == '+')
4941 break;
4942 i++;
cristybb503372010-05-27 20:51:26 +00004943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004944 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004945 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004946 if (list < 0)
4947 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004948 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004949 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004950 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004951 }
4952 if (LocaleCompare("log",option+1) == 0)
4953 {
4954 if (*option == '+')
4955 break;
4956 i++;
cristybb503372010-05-27 20:51:26 +00004957 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004958 (strchr(argv[i],'%') == (char *) NULL))
4959 ThrowMogrifyException(OptionError,"MissingArgument",option);
4960 break;
4961 }
4962 if (LocaleCompare("loop",option+1) == 0)
4963 {
4964 if (*option == '+')
4965 break;
4966 i++;
cristybb503372010-05-27 20:51:26 +00004967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004968 ThrowMogrifyException(OptionError,"MissingArgument",option);
4969 if (IsGeometry(argv[i]) == MagickFalse)
4970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4971 break;
4972 }
4973 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4974 }
4975 case 'm':
4976 {
4977 if (LocaleCompare("map",option+1) == 0)
4978 {
4979 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4980 if (*option == '+')
4981 break;
4982 i++;
cristybb503372010-05-27 20:51:26 +00004983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004984 ThrowMogrifyException(OptionError,"MissingArgument",option);
4985 break;
4986 }
4987 if (LocaleCompare("mask",option+1) == 0)
4988 {
4989 if (*option == '+')
4990 break;
4991 i++;
cristybb503372010-05-27 20:51:26 +00004992 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004993 ThrowMogrifyException(OptionError,"MissingArgument",option);
4994 break;
4995 }
4996 if (LocaleCompare("matte",option+1) == 0)
4997 break;
4998 if (LocaleCompare("mattecolor",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 break;
5006 }
cristyf40785b2010-03-06 02:27:27 +00005007 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005008 break;
cristyf40785b2010-03-06 02:27:27 +00005009 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005010 break;
cristy3ed852e2009-09-05 21:47:34 +00005011 if (LocaleCompare("modulate",option+1) == 0)
5012 {
5013 if (*option == '+')
5014 break;
5015 i++;
cristybb503372010-05-27 20:51:26 +00005016 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005017 ThrowMogrifyException(OptionError,"MissingArgument",option);
5018 if (IsGeometry(argv[i]) == MagickFalse)
5019 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5020 break;
5021 }
5022 if (LocaleCompare("median",option+1) == 0)
5023 {
5024 if (*option == '+')
5025 break;
5026 i++;
cristybb503372010-05-27 20:51:26 +00005027 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005028 ThrowMogrifyException(OptionError,"MissingArgument",option);
5029 if (IsGeometry(argv[i]) == MagickFalse)
5030 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5031 break;
5032 }
cristy69ec32d2011-02-27 23:57:09 +00005033 if (LocaleCompare("mode",option+1) == 0)
5034 {
5035 if (*option == '+')
5036 break;
5037 i++;
5038 if (i == (ssize_t) argc)
5039 ThrowMogrifyException(OptionError,"MissingArgument",option);
5040 if (IsGeometry(argv[i]) == MagickFalse)
5041 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5042 break;
5043 }
cristy3ed852e2009-09-05 21:47:34 +00005044 if (LocaleCompare("monitor",option+1) == 0)
5045 break;
5046 if (LocaleCompare("monochrome",option+1) == 0)
5047 break;
5048 if (LocaleCompare("morph",option+1) == 0)
5049 {
5050 if (*option == '+')
5051 break;
5052 i++;
cristybb503372010-05-27 20:51:26 +00005053 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005054 ThrowMogrifyException(OptionError,"MissingArgument",option);
5055 if (IsGeometry(argv[i]) == MagickFalse)
5056 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5057 break;
5058 }
anthony29188a82010-01-22 10:12:34 +00005059 if (LocaleCompare("morphology",option+1) == 0)
5060 {
anthony29188a82010-01-22 10:12:34 +00005061 char
5062 token[MaxTextExtent];
5063
cristyb6bd4ad2010-08-08 01:12:27 +00005064 KernelInfo
5065 *kernel_info;
5066
5067 ssize_t
5068 op;
5069
anthony29188a82010-01-22 10:12:34 +00005070 i++;
cristybb503372010-05-27 20:51:26 +00005071 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005072 ThrowMogrifyException(OptionError,"MissingArgument",option);
5073 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005074 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005075 if (op < 0)
5076 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005077 token);
anthony29188a82010-01-22 10:12:34 +00005078 i++;
cristybb503372010-05-27 20:51:26 +00005079 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005080 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005081 kernel_info=AcquireKernelInfo(argv[i]);
5082 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005083 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005084 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005085 break;
5086 }
cristy3ed852e2009-09-05 21:47:34 +00005087 if (LocaleCompare("mosaic",option+1) == 0)
5088 break;
5089 if (LocaleCompare("motion-blur",option+1) == 0)
5090 {
5091 if (*option == '+')
5092 break;
5093 i++;
cristybb503372010-05-27 20:51:26 +00005094 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005095 ThrowMogrifyException(OptionError,"MissingArgument",option);
5096 if (IsGeometry(argv[i]) == MagickFalse)
5097 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5098 break;
5099 }
5100 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5101 }
5102 case 'n':
5103 {
5104 if (LocaleCompare("negate",option+1) == 0)
5105 break;
5106 if (LocaleCompare("noise",option+1) == 0)
5107 {
5108 i++;
cristybb503372010-05-27 20:51:26 +00005109 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005110 ThrowMogrifyException(OptionError,"MissingArgument",option);
5111 if (*option == '+')
5112 {
cristybb503372010-05-27 20:51:26 +00005113 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005114 noise;
5115
cristy042ee782011-04-22 18:48:30 +00005116 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005117 if (noise < 0)
5118 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5119 argv[i]);
5120 break;
5121 }
5122 if (IsGeometry(argv[i]) == MagickFalse)
5123 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5124 break;
5125 }
5126 if (LocaleCompare("noop",option+1) == 0)
5127 break;
5128 if (LocaleCompare("normalize",option+1) == 0)
5129 break;
5130 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5131 }
5132 case 'o':
5133 {
5134 if (LocaleCompare("opaque",option+1) == 0)
5135 {
cristy3ed852e2009-09-05 21:47:34 +00005136 i++;
cristybb503372010-05-27 20:51:26 +00005137 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005138 ThrowMogrifyException(OptionError,"MissingArgument",option);
5139 break;
5140 }
5141 if (LocaleCompare("ordered-dither",option+1) == 0)
5142 {
5143 if (*option == '+')
5144 break;
5145 i++;
cristybb503372010-05-27 20:51:26 +00005146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005147 ThrowMogrifyException(OptionError,"MissingArgument",option);
5148 break;
5149 }
5150 if (LocaleCompare("orient",option+1) == 0)
5151 {
cristybb503372010-05-27 20:51:26 +00005152 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005153 orientation;
5154
5155 orientation=UndefinedOrientation;
5156 if (*option == '+')
5157 break;
5158 i++;
cristybb503372010-05-27 20:51:26 +00005159 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005160 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005161 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005162 argv[i]);
5163 if (orientation < 0)
5164 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5165 argv[i]);
5166 break;
5167 }
5168 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5169 }
5170 case 'p':
5171 {
5172 if (LocaleCompare("page",option+1) == 0)
5173 {
5174 if (*option == '+')
5175 break;
5176 i++;
cristybb503372010-05-27 20:51:26 +00005177 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005178 ThrowMogrifyException(OptionError,"MissingArgument",option);
5179 break;
5180 }
5181 if (LocaleCompare("paint",option+1) == 0)
5182 {
5183 if (*option == '+')
5184 break;
5185 i++;
cristybb503372010-05-27 20:51:26 +00005186 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005187 ThrowMogrifyException(OptionError,"MissingArgument",option);
5188 if (IsGeometry(argv[i]) == MagickFalse)
5189 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5190 break;
5191 }
5192 if (LocaleCompare("path",option+1) == 0)
5193 {
5194 (void) CloneString(&path,(char *) NULL);
5195 if (*option == '+')
5196 break;
5197 i++;
cristybb503372010-05-27 20:51:26 +00005198 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005199 ThrowMogrifyException(OptionError,"MissingArgument",option);
5200 (void) CloneString(&path,argv[i]);
5201 break;
5202 }
5203 if (LocaleCompare("pointsize",option+1) == 0)
5204 {
5205 if (*option == '+')
5206 break;
5207 i++;
cristybb503372010-05-27 20:51:26 +00005208 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005209 ThrowMogrifyException(OptionError,"MissingArgument",option);
5210 if (IsGeometry(argv[i]) == MagickFalse)
5211 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5212 break;
5213 }
5214 if (LocaleCompare("polaroid",option+1) == 0)
5215 {
5216 if (*option == '+')
5217 break;
5218 i++;
cristybb503372010-05-27 20:51:26 +00005219 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005220 ThrowMogrifyException(OptionError,"MissingArgument",option);
5221 if (IsGeometry(argv[i]) == MagickFalse)
5222 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5223 break;
5224 }
5225 if (LocaleCompare("posterize",option+1) == 0)
5226 {
5227 if (*option == '+')
5228 break;
5229 i++;
cristybb503372010-05-27 20:51:26 +00005230 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005231 ThrowMogrifyException(OptionError,"MissingArgument",option);
5232 if (IsGeometry(argv[i]) == MagickFalse)
5233 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5234 break;
5235 }
cristye7f51092010-01-17 00:39:37 +00005236 if (LocaleCompare("precision",option+1) == 0)
5237 {
5238 if (*option == '+')
5239 break;
5240 i++;
cristybb503372010-05-27 20:51:26 +00005241 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005242 ThrowMogrifyException(OptionError,"MissingArgument",option);
5243 if (IsGeometry(argv[i]) == MagickFalse)
5244 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5245 break;
5246 }
cristy3ed852e2009-09-05 21:47:34 +00005247 if (LocaleCompare("print",option+1) == 0)
5248 {
5249 if (*option == '+')
5250 break;
5251 i++;
cristybb503372010-05-27 20:51:26 +00005252 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005253 ThrowMogrifyException(OptionError,"MissingArgument",option);
5254 break;
5255 }
5256 if (LocaleCompare("process",option+1) == 0)
5257 {
5258 if (*option == '+')
5259 break;
5260 i++;
cristybb503372010-05-27 20:51:26 +00005261 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005262 ThrowMogrifyException(OptionError,"MissingArgument",option);
5263 break;
5264 }
5265 if (LocaleCompare("profile",option+1) == 0)
5266 {
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 break;
5271 }
5272 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5273 }
5274 case 'q':
5275 {
5276 if (LocaleCompare("quality",option+1) == 0)
5277 {
5278 if (*option == '+')
5279 break;
5280 i++;
cristybb503372010-05-27 20:51:26 +00005281 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005282 ThrowMogrifyException(OptionError,"MissingArgument",option);
5283 if (IsGeometry(argv[i]) == MagickFalse)
5284 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5285 break;
5286 }
5287 if (LocaleCompare("quantize",option+1) == 0)
5288 {
cristybb503372010-05-27 20:51:26 +00005289 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005290 colorspace;
5291
5292 if (*option == '+')
5293 break;
5294 i++;
cristybb503372010-05-27 20:51:26 +00005295 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005296 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005297 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005298 argv[i]);
5299 if (colorspace < 0)
5300 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5301 argv[i]);
5302 break;
5303 }
5304 if (LocaleCompare("quiet",option+1) == 0)
5305 break;
5306 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5307 }
5308 case 'r':
5309 {
5310 if (LocaleCompare("radial-blur",option+1) == 0)
5311 {
5312 i++;
cristybb503372010-05-27 20:51:26 +00005313 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005314 ThrowMogrifyException(OptionError,"MissingArgument",option);
5315 if (IsGeometry(argv[i]) == MagickFalse)
5316 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5317 break;
5318 }
5319 if (LocaleCompare("raise",option+1) == 0)
5320 {
5321 i++;
cristybb503372010-05-27 20:51:26 +00005322 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005323 ThrowMogrifyException(OptionError,"MissingArgument",option);
5324 if (IsGeometry(argv[i]) == MagickFalse)
5325 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5326 break;
5327 }
5328 if (LocaleCompare("random-threshold",option+1) == 0)
5329 {
5330 if (*option == '+')
5331 break;
5332 i++;
cristybb503372010-05-27 20:51:26 +00005333 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005334 ThrowMogrifyException(OptionError,"MissingArgument",option);
5335 if (IsGeometry(argv[i]) == MagickFalse)
5336 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5337 break;
5338 }
cristye6365592010-04-02 17:31:23 +00005339 if (LocaleCompare("recolor",option+1) == 0)
5340 {
5341 if (*option == '+')
5342 break;
5343 i++;
cristybb503372010-05-27 20:51:26 +00005344 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005345 ThrowMogrifyException(OptionError,"MissingArgument",option);
5346 if (IsGeometry(argv[i]) == MagickFalse)
5347 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5348 break;
5349 }
cristy3ed852e2009-09-05 21:47:34 +00005350 if (LocaleCompare("red-primary",option+1) == 0)
5351 {
5352 if (*option == '+')
5353 break;
5354 i++;
cristybb503372010-05-27 20:51:26 +00005355 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005356 ThrowMogrifyException(OptionError,"MissingArgument",option);
5357 if (IsGeometry(argv[i]) == MagickFalse)
5358 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5359 }
cristy9f2083a2010-04-22 19:48:05 +00005360 if (LocaleCompare("regard-warnings",option+1) == 0)
5361 break;
cristy3ed852e2009-09-05 21:47:34 +00005362 if (LocaleCompare("region",option+1) == 0)
5363 {
5364 if (*option == '+')
5365 break;
5366 i++;
cristybb503372010-05-27 20:51:26 +00005367 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005368 ThrowMogrifyException(OptionError,"MissingArgument",option);
5369 if (IsGeometry(argv[i]) == MagickFalse)
5370 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5371 break;
5372 }
cristyf0c78232010-03-15 12:53:40 +00005373 if (LocaleCompare("remap",option+1) == 0)
5374 {
5375 if (*option == '+')
5376 break;
5377 i++;
cristybb503372010-05-27 20:51:26 +00005378 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005379 ThrowMogrifyException(OptionError,"MissingArgument",option);
5380 break;
5381 }
cristy3ed852e2009-09-05 21:47:34 +00005382 if (LocaleCompare("render",option+1) == 0)
5383 break;
5384 if (LocaleCompare("repage",option+1) == 0)
5385 {
5386 if (*option == '+')
5387 break;
5388 i++;
cristybb503372010-05-27 20:51:26 +00005389 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005390 ThrowMogrifyException(OptionError,"MissingArgument",option);
5391 if (IsGeometry(argv[i]) == MagickFalse)
5392 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5393 break;
5394 }
5395 if (LocaleCompare("resample",option+1) == 0)
5396 {
5397 if (*option == '+')
5398 break;
5399 i++;
cristybb503372010-05-27 20:51:26 +00005400 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005401 ThrowMogrifyException(OptionError,"MissingArgument",option);
5402 if (IsGeometry(argv[i]) == MagickFalse)
5403 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5404 break;
5405 }
5406 if (LocaleCompare("resize",option+1) == 0)
5407 {
5408 if (*option == '+')
5409 break;
5410 i++;
cristybb503372010-05-27 20:51:26 +00005411 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005412 ThrowMogrifyException(OptionError,"MissingArgument",option);
5413 if (IsGeometry(argv[i]) == MagickFalse)
5414 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5415 break;
5416 }
cristyebbcfea2011-02-25 02:43:54 +00005417 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5418 {
5419 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5420 break;
5421 }
cristy3ed852e2009-09-05 21:47:34 +00005422 if (LocaleCompare("reverse",option+1) == 0)
5423 break;
5424 if (LocaleCompare("roll",option+1) == 0)
5425 {
5426 if (*option == '+')
5427 break;
5428 i++;
cristybb503372010-05-27 20:51:26 +00005429 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005430 ThrowMogrifyException(OptionError,"MissingArgument",option);
5431 if (IsGeometry(argv[i]) == MagickFalse)
5432 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5433 break;
5434 }
5435 if (LocaleCompare("rotate",option+1) == 0)
5436 {
5437 i++;
cristybb503372010-05-27 20:51:26 +00005438 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005439 ThrowMogrifyException(OptionError,"MissingArgument",option);
5440 if (IsGeometry(argv[i]) == MagickFalse)
5441 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5442 break;
5443 }
5444 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5445 }
5446 case 's':
5447 {
5448 if (LocaleCompare("sample",option+1) == 0)
5449 {
5450 if (*option == '+')
5451 break;
5452 i++;
cristybb503372010-05-27 20:51:26 +00005453 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005454 ThrowMogrifyException(OptionError,"MissingArgument",option);
5455 if (IsGeometry(argv[i]) == MagickFalse)
5456 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5457 break;
5458 }
5459 if (LocaleCompare("sampling-factor",option+1) == 0)
5460 {
5461 if (*option == '+')
5462 break;
5463 i++;
cristybb503372010-05-27 20:51:26 +00005464 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005465 ThrowMogrifyException(OptionError,"MissingArgument",option);
5466 if (IsGeometry(argv[i]) == MagickFalse)
5467 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5468 break;
5469 }
5470 if (LocaleCompare("scale",option+1) == 0)
5471 {
5472 if (*option == '+')
5473 break;
5474 i++;
cristybb503372010-05-27 20:51:26 +00005475 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005476 ThrowMogrifyException(OptionError,"MissingArgument",option);
5477 if (IsGeometry(argv[i]) == MagickFalse)
5478 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5479 break;
5480 }
5481 if (LocaleCompare("scene",option+1) == 0)
5482 {
5483 if (*option == '+')
5484 break;
5485 i++;
cristybb503372010-05-27 20:51:26 +00005486 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005487 ThrowMogrifyException(OptionError,"MissingArgument",option);
5488 if (IsGeometry(argv[i]) == MagickFalse)
5489 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5490 break;
5491 }
5492 if (LocaleCompare("seed",option+1) == 0)
5493 {
5494 if (*option == '+')
5495 break;
5496 i++;
cristybb503372010-05-27 20:51:26 +00005497 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005498 ThrowMogrifyException(OptionError,"MissingArgument",option);
5499 if (IsGeometry(argv[i]) == MagickFalse)
5500 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5501 break;
5502 }
5503 if (LocaleCompare("segment",option+1) == 0)
5504 {
5505 if (*option == '+')
5506 break;
5507 i++;
cristybb503372010-05-27 20:51:26 +00005508 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005509 ThrowMogrifyException(OptionError,"MissingArgument",option);
5510 if (IsGeometry(argv[i]) == MagickFalse)
5511 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5512 break;
5513 }
5514 if (LocaleCompare("selective-blur",option+1) == 0)
5515 {
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("separate",option+1) == 0)
5524 break;
5525 if (LocaleCompare("sepia-tone",option+1) == 0)
5526 {
5527 if (*option == '+')
5528 break;
5529 i++;
cristybb503372010-05-27 20:51:26 +00005530 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005531 ThrowMogrifyException(OptionError,"MissingArgument",option);
5532 if (IsGeometry(argv[i]) == MagickFalse)
5533 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5534 break;
5535 }
5536 if (LocaleCompare("set",option+1) == 0)
5537 {
5538 i++;
cristybb503372010-05-27 20:51:26 +00005539 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005540 ThrowMogrifyException(OptionError,"MissingArgument",option);
5541 if (*option == '+')
5542 break;
5543 i++;
cristybb503372010-05-27 20:51:26 +00005544 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005545 ThrowMogrifyException(OptionError,"MissingArgument",option);
5546 break;
5547 }
5548 if (LocaleCompare("shade",option+1) == 0)
5549 {
5550 i++;
cristybb503372010-05-27 20:51:26 +00005551 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005552 ThrowMogrifyException(OptionError,"MissingArgument",option);
5553 if (IsGeometry(argv[i]) == MagickFalse)
5554 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5555 break;
5556 }
5557 if (LocaleCompare("shadow",option+1) == 0)
5558 {
5559 if (*option == '+')
5560 break;
5561 i++;
cristybb503372010-05-27 20:51:26 +00005562 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005563 ThrowMogrifyException(OptionError,"MissingArgument",option);
5564 if (IsGeometry(argv[i]) == MagickFalse)
5565 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5566 break;
5567 }
5568 if (LocaleCompare("sharpen",option+1) == 0)
5569 {
5570 i++;
cristybb503372010-05-27 20:51:26 +00005571 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005572 ThrowMogrifyException(OptionError,"MissingArgument",option);
5573 if (IsGeometry(argv[i]) == MagickFalse)
5574 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5575 break;
5576 }
5577 if (LocaleCompare("shave",option+1) == 0)
5578 {
5579 if (*option == '+')
5580 break;
5581 i++;
cristybb503372010-05-27 20:51:26 +00005582 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005583 ThrowMogrifyException(OptionError,"MissingArgument",option);
5584 if (IsGeometry(argv[i]) == MagickFalse)
5585 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5586 break;
5587 }
5588 if (LocaleCompare("shear",option+1) == 0)
5589 {
5590 i++;
cristybb503372010-05-27 20:51:26 +00005591 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005592 ThrowMogrifyException(OptionError,"MissingArgument",option);
5593 if (IsGeometry(argv[i]) == MagickFalse)
5594 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5595 break;
5596 }
5597 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5598 {
5599 i++;
cristybb503372010-05-27 20:51:26 +00005600 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005601 ThrowMogrifyException(OptionError,"MissingArgument",option);
5602 if (IsGeometry(argv[i]) == MagickFalse)
5603 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5604 break;
5605 }
5606 if (LocaleCompare("size",option+1) == 0)
5607 {
5608 if (*option == '+')
5609 break;
5610 i++;
cristybb503372010-05-27 20:51:26 +00005611 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005612 ThrowMogrifyException(OptionError,"MissingArgument",option);
5613 if (IsGeometry(argv[i]) == MagickFalse)
5614 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5615 break;
5616 }
5617 if (LocaleCompare("sketch",option+1) == 0)
5618 {
5619 if (*option == '+')
5620 break;
5621 i++;
cristybb503372010-05-27 20:51:26 +00005622 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005623 ThrowMogrifyException(OptionError,"MissingArgument",option);
5624 if (IsGeometry(argv[i]) == MagickFalse)
5625 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5626 break;
5627 }
cristy4285d782011-02-09 20:12:28 +00005628 if (LocaleCompare("smush",option+1) == 0)
5629 {
cristy4285d782011-02-09 20:12:28 +00005630 i++;
5631 if (i == (ssize_t) argc)
5632 ThrowMogrifyException(OptionError,"MissingArgument",option);
5633 if (IsGeometry(argv[i]) == MagickFalse)
5634 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005635 i++;
5636 break;
5637 }
cristy3ed852e2009-09-05 21:47:34 +00005638 if (LocaleCompare("solarize",option+1) == 0)
5639 {
5640 if (*option == '+')
5641 break;
5642 i++;
cristybb503372010-05-27 20:51:26 +00005643 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005644 ThrowMogrifyException(OptionError,"MissingArgument",option);
5645 if (IsGeometry(argv[i]) == MagickFalse)
5646 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5647 break;
5648 }
5649 if (LocaleCompare("sparse-color",option+1) == 0)
5650 {
cristybb503372010-05-27 20:51:26 +00005651 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005652 op;
5653
5654 i++;
cristybb503372010-05-27 20:51:26 +00005655 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005656 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005657 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005658 if (op < 0)
5659 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5660 argv[i]);
5661 i++;
cristybb503372010-05-27 20:51:26 +00005662 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005663 ThrowMogrifyException(OptionError,"MissingArgument",option);
5664 break;
5665 }
5666 if (LocaleCompare("spread",option+1) == 0)
5667 {
5668 if (*option == '+')
5669 break;
5670 i++;
cristybb503372010-05-27 20:51:26 +00005671 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005672 ThrowMogrifyException(OptionError,"MissingArgument",option);
5673 if (IsGeometry(argv[i]) == MagickFalse)
5674 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5675 break;
5676 }
cristy0834d642011-03-18 18:26:08 +00005677 if (LocaleCompare("statistic",option+1) == 0)
5678 {
5679 ssize_t
5680 op;
5681
5682 if (*option == '+')
5683 break;
5684 i++;
5685 if (i == (ssize_t) argc)
5686 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005687 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005688 if (op < 0)
5689 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5690 argv[i]);
5691 i++;
5692 if (i == (ssize_t) (argc-1))
5693 ThrowMogrifyException(OptionError,"MissingArgument",option);
5694 if (IsGeometry(argv[i]) == MagickFalse)
5695 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5696 break;
5697 }
cristy3ed852e2009-09-05 21:47:34 +00005698 if (LocaleCompare("stretch",option+1) == 0)
5699 {
cristybb503372010-05-27 20:51:26 +00005700 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005701 stretch;
5702
5703 if (*option == '+')
5704 break;
5705 i++;
cristybb503372010-05-27 20:51:26 +00005706 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005707 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005708 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005709 if (stretch < 0)
5710 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5711 argv[i]);
5712 break;
5713 }
5714 if (LocaleCompare("strip",option+1) == 0)
5715 break;
5716 if (LocaleCompare("stroke",option+1) == 0)
5717 {
5718 if (*option == '+')
5719 break;
5720 i++;
cristybb503372010-05-27 20:51:26 +00005721 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005722 ThrowMogrifyException(OptionError,"MissingArgument",option);
5723 break;
5724 }
5725 if (LocaleCompare("strokewidth",option+1) == 0)
5726 {
5727 if (*option == '+')
5728 break;
5729 i++;
cristybb503372010-05-27 20:51:26 +00005730 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005731 ThrowMogrifyException(OptionError,"MissingArgument",option);
5732 if (IsGeometry(argv[i]) == MagickFalse)
5733 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5734 break;
5735 }
5736 if (LocaleCompare("style",option+1) == 0)
5737 {
cristybb503372010-05-27 20:51:26 +00005738 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005739 style;
5740
5741 if (*option == '+')
5742 break;
5743 i++;
cristybb503372010-05-27 20:51:26 +00005744 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005745 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005746 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005747 if (style < 0)
5748 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5749 argv[i]);
5750 break;
5751 }
cristyecb10ff2011-03-22 13:14:03 +00005752 if (LocaleCompare("swap",option+1) == 0)
5753 {
5754 if (*option == '+')
5755 break;
5756 i++;
5757 if (i == (ssize_t) (argc-1))
5758 ThrowMogrifyException(OptionError,"MissingArgument",option);
5759 if (IsGeometry(argv[i]) == MagickFalse)
5760 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5761 break;
5762 }
cristy3ed852e2009-09-05 21:47:34 +00005763 if (LocaleCompare("swirl",option+1) == 0)
5764 {
5765 if (*option == '+')
5766 break;
5767 i++;
cristybb503372010-05-27 20:51:26 +00005768 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005769 ThrowMogrifyException(OptionError,"MissingArgument",option);
5770 if (IsGeometry(argv[i]) == MagickFalse)
5771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5772 break;
5773 }
cristyd9a29192010-10-16 16:49:53 +00005774 if (LocaleCompare("synchronize",option+1) == 0)
5775 break;
cristy3ed852e2009-09-05 21:47:34 +00005776 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5777 }
5778 case 't':
5779 {
5780 if (LocaleCompare("taint",option+1) == 0)
5781 break;
5782 if (LocaleCompare("texture",option+1) == 0)
5783 {
5784 if (*option == '+')
5785 break;
5786 i++;
cristybb503372010-05-27 20:51:26 +00005787 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005788 ThrowMogrifyException(OptionError,"MissingArgument",option);
5789 break;
5790 }
5791 if (LocaleCompare("tile",option+1) == 0)
5792 {
5793 if (*option == '+')
5794 break;
5795 i++;
cristybb503372010-05-27 20:51:26 +00005796 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005797 ThrowMogrifyException(OptionError,"MissingArgument",option);
5798 break;
5799 }
5800 if (LocaleCompare("tile-offset",option+1) == 0)
5801 {
5802 if (*option == '+')
5803 break;
5804 i++;
cristybb503372010-05-27 20:51:26 +00005805 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005806 ThrowMogrifyException(OptionError,"MissingArgument",option);
5807 if (IsGeometry(argv[i]) == MagickFalse)
5808 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5809 break;
5810 }
5811 if (LocaleCompare("tint",option+1) == 0)
5812 {
5813 if (*option == '+')
5814 break;
5815 i++;
cristybb503372010-05-27 20:51:26 +00005816 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005817 ThrowMogrifyException(OptionError,"MissingArgument",option);
5818 if (IsGeometry(argv[i]) == MagickFalse)
5819 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5820 break;
5821 }
5822 if (LocaleCompare("transform",option+1) == 0)
5823 break;
5824 if (LocaleCompare("transpose",option+1) == 0)
5825 break;
5826 if (LocaleCompare("transverse",option+1) == 0)
5827 break;
5828 if (LocaleCompare("threshold",option+1) == 0)
5829 {
5830 if (*option == '+')
5831 break;
5832 i++;
cristybb503372010-05-27 20:51:26 +00005833 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005834 ThrowMogrifyException(OptionError,"MissingArgument",option);
5835 if (IsGeometry(argv[i]) == MagickFalse)
5836 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5837 break;
5838 }
5839 if (LocaleCompare("thumbnail",option+1) == 0)
5840 {
5841 if (*option == '+')
5842 break;
5843 i++;
cristybb503372010-05-27 20:51:26 +00005844 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005845 ThrowMogrifyException(OptionError,"MissingArgument",option);
5846 if (IsGeometry(argv[i]) == MagickFalse)
5847 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5848 break;
5849 }
5850 if (LocaleCompare("transparent",option+1) == 0)
5851 {
5852 i++;
cristybb503372010-05-27 20:51:26 +00005853 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005854 ThrowMogrifyException(OptionError,"MissingArgument",option);
5855 break;
5856 }
5857 if (LocaleCompare("transparent-color",option+1) == 0)
5858 {
5859 if (*option == '+')
5860 break;
5861 i++;
cristybb503372010-05-27 20:51:26 +00005862 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005863 ThrowMogrifyException(OptionError,"MissingArgument",option);
5864 break;
5865 }
5866 if (LocaleCompare("treedepth",option+1) == 0)
5867 {
5868 if (*option == '+')
5869 break;
5870 i++;
cristybb503372010-05-27 20:51:26 +00005871 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005872 ThrowMogrifyException(OptionError,"MissingArgument",option);
5873 if (IsGeometry(argv[i]) == MagickFalse)
5874 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5875 break;
5876 }
5877 if (LocaleCompare("trim",option+1) == 0)
5878 break;
5879 if (LocaleCompare("type",option+1) == 0)
5880 {
cristybb503372010-05-27 20:51:26 +00005881 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005882 type;
5883
5884 if (*option == '+')
5885 break;
5886 i++;
cristybb503372010-05-27 20:51:26 +00005887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005888 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005889 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005890 if (type < 0)
5891 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5892 argv[i]);
5893 break;
5894 }
5895 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5896 }
5897 case 'u':
5898 {
5899 if (LocaleCompare("undercolor",option+1) == 0)
5900 {
5901 if (*option == '+')
5902 break;
5903 i++;
cristybb503372010-05-27 20:51:26 +00005904 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005905 ThrowMogrifyException(OptionError,"MissingArgument",option);
5906 break;
5907 }
5908 if (LocaleCompare("unique-colors",option+1) == 0)
5909 break;
5910 if (LocaleCompare("units",option+1) == 0)
5911 {
cristybb503372010-05-27 20:51:26 +00005912 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005913 units;
5914
5915 if (*option == '+')
5916 break;
5917 i++;
cristybb503372010-05-27 20:51:26 +00005918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005919 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005920 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005921 argv[i]);
5922 if (units < 0)
5923 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5924 argv[i]);
5925 break;
5926 }
5927 if (LocaleCompare("unsharp",option+1) == 0)
5928 {
5929 i++;
cristybb503372010-05-27 20:51:26 +00005930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005931 ThrowMogrifyException(OptionError,"MissingArgument",option);
5932 if (IsGeometry(argv[i]) == MagickFalse)
5933 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5934 break;
5935 }
5936 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5937 }
5938 case 'v':
5939 {
5940 if (LocaleCompare("verbose",option+1) == 0)
5941 {
5942 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5943 break;
5944 }
5945 if ((LocaleCompare("version",option+1) == 0) ||
5946 (LocaleCompare("-version",option+1) == 0))
5947 {
cristyb51dff52011-05-19 16:55:47 +00005948 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005949 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005950 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5951 GetMagickCopyright());
5952 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5953 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005954 break;
5955 }
5956 if (LocaleCompare("view",option+1) == 0)
5957 {
5958 if (*option == '+')
5959 break;
5960 i++;
cristybb503372010-05-27 20:51:26 +00005961 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005962 ThrowMogrifyException(OptionError,"MissingArgument",option);
5963 break;
5964 }
5965 if (LocaleCompare("vignette",option+1) == 0)
5966 {
5967 if (*option == '+')
5968 break;
5969 i++;
cristybb503372010-05-27 20:51:26 +00005970 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005971 ThrowMogrifyException(OptionError,"MissingArgument",option);
5972 if (IsGeometry(argv[i]) == MagickFalse)
5973 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5974 break;
5975 }
5976 if (LocaleCompare("virtual-pixel",option+1) == 0)
5977 {
cristybb503372010-05-27 20:51:26 +00005978 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005979 method;
5980
5981 if (*option == '+')
5982 break;
5983 i++;
cristybb503372010-05-27 20:51:26 +00005984 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005985 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005986 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005987 argv[i]);
5988 if (method < 0)
5989 ThrowMogrifyException(OptionError,
5990 "UnrecognizedVirtualPixelMethod",argv[i]);
5991 break;
5992 }
5993 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5994 }
5995 case 'w':
5996 {
5997 if (LocaleCompare("wave",option+1) == 0)
5998 {
5999 i++;
cristybb503372010-05-27 20:51:26 +00006000 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006001 ThrowMogrifyException(OptionError,"MissingArgument",option);
6002 if (IsGeometry(argv[i]) == MagickFalse)
6003 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6004 break;
6005 }
6006 if (LocaleCompare("weight",option+1) == 0)
6007 {
6008 if (*option == '+')
6009 break;
6010 i++;
cristybb503372010-05-27 20:51:26 +00006011 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006012 ThrowMogrifyException(OptionError,"MissingArgument",option);
6013 break;
6014 }
6015 if (LocaleCompare("white-point",option+1) == 0)
6016 {
6017 if (*option == '+')
6018 break;
6019 i++;
cristybb503372010-05-27 20:51:26 +00006020 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006021 ThrowMogrifyException(OptionError,"MissingArgument",option);
6022 if (IsGeometry(argv[i]) == MagickFalse)
6023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6024 break;
6025 }
6026 if (LocaleCompare("white-threshold",option+1) == 0)
6027 {
6028 if (*option == '+')
6029 break;
6030 i++;
cristybb503372010-05-27 20:51:26 +00006031 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006032 ThrowMogrifyException(OptionError,"MissingArgument",option);
6033 if (IsGeometry(argv[i]) == MagickFalse)
6034 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6035 break;
6036 }
6037 if (LocaleCompare("write",option+1) == 0)
6038 {
6039 i++;
cristybb503372010-05-27 20:51:26 +00006040 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006041 ThrowMogrifyException(OptionError,"MissingArgument",option);
6042 break;
6043 }
6044 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6045 }
6046 case '?':
6047 break;
6048 default:
6049 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6050 }
cristy042ee782011-04-22 18:48:30 +00006051 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6052 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006053 if (fire != MagickFalse)
6054 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6055 }
6056 if (k != 0)
6057 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006058 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006059 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6060 DestroyMogrify();
6061 return(status != 0 ? MagickTrue : MagickFalse);
6062}
6063
6064/*
6065%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6066% %
6067% %
6068% %
6069+ M o g r i f y I m a g e I n f o %
6070% %
6071% %
6072% %
6073%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6074%
6075% MogrifyImageInfo() applies image processing settings to the image as
6076% prescribed by command line options.
6077%
6078% The format of the MogrifyImageInfo method is:
6079%
6080% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6081% const char **argv,ExceptionInfo *exception)
6082%
6083% A description of each parameter follows:
6084%
6085% o image_info: the image info..
6086%
6087% o argc: Specifies a pointer to an integer describing the number of
6088% elements in the argument vector.
6089%
6090% o argv: Specifies a pointer to a text array containing the command line
6091% arguments.
6092%
6093% o exception: return any errors or warnings in this structure.
6094%
6095*/
6096WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6097 const int argc,const char **argv,ExceptionInfo *exception)
6098{
6099 const char
6100 *option;
6101
6102 GeometryInfo
6103 geometry_info;
6104
cristybb503372010-05-27 20:51:26 +00006105 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006106 count;
6107
cristybb503372010-05-27 20:51:26 +00006108 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006109 i;
6110
6111 /*
6112 Initialize method variables.
6113 */
6114 assert(image_info != (ImageInfo *) NULL);
6115 assert(image_info->signature == MagickSignature);
6116 if (image_info->debug != MagickFalse)
6117 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6118 image_info->filename);
6119 if (argc < 0)
6120 return(MagickTrue);
6121 /*
6122 Set the image settings.
6123 */
cristybb503372010-05-27 20:51:26 +00006124 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006125 {
6126 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006127 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006128 continue;
cristy042ee782011-04-22 18:48:30 +00006129 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006130 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006131 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006132 break;
6133 switch (*(option+1))
6134 {
6135 case 'a':
6136 {
6137 if (LocaleCompare("adjoin",option+1) == 0)
6138 {
6139 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6140 break;
6141 }
6142 if (LocaleCompare("antialias",option+1) == 0)
6143 {
6144 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6145 break;
6146 }
6147 if (LocaleCompare("attenuate",option+1) == 0)
6148 {
6149 if (*option == '+')
6150 {
6151 (void) DeleteImageOption(image_info,option+1);
6152 break;
6153 }
6154 (void) SetImageOption(image_info,option+1,argv[i+1]);
6155 break;
6156 }
6157 if (LocaleCompare("authenticate",option+1) == 0)
6158 {
6159 if (*option == '+')
6160 (void) CloneString(&image_info->authenticate,(char *) NULL);
6161 else
6162 (void) CloneString(&image_info->authenticate,argv[i+1]);
6163 break;
6164 }
6165 break;
6166 }
6167 case 'b':
6168 {
6169 if (LocaleCompare("background",option+1) == 0)
6170 {
6171 if (*option == '+')
6172 {
6173 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006174 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006175 &image_info->background_color,exception);
6176 break;
6177 }
6178 (void) SetImageOption(image_info,option+1,argv[i+1]);
6179 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6180 exception);
6181 break;
6182 }
6183 if (LocaleCompare("bias",option+1) == 0)
6184 {
6185 if (*option == '+')
6186 {
6187 (void) SetImageOption(image_info,option+1,"0.0");
6188 break;
6189 }
6190 (void) SetImageOption(image_info,option+1,argv[i+1]);
6191 break;
6192 }
6193 if (LocaleCompare("black-point-compensation",option+1) == 0)
6194 {
6195 if (*option == '+')
6196 {
6197 (void) SetImageOption(image_info,option+1,"false");
6198 break;
6199 }
6200 (void) SetImageOption(image_info,option+1,"true");
6201 break;
6202 }
6203 if (LocaleCompare("blue-primary",option+1) == 0)
6204 {
6205 if (*option == '+')
6206 {
6207 (void) SetImageOption(image_info,option+1,"0.0");
6208 break;
6209 }
6210 (void) SetImageOption(image_info,option+1,argv[i+1]);
6211 break;
6212 }
6213 if (LocaleCompare("bordercolor",option+1) == 0)
6214 {
6215 if (*option == '+')
6216 {
6217 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006218 (void) QueryColorDatabase(MogrifyBorderColor,
6219 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006220 break;
6221 }
6222 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6223 exception);
6224 (void) SetImageOption(image_info,option+1,argv[i+1]);
6225 break;
6226 }
6227 if (LocaleCompare("box",option+1) == 0)
6228 {
6229 if (*option == '+')
6230 {
6231 (void) SetImageOption(image_info,"undercolor","none");
6232 break;
6233 }
6234 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6235 break;
6236 }
6237 break;
6238 }
6239 case 'c':
6240 {
6241 if (LocaleCompare("cache",option+1) == 0)
6242 {
6243 MagickSizeType
6244 limit;
6245
6246 limit=MagickResourceInfinity;
6247 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006248 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006249 (void) SetMagickResourceLimit(MemoryResource,limit);
6250 (void) SetMagickResourceLimit(MapResource,2*limit);
6251 break;
6252 }
6253 if (LocaleCompare("caption",option+1) == 0)
6254 {
6255 if (*option == '+')
6256 {
6257 (void) DeleteImageOption(image_info,option+1);
6258 break;
6259 }
6260 (void) SetImageOption(image_info,option+1,argv[i+1]);
6261 break;
6262 }
6263 if (LocaleCompare("channel",option+1) == 0)
6264 {
6265 if (*option == '+')
6266 {
6267 image_info->channel=DefaultChannels;
6268 break;
6269 }
6270 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6271 break;
6272 }
6273 if (LocaleCompare("colors",option+1) == 0)
6274 {
cristye27293e2009-12-18 02:53:20 +00006275 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006276 break;
6277 }
6278 if (LocaleCompare("colorspace",option+1) == 0)
6279 {
6280 if (*option == '+')
6281 {
6282 image_info->colorspace=UndefinedColorspace;
6283 (void) SetImageOption(image_info,option+1,"undefined");
6284 break;
6285 }
cristy042ee782011-04-22 18:48:30 +00006286 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006287 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6288 (void) SetImageOption(image_info,option+1,argv[i+1]);
6289 break;
6290 }
cristy3ed852e2009-09-05 21:47:34 +00006291 if (LocaleCompare("comment",option+1) == 0)
6292 {
6293 if (*option == '+')
6294 {
6295 (void) DeleteImageOption(image_info,option+1);
6296 break;
6297 }
6298 (void) SetImageOption(image_info,option+1,argv[i+1]);
6299 break;
6300 }
6301 if (LocaleCompare("compose",option+1) == 0)
6302 {
6303 if (*option == '+')
6304 {
6305 (void) SetImageOption(image_info,option+1,"undefined");
6306 break;
6307 }
6308 (void) SetImageOption(image_info,option+1,argv[i+1]);
6309 break;
6310 }
6311 if (LocaleCompare("compress",option+1) == 0)
6312 {
6313 if (*option == '+')
6314 {
6315 image_info->compression=UndefinedCompression;
6316 (void) SetImageOption(image_info,option+1,"undefined");
6317 break;
6318 }
cristy042ee782011-04-22 18:48:30 +00006319 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006320 MagickCompressOptions,MagickFalse,argv[i+1]);
6321 (void) SetImageOption(image_info,option+1,argv[i+1]);
6322 break;
6323 }
6324 break;
6325 }
6326 case 'd':
6327 {
6328 if (LocaleCompare("debug",option+1) == 0)
6329 {
6330 if (*option == '+')
6331 (void) SetLogEventMask("none");
6332 else
6333 (void) SetLogEventMask(argv[i+1]);
6334 image_info->debug=IsEventLogging();
6335 break;
6336 }
6337 if (LocaleCompare("define",option+1) == 0)
6338 {
6339 if (*option == '+')
6340 {
6341 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6342 (void) DeleteImageRegistry(argv[i+1]+9);
6343 else
6344 (void) DeleteImageOption(image_info,argv[i+1]);
6345 break;
6346 }
6347 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6348 {
6349 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6350 exception);
6351 break;
6352 }
6353 (void) DefineImageOption(image_info,argv[i+1]);
6354 break;
6355 }
6356 if (LocaleCompare("delay",option+1) == 0)
6357 {
6358 if (*option == '+')
6359 {
6360 (void) SetImageOption(image_info,option+1,"0");
6361 break;
6362 }
6363 (void) SetImageOption(image_info,option+1,argv[i+1]);
6364 break;
6365 }
6366 if (LocaleCompare("density",option+1) == 0)
6367 {
6368 /*
6369 Set image density.
6370 */
6371 if (*option == '+')
6372 {
6373 if (image_info->density != (char *) NULL)
6374 image_info->density=DestroyString(image_info->density);
6375 (void) SetImageOption(image_info,option+1,"72");
6376 break;
6377 }
6378 (void) CloneString(&image_info->density,argv[i+1]);
6379 (void) SetImageOption(image_info,option+1,argv[i+1]);
6380 break;
6381 }
6382 if (LocaleCompare("depth",option+1) == 0)
6383 {
6384 if (*option == '+')
6385 {
6386 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6387 break;
6388 }
cristye27293e2009-12-18 02:53:20 +00006389 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006390 break;
6391 }
cristyc9b12952010-03-28 01:12:28 +00006392 if (LocaleCompare("direction",option+1) == 0)
6393 {
6394 if (*option == '+')
6395 {
6396 (void) SetImageOption(image_info,option+1,"undefined");
6397 break;
6398 }
6399 (void) SetImageOption(image_info,option+1,argv[i+1]);
6400 break;
6401 }
cristy3ed852e2009-09-05 21:47:34 +00006402 if (LocaleCompare("display",option+1) == 0)
6403 {
6404 if (*option == '+')
6405 {
6406 if (image_info->server_name != (char *) NULL)
6407 image_info->server_name=DestroyString(
6408 image_info->server_name);
6409 break;
6410 }
6411 (void) CloneString(&image_info->server_name,argv[i+1]);
6412 break;
6413 }
6414 if (LocaleCompare("dispose",option+1) == 0)
6415 {
6416 if (*option == '+')
6417 {
6418 (void) SetImageOption(image_info,option+1,"undefined");
6419 break;
6420 }
6421 (void) SetImageOption(image_info,option+1,argv[i+1]);
6422 break;
6423 }
6424 if (LocaleCompare("dither",option+1) == 0)
6425 {
6426 if (*option == '+')
6427 {
6428 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006429 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006430 break;
6431 }
6432 (void) SetImageOption(image_info,option+1,argv[i+1]);
6433 image_info->dither=MagickTrue;
6434 break;
6435 }
6436 break;
6437 }
6438 case 'e':
6439 {
6440 if (LocaleCompare("encoding",option+1) == 0)
6441 {
6442 if (*option == '+')
6443 {
6444 (void) SetImageOption(image_info,option+1,"undefined");
6445 break;
6446 }
6447 (void) SetImageOption(image_info,option+1,argv[i+1]);
6448 break;
6449 }
6450 if (LocaleCompare("endian",option+1) == 0)
6451 {
6452 if (*option == '+')
6453 {
6454 image_info->endian=UndefinedEndian;
6455 (void) SetImageOption(image_info,option+1,"undefined");
6456 break;
6457 }
cristy042ee782011-04-22 18:48:30 +00006458 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006459 MagickEndianOptions,MagickFalse,argv[i+1]);
6460 (void) SetImageOption(image_info,option+1,argv[i+1]);
6461 break;
6462 }
6463 if (LocaleCompare("extract",option+1) == 0)
6464 {
6465 /*
6466 Set image extract geometry.
6467 */
6468 if (*option == '+')
6469 {
6470 if (image_info->extract != (char *) NULL)
6471 image_info->extract=DestroyString(image_info->extract);
6472 break;
6473 }
6474 (void) CloneString(&image_info->extract,argv[i+1]);
6475 break;
6476 }
6477 break;
6478 }
6479 case 'f':
6480 {
6481 if (LocaleCompare("fill",option+1) == 0)
6482 {
6483 if (*option == '+')
6484 {
6485 (void) SetImageOption(image_info,option+1,"none");
6486 break;
6487 }
6488 (void) SetImageOption(image_info,option+1,argv[i+1]);
6489 break;
6490 }
6491 if (LocaleCompare("filter",option+1) == 0)
6492 {
6493 if (*option == '+')
6494 {
6495 (void) SetImageOption(image_info,option+1,"undefined");
6496 break;
6497 }
6498 (void) SetImageOption(image_info,option+1,argv[i+1]);
6499 break;
6500 }
6501 if (LocaleCompare("font",option+1) == 0)
6502 {
6503 if (*option == '+')
6504 {
6505 if (image_info->font != (char *) NULL)
6506 image_info->font=DestroyString(image_info->font);
6507 break;
6508 }
6509 (void) CloneString(&image_info->font,argv[i+1]);
6510 break;
6511 }
6512 if (LocaleCompare("format",option+1) == 0)
6513 {
6514 register const char
6515 *q;
6516
6517 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006518 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006519 image_info->ping=MagickFalse;
6520 (void) SetImageOption(image_info,option+1,argv[i+1]);
6521 break;
6522 }
6523 if (LocaleCompare("fuzz",option+1) == 0)
6524 {
6525 if (*option == '+')
6526 {
6527 image_info->fuzz=0.0;
6528 (void) SetImageOption(image_info,option+1,"0");
6529 break;
6530 }
cristyf2f27272009-12-17 14:48:46 +00006531 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006532 1.0);
6533 (void) SetImageOption(image_info,option+1,argv[i+1]);
6534 break;
6535 }
6536 break;
6537 }
6538 case 'g':
6539 {
6540 if (LocaleCompare("gravity",option+1) == 0)
6541 {
6542 if (*option == '+')
6543 {
6544 (void) SetImageOption(image_info,option+1,"undefined");
6545 break;
6546 }
6547 (void) SetImageOption(image_info,option+1,argv[i+1]);
6548 break;
6549 }
6550 if (LocaleCompare("green-primary",option+1) == 0)
6551 {
6552 if (*option == '+')
6553 {
6554 (void) SetImageOption(image_info,option+1,"0.0");
6555 break;
6556 }
6557 (void) SetImageOption(image_info,option+1,argv[i+1]);
6558 break;
6559 }
6560 break;
6561 }
6562 case 'i':
6563 {
6564 if (LocaleCompare("intent",option+1) == 0)
6565 {
6566 if (*option == '+')
6567 {
6568 (void) SetImageOption(image_info,option+1,"undefined");
6569 break;
6570 }
6571 (void) SetImageOption(image_info,option+1,argv[i+1]);
6572 break;
6573 }
6574 if (LocaleCompare("interlace",option+1) == 0)
6575 {
6576 if (*option == '+')
6577 {
6578 image_info->interlace=UndefinedInterlace;
6579 (void) SetImageOption(image_info,option+1,"undefined");
6580 break;
6581 }
cristy042ee782011-04-22 18:48:30 +00006582 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006583 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6584 (void) SetImageOption(image_info,option+1,argv[i+1]);
6585 break;
6586 }
cristyb32b90a2009-09-07 21:45:48 +00006587 if (LocaleCompare("interline-spacing",option+1) == 0)
6588 {
6589 if (*option == '+')
6590 {
6591 (void) SetImageOption(image_info,option+1,"undefined");
6592 break;
6593 }
6594 (void) SetImageOption(image_info,option+1,argv[i+1]);
6595 break;
6596 }
cristy3ed852e2009-09-05 21:47:34 +00006597 if (LocaleCompare("interpolate",option+1) == 0)
6598 {
6599 if (*option == '+')
6600 {
6601 (void) SetImageOption(image_info,option+1,"undefined");
6602 break;
6603 }
6604 (void) SetImageOption(image_info,option+1,argv[i+1]);
6605 break;
6606 }
6607 if (LocaleCompare("interword-spacing",option+1) == 0)
6608 {
6609 if (*option == '+')
6610 {
6611 (void) SetImageOption(image_info,option+1,"undefined");
6612 break;
6613 }
6614 (void) SetImageOption(image_info,option+1,argv[i+1]);
6615 break;
6616 }
6617 break;
6618 }
6619 case 'k':
6620 {
6621 if (LocaleCompare("kerning",option+1) == 0)
6622 {
6623 if (*option == '+')
6624 {
6625 (void) SetImageOption(image_info,option+1,"undefined");
6626 break;
6627 }
6628 (void) SetImageOption(image_info,option+1,argv[i+1]);
6629 break;
6630 }
6631 break;
6632 }
6633 case 'l':
6634 {
6635 if (LocaleCompare("label",option+1) == 0)
6636 {
6637 if (*option == '+')
6638 {
6639 (void) DeleteImageOption(image_info,option+1);
6640 break;
6641 }
6642 (void) SetImageOption(image_info,option+1,argv[i+1]);
6643 break;
6644 }
6645 if (LocaleCompare("limit",option+1) == 0)
6646 {
6647 MagickSizeType
6648 limit;
6649
6650 ResourceType
6651 type;
6652
6653 if (*option == '+')
6654 break;
cristy042ee782011-04-22 18:48:30 +00006655 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006656 MagickFalse,argv[i+1]);
6657 limit=MagickResourceInfinity;
6658 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006659 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006660 (void) SetMagickResourceLimit(type,limit);
6661 break;
6662 }
6663 if (LocaleCompare("list",option+1) == 0)
6664 {
cristybb503372010-05-27 20:51:26 +00006665 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006666 list;
6667
6668 /*
6669 Display configuration list.
6670 */
cristy042ee782011-04-22 18:48:30 +00006671 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006672 switch (list)
6673 {
6674 case MagickCoderOptions:
6675 {
6676 (void) ListCoderInfo((FILE *) NULL,exception);
6677 break;
6678 }
6679 case MagickColorOptions:
6680 {
6681 (void) ListColorInfo((FILE *) NULL,exception);
6682 break;
6683 }
6684 case MagickConfigureOptions:
6685 {
6686 (void) ListConfigureInfo((FILE *) NULL,exception);
6687 break;
6688 }
6689 case MagickDelegateOptions:
6690 {
6691 (void) ListDelegateInfo((FILE *) NULL,exception);
6692 break;
6693 }
6694 case MagickFontOptions:
6695 {
6696 (void) ListTypeInfo((FILE *) NULL,exception);
6697 break;
6698 }
6699 case MagickFormatOptions:
6700 {
6701 (void) ListMagickInfo((FILE *) NULL,exception);
6702 break;
6703 }
6704 case MagickLocaleOptions:
6705 {
6706 (void) ListLocaleInfo((FILE *) NULL,exception);
6707 break;
6708 }
6709 case MagickLogOptions:
6710 {
6711 (void) ListLogInfo((FILE *) NULL,exception);
6712 break;
6713 }
6714 case MagickMagicOptions:
6715 {
6716 (void) ListMagicInfo((FILE *) NULL,exception);
6717 break;
6718 }
6719 case MagickMimeOptions:
6720 {
6721 (void) ListMimeInfo((FILE *) NULL,exception);
6722 break;
6723 }
6724 case MagickModuleOptions:
6725 {
6726 (void) ListModuleInfo((FILE *) NULL,exception);
6727 break;
6728 }
6729 case MagickPolicyOptions:
6730 {
6731 (void) ListPolicyInfo((FILE *) NULL,exception);
6732 break;
6733 }
6734 case MagickResourceOptions:
6735 {
6736 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6737 break;
6738 }
6739 case MagickThresholdOptions:
6740 {
6741 (void) ListThresholdMaps((FILE *) NULL,exception);
6742 break;
6743 }
6744 default:
6745 {
cristy042ee782011-04-22 18:48:30 +00006746 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006747 exception);
6748 break;
6749 }
6750 }
cristyaeb2cbc2010-05-07 13:28:58 +00006751 break;
cristy3ed852e2009-09-05 21:47:34 +00006752 }
6753 if (LocaleCompare("log",option+1) == 0)
6754 {
6755 if (*option == '+')
6756 break;
6757 (void) SetLogFormat(argv[i+1]);
6758 break;
6759 }
6760 if (LocaleCompare("loop",option+1) == 0)
6761 {
6762 if (*option == '+')
6763 {
6764 (void) SetImageOption(image_info,option+1,"0");
6765 break;
6766 }
6767 (void) SetImageOption(image_info,option+1,argv[i+1]);
6768 break;
6769 }
6770 break;
6771 }
6772 case 'm':
6773 {
6774 if (LocaleCompare("matte",option+1) == 0)
6775 {
6776 if (*option == '+')
6777 {
6778 (void) SetImageOption(image_info,option+1,"false");
6779 break;
6780 }
6781 (void) SetImageOption(image_info,option+1,"true");
6782 break;
6783 }
6784 if (LocaleCompare("mattecolor",option+1) == 0)
6785 {
6786 if (*option == '+')
6787 {
6788 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006789 (void) QueryColorDatabase(MogrifyMatteColor,
6790 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006791 break;
6792 }
6793 (void) SetImageOption(image_info,option+1,argv[i+1]);
6794 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6795 exception);
6796 break;
6797 }
6798 if (LocaleCompare("monitor",option+1) == 0)
6799 {
6800 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6801 (void *) NULL);
6802 break;
6803 }
6804 if (LocaleCompare("monochrome",option+1) == 0)
6805 {
6806 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6807 break;
6808 }
6809 break;
6810 }
6811 case 'o':
6812 {
6813 if (LocaleCompare("orient",option+1) == 0)
6814 {
6815 if (*option == '+')
6816 {
6817 image_info->orientation=UndefinedOrientation;
6818 (void) SetImageOption(image_info,option+1,"undefined");
6819 break;
6820 }
cristy042ee782011-04-22 18:48:30 +00006821 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006822 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006823 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006824 break;
6825 }
6826 }
6827 case 'p':
6828 {
6829 if (LocaleCompare("page",option+1) == 0)
6830 {
6831 char
6832 *canonical_page,
6833 page[MaxTextExtent];
6834
6835 const char
6836 *image_option;
6837
6838 MagickStatusType
6839 flags;
6840
6841 RectangleInfo
6842 geometry;
6843
6844 if (*option == '+')
6845 {
6846 (void) DeleteImageOption(image_info,option+1);
6847 (void) CloneString(&image_info->page,(char *) NULL);
6848 break;
6849 }
6850 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6851 image_option=GetImageOption(image_info,"page");
6852 if (image_option != (const char *) NULL)
6853 flags=ParseAbsoluteGeometry(image_option,&geometry);
6854 canonical_page=GetPageGeometry(argv[i+1]);
6855 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6856 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006857 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006858 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006859 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006860 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006861 (unsigned long) geometry.width,(unsigned long) geometry.height,
6862 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006863 (void) SetImageOption(image_info,option+1,page);
6864 (void) CloneString(&image_info->page,page);
6865 break;
6866 }
6867 if (LocaleCompare("pen",option+1) == 0)
6868 {
6869 if (*option == '+')
6870 {
6871 (void) SetImageOption(image_info,option+1,"none");
6872 break;
6873 }
6874 (void) SetImageOption(image_info,option+1,argv[i+1]);
6875 break;
6876 }
6877 if (LocaleCompare("ping",option+1) == 0)
6878 {
6879 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6880 break;
6881 }
6882 if (LocaleCompare("pointsize",option+1) == 0)
6883 {
6884 if (*option == '+')
6885 geometry_info.rho=0.0;
6886 else
6887 (void) ParseGeometry(argv[i+1],&geometry_info);
6888 image_info->pointsize=geometry_info.rho;
6889 break;
6890 }
cristye7f51092010-01-17 00:39:37 +00006891 if (LocaleCompare("precision",option+1) == 0)
6892 {
cristybf2766a2010-01-17 03:33:23 +00006893 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006894 break;
6895 }
cristy3ed852e2009-09-05 21:47:34 +00006896 if (LocaleCompare("preview",option+1) == 0)
6897 {
6898 /*
6899 Preview image.
6900 */
6901 if (*option == '+')
6902 {
6903 image_info->preview_type=UndefinedPreview;
6904 break;
6905 }
cristy042ee782011-04-22 18:48:30 +00006906 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006907 MagickPreviewOptions,MagickFalse,argv[i+1]);
6908 break;
6909 }
6910 break;
6911 }
6912 case 'q':
6913 {
6914 if (LocaleCompare("quality",option+1) == 0)
6915 {
6916 /*
6917 Set image compression quality.
6918 */
6919 if (*option == '+')
6920 {
6921 image_info->quality=UndefinedCompressionQuality;
6922 (void) SetImageOption(image_info,option+1,"0");
6923 break;
6924 }
cristye27293e2009-12-18 02:53:20 +00006925 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006926 (void) SetImageOption(image_info,option+1,argv[i+1]);
6927 break;
6928 }
6929 if (LocaleCompare("quiet",option+1) == 0)
6930 {
6931 static WarningHandler
6932 warning_handler = (WarningHandler) NULL;
6933
6934 if (*option == '+')
6935 {
6936 /*
6937 Restore error or warning messages.
6938 */
6939 warning_handler=SetWarningHandler(warning_handler);
6940 break;
6941 }
6942 /*
6943 Suppress error or warning messages.
6944 */
6945 warning_handler=SetWarningHandler((WarningHandler) NULL);
6946 break;
6947 }
6948 break;
6949 }
6950 case 'r':
6951 {
6952 if (LocaleCompare("red-primary",option+1) == 0)
6953 {
6954 if (*option == '+')
6955 {
6956 (void) SetImageOption(image_info,option+1,"0.0");
6957 break;
6958 }
6959 (void) SetImageOption(image_info,option+1,argv[i+1]);
6960 break;
6961 }
6962 break;
6963 }
6964 case 's':
6965 {
6966 if (LocaleCompare("sampling-factor",option+1) == 0)
6967 {
6968 /*
6969 Set image sampling factor.
6970 */
6971 if (*option == '+')
6972 {
6973 if (image_info->sampling_factor != (char *) NULL)
6974 image_info->sampling_factor=DestroyString(
6975 image_info->sampling_factor);
6976 break;
6977 }
6978 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6979 break;
6980 }
6981 if (LocaleCompare("scene",option+1) == 0)
6982 {
6983 /*
6984 Set image scene.
6985 */
6986 if (*option == '+')
6987 {
6988 image_info->scene=0;
6989 (void) SetImageOption(image_info,option+1,"0");
6990 break;
6991 }
cristye27293e2009-12-18 02:53:20 +00006992 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006993 (void) SetImageOption(image_info,option+1,argv[i+1]);
6994 break;
6995 }
6996 if (LocaleCompare("seed",option+1) == 0)
6997 {
cristybb503372010-05-27 20:51:26 +00006998 size_t
cristy3ed852e2009-09-05 21:47:34 +00006999 seed;
7000
7001 if (*option == '+')
7002 {
cristybb503372010-05-27 20:51:26 +00007003 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007004 SeedPseudoRandomGenerator(seed);
7005 break;
7006 }
cristye27293e2009-12-18 02:53:20 +00007007 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007008 SeedPseudoRandomGenerator(seed);
7009 break;
7010 }
7011 if (LocaleCompare("size",option+1) == 0)
7012 {
7013 if (*option == '+')
7014 {
7015 if (image_info->size != (char *) NULL)
7016 image_info->size=DestroyString(image_info->size);
7017 break;
7018 }
7019 (void) CloneString(&image_info->size,argv[i+1]);
7020 break;
7021 }
7022 if (LocaleCompare("stroke",option+1) == 0)
7023 {
7024 if (*option == '+')
7025 {
7026 (void) SetImageOption(image_info,option+1,"none");
7027 break;
7028 }
7029 (void) SetImageOption(image_info,option+1,argv[i+1]);
7030 break;
7031 }
7032 if (LocaleCompare("strokewidth",option+1) == 0)
7033 {
7034 if (*option == '+')
7035 {
7036 (void) SetImageOption(image_info,option+1,"0");
7037 break;
7038 }
7039 (void) SetImageOption(image_info,option+1,argv[i+1]);
7040 break;
7041 }
cristyd9a29192010-10-16 16:49:53 +00007042 if (LocaleCompare("synchronize",option+1) == 0)
7043 {
7044 if (*option == '+')
7045 {
7046 image_info->synchronize=MagickFalse;
7047 break;
7048 }
7049 image_info->synchronize=MagickTrue;
7050 break;
7051 }
cristy3ed852e2009-09-05 21:47:34 +00007052 break;
7053 }
7054 case 't':
7055 {
7056 if (LocaleCompare("taint",option+1) == 0)
7057 {
7058 if (*option == '+')
7059 {
7060 (void) SetImageOption(image_info,option+1,"false");
7061 break;
7062 }
7063 (void) SetImageOption(image_info,option+1,"true");
7064 break;
7065 }
7066 if (LocaleCompare("texture",option+1) == 0)
7067 {
7068 if (*option == '+')
7069 {
7070 if (image_info->texture != (char *) NULL)
7071 image_info->texture=DestroyString(image_info->texture);
7072 break;
7073 }
7074 (void) CloneString(&image_info->texture,argv[i+1]);
7075 break;
7076 }
7077 if (LocaleCompare("tile-offset",option+1) == 0)
7078 {
7079 if (*option == '+')
7080 {
7081 (void) SetImageOption(image_info,option+1,"0");
7082 break;
7083 }
7084 (void) SetImageOption(image_info,option+1,argv[i+1]);
7085 break;
7086 }
7087 if (LocaleCompare("transparent-color",option+1) == 0)
7088 {
7089 if (*option == '+')
7090 {
7091 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7092 (void) SetImageOption(image_info,option+1,"none");
7093 break;
7094 }
7095 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7096 exception);
7097 (void) SetImageOption(image_info,option+1,argv[i+1]);
7098 break;
7099 }
7100 if (LocaleCompare("type",option+1) == 0)
7101 {
7102 if (*option == '+')
7103 {
cristy5f1c1ff2010-12-23 21:38:06 +00007104 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007105 (void) SetImageOption(image_info,option+1,"undefined");
7106 break;
7107 }
cristy042ee782011-04-22 18:48:30 +00007108 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007109 MagickFalse,argv[i+1]);
7110 (void) SetImageOption(image_info,option+1,argv[i+1]);
7111 break;
7112 }
7113 break;
7114 }
7115 case 'u':
7116 {
7117 if (LocaleCompare("undercolor",option+1) == 0)
7118 {
7119 if (*option == '+')
7120 {
7121 (void) DeleteImageOption(image_info,option+1);
7122 break;
7123 }
7124 (void) SetImageOption(image_info,option+1,argv[i+1]);
7125 break;
7126 }
7127 if (LocaleCompare("units",option+1) == 0)
7128 {
7129 if (*option == '+')
7130 {
7131 image_info->units=UndefinedResolution;
7132 (void) SetImageOption(image_info,option+1,"undefined");
7133 break;
7134 }
cristy042ee782011-04-22 18:48:30 +00007135 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007136 MagickResolutionOptions,MagickFalse,argv[i+1]);
7137 (void) SetImageOption(image_info,option+1,argv[i+1]);
7138 break;
7139 }
7140 break;
7141 }
7142 case 'v':
7143 {
7144 if (LocaleCompare("verbose",option+1) == 0)
7145 {
7146 if (*option == '+')
7147 {
7148 image_info->verbose=MagickFalse;
7149 break;
7150 }
7151 image_info->verbose=MagickTrue;
7152 image_info->ping=MagickFalse;
7153 break;
7154 }
7155 if (LocaleCompare("view",option+1) == 0)
7156 {
7157 if (*option == '+')
7158 {
7159 if (image_info->view != (char *) NULL)
7160 image_info->view=DestroyString(image_info->view);
7161 break;
7162 }
7163 (void) CloneString(&image_info->view,argv[i+1]);
7164 break;
7165 }
7166 if (LocaleCompare("virtual-pixel",option+1) == 0)
7167 {
7168 if (*option == '+')
7169 {
7170 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7171 (void) SetImageOption(image_info,option+1,"undefined");
7172 break;
7173 }
7174 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007175 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007176 argv[i+1]);
7177 (void) SetImageOption(image_info,option+1,argv[i+1]);
7178 break;
7179 }
7180 break;
7181 }
7182 case 'w':
7183 {
7184 if (LocaleCompare("white-point",option+1) == 0)
7185 {
7186 if (*option == '+')
7187 {
7188 (void) SetImageOption(image_info,option+1,"0.0");
7189 break;
7190 }
7191 (void) SetImageOption(image_info,option+1,argv[i+1]);
7192 break;
7193 }
7194 break;
7195 }
7196 default:
7197 break;
7198 }
7199 i+=count;
7200 }
7201 return(MagickTrue);
7202}
7203
7204/*
7205%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7206% %
7207% %
7208% %
7209+ M o g r i f y I m a g e L i s t %
7210% %
7211% %
7212% %
7213%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7214%
7215% MogrifyImageList() applies any command line options that might affect the
7216% entire image list (e.g. -append, -coalesce, etc.).
7217%
7218% The format of the MogrifyImage method is:
7219%
7220% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7221% const char **argv,Image **images,ExceptionInfo *exception)
7222%
7223% A description of each parameter follows:
7224%
7225% o image_info: the image info..
7226%
7227% o argc: Specifies a pointer to an integer describing the number of
7228% elements in the argument vector.
7229%
7230% o argv: Specifies a pointer to a text array containing the command line
7231% arguments.
7232%
anthonye9c27192011-03-27 08:07:06 +00007233% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007234%
7235% o exception: return any errors or warnings in this structure.
7236%
7237*/
7238WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7239 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7240{
cristy3ed852e2009-09-05 21:47:34 +00007241 const char
7242 *option;
7243
cristy6b3da3a2010-06-20 02:21:46 +00007244 ImageInfo
7245 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007246
7247 MagickStatusType
7248 status;
7249
cristy28474bf2011-09-11 23:32:52 +00007250 PixelInterpolateMethod
7251 interpolate_method;
7252
cristy3ed852e2009-09-05 21:47:34 +00007253 QuantizeInfo
7254 *quantize_info;
7255
cristybb503372010-05-27 20:51:26 +00007256 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007257 i;
7258
cristy6b3da3a2010-06-20 02:21:46 +00007259 ssize_t
7260 count,
7261 index;
7262
cristy3ed852e2009-09-05 21:47:34 +00007263 /*
7264 Apply options to the image list.
7265 */
7266 assert(image_info != (ImageInfo *) NULL);
7267 assert(image_info->signature == MagickSignature);
7268 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007269 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007270 assert((*images)->signature == MagickSignature);
7271 if ((*images)->debug != MagickFalse)
7272 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7273 (*images)->filename);
7274 if ((argc <= 0) || (*argv == (char *) NULL))
7275 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007276 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007277 mogrify_info=CloneImageInfo(image_info);
7278 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007279 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007280 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007281 {
cristy74fe8f12009-10-03 19:09:01 +00007282 if (*images == (Image *) NULL)
7283 break;
cristy3ed852e2009-09-05 21:47:34 +00007284 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007285 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007286 continue;
cristy042ee782011-04-22 18:48:30 +00007287 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007288 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007289 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007290 break;
cristy6b3da3a2010-06-20 02:21:46 +00007291 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007292 switch (*(option+1))
7293 {
7294 case 'a':
7295 {
7296 if (LocaleCompare("affinity",option+1) == 0)
7297 {
cristy6b3da3a2010-06-20 02:21:46 +00007298 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007299 if (*option == '+')
7300 {
cristy018f07f2011-09-04 21:15:19 +00007301 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7302 exception);
cristy3ed852e2009-09-05 21:47:34 +00007303 break;
7304 }
7305 i++;
7306 break;
7307 }
7308 if (LocaleCompare("append",option+1) == 0)
7309 {
7310 Image
7311 *append_image;
7312
cristy6b3da3a2010-06-20 02:21:46 +00007313 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007314 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7315 MagickFalse,exception);
7316 if (append_image == (Image *) NULL)
7317 {
7318 status=MagickFalse;
7319 break;
7320 }
7321 *images=DestroyImageList(*images);
7322 *images=append_image;
7323 break;
7324 }
7325 if (LocaleCompare("average",option+1) == 0)
7326 {
7327 Image
7328 *average_image;
7329
cristyd18ae7c2010-03-07 17:39:52 +00007330 /*
7331 Average an image sequence (deprecated).
7332 */
cristy6b3da3a2010-06-20 02:21:46 +00007333 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007334 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7335 exception);
cristy3ed852e2009-09-05 21:47:34 +00007336 if (average_image == (Image *) NULL)
7337 {
7338 status=MagickFalse;
7339 break;
7340 }
7341 *images=DestroyImageList(*images);
7342 *images=average_image;
7343 break;
7344 }
7345 break;
7346 }
7347 case 'c':
7348 {
7349 if (LocaleCompare("channel",option+1) == 0)
7350 {
cristyf4ad9df2011-07-08 16:49:03 +00007351 ChannelType
7352 channel;
7353
cristy3ed852e2009-09-05 21:47:34 +00007354 if (*option == '+')
7355 {
7356 channel=DefaultChannels;
7357 break;
7358 }
7359 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007360 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007361 break;
7362 }
7363 if (LocaleCompare("clut",option+1) == 0)
7364 {
7365 Image
7366 *clut_image,
7367 *image;
7368
cristy6b3da3a2010-06-20 02:21:46 +00007369 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007370 image=RemoveFirstImageFromList(images);
7371 clut_image=RemoveFirstImageFromList(images);
7372 if (clut_image == (Image *) NULL)
7373 {
7374 status=MagickFalse;
7375 break;
7376 }
cristy28474bf2011-09-11 23:32:52 +00007377 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007378 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007379 *images=DestroyImageList(*images);
7380 *images=image;
7381 break;
7382 }
7383 if (LocaleCompare("coalesce",option+1) == 0)
7384 {
7385 Image
7386 *coalesce_image;
7387
cristy6b3da3a2010-06-20 02:21:46 +00007388 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007389 coalesce_image=CoalesceImages(*images,exception);
7390 if (coalesce_image == (Image *) NULL)
7391 {
7392 status=MagickFalse;
7393 break;
7394 }
7395 *images=DestroyImageList(*images);
7396 *images=coalesce_image;
7397 break;
7398 }
7399 if (LocaleCompare("combine",option+1) == 0)
7400 {
7401 Image
7402 *combine_image;
7403
cristy6b3da3a2010-06-20 02:21:46 +00007404 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007405 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007406 if (combine_image == (Image *) NULL)
7407 {
7408 status=MagickFalse;
7409 break;
7410 }
7411 *images=DestroyImageList(*images);
7412 *images=combine_image;
7413 break;
7414 }
7415 if (LocaleCompare("composite",option+1) == 0)
7416 {
7417 Image
7418 *mask_image,
7419 *composite_image,
7420 *image;
7421
7422 RectangleInfo
7423 geometry;
7424
cristy6b3da3a2010-06-20 02:21:46 +00007425 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007426 image=RemoveFirstImageFromList(images);
7427 composite_image=RemoveFirstImageFromList(images);
7428 if (composite_image == (Image *) NULL)
7429 {
7430 status=MagickFalse;
7431 break;
7432 }
7433 (void) TransformImage(&composite_image,(char *) NULL,
7434 composite_image->geometry);
7435 SetGeometry(composite_image,&geometry);
7436 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7437 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7438 &geometry);
7439 mask_image=RemoveFirstImageFromList(images);
7440 if (mask_image != (Image *) NULL)
7441 {
7442 if ((image->compose == DisplaceCompositeOp) ||
7443 (image->compose == DistortCompositeOp))
7444 {
7445 /*
7446 Merge Y displacement into X displacement image.
7447 */
7448 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7449 mask_image,0,0);
7450 mask_image=DestroyImage(mask_image);
7451 }
7452 else
7453 {
7454 /*
7455 Set a blending mask for the composition.
cristy28474bf2011-09-11 23:32:52 +00007456 Posible error, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007457 */
7458 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007459 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007460 }
7461 }
cristyf4ad9df2011-07-08 16:49:03 +00007462 (void) CompositeImage(image,image->compose,composite_image,
7463 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007464 if (mask_image != (Image *) NULL)
7465 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007466 composite_image=DestroyImage(composite_image);
7467 InheritException(exception,&image->exception);
7468 *images=DestroyImageList(*images);
7469 *images=image;
7470 break;
7471 }
cristy3ed852e2009-09-05 21:47:34 +00007472 break;
7473 }
7474 case 'd':
7475 {
7476 if (LocaleCompare("deconstruct",option+1) == 0)
7477 {
7478 Image
7479 *deconstruct_image;
7480
cristy6b3da3a2010-06-20 02:21:46 +00007481 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007482 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007483 exception);
cristy3ed852e2009-09-05 21:47:34 +00007484 if (deconstruct_image == (Image *) NULL)
7485 {
7486 status=MagickFalse;
7487 break;
7488 }
7489 *images=DestroyImageList(*images);
7490 *images=deconstruct_image;
7491 break;
7492 }
7493 if (LocaleCompare("delete",option+1) == 0)
7494 {
7495 if (*option == '+')
7496 DeleteImages(images,"-1",exception);
7497 else
7498 DeleteImages(images,argv[i+1],exception);
7499 break;
7500 }
7501 if (LocaleCompare("dither",option+1) == 0)
7502 {
7503 if (*option == '+')
7504 {
7505 quantize_info->dither=MagickFalse;
7506 break;
7507 }
7508 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007509 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007510 MagickDitherOptions,MagickFalse,argv[i+1]);
7511 break;
7512 }
cristyecb10ff2011-03-22 13:14:03 +00007513 if (LocaleCompare("duplicate",option+1) == 0)
7514 {
cristy72988482011-03-29 16:34:38 +00007515 Image
7516 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007517
anthony2b6bcae2011-03-23 13:05:34 +00007518 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007519 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7520 else
7521 {
7522 const char
7523 *p;
7524
anthony2b6bcae2011-03-23 13:05:34 +00007525 size_t
7526 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007527
anthony2b6bcae2011-03-23 13:05:34 +00007528 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007529 p=strchr(argv[i+1],',');
7530 if (p == (const char *) NULL)
7531 duplicate_images=DuplicateImages(*images,number_duplicates,
7532 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007533 else
cristy72988482011-03-29 16:34:38 +00007534 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7535 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007536 }
7537 AppendImageToList(images, duplicate_images);
7538 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007539 break;
7540 }
cristy3ed852e2009-09-05 21:47:34 +00007541 break;
7542 }
cristyd18ae7c2010-03-07 17:39:52 +00007543 case 'e':
7544 {
7545 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7546 {
7547 Image
7548 *evaluate_image;
7549
7550 MagickEvaluateOperator
7551 op;
7552
cristy6b3da3a2010-06-20 02:21:46 +00007553 (void) SyncImageSettings(mogrify_info,*images);
cristy28474bf2011-09-11 23:32:52 +00007554 op=(MagickEvaluateOperator) ParseCommandOption(
7555 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007556 evaluate_image=EvaluateImages(*images,op,exception);
7557 if (evaluate_image == (Image *) NULL)
7558 {
7559 status=MagickFalse;
7560 break;
7561 }
7562 *images=DestroyImageList(*images);
7563 *images=evaluate_image;
7564 break;
7565 }
7566 break;
7567 }
cristy3ed852e2009-09-05 21:47:34 +00007568 case 'f':
7569 {
cristyf0a247f2009-10-04 00:20:03 +00007570 if (LocaleCompare("fft",option+1) == 0)
7571 {
7572 Image
7573 *fourier_image;
7574
7575 /*
7576 Implements the discrete Fourier transform (DFT).
7577 */
cristy6b3da3a2010-06-20 02:21:46 +00007578 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007579 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7580 MagickTrue : MagickFalse,exception);
7581 if (fourier_image == (Image *) NULL)
7582 break;
7583 *images=DestroyImage(*images);
7584 *images=fourier_image;
7585 break;
7586 }
cristy3ed852e2009-09-05 21:47:34 +00007587 if (LocaleCompare("flatten",option+1) == 0)
7588 {
7589 Image
7590 *flatten_image;
7591
cristy6b3da3a2010-06-20 02:21:46 +00007592 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007593 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7594 if (flatten_image == (Image *) NULL)
7595 break;
7596 *images=DestroyImageList(*images);
7597 *images=flatten_image;
7598 break;
7599 }
7600 if (LocaleCompare("fx",option+1) == 0)
7601 {
7602 Image
7603 *fx_image;
7604
cristy6b3da3a2010-06-20 02:21:46 +00007605 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007606 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007607 if (fx_image == (Image *) NULL)
7608 {
7609 status=MagickFalse;
7610 break;
7611 }
7612 *images=DestroyImageList(*images);
7613 *images=fx_image;
7614 break;
7615 }
7616 break;
7617 }
7618 case 'h':
7619 {
7620 if (LocaleCompare("hald-clut",option+1) == 0)
7621 {
7622 Image
7623 *hald_image,
7624 *image;
7625
cristy6b3da3a2010-06-20 02:21:46 +00007626 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007627 image=RemoveFirstImageFromList(images);
7628 hald_image=RemoveFirstImageFromList(images);
7629 if (hald_image == (Image *) NULL)
7630 {
7631 status=MagickFalse;
7632 break;
7633 }
cristy7c0a0a42011-08-23 17:57:25 +00007634 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007635 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007636 if (*images != (Image *) NULL)
7637 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007638 *images=image;
7639 break;
7640 }
7641 break;
7642 }
7643 case 'i':
7644 {
7645 if (LocaleCompare("ift",option+1) == 0)
7646 {
7647 Image
cristy8587f882009-11-13 20:28:49 +00007648 *fourier_image,
7649 *magnitude_image,
7650 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007651
7652 /*
7653 Implements the inverse fourier discrete Fourier transform (DFT).
7654 */
cristy6b3da3a2010-06-20 02:21:46 +00007655 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007656 magnitude_image=RemoveFirstImageFromList(images);
7657 phase_image=RemoveFirstImageFromList(images);
7658 if (phase_image == (Image *) NULL)
7659 {
7660 status=MagickFalse;
7661 break;
7662 }
7663 fourier_image=InverseFourierTransformImage(magnitude_image,
7664 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007665 if (fourier_image == (Image *) NULL)
7666 break;
cristy0aff6ea2009-11-14 01:40:53 +00007667 if (*images != (Image *) NULL)
7668 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007669 *images=fourier_image;
7670 break;
7671 }
7672 if (LocaleCompare("insert",option+1) == 0)
7673 {
7674 Image
7675 *p,
7676 *q;
7677
7678 index=0;
7679 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007680 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007681 p=RemoveLastImageFromList(images);
7682 if (p == (Image *) NULL)
7683 {
7684 (void) ThrowMagickException(exception,GetMagickModule(),
7685 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7686 status=MagickFalse;
7687 break;
7688 }
7689 q=p;
7690 if (index == 0)
7691 PrependImageToList(images,q);
7692 else
cristybb503372010-05-27 20:51:26 +00007693 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007694 AppendImageToList(images,q);
7695 else
7696 {
7697 q=GetImageFromList(*images,index-1);
7698 if (q == (Image *) NULL)
7699 {
7700 (void) ThrowMagickException(exception,GetMagickModule(),
7701 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7702 status=MagickFalse;
7703 break;
7704 }
7705 InsertImageInList(&q,p);
7706 }
7707 *images=GetFirstImageInList(q);
7708 break;
7709 }
cristy28474bf2011-09-11 23:32:52 +00007710 if (LocaleCompare("interpolate",option+1) == 0)
7711 {
7712 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7713 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7714 break;
7715 }
cristy3ed852e2009-09-05 21:47:34 +00007716 break;
7717 }
7718 case 'l':
7719 {
7720 if (LocaleCompare("layers",option+1) == 0)
7721 {
7722 Image
7723 *layers;
7724
7725 ImageLayerMethod
7726 method;
7727
cristy6b3da3a2010-06-20 02:21:46 +00007728 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007729 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007730 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007731 MagickFalse,argv[i+1]);
7732 switch (method)
7733 {
7734 case CoalesceLayer:
7735 {
7736 layers=CoalesceImages(*images,exception);
7737 break;
7738 }
7739 case CompareAnyLayer:
7740 case CompareClearLayer:
7741 case CompareOverlayLayer:
7742 default:
7743 {
cristy8a9106f2011-07-05 14:39:26 +00007744 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007745 break;
7746 }
7747 case MergeLayer:
7748 case FlattenLayer:
7749 case MosaicLayer:
7750 case TrimBoundsLayer:
7751 {
7752 layers=MergeImageLayers(*images,method,exception);
7753 break;
7754 }
7755 case DisposeLayer:
7756 {
7757 layers=DisposeImages(*images,exception);
7758 break;
7759 }
7760 case OptimizeImageLayer:
7761 {
7762 layers=OptimizeImageLayers(*images,exception);
7763 break;
7764 }
7765 case OptimizePlusLayer:
7766 {
7767 layers=OptimizePlusImageLayers(*images,exception);
7768 break;
7769 }
7770 case OptimizeTransLayer:
7771 {
7772 OptimizeImageTransparency(*images,exception);
7773 break;
7774 }
7775 case RemoveDupsLayer:
7776 {
7777 RemoveDuplicateLayers(images,exception);
7778 break;
7779 }
7780 case RemoveZeroLayer:
7781 {
7782 RemoveZeroDelayLayers(images,exception);
7783 break;
7784 }
7785 case OptimizeLayer:
7786 {
7787 /*
7788 General Purpose, GIF Animation Optimizer.
7789 */
7790 layers=CoalesceImages(*images,exception);
7791 if (layers == (Image *) NULL)
7792 {
7793 status=MagickFalse;
7794 break;
7795 }
cristy3ed852e2009-09-05 21:47:34 +00007796 *images=DestroyImageList(*images);
7797 *images=layers;
7798 layers=OptimizeImageLayers(*images,exception);
7799 if (layers == (Image *) NULL)
7800 {
7801 status=MagickFalse;
7802 break;
7803 }
cristy3ed852e2009-09-05 21:47:34 +00007804 *images=DestroyImageList(*images);
7805 *images=layers;
7806 layers=(Image *) NULL;
7807 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007808 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7809 exception);
cristy3ed852e2009-09-05 21:47:34 +00007810 break;
7811 }
7812 case CompositeLayer:
7813 {
7814 CompositeOperator
7815 compose;
7816
7817 Image
7818 *source;
7819
7820 RectangleInfo
7821 geometry;
7822
7823 /*
7824 Split image sequence at the first 'NULL:' image.
7825 */
7826 source=(*images);
7827 while (source != (Image *) NULL)
7828 {
7829 source=GetNextImageInList(source);
7830 if ((source != (Image *) NULL) &&
7831 (LocaleCompare(source->magick,"NULL") == 0))
7832 break;
7833 }
7834 if (source != (Image *) NULL)
7835 {
7836 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7837 (GetNextImageInList(source) == (Image *) NULL))
7838 source=(Image *) NULL;
7839 else
7840 {
7841 /*
7842 Separate the two lists, junk the null: image.
7843 */
7844 source=SplitImageList(source->previous);
7845 DeleteImageFromList(&source);
7846 }
7847 }
7848 if (source == (Image *) NULL)
7849 {
7850 (void) ThrowMagickException(exception,GetMagickModule(),
7851 OptionError,"MissingNullSeparator","layers Composite");
7852 status=MagickFalse;
7853 break;
7854 }
7855 /*
7856 Adjust offset with gravity and virtual canvas.
7857 */
7858 SetGeometry(*images,&geometry);
7859 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7860 geometry.width=source->page.width != 0 ?
7861 source->page.width : source->columns;
7862 geometry.height=source->page.height != 0 ?
7863 source->page.height : source->rows;
7864 GravityAdjustGeometry((*images)->page.width != 0 ?
7865 (*images)->page.width : (*images)->columns,
7866 (*images)->page.height != 0 ? (*images)->page.height :
7867 (*images)->rows,(*images)->gravity,&geometry);
7868 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007869 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007870 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007871 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007872 MagickComposeOptions,MagickFalse,option);
7873 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7874 exception);
7875 source=DestroyImageList(source);
7876 break;
7877 }
7878 }
7879 if (layers == (Image *) NULL)
7880 break;
7881 InheritException(exception,&layers->exception);
7882 *images=DestroyImageList(*images);
7883 *images=layers;
7884 break;
7885 }
7886 break;
7887 }
7888 case 'm':
7889 {
7890 if (LocaleCompare("map",option+1) == 0)
7891 {
cristy6b3da3a2010-06-20 02:21:46 +00007892 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007893 if (*option == '+')
7894 {
cristy018f07f2011-09-04 21:15:19 +00007895 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7896 exception);
cristy3ed852e2009-09-05 21:47:34 +00007897 break;
7898 }
7899 i++;
7900 break;
7901 }
cristyf40785b2010-03-06 02:27:27 +00007902 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007903 {
7904 Image
cristyf40785b2010-03-06 02:27:27 +00007905 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007906
cristyd18ae7c2010-03-07 17:39:52 +00007907 /*
7908 Maximum image sequence (deprecated).
7909 */
cristy6b3da3a2010-06-20 02:21:46 +00007910 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007911 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007912 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007913 {
7914 status=MagickFalse;
7915 break;
7916 }
7917 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007918 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007919 break;
7920 }
cristyf40785b2010-03-06 02:27:27 +00007921 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007922 {
7923 Image
cristyf40785b2010-03-06 02:27:27 +00007924 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007925
cristyd18ae7c2010-03-07 17:39:52 +00007926 /*
7927 Minimum image sequence (deprecated).
7928 */
cristy6b3da3a2010-06-20 02:21:46 +00007929 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007930 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007931 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007932 {
7933 status=MagickFalse;
7934 break;
7935 }
7936 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007937 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007938 break;
7939 }
cristy3ed852e2009-09-05 21:47:34 +00007940 if (LocaleCompare("morph",option+1) == 0)
7941 {
7942 Image
7943 *morph_image;
7944
cristy6b3da3a2010-06-20 02:21:46 +00007945 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007946 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007947 exception);
7948 if (morph_image == (Image *) NULL)
7949 {
7950 status=MagickFalse;
7951 break;
7952 }
7953 *images=DestroyImageList(*images);
7954 *images=morph_image;
7955 break;
7956 }
7957 if (LocaleCompare("mosaic",option+1) == 0)
7958 {
7959 Image
7960 *mosaic_image;
7961
cristy6b3da3a2010-06-20 02:21:46 +00007962 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007963 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7964 if (mosaic_image == (Image *) NULL)
7965 {
7966 status=MagickFalse;
7967 break;
7968 }
7969 *images=DestroyImageList(*images);
7970 *images=mosaic_image;
7971 break;
7972 }
7973 break;
7974 }
7975 case 'p':
7976 {
7977 if (LocaleCompare("print",option+1) == 0)
7978 {
7979 char
7980 *string;
7981
cristy6b3da3a2010-06-20 02:21:46 +00007982 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007983 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7984 exception);
cristy3ed852e2009-09-05 21:47:34 +00007985 if (string == (char *) NULL)
7986 break;
cristyb51dff52011-05-19 16:55:47 +00007987 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007988 string=DestroyString(string);
7989 }
7990 if (LocaleCompare("process",option+1) == 0)
7991 {
7992 char
7993 **arguments;
7994
7995 int
7996 j,
7997 number_arguments;
7998
cristy6b3da3a2010-06-20 02:21:46 +00007999 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00008000 arguments=StringToArgv(argv[i+1],&number_arguments);
8001 if (arguments == (char **) NULL)
8002 break;
8003 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8004 {
8005 char
8006 breaker,
8007 quote,
8008 *token;
8009
8010 const char
8011 *arguments;
8012
8013 int
8014 next,
8015 status;
8016
8017 size_t
8018 length;
8019
8020 TokenInfo
8021 *token_info;
8022
8023 /*
8024 Support old style syntax, filter="-option arg".
8025 */
8026 length=strlen(argv[i+1]);
8027 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008028 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008029 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8030 sizeof(*token));
8031 if (token == (char *) NULL)
8032 break;
8033 next=0;
8034 arguments=argv[i+1];
8035 token_info=AcquireTokenInfo();
8036 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8037 "\"",'\0',&breaker,&next,&quote);
8038 token_info=DestroyTokenInfo(token_info);
8039 if (status == 0)
8040 {
8041 const char
8042 *argv;
8043
8044 argv=(&(arguments[next]));
8045 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8046 exception);
8047 }
8048 token=DestroyString(token);
8049 break;
8050 }
cristy91c0da22010-05-02 01:44:07 +00008051 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008052 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8053 number_arguments-2,(const char **) arguments+2,exception);
8054 for (j=0; j < number_arguments; j++)
8055 arguments[j]=DestroyString(arguments[j]);
8056 arguments=(char **) RelinquishMagickMemory(arguments);
8057 break;
8058 }
8059 break;
8060 }
8061 case 'r':
8062 {
8063 if (LocaleCompare("reverse",option+1) == 0)
8064 {
8065 ReverseImageList(images);
8066 InheritException(exception,&(*images)->exception);
8067 break;
8068 }
8069 break;
8070 }
8071 case 's':
8072 {
cristy4285d782011-02-09 20:12:28 +00008073 if (LocaleCompare("smush",option+1) == 0)
8074 {
8075 Image
8076 *smush_image;
8077
8078 ssize_t
8079 offset;
8080
8081 (void) SyncImagesSettings(mogrify_info,*images);
8082 offset=(ssize_t) StringToLong(argv[i+1]);
8083 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8084 MagickFalse,offset,exception);
8085 if (smush_image == (Image *) NULL)
8086 {
8087 status=MagickFalse;
8088 break;
8089 }
8090 *images=DestroyImageList(*images);
8091 *images=smush_image;
8092 break;
8093 }
cristy3ed852e2009-09-05 21:47:34 +00008094 if (LocaleCompare("swap",option+1) == 0)
8095 {
8096 Image
8097 *p,
8098 *q,
8099 *swap;
8100
cristybb503372010-05-27 20:51:26 +00008101 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008102 swap_index;
8103
8104 index=(-1);
8105 swap_index=(-2);
8106 if (*option != '+')
8107 {
8108 GeometryInfo
8109 geometry_info;
8110
8111 MagickStatusType
8112 flags;
8113
8114 swap_index=(-1);
8115 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008116 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008117 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008118 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008119 }
8120 p=GetImageFromList(*images,index);
8121 q=GetImageFromList(*images,swap_index);
8122 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8123 {
8124 (void) ThrowMagickException(exception,GetMagickModule(),
8125 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8126 status=MagickFalse;
8127 break;
8128 }
8129 if (p == q)
8130 break;
8131 swap=CloneImage(p,0,0,MagickTrue,exception);
8132 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8133 ReplaceImageInList(&q,swap);
8134 *images=GetFirstImageInList(q);
8135 break;
8136 }
8137 break;
8138 }
8139 case 'w':
8140 {
8141 if (LocaleCompare("write",option+1) == 0)
8142 {
cristy071dd7b2010-04-09 13:04:54 +00008143 char
cristy06609ee2010-03-17 20:21:27 +00008144 key[MaxTextExtent];
8145
cristy3ed852e2009-09-05 21:47:34 +00008146 Image
8147 *write_images;
8148
8149 ImageInfo
8150 *write_info;
8151
cristy6b3da3a2010-06-20 02:21:46 +00008152 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008153 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008154 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008155 write_images=(*images);
8156 if (*option == '+')
8157 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008158 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008159 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8160 write_info=DestroyImageInfo(write_info);
8161 if (*option == '+')
8162 write_images=DestroyImageList(write_images);
8163 break;
8164 }
8165 break;
8166 }
8167 default:
8168 break;
8169 }
8170 i+=count;
8171 }
8172 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008173 mogrify_info=DestroyImageInfo(mogrify_info);
8174 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008175 return(status != 0 ? MagickTrue : MagickFalse);
8176}
8177
8178/*
8179%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8180% %
8181% %
8182% %
8183+ M o g r i f y I m a g e s %
8184% %
8185% %
8186% %
8187%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8188%
8189% MogrifyImages() applies image processing options to a sequence of images as
8190% prescribed by command line options.
8191%
8192% The format of the MogrifyImage method is:
8193%
8194% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8195% const MagickBooleanType post,const int argc,const char **argv,
8196% Image **images,Exceptioninfo *exception)
8197%
8198% A description of each parameter follows:
8199%
8200% o image_info: the image info..
8201%
8202% o post: If true, post process image list operators otherwise pre-process.
8203%
8204% o argc: Specifies a pointer to an integer describing the number of
8205% elements in the argument vector.
8206%
8207% o argv: Specifies a pointer to a text array containing the command line
8208% arguments.
8209%
anthonye9c27192011-03-27 08:07:06 +00008210% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008211%
8212% o exception: return any errors or warnings in this structure.
8213%
8214*/
8215WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8216 const MagickBooleanType post,const int argc,const char **argv,
8217 Image **images,ExceptionInfo *exception)
8218{
8219#define MogrifyImageTag "Mogrify/Image"
8220
anthonye9c27192011-03-27 08:07:06 +00008221 MagickStatusType
8222 status;
cristy3ed852e2009-09-05 21:47:34 +00008223
cristy0e9f9c12010-02-11 03:00:47 +00008224 MagickBooleanType
8225 proceed;
8226
anthonye9c27192011-03-27 08:07:06 +00008227 size_t
8228 n;
cristy3ed852e2009-09-05 21:47:34 +00008229
cristybb503372010-05-27 20:51:26 +00008230 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008231 i;
8232
cristy3ed852e2009-09-05 21:47:34 +00008233 assert(image_info != (ImageInfo *) NULL);
8234 assert(image_info->signature == MagickSignature);
8235 if (images == (Image **) NULL)
8236 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008237 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008238 assert((*images)->signature == MagickSignature);
8239 if ((*images)->debug != MagickFalse)
8240 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8241 (*images)->filename);
8242 if ((argc <= 0) || (*argv == (char *) NULL))
8243 return(MagickTrue);
8244 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8245 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008246 status=0;
anthonye9c27192011-03-27 08:07:06 +00008247
anthonyce2716b2011-04-22 09:51:34 +00008248#if 0
cristy1e604812011-05-19 18:07:50 +00008249 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8250 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008251#endif
8252
anthonye9c27192011-03-27 08:07:06 +00008253 /*
8254 Pre-process multi-image sequence operators
8255 */
cristy3ed852e2009-09-05 21:47:34 +00008256 if (post == MagickFalse)
8257 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008258 /*
8259 For each image, process simple single image operators
8260 */
8261 i=0;
8262 n=GetImageListLength(*images);
8263 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008264 {
anthonyce2716b2011-04-22 09:51:34 +00008265#if 0
cristy1e604812011-05-19 18:07:50 +00008266 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8267 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008268#endif
anthonye9c27192011-03-27 08:07:06 +00008269 status&=MogrifyImage(image_info,argc,argv,images,exception);
8270 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008271 if (proceed == MagickFalse)
8272 break;
anthonye9c27192011-03-27 08:07:06 +00008273 if ( (*images)->next == (Image *) NULL )
8274 break;
8275 *images=(*images)->next;
8276 i++;
cristy3ed852e2009-09-05 21:47:34 +00008277 }
anthonye9c27192011-03-27 08:07:06 +00008278 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008279#if 0
cristy1e604812011-05-19 18:07:50 +00008280 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8281 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008282#endif
anthonye9c27192011-03-27 08:07:06 +00008283
8284 /*
8285 Post-process, multi-image sequence operators
8286 */
8287 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008288 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008289 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008290 return(status != 0 ? MagickTrue : MagickFalse);
8291}