blob: 2aaaa93fd4daf209a58095a44688ed4d47abc77f [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
387/*
anthony3d2f4862011-05-01 13:48:16 +0000388** SparseColorOption() parses the complex -sparse-color argument into an
389** an array of floating point values then calls SparseColorImage().
anthonydf8ebac2011-04-27 09:03:19 +0000390** Argument is a complex mix of floating-point pixel coodinates, and color
391** specifications (or direct floating point numbers). The number of floats
anthony3d2f4862011-05-01 13:48:16 +0000392** needed to represent a color varies depending on the current channel
anthonydf8ebac2011-04-27 09:03:19 +0000393** setting.
394*/
cristy3884f692011-07-08 18:00:18 +0000395static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000396 const SparseColorMethod method,const char *arguments,
397 const MagickBooleanType color_from_image,ExceptionInfo *exception)
398{
anthonydf8ebac2011-04-27 09:03:19 +0000399 char
400 token[MaxTextExtent];
401
402 const char
403 *p;
404
405 double
406 *sparse_arguments;
407
anthonydf8ebac2011-04-27 09:03:19 +0000408 Image
409 *sparse_image;
410
cristy4c08aed2011-07-01 19:47:50 +0000411 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000412 color;
413
414 MagickBooleanType
415 error;
416
cristy5f09d852011-05-29 01:39:29 +0000417 register size_t
418 x;
419
420 size_t
421 number_arguments,
422 number_colors;
423
anthonydf8ebac2011-04-27 09:03:19 +0000424 assert(image != (Image *) NULL);
425 assert(image->signature == MagickSignature);
426 if (image->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
428 assert(exception != (ExceptionInfo *) NULL);
429 assert(exception->signature == MagickSignature);
430 /*
431 Limit channels according to image - and add up number of color channel.
432 */
anthonydf8ebac2011-04-27 09:03:19 +0000433 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000434 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000435 number_colors++;
cristyed231572011-07-14 02:18:59 +0000436 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000437 number_colors++;
cristyed231572011-07-14 02:18:59 +0000438 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000439 number_colors++;
cristyed231572011-07-14 02:18:59 +0000440 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000441 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000442 number_colors++;
cristyed231572011-07-14 02:18:59 +0000443 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000444 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000445 number_colors++;
446
447 /*
448 Read string, to determine number of arguments needed,
449 */
450 p=arguments;
451 x=0;
452 while( *p != '\0' )
453 {
454 GetMagickToken(p,&p,token);
455 if ( token[0] == ',' ) continue;
456 if ( isalpha((int) token[0]) || token[0] == '#' ) {
457 if ( color_from_image ) {
458 (void) ThrowMagickException(exception,GetMagickModule(),
459 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
460 "Color arg given, when colors are coming from image");
461 return( (Image *)NULL);
462 }
463 x += number_colors; /* color argument */
464 }
465 else {
466 x++; /* floating point argument */
467 }
468 }
469 error=MagickTrue;
470 if ( color_from_image ) {
471 /* just the control points are being given */
472 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
473 number_arguments=(x/2)*(2+number_colors);
474 }
475 else {
476 /* control points and color values */
477 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
478 number_arguments=x;
479 }
480 if ( error ) {
481 (void) ThrowMagickException(exception,GetMagickModule(),
482 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
483 "Invalid number of Arguments");
484 return( (Image *)NULL);
485 }
486
487 /* Allocate and fill in the floating point arguments */
488 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
489 sizeof(*sparse_arguments));
490 if (sparse_arguments == (double *) NULL) {
491 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
492 "MemoryAllocationFailed","%s","SparseColorOption");
493 return( (Image *)NULL);
494 }
495 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
496 sizeof(*sparse_arguments));
497 p=arguments;
498 x=0;
499 while( *p != '\0' && x < number_arguments ) {
500 /* X coordinate */
501 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
502 if ( token[0] == '\0' ) break;
503 if ( isalpha((int) token[0]) || token[0] == '#' ) {
504 (void) ThrowMagickException(exception,GetMagickModule(),
505 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
506 "Color found, instead of X-coord");
507 error = MagickTrue;
508 break;
509 }
cristyc1acd842011-05-19 23:05:47 +0000510 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000511 /* Y coordinate */
512 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
513 if ( token[0] == '\0' ) break;
514 if ( isalpha((int) token[0]) || token[0] == '#' ) {
515 (void) ThrowMagickException(exception,GetMagickModule(),
516 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
517 "Color found, instead of Y-coord");
518 error = MagickTrue;
519 break;
520 }
cristyc1acd842011-05-19 23:05:47 +0000521 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000522 /* color values for this control point */
523#if 0
524 if ( (color_from_image ) {
525 /* get color from image */
526 /* HOW??? */
527 }
528 else
529#endif
530 {
531 /* color name or function given in string argument */
532 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
533 if ( token[0] == '\0' ) break;
534 if ( isalpha((int) token[0]) || token[0] == '#' ) {
535 /* Color string given */
536 (void) QueryMagickColor(token,&color,exception);
cristyed231572011-07-14 02:18:59 +0000537 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000538 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000539 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000540 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000541 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000542 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000543 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000544 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000545 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000546 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000547 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000548 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000549 }
550 else {
551 /* Colors given as a set of floating point values - experimental */
552 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000553 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000554 {
anthonydf8ebac2011-04-27 09:03:19 +0000555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristyc1acd842011-05-19 23:05:47 +0000558 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000559 token[0] = ','; /* used this token - get another */
560 }
cristyed231572011-07-14 02:18:59 +0000561 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000562 {
anthonydf8ebac2011-04-27 09:03:19 +0000563 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
564 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
565 break;
cristyc1acd842011-05-19 23:05:47 +0000566 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000567 token[0] = ','; /* used this token - get another */
568 }
cristyed231572011-07-14 02:18:59 +0000569 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000570 {
anthonydf8ebac2011-04-27 09:03:19 +0000571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristyc1acd842011-05-19 23:05:47 +0000574 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
cristyed231572011-07-14 02:18:59 +0000577 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000578 (image->colorspace == CMYKColorspace))
579 {
anthonydf8ebac2011-04-27 09:03:19 +0000580 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
581 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
582 break;
cristyc1acd842011-05-19 23:05:47 +0000583 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000584 token[0] = ','; /* used this token - get another */
585 }
cristyed231572011-07-14 02:18:59 +0000586 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000587 (image->matte != MagickFalse))
588 {
anthonydf8ebac2011-04-27 09:03:19 +0000589 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
590 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
591 break;
cristyc1acd842011-05-19 23:05:47 +0000592 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000593 token[0] = ','; /* used this token - get another */
594 }
595 }
596 }
597 }
598 if ( number_arguments != x && !error ) {
599 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
600 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
601 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
602 return( (Image *)NULL);
603 }
604 if ( error )
605 return( (Image *)NULL);
606
607 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000608 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
609 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000610 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
611 return( sparse_image );
612}
613
cristy3ed852e2009-09-05 21:47:34 +0000614WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
615 const char **argv,Image **image,ExceptionInfo *exception)
616{
anthonydf8ebac2011-04-27 09:03:19 +0000617 ChannelType
618 channel;
619
620 const char
621 *format,
622 *option;
623
624 DrawInfo
625 *draw_info;
626
627 GeometryInfo
628 geometry_info;
629
cristy3ed852e2009-09-05 21:47:34 +0000630 Image
631 *region_image;
632
anthonydf8ebac2011-04-27 09:03:19 +0000633 ImageInfo
634 *mogrify_info;
635
cristyebbcfea2011-02-25 02:43:54 +0000636 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000637 status;
638
cristy4c08aed2011-07-01 19:47:50 +0000639 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000640 fill;
cristy3ed852e2009-09-05 21:47:34 +0000641
anthonydf8ebac2011-04-27 09:03:19 +0000642 MagickStatusType
643 flags;
644
645 QuantizeInfo
646 *quantize_info;
647
648 RectangleInfo
649 geometry,
650 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000651
cristybb503372010-05-27 20:51:26 +0000652 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000653 i;
654
655 /*
656 Initialize method variables.
657 */
658 assert(image_info != (const ImageInfo *) NULL);
659 assert(image_info->signature == MagickSignature);
660 assert(image != (Image **) NULL);
661 assert((*image)->signature == MagickSignature);
662 if ((*image)->debug != MagickFalse)
663 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
664 if (argc < 0)
665 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000666 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000667 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
668 quantize_info=AcquireQuantizeInfo(mogrify_info);
669 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000670 GetPixelInfo(*image,&fill);
671 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
anthonydf8ebac2011-04-27 09:03:19 +0000672 channel=mogrify_info->channel;
673 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000674 SetGeometry(*image,&region_geometry);
675 region_image=NewImageList();
676 /*
677 Transmogrify the image.
678 */
cristybb503372010-05-27 20:51:26 +0000679 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000680 {
anthonydf8ebac2011-04-27 09:03:19 +0000681 Image
682 *mogrify_image;
683
anthonye9c27192011-03-27 08:07:06 +0000684 ssize_t
685 count;
686
anthonydf8ebac2011-04-27 09:03:19 +0000687 option=argv[i];
688 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000689 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000690 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
691 0L);
cristycee97112010-05-28 00:44:52 +0000692 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000693 break;
cristy6b3da3a2010-06-20 02:21:46 +0000694 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000695 mogrify_image=(Image *)NULL;
696 switch (*(option+1))
697 {
698 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000699 {
anthonydf8ebac2011-04-27 09:03:19 +0000700 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000701 {
anthonydf8ebac2011-04-27 09:03:19 +0000702 /*
703 Adaptive blur image.
704 */
705 (void) SyncImageSettings(mogrify_info,*image);
706 flags=ParseGeometry(argv[i+1],&geometry_info);
707 if ((flags & SigmaValue) == 0)
708 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000709 if ((flags & XiValue) == 0)
710 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000711 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000712 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000713 break;
cristy3ed852e2009-09-05 21:47:34 +0000714 }
anthonydf8ebac2011-04-27 09:03:19 +0000715 if (LocaleCompare("adaptive-resize",option+1) == 0)
716 {
717 /*
718 Adaptive resize image.
719 */
720 (void) SyncImageSettings(mogrify_info,*image);
721 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
722 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy5c4e2582011-09-11 19:21:03 +0000723 geometry.height,(*image)->interpolate,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000724 break;
725 }
726 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
727 {
728 /*
729 Adaptive sharpen image.
730 */
731 (void) SyncImageSettings(mogrify_info,*image);
732 flags=ParseGeometry(argv[i+1],&geometry_info);
733 if ((flags & SigmaValue) == 0)
734 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000735 if ((flags & XiValue) == 0)
736 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000737 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000738 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000739 break;
740 }
741 if (LocaleCompare("affine",option+1) == 0)
742 {
743 /*
744 Affine matrix.
745 */
746 if (*option == '+')
747 {
748 GetAffineMatrix(&draw_info->affine);
749 break;
750 }
751 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
752 break;
753 }
754 if (LocaleCompare("alpha",option+1) == 0)
755 {
756 AlphaChannelType
757 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000758
anthonydf8ebac2011-04-27 09:03:19 +0000759 (void) SyncImageSettings(mogrify_info,*image);
760 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
761 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000762 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000763 break;
764 }
765 if (LocaleCompare("annotate",option+1) == 0)
766 {
767 char
768 *text,
769 geometry[MaxTextExtent];
770
771 /*
772 Annotate image.
773 */
774 (void) SyncImageSettings(mogrify_info,*image);
775 SetGeometryInfo(&geometry_info);
776 flags=ParseGeometry(argv[i+1],&geometry_info);
777 if ((flags & SigmaValue) == 0)
778 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000779 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
780 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000781 if (text == (char *) NULL)
782 break;
783 (void) CloneString(&draw_info->text,text);
784 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000785 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000786 geometry_info.xi,geometry_info.psi);
787 (void) CloneString(&draw_info->geometry,geometry);
788 draw_info->affine.sx=cos(DegreesToRadians(
789 fmod(geometry_info.rho,360.0)));
790 draw_info->affine.rx=sin(DegreesToRadians(
791 fmod(geometry_info.rho,360.0)));
792 draw_info->affine.ry=(-sin(DegreesToRadians(
793 fmod(geometry_info.sigma,360.0))));
794 draw_info->affine.sy=cos(DegreesToRadians(
795 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000796 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000797 break;
798 }
799 if (LocaleCompare("antialias",option+1) == 0)
800 {
801 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
802 MagickFalse;
803 draw_info->text_antialias=(*option == '-') ? MagickTrue :
804 MagickFalse;
805 break;
806 }
807 if (LocaleCompare("auto-gamma",option+1) == 0)
808 {
809 /*
810 Auto Adjust Gamma of image based on its mean
811 */
812 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000813 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000814 break;
815 }
816 if (LocaleCompare("auto-level",option+1) == 0)
817 {
818 /*
819 Perfectly Normalize (max/min stretch) the image
820 */
821 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000822 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000823 break;
824 }
825 if (LocaleCompare("auto-orient",option+1) == 0)
826 {
827 (void) SyncImageSettings(mogrify_info,*image);
828 switch ((*image)->orientation)
829 {
830 case TopRightOrientation:
831 {
832 mogrify_image=FlopImage(*image,exception);
833 break;
834 }
835 case BottomRightOrientation:
836 {
837 mogrify_image=RotateImage(*image,180.0,exception);
838 break;
839 }
840 case BottomLeftOrientation:
841 {
842 mogrify_image=FlipImage(*image,exception);
843 break;
844 }
845 case LeftTopOrientation:
846 {
847 mogrify_image=TransposeImage(*image,exception);
848 break;
849 }
850 case RightTopOrientation:
851 {
852 mogrify_image=RotateImage(*image,90.0,exception);
853 break;
854 }
855 case RightBottomOrientation:
856 {
857 mogrify_image=TransverseImage(*image,exception);
858 break;
859 }
860 case LeftBottomOrientation:
861 {
862 mogrify_image=RotateImage(*image,270.0,exception);
863 break;
864 }
865 default:
866 break;
867 }
868 if (mogrify_image != (Image *) NULL)
869 mogrify_image->orientation=TopLeftOrientation;
870 break;
871 }
872 break;
873 }
874 case 'b':
875 {
876 if (LocaleCompare("black-threshold",option+1) == 0)
877 {
878 /*
879 Black threshold image.
880 */
881 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000882 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000883 InheritException(exception,&(*image)->exception);
884 break;
885 }
886 if (LocaleCompare("blue-shift",option+1) == 0)
887 {
888 /*
889 Blue shift image.
890 */
891 (void) SyncImageSettings(mogrify_info,*image);
892 geometry_info.rho=1.5;
893 if (*option == '-')
894 flags=ParseGeometry(argv[i+1],&geometry_info);
895 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
896 break;
897 }
898 if (LocaleCompare("blur",option+1) == 0)
899 {
900 /*
901 Gaussian blur image.
902 */
903 (void) SyncImageSettings(mogrify_info,*image);
904 flags=ParseGeometry(argv[i+1],&geometry_info);
905 if ((flags & SigmaValue) == 0)
906 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000907 if ((flags & XiValue) == 0)
908 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000909 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000910 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000911 break;
912 }
913 if (LocaleCompare("border",option+1) == 0)
914 {
915 /*
916 Surround image with a border of solid color.
917 */
918 (void) SyncImageSettings(mogrify_info,*image);
919 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
920 if ((flags & SigmaValue) == 0)
921 geometry.height=geometry.width;
922 mogrify_image=BorderImage(*image,&geometry,exception);
923 break;
924 }
925 if (LocaleCompare("bordercolor",option+1) == 0)
926 {
927 if (*option == '+')
928 {
cristy05c0c9a2011-09-05 23:16:13 +0000929 (void) QueryColorDatabase(MogrifyBorderColor,
930 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000931 break;
932 }
933 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
934 exception);
935 break;
936 }
937 if (LocaleCompare("box",option+1) == 0)
938 {
939 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
940 exception);
941 break;
942 }
943 if (LocaleCompare("brightness-contrast",option+1) == 0)
944 {
945 double
946 brightness,
947 contrast;
948
949 GeometryInfo
950 geometry_info;
951
952 MagickStatusType
953 flags;
954
955 /*
956 Brightness / contrast image.
957 */
958 (void) SyncImageSettings(mogrify_info,*image);
959 flags=ParseGeometry(argv[i+1],&geometry_info);
960 brightness=geometry_info.rho;
961 contrast=0.0;
962 if ((flags & SigmaValue) != 0)
963 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000964 (void) BrightnessContrastImage(*image,brightness,contrast,
965 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000966 InheritException(exception,&(*image)->exception);
967 break;
968 }
969 break;
970 }
971 case 'c':
972 {
973 if (LocaleCompare("cdl",option+1) == 0)
974 {
975 char
976 *color_correction_collection;
977
978 /*
979 Color correct with a color decision list.
980 */
981 (void) SyncImageSettings(mogrify_info,*image);
982 color_correction_collection=FileToString(argv[i+1],~0,exception);
983 if (color_correction_collection == (char *) NULL)
984 break;
cristy1bfa9f02011-08-11 02:35:43 +0000985 (void) ColorDecisionListImage(*image,color_correction_collection,
986 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000987 InheritException(exception,&(*image)->exception);
988 break;
989 }
990 if (LocaleCompare("channel",option+1) == 0)
991 {
992 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000993 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000994 else
cristyfa806a72011-07-04 02:06:13 +0000995 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +0000996 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000997 break;
998 }
999 if (LocaleCompare("charcoal",option+1) == 0)
1000 {
1001 /*
1002 Charcoal image.
1003 */
1004 (void) SyncImageSettings(mogrify_info,*image);
1005 flags=ParseGeometry(argv[i+1],&geometry_info);
1006 if ((flags & SigmaValue) == 0)
1007 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001008 if ((flags & XiValue) == 0)
1009 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001010 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001011 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001012 break;
1013 }
1014 if (LocaleCompare("chop",option+1) == 0)
1015 {
1016 /*
1017 Chop the image.
1018 */
1019 (void) SyncImageSettings(mogrify_info,*image);
1020 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1021 mogrify_image=ChopImage(*image,&geometry,exception);
1022 break;
1023 }
1024 if (LocaleCompare("clamp",option+1) == 0)
1025 {
1026 /*
1027 Clamp image.
1028 */
1029 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001030 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001031 InheritException(exception,&(*image)->exception);
1032 break;
1033 }
1034 if (LocaleCompare("clip",option+1) == 0)
1035 {
1036 (void) SyncImageSettings(mogrify_info,*image);
1037 if (*option == '+')
1038 {
cristy018f07f2011-09-04 21:15:19 +00001039 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001040 break;
1041 }
cristy018f07f2011-09-04 21:15:19 +00001042 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001043 break;
1044 }
1045 if (LocaleCompare("clip-mask",option+1) == 0)
1046 {
1047 CacheView
1048 *mask_view;
1049
1050 Image
1051 *mask_image;
1052
cristy4c08aed2011-07-01 19:47:50 +00001053 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001054 *restrict q;
1055
1056 register ssize_t
1057 x;
1058
1059 ssize_t
1060 y;
1061
1062 (void) SyncImageSettings(mogrify_info,*image);
1063 if (*option == '+')
1064 {
1065 /*
1066 Remove a mask.
1067 */
cristy018f07f2011-09-04 21:15:19 +00001068 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001069 break;
1070 }
1071 /*
1072 Set the image mask.
1073 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1074 */
1075 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1076 if (mask_image == (Image *) NULL)
1077 break;
cristy574cc262011-08-05 01:23:58 +00001078 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001079 return(MagickFalse);
1080 mask_view=AcquireCacheView(mask_image);
1081 for (y=0; y < (ssize_t) mask_image->rows; y++)
1082 {
1083 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1084 exception);
cristyacd2ed22011-08-30 01:44:23 +00001085 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001086 break;
1087 for (x=0; x < (ssize_t) mask_image->columns; x++)
1088 {
1089 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001090 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1091 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1092 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1093 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001094 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001095 }
1096 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1097 break;
1098 }
1099 mask_view=DestroyCacheView(mask_view);
1100 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001101 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001102 InheritException(exception,&(*image)->exception);
1103 break;
1104 }
1105 if (LocaleCompare("clip-path",option+1) == 0)
1106 {
1107 (void) SyncImageSettings(mogrify_info,*image);
1108 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001109 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001110 break;
1111 }
1112 if (LocaleCompare("colorize",option+1) == 0)
1113 {
1114 /*
1115 Colorize the image.
1116 */
1117 (void) SyncImageSettings(mogrify_info,*image);
1118 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1119 exception);
1120 break;
1121 }
1122 if (LocaleCompare("color-matrix",option+1) == 0)
1123 {
1124 KernelInfo
1125 *kernel;
1126
1127 (void) SyncImageSettings(mogrify_info,*image);
1128 kernel=AcquireKernelInfo(argv[i+1]);
1129 if (kernel == (KernelInfo *) NULL)
1130 break;
1131 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1132 kernel=DestroyKernelInfo(kernel);
1133 break;
1134 }
1135 if (LocaleCompare("colors",option+1) == 0)
1136 {
1137 /*
1138 Reduce the number of colors in the image.
1139 */
1140 (void) SyncImageSettings(mogrify_info,*image);
1141 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1142 if (quantize_info->number_colors == 0)
1143 break;
1144 if (((*image)->storage_class == DirectClass) ||
1145 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001146 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001147 else
cristy018f07f2011-09-04 21:15:19 +00001148 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001149 break;
1150 }
1151 if (LocaleCompare("colorspace",option+1) == 0)
1152 {
1153 ColorspaceType
1154 colorspace;
1155
1156 (void) SyncImageSettings(mogrify_info,*image);
1157 if (*option == '+')
1158 {
1159 (void) TransformImageColorspace(*image,RGBColorspace);
1160 InheritException(exception,&(*image)->exception);
1161 break;
1162 }
1163 colorspace=(ColorspaceType) ParseCommandOption(
1164 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1165 (void) TransformImageColorspace(*image,colorspace);
1166 InheritException(exception,&(*image)->exception);
1167 break;
1168 }
1169 if (LocaleCompare("contrast",option+1) == 0)
1170 {
1171 (void) SyncImageSettings(mogrify_info,*image);
1172 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001173 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001174 break;
1175 }
1176 if (LocaleCompare("contrast-stretch",option+1) == 0)
1177 {
1178 double
1179 black_point,
1180 white_point;
1181
1182 MagickStatusType
1183 flags;
1184
1185 /*
1186 Contrast stretch image.
1187 */
1188 (void) SyncImageSettings(mogrify_info,*image);
1189 flags=ParseGeometry(argv[i+1],&geometry_info);
1190 black_point=geometry_info.rho;
1191 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1192 black_point;
1193 if ((flags & PercentValue) != 0)
1194 {
1195 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1196 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1197 }
1198 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1199 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001200 (void) ContrastStretchImage(*image,black_point,white_point,
1201 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001202 InheritException(exception,&(*image)->exception);
1203 break;
1204 }
1205 if (LocaleCompare("convolve",option+1) == 0)
1206 {
anthonydf8ebac2011-04-27 09:03:19 +00001207 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001208 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001209
anthonydf8ebac2011-04-27 09:03:19 +00001210 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001211 kernel_info=AcquireKernelInfo(argv[i+1]);
1212 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001213 break;
cristy0a922382011-07-16 15:30:34 +00001214 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001215 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001216 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001217 break;
1218 }
1219 if (LocaleCompare("crop",option+1) == 0)
1220 {
1221 /*
1222 Crop a image to a smaller size
1223 */
1224 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001225 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001226 break;
1227 }
1228 if (LocaleCompare("cycle",option+1) == 0)
1229 {
1230 /*
1231 Cycle an image colormap.
1232 */
1233 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00001234 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1235 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001236 break;
1237 }
1238 break;
1239 }
1240 case 'd':
1241 {
1242 if (LocaleCompare("decipher",option+1) == 0)
1243 {
1244 StringInfo
1245 *passkey;
1246
1247 /*
1248 Decipher pixels.
1249 */
1250 (void) SyncImageSettings(mogrify_info,*image);
1251 passkey=FileToStringInfo(argv[i+1],~0,exception);
1252 if (passkey != (StringInfo *) NULL)
1253 {
1254 (void) PasskeyDecipherImage(*image,passkey,exception);
1255 passkey=DestroyStringInfo(passkey);
1256 }
1257 break;
1258 }
1259 if (LocaleCompare("density",option+1) == 0)
1260 {
1261 /*
1262 Set image density.
1263 */
1264 (void) CloneString(&draw_info->density,argv[i+1]);
1265 break;
1266 }
1267 if (LocaleCompare("depth",option+1) == 0)
1268 {
1269 (void) SyncImageSettings(mogrify_info,*image);
1270 if (*option == '+')
1271 {
1272 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1273 break;
1274 }
1275 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1276 break;
1277 }
1278 if (LocaleCompare("deskew",option+1) == 0)
1279 {
1280 double
1281 threshold;
1282
1283 /*
1284 Straighten the image.
1285 */
1286 (void) SyncImageSettings(mogrify_info,*image);
1287 if (*option == '+')
1288 threshold=40.0*QuantumRange/100.0;
1289 else
1290 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1291 mogrify_image=DeskewImage(*image,threshold,exception);
1292 break;
1293 }
1294 if (LocaleCompare("despeckle",option+1) == 0)
1295 {
1296 /*
1297 Reduce the speckles within an image.
1298 */
1299 (void) SyncImageSettings(mogrify_info,*image);
1300 mogrify_image=DespeckleImage(*image,exception);
1301 break;
1302 }
1303 if (LocaleCompare("display",option+1) == 0)
1304 {
1305 (void) CloneString(&draw_info->server_name,argv[i+1]);
1306 break;
1307 }
1308 if (LocaleCompare("distort",option+1) == 0)
1309 {
1310 char
1311 *args,
1312 token[MaxTextExtent];
1313
1314 const char
1315 *p;
1316
1317 DistortImageMethod
1318 method;
1319
1320 double
1321 *arguments;
1322
1323 register ssize_t
1324 x;
1325
1326 size_t
1327 number_arguments;
1328
1329 /*
1330 Distort image.
1331 */
1332 (void) SyncImageSettings(mogrify_info,*image);
1333 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1334 MagickFalse,argv[i+1]);
1335 if ( method == ResizeDistortion )
1336 {
1337 /* Special Case - Argument is actually a resize geometry!
1338 ** Convert that to an appropriate distortion argument array.
1339 */
1340 double
1341 resize_args[2];
1342 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1343 exception);
1344 resize_args[0]=(double)geometry.width;
1345 resize_args[1]=(double)geometry.height;
1346 mogrify_image=DistortImage(*image,method,(size_t)2,
1347 resize_args,MagickTrue,exception);
1348 break;
1349 }
cristy018f07f2011-09-04 21:15:19 +00001350 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1351 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001352 if (args == (char *) NULL)
1353 break;
1354 p=(char *) args;
1355 for (x=0; *p != '\0'; x++)
1356 {
1357 GetMagickToken(p,&p,token);
1358 if (*token == ',')
1359 GetMagickToken(p,&p,token);
1360 }
1361 number_arguments=(size_t) x;
1362 arguments=(double *) AcquireQuantumMemory(number_arguments,
1363 sizeof(*arguments));
1364 if (arguments == (double *) NULL)
1365 ThrowWandFatalException(ResourceLimitFatalError,
1366 "MemoryAllocationFailed",(*image)->filename);
1367 (void) ResetMagickMemory(arguments,0,number_arguments*
1368 sizeof(*arguments));
1369 p=(char *) args;
1370 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1371 {
1372 GetMagickToken(p,&p,token);
1373 if (*token == ',')
1374 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001375 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001376 }
1377 args=DestroyString(args);
1378 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1379 (*option == '+') ? MagickTrue : MagickFalse,exception);
1380 arguments=(double *) RelinquishMagickMemory(arguments);
1381 break;
1382 }
1383 if (LocaleCompare("dither",option+1) == 0)
1384 {
1385 if (*option == '+')
1386 {
1387 quantize_info->dither=MagickFalse;
1388 break;
1389 }
1390 quantize_info->dither=MagickTrue;
1391 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1392 MagickDitherOptions,MagickFalse,argv[i+1]);
1393 if (quantize_info->dither_method == NoDitherMethod)
1394 quantize_info->dither=MagickFalse;
1395 break;
1396 }
1397 if (LocaleCompare("draw",option+1) == 0)
1398 {
1399 /*
1400 Draw image.
1401 */
1402 (void) SyncImageSettings(mogrify_info,*image);
1403 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001404 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001405 break;
1406 }
1407 break;
1408 }
1409 case 'e':
1410 {
1411 if (LocaleCompare("edge",option+1) == 0)
1412 {
1413 /*
1414 Enhance edges in the image.
1415 */
1416 (void) SyncImageSettings(mogrify_info,*image);
1417 flags=ParseGeometry(argv[i+1],&geometry_info);
1418 if ((flags & SigmaValue) == 0)
1419 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001420 mogrify_image=EdgeImage(*image,geometry_info.rho,
1421 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001422 break;
1423 }
1424 if (LocaleCompare("emboss",option+1) == 0)
1425 {
1426 /*
1427 Gaussian embossen image.
1428 */
1429 (void) SyncImageSettings(mogrify_info,*image);
1430 flags=ParseGeometry(argv[i+1],&geometry_info);
1431 if ((flags & SigmaValue) == 0)
1432 geometry_info.sigma=1.0;
1433 mogrify_image=EmbossImage(*image,geometry_info.rho,
1434 geometry_info.sigma,exception);
1435 break;
1436 }
1437 if (LocaleCompare("encipher",option+1) == 0)
1438 {
1439 StringInfo
1440 *passkey;
1441
1442 /*
1443 Encipher pixels.
1444 */
1445 (void) SyncImageSettings(mogrify_info,*image);
1446 passkey=FileToStringInfo(argv[i+1],~0,exception);
1447 if (passkey != (StringInfo *) NULL)
1448 {
1449 (void) PasskeyEncipherImage(*image,passkey,exception);
1450 passkey=DestroyStringInfo(passkey);
1451 }
1452 break;
1453 }
1454 if (LocaleCompare("encoding",option+1) == 0)
1455 {
1456 (void) CloneString(&draw_info->encoding,argv[i+1]);
1457 break;
1458 }
1459 if (LocaleCompare("enhance",option+1) == 0)
1460 {
1461 /*
1462 Enhance image.
1463 */
1464 (void) SyncImageSettings(mogrify_info,*image);
1465 mogrify_image=EnhanceImage(*image,exception);
1466 break;
1467 }
1468 if (LocaleCompare("equalize",option+1) == 0)
1469 {
1470 /*
1471 Equalize image.
1472 */
1473 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001474 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001475 break;
1476 }
1477 if (LocaleCompare("evaluate",option+1) == 0)
1478 {
1479 double
1480 constant;
1481
1482 MagickEvaluateOperator
1483 op;
1484
1485 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001486 op=(MagickEvaluateOperator) ParseCommandOption(
1487 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001488 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001489 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001490 break;
1491 }
1492 if (LocaleCompare("extent",option+1) == 0)
1493 {
1494 /*
1495 Set the image extent.
1496 */
1497 (void) SyncImageSettings(mogrify_info,*image);
1498 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1499 if (geometry.width == 0)
1500 geometry.width=(*image)->columns;
1501 if (geometry.height == 0)
1502 geometry.height=(*image)->rows;
1503 mogrify_image=ExtentImage(*image,&geometry,exception);
1504 break;
1505 }
1506 break;
1507 }
1508 case 'f':
1509 {
1510 if (LocaleCompare("family",option+1) == 0)
1511 {
1512 if (*option == '+')
1513 {
1514 if (draw_info->family != (char *) NULL)
1515 draw_info->family=DestroyString(draw_info->family);
1516 break;
1517 }
1518 (void) CloneString(&draw_info->family,argv[i+1]);
1519 break;
1520 }
1521 if (LocaleCompare("features",option+1) == 0)
1522 {
1523 if (*option == '+')
1524 {
1525 (void) DeleteImageArtifact(*image,"identify:features");
1526 break;
1527 }
1528 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1529 break;
1530 }
1531 if (LocaleCompare("fill",option+1) == 0)
1532 {
1533 ExceptionInfo
1534 *sans;
1535
cristy4c08aed2011-07-01 19:47:50 +00001536 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001537 if (*option == '+')
1538 {
1539 (void) QueryMagickColor("none",&fill,exception);
1540 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1541 if (draw_info->fill_pattern != (Image *) NULL)
1542 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1543 break;
1544 }
1545 sans=AcquireExceptionInfo();
1546 (void) QueryMagickColor(argv[i+1],&fill,sans);
1547 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1548 sans=DestroyExceptionInfo(sans);
1549 if (status == MagickFalse)
1550 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1551 exception);
1552 break;
1553 }
1554 if (LocaleCompare("flip",option+1) == 0)
1555 {
1556 /*
1557 Flip image scanlines.
1558 */
1559 (void) SyncImageSettings(mogrify_info,*image);
1560 mogrify_image=FlipImage(*image,exception);
1561 break;
1562 }
anthonydf8ebac2011-04-27 09:03:19 +00001563 if (LocaleCompare("floodfill",option+1) == 0)
1564 {
cristy4c08aed2011-07-01 19:47:50 +00001565 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001566 target;
1567
1568 /*
1569 Floodfill image.
1570 */
1571 (void) SyncImageSettings(mogrify_info,*image);
1572 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1573 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001574 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001575 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001576 break;
1577 }
anthony3d2f4862011-05-01 13:48:16 +00001578 if (LocaleCompare("flop",option+1) == 0)
1579 {
1580 /*
1581 Flop image scanlines.
1582 */
1583 (void) SyncImageSettings(mogrify_info,*image);
1584 mogrify_image=FlopImage(*image,exception);
1585 break;
1586 }
anthonydf8ebac2011-04-27 09:03:19 +00001587 if (LocaleCompare("font",option+1) == 0)
1588 {
1589 if (*option == '+')
1590 {
1591 if (draw_info->font != (char *) NULL)
1592 draw_info->font=DestroyString(draw_info->font);
1593 break;
1594 }
1595 (void) CloneString(&draw_info->font,argv[i+1]);
1596 break;
1597 }
1598 if (LocaleCompare("format",option+1) == 0)
1599 {
1600 format=argv[i+1];
1601 break;
1602 }
1603 if (LocaleCompare("frame",option+1) == 0)
1604 {
1605 FrameInfo
1606 frame_info;
1607
1608 /*
1609 Surround image with an ornamental border.
1610 */
1611 (void) SyncImageSettings(mogrify_info,*image);
1612 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1613 frame_info.width=geometry.width;
1614 frame_info.height=geometry.height;
1615 if ((flags & HeightValue) == 0)
1616 frame_info.height=geometry.width;
1617 frame_info.outer_bevel=geometry.x;
1618 frame_info.inner_bevel=geometry.y;
1619 frame_info.x=(ssize_t) frame_info.width;
1620 frame_info.y=(ssize_t) frame_info.height;
1621 frame_info.width=(*image)->columns+2*frame_info.width;
1622 frame_info.height=(*image)->rows+2*frame_info.height;
1623 mogrify_image=FrameImage(*image,&frame_info,exception);
1624 break;
1625 }
1626 if (LocaleCompare("function",option+1) == 0)
1627 {
1628 char
1629 *arguments,
1630 token[MaxTextExtent];
1631
1632 const char
1633 *p;
1634
1635 double
1636 *parameters;
1637
1638 MagickFunction
1639 function;
1640
1641 register ssize_t
1642 x;
1643
1644 size_t
1645 number_parameters;
1646
1647 /*
1648 Function Modify Image Values
1649 */
1650 (void) SyncImageSettings(mogrify_info,*image);
1651 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1652 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001653 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1654 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001655 if (arguments == (char *) NULL)
1656 break;
1657 p=(char *) arguments;
1658 for (x=0; *p != '\0'; x++)
1659 {
1660 GetMagickToken(p,&p,token);
1661 if (*token == ',')
1662 GetMagickToken(p,&p,token);
1663 }
1664 number_parameters=(size_t) x;
1665 parameters=(double *) AcquireQuantumMemory(number_parameters,
1666 sizeof(*parameters));
1667 if (parameters == (double *) NULL)
1668 ThrowWandFatalException(ResourceLimitFatalError,
1669 "MemoryAllocationFailed",(*image)->filename);
1670 (void) ResetMagickMemory(parameters,0,number_parameters*
1671 sizeof(*parameters));
1672 p=(char *) arguments;
1673 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1674 {
1675 GetMagickToken(p,&p,token);
1676 if (*token == ',')
1677 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001678 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001679 }
1680 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001681 (void) FunctionImage(*image,function,number_parameters,parameters,
1682 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001683 parameters=(double *) RelinquishMagickMemory(parameters);
1684 break;
1685 }
1686 break;
1687 }
1688 case 'g':
1689 {
1690 if (LocaleCompare("gamma",option+1) == 0)
1691 {
1692 /*
1693 Gamma image.
1694 */
1695 (void) SyncImageSettings(mogrify_info,*image);
1696 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001697 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001698 else
cristyb3e7c6c2011-07-24 01:43:55 +00001699 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1700 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001701 break;
1702 }
1703 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1704 (LocaleCompare("gaussian",option+1) == 0))
1705 {
1706 /*
1707 Gaussian blur image.
1708 */
1709 (void) SyncImageSettings(mogrify_info,*image);
1710 flags=ParseGeometry(argv[i+1],&geometry_info);
1711 if ((flags & SigmaValue) == 0)
1712 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001713 if ((flags & XiValue) == 0)
1714 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001715 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001716 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001717 break;
1718 }
1719 if (LocaleCompare("geometry",option+1) == 0)
1720 {
1721 /*
1722 Record Image offset, Resize last image.
1723 */
1724 (void) SyncImageSettings(mogrify_info,*image);
1725 if (*option == '+')
1726 {
1727 if ((*image)->geometry != (char *) NULL)
1728 (*image)->geometry=DestroyString((*image)->geometry);
1729 break;
1730 }
1731 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1732 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1733 (void) CloneString(&(*image)->geometry,argv[i+1]);
1734 else
1735 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1736 (*image)->filter,(*image)->blur,exception);
1737 break;
1738 }
1739 if (LocaleCompare("gravity",option+1) == 0)
1740 {
1741 if (*option == '+')
1742 {
1743 draw_info->gravity=UndefinedGravity;
1744 break;
1745 }
1746 draw_info->gravity=(GravityType) ParseCommandOption(
1747 MagickGravityOptions,MagickFalse,argv[i+1]);
1748 break;
1749 }
1750 break;
1751 }
1752 case 'h':
1753 {
1754 if (LocaleCompare("highlight-color",option+1) == 0)
1755 {
1756 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1757 break;
1758 }
1759 break;
1760 }
1761 case 'i':
1762 {
1763 if (LocaleCompare("identify",option+1) == 0)
1764 {
1765 char
1766 *text;
1767
1768 (void) SyncImageSettings(mogrify_info,*image);
1769 if (format == (char *) NULL)
1770 {
cristya4037272011-08-28 15:11:39 +00001771 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1772 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001773 break;
1774 }
cristy018f07f2011-09-04 21:15:19 +00001775 text=InterpretImageProperties(mogrify_info,*image,format,
1776 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001777 if (text == (char *) NULL)
1778 break;
1779 (void) fputs(text,stdout);
1780 (void) fputc('\n',stdout);
1781 text=DestroyString(text);
1782 break;
1783 }
1784 if (LocaleCompare("implode",option+1) == 0)
1785 {
1786 /*
1787 Implode image.
1788 */
1789 (void) SyncImageSettings(mogrify_info,*image);
1790 (void) ParseGeometry(argv[i+1],&geometry_info);
1791 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1792 break;
1793 }
1794 if (LocaleCompare("interline-spacing",option+1) == 0)
1795 {
1796 if (*option == '+')
1797 (void) ParseGeometry("0",&geometry_info);
1798 else
1799 (void) ParseGeometry(argv[i+1],&geometry_info);
1800 draw_info->interline_spacing=geometry_info.rho;
1801 break;
1802 }
1803 if (LocaleCompare("interword-spacing",option+1) == 0)
1804 {
1805 if (*option == '+')
1806 (void) ParseGeometry("0",&geometry_info);
1807 else
1808 (void) ParseGeometry(argv[i+1],&geometry_info);
1809 draw_info->interword_spacing=geometry_info.rho;
1810 break;
1811 }
1812 break;
1813 }
1814 case 'k':
1815 {
1816 if (LocaleCompare("kerning",option+1) == 0)
1817 {
1818 if (*option == '+')
1819 (void) ParseGeometry("0",&geometry_info);
1820 else
1821 (void) ParseGeometry(argv[i+1],&geometry_info);
1822 draw_info->kerning=geometry_info.rho;
1823 break;
1824 }
1825 break;
1826 }
1827 case 'l':
1828 {
1829 if (LocaleCompare("lat",option+1) == 0)
1830 {
1831 /*
1832 Local adaptive threshold image.
1833 */
1834 (void) SyncImageSettings(mogrify_info,*image);
1835 flags=ParseGeometry(argv[i+1],&geometry_info);
1836 if ((flags & PercentValue) != 0)
1837 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1838 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001839 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001840 geometry_info.xi,exception);
1841 break;
1842 }
1843 if (LocaleCompare("level",option+1) == 0)
1844 {
1845 MagickRealType
1846 black_point,
1847 gamma,
1848 white_point;
1849
1850 MagickStatusType
1851 flags;
1852
1853 /*
1854 Parse levels.
1855 */
1856 (void) SyncImageSettings(mogrify_info,*image);
1857 flags=ParseGeometry(argv[i+1],&geometry_info);
1858 black_point=geometry_info.rho;
1859 white_point=(MagickRealType) QuantumRange;
1860 if ((flags & SigmaValue) != 0)
1861 white_point=geometry_info.sigma;
1862 gamma=1.0;
1863 if ((flags & XiValue) != 0)
1864 gamma=geometry_info.xi;
1865 if ((flags & PercentValue) != 0)
1866 {
1867 black_point*=(MagickRealType) (QuantumRange/100.0);
1868 white_point*=(MagickRealType) (QuantumRange/100.0);
1869 }
1870 if ((flags & SigmaValue) == 0)
1871 white_point=(MagickRealType) QuantumRange-black_point;
1872 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001873 (void) LevelizeImage(*image,black_point,white_point,gamma,
1874 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001875 else
cristy01e9afd2011-08-10 17:38:41 +00001876 (void) LevelImage(*image,black_point,white_point,gamma,
1877 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001878 InheritException(exception,&(*image)->exception);
1879 break;
1880 }
1881 if (LocaleCompare("level-colors",option+1) == 0)
1882 {
1883 char
1884 token[MaxTextExtent];
1885
1886 const char
1887 *p;
1888
cristy4c08aed2011-07-01 19:47:50 +00001889 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001890 black_point,
1891 white_point;
1892
1893 p=(const char *) argv[i+1];
1894 GetMagickToken(p,&p,token); /* get black point color */
1895 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1896 (void) QueryMagickColor(token,&black_point,exception);
1897 else
1898 (void) QueryMagickColor("#000000",&black_point,exception);
1899 if (isalpha((int) token[0]) || (token[0] == '#'))
1900 GetMagickToken(p,&p,token);
1901 if (*token == '\0')
1902 white_point=black_point; /* set everything to that color */
1903 else
1904 {
1905 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1906 GetMagickToken(p,&p,token); /* Get white point color. */
1907 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1908 (void) QueryMagickColor(token,&white_point,exception);
1909 else
1910 (void) QueryMagickColor("#ffffff",&white_point,exception);
1911 }
cristy490408a2011-07-07 14:42:05 +00001912 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001913 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001914 break;
1915 }
1916 if (LocaleCompare("linear-stretch",option+1) == 0)
1917 {
1918 double
1919 black_point,
1920 white_point;
1921
1922 MagickStatusType
1923 flags;
1924
1925 (void) SyncImageSettings(mogrify_info,*image);
1926 flags=ParseGeometry(argv[i+1],&geometry_info);
1927 black_point=geometry_info.rho;
1928 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1929 if ((flags & SigmaValue) != 0)
1930 white_point=geometry_info.sigma;
1931 if ((flags & PercentValue) != 0)
1932 {
1933 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1934 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1935 }
1936 if ((flags & SigmaValue) == 0)
1937 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1938 black_point;
cristy33bd5152011-08-24 01:42:24 +00001939 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001940 InheritException(exception,&(*image)->exception);
1941 break;
1942 }
1943 if (LocaleCompare("linewidth",option+1) == 0)
1944 {
cristyc1acd842011-05-19 23:05:47 +00001945 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1946 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001947 break;
1948 }
1949 if (LocaleCompare("liquid-rescale",option+1) == 0)
1950 {
1951 /*
1952 Liquid rescale image.
1953 */
1954 (void) SyncImageSettings(mogrify_info,*image);
1955 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1956 if ((flags & XValue) == 0)
1957 geometry.x=1;
1958 if ((flags & YValue) == 0)
1959 geometry.y=0;
1960 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1961 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1962 break;
1963 }
1964 if (LocaleCompare("lowlight-color",option+1) == 0)
1965 {
1966 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1967 break;
1968 }
1969 break;
1970 }
1971 case 'm':
1972 {
1973 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001974 {
cristy3ed852e2009-09-05 21:47:34 +00001975 Image
anthonydf8ebac2011-04-27 09:03:19 +00001976 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001977
anthonydf8ebac2011-04-27 09:03:19 +00001978 /*
1979 Transform image colors to match this set of colors.
1980 */
1981 (void) SyncImageSettings(mogrify_info,*image);
1982 if (*option == '+')
1983 break;
1984 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1985 if (remap_image == (Image *) NULL)
1986 break;
cristy018f07f2011-09-04 21:15:19 +00001987 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001988 remap_image=DestroyImage(remap_image);
1989 break;
1990 }
1991 if (LocaleCompare("mask",option+1) == 0)
1992 {
1993 Image
1994 *mask;
1995
1996 (void) SyncImageSettings(mogrify_info,*image);
1997 if (*option == '+')
1998 {
1999 /*
2000 Remove a mask.
2001 */
cristy018f07f2011-09-04 21:15:19 +00002002 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002003 break;
2004 }
2005 /*
2006 Set the image mask.
2007 */
2008 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2009 if (mask == (Image *) NULL)
2010 break;
cristy018f07f2011-09-04 21:15:19 +00002011 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002012 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002013 break;
2014 }
2015 if (LocaleCompare("matte",option+1) == 0)
2016 {
2017 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002018 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002019 break;
2020 }
2021 if (LocaleCompare("median",option+1) == 0)
2022 {
2023 /*
2024 Median filter image.
2025 */
2026 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002027 flags=ParseGeometry(argv[i+1],&geometry_info);
2028 if ((flags & SigmaValue) == 0)
2029 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002030 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002031 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002032 break;
2033 }
2034 if (LocaleCompare("mode",option+1) == 0)
2035 {
2036 /*
2037 Mode image.
2038 */
2039 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002040 flags=ParseGeometry(argv[i+1],&geometry_info);
2041 if ((flags & SigmaValue) == 0)
2042 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002043 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002044 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002045 break;
2046 }
2047 if (LocaleCompare("modulate",option+1) == 0)
2048 {
2049 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002050 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002051 break;
2052 }
2053 if (LocaleCompare("monitor",option+1) == 0)
2054 {
2055 if (*option == '+')
2056 {
2057 (void) SetImageProgressMonitor(*image,
2058 (MagickProgressMonitor) NULL,(void *) NULL);
2059 break;
2060 }
2061 (void) SetImageProgressMonitor(*image,MonitorProgress,
2062 (void *) NULL);
2063 break;
2064 }
2065 if (LocaleCompare("monochrome",option+1) == 0)
2066 {
2067 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00002068 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002069 break;
2070 }
2071 if (LocaleCompare("morphology",option+1) == 0)
2072 {
2073 char
2074 token[MaxTextExtent];
2075
2076 const char
2077 *p;
2078
2079 KernelInfo
2080 *kernel;
2081
2082 MorphologyMethod
2083 method;
2084
2085 ssize_t
2086 iterations;
2087
2088 /*
2089 Morphological Image Operation
2090 */
2091 (void) SyncImageSettings(mogrify_info,*image);
2092 p=argv[i+1];
2093 GetMagickToken(p,&p,token);
2094 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2095 MagickFalse,token);
2096 iterations=1L;
2097 GetMagickToken(p,&p,token);
2098 if ((*p == ':') || (*p == ','))
2099 GetMagickToken(p,&p,token);
2100 if ((*p != '\0'))
2101 iterations=(ssize_t) StringToLong(p);
2102 kernel=AcquireKernelInfo(argv[i+2]);
2103 if (kernel == (KernelInfo *) NULL)
2104 {
2105 (void) ThrowMagickException(exception,GetMagickModule(),
2106 OptionError,"UnabletoParseKernel","morphology");
2107 status=MagickFalse;
2108 break;
2109 }
cristyf4ad9df2011-07-08 16:49:03 +00002110 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2111 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002112 kernel=DestroyKernelInfo(kernel);
2113 break;
2114 }
2115 if (LocaleCompare("motion-blur",option+1) == 0)
2116 {
2117 /*
2118 Motion blur image.
2119 */
2120 (void) SyncImageSettings(mogrify_info,*image);
2121 flags=ParseGeometry(argv[i+1],&geometry_info);
2122 if ((flags & SigmaValue) == 0)
2123 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002124 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002125 geometry_info.sigma,geometry_info.xi,geometry_info.psi,
2126 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002127 break;
2128 }
2129 break;
2130 }
2131 case 'n':
2132 {
2133 if (LocaleCompare("negate",option+1) == 0)
2134 {
2135 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002136 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002137 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002138 break;
2139 }
2140 if (LocaleCompare("noise",option+1) == 0)
2141 {
2142 (void) SyncImageSettings(mogrify_info,*image);
2143 if (*option == '-')
2144 {
cristyf36cbcb2011-09-07 13:28:22 +00002145 flags=ParseGeometry(argv[i+1],&geometry_info);
2146 if ((flags & SigmaValue) == 0)
2147 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002148 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002149 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002150 }
2151 else
2152 {
2153 NoiseType
2154 noise;
2155
2156 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2157 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002158 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002159 }
2160 break;
2161 }
2162 if (LocaleCompare("normalize",option+1) == 0)
2163 {
2164 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002165 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002166 break;
2167 }
2168 break;
2169 }
2170 case 'o':
2171 {
2172 if (LocaleCompare("opaque",option+1) == 0)
2173 {
cristy4c08aed2011-07-01 19:47:50 +00002174 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002175 target;
2176
2177 (void) SyncImageSettings(mogrify_info,*image);
2178 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002179 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002180 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002181 break;
2182 }
2183 if (LocaleCompare("ordered-dither",option+1) == 0)
2184 {
2185 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002186 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002187 break;
2188 }
2189 break;
2190 }
2191 case 'p':
2192 {
2193 if (LocaleCompare("paint",option+1) == 0)
2194 {
anthonydf8ebac2011-04-27 09:03:19 +00002195 (void) SyncImageSettings(mogrify_info,*image);
2196 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002197 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2198 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002199 break;
2200 }
2201 if (LocaleCompare("pen",option+1) == 0)
2202 {
2203 if (*option == '+')
2204 {
2205 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2206 break;
2207 }
2208 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2209 break;
2210 }
2211 if (LocaleCompare("pointsize",option+1) == 0)
2212 {
2213 if (*option == '+')
2214 (void) ParseGeometry("12",&geometry_info);
2215 else
2216 (void) ParseGeometry(argv[i+1],&geometry_info);
2217 draw_info->pointsize=geometry_info.rho;
2218 break;
2219 }
2220 if (LocaleCompare("polaroid",option+1) == 0)
2221 {
2222 double
2223 angle;
2224
2225 RandomInfo
2226 *random_info;
2227
2228 /*
2229 Simulate a Polaroid picture.
2230 */
2231 (void) SyncImageSettings(mogrify_info,*image);
2232 random_info=AcquireRandomInfo();
2233 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2234 random_info=DestroyRandomInfo(random_info);
2235 if (*option == '-')
2236 {
2237 SetGeometryInfo(&geometry_info);
2238 flags=ParseGeometry(argv[i+1],&geometry_info);
2239 angle=geometry_info.rho;
2240 }
cristy5c4e2582011-09-11 19:21:03 +00002241 mogrify_image=PolaroidImage(*image,draw_info,angle,
2242 (*image)->interpolate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002243 break;
2244 }
2245 if (LocaleCompare("posterize",option+1) == 0)
2246 {
2247 /*
2248 Posterize image.
2249 */
2250 (void) SyncImageSettings(mogrify_info,*image);
2251 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002252 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002253 break;
2254 }
2255 if (LocaleCompare("preview",option+1) == 0)
2256 {
2257 PreviewType
2258 preview_type;
2259
2260 /*
2261 Preview image.
2262 */
2263 (void) SyncImageSettings(mogrify_info,*image);
2264 if (*option == '+')
2265 preview_type=UndefinedPreview;
2266 else
2267 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2268 MagickFalse,argv[i+1]);
2269 mogrify_image=PreviewImage(*image,preview_type,exception);
2270 break;
2271 }
2272 if (LocaleCompare("profile",option+1) == 0)
2273 {
2274 const char
2275 *name;
2276
2277 const StringInfo
2278 *profile;
2279
2280 Image
2281 *profile_image;
2282
2283 ImageInfo
2284 *profile_info;
2285
2286 (void) SyncImageSettings(mogrify_info,*image);
2287 if (*option == '+')
2288 {
2289 /*
2290 Remove a profile from the image.
2291 */
2292 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2293 NULL,0,MagickTrue);
2294 InheritException(exception,&(*image)->exception);
2295 break;
2296 }
2297 /*
2298 Associate a profile with the image.
2299 */
2300 profile_info=CloneImageInfo(mogrify_info);
2301 profile=GetImageProfile(*image,"iptc");
2302 if (profile != (StringInfo *) NULL)
2303 profile_info->profile=(void *) CloneStringInfo(profile);
2304 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2305 profile_info=DestroyImageInfo(profile_info);
2306 if (profile_image == (Image *) NULL)
2307 {
2308 StringInfo
2309 *profile;
2310
2311 profile_info=CloneImageInfo(mogrify_info);
2312 (void) CopyMagickString(profile_info->filename,argv[i+1],
2313 MaxTextExtent);
2314 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2315 if (profile != (StringInfo *) NULL)
2316 {
2317 (void) ProfileImage(*image,profile_info->magick,
2318 GetStringInfoDatum(profile),(size_t)
2319 GetStringInfoLength(profile),MagickFalse);
2320 profile=DestroyStringInfo(profile);
2321 }
2322 profile_info=DestroyImageInfo(profile_info);
2323 break;
2324 }
2325 ResetImageProfileIterator(profile_image);
2326 name=GetNextImageProfile(profile_image);
2327 while (name != (const char *) NULL)
2328 {
2329 profile=GetImageProfile(profile_image,name);
2330 if (profile != (StringInfo *) NULL)
2331 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2332 (size_t) GetStringInfoLength(profile),MagickFalse);
2333 name=GetNextImageProfile(profile_image);
2334 }
2335 profile_image=DestroyImage(profile_image);
2336 break;
2337 }
2338 break;
2339 }
2340 case 'q':
2341 {
2342 if (LocaleCompare("quantize",option+1) == 0)
2343 {
2344 if (*option == '+')
2345 {
2346 quantize_info->colorspace=UndefinedColorspace;
2347 break;
2348 }
2349 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2350 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2351 break;
2352 }
2353 break;
2354 }
2355 case 'r':
2356 {
2357 if (LocaleCompare("radial-blur",option+1) == 0)
2358 {
2359 /*
2360 Radial blur image.
2361 */
2362 (void) SyncImageSettings(mogrify_info,*image);
cristy6435bd92011-09-10 02:10:07 +00002363 flags=ParseGeometry(argv[i+1],&geometry_info);
2364 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2365 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002366 break;
2367 }
2368 if (LocaleCompare("raise",option+1) == 0)
2369 {
2370 /*
2371 Surround image with a raise of solid color.
2372 */
2373 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2374 if ((flags & SigmaValue) == 0)
2375 geometry.height=geometry.width;
2376 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002377 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002378 break;
2379 }
2380 if (LocaleCompare("random-threshold",option+1) == 0)
2381 {
2382 /*
2383 Threshold image.
2384 */
2385 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002386 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002387 break;
2388 }
2389 if (LocaleCompare("recolor",option+1) == 0)
2390 {
2391 KernelInfo
2392 *kernel;
2393
2394 (void) SyncImageSettings(mogrify_info,*image);
2395 kernel=AcquireKernelInfo(argv[i+1]);
2396 if (kernel == (KernelInfo *) NULL)
2397 break;
2398 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2399 kernel=DestroyKernelInfo(kernel);
2400 break;
2401 }
2402 if (LocaleCompare("region",option+1) == 0)
2403 {
2404 (void) SyncImageSettings(mogrify_info,*image);
2405 if (region_image != (Image *) NULL)
2406 {
2407 /*
2408 Composite region.
2409 */
2410 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002411 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2412 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002413 InheritException(exception,&region_image->exception);
2414 *image=DestroyImage(*image);
2415 *image=region_image;
2416 region_image = (Image *) NULL;
2417 }
2418 if (*option == '+')
2419 break;
2420 /*
2421 Apply transformations to a selected region of the image.
2422 */
cristy3ed852e2009-09-05 21:47:34 +00002423 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2424 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002425 mogrify_image=CropImage(*image,&region_geometry,exception);
2426 if (mogrify_image == (Image *) NULL)
2427 break;
2428 region_image=(*image);
2429 *image=mogrify_image;
2430 mogrify_image=(Image *) NULL;
2431 break;
cristy3ed852e2009-09-05 21:47:34 +00002432 }
anthonydf8ebac2011-04-27 09:03:19 +00002433 if (LocaleCompare("render",option+1) == 0)
2434 {
2435 (void) SyncImageSettings(mogrify_info,*image);
2436 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2437 break;
2438 }
2439 if (LocaleCompare("remap",option+1) == 0)
2440 {
2441 Image
2442 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002443
anthonydf8ebac2011-04-27 09:03:19 +00002444 /*
2445 Transform image colors to match this set of colors.
2446 */
2447 (void) SyncImageSettings(mogrify_info,*image);
2448 if (*option == '+')
2449 break;
2450 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2451 if (remap_image == (Image *) NULL)
2452 break;
cristy018f07f2011-09-04 21:15:19 +00002453 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002454 remap_image=DestroyImage(remap_image);
2455 break;
2456 }
2457 if (LocaleCompare("repage",option+1) == 0)
2458 {
2459 if (*option == '+')
2460 {
2461 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2462 break;
2463 }
2464 (void) ResetImagePage(*image,argv[i+1]);
2465 InheritException(exception,&(*image)->exception);
2466 break;
2467 }
2468 if (LocaleCompare("resample",option+1) == 0)
2469 {
2470 /*
2471 Resample image.
2472 */
2473 (void) SyncImageSettings(mogrify_info,*image);
2474 flags=ParseGeometry(argv[i+1],&geometry_info);
2475 if ((flags & SigmaValue) == 0)
2476 geometry_info.sigma=geometry_info.rho;
2477 mogrify_image=ResampleImage(*image,geometry_info.rho,
2478 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2479 break;
2480 }
2481 if (LocaleCompare("resize",option+1) == 0)
2482 {
2483 /*
2484 Resize image.
2485 */
2486 (void) SyncImageSettings(mogrify_info,*image);
2487 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2488 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2489 (*image)->filter,(*image)->blur,exception);
2490 break;
2491 }
2492 if (LocaleCompare("roll",option+1) == 0)
2493 {
2494 /*
2495 Roll image.
2496 */
2497 (void) SyncImageSettings(mogrify_info,*image);
2498 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2499 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2500 break;
2501 }
2502 if (LocaleCompare("rotate",option+1) == 0)
2503 {
2504 char
2505 *geometry;
2506
2507 /*
2508 Check for conditional image rotation.
2509 */
2510 (void) SyncImageSettings(mogrify_info,*image);
2511 if (strchr(argv[i+1],'>') != (char *) NULL)
2512 if ((*image)->columns <= (*image)->rows)
2513 break;
2514 if (strchr(argv[i+1],'<') != (char *) NULL)
2515 if ((*image)->columns >= (*image)->rows)
2516 break;
2517 /*
2518 Rotate image.
2519 */
2520 geometry=ConstantString(argv[i+1]);
2521 (void) SubstituteString(&geometry,">","");
2522 (void) SubstituteString(&geometry,"<","");
2523 (void) ParseGeometry(geometry,&geometry_info);
2524 geometry=DestroyString(geometry);
2525 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2526 break;
2527 }
2528 break;
2529 }
2530 case 's':
2531 {
2532 if (LocaleCompare("sample",option+1) == 0)
2533 {
2534 /*
2535 Sample image with pixel replication.
2536 */
2537 (void) SyncImageSettings(mogrify_info,*image);
2538 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2539 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2540 exception);
2541 break;
2542 }
2543 if (LocaleCompare("scale",option+1) == 0)
2544 {
2545 /*
2546 Resize image.
2547 */
2548 (void) SyncImageSettings(mogrify_info,*image);
2549 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2550 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2551 exception);
2552 break;
2553 }
2554 if (LocaleCompare("selective-blur",option+1) == 0)
2555 {
2556 /*
2557 Selectively blur pixels within a contrast threshold.
2558 */
2559 (void) SyncImageSettings(mogrify_info,*image);
2560 flags=ParseGeometry(argv[i+1],&geometry_info);
2561 if ((flags & PercentValue) != 0)
2562 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002563 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002564 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002565 break;
2566 }
2567 if (LocaleCompare("separate",option+1) == 0)
2568 {
2569 /*
2570 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002571 */
2572 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002573 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002574 break;
2575 }
2576 if (LocaleCompare("sepia-tone",option+1) == 0)
2577 {
2578 double
2579 threshold;
2580
2581 /*
2582 Sepia-tone image.
2583 */
2584 (void) SyncImageSettings(mogrify_info,*image);
2585 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2586 mogrify_image=SepiaToneImage(*image,threshold,exception);
2587 break;
2588 }
2589 if (LocaleCompare("segment",option+1) == 0)
2590 {
2591 /*
2592 Segment image.
2593 */
2594 (void) SyncImageSettings(mogrify_info,*image);
2595 flags=ParseGeometry(argv[i+1],&geometry_info);
2596 if ((flags & SigmaValue) == 0)
2597 geometry_info.sigma=1.0;
2598 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002599 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2600 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002601 break;
2602 }
2603 if (LocaleCompare("set",option+1) == 0)
2604 {
2605 char
2606 *value;
2607
2608 /*
2609 Set image option.
2610 */
2611 if (*option == '+')
2612 {
2613 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2614 (void) DeleteImageRegistry(argv[i+1]+9);
2615 else
2616 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2617 {
2618 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2619 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2620 }
2621 else
2622 (void) DeleteImageProperty(*image,argv[i+1]);
2623 break;
2624 }
cristy018f07f2011-09-04 21:15:19 +00002625 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2626 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002627 if (value == (char *) NULL)
2628 break;
2629 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2630 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2631 exception);
2632 else
2633 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2634 {
2635 (void) SetImageOption(image_info,argv[i+1]+7,value);
2636 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2637 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2638 }
2639 else
2640 (void) SetImageProperty(*image,argv[i+1],value);
2641 value=DestroyString(value);
2642 break;
2643 }
2644 if (LocaleCompare("shade",option+1) == 0)
2645 {
2646 /*
2647 Shade image.
2648 */
2649 (void) SyncImageSettings(mogrify_info,*image);
2650 flags=ParseGeometry(argv[i+1],&geometry_info);
2651 if ((flags & SigmaValue) == 0)
2652 geometry_info.sigma=1.0;
2653 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2654 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2655 break;
2656 }
2657 if (LocaleCompare("shadow",option+1) == 0)
2658 {
2659 /*
2660 Shadow image.
2661 */
2662 (void) SyncImageSettings(mogrify_info,*image);
2663 flags=ParseGeometry(argv[i+1],&geometry_info);
2664 if ((flags & SigmaValue) == 0)
2665 geometry_info.sigma=1.0;
2666 if ((flags & XiValue) == 0)
2667 geometry_info.xi=4.0;
2668 if ((flags & PsiValue) == 0)
2669 geometry_info.psi=4.0;
2670 mogrify_image=ShadowImage(*image,geometry_info.rho,
2671 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2672 ceil(geometry_info.psi-0.5),exception);
2673 break;
2674 }
2675 if (LocaleCompare("sharpen",option+1) == 0)
2676 {
2677 /*
2678 Sharpen image.
2679 */
2680 (void) SyncImageSettings(mogrify_info,*image);
2681 flags=ParseGeometry(argv[i+1],&geometry_info);
2682 if ((flags & SigmaValue) == 0)
2683 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002684 if ((flags & XiValue) == 0)
2685 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002686 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002687 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002688 break;
2689 }
2690 if (LocaleCompare("shave",option+1) == 0)
2691 {
2692 /*
2693 Shave the image edges.
2694 */
2695 (void) SyncImageSettings(mogrify_info,*image);
2696 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2697 mogrify_image=ShaveImage(*image,&geometry,exception);
2698 break;
2699 }
2700 if (LocaleCompare("shear",option+1) == 0)
2701 {
2702 /*
2703 Shear image.
2704 */
2705 (void) SyncImageSettings(mogrify_info,*image);
2706 flags=ParseGeometry(argv[i+1],&geometry_info);
2707 if ((flags & SigmaValue) == 0)
2708 geometry_info.sigma=geometry_info.rho;
2709 mogrify_image=ShearImage(*image,geometry_info.rho,
2710 geometry_info.sigma,exception);
2711 break;
2712 }
2713 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2714 {
2715 /*
2716 Sigmoidal non-linearity contrast control.
2717 */
2718 (void) SyncImageSettings(mogrify_info,*image);
2719 flags=ParseGeometry(argv[i+1],&geometry_info);
2720 if ((flags & SigmaValue) == 0)
2721 geometry_info.sigma=(double) QuantumRange/2.0;
2722 if ((flags & PercentValue) != 0)
2723 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2724 100.0;
cristy9ee60942011-07-06 14:54:38 +00002725 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002726 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2727 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002728 break;
2729 }
2730 if (LocaleCompare("sketch",option+1) == 0)
2731 {
2732 /*
2733 Sketch image.
2734 */
2735 (void) SyncImageSettings(mogrify_info,*image);
2736 flags=ParseGeometry(argv[i+1],&geometry_info);
2737 if ((flags & SigmaValue) == 0)
2738 geometry_info.sigma=1.0;
2739 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002740 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002741 break;
2742 }
2743 if (LocaleCompare("solarize",option+1) == 0)
2744 {
2745 double
2746 threshold;
2747
2748 (void) SyncImageSettings(mogrify_info,*image);
2749 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002750 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002751 break;
2752 }
2753 if (LocaleCompare("sparse-color",option+1) == 0)
2754 {
2755 SparseColorMethod
2756 method;
2757
2758 char
2759 *arguments;
2760
2761 /*
2762 Sparse Color Interpolated Gradient
2763 */
2764 (void) SyncImageSettings(mogrify_info,*image);
2765 method=(SparseColorMethod) ParseCommandOption(
2766 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002767 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2768 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002769 if (arguments == (char *) NULL)
2770 break;
cristy3884f692011-07-08 18:00:18 +00002771 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002772 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2773 arguments=DestroyString(arguments);
2774 break;
2775 }
2776 if (LocaleCompare("splice",option+1) == 0)
2777 {
2778 /*
2779 Splice a solid color into the image.
2780 */
2781 (void) SyncImageSettings(mogrify_info,*image);
2782 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2783 mogrify_image=SpliceImage(*image,&geometry,exception);
2784 break;
2785 }
2786 if (LocaleCompare("spread",option+1) == 0)
2787 {
2788 /*
2789 Spread an image.
2790 */
2791 (void) SyncImageSettings(mogrify_info,*image);
2792 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002793 mogrify_image=SpreadImage(*image,geometry_info.rho,
2794 (*image)->interpolate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002795 break;
2796 }
2797 if (LocaleCompare("statistic",option+1) == 0)
2798 {
2799 StatisticType
2800 type;
2801
2802 (void) SyncImageSettings(mogrify_info,*image);
2803 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2804 MagickFalse,argv[i+1]);
2805 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002806 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2807 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002808 break;
2809 }
2810 if (LocaleCompare("stretch",option+1) == 0)
2811 {
2812 if (*option == '+')
2813 {
2814 draw_info->stretch=UndefinedStretch;
2815 break;
2816 }
2817 draw_info->stretch=(StretchType) ParseCommandOption(
2818 MagickStretchOptions,MagickFalse,argv[i+1]);
2819 break;
2820 }
2821 if (LocaleCompare("strip",option+1) == 0)
2822 {
2823 /*
2824 Strip image of profiles and comments.
2825 */
2826 (void) SyncImageSettings(mogrify_info,*image);
2827 (void) StripImage(*image);
2828 InheritException(exception,&(*image)->exception);
2829 break;
2830 }
2831 if (LocaleCompare("stroke",option+1) == 0)
2832 {
2833 ExceptionInfo
2834 *sans;
2835
2836 if (*option == '+')
2837 {
2838 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2839 if (draw_info->stroke_pattern != (Image *) NULL)
2840 draw_info->stroke_pattern=DestroyImage(
2841 draw_info->stroke_pattern);
2842 break;
2843 }
2844 sans=AcquireExceptionInfo();
2845 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2846 sans=DestroyExceptionInfo(sans);
2847 if (status == MagickFalse)
2848 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2849 exception);
2850 break;
2851 }
2852 if (LocaleCompare("strokewidth",option+1) == 0)
2853 {
cristyc1acd842011-05-19 23:05:47 +00002854 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2855 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002856 break;
2857 }
2858 if (LocaleCompare("style",option+1) == 0)
2859 {
2860 if (*option == '+')
2861 {
2862 draw_info->style=UndefinedStyle;
2863 break;
2864 }
2865 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2866 MagickFalse,argv[i+1]);
2867 break;
2868 }
2869 if (LocaleCompare("swirl",option+1) == 0)
2870 {
2871 /*
2872 Swirl image.
2873 */
2874 (void) SyncImageSettings(mogrify_info,*image);
2875 (void) ParseGeometry(argv[i+1],&geometry_info);
2876 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2877 break;
2878 }
2879 break;
2880 }
2881 case 't':
2882 {
2883 if (LocaleCompare("threshold",option+1) == 0)
2884 {
2885 double
2886 threshold;
2887
2888 /*
2889 Threshold image.
2890 */
2891 (void) SyncImageSettings(mogrify_info,*image);
2892 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002893 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002894 else
2895 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002896 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002897 InheritException(exception,&(*image)->exception);
2898 break;
2899 }
2900 if (LocaleCompare("thumbnail",option+1) == 0)
2901 {
2902 /*
2903 Thumbnail image.
2904 */
2905 (void) SyncImageSettings(mogrify_info,*image);
2906 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2907 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2908 exception);
2909 break;
2910 }
2911 if (LocaleCompare("tile",option+1) == 0)
2912 {
2913 if (*option == '+')
2914 {
2915 if (draw_info->fill_pattern != (Image *) NULL)
2916 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2917 break;
2918 }
2919 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2920 exception);
2921 break;
2922 }
2923 if (LocaleCompare("tint",option+1) == 0)
2924 {
2925 /*
2926 Tint the image.
2927 */
2928 (void) SyncImageSettings(mogrify_info,*image);
2929 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2930 break;
2931 }
2932 if (LocaleCompare("transform",option+1) == 0)
2933 {
2934 /*
2935 Affine transform image.
2936 */
2937 (void) SyncImageSettings(mogrify_info,*image);
2938 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2939 exception);
2940 break;
2941 }
2942 if (LocaleCompare("transparent",option+1) == 0)
2943 {
cristy4c08aed2011-07-01 19:47:50 +00002944 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002945 target;
2946
2947 (void) SyncImageSettings(mogrify_info,*image);
2948 (void) QueryMagickColor(argv[i+1],&target,exception);
2949 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002950 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2951 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002952 break;
2953 }
2954 if (LocaleCompare("transpose",option+1) == 0)
2955 {
2956 /*
2957 Transpose image scanlines.
2958 */
2959 (void) SyncImageSettings(mogrify_info,*image);
2960 mogrify_image=TransposeImage(*image,exception);
2961 break;
2962 }
2963 if (LocaleCompare("transverse",option+1) == 0)
2964 {
2965 /*
2966 Transverse image scanlines.
2967 */
2968 (void) SyncImageSettings(mogrify_info,*image);
2969 mogrify_image=TransverseImage(*image,exception);
2970 break;
2971 }
2972 if (LocaleCompare("treedepth",option+1) == 0)
2973 {
2974 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2975 break;
2976 }
2977 if (LocaleCompare("trim",option+1) == 0)
2978 {
2979 /*
2980 Trim image.
2981 */
2982 (void) SyncImageSettings(mogrify_info,*image);
2983 mogrify_image=TrimImage(*image,exception);
2984 break;
2985 }
2986 if (LocaleCompare("type",option+1) == 0)
2987 {
2988 ImageType
2989 type;
2990
2991 (void) SyncImageSettings(mogrify_info,*image);
2992 if (*option == '+')
2993 type=UndefinedType;
2994 else
2995 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2996 argv[i+1]);
2997 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00002998 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002999 break;
3000 }
3001 break;
3002 }
3003 case 'u':
3004 {
3005 if (LocaleCompare("undercolor",option+1) == 0)
3006 {
3007 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3008 exception);
3009 break;
3010 }
3011 if (LocaleCompare("unique",option+1) == 0)
3012 {
3013 if (*option == '+')
3014 {
3015 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3016 break;
3017 }
3018 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3019 (void) SetImageArtifact(*image,"verbose","true");
3020 break;
3021 }
3022 if (LocaleCompare("unique-colors",option+1) == 0)
3023 {
3024 /*
3025 Unique image colors.
3026 */
3027 (void) SyncImageSettings(mogrify_info,*image);
3028 mogrify_image=UniqueImageColors(*image,exception);
3029 break;
3030 }
3031 if (LocaleCompare("unsharp",option+1) == 0)
3032 {
3033 /*
3034 Unsharp mask image.
3035 */
3036 (void) SyncImageSettings(mogrify_info,*image);
3037 flags=ParseGeometry(argv[i+1],&geometry_info);
3038 if ((flags & SigmaValue) == 0)
3039 geometry_info.sigma=1.0;
3040 if ((flags & XiValue) == 0)
3041 geometry_info.xi=1.0;
3042 if ((flags & PsiValue) == 0)
3043 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003044 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3045 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003046 break;
3047 }
3048 break;
3049 }
3050 case 'v':
3051 {
3052 if (LocaleCompare("verbose",option+1) == 0)
3053 {
3054 (void) SetImageArtifact(*image,option+1,
3055 *option == '+' ? "false" : "true");
3056 break;
3057 }
3058 if (LocaleCompare("vignette",option+1) == 0)
3059 {
3060 /*
3061 Vignette image.
3062 */
3063 (void) SyncImageSettings(mogrify_info,*image);
3064 flags=ParseGeometry(argv[i+1],&geometry_info);
3065 if ((flags & SigmaValue) == 0)
3066 geometry_info.sigma=1.0;
3067 if ((flags & XiValue) == 0)
3068 geometry_info.xi=0.1*(*image)->columns;
3069 if ((flags & PsiValue) == 0)
3070 geometry_info.psi=0.1*(*image)->rows;
3071 mogrify_image=VignetteImage(*image,geometry_info.rho,
3072 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3073 ceil(geometry_info.psi-0.5),exception);
3074 break;
3075 }
3076 if (LocaleCompare("virtual-pixel",option+1) == 0)
3077 {
3078 if (*option == '+')
3079 {
3080 (void) SetImageVirtualPixelMethod(*image,
3081 UndefinedVirtualPixelMethod);
3082 break;
3083 }
3084 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3085 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3086 argv[i+1]));
3087 break;
3088 }
3089 break;
3090 }
3091 case 'w':
3092 {
3093 if (LocaleCompare("wave",option+1) == 0)
3094 {
3095 /*
3096 Wave image.
3097 */
3098 (void) SyncImageSettings(mogrify_info,*image);
3099 flags=ParseGeometry(argv[i+1],&geometry_info);
3100 if ((flags & SigmaValue) == 0)
3101 geometry_info.sigma=1.0;
3102 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy5c4e2582011-09-11 19:21:03 +00003103 geometry_info.sigma,(*image)->interpolate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003104 break;
3105 }
3106 if (LocaleCompare("weight",option+1) == 0)
3107 {
3108 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3109 if (LocaleCompare(argv[i+1],"all") == 0)
3110 draw_info->weight=0;
3111 if (LocaleCompare(argv[i+1],"bold") == 0)
3112 draw_info->weight=700;
3113 if (LocaleCompare(argv[i+1],"bolder") == 0)
3114 if (draw_info->weight <= 800)
3115 draw_info->weight+=100;
3116 if (LocaleCompare(argv[i+1],"lighter") == 0)
3117 if (draw_info->weight >= 100)
3118 draw_info->weight-=100;
3119 if (LocaleCompare(argv[i+1],"normal") == 0)
3120 draw_info->weight=400;
3121 break;
3122 }
3123 if (LocaleCompare("white-threshold",option+1) == 0)
3124 {
3125 /*
3126 White threshold image.
3127 */
3128 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003129 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003130 InheritException(exception,&(*image)->exception);
3131 break;
3132 }
3133 break;
3134 }
3135 default:
3136 break;
3137 }
3138 /*
3139 Replace current image with any image that was generated
3140 */
3141 if (mogrify_image != (Image *) NULL)
3142 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003143 i+=count;
3144 }
3145 if (region_image != (Image *) NULL)
3146 {
anthonydf8ebac2011-04-27 09:03:19 +00003147 /*
3148 Composite transformed region onto image.
3149 */
cristy6b3da3a2010-06-20 02:21:46 +00003150 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003151 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003152 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3153 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003154 InheritException(exception,&region_image->exception);
3155 *image=DestroyImage(*image);
3156 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003157 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003158 }
3159 /*
3160 Free resources.
3161 */
anthonydf8ebac2011-04-27 09:03:19 +00003162 quantize_info=DestroyQuantizeInfo(quantize_info);
3163 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003164 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003165 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003166 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003167 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003168}
3169
3170/*
3171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3172% %
3173% %
3174% %
cristy5063d812010-10-19 16:28:10 +00003175+ 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 +00003176% %
3177% %
3178% %
3179%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3180%
3181% MogrifyImageCommand() transforms an image or a sequence of images. These
3182% transforms include image scaling, image rotation, color reduction, and
3183% others. The transmogrified image overwrites the original image.
3184%
3185% The format of the MogrifyImageCommand method is:
3186%
3187% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3188% const char **argv,char **metadata,ExceptionInfo *exception)
3189%
3190% A description of each parameter follows:
3191%
3192% o image_info: the image info.
3193%
3194% o argc: the number of elements in the argument vector.
3195%
3196% o argv: A text array containing the command line arguments.
3197%
3198% o metadata: any metadata is returned here.
3199%
3200% o exception: return any errors or warnings in this structure.
3201%
3202*/
3203
3204static MagickBooleanType MogrifyUsage(void)
3205{
3206 static const char
3207 *miscellaneous[]=
3208 {
3209 "-debug events display copious debugging information",
3210 "-help print program options",
3211 "-list type print a list of supported option arguments",
3212 "-log format format of debugging information",
3213 "-version print version information",
3214 (char *) NULL
3215 },
3216 *operators[]=
3217 {
3218 "-adaptive-blur geometry",
3219 " adaptively blur pixels; decrease effect near edges",
3220 "-adaptive-resize geometry",
3221 " adaptively resize image using 'mesh' interpolation",
3222 "-adaptive-sharpen geometry",
3223 " adaptively sharpen pixels; increase effect near edges",
3224 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3225 " transparent, extract, background, or shape",
3226 "-annotate geometry text",
3227 " annotate the image with text",
3228 "-auto-gamma automagically adjust gamma level of image",
3229 "-auto-level automagically adjust color levels of image",
3230 "-auto-orient automagically orient (rotate) image",
3231 "-bench iterations measure performance",
3232 "-black-threshold value",
3233 " force all pixels below the threshold into black",
3234 "-blue-shift simulate a scene at nighttime in the moonlight",
3235 "-blur geometry reduce image noise and reduce detail levels",
3236 "-border geometry surround image with a border of color",
3237 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003238 "-brightness-contrast geometry",
3239 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003240 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003241 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003242 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003243 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003244 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003245 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003246 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003247 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003248 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003249 "-contrast enhance or reduce the image contrast",
3250 "-contrast-stretch geometry",
3251 " improve contrast by `stretching' the intensity range",
3252 "-convolve coefficients",
3253 " apply a convolution kernel to the image",
3254 "-cycle amount cycle the image colormap",
3255 "-decipher filename convert cipher pixels to plain pixels",
3256 "-deskew threshold straighten an image",
3257 "-despeckle reduce the speckles within an image",
3258 "-distort method args",
3259 " distort images according to given method ad args",
3260 "-draw string annotate the image with a graphic primitive",
3261 "-edge radius apply a filter to detect edges in the image",
3262 "-encipher filename convert plain pixels to cipher pixels",
3263 "-emboss radius emboss an image",
3264 "-enhance apply a digital filter to enhance a noisy image",
3265 "-equalize perform histogram equalization to an image",
3266 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003267 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003268 "-extent geometry set the image size",
3269 "-extract geometry extract area from image",
3270 "-fft implements the discrete Fourier transform (DFT)",
3271 "-flip flip image vertically",
3272 "-floodfill geometry color",
3273 " floodfill the image with color",
3274 "-flop flop image horizontally",
3275 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003276 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003277 " apply function over image values",
3278 "-gamma value level of gamma correction",
3279 "-gaussian-blur geometry",
3280 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003281 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003282 "-identify identify the format and characteristics of the image",
3283 "-ift implements the inverse discrete Fourier transform (DFT)",
3284 "-implode amount implode image pixels about the center",
3285 "-lat geometry local adaptive thresholding",
3286 "-layers method optimize, merge, or compare image layers",
3287 "-level value adjust the level of image contrast",
3288 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003289 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003290 "-linear-stretch geometry",
3291 " improve contrast by `stretching with saturation'",
3292 "-liquid-rescale geometry",
3293 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003294 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003295 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003296 "-modulate value vary the brightness, saturation, and hue",
3297 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003298 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003299 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003300 "-motion-blur geometry",
3301 " simulate motion blur",
3302 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003303 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003304 "-normalize transform image to span the full range of colors",
3305 "-opaque color change this color to the fill color",
3306 "-ordered-dither NxN",
3307 " add a noise pattern to the image with specific",
3308 " amplitudes",
3309 "-paint radius simulate an oil painting",
3310 "-polaroid angle simulate a Polaroid picture",
3311 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003312 "-profile filename add, delete, or apply an image profile",
3313 "-quantize colorspace reduce colors in this colorspace",
3314 "-radial-blur angle radial blur the image",
3315 "-raise value lighten/darken image edges to create a 3-D effect",
3316 "-random-threshold low,high",
3317 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003318 "-region geometry apply options to a portion of the image",
3319 "-render render vector graphics",
3320 "-repage geometry size and location of an image canvas",
3321 "-resample geometry change the resolution of an image",
3322 "-resize geometry resize the image",
3323 "-roll geometry roll an image vertically or horizontally",
3324 "-rotate degrees apply Paeth rotation to the image",
3325 "-sample geometry scale image with pixel sampling",
3326 "-scale geometry scale the image",
3327 "-segment values segment an image",
3328 "-selective-blur geometry",
3329 " selectively blur pixels within a contrast threshold",
3330 "-sepia-tone threshold",
3331 " simulate a sepia-toned photo",
3332 "-set property value set an image property",
3333 "-shade degrees shade the image using a distant light source",
3334 "-shadow geometry simulate an image shadow",
3335 "-sharpen geometry sharpen the image",
3336 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003337 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003338 "-sigmoidal-contrast geometry",
3339 " increase the contrast without saturating highlights or shadows",
3340 "-sketch geometry simulate a pencil sketch",
3341 "-solarize threshold negate all pixels above the threshold level",
3342 "-sparse-color method args",
3343 " fill in a image based on a few color points",
3344 "-splice geometry splice the background color into the image",
3345 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003346 "-statistic type radius",
3347 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003348 "-strip strip image of all profiles and comments",
3349 "-swirl degrees swirl image pixels about the center",
3350 "-threshold value threshold the image",
3351 "-thumbnail geometry create a thumbnail of the image",
3352 "-tile filename tile image when filling a graphic primitive",
3353 "-tint value tint the image with the fill color",
3354 "-transform affine transform image",
3355 "-transparent color make this color transparent within the image",
3356 "-transpose flip image vertically and rotate 90 degrees",
3357 "-transverse flop image horizontally and rotate 270 degrees",
3358 "-trim trim image edges",
3359 "-type type image type",
3360 "-unique-colors discard all but one of any pixel color",
3361 "-unsharp geometry sharpen the image",
3362 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003363 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003364 "-white-threshold value",
3365 " force all pixels above the threshold into white",
3366 (char *) NULL
3367 },
3368 *sequence_operators[]=
3369 {
cristy4285d782011-02-09 20:12:28 +00003370 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003371 "-clut apply a color lookup table to the image",
3372 "-coalesce merge a sequence of images",
3373 "-combine combine a sequence of images",
3374 "-composite composite image",
3375 "-crop geometry cut out a rectangular region of the image",
3376 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003377 "-evaluate-sequence operator",
3378 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003379 "-flatten flatten a sequence of images",
3380 "-fx expression apply mathematical expression to an image channel(s)",
3381 "-hald-clut apply a Hald color lookup table to the image",
3382 "-morph value morph an image sequence",
3383 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003384 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003385 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003386 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003387 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003388 "-write filename write images to this file",
3389 (char *) NULL
3390 },
3391 *settings[]=
3392 {
3393 "-adjoin join images into a single multi-image file",
3394 "-affine matrix affine transform matrix",
3395 "-alpha option activate, deactivate, reset, or set the alpha channel",
3396 "-antialias remove pixel-aliasing",
3397 "-authenticate password",
3398 " decipher image with this password",
3399 "-attenuate value lessen (or intensify) when adding noise to an image",
3400 "-background color background color",
3401 "-bias value add bias when convolving an image",
3402 "-black-point-compensation",
3403 " use black point compensation",
3404 "-blue-primary point chromaticity blue primary point",
3405 "-bordercolor color border color",
3406 "-caption string assign a caption to an image",
3407 "-channel type apply option to select image channels",
3408 "-colors value preferred number of colors in the image",
3409 "-colorspace type alternate image colorspace",
3410 "-comment string annotate image with comment",
3411 "-compose operator set image composite operator",
3412 "-compress type type of pixel compression when writing the image",
3413 "-define format:option",
3414 " define one or more image format options",
3415 "-delay value display the next image after pausing",
3416 "-density geometry horizontal and vertical density of the image",
3417 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003418 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003419 "-display server get image or font from this X server",
3420 "-dispose method layer disposal method",
3421 "-dither method apply error diffusion to image",
3422 "-encoding type text encoding type",
3423 "-endian type endianness (MSB or LSB) of the image",
3424 "-family name render text with this font family",
3425 "-fill color color to use when filling a graphic primitive",
3426 "-filter type use this filter when resizing an image",
3427 "-font name render text with this font",
3428 "-format \"string\" output formatted image characteristics",
3429 "-fuzz distance colors within this distance are considered equal",
3430 "-gravity type horizontal and vertical text placement",
3431 "-green-primary point chromaticity green primary point",
3432 "-intent type type of rendering intent when managing the image color",
3433 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003434 "-interline-spacing value",
3435 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003436 "-interpolate method pixel color interpolation method",
3437 "-interword-spacing value",
3438 " set the space between two words",
3439 "-kerning value set the space between two letters",
3440 "-label string assign a label to an image",
3441 "-limit type value pixel cache resource limit",
3442 "-loop iterations add Netscape loop extension to your GIF animation",
3443 "-mask filename associate a mask with the image",
3444 "-mattecolor color frame color",
3445 "-monitor monitor progress",
3446 "-orient type image orientation",
3447 "-page geometry size and location of an image canvas (setting)",
3448 "-ping efficiently determine image attributes",
3449 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003450 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003451 "-preview type image preview type",
3452 "-quality value JPEG/MIFF/PNG compression level",
3453 "-quiet suppress all warning messages",
3454 "-red-primary point chromaticity red primary point",
3455 "-regard-warnings pay attention to warning messages",
3456 "-remap filename transform image colors to match this set of colors",
3457 "-respect-parentheses settings remain in effect until parenthesis boundary",
3458 "-sampling-factor geometry",
3459 " horizontal and vertical sampling factor",
3460 "-scene value image scene number",
3461 "-seed value seed a new sequence of pseudo-random numbers",
3462 "-size geometry width and height of image",
3463 "-stretch type render text with this font stretch",
3464 "-stroke color graphic primitive stroke color",
3465 "-strokewidth value graphic primitive stroke width",
3466 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003467 "-synchronize synchronize image to storage device",
3468 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003469 "-texture filename name of texture to tile onto the image background",
3470 "-tile-offset geometry",
3471 " tile offset",
3472 "-treedepth value color tree depth",
3473 "-transparent-color color",
3474 " transparent color",
3475 "-undercolor color annotation bounding box color",
3476 "-units type the units of image resolution",
3477 "-verbose print detailed information about the image",
3478 "-view FlashPix viewing transforms",
3479 "-virtual-pixel method",
3480 " virtual pixel access method",
3481 "-weight type render text with this font weight",
3482 "-white-point point chromaticity white point",
3483 (char *) NULL
3484 },
3485 *stack_operators[]=
3486 {
anthonyb69c4b32011-03-23 04:37:44 +00003487 "-delete indexes delete the image from the image sequence",
3488 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003489 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003490 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003491 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003492 "-swap indexes swap two images in the image sequence",
3493 (char *) NULL
3494 };
3495
3496 const char
3497 **p;
3498
cristybb503372010-05-27 20:51:26 +00003499 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003500 (void) printf("Copyright: %s\n",GetMagickCopyright());
3501 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003502 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3503 GetClientName());
3504 (void) printf("\nImage Settings:\n");
3505 for (p=settings; *p != (char *) NULL; p++)
3506 (void) printf(" %s\n",*p);
3507 (void) printf("\nImage Operators:\n");
3508 for (p=operators; *p != (char *) NULL; p++)
3509 (void) printf(" %s\n",*p);
3510 (void) printf("\nImage Sequence Operators:\n");
3511 for (p=sequence_operators; *p != (char *) NULL; p++)
3512 (void) printf(" %s\n",*p);
3513 (void) printf("\nImage Stack Operators:\n");
3514 for (p=stack_operators; *p != (char *) NULL; p++)
3515 (void) printf(" %s\n",*p);
3516 (void) printf("\nMiscellaneous Options:\n");
3517 for (p=miscellaneous; *p != (char *) NULL; p++)
3518 (void) printf(" %s\n",*p);
3519 (void) printf(
3520 "\nBy default, the image format of `file' is determined by its magic\n");
3521 (void) printf(
3522 "number. To specify a particular image format, precede the filename\n");
3523 (void) printf(
3524 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3525 (void) printf(
3526 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3527 (void) printf("'-' for standard input or output.\n");
3528 return(MagickFalse);
3529}
3530
3531WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3532 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3533{
3534#define DestroyMogrify() \
3535{ \
3536 if (format != (char *) NULL) \
3537 format=DestroyString(format); \
3538 if (path != (char *) NULL) \
3539 path=DestroyString(path); \
3540 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003541 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003542 argv[i]=DestroyString(argv[i]); \
3543 argv=(char **) RelinquishMagickMemory(argv); \
3544}
3545#define ThrowMogrifyException(asperity,tag,option) \
3546{ \
3547 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3548 option); \
3549 DestroyMogrify(); \
3550 return(MagickFalse); \
3551}
3552#define ThrowMogrifyInvalidArgumentException(option,argument) \
3553{ \
3554 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3555 "InvalidArgument","`%s': %s",argument,option); \
3556 DestroyMogrify(); \
3557 return(MagickFalse); \
3558}
3559
3560 char
3561 *format,
3562 *option,
3563 *path;
3564
3565 Image
3566 *image;
3567
3568 ImageStack
3569 image_stack[MaxImageStackDepth+1];
3570
cristy3ed852e2009-09-05 21:47:34 +00003571 MagickBooleanType
3572 global_colormap;
3573
3574 MagickBooleanType
3575 fire,
cristyebbcfea2011-02-25 02:43:54 +00003576 pend,
3577 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003578
3579 MagickStatusType
3580 status;
3581
cristyebbcfea2011-02-25 02:43:54 +00003582 register ssize_t
3583 i;
3584
3585 ssize_t
3586 j,
3587 k;
3588
cristy3ed852e2009-09-05 21:47:34 +00003589 /*
3590 Set defaults.
3591 */
3592 assert(image_info != (ImageInfo *) NULL);
3593 assert(image_info->signature == MagickSignature);
3594 if (image_info->debug != MagickFalse)
3595 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3596 assert(exception != (ExceptionInfo *) NULL);
3597 if (argc == 2)
3598 {
3599 option=argv[1];
3600 if ((LocaleCompare("version",option+1) == 0) ||
3601 (LocaleCompare("-version",option+1) == 0))
3602 {
cristyb51dff52011-05-19 16:55:47 +00003603 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003604 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003605 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3606 GetMagickCopyright());
3607 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3608 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003609 return(MagickFalse);
3610 }
3611 }
3612 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003613 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003614 format=(char *) NULL;
3615 path=(char *) NULL;
3616 global_colormap=MagickFalse;
3617 k=0;
3618 j=1;
3619 NewImageStack();
3620 option=(char *) NULL;
3621 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003622 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003623 status=MagickTrue;
3624 /*
3625 Parse command line.
3626 */
3627 ReadCommandlLine(argc,&argv);
3628 status=ExpandFilenames(&argc,&argv);
3629 if (status == MagickFalse)
3630 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3631 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003632 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003633 {
3634 option=argv[i];
3635 if (LocaleCompare(option,"(") == 0)
3636 {
3637 FireImageStack(MagickFalse,MagickTrue,pend);
3638 if (k == MaxImageStackDepth)
3639 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3640 option);
3641 PushImageStack();
3642 continue;
3643 }
3644 if (LocaleCompare(option,")") == 0)
3645 {
3646 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3647 if (k == 0)
3648 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3649 PopImageStack();
3650 continue;
3651 }
cristy042ee782011-04-22 18:48:30 +00003652 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003653 {
3654 char
3655 backup_filename[MaxTextExtent],
3656 *filename;
3657
3658 Image
3659 *images;
3660
3661 /*
3662 Option is a file name: begin by reading image from specified file.
3663 */
3664 FireImageStack(MagickFalse,MagickFalse,pend);
3665 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003666 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003667 filename=argv[++i];
3668 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3669 images=ReadImages(image_info,exception);
3670 status&=(images != (Image *) NULL) &&
3671 (exception->severity < ErrorException);
3672 if (images == (Image *) NULL)
3673 continue;
cristydaa76602010-06-30 13:05:11 +00003674 if (format != (char *) NULL)
3675 (void) CopyMagickString(images->filename,images->magick_filename,
3676 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003677 if (path != (char *) NULL)
3678 {
3679 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003680 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003681 path,*DirectorySeparator,filename);
3682 }
3683 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003684 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003685 AppendImageStack(images);
3686 FinalizeImageSettings(image_info,image,MagickFalse);
3687 if (global_colormap != MagickFalse)
3688 {
3689 QuantizeInfo
3690 *quantize_info;
3691
3692 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003693 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003694 quantize_info=DestroyQuantizeInfo(quantize_info);
3695 }
3696 *backup_filename='\0';
3697 if ((LocaleCompare(image->filename,"-") != 0) &&
3698 (IsPathWritable(image->filename) != MagickFalse))
3699 {
cristybb503372010-05-27 20:51:26 +00003700 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003701 i;
3702
3703 /*
3704 Rename image file as backup.
3705 */
3706 (void) CopyMagickString(backup_filename,image->filename,
3707 MaxTextExtent);
3708 for (i=0; i < 6; i++)
3709 {
3710 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3711 if (IsPathAccessible(backup_filename) == MagickFalse)
3712 break;
3713 }
3714 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3715 (rename(image->filename,backup_filename) != 0))
3716 *backup_filename='\0';
3717 }
3718 /*
3719 Write transmogrified image to disk.
3720 */
3721 image_info->synchronize=MagickTrue;
3722 status&=WriteImages(image_info,image,image->filename,exception);
3723 if ((status == MagickFalse) && (*backup_filename != '\0'))
3724 (void) remove(backup_filename);
3725 RemoveAllImageStack();
3726 continue;
3727 }
3728 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3729 switch (*(option+1))
3730 {
3731 case 'a':
3732 {
3733 if (LocaleCompare("adaptive-blur",option+1) == 0)
3734 {
3735 i++;
cristybb503372010-05-27 20:51:26 +00003736 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003737 ThrowMogrifyException(OptionError,"MissingArgument",option);
3738 if (IsGeometry(argv[i]) == MagickFalse)
3739 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3740 break;
3741 }
3742 if (LocaleCompare("adaptive-resize",option+1) == 0)
3743 {
3744 i++;
cristybb503372010-05-27 20:51:26 +00003745 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003746 ThrowMogrifyException(OptionError,"MissingArgument",option);
3747 if (IsGeometry(argv[i]) == MagickFalse)
3748 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3749 break;
3750 }
3751 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3752 {
3753 i++;
cristybb503372010-05-27 20:51:26 +00003754 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003755 ThrowMogrifyException(OptionError,"MissingArgument",option);
3756 if (IsGeometry(argv[i]) == MagickFalse)
3757 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3758 break;
3759 }
3760 if (LocaleCompare("affine",option+1) == 0)
3761 {
3762 if (*option == '+')
3763 break;
3764 i++;
cristybb503372010-05-27 20:51:26 +00003765 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003766 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003767 break;
3768 }
3769 if (LocaleCompare("alpha",option+1) == 0)
3770 {
cristybb503372010-05-27 20:51:26 +00003771 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003772 type;
3773
3774 if (*option == '+')
3775 break;
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);
cristy042ee782011-04-22 18:48:30 +00003779 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003780 if (type < 0)
3781 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3782 argv[i]);
3783 break;
3784 }
3785 if (LocaleCompare("annotate",option+1) == 0)
3786 {
3787 if (*option == '+')
3788 break;
3789 i++;
cristybb503372010-05-27 20:51:26 +00003790 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003791 ThrowMogrifyException(OptionError,"MissingArgument",option);
3792 if (IsGeometry(argv[i]) == MagickFalse)
3793 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003794 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003795 ThrowMogrifyException(OptionError,"MissingArgument",option);
3796 i++;
3797 break;
3798 }
3799 if (LocaleCompare("antialias",option+1) == 0)
3800 break;
3801 if (LocaleCompare("append",option+1) == 0)
3802 break;
3803 if (LocaleCompare("attenuate",option+1) == 0)
3804 {
3805 if (*option == '+')
3806 break;
3807 i++;
cristybb503372010-05-27 20:51:26 +00003808 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003809 ThrowMogrifyException(OptionError,"MissingArgument",option);
3810 if (IsGeometry(argv[i]) == MagickFalse)
3811 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3812 break;
3813 }
3814 if (LocaleCompare("authenticate",option+1) == 0)
3815 {
3816 if (*option == '+')
3817 break;
3818 i++;
cristybb503372010-05-27 20:51:26 +00003819 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003820 ThrowMogrifyException(OptionError,"MissingArgument",option);
3821 break;
3822 }
3823 if (LocaleCompare("auto-gamma",option+1) == 0)
3824 break;
3825 if (LocaleCompare("auto-level",option+1) == 0)
3826 break;
3827 if (LocaleCompare("auto-orient",option+1) == 0)
3828 break;
3829 if (LocaleCompare("average",option+1) == 0)
3830 break;
3831 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3832 }
3833 case 'b':
3834 {
3835 if (LocaleCompare("background",option+1) == 0)
3836 {
3837 if (*option == '+')
3838 break;
3839 i++;
cristybb503372010-05-27 20:51:26 +00003840 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003841 ThrowMogrifyException(OptionError,"MissingArgument",option);
3842 break;
3843 }
3844 if (LocaleCompare("bias",option+1) == 0)
3845 {
3846 if (*option == '+')
3847 break;
3848 i++;
cristybb503372010-05-27 20:51:26 +00003849 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003850 ThrowMogrifyException(OptionError,"MissingArgument",option);
3851 if (IsGeometry(argv[i]) == MagickFalse)
3852 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3853 break;
3854 }
3855 if (LocaleCompare("black-point-compensation",option+1) == 0)
3856 break;
3857 if (LocaleCompare("black-threshold",option+1) == 0)
3858 {
3859 if (*option == '+')
3860 break;
3861 i++;
cristybb503372010-05-27 20:51:26 +00003862 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003863 ThrowMogrifyException(OptionError,"MissingArgument",option);
3864 if (IsGeometry(argv[i]) == MagickFalse)
3865 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3866 break;
3867 }
3868 if (LocaleCompare("blue-primary",option+1) == 0)
3869 {
3870 if (*option == '+')
3871 break;
3872 i++;
cristybb503372010-05-27 20:51:26 +00003873 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003874 ThrowMogrifyException(OptionError,"MissingArgument",option);
3875 if (IsGeometry(argv[i]) == MagickFalse)
3876 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3877 break;
3878 }
3879 if (LocaleCompare("blue-shift",option+1) == 0)
3880 {
3881 i++;
cristybb503372010-05-27 20:51:26 +00003882 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003883 ThrowMogrifyException(OptionError,"MissingArgument",option);
3884 if (IsGeometry(argv[i]) == MagickFalse)
3885 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3886 break;
3887 }
3888 if (LocaleCompare("blur",option+1) == 0)
3889 {
3890 i++;
cristybb503372010-05-27 20:51:26 +00003891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003892 ThrowMogrifyException(OptionError,"MissingArgument",option);
3893 if (IsGeometry(argv[i]) == MagickFalse)
3894 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3895 break;
3896 }
3897 if (LocaleCompare("border",option+1) == 0)
3898 {
3899 if (*option == '+')
3900 break;
3901 i++;
cristybb503372010-05-27 20:51:26 +00003902 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003903 ThrowMogrifyException(OptionError,"MissingArgument",option);
3904 if (IsGeometry(argv[i]) == MagickFalse)
3905 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3906 break;
3907 }
3908 if (LocaleCompare("bordercolor",option+1) == 0)
3909 {
3910 if (*option == '+')
3911 break;
3912 i++;
cristybb503372010-05-27 20:51:26 +00003913 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003914 ThrowMogrifyException(OptionError,"MissingArgument",option);
3915 break;
3916 }
3917 if (LocaleCompare("box",option+1) == 0)
3918 {
3919 if (*option == '+')
3920 break;
3921 i++;
cristybb503372010-05-27 20:51:26 +00003922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003923 ThrowMogrifyException(OptionError,"MissingArgument",option);
3924 break;
3925 }
cristya28d6b82010-01-11 20:03:47 +00003926 if (LocaleCompare("brightness-contrast",option+1) == 0)
3927 {
3928 i++;
cristybb503372010-05-27 20:51:26 +00003929 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003930 ThrowMogrifyException(OptionError,"MissingArgument",option);
3931 if (IsGeometry(argv[i]) == MagickFalse)
3932 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3933 break;
3934 }
cristy3ed852e2009-09-05 21:47:34 +00003935 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3936 }
3937 case 'c':
3938 {
3939 if (LocaleCompare("cache",option+1) == 0)
3940 {
3941 if (*option == '+')
3942 break;
3943 i++;
cristybb503372010-05-27 20:51:26 +00003944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003945 ThrowMogrifyException(OptionError,"MissingArgument",option);
3946 if (IsGeometry(argv[i]) == MagickFalse)
3947 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3948 break;
3949 }
3950 if (LocaleCompare("caption",option+1) == 0)
3951 {
3952 if (*option == '+')
3953 break;
3954 i++;
cristybb503372010-05-27 20:51:26 +00003955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003956 ThrowMogrifyException(OptionError,"MissingArgument",option);
3957 break;
3958 }
3959 if (LocaleCompare("channel",option+1) == 0)
3960 {
cristybb503372010-05-27 20:51:26 +00003961 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003962 channel;
3963
3964 if (*option == '+')
3965 break;
3966 i++;
cristybb503372010-05-27 20:51:26 +00003967 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003968 ThrowMogrifyException(OptionError,"MissingArgument",option);
3969 channel=ParseChannelOption(argv[i]);
3970 if (channel < 0)
3971 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3972 argv[i]);
3973 break;
3974 }
3975 if (LocaleCompare("cdl",option+1) == 0)
3976 {
3977 if (*option == '+')
3978 break;
3979 i++;
cristybb503372010-05-27 20:51:26 +00003980 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003981 ThrowMogrifyException(OptionError,"MissingArgument",option);
3982 break;
3983 }
3984 if (LocaleCompare("charcoal",option+1) == 0)
3985 {
3986 if (*option == '+')
3987 break;
3988 i++;
cristybb503372010-05-27 20:51:26 +00003989 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003990 ThrowMogrifyException(OptionError,"MissingArgument",option);
3991 if (IsGeometry(argv[i]) == MagickFalse)
3992 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3993 break;
3994 }
3995 if (LocaleCompare("chop",option+1) == 0)
3996 {
3997 if (*option == '+')
3998 break;
3999 i++;
cristybb503372010-05-27 20:51:26 +00004000 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004001 ThrowMogrifyException(OptionError,"MissingArgument",option);
4002 if (IsGeometry(argv[i]) == MagickFalse)
4003 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4004 break;
4005 }
cristy1eb45dd2009-09-25 16:38:06 +00004006 if (LocaleCompare("clamp",option+1) == 0)
4007 break;
4008 if (LocaleCompare("clip",option+1) == 0)
4009 break;
cristy3ed852e2009-09-05 21:47:34 +00004010 if (LocaleCompare("clip-mask",option+1) == 0)
4011 {
4012 if (*option == '+')
4013 break;
4014 i++;
cristybb503372010-05-27 20:51:26 +00004015 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004016 ThrowMogrifyException(OptionError,"MissingArgument",option);
4017 break;
4018 }
4019 if (LocaleCompare("clut",option+1) == 0)
4020 break;
4021 if (LocaleCompare("coalesce",option+1) == 0)
4022 break;
4023 if (LocaleCompare("colorize",option+1) == 0)
4024 {
4025 if (*option == '+')
4026 break;
4027 i++;
cristybb503372010-05-27 20:51:26 +00004028 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004029 ThrowMogrifyException(OptionError,"MissingArgument",option);
4030 if (IsGeometry(argv[i]) == MagickFalse)
4031 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4032 break;
4033 }
cristye6365592010-04-02 17:31:23 +00004034 if (LocaleCompare("color-matrix",option+1) == 0)
4035 {
cristyb6bd4ad2010-08-08 01:12:27 +00004036 KernelInfo
4037 *kernel_info;
4038
cristye6365592010-04-02 17:31:23 +00004039 if (*option == '+')
4040 break;
4041 i++;
cristybb503372010-05-27 20:51:26 +00004042 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004043 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004044 kernel_info=AcquireKernelInfo(argv[i]);
4045 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004046 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004047 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004048 break;
4049 }
cristy3ed852e2009-09-05 21:47:34 +00004050 if (LocaleCompare("colors",option+1) == 0)
4051 {
4052 if (*option == '+')
4053 break;
4054 i++;
cristybb503372010-05-27 20:51:26 +00004055 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004056 ThrowMogrifyException(OptionError,"MissingArgument",option);
4057 if (IsGeometry(argv[i]) == MagickFalse)
4058 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4059 break;
4060 }
4061 if (LocaleCompare("colorspace",option+1) == 0)
4062 {
cristybb503372010-05-27 20:51:26 +00004063 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004064 colorspace;
4065
4066 if (*option == '+')
4067 break;
4068 i++;
cristybb503372010-05-27 20:51:26 +00004069 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004070 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004071 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004072 argv[i]);
4073 if (colorspace < 0)
4074 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4075 argv[i]);
4076 break;
4077 }
4078 if (LocaleCompare("combine",option+1) == 0)
4079 break;
4080 if (LocaleCompare("comment",option+1) == 0)
4081 {
4082 if (*option == '+')
4083 break;
4084 i++;
cristybb503372010-05-27 20:51:26 +00004085 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004086 ThrowMogrifyException(OptionError,"MissingArgument",option);
4087 break;
4088 }
4089 if (LocaleCompare("composite",option+1) == 0)
4090 break;
4091 if (LocaleCompare("compress",option+1) == 0)
4092 {
cristybb503372010-05-27 20:51:26 +00004093 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004094 compress;
4095
4096 if (*option == '+')
4097 break;
4098 i++;
cristybb503372010-05-27 20:51:26 +00004099 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004100 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004101 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004102 argv[i]);
4103 if (compress < 0)
4104 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4105 argv[i]);
4106 break;
4107 }
cristy22879752009-10-25 23:55:40 +00004108 if (LocaleCompare("concurrent",option+1) == 0)
4109 break;
cristy3ed852e2009-09-05 21:47:34 +00004110 if (LocaleCompare("contrast",option+1) == 0)
4111 break;
4112 if (LocaleCompare("contrast-stretch",option+1) == 0)
4113 {
4114 i++;
cristybb503372010-05-27 20:51:26 +00004115 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004116 ThrowMogrifyException(OptionError,"MissingArgument",option);
4117 if (IsGeometry(argv[i]) == MagickFalse)
4118 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4119 break;
4120 }
4121 if (LocaleCompare("convolve",option+1) == 0)
4122 {
cristyb6bd4ad2010-08-08 01:12:27 +00004123 KernelInfo
4124 *kernel_info;
4125
cristy3ed852e2009-09-05 21:47:34 +00004126 if (*option == '+')
4127 break;
4128 i++;
cristybb503372010-05-27 20:51:26 +00004129 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004130 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004131 kernel_info=AcquireKernelInfo(argv[i]);
4132 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004133 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004134 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004135 break;
4136 }
4137 if (LocaleCompare("crop",option+1) == 0)
4138 {
4139 if (*option == '+')
4140 break;
4141 i++;
cristybb503372010-05-27 20:51:26 +00004142 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004143 ThrowMogrifyException(OptionError,"MissingArgument",option);
4144 if (IsGeometry(argv[i]) == MagickFalse)
4145 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4146 break;
4147 }
4148 if (LocaleCompare("cycle",option+1) == 0)
4149 {
4150 if (*option == '+')
4151 break;
4152 i++;
cristybb503372010-05-27 20:51:26 +00004153 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004154 ThrowMogrifyException(OptionError,"MissingArgument",option);
4155 if (IsGeometry(argv[i]) == MagickFalse)
4156 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4157 break;
4158 }
4159 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4160 }
4161 case 'd':
4162 {
4163 if (LocaleCompare("decipher",option+1) == 0)
4164 {
4165 if (*option == '+')
4166 break;
4167 i++;
cristybb503372010-05-27 20:51:26 +00004168 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004169 ThrowMogrifyException(OptionError,"MissingArgument",option);
4170 break;
4171 }
4172 if (LocaleCompare("deconstruct",option+1) == 0)
4173 break;
4174 if (LocaleCompare("debug",option+1) == 0)
4175 {
cristybb503372010-05-27 20:51:26 +00004176 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004177 event;
4178
4179 if (*option == '+')
4180 break;
4181 i++;
cristybb503372010-05-27 20:51:26 +00004182 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004183 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004184 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004185 if (event < 0)
4186 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4187 argv[i]);
4188 (void) SetLogEventMask(argv[i]);
4189 break;
4190 }
4191 if (LocaleCompare("define",option+1) == 0)
4192 {
4193 i++;
cristybb503372010-05-27 20:51:26 +00004194 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004195 ThrowMogrifyException(OptionError,"MissingArgument",option);
4196 if (*option == '+')
4197 {
4198 const char
4199 *define;
4200
4201 define=GetImageOption(image_info,argv[i]);
4202 if (define == (const char *) NULL)
4203 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4204 break;
4205 }
4206 break;
4207 }
4208 if (LocaleCompare("delay",option+1) == 0)
4209 {
4210 if (*option == '+')
4211 break;
4212 i++;
cristybb503372010-05-27 20:51:26 +00004213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004214 ThrowMogrifyException(OptionError,"MissingArgument",option);
4215 if (IsGeometry(argv[i]) == MagickFalse)
4216 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4217 break;
4218 }
cristyecb10ff2011-03-22 13:14:03 +00004219 if (LocaleCompare("delete",option+1) == 0)
4220 {
4221 if (*option == '+')
4222 break;
4223 i++;
4224 if (i == (ssize_t) (argc-1))
4225 ThrowMogrifyException(OptionError,"MissingArgument",option);
4226 if (IsGeometry(argv[i]) == MagickFalse)
4227 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4228 break;
4229 }
cristy3ed852e2009-09-05 21:47:34 +00004230 if (LocaleCompare("density",option+1) == 0)
4231 {
4232 if (*option == '+')
4233 break;
4234 i++;
cristybb503372010-05-27 20:51:26 +00004235 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004236 ThrowMogrifyException(OptionError,"MissingArgument",option);
4237 if (IsGeometry(argv[i]) == MagickFalse)
4238 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4239 break;
4240 }
4241 if (LocaleCompare("depth",option+1) == 0)
4242 {
4243 if (*option == '+')
4244 break;
4245 i++;
cristybb503372010-05-27 20:51:26 +00004246 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004247 ThrowMogrifyException(OptionError,"MissingArgument",option);
4248 if (IsGeometry(argv[i]) == MagickFalse)
4249 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4250 break;
4251 }
4252 if (LocaleCompare("deskew",option+1) == 0)
4253 {
4254 if (*option == '+')
4255 break;
4256 i++;
cristybb503372010-05-27 20:51:26 +00004257 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004258 ThrowMogrifyException(OptionError,"MissingArgument",option);
4259 if (IsGeometry(argv[i]) == MagickFalse)
4260 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4261 break;
4262 }
4263 if (LocaleCompare("despeckle",option+1) == 0)
4264 break;
4265 if (LocaleCompare("dft",option+1) == 0)
4266 break;
cristyc9b12952010-03-28 01:12:28 +00004267 if (LocaleCompare("direction",option+1) == 0)
4268 {
cristybb503372010-05-27 20:51:26 +00004269 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004270 direction;
4271
4272 if (*option == '+')
4273 break;
4274 i++;
cristybb503372010-05-27 20:51:26 +00004275 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004276 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004277 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004278 argv[i]);
4279 if (direction < 0)
4280 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4281 argv[i]);
4282 break;
4283 }
cristy3ed852e2009-09-05 21:47:34 +00004284 if (LocaleCompare("display",option+1) == 0)
4285 {
4286 if (*option == '+')
4287 break;
4288 i++;
cristybb503372010-05-27 20:51:26 +00004289 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004290 ThrowMogrifyException(OptionError,"MissingArgument",option);
4291 break;
4292 }
4293 if (LocaleCompare("dispose",option+1) == 0)
4294 {
cristybb503372010-05-27 20:51:26 +00004295 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004296 dispose;
4297
4298 if (*option == '+')
4299 break;
4300 i++;
cristybb503372010-05-27 20:51:26 +00004301 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004302 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004303 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004304 if (dispose < 0)
4305 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4306 argv[i]);
4307 break;
4308 }
4309 if (LocaleCompare("distort",option+1) == 0)
4310 {
cristybb503372010-05-27 20:51:26 +00004311 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004312 op;
4313
4314 i++;
cristybb503372010-05-27 20:51:26 +00004315 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004316 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004317 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004318 if (op < 0)
4319 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4320 argv[i]);
4321 i++;
cristybb503372010-05-27 20:51:26 +00004322 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004323 ThrowMogrifyException(OptionError,"MissingArgument",option);
4324 break;
4325 }
4326 if (LocaleCompare("dither",option+1) == 0)
4327 {
cristybb503372010-05-27 20:51:26 +00004328 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004329 method;
4330
4331 if (*option == '+')
4332 break;
4333 i++;
cristybb503372010-05-27 20:51:26 +00004334 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004335 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004336 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004337 if (method < 0)
4338 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4339 argv[i]);
4340 break;
4341 }
4342 if (LocaleCompare("draw",option+1) == 0)
4343 {
4344 if (*option == '+')
4345 break;
4346 i++;
cristybb503372010-05-27 20:51:26 +00004347 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004348 ThrowMogrifyException(OptionError,"MissingArgument",option);
4349 break;
4350 }
cristyecb10ff2011-03-22 13:14:03 +00004351 if (LocaleCompare("duplicate",option+1) == 0)
4352 {
4353 if (*option == '+')
4354 break;
4355 i++;
4356 if (i == (ssize_t) (argc-1))
4357 ThrowMogrifyException(OptionError,"MissingArgument",option);
4358 if (IsGeometry(argv[i]) == MagickFalse)
4359 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4360 break;
4361 }
cristy22879752009-10-25 23:55:40 +00004362 if (LocaleCompare("duration",option+1) == 0)
4363 {
4364 if (*option == '+')
4365 break;
4366 i++;
cristybb503372010-05-27 20:51:26 +00004367 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004368 ThrowMogrifyException(OptionError,"MissingArgument",option);
4369 if (IsGeometry(argv[i]) == MagickFalse)
4370 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4371 break;
4372 }
cristy3ed852e2009-09-05 21:47:34 +00004373 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4374 }
4375 case 'e':
4376 {
4377 if (LocaleCompare("edge",option+1) == 0)
4378 {
4379 if (*option == '+')
4380 break;
4381 i++;
cristybb503372010-05-27 20:51:26 +00004382 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004383 ThrowMogrifyException(OptionError,"MissingArgument",option);
4384 if (IsGeometry(argv[i]) == MagickFalse)
4385 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4386 break;
4387 }
4388 if (LocaleCompare("emboss",option+1) == 0)
4389 {
4390 if (*option == '+')
4391 break;
4392 i++;
cristybb503372010-05-27 20:51:26 +00004393 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004394 ThrowMogrifyException(OptionError,"MissingArgument",option);
4395 if (IsGeometry(argv[i]) == MagickFalse)
4396 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4397 break;
4398 }
4399 if (LocaleCompare("encipher",option+1) == 0)
4400 {
4401 if (*option == '+')
4402 break;
4403 i++;
cristybb503372010-05-27 20:51:26 +00004404 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004405 ThrowMogrifyException(OptionError,"MissingArgument",option);
4406 break;
4407 }
4408 if (LocaleCompare("encoding",option+1) == 0)
4409 {
4410 if (*option == '+')
4411 break;
4412 i++;
cristybb503372010-05-27 20:51:26 +00004413 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004414 ThrowMogrifyException(OptionError,"MissingArgument",option);
4415 break;
4416 }
4417 if (LocaleCompare("endian",option+1) == 0)
4418 {
cristybb503372010-05-27 20:51:26 +00004419 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004420 endian;
4421
4422 if (*option == '+')
4423 break;
4424 i++;
cristybb503372010-05-27 20:51:26 +00004425 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004426 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004427 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004428 if (endian < 0)
4429 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4430 argv[i]);
4431 break;
4432 }
4433 if (LocaleCompare("enhance",option+1) == 0)
4434 break;
4435 if (LocaleCompare("equalize",option+1) == 0)
4436 break;
4437 if (LocaleCompare("evaluate",option+1) == 0)
4438 {
cristybb503372010-05-27 20:51:26 +00004439 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004440 op;
4441
4442 if (*option == '+')
4443 break;
4444 i++;
cristybb503372010-05-27 20:51:26 +00004445 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004446 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004447 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004448 if (op < 0)
4449 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4450 argv[i]);
4451 i++;
cristybb503372010-05-27 20:51:26 +00004452 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004453 ThrowMogrifyException(OptionError,"MissingArgument",option);
4454 if (IsGeometry(argv[i]) == MagickFalse)
4455 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4456 break;
4457 }
cristyd18ae7c2010-03-07 17:39:52 +00004458 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4459 {
cristybb503372010-05-27 20:51:26 +00004460 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004461 op;
4462
4463 if (*option == '+')
4464 break;
4465 i++;
cristybb503372010-05-27 20:51:26 +00004466 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004467 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004468 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004469 if (op < 0)
4470 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4471 argv[i]);
4472 break;
4473 }
cristy3ed852e2009-09-05 21:47:34 +00004474 if (LocaleCompare("extent",option+1) == 0)
4475 {
4476 if (*option == '+')
4477 break;
4478 i++;
cristybb503372010-05-27 20:51:26 +00004479 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004480 ThrowMogrifyException(OptionError,"MissingArgument",option);
4481 if (IsGeometry(argv[i]) == MagickFalse)
4482 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4483 break;
4484 }
4485 if (LocaleCompare("extract",option+1) == 0)
4486 {
4487 if (*option == '+')
4488 break;
4489 i++;
cristybb503372010-05-27 20:51:26 +00004490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004491 ThrowMogrifyException(OptionError,"MissingArgument",option);
4492 if (IsGeometry(argv[i]) == MagickFalse)
4493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4494 break;
4495 }
4496 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4497 }
4498 case 'f':
4499 {
4500 if (LocaleCompare("family",option+1) == 0)
4501 {
4502 if (*option == '+')
4503 break;
4504 i++;
cristybb503372010-05-27 20:51:26 +00004505 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004506 ThrowMogrifyException(OptionError,"MissingArgument",option);
4507 break;
4508 }
4509 if (LocaleCompare("fill",option+1) == 0)
4510 {
4511 if (*option == '+')
4512 break;
4513 i++;
cristybb503372010-05-27 20:51:26 +00004514 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004515 ThrowMogrifyException(OptionError,"MissingArgument",option);
4516 break;
4517 }
4518 if (LocaleCompare("filter",option+1) == 0)
4519 {
cristybb503372010-05-27 20:51:26 +00004520 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004521 filter;
4522
4523 if (*option == '+')
4524 break;
4525 i++;
cristybb503372010-05-27 20:51:26 +00004526 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004527 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004528 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004529 if (filter < 0)
4530 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4531 argv[i]);
4532 break;
4533 }
4534 if (LocaleCompare("flatten",option+1) == 0)
4535 break;
4536 if (LocaleCompare("flip",option+1) == 0)
4537 break;
4538 if (LocaleCompare("flop",option+1) == 0)
4539 break;
4540 if (LocaleCompare("floodfill",option+1) == 0)
4541 {
4542 if (*option == '+')
4543 break;
4544 i++;
cristybb503372010-05-27 20:51:26 +00004545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004546 ThrowMogrifyException(OptionError,"MissingArgument",option);
4547 if (IsGeometry(argv[i]) == MagickFalse)
4548 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4549 i++;
cristybb503372010-05-27 20:51:26 +00004550 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004551 ThrowMogrifyException(OptionError,"MissingArgument",option);
4552 break;
4553 }
4554 if (LocaleCompare("font",option+1) == 0)
4555 {
4556 if (*option == '+')
4557 break;
4558 i++;
cristybb503372010-05-27 20:51:26 +00004559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004560 ThrowMogrifyException(OptionError,"MissingArgument",option);
4561 break;
4562 }
4563 if (LocaleCompare("format",option+1) == 0)
4564 {
4565 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4566 (void) CloneString(&format,(char *) NULL);
4567 if (*option == '+')
4568 break;
4569 i++;
cristybb503372010-05-27 20:51:26 +00004570 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004571 ThrowMogrifyException(OptionError,"MissingArgument",option);
4572 (void) CloneString(&format,argv[i]);
4573 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4574 (void) ConcatenateMagickString(image_info->filename,":",
4575 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004576 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004577 if (*image_info->magick == '\0')
4578 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4579 format);
4580 break;
4581 }
4582 if (LocaleCompare("frame",option+1) == 0)
4583 {
4584 if (*option == '+')
4585 break;
4586 i++;
cristybb503372010-05-27 20:51:26 +00004587 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004588 ThrowMogrifyException(OptionError,"MissingArgument",option);
4589 if (IsGeometry(argv[i]) == MagickFalse)
4590 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4591 break;
4592 }
4593 if (LocaleCompare("function",option+1) == 0)
4594 {
cristybb503372010-05-27 20:51:26 +00004595 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004596 op;
4597
4598 if (*option == '+')
4599 break;
4600 i++;
cristybb503372010-05-27 20:51:26 +00004601 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004602 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004603 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004604 if (op < 0)
4605 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4606 i++;
cristybb503372010-05-27 20:51:26 +00004607 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004608 ThrowMogrifyException(OptionError,"MissingArgument",option);
4609 break;
4610 }
4611 if (LocaleCompare("fuzz",option+1) == 0)
4612 {
4613 if (*option == '+')
4614 break;
4615 i++;
cristybb503372010-05-27 20:51:26 +00004616 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004617 ThrowMogrifyException(OptionError,"MissingArgument",option);
4618 if (IsGeometry(argv[i]) == MagickFalse)
4619 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4620 break;
4621 }
4622 if (LocaleCompare("fx",option+1) == 0)
4623 {
4624 if (*option == '+')
4625 break;
4626 i++;
cristybb503372010-05-27 20:51:26 +00004627 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004628 ThrowMogrifyException(OptionError,"MissingArgument",option);
4629 break;
4630 }
4631 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4632 }
4633 case 'g':
4634 {
4635 if (LocaleCompare("gamma",option+1) == 0)
4636 {
4637 i++;
cristybb503372010-05-27 20:51:26 +00004638 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004639 ThrowMogrifyException(OptionError,"MissingArgument",option);
4640 if (IsGeometry(argv[i]) == MagickFalse)
4641 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4642 break;
4643 }
4644 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4645 (LocaleCompare("gaussian",option+1) == 0))
4646 {
4647 i++;
cristybb503372010-05-27 20:51:26 +00004648 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004649 ThrowMogrifyException(OptionError,"MissingArgument",option);
4650 if (IsGeometry(argv[i]) == MagickFalse)
4651 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4652 break;
4653 }
4654 if (LocaleCompare("geometry",option+1) == 0)
4655 {
4656 if (*option == '+')
4657 break;
4658 i++;
cristybb503372010-05-27 20:51:26 +00004659 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004660 ThrowMogrifyException(OptionError,"MissingArgument",option);
4661 if (IsGeometry(argv[i]) == MagickFalse)
4662 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4663 break;
4664 }
4665 if (LocaleCompare("gravity",option+1) == 0)
4666 {
cristybb503372010-05-27 20:51:26 +00004667 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004668 gravity;
4669
4670 if (*option == '+')
4671 break;
4672 i++;
cristybb503372010-05-27 20:51:26 +00004673 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004674 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004675 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004676 if (gravity < 0)
4677 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4678 argv[i]);
4679 break;
4680 }
4681 if (LocaleCompare("green-primary",option+1) == 0)
4682 {
4683 if (*option == '+')
4684 break;
4685 i++;
cristybb503372010-05-27 20:51:26 +00004686 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004687 ThrowMogrifyException(OptionError,"MissingArgument",option);
4688 if (IsGeometry(argv[i]) == MagickFalse)
4689 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4690 break;
4691 }
4692 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4693 }
4694 case 'h':
4695 {
4696 if (LocaleCompare("hald-clut",option+1) == 0)
4697 break;
4698 if ((LocaleCompare("help",option+1) == 0) ||
4699 (LocaleCompare("-help",option+1) == 0))
4700 return(MogrifyUsage());
4701 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4702 }
4703 case 'i':
4704 {
4705 if (LocaleCompare("identify",option+1) == 0)
4706 break;
4707 if (LocaleCompare("idft",option+1) == 0)
4708 break;
4709 if (LocaleCompare("implode",option+1) == 0)
4710 {
4711 if (*option == '+')
4712 break;
4713 i++;
cristybb503372010-05-27 20:51:26 +00004714 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004715 ThrowMogrifyException(OptionError,"MissingArgument",option);
4716 if (IsGeometry(argv[i]) == MagickFalse)
4717 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4718 break;
4719 }
4720 if (LocaleCompare("intent",option+1) == 0)
4721 {
cristybb503372010-05-27 20:51:26 +00004722 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004723 intent;
4724
4725 if (*option == '+')
4726 break;
4727 i++;
cristybb503372010-05-27 20:51:26 +00004728 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004729 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004730 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004731 if (intent < 0)
4732 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4733 argv[i]);
4734 break;
4735 }
4736 if (LocaleCompare("interlace",option+1) == 0)
4737 {
cristybb503372010-05-27 20:51:26 +00004738 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004739 interlace;
4740
4741 if (*option == '+')
4742 break;
4743 i++;
cristybb503372010-05-27 20:51:26 +00004744 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004745 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004746 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004747 argv[i]);
4748 if (interlace < 0)
4749 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4750 argv[i]);
4751 break;
4752 }
cristyb32b90a2009-09-07 21:45:48 +00004753 if (LocaleCompare("interline-spacing",option+1) == 0)
4754 {
4755 if (*option == '+')
4756 break;
4757 i++;
cristybb503372010-05-27 20:51:26 +00004758 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004759 ThrowMogrifyException(OptionError,"MissingArgument",option);
4760 if (IsGeometry(argv[i]) == MagickFalse)
4761 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4762 break;
4763 }
cristy3ed852e2009-09-05 21:47:34 +00004764 if (LocaleCompare("interpolate",option+1) == 0)
4765 {
cristybb503372010-05-27 20:51:26 +00004766 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004767 interpolate;
4768
4769 if (*option == '+')
4770 break;
4771 i++;
cristybb503372010-05-27 20:51:26 +00004772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004773 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004774 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004775 argv[i]);
4776 if (interpolate < 0)
4777 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4778 argv[i]);
4779 break;
4780 }
4781 if (LocaleCompare("interword-spacing",option+1) == 0)
4782 {
4783 if (*option == '+')
4784 break;
4785 i++;
cristybb503372010-05-27 20:51:26 +00004786 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004787 ThrowMogrifyException(OptionError,"MissingArgument",option);
4788 if (IsGeometry(argv[i]) == MagickFalse)
4789 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4790 break;
4791 }
4792 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4793 }
4794 case 'k':
4795 {
4796 if (LocaleCompare("kerning",option+1) == 0)
4797 {
4798 if (*option == '+')
4799 break;
4800 i++;
cristybb503372010-05-27 20:51:26 +00004801 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004802 ThrowMogrifyException(OptionError,"MissingArgument",option);
4803 if (IsGeometry(argv[i]) == MagickFalse)
4804 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4805 break;
4806 }
4807 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4808 }
4809 case 'l':
4810 {
4811 if (LocaleCompare("label",option+1) == 0)
4812 {
4813 if (*option == '+')
4814 break;
4815 i++;
cristybb503372010-05-27 20:51:26 +00004816 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004817 ThrowMogrifyException(OptionError,"MissingArgument",option);
4818 break;
4819 }
4820 if (LocaleCompare("lat",option+1) == 0)
4821 {
4822 if (*option == '+')
4823 break;
4824 i++;
cristybb503372010-05-27 20:51:26 +00004825 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004826 ThrowMogrifyException(OptionError,"MissingArgument",option);
4827 if (IsGeometry(argv[i]) == MagickFalse)
4828 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4829 }
4830 if (LocaleCompare("layers",option+1) == 0)
4831 {
cristybb503372010-05-27 20:51:26 +00004832 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004833 type;
4834
4835 if (*option == '+')
4836 break;
4837 i++;
cristybb503372010-05-27 20:51:26 +00004838 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004839 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004840 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004841 if (type < 0)
4842 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4843 argv[i]);
4844 break;
4845 }
4846 if (LocaleCompare("level",option+1) == 0)
4847 {
4848 i++;
cristybb503372010-05-27 20:51:26 +00004849 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004850 ThrowMogrifyException(OptionError,"MissingArgument",option);
4851 if (IsGeometry(argv[i]) == MagickFalse)
4852 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4853 break;
4854 }
4855 if (LocaleCompare("level-colors",option+1) == 0)
4856 {
4857 i++;
cristybb503372010-05-27 20:51:26 +00004858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004859 ThrowMogrifyException(OptionError,"MissingArgument",option);
4860 break;
4861 }
4862 if (LocaleCompare("linewidth",option+1) == 0)
4863 {
4864 if (*option == '+')
4865 break;
4866 i++;
cristybb503372010-05-27 20:51:26 +00004867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004868 ThrowMogrifyException(OptionError,"MissingArgument",option);
4869 if (IsGeometry(argv[i]) == MagickFalse)
4870 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4871 break;
4872 }
4873 if (LocaleCompare("limit",option+1) == 0)
4874 {
4875 char
4876 *p;
4877
4878 double
4879 value;
4880
cristybb503372010-05-27 20:51:26 +00004881 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004882 resource;
4883
4884 if (*option == '+')
4885 break;
4886 i++;
cristybb503372010-05-27 20:51:26 +00004887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004888 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004889 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004890 argv[i]);
4891 if (resource < 0)
4892 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4893 argv[i]);
4894 i++;
cristybb503372010-05-27 20:51:26 +00004895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004896 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004897 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004898 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004899 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4900 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4901 break;
4902 }
4903 if (LocaleCompare("liquid-rescale",option+1) == 0)
4904 {
4905 i++;
cristybb503372010-05-27 20:51:26 +00004906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004907 ThrowMogrifyException(OptionError,"MissingArgument",option);
4908 if (IsGeometry(argv[i]) == MagickFalse)
4909 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4910 break;
4911 }
4912 if (LocaleCompare("list",option+1) == 0)
4913 {
cristybb503372010-05-27 20:51:26 +00004914 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004915 list;
4916
4917 if (*option == '+')
4918 break;
4919 i++;
cristybb503372010-05-27 20:51:26 +00004920 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004921 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004922 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004923 if (list < 0)
4924 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004925 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004926 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004927 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004928 }
4929 if (LocaleCompare("log",option+1) == 0)
4930 {
4931 if (*option == '+')
4932 break;
4933 i++;
cristybb503372010-05-27 20:51:26 +00004934 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004935 (strchr(argv[i],'%') == (char *) NULL))
4936 ThrowMogrifyException(OptionError,"MissingArgument",option);
4937 break;
4938 }
4939 if (LocaleCompare("loop",option+1) == 0)
4940 {
4941 if (*option == '+')
4942 break;
4943 i++;
cristybb503372010-05-27 20:51:26 +00004944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004945 ThrowMogrifyException(OptionError,"MissingArgument",option);
4946 if (IsGeometry(argv[i]) == MagickFalse)
4947 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4948 break;
4949 }
4950 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4951 }
4952 case 'm':
4953 {
4954 if (LocaleCompare("map",option+1) == 0)
4955 {
4956 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4957 if (*option == '+')
4958 break;
4959 i++;
cristybb503372010-05-27 20:51:26 +00004960 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004961 ThrowMogrifyException(OptionError,"MissingArgument",option);
4962 break;
4963 }
4964 if (LocaleCompare("mask",option+1) == 0)
4965 {
4966 if (*option == '+')
4967 break;
4968 i++;
cristybb503372010-05-27 20:51:26 +00004969 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004970 ThrowMogrifyException(OptionError,"MissingArgument",option);
4971 break;
4972 }
4973 if (LocaleCompare("matte",option+1) == 0)
4974 break;
4975 if (LocaleCompare("mattecolor",option+1) == 0)
4976 {
4977 if (*option == '+')
4978 break;
4979 i++;
cristybb503372010-05-27 20:51:26 +00004980 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004981 ThrowMogrifyException(OptionError,"MissingArgument",option);
4982 break;
4983 }
cristyf40785b2010-03-06 02:27:27 +00004984 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004985 break;
cristyf40785b2010-03-06 02:27:27 +00004986 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004987 break;
cristy3ed852e2009-09-05 21:47:34 +00004988 if (LocaleCompare("modulate",option+1) == 0)
4989 {
4990 if (*option == '+')
4991 break;
4992 i++;
cristybb503372010-05-27 20:51:26 +00004993 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004994 ThrowMogrifyException(OptionError,"MissingArgument",option);
4995 if (IsGeometry(argv[i]) == MagickFalse)
4996 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4997 break;
4998 }
4999 if (LocaleCompare("median",option+1) == 0)
5000 {
5001 if (*option == '+')
5002 break;
5003 i++;
cristybb503372010-05-27 20:51:26 +00005004 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005005 ThrowMogrifyException(OptionError,"MissingArgument",option);
5006 if (IsGeometry(argv[i]) == MagickFalse)
5007 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5008 break;
5009 }
cristy69ec32d2011-02-27 23:57:09 +00005010 if (LocaleCompare("mode",option+1) == 0)
5011 {
5012 if (*option == '+')
5013 break;
5014 i++;
5015 if (i == (ssize_t) argc)
5016 ThrowMogrifyException(OptionError,"MissingArgument",option);
5017 if (IsGeometry(argv[i]) == MagickFalse)
5018 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5019 break;
5020 }
cristy3ed852e2009-09-05 21:47:34 +00005021 if (LocaleCompare("monitor",option+1) == 0)
5022 break;
5023 if (LocaleCompare("monochrome",option+1) == 0)
5024 break;
5025 if (LocaleCompare("morph",option+1) == 0)
5026 {
5027 if (*option == '+')
5028 break;
5029 i++;
cristybb503372010-05-27 20:51:26 +00005030 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005031 ThrowMogrifyException(OptionError,"MissingArgument",option);
5032 if (IsGeometry(argv[i]) == MagickFalse)
5033 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5034 break;
5035 }
anthony29188a82010-01-22 10:12:34 +00005036 if (LocaleCompare("morphology",option+1) == 0)
5037 {
anthony29188a82010-01-22 10:12:34 +00005038 char
5039 token[MaxTextExtent];
5040
cristyb6bd4ad2010-08-08 01:12:27 +00005041 KernelInfo
5042 *kernel_info;
5043
5044 ssize_t
5045 op;
5046
anthony29188a82010-01-22 10:12:34 +00005047 i++;
cristybb503372010-05-27 20:51:26 +00005048 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005049 ThrowMogrifyException(OptionError,"MissingArgument",option);
5050 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005051 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005052 if (op < 0)
5053 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005054 token);
anthony29188a82010-01-22 10:12:34 +00005055 i++;
cristybb503372010-05-27 20:51:26 +00005056 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005057 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005058 kernel_info=AcquireKernelInfo(argv[i]);
5059 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005060 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005061 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005062 break;
5063 }
cristy3ed852e2009-09-05 21:47:34 +00005064 if (LocaleCompare("mosaic",option+1) == 0)
5065 break;
5066 if (LocaleCompare("motion-blur",option+1) == 0)
5067 {
5068 if (*option == '+')
5069 break;
5070 i++;
cristybb503372010-05-27 20:51:26 +00005071 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005072 ThrowMogrifyException(OptionError,"MissingArgument",option);
5073 if (IsGeometry(argv[i]) == MagickFalse)
5074 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5075 break;
5076 }
5077 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5078 }
5079 case 'n':
5080 {
5081 if (LocaleCompare("negate",option+1) == 0)
5082 break;
5083 if (LocaleCompare("noise",option+1) == 0)
5084 {
5085 i++;
cristybb503372010-05-27 20:51:26 +00005086 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005087 ThrowMogrifyException(OptionError,"MissingArgument",option);
5088 if (*option == '+')
5089 {
cristybb503372010-05-27 20:51:26 +00005090 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005091 noise;
5092
cristy042ee782011-04-22 18:48:30 +00005093 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005094 if (noise < 0)
5095 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5096 argv[i]);
5097 break;
5098 }
5099 if (IsGeometry(argv[i]) == MagickFalse)
5100 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5101 break;
5102 }
5103 if (LocaleCompare("noop",option+1) == 0)
5104 break;
5105 if (LocaleCompare("normalize",option+1) == 0)
5106 break;
5107 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5108 }
5109 case 'o':
5110 {
5111 if (LocaleCompare("opaque",option+1) == 0)
5112 {
cristy3ed852e2009-09-05 21:47:34 +00005113 i++;
cristybb503372010-05-27 20:51:26 +00005114 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005115 ThrowMogrifyException(OptionError,"MissingArgument",option);
5116 break;
5117 }
5118 if (LocaleCompare("ordered-dither",option+1) == 0)
5119 {
5120 if (*option == '+')
5121 break;
5122 i++;
cristybb503372010-05-27 20:51:26 +00005123 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005124 ThrowMogrifyException(OptionError,"MissingArgument",option);
5125 break;
5126 }
5127 if (LocaleCompare("orient",option+1) == 0)
5128 {
cristybb503372010-05-27 20:51:26 +00005129 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005130 orientation;
5131
5132 orientation=UndefinedOrientation;
5133 if (*option == '+')
5134 break;
5135 i++;
cristybb503372010-05-27 20:51:26 +00005136 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005137 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005138 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005139 argv[i]);
5140 if (orientation < 0)
5141 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5142 argv[i]);
5143 break;
5144 }
5145 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5146 }
5147 case 'p':
5148 {
5149 if (LocaleCompare("page",option+1) == 0)
5150 {
5151 if (*option == '+')
5152 break;
5153 i++;
cristybb503372010-05-27 20:51:26 +00005154 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005155 ThrowMogrifyException(OptionError,"MissingArgument",option);
5156 break;
5157 }
5158 if (LocaleCompare("paint",option+1) == 0)
5159 {
5160 if (*option == '+')
5161 break;
5162 i++;
cristybb503372010-05-27 20:51:26 +00005163 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005164 ThrowMogrifyException(OptionError,"MissingArgument",option);
5165 if (IsGeometry(argv[i]) == MagickFalse)
5166 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5167 break;
5168 }
5169 if (LocaleCompare("path",option+1) == 0)
5170 {
5171 (void) CloneString(&path,(char *) NULL);
5172 if (*option == '+')
5173 break;
5174 i++;
cristybb503372010-05-27 20:51:26 +00005175 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005176 ThrowMogrifyException(OptionError,"MissingArgument",option);
5177 (void) CloneString(&path,argv[i]);
5178 break;
5179 }
5180 if (LocaleCompare("pointsize",option+1) == 0)
5181 {
5182 if (*option == '+')
5183 break;
5184 i++;
cristybb503372010-05-27 20:51:26 +00005185 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005186 ThrowMogrifyException(OptionError,"MissingArgument",option);
5187 if (IsGeometry(argv[i]) == MagickFalse)
5188 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5189 break;
5190 }
5191 if (LocaleCompare("polaroid",option+1) == 0)
5192 {
5193 if (*option == '+')
5194 break;
5195 i++;
cristybb503372010-05-27 20:51:26 +00005196 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005197 ThrowMogrifyException(OptionError,"MissingArgument",option);
5198 if (IsGeometry(argv[i]) == MagickFalse)
5199 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5200 break;
5201 }
5202 if (LocaleCompare("posterize",option+1) == 0)
5203 {
5204 if (*option == '+')
5205 break;
5206 i++;
cristybb503372010-05-27 20:51:26 +00005207 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005208 ThrowMogrifyException(OptionError,"MissingArgument",option);
5209 if (IsGeometry(argv[i]) == MagickFalse)
5210 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5211 break;
5212 }
cristye7f51092010-01-17 00:39:37 +00005213 if (LocaleCompare("precision",option+1) == 0)
5214 {
5215 if (*option == '+')
5216 break;
5217 i++;
cristybb503372010-05-27 20:51:26 +00005218 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005219 ThrowMogrifyException(OptionError,"MissingArgument",option);
5220 if (IsGeometry(argv[i]) == MagickFalse)
5221 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5222 break;
5223 }
cristy3ed852e2009-09-05 21:47:34 +00005224 if (LocaleCompare("print",option+1) == 0)
5225 {
5226 if (*option == '+')
5227 break;
5228 i++;
cristybb503372010-05-27 20:51:26 +00005229 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005230 ThrowMogrifyException(OptionError,"MissingArgument",option);
5231 break;
5232 }
5233 if (LocaleCompare("process",option+1) == 0)
5234 {
5235 if (*option == '+')
5236 break;
5237 i++;
cristybb503372010-05-27 20:51:26 +00005238 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005239 ThrowMogrifyException(OptionError,"MissingArgument",option);
5240 break;
5241 }
5242 if (LocaleCompare("profile",option+1) == 0)
5243 {
5244 i++;
cristybb503372010-05-27 20:51:26 +00005245 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005246 ThrowMogrifyException(OptionError,"MissingArgument",option);
5247 break;
5248 }
5249 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5250 }
5251 case 'q':
5252 {
5253 if (LocaleCompare("quality",option+1) == 0)
5254 {
5255 if (*option == '+')
5256 break;
5257 i++;
cristybb503372010-05-27 20:51:26 +00005258 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005259 ThrowMogrifyException(OptionError,"MissingArgument",option);
5260 if (IsGeometry(argv[i]) == MagickFalse)
5261 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5262 break;
5263 }
5264 if (LocaleCompare("quantize",option+1) == 0)
5265 {
cristybb503372010-05-27 20:51:26 +00005266 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005267 colorspace;
5268
5269 if (*option == '+')
5270 break;
5271 i++;
cristybb503372010-05-27 20:51:26 +00005272 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005273 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005274 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005275 argv[i]);
5276 if (colorspace < 0)
5277 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5278 argv[i]);
5279 break;
5280 }
5281 if (LocaleCompare("quiet",option+1) == 0)
5282 break;
5283 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5284 }
5285 case 'r':
5286 {
5287 if (LocaleCompare("radial-blur",option+1) == 0)
5288 {
5289 i++;
cristybb503372010-05-27 20:51:26 +00005290 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005291 ThrowMogrifyException(OptionError,"MissingArgument",option);
5292 if (IsGeometry(argv[i]) == MagickFalse)
5293 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5294 break;
5295 }
5296 if (LocaleCompare("raise",option+1) == 0)
5297 {
5298 i++;
cristybb503372010-05-27 20:51:26 +00005299 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005300 ThrowMogrifyException(OptionError,"MissingArgument",option);
5301 if (IsGeometry(argv[i]) == MagickFalse)
5302 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5303 break;
5304 }
5305 if (LocaleCompare("random-threshold",option+1) == 0)
5306 {
5307 if (*option == '+')
5308 break;
5309 i++;
cristybb503372010-05-27 20:51:26 +00005310 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005311 ThrowMogrifyException(OptionError,"MissingArgument",option);
5312 if (IsGeometry(argv[i]) == MagickFalse)
5313 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5314 break;
5315 }
cristye6365592010-04-02 17:31:23 +00005316 if (LocaleCompare("recolor",option+1) == 0)
5317 {
5318 if (*option == '+')
5319 break;
5320 i++;
cristybb503372010-05-27 20:51:26 +00005321 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005322 ThrowMogrifyException(OptionError,"MissingArgument",option);
5323 if (IsGeometry(argv[i]) == MagickFalse)
5324 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5325 break;
5326 }
cristy3ed852e2009-09-05 21:47:34 +00005327 if (LocaleCompare("red-primary",option+1) == 0)
5328 {
5329 if (*option == '+')
5330 break;
5331 i++;
cristybb503372010-05-27 20:51:26 +00005332 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005333 ThrowMogrifyException(OptionError,"MissingArgument",option);
5334 if (IsGeometry(argv[i]) == MagickFalse)
5335 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5336 }
cristy9f2083a2010-04-22 19:48:05 +00005337 if (LocaleCompare("regard-warnings",option+1) == 0)
5338 break;
cristy3ed852e2009-09-05 21:47:34 +00005339 if (LocaleCompare("region",option+1) == 0)
5340 {
5341 if (*option == '+')
5342 break;
5343 i++;
cristybb503372010-05-27 20:51:26 +00005344 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005345 ThrowMogrifyException(OptionError,"MissingArgument",option);
5346 if (IsGeometry(argv[i]) == MagickFalse)
5347 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5348 break;
5349 }
cristyf0c78232010-03-15 12:53:40 +00005350 if (LocaleCompare("remap",option+1) == 0)
5351 {
5352 if (*option == '+')
5353 break;
5354 i++;
cristybb503372010-05-27 20:51:26 +00005355 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005356 ThrowMogrifyException(OptionError,"MissingArgument",option);
5357 break;
5358 }
cristy3ed852e2009-09-05 21:47:34 +00005359 if (LocaleCompare("render",option+1) == 0)
5360 break;
5361 if (LocaleCompare("repage",option+1) == 0)
5362 {
5363 if (*option == '+')
5364 break;
5365 i++;
cristybb503372010-05-27 20:51:26 +00005366 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005367 ThrowMogrifyException(OptionError,"MissingArgument",option);
5368 if (IsGeometry(argv[i]) == MagickFalse)
5369 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5370 break;
5371 }
5372 if (LocaleCompare("resample",option+1) == 0)
5373 {
5374 if (*option == '+')
5375 break;
5376 i++;
cristybb503372010-05-27 20:51:26 +00005377 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005378 ThrowMogrifyException(OptionError,"MissingArgument",option);
5379 if (IsGeometry(argv[i]) == MagickFalse)
5380 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5381 break;
5382 }
5383 if (LocaleCompare("resize",option+1) == 0)
5384 {
5385 if (*option == '+')
5386 break;
5387 i++;
cristybb503372010-05-27 20:51:26 +00005388 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005389 ThrowMogrifyException(OptionError,"MissingArgument",option);
5390 if (IsGeometry(argv[i]) == MagickFalse)
5391 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5392 break;
5393 }
cristyebbcfea2011-02-25 02:43:54 +00005394 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5395 {
5396 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5397 break;
5398 }
cristy3ed852e2009-09-05 21:47:34 +00005399 if (LocaleCompare("reverse",option+1) == 0)
5400 break;
5401 if (LocaleCompare("roll",option+1) == 0)
5402 {
5403 if (*option == '+')
5404 break;
5405 i++;
cristybb503372010-05-27 20:51:26 +00005406 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005407 ThrowMogrifyException(OptionError,"MissingArgument",option);
5408 if (IsGeometry(argv[i]) == MagickFalse)
5409 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5410 break;
5411 }
5412 if (LocaleCompare("rotate",option+1) == 0)
5413 {
5414 i++;
cristybb503372010-05-27 20:51:26 +00005415 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005416 ThrowMogrifyException(OptionError,"MissingArgument",option);
5417 if (IsGeometry(argv[i]) == MagickFalse)
5418 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5419 break;
5420 }
5421 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5422 }
5423 case 's':
5424 {
5425 if (LocaleCompare("sample",option+1) == 0)
5426 {
5427 if (*option == '+')
5428 break;
5429 i++;
cristybb503372010-05-27 20:51:26 +00005430 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005431 ThrowMogrifyException(OptionError,"MissingArgument",option);
5432 if (IsGeometry(argv[i]) == MagickFalse)
5433 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5434 break;
5435 }
5436 if (LocaleCompare("sampling-factor",option+1) == 0)
5437 {
5438 if (*option == '+')
5439 break;
5440 i++;
cristybb503372010-05-27 20:51:26 +00005441 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005442 ThrowMogrifyException(OptionError,"MissingArgument",option);
5443 if (IsGeometry(argv[i]) == MagickFalse)
5444 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5445 break;
5446 }
5447 if (LocaleCompare("scale",option+1) == 0)
5448 {
5449 if (*option == '+')
5450 break;
5451 i++;
cristybb503372010-05-27 20:51:26 +00005452 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005453 ThrowMogrifyException(OptionError,"MissingArgument",option);
5454 if (IsGeometry(argv[i]) == MagickFalse)
5455 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5456 break;
5457 }
5458 if (LocaleCompare("scene",option+1) == 0)
5459 {
5460 if (*option == '+')
5461 break;
5462 i++;
cristybb503372010-05-27 20:51:26 +00005463 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005464 ThrowMogrifyException(OptionError,"MissingArgument",option);
5465 if (IsGeometry(argv[i]) == MagickFalse)
5466 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5467 break;
5468 }
5469 if (LocaleCompare("seed",option+1) == 0)
5470 {
5471 if (*option == '+')
5472 break;
5473 i++;
cristybb503372010-05-27 20:51:26 +00005474 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005475 ThrowMogrifyException(OptionError,"MissingArgument",option);
5476 if (IsGeometry(argv[i]) == MagickFalse)
5477 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5478 break;
5479 }
5480 if (LocaleCompare("segment",option+1) == 0)
5481 {
5482 if (*option == '+')
5483 break;
5484 i++;
cristybb503372010-05-27 20:51:26 +00005485 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005486 ThrowMogrifyException(OptionError,"MissingArgument",option);
5487 if (IsGeometry(argv[i]) == MagickFalse)
5488 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5489 break;
5490 }
5491 if (LocaleCompare("selective-blur",option+1) == 0)
5492 {
5493 i++;
cristybb503372010-05-27 20:51:26 +00005494 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005495 ThrowMogrifyException(OptionError,"MissingArgument",option);
5496 if (IsGeometry(argv[i]) == MagickFalse)
5497 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5498 break;
5499 }
5500 if (LocaleCompare("separate",option+1) == 0)
5501 break;
5502 if (LocaleCompare("sepia-tone",option+1) == 0)
5503 {
5504 if (*option == '+')
5505 break;
5506 i++;
cristybb503372010-05-27 20:51:26 +00005507 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005508 ThrowMogrifyException(OptionError,"MissingArgument",option);
5509 if (IsGeometry(argv[i]) == MagickFalse)
5510 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5511 break;
5512 }
5513 if (LocaleCompare("set",option+1) == 0)
5514 {
5515 i++;
cristybb503372010-05-27 20:51:26 +00005516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005517 ThrowMogrifyException(OptionError,"MissingArgument",option);
5518 if (*option == '+')
5519 break;
5520 i++;
cristybb503372010-05-27 20:51:26 +00005521 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005522 ThrowMogrifyException(OptionError,"MissingArgument",option);
5523 break;
5524 }
5525 if (LocaleCompare("shade",option+1) == 0)
5526 {
5527 i++;
cristybb503372010-05-27 20:51:26 +00005528 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005529 ThrowMogrifyException(OptionError,"MissingArgument",option);
5530 if (IsGeometry(argv[i]) == MagickFalse)
5531 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5532 break;
5533 }
5534 if (LocaleCompare("shadow",option+1) == 0)
5535 {
5536 if (*option == '+')
5537 break;
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 (IsGeometry(argv[i]) == MagickFalse)
5542 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5543 break;
5544 }
5545 if (LocaleCompare("sharpen",option+1) == 0)
5546 {
5547 i++;
cristybb503372010-05-27 20:51:26 +00005548 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005549 ThrowMogrifyException(OptionError,"MissingArgument",option);
5550 if (IsGeometry(argv[i]) == MagickFalse)
5551 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5552 break;
5553 }
5554 if (LocaleCompare("shave",option+1) == 0)
5555 {
5556 if (*option == '+')
5557 break;
5558 i++;
cristybb503372010-05-27 20:51:26 +00005559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005560 ThrowMogrifyException(OptionError,"MissingArgument",option);
5561 if (IsGeometry(argv[i]) == MagickFalse)
5562 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5563 break;
5564 }
5565 if (LocaleCompare("shear",option+1) == 0)
5566 {
5567 i++;
cristybb503372010-05-27 20:51:26 +00005568 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005569 ThrowMogrifyException(OptionError,"MissingArgument",option);
5570 if (IsGeometry(argv[i]) == MagickFalse)
5571 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5572 break;
5573 }
5574 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5575 {
5576 i++;
cristybb503372010-05-27 20:51:26 +00005577 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005578 ThrowMogrifyException(OptionError,"MissingArgument",option);
5579 if (IsGeometry(argv[i]) == MagickFalse)
5580 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5581 break;
5582 }
5583 if (LocaleCompare("size",option+1) == 0)
5584 {
5585 if (*option == '+')
5586 break;
5587 i++;
cristybb503372010-05-27 20:51:26 +00005588 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005589 ThrowMogrifyException(OptionError,"MissingArgument",option);
5590 if (IsGeometry(argv[i]) == MagickFalse)
5591 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5592 break;
5593 }
5594 if (LocaleCompare("sketch",option+1) == 0)
5595 {
5596 if (*option == '+')
5597 break;
5598 i++;
cristybb503372010-05-27 20:51:26 +00005599 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005600 ThrowMogrifyException(OptionError,"MissingArgument",option);
5601 if (IsGeometry(argv[i]) == MagickFalse)
5602 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5603 break;
5604 }
cristy4285d782011-02-09 20:12:28 +00005605 if (LocaleCompare("smush",option+1) == 0)
5606 {
cristy4285d782011-02-09 20:12:28 +00005607 i++;
5608 if (i == (ssize_t) argc)
5609 ThrowMogrifyException(OptionError,"MissingArgument",option);
5610 if (IsGeometry(argv[i]) == MagickFalse)
5611 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005612 i++;
5613 break;
5614 }
cristy3ed852e2009-09-05 21:47:34 +00005615 if (LocaleCompare("solarize",option+1) == 0)
5616 {
5617 if (*option == '+')
5618 break;
5619 i++;
cristybb503372010-05-27 20:51:26 +00005620 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005621 ThrowMogrifyException(OptionError,"MissingArgument",option);
5622 if (IsGeometry(argv[i]) == MagickFalse)
5623 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5624 break;
5625 }
5626 if (LocaleCompare("sparse-color",option+1) == 0)
5627 {
cristybb503372010-05-27 20:51:26 +00005628 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005629 op;
5630
5631 i++;
cristybb503372010-05-27 20:51:26 +00005632 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005633 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005634 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005635 if (op < 0)
5636 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5637 argv[i]);
5638 i++;
cristybb503372010-05-27 20:51:26 +00005639 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005640 ThrowMogrifyException(OptionError,"MissingArgument",option);
5641 break;
5642 }
5643 if (LocaleCompare("spread",option+1) == 0)
5644 {
5645 if (*option == '+')
5646 break;
5647 i++;
cristybb503372010-05-27 20:51:26 +00005648 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005649 ThrowMogrifyException(OptionError,"MissingArgument",option);
5650 if (IsGeometry(argv[i]) == MagickFalse)
5651 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5652 break;
5653 }
cristy0834d642011-03-18 18:26:08 +00005654 if (LocaleCompare("statistic",option+1) == 0)
5655 {
5656 ssize_t
5657 op;
5658
5659 if (*option == '+')
5660 break;
5661 i++;
5662 if (i == (ssize_t) argc)
5663 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005664 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005665 if (op < 0)
5666 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5667 argv[i]);
5668 i++;
5669 if (i == (ssize_t) (argc-1))
5670 ThrowMogrifyException(OptionError,"MissingArgument",option);
5671 if (IsGeometry(argv[i]) == MagickFalse)
5672 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5673 break;
5674 }
cristy3ed852e2009-09-05 21:47:34 +00005675 if (LocaleCompare("stretch",option+1) == 0)
5676 {
cristybb503372010-05-27 20:51:26 +00005677 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005678 stretch;
5679
5680 if (*option == '+')
5681 break;
5682 i++;
cristybb503372010-05-27 20:51:26 +00005683 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005684 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005685 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005686 if (stretch < 0)
5687 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5688 argv[i]);
5689 break;
5690 }
5691 if (LocaleCompare("strip",option+1) == 0)
5692 break;
5693 if (LocaleCompare("stroke",option+1) == 0)
5694 {
5695 if (*option == '+')
5696 break;
5697 i++;
cristybb503372010-05-27 20:51:26 +00005698 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005699 ThrowMogrifyException(OptionError,"MissingArgument",option);
5700 break;
5701 }
5702 if (LocaleCompare("strokewidth",option+1) == 0)
5703 {
5704 if (*option == '+')
5705 break;
5706 i++;
cristybb503372010-05-27 20:51:26 +00005707 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005708 ThrowMogrifyException(OptionError,"MissingArgument",option);
5709 if (IsGeometry(argv[i]) == MagickFalse)
5710 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5711 break;
5712 }
5713 if (LocaleCompare("style",option+1) == 0)
5714 {
cristybb503372010-05-27 20:51:26 +00005715 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005716 style;
5717
5718 if (*option == '+')
5719 break;
5720 i++;
cristybb503372010-05-27 20:51:26 +00005721 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005722 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005723 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005724 if (style < 0)
5725 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5726 argv[i]);
5727 break;
5728 }
cristyecb10ff2011-03-22 13:14:03 +00005729 if (LocaleCompare("swap",option+1) == 0)
5730 {
5731 if (*option == '+')
5732 break;
5733 i++;
5734 if (i == (ssize_t) (argc-1))
5735 ThrowMogrifyException(OptionError,"MissingArgument",option);
5736 if (IsGeometry(argv[i]) == MagickFalse)
5737 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5738 break;
5739 }
cristy3ed852e2009-09-05 21:47:34 +00005740 if (LocaleCompare("swirl",option+1) == 0)
5741 {
5742 if (*option == '+')
5743 break;
5744 i++;
cristybb503372010-05-27 20:51:26 +00005745 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005746 ThrowMogrifyException(OptionError,"MissingArgument",option);
5747 if (IsGeometry(argv[i]) == MagickFalse)
5748 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5749 break;
5750 }
cristyd9a29192010-10-16 16:49:53 +00005751 if (LocaleCompare("synchronize",option+1) == 0)
5752 break;
cristy3ed852e2009-09-05 21:47:34 +00005753 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5754 }
5755 case 't':
5756 {
5757 if (LocaleCompare("taint",option+1) == 0)
5758 break;
5759 if (LocaleCompare("texture",option+1) == 0)
5760 {
5761 if (*option == '+')
5762 break;
5763 i++;
cristybb503372010-05-27 20:51:26 +00005764 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005765 ThrowMogrifyException(OptionError,"MissingArgument",option);
5766 break;
5767 }
5768 if (LocaleCompare("tile",option+1) == 0)
5769 {
5770 if (*option == '+')
5771 break;
5772 i++;
cristybb503372010-05-27 20:51:26 +00005773 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005774 ThrowMogrifyException(OptionError,"MissingArgument",option);
5775 break;
5776 }
5777 if (LocaleCompare("tile-offset",option+1) == 0)
5778 {
5779 if (*option == '+')
5780 break;
5781 i++;
cristybb503372010-05-27 20:51:26 +00005782 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005783 ThrowMogrifyException(OptionError,"MissingArgument",option);
5784 if (IsGeometry(argv[i]) == MagickFalse)
5785 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5786 break;
5787 }
5788 if (LocaleCompare("tint",option+1) == 0)
5789 {
5790 if (*option == '+')
5791 break;
5792 i++;
cristybb503372010-05-27 20:51:26 +00005793 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005794 ThrowMogrifyException(OptionError,"MissingArgument",option);
5795 if (IsGeometry(argv[i]) == MagickFalse)
5796 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5797 break;
5798 }
5799 if (LocaleCompare("transform",option+1) == 0)
5800 break;
5801 if (LocaleCompare("transpose",option+1) == 0)
5802 break;
5803 if (LocaleCompare("transverse",option+1) == 0)
5804 break;
5805 if (LocaleCompare("threshold",option+1) == 0)
5806 {
5807 if (*option == '+')
5808 break;
5809 i++;
cristybb503372010-05-27 20:51:26 +00005810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005811 ThrowMogrifyException(OptionError,"MissingArgument",option);
5812 if (IsGeometry(argv[i]) == MagickFalse)
5813 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5814 break;
5815 }
5816 if (LocaleCompare("thumbnail",option+1) == 0)
5817 {
5818 if (*option == '+')
5819 break;
5820 i++;
cristybb503372010-05-27 20:51:26 +00005821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005822 ThrowMogrifyException(OptionError,"MissingArgument",option);
5823 if (IsGeometry(argv[i]) == MagickFalse)
5824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5825 break;
5826 }
5827 if (LocaleCompare("transparent",option+1) == 0)
5828 {
5829 i++;
cristybb503372010-05-27 20:51:26 +00005830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005831 ThrowMogrifyException(OptionError,"MissingArgument",option);
5832 break;
5833 }
5834 if (LocaleCompare("transparent-color",option+1) == 0)
5835 {
5836 if (*option == '+')
5837 break;
5838 i++;
cristybb503372010-05-27 20:51:26 +00005839 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005840 ThrowMogrifyException(OptionError,"MissingArgument",option);
5841 break;
5842 }
5843 if (LocaleCompare("treedepth",option+1) == 0)
5844 {
5845 if (*option == '+')
5846 break;
5847 i++;
cristybb503372010-05-27 20:51:26 +00005848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005849 ThrowMogrifyException(OptionError,"MissingArgument",option);
5850 if (IsGeometry(argv[i]) == MagickFalse)
5851 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5852 break;
5853 }
5854 if (LocaleCompare("trim",option+1) == 0)
5855 break;
5856 if (LocaleCompare("type",option+1) == 0)
5857 {
cristybb503372010-05-27 20:51:26 +00005858 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005859 type;
5860
5861 if (*option == '+')
5862 break;
5863 i++;
cristybb503372010-05-27 20:51:26 +00005864 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005865 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005866 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005867 if (type < 0)
5868 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5869 argv[i]);
5870 break;
5871 }
5872 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5873 }
5874 case 'u':
5875 {
5876 if (LocaleCompare("undercolor",option+1) == 0)
5877 {
5878 if (*option == '+')
5879 break;
5880 i++;
cristybb503372010-05-27 20:51:26 +00005881 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005882 ThrowMogrifyException(OptionError,"MissingArgument",option);
5883 break;
5884 }
5885 if (LocaleCompare("unique-colors",option+1) == 0)
5886 break;
5887 if (LocaleCompare("units",option+1) == 0)
5888 {
cristybb503372010-05-27 20:51:26 +00005889 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005890 units;
5891
5892 if (*option == '+')
5893 break;
5894 i++;
cristybb503372010-05-27 20:51:26 +00005895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005896 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005897 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005898 argv[i]);
5899 if (units < 0)
5900 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5901 argv[i]);
5902 break;
5903 }
5904 if (LocaleCompare("unsharp",option+1) == 0)
5905 {
5906 i++;
cristybb503372010-05-27 20:51:26 +00005907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005908 ThrowMogrifyException(OptionError,"MissingArgument",option);
5909 if (IsGeometry(argv[i]) == MagickFalse)
5910 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5911 break;
5912 }
5913 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5914 }
5915 case 'v':
5916 {
5917 if (LocaleCompare("verbose",option+1) == 0)
5918 {
5919 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5920 break;
5921 }
5922 if ((LocaleCompare("version",option+1) == 0) ||
5923 (LocaleCompare("-version",option+1) == 0))
5924 {
cristyb51dff52011-05-19 16:55:47 +00005925 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005926 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005927 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5928 GetMagickCopyright());
5929 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5930 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005931 break;
5932 }
5933 if (LocaleCompare("view",option+1) == 0)
5934 {
5935 if (*option == '+')
5936 break;
5937 i++;
cristybb503372010-05-27 20:51:26 +00005938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005939 ThrowMogrifyException(OptionError,"MissingArgument",option);
5940 break;
5941 }
5942 if (LocaleCompare("vignette",option+1) == 0)
5943 {
5944 if (*option == '+')
5945 break;
5946 i++;
cristybb503372010-05-27 20:51:26 +00005947 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005948 ThrowMogrifyException(OptionError,"MissingArgument",option);
5949 if (IsGeometry(argv[i]) == MagickFalse)
5950 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5951 break;
5952 }
5953 if (LocaleCompare("virtual-pixel",option+1) == 0)
5954 {
cristybb503372010-05-27 20:51:26 +00005955 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005956 method;
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);
cristy042ee782011-04-22 18:48:30 +00005963 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005964 argv[i]);
5965 if (method < 0)
5966 ThrowMogrifyException(OptionError,
5967 "UnrecognizedVirtualPixelMethod",argv[i]);
5968 break;
5969 }
5970 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5971 }
5972 case 'w':
5973 {
5974 if (LocaleCompare("wave",option+1) == 0)
5975 {
5976 i++;
cristybb503372010-05-27 20:51:26 +00005977 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005978 ThrowMogrifyException(OptionError,"MissingArgument",option);
5979 if (IsGeometry(argv[i]) == MagickFalse)
5980 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5981 break;
5982 }
5983 if (LocaleCompare("weight",option+1) == 0)
5984 {
5985 if (*option == '+')
5986 break;
5987 i++;
cristybb503372010-05-27 20:51:26 +00005988 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005989 ThrowMogrifyException(OptionError,"MissingArgument",option);
5990 break;
5991 }
5992 if (LocaleCompare("white-point",option+1) == 0)
5993 {
5994 if (*option == '+')
5995 break;
5996 i++;
cristybb503372010-05-27 20:51:26 +00005997 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005998 ThrowMogrifyException(OptionError,"MissingArgument",option);
5999 if (IsGeometry(argv[i]) == MagickFalse)
6000 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6001 break;
6002 }
6003 if (LocaleCompare("white-threshold",option+1) == 0)
6004 {
6005 if (*option == '+')
6006 break;
6007 i++;
cristybb503372010-05-27 20:51:26 +00006008 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006009 ThrowMogrifyException(OptionError,"MissingArgument",option);
6010 if (IsGeometry(argv[i]) == MagickFalse)
6011 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6012 break;
6013 }
6014 if (LocaleCompare("write",option+1) == 0)
6015 {
6016 i++;
cristybb503372010-05-27 20:51:26 +00006017 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006018 ThrowMogrifyException(OptionError,"MissingArgument",option);
6019 break;
6020 }
6021 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6022 }
6023 case '?':
6024 break;
6025 default:
6026 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6027 }
cristy042ee782011-04-22 18:48:30 +00006028 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6029 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006030 if (fire != MagickFalse)
6031 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6032 }
6033 if (k != 0)
6034 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006035 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006036 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6037 DestroyMogrify();
6038 return(status != 0 ? MagickTrue : MagickFalse);
6039}
6040
6041/*
6042%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6043% %
6044% %
6045% %
6046+ M o g r i f y I m a g e I n f o %
6047% %
6048% %
6049% %
6050%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6051%
6052% MogrifyImageInfo() applies image processing settings to the image as
6053% prescribed by command line options.
6054%
6055% The format of the MogrifyImageInfo method is:
6056%
6057% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6058% const char **argv,ExceptionInfo *exception)
6059%
6060% A description of each parameter follows:
6061%
6062% o image_info: the image info..
6063%
6064% o argc: Specifies a pointer to an integer describing the number of
6065% elements in the argument vector.
6066%
6067% o argv: Specifies a pointer to a text array containing the command line
6068% arguments.
6069%
6070% o exception: return any errors or warnings in this structure.
6071%
6072*/
6073WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6074 const int argc,const char **argv,ExceptionInfo *exception)
6075{
6076 const char
6077 *option;
6078
6079 GeometryInfo
6080 geometry_info;
6081
cristybb503372010-05-27 20:51:26 +00006082 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006083 count;
6084
cristybb503372010-05-27 20:51:26 +00006085 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006086 i;
6087
6088 /*
6089 Initialize method variables.
6090 */
6091 assert(image_info != (ImageInfo *) NULL);
6092 assert(image_info->signature == MagickSignature);
6093 if (image_info->debug != MagickFalse)
6094 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6095 image_info->filename);
6096 if (argc < 0)
6097 return(MagickTrue);
6098 /*
6099 Set the image settings.
6100 */
cristybb503372010-05-27 20:51:26 +00006101 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006102 {
6103 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006104 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006105 continue;
cristy042ee782011-04-22 18:48:30 +00006106 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006107 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006108 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006109 break;
6110 switch (*(option+1))
6111 {
6112 case 'a':
6113 {
6114 if (LocaleCompare("adjoin",option+1) == 0)
6115 {
6116 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6117 break;
6118 }
6119 if (LocaleCompare("antialias",option+1) == 0)
6120 {
6121 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6122 break;
6123 }
6124 if (LocaleCompare("attenuate",option+1) == 0)
6125 {
6126 if (*option == '+')
6127 {
6128 (void) DeleteImageOption(image_info,option+1);
6129 break;
6130 }
6131 (void) SetImageOption(image_info,option+1,argv[i+1]);
6132 break;
6133 }
6134 if (LocaleCompare("authenticate",option+1) == 0)
6135 {
6136 if (*option == '+')
6137 (void) CloneString(&image_info->authenticate,(char *) NULL);
6138 else
6139 (void) CloneString(&image_info->authenticate,argv[i+1]);
6140 break;
6141 }
6142 break;
6143 }
6144 case 'b':
6145 {
6146 if (LocaleCompare("background",option+1) == 0)
6147 {
6148 if (*option == '+')
6149 {
6150 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006151 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006152 &image_info->background_color,exception);
6153 break;
6154 }
6155 (void) SetImageOption(image_info,option+1,argv[i+1]);
6156 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6157 exception);
6158 break;
6159 }
6160 if (LocaleCompare("bias",option+1) == 0)
6161 {
6162 if (*option == '+')
6163 {
6164 (void) SetImageOption(image_info,option+1,"0.0");
6165 break;
6166 }
6167 (void) SetImageOption(image_info,option+1,argv[i+1]);
6168 break;
6169 }
6170 if (LocaleCompare("black-point-compensation",option+1) == 0)
6171 {
6172 if (*option == '+')
6173 {
6174 (void) SetImageOption(image_info,option+1,"false");
6175 break;
6176 }
6177 (void) SetImageOption(image_info,option+1,"true");
6178 break;
6179 }
6180 if (LocaleCompare("blue-primary",option+1) == 0)
6181 {
6182 if (*option == '+')
6183 {
6184 (void) SetImageOption(image_info,option+1,"0.0");
6185 break;
6186 }
6187 (void) SetImageOption(image_info,option+1,argv[i+1]);
6188 break;
6189 }
6190 if (LocaleCompare("bordercolor",option+1) == 0)
6191 {
6192 if (*option == '+')
6193 {
6194 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006195 (void) QueryColorDatabase(MogrifyBorderColor,
6196 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006197 break;
6198 }
6199 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6200 exception);
6201 (void) SetImageOption(image_info,option+1,argv[i+1]);
6202 break;
6203 }
6204 if (LocaleCompare("box",option+1) == 0)
6205 {
6206 if (*option == '+')
6207 {
6208 (void) SetImageOption(image_info,"undercolor","none");
6209 break;
6210 }
6211 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6212 break;
6213 }
6214 break;
6215 }
6216 case 'c':
6217 {
6218 if (LocaleCompare("cache",option+1) == 0)
6219 {
6220 MagickSizeType
6221 limit;
6222
6223 limit=MagickResourceInfinity;
6224 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006225 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006226 (void) SetMagickResourceLimit(MemoryResource,limit);
6227 (void) SetMagickResourceLimit(MapResource,2*limit);
6228 break;
6229 }
6230 if (LocaleCompare("caption",option+1) == 0)
6231 {
6232 if (*option == '+')
6233 {
6234 (void) DeleteImageOption(image_info,option+1);
6235 break;
6236 }
6237 (void) SetImageOption(image_info,option+1,argv[i+1]);
6238 break;
6239 }
6240 if (LocaleCompare("channel",option+1) == 0)
6241 {
6242 if (*option == '+')
6243 {
6244 image_info->channel=DefaultChannels;
6245 break;
6246 }
6247 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6248 break;
6249 }
6250 if (LocaleCompare("colors",option+1) == 0)
6251 {
cristye27293e2009-12-18 02:53:20 +00006252 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006253 break;
6254 }
6255 if (LocaleCompare("colorspace",option+1) == 0)
6256 {
6257 if (*option == '+')
6258 {
6259 image_info->colorspace=UndefinedColorspace;
6260 (void) SetImageOption(image_info,option+1,"undefined");
6261 break;
6262 }
cristy042ee782011-04-22 18:48:30 +00006263 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006264 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6265 (void) SetImageOption(image_info,option+1,argv[i+1]);
6266 break;
6267 }
cristy3ed852e2009-09-05 21:47:34 +00006268 if (LocaleCompare("comment",option+1) == 0)
6269 {
6270 if (*option == '+')
6271 {
6272 (void) DeleteImageOption(image_info,option+1);
6273 break;
6274 }
6275 (void) SetImageOption(image_info,option+1,argv[i+1]);
6276 break;
6277 }
6278 if (LocaleCompare("compose",option+1) == 0)
6279 {
6280 if (*option == '+')
6281 {
6282 (void) SetImageOption(image_info,option+1,"undefined");
6283 break;
6284 }
6285 (void) SetImageOption(image_info,option+1,argv[i+1]);
6286 break;
6287 }
6288 if (LocaleCompare("compress",option+1) == 0)
6289 {
6290 if (*option == '+')
6291 {
6292 image_info->compression=UndefinedCompression;
6293 (void) SetImageOption(image_info,option+1,"undefined");
6294 break;
6295 }
cristy042ee782011-04-22 18:48:30 +00006296 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006297 MagickCompressOptions,MagickFalse,argv[i+1]);
6298 (void) SetImageOption(image_info,option+1,argv[i+1]);
6299 break;
6300 }
6301 break;
6302 }
6303 case 'd':
6304 {
6305 if (LocaleCompare("debug",option+1) == 0)
6306 {
6307 if (*option == '+')
6308 (void) SetLogEventMask("none");
6309 else
6310 (void) SetLogEventMask(argv[i+1]);
6311 image_info->debug=IsEventLogging();
6312 break;
6313 }
6314 if (LocaleCompare("define",option+1) == 0)
6315 {
6316 if (*option == '+')
6317 {
6318 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6319 (void) DeleteImageRegistry(argv[i+1]+9);
6320 else
6321 (void) DeleteImageOption(image_info,argv[i+1]);
6322 break;
6323 }
6324 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6325 {
6326 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6327 exception);
6328 break;
6329 }
6330 (void) DefineImageOption(image_info,argv[i+1]);
6331 break;
6332 }
6333 if (LocaleCompare("delay",option+1) == 0)
6334 {
6335 if (*option == '+')
6336 {
6337 (void) SetImageOption(image_info,option+1,"0");
6338 break;
6339 }
6340 (void) SetImageOption(image_info,option+1,argv[i+1]);
6341 break;
6342 }
6343 if (LocaleCompare("density",option+1) == 0)
6344 {
6345 /*
6346 Set image density.
6347 */
6348 if (*option == '+')
6349 {
6350 if (image_info->density != (char *) NULL)
6351 image_info->density=DestroyString(image_info->density);
6352 (void) SetImageOption(image_info,option+1,"72");
6353 break;
6354 }
6355 (void) CloneString(&image_info->density,argv[i+1]);
6356 (void) SetImageOption(image_info,option+1,argv[i+1]);
6357 break;
6358 }
6359 if (LocaleCompare("depth",option+1) == 0)
6360 {
6361 if (*option == '+')
6362 {
6363 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6364 break;
6365 }
cristye27293e2009-12-18 02:53:20 +00006366 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006367 break;
6368 }
cristyc9b12952010-03-28 01:12:28 +00006369 if (LocaleCompare("direction",option+1) == 0)
6370 {
6371 if (*option == '+')
6372 {
6373 (void) SetImageOption(image_info,option+1,"undefined");
6374 break;
6375 }
6376 (void) SetImageOption(image_info,option+1,argv[i+1]);
6377 break;
6378 }
cristy3ed852e2009-09-05 21:47:34 +00006379 if (LocaleCompare("display",option+1) == 0)
6380 {
6381 if (*option == '+')
6382 {
6383 if (image_info->server_name != (char *) NULL)
6384 image_info->server_name=DestroyString(
6385 image_info->server_name);
6386 break;
6387 }
6388 (void) CloneString(&image_info->server_name,argv[i+1]);
6389 break;
6390 }
6391 if (LocaleCompare("dispose",option+1) == 0)
6392 {
6393 if (*option == '+')
6394 {
6395 (void) SetImageOption(image_info,option+1,"undefined");
6396 break;
6397 }
6398 (void) SetImageOption(image_info,option+1,argv[i+1]);
6399 break;
6400 }
6401 if (LocaleCompare("dither",option+1) == 0)
6402 {
6403 if (*option == '+')
6404 {
6405 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006406 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006407 break;
6408 }
6409 (void) SetImageOption(image_info,option+1,argv[i+1]);
6410 image_info->dither=MagickTrue;
6411 break;
6412 }
6413 break;
6414 }
6415 case 'e':
6416 {
6417 if (LocaleCompare("encoding",option+1) == 0)
6418 {
6419 if (*option == '+')
6420 {
6421 (void) SetImageOption(image_info,option+1,"undefined");
6422 break;
6423 }
6424 (void) SetImageOption(image_info,option+1,argv[i+1]);
6425 break;
6426 }
6427 if (LocaleCompare("endian",option+1) == 0)
6428 {
6429 if (*option == '+')
6430 {
6431 image_info->endian=UndefinedEndian;
6432 (void) SetImageOption(image_info,option+1,"undefined");
6433 break;
6434 }
cristy042ee782011-04-22 18:48:30 +00006435 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006436 MagickEndianOptions,MagickFalse,argv[i+1]);
6437 (void) SetImageOption(image_info,option+1,argv[i+1]);
6438 break;
6439 }
6440 if (LocaleCompare("extract",option+1) == 0)
6441 {
6442 /*
6443 Set image extract geometry.
6444 */
6445 if (*option == '+')
6446 {
6447 if (image_info->extract != (char *) NULL)
6448 image_info->extract=DestroyString(image_info->extract);
6449 break;
6450 }
6451 (void) CloneString(&image_info->extract,argv[i+1]);
6452 break;
6453 }
6454 break;
6455 }
6456 case 'f':
6457 {
6458 if (LocaleCompare("fill",option+1) == 0)
6459 {
6460 if (*option == '+')
6461 {
6462 (void) SetImageOption(image_info,option+1,"none");
6463 break;
6464 }
6465 (void) SetImageOption(image_info,option+1,argv[i+1]);
6466 break;
6467 }
6468 if (LocaleCompare("filter",option+1) == 0)
6469 {
6470 if (*option == '+')
6471 {
6472 (void) SetImageOption(image_info,option+1,"undefined");
6473 break;
6474 }
6475 (void) SetImageOption(image_info,option+1,argv[i+1]);
6476 break;
6477 }
6478 if (LocaleCompare("font",option+1) == 0)
6479 {
6480 if (*option == '+')
6481 {
6482 if (image_info->font != (char *) NULL)
6483 image_info->font=DestroyString(image_info->font);
6484 break;
6485 }
6486 (void) CloneString(&image_info->font,argv[i+1]);
6487 break;
6488 }
6489 if (LocaleCompare("format",option+1) == 0)
6490 {
6491 register const char
6492 *q;
6493
6494 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006495 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006496 image_info->ping=MagickFalse;
6497 (void) SetImageOption(image_info,option+1,argv[i+1]);
6498 break;
6499 }
6500 if (LocaleCompare("fuzz",option+1) == 0)
6501 {
6502 if (*option == '+')
6503 {
6504 image_info->fuzz=0.0;
6505 (void) SetImageOption(image_info,option+1,"0");
6506 break;
6507 }
cristyf2f27272009-12-17 14:48:46 +00006508 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006509 1.0);
6510 (void) SetImageOption(image_info,option+1,argv[i+1]);
6511 break;
6512 }
6513 break;
6514 }
6515 case 'g':
6516 {
6517 if (LocaleCompare("gravity",option+1) == 0)
6518 {
6519 if (*option == '+')
6520 {
6521 (void) SetImageOption(image_info,option+1,"undefined");
6522 break;
6523 }
6524 (void) SetImageOption(image_info,option+1,argv[i+1]);
6525 break;
6526 }
6527 if (LocaleCompare("green-primary",option+1) == 0)
6528 {
6529 if (*option == '+')
6530 {
6531 (void) SetImageOption(image_info,option+1,"0.0");
6532 break;
6533 }
6534 (void) SetImageOption(image_info,option+1,argv[i+1]);
6535 break;
6536 }
6537 break;
6538 }
6539 case 'i':
6540 {
6541 if (LocaleCompare("intent",option+1) == 0)
6542 {
6543 if (*option == '+')
6544 {
6545 (void) SetImageOption(image_info,option+1,"undefined");
6546 break;
6547 }
6548 (void) SetImageOption(image_info,option+1,argv[i+1]);
6549 break;
6550 }
6551 if (LocaleCompare("interlace",option+1) == 0)
6552 {
6553 if (*option == '+')
6554 {
6555 image_info->interlace=UndefinedInterlace;
6556 (void) SetImageOption(image_info,option+1,"undefined");
6557 break;
6558 }
cristy042ee782011-04-22 18:48:30 +00006559 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006560 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6561 (void) SetImageOption(image_info,option+1,argv[i+1]);
6562 break;
6563 }
cristyb32b90a2009-09-07 21:45:48 +00006564 if (LocaleCompare("interline-spacing",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 }
cristy3ed852e2009-09-05 21:47:34 +00006574 if (LocaleCompare("interpolate",option+1) == 0)
6575 {
6576 if (*option == '+')
6577 {
6578 (void) SetImageOption(image_info,option+1,"undefined");
6579 break;
6580 }
6581 (void) SetImageOption(image_info,option+1,argv[i+1]);
6582 break;
6583 }
6584 if (LocaleCompare("interword-spacing",option+1) == 0)
6585 {
6586 if (*option == '+')
6587 {
6588 (void) SetImageOption(image_info,option+1,"undefined");
6589 break;
6590 }
6591 (void) SetImageOption(image_info,option+1,argv[i+1]);
6592 break;
6593 }
6594 break;
6595 }
6596 case 'k':
6597 {
6598 if (LocaleCompare("kerning",option+1) == 0)
6599 {
6600 if (*option == '+')
6601 {
6602 (void) SetImageOption(image_info,option+1,"undefined");
6603 break;
6604 }
6605 (void) SetImageOption(image_info,option+1,argv[i+1]);
6606 break;
6607 }
6608 break;
6609 }
6610 case 'l':
6611 {
6612 if (LocaleCompare("label",option+1) == 0)
6613 {
6614 if (*option == '+')
6615 {
6616 (void) DeleteImageOption(image_info,option+1);
6617 break;
6618 }
6619 (void) SetImageOption(image_info,option+1,argv[i+1]);
6620 break;
6621 }
6622 if (LocaleCompare("limit",option+1) == 0)
6623 {
6624 MagickSizeType
6625 limit;
6626
6627 ResourceType
6628 type;
6629
6630 if (*option == '+')
6631 break;
cristy042ee782011-04-22 18:48:30 +00006632 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006633 MagickFalse,argv[i+1]);
6634 limit=MagickResourceInfinity;
6635 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006636 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006637 (void) SetMagickResourceLimit(type,limit);
6638 break;
6639 }
6640 if (LocaleCompare("list",option+1) == 0)
6641 {
cristybb503372010-05-27 20:51:26 +00006642 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006643 list;
6644
6645 /*
6646 Display configuration list.
6647 */
cristy042ee782011-04-22 18:48:30 +00006648 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006649 switch (list)
6650 {
6651 case MagickCoderOptions:
6652 {
6653 (void) ListCoderInfo((FILE *) NULL,exception);
6654 break;
6655 }
6656 case MagickColorOptions:
6657 {
6658 (void) ListColorInfo((FILE *) NULL,exception);
6659 break;
6660 }
6661 case MagickConfigureOptions:
6662 {
6663 (void) ListConfigureInfo((FILE *) NULL,exception);
6664 break;
6665 }
6666 case MagickDelegateOptions:
6667 {
6668 (void) ListDelegateInfo((FILE *) NULL,exception);
6669 break;
6670 }
6671 case MagickFontOptions:
6672 {
6673 (void) ListTypeInfo((FILE *) NULL,exception);
6674 break;
6675 }
6676 case MagickFormatOptions:
6677 {
6678 (void) ListMagickInfo((FILE *) NULL,exception);
6679 break;
6680 }
6681 case MagickLocaleOptions:
6682 {
6683 (void) ListLocaleInfo((FILE *) NULL,exception);
6684 break;
6685 }
6686 case MagickLogOptions:
6687 {
6688 (void) ListLogInfo((FILE *) NULL,exception);
6689 break;
6690 }
6691 case MagickMagicOptions:
6692 {
6693 (void) ListMagicInfo((FILE *) NULL,exception);
6694 break;
6695 }
6696 case MagickMimeOptions:
6697 {
6698 (void) ListMimeInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickModuleOptions:
6702 {
6703 (void) ListModuleInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickPolicyOptions:
6707 {
6708 (void) ListPolicyInfo((FILE *) NULL,exception);
6709 break;
6710 }
6711 case MagickResourceOptions:
6712 {
6713 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6714 break;
6715 }
6716 case MagickThresholdOptions:
6717 {
6718 (void) ListThresholdMaps((FILE *) NULL,exception);
6719 break;
6720 }
6721 default:
6722 {
cristy042ee782011-04-22 18:48:30 +00006723 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006724 exception);
6725 break;
6726 }
6727 }
cristyaeb2cbc2010-05-07 13:28:58 +00006728 break;
cristy3ed852e2009-09-05 21:47:34 +00006729 }
6730 if (LocaleCompare("log",option+1) == 0)
6731 {
6732 if (*option == '+')
6733 break;
6734 (void) SetLogFormat(argv[i+1]);
6735 break;
6736 }
6737 if (LocaleCompare("loop",option+1) == 0)
6738 {
6739 if (*option == '+')
6740 {
6741 (void) SetImageOption(image_info,option+1,"0");
6742 break;
6743 }
6744 (void) SetImageOption(image_info,option+1,argv[i+1]);
6745 break;
6746 }
6747 break;
6748 }
6749 case 'm':
6750 {
6751 if (LocaleCompare("matte",option+1) == 0)
6752 {
6753 if (*option == '+')
6754 {
6755 (void) SetImageOption(image_info,option+1,"false");
6756 break;
6757 }
6758 (void) SetImageOption(image_info,option+1,"true");
6759 break;
6760 }
6761 if (LocaleCompare("mattecolor",option+1) == 0)
6762 {
6763 if (*option == '+')
6764 {
6765 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006766 (void) QueryColorDatabase(MogrifyMatteColor,
6767 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006768 break;
6769 }
6770 (void) SetImageOption(image_info,option+1,argv[i+1]);
6771 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6772 exception);
6773 break;
6774 }
6775 if (LocaleCompare("monitor",option+1) == 0)
6776 {
6777 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6778 (void *) NULL);
6779 break;
6780 }
6781 if (LocaleCompare("monochrome",option+1) == 0)
6782 {
6783 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6784 break;
6785 }
6786 break;
6787 }
6788 case 'o':
6789 {
6790 if (LocaleCompare("orient",option+1) == 0)
6791 {
6792 if (*option == '+')
6793 {
6794 image_info->orientation=UndefinedOrientation;
6795 (void) SetImageOption(image_info,option+1,"undefined");
6796 break;
6797 }
cristy042ee782011-04-22 18:48:30 +00006798 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006799 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006800 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006801 break;
6802 }
6803 }
6804 case 'p':
6805 {
6806 if (LocaleCompare("page",option+1) == 0)
6807 {
6808 char
6809 *canonical_page,
6810 page[MaxTextExtent];
6811
6812 const char
6813 *image_option;
6814
6815 MagickStatusType
6816 flags;
6817
6818 RectangleInfo
6819 geometry;
6820
6821 if (*option == '+')
6822 {
6823 (void) DeleteImageOption(image_info,option+1);
6824 (void) CloneString(&image_info->page,(char *) NULL);
6825 break;
6826 }
6827 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6828 image_option=GetImageOption(image_info,"page");
6829 if (image_option != (const char *) NULL)
6830 flags=ParseAbsoluteGeometry(image_option,&geometry);
6831 canonical_page=GetPageGeometry(argv[i+1]);
6832 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6833 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006834 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006835 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006836 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006837 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006838 (unsigned long) geometry.width,(unsigned long) geometry.height,
6839 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006840 (void) SetImageOption(image_info,option+1,page);
6841 (void) CloneString(&image_info->page,page);
6842 break;
6843 }
6844 if (LocaleCompare("pen",option+1) == 0)
6845 {
6846 if (*option == '+')
6847 {
6848 (void) SetImageOption(image_info,option+1,"none");
6849 break;
6850 }
6851 (void) SetImageOption(image_info,option+1,argv[i+1]);
6852 break;
6853 }
6854 if (LocaleCompare("ping",option+1) == 0)
6855 {
6856 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6857 break;
6858 }
6859 if (LocaleCompare("pointsize",option+1) == 0)
6860 {
6861 if (*option == '+')
6862 geometry_info.rho=0.0;
6863 else
6864 (void) ParseGeometry(argv[i+1],&geometry_info);
6865 image_info->pointsize=geometry_info.rho;
6866 break;
6867 }
cristye7f51092010-01-17 00:39:37 +00006868 if (LocaleCompare("precision",option+1) == 0)
6869 {
cristybf2766a2010-01-17 03:33:23 +00006870 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006871 break;
6872 }
cristy3ed852e2009-09-05 21:47:34 +00006873 if (LocaleCompare("preview",option+1) == 0)
6874 {
6875 /*
6876 Preview image.
6877 */
6878 if (*option == '+')
6879 {
6880 image_info->preview_type=UndefinedPreview;
6881 break;
6882 }
cristy042ee782011-04-22 18:48:30 +00006883 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006884 MagickPreviewOptions,MagickFalse,argv[i+1]);
6885 break;
6886 }
6887 break;
6888 }
6889 case 'q':
6890 {
6891 if (LocaleCompare("quality",option+1) == 0)
6892 {
6893 /*
6894 Set image compression quality.
6895 */
6896 if (*option == '+')
6897 {
6898 image_info->quality=UndefinedCompressionQuality;
6899 (void) SetImageOption(image_info,option+1,"0");
6900 break;
6901 }
cristye27293e2009-12-18 02:53:20 +00006902 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006903 (void) SetImageOption(image_info,option+1,argv[i+1]);
6904 break;
6905 }
6906 if (LocaleCompare("quiet",option+1) == 0)
6907 {
6908 static WarningHandler
6909 warning_handler = (WarningHandler) NULL;
6910
6911 if (*option == '+')
6912 {
6913 /*
6914 Restore error or warning messages.
6915 */
6916 warning_handler=SetWarningHandler(warning_handler);
6917 break;
6918 }
6919 /*
6920 Suppress error or warning messages.
6921 */
6922 warning_handler=SetWarningHandler((WarningHandler) NULL);
6923 break;
6924 }
6925 break;
6926 }
6927 case 'r':
6928 {
6929 if (LocaleCompare("red-primary",option+1) == 0)
6930 {
6931 if (*option == '+')
6932 {
6933 (void) SetImageOption(image_info,option+1,"0.0");
6934 break;
6935 }
6936 (void) SetImageOption(image_info,option+1,argv[i+1]);
6937 break;
6938 }
6939 break;
6940 }
6941 case 's':
6942 {
6943 if (LocaleCompare("sampling-factor",option+1) == 0)
6944 {
6945 /*
6946 Set image sampling factor.
6947 */
6948 if (*option == '+')
6949 {
6950 if (image_info->sampling_factor != (char *) NULL)
6951 image_info->sampling_factor=DestroyString(
6952 image_info->sampling_factor);
6953 break;
6954 }
6955 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6956 break;
6957 }
6958 if (LocaleCompare("scene",option+1) == 0)
6959 {
6960 /*
6961 Set image scene.
6962 */
6963 if (*option == '+')
6964 {
6965 image_info->scene=0;
6966 (void) SetImageOption(image_info,option+1,"0");
6967 break;
6968 }
cristye27293e2009-12-18 02:53:20 +00006969 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006970 (void) SetImageOption(image_info,option+1,argv[i+1]);
6971 break;
6972 }
6973 if (LocaleCompare("seed",option+1) == 0)
6974 {
cristybb503372010-05-27 20:51:26 +00006975 size_t
cristy3ed852e2009-09-05 21:47:34 +00006976 seed;
6977
6978 if (*option == '+')
6979 {
cristybb503372010-05-27 20:51:26 +00006980 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006981 SeedPseudoRandomGenerator(seed);
6982 break;
6983 }
cristye27293e2009-12-18 02:53:20 +00006984 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006985 SeedPseudoRandomGenerator(seed);
6986 break;
6987 }
6988 if (LocaleCompare("size",option+1) == 0)
6989 {
6990 if (*option == '+')
6991 {
6992 if (image_info->size != (char *) NULL)
6993 image_info->size=DestroyString(image_info->size);
6994 break;
6995 }
6996 (void) CloneString(&image_info->size,argv[i+1]);
6997 break;
6998 }
6999 if (LocaleCompare("stroke",option+1) == 0)
7000 {
7001 if (*option == '+')
7002 {
7003 (void) SetImageOption(image_info,option+1,"none");
7004 break;
7005 }
7006 (void) SetImageOption(image_info,option+1,argv[i+1]);
7007 break;
7008 }
7009 if (LocaleCompare("strokewidth",option+1) == 0)
7010 {
7011 if (*option == '+')
7012 {
7013 (void) SetImageOption(image_info,option+1,"0");
7014 break;
7015 }
7016 (void) SetImageOption(image_info,option+1,argv[i+1]);
7017 break;
7018 }
cristyd9a29192010-10-16 16:49:53 +00007019 if (LocaleCompare("synchronize",option+1) == 0)
7020 {
7021 if (*option == '+')
7022 {
7023 image_info->synchronize=MagickFalse;
7024 break;
7025 }
7026 image_info->synchronize=MagickTrue;
7027 break;
7028 }
cristy3ed852e2009-09-05 21:47:34 +00007029 break;
7030 }
7031 case 't':
7032 {
7033 if (LocaleCompare("taint",option+1) == 0)
7034 {
7035 if (*option == '+')
7036 {
7037 (void) SetImageOption(image_info,option+1,"false");
7038 break;
7039 }
7040 (void) SetImageOption(image_info,option+1,"true");
7041 break;
7042 }
7043 if (LocaleCompare("texture",option+1) == 0)
7044 {
7045 if (*option == '+')
7046 {
7047 if (image_info->texture != (char *) NULL)
7048 image_info->texture=DestroyString(image_info->texture);
7049 break;
7050 }
7051 (void) CloneString(&image_info->texture,argv[i+1]);
7052 break;
7053 }
7054 if (LocaleCompare("tile-offset",option+1) == 0)
7055 {
7056 if (*option == '+')
7057 {
7058 (void) SetImageOption(image_info,option+1,"0");
7059 break;
7060 }
7061 (void) SetImageOption(image_info,option+1,argv[i+1]);
7062 break;
7063 }
7064 if (LocaleCompare("transparent-color",option+1) == 0)
7065 {
7066 if (*option == '+')
7067 {
7068 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7069 (void) SetImageOption(image_info,option+1,"none");
7070 break;
7071 }
7072 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7073 exception);
7074 (void) SetImageOption(image_info,option+1,argv[i+1]);
7075 break;
7076 }
7077 if (LocaleCompare("type",option+1) == 0)
7078 {
7079 if (*option == '+')
7080 {
cristy5f1c1ff2010-12-23 21:38:06 +00007081 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007082 (void) SetImageOption(image_info,option+1,"undefined");
7083 break;
7084 }
cristy042ee782011-04-22 18:48:30 +00007085 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007086 MagickFalse,argv[i+1]);
7087 (void) SetImageOption(image_info,option+1,argv[i+1]);
7088 break;
7089 }
7090 break;
7091 }
7092 case 'u':
7093 {
7094 if (LocaleCompare("undercolor",option+1) == 0)
7095 {
7096 if (*option == '+')
7097 {
7098 (void) DeleteImageOption(image_info,option+1);
7099 break;
7100 }
7101 (void) SetImageOption(image_info,option+1,argv[i+1]);
7102 break;
7103 }
7104 if (LocaleCompare("units",option+1) == 0)
7105 {
7106 if (*option == '+')
7107 {
7108 image_info->units=UndefinedResolution;
7109 (void) SetImageOption(image_info,option+1,"undefined");
7110 break;
7111 }
cristy042ee782011-04-22 18:48:30 +00007112 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007113 MagickResolutionOptions,MagickFalse,argv[i+1]);
7114 (void) SetImageOption(image_info,option+1,argv[i+1]);
7115 break;
7116 }
7117 break;
7118 }
7119 case 'v':
7120 {
7121 if (LocaleCompare("verbose",option+1) == 0)
7122 {
7123 if (*option == '+')
7124 {
7125 image_info->verbose=MagickFalse;
7126 break;
7127 }
7128 image_info->verbose=MagickTrue;
7129 image_info->ping=MagickFalse;
7130 break;
7131 }
7132 if (LocaleCompare("view",option+1) == 0)
7133 {
7134 if (*option == '+')
7135 {
7136 if (image_info->view != (char *) NULL)
7137 image_info->view=DestroyString(image_info->view);
7138 break;
7139 }
7140 (void) CloneString(&image_info->view,argv[i+1]);
7141 break;
7142 }
7143 if (LocaleCompare("virtual-pixel",option+1) == 0)
7144 {
7145 if (*option == '+')
7146 {
7147 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7148 (void) SetImageOption(image_info,option+1,"undefined");
7149 break;
7150 }
7151 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007152 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007153 argv[i+1]);
7154 (void) SetImageOption(image_info,option+1,argv[i+1]);
7155 break;
7156 }
7157 break;
7158 }
7159 case 'w':
7160 {
7161 if (LocaleCompare("white-point",option+1) == 0)
7162 {
7163 if (*option == '+')
7164 {
7165 (void) SetImageOption(image_info,option+1,"0.0");
7166 break;
7167 }
7168 (void) SetImageOption(image_info,option+1,argv[i+1]);
7169 break;
7170 }
7171 break;
7172 }
7173 default:
7174 break;
7175 }
7176 i+=count;
7177 }
7178 return(MagickTrue);
7179}
7180
7181/*
7182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7183% %
7184% %
7185% %
7186+ M o g r i f y I m a g e L i s t %
7187% %
7188% %
7189% %
7190%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7191%
7192% MogrifyImageList() applies any command line options that might affect the
7193% entire image list (e.g. -append, -coalesce, etc.).
7194%
7195% The format of the MogrifyImage method is:
7196%
7197% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7198% const char **argv,Image **images,ExceptionInfo *exception)
7199%
7200% A description of each parameter follows:
7201%
7202% o image_info: the image info..
7203%
7204% o argc: Specifies a pointer to an integer describing the number of
7205% elements in the argument vector.
7206%
7207% o argv: Specifies a pointer to a text array containing the command line
7208% arguments.
7209%
anthonye9c27192011-03-27 08:07:06 +00007210% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007211%
7212% o exception: return any errors or warnings in this structure.
7213%
7214*/
7215WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7216 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7217{
cristy3ed852e2009-09-05 21:47:34 +00007218 const char
7219 *option;
7220
cristy6b3da3a2010-06-20 02:21:46 +00007221 ImageInfo
7222 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007223
7224 MagickStatusType
7225 status;
7226
7227 QuantizeInfo
7228 *quantize_info;
7229
cristybb503372010-05-27 20:51:26 +00007230 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007231 i;
7232
cristy6b3da3a2010-06-20 02:21:46 +00007233 ssize_t
7234 count,
7235 index;
7236
cristy3ed852e2009-09-05 21:47:34 +00007237 /*
7238 Apply options to the image list.
7239 */
7240 assert(image_info != (ImageInfo *) NULL);
7241 assert(image_info->signature == MagickSignature);
7242 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007243 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007244 assert((*images)->signature == MagickSignature);
7245 if ((*images)->debug != MagickFalse)
7246 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7247 (*images)->filename);
7248 if ((argc <= 0) || (*argv == (char *) NULL))
7249 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007250 mogrify_info=CloneImageInfo(image_info);
7251 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007252 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007253 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007254 {
cristy74fe8f12009-10-03 19:09:01 +00007255 if (*images == (Image *) NULL)
7256 break;
cristy3ed852e2009-09-05 21:47:34 +00007257 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007258 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007259 continue;
cristy042ee782011-04-22 18:48:30 +00007260 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007261 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007262 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007263 break;
cristy6b3da3a2010-06-20 02:21:46 +00007264 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007265 switch (*(option+1))
7266 {
7267 case 'a':
7268 {
7269 if (LocaleCompare("affinity",option+1) == 0)
7270 {
cristy6b3da3a2010-06-20 02:21:46 +00007271 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007272 if (*option == '+')
7273 {
cristy018f07f2011-09-04 21:15:19 +00007274 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7275 exception);
cristy3ed852e2009-09-05 21:47:34 +00007276 break;
7277 }
7278 i++;
7279 break;
7280 }
7281 if (LocaleCompare("append",option+1) == 0)
7282 {
7283 Image
7284 *append_image;
7285
cristy6b3da3a2010-06-20 02:21:46 +00007286 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007287 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7288 MagickFalse,exception);
7289 if (append_image == (Image *) NULL)
7290 {
7291 status=MagickFalse;
7292 break;
7293 }
7294 *images=DestroyImageList(*images);
7295 *images=append_image;
7296 break;
7297 }
7298 if (LocaleCompare("average",option+1) == 0)
7299 {
7300 Image
7301 *average_image;
7302
cristyd18ae7c2010-03-07 17:39:52 +00007303 /*
7304 Average an image sequence (deprecated).
7305 */
cristy6b3da3a2010-06-20 02:21:46 +00007306 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007307 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7308 exception);
cristy3ed852e2009-09-05 21:47:34 +00007309 if (average_image == (Image *) NULL)
7310 {
7311 status=MagickFalse;
7312 break;
7313 }
7314 *images=DestroyImageList(*images);
7315 *images=average_image;
7316 break;
7317 }
7318 break;
7319 }
7320 case 'c':
7321 {
7322 if (LocaleCompare("channel",option+1) == 0)
7323 {
cristyf4ad9df2011-07-08 16:49:03 +00007324 ChannelType
7325 channel;
7326
cristy3ed852e2009-09-05 21:47:34 +00007327 if (*option == '+')
7328 {
7329 channel=DefaultChannels;
7330 break;
7331 }
7332 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007333 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007334 break;
7335 }
7336 if (LocaleCompare("clut",option+1) == 0)
7337 {
7338 Image
7339 *clut_image,
7340 *image;
7341
cristy6b3da3a2010-06-20 02:21:46 +00007342 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007343 image=RemoveFirstImageFromList(images);
7344 clut_image=RemoveFirstImageFromList(images);
7345 if (clut_image == (Image *) NULL)
7346 {
7347 status=MagickFalse;
7348 break;
7349 }
cristy5c4e2582011-09-11 19:21:03 +00007350 (void) ClutImage(image,clut_image,image->interpolate,exception);
cristy3ed852e2009-09-05 21:47:34 +00007351 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007352 *images=DestroyImageList(*images);
7353 *images=image;
7354 break;
7355 }
7356 if (LocaleCompare("coalesce",option+1) == 0)
7357 {
7358 Image
7359 *coalesce_image;
7360
cristy6b3da3a2010-06-20 02:21:46 +00007361 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007362 coalesce_image=CoalesceImages(*images,exception);
7363 if (coalesce_image == (Image *) NULL)
7364 {
7365 status=MagickFalse;
7366 break;
7367 }
7368 *images=DestroyImageList(*images);
7369 *images=coalesce_image;
7370 break;
7371 }
7372 if (LocaleCompare("combine",option+1) == 0)
7373 {
7374 Image
7375 *combine_image;
7376
cristy6b3da3a2010-06-20 02:21:46 +00007377 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007378 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007379 if (combine_image == (Image *) NULL)
7380 {
7381 status=MagickFalse;
7382 break;
7383 }
7384 *images=DestroyImageList(*images);
7385 *images=combine_image;
7386 break;
7387 }
7388 if (LocaleCompare("composite",option+1) == 0)
7389 {
7390 Image
7391 *mask_image,
7392 *composite_image,
7393 *image;
7394
7395 RectangleInfo
7396 geometry;
7397
cristy6b3da3a2010-06-20 02:21:46 +00007398 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007399 image=RemoveFirstImageFromList(images);
7400 composite_image=RemoveFirstImageFromList(images);
7401 if (composite_image == (Image *) NULL)
7402 {
7403 status=MagickFalse;
7404 break;
7405 }
7406 (void) TransformImage(&composite_image,(char *) NULL,
7407 composite_image->geometry);
7408 SetGeometry(composite_image,&geometry);
7409 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7410 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7411 &geometry);
7412 mask_image=RemoveFirstImageFromList(images);
7413 if (mask_image != (Image *) NULL)
7414 {
7415 if ((image->compose == DisplaceCompositeOp) ||
7416 (image->compose == DistortCompositeOp))
7417 {
7418 /*
7419 Merge Y displacement into X displacement image.
7420 */
7421 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7422 mask_image,0,0);
7423 mask_image=DestroyImage(mask_image);
7424 }
7425 else
7426 {
7427 /*
7428 Set a blending mask for the composition.
7429 */
anthonya129f702011-04-14 01:08:48 +00007430 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007431 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007432 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007433 }
7434 }
cristyf4ad9df2011-07-08 16:49:03 +00007435 (void) CompositeImage(image,image->compose,composite_image,
7436 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007437 if (mask_image != (Image *) NULL)
7438 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007439 composite_image=DestroyImage(composite_image);
7440 InheritException(exception,&image->exception);
7441 *images=DestroyImageList(*images);
7442 *images=image;
7443 break;
7444 }
anthony9f4f0342011-03-28 11:47:22 +00007445#if 0
7446This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007447 if (LocaleCompare("crop",option+1) == 0)
7448 {
7449 MagickStatusType
7450 flags;
7451
7452 RectangleInfo
7453 geometry;
7454
anthonye9c27192011-03-27 08:07:06 +00007455 /*
anthony9f4f0342011-03-28 11:47:22 +00007456 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007457 */
cristy6b3da3a2010-06-20 02:21:46 +00007458 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007459 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7460 if (((geometry.width == 0) && (geometry.height == 0)) ||
7461 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7462 break;
7463 (void) TransformImages(images,argv[i+1],(char *) NULL);
7464 InheritException(exception,&(*images)->exception);
7465 break;
7466 }
anthony9f4f0342011-03-28 11:47:22 +00007467#endif
cristy3ed852e2009-09-05 21:47:34 +00007468 break;
7469 }
7470 case 'd':
7471 {
7472 if (LocaleCompare("deconstruct",option+1) == 0)
7473 {
7474 Image
7475 *deconstruct_image;
7476
cristy6b3da3a2010-06-20 02:21:46 +00007477 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007478 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007479 exception);
cristy3ed852e2009-09-05 21:47:34 +00007480 if (deconstruct_image == (Image *) NULL)
7481 {
7482 status=MagickFalse;
7483 break;
7484 }
7485 *images=DestroyImageList(*images);
7486 *images=deconstruct_image;
7487 break;
7488 }
7489 if (LocaleCompare("delete",option+1) == 0)
7490 {
7491 if (*option == '+')
7492 DeleteImages(images,"-1",exception);
7493 else
7494 DeleteImages(images,argv[i+1],exception);
7495 break;
7496 }
7497 if (LocaleCompare("dither",option+1) == 0)
7498 {
7499 if (*option == '+')
7500 {
7501 quantize_info->dither=MagickFalse;
7502 break;
7503 }
7504 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007505 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007506 MagickDitherOptions,MagickFalse,argv[i+1]);
7507 break;
7508 }
cristyecb10ff2011-03-22 13:14:03 +00007509 if (LocaleCompare("duplicate",option+1) == 0)
7510 {
cristy72988482011-03-29 16:34:38 +00007511 Image
7512 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007513
anthony2b6bcae2011-03-23 13:05:34 +00007514 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007515 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7516 else
7517 {
7518 const char
7519 *p;
7520
anthony2b6bcae2011-03-23 13:05:34 +00007521 size_t
7522 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007523
anthony2b6bcae2011-03-23 13:05:34 +00007524 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007525 p=strchr(argv[i+1],',');
7526 if (p == (const char *) NULL)
7527 duplicate_images=DuplicateImages(*images,number_duplicates,
7528 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007529 else
cristy72988482011-03-29 16:34:38 +00007530 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7531 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007532 }
7533 AppendImageToList(images, duplicate_images);
7534 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007535 break;
7536 }
cristy3ed852e2009-09-05 21:47:34 +00007537 break;
7538 }
cristyd18ae7c2010-03-07 17:39:52 +00007539 case 'e':
7540 {
7541 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7542 {
7543 Image
7544 *evaluate_image;
7545
7546 MagickEvaluateOperator
7547 op;
7548
cristy6b3da3a2010-06-20 02:21:46 +00007549 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007550 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007551 MagickFalse,argv[i+1]);
7552 evaluate_image=EvaluateImages(*images,op,exception);
7553 if (evaluate_image == (Image *) NULL)
7554 {
7555 status=MagickFalse;
7556 break;
7557 }
7558 *images=DestroyImageList(*images);
7559 *images=evaluate_image;
7560 break;
7561 }
7562 break;
7563 }
cristy3ed852e2009-09-05 21:47:34 +00007564 case 'f':
7565 {
cristyf0a247f2009-10-04 00:20:03 +00007566 if (LocaleCompare("fft",option+1) == 0)
7567 {
7568 Image
7569 *fourier_image;
7570
7571 /*
7572 Implements the discrete Fourier transform (DFT).
7573 */
cristy6b3da3a2010-06-20 02:21:46 +00007574 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007575 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7576 MagickTrue : MagickFalse,exception);
7577 if (fourier_image == (Image *) NULL)
7578 break;
7579 *images=DestroyImage(*images);
7580 *images=fourier_image;
7581 break;
7582 }
cristy3ed852e2009-09-05 21:47:34 +00007583 if (LocaleCompare("flatten",option+1) == 0)
7584 {
7585 Image
7586 *flatten_image;
7587
cristy6b3da3a2010-06-20 02:21:46 +00007588 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007589 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7590 if (flatten_image == (Image *) NULL)
7591 break;
7592 *images=DestroyImageList(*images);
7593 *images=flatten_image;
7594 break;
7595 }
7596 if (LocaleCompare("fx",option+1) == 0)
7597 {
7598 Image
7599 *fx_image;
7600
cristy6b3da3a2010-06-20 02:21:46 +00007601 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007602 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007603 if (fx_image == (Image *) NULL)
7604 {
7605 status=MagickFalse;
7606 break;
7607 }
7608 *images=DestroyImageList(*images);
7609 *images=fx_image;
7610 break;
7611 }
7612 break;
7613 }
7614 case 'h':
7615 {
7616 if (LocaleCompare("hald-clut",option+1) == 0)
7617 {
7618 Image
7619 *hald_image,
7620 *image;
7621
cristy6b3da3a2010-06-20 02:21:46 +00007622 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007623 image=RemoveFirstImageFromList(images);
7624 hald_image=RemoveFirstImageFromList(images);
7625 if (hald_image == (Image *) NULL)
7626 {
7627 status=MagickFalse;
7628 break;
7629 }
cristy7c0a0a42011-08-23 17:57:25 +00007630 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007631 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007632 if (*images != (Image *) NULL)
7633 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007634 *images=image;
7635 break;
7636 }
7637 break;
7638 }
7639 case 'i':
7640 {
7641 if (LocaleCompare("ift",option+1) == 0)
7642 {
7643 Image
cristy8587f882009-11-13 20:28:49 +00007644 *fourier_image,
7645 *magnitude_image,
7646 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007647
7648 /*
7649 Implements the inverse fourier discrete Fourier transform (DFT).
7650 */
cristy6b3da3a2010-06-20 02:21:46 +00007651 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007652 magnitude_image=RemoveFirstImageFromList(images);
7653 phase_image=RemoveFirstImageFromList(images);
7654 if (phase_image == (Image *) NULL)
7655 {
7656 status=MagickFalse;
7657 break;
7658 }
7659 fourier_image=InverseFourierTransformImage(magnitude_image,
7660 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007661 if (fourier_image == (Image *) NULL)
7662 break;
cristy0aff6ea2009-11-14 01:40:53 +00007663 if (*images != (Image *) NULL)
7664 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007665 *images=fourier_image;
7666 break;
7667 }
7668 if (LocaleCompare("insert",option+1) == 0)
7669 {
7670 Image
7671 *p,
7672 *q;
7673
7674 index=0;
7675 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007676 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007677 p=RemoveLastImageFromList(images);
7678 if (p == (Image *) NULL)
7679 {
7680 (void) ThrowMagickException(exception,GetMagickModule(),
7681 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7682 status=MagickFalse;
7683 break;
7684 }
7685 q=p;
7686 if (index == 0)
7687 PrependImageToList(images,q);
7688 else
cristybb503372010-05-27 20:51:26 +00007689 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007690 AppendImageToList(images,q);
7691 else
7692 {
7693 q=GetImageFromList(*images,index-1);
7694 if (q == (Image *) NULL)
7695 {
7696 (void) ThrowMagickException(exception,GetMagickModule(),
7697 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7698 status=MagickFalse;
7699 break;
7700 }
7701 InsertImageInList(&q,p);
7702 }
7703 *images=GetFirstImageInList(q);
7704 break;
7705 }
7706 break;
7707 }
7708 case 'l':
7709 {
7710 if (LocaleCompare("layers",option+1) == 0)
7711 {
7712 Image
7713 *layers;
7714
7715 ImageLayerMethod
7716 method;
7717
cristy6b3da3a2010-06-20 02:21:46 +00007718 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007719 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007720 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007721 MagickFalse,argv[i+1]);
7722 switch (method)
7723 {
7724 case CoalesceLayer:
7725 {
7726 layers=CoalesceImages(*images,exception);
7727 break;
7728 }
7729 case CompareAnyLayer:
7730 case CompareClearLayer:
7731 case CompareOverlayLayer:
7732 default:
7733 {
cristy8a9106f2011-07-05 14:39:26 +00007734 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007735 break;
7736 }
7737 case MergeLayer:
7738 case FlattenLayer:
7739 case MosaicLayer:
7740 case TrimBoundsLayer:
7741 {
7742 layers=MergeImageLayers(*images,method,exception);
7743 break;
7744 }
7745 case DisposeLayer:
7746 {
7747 layers=DisposeImages(*images,exception);
7748 break;
7749 }
7750 case OptimizeImageLayer:
7751 {
7752 layers=OptimizeImageLayers(*images,exception);
7753 break;
7754 }
7755 case OptimizePlusLayer:
7756 {
7757 layers=OptimizePlusImageLayers(*images,exception);
7758 break;
7759 }
7760 case OptimizeTransLayer:
7761 {
7762 OptimizeImageTransparency(*images,exception);
7763 break;
7764 }
7765 case RemoveDupsLayer:
7766 {
7767 RemoveDuplicateLayers(images,exception);
7768 break;
7769 }
7770 case RemoveZeroLayer:
7771 {
7772 RemoveZeroDelayLayers(images,exception);
7773 break;
7774 }
7775 case OptimizeLayer:
7776 {
7777 /*
7778 General Purpose, GIF Animation Optimizer.
7779 */
7780 layers=CoalesceImages(*images,exception);
7781 if (layers == (Image *) NULL)
7782 {
7783 status=MagickFalse;
7784 break;
7785 }
cristy3ed852e2009-09-05 21:47:34 +00007786 *images=DestroyImageList(*images);
7787 *images=layers;
7788 layers=OptimizeImageLayers(*images,exception);
7789 if (layers == (Image *) NULL)
7790 {
7791 status=MagickFalse;
7792 break;
7793 }
cristy3ed852e2009-09-05 21:47:34 +00007794 *images=DestroyImageList(*images);
7795 *images=layers;
7796 layers=(Image *) NULL;
7797 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007798 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7799 exception);
cristy3ed852e2009-09-05 21:47:34 +00007800 break;
7801 }
7802 case CompositeLayer:
7803 {
7804 CompositeOperator
7805 compose;
7806
7807 Image
7808 *source;
7809
7810 RectangleInfo
7811 geometry;
7812
7813 /*
7814 Split image sequence at the first 'NULL:' image.
7815 */
7816 source=(*images);
7817 while (source != (Image *) NULL)
7818 {
7819 source=GetNextImageInList(source);
7820 if ((source != (Image *) NULL) &&
7821 (LocaleCompare(source->magick,"NULL") == 0))
7822 break;
7823 }
7824 if (source != (Image *) NULL)
7825 {
7826 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7827 (GetNextImageInList(source) == (Image *) NULL))
7828 source=(Image *) NULL;
7829 else
7830 {
7831 /*
7832 Separate the two lists, junk the null: image.
7833 */
7834 source=SplitImageList(source->previous);
7835 DeleteImageFromList(&source);
7836 }
7837 }
7838 if (source == (Image *) NULL)
7839 {
7840 (void) ThrowMagickException(exception,GetMagickModule(),
7841 OptionError,"MissingNullSeparator","layers Composite");
7842 status=MagickFalse;
7843 break;
7844 }
7845 /*
7846 Adjust offset with gravity and virtual canvas.
7847 */
7848 SetGeometry(*images,&geometry);
7849 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7850 geometry.width=source->page.width != 0 ?
7851 source->page.width : source->columns;
7852 geometry.height=source->page.height != 0 ?
7853 source->page.height : source->rows;
7854 GravityAdjustGeometry((*images)->page.width != 0 ?
7855 (*images)->page.width : (*images)->columns,
7856 (*images)->page.height != 0 ? (*images)->page.height :
7857 (*images)->rows,(*images)->gravity,&geometry);
7858 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007859 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007860 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007861 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007862 MagickComposeOptions,MagickFalse,option);
7863 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7864 exception);
7865 source=DestroyImageList(source);
7866 break;
7867 }
7868 }
7869 if (layers == (Image *) NULL)
7870 break;
7871 InheritException(exception,&layers->exception);
7872 *images=DestroyImageList(*images);
7873 *images=layers;
7874 break;
7875 }
7876 break;
7877 }
7878 case 'm':
7879 {
7880 if (LocaleCompare("map",option+1) == 0)
7881 {
cristy6b3da3a2010-06-20 02:21:46 +00007882 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007883 if (*option == '+')
7884 {
cristy018f07f2011-09-04 21:15:19 +00007885 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7886 exception);
cristy3ed852e2009-09-05 21:47:34 +00007887 break;
7888 }
7889 i++;
7890 break;
7891 }
cristyf40785b2010-03-06 02:27:27 +00007892 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007893 {
7894 Image
cristyf40785b2010-03-06 02:27:27 +00007895 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007896
cristyd18ae7c2010-03-07 17:39:52 +00007897 /*
7898 Maximum image sequence (deprecated).
7899 */
cristy6b3da3a2010-06-20 02:21:46 +00007900 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007901 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007902 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007903 {
7904 status=MagickFalse;
7905 break;
7906 }
7907 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007908 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007909 break;
7910 }
cristyf40785b2010-03-06 02:27:27 +00007911 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007912 {
7913 Image
cristyf40785b2010-03-06 02:27:27 +00007914 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007915
cristyd18ae7c2010-03-07 17:39:52 +00007916 /*
7917 Minimum image sequence (deprecated).
7918 */
cristy6b3da3a2010-06-20 02:21:46 +00007919 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007920 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007921 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007922 {
7923 status=MagickFalse;
7924 break;
7925 }
7926 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007927 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007928 break;
7929 }
cristy3ed852e2009-09-05 21:47:34 +00007930 if (LocaleCompare("morph",option+1) == 0)
7931 {
7932 Image
7933 *morph_image;
7934
cristy6b3da3a2010-06-20 02:21:46 +00007935 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007936 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007937 exception);
7938 if (morph_image == (Image *) NULL)
7939 {
7940 status=MagickFalse;
7941 break;
7942 }
7943 *images=DestroyImageList(*images);
7944 *images=morph_image;
7945 break;
7946 }
7947 if (LocaleCompare("mosaic",option+1) == 0)
7948 {
7949 Image
7950 *mosaic_image;
7951
cristy6b3da3a2010-06-20 02:21:46 +00007952 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007953 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7954 if (mosaic_image == (Image *) NULL)
7955 {
7956 status=MagickFalse;
7957 break;
7958 }
7959 *images=DestroyImageList(*images);
7960 *images=mosaic_image;
7961 break;
7962 }
7963 break;
7964 }
7965 case 'p':
7966 {
7967 if (LocaleCompare("print",option+1) == 0)
7968 {
7969 char
7970 *string;
7971
cristy6b3da3a2010-06-20 02:21:46 +00007972 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007973 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7974 exception);
cristy3ed852e2009-09-05 21:47:34 +00007975 if (string == (char *) NULL)
7976 break;
cristyb51dff52011-05-19 16:55:47 +00007977 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007978 string=DestroyString(string);
7979 }
7980 if (LocaleCompare("process",option+1) == 0)
7981 {
7982 char
7983 **arguments;
7984
7985 int
7986 j,
7987 number_arguments;
7988
cristy6b3da3a2010-06-20 02:21:46 +00007989 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007990 arguments=StringToArgv(argv[i+1],&number_arguments);
7991 if (arguments == (char **) NULL)
7992 break;
7993 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7994 {
7995 char
7996 breaker,
7997 quote,
7998 *token;
7999
8000 const char
8001 *arguments;
8002
8003 int
8004 next,
8005 status;
8006
8007 size_t
8008 length;
8009
8010 TokenInfo
8011 *token_info;
8012
8013 /*
8014 Support old style syntax, filter="-option arg".
8015 */
8016 length=strlen(argv[i+1]);
8017 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008018 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008019 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8020 sizeof(*token));
8021 if (token == (char *) NULL)
8022 break;
8023 next=0;
8024 arguments=argv[i+1];
8025 token_info=AcquireTokenInfo();
8026 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8027 "\"",'\0',&breaker,&next,&quote);
8028 token_info=DestroyTokenInfo(token_info);
8029 if (status == 0)
8030 {
8031 const char
8032 *argv;
8033
8034 argv=(&(arguments[next]));
8035 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8036 exception);
8037 }
8038 token=DestroyString(token);
8039 break;
8040 }
cristy91c0da22010-05-02 01:44:07 +00008041 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008042 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8043 number_arguments-2,(const char **) arguments+2,exception);
8044 for (j=0; j < number_arguments; j++)
8045 arguments[j]=DestroyString(arguments[j]);
8046 arguments=(char **) RelinquishMagickMemory(arguments);
8047 break;
8048 }
8049 break;
8050 }
8051 case 'r':
8052 {
8053 if (LocaleCompare("reverse",option+1) == 0)
8054 {
8055 ReverseImageList(images);
8056 InheritException(exception,&(*images)->exception);
8057 break;
8058 }
8059 break;
8060 }
8061 case 's':
8062 {
cristy4285d782011-02-09 20:12:28 +00008063 if (LocaleCompare("smush",option+1) == 0)
8064 {
8065 Image
8066 *smush_image;
8067
8068 ssize_t
8069 offset;
8070
8071 (void) SyncImagesSettings(mogrify_info,*images);
8072 offset=(ssize_t) StringToLong(argv[i+1]);
8073 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8074 MagickFalse,offset,exception);
8075 if (smush_image == (Image *) NULL)
8076 {
8077 status=MagickFalse;
8078 break;
8079 }
8080 *images=DestroyImageList(*images);
8081 *images=smush_image;
8082 break;
8083 }
cristy3ed852e2009-09-05 21:47:34 +00008084 if (LocaleCompare("swap",option+1) == 0)
8085 {
8086 Image
8087 *p,
8088 *q,
8089 *swap;
8090
cristybb503372010-05-27 20:51:26 +00008091 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008092 swap_index;
8093
8094 index=(-1);
8095 swap_index=(-2);
8096 if (*option != '+')
8097 {
8098 GeometryInfo
8099 geometry_info;
8100
8101 MagickStatusType
8102 flags;
8103
8104 swap_index=(-1);
8105 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008106 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008107 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008108 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008109 }
8110 p=GetImageFromList(*images,index);
8111 q=GetImageFromList(*images,swap_index);
8112 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8113 {
8114 (void) ThrowMagickException(exception,GetMagickModule(),
8115 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8116 status=MagickFalse;
8117 break;
8118 }
8119 if (p == q)
8120 break;
8121 swap=CloneImage(p,0,0,MagickTrue,exception);
8122 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8123 ReplaceImageInList(&q,swap);
8124 *images=GetFirstImageInList(q);
8125 break;
8126 }
8127 break;
8128 }
8129 case 'w':
8130 {
8131 if (LocaleCompare("write",option+1) == 0)
8132 {
cristy071dd7b2010-04-09 13:04:54 +00008133 char
cristy06609ee2010-03-17 20:21:27 +00008134 key[MaxTextExtent];
8135
cristy3ed852e2009-09-05 21:47:34 +00008136 Image
8137 *write_images;
8138
8139 ImageInfo
8140 *write_info;
8141
cristy6b3da3a2010-06-20 02:21:46 +00008142 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008143 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008144 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008145 write_images=(*images);
8146 if (*option == '+')
8147 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008148 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008149 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8150 write_info=DestroyImageInfo(write_info);
8151 if (*option == '+')
8152 write_images=DestroyImageList(write_images);
8153 break;
8154 }
8155 break;
8156 }
8157 default:
8158 break;
8159 }
8160 i+=count;
8161 }
8162 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008163 mogrify_info=DestroyImageInfo(mogrify_info);
8164 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008165 return(status != 0 ? MagickTrue : MagickFalse);
8166}
8167
8168/*
8169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8170% %
8171% %
8172% %
8173+ M o g r i f y I m a g e s %
8174% %
8175% %
8176% %
8177%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8178%
8179% MogrifyImages() applies image processing options to a sequence of images as
8180% prescribed by command line options.
8181%
8182% The format of the MogrifyImage method is:
8183%
8184% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8185% const MagickBooleanType post,const int argc,const char **argv,
8186% Image **images,Exceptioninfo *exception)
8187%
8188% A description of each parameter follows:
8189%
8190% o image_info: the image info..
8191%
8192% o post: If true, post process image list operators otherwise pre-process.
8193%
8194% o argc: Specifies a pointer to an integer describing the number of
8195% elements in the argument vector.
8196%
8197% o argv: Specifies a pointer to a text array containing the command line
8198% arguments.
8199%
anthonye9c27192011-03-27 08:07:06 +00008200% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008201%
8202% o exception: return any errors or warnings in this structure.
8203%
8204*/
8205WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8206 const MagickBooleanType post,const int argc,const char **argv,
8207 Image **images,ExceptionInfo *exception)
8208{
8209#define MogrifyImageTag "Mogrify/Image"
8210
anthonye9c27192011-03-27 08:07:06 +00008211 MagickStatusType
8212 status;
cristy3ed852e2009-09-05 21:47:34 +00008213
cristy0e9f9c12010-02-11 03:00:47 +00008214 MagickBooleanType
8215 proceed;
8216
anthonye9c27192011-03-27 08:07:06 +00008217 size_t
8218 n;
cristy3ed852e2009-09-05 21:47:34 +00008219
cristybb503372010-05-27 20:51:26 +00008220 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008221 i;
8222
cristy3ed852e2009-09-05 21:47:34 +00008223 assert(image_info != (ImageInfo *) NULL);
8224 assert(image_info->signature == MagickSignature);
8225 if (images == (Image **) NULL)
8226 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008227 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008228 assert((*images)->signature == MagickSignature);
8229 if ((*images)->debug != MagickFalse)
8230 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8231 (*images)->filename);
8232 if ((argc <= 0) || (*argv == (char *) NULL))
8233 return(MagickTrue);
8234 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8235 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008236 status=0;
anthonye9c27192011-03-27 08:07:06 +00008237
anthonyce2716b2011-04-22 09:51:34 +00008238#if 0
cristy1e604812011-05-19 18:07:50 +00008239 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8240 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008241#endif
8242
anthonye9c27192011-03-27 08:07:06 +00008243 /*
8244 Pre-process multi-image sequence operators
8245 */
cristy3ed852e2009-09-05 21:47:34 +00008246 if (post == MagickFalse)
8247 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008248 /*
8249 For each image, process simple single image operators
8250 */
8251 i=0;
8252 n=GetImageListLength(*images);
8253 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008254 {
anthonyce2716b2011-04-22 09:51:34 +00008255#if 0
cristy1e604812011-05-19 18:07:50 +00008256 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8257 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008258#endif
anthonye9c27192011-03-27 08:07:06 +00008259 status&=MogrifyImage(image_info,argc,argv,images,exception);
8260 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008261 if (proceed == MagickFalse)
8262 break;
anthonye9c27192011-03-27 08:07:06 +00008263 if ( (*images)->next == (Image *) NULL )
8264 break;
8265 *images=(*images)->next;
8266 i++;
cristy3ed852e2009-09-05 21:47:34 +00008267 }
anthonye9c27192011-03-27 08:07:06 +00008268 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008269#if 0
cristy1e604812011-05-19 18:07:50 +00008270 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8271 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008272#endif
anthonye9c27192011-03-27 08:07:06 +00008273
8274 /*
8275 Post-process, multi-image sequence operators
8276 */
8277 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008278 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008279 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008280 return(status != 0 ? MagickTrue : MagickFalse);
8281}