blob: 34241782f1a1eff6e997b8870f197329678ab3b3 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
54#include "MagickCore/thread-private.h"
55#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000056
57/*
cristy154fa9d2011-08-05 14:25:15 +000058 Constant declaration.
59*/
cristy3a557c02011-08-06 19:48:02 +000060static const char
cristy638895a2011-08-06 23:19:14 +000061 MogrifyBackgroundColor[] = "#ffffff", /* white */
62 MogrifyBorderColor[] = "#dfdfdf", /* gray */
63 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000064
65/*
cristy3ed852e2009-09-05 21:47:34 +000066 Define declarations.
67*/
68#define UndefinedCompressionQuality 0UL
69
70/*
cristy3ed852e2009-09-05 21:47:34 +000071%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% %
73% %
74% %
cristy5063d812010-10-19 16:28:10 +000075% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000076% %
77% %
78% %
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80%
81% MagickCommandGenesis() applies image processing options to an image as
82% prescribed by command line options.
83%
84% The format of the MagickCommandGenesis method is:
85%
86% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000087% MagickCommand command,int argc,char **argv,char **metadata,
88% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000089%
90% A description of each parameter follows:
91%
92% o image_info: the image info.
93%
cristy5063d812010-10-19 16:28:10 +000094% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000095% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000096% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
97% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000098%
99% o argc: Specifies a pointer to an integer describing the number of
100% elements in the argument vector.
101%
102% o argv: Specifies a pointer to a text array containing the command line
103% arguments.
104%
cristy5063d812010-10-19 16:28:10 +0000105% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000106%
107% o exception: return any errors or warnings in this structure.
108%
109*/
110WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
111 MagickCommand command,int argc,char **argv,char **metadata,
112 ExceptionInfo *exception)
113{
114 char
115 *option;
116
117 double
118 duration,
119 elapsed_time,
120 user_time;
121
cristy3980b0d2009-10-25 14:37:13 +0000122 MagickBooleanType
123 concurrent,
124 regard_warnings,
125 status;
126
cristybb503372010-05-27 20:51:26 +0000127 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000128 i;
129
130 TimerInfo
131 *timer;
132
cristybb503372010-05-27 20:51:26 +0000133 size_t
cristy3980b0d2009-10-25 14:37:13 +0000134 iterations;
135
cristyd0a94fa2010-03-12 14:18:11 +0000136 (void) setlocale(LC_ALL,"");
137 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000138 concurrent=MagickFalse;
139 duration=(-1.0);
140 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000141 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000142 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000143 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000144 {
145 option=argv[i];
146 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
147 continue;
148 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000149 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000150 if (LocaleCompare("concurrent",option+1) == 0)
151 concurrent=MagickTrue;
152 if (LocaleCompare("debug",option+1) == 0)
153 (void) SetLogEventMask(argv[++i]);
154 if (LocaleCompare("duration",option+1) == 0)
cristyc1acd842011-05-19 23:05:47 +0000155 duration=InterpretLocaleValue(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000156 if (LocaleCompare("regard-warnings",option+1) == 0)
157 regard_warnings=MagickTrue;
158 }
159 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000160 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000161 {
cristybb503372010-05-27 20:51:26 +0000162 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000163 {
cristy33557d72009-11-06 00:54:33 +0000164 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000165 continue;
166 if (duration > 0)
167 {
168 if (GetElapsedTime(timer) > duration)
169 continue;
170 (void) ContinueTimer(timer);
171 }
172 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000173 if (exception->severity != UndefinedException)
174 {
175 if ((exception->severity > ErrorException) ||
176 (regard_warnings != MagickFalse))
177 status=MagickTrue;
178 CatchException(exception);
179 }
cristy3d1a5512009-10-25 21:23:27 +0000180 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000181 {
182 (void) fputs(*metadata,stdout);
183 (void) fputc('\n',stdout);
184 *metadata=DestroyString(*metadata);
185 }
186 }
187 }
cristyceae09d2009-10-28 17:18:47 +0000188 else
189 {
190 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000191#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000192 # pragma omp parallel for shared(status)
193#endif
cristybb503372010-05-27 20:51:26 +0000194 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000195 {
cristy33557d72009-11-06 00:54:33 +0000196 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000197 continue;
198 if (duration > 0)
199 {
200 if (GetElapsedTime(timer) > duration)
201 continue;
202 (void) ContinueTimer(timer);
203 }
204 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000205#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000206 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000207#endif
208 {
209 if (exception->severity != UndefinedException)
210 {
211 if ((exception->severity > ErrorException) ||
212 (regard_warnings != MagickFalse))
213 status=MagickTrue;
214 CatchException(exception);
215 }
216 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
217 {
218 (void) fputs(*metadata,stdout);
219 (void) fputc('\n',stdout);
220 *metadata=DestroyString(*metadata);
221 }
222 }
223 }
224 }
cristy3980b0d2009-10-25 14:37:13 +0000225 if (iterations > 1)
226 {
227 elapsed_time=GetElapsedTime(timer);
228 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000229 (void) FormatLocaleFile(stderr,
cristye8c25f92010-06-03 00:53:06 +0000230 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
231 iterations,1.0*iterations/elapsed_time,user_time,(double)
232 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
233 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000234 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000235 }
236 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000237 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000238}
239
240/*
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242% %
243% %
244% %
cristy3ed852e2009-09-05 21:47:34 +0000245+ M o g r i f y I m a g e %
246% %
247% %
248% %
249%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250%
anthonye9c27192011-03-27 08:07:06 +0000251% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000252% image that may be part of a large list, but also handles any 'region'
253% image handling.
anthonye9c27192011-03-27 08:07:06 +0000254%
255% The image in the list may be modified in three different ways...
256%
257% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
258% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
259% * replace by a list of images (only the -separate option!)
260%
261% In each case the result is returned into the list, and a pointer to the
262% modified image (last image added if replaced by a list of images) is
263% returned.
264%
265% ASIDE: The -crop is present but restricted to non-tile single image crops
266%
267% This means if all the images are being processed (such as by
268% MogrifyImages(), next image to be processed will be as per the pointer
269% (*image)->next. Also the image list may grow as a result of some specific
270% operations but as images are never merged or deleted, it will never shrink
271% in length. Typically the list will remain the same length.
272%
273% WARNING: As the image pointed to may be replaced, the first image in the
274% list may also change. GetFirstImageInList() should be used by caller if
275% they wish return the Image pointer to the first image in list.
276%
cristy3ed852e2009-09-05 21:47:34 +0000277%
278% The format of the MogrifyImage method is:
279%
280% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
281% const char **argv,Image **image)
282%
283% A description of each parameter follows:
284%
285% o image_info: the image info..
286%
287% o argc: Specifies a pointer to an integer describing the number of
288% elements in the argument vector.
289%
290% o argv: Specifies a pointer to a text array containing the command line
291% arguments.
292%
293% o image: the image.
294%
295% o exception: return any errors or warnings in this structure.
296%
297*/
298
cristy4c08aed2011-07-01 19:47:50 +0000299/*
300** GetImageCache() will read an image into a image cache if not already
301** present then return the image that is in the cache under that filename.
302*/
anthonydf8ebac2011-04-27 09:03:19 +0000303static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
304 ExceptionInfo *exception)
305{
306 char
307 key[MaxTextExtent];
308
309 ExceptionInfo
310 *sans_exception;
311
312 Image
313 *image;
314
315 ImageInfo
316 *read_info;
317
cristyb51dff52011-05-19 16:55:47 +0000318 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000319 sans_exception=AcquireExceptionInfo();
320 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
321 sans_exception=DestroyExceptionInfo(sans_exception);
322 if (image != (Image *) NULL)
323 return(image);
324 read_info=CloneImageInfo(image_info);
325 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
326 image=ReadImage(read_info,exception);
327 read_info=DestroyImageInfo(read_info);
328 if (image != (Image *) NULL)
329 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
330 return(image);
331}
332
cristy3ed852e2009-09-05 21:47:34 +0000333static MagickBooleanType IsPathWritable(const char *path)
334{
335 if (IsPathAccessible(path) == MagickFalse)
336 return(MagickFalse);
337 if (access(path,W_OK) != 0)
338 return(MagickFalse);
339 return(MagickTrue);
340}
341
cristybb503372010-05-27 20:51:26 +0000342static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000343{
344 if (x > y)
345 return(x);
346 return(y);
347}
348
anthonydf8ebac2011-04-27 09:03:19 +0000349static MagickBooleanType MonitorProgress(const char *text,
350 const MagickOffsetType offset,const MagickSizeType extent,
351 void *wand_unused(client_data))
352{
353 char
354 message[MaxTextExtent],
355 tag[MaxTextExtent];
356
357 const char
358 *locale_message;
359
360 register char
361 *p;
362
363 if (extent < 2)
364 return(MagickTrue);
365 (void) CopyMagickMemory(tag,text,MaxTextExtent);
366 p=strrchr(tag,'/');
367 if (p != (char *) NULL)
368 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000369 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000370 locale_message=GetLocaleMessage(message);
371 if (locale_message == message)
372 locale_message=tag;
373 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000374 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
375 locale_message,(long) offset,(unsigned long) extent,(long)
376 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000377 else
cristyb51dff52011-05-19 16:55:47 +0000378 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000379 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
380 (100L*offset/(extent-1)));
381 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000382 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000383 (void) fflush(stderr);
384 return(MagickTrue);
385}
386
cristy3884f692011-07-08 18:00:18 +0000387static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000388 const SparseColorMethod method,const char *arguments,
389 const MagickBooleanType color_from_image,ExceptionInfo *exception)
390{
anthonydf8ebac2011-04-27 09:03:19 +0000391 char
392 token[MaxTextExtent];
393
394 const char
395 *p;
396
397 double
398 *sparse_arguments;
399
anthonydf8ebac2011-04-27 09:03:19 +0000400 Image
401 *sparse_image;
402
cristy4c08aed2011-07-01 19:47:50 +0000403 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000404 color;
405
406 MagickBooleanType
407 error;
408
cristy5f09d852011-05-29 01:39:29 +0000409 register size_t
410 x;
411
412 size_t
413 number_arguments,
414 number_colors;
415
cristy28474bf2011-09-11 23:32:52 +0000416 /*
417 SparseColorOption() parses the complex -sparse-color argument into an
418 an array of floating point values then calls SparseColorImage().
419 Argument is a complex mix of floating-point pixel coodinates, and color
420 specifications (or direct floating point numbers). The number of floats
421 needed to represent a color varies depending on the current channel
422 setting.
423 */
anthonydf8ebac2011-04-27 09:03:19 +0000424 assert(image != (Image *) NULL);
425 assert(image->signature == MagickSignature);
426 if (image->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
428 assert(exception != (ExceptionInfo *) NULL);
429 assert(exception->signature == MagickSignature);
430 /*
431 Limit channels according to image - and add up number of color channel.
432 */
anthonydf8ebac2011-04-27 09:03:19 +0000433 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000434 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000435 number_colors++;
cristyed231572011-07-14 02:18:59 +0000436 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000437 number_colors++;
cristyed231572011-07-14 02:18:59 +0000438 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000439 number_colors++;
cristyed231572011-07-14 02:18:59 +0000440 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000441 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000442 number_colors++;
cristyed231572011-07-14 02:18:59 +0000443 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000444 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000445 number_colors++;
446
447 /*
448 Read string, to determine number of arguments needed,
449 */
450 p=arguments;
451 x=0;
452 while( *p != '\0' )
453 {
454 GetMagickToken(p,&p,token);
455 if ( token[0] == ',' ) continue;
456 if ( isalpha((int) token[0]) || token[0] == '#' ) {
457 if ( color_from_image ) {
458 (void) ThrowMagickException(exception,GetMagickModule(),
459 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
460 "Color arg given, when colors are coming from image");
461 return( (Image *)NULL);
462 }
463 x += number_colors; /* color argument */
464 }
465 else {
466 x++; /* floating point argument */
467 }
468 }
469 error=MagickTrue;
470 if ( color_from_image ) {
471 /* just the control points are being given */
472 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
473 number_arguments=(x/2)*(2+number_colors);
474 }
475 else {
476 /* control points and color values */
477 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
478 number_arguments=x;
479 }
480 if ( error ) {
481 (void) ThrowMagickException(exception,GetMagickModule(),
482 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
483 "Invalid number of Arguments");
484 return( (Image *)NULL);
485 }
486
487 /* Allocate and fill in the floating point arguments */
488 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
489 sizeof(*sparse_arguments));
490 if (sparse_arguments == (double *) NULL) {
491 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
492 "MemoryAllocationFailed","%s","SparseColorOption");
493 return( (Image *)NULL);
494 }
495 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
496 sizeof(*sparse_arguments));
497 p=arguments;
498 x=0;
499 while( *p != '\0' && x < number_arguments ) {
500 /* X coordinate */
501 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
502 if ( token[0] == '\0' ) break;
503 if ( isalpha((int) token[0]) || token[0] == '#' ) {
504 (void) ThrowMagickException(exception,GetMagickModule(),
505 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
506 "Color found, instead of X-coord");
507 error = MagickTrue;
508 break;
509 }
cristyc1acd842011-05-19 23:05:47 +0000510 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000511 /* Y coordinate */
512 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
513 if ( token[0] == '\0' ) break;
514 if ( isalpha((int) token[0]) || token[0] == '#' ) {
515 (void) ThrowMagickException(exception,GetMagickModule(),
516 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
517 "Color found, instead of Y-coord");
518 error = MagickTrue;
519 break;
520 }
cristyc1acd842011-05-19 23:05:47 +0000521 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000522 /* color values for this control point */
523#if 0
524 if ( (color_from_image ) {
525 /* get color from image */
526 /* HOW??? */
527 }
528 else
529#endif
530 {
531 /* color name or function given in string argument */
532 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
533 if ( token[0] == '\0' ) break;
534 if ( isalpha((int) token[0]) || token[0] == '#' ) {
535 /* Color string given */
536 (void) QueryMagickColor(token,&color,exception);
cristyed231572011-07-14 02:18:59 +0000537 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000538 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000539 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000540 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000541 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000542 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000543 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000544 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000545 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000546 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000547 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000548 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000549 }
550 else {
551 /* Colors given as a set of floating point values - experimental */
552 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000553 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000554 {
anthonydf8ebac2011-04-27 09:03:19 +0000555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristyc1acd842011-05-19 23:05:47 +0000558 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000559 token[0] = ','; /* used this token - get another */
560 }
cristyed231572011-07-14 02:18:59 +0000561 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000562 {
anthonydf8ebac2011-04-27 09:03:19 +0000563 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
564 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
565 break;
cristyc1acd842011-05-19 23:05:47 +0000566 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000567 token[0] = ','; /* used this token - get another */
568 }
cristyed231572011-07-14 02:18:59 +0000569 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000570 {
anthonydf8ebac2011-04-27 09:03:19 +0000571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristyc1acd842011-05-19 23:05:47 +0000574 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
cristyed231572011-07-14 02:18:59 +0000577 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000578 (image->colorspace == CMYKColorspace))
579 {
anthonydf8ebac2011-04-27 09:03:19 +0000580 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
581 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
582 break;
cristyc1acd842011-05-19 23:05:47 +0000583 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000584 token[0] = ','; /* used this token - get another */
585 }
cristyed231572011-07-14 02:18:59 +0000586 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000587 (image->matte != MagickFalse))
588 {
anthonydf8ebac2011-04-27 09:03:19 +0000589 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
590 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
591 break;
cristyc1acd842011-05-19 23:05:47 +0000592 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000593 token[0] = ','; /* used this token - get another */
594 }
595 }
596 }
597 }
598 if ( number_arguments != x && !error ) {
599 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
600 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
601 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
602 return( (Image *)NULL);
603 }
604 if ( error )
605 return( (Image *)NULL);
606
607 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000608 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
609 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000610 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
611 return( sparse_image );
612}
613
cristy3ed852e2009-09-05 21:47:34 +0000614WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
615 const char **argv,Image **image,ExceptionInfo *exception)
616{
anthonydf8ebac2011-04-27 09:03:19 +0000617 ChannelType
618 channel;
619
620 const char
621 *format,
622 *option;
623
624 DrawInfo
625 *draw_info;
626
627 GeometryInfo
628 geometry_info;
629
cristy3ed852e2009-09-05 21:47:34 +0000630 Image
631 *region_image;
632
anthonydf8ebac2011-04-27 09:03:19 +0000633 ImageInfo
634 *mogrify_info;
635
cristyebbcfea2011-02-25 02:43:54 +0000636 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000637 status;
638
cristy4c08aed2011-07-01 19:47:50 +0000639 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000640 fill;
cristy3ed852e2009-09-05 21:47:34 +0000641
anthonydf8ebac2011-04-27 09:03:19 +0000642 MagickStatusType
643 flags;
644
cristy28474bf2011-09-11 23:32:52 +0000645 PixelInterpolateMethod
646 interpolate_method;
647
anthonydf8ebac2011-04-27 09:03:19 +0000648 QuantizeInfo
649 *quantize_info;
650
651 RectangleInfo
652 geometry,
653 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000654
cristybb503372010-05-27 20:51:26 +0000655 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000656 i;
657
658 /*
659 Initialize method variables.
660 */
661 assert(image_info != (const ImageInfo *) NULL);
662 assert(image_info->signature == MagickSignature);
663 assert(image != (Image **) NULL);
664 assert((*image)->signature == MagickSignature);
665 if ((*image)->debug != MagickFalse)
666 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
667 if (argc < 0)
668 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000669 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000670 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
671 quantize_info=AcquireQuantizeInfo(mogrify_info);
672 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000673 GetPixelInfo(*image,&fill);
674 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
cristy28474bf2011-09-11 23:32:52 +0000675 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000676 channel=mogrify_info->channel;
677 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000678 SetGeometry(*image,&region_geometry);
679 region_image=NewImageList();
680 /*
681 Transmogrify the image.
682 */
cristybb503372010-05-27 20:51:26 +0000683 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000684 {
anthonydf8ebac2011-04-27 09:03:19 +0000685 Image
686 *mogrify_image;
687
anthonye9c27192011-03-27 08:07:06 +0000688 ssize_t
689 count;
690
anthonydf8ebac2011-04-27 09:03:19 +0000691 option=argv[i];
692 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000693 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000694 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
695 0L);
cristycee97112010-05-28 00:44:52 +0000696 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000697 break;
cristy6b3da3a2010-06-20 02:21:46 +0000698 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000699 mogrify_image=(Image *)NULL;
700 switch (*(option+1))
701 {
702 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000703 {
anthonydf8ebac2011-04-27 09:03:19 +0000704 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000705 {
anthonydf8ebac2011-04-27 09:03:19 +0000706 /*
707 Adaptive blur image.
708 */
709 (void) SyncImageSettings(mogrify_info,*image);
710 flags=ParseGeometry(argv[i+1],&geometry_info);
711 if ((flags & SigmaValue) == 0)
712 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000713 if ((flags & XiValue) == 0)
714 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000715 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000716 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000717 break;
cristy3ed852e2009-09-05 21:47:34 +0000718 }
anthonydf8ebac2011-04-27 09:03:19 +0000719 if (LocaleCompare("adaptive-resize",option+1) == 0)
720 {
721 /*
722 Adaptive resize image.
723 */
724 (void) SyncImageSettings(mogrify_info,*image);
725 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
726 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
cristy28474bf2011-09-11 23:32:52 +0000727 geometry.height,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000728 break;
729 }
730 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
731 {
732 /*
733 Adaptive sharpen image.
734 */
735 (void) SyncImageSettings(mogrify_info,*image);
736 flags=ParseGeometry(argv[i+1],&geometry_info);
737 if ((flags & SigmaValue) == 0)
738 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000739 if ((flags & XiValue) == 0)
740 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000741 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000742 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000743 break;
744 }
745 if (LocaleCompare("affine",option+1) == 0)
746 {
747 /*
748 Affine matrix.
749 */
750 if (*option == '+')
751 {
752 GetAffineMatrix(&draw_info->affine);
753 break;
754 }
755 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
756 break;
757 }
758 if (LocaleCompare("alpha",option+1) == 0)
759 {
760 AlphaChannelType
761 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000762
anthonydf8ebac2011-04-27 09:03:19 +0000763 (void) SyncImageSettings(mogrify_info,*image);
764 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
765 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000766 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000767 break;
768 }
769 if (LocaleCompare("annotate",option+1) == 0)
770 {
771 char
772 *text,
773 geometry[MaxTextExtent];
774
775 /*
776 Annotate image.
777 */
778 (void) SyncImageSettings(mogrify_info,*image);
779 SetGeometryInfo(&geometry_info);
780 flags=ParseGeometry(argv[i+1],&geometry_info);
781 if ((flags & SigmaValue) == 0)
782 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000783 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
784 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000785 if (text == (char *) NULL)
786 break;
787 (void) CloneString(&draw_info->text,text);
788 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000789 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000790 geometry_info.xi,geometry_info.psi);
791 (void) CloneString(&draw_info->geometry,geometry);
792 draw_info->affine.sx=cos(DegreesToRadians(
793 fmod(geometry_info.rho,360.0)));
794 draw_info->affine.rx=sin(DegreesToRadians(
795 fmod(geometry_info.rho,360.0)));
796 draw_info->affine.ry=(-sin(DegreesToRadians(
797 fmod(geometry_info.sigma,360.0))));
798 draw_info->affine.sy=cos(DegreesToRadians(
799 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000800 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000801 break;
802 }
803 if (LocaleCompare("antialias",option+1) == 0)
804 {
805 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
806 MagickFalse;
807 draw_info->text_antialias=(*option == '-') ? MagickTrue :
808 MagickFalse;
809 break;
810 }
811 if (LocaleCompare("auto-gamma",option+1) == 0)
812 {
813 /*
814 Auto Adjust Gamma of image based on its mean
815 */
816 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000817 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000818 break;
819 }
820 if (LocaleCompare("auto-level",option+1) == 0)
821 {
822 /*
823 Perfectly Normalize (max/min stretch) the image
824 */
825 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000826 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000827 break;
828 }
829 if (LocaleCompare("auto-orient",option+1) == 0)
830 {
831 (void) SyncImageSettings(mogrify_info,*image);
832 switch ((*image)->orientation)
833 {
834 case TopRightOrientation:
835 {
836 mogrify_image=FlopImage(*image,exception);
837 break;
838 }
839 case BottomRightOrientation:
840 {
841 mogrify_image=RotateImage(*image,180.0,exception);
842 break;
843 }
844 case BottomLeftOrientation:
845 {
846 mogrify_image=FlipImage(*image,exception);
847 break;
848 }
849 case LeftTopOrientation:
850 {
851 mogrify_image=TransposeImage(*image,exception);
852 break;
853 }
854 case RightTopOrientation:
855 {
856 mogrify_image=RotateImage(*image,90.0,exception);
857 break;
858 }
859 case RightBottomOrientation:
860 {
861 mogrify_image=TransverseImage(*image,exception);
862 break;
863 }
864 case LeftBottomOrientation:
865 {
866 mogrify_image=RotateImage(*image,270.0,exception);
867 break;
868 }
869 default:
870 break;
871 }
872 if (mogrify_image != (Image *) NULL)
873 mogrify_image->orientation=TopLeftOrientation;
874 break;
875 }
876 break;
877 }
878 case 'b':
879 {
880 if (LocaleCompare("black-threshold",option+1) == 0)
881 {
882 /*
883 Black threshold image.
884 */
885 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000886 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000887 InheritException(exception,&(*image)->exception);
888 break;
889 }
890 if (LocaleCompare("blue-shift",option+1) == 0)
891 {
892 /*
893 Blue shift image.
894 */
895 (void) SyncImageSettings(mogrify_info,*image);
896 geometry_info.rho=1.5;
897 if (*option == '-')
898 flags=ParseGeometry(argv[i+1],&geometry_info);
899 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
900 break;
901 }
902 if (LocaleCompare("blur",option+1) == 0)
903 {
904 /*
905 Gaussian blur image.
906 */
907 (void) SyncImageSettings(mogrify_info,*image);
908 flags=ParseGeometry(argv[i+1],&geometry_info);
909 if ((flags & SigmaValue) == 0)
910 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000911 if ((flags & XiValue) == 0)
912 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000913 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000914 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000915 break;
916 }
917 if (LocaleCompare("border",option+1) == 0)
918 {
919 /*
920 Surround image with a border of solid color.
921 */
922 (void) SyncImageSettings(mogrify_info,*image);
923 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
924 if ((flags & SigmaValue) == 0)
925 geometry.height=geometry.width;
926 mogrify_image=BorderImage(*image,&geometry,exception);
927 break;
928 }
929 if (LocaleCompare("bordercolor",option+1) == 0)
930 {
931 if (*option == '+')
932 {
cristy05c0c9a2011-09-05 23:16:13 +0000933 (void) QueryColorDatabase(MogrifyBorderColor,
934 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000935 break;
936 }
937 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
938 exception);
939 break;
940 }
941 if (LocaleCompare("box",option+1) == 0)
942 {
943 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
944 exception);
945 break;
946 }
947 if (LocaleCompare("brightness-contrast",option+1) == 0)
948 {
949 double
950 brightness,
951 contrast;
952
953 GeometryInfo
954 geometry_info;
955
956 MagickStatusType
957 flags;
958
959 /*
960 Brightness / contrast image.
961 */
962 (void) SyncImageSettings(mogrify_info,*image);
963 flags=ParseGeometry(argv[i+1],&geometry_info);
964 brightness=geometry_info.rho;
965 contrast=0.0;
966 if ((flags & SigmaValue) != 0)
967 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000968 (void) BrightnessContrastImage(*image,brightness,contrast,
969 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000970 InheritException(exception,&(*image)->exception);
971 break;
972 }
973 break;
974 }
975 case 'c':
976 {
977 if (LocaleCompare("cdl",option+1) == 0)
978 {
979 char
980 *color_correction_collection;
981
982 /*
983 Color correct with a color decision list.
984 */
985 (void) SyncImageSettings(mogrify_info,*image);
986 color_correction_collection=FileToString(argv[i+1],~0,exception);
987 if (color_correction_collection == (char *) NULL)
988 break;
cristy1bfa9f02011-08-11 02:35:43 +0000989 (void) ColorDecisionListImage(*image,color_correction_collection,
990 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000991 InheritException(exception,&(*image)->exception);
992 break;
993 }
994 if (LocaleCompare("channel",option+1) == 0)
995 {
996 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000997 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000998 else
cristyfa806a72011-07-04 02:06:13 +0000999 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00001000 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +00001001 break;
1002 }
1003 if (LocaleCompare("charcoal",option+1) == 0)
1004 {
1005 /*
1006 Charcoal image.
1007 */
1008 (void) SyncImageSettings(mogrify_info,*image);
1009 flags=ParseGeometry(argv[i+1],&geometry_info);
1010 if ((flags & SigmaValue) == 0)
1011 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001012 if ((flags & XiValue) == 0)
1013 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001014 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001015 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001016 break;
1017 }
1018 if (LocaleCompare("chop",option+1) == 0)
1019 {
1020 /*
1021 Chop the image.
1022 */
1023 (void) SyncImageSettings(mogrify_info,*image);
1024 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1025 mogrify_image=ChopImage(*image,&geometry,exception);
1026 break;
1027 }
1028 if (LocaleCompare("clamp",option+1) == 0)
1029 {
1030 /*
1031 Clamp image.
1032 */
1033 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001034 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001035 InheritException(exception,&(*image)->exception);
1036 break;
1037 }
1038 if (LocaleCompare("clip",option+1) == 0)
1039 {
1040 (void) SyncImageSettings(mogrify_info,*image);
1041 if (*option == '+')
1042 {
cristy018f07f2011-09-04 21:15:19 +00001043 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001044 break;
1045 }
cristy018f07f2011-09-04 21:15:19 +00001046 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001047 break;
1048 }
1049 if (LocaleCompare("clip-mask",option+1) == 0)
1050 {
1051 CacheView
1052 *mask_view;
1053
1054 Image
1055 *mask_image;
1056
cristy4c08aed2011-07-01 19:47:50 +00001057 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001058 *restrict q;
1059
1060 register ssize_t
1061 x;
1062
1063 ssize_t
1064 y;
1065
1066 (void) SyncImageSettings(mogrify_info,*image);
1067 if (*option == '+')
1068 {
1069 /*
1070 Remove a mask.
1071 */
cristy018f07f2011-09-04 21:15:19 +00001072 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001073 break;
1074 }
1075 /*
1076 Set the image mask.
1077 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1078 */
1079 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1080 if (mask_image == (Image *) NULL)
1081 break;
cristy574cc262011-08-05 01:23:58 +00001082 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001083 return(MagickFalse);
1084 mask_view=AcquireCacheView(mask_image);
1085 for (y=0; y < (ssize_t) mask_image->rows; y++)
1086 {
1087 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1088 exception);
cristyacd2ed22011-08-30 01:44:23 +00001089 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001090 break;
1091 for (x=0; x < (ssize_t) mask_image->columns; x++)
1092 {
1093 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001094 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1095 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1096 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1097 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001098 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001099 }
1100 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1101 break;
1102 }
1103 mask_view=DestroyCacheView(mask_view);
1104 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001105 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001106 InheritException(exception,&(*image)->exception);
1107 break;
1108 }
1109 if (LocaleCompare("clip-path",option+1) == 0)
1110 {
1111 (void) SyncImageSettings(mogrify_info,*image);
1112 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001113 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001114 break;
1115 }
1116 if (LocaleCompare("colorize",option+1) == 0)
1117 {
1118 /*
1119 Colorize the image.
1120 */
1121 (void) SyncImageSettings(mogrify_info,*image);
1122 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1123 exception);
1124 break;
1125 }
1126 if (LocaleCompare("color-matrix",option+1) == 0)
1127 {
1128 KernelInfo
1129 *kernel;
1130
1131 (void) SyncImageSettings(mogrify_info,*image);
1132 kernel=AcquireKernelInfo(argv[i+1]);
1133 if (kernel == (KernelInfo *) NULL)
1134 break;
1135 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1136 kernel=DestroyKernelInfo(kernel);
1137 break;
1138 }
1139 if (LocaleCompare("colors",option+1) == 0)
1140 {
1141 /*
1142 Reduce the number of colors in the image.
1143 */
1144 (void) SyncImageSettings(mogrify_info,*image);
1145 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1146 if (quantize_info->number_colors == 0)
1147 break;
1148 if (((*image)->storage_class == DirectClass) ||
1149 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001150 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001151 else
cristy018f07f2011-09-04 21:15:19 +00001152 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001153 break;
1154 }
1155 if (LocaleCompare("colorspace",option+1) == 0)
1156 {
1157 ColorspaceType
1158 colorspace;
1159
1160 (void) SyncImageSettings(mogrify_info,*image);
1161 if (*option == '+')
1162 {
1163 (void) TransformImageColorspace(*image,RGBColorspace);
1164 InheritException(exception,&(*image)->exception);
1165 break;
1166 }
1167 colorspace=(ColorspaceType) ParseCommandOption(
1168 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1169 (void) TransformImageColorspace(*image,colorspace);
1170 InheritException(exception,&(*image)->exception);
1171 break;
1172 }
1173 if (LocaleCompare("contrast",option+1) == 0)
1174 {
1175 (void) SyncImageSettings(mogrify_info,*image);
1176 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001177 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001178 break;
1179 }
1180 if (LocaleCompare("contrast-stretch",option+1) == 0)
1181 {
1182 double
1183 black_point,
1184 white_point;
1185
1186 MagickStatusType
1187 flags;
1188
1189 /*
1190 Contrast stretch image.
1191 */
1192 (void) SyncImageSettings(mogrify_info,*image);
1193 flags=ParseGeometry(argv[i+1],&geometry_info);
1194 black_point=geometry_info.rho;
1195 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1196 black_point;
1197 if ((flags & PercentValue) != 0)
1198 {
1199 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1200 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1201 }
1202 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1203 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001204 (void) ContrastStretchImage(*image,black_point,white_point,
1205 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001206 InheritException(exception,&(*image)->exception);
1207 break;
1208 }
1209 if (LocaleCompare("convolve",option+1) == 0)
1210 {
anthonydf8ebac2011-04-27 09:03:19 +00001211 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001212 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001213
anthonydf8ebac2011-04-27 09:03:19 +00001214 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001215 kernel_info=AcquireKernelInfo(argv[i+1]);
1216 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001217 break;
cristy0a922382011-07-16 15:30:34 +00001218 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001219 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001220 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001221 break;
1222 }
1223 if (LocaleCompare("crop",option+1) == 0)
1224 {
1225 /*
1226 Crop a image to a smaller size
1227 */
1228 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001229 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001230 break;
1231 }
1232 if (LocaleCompare("cycle",option+1) == 0)
1233 {
1234 /*
1235 Cycle an image colormap.
1236 */
1237 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00001238 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1239 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001240 break;
1241 }
1242 break;
1243 }
1244 case 'd':
1245 {
1246 if (LocaleCompare("decipher",option+1) == 0)
1247 {
1248 StringInfo
1249 *passkey;
1250
1251 /*
1252 Decipher pixels.
1253 */
1254 (void) SyncImageSettings(mogrify_info,*image);
1255 passkey=FileToStringInfo(argv[i+1],~0,exception);
1256 if (passkey != (StringInfo *) NULL)
1257 {
1258 (void) PasskeyDecipherImage(*image,passkey,exception);
1259 passkey=DestroyStringInfo(passkey);
1260 }
1261 break;
1262 }
1263 if (LocaleCompare("density",option+1) == 0)
1264 {
1265 /*
1266 Set image density.
1267 */
1268 (void) CloneString(&draw_info->density,argv[i+1]);
1269 break;
1270 }
1271 if (LocaleCompare("depth",option+1) == 0)
1272 {
1273 (void) SyncImageSettings(mogrify_info,*image);
1274 if (*option == '+')
1275 {
1276 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1277 break;
1278 }
1279 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1280 break;
1281 }
1282 if (LocaleCompare("deskew",option+1) == 0)
1283 {
1284 double
1285 threshold;
1286
1287 /*
1288 Straighten the image.
1289 */
1290 (void) SyncImageSettings(mogrify_info,*image);
1291 if (*option == '+')
1292 threshold=40.0*QuantumRange/100.0;
1293 else
1294 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1295 mogrify_image=DeskewImage(*image,threshold,exception);
1296 break;
1297 }
1298 if (LocaleCompare("despeckle",option+1) == 0)
1299 {
1300 /*
1301 Reduce the speckles within an image.
1302 */
1303 (void) SyncImageSettings(mogrify_info,*image);
1304 mogrify_image=DespeckleImage(*image,exception);
1305 break;
1306 }
1307 if (LocaleCompare("display",option+1) == 0)
1308 {
1309 (void) CloneString(&draw_info->server_name,argv[i+1]);
1310 break;
1311 }
1312 if (LocaleCompare("distort",option+1) == 0)
1313 {
1314 char
1315 *args,
1316 token[MaxTextExtent];
1317
1318 const char
1319 *p;
1320
1321 DistortImageMethod
1322 method;
1323
1324 double
1325 *arguments;
1326
1327 register ssize_t
1328 x;
1329
1330 size_t
1331 number_arguments;
1332
1333 /*
1334 Distort image.
1335 */
1336 (void) SyncImageSettings(mogrify_info,*image);
1337 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1338 MagickFalse,argv[i+1]);
1339 if ( method == ResizeDistortion )
1340 {
1341 /* Special Case - Argument is actually a resize geometry!
1342 ** Convert that to an appropriate distortion argument array.
1343 */
1344 double
1345 resize_args[2];
1346 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1347 exception);
1348 resize_args[0]=(double)geometry.width;
1349 resize_args[1]=(double)geometry.height;
1350 mogrify_image=DistortImage(*image,method,(size_t)2,
1351 resize_args,MagickTrue,exception);
1352 break;
1353 }
cristy018f07f2011-09-04 21:15:19 +00001354 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1355 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001356 if (args == (char *) NULL)
1357 break;
1358 p=(char *) args;
1359 for (x=0; *p != '\0'; x++)
1360 {
1361 GetMagickToken(p,&p,token);
1362 if (*token == ',')
1363 GetMagickToken(p,&p,token);
1364 }
1365 number_arguments=(size_t) x;
1366 arguments=(double *) AcquireQuantumMemory(number_arguments,
1367 sizeof(*arguments));
1368 if (arguments == (double *) NULL)
1369 ThrowWandFatalException(ResourceLimitFatalError,
1370 "MemoryAllocationFailed",(*image)->filename);
1371 (void) ResetMagickMemory(arguments,0,number_arguments*
1372 sizeof(*arguments));
1373 p=(char *) args;
1374 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1375 {
1376 GetMagickToken(p,&p,token);
1377 if (*token == ',')
1378 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001379 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001380 }
1381 args=DestroyString(args);
1382 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1383 (*option == '+') ? MagickTrue : MagickFalse,exception);
1384 arguments=(double *) RelinquishMagickMemory(arguments);
1385 break;
1386 }
1387 if (LocaleCompare("dither",option+1) == 0)
1388 {
1389 if (*option == '+')
1390 {
1391 quantize_info->dither=MagickFalse;
1392 break;
1393 }
1394 quantize_info->dither=MagickTrue;
1395 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1396 MagickDitherOptions,MagickFalse,argv[i+1]);
1397 if (quantize_info->dither_method == NoDitherMethod)
1398 quantize_info->dither=MagickFalse;
1399 break;
1400 }
1401 if (LocaleCompare("draw",option+1) == 0)
1402 {
1403 /*
1404 Draw image.
1405 */
1406 (void) SyncImageSettings(mogrify_info,*image);
1407 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001408 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001409 break;
1410 }
1411 break;
1412 }
1413 case 'e':
1414 {
1415 if (LocaleCompare("edge",option+1) == 0)
1416 {
1417 /*
1418 Enhance edges in the image.
1419 */
1420 (void) SyncImageSettings(mogrify_info,*image);
1421 flags=ParseGeometry(argv[i+1],&geometry_info);
1422 if ((flags & SigmaValue) == 0)
1423 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001424 mogrify_image=EdgeImage(*image,geometry_info.rho,
1425 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001426 break;
1427 }
1428 if (LocaleCompare("emboss",option+1) == 0)
1429 {
1430 /*
1431 Gaussian embossen image.
1432 */
1433 (void) SyncImageSettings(mogrify_info,*image);
1434 flags=ParseGeometry(argv[i+1],&geometry_info);
1435 if ((flags & SigmaValue) == 0)
1436 geometry_info.sigma=1.0;
1437 mogrify_image=EmbossImage(*image,geometry_info.rho,
1438 geometry_info.sigma,exception);
1439 break;
1440 }
1441 if (LocaleCompare("encipher",option+1) == 0)
1442 {
1443 StringInfo
1444 *passkey;
1445
1446 /*
1447 Encipher pixels.
1448 */
1449 (void) SyncImageSettings(mogrify_info,*image);
1450 passkey=FileToStringInfo(argv[i+1],~0,exception);
1451 if (passkey != (StringInfo *) NULL)
1452 {
1453 (void) PasskeyEncipherImage(*image,passkey,exception);
1454 passkey=DestroyStringInfo(passkey);
1455 }
1456 break;
1457 }
1458 if (LocaleCompare("encoding",option+1) == 0)
1459 {
1460 (void) CloneString(&draw_info->encoding,argv[i+1]);
1461 break;
1462 }
1463 if (LocaleCompare("enhance",option+1) == 0)
1464 {
1465 /*
1466 Enhance image.
1467 */
1468 (void) SyncImageSettings(mogrify_info,*image);
1469 mogrify_image=EnhanceImage(*image,exception);
1470 break;
1471 }
1472 if (LocaleCompare("equalize",option+1) == 0)
1473 {
1474 /*
1475 Equalize image.
1476 */
1477 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001478 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001479 break;
1480 }
1481 if (LocaleCompare("evaluate",option+1) == 0)
1482 {
1483 double
1484 constant;
1485
1486 MagickEvaluateOperator
1487 op;
1488
1489 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001490 op=(MagickEvaluateOperator) ParseCommandOption(
1491 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001492 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001493 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001494 break;
1495 }
1496 if (LocaleCompare("extent",option+1) == 0)
1497 {
1498 /*
1499 Set the image extent.
1500 */
1501 (void) SyncImageSettings(mogrify_info,*image);
1502 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1503 if (geometry.width == 0)
1504 geometry.width=(*image)->columns;
1505 if (geometry.height == 0)
1506 geometry.height=(*image)->rows;
1507 mogrify_image=ExtentImage(*image,&geometry,exception);
1508 break;
1509 }
1510 break;
1511 }
1512 case 'f':
1513 {
1514 if (LocaleCompare("family",option+1) == 0)
1515 {
1516 if (*option == '+')
1517 {
1518 if (draw_info->family != (char *) NULL)
1519 draw_info->family=DestroyString(draw_info->family);
1520 break;
1521 }
1522 (void) CloneString(&draw_info->family,argv[i+1]);
1523 break;
1524 }
1525 if (LocaleCompare("features",option+1) == 0)
1526 {
1527 if (*option == '+')
1528 {
1529 (void) DeleteImageArtifact(*image,"identify:features");
1530 break;
1531 }
1532 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1533 break;
1534 }
1535 if (LocaleCompare("fill",option+1) == 0)
1536 {
1537 ExceptionInfo
1538 *sans;
1539
cristy4c08aed2011-07-01 19:47:50 +00001540 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001541 if (*option == '+')
1542 {
1543 (void) QueryMagickColor("none",&fill,exception);
1544 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1545 if (draw_info->fill_pattern != (Image *) NULL)
1546 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1547 break;
1548 }
1549 sans=AcquireExceptionInfo();
1550 (void) QueryMagickColor(argv[i+1],&fill,sans);
1551 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1552 sans=DestroyExceptionInfo(sans);
1553 if (status == MagickFalse)
1554 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1555 exception);
1556 break;
1557 }
1558 if (LocaleCompare("flip",option+1) == 0)
1559 {
1560 /*
1561 Flip image scanlines.
1562 */
1563 (void) SyncImageSettings(mogrify_info,*image);
1564 mogrify_image=FlipImage(*image,exception);
1565 break;
1566 }
anthonydf8ebac2011-04-27 09:03:19 +00001567 if (LocaleCompare("floodfill",option+1) == 0)
1568 {
cristy4c08aed2011-07-01 19:47:50 +00001569 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001570 target;
1571
1572 /*
1573 Floodfill image.
1574 */
1575 (void) SyncImageSettings(mogrify_info,*image);
1576 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1577 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001578 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001579 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001580 break;
1581 }
anthony3d2f4862011-05-01 13:48:16 +00001582 if (LocaleCompare("flop",option+1) == 0)
1583 {
1584 /*
1585 Flop image scanlines.
1586 */
1587 (void) SyncImageSettings(mogrify_info,*image);
1588 mogrify_image=FlopImage(*image,exception);
1589 break;
1590 }
anthonydf8ebac2011-04-27 09:03:19 +00001591 if (LocaleCompare("font",option+1) == 0)
1592 {
1593 if (*option == '+')
1594 {
1595 if (draw_info->font != (char *) NULL)
1596 draw_info->font=DestroyString(draw_info->font);
1597 break;
1598 }
1599 (void) CloneString(&draw_info->font,argv[i+1]);
1600 break;
1601 }
1602 if (LocaleCompare("format",option+1) == 0)
1603 {
1604 format=argv[i+1];
1605 break;
1606 }
1607 if (LocaleCompare("frame",option+1) == 0)
1608 {
1609 FrameInfo
1610 frame_info;
1611
1612 /*
1613 Surround image with an ornamental border.
1614 */
1615 (void) SyncImageSettings(mogrify_info,*image);
1616 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1617 frame_info.width=geometry.width;
1618 frame_info.height=geometry.height;
1619 if ((flags & HeightValue) == 0)
1620 frame_info.height=geometry.width;
1621 frame_info.outer_bevel=geometry.x;
1622 frame_info.inner_bevel=geometry.y;
1623 frame_info.x=(ssize_t) frame_info.width;
1624 frame_info.y=(ssize_t) frame_info.height;
1625 frame_info.width=(*image)->columns+2*frame_info.width;
1626 frame_info.height=(*image)->rows+2*frame_info.height;
1627 mogrify_image=FrameImage(*image,&frame_info,exception);
1628 break;
1629 }
1630 if (LocaleCompare("function",option+1) == 0)
1631 {
1632 char
1633 *arguments,
1634 token[MaxTextExtent];
1635
1636 const char
1637 *p;
1638
1639 double
1640 *parameters;
1641
1642 MagickFunction
1643 function;
1644
1645 register ssize_t
1646 x;
1647
1648 size_t
1649 number_parameters;
1650
1651 /*
1652 Function Modify Image Values
1653 */
1654 (void) SyncImageSettings(mogrify_info,*image);
1655 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1656 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001657 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1658 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001659 if (arguments == (char *) NULL)
1660 break;
1661 p=(char *) arguments;
1662 for (x=0; *p != '\0'; x++)
1663 {
1664 GetMagickToken(p,&p,token);
1665 if (*token == ',')
1666 GetMagickToken(p,&p,token);
1667 }
1668 number_parameters=(size_t) x;
1669 parameters=(double *) AcquireQuantumMemory(number_parameters,
1670 sizeof(*parameters));
1671 if (parameters == (double *) NULL)
1672 ThrowWandFatalException(ResourceLimitFatalError,
1673 "MemoryAllocationFailed",(*image)->filename);
1674 (void) ResetMagickMemory(parameters,0,number_parameters*
1675 sizeof(*parameters));
1676 p=(char *) arguments;
1677 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1678 {
1679 GetMagickToken(p,&p,token);
1680 if (*token == ',')
1681 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001682 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001683 }
1684 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001685 (void) FunctionImage(*image,function,number_parameters,parameters,
1686 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001687 parameters=(double *) RelinquishMagickMemory(parameters);
1688 break;
1689 }
1690 break;
1691 }
1692 case 'g':
1693 {
1694 if (LocaleCompare("gamma",option+1) == 0)
1695 {
1696 /*
1697 Gamma image.
1698 */
1699 (void) SyncImageSettings(mogrify_info,*image);
1700 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001701 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001702 else
cristyb3e7c6c2011-07-24 01:43:55 +00001703 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1704 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001705 break;
1706 }
1707 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1708 (LocaleCompare("gaussian",option+1) == 0))
1709 {
1710 /*
1711 Gaussian blur image.
1712 */
1713 (void) SyncImageSettings(mogrify_info,*image);
1714 flags=ParseGeometry(argv[i+1],&geometry_info);
1715 if ((flags & SigmaValue) == 0)
1716 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001717 if ((flags & XiValue) == 0)
1718 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001719 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001720 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001721 break;
1722 }
1723 if (LocaleCompare("geometry",option+1) == 0)
1724 {
1725 /*
1726 Record Image offset, Resize last image.
1727 */
1728 (void) SyncImageSettings(mogrify_info,*image);
1729 if (*option == '+')
1730 {
1731 if ((*image)->geometry != (char *) NULL)
1732 (*image)->geometry=DestroyString((*image)->geometry);
1733 break;
1734 }
1735 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1736 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1737 (void) CloneString(&(*image)->geometry,argv[i+1]);
1738 else
1739 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1740 (*image)->filter,(*image)->blur,exception);
1741 break;
1742 }
1743 if (LocaleCompare("gravity",option+1) == 0)
1744 {
1745 if (*option == '+')
1746 {
1747 draw_info->gravity=UndefinedGravity;
1748 break;
1749 }
1750 draw_info->gravity=(GravityType) ParseCommandOption(
1751 MagickGravityOptions,MagickFalse,argv[i+1]);
1752 break;
1753 }
1754 break;
1755 }
1756 case 'h':
1757 {
1758 if (LocaleCompare("highlight-color",option+1) == 0)
1759 {
1760 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1761 break;
1762 }
1763 break;
1764 }
1765 case 'i':
1766 {
1767 if (LocaleCompare("identify",option+1) == 0)
1768 {
1769 char
1770 *text;
1771
1772 (void) SyncImageSettings(mogrify_info,*image);
1773 if (format == (char *) NULL)
1774 {
cristya4037272011-08-28 15:11:39 +00001775 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1776 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001777 break;
1778 }
cristy018f07f2011-09-04 21:15:19 +00001779 text=InterpretImageProperties(mogrify_info,*image,format,
1780 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001781 if (text == (char *) NULL)
1782 break;
1783 (void) fputs(text,stdout);
1784 (void) fputc('\n',stdout);
1785 text=DestroyString(text);
1786 break;
1787 }
1788 if (LocaleCompare("implode",option+1) == 0)
1789 {
1790 /*
1791 Implode image.
1792 */
1793 (void) SyncImageSettings(mogrify_info,*image);
1794 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001795 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1796 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001797 break;
1798 }
1799 if (LocaleCompare("interline-spacing",option+1) == 0)
1800 {
1801 if (*option == '+')
1802 (void) ParseGeometry("0",&geometry_info);
1803 else
1804 (void) ParseGeometry(argv[i+1],&geometry_info);
1805 draw_info->interline_spacing=geometry_info.rho;
1806 break;
1807 }
cristy28474bf2011-09-11 23:32:52 +00001808 if (LocaleCompare("interpolate",option+1) == 0)
1809 {
1810 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1811 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1812 break;
1813 }
anthonydf8ebac2011-04-27 09:03:19 +00001814 if (LocaleCompare("interword-spacing",option+1) == 0)
1815 {
1816 if (*option == '+')
1817 (void) ParseGeometry("0",&geometry_info);
1818 else
1819 (void) ParseGeometry(argv[i+1],&geometry_info);
1820 draw_info->interword_spacing=geometry_info.rho;
1821 break;
1822 }
1823 break;
1824 }
1825 case 'k':
1826 {
1827 if (LocaleCompare("kerning",option+1) == 0)
1828 {
1829 if (*option == '+')
1830 (void) ParseGeometry("0",&geometry_info);
1831 else
1832 (void) ParseGeometry(argv[i+1],&geometry_info);
1833 draw_info->kerning=geometry_info.rho;
1834 break;
1835 }
1836 break;
1837 }
1838 case 'l':
1839 {
1840 if (LocaleCompare("lat",option+1) == 0)
1841 {
1842 /*
1843 Local adaptive threshold image.
1844 */
1845 (void) SyncImageSettings(mogrify_info,*image);
1846 flags=ParseGeometry(argv[i+1],&geometry_info);
1847 if ((flags & PercentValue) != 0)
1848 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1849 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001850 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001851 geometry_info.xi,exception);
1852 break;
1853 }
1854 if (LocaleCompare("level",option+1) == 0)
1855 {
1856 MagickRealType
1857 black_point,
1858 gamma,
1859 white_point;
1860
1861 MagickStatusType
1862 flags;
1863
1864 /*
1865 Parse levels.
1866 */
1867 (void) SyncImageSettings(mogrify_info,*image);
1868 flags=ParseGeometry(argv[i+1],&geometry_info);
1869 black_point=geometry_info.rho;
1870 white_point=(MagickRealType) QuantumRange;
1871 if ((flags & SigmaValue) != 0)
1872 white_point=geometry_info.sigma;
1873 gamma=1.0;
1874 if ((flags & XiValue) != 0)
1875 gamma=geometry_info.xi;
1876 if ((flags & PercentValue) != 0)
1877 {
1878 black_point*=(MagickRealType) (QuantumRange/100.0);
1879 white_point*=(MagickRealType) (QuantumRange/100.0);
1880 }
1881 if ((flags & SigmaValue) == 0)
1882 white_point=(MagickRealType) QuantumRange-black_point;
1883 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001884 (void) LevelizeImage(*image,black_point,white_point,gamma,
1885 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001886 else
cristy01e9afd2011-08-10 17:38:41 +00001887 (void) LevelImage(*image,black_point,white_point,gamma,
1888 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001889 InheritException(exception,&(*image)->exception);
1890 break;
1891 }
1892 if (LocaleCompare("level-colors",option+1) == 0)
1893 {
1894 char
1895 token[MaxTextExtent];
1896
1897 const char
1898 *p;
1899
cristy4c08aed2011-07-01 19:47:50 +00001900 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001901 black_point,
1902 white_point;
1903
1904 p=(const char *) argv[i+1];
1905 GetMagickToken(p,&p,token); /* get black point color */
1906 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1907 (void) QueryMagickColor(token,&black_point,exception);
1908 else
1909 (void) QueryMagickColor("#000000",&black_point,exception);
1910 if (isalpha((int) token[0]) || (token[0] == '#'))
1911 GetMagickToken(p,&p,token);
1912 if (*token == '\0')
1913 white_point=black_point; /* set everything to that color */
1914 else
1915 {
1916 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1917 GetMagickToken(p,&p,token); /* Get white point color. */
1918 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1919 (void) QueryMagickColor(token,&white_point,exception);
1920 else
1921 (void) QueryMagickColor("#ffffff",&white_point,exception);
1922 }
cristy490408a2011-07-07 14:42:05 +00001923 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001924 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001925 break;
1926 }
1927 if (LocaleCompare("linear-stretch",option+1) == 0)
1928 {
1929 double
1930 black_point,
1931 white_point;
1932
1933 MagickStatusType
1934 flags;
1935
1936 (void) SyncImageSettings(mogrify_info,*image);
1937 flags=ParseGeometry(argv[i+1],&geometry_info);
1938 black_point=geometry_info.rho;
1939 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1940 if ((flags & SigmaValue) != 0)
1941 white_point=geometry_info.sigma;
1942 if ((flags & PercentValue) != 0)
1943 {
1944 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1945 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1946 }
1947 if ((flags & SigmaValue) == 0)
1948 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1949 black_point;
cristy33bd5152011-08-24 01:42:24 +00001950 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001951 InheritException(exception,&(*image)->exception);
1952 break;
1953 }
1954 if (LocaleCompare("linewidth",option+1) == 0)
1955 {
cristyc1acd842011-05-19 23:05:47 +00001956 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1957 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001958 break;
1959 }
1960 if (LocaleCompare("liquid-rescale",option+1) == 0)
1961 {
1962 /*
1963 Liquid rescale image.
1964 */
1965 (void) SyncImageSettings(mogrify_info,*image);
1966 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1967 if ((flags & XValue) == 0)
1968 geometry.x=1;
1969 if ((flags & YValue) == 0)
1970 geometry.y=0;
1971 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1972 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1973 break;
1974 }
1975 if (LocaleCompare("lowlight-color",option+1) == 0)
1976 {
1977 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1978 break;
1979 }
1980 break;
1981 }
1982 case 'm':
1983 {
1984 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001985 {
cristy3ed852e2009-09-05 21:47:34 +00001986 Image
anthonydf8ebac2011-04-27 09:03:19 +00001987 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001988
anthonydf8ebac2011-04-27 09:03:19 +00001989 /*
1990 Transform image colors to match this set of colors.
1991 */
1992 (void) SyncImageSettings(mogrify_info,*image);
1993 if (*option == '+')
1994 break;
1995 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1996 if (remap_image == (Image *) NULL)
1997 break;
cristy018f07f2011-09-04 21:15:19 +00001998 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001999 remap_image=DestroyImage(remap_image);
2000 break;
2001 }
2002 if (LocaleCompare("mask",option+1) == 0)
2003 {
2004 Image
2005 *mask;
2006
2007 (void) SyncImageSettings(mogrify_info,*image);
2008 if (*option == '+')
2009 {
2010 /*
2011 Remove a mask.
2012 */
cristy018f07f2011-09-04 21:15:19 +00002013 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002014 break;
2015 }
2016 /*
2017 Set the image mask.
2018 */
2019 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2020 if (mask == (Image *) NULL)
2021 break;
cristy018f07f2011-09-04 21:15:19 +00002022 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002023 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002024 break;
2025 }
2026 if (LocaleCompare("matte",option+1) == 0)
2027 {
2028 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002029 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002030 break;
2031 }
2032 if (LocaleCompare("median",option+1) == 0)
2033 {
2034 /*
2035 Median filter image.
2036 */
2037 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002038 flags=ParseGeometry(argv[i+1],&geometry_info);
2039 if ((flags & SigmaValue) == 0)
2040 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002041 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002042 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002043 break;
2044 }
2045 if (LocaleCompare("mode",option+1) == 0)
2046 {
2047 /*
2048 Mode image.
2049 */
2050 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002051 flags=ParseGeometry(argv[i+1],&geometry_info);
2052 if ((flags & SigmaValue) == 0)
2053 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002054 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002055 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002056 break;
2057 }
2058 if (LocaleCompare("modulate",option+1) == 0)
2059 {
2060 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002061 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002062 break;
2063 }
2064 if (LocaleCompare("monitor",option+1) == 0)
2065 {
2066 if (*option == '+')
2067 {
2068 (void) SetImageProgressMonitor(*image,
2069 (MagickProgressMonitor) NULL,(void *) NULL);
2070 break;
2071 }
2072 (void) SetImageProgressMonitor(*image,MonitorProgress,
2073 (void *) NULL);
2074 break;
2075 }
2076 if (LocaleCompare("monochrome",option+1) == 0)
2077 {
2078 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00002079 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002080 break;
2081 }
2082 if (LocaleCompare("morphology",option+1) == 0)
2083 {
2084 char
2085 token[MaxTextExtent];
2086
2087 const char
2088 *p;
2089
2090 KernelInfo
2091 *kernel;
2092
2093 MorphologyMethod
2094 method;
2095
2096 ssize_t
2097 iterations;
2098
2099 /*
2100 Morphological Image Operation
2101 */
2102 (void) SyncImageSettings(mogrify_info,*image);
2103 p=argv[i+1];
2104 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002105 method=(MorphologyMethod) ParseCommandOption(
2106 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002107 iterations=1L;
2108 GetMagickToken(p,&p,token);
2109 if ((*p == ':') || (*p == ','))
2110 GetMagickToken(p,&p,token);
2111 if ((*p != '\0'))
2112 iterations=(ssize_t) StringToLong(p);
2113 kernel=AcquireKernelInfo(argv[i+2]);
2114 if (kernel == (KernelInfo *) NULL)
2115 {
2116 (void) ThrowMagickException(exception,GetMagickModule(),
2117 OptionError,"UnabletoParseKernel","morphology");
2118 status=MagickFalse;
2119 break;
2120 }
cristyf4ad9df2011-07-08 16:49:03 +00002121 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2122 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002123 kernel=DestroyKernelInfo(kernel);
2124 break;
2125 }
2126 if (LocaleCompare("motion-blur",option+1) == 0)
2127 {
2128 /*
2129 Motion blur image.
2130 */
2131 (void) SyncImageSettings(mogrify_info,*image);
2132 flags=ParseGeometry(argv[i+1],&geometry_info);
2133 if ((flags & SigmaValue) == 0)
2134 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002135 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002136 geometry_info.sigma,geometry_info.xi,geometry_info.psi,
2137 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002138 break;
2139 }
2140 break;
2141 }
2142 case 'n':
2143 {
2144 if (LocaleCompare("negate",option+1) == 0)
2145 {
2146 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002147 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002148 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002149 break;
2150 }
2151 if (LocaleCompare("noise",option+1) == 0)
2152 {
2153 (void) SyncImageSettings(mogrify_info,*image);
2154 if (*option == '-')
2155 {
cristyf36cbcb2011-09-07 13:28:22 +00002156 flags=ParseGeometry(argv[i+1],&geometry_info);
2157 if ((flags & SigmaValue) == 0)
2158 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002159 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002160 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002161 }
2162 else
2163 {
2164 NoiseType
2165 noise;
2166
2167 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2168 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002169 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002170 }
2171 break;
2172 }
2173 if (LocaleCompare("normalize",option+1) == 0)
2174 {
2175 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002176 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002177 break;
2178 }
2179 break;
2180 }
2181 case 'o':
2182 {
2183 if (LocaleCompare("opaque",option+1) == 0)
2184 {
cristy4c08aed2011-07-01 19:47:50 +00002185 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002186 target;
2187
2188 (void) SyncImageSettings(mogrify_info,*image);
2189 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002190 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002191 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002192 break;
2193 }
2194 if (LocaleCompare("ordered-dither",option+1) == 0)
2195 {
2196 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002197 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002198 break;
2199 }
2200 break;
2201 }
2202 case 'p':
2203 {
2204 if (LocaleCompare("paint",option+1) == 0)
2205 {
anthonydf8ebac2011-04-27 09:03:19 +00002206 (void) SyncImageSettings(mogrify_info,*image);
2207 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002208 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2209 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002210 break;
2211 }
2212 if (LocaleCompare("pen",option+1) == 0)
2213 {
2214 if (*option == '+')
2215 {
2216 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2217 break;
2218 }
2219 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2220 break;
2221 }
2222 if (LocaleCompare("pointsize",option+1) == 0)
2223 {
2224 if (*option == '+')
2225 (void) ParseGeometry("12",&geometry_info);
2226 else
2227 (void) ParseGeometry(argv[i+1],&geometry_info);
2228 draw_info->pointsize=geometry_info.rho;
2229 break;
2230 }
2231 if (LocaleCompare("polaroid",option+1) == 0)
2232 {
2233 double
2234 angle;
2235
2236 RandomInfo
2237 *random_info;
2238
2239 /*
2240 Simulate a Polaroid picture.
2241 */
2242 (void) SyncImageSettings(mogrify_info,*image);
2243 random_info=AcquireRandomInfo();
2244 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2245 random_info=DestroyRandomInfo(random_info);
2246 if (*option == '-')
2247 {
2248 SetGeometryInfo(&geometry_info);
2249 flags=ParseGeometry(argv[i+1],&geometry_info);
2250 angle=geometry_info.rho;
2251 }
cristy5c4e2582011-09-11 19:21:03 +00002252 mogrify_image=PolaroidImage(*image,draw_info,angle,
cristy28474bf2011-09-11 23:32:52 +00002253 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002254 break;
2255 }
2256 if (LocaleCompare("posterize",option+1) == 0)
2257 {
2258 /*
2259 Posterize image.
2260 */
2261 (void) SyncImageSettings(mogrify_info,*image);
2262 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002263 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002264 break;
2265 }
2266 if (LocaleCompare("preview",option+1) == 0)
2267 {
2268 PreviewType
2269 preview_type;
2270
2271 /*
2272 Preview image.
2273 */
2274 (void) SyncImageSettings(mogrify_info,*image);
2275 if (*option == '+')
2276 preview_type=UndefinedPreview;
2277 else
cristy28474bf2011-09-11 23:32:52 +00002278 preview_type=(PreviewType) ParseCommandOption(
2279 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002280 mogrify_image=PreviewImage(*image,preview_type,exception);
2281 break;
2282 }
2283 if (LocaleCompare("profile",option+1) == 0)
2284 {
2285 const char
2286 *name;
2287
2288 const StringInfo
2289 *profile;
2290
2291 Image
2292 *profile_image;
2293
2294 ImageInfo
2295 *profile_info;
2296
2297 (void) SyncImageSettings(mogrify_info,*image);
2298 if (*option == '+')
2299 {
2300 /*
2301 Remove a profile from the image.
2302 */
2303 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2304 NULL,0,MagickTrue);
2305 InheritException(exception,&(*image)->exception);
2306 break;
2307 }
2308 /*
2309 Associate a profile with the image.
2310 */
2311 profile_info=CloneImageInfo(mogrify_info);
2312 profile=GetImageProfile(*image,"iptc");
2313 if (profile != (StringInfo *) NULL)
2314 profile_info->profile=(void *) CloneStringInfo(profile);
2315 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2316 profile_info=DestroyImageInfo(profile_info);
2317 if (profile_image == (Image *) NULL)
2318 {
2319 StringInfo
2320 *profile;
2321
2322 profile_info=CloneImageInfo(mogrify_info);
2323 (void) CopyMagickString(profile_info->filename,argv[i+1],
2324 MaxTextExtent);
2325 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2326 if (profile != (StringInfo *) NULL)
2327 {
2328 (void) ProfileImage(*image,profile_info->magick,
2329 GetStringInfoDatum(profile),(size_t)
2330 GetStringInfoLength(profile),MagickFalse);
2331 profile=DestroyStringInfo(profile);
2332 }
2333 profile_info=DestroyImageInfo(profile_info);
2334 break;
2335 }
2336 ResetImageProfileIterator(profile_image);
2337 name=GetNextImageProfile(profile_image);
2338 while (name != (const char *) NULL)
2339 {
2340 profile=GetImageProfile(profile_image,name);
2341 if (profile != (StringInfo *) NULL)
2342 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2343 (size_t) GetStringInfoLength(profile),MagickFalse);
2344 name=GetNextImageProfile(profile_image);
2345 }
2346 profile_image=DestroyImage(profile_image);
2347 break;
2348 }
2349 break;
2350 }
2351 case 'q':
2352 {
2353 if (LocaleCompare("quantize",option+1) == 0)
2354 {
2355 if (*option == '+')
2356 {
2357 quantize_info->colorspace=UndefinedColorspace;
2358 break;
2359 }
2360 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2361 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2362 break;
2363 }
2364 break;
2365 }
2366 case 'r':
2367 {
2368 if (LocaleCompare("radial-blur",option+1) == 0)
2369 {
2370 /*
2371 Radial blur image.
2372 */
2373 (void) SyncImageSettings(mogrify_info,*image);
cristy6435bd92011-09-10 02:10:07 +00002374 flags=ParseGeometry(argv[i+1],&geometry_info);
2375 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2376 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002377 break;
2378 }
2379 if (LocaleCompare("raise",option+1) == 0)
2380 {
2381 /*
2382 Surround image with a raise of solid color.
2383 */
2384 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2385 if ((flags & SigmaValue) == 0)
2386 geometry.height=geometry.width;
2387 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002388 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002389 break;
2390 }
2391 if (LocaleCompare("random-threshold",option+1) == 0)
2392 {
2393 /*
2394 Threshold image.
2395 */
2396 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002397 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002398 break;
2399 }
2400 if (LocaleCompare("recolor",option+1) == 0)
2401 {
2402 KernelInfo
2403 *kernel;
2404
2405 (void) SyncImageSettings(mogrify_info,*image);
2406 kernel=AcquireKernelInfo(argv[i+1]);
2407 if (kernel == (KernelInfo *) NULL)
2408 break;
2409 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2410 kernel=DestroyKernelInfo(kernel);
2411 break;
2412 }
2413 if (LocaleCompare("region",option+1) == 0)
2414 {
2415 (void) SyncImageSettings(mogrify_info,*image);
2416 if (region_image != (Image *) NULL)
2417 {
2418 /*
2419 Composite region.
2420 */
2421 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002422 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2423 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002424 InheritException(exception,&region_image->exception);
2425 *image=DestroyImage(*image);
2426 *image=region_image;
2427 region_image = (Image *) NULL;
2428 }
2429 if (*option == '+')
2430 break;
2431 /*
2432 Apply transformations to a selected region of the image.
2433 */
cristy3ed852e2009-09-05 21:47:34 +00002434 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2435 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002436 mogrify_image=CropImage(*image,&region_geometry,exception);
2437 if (mogrify_image == (Image *) NULL)
2438 break;
2439 region_image=(*image);
2440 *image=mogrify_image;
2441 mogrify_image=(Image *) NULL;
2442 break;
cristy3ed852e2009-09-05 21:47:34 +00002443 }
anthonydf8ebac2011-04-27 09:03:19 +00002444 if (LocaleCompare("render",option+1) == 0)
2445 {
2446 (void) SyncImageSettings(mogrify_info,*image);
2447 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2448 break;
2449 }
2450 if (LocaleCompare("remap",option+1) == 0)
2451 {
2452 Image
2453 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002454
anthonydf8ebac2011-04-27 09:03:19 +00002455 /*
2456 Transform image colors to match this set of colors.
2457 */
2458 (void) SyncImageSettings(mogrify_info,*image);
2459 if (*option == '+')
2460 break;
2461 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2462 if (remap_image == (Image *) NULL)
2463 break;
cristy018f07f2011-09-04 21:15:19 +00002464 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002465 remap_image=DestroyImage(remap_image);
2466 break;
2467 }
2468 if (LocaleCompare("repage",option+1) == 0)
2469 {
2470 if (*option == '+')
2471 {
2472 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2473 break;
2474 }
2475 (void) ResetImagePage(*image,argv[i+1]);
2476 InheritException(exception,&(*image)->exception);
2477 break;
2478 }
2479 if (LocaleCompare("resample",option+1) == 0)
2480 {
2481 /*
2482 Resample image.
2483 */
2484 (void) SyncImageSettings(mogrify_info,*image);
2485 flags=ParseGeometry(argv[i+1],&geometry_info);
2486 if ((flags & SigmaValue) == 0)
2487 geometry_info.sigma=geometry_info.rho;
2488 mogrify_image=ResampleImage(*image,geometry_info.rho,
2489 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2490 break;
2491 }
2492 if (LocaleCompare("resize",option+1) == 0)
2493 {
2494 /*
2495 Resize image.
2496 */
2497 (void) SyncImageSettings(mogrify_info,*image);
2498 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2499 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2500 (*image)->filter,(*image)->blur,exception);
2501 break;
2502 }
2503 if (LocaleCompare("roll",option+1) == 0)
2504 {
2505 /*
2506 Roll image.
2507 */
2508 (void) SyncImageSettings(mogrify_info,*image);
2509 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2510 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2511 break;
2512 }
2513 if (LocaleCompare("rotate",option+1) == 0)
2514 {
2515 char
2516 *geometry;
2517
2518 /*
2519 Check for conditional image rotation.
2520 */
2521 (void) SyncImageSettings(mogrify_info,*image);
2522 if (strchr(argv[i+1],'>') != (char *) NULL)
2523 if ((*image)->columns <= (*image)->rows)
2524 break;
2525 if (strchr(argv[i+1],'<') != (char *) NULL)
2526 if ((*image)->columns >= (*image)->rows)
2527 break;
2528 /*
2529 Rotate image.
2530 */
2531 geometry=ConstantString(argv[i+1]);
2532 (void) SubstituteString(&geometry,">","");
2533 (void) SubstituteString(&geometry,"<","");
2534 (void) ParseGeometry(geometry,&geometry_info);
2535 geometry=DestroyString(geometry);
2536 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2537 break;
2538 }
2539 break;
2540 }
2541 case 's':
2542 {
2543 if (LocaleCompare("sample",option+1) == 0)
2544 {
2545 /*
2546 Sample image with pixel replication.
2547 */
2548 (void) SyncImageSettings(mogrify_info,*image);
2549 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2550 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2551 exception);
2552 break;
2553 }
2554 if (LocaleCompare("scale",option+1) == 0)
2555 {
2556 /*
2557 Resize image.
2558 */
2559 (void) SyncImageSettings(mogrify_info,*image);
2560 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2561 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2562 exception);
2563 break;
2564 }
2565 if (LocaleCompare("selective-blur",option+1) == 0)
2566 {
2567 /*
2568 Selectively blur pixels within a contrast threshold.
2569 */
2570 (void) SyncImageSettings(mogrify_info,*image);
2571 flags=ParseGeometry(argv[i+1],&geometry_info);
2572 if ((flags & PercentValue) != 0)
2573 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002574 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002575 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002576 break;
2577 }
2578 if (LocaleCompare("separate",option+1) == 0)
2579 {
2580 /*
2581 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002582 */
2583 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002584 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002585 break;
2586 }
2587 if (LocaleCompare("sepia-tone",option+1) == 0)
2588 {
2589 double
2590 threshold;
2591
2592 /*
2593 Sepia-tone image.
2594 */
2595 (void) SyncImageSettings(mogrify_info,*image);
2596 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2597 mogrify_image=SepiaToneImage(*image,threshold,exception);
2598 break;
2599 }
2600 if (LocaleCompare("segment",option+1) == 0)
2601 {
2602 /*
2603 Segment image.
2604 */
2605 (void) SyncImageSettings(mogrify_info,*image);
2606 flags=ParseGeometry(argv[i+1],&geometry_info);
2607 if ((flags & SigmaValue) == 0)
2608 geometry_info.sigma=1.0;
2609 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002610 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2611 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002612 break;
2613 }
2614 if (LocaleCompare("set",option+1) == 0)
2615 {
2616 char
2617 *value;
2618
2619 /*
2620 Set image option.
2621 */
2622 if (*option == '+')
2623 {
2624 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2625 (void) DeleteImageRegistry(argv[i+1]+9);
2626 else
2627 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2628 {
2629 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2630 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2631 }
2632 else
2633 (void) DeleteImageProperty(*image,argv[i+1]);
2634 break;
2635 }
cristy018f07f2011-09-04 21:15:19 +00002636 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2637 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002638 if (value == (char *) NULL)
2639 break;
2640 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2641 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2642 exception);
2643 else
2644 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2645 {
2646 (void) SetImageOption(image_info,argv[i+1]+7,value);
2647 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2648 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2649 }
2650 else
2651 (void) SetImageProperty(*image,argv[i+1],value);
2652 value=DestroyString(value);
2653 break;
2654 }
2655 if (LocaleCompare("shade",option+1) == 0)
2656 {
2657 /*
2658 Shade image.
2659 */
2660 (void) SyncImageSettings(mogrify_info,*image);
2661 flags=ParseGeometry(argv[i+1],&geometry_info);
2662 if ((flags & SigmaValue) == 0)
2663 geometry_info.sigma=1.0;
2664 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2665 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2666 break;
2667 }
2668 if (LocaleCompare("shadow",option+1) == 0)
2669 {
2670 /*
2671 Shadow image.
2672 */
2673 (void) SyncImageSettings(mogrify_info,*image);
2674 flags=ParseGeometry(argv[i+1],&geometry_info);
2675 if ((flags & SigmaValue) == 0)
2676 geometry_info.sigma=1.0;
2677 if ((flags & XiValue) == 0)
2678 geometry_info.xi=4.0;
2679 if ((flags & PsiValue) == 0)
2680 geometry_info.psi=4.0;
2681 mogrify_image=ShadowImage(*image,geometry_info.rho,
2682 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2683 ceil(geometry_info.psi-0.5),exception);
2684 break;
2685 }
2686 if (LocaleCompare("sharpen",option+1) == 0)
2687 {
2688 /*
2689 Sharpen image.
2690 */
2691 (void) SyncImageSettings(mogrify_info,*image);
2692 flags=ParseGeometry(argv[i+1],&geometry_info);
2693 if ((flags & SigmaValue) == 0)
2694 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002695 if ((flags & XiValue) == 0)
2696 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002697 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002698 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002699 break;
2700 }
2701 if (LocaleCompare("shave",option+1) == 0)
2702 {
2703 /*
2704 Shave the image edges.
2705 */
2706 (void) SyncImageSettings(mogrify_info,*image);
2707 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2708 mogrify_image=ShaveImage(*image,&geometry,exception);
2709 break;
2710 }
2711 if (LocaleCompare("shear",option+1) == 0)
2712 {
2713 /*
2714 Shear image.
2715 */
2716 (void) SyncImageSettings(mogrify_info,*image);
2717 flags=ParseGeometry(argv[i+1],&geometry_info);
2718 if ((flags & SigmaValue) == 0)
2719 geometry_info.sigma=geometry_info.rho;
2720 mogrify_image=ShearImage(*image,geometry_info.rho,
2721 geometry_info.sigma,exception);
2722 break;
2723 }
2724 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2725 {
2726 /*
2727 Sigmoidal non-linearity contrast control.
2728 */
2729 (void) SyncImageSettings(mogrify_info,*image);
2730 flags=ParseGeometry(argv[i+1],&geometry_info);
2731 if ((flags & SigmaValue) == 0)
2732 geometry_info.sigma=(double) QuantumRange/2.0;
2733 if ((flags & PercentValue) != 0)
2734 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2735 100.0;
cristy9ee60942011-07-06 14:54:38 +00002736 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002737 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2738 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002739 break;
2740 }
2741 if (LocaleCompare("sketch",option+1) == 0)
2742 {
2743 /*
2744 Sketch image.
2745 */
2746 (void) SyncImageSettings(mogrify_info,*image);
2747 flags=ParseGeometry(argv[i+1],&geometry_info);
2748 if ((flags & SigmaValue) == 0)
2749 geometry_info.sigma=1.0;
2750 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002751 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002752 break;
2753 }
2754 if (LocaleCompare("solarize",option+1) == 0)
2755 {
2756 double
2757 threshold;
2758
2759 (void) SyncImageSettings(mogrify_info,*image);
2760 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002761 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002762 break;
2763 }
2764 if (LocaleCompare("sparse-color",option+1) == 0)
2765 {
2766 SparseColorMethod
2767 method;
2768
2769 char
2770 *arguments;
2771
2772 /*
2773 Sparse Color Interpolated Gradient
2774 */
2775 (void) SyncImageSettings(mogrify_info,*image);
2776 method=(SparseColorMethod) ParseCommandOption(
2777 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002778 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2779 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002780 if (arguments == (char *) NULL)
2781 break;
cristy3884f692011-07-08 18:00:18 +00002782 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002783 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2784 arguments=DestroyString(arguments);
2785 break;
2786 }
2787 if (LocaleCompare("splice",option+1) == 0)
2788 {
2789 /*
2790 Splice a solid color into the image.
2791 */
2792 (void) SyncImageSettings(mogrify_info,*image);
2793 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2794 mogrify_image=SpliceImage(*image,&geometry,exception);
2795 break;
2796 }
2797 if (LocaleCompare("spread",option+1) == 0)
2798 {
2799 /*
2800 Spread an image.
2801 */
2802 (void) SyncImageSettings(mogrify_info,*image);
2803 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002804 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002805 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002806 break;
2807 }
2808 if (LocaleCompare("statistic",option+1) == 0)
2809 {
2810 StatisticType
2811 type;
2812
2813 (void) SyncImageSettings(mogrify_info,*image);
2814 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2815 MagickFalse,argv[i+1]);
2816 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002817 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2818 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002819 break;
2820 }
2821 if (LocaleCompare("stretch",option+1) == 0)
2822 {
2823 if (*option == '+')
2824 {
2825 draw_info->stretch=UndefinedStretch;
2826 break;
2827 }
2828 draw_info->stretch=(StretchType) ParseCommandOption(
2829 MagickStretchOptions,MagickFalse,argv[i+1]);
2830 break;
2831 }
2832 if (LocaleCompare("strip",option+1) == 0)
2833 {
2834 /*
2835 Strip image of profiles and comments.
2836 */
2837 (void) SyncImageSettings(mogrify_info,*image);
2838 (void) StripImage(*image);
2839 InheritException(exception,&(*image)->exception);
2840 break;
2841 }
2842 if (LocaleCompare("stroke",option+1) == 0)
2843 {
2844 ExceptionInfo
2845 *sans;
2846
2847 if (*option == '+')
2848 {
2849 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2850 if (draw_info->stroke_pattern != (Image *) NULL)
2851 draw_info->stroke_pattern=DestroyImage(
2852 draw_info->stroke_pattern);
2853 break;
2854 }
2855 sans=AcquireExceptionInfo();
2856 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2857 sans=DestroyExceptionInfo(sans);
2858 if (status == MagickFalse)
2859 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2860 exception);
2861 break;
2862 }
2863 if (LocaleCompare("strokewidth",option+1) == 0)
2864 {
cristyc1acd842011-05-19 23:05:47 +00002865 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2866 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002867 break;
2868 }
2869 if (LocaleCompare("style",option+1) == 0)
2870 {
2871 if (*option == '+')
2872 {
2873 draw_info->style=UndefinedStyle;
2874 break;
2875 }
2876 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2877 MagickFalse,argv[i+1]);
2878 break;
2879 }
2880 if (LocaleCompare("swirl",option+1) == 0)
2881 {
2882 /*
2883 Swirl image.
2884 */
2885 (void) SyncImageSettings(mogrify_info,*image);
2886 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002887 mogrify_image=SwirlImage(*image,geometry_info.rho,
2888 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002889 break;
2890 }
2891 break;
2892 }
2893 case 't':
2894 {
2895 if (LocaleCompare("threshold",option+1) == 0)
2896 {
2897 double
2898 threshold;
2899
2900 /*
2901 Threshold image.
2902 */
2903 (void) SyncImageSettings(mogrify_info,*image);
2904 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002905 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002906 else
2907 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002908 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002909 InheritException(exception,&(*image)->exception);
2910 break;
2911 }
2912 if (LocaleCompare("thumbnail",option+1) == 0)
2913 {
2914 /*
2915 Thumbnail image.
2916 */
2917 (void) SyncImageSettings(mogrify_info,*image);
2918 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2919 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2920 exception);
2921 break;
2922 }
2923 if (LocaleCompare("tile",option+1) == 0)
2924 {
2925 if (*option == '+')
2926 {
2927 if (draw_info->fill_pattern != (Image *) NULL)
2928 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2929 break;
2930 }
2931 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2932 exception);
2933 break;
2934 }
2935 if (LocaleCompare("tint",option+1) == 0)
2936 {
2937 /*
2938 Tint the image.
2939 */
2940 (void) SyncImageSettings(mogrify_info,*image);
cristy28474bf2011-09-11 23:32:52 +00002941 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002942 break;
2943 }
2944 if (LocaleCompare("transform",option+1) == 0)
2945 {
2946 /*
2947 Affine transform image.
2948 */
2949 (void) SyncImageSettings(mogrify_info,*image);
2950 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2951 exception);
2952 break;
2953 }
2954 if (LocaleCompare("transparent",option+1) == 0)
2955 {
cristy4c08aed2011-07-01 19:47:50 +00002956 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002957 target;
2958
2959 (void) SyncImageSettings(mogrify_info,*image);
2960 (void) QueryMagickColor(argv[i+1],&target,exception);
2961 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002962 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2963 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002964 break;
2965 }
2966 if (LocaleCompare("transpose",option+1) == 0)
2967 {
2968 /*
2969 Transpose image scanlines.
2970 */
2971 (void) SyncImageSettings(mogrify_info,*image);
2972 mogrify_image=TransposeImage(*image,exception);
2973 break;
2974 }
2975 if (LocaleCompare("transverse",option+1) == 0)
2976 {
2977 /*
2978 Transverse image scanlines.
2979 */
2980 (void) SyncImageSettings(mogrify_info,*image);
2981 mogrify_image=TransverseImage(*image,exception);
2982 break;
2983 }
2984 if (LocaleCompare("treedepth",option+1) == 0)
2985 {
2986 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2987 break;
2988 }
2989 if (LocaleCompare("trim",option+1) == 0)
2990 {
2991 /*
2992 Trim image.
2993 */
2994 (void) SyncImageSettings(mogrify_info,*image);
2995 mogrify_image=TrimImage(*image,exception);
2996 break;
2997 }
2998 if (LocaleCompare("type",option+1) == 0)
2999 {
3000 ImageType
3001 type;
3002
3003 (void) SyncImageSettings(mogrify_info,*image);
3004 if (*option == '+')
3005 type=UndefinedType;
3006 else
3007 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3008 argv[i+1]);
3009 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003010 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003011 break;
3012 }
3013 break;
3014 }
3015 case 'u':
3016 {
3017 if (LocaleCompare("undercolor",option+1) == 0)
3018 {
3019 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3020 exception);
3021 break;
3022 }
3023 if (LocaleCompare("unique",option+1) == 0)
3024 {
3025 if (*option == '+')
3026 {
3027 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3028 break;
3029 }
3030 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3031 (void) SetImageArtifact(*image,"verbose","true");
3032 break;
3033 }
3034 if (LocaleCompare("unique-colors",option+1) == 0)
3035 {
3036 /*
3037 Unique image colors.
3038 */
3039 (void) SyncImageSettings(mogrify_info,*image);
3040 mogrify_image=UniqueImageColors(*image,exception);
3041 break;
3042 }
3043 if (LocaleCompare("unsharp",option+1) == 0)
3044 {
3045 /*
3046 Unsharp mask image.
3047 */
3048 (void) SyncImageSettings(mogrify_info,*image);
3049 flags=ParseGeometry(argv[i+1],&geometry_info);
3050 if ((flags & SigmaValue) == 0)
3051 geometry_info.sigma=1.0;
3052 if ((flags & XiValue) == 0)
3053 geometry_info.xi=1.0;
3054 if ((flags & PsiValue) == 0)
3055 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003056 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3057 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003058 break;
3059 }
3060 break;
3061 }
3062 case 'v':
3063 {
3064 if (LocaleCompare("verbose",option+1) == 0)
3065 {
3066 (void) SetImageArtifact(*image,option+1,
3067 *option == '+' ? "false" : "true");
3068 break;
3069 }
3070 if (LocaleCompare("vignette",option+1) == 0)
3071 {
3072 /*
3073 Vignette image.
3074 */
3075 (void) SyncImageSettings(mogrify_info,*image);
3076 flags=ParseGeometry(argv[i+1],&geometry_info);
3077 if ((flags & SigmaValue) == 0)
3078 geometry_info.sigma=1.0;
3079 if ((flags & XiValue) == 0)
3080 geometry_info.xi=0.1*(*image)->columns;
3081 if ((flags & PsiValue) == 0)
3082 geometry_info.psi=0.1*(*image)->rows;
3083 mogrify_image=VignetteImage(*image,geometry_info.rho,
3084 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3085 ceil(geometry_info.psi-0.5),exception);
3086 break;
3087 }
3088 if (LocaleCompare("virtual-pixel",option+1) == 0)
3089 {
3090 if (*option == '+')
3091 {
3092 (void) SetImageVirtualPixelMethod(*image,
3093 UndefinedVirtualPixelMethod);
3094 break;
3095 }
3096 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3097 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3098 argv[i+1]));
3099 break;
3100 }
3101 break;
3102 }
3103 case 'w':
3104 {
3105 if (LocaleCompare("wave",option+1) == 0)
3106 {
3107 /*
3108 Wave image.
3109 */
3110 (void) SyncImageSettings(mogrify_info,*image);
3111 flags=ParseGeometry(argv[i+1],&geometry_info);
3112 if ((flags & SigmaValue) == 0)
3113 geometry_info.sigma=1.0;
3114 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003115 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003116 break;
3117 }
3118 if (LocaleCompare("weight",option+1) == 0)
3119 {
3120 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3121 if (LocaleCompare(argv[i+1],"all") == 0)
3122 draw_info->weight=0;
3123 if (LocaleCompare(argv[i+1],"bold") == 0)
3124 draw_info->weight=700;
3125 if (LocaleCompare(argv[i+1],"bolder") == 0)
3126 if (draw_info->weight <= 800)
3127 draw_info->weight+=100;
3128 if (LocaleCompare(argv[i+1],"lighter") == 0)
3129 if (draw_info->weight >= 100)
3130 draw_info->weight-=100;
3131 if (LocaleCompare(argv[i+1],"normal") == 0)
3132 draw_info->weight=400;
3133 break;
3134 }
3135 if (LocaleCompare("white-threshold",option+1) == 0)
3136 {
3137 /*
3138 White threshold image.
3139 */
3140 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003141 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003142 InheritException(exception,&(*image)->exception);
3143 break;
3144 }
3145 break;
3146 }
3147 default:
3148 break;
3149 }
3150 /*
3151 Replace current image with any image that was generated
3152 */
3153 if (mogrify_image != (Image *) NULL)
3154 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003155 i+=count;
3156 }
3157 if (region_image != (Image *) NULL)
3158 {
anthonydf8ebac2011-04-27 09:03:19 +00003159 /*
3160 Composite transformed region onto image.
3161 */
cristy6b3da3a2010-06-20 02:21:46 +00003162 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003163 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003164 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3165 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003166 InheritException(exception,&region_image->exception);
3167 *image=DestroyImage(*image);
3168 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003169 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003170 }
3171 /*
3172 Free resources.
3173 */
anthonydf8ebac2011-04-27 09:03:19 +00003174 quantize_info=DestroyQuantizeInfo(quantize_info);
3175 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003176 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003177 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003178 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003179 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003180}
3181
3182/*
3183%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3184% %
3185% %
3186% %
cristy5063d812010-10-19 16:28:10 +00003187+ 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 +00003188% %
3189% %
3190% %
3191%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3192%
3193% MogrifyImageCommand() transforms an image or a sequence of images. These
3194% transforms include image scaling, image rotation, color reduction, and
3195% others. The transmogrified image overwrites the original image.
3196%
3197% The format of the MogrifyImageCommand method is:
3198%
3199% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3200% const char **argv,char **metadata,ExceptionInfo *exception)
3201%
3202% A description of each parameter follows:
3203%
3204% o image_info: the image info.
3205%
3206% o argc: the number of elements in the argument vector.
3207%
3208% o argv: A text array containing the command line arguments.
3209%
3210% o metadata: any metadata is returned here.
3211%
3212% o exception: return any errors or warnings in this structure.
3213%
3214*/
3215
3216static MagickBooleanType MogrifyUsage(void)
3217{
3218 static const char
3219 *miscellaneous[]=
3220 {
3221 "-debug events display copious debugging information",
3222 "-help print program options",
3223 "-list type print a list of supported option arguments",
3224 "-log format format of debugging information",
3225 "-version print version information",
3226 (char *) NULL
3227 },
3228 *operators[]=
3229 {
3230 "-adaptive-blur geometry",
3231 " adaptively blur pixels; decrease effect near edges",
3232 "-adaptive-resize geometry",
3233 " adaptively resize image using 'mesh' interpolation",
3234 "-adaptive-sharpen geometry",
3235 " adaptively sharpen pixels; increase effect near edges",
3236 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3237 " transparent, extract, background, or shape",
3238 "-annotate geometry text",
3239 " annotate the image with text",
3240 "-auto-gamma automagically adjust gamma level of image",
3241 "-auto-level automagically adjust color levels of image",
3242 "-auto-orient automagically orient (rotate) image",
3243 "-bench iterations measure performance",
3244 "-black-threshold value",
3245 " force all pixels below the threshold into black",
3246 "-blue-shift simulate a scene at nighttime in the moonlight",
3247 "-blur geometry reduce image noise and reduce detail levels",
3248 "-border geometry surround image with a border of color",
3249 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003250 "-brightness-contrast geometry",
3251 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003252 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003253 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003254 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003255 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003256 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003257 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003258 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003259 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003260 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003261 "-contrast enhance or reduce the image contrast",
3262 "-contrast-stretch geometry",
3263 " improve contrast by `stretching' the intensity range",
3264 "-convolve coefficients",
3265 " apply a convolution kernel to the image",
3266 "-cycle amount cycle the image colormap",
3267 "-decipher filename convert cipher pixels to plain pixels",
3268 "-deskew threshold straighten an image",
3269 "-despeckle reduce the speckles within an image",
3270 "-distort method args",
3271 " distort images according to given method ad args",
3272 "-draw string annotate the image with a graphic primitive",
3273 "-edge radius apply a filter to detect edges in the image",
3274 "-encipher filename convert plain pixels to cipher pixels",
3275 "-emboss radius emboss an image",
3276 "-enhance apply a digital filter to enhance a noisy image",
3277 "-equalize perform histogram equalization to an image",
3278 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003279 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003280 "-extent geometry set the image size",
3281 "-extract geometry extract area from image",
3282 "-fft implements the discrete Fourier transform (DFT)",
3283 "-flip flip image vertically",
3284 "-floodfill geometry color",
3285 " floodfill the image with color",
3286 "-flop flop image horizontally",
3287 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003288 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003289 " apply function over image values",
3290 "-gamma value level of gamma correction",
3291 "-gaussian-blur geometry",
3292 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003293 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003294 "-identify identify the format and characteristics of the image",
3295 "-ift implements the inverse discrete Fourier transform (DFT)",
3296 "-implode amount implode image pixels about the center",
3297 "-lat geometry local adaptive thresholding",
3298 "-layers method optimize, merge, or compare image layers",
3299 "-level value adjust the level of image contrast",
3300 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003301 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003302 "-linear-stretch geometry",
3303 " improve contrast by `stretching with saturation'",
3304 "-liquid-rescale geometry",
3305 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003306 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003307 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003308 "-modulate value vary the brightness, saturation, and hue",
3309 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003310 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003311 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003312 "-motion-blur geometry",
3313 " simulate motion blur",
3314 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003315 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003316 "-normalize transform image to span the full range of colors",
3317 "-opaque color change this color to the fill color",
3318 "-ordered-dither NxN",
3319 " add a noise pattern to the image with specific",
3320 " amplitudes",
3321 "-paint radius simulate an oil painting",
3322 "-polaroid angle simulate a Polaroid picture",
3323 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003324 "-profile filename add, delete, or apply an image profile",
3325 "-quantize colorspace reduce colors in this colorspace",
3326 "-radial-blur angle radial blur the image",
3327 "-raise value lighten/darken image edges to create a 3-D effect",
3328 "-random-threshold low,high",
3329 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003330 "-region geometry apply options to a portion of the image",
3331 "-render render vector graphics",
3332 "-repage geometry size and location of an image canvas",
3333 "-resample geometry change the resolution of an image",
3334 "-resize geometry resize the image",
3335 "-roll geometry roll an image vertically or horizontally",
3336 "-rotate degrees apply Paeth rotation to the image",
3337 "-sample geometry scale image with pixel sampling",
3338 "-scale geometry scale the image",
3339 "-segment values segment an image",
3340 "-selective-blur geometry",
3341 " selectively blur pixels within a contrast threshold",
3342 "-sepia-tone threshold",
3343 " simulate a sepia-toned photo",
3344 "-set property value set an image property",
3345 "-shade degrees shade the image using a distant light source",
3346 "-shadow geometry simulate an image shadow",
3347 "-sharpen geometry sharpen the image",
3348 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003349 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003350 "-sigmoidal-contrast geometry",
3351 " increase the contrast without saturating highlights or shadows",
3352 "-sketch geometry simulate a pencil sketch",
3353 "-solarize threshold negate all pixels above the threshold level",
3354 "-sparse-color method args",
3355 " fill in a image based on a few color points",
3356 "-splice geometry splice the background color into the image",
3357 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003358 "-statistic type radius",
3359 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003360 "-strip strip image of all profiles and comments",
3361 "-swirl degrees swirl image pixels about the center",
3362 "-threshold value threshold the image",
3363 "-thumbnail geometry create a thumbnail of the image",
3364 "-tile filename tile image when filling a graphic primitive",
3365 "-tint value tint the image with the fill color",
3366 "-transform affine transform image",
3367 "-transparent color make this color transparent within the image",
3368 "-transpose flip image vertically and rotate 90 degrees",
3369 "-transverse flop image horizontally and rotate 270 degrees",
3370 "-trim trim image edges",
3371 "-type type image type",
3372 "-unique-colors discard all but one of any pixel color",
3373 "-unsharp geometry sharpen the image",
3374 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003375 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003376 "-white-threshold value",
3377 " force all pixels above the threshold into white",
3378 (char *) NULL
3379 },
3380 *sequence_operators[]=
3381 {
cristy4285d782011-02-09 20:12:28 +00003382 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003383 "-clut apply a color lookup table to the image",
3384 "-coalesce merge a sequence of images",
3385 "-combine combine a sequence of images",
3386 "-composite composite image",
3387 "-crop geometry cut out a rectangular region of the image",
3388 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003389 "-evaluate-sequence operator",
3390 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003391 "-flatten flatten a sequence of images",
3392 "-fx expression apply mathematical expression to an image channel(s)",
3393 "-hald-clut apply a Hald color lookup table to the image",
3394 "-morph value morph an image sequence",
3395 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003396 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003397 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003398 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003399 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003400 "-write filename write images to this file",
3401 (char *) NULL
3402 },
3403 *settings[]=
3404 {
3405 "-adjoin join images into a single multi-image file",
3406 "-affine matrix affine transform matrix",
3407 "-alpha option activate, deactivate, reset, or set the alpha channel",
3408 "-antialias remove pixel-aliasing",
3409 "-authenticate password",
3410 " decipher image with this password",
3411 "-attenuate value lessen (or intensify) when adding noise to an image",
3412 "-background color background color",
3413 "-bias value add bias when convolving an image",
3414 "-black-point-compensation",
3415 " use black point compensation",
3416 "-blue-primary point chromaticity blue primary point",
3417 "-bordercolor color border color",
3418 "-caption string assign a caption to an image",
3419 "-channel type apply option to select image channels",
3420 "-colors value preferred number of colors in the image",
3421 "-colorspace type alternate image colorspace",
3422 "-comment string annotate image with comment",
3423 "-compose operator set image composite operator",
3424 "-compress type type of pixel compression when writing the image",
3425 "-define format:option",
3426 " define one or more image format options",
3427 "-delay value display the next image after pausing",
3428 "-density geometry horizontal and vertical density of the image",
3429 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003430 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003431 "-display server get image or font from this X server",
3432 "-dispose method layer disposal method",
3433 "-dither method apply error diffusion to image",
3434 "-encoding type text encoding type",
3435 "-endian type endianness (MSB or LSB) of the image",
3436 "-family name render text with this font family",
3437 "-fill color color to use when filling a graphic primitive",
3438 "-filter type use this filter when resizing an image",
3439 "-font name render text with this font",
3440 "-format \"string\" output formatted image characteristics",
3441 "-fuzz distance colors within this distance are considered equal",
3442 "-gravity type horizontal and vertical text placement",
3443 "-green-primary point chromaticity green primary point",
3444 "-intent type type of rendering intent when managing the image color",
3445 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003446 "-interline-spacing value",
3447 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003448 "-interpolate method pixel color interpolation method",
3449 "-interword-spacing value",
3450 " set the space between two words",
3451 "-kerning value set the space between two letters",
3452 "-label string assign a label to an image",
3453 "-limit type value pixel cache resource limit",
3454 "-loop iterations add Netscape loop extension to your GIF animation",
3455 "-mask filename associate a mask with the image",
3456 "-mattecolor color frame color",
3457 "-monitor monitor progress",
3458 "-orient type image orientation",
3459 "-page geometry size and location of an image canvas (setting)",
3460 "-ping efficiently determine image attributes",
3461 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003462 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003463 "-preview type image preview type",
3464 "-quality value JPEG/MIFF/PNG compression level",
3465 "-quiet suppress all warning messages",
3466 "-red-primary point chromaticity red primary point",
3467 "-regard-warnings pay attention to warning messages",
3468 "-remap filename transform image colors to match this set of colors",
3469 "-respect-parentheses settings remain in effect until parenthesis boundary",
3470 "-sampling-factor geometry",
3471 " horizontal and vertical sampling factor",
3472 "-scene value image scene number",
3473 "-seed value seed a new sequence of pseudo-random numbers",
3474 "-size geometry width and height of image",
3475 "-stretch type render text with this font stretch",
3476 "-stroke color graphic primitive stroke color",
3477 "-strokewidth value graphic primitive stroke width",
3478 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003479 "-synchronize synchronize image to storage device",
3480 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003481 "-texture filename name of texture to tile onto the image background",
3482 "-tile-offset geometry",
3483 " tile offset",
3484 "-treedepth value color tree depth",
3485 "-transparent-color color",
3486 " transparent color",
3487 "-undercolor color annotation bounding box color",
3488 "-units type the units of image resolution",
3489 "-verbose print detailed information about the image",
3490 "-view FlashPix viewing transforms",
3491 "-virtual-pixel method",
3492 " virtual pixel access method",
3493 "-weight type render text with this font weight",
3494 "-white-point point chromaticity white point",
3495 (char *) NULL
3496 },
3497 *stack_operators[]=
3498 {
anthonyb69c4b32011-03-23 04:37:44 +00003499 "-delete indexes delete the image from the image sequence",
3500 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003501 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003502 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003503 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003504 "-swap indexes swap two images in the image sequence",
3505 (char *) NULL
3506 };
3507
3508 const char
3509 **p;
3510
cristybb503372010-05-27 20:51:26 +00003511 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003512 (void) printf("Copyright: %s\n",GetMagickCopyright());
3513 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003514 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3515 GetClientName());
3516 (void) printf("\nImage Settings:\n");
3517 for (p=settings; *p != (char *) NULL; p++)
3518 (void) printf(" %s\n",*p);
3519 (void) printf("\nImage Operators:\n");
3520 for (p=operators; *p != (char *) NULL; p++)
3521 (void) printf(" %s\n",*p);
3522 (void) printf("\nImage Sequence Operators:\n");
3523 for (p=sequence_operators; *p != (char *) NULL; p++)
3524 (void) printf(" %s\n",*p);
3525 (void) printf("\nImage Stack Operators:\n");
3526 for (p=stack_operators; *p != (char *) NULL; p++)
3527 (void) printf(" %s\n",*p);
3528 (void) printf("\nMiscellaneous Options:\n");
3529 for (p=miscellaneous; *p != (char *) NULL; p++)
3530 (void) printf(" %s\n",*p);
3531 (void) printf(
3532 "\nBy default, the image format of `file' is determined by its magic\n");
3533 (void) printf(
3534 "number. To specify a particular image format, precede the filename\n");
3535 (void) printf(
3536 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3537 (void) printf(
3538 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3539 (void) printf("'-' for standard input or output.\n");
3540 return(MagickFalse);
3541}
3542
3543WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3544 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3545{
3546#define DestroyMogrify() \
3547{ \
3548 if (format != (char *) NULL) \
3549 format=DestroyString(format); \
3550 if (path != (char *) NULL) \
3551 path=DestroyString(path); \
3552 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003553 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003554 argv[i]=DestroyString(argv[i]); \
3555 argv=(char **) RelinquishMagickMemory(argv); \
3556}
3557#define ThrowMogrifyException(asperity,tag,option) \
3558{ \
3559 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3560 option); \
3561 DestroyMogrify(); \
3562 return(MagickFalse); \
3563}
3564#define ThrowMogrifyInvalidArgumentException(option,argument) \
3565{ \
3566 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3567 "InvalidArgument","`%s': %s",argument,option); \
3568 DestroyMogrify(); \
3569 return(MagickFalse); \
3570}
3571
3572 char
3573 *format,
3574 *option,
3575 *path;
3576
3577 Image
3578 *image;
3579
3580 ImageStack
3581 image_stack[MaxImageStackDepth+1];
3582
cristy3ed852e2009-09-05 21:47:34 +00003583 MagickBooleanType
3584 global_colormap;
3585
3586 MagickBooleanType
3587 fire,
cristyebbcfea2011-02-25 02:43:54 +00003588 pend,
3589 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003590
3591 MagickStatusType
3592 status;
3593
cristyebbcfea2011-02-25 02:43:54 +00003594 register ssize_t
3595 i;
3596
3597 ssize_t
3598 j,
3599 k;
3600
cristy3ed852e2009-09-05 21:47:34 +00003601 /*
3602 Set defaults.
3603 */
3604 assert(image_info != (ImageInfo *) NULL);
3605 assert(image_info->signature == MagickSignature);
3606 if (image_info->debug != MagickFalse)
3607 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3608 assert(exception != (ExceptionInfo *) NULL);
3609 if (argc == 2)
3610 {
3611 option=argv[1];
3612 if ((LocaleCompare("version",option+1) == 0) ||
3613 (LocaleCompare("-version",option+1) == 0))
3614 {
cristyb51dff52011-05-19 16:55:47 +00003615 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003616 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003617 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3618 GetMagickCopyright());
3619 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3620 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003621 return(MagickFalse);
3622 }
3623 }
3624 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003625 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003626 format=(char *) NULL;
3627 path=(char *) NULL;
3628 global_colormap=MagickFalse;
3629 k=0;
3630 j=1;
3631 NewImageStack();
3632 option=(char *) NULL;
3633 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003634 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003635 status=MagickTrue;
3636 /*
3637 Parse command line.
3638 */
3639 ReadCommandlLine(argc,&argv);
3640 status=ExpandFilenames(&argc,&argv);
3641 if (status == MagickFalse)
3642 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3643 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003644 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003645 {
3646 option=argv[i];
3647 if (LocaleCompare(option,"(") == 0)
3648 {
3649 FireImageStack(MagickFalse,MagickTrue,pend);
3650 if (k == MaxImageStackDepth)
3651 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3652 option);
3653 PushImageStack();
3654 continue;
3655 }
3656 if (LocaleCompare(option,")") == 0)
3657 {
3658 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3659 if (k == 0)
3660 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3661 PopImageStack();
3662 continue;
3663 }
cristy042ee782011-04-22 18:48:30 +00003664 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003665 {
3666 char
3667 backup_filename[MaxTextExtent],
3668 *filename;
3669
3670 Image
3671 *images;
3672
3673 /*
3674 Option is a file name: begin by reading image from specified file.
3675 */
3676 FireImageStack(MagickFalse,MagickFalse,pend);
3677 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003678 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003679 filename=argv[++i];
3680 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3681 images=ReadImages(image_info,exception);
3682 status&=(images != (Image *) NULL) &&
3683 (exception->severity < ErrorException);
3684 if (images == (Image *) NULL)
3685 continue;
cristydaa76602010-06-30 13:05:11 +00003686 if (format != (char *) NULL)
3687 (void) CopyMagickString(images->filename,images->magick_filename,
3688 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003689 if (path != (char *) NULL)
3690 {
3691 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003692 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003693 path,*DirectorySeparator,filename);
3694 }
3695 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003696 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003697 AppendImageStack(images);
3698 FinalizeImageSettings(image_info,image,MagickFalse);
3699 if (global_colormap != MagickFalse)
3700 {
3701 QuantizeInfo
3702 *quantize_info;
3703
3704 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003705 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003706 quantize_info=DestroyQuantizeInfo(quantize_info);
3707 }
3708 *backup_filename='\0';
3709 if ((LocaleCompare(image->filename,"-") != 0) &&
3710 (IsPathWritable(image->filename) != MagickFalse))
3711 {
cristybb503372010-05-27 20:51:26 +00003712 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003713 i;
3714
3715 /*
3716 Rename image file as backup.
3717 */
3718 (void) CopyMagickString(backup_filename,image->filename,
3719 MaxTextExtent);
3720 for (i=0; i < 6; i++)
3721 {
3722 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3723 if (IsPathAccessible(backup_filename) == MagickFalse)
3724 break;
3725 }
3726 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3727 (rename(image->filename,backup_filename) != 0))
3728 *backup_filename='\0';
3729 }
3730 /*
3731 Write transmogrified image to disk.
3732 */
3733 image_info->synchronize=MagickTrue;
3734 status&=WriteImages(image_info,image,image->filename,exception);
3735 if ((status == MagickFalse) && (*backup_filename != '\0'))
3736 (void) remove(backup_filename);
3737 RemoveAllImageStack();
3738 continue;
3739 }
3740 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3741 switch (*(option+1))
3742 {
3743 case 'a':
3744 {
3745 if (LocaleCompare("adaptive-blur",option+1) == 0)
3746 {
3747 i++;
cristybb503372010-05-27 20:51:26 +00003748 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003749 ThrowMogrifyException(OptionError,"MissingArgument",option);
3750 if (IsGeometry(argv[i]) == MagickFalse)
3751 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3752 break;
3753 }
3754 if (LocaleCompare("adaptive-resize",option+1) == 0)
3755 {
3756 i++;
cristybb503372010-05-27 20:51:26 +00003757 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003758 ThrowMogrifyException(OptionError,"MissingArgument",option);
3759 if (IsGeometry(argv[i]) == MagickFalse)
3760 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3761 break;
3762 }
3763 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3764 {
3765 i++;
cristybb503372010-05-27 20:51:26 +00003766 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003767 ThrowMogrifyException(OptionError,"MissingArgument",option);
3768 if (IsGeometry(argv[i]) == MagickFalse)
3769 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3770 break;
3771 }
3772 if (LocaleCompare("affine",option+1) == 0)
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);
cristy3ed852e2009-09-05 21:47:34 +00003779 break;
3780 }
3781 if (LocaleCompare("alpha",option+1) == 0)
3782 {
cristybb503372010-05-27 20:51:26 +00003783 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003784 type;
3785
3786 if (*option == '+')
3787 break;
3788 i++;
cristybb503372010-05-27 20:51:26 +00003789 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003790 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003791 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003792 if (type < 0)
3793 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3794 argv[i]);
3795 break;
3796 }
3797 if (LocaleCompare("annotate",option+1) == 0)
3798 {
3799 if (*option == '+')
3800 break;
3801 i++;
cristybb503372010-05-27 20:51:26 +00003802 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003803 ThrowMogrifyException(OptionError,"MissingArgument",option);
3804 if (IsGeometry(argv[i]) == MagickFalse)
3805 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003806 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003807 ThrowMogrifyException(OptionError,"MissingArgument",option);
3808 i++;
3809 break;
3810 }
3811 if (LocaleCompare("antialias",option+1) == 0)
3812 break;
3813 if (LocaleCompare("append",option+1) == 0)
3814 break;
3815 if (LocaleCompare("attenuate",option+1) == 0)
3816 {
3817 if (*option == '+')
3818 break;
3819 i++;
cristybb503372010-05-27 20:51:26 +00003820 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003821 ThrowMogrifyException(OptionError,"MissingArgument",option);
3822 if (IsGeometry(argv[i]) == MagickFalse)
3823 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3824 break;
3825 }
3826 if (LocaleCompare("authenticate",option+1) == 0)
3827 {
3828 if (*option == '+')
3829 break;
3830 i++;
cristybb503372010-05-27 20:51:26 +00003831 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003832 ThrowMogrifyException(OptionError,"MissingArgument",option);
3833 break;
3834 }
3835 if (LocaleCompare("auto-gamma",option+1) == 0)
3836 break;
3837 if (LocaleCompare("auto-level",option+1) == 0)
3838 break;
3839 if (LocaleCompare("auto-orient",option+1) == 0)
3840 break;
3841 if (LocaleCompare("average",option+1) == 0)
3842 break;
3843 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3844 }
3845 case 'b':
3846 {
3847 if (LocaleCompare("background",option+1) == 0)
3848 {
3849 if (*option == '+')
3850 break;
3851 i++;
cristybb503372010-05-27 20:51:26 +00003852 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003853 ThrowMogrifyException(OptionError,"MissingArgument",option);
3854 break;
3855 }
3856 if (LocaleCompare("bias",option+1) == 0)
3857 {
3858 if (*option == '+')
3859 break;
3860 i++;
cristybb503372010-05-27 20:51:26 +00003861 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003862 ThrowMogrifyException(OptionError,"MissingArgument",option);
3863 if (IsGeometry(argv[i]) == MagickFalse)
3864 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3865 break;
3866 }
3867 if (LocaleCompare("black-point-compensation",option+1) == 0)
3868 break;
3869 if (LocaleCompare("black-threshold",option+1) == 0)
3870 {
3871 if (*option == '+')
3872 break;
3873 i++;
cristybb503372010-05-27 20:51:26 +00003874 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003875 ThrowMogrifyException(OptionError,"MissingArgument",option);
3876 if (IsGeometry(argv[i]) == MagickFalse)
3877 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3878 break;
3879 }
3880 if (LocaleCompare("blue-primary",option+1) == 0)
3881 {
3882 if (*option == '+')
3883 break;
3884 i++;
cristybb503372010-05-27 20:51:26 +00003885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003886 ThrowMogrifyException(OptionError,"MissingArgument",option);
3887 if (IsGeometry(argv[i]) == MagickFalse)
3888 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3889 break;
3890 }
3891 if (LocaleCompare("blue-shift",option+1) == 0)
3892 {
3893 i++;
cristybb503372010-05-27 20:51:26 +00003894 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003895 ThrowMogrifyException(OptionError,"MissingArgument",option);
3896 if (IsGeometry(argv[i]) == MagickFalse)
3897 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3898 break;
3899 }
3900 if (LocaleCompare("blur",option+1) == 0)
3901 {
3902 i++;
cristybb503372010-05-27 20:51:26 +00003903 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003904 ThrowMogrifyException(OptionError,"MissingArgument",option);
3905 if (IsGeometry(argv[i]) == MagickFalse)
3906 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3907 break;
3908 }
3909 if (LocaleCompare("border",option+1) == 0)
3910 {
3911 if (*option == '+')
3912 break;
3913 i++;
cristybb503372010-05-27 20:51:26 +00003914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003915 ThrowMogrifyException(OptionError,"MissingArgument",option);
3916 if (IsGeometry(argv[i]) == MagickFalse)
3917 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3918 break;
3919 }
3920 if (LocaleCompare("bordercolor",option+1) == 0)
3921 {
3922 if (*option == '+')
3923 break;
3924 i++;
cristybb503372010-05-27 20:51:26 +00003925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003926 ThrowMogrifyException(OptionError,"MissingArgument",option);
3927 break;
3928 }
3929 if (LocaleCompare("box",option+1) == 0)
3930 {
3931 if (*option == '+')
3932 break;
3933 i++;
cristybb503372010-05-27 20:51:26 +00003934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003935 ThrowMogrifyException(OptionError,"MissingArgument",option);
3936 break;
3937 }
cristya28d6b82010-01-11 20:03:47 +00003938 if (LocaleCompare("brightness-contrast",option+1) == 0)
3939 {
3940 i++;
cristybb503372010-05-27 20:51:26 +00003941 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003942 ThrowMogrifyException(OptionError,"MissingArgument",option);
3943 if (IsGeometry(argv[i]) == MagickFalse)
3944 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3945 break;
3946 }
cristy3ed852e2009-09-05 21:47:34 +00003947 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3948 }
3949 case 'c':
3950 {
3951 if (LocaleCompare("cache",option+1) == 0)
3952 {
3953 if (*option == '+')
3954 break;
3955 i++;
cristybb503372010-05-27 20:51:26 +00003956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003957 ThrowMogrifyException(OptionError,"MissingArgument",option);
3958 if (IsGeometry(argv[i]) == MagickFalse)
3959 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3960 break;
3961 }
3962 if (LocaleCompare("caption",option+1) == 0)
3963 {
3964 if (*option == '+')
3965 break;
3966 i++;
cristybb503372010-05-27 20:51:26 +00003967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003968 ThrowMogrifyException(OptionError,"MissingArgument",option);
3969 break;
3970 }
3971 if (LocaleCompare("channel",option+1) == 0)
3972 {
cristybb503372010-05-27 20:51:26 +00003973 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003974 channel;
3975
3976 if (*option == '+')
3977 break;
3978 i++;
cristybb503372010-05-27 20:51:26 +00003979 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003980 ThrowMogrifyException(OptionError,"MissingArgument",option);
3981 channel=ParseChannelOption(argv[i]);
3982 if (channel < 0)
3983 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3984 argv[i]);
3985 break;
3986 }
3987 if (LocaleCompare("cdl",option+1) == 0)
3988 {
3989 if (*option == '+')
3990 break;
3991 i++;
cristybb503372010-05-27 20:51:26 +00003992 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003993 ThrowMogrifyException(OptionError,"MissingArgument",option);
3994 break;
3995 }
3996 if (LocaleCompare("charcoal",option+1) == 0)
3997 {
3998 if (*option == '+')
3999 break;
4000 i++;
cristybb503372010-05-27 20:51:26 +00004001 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004002 ThrowMogrifyException(OptionError,"MissingArgument",option);
4003 if (IsGeometry(argv[i]) == MagickFalse)
4004 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4005 break;
4006 }
4007 if (LocaleCompare("chop",option+1) == 0)
4008 {
4009 if (*option == '+')
4010 break;
4011 i++;
cristybb503372010-05-27 20:51:26 +00004012 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004013 ThrowMogrifyException(OptionError,"MissingArgument",option);
4014 if (IsGeometry(argv[i]) == MagickFalse)
4015 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4016 break;
4017 }
cristy1eb45dd2009-09-25 16:38:06 +00004018 if (LocaleCompare("clamp",option+1) == 0)
4019 break;
4020 if (LocaleCompare("clip",option+1) == 0)
4021 break;
cristy3ed852e2009-09-05 21:47:34 +00004022 if (LocaleCompare("clip-mask",option+1) == 0)
4023 {
4024 if (*option == '+')
4025 break;
4026 i++;
cristybb503372010-05-27 20:51:26 +00004027 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004028 ThrowMogrifyException(OptionError,"MissingArgument",option);
4029 break;
4030 }
4031 if (LocaleCompare("clut",option+1) == 0)
4032 break;
4033 if (LocaleCompare("coalesce",option+1) == 0)
4034 break;
4035 if (LocaleCompare("colorize",option+1) == 0)
4036 {
4037 if (*option == '+')
4038 break;
4039 i++;
cristybb503372010-05-27 20:51:26 +00004040 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004041 ThrowMogrifyException(OptionError,"MissingArgument",option);
4042 if (IsGeometry(argv[i]) == MagickFalse)
4043 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4044 break;
4045 }
cristye6365592010-04-02 17:31:23 +00004046 if (LocaleCompare("color-matrix",option+1) == 0)
4047 {
cristyb6bd4ad2010-08-08 01:12:27 +00004048 KernelInfo
4049 *kernel_info;
4050
cristye6365592010-04-02 17:31:23 +00004051 if (*option == '+')
4052 break;
4053 i++;
cristybb503372010-05-27 20:51:26 +00004054 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004055 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004056 kernel_info=AcquireKernelInfo(argv[i]);
4057 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004058 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004059 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004060 break;
4061 }
cristy3ed852e2009-09-05 21:47:34 +00004062 if (LocaleCompare("colors",option+1) == 0)
4063 {
4064 if (*option == '+')
4065 break;
4066 i++;
cristybb503372010-05-27 20:51:26 +00004067 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004068 ThrowMogrifyException(OptionError,"MissingArgument",option);
4069 if (IsGeometry(argv[i]) == MagickFalse)
4070 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4071 break;
4072 }
4073 if (LocaleCompare("colorspace",option+1) == 0)
4074 {
cristybb503372010-05-27 20:51:26 +00004075 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004076 colorspace;
4077
4078 if (*option == '+')
4079 break;
4080 i++;
cristybb503372010-05-27 20:51:26 +00004081 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004082 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004083 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004084 argv[i]);
4085 if (colorspace < 0)
4086 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4087 argv[i]);
4088 break;
4089 }
4090 if (LocaleCompare("combine",option+1) == 0)
4091 break;
4092 if (LocaleCompare("comment",option+1) == 0)
4093 {
4094 if (*option == '+')
4095 break;
4096 i++;
cristybb503372010-05-27 20:51:26 +00004097 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004098 ThrowMogrifyException(OptionError,"MissingArgument",option);
4099 break;
4100 }
4101 if (LocaleCompare("composite",option+1) == 0)
4102 break;
4103 if (LocaleCompare("compress",option+1) == 0)
4104 {
cristybb503372010-05-27 20:51:26 +00004105 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004106 compress;
4107
4108 if (*option == '+')
4109 break;
4110 i++;
cristybb503372010-05-27 20:51:26 +00004111 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004112 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004113 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004114 argv[i]);
4115 if (compress < 0)
4116 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4117 argv[i]);
4118 break;
4119 }
cristy22879752009-10-25 23:55:40 +00004120 if (LocaleCompare("concurrent",option+1) == 0)
4121 break;
cristy3ed852e2009-09-05 21:47:34 +00004122 if (LocaleCompare("contrast",option+1) == 0)
4123 break;
4124 if (LocaleCompare("contrast-stretch",option+1) == 0)
4125 {
4126 i++;
cristybb503372010-05-27 20:51:26 +00004127 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004128 ThrowMogrifyException(OptionError,"MissingArgument",option);
4129 if (IsGeometry(argv[i]) == MagickFalse)
4130 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4131 break;
4132 }
4133 if (LocaleCompare("convolve",option+1) == 0)
4134 {
cristyb6bd4ad2010-08-08 01:12:27 +00004135 KernelInfo
4136 *kernel_info;
4137
cristy3ed852e2009-09-05 21:47:34 +00004138 if (*option == '+')
4139 break;
4140 i++;
cristybb503372010-05-27 20:51:26 +00004141 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004142 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004143 kernel_info=AcquireKernelInfo(argv[i]);
4144 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004145 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004146 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004147 break;
4148 }
4149 if (LocaleCompare("crop",option+1) == 0)
4150 {
4151 if (*option == '+')
4152 break;
4153 i++;
cristybb503372010-05-27 20:51:26 +00004154 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004155 ThrowMogrifyException(OptionError,"MissingArgument",option);
4156 if (IsGeometry(argv[i]) == MagickFalse)
4157 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4158 break;
4159 }
4160 if (LocaleCompare("cycle",option+1) == 0)
4161 {
4162 if (*option == '+')
4163 break;
4164 i++;
cristybb503372010-05-27 20:51:26 +00004165 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004166 ThrowMogrifyException(OptionError,"MissingArgument",option);
4167 if (IsGeometry(argv[i]) == MagickFalse)
4168 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4169 break;
4170 }
4171 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4172 }
4173 case 'd':
4174 {
4175 if (LocaleCompare("decipher",option+1) == 0)
4176 {
4177 if (*option == '+')
4178 break;
4179 i++;
cristybb503372010-05-27 20:51:26 +00004180 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004181 ThrowMogrifyException(OptionError,"MissingArgument",option);
4182 break;
4183 }
4184 if (LocaleCompare("deconstruct",option+1) == 0)
4185 break;
4186 if (LocaleCompare("debug",option+1) == 0)
4187 {
cristybb503372010-05-27 20:51:26 +00004188 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004189 event;
4190
4191 if (*option == '+')
4192 break;
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);
cristy042ee782011-04-22 18:48:30 +00004196 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004197 if (event < 0)
4198 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4199 argv[i]);
4200 (void) SetLogEventMask(argv[i]);
4201 break;
4202 }
4203 if (LocaleCompare("define",option+1) == 0)
4204 {
4205 i++;
cristybb503372010-05-27 20:51:26 +00004206 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004207 ThrowMogrifyException(OptionError,"MissingArgument",option);
4208 if (*option == '+')
4209 {
4210 const char
4211 *define;
4212
4213 define=GetImageOption(image_info,argv[i]);
4214 if (define == (const char *) NULL)
4215 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4216 break;
4217 }
4218 break;
4219 }
4220 if (LocaleCompare("delay",option+1) == 0)
4221 {
4222 if (*option == '+')
4223 break;
4224 i++;
cristybb503372010-05-27 20:51:26 +00004225 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004226 ThrowMogrifyException(OptionError,"MissingArgument",option);
4227 if (IsGeometry(argv[i]) == MagickFalse)
4228 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4229 break;
4230 }
cristyecb10ff2011-03-22 13:14:03 +00004231 if (LocaleCompare("delete",option+1) == 0)
4232 {
4233 if (*option == '+')
4234 break;
4235 i++;
4236 if (i == (ssize_t) (argc-1))
4237 ThrowMogrifyException(OptionError,"MissingArgument",option);
4238 if (IsGeometry(argv[i]) == MagickFalse)
4239 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4240 break;
4241 }
cristy3ed852e2009-09-05 21:47:34 +00004242 if (LocaleCompare("density",option+1) == 0)
4243 {
4244 if (*option == '+')
4245 break;
4246 i++;
cristybb503372010-05-27 20:51:26 +00004247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004248 ThrowMogrifyException(OptionError,"MissingArgument",option);
4249 if (IsGeometry(argv[i]) == MagickFalse)
4250 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4251 break;
4252 }
4253 if (LocaleCompare("depth",option+1) == 0)
4254 {
4255 if (*option == '+')
4256 break;
4257 i++;
cristybb503372010-05-27 20:51:26 +00004258 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004259 ThrowMogrifyException(OptionError,"MissingArgument",option);
4260 if (IsGeometry(argv[i]) == MagickFalse)
4261 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4262 break;
4263 }
4264 if (LocaleCompare("deskew",option+1) == 0)
4265 {
4266 if (*option == '+')
4267 break;
4268 i++;
cristybb503372010-05-27 20:51:26 +00004269 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004270 ThrowMogrifyException(OptionError,"MissingArgument",option);
4271 if (IsGeometry(argv[i]) == MagickFalse)
4272 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4273 break;
4274 }
4275 if (LocaleCompare("despeckle",option+1) == 0)
4276 break;
4277 if (LocaleCompare("dft",option+1) == 0)
4278 break;
cristyc9b12952010-03-28 01:12:28 +00004279 if (LocaleCompare("direction",option+1) == 0)
4280 {
cristybb503372010-05-27 20:51:26 +00004281 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004282 direction;
4283
4284 if (*option == '+')
4285 break;
4286 i++;
cristybb503372010-05-27 20:51:26 +00004287 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004288 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004289 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004290 argv[i]);
4291 if (direction < 0)
4292 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4293 argv[i]);
4294 break;
4295 }
cristy3ed852e2009-09-05 21:47:34 +00004296 if (LocaleCompare("display",option+1) == 0)
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);
4303 break;
4304 }
4305 if (LocaleCompare("dispose",option+1) == 0)
4306 {
cristybb503372010-05-27 20:51:26 +00004307 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004308 dispose;
4309
4310 if (*option == '+')
4311 break;
4312 i++;
cristybb503372010-05-27 20:51:26 +00004313 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004314 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004315 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004316 if (dispose < 0)
4317 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4318 argv[i]);
4319 break;
4320 }
4321 if (LocaleCompare("distort",option+1) == 0)
4322 {
cristybb503372010-05-27 20:51:26 +00004323 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004324 op;
4325
4326 i++;
cristybb503372010-05-27 20:51:26 +00004327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004328 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004329 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004330 if (op < 0)
4331 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4332 argv[i]);
4333 i++;
cristybb503372010-05-27 20:51:26 +00004334 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004335 ThrowMogrifyException(OptionError,"MissingArgument",option);
4336 break;
4337 }
4338 if (LocaleCompare("dither",option+1) == 0)
4339 {
cristybb503372010-05-27 20:51:26 +00004340 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004341 method;
4342
4343 if (*option == '+')
4344 break;
4345 i++;
cristybb503372010-05-27 20:51:26 +00004346 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004347 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004348 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004349 if (method < 0)
4350 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4351 argv[i]);
4352 break;
4353 }
4354 if (LocaleCompare("draw",option+1) == 0)
4355 {
4356 if (*option == '+')
4357 break;
4358 i++;
cristybb503372010-05-27 20:51:26 +00004359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004360 ThrowMogrifyException(OptionError,"MissingArgument",option);
4361 break;
4362 }
cristyecb10ff2011-03-22 13:14:03 +00004363 if (LocaleCompare("duplicate",option+1) == 0)
4364 {
4365 if (*option == '+')
4366 break;
4367 i++;
4368 if (i == (ssize_t) (argc-1))
4369 ThrowMogrifyException(OptionError,"MissingArgument",option);
4370 if (IsGeometry(argv[i]) == MagickFalse)
4371 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4372 break;
4373 }
cristy22879752009-10-25 23:55:40 +00004374 if (LocaleCompare("duration",option+1) == 0)
4375 {
4376 if (*option == '+')
4377 break;
4378 i++;
cristybb503372010-05-27 20:51:26 +00004379 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004380 ThrowMogrifyException(OptionError,"MissingArgument",option);
4381 if (IsGeometry(argv[i]) == MagickFalse)
4382 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4383 break;
4384 }
cristy3ed852e2009-09-05 21:47:34 +00004385 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4386 }
4387 case 'e':
4388 {
4389 if (LocaleCompare("edge",option+1) == 0)
4390 {
4391 if (*option == '+')
4392 break;
4393 i++;
cristybb503372010-05-27 20:51:26 +00004394 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004395 ThrowMogrifyException(OptionError,"MissingArgument",option);
4396 if (IsGeometry(argv[i]) == MagickFalse)
4397 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4398 break;
4399 }
4400 if (LocaleCompare("emboss",option+1) == 0)
4401 {
4402 if (*option == '+')
4403 break;
4404 i++;
cristybb503372010-05-27 20:51:26 +00004405 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004406 ThrowMogrifyException(OptionError,"MissingArgument",option);
4407 if (IsGeometry(argv[i]) == MagickFalse)
4408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4409 break;
4410 }
4411 if (LocaleCompare("encipher",option+1) == 0)
4412 {
4413 if (*option == '+')
4414 break;
4415 i++;
cristybb503372010-05-27 20:51:26 +00004416 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004417 ThrowMogrifyException(OptionError,"MissingArgument",option);
4418 break;
4419 }
4420 if (LocaleCompare("encoding",option+1) == 0)
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);
4427 break;
4428 }
4429 if (LocaleCompare("endian",option+1) == 0)
4430 {
cristybb503372010-05-27 20:51:26 +00004431 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004432 endian;
4433
4434 if (*option == '+')
4435 break;
4436 i++;
cristybb503372010-05-27 20:51:26 +00004437 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004438 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004439 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004440 if (endian < 0)
4441 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4442 argv[i]);
4443 break;
4444 }
4445 if (LocaleCompare("enhance",option+1) == 0)
4446 break;
4447 if (LocaleCompare("equalize",option+1) == 0)
4448 break;
4449 if (LocaleCompare("evaluate",option+1) == 0)
4450 {
cristybb503372010-05-27 20:51:26 +00004451 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004452 op;
4453
4454 if (*option == '+')
4455 break;
4456 i++;
cristybb503372010-05-27 20:51:26 +00004457 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004458 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004459 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004460 if (op < 0)
4461 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4462 argv[i]);
4463 i++;
cristybb503372010-05-27 20:51:26 +00004464 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004465 ThrowMogrifyException(OptionError,"MissingArgument",option);
4466 if (IsGeometry(argv[i]) == MagickFalse)
4467 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4468 break;
4469 }
cristyd18ae7c2010-03-07 17:39:52 +00004470 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4471 {
cristybb503372010-05-27 20:51:26 +00004472 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004473 op;
4474
4475 if (*option == '+')
4476 break;
4477 i++;
cristybb503372010-05-27 20:51:26 +00004478 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004479 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004480 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004481 if (op < 0)
4482 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4483 argv[i]);
4484 break;
4485 }
cristy3ed852e2009-09-05 21:47:34 +00004486 if (LocaleCompare("extent",option+1) == 0)
4487 {
4488 if (*option == '+')
4489 break;
4490 i++;
cristybb503372010-05-27 20:51:26 +00004491 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004492 ThrowMogrifyException(OptionError,"MissingArgument",option);
4493 if (IsGeometry(argv[i]) == MagickFalse)
4494 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4495 break;
4496 }
4497 if (LocaleCompare("extract",option+1) == 0)
4498 {
4499 if (*option == '+')
4500 break;
4501 i++;
cristybb503372010-05-27 20:51:26 +00004502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004503 ThrowMogrifyException(OptionError,"MissingArgument",option);
4504 if (IsGeometry(argv[i]) == MagickFalse)
4505 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4506 break;
4507 }
4508 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4509 }
4510 case 'f':
4511 {
4512 if (LocaleCompare("family",option+1) == 0)
4513 {
4514 if (*option == '+')
4515 break;
4516 i++;
cristybb503372010-05-27 20:51:26 +00004517 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004518 ThrowMogrifyException(OptionError,"MissingArgument",option);
4519 break;
4520 }
4521 if (LocaleCompare("fill",option+1) == 0)
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);
4528 break;
4529 }
4530 if (LocaleCompare("filter",option+1) == 0)
4531 {
cristybb503372010-05-27 20:51:26 +00004532 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004533 filter;
4534
4535 if (*option == '+')
4536 break;
4537 i++;
cristybb503372010-05-27 20:51:26 +00004538 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004539 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004540 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004541 if (filter < 0)
4542 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4543 argv[i]);
4544 break;
4545 }
4546 if (LocaleCompare("flatten",option+1) == 0)
4547 break;
4548 if (LocaleCompare("flip",option+1) == 0)
4549 break;
4550 if (LocaleCompare("flop",option+1) == 0)
4551 break;
4552 if (LocaleCompare("floodfill",option+1) == 0)
4553 {
4554 if (*option == '+')
4555 break;
4556 i++;
cristybb503372010-05-27 20:51:26 +00004557 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004558 ThrowMogrifyException(OptionError,"MissingArgument",option);
4559 if (IsGeometry(argv[i]) == MagickFalse)
4560 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4561 i++;
cristybb503372010-05-27 20:51:26 +00004562 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004563 ThrowMogrifyException(OptionError,"MissingArgument",option);
4564 break;
4565 }
4566 if (LocaleCompare("font",option+1) == 0)
4567 {
4568 if (*option == '+')
4569 break;
4570 i++;
cristybb503372010-05-27 20:51:26 +00004571 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004572 ThrowMogrifyException(OptionError,"MissingArgument",option);
4573 break;
4574 }
4575 if (LocaleCompare("format",option+1) == 0)
4576 {
4577 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4578 (void) CloneString(&format,(char *) NULL);
4579 if (*option == '+')
4580 break;
4581 i++;
cristybb503372010-05-27 20:51:26 +00004582 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004583 ThrowMogrifyException(OptionError,"MissingArgument",option);
4584 (void) CloneString(&format,argv[i]);
4585 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4586 (void) ConcatenateMagickString(image_info->filename,":",
4587 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004588 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004589 if (*image_info->magick == '\0')
4590 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4591 format);
4592 break;
4593 }
4594 if (LocaleCompare("frame",option+1) == 0)
4595 {
4596 if (*option == '+')
4597 break;
4598 i++;
cristybb503372010-05-27 20:51:26 +00004599 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004600 ThrowMogrifyException(OptionError,"MissingArgument",option);
4601 if (IsGeometry(argv[i]) == MagickFalse)
4602 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4603 break;
4604 }
4605 if (LocaleCompare("function",option+1) == 0)
4606 {
cristybb503372010-05-27 20:51:26 +00004607 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004608 op;
4609
4610 if (*option == '+')
4611 break;
4612 i++;
cristybb503372010-05-27 20:51:26 +00004613 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004614 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004615 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004616 if (op < 0)
4617 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4618 i++;
cristybb503372010-05-27 20:51:26 +00004619 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004620 ThrowMogrifyException(OptionError,"MissingArgument",option);
4621 break;
4622 }
4623 if (LocaleCompare("fuzz",option+1) == 0)
4624 {
4625 if (*option == '+')
4626 break;
4627 i++;
cristybb503372010-05-27 20:51:26 +00004628 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004629 ThrowMogrifyException(OptionError,"MissingArgument",option);
4630 if (IsGeometry(argv[i]) == MagickFalse)
4631 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4632 break;
4633 }
4634 if (LocaleCompare("fx",option+1) == 0)
4635 {
4636 if (*option == '+')
4637 break;
4638 i++;
cristybb503372010-05-27 20:51:26 +00004639 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004640 ThrowMogrifyException(OptionError,"MissingArgument",option);
4641 break;
4642 }
4643 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4644 }
4645 case 'g':
4646 {
4647 if (LocaleCompare("gamma",option+1) == 0)
4648 {
4649 i++;
cristybb503372010-05-27 20:51:26 +00004650 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004651 ThrowMogrifyException(OptionError,"MissingArgument",option);
4652 if (IsGeometry(argv[i]) == MagickFalse)
4653 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4654 break;
4655 }
4656 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4657 (LocaleCompare("gaussian",option+1) == 0))
4658 {
4659 i++;
cristybb503372010-05-27 20:51:26 +00004660 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004661 ThrowMogrifyException(OptionError,"MissingArgument",option);
4662 if (IsGeometry(argv[i]) == MagickFalse)
4663 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4664 break;
4665 }
4666 if (LocaleCompare("geometry",option+1) == 0)
4667 {
4668 if (*option == '+')
4669 break;
4670 i++;
cristybb503372010-05-27 20:51:26 +00004671 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004672 ThrowMogrifyException(OptionError,"MissingArgument",option);
4673 if (IsGeometry(argv[i]) == MagickFalse)
4674 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4675 break;
4676 }
4677 if (LocaleCompare("gravity",option+1) == 0)
4678 {
cristybb503372010-05-27 20:51:26 +00004679 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004680 gravity;
4681
4682 if (*option == '+')
4683 break;
4684 i++;
cristybb503372010-05-27 20:51:26 +00004685 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004686 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004687 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004688 if (gravity < 0)
4689 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4690 argv[i]);
4691 break;
4692 }
4693 if (LocaleCompare("green-primary",option+1) == 0)
4694 {
4695 if (*option == '+')
4696 break;
4697 i++;
cristybb503372010-05-27 20:51:26 +00004698 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004699 ThrowMogrifyException(OptionError,"MissingArgument",option);
4700 if (IsGeometry(argv[i]) == MagickFalse)
4701 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4702 break;
4703 }
4704 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4705 }
4706 case 'h':
4707 {
4708 if (LocaleCompare("hald-clut",option+1) == 0)
4709 break;
4710 if ((LocaleCompare("help",option+1) == 0) ||
4711 (LocaleCompare("-help",option+1) == 0))
4712 return(MogrifyUsage());
4713 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4714 }
4715 case 'i':
4716 {
4717 if (LocaleCompare("identify",option+1) == 0)
4718 break;
4719 if (LocaleCompare("idft",option+1) == 0)
4720 break;
4721 if (LocaleCompare("implode",option+1) == 0)
4722 {
4723 if (*option == '+')
4724 break;
4725 i++;
cristybb503372010-05-27 20:51:26 +00004726 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004727 ThrowMogrifyException(OptionError,"MissingArgument",option);
4728 if (IsGeometry(argv[i]) == MagickFalse)
4729 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4730 break;
4731 }
4732 if (LocaleCompare("intent",option+1) == 0)
4733 {
cristybb503372010-05-27 20:51:26 +00004734 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004735 intent;
4736
4737 if (*option == '+')
4738 break;
4739 i++;
cristybb503372010-05-27 20:51:26 +00004740 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004741 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004742 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004743 if (intent < 0)
4744 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4745 argv[i]);
4746 break;
4747 }
4748 if (LocaleCompare("interlace",option+1) == 0)
4749 {
cristybb503372010-05-27 20:51:26 +00004750 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004751 interlace;
4752
4753 if (*option == '+')
4754 break;
4755 i++;
cristybb503372010-05-27 20:51:26 +00004756 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004757 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004758 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004759 argv[i]);
4760 if (interlace < 0)
4761 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4762 argv[i]);
4763 break;
4764 }
cristyb32b90a2009-09-07 21:45:48 +00004765 if (LocaleCompare("interline-spacing",option+1) == 0)
4766 {
4767 if (*option == '+')
4768 break;
4769 i++;
cristybb503372010-05-27 20:51:26 +00004770 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004771 ThrowMogrifyException(OptionError,"MissingArgument",option);
4772 if (IsGeometry(argv[i]) == MagickFalse)
4773 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4774 break;
4775 }
cristy3ed852e2009-09-05 21:47:34 +00004776 if (LocaleCompare("interpolate",option+1) == 0)
4777 {
cristybb503372010-05-27 20:51:26 +00004778 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004779 interpolate;
4780
4781 if (*option == '+')
4782 break;
4783 i++;
cristybb503372010-05-27 20:51:26 +00004784 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004785 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004786 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004787 argv[i]);
4788 if (interpolate < 0)
4789 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4790 argv[i]);
4791 break;
4792 }
4793 if (LocaleCompare("interword-spacing",option+1) == 0)
4794 {
4795 if (*option == '+')
4796 break;
4797 i++;
cristybb503372010-05-27 20:51:26 +00004798 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004799 ThrowMogrifyException(OptionError,"MissingArgument",option);
4800 if (IsGeometry(argv[i]) == MagickFalse)
4801 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4802 break;
4803 }
4804 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4805 }
4806 case 'k':
4807 {
4808 if (LocaleCompare("kerning",option+1) == 0)
4809 {
4810 if (*option == '+')
4811 break;
4812 i++;
cristybb503372010-05-27 20:51:26 +00004813 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004814 ThrowMogrifyException(OptionError,"MissingArgument",option);
4815 if (IsGeometry(argv[i]) == MagickFalse)
4816 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4817 break;
4818 }
4819 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4820 }
4821 case 'l':
4822 {
4823 if (LocaleCompare("label",option+1) == 0)
4824 {
4825 if (*option == '+')
4826 break;
4827 i++;
cristybb503372010-05-27 20:51:26 +00004828 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004829 ThrowMogrifyException(OptionError,"MissingArgument",option);
4830 break;
4831 }
4832 if (LocaleCompare("lat",option+1) == 0)
4833 {
4834 if (*option == '+')
4835 break;
4836 i++;
cristybb503372010-05-27 20:51:26 +00004837 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004838 ThrowMogrifyException(OptionError,"MissingArgument",option);
4839 if (IsGeometry(argv[i]) == MagickFalse)
4840 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4841 }
4842 if (LocaleCompare("layers",option+1) == 0)
4843 {
cristybb503372010-05-27 20:51:26 +00004844 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004845 type;
4846
4847 if (*option == '+')
4848 break;
4849 i++;
cristybb503372010-05-27 20:51:26 +00004850 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004851 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004852 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004853 if (type < 0)
4854 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4855 argv[i]);
4856 break;
4857 }
4858 if (LocaleCompare("level",option+1) == 0)
4859 {
4860 i++;
cristybb503372010-05-27 20:51:26 +00004861 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004862 ThrowMogrifyException(OptionError,"MissingArgument",option);
4863 if (IsGeometry(argv[i]) == MagickFalse)
4864 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4865 break;
4866 }
4867 if (LocaleCompare("level-colors",option+1) == 0)
4868 {
4869 i++;
cristybb503372010-05-27 20:51:26 +00004870 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004871 ThrowMogrifyException(OptionError,"MissingArgument",option);
4872 break;
4873 }
4874 if (LocaleCompare("linewidth",option+1) == 0)
4875 {
4876 if (*option == '+')
4877 break;
4878 i++;
cristybb503372010-05-27 20:51:26 +00004879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004880 ThrowMogrifyException(OptionError,"MissingArgument",option);
4881 if (IsGeometry(argv[i]) == MagickFalse)
4882 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4883 break;
4884 }
4885 if (LocaleCompare("limit",option+1) == 0)
4886 {
4887 char
4888 *p;
4889
4890 double
4891 value;
4892
cristybb503372010-05-27 20:51:26 +00004893 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004894 resource;
4895
4896 if (*option == '+')
4897 break;
4898 i++;
cristybb503372010-05-27 20:51:26 +00004899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004900 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004901 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004902 argv[i]);
4903 if (resource < 0)
4904 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4905 argv[i]);
4906 i++;
cristybb503372010-05-27 20:51:26 +00004907 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004908 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004909 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004910 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004911 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4912 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4913 break;
4914 }
4915 if (LocaleCompare("liquid-rescale",option+1) == 0)
4916 {
4917 i++;
cristybb503372010-05-27 20:51:26 +00004918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004919 ThrowMogrifyException(OptionError,"MissingArgument",option);
4920 if (IsGeometry(argv[i]) == MagickFalse)
4921 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4922 break;
4923 }
4924 if (LocaleCompare("list",option+1) == 0)
4925 {
cristybb503372010-05-27 20:51:26 +00004926 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004927 list;
4928
4929 if (*option == '+')
4930 break;
4931 i++;
cristybb503372010-05-27 20:51:26 +00004932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004933 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004934 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004935 if (list < 0)
4936 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004937 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004938 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004939 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004940 }
4941 if (LocaleCompare("log",option+1) == 0)
4942 {
4943 if (*option == '+')
4944 break;
4945 i++;
cristybb503372010-05-27 20:51:26 +00004946 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004947 (strchr(argv[i],'%') == (char *) NULL))
4948 ThrowMogrifyException(OptionError,"MissingArgument",option);
4949 break;
4950 }
4951 if (LocaleCompare("loop",option+1) == 0)
4952 {
4953 if (*option == '+')
4954 break;
4955 i++;
cristybb503372010-05-27 20:51:26 +00004956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004957 ThrowMogrifyException(OptionError,"MissingArgument",option);
4958 if (IsGeometry(argv[i]) == MagickFalse)
4959 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4960 break;
4961 }
4962 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4963 }
4964 case 'm':
4965 {
4966 if (LocaleCompare("map",option+1) == 0)
4967 {
4968 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4969 if (*option == '+')
4970 break;
4971 i++;
cristybb503372010-05-27 20:51:26 +00004972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004973 ThrowMogrifyException(OptionError,"MissingArgument",option);
4974 break;
4975 }
4976 if (LocaleCompare("mask",option+1) == 0)
4977 {
4978 if (*option == '+')
4979 break;
4980 i++;
cristybb503372010-05-27 20:51:26 +00004981 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004982 ThrowMogrifyException(OptionError,"MissingArgument",option);
4983 break;
4984 }
4985 if (LocaleCompare("matte",option+1) == 0)
4986 break;
4987 if (LocaleCompare("mattecolor",option+1) == 0)
4988 {
4989 if (*option == '+')
4990 break;
4991 i++;
cristybb503372010-05-27 20:51:26 +00004992 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004993 ThrowMogrifyException(OptionError,"MissingArgument",option);
4994 break;
4995 }
cristyf40785b2010-03-06 02:27:27 +00004996 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004997 break;
cristyf40785b2010-03-06 02:27:27 +00004998 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004999 break;
cristy3ed852e2009-09-05 21:47:34 +00005000 if (LocaleCompare("modulate",option+1) == 0)
5001 {
5002 if (*option == '+')
5003 break;
5004 i++;
cristybb503372010-05-27 20:51:26 +00005005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005006 ThrowMogrifyException(OptionError,"MissingArgument",option);
5007 if (IsGeometry(argv[i]) == MagickFalse)
5008 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5009 break;
5010 }
5011 if (LocaleCompare("median",option+1) == 0)
5012 {
5013 if (*option == '+')
5014 break;
5015 i++;
cristybb503372010-05-27 20:51:26 +00005016 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005017 ThrowMogrifyException(OptionError,"MissingArgument",option);
5018 if (IsGeometry(argv[i]) == MagickFalse)
5019 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5020 break;
5021 }
cristy69ec32d2011-02-27 23:57:09 +00005022 if (LocaleCompare("mode",option+1) == 0)
5023 {
5024 if (*option == '+')
5025 break;
5026 i++;
5027 if (i == (ssize_t) argc)
5028 ThrowMogrifyException(OptionError,"MissingArgument",option);
5029 if (IsGeometry(argv[i]) == MagickFalse)
5030 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5031 break;
5032 }
cristy3ed852e2009-09-05 21:47:34 +00005033 if (LocaleCompare("monitor",option+1) == 0)
5034 break;
5035 if (LocaleCompare("monochrome",option+1) == 0)
5036 break;
5037 if (LocaleCompare("morph",option+1) == 0)
5038 {
5039 if (*option == '+')
5040 break;
5041 i++;
cristybb503372010-05-27 20:51:26 +00005042 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005043 ThrowMogrifyException(OptionError,"MissingArgument",option);
5044 if (IsGeometry(argv[i]) == MagickFalse)
5045 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5046 break;
5047 }
anthony29188a82010-01-22 10:12:34 +00005048 if (LocaleCompare("morphology",option+1) == 0)
5049 {
anthony29188a82010-01-22 10:12:34 +00005050 char
5051 token[MaxTextExtent];
5052
cristyb6bd4ad2010-08-08 01:12:27 +00005053 KernelInfo
5054 *kernel_info;
5055
5056 ssize_t
5057 op;
5058
anthony29188a82010-01-22 10:12:34 +00005059 i++;
cristybb503372010-05-27 20:51:26 +00005060 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005061 ThrowMogrifyException(OptionError,"MissingArgument",option);
5062 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005063 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005064 if (op < 0)
5065 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005066 token);
anthony29188a82010-01-22 10:12:34 +00005067 i++;
cristybb503372010-05-27 20:51:26 +00005068 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005069 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005070 kernel_info=AcquireKernelInfo(argv[i]);
5071 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005072 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005073 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005074 break;
5075 }
cristy3ed852e2009-09-05 21:47:34 +00005076 if (LocaleCompare("mosaic",option+1) == 0)
5077 break;
5078 if (LocaleCompare("motion-blur",option+1) == 0)
5079 {
5080 if (*option == '+')
5081 break;
5082 i++;
cristybb503372010-05-27 20:51:26 +00005083 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005084 ThrowMogrifyException(OptionError,"MissingArgument",option);
5085 if (IsGeometry(argv[i]) == MagickFalse)
5086 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5087 break;
5088 }
5089 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5090 }
5091 case 'n':
5092 {
5093 if (LocaleCompare("negate",option+1) == 0)
5094 break;
5095 if (LocaleCompare("noise",option+1) == 0)
5096 {
5097 i++;
cristybb503372010-05-27 20:51:26 +00005098 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005099 ThrowMogrifyException(OptionError,"MissingArgument",option);
5100 if (*option == '+')
5101 {
cristybb503372010-05-27 20:51:26 +00005102 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005103 noise;
5104
cristy042ee782011-04-22 18:48:30 +00005105 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005106 if (noise < 0)
5107 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5108 argv[i]);
5109 break;
5110 }
5111 if (IsGeometry(argv[i]) == MagickFalse)
5112 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5113 break;
5114 }
5115 if (LocaleCompare("noop",option+1) == 0)
5116 break;
5117 if (LocaleCompare("normalize",option+1) == 0)
5118 break;
5119 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5120 }
5121 case 'o':
5122 {
5123 if (LocaleCompare("opaque",option+1) == 0)
5124 {
cristy3ed852e2009-09-05 21:47:34 +00005125 i++;
cristybb503372010-05-27 20:51:26 +00005126 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005127 ThrowMogrifyException(OptionError,"MissingArgument",option);
5128 break;
5129 }
5130 if (LocaleCompare("ordered-dither",option+1) == 0)
5131 {
5132 if (*option == '+')
5133 break;
5134 i++;
cristybb503372010-05-27 20:51:26 +00005135 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005136 ThrowMogrifyException(OptionError,"MissingArgument",option);
5137 break;
5138 }
5139 if (LocaleCompare("orient",option+1) == 0)
5140 {
cristybb503372010-05-27 20:51:26 +00005141 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005142 orientation;
5143
5144 orientation=UndefinedOrientation;
5145 if (*option == '+')
5146 break;
5147 i++;
cristybb503372010-05-27 20:51:26 +00005148 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005149 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005150 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005151 argv[i]);
5152 if (orientation < 0)
5153 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5154 argv[i]);
5155 break;
5156 }
5157 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5158 }
5159 case 'p':
5160 {
5161 if (LocaleCompare("page",option+1) == 0)
5162 {
5163 if (*option == '+')
5164 break;
5165 i++;
cristybb503372010-05-27 20:51:26 +00005166 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005167 ThrowMogrifyException(OptionError,"MissingArgument",option);
5168 break;
5169 }
5170 if (LocaleCompare("paint",option+1) == 0)
5171 {
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 if (IsGeometry(argv[i]) == MagickFalse)
5178 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5179 break;
5180 }
5181 if (LocaleCompare("path",option+1) == 0)
5182 {
5183 (void) CloneString(&path,(char *) NULL);
5184 if (*option == '+')
5185 break;
5186 i++;
cristybb503372010-05-27 20:51:26 +00005187 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005188 ThrowMogrifyException(OptionError,"MissingArgument",option);
5189 (void) CloneString(&path,argv[i]);
5190 break;
5191 }
5192 if (LocaleCompare("pointsize",option+1) == 0)
5193 {
5194 if (*option == '+')
5195 break;
5196 i++;
cristybb503372010-05-27 20:51:26 +00005197 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005198 ThrowMogrifyException(OptionError,"MissingArgument",option);
5199 if (IsGeometry(argv[i]) == MagickFalse)
5200 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5201 break;
5202 }
5203 if (LocaleCompare("polaroid",option+1) == 0)
5204 {
5205 if (*option == '+')
5206 break;
5207 i++;
cristybb503372010-05-27 20:51:26 +00005208 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005209 ThrowMogrifyException(OptionError,"MissingArgument",option);
5210 if (IsGeometry(argv[i]) == MagickFalse)
5211 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5212 break;
5213 }
5214 if (LocaleCompare("posterize",option+1) == 0)
5215 {
5216 if (*option == '+')
5217 break;
5218 i++;
cristybb503372010-05-27 20:51:26 +00005219 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005220 ThrowMogrifyException(OptionError,"MissingArgument",option);
5221 if (IsGeometry(argv[i]) == MagickFalse)
5222 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5223 break;
5224 }
cristye7f51092010-01-17 00:39:37 +00005225 if (LocaleCompare("precision",option+1) == 0)
5226 {
5227 if (*option == '+')
5228 break;
5229 i++;
cristybb503372010-05-27 20:51:26 +00005230 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005231 ThrowMogrifyException(OptionError,"MissingArgument",option);
5232 if (IsGeometry(argv[i]) == MagickFalse)
5233 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5234 break;
5235 }
cristy3ed852e2009-09-05 21:47:34 +00005236 if (LocaleCompare("print",option+1) == 0)
5237 {
5238 if (*option == '+')
5239 break;
5240 i++;
cristybb503372010-05-27 20:51:26 +00005241 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005242 ThrowMogrifyException(OptionError,"MissingArgument",option);
5243 break;
5244 }
5245 if (LocaleCompare("process",option+1) == 0)
5246 {
5247 if (*option == '+')
5248 break;
5249 i++;
cristybb503372010-05-27 20:51:26 +00005250 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005251 ThrowMogrifyException(OptionError,"MissingArgument",option);
5252 break;
5253 }
5254 if (LocaleCompare("profile",option+1) == 0)
5255 {
5256 i++;
cristybb503372010-05-27 20:51:26 +00005257 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005258 ThrowMogrifyException(OptionError,"MissingArgument",option);
5259 break;
5260 }
5261 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5262 }
5263 case 'q':
5264 {
5265 if (LocaleCompare("quality",option+1) == 0)
5266 {
5267 if (*option == '+')
5268 break;
5269 i++;
cristybb503372010-05-27 20:51:26 +00005270 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005271 ThrowMogrifyException(OptionError,"MissingArgument",option);
5272 if (IsGeometry(argv[i]) == MagickFalse)
5273 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5274 break;
5275 }
5276 if (LocaleCompare("quantize",option+1) == 0)
5277 {
cristybb503372010-05-27 20:51:26 +00005278 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005279 colorspace;
5280
5281 if (*option == '+')
5282 break;
5283 i++;
cristybb503372010-05-27 20:51:26 +00005284 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005285 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005286 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005287 argv[i]);
5288 if (colorspace < 0)
5289 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5290 argv[i]);
5291 break;
5292 }
5293 if (LocaleCompare("quiet",option+1) == 0)
5294 break;
5295 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5296 }
5297 case 'r':
5298 {
5299 if (LocaleCompare("radial-blur",option+1) == 0)
5300 {
5301 i++;
cristybb503372010-05-27 20:51:26 +00005302 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005303 ThrowMogrifyException(OptionError,"MissingArgument",option);
5304 if (IsGeometry(argv[i]) == MagickFalse)
5305 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5306 break;
5307 }
5308 if (LocaleCompare("raise",option+1) == 0)
5309 {
5310 i++;
cristybb503372010-05-27 20:51:26 +00005311 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005312 ThrowMogrifyException(OptionError,"MissingArgument",option);
5313 if (IsGeometry(argv[i]) == MagickFalse)
5314 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5315 break;
5316 }
5317 if (LocaleCompare("random-threshold",option+1) == 0)
5318 {
5319 if (*option == '+')
5320 break;
5321 i++;
cristybb503372010-05-27 20:51:26 +00005322 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005323 ThrowMogrifyException(OptionError,"MissingArgument",option);
5324 if (IsGeometry(argv[i]) == MagickFalse)
5325 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5326 break;
5327 }
cristye6365592010-04-02 17:31:23 +00005328 if (LocaleCompare("recolor",option+1) == 0)
5329 {
5330 if (*option == '+')
5331 break;
5332 i++;
cristybb503372010-05-27 20:51:26 +00005333 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005334 ThrowMogrifyException(OptionError,"MissingArgument",option);
5335 if (IsGeometry(argv[i]) == MagickFalse)
5336 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5337 break;
5338 }
cristy3ed852e2009-09-05 21:47:34 +00005339 if (LocaleCompare("red-primary",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 }
cristy9f2083a2010-04-22 19:48:05 +00005349 if (LocaleCompare("regard-warnings",option+1) == 0)
5350 break;
cristy3ed852e2009-09-05 21:47:34 +00005351 if (LocaleCompare("region",option+1) == 0)
5352 {
5353 if (*option == '+')
5354 break;
5355 i++;
cristybb503372010-05-27 20:51:26 +00005356 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005357 ThrowMogrifyException(OptionError,"MissingArgument",option);
5358 if (IsGeometry(argv[i]) == MagickFalse)
5359 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5360 break;
5361 }
cristyf0c78232010-03-15 12:53:40 +00005362 if (LocaleCompare("remap",option+1) == 0)
5363 {
5364 if (*option == '+')
5365 break;
5366 i++;
cristybb503372010-05-27 20:51:26 +00005367 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005368 ThrowMogrifyException(OptionError,"MissingArgument",option);
5369 break;
5370 }
cristy3ed852e2009-09-05 21:47:34 +00005371 if (LocaleCompare("render",option+1) == 0)
5372 break;
5373 if (LocaleCompare("repage",option+1) == 0)
5374 {
5375 if (*option == '+')
5376 break;
5377 i++;
cristybb503372010-05-27 20:51:26 +00005378 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005379 ThrowMogrifyException(OptionError,"MissingArgument",option);
5380 if (IsGeometry(argv[i]) == MagickFalse)
5381 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5382 break;
5383 }
5384 if (LocaleCompare("resample",option+1) == 0)
5385 {
5386 if (*option == '+')
5387 break;
5388 i++;
cristybb503372010-05-27 20:51:26 +00005389 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005390 ThrowMogrifyException(OptionError,"MissingArgument",option);
5391 if (IsGeometry(argv[i]) == MagickFalse)
5392 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5393 break;
5394 }
5395 if (LocaleCompare("resize",option+1) == 0)
5396 {
5397 if (*option == '+')
5398 break;
5399 i++;
cristybb503372010-05-27 20:51:26 +00005400 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005401 ThrowMogrifyException(OptionError,"MissingArgument",option);
5402 if (IsGeometry(argv[i]) == MagickFalse)
5403 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5404 break;
5405 }
cristyebbcfea2011-02-25 02:43:54 +00005406 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5407 {
5408 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5409 break;
5410 }
cristy3ed852e2009-09-05 21:47:34 +00005411 if (LocaleCompare("reverse",option+1) == 0)
5412 break;
5413 if (LocaleCompare("roll",option+1) == 0)
5414 {
5415 if (*option == '+')
5416 break;
5417 i++;
cristybb503372010-05-27 20:51:26 +00005418 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005419 ThrowMogrifyException(OptionError,"MissingArgument",option);
5420 if (IsGeometry(argv[i]) == MagickFalse)
5421 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5422 break;
5423 }
5424 if (LocaleCompare("rotate",option+1) == 0)
5425 {
5426 i++;
cristybb503372010-05-27 20:51:26 +00005427 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005428 ThrowMogrifyException(OptionError,"MissingArgument",option);
5429 if (IsGeometry(argv[i]) == MagickFalse)
5430 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5431 break;
5432 }
5433 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5434 }
5435 case 's':
5436 {
5437 if (LocaleCompare("sample",option+1) == 0)
5438 {
5439 if (*option == '+')
5440 break;
5441 i++;
cristybb503372010-05-27 20:51:26 +00005442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005443 ThrowMogrifyException(OptionError,"MissingArgument",option);
5444 if (IsGeometry(argv[i]) == MagickFalse)
5445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5446 break;
5447 }
5448 if (LocaleCompare("sampling-factor",option+1) == 0)
5449 {
5450 if (*option == '+')
5451 break;
5452 i++;
cristybb503372010-05-27 20:51:26 +00005453 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005454 ThrowMogrifyException(OptionError,"MissingArgument",option);
5455 if (IsGeometry(argv[i]) == MagickFalse)
5456 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5457 break;
5458 }
5459 if (LocaleCompare("scale",option+1) == 0)
5460 {
5461 if (*option == '+')
5462 break;
5463 i++;
cristybb503372010-05-27 20:51:26 +00005464 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005465 ThrowMogrifyException(OptionError,"MissingArgument",option);
5466 if (IsGeometry(argv[i]) == MagickFalse)
5467 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5468 break;
5469 }
5470 if (LocaleCompare("scene",option+1) == 0)
5471 {
5472 if (*option == '+')
5473 break;
5474 i++;
cristybb503372010-05-27 20:51:26 +00005475 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005476 ThrowMogrifyException(OptionError,"MissingArgument",option);
5477 if (IsGeometry(argv[i]) == MagickFalse)
5478 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5479 break;
5480 }
5481 if (LocaleCompare("seed",option+1) == 0)
5482 {
5483 if (*option == '+')
5484 break;
5485 i++;
cristybb503372010-05-27 20:51:26 +00005486 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005487 ThrowMogrifyException(OptionError,"MissingArgument",option);
5488 if (IsGeometry(argv[i]) == MagickFalse)
5489 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5490 break;
5491 }
5492 if (LocaleCompare("segment",option+1) == 0)
5493 {
5494 if (*option == '+')
5495 break;
5496 i++;
cristybb503372010-05-27 20:51:26 +00005497 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005498 ThrowMogrifyException(OptionError,"MissingArgument",option);
5499 if (IsGeometry(argv[i]) == MagickFalse)
5500 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5501 break;
5502 }
5503 if (LocaleCompare("selective-blur",option+1) == 0)
5504 {
5505 i++;
cristybb503372010-05-27 20:51:26 +00005506 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005507 ThrowMogrifyException(OptionError,"MissingArgument",option);
5508 if (IsGeometry(argv[i]) == MagickFalse)
5509 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5510 break;
5511 }
5512 if (LocaleCompare("separate",option+1) == 0)
5513 break;
5514 if (LocaleCompare("sepia-tone",option+1) == 0)
5515 {
5516 if (*option == '+')
5517 break;
5518 i++;
cristybb503372010-05-27 20:51:26 +00005519 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005520 ThrowMogrifyException(OptionError,"MissingArgument",option);
5521 if (IsGeometry(argv[i]) == MagickFalse)
5522 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5523 break;
5524 }
5525 if (LocaleCompare("set",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 (*option == '+')
5531 break;
5532 i++;
cristybb503372010-05-27 20:51:26 +00005533 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005534 ThrowMogrifyException(OptionError,"MissingArgument",option);
5535 break;
5536 }
5537 if (LocaleCompare("shade",option+1) == 0)
5538 {
5539 i++;
cristybb503372010-05-27 20:51:26 +00005540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005541 ThrowMogrifyException(OptionError,"MissingArgument",option);
5542 if (IsGeometry(argv[i]) == MagickFalse)
5543 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5544 break;
5545 }
5546 if (LocaleCompare("shadow",option+1) == 0)
5547 {
5548 if (*option == '+')
5549 break;
5550 i++;
cristybb503372010-05-27 20:51:26 +00005551 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005552 ThrowMogrifyException(OptionError,"MissingArgument",option);
5553 if (IsGeometry(argv[i]) == MagickFalse)
5554 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5555 break;
5556 }
5557 if (LocaleCompare("sharpen",option+1) == 0)
5558 {
5559 i++;
cristybb503372010-05-27 20:51:26 +00005560 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005561 ThrowMogrifyException(OptionError,"MissingArgument",option);
5562 if (IsGeometry(argv[i]) == MagickFalse)
5563 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5564 break;
5565 }
5566 if (LocaleCompare("shave",option+1) == 0)
5567 {
5568 if (*option == '+')
5569 break;
5570 i++;
cristybb503372010-05-27 20:51:26 +00005571 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005572 ThrowMogrifyException(OptionError,"MissingArgument",option);
5573 if (IsGeometry(argv[i]) == MagickFalse)
5574 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5575 break;
5576 }
5577 if (LocaleCompare("shear",option+1) == 0)
5578 {
5579 i++;
cristybb503372010-05-27 20:51:26 +00005580 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005581 ThrowMogrifyException(OptionError,"MissingArgument",option);
5582 if (IsGeometry(argv[i]) == MagickFalse)
5583 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5584 break;
5585 }
5586 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5587 {
5588 i++;
cristybb503372010-05-27 20:51:26 +00005589 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005590 ThrowMogrifyException(OptionError,"MissingArgument",option);
5591 if (IsGeometry(argv[i]) == MagickFalse)
5592 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5593 break;
5594 }
5595 if (LocaleCompare("size",option+1) == 0)
5596 {
5597 if (*option == '+')
5598 break;
5599 i++;
cristybb503372010-05-27 20:51:26 +00005600 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005601 ThrowMogrifyException(OptionError,"MissingArgument",option);
5602 if (IsGeometry(argv[i]) == MagickFalse)
5603 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5604 break;
5605 }
5606 if (LocaleCompare("sketch",option+1) == 0)
5607 {
5608 if (*option == '+')
5609 break;
5610 i++;
cristybb503372010-05-27 20:51:26 +00005611 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005612 ThrowMogrifyException(OptionError,"MissingArgument",option);
5613 if (IsGeometry(argv[i]) == MagickFalse)
5614 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5615 break;
5616 }
cristy4285d782011-02-09 20:12:28 +00005617 if (LocaleCompare("smush",option+1) == 0)
5618 {
cristy4285d782011-02-09 20:12:28 +00005619 i++;
5620 if (i == (ssize_t) argc)
5621 ThrowMogrifyException(OptionError,"MissingArgument",option);
5622 if (IsGeometry(argv[i]) == MagickFalse)
5623 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005624 i++;
5625 break;
5626 }
cristy3ed852e2009-09-05 21:47:34 +00005627 if (LocaleCompare("solarize",option+1) == 0)
5628 {
5629 if (*option == '+')
5630 break;
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);
5634 if (IsGeometry(argv[i]) == MagickFalse)
5635 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5636 break;
5637 }
5638 if (LocaleCompare("sparse-color",option+1) == 0)
5639 {
cristybb503372010-05-27 20:51:26 +00005640 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005641 op;
5642
5643 i++;
cristybb503372010-05-27 20:51:26 +00005644 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005645 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005646 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005647 if (op < 0)
5648 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5649 argv[i]);
5650 i++;
cristybb503372010-05-27 20:51:26 +00005651 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005652 ThrowMogrifyException(OptionError,"MissingArgument",option);
5653 break;
5654 }
5655 if (LocaleCompare("spread",option+1) == 0)
5656 {
5657 if (*option == '+')
5658 break;
5659 i++;
cristybb503372010-05-27 20:51:26 +00005660 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005661 ThrowMogrifyException(OptionError,"MissingArgument",option);
5662 if (IsGeometry(argv[i]) == MagickFalse)
5663 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5664 break;
5665 }
cristy0834d642011-03-18 18:26:08 +00005666 if (LocaleCompare("statistic",option+1) == 0)
5667 {
5668 ssize_t
5669 op;
5670
5671 if (*option == '+')
5672 break;
5673 i++;
5674 if (i == (ssize_t) argc)
5675 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005676 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005677 if (op < 0)
5678 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5679 argv[i]);
5680 i++;
5681 if (i == (ssize_t) (argc-1))
5682 ThrowMogrifyException(OptionError,"MissingArgument",option);
5683 if (IsGeometry(argv[i]) == MagickFalse)
5684 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5685 break;
5686 }
cristy3ed852e2009-09-05 21:47:34 +00005687 if (LocaleCompare("stretch",option+1) == 0)
5688 {
cristybb503372010-05-27 20:51:26 +00005689 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005690 stretch;
5691
5692 if (*option == '+')
5693 break;
5694 i++;
cristybb503372010-05-27 20:51:26 +00005695 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005696 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005697 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005698 if (stretch < 0)
5699 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5700 argv[i]);
5701 break;
5702 }
5703 if (LocaleCompare("strip",option+1) == 0)
5704 break;
5705 if (LocaleCompare("stroke",option+1) == 0)
5706 {
5707 if (*option == '+')
5708 break;
5709 i++;
cristybb503372010-05-27 20:51:26 +00005710 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005711 ThrowMogrifyException(OptionError,"MissingArgument",option);
5712 break;
5713 }
5714 if (LocaleCompare("strokewidth",option+1) == 0)
5715 {
5716 if (*option == '+')
5717 break;
5718 i++;
cristybb503372010-05-27 20:51:26 +00005719 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005720 ThrowMogrifyException(OptionError,"MissingArgument",option);
5721 if (IsGeometry(argv[i]) == MagickFalse)
5722 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5723 break;
5724 }
5725 if (LocaleCompare("style",option+1) == 0)
5726 {
cristybb503372010-05-27 20:51:26 +00005727 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005728 style;
5729
5730 if (*option == '+')
5731 break;
5732 i++;
cristybb503372010-05-27 20:51:26 +00005733 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005734 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005735 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005736 if (style < 0)
5737 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5738 argv[i]);
5739 break;
5740 }
cristyecb10ff2011-03-22 13:14:03 +00005741 if (LocaleCompare("swap",option+1) == 0)
5742 {
5743 if (*option == '+')
5744 break;
5745 i++;
5746 if (i == (ssize_t) (argc-1))
5747 ThrowMogrifyException(OptionError,"MissingArgument",option);
5748 if (IsGeometry(argv[i]) == MagickFalse)
5749 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5750 break;
5751 }
cristy3ed852e2009-09-05 21:47:34 +00005752 if (LocaleCompare("swirl",option+1) == 0)
5753 {
5754 if (*option == '+')
5755 break;
5756 i++;
cristybb503372010-05-27 20:51:26 +00005757 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005758 ThrowMogrifyException(OptionError,"MissingArgument",option);
5759 if (IsGeometry(argv[i]) == MagickFalse)
5760 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5761 break;
5762 }
cristyd9a29192010-10-16 16:49:53 +00005763 if (LocaleCompare("synchronize",option+1) == 0)
5764 break;
cristy3ed852e2009-09-05 21:47:34 +00005765 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5766 }
5767 case 't':
5768 {
5769 if (LocaleCompare("taint",option+1) == 0)
5770 break;
5771 if (LocaleCompare("texture",option+1) == 0)
5772 {
5773 if (*option == '+')
5774 break;
5775 i++;
cristybb503372010-05-27 20:51:26 +00005776 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005777 ThrowMogrifyException(OptionError,"MissingArgument",option);
5778 break;
5779 }
5780 if (LocaleCompare("tile",option+1) == 0)
5781 {
5782 if (*option == '+')
5783 break;
5784 i++;
cristybb503372010-05-27 20:51:26 +00005785 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005786 ThrowMogrifyException(OptionError,"MissingArgument",option);
5787 break;
5788 }
5789 if (LocaleCompare("tile-offset",option+1) == 0)
5790 {
5791 if (*option == '+')
5792 break;
5793 i++;
cristybb503372010-05-27 20:51:26 +00005794 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005795 ThrowMogrifyException(OptionError,"MissingArgument",option);
5796 if (IsGeometry(argv[i]) == MagickFalse)
5797 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5798 break;
5799 }
5800 if (LocaleCompare("tint",option+1) == 0)
5801 {
5802 if (*option == '+')
5803 break;
5804 i++;
cristybb503372010-05-27 20:51:26 +00005805 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005806 ThrowMogrifyException(OptionError,"MissingArgument",option);
5807 if (IsGeometry(argv[i]) == MagickFalse)
5808 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5809 break;
5810 }
5811 if (LocaleCompare("transform",option+1) == 0)
5812 break;
5813 if (LocaleCompare("transpose",option+1) == 0)
5814 break;
5815 if (LocaleCompare("transverse",option+1) == 0)
5816 break;
5817 if (LocaleCompare("threshold",option+1) == 0)
5818 {
5819 if (*option == '+')
5820 break;
5821 i++;
cristybb503372010-05-27 20:51:26 +00005822 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005823 ThrowMogrifyException(OptionError,"MissingArgument",option);
5824 if (IsGeometry(argv[i]) == MagickFalse)
5825 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5826 break;
5827 }
5828 if (LocaleCompare("thumbnail",option+1) == 0)
5829 {
5830 if (*option == '+')
5831 break;
5832 i++;
cristybb503372010-05-27 20:51:26 +00005833 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005834 ThrowMogrifyException(OptionError,"MissingArgument",option);
5835 if (IsGeometry(argv[i]) == MagickFalse)
5836 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5837 break;
5838 }
5839 if (LocaleCompare("transparent",option+1) == 0)
5840 {
5841 i++;
cristybb503372010-05-27 20:51:26 +00005842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005843 ThrowMogrifyException(OptionError,"MissingArgument",option);
5844 break;
5845 }
5846 if (LocaleCompare("transparent-color",option+1) == 0)
5847 {
5848 if (*option == '+')
5849 break;
5850 i++;
cristybb503372010-05-27 20:51:26 +00005851 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005852 ThrowMogrifyException(OptionError,"MissingArgument",option);
5853 break;
5854 }
5855 if (LocaleCompare("treedepth",option+1) == 0)
5856 {
5857 if (*option == '+')
5858 break;
5859 i++;
cristybb503372010-05-27 20:51:26 +00005860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005861 ThrowMogrifyException(OptionError,"MissingArgument",option);
5862 if (IsGeometry(argv[i]) == MagickFalse)
5863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5864 break;
5865 }
5866 if (LocaleCompare("trim",option+1) == 0)
5867 break;
5868 if (LocaleCompare("type",option+1) == 0)
5869 {
cristybb503372010-05-27 20:51:26 +00005870 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005871 type;
5872
5873 if (*option == '+')
5874 break;
5875 i++;
cristybb503372010-05-27 20:51:26 +00005876 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005877 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005878 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005879 if (type < 0)
5880 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5881 argv[i]);
5882 break;
5883 }
5884 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5885 }
5886 case 'u':
5887 {
5888 if (LocaleCompare("undercolor",option+1) == 0)
5889 {
5890 if (*option == '+')
5891 break;
5892 i++;
cristybb503372010-05-27 20:51:26 +00005893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005894 ThrowMogrifyException(OptionError,"MissingArgument",option);
5895 break;
5896 }
5897 if (LocaleCompare("unique-colors",option+1) == 0)
5898 break;
5899 if (LocaleCompare("units",option+1) == 0)
5900 {
cristybb503372010-05-27 20:51:26 +00005901 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005902 units;
5903
5904 if (*option == '+')
5905 break;
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);
cristy042ee782011-04-22 18:48:30 +00005909 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005910 argv[i]);
5911 if (units < 0)
5912 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5913 argv[i]);
5914 break;
5915 }
5916 if (LocaleCompare("unsharp",option+1) == 0)
5917 {
5918 i++;
cristybb503372010-05-27 20:51:26 +00005919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005920 ThrowMogrifyException(OptionError,"MissingArgument",option);
5921 if (IsGeometry(argv[i]) == MagickFalse)
5922 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5923 break;
5924 }
5925 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5926 }
5927 case 'v':
5928 {
5929 if (LocaleCompare("verbose",option+1) == 0)
5930 {
5931 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5932 break;
5933 }
5934 if ((LocaleCompare("version",option+1) == 0) ||
5935 (LocaleCompare("-version",option+1) == 0))
5936 {
cristyb51dff52011-05-19 16:55:47 +00005937 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005938 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005939 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5940 GetMagickCopyright());
5941 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5942 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005943 break;
5944 }
5945 if (LocaleCompare("view",option+1) == 0)
5946 {
5947 if (*option == '+')
5948 break;
5949 i++;
cristybb503372010-05-27 20:51:26 +00005950 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005951 ThrowMogrifyException(OptionError,"MissingArgument",option);
5952 break;
5953 }
5954 if (LocaleCompare("vignette",option+1) == 0)
5955 {
5956 if (*option == '+')
5957 break;
5958 i++;
cristybb503372010-05-27 20:51:26 +00005959 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005960 ThrowMogrifyException(OptionError,"MissingArgument",option);
5961 if (IsGeometry(argv[i]) == MagickFalse)
5962 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5963 break;
5964 }
5965 if (LocaleCompare("virtual-pixel",option+1) == 0)
5966 {
cristybb503372010-05-27 20:51:26 +00005967 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005968 method;
5969
5970 if (*option == '+')
5971 break;
5972 i++;
cristybb503372010-05-27 20:51:26 +00005973 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005974 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005975 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005976 argv[i]);
5977 if (method < 0)
5978 ThrowMogrifyException(OptionError,
5979 "UnrecognizedVirtualPixelMethod",argv[i]);
5980 break;
5981 }
5982 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5983 }
5984 case 'w':
5985 {
5986 if (LocaleCompare("wave",option+1) == 0)
5987 {
5988 i++;
cristybb503372010-05-27 20:51:26 +00005989 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005990 ThrowMogrifyException(OptionError,"MissingArgument",option);
5991 if (IsGeometry(argv[i]) == MagickFalse)
5992 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5993 break;
5994 }
5995 if (LocaleCompare("weight",option+1) == 0)
5996 {
5997 if (*option == '+')
5998 break;
5999 i++;
cristybb503372010-05-27 20:51:26 +00006000 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006001 ThrowMogrifyException(OptionError,"MissingArgument",option);
6002 break;
6003 }
6004 if (LocaleCompare("white-point",option+1) == 0)
6005 {
6006 if (*option == '+')
6007 break;
6008 i++;
cristybb503372010-05-27 20:51:26 +00006009 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006010 ThrowMogrifyException(OptionError,"MissingArgument",option);
6011 if (IsGeometry(argv[i]) == MagickFalse)
6012 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6013 break;
6014 }
6015 if (LocaleCompare("white-threshold",option+1) == 0)
6016 {
6017 if (*option == '+')
6018 break;
6019 i++;
cristybb503372010-05-27 20:51:26 +00006020 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006021 ThrowMogrifyException(OptionError,"MissingArgument",option);
6022 if (IsGeometry(argv[i]) == MagickFalse)
6023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6024 break;
6025 }
6026 if (LocaleCompare("write",option+1) == 0)
6027 {
6028 i++;
cristybb503372010-05-27 20:51:26 +00006029 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006030 ThrowMogrifyException(OptionError,"MissingArgument",option);
6031 break;
6032 }
6033 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6034 }
6035 case '?':
6036 break;
6037 default:
6038 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6039 }
cristy042ee782011-04-22 18:48:30 +00006040 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6041 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006042 if (fire != MagickFalse)
6043 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6044 }
6045 if (k != 0)
6046 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006047 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006048 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6049 DestroyMogrify();
6050 return(status != 0 ? MagickTrue : MagickFalse);
6051}
6052
6053/*
6054%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6055% %
6056% %
6057% %
6058+ M o g r i f y I m a g e I n f o %
6059% %
6060% %
6061% %
6062%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6063%
6064% MogrifyImageInfo() applies image processing settings to the image as
6065% prescribed by command line options.
6066%
6067% The format of the MogrifyImageInfo method is:
6068%
6069% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6070% const char **argv,ExceptionInfo *exception)
6071%
6072% A description of each parameter follows:
6073%
6074% o image_info: the image info..
6075%
6076% o argc: Specifies a pointer to an integer describing the number of
6077% elements in the argument vector.
6078%
6079% o argv: Specifies a pointer to a text array containing the command line
6080% arguments.
6081%
6082% o exception: return any errors or warnings in this structure.
6083%
6084*/
6085WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6086 const int argc,const char **argv,ExceptionInfo *exception)
6087{
6088 const char
6089 *option;
6090
6091 GeometryInfo
6092 geometry_info;
6093
cristybb503372010-05-27 20:51:26 +00006094 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006095 count;
6096
cristybb503372010-05-27 20:51:26 +00006097 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006098 i;
6099
6100 /*
6101 Initialize method variables.
6102 */
6103 assert(image_info != (ImageInfo *) NULL);
6104 assert(image_info->signature == MagickSignature);
6105 if (image_info->debug != MagickFalse)
6106 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6107 image_info->filename);
6108 if (argc < 0)
6109 return(MagickTrue);
6110 /*
6111 Set the image settings.
6112 */
cristybb503372010-05-27 20:51:26 +00006113 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006114 {
6115 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006116 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006117 continue;
cristy042ee782011-04-22 18:48:30 +00006118 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006119 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006120 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006121 break;
6122 switch (*(option+1))
6123 {
6124 case 'a':
6125 {
6126 if (LocaleCompare("adjoin",option+1) == 0)
6127 {
6128 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6129 break;
6130 }
6131 if (LocaleCompare("antialias",option+1) == 0)
6132 {
6133 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6134 break;
6135 }
6136 if (LocaleCompare("attenuate",option+1) == 0)
6137 {
6138 if (*option == '+')
6139 {
6140 (void) DeleteImageOption(image_info,option+1);
6141 break;
6142 }
6143 (void) SetImageOption(image_info,option+1,argv[i+1]);
6144 break;
6145 }
6146 if (LocaleCompare("authenticate",option+1) == 0)
6147 {
6148 if (*option == '+')
6149 (void) CloneString(&image_info->authenticate,(char *) NULL);
6150 else
6151 (void) CloneString(&image_info->authenticate,argv[i+1]);
6152 break;
6153 }
6154 break;
6155 }
6156 case 'b':
6157 {
6158 if (LocaleCompare("background",option+1) == 0)
6159 {
6160 if (*option == '+')
6161 {
6162 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006163 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006164 &image_info->background_color,exception);
6165 break;
6166 }
6167 (void) SetImageOption(image_info,option+1,argv[i+1]);
6168 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6169 exception);
6170 break;
6171 }
6172 if (LocaleCompare("bias",option+1) == 0)
6173 {
6174 if (*option == '+')
6175 {
6176 (void) SetImageOption(image_info,option+1,"0.0");
6177 break;
6178 }
6179 (void) SetImageOption(image_info,option+1,argv[i+1]);
6180 break;
6181 }
6182 if (LocaleCompare("black-point-compensation",option+1) == 0)
6183 {
6184 if (*option == '+')
6185 {
6186 (void) SetImageOption(image_info,option+1,"false");
6187 break;
6188 }
6189 (void) SetImageOption(image_info,option+1,"true");
6190 break;
6191 }
6192 if (LocaleCompare("blue-primary",option+1) == 0)
6193 {
6194 if (*option == '+')
6195 {
6196 (void) SetImageOption(image_info,option+1,"0.0");
6197 break;
6198 }
6199 (void) SetImageOption(image_info,option+1,argv[i+1]);
6200 break;
6201 }
6202 if (LocaleCompare("bordercolor",option+1) == 0)
6203 {
6204 if (*option == '+')
6205 {
6206 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006207 (void) QueryColorDatabase(MogrifyBorderColor,
6208 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006209 break;
6210 }
6211 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6212 exception);
6213 (void) SetImageOption(image_info,option+1,argv[i+1]);
6214 break;
6215 }
6216 if (LocaleCompare("box",option+1) == 0)
6217 {
6218 if (*option == '+')
6219 {
6220 (void) SetImageOption(image_info,"undercolor","none");
6221 break;
6222 }
6223 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6224 break;
6225 }
6226 break;
6227 }
6228 case 'c':
6229 {
6230 if (LocaleCompare("cache",option+1) == 0)
6231 {
6232 MagickSizeType
6233 limit;
6234
6235 limit=MagickResourceInfinity;
6236 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006237 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006238 (void) SetMagickResourceLimit(MemoryResource,limit);
6239 (void) SetMagickResourceLimit(MapResource,2*limit);
6240 break;
6241 }
6242 if (LocaleCompare("caption",option+1) == 0)
6243 {
6244 if (*option == '+')
6245 {
6246 (void) DeleteImageOption(image_info,option+1);
6247 break;
6248 }
6249 (void) SetImageOption(image_info,option+1,argv[i+1]);
6250 break;
6251 }
6252 if (LocaleCompare("channel",option+1) == 0)
6253 {
6254 if (*option == '+')
6255 {
6256 image_info->channel=DefaultChannels;
6257 break;
6258 }
6259 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6260 break;
6261 }
6262 if (LocaleCompare("colors",option+1) == 0)
6263 {
cristye27293e2009-12-18 02:53:20 +00006264 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006265 break;
6266 }
6267 if (LocaleCompare("colorspace",option+1) == 0)
6268 {
6269 if (*option == '+')
6270 {
6271 image_info->colorspace=UndefinedColorspace;
6272 (void) SetImageOption(image_info,option+1,"undefined");
6273 break;
6274 }
cristy042ee782011-04-22 18:48:30 +00006275 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006276 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6277 (void) SetImageOption(image_info,option+1,argv[i+1]);
6278 break;
6279 }
cristy3ed852e2009-09-05 21:47:34 +00006280 if (LocaleCompare("comment",option+1) == 0)
6281 {
6282 if (*option == '+')
6283 {
6284 (void) DeleteImageOption(image_info,option+1);
6285 break;
6286 }
6287 (void) SetImageOption(image_info,option+1,argv[i+1]);
6288 break;
6289 }
6290 if (LocaleCompare("compose",option+1) == 0)
6291 {
6292 if (*option == '+')
6293 {
6294 (void) SetImageOption(image_info,option+1,"undefined");
6295 break;
6296 }
6297 (void) SetImageOption(image_info,option+1,argv[i+1]);
6298 break;
6299 }
6300 if (LocaleCompare("compress",option+1) == 0)
6301 {
6302 if (*option == '+')
6303 {
6304 image_info->compression=UndefinedCompression;
6305 (void) SetImageOption(image_info,option+1,"undefined");
6306 break;
6307 }
cristy042ee782011-04-22 18:48:30 +00006308 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006309 MagickCompressOptions,MagickFalse,argv[i+1]);
6310 (void) SetImageOption(image_info,option+1,argv[i+1]);
6311 break;
6312 }
6313 break;
6314 }
6315 case 'd':
6316 {
6317 if (LocaleCompare("debug",option+1) == 0)
6318 {
6319 if (*option == '+')
6320 (void) SetLogEventMask("none");
6321 else
6322 (void) SetLogEventMask(argv[i+1]);
6323 image_info->debug=IsEventLogging();
6324 break;
6325 }
6326 if (LocaleCompare("define",option+1) == 0)
6327 {
6328 if (*option == '+')
6329 {
6330 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6331 (void) DeleteImageRegistry(argv[i+1]+9);
6332 else
6333 (void) DeleteImageOption(image_info,argv[i+1]);
6334 break;
6335 }
6336 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6337 {
6338 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6339 exception);
6340 break;
6341 }
6342 (void) DefineImageOption(image_info,argv[i+1]);
6343 break;
6344 }
6345 if (LocaleCompare("delay",option+1) == 0)
6346 {
6347 if (*option == '+')
6348 {
6349 (void) SetImageOption(image_info,option+1,"0");
6350 break;
6351 }
6352 (void) SetImageOption(image_info,option+1,argv[i+1]);
6353 break;
6354 }
6355 if (LocaleCompare("density",option+1) == 0)
6356 {
6357 /*
6358 Set image density.
6359 */
6360 if (*option == '+')
6361 {
6362 if (image_info->density != (char *) NULL)
6363 image_info->density=DestroyString(image_info->density);
6364 (void) SetImageOption(image_info,option+1,"72");
6365 break;
6366 }
6367 (void) CloneString(&image_info->density,argv[i+1]);
6368 (void) SetImageOption(image_info,option+1,argv[i+1]);
6369 break;
6370 }
6371 if (LocaleCompare("depth",option+1) == 0)
6372 {
6373 if (*option == '+')
6374 {
6375 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6376 break;
6377 }
cristye27293e2009-12-18 02:53:20 +00006378 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006379 break;
6380 }
cristyc9b12952010-03-28 01:12:28 +00006381 if (LocaleCompare("direction",option+1) == 0)
6382 {
6383 if (*option == '+')
6384 {
6385 (void) SetImageOption(image_info,option+1,"undefined");
6386 break;
6387 }
6388 (void) SetImageOption(image_info,option+1,argv[i+1]);
6389 break;
6390 }
cristy3ed852e2009-09-05 21:47:34 +00006391 if (LocaleCompare("display",option+1) == 0)
6392 {
6393 if (*option == '+')
6394 {
6395 if (image_info->server_name != (char *) NULL)
6396 image_info->server_name=DestroyString(
6397 image_info->server_name);
6398 break;
6399 }
6400 (void) CloneString(&image_info->server_name,argv[i+1]);
6401 break;
6402 }
6403 if (LocaleCompare("dispose",option+1) == 0)
6404 {
6405 if (*option == '+')
6406 {
6407 (void) SetImageOption(image_info,option+1,"undefined");
6408 break;
6409 }
6410 (void) SetImageOption(image_info,option+1,argv[i+1]);
6411 break;
6412 }
6413 if (LocaleCompare("dither",option+1) == 0)
6414 {
6415 if (*option == '+')
6416 {
6417 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006418 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006419 break;
6420 }
6421 (void) SetImageOption(image_info,option+1,argv[i+1]);
6422 image_info->dither=MagickTrue;
6423 break;
6424 }
6425 break;
6426 }
6427 case 'e':
6428 {
6429 if (LocaleCompare("encoding",option+1) == 0)
6430 {
6431 if (*option == '+')
6432 {
6433 (void) SetImageOption(image_info,option+1,"undefined");
6434 break;
6435 }
6436 (void) SetImageOption(image_info,option+1,argv[i+1]);
6437 break;
6438 }
6439 if (LocaleCompare("endian",option+1) == 0)
6440 {
6441 if (*option == '+')
6442 {
6443 image_info->endian=UndefinedEndian;
6444 (void) SetImageOption(image_info,option+1,"undefined");
6445 break;
6446 }
cristy042ee782011-04-22 18:48:30 +00006447 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006448 MagickEndianOptions,MagickFalse,argv[i+1]);
6449 (void) SetImageOption(image_info,option+1,argv[i+1]);
6450 break;
6451 }
6452 if (LocaleCompare("extract",option+1) == 0)
6453 {
6454 /*
6455 Set image extract geometry.
6456 */
6457 if (*option == '+')
6458 {
6459 if (image_info->extract != (char *) NULL)
6460 image_info->extract=DestroyString(image_info->extract);
6461 break;
6462 }
6463 (void) CloneString(&image_info->extract,argv[i+1]);
6464 break;
6465 }
6466 break;
6467 }
6468 case 'f':
6469 {
6470 if (LocaleCompare("fill",option+1) == 0)
6471 {
6472 if (*option == '+')
6473 {
6474 (void) SetImageOption(image_info,option+1,"none");
6475 break;
6476 }
6477 (void) SetImageOption(image_info,option+1,argv[i+1]);
6478 break;
6479 }
6480 if (LocaleCompare("filter",option+1) == 0)
6481 {
6482 if (*option == '+')
6483 {
6484 (void) SetImageOption(image_info,option+1,"undefined");
6485 break;
6486 }
6487 (void) SetImageOption(image_info,option+1,argv[i+1]);
6488 break;
6489 }
6490 if (LocaleCompare("font",option+1) == 0)
6491 {
6492 if (*option == '+')
6493 {
6494 if (image_info->font != (char *) NULL)
6495 image_info->font=DestroyString(image_info->font);
6496 break;
6497 }
6498 (void) CloneString(&image_info->font,argv[i+1]);
6499 break;
6500 }
6501 if (LocaleCompare("format",option+1) == 0)
6502 {
6503 register const char
6504 *q;
6505
6506 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006507 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006508 image_info->ping=MagickFalse;
6509 (void) SetImageOption(image_info,option+1,argv[i+1]);
6510 break;
6511 }
6512 if (LocaleCompare("fuzz",option+1) == 0)
6513 {
6514 if (*option == '+')
6515 {
6516 image_info->fuzz=0.0;
6517 (void) SetImageOption(image_info,option+1,"0");
6518 break;
6519 }
cristyf2f27272009-12-17 14:48:46 +00006520 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006521 1.0);
6522 (void) SetImageOption(image_info,option+1,argv[i+1]);
6523 break;
6524 }
6525 break;
6526 }
6527 case 'g':
6528 {
6529 if (LocaleCompare("gravity",option+1) == 0)
6530 {
6531 if (*option == '+')
6532 {
6533 (void) SetImageOption(image_info,option+1,"undefined");
6534 break;
6535 }
6536 (void) SetImageOption(image_info,option+1,argv[i+1]);
6537 break;
6538 }
6539 if (LocaleCompare("green-primary",option+1) == 0)
6540 {
6541 if (*option == '+')
6542 {
6543 (void) SetImageOption(image_info,option+1,"0.0");
6544 break;
6545 }
6546 (void) SetImageOption(image_info,option+1,argv[i+1]);
6547 break;
6548 }
6549 break;
6550 }
6551 case 'i':
6552 {
6553 if (LocaleCompare("intent",option+1) == 0)
6554 {
6555 if (*option == '+')
6556 {
6557 (void) SetImageOption(image_info,option+1,"undefined");
6558 break;
6559 }
6560 (void) SetImageOption(image_info,option+1,argv[i+1]);
6561 break;
6562 }
6563 if (LocaleCompare("interlace",option+1) == 0)
6564 {
6565 if (*option == '+')
6566 {
6567 image_info->interlace=UndefinedInterlace;
6568 (void) SetImageOption(image_info,option+1,"undefined");
6569 break;
6570 }
cristy042ee782011-04-22 18:48:30 +00006571 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006572 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6573 (void) SetImageOption(image_info,option+1,argv[i+1]);
6574 break;
6575 }
cristyb32b90a2009-09-07 21:45:48 +00006576 if (LocaleCompare("interline-spacing",option+1) == 0)
6577 {
6578 if (*option == '+')
6579 {
6580 (void) SetImageOption(image_info,option+1,"undefined");
6581 break;
6582 }
6583 (void) SetImageOption(image_info,option+1,argv[i+1]);
6584 break;
6585 }
cristy3ed852e2009-09-05 21:47:34 +00006586 if (LocaleCompare("interpolate",option+1) == 0)
6587 {
6588 if (*option == '+')
6589 {
6590 (void) SetImageOption(image_info,option+1,"undefined");
6591 break;
6592 }
6593 (void) SetImageOption(image_info,option+1,argv[i+1]);
6594 break;
6595 }
6596 if (LocaleCompare("interword-spacing",option+1) == 0)
6597 {
6598 if (*option == '+')
6599 {
6600 (void) SetImageOption(image_info,option+1,"undefined");
6601 break;
6602 }
6603 (void) SetImageOption(image_info,option+1,argv[i+1]);
6604 break;
6605 }
6606 break;
6607 }
6608 case 'k':
6609 {
6610 if (LocaleCompare("kerning",option+1) == 0)
6611 {
6612 if (*option == '+')
6613 {
6614 (void) SetImageOption(image_info,option+1,"undefined");
6615 break;
6616 }
6617 (void) SetImageOption(image_info,option+1,argv[i+1]);
6618 break;
6619 }
6620 break;
6621 }
6622 case 'l':
6623 {
6624 if (LocaleCompare("label",option+1) == 0)
6625 {
6626 if (*option == '+')
6627 {
6628 (void) DeleteImageOption(image_info,option+1);
6629 break;
6630 }
6631 (void) SetImageOption(image_info,option+1,argv[i+1]);
6632 break;
6633 }
6634 if (LocaleCompare("limit",option+1) == 0)
6635 {
6636 MagickSizeType
6637 limit;
6638
6639 ResourceType
6640 type;
6641
6642 if (*option == '+')
6643 break;
cristy042ee782011-04-22 18:48:30 +00006644 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006645 MagickFalse,argv[i+1]);
6646 limit=MagickResourceInfinity;
6647 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006648 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006649 (void) SetMagickResourceLimit(type,limit);
6650 break;
6651 }
6652 if (LocaleCompare("list",option+1) == 0)
6653 {
cristybb503372010-05-27 20:51:26 +00006654 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006655 list;
6656
6657 /*
6658 Display configuration list.
6659 */
cristy042ee782011-04-22 18:48:30 +00006660 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006661 switch (list)
6662 {
6663 case MagickCoderOptions:
6664 {
6665 (void) ListCoderInfo((FILE *) NULL,exception);
6666 break;
6667 }
6668 case MagickColorOptions:
6669 {
6670 (void) ListColorInfo((FILE *) NULL,exception);
6671 break;
6672 }
6673 case MagickConfigureOptions:
6674 {
6675 (void) ListConfigureInfo((FILE *) NULL,exception);
6676 break;
6677 }
6678 case MagickDelegateOptions:
6679 {
6680 (void) ListDelegateInfo((FILE *) NULL,exception);
6681 break;
6682 }
6683 case MagickFontOptions:
6684 {
6685 (void) ListTypeInfo((FILE *) NULL,exception);
6686 break;
6687 }
6688 case MagickFormatOptions:
6689 {
6690 (void) ListMagickInfo((FILE *) NULL,exception);
6691 break;
6692 }
6693 case MagickLocaleOptions:
6694 {
6695 (void) ListLocaleInfo((FILE *) NULL,exception);
6696 break;
6697 }
6698 case MagickLogOptions:
6699 {
6700 (void) ListLogInfo((FILE *) NULL,exception);
6701 break;
6702 }
6703 case MagickMagicOptions:
6704 {
6705 (void) ListMagicInfo((FILE *) NULL,exception);
6706 break;
6707 }
6708 case MagickMimeOptions:
6709 {
6710 (void) ListMimeInfo((FILE *) NULL,exception);
6711 break;
6712 }
6713 case MagickModuleOptions:
6714 {
6715 (void) ListModuleInfo((FILE *) NULL,exception);
6716 break;
6717 }
6718 case MagickPolicyOptions:
6719 {
6720 (void) ListPolicyInfo((FILE *) NULL,exception);
6721 break;
6722 }
6723 case MagickResourceOptions:
6724 {
6725 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6726 break;
6727 }
6728 case MagickThresholdOptions:
6729 {
6730 (void) ListThresholdMaps((FILE *) NULL,exception);
6731 break;
6732 }
6733 default:
6734 {
cristy042ee782011-04-22 18:48:30 +00006735 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006736 exception);
6737 break;
6738 }
6739 }
cristyaeb2cbc2010-05-07 13:28:58 +00006740 break;
cristy3ed852e2009-09-05 21:47:34 +00006741 }
6742 if (LocaleCompare("log",option+1) == 0)
6743 {
6744 if (*option == '+')
6745 break;
6746 (void) SetLogFormat(argv[i+1]);
6747 break;
6748 }
6749 if (LocaleCompare("loop",option+1) == 0)
6750 {
6751 if (*option == '+')
6752 {
6753 (void) SetImageOption(image_info,option+1,"0");
6754 break;
6755 }
6756 (void) SetImageOption(image_info,option+1,argv[i+1]);
6757 break;
6758 }
6759 break;
6760 }
6761 case 'm':
6762 {
6763 if (LocaleCompare("matte",option+1) == 0)
6764 {
6765 if (*option == '+')
6766 {
6767 (void) SetImageOption(image_info,option+1,"false");
6768 break;
6769 }
6770 (void) SetImageOption(image_info,option+1,"true");
6771 break;
6772 }
6773 if (LocaleCompare("mattecolor",option+1) == 0)
6774 {
6775 if (*option == '+')
6776 {
6777 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006778 (void) QueryColorDatabase(MogrifyMatteColor,
6779 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006780 break;
6781 }
6782 (void) SetImageOption(image_info,option+1,argv[i+1]);
6783 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6784 exception);
6785 break;
6786 }
6787 if (LocaleCompare("monitor",option+1) == 0)
6788 {
6789 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6790 (void *) NULL);
6791 break;
6792 }
6793 if (LocaleCompare("monochrome",option+1) == 0)
6794 {
6795 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6796 break;
6797 }
6798 break;
6799 }
6800 case 'o':
6801 {
6802 if (LocaleCompare("orient",option+1) == 0)
6803 {
6804 if (*option == '+')
6805 {
6806 image_info->orientation=UndefinedOrientation;
6807 (void) SetImageOption(image_info,option+1,"undefined");
6808 break;
6809 }
cristy042ee782011-04-22 18:48:30 +00006810 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006811 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006812 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006813 break;
6814 }
6815 }
6816 case 'p':
6817 {
6818 if (LocaleCompare("page",option+1) == 0)
6819 {
6820 char
6821 *canonical_page,
6822 page[MaxTextExtent];
6823
6824 const char
6825 *image_option;
6826
6827 MagickStatusType
6828 flags;
6829
6830 RectangleInfo
6831 geometry;
6832
6833 if (*option == '+')
6834 {
6835 (void) DeleteImageOption(image_info,option+1);
6836 (void) CloneString(&image_info->page,(char *) NULL);
6837 break;
6838 }
6839 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6840 image_option=GetImageOption(image_info,"page");
6841 if (image_option != (const char *) NULL)
6842 flags=ParseAbsoluteGeometry(image_option,&geometry);
6843 canonical_page=GetPageGeometry(argv[i+1]);
6844 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6845 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006846 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006847 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006848 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006849 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006850 (unsigned long) geometry.width,(unsigned long) geometry.height,
6851 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006852 (void) SetImageOption(image_info,option+1,page);
6853 (void) CloneString(&image_info->page,page);
6854 break;
6855 }
6856 if (LocaleCompare("pen",option+1) == 0)
6857 {
6858 if (*option == '+')
6859 {
6860 (void) SetImageOption(image_info,option+1,"none");
6861 break;
6862 }
6863 (void) SetImageOption(image_info,option+1,argv[i+1]);
6864 break;
6865 }
6866 if (LocaleCompare("ping",option+1) == 0)
6867 {
6868 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6869 break;
6870 }
6871 if (LocaleCompare("pointsize",option+1) == 0)
6872 {
6873 if (*option == '+')
6874 geometry_info.rho=0.0;
6875 else
6876 (void) ParseGeometry(argv[i+1],&geometry_info);
6877 image_info->pointsize=geometry_info.rho;
6878 break;
6879 }
cristye7f51092010-01-17 00:39:37 +00006880 if (LocaleCompare("precision",option+1) == 0)
6881 {
cristybf2766a2010-01-17 03:33:23 +00006882 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006883 break;
6884 }
cristy3ed852e2009-09-05 21:47:34 +00006885 if (LocaleCompare("preview",option+1) == 0)
6886 {
6887 /*
6888 Preview image.
6889 */
6890 if (*option == '+')
6891 {
6892 image_info->preview_type=UndefinedPreview;
6893 break;
6894 }
cristy042ee782011-04-22 18:48:30 +00006895 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006896 MagickPreviewOptions,MagickFalse,argv[i+1]);
6897 break;
6898 }
6899 break;
6900 }
6901 case 'q':
6902 {
6903 if (LocaleCompare("quality",option+1) == 0)
6904 {
6905 /*
6906 Set image compression quality.
6907 */
6908 if (*option == '+')
6909 {
6910 image_info->quality=UndefinedCompressionQuality;
6911 (void) SetImageOption(image_info,option+1,"0");
6912 break;
6913 }
cristye27293e2009-12-18 02:53:20 +00006914 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006915 (void) SetImageOption(image_info,option+1,argv[i+1]);
6916 break;
6917 }
6918 if (LocaleCompare("quiet",option+1) == 0)
6919 {
6920 static WarningHandler
6921 warning_handler = (WarningHandler) NULL;
6922
6923 if (*option == '+')
6924 {
6925 /*
6926 Restore error or warning messages.
6927 */
6928 warning_handler=SetWarningHandler(warning_handler);
6929 break;
6930 }
6931 /*
6932 Suppress error or warning messages.
6933 */
6934 warning_handler=SetWarningHandler((WarningHandler) NULL);
6935 break;
6936 }
6937 break;
6938 }
6939 case 'r':
6940 {
6941 if (LocaleCompare("red-primary",option+1) == 0)
6942 {
6943 if (*option == '+')
6944 {
6945 (void) SetImageOption(image_info,option+1,"0.0");
6946 break;
6947 }
6948 (void) SetImageOption(image_info,option+1,argv[i+1]);
6949 break;
6950 }
6951 break;
6952 }
6953 case 's':
6954 {
6955 if (LocaleCompare("sampling-factor",option+1) == 0)
6956 {
6957 /*
6958 Set image sampling factor.
6959 */
6960 if (*option == '+')
6961 {
6962 if (image_info->sampling_factor != (char *) NULL)
6963 image_info->sampling_factor=DestroyString(
6964 image_info->sampling_factor);
6965 break;
6966 }
6967 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6968 break;
6969 }
6970 if (LocaleCompare("scene",option+1) == 0)
6971 {
6972 /*
6973 Set image scene.
6974 */
6975 if (*option == '+')
6976 {
6977 image_info->scene=0;
6978 (void) SetImageOption(image_info,option+1,"0");
6979 break;
6980 }
cristye27293e2009-12-18 02:53:20 +00006981 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006982 (void) SetImageOption(image_info,option+1,argv[i+1]);
6983 break;
6984 }
6985 if (LocaleCompare("seed",option+1) == 0)
6986 {
cristybb503372010-05-27 20:51:26 +00006987 size_t
cristy3ed852e2009-09-05 21:47:34 +00006988 seed;
6989
6990 if (*option == '+')
6991 {
cristybb503372010-05-27 20:51:26 +00006992 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006993 SeedPseudoRandomGenerator(seed);
6994 break;
6995 }
cristye27293e2009-12-18 02:53:20 +00006996 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006997 SeedPseudoRandomGenerator(seed);
6998 break;
6999 }
7000 if (LocaleCompare("size",option+1) == 0)
7001 {
7002 if (*option == '+')
7003 {
7004 if (image_info->size != (char *) NULL)
7005 image_info->size=DestroyString(image_info->size);
7006 break;
7007 }
7008 (void) CloneString(&image_info->size,argv[i+1]);
7009 break;
7010 }
7011 if (LocaleCompare("stroke",option+1) == 0)
7012 {
7013 if (*option == '+')
7014 {
7015 (void) SetImageOption(image_info,option+1,"none");
7016 break;
7017 }
7018 (void) SetImageOption(image_info,option+1,argv[i+1]);
7019 break;
7020 }
7021 if (LocaleCompare("strokewidth",option+1) == 0)
7022 {
7023 if (*option == '+')
7024 {
7025 (void) SetImageOption(image_info,option+1,"0");
7026 break;
7027 }
7028 (void) SetImageOption(image_info,option+1,argv[i+1]);
7029 break;
7030 }
cristyd9a29192010-10-16 16:49:53 +00007031 if (LocaleCompare("synchronize",option+1) == 0)
7032 {
7033 if (*option == '+')
7034 {
7035 image_info->synchronize=MagickFalse;
7036 break;
7037 }
7038 image_info->synchronize=MagickTrue;
7039 break;
7040 }
cristy3ed852e2009-09-05 21:47:34 +00007041 break;
7042 }
7043 case 't':
7044 {
7045 if (LocaleCompare("taint",option+1) == 0)
7046 {
7047 if (*option == '+')
7048 {
7049 (void) SetImageOption(image_info,option+1,"false");
7050 break;
7051 }
7052 (void) SetImageOption(image_info,option+1,"true");
7053 break;
7054 }
7055 if (LocaleCompare("texture",option+1) == 0)
7056 {
7057 if (*option == '+')
7058 {
7059 if (image_info->texture != (char *) NULL)
7060 image_info->texture=DestroyString(image_info->texture);
7061 break;
7062 }
7063 (void) CloneString(&image_info->texture,argv[i+1]);
7064 break;
7065 }
7066 if (LocaleCompare("tile-offset",option+1) == 0)
7067 {
7068 if (*option == '+')
7069 {
7070 (void) SetImageOption(image_info,option+1,"0");
7071 break;
7072 }
7073 (void) SetImageOption(image_info,option+1,argv[i+1]);
7074 break;
7075 }
7076 if (LocaleCompare("transparent-color",option+1) == 0)
7077 {
7078 if (*option == '+')
7079 {
7080 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7081 (void) SetImageOption(image_info,option+1,"none");
7082 break;
7083 }
7084 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7085 exception);
7086 (void) SetImageOption(image_info,option+1,argv[i+1]);
7087 break;
7088 }
7089 if (LocaleCompare("type",option+1) == 0)
7090 {
7091 if (*option == '+')
7092 {
cristy5f1c1ff2010-12-23 21:38:06 +00007093 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007094 (void) SetImageOption(image_info,option+1,"undefined");
7095 break;
7096 }
cristy042ee782011-04-22 18:48:30 +00007097 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007098 MagickFalse,argv[i+1]);
7099 (void) SetImageOption(image_info,option+1,argv[i+1]);
7100 break;
7101 }
7102 break;
7103 }
7104 case 'u':
7105 {
7106 if (LocaleCompare("undercolor",option+1) == 0)
7107 {
7108 if (*option == '+')
7109 {
7110 (void) DeleteImageOption(image_info,option+1);
7111 break;
7112 }
7113 (void) SetImageOption(image_info,option+1,argv[i+1]);
7114 break;
7115 }
7116 if (LocaleCompare("units",option+1) == 0)
7117 {
7118 if (*option == '+')
7119 {
7120 image_info->units=UndefinedResolution;
7121 (void) SetImageOption(image_info,option+1,"undefined");
7122 break;
7123 }
cristy042ee782011-04-22 18:48:30 +00007124 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007125 MagickResolutionOptions,MagickFalse,argv[i+1]);
7126 (void) SetImageOption(image_info,option+1,argv[i+1]);
7127 break;
7128 }
7129 break;
7130 }
7131 case 'v':
7132 {
7133 if (LocaleCompare("verbose",option+1) == 0)
7134 {
7135 if (*option == '+')
7136 {
7137 image_info->verbose=MagickFalse;
7138 break;
7139 }
7140 image_info->verbose=MagickTrue;
7141 image_info->ping=MagickFalse;
7142 break;
7143 }
7144 if (LocaleCompare("view",option+1) == 0)
7145 {
7146 if (*option == '+')
7147 {
7148 if (image_info->view != (char *) NULL)
7149 image_info->view=DestroyString(image_info->view);
7150 break;
7151 }
7152 (void) CloneString(&image_info->view,argv[i+1]);
7153 break;
7154 }
7155 if (LocaleCompare("virtual-pixel",option+1) == 0)
7156 {
7157 if (*option == '+')
7158 {
7159 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7160 (void) SetImageOption(image_info,option+1,"undefined");
7161 break;
7162 }
7163 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007164 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007165 argv[i+1]);
7166 (void) SetImageOption(image_info,option+1,argv[i+1]);
7167 break;
7168 }
7169 break;
7170 }
7171 case 'w':
7172 {
7173 if (LocaleCompare("white-point",option+1) == 0)
7174 {
7175 if (*option == '+')
7176 {
7177 (void) SetImageOption(image_info,option+1,"0.0");
7178 break;
7179 }
7180 (void) SetImageOption(image_info,option+1,argv[i+1]);
7181 break;
7182 }
7183 break;
7184 }
7185 default:
7186 break;
7187 }
7188 i+=count;
7189 }
7190 return(MagickTrue);
7191}
7192
7193/*
7194%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7195% %
7196% %
7197% %
7198+ M o g r i f y I m a g e L i s t %
7199% %
7200% %
7201% %
7202%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7203%
7204% MogrifyImageList() applies any command line options that might affect the
7205% entire image list (e.g. -append, -coalesce, etc.).
7206%
7207% The format of the MogrifyImage method is:
7208%
7209% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7210% const char **argv,Image **images,ExceptionInfo *exception)
7211%
7212% A description of each parameter follows:
7213%
7214% o image_info: the image info..
7215%
7216% o argc: Specifies a pointer to an integer describing the number of
7217% elements in the argument vector.
7218%
7219% o argv: Specifies a pointer to a text array containing the command line
7220% arguments.
7221%
anthonye9c27192011-03-27 08:07:06 +00007222% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007223%
7224% o exception: return any errors or warnings in this structure.
7225%
7226*/
7227WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7228 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7229{
cristy3ed852e2009-09-05 21:47:34 +00007230 const char
7231 *option;
7232
cristy6b3da3a2010-06-20 02:21:46 +00007233 ImageInfo
7234 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007235
7236 MagickStatusType
7237 status;
7238
cristy28474bf2011-09-11 23:32:52 +00007239 PixelInterpolateMethod
7240 interpolate_method;
7241
cristy3ed852e2009-09-05 21:47:34 +00007242 QuantizeInfo
7243 *quantize_info;
7244
cristybb503372010-05-27 20:51:26 +00007245 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007246 i;
7247
cristy6b3da3a2010-06-20 02:21:46 +00007248 ssize_t
7249 count,
7250 index;
7251
cristy3ed852e2009-09-05 21:47:34 +00007252 /*
7253 Apply options to the image list.
7254 */
7255 assert(image_info != (ImageInfo *) NULL);
7256 assert(image_info->signature == MagickSignature);
7257 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007258 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007259 assert((*images)->signature == MagickSignature);
7260 if ((*images)->debug != MagickFalse)
7261 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7262 (*images)->filename);
7263 if ((argc <= 0) || (*argv == (char *) NULL))
7264 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007265 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007266 mogrify_info=CloneImageInfo(image_info);
7267 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007268 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007269 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007270 {
cristy74fe8f12009-10-03 19:09:01 +00007271 if (*images == (Image *) NULL)
7272 break;
cristy3ed852e2009-09-05 21:47:34 +00007273 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007274 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007275 continue;
cristy042ee782011-04-22 18:48:30 +00007276 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007277 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007278 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007279 break;
cristy6b3da3a2010-06-20 02:21:46 +00007280 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007281 switch (*(option+1))
7282 {
7283 case 'a':
7284 {
7285 if (LocaleCompare("affinity",option+1) == 0)
7286 {
cristy6b3da3a2010-06-20 02:21:46 +00007287 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007288 if (*option == '+')
7289 {
cristy018f07f2011-09-04 21:15:19 +00007290 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7291 exception);
cristy3ed852e2009-09-05 21:47:34 +00007292 break;
7293 }
7294 i++;
7295 break;
7296 }
7297 if (LocaleCompare("append",option+1) == 0)
7298 {
7299 Image
7300 *append_image;
7301
cristy6b3da3a2010-06-20 02:21:46 +00007302 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007303 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7304 MagickFalse,exception);
7305 if (append_image == (Image *) NULL)
7306 {
7307 status=MagickFalse;
7308 break;
7309 }
7310 *images=DestroyImageList(*images);
7311 *images=append_image;
7312 break;
7313 }
7314 if (LocaleCompare("average",option+1) == 0)
7315 {
7316 Image
7317 *average_image;
7318
cristyd18ae7c2010-03-07 17:39:52 +00007319 /*
7320 Average an image sequence (deprecated).
7321 */
cristy6b3da3a2010-06-20 02:21:46 +00007322 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007323 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7324 exception);
cristy3ed852e2009-09-05 21:47:34 +00007325 if (average_image == (Image *) NULL)
7326 {
7327 status=MagickFalse;
7328 break;
7329 }
7330 *images=DestroyImageList(*images);
7331 *images=average_image;
7332 break;
7333 }
7334 break;
7335 }
7336 case 'c':
7337 {
7338 if (LocaleCompare("channel",option+1) == 0)
7339 {
cristyf4ad9df2011-07-08 16:49:03 +00007340 ChannelType
7341 channel;
7342
cristy3ed852e2009-09-05 21:47:34 +00007343 if (*option == '+')
7344 {
7345 channel=DefaultChannels;
7346 break;
7347 }
7348 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007349 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007350 break;
7351 }
7352 if (LocaleCompare("clut",option+1) == 0)
7353 {
7354 Image
7355 *clut_image,
7356 *image;
7357
cristy6b3da3a2010-06-20 02:21:46 +00007358 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007359 image=RemoveFirstImageFromList(images);
7360 clut_image=RemoveFirstImageFromList(images);
7361 if (clut_image == (Image *) NULL)
7362 {
7363 status=MagickFalse;
7364 break;
7365 }
cristy28474bf2011-09-11 23:32:52 +00007366 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007367 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007368 *images=DestroyImageList(*images);
7369 *images=image;
7370 break;
7371 }
7372 if (LocaleCompare("coalesce",option+1) == 0)
7373 {
7374 Image
7375 *coalesce_image;
7376
cristy6b3da3a2010-06-20 02:21:46 +00007377 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007378 coalesce_image=CoalesceImages(*images,exception);
7379 if (coalesce_image == (Image *) NULL)
7380 {
7381 status=MagickFalse;
7382 break;
7383 }
7384 *images=DestroyImageList(*images);
7385 *images=coalesce_image;
7386 break;
7387 }
7388 if (LocaleCompare("combine",option+1) == 0)
7389 {
7390 Image
7391 *combine_image;
7392
cristy6b3da3a2010-06-20 02:21:46 +00007393 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007394 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007395 if (combine_image == (Image *) NULL)
7396 {
7397 status=MagickFalse;
7398 break;
7399 }
7400 *images=DestroyImageList(*images);
7401 *images=combine_image;
7402 break;
7403 }
7404 if (LocaleCompare("composite",option+1) == 0)
7405 {
7406 Image
7407 *mask_image,
7408 *composite_image,
7409 *image;
7410
7411 RectangleInfo
7412 geometry;
7413
cristy6b3da3a2010-06-20 02:21:46 +00007414 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007415 image=RemoveFirstImageFromList(images);
7416 composite_image=RemoveFirstImageFromList(images);
7417 if (composite_image == (Image *) NULL)
7418 {
7419 status=MagickFalse;
7420 break;
7421 }
7422 (void) TransformImage(&composite_image,(char *) NULL,
7423 composite_image->geometry);
7424 SetGeometry(composite_image,&geometry);
7425 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7426 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7427 &geometry);
7428 mask_image=RemoveFirstImageFromList(images);
7429 if (mask_image != (Image *) NULL)
7430 {
7431 if ((image->compose == DisplaceCompositeOp) ||
7432 (image->compose == DistortCompositeOp))
7433 {
7434 /*
7435 Merge Y displacement into X displacement image.
7436 */
7437 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7438 mask_image,0,0);
7439 mask_image=DestroyImage(mask_image);
7440 }
7441 else
7442 {
7443 /*
7444 Set a blending mask for the composition.
cristy28474bf2011-09-11 23:32:52 +00007445 Posible error, what if image->mask already set.
cristy3ed852e2009-09-05 21:47:34 +00007446 */
7447 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007448 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007449 }
7450 }
cristyf4ad9df2011-07-08 16:49:03 +00007451 (void) CompositeImage(image,image->compose,composite_image,
7452 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007453 if (mask_image != (Image *) NULL)
7454 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007455 composite_image=DestroyImage(composite_image);
7456 InheritException(exception,&image->exception);
7457 *images=DestroyImageList(*images);
7458 *images=image;
7459 break;
7460 }
cristy3ed852e2009-09-05 21:47:34 +00007461 break;
7462 }
7463 case 'd':
7464 {
7465 if (LocaleCompare("deconstruct",option+1) == 0)
7466 {
7467 Image
7468 *deconstruct_image;
7469
cristy6b3da3a2010-06-20 02:21:46 +00007470 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007471 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007472 exception);
cristy3ed852e2009-09-05 21:47:34 +00007473 if (deconstruct_image == (Image *) NULL)
7474 {
7475 status=MagickFalse;
7476 break;
7477 }
7478 *images=DestroyImageList(*images);
7479 *images=deconstruct_image;
7480 break;
7481 }
7482 if (LocaleCompare("delete",option+1) == 0)
7483 {
7484 if (*option == '+')
7485 DeleteImages(images,"-1",exception);
7486 else
7487 DeleteImages(images,argv[i+1],exception);
7488 break;
7489 }
7490 if (LocaleCompare("dither",option+1) == 0)
7491 {
7492 if (*option == '+')
7493 {
7494 quantize_info->dither=MagickFalse;
7495 break;
7496 }
7497 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007498 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007499 MagickDitherOptions,MagickFalse,argv[i+1]);
7500 break;
7501 }
cristyecb10ff2011-03-22 13:14:03 +00007502 if (LocaleCompare("duplicate",option+1) == 0)
7503 {
cristy72988482011-03-29 16:34:38 +00007504 Image
7505 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007506
anthony2b6bcae2011-03-23 13:05:34 +00007507 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007508 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7509 else
7510 {
7511 const char
7512 *p;
7513
anthony2b6bcae2011-03-23 13:05:34 +00007514 size_t
7515 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007516
anthony2b6bcae2011-03-23 13:05:34 +00007517 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007518 p=strchr(argv[i+1],',');
7519 if (p == (const char *) NULL)
7520 duplicate_images=DuplicateImages(*images,number_duplicates,
7521 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007522 else
cristy72988482011-03-29 16:34:38 +00007523 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7524 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007525 }
7526 AppendImageToList(images, duplicate_images);
7527 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007528 break;
7529 }
cristy3ed852e2009-09-05 21:47:34 +00007530 break;
7531 }
cristyd18ae7c2010-03-07 17:39:52 +00007532 case 'e':
7533 {
7534 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7535 {
7536 Image
7537 *evaluate_image;
7538
7539 MagickEvaluateOperator
7540 op;
7541
cristy6b3da3a2010-06-20 02:21:46 +00007542 (void) SyncImageSettings(mogrify_info,*images);
cristy28474bf2011-09-11 23:32:52 +00007543 op=(MagickEvaluateOperator) ParseCommandOption(
7544 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007545 evaluate_image=EvaluateImages(*images,op,exception);
7546 if (evaluate_image == (Image *) NULL)
7547 {
7548 status=MagickFalse;
7549 break;
7550 }
7551 *images=DestroyImageList(*images);
7552 *images=evaluate_image;
7553 break;
7554 }
7555 break;
7556 }
cristy3ed852e2009-09-05 21:47:34 +00007557 case 'f':
7558 {
cristyf0a247f2009-10-04 00:20:03 +00007559 if (LocaleCompare("fft",option+1) == 0)
7560 {
7561 Image
7562 *fourier_image;
7563
7564 /*
7565 Implements the discrete Fourier transform (DFT).
7566 */
cristy6b3da3a2010-06-20 02:21:46 +00007567 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007568 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7569 MagickTrue : MagickFalse,exception);
7570 if (fourier_image == (Image *) NULL)
7571 break;
7572 *images=DestroyImage(*images);
7573 *images=fourier_image;
7574 break;
7575 }
cristy3ed852e2009-09-05 21:47:34 +00007576 if (LocaleCompare("flatten",option+1) == 0)
7577 {
7578 Image
7579 *flatten_image;
7580
cristy6b3da3a2010-06-20 02:21:46 +00007581 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007582 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7583 if (flatten_image == (Image *) NULL)
7584 break;
7585 *images=DestroyImageList(*images);
7586 *images=flatten_image;
7587 break;
7588 }
7589 if (LocaleCompare("fx",option+1) == 0)
7590 {
7591 Image
7592 *fx_image;
7593
cristy6b3da3a2010-06-20 02:21:46 +00007594 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007595 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007596 if (fx_image == (Image *) NULL)
7597 {
7598 status=MagickFalse;
7599 break;
7600 }
7601 *images=DestroyImageList(*images);
7602 *images=fx_image;
7603 break;
7604 }
7605 break;
7606 }
7607 case 'h':
7608 {
7609 if (LocaleCompare("hald-clut",option+1) == 0)
7610 {
7611 Image
7612 *hald_image,
7613 *image;
7614
cristy6b3da3a2010-06-20 02:21:46 +00007615 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007616 image=RemoveFirstImageFromList(images);
7617 hald_image=RemoveFirstImageFromList(images);
7618 if (hald_image == (Image *) NULL)
7619 {
7620 status=MagickFalse;
7621 break;
7622 }
cristy7c0a0a42011-08-23 17:57:25 +00007623 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007624 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007625 if (*images != (Image *) NULL)
7626 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007627 *images=image;
7628 break;
7629 }
7630 break;
7631 }
7632 case 'i':
7633 {
7634 if (LocaleCompare("ift",option+1) == 0)
7635 {
7636 Image
cristy8587f882009-11-13 20:28:49 +00007637 *fourier_image,
7638 *magnitude_image,
7639 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007640
7641 /*
7642 Implements the inverse fourier discrete Fourier transform (DFT).
7643 */
cristy6b3da3a2010-06-20 02:21:46 +00007644 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007645 magnitude_image=RemoveFirstImageFromList(images);
7646 phase_image=RemoveFirstImageFromList(images);
7647 if (phase_image == (Image *) NULL)
7648 {
7649 status=MagickFalse;
7650 break;
7651 }
7652 fourier_image=InverseFourierTransformImage(magnitude_image,
7653 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007654 if (fourier_image == (Image *) NULL)
7655 break;
cristy0aff6ea2009-11-14 01:40:53 +00007656 if (*images != (Image *) NULL)
7657 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007658 *images=fourier_image;
7659 break;
7660 }
7661 if (LocaleCompare("insert",option+1) == 0)
7662 {
7663 Image
7664 *p,
7665 *q;
7666
7667 index=0;
7668 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007669 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007670 p=RemoveLastImageFromList(images);
7671 if (p == (Image *) NULL)
7672 {
7673 (void) ThrowMagickException(exception,GetMagickModule(),
7674 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7675 status=MagickFalse;
7676 break;
7677 }
7678 q=p;
7679 if (index == 0)
7680 PrependImageToList(images,q);
7681 else
cristybb503372010-05-27 20:51:26 +00007682 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007683 AppendImageToList(images,q);
7684 else
7685 {
7686 q=GetImageFromList(*images,index-1);
7687 if (q == (Image *) NULL)
7688 {
7689 (void) ThrowMagickException(exception,GetMagickModule(),
7690 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7691 status=MagickFalse;
7692 break;
7693 }
7694 InsertImageInList(&q,p);
7695 }
7696 *images=GetFirstImageInList(q);
7697 break;
7698 }
cristy28474bf2011-09-11 23:32:52 +00007699 if (LocaleCompare("interpolate",option+1) == 0)
7700 {
7701 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7702 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7703 break;
7704 }
cristy3ed852e2009-09-05 21:47:34 +00007705 break;
7706 }
7707 case 'l':
7708 {
7709 if (LocaleCompare("layers",option+1) == 0)
7710 {
7711 Image
7712 *layers;
7713
7714 ImageLayerMethod
7715 method;
7716
cristy6b3da3a2010-06-20 02:21:46 +00007717 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007718 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007719 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007720 MagickFalse,argv[i+1]);
7721 switch (method)
7722 {
7723 case CoalesceLayer:
7724 {
7725 layers=CoalesceImages(*images,exception);
7726 break;
7727 }
7728 case CompareAnyLayer:
7729 case CompareClearLayer:
7730 case CompareOverlayLayer:
7731 default:
7732 {
cristy8a9106f2011-07-05 14:39:26 +00007733 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007734 break;
7735 }
7736 case MergeLayer:
7737 case FlattenLayer:
7738 case MosaicLayer:
7739 case TrimBoundsLayer:
7740 {
7741 layers=MergeImageLayers(*images,method,exception);
7742 break;
7743 }
7744 case DisposeLayer:
7745 {
7746 layers=DisposeImages(*images,exception);
7747 break;
7748 }
7749 case OptimizeImageLayer:
7750 {
7751 layers=OptimizeImageLayers(*images,exception);
7752 break;
7753 }
7754 case OptimizePlusLayer:
7755 {
7756 layers=OptimizePlusImageLayers(*images,exception);
7757 break;
7758 }
7759 case OptimizeTransLayer:
7760 {
7761 OptimizeImageTransparency(*images,exception);
7762 break;
7763 }
7764 case RemoveDupsLayer:
7765 {
7766 RemoveDuplicateLayers(images,exception);
7767 break;
7768 }
7769 case RemoveZeroLayer:
7770 {
7771 RemoveZeroDelayLayers(images,exception);
7772 break;
7773 }
7774 case OptimizeLayer:
7775 {
7776 /*
7777 General Purpose, GIF Animation Optimizer.
7778 */
7779 layers=CoalesceImages(*images,exception);
7780 if (layers == (Image *) NULL)
7781 {
7782 status=MagickFalse;
7783 break;
7784 }
cristy3ed852e2009-09-05 21:47:34 +00007785 *images=DestroyImageList(*images);
7786 *images=layers;
7787 layers=OptimizeImageLayers(*images,exception);
7788 if (layers == (Image *) NULL)
7789 {
7790 status=MagickFalse;
7791 break;
7792 }
cristy3ed852e2009-09-05 21:47:34 +00007793 *images=DestroyImageList(*images);
7794 *images=layers;
7795 layers=(Image *) NULL;
7796 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007797 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7798 exception);
cristy3ed852e2009-09-05 21:47:34 +00007799 break;
7800 }
7801 case CompositeLayer:
7802 {
7803 CompositeOperator
7804 compose;
7805
7806 Image
7807 *source;
7808
7809 RectangleInfo
7810 geometry;
7811
7812 /*
7813 Split image sequence at the first 'NULL:' image.
7814 */
7815 source=(*images);
7816 while (source != (Image *) NULL)
7817 {
7818 source=GetNextImageInList(source);
7819 if ((source != (Image *) NULL) &&
7820 (LocaleCompare(source->magick,"NULL") == 0))
7821 break;
7822 }
7823 if (source != (Image *) NULL)
7824 {
7825 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7826 (GetNextImageInList(source) == (Image *) NULL))
7827 source=(Image *) NULL;
7828 else
7829 {
7830 /*
7831 Separate the two lists, junk the null: image.
7832 */
7833 source=SplitImageList(source->previous);
7834 DeleteImageFromList(&source);
7835 }
7836 }
7837 if (source == (Image *) NULL)
7838 {
7839 (void) ThrowMagickException(exception,GetMagickModule(),
7840 OptionError,"MissingNullSeparator","layers Composite");
7841 status=MagickFalse;
7842 break;
7843 }
7844 /*
7845 Adjust offset with gravity and virtual canvas.
7846 */
7847 SetGeometry(*images,&geometry);
7848 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7849 geometry.width=source->page.width != 0 ?
7850 source->page.width : source->columns;
7851 geometry.height=source->page.height != 0 ?
7852 source->page.height : source->rows;
7853 GravityAdjustGeometry((*images)->page.width != 0 ?
7854 (*images)->page.width : (*images)->columns,
7855 (*images)->page.height != 0 ? (*images)->page.height :
7856 (*images)->rows,(*images)->gravity,&geometry);
7857 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007858 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007859 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007860 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007861 MagickComposeOptions,MagickFalse,option);
7862 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7863 exception);
7864 source=DestroyImageList(source);
7865 break;
7866 }
7867 }
7868 if (layers == (Image *) NULL)
7869 break;
7870 InheritException(exception,&layers->exception);
7871 *images=DestroyImageList(*images);
7872 *images=layers;
7873 break;
7874 }
7875 break;
7876 }
7877 case 'm':
7878 {
7879 if (LocaleCompare("map",option+1) == 0)
7880 {
cristy6b3da3a2010-06-20 02:21:46 +00007881 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007882 if (*option == '+')
7883 {
cristy018f07f2011-09-04 21:15:19 +00007884 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7885 exception);
cristy3ed852e2009-09-05 21:47:34 +00007886 break;
7887 }
7888 i++;
7889 break;
7890 }
cristyf40785b2010-03-06 02:27:27 +00007891 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007892 {
7893 Image
cristyf40785b2010-03-06 02:27:27 +00007894 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007895
cristyd18ae7c2010-03-07 17:39:52 +00007896 /*
7897 Maximum image sequence (deprecated).
7898 */
cristy6b3da3a2010-06-20 02:21:46 +00007899 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007900 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007901 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007902 {
7903 status=MagickFalse;
7904 break;
7905 }
7906 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007907 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007908 break;
7909 }
cristyf40785b2010-03-06 02:27:27 +00007910 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007911 {
7912 Image
cristyf40785b2010-03-06 02:27:27 +00007913 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007914
cristyd18ae7c2010-03-07 17:39:52 +00007915 /*
7916 Minimum image sequence (deprecated).
7917 */
cristy6b3da3a2010-06-20 02:21:46 +00007918 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007919 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007920 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007921 {
7922 status=MagickFalse;
7923 break;
7924 }
7925 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007926 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007927 break;
7928 }
cristy3ed852e2009-09-05 21:47:34 +00007929 if (LocaleCompare("morph",option+1) == 0)
7930 {
7931 Image
7932 *morph_image;
7933
cristy6b3da3a2010-06-20 02:21:46 +00007934 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007935 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007936 exception);
7937 if (morph_image == (Image *) NULL)
7938 {
7939 status=MagickFalse;
7940 break;
7941 }
7942 *images=DestroyImageList(*images);
7943 *images=morph_image;
7944 break;
7945 }
7946 if (LocaleCompare("mosaic",option+1) == 0)
7947 {
7948 Image
7949 *mosaic_image;
7950
cristy6b3da3a2010-06-20 02:21:46 +00007951 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007952 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7953 if (mosaic_image == (Image *) NULL)
7954 {
7955 status=MagickFalse;
7956 break;
7957 }
7958 *images=DestroyImageList(*images);
7959 *images=mosaic_image;
7960 break;
7961 }
7962 break;
7963 }
7964 case 'p':
7965 {
7966 if (LocaleCompare("print",option+1) == 0)
7967 {
7968 char
7969 *string;
7970
cristy6b3da3a2010-06-20 02:21:46 +00007971 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007972 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7973 exception);
cristy3ed852e2009-09-05 21:47:34 +00007974 if (string == (char *) NULL)
7975 break;
cristyb51dff52011-05-19 16:55:47 +00007976 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007977 string=DestroyString(string);
7978 }
7979 if (LocaleCompare("process",option+1) == 0)
7980 {
7981 char
7982 **arguments;
7983
7984 int
7985 j,
7986 number_arguments;
7987
cristy6b3da3a2010-06-20 02:21:46 +00007988 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007989 arguments=StringToArgv(argv[i+1],&number_arguments);
7990 if (arguments == (char **) NULL)
7991 break;
7992 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7993 {
7994 char
7995 breaker,
7996 quote,
7997 *token;
7998
7999 const char
8000 *arguments;
8001
8002 int
8003 next,
8004 status;
8005
8006 size_t
8007 length;
8008
8009 TokenInfo
8010 *token_info;
8011
8012 /*
8013 Support old style syntax, filter="-option arg".
8014 */
8015 length=strlen(argv[i+1]);
8016 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008017 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008018 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8019 sizeof(*token));
8020 if (token == (char *) NULL)
8021 break;
8022 next=0;
8023 arguments=argv[i+1];
8024 token_info=AcquireTokenInfo();
8025 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8026 "\"",'\0',&breaker,&next,&quote);
8027 token_info=DestroyTokenInfo(token_info);
8028 if (status == 0)
8029 {
8030 const char
8031 *argv;
8032
8033 argv=(&(arguments[next]));
8034 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8035 exception);
8036 }
8037 token=DestroyString(token);
8038 break;
8039 }
cristy91c0da22010-05-02 01:44:07 +00008040 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008041 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8042 number_arguments-2,(const char **) arguments+2,exception);
8043 for (j=0; j < number_arguments; j++)
8044 arguments[j]=DestroyString(arguments[j]);
8045 arguments=(char **) RelinquishMagickMemory(arguments);
8046 break;
8047 }
8048 break;
8049 }
8050 case 'r':
8051 {
8052 if (LocaleCompare("reverse",option+1) == 0)
8053 {
8054 ReverseImageList(images);
8055 InheritException(exception,&(*images)->exception);
8056 break;
8057 }
8058 break;
8059 }
8060 case 's':
8061 {
cristy4285d782011-02-09 20:12:28 +00008062 if (LocaleCompare("smush",option+1) == 0)
8063 {
8064 Image
8065 *smush_image;
8066
8067 ssize_t
8068 offset;
8069
8070 (void) SyncImagesSettings(mogrify_info,*images);
8071 offset=(ssize_t) StringToLong(argv[i+1]);
8072 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8073 MagickFalse,offset,exception);
8074 if (smush_image == (Image *) NULL)
8075 {
8076 status=MagickFalse;
8077 break;
8078 }
8079 *images=DestroyImageList(*images);
8080 *images=smush_image;
8081 break;
8082 }
cristy3ed852e2009-09-05 21:47:34 +00008083 if (LocaleCompare("swap",option+1) == 0)
8084 {
8085 Image
8086 *p,
8087 *q,
8088 *swap;
8089
cristybb503372010-05-27 20:51:26 +00008090 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008091 swap_index;
8092
8093 index=(-1);
8094 swap_index=(-2);
8095 if (*option != '+')
8096 {
8097 GeometryInfo
8098 geometry_info;
8099
8100 MagickStatusType
8101 flags;
8102
8103 swap_index=(-1);
8104 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008105 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008106 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008107 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008108 }
8109 p=GetImageFromList(*images,index);
8110 q=GetImageFromList(*images,swap_index);
8111 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8112 {
8113 (void) ThrowMagickException(exception,GetMagickModule(),
8114 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8115 status=MagickFalse;
8116 break;
8117 }
8118 if (p == q)
8119 break;
8120 swap=CloneImage(p,0,0,MagickTrue,exception);
8121 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8122 ReplaceImageInList(&q,swap);
8123 *images=GetFirstImageInList(q);
8124 break;
8125 }
8126 break;
8127 }
8128 case 'w':
8129 {
8130 if (LocaleCompare("write",option+1) == 0)
8131 {
cristy071dd7b2010-04-09 13:04:54 +00008132 char
cristy06609ee2010-03-17 20:21:27 +00008133 key[MaxTextExtent];
8134
cristy3ed852e2009-09-05 21:47:34 +00008135 Image
8136 *write_images;
8137
8138 ImageInfo
8139 *write_info;
8140
cristy6b3da3a2010-06-20 02:21:46 +00008141 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008142 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008143 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008144 write_images=(*images);
8145 if (*option == '+')
8146 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008147 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008148 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8149 write_info=DestroyImageInfo(write_info);
8150 if (*option == '+')
8151 write_images=DestroyImageList(write_images);
8152 break;
8153 }
8154 break;
8155 }
8156 default:
8157 break;
8158 }
8159 i+=count;
8160 }
8161 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008162 mogrify_info=DestroyImageInfo(mogrify_info);
8163 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008164 return(status != 0 ? MagickTrue : MagickFalse);
8165}
8166
8167/*
8168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8169% %
8170% %
8171% %
8172+ M o g r i f y I m a g e s %
8173% %
8174% %
8175% %
8176%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8177%
8178% MogrifyImages() applies image processing options to a sequence of images as
8179% prescribed by command line options.
8180%
8181% The format of the MogrifyImage method is:
8182%
8183% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8184% const MagickBooleanType post,const int argc,const char **argv,
8185% Image **images,Exceptioninfo *exception)
8186%
8187% A description of each parameter follows:
8188%
8189% o image_info: the image info..
8190%
8191% o post: If true, post process image list operators otherwise pre-process.
8192%
8193% o argc: Specifies a pointer to an integer describing the number of
8194% elements in the argument vector.
8195%
8196% o argv: Specifies a pointer to a text array containing the command line
8197% arguments.
8198%
anthonye9c27192011-03-27 08:07:06 +00008199% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008200%
8201% o exception: return any errors or warnings in this structure.
8202%
8203*/
8204WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8205 const MagickBooleanType post,const int argc,const char **argv,
8206 Image **images,ExceptionInfo *exception)
8207{
8208#define MogrifyImageTag "Mogrify/Image"
8209
anthonye9c27192011-03-27 08:07:06 +00008210 MagickStatusType
8211 status;
cristy3ed852e2009-09-05 21:47:34 +00008212
cristy0e9f9c12010-02-11 03:00:47 +00008213 MagickBooleanType
8214 proceed;
8215
anthonye9c27192011-03-27 08:07:06 +00008216 size_t
8217 n;
cristy3ed852e2009-09-05 21:47:34 +00008218
cristybb503372010-05-27 20:51:26 +00008219 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008220 i;
8221
cristy3ed852e2009-09-05 21:47:34 +00008222 assert(image_info != (ImageInfo *) NULL);
8223 assert(image_info->signature == MagickSignature);
8224 if (images == (Image **) NULL)
8225 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008226 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008227 assert((*images)->signature == MagickSignature);
8228 if ((*images)->debug != MagickFalse)
8229 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8230 (*images)->filename);
8231 if ((argc <= 0) || (*argv == (char *) NULL))
8232 return(MagickTrue);
8233 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8234 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008235 status=0;
anthonye9c27192011-03-27 08:07:06 +00008236
anthonyce2716b2011-04-22 09:51:34 +00008237#if 0
cristy1e604812011-05-19 18:07:50 +00008238 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8239 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008240#endif
8241
anthonye9c27192011-03-27 08:07:06 +00008242 /*
8243 Pre-process multi-image sequence operators
8244 */
cristy3ed852e2009-09-05 21:47:34 +00008245 if (post == MagickFalse)
8246 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008247 /*
8248 For each image, process simple single image operators
8249 */
8250 i=0;
8251 n=GetImageListLength(*images);
8252 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008253 {
anthonyce2716b2011-04-22 09:51:34 +00008254#if 0
cristy1e604812011-05-19 18:07:50 +00008255 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8256 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008257#endif
anthonye9c27192011-03-27 08:07:06 +00008258 status&=MogrifyImage(image_info,argc,argv,images,exception);
8259 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008260 if (proceed == MagickFalse)
8261 break;
anthonye9c27192011-03-27 08:07:06 +00008262 if ( (*images)->next == (Image *) NULL )
8263 break;
8264 *images=(*images)->next;
8265 i++;
cristy3ed852e2009-09-05 21:47:34 +00008266 }
anthonye9c27192011-03-27 08:07:06 +00008267 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008268#if 0
cristy1e604812011-05-19 18:07:50 +00008269 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8270 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008271#endif
anthonye9c27192011-03-27 08:07:06 +00008272
8273 /*
8274 Post-process, multi-image sequence operators
8275 */
8276 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008277 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008278 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008279 return(status != 0 ? MagickTrue : MagickFalse);
8280}