blob: 4c16c93826d7258a3b7fdd0b7b819e605f4b66ea [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
54#include "MagickCore/thread-private.h"
55#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000056
57/*
cristy154fa9d2011-08-05 14:25:15 +000058 Constant declaration.
59*/
cristy3a557c02011-08-06 19:48:02 +000060static const char
cristy638895a2011-08-06 23:19:14 +000061 MogrifyBackgroundColor[] = "#ffffff", /* white */
62 MogrifyBorderColor[] = "#dfdfdf", /* gray */
63 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000064
65/*
cristy3ed852e2009-09-05 21:47:34 +000066 Define declarations.
67*/
68#define UndefinedCompressionQuality 0UL
69
70/*
cristy3ed852e2009-09-05 21:47:34 +000071%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% %
73% %
74% %
cristy5063d812010-10-19 16:28:10 +000075% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000076% %
77% %
78% %
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80%
81% MagickCommandGenesis() applies image processing options to an image as
82% prescribed by command line options.
83%
84% The format of the MagickCommandGenesis method is:
85%
86% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000087% MagickCommand command,int argc,char **argv,char **metadata,
88% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000089%
90% A description of each parameter follows:
91%
92% o image_info: the image info.
93%
cristy5063d812010-10-19 16:28:10 +000094% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000095% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000096% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
97% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000098%
99% o argc: Specifies a pointer to an integer describing the number of
100% elements in the argument vector.
101%
102% o argv: Specifies a pointer to a text array containing the command line
103% arguments.
104%
cristy5063d812010-10-19 16:28:10 +0000105% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000106%
107% o exception: return any errors or warnings in this structure.
108%
109*/
110WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
111 MagickCommand command,int argc,char **argv,char **metadata,
112 ExceptionInfo *exception)
113{
114 char
115 *option;
116
117 double
118 duration,
119 elapsed_time,
120 user_time;
121
cristy3980b0d2009-10-25 14:37:13 +0000122 MagickBooleanType
123 concurrent,
124 regard_warnings,
125 status;
126
cristybb503372010-05-27 20:51:26 +0000127 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000128 i;
129
130 TimerInfo
131 *timer;
132
cristybb503372010-05-27 20:51:26 +0000133 size_t
cristy3980b0d2009-10-25 14:37:13 +0000134 iterations;
135
cristyd0a94fa2010-03-12 14:18:11 +0000136 (void) setlocale(LC_ALL,"");
137 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000138 concurrent=MagickFalse;
139 duration=(-1.0);
140 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000141 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000142 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000143 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000144 {
145 option=argv[i];
146 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
147 continue;
148 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000149 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000150 if (LocaleCompare("concurrent",option+1) == 0)
151 concurrent=MagickTrue;
152 if (LocaleCompare("debug",option+1) == 0)
153 (void) SetLogEventMask(argv[++i]);
154 if (LocaleCompare("duration",option+1) == 0)
cristyc1acd842011-05-19 23:05:47 +0000155 duration=InterpretLocaleValue(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000156 if (LocaleCompare("regard-warnings",option+1) == 0)
157 regard_warnings=MagickTrue;
158 }
159 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000160 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000161 {
cristybb503372010-05-27 20:51:26 +0000162 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000163 {
cristy33557d72009-11-06 00:54:33 +0000164 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000165 continue;
166 if (duration > 0)
167 {
168 if (GetElapsedTime(timer) > duration)
169 continue;
170 (void) ContinueTimer(timer);
171 }
172 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000173 if (exception->severity != UndefinedException)
174 {
175 if ((exception->severity > ErrorException) ||
176 (regard_warnings != MagickFalse))
177 status=MagickTrue;
178 CatchException(exception);
179 }
cristy3d1a5512009-10-25 21:23:27 +0000180 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000181 {
182 (void) fputs(*metadata,stdout);
183 (void) fputc('\n',stdout);
184 *metadata=DestroyString(*metadata);
185 }
186 }
187 }
cristyceae09d2009-10-28 17:18:47 +0000188 else
189 {
190 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000191#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000192 # pragma omp parallel for shared(status)
193#endif
cristybb503372010-05-27 20:51:26 +0000194 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000195 {
cristy33557d72009-11-06 00:54:33 +0000196 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000197 continue;
198 if (duration > 0)
199 {
200 if (GetElapsedTime(timer) > duration)
201 continue;
202 (void) ContinueTimer(timer);
203 }
204 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000205#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000206 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000207#endif
208 {
209 if (exception->severity != UndefinedException)
210 {
211 if ((exception->severity > ErrorException) ||
212 (regard_warnings != MagickFalse))
213 status=MagickTrue;
214 CatchException(exception);
215 }
216 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
217 {
218 (void) fputs(*metadata,stdout);
219 (void) fputc('\n',stdout);
220 *metadata=DestroyString(*metadata);
221 }
222 }
223 }
224 }
cristy3980b0d2009-10-25 14:37:13 +0000225 if (iterations > 1)
226 {
227 elapsed_time=GetElapsedTime(timer);
228 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000229 (void) FormatLocaleFile(stderr,
cristye8c25f92010-06-03 00:53:06 +0000230 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
231 iterations,1.0*iterations/elapsed_time,user_time,(double)
232 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
233 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000234 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000235 }
236 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000237 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000238}
239
240/*
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242% %
243% %
244% %
cristy3ed852e2009-09-05 21:47:34 +0000245+ M o g r i f y I m a g e %
246% %
247% %
248% %
249%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250%
anthonye9c27192011-03-27 08:07:06 +0000251% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000252% image that may be part of a large list, but also handles any 'region'
253% image handling.
anthonye9c27192011-03-27 08:07:06 +0000254%
255% The image in the list may be modified in three different ways...
256%
257% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
258% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
259% * replace by a list of images (only the -separate option!)
260%
261% In each case the result is returned into the list, and a pointer to the
262% modified image (last image added if replaced by a list of images) is
263% returned.
264%
265% ASIDE: The -crop is present but restricted to non-tile single image crops
266%
267% This means if all the images are being processed (such as by
268% MogrifyImages(), next image to be processed will be as per the pointer
269% (*image)->next. Also the image list may grow as a result of some specific
270% operations but as images are never merged or deleted, it will never shrink
271% in length. Typically the list will remain the same length.
272%
273% WARNING: As the image pointed to may be replaced, the first image in the
274% list may also change. GetFirstImageInList() should be used by caller if
275% they wish return the Image pointer to the first image in list.
276%
cristy3ed852e2009-09-05 21:47:34 +0000277%
278% The format of the MogrifyImage method is:
279%
280% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
281% const char **argv,Image **image)
282%
283% A description of each parameter follows:
284%
285% o image_info: the image info..
286%
287% o argc: Specifies a pointer to an integer describing the number of
288% elements in the argument vector.
289%
290% o argv: Specifies a pointer to a text array containing the command line
291% arguments.
292%
293% o image: the image.
294%
295% o exception: return any errors or warnings in this structure.
296%
297*/
298
cristy4c08aed2011-07-01 19:47:50 +0000299/*
300** GetImageCache() will read an image into a image cache if not already
301** present then return the image that is in the cache under that filename.
302*/
anthonydf8ebac2011-04-27 09:03:19 +0000303static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
304 ExceptionInfo *exception)
305{
306 char
307 key[MaxTextExtent];
308
309 ExceptionInfo
310 *sans_exception;
311
312 Image
313 *image;
314
315 ImageInfo
316 *read_info;
317
cristyb51dff52011-05-19 16:55:47 +0000318 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000319 sans_exception=AcquireExceptionInfo();
320 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
321 sans_exception=DestroyExceptionInfo(sans_exception);
322 if (image != (Image *) NULL)
323 return(image);
324 read_info=CloneImageInfo(image_info);
325 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
326 image=ReadImage(read_info,exception);
327 read_info=DestroyImageInfo(read_info);
328 if (image != (Image *) NULL)
329 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
330 return(image);
331}
332
cristy3ed852e2009-09-05 21:47:34 +0000333static MagickBooleanType IsPathWritable(const char *path)
334{
335 if (IsPathAccessible(path) == MagickFalse)
336 return(MagickFalse);
337 if (access(path,W_OK) != 0)
338 return(MagickFalse);
339 return(MagickTrue);
340}
341
cristybb503372010-05-27 20:51:26 +0000342static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000343{
344 if (x > y)
345 return(x);
346 return(y);
347}
348
anthonydf8ebac2011-04-27 09:03:19 +0000349static MagickBooleanType MonitorProgress(const char *text,
350 const MagickOffsetType offset,const MagickSizeType extent,
351 void *wand_unused(client_data))
352{
353 char
354 message[MaxTextExtent],
355 tag[MaxTextExtent];
356
357 const char
358 *locale_message;
359
360 register char
361 *p;
362
363 if (extent < 2)
364 return(MagickTrue);
365 (void) CopyMagickMemory(tag,text,MaxTextExtent);
366 p=strrchr(tag,'/');
367 if (p != (char *) NULL)
368 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000369 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000370 locale_message=GetLocaleMessage(message);
371 if (locale_message == message)
372 locale_message=tag;
373 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000374 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
375 locale_message,(long) offset,(unsigned long) extent,(long)
376 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000377 else
cristyb51dff52011-05-19 16:55:47 +0000378 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000379 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
380 (100L*offset/(extent-1)));
381 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000382 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000383 (void) fflush(stderr);
384 return(MagickTrue);
385}
386
387/*
anthony3d2f4862011-05-01 13:48:16 +0000388** SparseColorOption() parses the complex -sparse-color argument into an
389** an array of floating point values then calls SparseColorImage().
anthonydf8ebac2011-04-27 09:03:19 +0000390** Argument is a complex mix of floating-point pixel coodinates, and color
391** specifications (or direct floating point numbers). The number of floats
anthony3d2f4862011-05-01 13:48:16 +0000392** needed to represent a color varies depending on the current channel
anthonydf8ebac2011-04-27 09:03:19 +0000393** setting.
394*/
cristy3884f692011-07-08 18:00:18 +0000395static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000396 const SparseColorMethod method,const char *arguments,
397 const MagickBooleanType color_from_image,ExceptionInfo *exception)
398{
anthonydf8ebac2011-04-27 09:03:19 +0000399 char
400 token[MaxTextExtent];
401
402 const char
403 *p;
404
405 double
406 *sparse_arguments;
407
anthonydf8ebac2011-04-27 09:03:19 +0000408 Image
409 *sparse_image;
410
cristy4c08aed2011-07-01 19:47:50 +0000411 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000412 color;
413
414 MagickBooleanType
415 error;
416
cristy5f09d852011-05-29 01:39:29 +0000417 register size_t
418 x;
419
420 size_t
421 number_arguments,
422 number_colors;
423
anthonydf8ebac2011-04-27 09:03:19 +0000424 assert(image != (Image *) NULL);
425 assert(image->signature == MagickSignature);
426 if (image->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
428 assert(exception != (ExceptionInfo *) NULL);
429 assert(exception->signature == MagickSignature);
430 /*
431 Limit channels according to image - and add up number of color channel.
432 */
anthonydf8ebac2011-04-27 09:03:19 +0000433 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000434 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000435 number_colors++;
cristyed231572011-07-14 02:18:59 +0000436 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000437 number_colors++;
cristyed231572011-07-14 02:18:59 +0000438 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000439 number_colors++;
cristyed231572011-07-14 02:18:59 +0000440 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000441 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000442 number_colors++;
cristyed231572011-07-14 02:18:59 +0000443 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000444 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000445 number_colors++;
446
447 /*
448 Read string, to determine number of arguments needed,
449 */
450 p=arguments;
451 x=0;
452 while( *p != '\0' )
453 {
454 GetMagickToken(p,&p,token);
455 if ( token[0] == ',' ) continue;
456 if ( isalpha((int) token[0]) || token[0] == '#' ) {
457 if ( color_from_image ) {
458 (void) ThrowMagickException(exception,GetMagickModule(),
459 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
460 "Color arg given, when colors are coming from image");
461 return( (Image *)NULL);
462 }
463 x += number_colors; /* color argument */
464 }
465 else {
466 x++; /* floating point argument */
467 }
468 }
469 error=MagickTrue;
470 if ( color_from_image ) {
471 /* just the control points are being given */
472 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
473 number_arguments=(x/2)*(2+number_colors);
474 }
475 else {
476 /* control points and color values */
477 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
478 number_arguments=x;
479 }
480 if ( error ) {
481 (void) ThrowMagickException(exception,GetMagickModule(),
482 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
483 "Invalid number of Arguments");
484 return( (Image *)NULL);
485 }
486
487 /* Allocate and fill in the floating point arguments */
488 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
489 sizeof(*sparse_arguments));
490 if (sparse_arguments == (double *) NULL) {
491 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
492 "MemoryAllocationFailed","%s","SparseColorOption");
493 return( (Image *)NULL);
494 }
495 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
496 sizeof(*sparse_arguments));
497 p=arguments;
498 x=0;
499 while( *p != '\0' && x < number_arguments ) {
500 /* X coordinate */
501 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
502 if ( token[0] == '\0' ) break;
503 if ( isalpha((int) token[0]) || token[0] == '#' ) {
504 (void) ThrowMagickException(exception,GetMagickModule(),
505 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
506 "Color found, instead of X-coord");
507 error = MagickTrue;
508 break;
509 }
cristyc1acd842011-05-19 23:05:47 +0000510 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000511 /* Y coordinate */
512 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
513 if ( token[0] == '\0' ) break;
514 if ( isalpha((int) token[0]) || token[0] == '#' ) {
515 (void) ThrowMagickException(exception,GetMagickModule(),
516 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
517 "Color found, instead of Y-coord");
518 error = MagickTrue;
519 break;
520 }
cristyc1acd842011-05-19 23:05:47 +0000521 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000522 /* color values for this control point */
523#if 0
524 if ( (color_from_image ) {
525 /* get color from image */
526 /* HOW??? */
527 }
528 else
529#endif
530 {
531 /* color name or function given in string argument */
532 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
533 if ( token[0] == '\0' ) break;
534 if ( isalpha((int) token[0]) || token[0] == '#' ) {
535 /* Color string given */
536 (void) QueryMagickColor(token,&color,exception);
cristyed231572011-07-14 02:18:59 +0000537 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000538 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000539 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000540 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000541 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000542 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000543 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000544 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000545 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000546 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000547 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000548 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000549 }
550 else {
551 /* Colors given as a set of floating point values - experimental */
552 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000553 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000554 {
anthonydf8ebac2011-04-27 09:03:19 +0000555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristyc1acd842011-05-19 23:05:47 +0000558 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000559 token[0] = ','; /* used this token - get another */
560 }
cristyed231572011-07-14 02:18:59 +0000561 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000562 {
anthonydf8ebac2011-04-27 09:03:19 +0000563 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
564 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
565 break;
cristyc1acd842011-05-19 23:05:47 +0000566 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000567 token[0] = ','; /* used this token - get another */
568 }
cristyed231572011-07-14 02:18:59 +0000569 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000570 {
anthonydf8ebac2011-04-27 09:03:19 +0000571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristyc1acd842011-05-19 23:05:47 +0000574 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
cristyed231572011-07-14 02:18:59 +0000577 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000578 (image->colorspace == CMYKColorspace))
579 {
anthonydf8ebac2011-04-27 09:03:19 +0000580 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
581 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
582 break;
cristyc1acd842011-05-19 23:05:47 +0000583 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000584 token[0] = ','; /* used this token - get another */
585 }
cristyed231572011-07-14 02:18:59 +0000586 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000587 (image->matte != MagickFalse))
588 {
anthonydf8ebac2011-04-27 09:03:19 +0000589 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
590 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
591 break;
cristyc1acd842011-05-19 23:05:47 +0000592 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000593 token[0] = ','; /* used this token - get another */
594 }
595 }
596 }
597 }
598 if ( number_arguments != x && !error ) {
599 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
600 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
601 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
602 return( (Image *)NULL);
603 }
604 if ( error )
605 return( (Image *)NULL);
606
607 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000608 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
609 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000610 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
611 return( sparse_image );
612}
613
cristy3ed852e2009-09-05 21:47:34 +0000614WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
615 const char **argv,Image **image,ExceptionInfo *exception)
616{
anthonydf8ebac2011-04-27 09:03:19 +0000617 ChannelType
618 channel;
619
620 const char
621 *format,
622 *option;
623
624 DrawInfo
625 *draw_info;
626
627 GeometryInfo
628 geometry_info;
629
cristy3ed852e2009-09-05 21:47:34 +0000630 Image
631 *region_image;
632
anthonydf8ebac2011-04-27 09:03:19 +0000633 ImageInfo
634 *mogrify_info;
635
cristyebbcfea2011-02-25 02:43:54 +0000636 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000637 status;
638
cristy4c08aed2011-07-01 19:47:50 +0000639 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000640 fill;
cristy3ed852e2009-09-05 21:47:34 +0000641
anthonydf8ebac2011-04-27 09:03:19 +0000642 MagickStatusType
643 flags;
644
645 QuantizeInfo
646 *quantize_info;
647
648 RectangleInfo
649 geometry,
650 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000651
cristybb503372010-05-27 20:51:26 +0000652 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000653 i;
654
655 /*
656 Initialize method variables.
657 */
658 assert(image_info != (const ImageInfo *) NULL);
659 assert(image_info->signature == MagickSignature);
660 assert(image != (Image **) NULL);
661 assert((*image)->signature == MagickSignature);
662 if ((*image)->debug != MagickFalse)
663 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
664 if (argc < 0)
665 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000666 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000667 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
668 quantize_info=AcquireQuantizeInfo(mogrify_info);
669 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000670 GetPixelInfo(*image,&fill);
671 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
anthonydf8ebac2011-04-27 09:03:19 +0000672 channel=mogrify_info->channel;
673 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000674 SetGeometry(*image,&region_geometry);
675 region_image=NewImageList();
676 /*
677 Transmogrify the image.
678 */
cristybb503372010-05-27 20:51:26 +0000679 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000680 {
anthonydf8ebac2011-04-27 09:03:19 +0000681 Image
682 *mogrify_image;
683
anthonye9c27192011-03-27 08:07:06 +0000684 ssize_t
685 count;
686
anthonydf8ebac2011-04-27 09:03:19 +0000687 option=argv[i];
688 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000689 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000690 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
691 0L);
cristycee97112010-05-28 00:44:52 +0000692 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000693 break;
cristy6b3da3a2010-06-20 02:21:46 +0000694 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000695 mogrify_image=(Image *)NULL;
696 switch (*(option+1))
697 {
698 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000699 {
anthonydf8ebac2011-04-27 09:03:19 +0000700 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000701 {
anthonydf8ebac2011-04-27 09:03:19 +0000702 /*
703 Adaptive blur image.
704 */
705 (void) SyncImageSettings(mogrify_info,*image);
706 flags=ParseGeometry(argv[i+1],&geometry_info);
707 if ((flags & SigmaValue) == 0)
708 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000709 if ((flags & XiValue) == 0)
710 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000711 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000712 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000713 break;
cristy3ed852e2009-09-05 21:47:34 +0000714 }
anthonydf8ebac2011-04-27 09:03:19 +0000715 if (LocaleCompare("adaptive-resize",option+1) == 0)
716 {
717 /*
718 Adaptive resize image.
719 */
720 (void) SyncImageSettings(mogrify_info,*image);
721 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
722 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
723 geometry.height,exception);
724 break;
725 }
726 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
727 {
728 /*
729 Adaptive sharpen image.
730 */
731 (void) SyncImageSettings(mogrify_info,*image);
732 flags=ParseGeometry(argv[i+1],&geometry_info);
733 if ((flags & SigmaValue) == 0)
734 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000735 if ((flags & XiValue) == 0)
736 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000737 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000738 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000739 break;
740 }
741 if (LocaleCompare("affine",option+1) == 0)
742 {
743 /*
744 Affine matrix.
745 */
746 if (*option == '+')
747 {
748 GetAffineMatrix(&draw_info->affine);
749 break;
750 }
751 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
752 break;
753 }
754 if (LocaleCompare("alpha",option+1) == 0)
755 {
756 AlphaChannelType
757 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000758
anthonydf8ebac2011-04-27 09:03:19 +0000759 (void) SyncImageSettings(mogrify_info,*image);
760 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
761 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000762 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000763 break;
764 }
765 if (LocaleCompare("annotate",option+1) == 0)
766 {
767 char
768 *text,
769 geometry[MaxTextExtent];
770
771 /*
772 Annotate image.
773 */
774 (void) SyncImageSettings(mogrify_info,*image);
775 SetGeometryInfo(&geometry_info);
776 flags=ParseGeometry(argv[i+1],&geometry_info);
777 if ((flags & SigmaValue) == 0)
778 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000779 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
780 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000781 if (text == (char *) NULL)
782 break;
783 (void) CloneString(&draw_info->text,text);
784 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000785 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000786 geometry_info.xi,geometry_info.psi);
787 (void) CloneString(&draw_info->geometry,geometry);
788 draw_info->affine.sx=cos(DegreesToRadians(
789 fmod(geometry_info.rho,360.0)));
790 draw_info->affine.rx=sin(DegreesToRadians(
791 fmod(geometry_info.rho,360.0)));
792 draw_info->affine.ry=(-sin(DegreesToRadians(
793 fmod(geometry_info.sigma,360.0))));
794 draw_info->affine.sy=cos(DegreesToRadians(
795 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000796 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000797 break;
798 }
799 if (LocaleCompare("antialias",option+1) == 0)
800 {
801 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
802 MagickFalse;
803 draw_info->text_antialias=(*option == '-') ? MagickTrue :
804 MagickFalse;
805 break;
806 }
807 if (LocaleCompare("auto-gamma",option+1) == 0)
808 {
809 /*
810 Auto Adjust Gamma of image based on its mean
811 */
812 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000813 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000814 break;
815 }
816 if (LocaleCompare("auto-level",option+1) == 0)
817 {
818 /*
819 Perfectly Normalize (max/min stretch) the image
820 */
821 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000822 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000823 break;
824 }
825 if (LocaleCompare("auto-orient",option+1) == 0)
826 {
827 (void) SyncImageSettings(mogrify_info,*image);
828 switch ((*image)->orientation)
829 {
830 case TopRightOrientation:
831 {
832 mogrify_image=FlopImage(*image,exception);
833 break;
834 }
835 case BottomRightOrientation:
836 {
837 mogrify_image=RotateImage(*image,180.0,exception);
838 break;
839 }
840 case BottomLeftOrientation:
841 {
842 mogrify_image=FlipImage(*image,exception);
843 break;
844 }
845 case LeftTopOrientation:
846 {
847 mogrify_image=TransposeImage(*image,exception);
848 break;
849 }
850 case RightTopOrientation:
851 {
852 mogrify_image=RotateImage(*image,90.0,exception);
853 break;
854 }
855 case RightBottomOrientation:
856 {
857 mogrify_image=TransverseImage(*image,exception);
858 break;
859 }
860 case LeftBottomOrientation:
861 {
862 mogrify_image=RotateImage(*image,270.0,exception);
863 break;
864 }
865 default:
866 break;
867 }
868 if (mogrify_image != (Image *) NULL)
869 mogrify_image->orientation=TopLeftOrientation;
870 break;
871 }
872 break;
873 }
874 case 'b':
875 {
876 if (LocaleCompare("black-threshold",option+1) == 0)
877 {
878 /*
879 Black threshold image.
880 */
881 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000882 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000883 InheritException(exception,&(*image)->exception);
884 break;
885 }
886 if (LocaleCompare("blue-shift",option+1) == 0)
887 {
888 /*
889 Blue shift image.
890 */
891 (void) SyncImageSettings(mogrify_info,*image);
892 geometry_info.rho=1.5;
893 if (*option == '-')
894 flags=ParseGeometry(argv[i+1],&geometry_info);
895 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
896 break;
897 }
898 if (LocaleCompare("blur",option+1) == 0)
899 {
900 /*
901 Gaussian blur image.
902 */
903 (void) SyncImageSettings(mogrify_info,*image);
904 flags=ParseGeometry(argv[i+1],&geometry_info);
905 if ((flags & SigmaValue) == 0)
906 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000907 if ((flags & XiValue) == 0)
908 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000909 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000910 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000911 break;
912 }
913 if (LocaleCompare("border",option+1) == 0)
914 {
915 /*
916 Surround image with a border of solid color.
917 */
918 (void) SyncImageSettings(mogrify_info,*image);
919 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
920 if ((flags & SigmaValue) == 0)
921 geometry.height=geometry.width;
922 mogrify_image=BorderImage(*image,&geometry,exception);
923 break;
924 }
925 if (LocaleCompare("bordercolor",option+1) == 0)
926 {
927 if (*option == '+')
928 {
cristy05c0c9a2011-09-05 23:16:13 +0000929 (void) QueryColorDatabase(MogrifyBorderColor,
930 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000931 break;
932 }
933 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
934 exception);
935 break;
936 }
937 if (LocaleCompare("box",option+1) == 0)
938 {
939 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
940 exception);
941 break;
942 }
943 if (LocaleCompare("brightness-contrast",option+1) == 0)
944 {
945 double
946 brightness,
947 contrast;
948
949 GeometryInfo
950 geometry_info;
951
952 MagickStatusType
953 flags;
954
955 /*
956 Brightness / contrast image.
957 */
958 (void) SyncImageSettings(mogrify_info,*image);
959 flags=ParseGeometry(argv[i+1],&geometry_info);
960 brightness=geometry_info.rho;
961 contrast=0.0;
962 if ((flags & SigmaValue) != 0)
963 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000964 (void) BrightnessContrastImage(*image,brightness,contrast,
965 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000966 InheritException(exception,&(*image)->exception);
967 break;
968 }
969 break;
970 }
971 case 'c':
972 {
973 if (LocaleCompare("cdl",option+1) == 0)
974 {
975 char
976 *color_correction_collection;
977
978 /*
979 Color correct with a color decision list.
980 */
981 (void) SyncImageSettings(mogrify_info,*image);
982 color_correction_collection=FileToString(argv[i+1],~0,exception);
983 if (color_correction_collection == (char *) NULL)
984 break;
cristy1bfa9f02011-08-11 02:35:43 +0000985 (void) ColorDecisionListImage(*image,color_correction_collection,
986 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000987 InheritException(exception,&(*image)->exception);
988 break;
989 }
990 if (LocaleCompare("channel",option+1) == 0)
991 {
992 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000993 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000994 else
cristyfa806a72011-07-04 02:06:13 +0000995 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +0000996 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000997 break;
998 }
999 if (LocaleCompare("charcoal",option+1) == 0)
1000 {
1001 /*
1002 Charcoal image.
1003 */
1004 (void) SyncImageSettings(mogrify_info,*image);
1005 flags=ParseGeometry(argv[i+1],&geometry_info);
1006 if ((flags & SigmaValue) == 0)
1007 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001008 if ((flags & XiValue) == 0)
1009 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001010 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001011 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001012 break;
1013 }
1014 if (LocaleCompare("chop",option+1) == 0)
1015 {
1016 /*
1017 Chop the image.
1018 */
1019 (void) SyncImageSettings(mogrify_info,*image);
1020 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1021 mogrify_image=ChopImage(*image,&geometry,exception);
1022 break;
1023 }
1024 if (LocaleCompare("clamp",option+1) == 0)
1025 {
1026 /*
1027 Clamp image.
1028 */
1029 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001030 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001031 InheritException(exception,&(*image)->exception);
1032 break;
1033 }
1034 if (LocaleCompare("clip",option+1) == 0)
1035 {
1036 (void) SyncImageSettings(mogrify_info,*image);
1037 if (*option == '+')
1038 {
cristy018f07f2011-09-04 21:15:19 +00001039 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001040 break;
1041 }
cristy018f07f2011-09-04 21:15:19 +00001042 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001043 break;
1044 }
1045 if (LocaleCompare("clip-mask",option+1) == 0)
1046 {
1047 CacheView
1048 *mask_view;
1049
1050 Image
1051 *mask_image;
1052
cristy4c08aed2011-07-01 19:47:50 +00001053 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001054 *restrict q;
1055
1056 register ssize_t
1057 x;
1058
1059 ssize_t
1060 y;
1061
1062 (void) SyncImageSettings(mogrify_info,*image);
1063 if (*option == '+')
1064 {
1065 /*
1066 Remove a mask.
1067 */
cristy018f07f2011-09-04 21:15:19 +00001068 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001069 break;
1070 }
1071 /*
1072 Set the image mask.
1073 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1074 */
1075 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1076 if (mask_image == (Image *) NULL)
1077 break;
cristy574cc262011-08-05 01:23:58 +00001078 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001079 return(MagickFalse);
1080 mask_view=AcquireCacheView(mask_image);
1081 for (y=0; y < (ssize_t) mask_image->rows; y++)
1082 {
1083 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1084 exception);
cristyacd2ed22011-08-30 01:44:23 +00001085 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001086 break;
1087 for (x=0; x < (ssize_t) mask_image->columns; x++)
1088 {
1089 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001090 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1091 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1092 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1093 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001094 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001095 }
1096 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1097 break;
1098 }
1099 mask_view=DestroyCacheView(mask_view);
1100 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001101 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001102 InheritException(exception,&(*image)->exception);
1103 break;
1104 }
1105 if (LocaleCompare("clip-path",option+1) == 0)
1106 {
1107 (void) SyncImageSettings(mogrify_info,*image);
1108 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001109 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001110 break;
1111 }
1112 if (LocaleCompare("colorize",option+1) == 0)
1113 {
1114 /*
1115 Colorize the image.
1116 */
1117 (void) SyncImageSettings(mogrify_info,*image);
1118 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1119 exception);
1120 break;
1121 }
1122 if (LocaleCompare("color-matrix",option+1) == 0)
1123 {
1124 KernelInfo
1125 *kernel;
1126
1127 (void) SyncImageSettings(mogrify_info,*image);
1128 kernel=AcquireKernelInfo(argv[i+1]);
1129 if (kernel == (KernelInfo *) NULL)
1130 break;
1131 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1132 kernel=DestroyKernelInfo(kernel);
1133 break;
1134 }
1135 if (LocaleCompare("colors",option+1) == 0)
1136 {
1137 /*
1138 Reduce the number of colors in the image.
1139 */
1140 (void) SyncImageSettings(mogrify_info,*image);
1141 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1142 if (quantize_info->number_colors == 0)
1143 break;
1144 if (((*image)->storage_class == DirectClass) ||
1145 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001146 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001147 else
cristy018f07f2011-09-04 21:15:19 +00001148 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001149 break;
1150 }
1151 if (LocaleCompare("colorspace",option+1) == 0)
1152 {
1153 ColorspaceType
1154 colorspace;
1155
1156 (void) SyncImageSettings(mogrify_info,*image);
1157 if (*option == '+')
1158 {
1159 (void) TransformImageColorspace(*image,RGBColorspace);
1160 InheritException(exception,&(*image)->exception);
1161 break;
1162 }
1163 colorspace=(ColorspaceType) ParseCommandOption(
1164 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1165 (void) TransformImageColorspace(*image,colorspace);
1166 InheritException(exception,&(*image)->exception);
1167 break;
1168 }
1169 if (LocaleCompare("contrast",option+1) == 0)
1170 {
1171 (void) SyncImageSettings(mogrify_info,*image);
1172 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001173 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001174 break;
1175 }
1176 if (LocaleCompare("contrast-stretch",option+1) == 0)
1177 {
1178 double
1179 black_point,
1180 white_point;
1181
1182 MagickStatusType
1183 flags;
1184
1185 /*
1186 Contrast stretch image.
1187 */
1188 (void) SyncImageSettings(mogrify_info,*image);
1189 flags=ParseGeometry(argv[i+1],&geometry_info);
1190 black_point=geometry_info.rho;
1191 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1192 black_point;
1193 if ((flags & PercentValue) != 0)
1194 {
1195 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1196 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1197 }
1198 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1199 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001200 (void) ContrastStretchImage(*image,black_point,white_point,
1201 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001202 InheritException(exception,&(*image)->exception);
1203 break;
1204 }
1205 if (LocaleCompare("convolve",option+1) == 0)
1206 {
anthonydf8ebac2011-04-27 09:03:19 +00001207 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001208 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001209
anthonydf8ebac2011-04-27 09:03:19 +00001210 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001211 kernel_info=AcquireKernelInfo(argv[i+1]);
1212 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001213 break;
cristy0a922382011-07-16 15:30:34 +00001214 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001215 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001216 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001217 break;
1218 }
1219 if (LocaleCompare("crop",option+1) == 0)
1220 {
1221 /*
1222 Crop a image to a smaller size
1223 */
1224 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001225 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001226 break;
1227 }
1228 if (LocaleCompare("cycle",option+1) == 0)
1229 {
1230 /*
1231 Cycle an image colormap.
1232 */
1233 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00001234 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1235 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001236 break;
1237 }
1238 break;
1239 }
1240 case 'd':
1241 {
1242 if (LocaleCompare("decipher",option+1) == 0)
1243 {
1244 StringInfo
1245 *passkey;
1246
1247 /*
1248 Decipher pixels.
1249 */
1250 (void) SyncImageSettings(mogrify_info,*image);
1251 passkey=FileToStringInfo(argv[i+1],~0,exception);
1252 if (passkey != (StringInfo *) NULL)
1253 {
1254 (void) PasskeyDecipherImage(*image,passkey,exception);
1255 passkey=DestroyStringInfo(passkey);
1256 }
1257 break;
1258 }
1259 if (LocaleCompare("density",option+1) == 0)
1260 {
1261 /*
1262 Set image density.
1263 */
1264 (void) CloneString(&draw_info->density,argv[i+1]);
1265 break;
1266 }
1267 if (LocaleCompare("depth",option+1) == 0)
1268 {
1269 (void) SyncImageSettings(mogrify_info,*image);
1270 if (*option == '+')
1271 {
1272 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1273 break;
1274 }
1275 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1276 break;
1277 }
1278 if (LocaleCompare("deskew",option+1) == 0)
1279 {
1280 double
1281 threshold;
1282
1283 /*
1284 Straighten the image.
1285 */
1286 (void) SyncImageSettings(mogrify_info,*image);
1287 if (*option == '+')
1288 threshold=40.0*QuantumRange/100.0;
1289 else
1290 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1291 mogrify_image=DeskewImage(*image,threshold,exception);
1292 break;
1293 }
1294 if (LocaleCompare("despeckle",option+1) == 0)
1295 {
1296 /*
1297 Reduce the speckles within an image.
1298 */
1299 (void) SyncImageSettings(mogrify_info,*image);
1300 mogrify_image=DespeckleImage(*image,exception);
1301 break;
1302 }
1303 if (LocaleCompare("display",option+1) == 0)
1304 {
1305 (void) CloneString(&draw_info->server_name,argv[i+1]);
1306 break;
1307 }
1308 if (LocaleCompare("distort",option+1) == 0)
1309 {
1310 char
1311 *args,
1312 token[MaxTextExtent];
1313
1314 const char
1315 *p;
1316
1317 DistortImageMethod
1318 method;
1319
1320 double
1321 *arguments;
1322
1323 register ssize_t
1324 x;
1325
1326 size_t
1327 number_arguments;
1328
1329 /*
1330 Distort image.
1331 */
1332 (void) SyncImageSettings(mogrify_info,*image);
1333 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1334 MagickFalse,argv[i+1]);
1335 if ( method == ResizeDistortion )
1336 {
1337 /* Special Case - Argument is actually a resize geometry!
1338 ** Convert that to an appropriate distortion argument array.
1339 */
1340 double
1341 resize_args[2];
1342 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1343 exception);
1344 resize_args[0]=(double)geometry.width;
1345 resize_args[1]=(double)geometry.height;
1346 mogrify_image=DistortImage(*image,method,(size_t)2,
1347 resize_args,MagickTrue,exception);
1348 break;
1349 }
cristy018f07f2011-09-04 21:15:19 +00001350 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1351 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001352 if (args == (char *) NULL)
1353 break;
1354 p=(char *) args;
1355 for (x=0; *p != '\0'; x++)
1356 {
1357 GetMagickToken(p,&p,token);
1358 if (*token == ',')
1359 GetMagickToken(p,&p,token);
1360 }
1361 number_arguments=(size_t) x;
1362 arguments=(double *) AcquireQuantumMemory(number_arguments,
1363 sizeof(*arguments));
1364 if (arguments == (double *) NULL)
1365 ThrowWandFatalException(ResourceLimitFatalError,
1366 "MemoryAllocationFailed",(*image)->filename);
1367 (void) ResetMagickMemory(arguments,0,number_arguments*
1368 sizeof(*arguments));
1369 p=(char *) args;
1370 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1371 {
1372 GetMagickToken(p,&p,token);
1373 if (*token == ',')
1374 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001375 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001376 }
1377 args=DestroyString(args);
1378 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1379 (*option == '+') ? MagickTrue : MagickFalse,exception);
1380 arguments=(double *) RelinquishMagickMemory(arguments);
1381 break;
1382 }
1383 if (LocaleCompare("dither",option+1) == 0)
1384 {
1385 if (*option == '+')
1386 {
1387 quantize_info->dither=MagickFalse;
1388 break;
1389 }
1390 quantize_info->dither=MagickTrue;
1391 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1392 MagickDitherOptions,MagickFalse,argv[i+1]);
1393 if (quantize_info->dither_method == NoDitherMethod)
1394 quantize_info->dither=MagickFalse;
1395 break;
1396 }
1397 if (LocaleCompare("draw",option+1) == 0)
1398 {
1399 /*
1400 Draw image.
1401 */
1402 (void) SyncImageSettings(mogrify_info,*image);
1403 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001404 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001405 break;
1406 }
1407 break;
1408 }
1409 case 'e':
1410 {
1411 if (LocaleCompare("edge",option+1) == 0)
1412 {
1413 /*
1414 Enhance edges in the image.
1415 */
1416 (void) SyncImageSettings(mogrify_info,*image);
1417 flags=ParseGeometry(argv[i+1],&geometry_info);
1418 if ((flags & SigmaValue) == 0)
1419 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001420 mogrify_image=EdgeImage(*image,geometry_info.rho,
1421 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001422 break;
1423 }
1424 if (LocaleCompare("emboss",option+1) == 0)
1425 {
1426 /*
1427 Gaussian embossen image.
1428 */
1429 (void) SyncImageSettings(mogrify_info,*image);
1430 flags=ParseGeometry(argv[i+1],&geometry_info);
1431 if ((flags & SigmaValue) == 0)
1432 geometry_info.sigma=1.0;
1433 mogrify_image=EmbossImage(*image,geometry_info.rho,
1434 geometry_info.sigma,exception);
1435 break;
1436 }
1437 if (LocaleCompare("encipher",option+1) == 0)
1438 {
1439 StringInfo
1440 *passkey;
1441
1442 /*
1443 Encipher pixels.
1444 */
1445 (void) SyncImageSettings(mogrify_info,*image);
1446 passkey=FileToStringInfo(argv[i+1],~0,exception);
1447 if (passkey != (StringInfo *) NULL)
1448 {
1449 (void) PasskeyEncipherImage(*image,passkey,exception);
1450 passkey=DestroyStringInfo(passkey);
1451 }
1452 break;
1453 }
1454 if (LocaleCompare("encoding",option+1) == 0)
1455 {
1456 (void) CloneString(&draw_info->encoding,argv[i+1]);
1457 break;
1458 }
1459 if (LocaleCompare("enhance",option+1) == 0)
1460 {
1461 /*
1462 Enhance image.
1463 */
1464 (void) SyncImageSettings(mogrify_info,*image);
1465 mogrify_image=EnhanceImage(*image,exception);
1466 break;
1467 }
1468 if (LocaleCompare("equalize",option+1) == 0)
1469 {
1470 /*
1471 Equalize image.
1472 */
1473 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001474 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001475 break;
1476 }
1477 if (LocaleCompare("evaluate",option+1) == 0)
1478 {
1479 double
1480 constant;
1481
1482 MagickEvaluateOperator
1483 op;
1484
1485 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001486 op=(MagickEvaluateOperator) ParseCommandOption(
1487 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001488 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001489 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001490 break;
1491 }
1492 if (LocaleCompare("extent",option+1) == 0)
1493 {
1494 /*
1495 Set the image extent.
1496 */
1497 (void) SyncImageSettings(mogrify_info,*image);
1498 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1499 if (geometry.width == 0)
1500 geometry.width=(*image)->columns;
1501 if (geometry.height == 0)
1502 geometry.height=(*image)->rows;
1503 mogrify_image=ExtentImage(*image,&geometry,exception);
1504 break;
1505 }
1506 break;
1507 }
1508 case 'f':
1509 {
1510 if (LocaleCompare("family",option+1) == 0)
1511 {
1512 if (*option == '+')
1513 {
1514 if (draw_info->family != (char *) NULL)
1515 draw_info->family=DestroyString(draw_info->family);
1516 break;
1517 }
1518 (void) CloneString(&draw_info->family,argv[i+1]);
1519 break;
1520 }
1521 if (LocaleCompare("features",option+1) == 0)
1522 {
1523 if (*option == '+')
1524 {
1525 (void) DeleteImageArtifact(*image,"identify:features");
1526 break;
1527 }
1528 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1529 break;
1530 }
1531 if (LocaleCompare("fill",option+1) == 0)
1532 {
1533 ExceptionInfo
1534 *sans;
1535
cristy4c08aed2011-07-01 19:47:50 +00001536 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001537 if (*option == '+')
1538 {
1539 (void) QueryMagickColor("none",&fill,exception);
1540 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1541 if (draw_info->fill_pattern != (Image *) NULL)
1542 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1543 break;
1544 }
1545 sans=AcquireExceptionInfo();
1546 (void) QueryMagickColor(argv[i+1],&fill,sans);
1547 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1548 sans=DestroyExceptionInfo(sans);
1549 if (status == MagickFalse)
1550 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1551 exception);
1552 break;
1553 }
1554 if (LocaleCompare("flip",option+1) == 0)
1555 {
1556 /*
1557 Flip image scanlines.
1558 */
1559 (void) SyncImageSettings(mogrify_info,*image);
1560 mogrify_image=FlipImage(*image,exception);
1561 break;
1562 }
anthonydf8ebac2011-04-27 09:03:19 +00001563 if (LocaleCompare("floodfill",option+1) == 0)
1564 {
cristy4c08aed2011-07-01 19:47:50 +00001565 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001566 target;
1567
1568 /*
1569 Floodfill image.
1570 */
1571 (void) SyncImageSettings(mogrify_info,*image);
1572 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1573 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001574 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001575 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001576 break;
1577 }
anthony3d2f4862011-05-01 13:48:16 +00001578 if (LocaleCompare("flop",option+1) == 0)
1579 {
1580 /*
1581 Flop image scanlines.
1582 */
1583 (void) SyncImageSettings(mogrify_info,*image);
1584 mogrify_image=FlopImage(*image,exception);
1585 break;
1586 }
anthonydf8ebac2011-04-27 09:03:19 +00001587 if (LocaleCompare("font",option+1) == 0)
1588 {
1589 if (*option == '+')
1590 {
1591 if (draw_info->font != (char *) NULL)
1592 draw_info->font=DestroyString(draw_info->font);
1593 break;
1594 }
1595 (void) CloneString(&draw_info->font,argv[i+1]);
1596 break;
1597 }
1598 if (LocaleCompare("format",option+1) == 0)
1599 {
1600 format=argv[i+1];
1601 break;
1602 }
1603 if (LocaleCompare("frame",option+1) == 0)
1604 {
1605 FrameInfo
1606 frame_info;
1607
1608 /*
1609 Surround image with an ornamental border.
1610 */
1611 (void) SyncImageSettings(mogrify_info,*image);
1612 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1613 frame_info.width=geometry.width;
1614 frame_info.height=geometry.height;
1615 if ((flags & HeightValue) == 0)
1616 frame_info.height=geometry.width;
1617 frame_info.outer_bevel=geometry.x;
1618 frame_info.inner_bevel=geometry.y;
1619 frame_info.x=(ssize_t) frame_info.width;
1620 frame_info.y=(ssize_t) frame_info.height;
1621 frame_info.width=(*image)->columns+2*frame_info.width;
1622 frame_info.height=(*image)->rows+2*frame_info.height;
1623 mogrify_image=FrameImage(*image,&frame_info,exception);
1624 break;
1625 }
1626 if (LocaleCompare("function",option+1) == 0)
1627 {
1628 char
1629 *arguments,
1630 token[MaxTextExtent];
1631
1632 const char
1633 *p;
1634
1635 double
1636 *parameters;
1637
1638 MagickFunction
1639 function;
1640
1641 register ssize_t
1642 x;
1643
1644 size_t
1645 number_parameters;
1646
1647 /*
1648 Function Modify Image Values
1649 */
1650 (void) SyncImageSettings(mogrify_info,*image);
1651 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1652 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001653 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1654 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001655 if (arguments == (char *) NULL)
1656 break;
1657 p=(char *) arguments;
1658 for (x=0; *p != '\0'; x++)
1659 {
1660 GetMagickToken(p,&p,token);
1661 if (*token == ',')
1662 GetMagickToken(p,&p,token);
1663 }
1664 number_parameters=(size_t) x;
1665 parameters=(double *) AcquireQuantumMemory(number_parameters,
1666 sizeof(*parameters));
1667 if (parameters == (double *) NULL)
1668 ThrowWandFatalException(ResourceLimitFatalError,
1669 "MemoryAllocationFailed",(*image)->filename);
1670 (void) ResetMagickMemory(parameters,0,number_parameters*
1671 sizeof(*parameters));
1672 p=(char *) arguments;
1673 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1674 {
1675 GetMagickToken(p,&p,token);
1676 if (*token == ',')
1677 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001678 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001679 }
1680 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001681 (void) FunctionImage(*image,function,number_parameters,parameters,
1682 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001683 parameters=(double *) RelinquishMagickMemory(parameters);
1684 break;
1685 }
1686 break;
1687 }
1688 case 'g':
1689 {
1690 if (LocaleCompare("gamma",option+1) == 0)
1691 {
1692 /*
1693 Gamma image.
1694 */
1695 (void) SyncImageSettings(mogrify_info,*image);
1696 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001697 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001698 else
cristyb3e7c6c2011-07-24 01:43:55 +00001699 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1700 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001701 break;
1702 }
1703 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1704 (LocaleCompare("gaussian",option+1) == 0))
1705 {
1706 /*
1707 Gaussian blur image.
1708 */
1709 (void) SyncImageSettings(mogrify_info,*image);
1710 flags=ParseGeometry(argv[i+1],&geometry_info);
1711 if ((flags & SigmaValue) == 0)
1712 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001713 if ((flags & XiValue) == 0)
1714 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00001715 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001716 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001717 break;
1718 }
1719 if (LocaleCompare("geometry",option+1) == 0)
1720 {
1721 /*
1722 Record Image offset, Resize last image.
1723 */
1724 (void) SyncImageSettings(mogrify_info,*image);
1725 if (*option == '+')
1726 {
1727 if ((*image)->geometry != (char *) NULL)
1728 (*image)->geometry=DestroyString((*image)->geometry);
1729 break;
1730 }
1731 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1732 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1733 (void) CloneString(&(*image)->geometry,argv[i+1]);
1734 else
1735 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1736 (*image)->filter,(*image)->blur,exception);
1737 break;
1738 }
1739 if (LocaleCompare("gravity",option+1) == 0)
1740 {
1741 if (*option == '+')
1742 {
1743 draw_info->gravity=UndefinedGravity;
1744 break;
1745 }
1746 draw_info->gravity=(GravityType) ParseCommandOption(
1747 MagickGravityOptions,MagickFalse,argv[i+1]);
1748 break;
1749 }
1750 break;
1751 }
1752 case 'h':
1753 {
1754 if (LocaleCompare("highlight-color",option+1) == 0)
1755 {
1756 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1757 break;
1758 }
1759 break;
1760 }
1761 case 'i':
1762 {
1763 if (LocaleCompare("identify",option+1) == 0)
1764 {
1765 char
1766 *text;
1767
1768 (void) SyncImageSettings(mogrify_info,*image);
1769 if (format == (char *) NULL)
1770 {
cristya4037272011-08-28 15:11:39 +00001771 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1772 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001773 break;
1774 }
cristy018f07f2011-09-04 21:15:19 +00001775 text=InterpretImageProperties(mogrify_info,*image,format,
1776 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001777 if (text == (char *) NULL)
1778 break;
1779 (void) fputs(text,stdout);
1780 (void) fputc('\n',stdout);
1781 text=DestroyString(text);
1782 break;
1783 }
1784 if (LocaleCompare("implode",option+1) == 0)
1785 {
1786 /*
1787 Implode image.
1788 */
1789 (void) SyncImageSettings(mogrify_info,*image);
1790 (void) ParseGeometry(argv[i+1],&geometry_info);
1791 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1792 break;
1793 }
1794 if (LocaleCompare("interline-spacing",option+1) == 0)
1795 {
1796 if (*option == '+')
1797 (void) ParseGeometry("0",&geometry_info);
1798 else
1799 (void) ParseGeometry(argv[i+1],&geometry_info);
1800 draw_info->interline_spacing=geometry_info.rho;
1801 break;
1802 }
1803 if (LocaleCompare("interword-spacing",option+1) == 0)
1804 {
1805 if (*option == '+')
1806 (void) ParseGeometry("0",&geometry_info);
1807 else
1808 (void) ParseGeometry(argv[i+1],&geometry_info);
1809 draw_info->interword_spacing=geometry_info.rho;
1810 break;
1811 }
1812 break;
1813 }
1814 case 'k':
1815 {
1816 if (LocaleCompare("kerning",option+1) == 0)
1817 {
1818 if (*option == '+')
1819 (void) ParseGeometry("0",&geometry_info);
1820 else
1821 (void) ParseGeometry(argv[i+1],&geometry_info);
1822 draw_info->kerning=geometry_info.rho;
1823 break;
1824 }
1825 break;
1826 }
1827 case 'l':
1828 {
1829 if (LocaleCompare("lat",option+1) == 0)
1830 {
1831 /*
1832 Local adaptive threshold image.
1833 */
1834 (void) SyncImageSettings(mogrify_info,*image);
1835 flags=ParseGeometry(argv[i+1],&geometry_info);
1836 if ((flags & PercentValue) != 0)
1837 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1838 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001839 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001840 geometry_info.xi,exception);
1841 break;
1842 }
1843 if (LocaleCompare("level",option+1) == 0)
1844 {
1845 MagickRealType
1846 black_point,
1847 gamma,
1848 white_point;
1849
1850 MagickStatusType
1851 flags;
1852
1853 /*
1854 Parse levels.
1855 */
1856 (void) SyncImageSettings(mogrify_info,*image);
1857 flags=ParseGeometry(argv[i+1],&geometry_info);
1858 black_point=geometry_info.rho;
1859 white_point=(MagickRealType) QuantumRange;
1860 if ((flags & SigmaValue) != 0)
1861 white_point=geometry_info.sigma;
1862 gamma=1.0;
1863 if ((flags & XiValue) != 0)
1864 gamma=geometry_info.xi;
1865 if ((flags & PercentValue) != 0)
1866 {
1867 black_point*=(MagickRealType) (QuantumRange/100.0);
1868 white_point*=(MagickRealType) (QuantumRange/100.0);
1869 }
1870 if ((flags & SigmaValue) == 0)
1871 white_point=(MagickRealType) QuantumRange-black_point;
1872 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001873 (void) LevelizeImage(*image,black_point,white_point,gamma,
1874 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001875 else
cristy01e9afd2011-08-10 17:38:41 +00001876 (void) LevelImage(*image,black_point,white_point,gamma,
1877 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001878 InheritException(exception,&(*image)->exception);
1879 break;
1880 }
1881 if (LocaleCompare("level-colors",option+1) == 0)
1882 {
1883 char
1884 token[MaxTextExtent];
1885
1886 const char
1887 *p;
1888
cristy4c08aed2011-07-01 19:47:50 +00001889 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001890 black_point,
1891 white_point;
1892
1893 p=(const char *) argv[i+1];
1894 GetMagickToken(p,&p,token); /* get black point color */
1895 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1896 (void) QueryMagickColor(token,&black_point,exception);
1897 else
1898 (void) QueryMagickColor("#000000",&black_point,exception);
1899 if (isalpha((int) token[0]) || (token[0] == '#'))
1900 GetMagickToken(p,&p,token);
1901 if (*token == '\0')
1902 white_point=black_point; /* set everything to that color */
1903 else
1904 {
1905 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1906 GetMagickToken(p,&p,token); /* Get white point color. */
1907 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1908 (void) QueryMagickColor(token,&white_point,exception);
1909 else
1910 (void) QueryMagickColor("#ffffff",&white_point,exception);
1911 }
cristy490408a2011-07-07 14:42:05 +00001912 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001913 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001914 break;
1915 }
1916 if (LocaleCompare("linear-stretch",option+1) == 0)
1917 {
1918 double
1919 black_point,
1920 white_point;
1921
1922 MagickStatusType
1923 flags;
1924
1925 (void) SyncImageSettings(mogrify_info,*image);
1926 flags=ParseGeometry(argv[i+1],&geometry_info);
1927 black_point=geometry_info.rho;
1928 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1929 if ((flags & SigmaValue) != 0)
1930 white_point=geometry_info.sigma;
1931 if ((flags & PercentValue) != 0)
1932 {
1933 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1934 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1935 }
1936 if ((flags & SigmaValue) == 0)
1937 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1938 black_point;
cristy33bd5152011-08-24 01:42:24 +00001939 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001940 InheritException(exception,&(*image)->exception);
1941 break;
1942 }
1943 if (LocaleCompare("linewidth",option+1) == 0)
1944 {
cristyc1acd842011-05-19 23:05:47 +00001945 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1946 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001947 break;
1948 }
1949 if (LocaleCompare("liquid-rescale",option+1) == 0)
1950 {
1951 /*
1952 Liquid rescale image.
1953 */
1954 (void) SyncImageSettings(mogrify_info,*image);
1955 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1956 if ((flags & XValue) == 0)
1957 geometry.x=1;
1958 if ((flags & YValue) == 0)
1959 geometry.y=0;
1960 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1961 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1962 break;
1963 }
1964 if (LocaleCompare("lowlight-color",option+1) == 0)
1965 {
1966 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1967 break;
1968 }
1969 break;
1970 }
1971 case 'm':
1972 {
1973 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001974 {
cristy3ed852e2009-09-05 21:47:34 +00001975 Image
anthonydf8ebac2011-04-27 09:03:19 +00001976 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001977
anthonydf8ebac2011-04-27 09:03:19 +00001978 /*
1979 Transform image colors to match this set of colors.
1980 */
1981 (void) SyncImageSettings(mogrify_info,*image);
1982 if (*option == '+')
1983 break;
1984 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1985 if (remap_image == (Image *) NULL)
1986 break;
cristy018f07f2011-09-04 21:15:19 +00001987 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001988 remap_image=DestroyImage(remap_image);
1989 break;
1990 }
1991 if (LocaleCompare("mask",option+1) == 0)
1992 {
1993 Image
1994 *mask;
1995
1996 (void) SyncImageSettings(mogrify_info,*image);
1997 if (*option == '+')
1998 {
1999 /*
2000 Remove a mask.
2001 */
cristy018f07f2011-09-04 21:15:19 +00002002 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002003 break;
2004 }
2005 /*
2006 Set the image mask.
2007 */
2008 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2009 if (mask == (Image *) NULL)
2010 break;
cristy018f07f2011-09-04 21:15:19 +00002011 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002012 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002013 break;
2014 }
2015 if (LocaleCompare("matte",option+1) == 0)
2016 {
2017 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002018 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002019 break;
2020 }
2021 if (LocaleCompare("median",option+1) == 0)
2022 {
2023 /*
2024 Median filter image.
2025 */
2026 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002027 flags=ParseGeometry(argv[i+1],&geometry_info);
2028 if ((flags & SigmaValue) == 0)
2029 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002030 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002031 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002032 break;
2033 }
2034 if (LocaleCompare("mode",option+1) == 0)
2035 {
2036 /*
2037 Mode image.
2038 */
2039 (void) SyncImageSettings(mogrify_info,*image);
cristyf36cbcb2011-09-07 13:28:22 +00002040 flags=ParseGeometry(argv[i+1],&geometry_info);
2041 if ((flags & SigmaValue) == 0)
2042 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002043 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002044 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002045 break;
2046 }
2047 if (LocaleCompare("modulate",option+1) == 0)
2048 {
2049 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002050 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002051 break;
2052 }
2053 if (LocaleCompare("monitor",option+1) == 0)
2054 {
2055 if (*option == '+')
2056 {
2057 (void) SetImageProgressMonitor(*image,
2058 (MagickProgressMonitor) NULL,(void *) NULL);
2059 break;
2060 }
2061 (void) SetImageProgressMonitor(*image,MonitorProgress,
2062 (void *) NULL);
2063 break;
2064 }
2065 if (LocaleCompare("monochrome",option+1) == 0)
2066 {
2067 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00002068 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002069 break;
2070 }
2071 if (LocaleCompare("morphology",option+1) == 0)
2072 {
2073 char
2074 token[MaxTextExtent];
2075
2076 const char
2077 *p;
2078
2079 KernelInfo
2080 *kernel;
2081
2082 MorphologyMethod
2083 method;
2084
2085 ssize_t
2086 iterations;
2087
2088 /*
2089 Morphological Image Operation
2090 */
2091 (void) SyncImageSettings(mogrify_info,*image);
2092 p=argv[i+1];
2093 GetMagickToken(p,&p,token);
2094 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2095 MagickFalse,token);
2096 iterations=1L;
2097 GetMagickToken(p,&p,token);
2098 if ((*p == ':') || (*p == ','))
2099 GetMagickToken(p,&p,token);
2100 if ((*p != '\0'))
2101 iterations=(ssize_t) StringToLong(p);
2102 kernel=AcquireKernelInfo(argv[i+2]);
2103 if (kernel == (KernelInfo *) NULL)
2104 {
2105 (void) ThrowMagickException(exception,GetMagickModule(),
2106 OptionError,"UnabletoParseKernel","morphology");
2107 status=MagickFalse;
2108 break;
2109 }
cristyf4ad9df2011-07-08 16:49:03 +00002110 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2111 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002112 kernel=DestroyKernelInfo(kernel);
2113 break;
2114 }
2115 if (LocaleCompare("motion-blur",option+1) == 0)
2116 {
2117 /*
2118 Motion blur image.
2119 */
2120 (void) SyncImageSettings(mogrify_info,*image);
2121 flags=ParseGeometry(argv[i+1],&geometry_info);
2122 if ((flags & SigmaValue) == 0)
2123 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002124 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2125 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002126 break;
2127 }
2128 break;
2129 }
2130 case 'n':
2131 {
2132 if (LocaleCompare("negate",option+1) == 0)
2133 {
2134 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002135 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002136 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002137 break;
2138 }
2139 if (LocaleCompare("noise",option+1) == 0)
2140 {
2141 (void) SyncImageSettings(mogrify_info,*image);
2142 if (*option == '-')
2143 {
cristyf36cbcb2011-09-07 13:28:22 +00002144 flags=ParseGeometry(argv[i+1],&geometry_info);
2145 if ((flags & SigmaValue) == 0)
2146 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002147 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002148 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002149 }
2150 else
2151 {
2152 NoiseType
2153 noise;
2154
2155 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2156 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002157 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002158 }
2159 break;
2160 }
2161 if (LocaleCompare("normalize",option+1) == 0)
2162 {
2163 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002164 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002165 break;
2166 }
2167 break;
2168 }
2169 case 'o':
2170 {
2171 if (LocaleCompare("opaque",option+1) == 0)
2172 {
cristy4c08aed2011-07-01 19:47:50 +00002173 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002174 target;
2175
2176 (void) SyncImageSettings(mogrify_info,*image);
2177 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002178 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002179 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002180 break;
2181 }
2182 if (LocaleCompare("ordered-dither",option+1) == 0)
2183 {
2184 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002185 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002186 break;
2187 }
2188 break;
2189 }
2190 case 'p':
2191 {
2192 if (LocaleCompare("paint",option+1) == 0)
2193 {
anthonydf8ebac2011-04-27 09:03:19 +00002194 (void) SyncImageSettings(mogrify_info,*image);
2195 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002196 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2197 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002198 break;
2199 }
2200 if (LocaleCompare("pen",option+1) == 0)
2201 {
2202 if (*option == '+')
2203 {
2204 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2205 break;
2206 }
2207 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2208 break;
2209 }
2210 if (LocaleCompare("pointsize",option+1) == 0)
2211 {
2212 if (*option == '+')
2213 (void) ParseGeometry("12",&geometry_info);
2214 else
2215 (void) ParseGeometry(argv[i+1],&geometry_info);
2216 draw_info->pointsize=geometry_info.rho;
2217 break;
2218 }
2219 if (LocaleCompare("polaroid",option+1) == 0)
2220 {
2221 double
2222 angle;
2223
2224 RandomInfo
2225 *random_info;
2226
2227 /*
2228 Simulate a Polaroid picture.
2229 */
2230 (void) SyncImageSettings(mogrify_info,*image);
2231 random_info=AcquireRandomInfo();
2232 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2233 random_info=DestroyRandomInfo(random_info);
2234 if (*option == '-')
2235 {
2236 SetGeometryInfo(&geometry_info);
2237 flags=ParseGeometry(argv[i+1],&geometry_info);
2238 angle=geometry_info.rho;
2239 }
2240 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2241 break;
2242 }
2243 if (LocaleCompare("posterize",option+1) == 0)
2244 {
2245 /*
2246 Posterize image.
2247 */
2248 (void) SyncImageSettings(mogrify_info,*image);
2249 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002250 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002251 break;
2252 }
2253 if (LocaleCompare("preview",option+1) == 0)
2254 {
2255 PreviewType
2256 preview_type;
2257
2258 /*
2259 Preview image.
2260 */
2261 (void) SyncImageSettings(mogrify_info,*image);
2262 if (*option == '+')
2263 preview_type=UndefinedPreview;
2264 else
2265 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2266 MagickFalse,argv[i+1]);
2267 mogrify_image=PreviewImage(*image,preview_type,exception);
2268 break;
2269 }
2270 if (LocaleCompare("profile",option+1) == 0)
2271 {
2272 const char
2273 *name;
2274
2275 const StringInfo
2276 *profile;
2277
2278 Image
2279 *profile_image;
2280
2281 ImageInfo
2282 *profile_info;
2283
2284 (void) SyncImageSettings(mogrify_info,*image);
2285 if (*option == '+')
2286 {
2287 /*
2288 Remove a profile from the image.
2289 */
2290 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2291 NULL,0,MagickTrue);
2292 InheritException(exception,&(*image)->exception);
2293 break;
2294 }
2295 /*
2296 Associate a profile with the image.
2297 */
2298 profile_info=CloneImageInfo(mogrify_info);
2299 profile=GetImageProfile(*image,"iptc");
2300 if (profile != (StringInfo *) NULL)
2301 profile_info->profile=(void *) CloneStringInfo(profile);
2302 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2303 profile_info=DestroyImageInfo(profile_info);
2304 if (profile_image == (Image *) NULL)
2305 {
2306 StringInfo
2307 *profile;
2308
2309 profile_info=CloneImageInfo(mogrify_info);
2310 (void) CopyMagickString(profile_info->filename,argv[i+1],
2311 MaxTextExtent);
2312 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2313 if (profile != (StringInfo *) NULL)
2314 {
2315 (void) ProfileImage(*image,profile_info->magick,
2316 GetStringInfoDatum(profile),(size_t)
2317 GetStringInfoLength(profile),MagickFalse);
2318 profile=DestroyStringInfo(profile);
2319 }
2320 profile_info=DestroyImageInfo(profile_info);
2321 break;
2322 }
2323 ResetImageProfileIterator(profile_image);
2324 name=GetNextImageProfile(profile_image);
2325 while (name != (const char *) NULL)
2326 {
2327 profile=GetImageProfile(profile_image,name);
2328 if (profile != (StringInfo *) NULL)
2329 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2330 (size_t) GetStringInfoLength(profile),MagickFalse);
2331 name=GetNextImageProfile(profile_image);
2332 }
2333 profile_image=DestroyImage(profile_image);
2334 break;
2335 }
2336 break;
2337 }
2338 case 'q':
2339 {
2340 if (LocaleCompare("quantize",option+1) == 0)
2341 {
2342 if (*option == '+')
2343 {
2344 quantize_info->colorspace=UndefinedColorspace;
2345 break;
2346 }
2347 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2348 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2349 break;
2350 }
2351 break;
2352 }
2353 case 'r':
2354 {
2355 if (LocaleCompare("radial-blur",option+1) == 0)
2356 {
2357 /*
2358 Radial blur image.
2359 */
2360 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002361 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2362 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002363 break;
2364 }
2365 if (LocaleCompare("raise",option+1) == 0)
2366 {
2367 /*
2368 Surround image with a raise of solid color.
2369 */
2370 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2371 if ((flags & SigmaValue) == 0)
2372 geometry.height=geometry.width;
2373 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002374 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002375 break;
2376 }
2377 if (LocaleCompare("random-threshold",option+1) == 0)
2378 {
2379 /*
2380 Threshold image.
2381 */
2382 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002383 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002384 break;
2385 }
2386 if (LocaleCompare("recolor",option+1) == 0)
2387 {
2388 KernelInfo
2389 *kernel;
2390
2391 (void) SyncImageSettings(mogrify_info,*image);
2392 kernel=AcquireKernelInfo(argv[i+1]);
2393 if (kernel == (KernelInfo *) NULL)
2394 break;
2395 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2396 kernel=DestroyKernelInfo(kernel);
2397 break;
2398 }
2399 if (LocaleCompare("region",option+1) == 0)
2400 {
2401 (void) SyncImageSettings(mogrify_info,*image);
2402 if (region_image != (Image *) NULL)
2403 {
2404 /*
2405 Composite region.
2406 */
2407 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002408 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2409 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002410 InheritException(exception,&region_image->exception);
2411 *image=DestroyImage(*image);
2412 *image=region_image;
2413 region_image = (Image *) NULL;
2414 }
2415 if (*option == '+')
2416 break;
2417 /*
2418 Apply transformations to a selected region of the image.
2419 */
cristy3ed852e2009-09-05 21:47:34 +00002420 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2421 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002422 mogrify_image=CropImage(*image,&region_geometry,exception);
2423 if (mogrify_image == (Image *) NULL)
2424 break;
2425 region_image=(*image);
2426 *image=mogrify_image;
2427 mogrify_image=(Image *) NULL;
2428 break;
cristy3ed852e2009-09-05 21:47:34 +00002429 }
anthonydf8ebac2011-04-27 09:03:19 +00002430 if (LocaleCompare("render",option+1) == 0)
2431 {
2432 (void) SyncImageSettings(mogrify_info,*image);
2433 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2434 break;
2435 }
2436 if (LocaleCompare("remap",option+1) == 0)
2437 {
2438 Image
2439 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002440
anthonydf8ebac2011-04-27 09:03:19 +00002441 /*
2442 Transform image colors to match this set of colors.
2443 */
2444 (void) SyncImageSettings(mogrify_info,*image);
2445 if (*option == '+')
2446 break;
2447 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2448 if (remap_image == (Image *) NULL)
2449 break;
cristy018f07f2011-09-04 21:15:19 +00002450 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002451 remap_image=DestroyImage(remap_image);
2452 break;
2453 }
2454 if (LocaleCompare("repage",option+1) == 0)
2455 {
2456 if (*option == '+')
2457 {
2458 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2459 break;
2460 }
2461 (void) ResetImagePage(*image,argv[i+1]);
2462 InheritException(exception,&(*image)->exception);
2463 break;
2464 }
2465 if (LocaleCompare("resample",option+1) == 0)
2466 {
2467 /*
2468 Resample image.
2469 */
2470 (void) SyncImageSettings(mogrify_info,*image);
2471 flags=ParseGeometry(argv[i+1],&geometry_info);
2472 if ((flags & SigmaValue) == 0)
2473 geometry_info.sigma=geometry_info.rho;
2474 mogrify_image=ResampleImage(*image,geometry_info.rho,
2475 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2476 break;
2477 }
2478 if (LocaleCompare("resize",option+1) == 0)
2479 {
2480 /*
2481 Resize image.
2482 */
2483 (void) SyncImageSettings(mogrify_info,*image);
2484 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2485 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2486 (*image)->filter,(*image)->blur,exception);
2487 break;
2488 }
2489 if (LocaleCompare("roll",option+1) == 0)
2490 {
2491 /*
2492 Roll image.
2493 */
2494 (void) SyncImageSettings(mogrify_info,*image);
2495 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2496 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2497 break;
2498 }
2499 if (LocaleCompare("rotate",option+1) == 0)
2500 {
2501 char
2502 *geometry;
2503
2504 /*
2505 Check for conditional image rotation.
2506 */
2507 (void) SyncImageSettings(mogrify_info,*image);
2508 if (strchr(argv[i+1],'>') != (char *) NULL)
2509 if ((*image)->columns <= (*image)->rows)
2510 break;
2511 if (strchr(argv[i+1],'<') != (char *) NULL)
2512 if ((*image)->columns >= (*image)->rows)
2513 break;
2514 /*
2515 Rotate image.
2516 */
2517 geometry=ConstantString(argv[i+1]);
2518 (void) SubstituteString(&geometry,">","");
2519 (void) SubstituteString(&geometry,"<","");
2520 (void) ParseGeometry(geometry,&geometry_info);
2521 geometry=DestroyString(geometry);
2522 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2523 break;
2524 }
2525 break;
2526 }
2527 case 's':
2528 {
2529 if (LocaleCompare("sample",option+1) == 0)
2530 {
2531 /*
2532 Sample image with pixel replication.
2533 */
2534 (void) SyncImageSettings(mogrify_info,*image);
2535 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2536 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2537 exception);
2538 break;
2539 }
2540 if (LocaleCompare("scale",option+1) == 0)
2541 {
2542 /*
2543 Resize image.
2544 */
2545 (void) SyncImageSettings(mogrify_info,*image);
2546 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2547 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2548 exception);
2549 break;
2550 }
2551 if (LocaleCompare("selective-blur",option+1) == 0)
2552 {
2553 /*
2554 Selectively blur pixels within a contrast threshold.
2555 */
2556 (void) SyncImageSettings(mogrify_info,*image);
2557 flags=ParseGeometry(argv[i+1],&geometry_info);
2558 if ((flags & PercentValue) != 0)
2559 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002560 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2561 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002562 break;
2563 }
2564 if (LocaleCompare("separate",option+1) == 0)
2565 {
2566 /*
2567 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002568 */
2569 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002570 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002571 break;
2572 }
2573 if (LocaleCompare("sepia-tone",option+1) == 0)
2574 {
2575 double
2576 threshold;
2577
2578 /*
2579 Sepia-tone image.
2580 */
2581 (void) SyncImageSettings(mogrify_info,*image);
2582 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2583 mogrify_image=SepiaToneImage(*image,threshold,exception);
2584 break;
2585 }
2586 if (LocaleCompare("segment",option+1) == 0)
2587 {
2588 /*
2589 Segment image.
2590 */
2591 (void) SyncImageSettings(mogrify_info,*image);
2592 flags=ParseGeometry(argv[i+1],&geometry_info);
2593 if ((flags & SigmaValue) == 0)
2594 geometry_info.sigma=1.0;
2595 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002596 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2597 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002598 break;
2599 }
2600 if (LocaleCompare("set",option+1) == 0)
2601 {
2602 char
2603 *value;
2604
2605 /*
2606 Set image option.
2607 */
2608 if (*option == '+')
2609 {
2610 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2611 (void) DeleteImageRegistry(argv[i+1]+9);
2612 else
2613 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2614 {
2615 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2616 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2617 }
2618 else
2619 (void) DeleteImageProperty(*image,argv[i+1]);
2620 break;
2621 }
cristy018f07f2011-09-04 21:15:19 +00002622 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2623 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002624 if (value == (char *) NULL)
2625 break;
2626 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2627 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2628 exception);
2629 else
2630 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2631 {
2632 (void) SetImageOption(image_info,argv[i+1]+7,value);
2633 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2634 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2635 }
2636 else
2637 (void) SetImageProperty(*image,argv[i+1],value);
2638 value=DestroyString(value);
2639 break;
2640 }
2641 if (LocaleCompare("shade",option+1) == 0)
2642 {
2643 /*
2644 Shade image.
2645 */
2646 (void) SyncImageSettings(mogrify_info,*image);
2647 flags=ParseGeometry(argv[i+1],&geometry_info);
2648 if ((flags & SigmaValue) == 0)
2649 geometry_info.sigma=1.0;
2650 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2651 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2652 break;
2653 }
2654 if (LocaleCompare("shadow",option+1) == 0)
2655 {
2656 /*
2657 Shadow image.
2658 */
2659 (void) SyncImageSettings(mogrify_info,*image);
2660 flags=ParseGeometry(argv[i+1],&geometry_info);
2661 if ((flags & SigmaValue) == 0)
2662 geometry_info.sigma=1.0;
2663 if ((flags & XiValue) == 0)
2664 geometry_info.xi=4.0;
2665 if ((flags & PsiValue) == 0)
2666 geometry_info.psi=4.0;
2667 mogrify_image=ShadowImage(*image,geometry_info.rho,
2668 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2669 ceil(geometry_info.psi-0.5),exception);
2670 break;
2671 }
2672 if (LocaleCompare("sharpen",option+1) == 0)
2673 {
2674 /*
2675 Sharpen image.
2676 */
2677 (void) SyncImageSettings(mogrify_info,*image);
2678 flags=ParseGeometry(argv[i+1],&geometry_info);
2679 if ((flags & SigmaValue) == 0)
2680 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002681 if ((flags & XiValue) == 0)
2682 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002683 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002684 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002685 break;
2686 }
2687 if (LocaleCompare("shave",option+1) == 0)
2688 {
2689 /*
2690 Shave the image edges.
2691 */
2692 (void) SyncImageSettings(mogrify_info,*image);
2693 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2694 mogrify_image=ShaveImage(*image,&geometry,exception);
2695 break;
2696 }
2697 if (LocaleCompare("shear",option+1) == 0)
2698 {
2699 /*
2700 Shear image.
2701 */
2702 (void) SyncImageSettings(mogrify_info,*image);
2703 flags=ParseGeometry(argv[i+1],&geometry_info);
2704 if ((flags & SigmaValue) == 0)
2705 geometry_info.sigma=geometry_info.rho;
2706 mogrify_image=ShearImage(*image,geometry_info.rho,
2707 geometry_info.sigma,exception);
2708 break;
2709 }
2710 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2711 {
2712 /*
2713 Sigmoidal non-linearity contrast control.
2714 */
2715 (void) SyncImageSettings(mogrify_info,*image);
2716 flags=ParseGeometry(argv[i+1],&geometry_info);
2717 if ((flags & SigmaValue) == 0)
2718 geometry_info.sigma=(double) QuantumRange/2.0;
2719 if ((flags & PercentValue) != 0)
2720 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2721 100.0;
cristy9ee60942011-07-06 14:54:38 +00002722 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002723 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2724 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002725 break;
2726 }
2727 if (LocaleCompare("sketch",option+1) == 0)
2728 {
2729 /*
2730 Sketch image.
2731 */
2732 (void) SyncImageSettings(mogrify_info,*image);
2733 flags=ParseGeometry(argv[i+1],&geometry_info);
2734 if ((flags & SigmaValue) == 0)
2735 geometry_info.sigma=1.0;
2736 mogrify_image=SketchImage(*image,geometry_info.rho,
2737 geometry_info.sigma,geometry_info.xi,exception);
2738 break;
2739 }
2740 if (LocaleCompare("solarize",option+1) == 0)
2741 {
2742 double
2743 threshold;
2744
2745 (void) SyncImageSettings(mogrify_info,*image);
2746 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002747 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002748 break;
2749 }
2750 if (LocaleCompare("sparse-color",option+1) == 0)
2751 {
2752 SparseColorMethod
2753 method;
2754
2755 char
2756 *arguments;
2757
2758 /*
2759 Sparse Color Interpolated Gradient
2760 */
2761 (void) SyncImageSettings(mogrify_info,*image);
2762 method=(SparseColorMethod) ParseCommandOption(
2763 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002764 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2765 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002766 if (arguments == (char *) NULL)
2767 break;
cristy3884f692011-07-08 18:00:18 +00002768 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002769 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2770 arguments=DestroyString(arguments);
2771 break;
2772 }
2773 if (LocaleCompare("splice",option+1) == 0)
2774 {
2775 /*
2776 Splice a solid color into the image.
2777 */
2778 (void) SyncImageSettings(mogrify_info,*image);
2779 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2780 mogrify_image=SpliceImage(*image,&geometry,exception);
2781 break;
2782 }
2783 if (LocaleCompare("spread",option+1) == 0)
2784 {
2785 /*
2786 Spread an image.
2787 */
2788 (void) SyncImageSettings(mogrify_info,*image);
2789 (void) ParseGeometry(argv[i+1],&geometry_info);
2790 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2791 break;
2792 }
2793 if (LocaleCompare("statistic",option+1) == 0)
2794 {
2795 StatisticType
2796 type;
2797
2798 (void) SyncImageSettings(mogrify_info,*image);
2799 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2800 MagickFalse,argv[i+1]);
2801 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002802 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2803 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002804 break;
2805 }
2806 if (LocaleCompare("stretch",option+1) == 0)
2807 {
2808 if (*option == '+')
2809 {
2810 draw_info->stretch=UndefinedStretch;
2811 break;
2812 }
2813 draw_info->stretch=(StretchType) ParseCommandOption(
2814 MagickStretchOptions,MagickFalse,argv[i+1]);
2815 break;
2816 }
2817 if (LocaleCompare("strip",option+1) == 0)
2818 {
2819 /*
2820 Strip image of profiles and comments.
2821 */
2822 (void) SyncImageSettings(mogrify_info,*image);
2823 (void) StripImage(*image);
2824 InheritException(exception,&(*image)->exception);
2825 break;
2826 }
2827 if (LocaleCompare("stroke",option+1) == 0)
2828 {
2829 ExceptionInfo
2830 *sans;
2831
2832 if (*option == '+')
2833 {
2834 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2835 if (draw_info->stroke_pattern != (Image *) NULL)
2836 draw_info->stroke_pattern=DestroyImage(
2837 draw_info->stroke_pattern);
2838 break;
2839 }
2840 sans=AcquireExceptionInfo();
2841 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2842 sans=DestroyExceptionInfo(sans);
2843 if (status == MagickFalse)
2844 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2845 exception);
2846 break;
2847 }
2848 if (LocaleCompare("strokewidth",option+1) == 0)
2849 {
cristyc1acd842011-05-19 23:05:47 +00002850 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2851 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002852 break;
2853 }
2854 if (LocaleCompare("style",option+1) == 0)
2855 {
2856 if (*option == '+')
2857 {
2858 draw_info->style=UndefinedStyle;
2859 break;
2860 }
2861 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2862 MagickFalse,argv[i+1]);
2863 break;
2864 }
2865 if (LocaleCompare("swirl",option+1) == 0)
2866 {
2867 /*
2868 Swirl image.
2869 */
2870 (void) SyncImageSettings(mogrify_info,*image);
2871 (void) ParseGeometry(argv[i+1],&geometry_info);
2872 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2873 break;
2874 }
2875 break;
2876 }
2877 case 't':
2878 {
2879 if (LocaleCompare("threshold",option+1) == 0)
2880 {
2881 double
2882 threshold;
2883
2884 /*
2885 Threshold image.
2886 */
2887 (void) SyncImageSettings(mogrify_info,*image);
2888 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002889 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002890 else
2891 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002892 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002893 InheritException(exception,&(*image)->exception);
2894 break;
2895 }
2896 if (LocaleCompare("thumbnail",option+1) == 0)
2897 {
2898 /*
2899 Thumbnail image.
2900 */
2901 (void) SyncImageSettings(mogrify_info,*image);
2902 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2903 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2904 exception);
2905 break;
2906 }
2907 if (LocaleCompare("tile",option+1) == 0)
2908 {
2909 if (*option == '+')
2910 {
2911 if (draw_info->fill_pattern != (Image *) NULL)
2912 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2913 break;
2914 }
2915 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2916 exception);
2917 break;
2918 }
2919 if (LocaleCompare("tint",option+1) == 0)
2920 {
2921 /*
2922 Tint the image.
2923 */
2924 (void) SyncImageSettings(mogrify_info,*image);
2925 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2926 break;
2927 }
2928 if (LocaleCompare("transform",option+1) == 0)
2929 {
2930 /*
2931 Affine transform image.
2932 */
2933 (void) SyncImageSettings(mogrify_info,*image);
2934 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2935 exception);
2936 break;
2937 }
2938 if (LocaleCompare("transparent",option+1) == 0)
2939 {
cristy4c08aed2011-07-01 19:47:50 +00002940 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002941 target;
2942
2943 (void) SyncImageSettings(mogrify_info,*image);
2944 (void) QueryMagickColor(argv[i+1],&target,exception);
2945 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002946 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2947 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002948 break;
2949 }
2950 if (LocaleCompare("transpose",option+1) == 0)
2951 {
2952 /*
2953 Transpose image scanlines.
2954 */
2955 (void) SyncImageSettings(mogrify_info,*image);
2956 mogrify_image=TransposeImage(*image,exception);
2957 break;
2958 }
2959 if (LocaleCompare("transverse",option+1) == 0)
2960 {
2961 /*
2962 Transverse image scanlines.
2963 */
2964 (void) SyncImageSettings(mogrify_info,*image);
2965 mogrify_image=TransverseImage(*image,exception);
2966 break;
2967 }
2968 if (LocaleCompare("treedepth",option+1) == 0)
2969 {
2970 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2971 break;
2972 }
2973 if (LocaleCompare("trim",option+1) == 0)
2974 {
2975 /*
2976 Trim image.
2977 */
2978 (void) SyncImageSettings(mogrify_info,*image);
2979 mogrify_image=TrimImage(*image,exception);
2980 break;
2981 }
2982 if (LocaleCompare("type",option+1) == 0)
2983 {
2984 ImageType
2985 type;
2986
2987 (void) SyncImageSettings(mogrify_info,*image);
2988 if (*option == '+')
2989 type=UndefinedType;
2990 else
2991 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2992 argv[i+1]);
2993 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00002994 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002995 break;
2996 }
2997 break;
2998 }
2999 case 'u':
3000 {
3001 if (LocaleCompare("undercolor",option+1) == 0)
3002 {
3003 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3004 exception);
3005 break;
3006 }
3007 if (LocaleCompare("unique",option+1) == 0)
3008 {
3009 if (*option == '+')
3010 {
3011 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3012 break;
3013 }
3014 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3015 (void) SetImageArtifact(*image,"verbose","true");
3016 break;
3017 }
3018 if (LocaleCompare("unique-colors",option+1) == 0)
3019 {
3020 /*
3021 Unique image colors.
3022 */
3023 (void) SyncImageSettings(mogrify_info,*image);
3024 mogrify_image=UniqueImageColors(*image,exception);
3025 break;
3026 }
3027 if (LocaleCompare("unsharp",option+1) == 0)
3028 {
3029 /*
3030 Unsharp mask image.
3031 */
3032 (void) SyncImageSettings(mogrify_info,*image);
3033 flags=ParseGeometry(argv[i+1],&geometry_info);
3034 if ((flags & SigmaValue) == 0)
3035 geometry_info.sigma=1.0;
3036 if ((flags & XiValue) == 0)
3037 geometry_info.xi=1.0;
3038 if ((flags & PsiValue) == 0)
3039 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003040 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3041 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003042 break;
3043 }
3044 break;
3045 }
3046 case 'v':
3047 {
3048 if (LocaleCompare("verbose",option+1) == 0)
3049 {
3050 (void) SetImageArtifact(*image,option+1,
3051 *option == '+' ? "false" : "true");
3052 break;
3053 }
3054 if (LocaleCompare("vignette",option+1) == 0)
3055 {
3056 /*
3057 Vignette image.
3058 */
3059 (void) SyncImageSettings(mogrify_info,*image);
3060 flags=ParseGeometry(argv[i+1],&geometry_info);
3061 if ((flags & SigmaValue) == 0)
3062 geometry_info.sigma=1.0;
3063 if ((flags & XiValue) == 0)
3064 geometry_info.xi=0.1*(*image)->columns;
3065 if ((flags & PsiValue) == 0)
3066 geometry_info.psi=0.1*(*image)->rows;
3067 mogrify_image=VignetteImage(*image,geometry_info.rho,
3068 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3069 ceil(geometry_info.psi-0.5),exception);
3070 break;
3071 }
3072 if (LocaleCompare("virtual-pixel",option+1) == 0)
3073 {
3074 if (*option == '+')
3075 {
3076 (void) SetImageVirtualPixelMethod(*image,
3077 UndefinedVirtualPixelMethod);
3078 break;
3079 }
3080 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3081 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3082 argv[i+1]));
3083 break;
3084 }
3085 break;
3086 }
3087 case 'w':
3088 {
3089 if (LocaleCompare("wave",option+1) == 0)
3090 {
3091 /*
3092 Wave image.
3093 */
3094 (void) SyncImageSettings(mogrify_info,*image);
3095 flags=ParseGeometry(argv[i+1],&geometry_info);
3096 if ((flags & SigmaValue) == 0)
3097 geometry_info.sigma=1.0;
3098 mogrify_image=WaveImage(*image,geometry_info.rho,
3099 geometry_info.sigma,exception);
3100 break;
3101 }
3102 if (LocaleCompare("weight",option+1) == 0)
3103 {
3104 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3105 if (LocaleCompare(argv[i+1],"all") == 0)
3106 draw_info->weight=0;
3107 if (LocaleCompare(argv[i+1],"bold") == 0)
3108 draw_info->weight=700;
3109 if (LocaleCompare(argv[i+1],"bolder") == 0)
3110 if (draw_info->weight <= 800)
3111 draw_info->weight+=100;
3112 if (LocaleCompare(argv[i+1],"lighter") == 0)
3113 if (draw_info->weight >= 100)
3114 draw_info->weight-=100;
3115 if (LocaleCompare(argv[i+1],"normal") == 0)
3116 draw_info->weight=400;
3117 break;
3118 }
3119 if (LocaleCompare("white-threshold",option+1) == 0)
3120 {
3121 /*
3122 White threshold image.
3123 */
3124 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003125 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003126 InheritException(exception,&(*image)->exception);
3127 break;
3128 }
3129 break;
3130 }
3131 default:
3132 break;
3133 }
3134 /*
3135 Replace current image with any image that was generated
3136 */
3137 if (mogrify_image != (Image *) NULL)
3138 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003139 i+=count;
3140 }
3141 if (region_image != (Image *) NULL)
3142 {
anthonydf8ebac2011-04-27 09:03:19 +00003143 /*
3144 Composite transformed region onto image.
3145 */
cristy6b3da3a2010-06-20 02:21:46 +00003146 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003147 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003148 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3149 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003150 InheritException(exception,&region_image->exception);
3151 *image=DestroyImage(*image);
3152 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003153 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003154 }
3155 /*
3156 Free resources.
3157 */
anthonydf8ebac2011-04-27 09:03:19 +00003158 quantize_info=DestroyQuantizeInfo(quantize_info);
3159 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003160 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003161 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003162 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003163 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003164}
3165
3166/*
3167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3168% %
3169% %
3170% %
cristy5063d812010-10-19 16:28:10 +00003171+ 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 +00003172% %
3173% %
3174% %
3175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3176%
3177% MogrifyImageCommand() transforms an image or a sequence of images. These
3178% transforms include image scaling, image rotation, color reduction, and
3179% others. The transmogrified image overwrites the original image.
3180%
3181% The format of the MogrifyImageCommand method is:
3182%
3183% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3184% const char **argv,char **metadata,ExceptionInfo *exception)
3185%
3186% A description of each parameter follows:
3187%
3188% o image_info: the image info.
3189%
3190% o argc: the number of elements in the argument vector.
3191%
3192% o argv: A text array containing the command line arguments.
3193%
3194% o metadata: any metadata is returned here.
3195%
3196% o exception: return any errors or warnings in this structure.
3197%
3198*/
3199
3200static MagickBooleanType MogrifyUsage(void)
3201{
3202 static const char
3203 *miscellaneous[]=
3204 {
3205 "-debug events display copious debugging information",
3206 "-help print program options",
3207 "-list type print a list of supported option arguments",
3208 "-log format format of debugging information",
3209 "-version print version information",
3210 (char *) NULL
3211 },
3212 *operators[]=
3213 {
3214 "-adaptive-blur geometry",
3215 " adaptively blur pixels; decrease effect near edges",
3216 "-adaptive-resize geometry",
3217 " adaptively resize image using 'mesh' interpolation",
3218 "-adaptive-sharpen geometry",
3219 " adaptively sharpen pixels; increase effect near edges",
3220 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3221 " transparent, extract, background, or shape",
3222 "-annotate geometry text",
3223 " annotate the image with text",
3224 "-auto-gamma automagically adjust gamma level of image",
3225 "-auto-level automagically adjust color levels of image",
3226 "-auto-orient automagically orient (rotate) image",
3227 "-bench iterations measure performance",
3228 "-black-threshold value",
3229 " force all pixels below the threshold into black",
3230 "-blue-shift simulate a scene at nighttime in the moonlight",
3231 "-blur geometry reduce image noise and reduce detail levels",
3232 "-border geometry surround image with a border of color",
3233 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003234 "-brightness-contrast geometry",
3235 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003236 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003237 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003238 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003239 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003240 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003241 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003242 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003243 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003244 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003245 "-contrast enhance or reduce the image contrast",
3246 "-contrast-stretch geometry",
3247 " improve contrast by `stretching' the intensity range",
3248 "-convolve coefficients",
3249 " apply a convolution kernel to the image",
3250 "-cycle amount cycle the image colormap",
3251 "-decipher filename convert cipher pixels to plain pixels",
3252 "-deskew threshold straighten an image",
3253 "-despeckle reduce the speckles within an image",
3254 "-distort method args",
3255 " distort images according to given method ad args",
3256 "-draw string annotate the image with a graphic primitive",
3257 "-edge radius apply a filter to detect edges in the image",
3258 "-encipher filename convert plain pixels to cipher pixels",
3259 "-emboss radius emboss an image",
3260 "-enhance apply a digital filter to enhance a noisy image",
3261 "-equalize perform histogram equalization to an image",
3262 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003263 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003264 "-extent geometry set the image size",
3265 "-extract geometry extract area from image",
3266 "-fft implements the discrete Fourier transform (DFT)",
3267 "-flip flip image vertically",
3268 "-floodfill geometry color",
3269 " floodfill the image with color",
3270 "-flop flop image horizontally",
3271 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003272 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003273 " apply function over image values",
3274 "-gamma value level of gamma correction",
3275 "-gaussian-blur geometry",
3276 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003277 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003278 "-identify identify the format and characteristics of the image",
3279 "-ift implements the inverse discrete Fourier transform (DFT)",
3280 "-implode amount implode image pixels about the center",
3281 "-lat geometry local adaptive thresholding",
3282 "-layers method optimize, merge, or compare image layers",
3283 "-level value adjust the level of image contrast",
3284 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003285 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003286 "-linear-stretch geometry",
3287 " improve contrast by `stretching with saturation'",
3288 "-liquid-rescale geometry",
3289 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003290 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003291 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003292 "-modulate value vary the brightness, saturation, and hue",
3293 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003294 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003295 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003296 "-motion-blur geometry",
3297 " simulate motion blur",
3298 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003299 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003300 "-normalize transform image to span the full range of colors",
3301 "-opaque color change this color to the fill color",
3302 "-ordered-dither NxN",
3303 " add a noise pattern to the image with specific",
3304 " amplitudes",
3305 "-paint radius simulate an oil painting",
3306 "-polaroid angle simulate a Polaroid picture",
3307 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003308 "-profile filename add, delete, or apply an image profile",
3309 "-quantize colorspace reduce colors in this colorspace",
3310 "-radial-blur angle radial blur the image",
3311 "-raise value lighten/darken image edges to create a 3-D effect",
3312 "-random-threshold low,high",
3313 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003314 "-region geometry apply options to a portion of the image",
3315 "-render render vector graphics",
3316 "-repage geometry size and location of an image canvas",
3317 "-resample geometry change the resolution of an image",
3318 "-resize geometry resize the image",
3319 "-roll geometry roll an image vertically or horizontally",
3320 "-rotate degrees apply Paeth rotation to the image",
3321 "-sample geometry scale image with pixel sampling",
3322 "-scale geometry scale the image",
3323 "-segment values segment an image",
3324 "-selective-blur geometry",
3325 " selectively blur pixels within a contrast threshold",
3326 "-sepia-tone threshold",
3327 " simulate a sepia-toned photo",
3328 "-set property value set an image property",
3329 "-shade degrees shade the image using a distant light source",
3330 "-shadow geometry simulate an image shadow",
3331 "-sharpen geometry sharpen the image",
3332 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003333 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003334 "-sigmoidal-contrast geometry",
3335 " increase the contrast without saturating highlights or shadows",
3336 "-sketch geometry simulate a pencil sketch",
3337 "-solarize threshold negate all pixels above the threshold level",
3338 "-sparse-color method args",
3339 " fill in a image based on a few color points",
3340 "-splice geometry splice the background color into the image",
3341 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003342 "-statistic type radius",
3343 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003344 "-strip strip image of all profiles and comments",
3345 "-swirl degrees swirl image pixels about the center",
3346 "-threshold value threshold the image",
3347 "-thumbnail geometry create a thumbnail of the image",
3348 "-tile filename tile image when filling a graphic primitive",
3349 "-tint value tint the image with the fill color",
3350 "-transform affine transform image",
3351 "-transparent color make this color transparent within the image",
3352 "-transpose flip image vertically and rotate 90 degrees",
3353 "-transverse flop image horizontally and rotate 270 degrees",
3354 "-trim trim image edges",
3355 "-type type image type",
3356 "-unique-colors discard all but one of any pixel color",
3357 "-unsharp geometry sharpen the image",
3358 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003359 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003360 "-white-threshold value",
3361 " force all pixels above the threshold into white",
3362 (char *) NULL
3363 },
3364 *sequence_operators[]=
3365 {
cristy4285d782011-02-09 20:12:28 +00003366 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003367 "-clut apply a color lookup table to the image",
3368 "-coalesce merge a sequence of images",
3369 "-combine combine a sequence of images",
3370 "-composite composite image",
3371 "-crop geometry cut out a rectangular region of the image",
3372 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003373 "-evaluate-sequence operator",
3374 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003375 "-flatten flatten a sequence of images",
3376 "-fx expression apply mathematical expression to an image channel(s)",
3377 "-hald-clut apply a Hald color lookup table to the image",
3378 "-morph value morph an image sequence",
3379 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003380 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003381 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003382 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003383 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003384 "-write filename write images to this file",
3385 (char *) NULL
3386 },
3387 *settings[]=
3388 {
3389 "-adjoin join images into a single multi-image file",
3390 "-affine matrix affine transform matrix",
3391 "-alpha option activate, deactivate, reset, or set the alpha channel",
3392 "-antialias remove pixel-aliasing",
3393 "-authenticate password",
3394 " decipher image with this password",
3395 "-attenuate value lessen (or intensify) when adding noise to an image",
3396 "-background color background color",
3397 "-bias value add bias when convolving an image",
3398 "-black-point-compensation",
3399 " use black point compensation",
3400 "-blue-primary point chromaticity blue primary point",
3401 "-bordercolor color border color",
3402 "-caption string assign a caption to an image",
3403 "-channel type apply option to select image channels",
3404 "-colors value preferred number of colors in the image",
3405 "-colorspace type alternate image colorspace",
3406 "-comment string annotate image with comment",
3407 "-compose operator set image composite operator",
3408 "-compress type type of pixel compression when writing the image",
3409 "-define format:option",
3410 " define one or more image format options",
3411 "-delay value display the next image after pausing",
3412 "-density geometry horizontal and vertical density of the image",
3413 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003414 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003415 "-display server get image or font from this X server",
3416 "-dispose method layer disposal method",
3417 "-dither method apply error diffusion to image",
3418 "-encoding type text encoding type",
3419 "-endian type endianness (MSB or LSB) of the image",
3420 "-family name render text with this font family",
3421 "-fill color color to use when filling a graphic primitive",
3422 "-filter type use this filter when resizing an image",
3423 "-font name render text with this font",
3424 "-format \"string\" output formatted image characteristics",
3425 "-fuzz distance colors within this distance are considered equal",
3426 "-gravity type horizontal and vertical text placement",
3427 "-green-primary point chromaticity green primary point",
3428 "-intent type type of rendering intent when managing the image color",
3429 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003430 "-interline-spacing value",
3431 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003432 "-interpolate method pixel color interpolation method",
3433 "-interword-spacing value",
3434 " set the space between two words",
3435 "-kerning value set the space between two letters",
3436 "-label string assign a label to an image",
3437 "-limit type value pixel cache resource limit",
3438 "-loop iterations add Netscape loop extension to your GIF animation",
3439 "-mask filename associate a mask with the image",
3440 "-mattecolor color frame color",
3441 "-monitor monitor progress",
3442 "-orient type image orientation",
3443 "-page geometry size and location of an image canvas (setting)",
3444 "-ping efficiently determine image attributes",
3445 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003446 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003447 "-preview type image preview type",
3448 "-quality value JPEG/MIFF/PNG compression level",
3449 "-quiet suppress all warning messages",
3450 "-red-primary point chromaticity red primary point",
3451 "-regard-warnings pay attention to warning messages",
3452 "-remap filename transform image colors to match this set of colors",
3453 "-respect-parentheses settings remain in effect until parenthesis boundary",
3454 "-sampling-factor geometry",
3455 " horizontal and vertical sampling factor",
3456 "-scene value image scene number",
3457 "-seed value seed a new sequence of pseudo-random numbers",
3458 "-size geometry width and height of image",
3459 "-stretch type render text with this font stretch",
3460 "-stroke color graphic primitive stroke color",
3461 "-strokewidth value graphic primitive stroke width",
3462 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003463 "-synchronize synchronize image to storage device",
3464 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003465 "-texture filename name of texture to tile onto the image background",
3466 "-tile-offset geometry",
3467 " tile offset",
3468 "-treedepth value color tree depth",
3469 "-transparent-color color",
3470 " transparent color",
3471 "-undercolor color annotation bounding box color",
3472 "-units type the units of image resolution",
3473 "-verbose print detailed information about the image",
3474 "-view FlashPix viewing transforms",
3475 "-virtual-pixel method",
3476 " virtual pixel access method",
3477 "-weight type render text with this font weight",
3478 "-white-point point chromaticity white point",
3479 (char *) NULL
3480 },
3481 *stack_operators[]=
3482 {
anthonyb69c4b32011-03-23 04:37:44 +00003483 "-delete indexes delete the image from the image sequence",
3484 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003485 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003486 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003487 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003488 "-swap indexes swap two images in the image sequence",
3489 (char *) NULL
3490 };
3491
3492 const char
3493 **p;
3494
cristybb503372010-05-27 20:51:26 +00003495 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003496 (void) printf("Copyright: %s\n",GetMagickCopyright());
3497 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003498 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3499 GetClientName());
3500 (void) printf("\nImage Settings:\n");
3501 for (p=settings; *p != (char *) NULL; p++)
3502 (void) printf(" %s\n",*p);
3503 (void) printf("\nImage Operators:\n");
3504 for (p=operators; *p != (char *) NULL; p++)
3505 (void) printf(" %s\n",*p);
3506 (void) printf("\nImage Sequence Operators:\n");
3507 for (p=sequence_operators; *p != (char *) NULL; p++)
3508 (void) printf(" %s\n",*p);
3509 (void) printf("\nImage Stack Operators:\n");
3510 for (p=stack_operators; *p != (char *) NULL; p++)
3511 (void) printf(" %s\n",*p);
3512 (void) printf("\nMiscellaneous Options:\n");
3513 for (p=miscellaneous; *p != (char *) NULL; p++)
3514 (void) printf(" %s\n",*p);
3515 (void) printf(
3516 "\nBy default, the image format of `file' is determined by its magic\n");
3517 (void) printf(
3518 "number. To specify a particular image format, precede the filename\n");
3519 (void) printf(
3520 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3521 (void) printf(
3522 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3523 (void) printf("'-' for standard input or output.\n");
3524 return(MagickFalse);
3525}
3526
3527WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3528 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3529{
3530#define DestroyMogrify() \
3531{ \
3532 if (format != (char *) NULL) \
3533 format=DestroyString(format); \
3534 if (path != (char *) NULL) \
3535 path=DestroyString(path); \
3536 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003537 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003538 argv[i]=DestroyString(argv[i]); \
3539 argv=(char **) RelinquishMagickMemory(argv); \
3540}
3541#define ThrowMogrifyException(asperity,tag,option) \
3542{ \
3543 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3544 option); \
3545 DestroyMogrify(); \
3546 return(MagickFalse); \
3547}
3548#define ThrowMogrifyInvalidArgumentException(option,argument) \
3549{ \
3550 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3551 "InvalidArgument","`%s': %s",argument,option); \
3552 DestroyMogrify(); \
3553 return(MagickFalse); \
3554}
3555
3556 char
3557 *format,
3558 *option,
3559 *path;
3560
3561 Image
3562 *image;
3563
3564 ImageStack
3565 image_stack[MaxImageStackDepth+1];
3566
cristy3ed852e2009-09-05 21:47:34 +00003567 MagickBooleanType
3568 global_colormap;
3569
3570 MagickBooleanType
3571 fire,
cristyebbcfea2011-02-25 02:43:54 +00003572 pend,
3573 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003574
3575 MagickStatusType
3576 status;
3577
cristyebbcfea2011-02-25 02:43:54 +00003578 register ssize_t
3579 i;
3580
3581 ssize_t
3582 j,
3583 k;
3584
cristy3ed852e2009-09-05 21:47:34 +00003585 /*
3586 Set defaults.
3587 */
3588 assert(image_info != (ImageInfo *) NULL);
3589 assert(image_info->signature == MagickSignature);
3590 if (image_info->debug != MagickFalse)
3591 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3592 assert(exception != (ExceptionInfo *) NULL);
3593 if (argc == 2)
3594 {
3595 option=argv[1];
3596 if ((LocaleCompare("version",option+1) == 0) ||
3597 (LocaleCompare("-version",option+1) == 0))
3598 {
cristyb51dff52011-05-19 16:55:47 +00003599 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003600 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003601 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3602 GetMagickCopyright());
3603 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3604 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003605 return(MagickFalse);
3606 }
3607 }
3608 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003609 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003610 format=(char *) NULL;
3611 path=(char *) NULL;
3612 global_colormap=MagickFalse;
3613 k=0;
3614 j=1;
3615 NewImageStack();
3616 option=(char *) NULL;
3617 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003618 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003619 status=MagickTrue;
3620 /*
3621 Parse command line.
3622 */
3623 ReadCommandlLine(argc,&argv);
3624 status=ExpandFilenames(&argc,&argv);
3625 if (status == MagickFalse)
3626 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3627 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003628 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003629 {
3630 option=argv[i];
3631 if (LocaleCompare(option,"(") == 0)
3632 {
3633 FireImageStack(MagickFalse,MagickTrue,pend);
3634 if (k == MaxImageStackDepth)
3635 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3636 option);
3637 PushImageStack();
3638 continue;
3639 }
3640 if (LocaleCompare(option,")") == 0)
3641 {
3642 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3643 if (k == 0)
3644 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3645 PopImageStack();
3646 continue;
3647 }
cristy042ee782011-04-22 18:48:30 +00003648 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003649 {
3650 char
3651 backup_filename[MaxTextExtent],
3652 *filename;
3653
3654 Image
3655 *images;
3656
3657 /*
3658 Option is a file name: begin by reading image from specified file.
3659 */
3660 FireImageStack(MagickFalse,MagickFalse,pend);
3661 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003662 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003663 filename=argv[++i];
3664 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3665 images=ReadImages(image_info,exception);
3666 status&=(images != (Image *) NULL) &&
3667 (exception->severity < ErrorException);
3668 if (images == (Image *) NULL)
3669 continue;
cristydaa76602010-06-30 13:05:11 +00003670 if (format != (char *) NULL)
3671 (void) CopyMagickString(images->filename,images->magick_filename,
3672 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003673 if (path != (char *) NULL)
3674 {
3675 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003676 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003677 path,*DirectorySeparator,filename);
3678 }
3679 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003680 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003681 AppendImageStack(images);
3682 FinalizeImageSettings(image_info,image,MagickFalse);
3683 if (global_colormap != MagickFalse)
3684 {
3685 QuantizeInfo
3686 *quantize_info;
3687
3688 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003689 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003690 quantize_info=DestroyQuantizeInfo(quantize_info);
3691 }
3692 *backup_filename='\0';
3693 if ((LocaleCompare(image->filename,"-") != 0) &&
3694 (IsPathWritable(image->filename) != MagickFalse))
3695 {
cristybb503372010-05-27 20:51:26 +00003696 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003697 i;
3698
3699 /*
3700 Rename image file as backup.
3701 */
3702 (void) CopyMagickString(backup_filename,image->filename,
3703 MaxTextExtent);
3704 for (i=0; i < 6; i++)
3705 {
3706 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3707 if (IsPathAccessible(backup_filename) == MagickFalse)
3708 break;
3709 }
3710 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3711 (rename(image->filename,backup_filename) != 0))
3712 *backup_filename='\0';
3713 }
3714 /*
3715 Write transmogrified image to disk.
3716 */
3717 image_info->synchronize=MagickTrue;
3718 status&=WriteImages(image_info,image,image->filename,exception);
3719 if ((status == MagickFalse) && (*backup_filename != '\0'))
3720 (void) remove(backup_filename);
3721 RemoveAllImageStack();
3722 continue;
3723 }
3724 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3725 switch (*(option+1))
3726 {
3727 case 'a':
3728 {
3729 if (LocaleCompare("adaptive-blur",option+1) == 0)
3730 {
3731 i++;
cristybb503372010-05-27 20:51:26 +00003732 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003733 ThrowMogrifyException(OptionError,"MissingArgument",option);
3734 if (IsGeometry(argv[i]) == MagickFalse)
3735 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3736 break;
3737 }
3738 if (LocaleCompare("adaptive-resize",option+1) == 0)
3739 {
3740 i++;
cristybb503372010-05-27 20:51:26 +00003741 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003742 ThrowMogrifyException(OptionError,"MissingArgument",option);
3743 if (IsGeometry(argv[i]) == MagickFalse)
3744 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3745 break;
3746 }
3747 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3748 {
3749 i++;
cristybb503372010-05-27 20:51:26 +00003750 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003751 ThrowMogrifyException(OptionError,"MissingArgument",option);
3752 if (IsGeometry(argv[i]) == MagickFalse)
3753 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3754 break;
3755 }
3756 if (LocaleCompare("affine",option+1) == 0)
3757 {
3758 if (*option == '+')
3759 break;
3760 i++;
cristybb503372010-05-27 20:51:26 +00003761 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003762 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003763 break;
3764 }
3765 if (LocaleCompare("alpha",option+1) == 0)
3766 {
cristybb503372010-05-27 20:51:26 +00003767 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003768 type;
3769
3770 if (*option == '+')
3771 break;
3772 i++;
cristybb503372010-05-27 20:51:26 +00003773 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003774 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003775 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003776 if (type < 0)
3777 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3778 argv[i]);
3779 break;
3780 }
3781 if (LocaleCompare("annotate",option+1) == 0)
3782 {
3783 if (*option == '+')
3784 break;
3785 i++;
cristybb503372010-05-27 20:51:26 +00003786 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003787 ThrowMogrifyException(OptionError,"MissingArgument",option);
3788 if (IsGeometry(argv[i]) == MagickFalse)
3789 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003790 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003791 ThrowMogrifyException(OptionError,"MissingArgument",option);
3792 i++;
3793 break;
3794 }
3795 if (LocaleCompare("antialias",option+1) == 0)
3796 break;
3797 if (LocaleCompare("append",option+1) == 0)
3798 break;
3799 if (LocaleCompare("attenuate",option+1) == 0)
3800 {
3801 if (*option == '+')
3802 break;
3803 i++;
cristybb503372010-05-27 20:51:26 +00003804 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003805 ThrowMogrifyException(OptionError,"MissingArgument",option);
3806 if (IsGeometry(argv[i]) == MagickFalse)
3807 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3808 break;
3809 }
3810 if (LocaleCompare("authenticate",option+1) == 0)
3811 {
3812 if (*option == '+')
3813 break;
3814 i++;
cristybb503372010-05-27 20:51:26 +00003815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003816 ThrowMogrifyException(OptionError,"MissingArgument",option);
3817 break;
3818 }
3819 if (LocaleCompare("auto-gamma",option+1) == 0)
3820 break;
3821 if (LocaleCompare("auto-level",option+1) == 0)
3822 break;
3823 if (LocaleCompare("auto-orient",option+1) == 0)
3824 break;
3825 if (LocaleCompare("average",option+1) == 0)
3826 break;
3827 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3828 }
3829 case 'b':
3830 {
3831 if (LocaleCompare("background",option+1) == 0)
3832 {
3833 if (*option == '+')
3834 break;
3835 i++;
cristybb503372010-05-27 20:51:26 +00003836 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003837 ThrowMogrifyException(OptionError,"MissingArgument",option);
3838 break;
3839 }
3840 if (LocaleCompare("bias",option+1) == 0)
3841 {
3842 if (*option == '+')
3843 break;
3844 i++;
cristybb503372010-05-27 20:51:26 +00003845 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003846 ThrowMogrifyException(OptionError,"MissingArgument",option);
3847 if (IsGeometry(argv[i]) == MagickFalse)
3848 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3849 break;
3850 }
3851 if (LocaleCompare("black-point-compensation",option+1) == 0)
3852 break;
3853 if (LocaleCompare("black-threshold",option+1) == 0)
3854 {
3855 if (*option == '+')
3856 break;
3857 i++;
cristybb503372010-05-27 20:51:26 +00003858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003859 ThrowMogrifyException(OptionError,"MissingArgument",option);
3860 if (IsGeometry(argv[i]) == MagickFalse)
3861 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3862 break;
3863 }
3864 if (LocaleCompare("blue-primary",option+1) == 0)
3865 {
3866 if (*option == '+')
3867 break;
3868 i++;
cristybb503372010-05-27 20:51:26 +00003869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003870 ThrowMogrifyException(OptionError,"MissingArgument",option);
3871 if (IsGeometry(argv[i]) == MagickFalse)
3872 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3873 break;
3874 }
3875 if (LocaleCompare("blue-shift",option+1) == 0)
3876 {
3877 i++;
cristybb503372010-05-27 20:51:26 +00003878 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003879 ThrowMogrifyException(OptionError,"MissingArgument",option);
3880 if (IsGeometry(argv[i]) == MagickFalse)
3881 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3882 break;
3883 }
3884 if (LocaleCompare("blur",option+1) == 0)
3885 {
3886 i++;
cristybb503372010-05-27 20:51:26 +00003887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003888 ThrowMogrifyException(OptionError,"MissingArgument",option);
3889 if (IsGeometry(argv[i]) == MagickFalse)
3890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3891 break;
3892 }
3893 if (LocaleCompare("border",option+1) == 0)
3894 {
3895 if (*option == '+')
3896 break;
3897 i++;
cristybb503372010-05-27 20:51:26 +00003898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003899 ThrowMogrifyException(OptionError,"MissingArgument",option);
3900 if (IsGeometry(argv[i]) == MagickFalse)
3901 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3902 break;
3903 }
3904 if (LocaleCompare("bordercolor",option+1) == 0)
3905 {
3906 if (*option == '+')
3907 break;
3908 i++;
cristybb503372010-05-27 20:51:26 +00003909 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003910 ThrowMogrifyException(OptionError,"MissingArgument",option);
3911 break;
3912 }
3913 if (LocaleCompare("box",option+1) == 0)
3914 {
3915 if (*option == '+')
3916 break;
3917 i++;
cristybb503372010-05-27 20:51:26 +00003918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003919 ThrowMogrifyException(OptionError,"MissingArgument",option);
3920 break;
3921 }
cristya28d6b82010-01-11 20:03:47 +00003922 if (LocaleCompare("brightness-contrast",option+1) == 0)
3923 {
3924 i++;
cristybb503372010-05-27 20:51:26 +00003925 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003926 ThrowMogrifyException(OptionError,"MissingArgument",option);
3927 if (IsGeometry(argv[i]) == MagickFalse)
3928 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3929 break;
3930 }
cristy3ed852e2009-09-05 21:47:34 +00003931 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3932 }
3933 case 'c':
3934 {
3935 if (LocaleCompare("cache",option+1) == 0)
3936 {
3937 if (*option == '+')
3938 break;
3939 i++;
cristybb503372010-05-27 20:51:26 +00003940 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003941 ThrowMogrifyException(OptionError,"MissingArgument",option);
3942 if (IsGeometry(argv[i]) == MagickFalse)
3943 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3944 break;
3945 }
3946 if (LocaleCompare("caption",option+1) == 0)
3947 {
3948 if (*option == '+')
3949 break;
3950 i++;
cristybb503372010-05-27 20:51:26 +00003951 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003952 ThrowMogrifyException(OptionError,"MissingArgument",option);
3953 break;
3954 }
3955 if (LocaleCompare("channel",option+1) == 0)
3956 {
cristybb503372010-05-27 20:51:26 +00003957 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003958 channel;
3959
3960 if (*option == '+')
3961 break;
3962 i++;
cristybb503372010-05-27 20:51:26 +00003963 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003964 ThrowMogrifyException(OptionError,"MissingArgument",option);
3965 channel=ParseChannelOption(argv[i]);
3966 if (channel < 0)
3967 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3968 argv[i]);
3969 break;
3970 }
3971 if (LocaleCompare("cdl",option+1) == 0)
3972 {
3973 if (*option == '+')
3974 break;
3975 i++;
cristybb503372010-05-27 20:51:26 +00003976 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003977 ThrowMogrifyException(OptionError,"MissingArgument",option);
3978 break;
3979 }
3980 if (LocaleCompare("charcoal",option+1) == 0)
3981 {
3982 if (*option == '+')
3983 break;
3984 i++;
cristybb503372010-05-27 20:51:26 +00003985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003986 ThrowMogrifyException(OptionError,"MissingArgument",option);
3987 if (IsGeometry(argv[i]) == MagickFalse)
3988 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3989 break;
3990 }
3991 if (LocaleCompare("chop",option+1) == 0)
3992 {
3993 if (*option == '+')
3994 break;
3995 i++;
cristybb503372010-05-27 20:51:26 +00003996 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003997 ThrowMogrifyException(OptionError,"MissingArgument",option);
3998 if (IsGeometry(argv[i]) == MagickFalse)
3999 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4000 break;
4001 }
cristy1eb45dd2009-09-25 16:38:06 +00004002 if (LocaleCompare("clamp",option+1) == 0)
4003 break;
4004 if (LocaleCompare("clip",option+1) == 0)
4005 break;
cristy3ed852e2009-09-05 21:47:34 +00004006 if (LocaleCompare("clip-mask",option+1) == 0)
4007 {
4008 if (*option == '+')
4009 break;
4010 i++;
cristybb503372010-05-27 20:51:26 +00004011 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004012 ThrowMogrifyException(OptionError,"MissingArgument",option);
4013 break;
4014 }
4015 if (LocaleCompare("clut",option+1) == 0)
4016 break;
4017 if (LocaleCompare("coalesce",option+1) == 0)
4018 break;
4019 if (LocaleCompare("colorize",option+1) == 0)
4020 {
4021 if (*option == '+')
4022 break;
4023 i++;
cristybb503372010-05-27 20:51:26 +00004024 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004025 ThrowMogrifyException(OptionError,"MissingArgument",option);
4026 if (IsGeometry(argv[i]) == MagickFalse)
4027 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4028 break;
4029 }
cristye6365592010-04-02 17:31:23 +00004030 if (LocaleCompare("color-matrix",option+1) == 0)
4031 {
cristyb6bd4ad2010-08-08 01:12:27 +00004032 KernelInfo
4033 *kernel_info;
4034
cristye6365592010-04-02 17:31:23 +00004035 if (*option == '+')
4036 break;
4037 i++;
cristybb503372010-05-27 20:51:26 +00004038 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004039 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004040 kernel_info=AcquireKernelInfo(argv[i]);
4041 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004042 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004043 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004044 break;
4045 }
cristy3ed852e2009-09-05 21:47:34 +00004046 if (LocaleCompare("colors",option+1) == 0)
4047 {
4048 if (*option == '+')
4049 break;
4050 i++;
cristybb503372010-05-27 20:51:26 +00004051 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004052 ThrowMogrifyException(OptionError,"MissingArgument",option);
4053 if (IsGeometry(argv[i]) == MagickFalse)
4054 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4055 break;
4056 }
4057 if (LocaleCompare("colorspace",option+1) == 0)
4058 {
cristybb503372010-05-27 20:51:26 +00004059 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004060 colorspace;
4061
4062 if (*option == '+')
4063 break;
4064 i++;
cristybb503372010-05-27 20:51:26 +00004065 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004066 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004067 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004068 argv[i]);
4069 if (colorspace < 0)
4070 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4071 argv[i]);
4072 break;
4073 }
4074 if (LocaleCompare("combine",option+1) == 0)
4075 break;
4076 if (LocaleCompare("comment",option+1) == 0)
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);
4083 break;
4084 }
4085 if (LocaleCompare("composite",option+1) == 0)
4086 break;
4087 if (LocaleCompare("compress",option+1) == 0)
4088 {
cristybb503372010-05-27 20:51:26 +00004089 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004090 compress;
4091
4092 if (*option == '+')
4093 break;
4094 i++;
cristybb503372010-05-27 20:51:26 +00004095 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004096 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004097 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004098 argv[i]);
4099 if (compress < 0)
4100 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4101 argv[i]);
4102 break;
4103 }
cristy22879752009-10-25 23:55:40 +00004104 if (LocaleCompare("concurrent",option+1) == 0)
4105 break;
cristy3ed852e2009-09-05 21:47:34 +00004106 if (LocaleCompare("contrast",option+1) == 0)
4107 break;
4108 if (LocaleCompare("contrast-stretch",option+1) == 0)
4109 {
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);
4113 if (IsGeometry(argv[i]) == MagickFalse)
4114 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4115 break;
4116 }
4117 if (LocaleCompare("convolve",option+1) == 0)
4118 {
cristyb6bd4ad2010-08-08 01:12:27 +00004119 KernelInfo
4120 *kernel_info;
4121
cristy3ed852e2009-09-05 21:47:34 +00004122 if (*option == '+')
4123 break;
4124 i++;
cristybb503372010-05-27 20:51:26 +00004125 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004126 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004127 kernel_info=AcquireKernelInfo(argv[i]);
4128 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004129 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004130 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004131 break;
4132 }
4133 if (LocaleCompare("crop",option+1) == 0)
4134 {
4135 if (*option == '+')
4136 break;
4137 i++;
cristybb503372010-05-27 20:51:26 +00004138 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004139 ThrowMogrifyException(OptionError,"MissingArgument",option);
4140 if (IsGeometry(argv[i]) == MagickFalse)
4141 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4142 break;
4143 }
4144 if (LocaleCompare("cycle",option+1) == 0)
4145 {
4146 if (*option == '+')
4147 break;
4148 i++;
cristybb503372010-05-27 20:51:26 +00004149 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004150 ThrowMogrifyException(OptionError,"MissingArgument",option);
4151 if (IsGeometry(argv[i]) == MagickFalse)
4152 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4153 break;
4154 }
4155 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4156 }
4157 case 'd':
4158 {
4159 if (LocaleCompare("decipher",option+1) == 0)
4160 {
4161 if (*option == '+')
4162 break;
4163 i++;
cristybb503372010-05-27 20:51:26 +00004164 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004165 ThrowMogrifyException(OptionError,"MissingArgument",option);
4166 break;
4167 }
4168 if (LocaleCompare("deconstruct",option+1) == 0)
4169 break;
4170 if (LocaleCompare("debug",option+1) == 0)
4171 {
cristybb503372010-05-27 20:51:26 +00004172 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004173 event;
4174
4175 if (*option == '+')
4176 break;
4177 i++;
cristybb503372010-05-27 20:51:26 +00004178 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004179 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004180 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004181 if (event < 0)
4182 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4183 argv[i]);
4184 (void) SetLogEventMask(argv[i]);
4185 break;
4186 }
4187 if (LocaleCompare("define",option+1) == 0)
4188 {
4189 i++;
cristybb503372010-05-27 20:51:26 +00004190 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004191 ThrowMogrifyException(OptionError,"MissingArgument",option);
4192 if (*option == '+')
4193 {
4194 const char
4195 *define;
4196
4197 define=GetImageOption(image_info,argv[i]);
4198 if (define == (const char *) NULL)
4199 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4200 break;
4201 }
4202 break;
4203 }
4204 if (LocaleCompare("delay",option+1) == 0)
4205 {
4206 if (*option == '+')
4207 break;
4208 i++;
cristybb503372010-05-27 20:51:26 +00004209 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004210 ThrowMogrifyException(OptionError,"MissingArgument",option);
4211 if (IsGeometry(argv[i]) == MagickFalse)
4212 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4213 break;
4214 }
cristyecb10ff2011-03-22 13:14:03 +00004215 if (LocaleCompare("delete",option+1) == 0)
4216 {
4217 if (*option == '+')
4218 break;
4219 i++;
4220 if (i == (ssize_t) (argc-1))
4221 ThrowMogrifyException(OptionError,"MissingArgument",option);
4222 if (IsGeometry(argv[i]) == MagickFalse)
4223 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4224 break;
4225 }
cristy3ed852e2009-09-05 21:47:34 +00004226 if (LocaleCompare("density",option+1) == 0)
4227 {
4228 if (*option == '+')
4229 break;
4230 i++;
cristybb503372010-05-27 20:51:26 +00004231 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004232 ThrowMogrifyException(OptionError,"MissingArgument",option);
4233 if (IsGeometry(argv[i]) == MagickFalse)
4234 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4235 break;
4236 }
4237 if (LocaleCompare("depth",option+1) == 0)
4238 {
4239 if (*option == '+')
4240 break;
4241 i++;
cristybb503372010-05-27 20:51:26 +00004242 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004243 ThrowMogrifyException(OptionError,"MissingArgument",option);
4244 if (IsGeometry(argv[i]) == MagickFalse)
4245 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4246 break;
4247 }
4248 if (LocaleCompare("deskew",option+1) == 0)
4249 {
4250 if (*option == '+')
4251 break;
4252 i++;
cristybb503372010-05-27 20:51:26 +00004253 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004254 ThrowMogrifyException(OptionError,"MissingArgument",option);
4255 if (IsGeometry(argv[i]) == MagickFalse)
4256 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4257 break;
4258 }
4259 if (LocaleCompare("despeckle",option+1) == 0)
4260 break;
4261 if (LocaleCompare("dft",option+1) == 0)
4262 break;
cristyc9b12952010-03-28 01:12:28 +00004263 if (LocaleCompare("direction",option+1) == 0)
4264 {
cristybb503372010-05-27 20:51:26 +00004265 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004266 direction;
4267
4268 if (*option == '+')
4269 break;
4270 i++;
cristybb503372010-05-27 20:51:26 +00004271 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004272 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004273 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004274 argv[i]);
4275 if (direction < 0)
4276 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4277 argv[i]);
4278 break;
4279 }
cristy3ed852e2009-09-05 21:47:34 +00004280 if (LocaleCompare("display",option+1) == 0)
4281 {
4282 if (*option == '+')
4283 break;
4284 i++;
cristybb503372010-05-27 20:51:26 +00004285 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004286 ThrowMogrifyException(OptionError,"MissingArgument",option);
4287 break;
4288 }
4289 if (LocaleCompare("dispose",option+1) == 0)
4290 {
cristybb503372010-05-27 20:51:26 +00004291 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004292 dispose;
4293
4294 if (*option == '+')
4295 break;
4296 i++;
cristybb503372010-05-27 20:51:26 +00004297 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004298 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004299 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004300 if (dispose < 0)
4301 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4302 argv[i]);
4303 break;
4304 }
4305 if (LocaleCompare("distort",option+1) == 0)
4306 {
cristybb503372010-05-27 20:51:26 +00004307 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004308 op;
4309
4310 i++;
cristybb503372010-05-27 20:51:26 +00004311 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004312 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004313 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004314 if (op < 0)
4315 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4316 argv[i]);
4317 i++;
cristybb503372010-05-27 20:51:26 +00004318 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004319 ThrowMogrifyException(OptionError,"MissingArgument",option);
4320 break;
4321 }
4322 if (LocaleCompare("dither",option+1) == 0)
4323 {
cristybb503372010-05-27 20:51:26 +00004324 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004325 method;
4326
4327 if (*option == '+')
4328 break;
4329 i++;
cristybb503372010-05-27 20:51:26 +00004330 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004331 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004332 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004333 if (method < 0)
4334 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4335 argv[i]);
4336 break;
4337 }
4338 if (LocaleCompare("draw",option+1) == 0)
4339 {
4340 if (*option == '+')
4341 break;
4342 i++;
cristybb503372010-05-27 20:51:26 +00004343 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004344 ThrowMogrifyException(OptionError,"MissingArgument",option);
4345 break;
4346 }
cristyecb10ff2011-03-22 13:14:03 +00004347 if (LocaleCompare("duplicate",option+1) == 0)
4348 {
4349 if (*option == '+')
4350 break;
4351 i++;
4352 if (i == (ssize_t) (argc-1))
4353 ThrowMogrifyException(OptionError,"MissingArgument",option);
4354 if (IsGeometry(argv[i]) == MagickFalse)
4355 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4356 break;
4357 }
cristy22879752009-10-25 23:55:40 +00004358 if (LocaleCompare("duration",option+1) == 0)
4359 {
4360 if (*option == '+')
4361 break;
4362 i++;
cristybb503372010-05-27 20:51:26 +00004363 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004364 ThrowMogrifyException(OptionError,"MissingArgument",option);
4365 if (IsGeometry(argv[i]) == MagickFalse)
4366 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4367 break;
4368 }
cristy3ed852e2009-09-05 21:47:34 +00004369 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4370 }
4371 case 'e':
4372 {
4373 if (LocaleCompare("edge",option+1) == 0)
4374 {
4375 if (*option == '+')
4376 break;
4377 i++;
cristybb503372010-05-27 20:51:26 +00004378 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004379 ThrowMogrifyException(OptionError,"MissingArgument",option);
4380 if (IsGeometry(argv[i]) == MagickFalse)
4381 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4382 break;
4383 }
4384 if (LocaleCompare("emboss",option+1) == 0)
4385 {
4386 if (*option == '+')
4387 break;
4388 i++;
cristybb503372010-05-27 20:51:26 +00004389 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004390 ThrowMogrifyException(OptionError,"MissingArgument",option);
4391 if (IsGeometry(argv[i]) == MagickFalse)
4392 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4393 break;
4394 }
4395 if (LocaleCompare("encipher",option+1) == 0)
4396 {
4397 if (*option == '+')
4398 break;
4399 i++;
cristybb503372010-05-27 20:51:26 +00004400 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004401 ThrowMogrifyException(OptionError,"MissingArgument",option);
4402 break;
4403 }
4404 if (LocaleCompare("encoding",option+1) == 0)
4405 {
4406 if (*option == '+')
4407 break;
4408 i++;
cristybb503372010-05-27 20:51:26 +00004409 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004410 ThrowMogrifyException(OptionError,"MissingArgument",option);
4411 break;
4412 }
4413 if (LocaleCompare("endian",option+1) == 0)
4414 {
cristybb503372010-05-27 20:51:26 +00004415 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004416 endian;
4417
4418 if (*option == '+')
4419 break;
4420 i++;
cristybb503372010-05-27 20:51:26 +00004421 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004422 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004423 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004424 if (endian < 0)
4425 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4426 argv[i]);
4427 break;
4428 }
4429 if (LocaleCompare("enhance",option+1) == 0)
4430 break;
4431 if (LocaleCompare("equalize",option+1) == 0)
4432 break;
4433 if (LocaleCompare("evaluate",option+1) == 0)
4434 {
cristybb503372010-05-27 20:51:26 +00004435 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004436 op;
4437
4438 if (*option == '+')
4439 break;
4440 i++;
cristybb503372010-05-27 20:51:26 +00004441 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004442 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004443 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004444 if (op < 0)
4445 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4446 argv[i]);
4447 i++;
cristybb503372010-05-27 20:51:26 +00004448 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004449 ThrowMogrifyException(OptionError,"MissingArgument",option);
4450 if (IsGeometry(argv[i]) == MagickFalse)
4451 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4452 break;
4453 }
cristyd18ae7c2010-03-07 17:39:52 +00004454 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4455 {
cristybb503372010-05-27 20:51:26 +00004456 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004457 op;
4458
4459 if (*option == '+')
4460 break;
4461 i++;
cristybb503372010-05-27 20:51:26 +00004462 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004463 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004464 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004465 if (op < 0)
4466 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4467 argv[i]);
4468 break;
4469 }
cristy3ed852e2009-09-05 21:47:34 +00004470 if (LocaleCompare("extent",option+1) == 0)
4471 {
4472 if (*option == '+')
4473 break;
4474 i++;
cristybb503372010-05-27 20:51:26 +00004475 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004476 ThrowMogrifyException(OptionError,"MissingArgument",option);
4477 if (IsGeometry(argv[i]) == MagickFalse)
4478 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4479 break;
4480 }
4481 if (LocaleCompare("extract",option+1) == 0)
4482 {
4483 if (*option == '+')
4484 break;
4485 i++;
cristybb503372010-05-27 20:51:26 +00004486 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004487 ThrowMogrifyException(OptionError,"MissingArgument",option);
4488 if (IsGeometry(argv[i]) == MagickFalse)
4489 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4490 break;
4491 }
4492 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4493 }
4494 case 'f':
4495 {
4496 if (LocaleCompare("family",option+1) == 0)
4497 {
4498 if (*option == '+')
4499 break;
4500 i++;
cristybb503372010-05-27 20:51:26 +00004501 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004502 ThrowMogrifyException(OptionError,"MissingArgument",option);
4503 break;
4504 }
4505 if (LocaleCompare("fill",option+1) == 0)
4506 {
4507 if (*option == '+')
4508 break;
4509 i++;
cristybb503372010-05-27 20:51:26 +00004510 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004511 ThrowMogrifyException(OptionError,"MissingArgument",option);
4512 break;
4513 }
4514 if (LocaleCompare("filter",option+1) == 0)
4515 {
cristybb503372010-05-27 20:51:26 +00004516 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004517 filter;
4518
4519 if (*option == '+')
4520 break;
4521 i++;
cristybb503372010-05-27 20:51:26 +00004522 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004523 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004524 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004525 if (filter < 0)
4526 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4527 argv[i]);
4528 break;
4529 }
4530 if (LocaleCompare("flatten",option+1) == 0)
4531 break;
4532 if (LocaleCompare("flip",option+1) == 0)
4533 break;
4534 if (LocaleCompare("flop",option+1) == 0)
4535 break;
4536 if (LocaleCompare("floodfill",option+1) == 0)
4537 {
4538 if (*option == '+')
4539 break;
4540 i++;
cristybb503372010-05-27 20:51:26 +00004541 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004542 ThrowMogrifyException(OptionError,"MissingArgument",option);
4543 if (IsGeometry(argv[i]) == MagickFalse)
4544 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4545 i++;
cristybb503372010-05-27 20:51:26 +00004546 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004547 ThrowMogrifyException(OptionError,"MissingArgument",option);
4548 break;
4549 }
4550 if (LocaleCompare("font",option+1) == 0)
4551 {
4552 if (*option == '+')
4553 break;
4554 i++;
cristybb503372010-05-27 20:51:26 +00004555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004556 ThrowMogrifyException(OptionError,"MissingArgument",option);
4557 break;
4558 }
4559 if (LocaleCompare("format",option+1) == 0)
4560 {
4561 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4562 (void) CloneString(&format,(char *) NULL);
4563 if (*option == '+')
4564 break;
4565 i++;
cristybb503372010-05-27 20:51:26 +00004566 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004567 ThrowMogrifyException(OptionError,"MissingArgument",option);
4568 (void) CloneString(&format,argv[i]);
4569 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4570 (void) ConcatenateMagickString(image_info->filename,":",
4571 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004572 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004573 if (*image_info->magick == '\0')
4574 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4575 format);
4576 break;
4577 }
4578 if (LocaleCompare("frame",option+1) == 0)
4579 {
4580 if (*option == '+')
4581 break;
4582 i++;
cristybb503372010-05-27 20:51:26 +00004583 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004584 ThrowMogrifyException(OptionError,"MissingArgument",option);
4585 if (IsGeometry(argv[i]) == MagickFalse)
4586 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4587 break;
4588 }
4589 if (LocaleCompare("function",option+1) == 0)
4590 {
cristybb503372010-05-27 20:51:26 +00004591 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004592 op;
4593
4594 if (*option == '+')
4595 break;
4596 i++;
cristybb503372010-05-27 20:51:26 +00004597 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004598 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004599 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004600 if (op < 0)
4601 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4602 i++;
cristybb503372010-05-27 20:51:26 +00004603 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004604 ThrowMogrifyException(OptionError,"MissingArgument",option);
4605 break;
4606 }
4607 if (LocaleCompare("fuzz",option+1) == 0)
4608 {
4609 if (*option == '+')
4610 break;
4611 i++;
cristybb503372010-05-27 20:51:26 +00004612 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004613 ThrowMogrifyException(OptionError,"MissingArgument",option);
4614 if (IsGeometry(argv[i]) == MagickFalse)
4615 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4616 break;
4617 }
4618 if (LocaleCompare("fx",option+1) == 0)
4619 {
4620 if (*option == '+')
4621 break;
4622 i++;
cristybb503372010-05-27 20:51:26 +00004623 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004624 ThrowMogrifyException(OptionError,"MissingArgument",option);
4625 break;
4626 }
4627 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4628 }
4629 case 'g':
4630 {
4631 if (LocaleCompare("gamma",option+1) == 0)
4632 {
4633 i++;
cristybb503372010-05-27 20:51:26 +00004634 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004635 ThrowMogrifyException(OptionError,"MissingArgument",option);
4636 if (IsGeometry(argv[i]) == MagickFalse)
4637 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4638 break;
4639 }
4640 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4641 (LocaleCompare("gaussian",option+1) == 0))
4642 {
4643 i++;
cristybb503372010-05-27 20:51:26 +00004644 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004645 ThrowMogrifyException(OptionError,"MissingArgument",option);
4646 if (IsGeometry(argv[i]) == MagickFalse)
4647 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4648 break;
4649 }
4650 if (LocaleCompare("geometry",option+1) == 0)
4651 {
4652 if (*option == '+')
4653 break;
4654 i++;
cristybb503372010-05-27 20:51:26 +00004655 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004656 ThrowMogrifyException(OptionError,"MissingArgument",option);
4657 if (IsGeometry(argv[i]) == MagickFalse)
4658 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4659 break;
4660 }
4661 if (LocaleCompare("gravity",option+1) == 0)
4662 {
cristybb503372010-05-27 20:51:26 +00004663 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004664 gravity;
4665
4666 if (*option == '+')
4667 break;
4668 i++;
cristybb503372010-05-27 20:51:26 +00004669 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004670 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004671 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004672 if (gravity < 0)
4673 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4674 argv[i]);
4675 break;
4676 }
4677 if (LocaleCompare("green-primary",option+1) == 0)
4678 {
4679 if (*option == '+')
4680 break;
4681 i++;
cristybb503372010-05-27 20:51:26 +00004682 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004683 ThrowMogrifyException(OptionError,"MissingArgument",option);
4684 if (IsGeometry(argv[i]) == MagickFalse)
4685 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4686 break;
4687 }
4688 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4689 }
4690 case 'h':
4691 {
4692 if (LocaleCompare("hald-clut",option+1) == 0)
4693 break;
4694 if ((LocaleCompare("help",option+1) == 0) ||
4695 (LocaleCompare("-help",option+1) == 0))
4696 return(MogrifyUsage());
4697 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4698 }
4699 case 'i':
4700 {
4701 if (LocaleCompare("identify",option+1) == 0)
4702 break;
4703 if (LocaleCompare("idft",option+1) == 0)
4704 break;
4705 if (LocaleCompare("implode",option+1) == 0)
4706 {
4707 if (*option == '+')
4708 break;
4709 i++;
cristybb503372010-05-27 20:51:26 +00004710 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004711 ThrowMogrifyException(OptionError,"MissingArgument",option);
4712 if (IsGeometry(argv[i]) == MagickFalse)
4713 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4714 break;
4715 }
4716 if (LocaleCompare("intent",option+1) == 0)
4717 {
cristybb503372010-05-27 20:51:26 +00004718 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004719 intent;
4720
4721 if (*option == '+')
4722 break;
4723 i++;
cristybb503372010-05-27 20:51:26 +00004724 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004725 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004726 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004727 if (intent < 0)
4728 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4729 argv[i]);
4730 break;
4731 }
4732 if (LocaleCompare("interlace",option+1) == 0)
4733 {
cristybb503372010-05-27 20:51:26 +00004734 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004735 interlace;
4736
4737 if (*option == '+')
4738 break;
4739 i++;
cristybb503372010-05-27 20:51:26 +00004740 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004741 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004742 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004743 argv[i]);
4744 if (interlace < 0)
4745 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4746 argv[i]);
4747 break;
4748 }
cristyb32b90a2009-09-07 21:45:48 +00004749 if (LocaleCompare("interline-spacing",option+1) == 0)
4750 {
4751 if (*option == '+')
4752 break;
4753 i++;
cristybb503372010-05-27 20:51:26 +00004754 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004755 ThrowMogrifyException(OptionError,"MissingArgument",option);
4756 if (IsGeometry(argv[i]) == MagickFalse)
4757 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4758 break;
4759 }
cristy3ed852e2009-09-05 21:47:34 +00004760 if (LocaleCompare("interpolate",option+1) == 0)
4761 {
cristybb503372010-05-27 20:51:26 +00004762 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004763 interpolate;
4764
4765 if (*option == '+')
4766 break;
4767 i++;
cristybb503372010-05-27 20:51:26 +00004768 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004769 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004770 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004771 argv[i]);
4772 if (interpolate < 0)
4773 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4774 argv[i]);
4775 break;
4776 }
4777 if (LocaleCompare("interword-spacing",option+1) == 0)
4778 {
4779 if (*option == '+')
4780 break;
4781 i++;
cristybb503372010-05-27 20:51:26 +00004782 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004783 ThrowMogrifyException(OptionError,"MissingArgument",option);
4784 if (IsGeometry(argv[i]) == MagickFalse)
4785 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4786 break;
4787 }
4788 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4789 }
4790 case 'k':
4791 {
4792 if (LocaleCompare("kerning",option+1) == 0)
4793 {
4794 if (*option == '+')
4795 break;
4796 i++;
cristybb503372010-05-27 20:51:26 +00004797 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004798 ThrowMogrifyException(OptionError,"MissingArgument",option);
4799 if (IsGeometry(argv[i]) == MagickFalse)
4800 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4801 break;
4802 }
4803 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4804 }
4805 case 'l':
4806 {
4807 if (LocaleCompare("label",option+1) == 0)
4808 {
4809 if (*option == '+')
4810 break;
4811 i++;
cristybb503372010-05-27 20:51:26 +00004812 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004813 ThrowMogrifyException(OptionError,"MissingArgument",option);
4814 break;
4815 }
4816 if (LocaleCompare("lat",option+1) == 0)
4817 {
4818 if (*option == '+')
4819 break;
4820 i++;
cristybb503372010-05-27 20:51:26 +00004821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004822 ThrowMogrifyException(OptionError,"MissingArgument",option);
4823 if (IsGeometry(argv[i]) == MagickFalse)
4824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4825 }
4826 if (LocaleCompare("layers",option+1) == 0)
4827 {
cristybb503372010-05-27 20:51:26 +00004828 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004829 type;
4830
4831 if (*option == '+')
4832 break;
4833 i++;
cristybb503372010-05-27 20:51:26 +00004834 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004835 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004836 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004837 if (type < 0)
4838 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4839 argv[i]);
4840 break;
4841 }
4842 if (LocaleCompare("level",option+1) == 0)
4843 {
4844 i++;
cristybb503372010-05-27 20:51:26 +00004845 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004846 ThrowMogrifyException(OptionError,"MissingArgument",option);
4847 if (IsGeometry(argv[i]) == MagickFalse)
4848 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4849 break;
4850 }
4851 if (LocaleCompare("level-colors",option+1) == 0)
4852 {
4853 i++;
cristybb503372010-05-27 20:51:26 +00004854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004855 ThrowMogrifyException(OptionError,"MissingArgument",option);
4856 break;
4857 }
4858 if (LocaleCompare("linewidth",option+1) == 0)
4859 {
4860 if (*option == '+')
4861 break;
4862 i++;
cristybb503372010-05-27 20:51:26 +00004863 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004864 ThrowMogrifyException(OptionError,"MissingArgument",option);
4865 if (IsGeometry(argv[i]) == MagickFalse)
4866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4867 break;
4868 }
4869 if (LocaleCompare("limit",option+1) == 0)
4870 {
4871 char
4872 *p;
4873
4874 double
4875 value;
4876
cristybb503372010-05-27 20:51:26 +00004877 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004878 resource;
4879
4880 if (*option == '+')
4881 break;
4882 i++;
cristybb503372010-05-27 20:51:26 +00004883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004884 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004885 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004886 argv[i]);
4887 if (resource < 0)
4888 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4889 argv[i]);
4890 i++;
cristybb503372010-05-27 20:51:26 +00004891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004892 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004893 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004894 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004895 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4896 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4897 break;
4898 }
4899 if (LocaleCompare("liquid-rescale",option+1) == 0)
4900 {
4901 i++;
cristybb503372010-05-27 20:51:26 +00004902 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004903 ThrowMogrifyException(OptionError,"MissingArgument",option);
4904 if (IsGeometry(argv[i]) == MagickFalse)
4905 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4906 break;
4907 }
4908 if (LocaleCompare("list",option+1) == 0)
4909 {
cristybb503372010-05-27 20:51:26 +00004910 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004911 list;
4912
4913 if (*option == '+')
4914 break;
4915 i++;
cristybb503372010-05-27 20:51:26 +00004916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004917 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004918 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004919 if (list < 0)
4920 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004921 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004922 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004923 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004924 }
4925 if (LocaleCompare("log",option+1) == 0)
4926 {
4927 if (*option == '+')
4928 break;
4929 i++;
cristybb503372010-05-27 20:51:26 +00004930 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004931 (strchr(argv[i],'%') == (char *) NULL))
4932 ThrowMogrifyException(OptionError,"MissingArgument",option);
4933 break;
4934 }
4935 if (LocaleCompare("loop",option+1) == 0)
4936 {
4937 if (*option == '+')
4938 break;
4939 i++;
cristybb503372010-05-27 20:51:26 +00004940 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004941 ThrowMogrifyException(OptionError,"MissingArgument",option);
4942 if (IsGeometry(argv[i]) == MagickFalse)
4943 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4944 break;
4945 }
4946 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4947 }
4948 case 'm':
4949 {
4950 if (LocaleCompare("map",option+1) == 0)
4951 {
4952 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
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 break;
4959 }
4960 if (LocaleCompare("mask",option+1) == 0)
4961 {
4962 if (*option == '+')
4963 break;
4964 i++;
cristybb503372010-05-27 20:51:26 +00004965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004966 ThrowMogrifyException(OptionError,"MissingArgument",option);
4967 break;
4968 }
4969 if (LocaleCompare("matte",option+1) == 0)
4970 break;
4971 if (LocaleCompare("mattecolor",option+1) == 0)
4972 {
4973 if (*option == '+')
4974 break;
4975 i++;
cristybb503372010-05-27 20:51:26 +00004976 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004977 ThrowMogrifyException(OptionError,"MissingArgument",option);
4978 break;
4979 }
cristyf40785b2010-03-06 02:27:27 +00004980 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004981 break;
cristyf40785b2010-03-06 02:27:27 +00004982 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004983 break;
cristy3ed852e2009-09-05 21:47:34 +00004984 if (LocaleCompare("modulate",option+1) == 0)
4985 {
4986 if (*option == '+')
4987 break;
4988 i++;
cristybb503372010-05-27 20:51:26 +00004989 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004990 ThrowMogrifyException(OptionError,"MissingArgument",option);
4991 if (IsGeometry(argv[i]) == MagickFalse)
4992 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4993 break;
4994 }
4995 if (LocaleCompare("median",option+1) == 0)
4996 {
4997 if (*option == '+')
4998 break;
4999 i++;
cristybb503372010-05-27 20:51:26 +00005000 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005001 ThrowMogrifyException(OptionError,"MissingArgument",option);
5002 if (IsGeometry(argv[i]) == MagickFalse)
5003 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5004 break;
5005 }
cristy69ec32d2011-02-27 23:57:09 +00005006 if (LocaleCompare("mode",option+1) == 0)
5007 {
5008 if (*option == '+')
5009 break;
5010 i++;
5011 if (i == (ssize_t) argc)
5012 ThrowMogrifyException(OptionError,"MissingArgument",option);
5013 if (IsGeometry(argv[i]) == MagickFalse)
5014 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5015 break;
5016 }
cristy3ed852e2009-09-05 21:47:34 +00005017 if (LocaleCompare("monitor",option+1) == 0)
5018 break;
5019 if (LocaleCompare("monochrome",option+1) == 0)
5020 break;
5021 if (LocaleCompare("morph",option+1) == 0)
5022 {
5023 if (*option == '+')
5024 break;
5025 i++;
cristybb503372010-05-27 20:51:26 +00005026 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005027 ThrowMogrifyException(OptionError,"MissingArgument",option);
5028 if (IsGeometry(argv[i]) == MagickFalse)
5029 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5030 break;
5031 }
anthony29188a82010-01-22 10:12:34 +00005032 if (LocaleCompare("morphology",option+1) == 0)
5033 {
anthony29188a82010-01-22 10:12:34 +00005034 char
5035 token[MaxTextExtent];
5036
cristyb6bd4ad2010-08-08 01:12:27 +00005037 KernelInfo
5038 *kernel_info;
5039
5040 ssize_t
5041 op;
5042
anthony29188a82010-01-22 10:12:34 +00005043 i++;
cristybb503372010-05-27 20:51:26 +00005044 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005045 ThrowMogrifyException(OptionError,"MissingArgument",option);
5046 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005047 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005048 if (op < 0)
5049 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005050 token);
anthony29188a82010-01-22 10:12:34 +00005051 i++;
cristybb503372010-05-27 20:51:26 +00005052 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005053 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005054 kernel_info=AcquireKernelInfo(argv[i]);
5055 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005056 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005057 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005058 break;
5059 }
cristy3ed852e2009-09-05 21:47:34 +00005060 if (LocaleCompare("mosaic",option+1) == 0)
5061 break;
5062 if (LocaleCompare("motion-blur",option+1) == 0)
5063 {
5064 if (*option == '+')
5065 break;
5066 i++;
cristybb503372010-05-27 20:51:26 +00005067 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005068 ThrowMogrifyException(OptionError,"MissingArgument",option);
5069 if (IsGeometry(argv[i]) == MagickFalse)
5070 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5071 break;
5072 }
5073 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5074 }
5075 case 'n':
5076 {
5077 if (LocaleCompare("negate",option+1) == 0)
5078 break;
5079 if (LocaleCompare("noise",option+1) == 0)
5080 {
5081 i++;
cristybb503372010-05-27 20:51:26 +00005082 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005083 ThrowMogrifyException(OptionError,"MissingArgument",option);
5084 if (*option == '+')
5085 {
cristybb503372010-05-27 20:51:26 +00005086 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005087 noise;
5088
cristy042ee782011-04-22 18:48:30 +00005089 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005090 if (noise < 0)
5091 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5092 argv[i]);
5093 break;
5094 }
5095 if (IsGeometry(argv[i]) == MagickFalse)
5096 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5097 break;
5098 }
5099 if (LocaleCompare("noop",option+1) == 0)
5100 break;
5101 if (LocaleCompare("normalize",option+1) == 0)
5102 break;
5103 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5104 }
5105 case 'o':
5106 {
5107 if (LocaleCompare("opaque",option+1) == 0)
5108 {
cristy3ed852e2009-09-05 21:47:34 +00005109 i++;
cristybb503372010-05-27 20:51:26 +00005110 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005111 ThrowMogrifyException(OptionError,"MissingArgument",option);
5112 break;
5113 }
5114 if (LocaleCompare("ordered-dither",option+1) == 0)
5115 {
5116 if (*option == '+')
5117 break;
5118 i++;
cristybb503372010-05-27 20:51:26 +00005119 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005120 ThrowMogrifyException(OptionError,"MissingArgument",option);
5121 break;
5122 }
5123 if (LocaleCompare("orient",option+1) == 0)
5124 {
cristybb503372010-05-27 20:51:26 +00005125 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005126 orientation;
5127
5128 orientation=UndefinedOrientation;
5129 if (*option == '+')
5130 break;
5131 i++;
cristybb503372010-05-27 20:51:26 +00005132 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005133 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005134 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005135 argv[i]);
5136 if (orientation < 0)
5137 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5138 argv[i]);
5139 break;
5140 }
5141 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5142 }
5143 case 'p':
5144 {
5145 if (LocaleCompare("page",option+1) == 0)
5146 {
5147 if (*option == '+')
5148 break;
5149 i++;
cristybb503372010-05-27 20:51:26 +00005150 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005151 ThrowMogrifyException(OptionError,"MissingArgument",option);
5152 break;
5153 }
5154 if (LocaleCompare("paint",option+1) == 0)
5155 {
5156 if (*option == '+')
5157 break;
5158 i++;
cristybb503372010-05-27 20:51:26 +00005159 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005160 ThrowMogrifyException(OptionError,"MissingArgument",option);
5161 if (IsGeometry(argv[i]) == MagickFalse)
5162 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5163 break;
5164 }
5165 if (LocaleCompare("path",option+1) == 0)
5166 {
5167 (void) CloneString(&path,(char *) NULL);
5168 if (*option == '+')
5169 break;
5170 i++;
cristybb503372010-05-27 20:51:26 +00005171 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005172 ThrowMogrifyException(OptionError,"MissingArgument",option);
5173 (void) CloneString(&path,argv[i]);
5174 break;
5175 }
5176 if (LocaleCompare("pointsize",option+1) == 0)
5177 {
5178 if (*option == '+')
5179 break;
5180 i++;
cristybb503372010-05-27 20:51:26 +00005181 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005182 ThrowMogrifyException(OptionError,"MissingArgument",option);
5183 if (IsGeometry(argv[i]) == MagickFalse)
5184 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5185 break;
5186 }
5187 if (LocaleCompare("polaroid",option+1) == 0)
5188 {
5189 if (*option == '+')
5190 break;
5191 i++;
cristybb503372010-05-27 20:51:26 +00005192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005193 ThrowMogrifyException(OptionError,"MissingArgument",option);
5194 if (IsGeometry(argv[i]) == MagickFalse)
5195 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5196 break;
5197 }
5198 if (LocaleCompare("posterize",option+1) == 0)
5199 {
5200 if (*option == '+')
5201 break;
5202 i++;
cristybb503372010-05-27 20:51:26 +00005203 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005204 ThrowMogrifyException(OptionError,"MissingArgument",option);
5205 if (IsGeometry(argv[i]) == MagickFalse)
5206 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5207 break;
5208 }
cristye7f51092010-01-17 00:39:37 +00005209 if (LocaleCompare("precision",option+1) == 0)
5210 {
5211 if (*option == '+')
5212 break;
5213 i++;
cristybb503372010-05-27 20:51:26 +00005214 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005215 ThrowMogrifyException(OptionError,"MissingArgument",option);
5216 if (IsGeometry(argv[i]) == MagickFalse)
5217 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5218 break;
5219 }
cristy3ed852e2009-09-05 21:47:34 +00005220 if (LocaleCompare("print",option+1) == 0)
5221 {
5222 if (*option == '+')
5223 break;
5224 i++;
cristybb503372010-05-27 20:51:26 +00005225 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005226 ThrowMogrifyException(OptionError,"MissingArgument",option);
5227 break;
5228 }
5229 if (LocaleCompare("process",option+1) == 0)
5230 {
5231 if (*option == '+')
5232 break;
5233 i++;
cristybb503372010-05-27 20:51:26 +00005234 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005235 ThrowMogrifyException(OptionError,"MissingArgument",option);
5236 break;
5237 }
5238 if (LocaleCompare("profile",option+1) == 0)
5239 {
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 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5246 }
5247 case 'q':
5248 {
5249 if (LocaleCompare("quality",option+1) == 0)
5250 {
5251 if (*option == '+')
5252 break;
5253 i++;
cristybb503372010-05-27 20:51:26 +00005254 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005255 ThrowMogrifyException(OptionError,"MissingArgument",option);
5256 if (IsGeometry(argv[i]) == MagickFalse)
5257 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5258 break;
5259 }
5260 if (LocaleCompare("quantize",option+1) == 0)
5261 {
cristybb503372010-05-27 20:51:26 +00005262 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005263 colorspace;
5264
5265 if (*option == '+')
5266 break;
5267 i++;
cristybb503372010-05-27 20:51:26 +00005268 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005269 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005270 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005271 argv[i]);
5272 if (colorspace < 0)
5273 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5274 argv[i]);
5275 break;
5276 }
5277 if (LocaleCompare("quiet",option+1) == 0)
5278 break;
5279 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5280 }
5281 case 'r':
5282 {
5283 if (LocaleCompare("radial-blur",option+1) == 0)
5284 {
5285 i++;
cristybb503372010-05-27 20:51:26 +00005286 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005287 ThrowMogrifyException(OptionError,"MissingArgument",option);
5288 if (IsGeometry(argv[i]) == MagickFalse)
5289 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5290 break;
5291 }
5292 if (LocaleCompare("raise",option+1) == 0)
5293 {
5294 i++;
cristybb503372010-05-27 20:51:26 +00005295 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005296 ThrowMogrifyException(OptionError,"MissingArgument",option);
5297 if (IsGeometry(argv[i]) == MagickFalse)
5298 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5299 break;
5300 }
5301 if (LocaleCompare("random-threshold",option+1) == 0)
5302 {
5303 if (*option == '+')
5304 break;
5305 i++;
cristybb503372010-05-27 20:51:26 +00005306 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005307 ThrowMogrifyException(OptionError,"MissingArgument",option);
5308 if (IsGeometry(argv[i]) == MagickFalse)
5309 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5310 break;
5311 }
cristye6365592010-04-02 17:31:23 +00005312 if (LocaleCompare("recolor",option+1) == 0)
5313 {
5314 if (*option == '+')
5315 break;
5316 i++;
cristybb503372010-05-27 20:51:26 +00005317 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005318 ThrowMogrifyException(OptionError,"MissingArgument",option);
5319 if (IsGeometry(argv[i]) == MagickFalse)
5320 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5321 break;
5322 }
cristy3ed852e2009-09-05 21:47:34 +00005323 if (LocaleCompare("red-primary",option+1) == 0)
5324 {
5325 if (*option == '+')
5326 break;
5327 i++;
cristybb503372010-05-27 20:51:26 +00005328 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005329 ThrowMogrifyException(OptionError,"MissingArgument",option);
5330 if (IsGeometry(argv[i]) == MagickFalse)
5331 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5332 }
cristy9f2083a2010-04-22 19:48:05 +00005333 if (LocaleCompare("regard-warnings",option+1) == 0)
5334 break;
cristy3ed852e2009-09-05 21:47:34 +00005335 if (LocaleCompare("region",option+1) == 0)
5336 {
5337 if (*option == '+')
5338 break;
5339 i++;
cristybb503372010-05-27 20:51:26 +00005340 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005341 ThrowMogrifyException(OptionError,"MissingArgument",option);
5342 if (IsGeometry(argv[i]) == MagickFalse)
5343 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5344 break;
5345 }
cristyf0c78232010-03-15 12:53:40 +00005346 if (LocaleCompare("remap",option+1) == 0)
5347 {
5348 if (*option == '+')
5349 break;
5350 i++;
cristybb503372010-05-27 20:51:26 +00005351 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005352 ThrowMogrifyException(OptionError,"MissingArgument",option);
5353 break;
5354 }
cristy3ed852e2009-09-05 21:47:34 +00005355 if (LocaleCompare("render",option+1) == 0)
5356 break;
5357 if (LocaleCompare("repage",option+1) == 0)
5358 {
5359 if (*option == '+')
5360 break;
5361 i++;
cristybb503372010-05-27 20:51:26 +00005362 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005363 ThrowMogrifyException(OptionError,"MissingArgument",option);
5364 if (IsGeometry(argv[i]) == MagickFalse)
5365 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5366 break;
5367 }
5368 if (LocaleCompare("resample",option+1) == 0)
5369 {
5370 if (*option == '+')
5371 break;
5372 i++;
cristybb503372010-05-27 20:51:26 +00005373 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005374 ThrowMogrifyException(OptionError,"MissingArgument",option);
5375 if (IsGeometry(argv[i]) == MagickFalse)
5376 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5377 break;
5378 }
5379 if (LocaleCompare("resize",option+1) == 0)
5380 {
5381 if (*option == '+')
5382 break;
5383 i++;
cristybb503372010-05-27 20:51:26 +00005384 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005385 ThrowMogrifyException(OptionError,"MissingArgument",option);
5386 if (IsGeometry(argv[i]) == MagickFalse)
5387 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5388 break;
5389 }
cristyebbcfea2011-02-25 02:43:54 +00005390 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5391 {
5392 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5393 break;
5394 }
cristy3ed852e2009-09-05 21:47:34 +00005395 if (LocaleCompare("reverse",option+1) == 0)
5396 break;
5397 if (LocaleCompare("roll",option+1) == 0)
5398 {
5399 if (*option == '+')
5400 break;
5401 i++;
cristybb503372010-05-27 20:51:26 +00005402 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005403 ThrowMogrifyException(OptionError,"MissingArgument",option);
5404 if (IsGeometry(argv[i]) == MagickFalse)
5405 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5406 break;
5407 }
5408 if (LocaleCompare("rotate",option+1) == 0)
5409 {
5410 i++;
cristybb503372010-05-27 20:51:26 +00005411 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005412 ThrowMogrifyException(OptionError,"MissingArgument",option);
5413 if (IsGeometry(argv[i]) == MagickFalse)
5414 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5415 break;
5416 }
5417 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5418 }
5419 case 's':
5420 {
5421 if (LocaleCompare("sample",option+1) == 0)
5422 {
5423 if (*option == '+')
5424 break;
5425 i++;
cristybb503372010-05-27 20:51:26 +00005426 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005427 ThrowMogrifyException(OptionError,"MissingArgument",option);
5428 if (IsGeometry(argv[i]) == MagickFalse)
5429 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5430 break;
5431 }
5432 if (LocaleCompare("sampling-factor",option+1) == 0)
5433 {
5434 if (*option == '+')
5435 break;
5436 i++;
cristybb503372010-05-27 20:51:26 +00005437 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005438 ThrowMogrifyException(OptionError,"MissingArgument",option);
5439 if (IsGeometry(argv[i]) == MagickFalse)
5440 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5441 break;
5442 }
5443 if (LocaleCompare("scale",option+1) == 0)
5444 {
5445 if (*option == '+')
5446 break;
5447 i++;
cristybb503372010-05-27 20:51:26 +00005448 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005449 ThrowMogrifyException(OptionError,"MissingArgument",option);
5450 if (IsGeometry(argv[i]) == MagickFalse)
5451 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5452 break;
5453 }
5454 if (LocaleCompare("scene",option+1) == 0)
5455 {
5456 if (*option == '+')
5457 break;
5458 i++;
cristybb503372010-05-27 20:51:26 +00005459 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005460 ThrowMogrifyException(OptionError,"MissingArgument",option);
5461 if (IsGeometry(argv[i]) == MagickFalse)
5462 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5463 break;
5464 }
5465 if (LocaleCompare("seed",option+1) == 0)
5466 {
5467 if (*option == '+')
5468 break;
5469 i++;
cristybb503372010-05-27 20:51:26 +00005470 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005471 ThrowMogrifyException(OptionError,"MissingArgument",option);
5472 if (IsGeometry(argv[i]) == MagickFalse)
5473 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5474 break;
5475 }
5476 if (LocaleCompare("segment",option+1) == 0)
5477 {
5478 if (*option == '+')
5479 break;
5480 i++;
cristybb503372010-05-27 20:51:26 +00005481 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005482 ThrowMogrifyException(OptionError,"MissingArgument",option);
5483 if (IsGeometry(argv[i]) == MagickFalse)
5484 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5485 break;
5486 }
5487 if (LocaleCompare("selective-blur",option+1) == 0)
5488 {
5489 i++;
cristybb503372010-05-27 20:51:26 +00005490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005491 ThrowMogrifyException(OptionError,"MissingArgument",option);
5492 if (IsGeometry(argv[i]) == MagickFalse)
5493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5494 break;
5495 }
5496 if (LocaleCompare("separate",option+1) == 0)
5497 break;
5498 if (LocaleCompare("sepia-tone",option+1) == 0)
5499 {
5500 if (*option == '+')
5501 break;
5502 i++;
cristybb503372010-05-27 20:51:26 +00005503 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005504 ThrowMogrifyException(OptionError,"MissingArgument",option);
5505 if (IsGeometry(argv[i]) == MagickFalse)
5506 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5507 break;
5508 }
5509 if (LocaleCompare("set",option+1) == 0)
5510 {
5511 i++;
cristybb503372010-05-27 20:51:26 +00005512 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005513 ThrowMogrifyException(OptionError,"MissingArgument",option);
5514 if (*option == '+')
5515 break;
5516 i++;
cristybb503372010-05-27 20:51:26 +00005517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005518 ThrowMogrifyException(OptionError,"MissingArgument",option);
5519 break;
5520 }
5521 if (LocaleCompare("shade",option+1) == 0)
5522 {
5523 i++;
cristybb503372010-05-27 20:51:26 +00005524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005525 ThrowMogrifyException(OptionError,"MissingArgument",option);
5526 if (IsGeometry(argv[i]) == MagickFalse)
5527 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5528 break;
5529 }
5530 if (LocaleCompare("shadow",option+1) == 0)
5531 {
5532 if (*option == '+')
5533 break;
5534 i++;
cristybb503372010-05-27 20:51:26 +00005535 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005536 ThrowMogrifyException(OptionError,"MissingArgument",option);
5537 if (IsGeometry(argv[i]) == MagickFalse)
5538 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5539 break;
5540 }
5541 if (LocaleCompare("sharpen",option+1) == 0)
5542 {
5543 i++;
cristybb503372010-05-27 20:51:26 +00005544 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005545 ThrowMogrifyException(OptionError,"MissingArgument",option);
5546 if (IsGeometry(argv[i]) == MagickFalse)
5547 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5548 break;
5549 }
5550 if (LocaleCompare("shave",option+1) == 0)
5551 {
5552 if (*option == '+')
5553 break;
5554 i++;
cristybb503372010-05-27 20:51:26 +00005555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005556 ThrowMogrifyException(OptionError,"MissingArgument",option);
5557 if (IsGeometry(argv[i]) == MagickFalse)
5558 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5559 break;
5560 }
5561 if (LocaleCompare("shear",option+1) == 0)
5562 {
5563 i++;
cristybb503372010-05-27 20:51:26 +00005564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005565 ThrowMogrifyException(OptionError,"MissingArgument",option);
5566 if (IsGeometry(argv[i]) == MagickFalse)
5567 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5568 break;
5569 }
5570 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5571 {
5572 i++;
cristybb503372010-05-27 20:51:26 +00005573 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005574 ThrowMogrifyException(OptionError,"MissingArgument",option);
5575 if (IsGeometry(argv[i]) == MagickFalse)
5576 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5577 break;
5578 }
5579 if (LocaleCompare("size",option+1) == 0)
5580 {
5581 if (*option == '+')
5582 break;
5583 i++;
cristybb503372010-05-27 20:51:26 +00005584 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005585 ThrowMogrifyException(OptionError,"MissingArgument",option);
5586 if (IsGeometry(argv[i]) == MagickFalse)
5587 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5588 break;
5589 }
5590 if (LocaleCompare("sketch",option+1) == 0)
5591 {
5592 if (*option == '+')
5593 break;
5594 i++;
cristybb503372010-05-27 20:51:26 +00005595 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005596 ThrowMogrifyException(OptionError,"MissingArgument",option);
5597 if (IsGeometry(argv[i]) == MagickFalse)
5598 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5599 break;
5600 }
cristy4285d782011-02-09 20:12:28 +00005601 if (LocaleCompare("smush",option+1) == 0)
5602 {
cristy4285d782011-02-09 20:12:28 +00005603 i++;
5604 if (i == (ssize_t) argc)
5605 ThrowMogrifyException(OptionError,"MissingArgument",option);
5606 if (IsGeometry(argv[i]) == MagickFalse)
5607 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005608 i++;
5609 break;
5610 }
cristy3ed852e2009-09-05 21:47:34 +00005611 if (LocaleCompare("solarize",option+1) == 0)
5612 {
5613 if (*option == '+')
5614 break;
5615 i++;
cristybb503372010-05-27 20:51:26 +00005616 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005617 ThrowMogrifyException(OptionError,"MissingArgument",option);
5618 if (IsGeometry(argv[i]) == MagickFalse)
5619 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5620 break;
5621 }
5622 if (LocaleCompare("sparse-color",option+1) == 0)
5623 {
cristybb503372010-05-27 20:51:26 +00005624 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005625 op;
5626
5627 i++;
cristybb503372010-05-27 20:51:26 +00005628 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005629 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005630 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005631 if (op < 0)
5632 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5633 argv[i]);
5634 i++;
cristybb503372010-05-27 20:51:26 +00005635 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005636 ThrowMogrifyException(OptionError,"MissingArgument",option);
5637 break;
5638 }
5639 if (LocaleCompare("spread",option+1) == 0)
5640 {
5641 if (*option == '+')
5642 break;
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);
5646 if (IsGeometry(argv[i]) == MagickFalse)
5647 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5648 break;
5649 }
cristy0834d642011-03-18 18:26:08 +00005650 if (LocaleCompare("statistic",option+1) == 0)
5651 {
5652 ssize_t
5653 op;
5654
5655 if (*option == '+')
5656 break;
5657 i++;
5658 if (i == (ssize_t) argc)
5659 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005660 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005661 if (op < 0)
5662 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5663 argv[i]);
5664 i++;
5665 if (i == (ssize_t) (argc-1))
5666 ThrowMogrifyException(OptionError,"MissingArgument",option);
5667 if (IsGeometry(argv[i]) == MagickFalse)
5668 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5669 break;
5670 }
cristy3ed852e2009-09-05 21:47:34 +00005671 if (LocaleCompare("stretch",option+1) == 0)
5672 {
cristybb503372010-05-27 20:51:26 +00005673 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005674 stretch;
5675
5676 if (*option == '+')
5677 break;
5678 i++;
cristybb503372010-05-27 20:51:26 +00005679 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005680 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005681 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005682 if (stretch < 0)
5683 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5684 argv[i]);
5685 break;
5686 }
5687 if (LocaleCompare("strip",option+1) == 0)
5688 break;
5689 if (LocaleCompare("stroke",option+1) == 0)
5690 {
5691 if (*option == '+')
5692 break;
5693 i++;
cristybb503372010-05-27 20:51:26 +00005694 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005695 ThrowMogrifyException(OptionError,"MissingArgument",option);
5696 break;
5697 }
5698 if (LocaleCompare("strokewidth",option+1) == 0)
5699 {
5700 if (*option == '+')
5701 break;
5702 i++;
cristybb503372010-05-27 20:51:26 +00005703 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005704 ThrowMogrifyException(OptionError,"MissingArgument",option);
5705 if (IsGeometry(argv[i]) == MagickFalse)
5706 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5707 break;
5708 }
5709 if (LocaleCompare("style",option+1) == 0)
5710 {
cristybb503372010-05-27 20:51:26 +00005711 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005712 style;
5713
5714 if (*option == '+')
5715 break;
5716 i++;
cristybb503372010-05-27 20:51:26 +00005717 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005718 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005719 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005720 if (style < 0)
5721 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5722 argv[i]);
5723 break;
5724 }
cristyecb10ff2011-03-22 13:14:03 +00005725 if (LocaleCompare("swap",option+1) == 0)
5726 {
5727 if (*option == '+')
5728 break;
5729 i++;
5730 if (i == (ssize_t) (argc-1))
5731 ThrowMogrifyException(OptionError,"MissingArgument",option);
5732 if (IsGeometry(argv[i]) == MagickFalse)
5733 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5734 break;
5735 }
cristy3ed852e2009-09-05 21:47:34 +00005736 if (LocaleCompare("swirl",option+1) == 0)
5737 {
5738 if (*option == '+')
5739 break;
5740 i++;
cristybb503372010-05-27 20:51:26 +00005741 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005742 ThrowMogrifyException(OptionError,"MissingArgument",option);
5743 if (IsGeometry(argv[i]) == MagickFalse)
5744 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5745 break;
5746 }
cristyd9a29192010-10-16 16:49:53 +00005747 if (LocaleCompare("synchronize",option+1) == 0)
5748 break;
cristy3ed852e2009-09-05 21:47:34 +00005749 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5750 }
5751 case 't':
5752 {
5753 if (LocaleCompare("taint",option+1) == 0)
5754 break;
5755 if (LocaleCompare("texture",option+1) == 0)
5756 {
5757 if (*option == '+')
5758 break;
5759 i++;
cristybb503372010-05-27 20:51:26 +00005760 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005761 ThrowMogrifyException(OptionError,"MissingArgument",option);
5762 break;
5763 }
5764 if (LocaleCompare("tile",option+1) == 0)
5765 {
5766 if (*option == '+')
5767 break;
5768 i++;
cristybb503372010-05-27 20:51:26 +00005769 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005770 ThrowMogrifyException(OptionError,"MissingArgument",option);
5771 break;
5772 }
5773 if (LocaleCompare("tile-offset",option+1) == 0)
5774 {
5775 if (*option == '+')
5776 break;
5777 i++;
cristybb503372010-05-27 20:51:26 +00005778 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005779 ThrowMogrifyException(OptionError,"MissingArgument",option);
5780 if (IsGeometry(argv[i]) == MagickFalse)
5781 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5782 break;
5783 }
5784 if (LocaleCompare("tint",option+1) == 0)
5785 {
5786 if (*option == '+')
5787 break;
5788 i++;
cristybb503372010-05-27 20:51:26 +00005789 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005790 ThrowMogrifyException(OptionError,"MissingArgument",option);
5791 if (IsGeometry(argv[i]) == MagickFalse)
5792 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5793 break;
5794 }
5795 if (LocaleCompare("transform",option+1) == 0)
5796 break;
5797 if (LocaleCompare("transpose",option+1) == 0)
5798 break;
5799 if (LocaleCompare("transverse",option+1) == 0)
5800 break;
5801 if (LocaleCompare("threshold",option+1) == 0)
5802 {
5803 if (*option == '+')
5804 break;
5805 i++;
cristybb503372010-05-27 20:51:26 +00005806 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005807 ThrowMogrifyException(OptionError,"MissingArgument",option);
5808 if (IsGeometry(argv[i]) == MagickFalse)
5809 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5810 break;
5811 }
5812 if (LocaleCompare("thumbnail",option+1) == 0)
5813 {
5814 if (*option == '+')
5815 break;
5816 i++;
cristybb503372010-05-27 20:51:26 +00005817 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005818 ThrowMogrifyException(OptionError,"MissingArgument",option);
5819 if (IsGeometry(argv[i]) == MagickFalse)
5820 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5821 break;
5822 }
5823 if (LocaleCompare("transparent",option+1) == 0)
5824 {
5825 i++;
cristybb503372010-05-27 20:51:26 +00005826 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005827 ThrowMogrifyException(OptionError,"MissingArgument",option);
5828 break;
5829 }
5830 if (LocaleCompare("transparent-color",option+1) == 0)
5831 {
5832 if (*option == '+')
5833 break;
5834 i++;
cristybb503372010-05-27 20:51:26 +00005835 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005836 ThrowMogrifyException(OptionError,"MissingArgument",option);
5837 break;
5838 }
5839 if (LocaleCompare("treedepth",option+1) == 0)
5840 {
5841 if (*option == '+')
5842 break;
5843 i++;
cristybb503372010-05-27 20:51:26 +00005844 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005845 ThrowMogrifyException(OptionError,"MissingArgument",option);
5846 if (IsGeometry(argv[i]) == MagickFalse)
5847 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5848 break;
5849 }
5850 if (LocaleCompare("trim",option+1) == 0)
5851 break;
5852 if (LocaleCompare("type",option+1) == 0)
5853 {
cristybb503372010-05-27 20:51:26 +00005854 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005855 type;
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);
cristy042ee782011-04-22 18:48:30 +00005862 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005863 if (type < 0)
5864 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5865 argv[i]);
5866 break;
5867 }
5868 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5869 }
5870 case 'u':
5871 {
5872 if (LocaleCompare("undercolor",option+1) == 0)
5873 {
5874 if (*option == '+')
5875 break;
5876 i++;
cristybb503372010-05-27 20:51:26 +00005877 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005878 ThrowMogrifyException(OptionError,"MissingArgument",option);
5879 break;
5880 }
5881 if (LocaleCompare("unique-colors",option+1) == 0)
5882 break;
5883 if (LocaleCompare("units",option+1) == 0)
5884 {
cristybb503372010-05-27 20:51:26 +00005885 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005886 units;
5887
5888 if (*option == '+')
5889 break;
5890 i++;
cristybb503372010-05-27 20:51:26 +00005891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005892 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005893 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005894 argv[i]);
5895 if (units < 0)
5896 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5897 argv[i]);
5898 break;
5899 }
5900 if (LocaleCompare("unsharp",option+1) == 0)
5901 {
5902 i++;
cristybb503372010-05-27 20:51:26 +00005903 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005904 ThrowMogrifyException(OptionError,"MissingArgument",option);
5905 if (IsGeometry(argv[i]) == MagickFalse)
5906 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5907 break;
5908 }
5909 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5910 }
5911 case 'v':
5912 {
5913 if (LocaleCompare("verbose",option+1) == 0)
5914 {
5915 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5916 break;
5917 }
5918 if ((LocaleCompare("version",option+1) == 0) ||
5919 (LocaleCompare("-version",option+1) == 0))
5920 {
cristyb51dff52011-05-19 16:55:47 +00005921 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005922 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005923 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5924 GetMagickCopyright());
5925 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5926 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005927 break;
5928 }
5929 if (LocaleCompare("view",option+1) == 0)
5930 {
5931 if (*option == '+')
5932 break;
5933 i++;
cristybb503372010-05-27 20:51:26 +00005934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005935 ThrowMogrifyException(OptionError,"MissingArgument",option);
5936 break;
5937 }
5938 if (LocaleCompare("vignette",option+1) == 0)
5939 {
5940 if (*option == '+')
5941 break;
5942 i++;
cristybb503372010-05-27 20:51:26 +00005943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005944 ThrowMogrifyException(OptionError,"MissingArgument",option);
5945 if (IsGeometry(argv[i]) == MagickFalse)
5946 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5947 break;
5948 }
5949 if (LocaleCompare("virtual-pixel",option+1) == 0)
5950 {
cristybb503372010-05-27 20:51:26 +00005951 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005952 method;
5953
5954 if (*option == '+')
5955 break;
5956 i++;
cristybb503372010-05-27 20:51:26 +00005957 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005958 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005959 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005960 argv[i]);
5961 if (method < 0)
5962 ThrowMogrifyException(OptionError,
5963 "UnrecognizedVirtualPixelMethod",argv[i]);
5964 break;
5965 }
5966 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5967 }
5968 case 'w':
5969 {
5970 if (LocaleCompare("wave",option+1) == 0)
5971 {
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);
5975 if (IsGeometry(argv[i]) == MagickFalse)
5976 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5977 break;
5978 }
5979 if (LocaleCompare("weight",option+1) == 0)
5980 {
5981 if (*option == '+')
5982 break;
5983 i++;
cristybb503372010-05-27 20:51:26 +00005984 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005985 ThrowMogrifyException(OptionError,"MissingArgument",option);
5986 break;
5987 }
5988 if (LocaleCompare("white-point",option+1) == 0)
5989 {
5990 if (*option == '+')
5991 break;
5992 i++;
cristybb503372010-05-27 20:51:26 +00005993 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005994 ThrowMogrifyException(OptionError,"MissingArgument",option);
5995 if (IsGeometry(argv[i]) == MagickFalse)
5996 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5997 break;
5998 }
5999 if (LocaleCompare("white-threshold",option+1) == 0)
6000 {
6001 if (*option == '+')
6002 break;
6003 i++;
cristybb503372010-05-27 20:51:26 +00006004 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006005 ThrowMogrifyException(OptionError,"MissingArgument",option);
6006 if (IsGeometry(argv[i]) == MagickFalse)
6007 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6008 break;
6009 }
6010 if (LocaleCompare("write",option+1) == 0)
6011 {
6012 i++;
cristybb503372010-05-27 20:51:26 +00006013 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006014 ThrowMogrifyException(OptionError,"MissingArgument",option);
6015 break;
6016 }
6017 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6018 }
6019 case '?':
6020 break;
6021 default:
6022 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6023 }
cristy042ee782011-04-22 18:48:30 +00006024 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6025 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006026 if (fire != MagickFalse)
6027 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6028 }
6029 if (k != 0)
6030 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006031 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006032 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6033 DestroyMogrify();
6034 return(status != 0 ? MagickTrue : MagickFalse);
6035}
6036
6037/*
6038%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6039% %
6040% %
6041% %
6042+ M o g r i f y I m a g e I n f o %
6043% %
6044% %
6045% %
6046%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6047%
6048% MogrifyImageInfo() applies image processing settings to the image as
6049% prescribed by command line options.
6050%
6051% The format of the MogrifyImageInfo method is:
6052%
6053% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6054% const char **argv,ExceptionInfo *exception)
6055%
6056% A description of each parameter follows:
6057%
6058% o image_info: the image info..
6059%
6060% o argc: Specifies a pointer to an integer describing the number of
6061% elements in the argument vector.
6062%
6063% o argv: Specifies a pointer to a text array containing the command line
6064% arguments.
6065%
6066% o exception: return any errors or warnings in this structure.
6067%
6068*/
6069WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6070 const int argc,const char **argv,ExceptionInfo *exception)
6071{
6072 const char
6073 *option;
6074
6075 GeometryInfo
6076 geometry_info;
6077
cristybb503372010-05-27 20:51:26 +00006078 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006079 count;
6080
cristybb503372010-05-27 20:51:26 +00006081 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006082 i;
6083
6084 /*
6085 Initialize method variables.
6086 */
6087 assert(image_info != (ImageInfo *) NULL);
6088 assert(image_info->signature == MagickSignature);
6089 if (image_info->debug != MagickFalse)
6090 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6091 image_info->filename);
6092 if (argc < 0)
6093 return(MagickTrue);
6094 /*
6095 Set the image settings.
6096 */
cristybb503372010-05-27 20:51:26 +00006097 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006098 {
6099 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006100 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006101 continue;
cristy042ee782011-04-22 18:48:30 +00006102 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006103 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006104 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006105 break;
6106 switch (*(option+1))
6107 {
6108 case 'a':
6109 {
6110 if (LocaleCompare("adjoin",option+1) == 0)
6111 {
6112 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6113 break;
6114 }
6115 if (LocaleCompare("antialias",option+1) == 0)
6116 {
6117 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6118 break;
6119 }
6120 if (LocaleCompare("attenuate",option+1) == 0)
6121 {
6122 if (*option == '+')
6123 {
6124 (void) DeleteImageOption(image_info,option+1);
6125 break;
6126 }
6127 (void) SetImageOption(image_info,option+1,argv[i+1]);
6128 break;
6129 }
6130 if (LocaleCompare("authenticate",option+1) == 0)
6131 {
6132 if (*option == '+')
6133 (void) CloneString(&image_info->authenticate,(char *) NULL);
6134 else
6135 (void) CloneString(&image_info->authenticate,argv[i+1]);
6136 break;
6137 }
6138 break;
6139 }
6140 case 'b':
6141 {
6142 if (LocaleCompare("background",option+1) == 0)
6143 {
6144 if (*option == '+')
6145 {
6146 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006147 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006148 &image_info->background_color,exception);
6149 break;
6150 }
6151 (void) SetImageOption(image_info,option+1,argv[i+1]);
6152 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6153 exception);
6154 break;
6155 }
6156 if (LocaleCompare("bias",option+1) == 0)
6157 {
6158 if (*option == '+')
6159 {
6160 (void) SetImageOption(image_info,option+1,"0.0");
6161 break;
6162 }
6163 (void) SetImageOption(image_info,option+1,argv[i+1]);
6164 break;
6165 }
6166 if (LocaleCompare("black-point-compensation",option+1) == 0)
6167 {
6168 if (*option == '+')
6169 {
6170 (void) SetImageOption(image_info,option+1,"false");
6171 break;
6172 }
6173 (void) SetImageOption(image_info,option+1,"true");
6174 break;
6175 }
6176 if (LocaleCompare("blue-primary",option+1) == 0)
6177 {
6178 if (*option == '+')
6179 {
6180 (void) SetImageOption(image_info,option+1,"0.0");
6181 break;
6182 }
6183 (void) SetImageOption(image_info,option+1,argv[i+1]);
6184 break;
6185 }
6186 if (LocaleCompare("bordercolor",option+1) == 0)
6187 {
6188 if (*option == '+')
6189 {
6190 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006191 (void) QueryColorDatabase(MogrifyBorderColor,
6192 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006193 break;
6194 }
6195 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6196 exception);
6197 (void) SetImageOption(image_info,option+1,argv[i+1]);
6198 break;
6199 }
6200 if (LocaleCompare("box",option+1) == 0)
6201 {
6202 if (*option == '+')
6203 {
6204 (void) SetImageOption(image_info,"undercolor","none");
6205 break;
6206 }
6207 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6208 break;
6209 }
6210 break;
6211 }
6212 case 'c':
6213 {
6214 if (LocaleCompare("cache",option+1) == 0)
6215 {
6216 MagickSizeType
6217 limit;
6218
6219 limit=MagickResourceInfinity;
6220 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006221 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006222 (void) SetMagickResourceLimit(MemoryResource,limit);
6223 (void) SetMagickResourceLimit(MapResource,2*limit);
6224 break;
6225 }
6226 if (LocaleCompare("caption",option+1) == 0)
6227 {
6228 if (*option == '+')
6229 {
6230 (void) DeleteImageOption(image_info,option+1);
6231 break;
6232 }
6233 (void) SetImageOption(image_info,option+1,argv[i+1]);
6234 break;
6235 }
6236 if (LocaleCompare("channel",option+1) == 0)
6237 {
6238 if (*option == '+')
6239 {
6240 image_info->channel=DefaultChannels;
6241 break;
6242 }
6243 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6244 break;
6245 }
6246 if (LocaleCompare("colors",option+1) == 0)
6247 {
cristye27293e2009-12-18 02:53:20 +00006248 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006249 break;
6250 }
6251 if (LocaleCompare("colorspace",option+1) == 0)
6252 {
6253 if (*option == '+')
6254 {
6255 image_info->colorspace=UndefinedColorspace;
6256 (void) SetImageOption(image_info,option+1,"undefined");
6257 break;
6258 }
cristy042ee782011-04-22 18:48:30 +00006259 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006260 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6261 (void) SetImageOption(image_info,option+1,argv[i+1]);
6262 break;
6263 }
cristy3ed852e2009-09-05 21:47:34 +00006264 if (LocaleCompare("comment",option+1) == 0)
6265 {
6266 if (*option == '+')
6267 {
6268 (void) DeleteImageOption(image_info,option+1);
6269 break;
6270 }
6271 (void) SetImageOption(image_info,option+1,argv[i+1]);
6272 break;
6273 }
6274 if (LocaleCompare("compose",option+1) == 0)
6275 {
6276 if (*option == '+')
6277 {
6278 (void) SetImageOption(image_info,option+1,"undefined");
6279 break;
6280 }
6281 (void) SetImageOption(image_info,option+1,argv[i+1]);
6282 break;
6283 }
6284 if (LocaleCompare("compress",option+1) == 0)
6285 {
6286 if (*option == '+')
6287 {
6288 image_info->compression=UndefinedCompression;
6289 (void) SetImageOption(image_info,option+1,"undefined");
6290 break;
6291 }
cristy042ee782011-04-22 18:48:30 +00006292 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006293 MagickCompressOptions,MagickFalse,argv[i+1]);
6294 (void) SetImageOption(image_info,option+1,argv[i+1]);
6295 break;
6296 }
6297 break;
6298 }
6299 case 'd':
6300 {
6301 if (LocaleCompare("debug",option+1) == 0)
6302 {
6303 if (*option == '+')
6304 (void) SetLogEventMask("none");
6305 else
6306 (void) SetLogEventMask(argv[i+1]);
6307 image_info->debug=IsEventLogging();
6308 break;
6309 }
6310 if (LocaleCompare("define",option+1) == 0)
6311 {
6312 if (*option == '+')
6313 {
6314 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6315 (void) DeleteImageRegistry(argv[i+1]+9);
6316 else
6317 (void) DeleteImageOption(image_info,argv[i+1]);
6318 break;
6319 }
6320 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6321 {
6322 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6323 exception);
6324 break;
6325 }
6326 (void) DefineImageOption(image_info,argv[i+1]);
6327 break;
6328 }
6329 if (LocaleCompare("delay",option+1) == 0)
6330 {
6331 if (*option == '+')
6332 {
6333 (void) SetImageOption(image_info,option+1,"0");
6334 break;
6335 }
6336 (void) SetImageOption(image_info,option+1,argv[i+1]);
6337 break;
6338 }
6339 if (LocaleCompare("density",option+1) == 0)
6340 {
6341 /*
6342 Set image density.
6343 */
6344 if (*option == '+')
6345 {
6346 if (image_info->density != (char *) NULL)
6347 image_info->density=DestroyString(image_info->density);
6348 (void) SetImageOption(image_info,option+1,"72");
6349 break;
6350 }
6351 (void) CloneString(&image_info->density,argv[i+1]);
6352 (void) SetImageOption(image_info,option+1,argv[i+1]);
6353 break;
6354 }
6355 if (LocaleCompare("depth",option+1) == 0)
6356 {
6357 if (*option == '+')
6358 {
6359 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6360 break;
6361 }
cristye27293e2009-12-18 02:53:20 +00006362 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006363 break;
6364 }
cristyc9b12952010-03-28 01:12:28 +00006365 if (LocaleCompare("direction",option+1) == 0)
6366 {
6367 if (*option == '+')
6368 {
6369 (void) SetImageOption(image_info,option+1,"undefined");
6370 break;
6371 }
6372 (void) SetImageOption(image_info,option+1,argv[i+1]);
6373 break;
6374 }
cristy3ed852e2009-09-05 21:47:34 +00006375 if (LocaleCompare("display",option+1) == 0)
6376 {
6377 if (*option == '+')
6378 {
6379 if (image_info->server_name != (char *) NULL)
6380 image_info->server_name=DestroyString(
6381 image_info->server_name);
6382 break;
6383 }
6384 (void) CloneString(&image_info->server_name,argv[i+1]);
6385 break;
6386 }
6387 if (LocaleCompare("dispose",option+1) == 0)
6388 {
6389 if (*option == '+')
6390 {
6391 (void) SetImageOption(image_info,option+1,"undefined");
6392 break;
6393 }
6394 (void) SetImageOption(image_info,option+1,argv[i+1]);
6395 break;
6396 }
6397 if (LocaleCompare("dither",option+1) == 0)
6398 {
6399 if (*option == '+')
6400 {
6401 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006402 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006403 break;
6404 }
6405 (void) SetImageOption(image_info,option+1,argv[i+1]);
6406 image_info->dither=MagickTrue;
6407 break;
6408 }
6409 break;
6410 }
6411 case 'e':
6412 {
6413 if (LocaleCompare("encoding",option+1) == 0)
6414 {
6415 if (*option == '+')
6416 {
6417 (void) SetImageOption(image_info,option+1,"undefined");
6418 break;
6419 }
6420 (void) SetImageOption(image_info,option+1,argv[i+1]);
6421 break;
6422 }
6423 if (LocaleCompare("endian",option+1) == 0)
6424 {
6425 if (*option == '+')
6426 {
6427 image_info->endian=UndefinedEndian;
6428 (void) SetImageOption(image_info,option+1,"undefined");
6429 break;
6430 }
cristy042ee782011-04-22 18:48:30 +00006431 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006432 MagickEndianOptions,MagickFalse,argv[i+1]);
6433 (void) SetImageOption(image_info,option+1,argv[i+1]);
6434 break;
6435 }
6436 if (LocaleCompare("extract",option+1) == 0)
6437 {
6438 /*
6439 Set image extract geometry.
6440 */
6441 if (*option == '+')
6442 {
6443 if (image_info->extract != (char *) NULL)
6444 image_info->extract=DestroyString(image_info->extract);
6445 break;
6446 }
6447 (void) CloneString(&image_info->extract,argv[i+1]);
6448 break;
6449 }
6450 break;
6451 }
6452 case 'f':
6453 {
6454 if (LocaleCompare("fill",option+1) == 0)
6455 {
6456 if (*option == '+')
6457 {
6458 (void) SetImageOption(image_info,option+1,"none");
6459 break;
6460 }
6461 (void) SetImageOption(image_info,option+1,argv[i+1]);
6462 break;
6463 }
6464 if (LocaleCompare("filter",option+1) == 0)
6465 {
6466 if (*option == '+')
6467 {
6468 (void) SetImageOption(image_info,option+1,"undefined");
6469 break;
6470 }
6471 (void) SetImageOption(image_info,option+1,argv[i+1]);
6472 break;
6473 }
6474 if (LocaleCompare("font",option+1) == 0)
6475 {
6476 if (*option == '+')
6477 {
6478 if (image_info->font != (char *) NULL)
6479 image_info->font=DestroyString(image_info->font);
6480 break;
6481 }
6482 (void) CloneString(&image_info->font,argv[i+1]);
6483 break;
6484 }
6485 if (LocaleCompare("format",option+1) == 0)
6486 {
6487 register const char
6488 *q;
6489
6490 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006491 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006492 image_info->ping=MagickFalse;
6493 (void) SetImageOption(image_info,option+1,argv[i+1]);
6494 break;
6495 }
6496 if (LocaleCompare("fuzz",option+1) == 0)
6497 {
6498 if (*option == '+')
6499 {
6500 image_info->fuzz=0.0;
6501 (void) SetImageOption(image_info,option+1,"0");
6502 break;
6503 }
cristyf2f27272009-12-17 14:48:46 +00006504 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006505 1.0);
6506 (void) SetImageOption(image_info,option+1,argv[i+1]);
6507 break;
6508 }
6509 break;
6510 }
6511 case 'g':
6512 {
6513 if (LocaleCompare("gravity",option+1) == 0)
6514 {
6515 if (*option == '+')
6516 {
6517 (void) SetImageOption(image_info,option+1,"undefined");
6518 break;
6519 }
6520 (void) SetImageOption(image_info,option+1,argv[i+1]);
6521 break;
6522 }
6523 if (LocaleCompare("green-primary",option+1) == 0)
6524 {
6525 if (*option == '+')
6526 {
6527 (void) SetImageOption(image_info,option+1,"0.0");
6528 break;
6529 }
6530 (void) SetImageOption(image_info,option+1,argv[i+1]);
6531 break;
6532 }
6533 break;
6534 }
6535 case 'i':
6536 {
6537 if (LocaleCompare("intent",option+1) == 0)
6538 {
6539 if (*option == '+')
6540 {
6541 (void) SetImageOption(image_info,option+1,"undefined");
6542 break;
6543 }
6544 (void) SetImageOption(image_info,option+1,argv[i+1]);
6545 break;
6546 }
6547 if (LocaleCompare("interlace",option+1) == 0)
6548 {
6549 if (*option == '+')
6550 {
6551 image_info->interlace=UndefinedInterlace;
6552 (void) SetImageOption(image_info,option+1,"undefined");
6553 break;
6554 }
cristy042ee782011-04-22 18:48:30 +00006555 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006556 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6557 (void) SetImageOption(image_info,option+1,argv[i+1]);
6558 break;
6559 }
cristyb32b90a2009-09-07 21:45:48 +00006560 if (LocaleCompare("interline-spacing",option+1) == 0)
6561 {
6562 if (*option == '+')
6563 {
6564 (void) SetImageOption(image_info,option+1,"undefined");
6565 break;
6566 }
6567 (void) SetImageOption(image_info,option+1,argv[i+1]);
6568 break;
6569 }
cristy3ed852e2009-09-05 21:47:34 +00006570 if (LocaleCompare("interpolate",option+1) == 0)
6571 {
6572 if (*option == '+')
6573 {
6574 (void) SetImageOption(image_info,option+1,"undefined");
6575 break;
6576 }
6577 (void) SetImageOption(image_info,option+1,argv[i+1]);
6578 break;
6579 }
6580 if (LocaleCompare("interword-spacing",option+1) == 0)
6581 {
6582 if (*option == '+')
6583 {
6584 (void) SetImageOption(image_info,option+1,"undefined");
6585 break;
6586 }
6587 (void) SetImageOption(image_info,option+1,argv[i+1]);
6588 break;
6589 }
6590 break;
6591 }
6592 case 'k':
6593 {
6594 if (LocaleCompare("kerning",option+1) == 0)
6595 {
6596 if (*option == '+')
6597 {
6598 (void) SetImageOption(image_info,option+1,"undefined");
6599 break;
6600 }
6601 (void) SetImageOption(image_info,option+1,argv[i+1]);
6602 break;
6603 }
6604 break;
6605 }
6606 case 'l':
6607 {
6608 if (LocaleCompare("label",option+1) == 0)
6609 {
6610 if (*option == '+')
6611 {
6612 (void) DeleteImageOption(image_info,option+1);
6613 break;
6614 }
6615 (void) SetImageOption(image_info,option+1,argv[i+1]);
6616 break;
6617 }
6618 if (LocaleCompare("limit",option+1) == 0)
6619 {
6620 MagickSizeType
6621 limit;
6622
6623 ResourceType
6624 type;
6625
6626 if (*option == '+')
6627 break;
cristy042ee782011-04-22 18:48:30 +00006628 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006629 MagickFalse,argv[i+1]);
6630 limit=MagickResourceInfinity;
6631 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006632 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006633 (void) SetMagickResourceLimit(type,limit);
6634 break;
6635 }
6636 if (LocaleCompare("list",option+1) == 0)
6637 {
cristybb503372010-05-27 20:51:26 +00006638 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006639 list;
6640
6641 /*
6642 Display configuration list.
6643 */
cristy042ee782011-04-22 18:48:30 +00006644 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006645 switch (list)
6646 {
6647 case MagickCoderOptions:
6648 {
6649 (void) ListCoderInfo((FILE *) NULL,exception);
6650 break;
6651 }
6652 case MagickColorOptions:
6653 {
6654 (void) ListColorInfo((FILE *) NULL,exception);
6655 break;
6656 }
6657 case MagickConfigureOptions:
6658 {
6659 (void) ListConfigureInfo((FILE *) NULL,exception);
6660 break;
6661 }
6662 case MagickDelegateOptions:
6663 {
6664 (void) ListDelegateInfo((FILE *) NULL,exception);
6665 break;
6666 }
6667 case MagickFontOptions:
6668 {
6669 (void) ListTypeInfo((FILE *) NULL,exception);
6670 break;
6671 }
6672 case MagickFormatOptions:
6673 {
6674 (void) ListMagickInfo((FILE *) NULL,exception);
6675 break;
6676 }
6677 case MagickLocaleOptions:
6678 {
6679 (void) ListLocaleInfo((FILE *) NULL,exception);
6680 break;
6681 }
6682 case MagickLogOptions:
6683 {
6684 (void) ListLogInfo((FILE *) NULL,exception);
6685 break;
6686 }
6687 case MagickMagicOptions:
6688 {
6689 (void) ListMagicInfo((FILE *) NULL,exception);
6690 break;
6691 }
6692 case MagickMimeOptions:
6693 {
6694 (void) ListMimeInfo((FILE *) NULL,exception);
6695 break;
6696 }
6697 case MagickModuleOptions:
6698 {
6699 (void) ListModuleInfo((FILE *) NULL,exception);
6700 break;
6701 }
6702 case MagickPolicyOptions:
6703 {
6704 (void) ListPolicyInfo((FILE *) NULL,exception);
6705 break;
6706 }
6707 case MagickResourceOptions:
6708 {
6709 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6710 break;
6711 }
6712 case MagickThresholdOptions:
6713 {
6714 (void) ListThresholdMaps((FILE *) NULL,exception);
6715 break;
6716 }
6717 default:
6718 {
cristy042ee782011-04-22 18:48:30 +00006719 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006720 exception);
6721 break;
6722 }
6723 }
cristyaeb2cbc2010-05-07 13:28:58 +00006724 break;
cristy3ed852e2009-09-05 21:47:34 +00006725 }
6726 if (LocaleCompare("log",option+1) == 0)
6727 {
6728 if (*option == '+')
6729 break;
6730 (void) SetLogFormat(argv[i+1]);
6731 break;
6732 }
6733 if (LocaleCompare("loop",option+1) == 0)
6734 {
6735 if (*option == '+')
6736 {
6737 (void) SetImageOption(image_info,option+1,"0");
6738 break;
6739 }
6740 (void) SetImageOption(image_info,option+1,argv[i+1]);
6741 break;
6742 }
6743 break;
6744 }
6745 case 'm':
6746 {
6747 if (LocaleCompare("matte",option+1) == 0)
6748 {
6749 if (*option == '+')
6750 {
6751 (void) SetImageOption(image_info,option+1,"false");
6752 break;
6753 }
6754 (void) SetImageOption(image_info,option+1,"true");
6755 break;
6756 }
6757 if (LocaleCompare("mattecolor",option+1) == 0)
6758 {
6759 if (*option == '+')
6760 {
6761 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006762 (void) QueryColorDatabase(MogrifyMatteColor,
6763 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006764 break;
6765 }
6766 (void) SetImageOption(image_info,option+1,argv[i+1]);
6767 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6768 exception);
6769 break;
6770 }
6771 if (LocaleCompare("monitor",option+1) == 0)
6772 {
6773 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6774 (void *) NULL);
6775 break;
6776 }
6777 if (LocaleCompare("monochrome",option+1) == 0)
6778 {
6779 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6780 break;
6781 }
6782 break;
6783 }
6784 case 'o':
6785 {
6786 if (LocaleCompare("orient",option+1) == 0)
6787 {
6788 if (*option == '+')
6789 {
6790 image_info->orientation=UndefinedOrientation;
6791 (void) SetImageOption(image_info,option+1,"undefined");
6792 break;
6793 }
cristy042ee782011-04-22 18:48:30 +00006794 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006795 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006796 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006797 break;
6798 }
6799 }
6800 case 'p':
6801 {
6802 if (LocaleCompare("page",option+1) == 0)
6803 {
6804 char
6805 *canonical_page,
6806 page[MaxTextExtent];
6807
6808 const char
6809 *image_option;
6810
6811 MagickStatusType
6812 flags;
6813
6814 RectangleInfo
6815 geometry;
6816
6817 if (*option == '+')
6818 {
6819 (void) DeleteImageOption(image_info,option+1);
6820 (void) CloneString(&image_info->page,(char *) NULL);
6821 break;
6822 }
6823 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6824 image_option=GetImageOption(image_info,"page");
6825 if (image_option != (const char *) NULL)
6826 flags=ParseAbsoluteGeometry(image_option,&geometry);
6827 canonical_page=GetPageGeometry(argv[i+1]);
6828 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6829 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006830 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006831 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006832 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006833 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006834 (unsigned long) geometry.width,(unsigned long) geometry.height,
6835 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006836 (void) SetImageOption(image_info,option+1,page);
6837 (void) CloneString(&image_info->page,page);
6838 break;
6839 }
6840 if (LocaleCompare("pen",option+1) == 0)
6841 {
6842 if (*option == '+')
6843 {
6844 (void) SetImageOption(image_info,option+1,"none");
6845 break;
6846 }
6847 (void) SetImageOption(image_info,option+1,argv[i+1]);
6848 break;
6849 }
6850 if (LocaleCompare("ping",option+1) == 0)
6851 {
6852 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6853 break;
6854 }
6855 if (LocaleCompare("pointsize",option+1) == 0)
6856 {
6857 if (*option == '+')
6858 geometry_info.rho=0.0;
6859 else
6860 (void) ParseGeometry(argv[i+1],&geometry_info);
6861 image_info->pointsize=geometry_info.rho;
6862 break;
6863 }
cristye7f51092010-01-17 00:39:37 +00006864 if (LocaleCompare("precision",option+1) == 0)
6865 {
cristybf2766a2010-01-17 03:33:23 +00006866 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006867 break;
6868 }
cristy3ed852e2009-09-05 21:47:34 +00006869 if (LocaleCompare("preview",option+1) == 0)
6870 {
6871 /*
6872 Preview image.
6873 */
6874 if (*option == '+')
6875 {
6876 image_info->preview_type=UndefinedPreview;
6877 break;
6878 }
cristy042ee782011-04-22 18:48:30 +00006879 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006880 MagickPreviewOptions,MagickFalse,argv[i+1]);
6881 break;
6882 }
6883 break;
6884 }
6885 case 'q':
6886 {
6887 if (LocaleCompare("quality",option+1) == 0)
6888 {
6889 /*
6890 Set image compression quality.
6891 */
6892 if (*option == '+')
6893 {
6894 image_info->quality=UndefinedCompressionQuality;
6895 (void) SetImageOption(image_info,option+1,"0");
6896 break;
6897 }
cristye27293e2009-12-18 02:53:20 +00006898 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006899 (void) SetImageOption(image_info,option+1,argv[i+1]);
6900 break;
6901 }
6902 if (LocaleCompare("quiet",option+1) == 0)
6903 {
6904 static WarningHandler
6905 warning_handler = (WarningHandler) NULL;
6906
6907 if (*option == '+')
6908 {
6909 /*
6910 Restore error or warning messages.
6911 */
6912 warning_handler=SetWarningHandler(warning_handler);
6913 break;
6914 }
6915 /*
6916 Suppress error or warning messages.
6917 */
6918 warning_handler=SetWarningHandler((WarningHandler) NULL);
6919 break;
6920 }
6921 break;
6922 }
6923 case 'r':
6924 {
6925 if (LocaleCompare("red-primary",option+1) == 0)
6926 {
6927 if (*option == '+')
6928 {
6929 (void) SetImageOption(image_info,option+1,"0.0");
6930 break;
6931 }
6932 (void) SetImageOption(image_info,option+1,argv[i+1]);
6933 break;
6934 }
6935 break;
6936 }
6937 case 's':
6938 {
6939 if (LocaleCompare("sampling-factor",option+1) == 0)
6940 {
6941 /*
6942 Set image sampling factor.
6943 */
6944 if (*option == '+')
6945 {
6946 if (image_info->sampling_factor != (char *) NULL)
6947 image_info->sampling_factor=DestroyString(
6948 image_info->sampling_factor);
6949 break;
6950 }
6951 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6952 break;
6953 }
6954 if (LocaleCompare("scene",option+1) == 0)
6955 {
6956 /*
6957 Set image scene.
6958 */
6959 if (*option == '+')
6960 {
6961 image_info->scene=0;
6962 (void) SetImageOption(image_info,option+1,"0");
6963 break;
6964 }
cristye27293e2009-12-18 02:53:20 +00006965 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006966 (void) SetImageOption(image_info,option+1,argv[i+1]);
6967 break;
6968 }
6969 if (LocaleCompare("seed",option+1) == 0)
6970 {
cristybb503372010-05-27 20:51:26 +00006971 size_t
cristy3ed852e2009-09-05 21:47:34 +00006972 seed;
6973
6974 if (*option == '+')
6975 {
cristybb503372010-05-27 20:51:26 +00006976 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006977 SeedPseudoRandomGenerator(seed);
6978 break;
6979 }
cristye27293e2009-12-18 02:53:20 +00006980 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006981 SeedPseudoRandomGenerator(seed);
6982 break;
6983 }
6984 if (LocaleCompare("size",option+1) == 0)
6985 {
6986 if (*option == '+')
6987 {
6988 if (image_info->size != (char *) NULL)
6989 image_info->size=DestroyString(image_info->size);
6990 break;
6991 }
6992 (void) CloneString(&image_info->size,argv[i+1]);
6993 break;
6994 }
6995 if (LocaleCompare("stroke",option+1) == 0)
6996 {
6997 if (*option == '+')
6998 {
6999 (void) SetImageOption(image_info,option+1,"none");
7000 break;
7001 }
7002 (void) SetImageOption(image_info,option+1,argv[i+1]);
7003 break;
7004 }
7005 if (LocaleCompare("strokewidth",option+1) == 0)
7006 {
7007 if (*option == '+')
7008 {
7009 (void) SetImageOption(image_info,option+1,"0");
7010 break;
7011 }
7012 (void) SetImageOption(image_info,option+1,argv[i+1]);
7013 break;
7014 }
cristyd9a29192010-10-16 16:49:53 +00007015 if (LocaleCompare("synchronize",option+1) == 0)
7016 {
7017 if (*option == '+')
7018 {
7019 image_info->synchronize=MagickFalse;
7020 break;
7021 }
7022 image_info->synchronize=MagickTrue;
7023 break;
7024 }
cristy3ed852e2009-09-05 21:47:34 +00007025 break;
7026 }
7027 case 't':
7028 {
7029 if (LocaleCompare("taint",option+1) == 0)
7030 {
7031 if (*option == '+')
7032 {
7033 (void) SetImageOption(image_info,option+1,"false");
7034 break;
7035 }
7036 (void) SetImageOption(image_info,option+1,"true");
7037 break;
7038 }
7039 if (LocaleCompare("texture",option+1) == 0)
7040 {
7041 if (*option == '+')
7042 {
7043 if (image_info->texture != (char *) NULL)
7044 image_info->texture=DestroyString(image_info->texture);
7045 break;
7046 }
7047 (void) CloneString(&image_info->texture,argv[i+1]);
7048 break;
7049 }
7050 if (LocaleCompare("tile-offset",option+1) == 0)
7051 {
7052 if (*option == '+')
7053 {
7054 (void) SetImageOption(image_info,option+1,"0");
7055 break;
7056 }
7057 (void) SetImageOption(image_info,option+1,argv[i+1]);
7058 break;
7059 }
7060 if (LocaleCompare("transparent-color",option+1) == 0)
7061 {
7062 if (*option == '+')
7063 {
7064 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7065 (void) SetImageOption(image_info,option+1,"none");
7066 break;
7067 }
7068 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7069 exception);
7070 (void) SetImageOption(image_info,option+1,argv[i+1]);
7071 break;
7072 }
7073 if (LocaleCompare("type",option+1) == 0)
7074 {
7075 if (*option == '+')
7076 {
cristy5f1c1ff2010-12-23 21:38:06 +00007077 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007078 (void) SetImageOption(image_info,option+1,"undefined");
7079 break;
7080 }
cristy042ee782011-04-22 18:48:30 +00007081 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007082 MagickFalse,argv[i+1]);
7083 (void) SetImageOption(image_info,option+1,argv[i+1]);
7084 break;
7085 }
7086 break;
7087 }
7088 case 'u':
7089 {
7090 if (LocaleCompare("undercolor",option+1) == 0)
7091 {
7092 if (*option == '+')
7093 {
7094 (void) DeleteImageOption(image_info,option+1);
7095 break;
7096 }
7097 (void) SetImageOption(image_info,option+1,argv[i+1]);
7098 break;
7099 }
7100 if (LocaleCompare("units",option+1) == 0)
7101 {
7102 if (*option == '+')
7103 {
7104 image_info->units=UndefinedResolution;
7105 (void) SetImageOption(image_info,option+1,"undefined");
7106 break;
7107 }
cristy042ee782011-04-22 18:48:30 +00007108 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007109 MagickResolutionOptions,MagickFalse,argv[i+1]);
7110 (void) SetImageOption(image_info,option+1,argv[i+1]);
7111 break;
7112 }
7113 break;
7114 }
7115 case 'v':
7116 {
7117 if (LocaleCompare("verbose",option+1) == 0)
7118 {
7119 if (*option == '+')
7120 {
7121 image_info->verbose=MagickFalse;
7122 break;
7123 }
7124 image_info->verbose=MagickTrue;
7125 image_info->ping=MagickFalse;
7126 break;
7127 }
7128 if (LocaleCompare("view",option+1) == 0)
7129 {
7130 if (*option == '+')
7131 {
7132 if (image_info->view != (char *) NULL)
7133 image_info->view=DestroyString(image_info->view);
7134 break;
7135 }
7136 (void) CloneString(&image_info->view,argv[i+1]);
7137 break;
7138 }
7139 if (LocaleCompare("virtual-pixel",option+1) == 0)
7140 {
7141 if (*option == '+')
7142 {
7143 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7144 (void) SetImageOption(image_info,option+1,"undefined");
7145 break;
7146 }
7147 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007148 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007149 argv[i+1]);
7150 (void) SetImageOption(image_info,option+1,argv[i+1]);
7151 break;
7152 }
7153 break;
7154 }
7155 case 'w':
7156 {
7157 if (LocaleCompare("white-point",option+1) == 0)
7158 {
7159 if (*option == '+')
7160 {
7161 (void) SetImageOption(image_info,option+1,"0.0");
7162 break;
7163 }
7164 (void) SetImageOption(image_info,option+1,argv[i+1]);
7165 break;
7166 }
7167 break;
7168 }
7169 default:
7170 break;
7171 }
7172 i+=count;
7173 }
7174 return(MagickTrue);
7175}
7176
7177/*
7178%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7179% %
7180% %
7181% %
7182+ M o g r i f y I m a g e L i s t %
7183% %
7184% %
7185% %
7186%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7187%
7188% MogrifyImageList() applies any command line options that might affect the
7189% entire image list (e.g. -append, -coalesce, etc.).
7190%
7191% The format of the MogrifyImage method is:
7192%
7193% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7194% const char **argv,Image **images,ExceptionInfo *exception)
7195%
7196% A description of each parameter follows:
7197%
7198% o image_info: the image info..
7199%
7200% o argc: Specifies a pointer to an integer describing the number of
7201% elements in the argument vector.
7202%
7203% o argv: Specifies a pointer to a text array containing the command line
7204% arguments.
7205%
anthonye9c27192011-03-27 08:07:06 +00007206% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007207%
7208% o exception: return any errors or warnings in this structure.
7209%
7210*/
7211WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7212 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7213{
cristy3ed852e2009-09-05 21:47:34 +00007214 const char
7215 *option;
7216
cristy6b3da3a2010-06-20 02:21:46 +00007217 ImageInfo
7218 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007219
7220 MagickStatusType
7221 status;
7222
7223 QuantizeInfo
7224 *quantize_info;
7225
cristybb503372010-05-27 20:51:26 +00007226 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007227 i;
7228
cristy6b3da3a2010-06-20 02:21:46 +00007229 ssize_t
7230 count,
7231 index;
7232
cristy3ed852e2009-09-05 21:47:34 +00007233 /*
7234 Apply options to the image list.
7235 */
7236 assert(image_info != (ImageInfo *) NULL);
7237 assert(image_info->signature == MagickSignature);
7238 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007239 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007240 assert((*images)->signature == MagickSignature);
7241 if ((*images)->debug != MagickFalse)
7242 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7243 (*images)->filename);
7244 if ((argc <= 0) || (*argv == (char *) NULL))
7245 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007246 mogrify_info=CloneImageInfo(image_info);
7247 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007248 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007249 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007250 {
cristy74fe8f12009-10-03 19:09:01 +00007251 if (*images == (Image *) NULL)
7252 break;
cristy3ed852e2009-09-05 21:47:34 +00007253 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007254 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007255 continue;
cristy042ee782011-04-22 18:48:30 +00007256 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007257 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007258 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007259 break;
cristy6b3da3a2010-06-20 02:21:46 +00007260 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007261 switch (*(option+1))
7262 {
7263 case 'a':
7264 {
7265 if (LocaleCompare("affinity",option+1) == 0)
7266 {
cristy6b3da3a2010-06-20 02:21:46 +00007267 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007268 if (*option == '+')
7269 {
cristy018f07f2011-09-04 21:15:19 +00007270 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7271 exception);
cristy3ed852e2009-09-05 21:47:34 +00007272 break;
7273 }
7274 i++;
7275 break;
7276 }
7277 if (LocaleCompare("append",option+1) == 0)
7278 {
7279 Image
7280 *append_image;
7281
cristy6b3da3a2010-06-20 02:21:46 +00007282 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007283 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7284 MagickFalse,exception);
7285 if (append_image == (Image *) NULL)
7286 {
7287 status=MagickFalse;
7288 break;
7289 }
7290 *images=DestroyImageList(*images);
7291 *images=append_image;
7292 break;
7293 }
7294 if (LocaleCompare("average",option+1) == 0)
7295 {
7296 Image
7297 *average_image;
7298
cristyd18ae7c2010-03-07 17:39:52 +00007299 /*
7300 Average an image sequence (deprecated).
7301 */
cristy6b3da3a2010-06-20 02:21:46 +00007302 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007303 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7304 exception);
cristy3ed852e2009-09-05 21:47:34 +00007305 if (average_image == (Image *) NULL)
7306 {
7307 status=MagickFalse;
7308 break;
7309 }
7310 *images=DestroyImageList(*images);
7311 *images=average_image;
7312 break;
7313 }
7314 break;
7315 }
7316 case 'c':
7317 {
7318 if (LocaleCompare("channel",option+1) == 0)
7319 {
cristyf4ad9df2011-07-08 16:49:03 +00007320 ChannelType
7321 channel;
7322
cristy3ed852e2009-09-05 21:47:34 +00007323 if (*option == '+')
7324 {
7325 channel=DefaultChannels;
7326 break;
7327 }
7328 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007329 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007330 break;
7331 }
7332 if (LocaleCompare("clut",option+1) == 0)
7333 {
7334 Image
7335 *clut_image,
7336 *image;
7337
cristy6b3da3a2010-06-20 02:21:46 +00007338 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007339 image=RemoveFirstImageFromList(images);
7340 clut_image=RemoveFirstImageFromList(images);
7341 if (clut_image == (Image *) NULL)
7342 {
7343 status=MagickFalse;
7344 break;
7345 }
cristy444eda62011-08-10 02:07:46 +00007346 (void) ClutImage(image,clut_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007347 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007348 *images=DestroyImageList(*images);
7349 *images=image;
7350 break;
7351 }
7352 if (LocaleCompare("coalesce",option+1) == 0)
7353 {
7354 Image
7355 *coalesce_image;
7356
cristy6b3da3a2010-06-20 02:21:46 +00007357 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007358 coalesce_image=CoalesceImages(*images,exception);
7359 if (coalesce_image == (Image *) NULL)
7360 {
7361 status=MagickFalse;
7362 break;
7363 }
7364 *images=DestroyImageList(*images);
7365 *images=coalesce_image;
7366 break;
7367 }
7368 if (LocaleCompare("combine",option+1) == 0)
7369 {
7370 Image
7371 *combine_image;
7372
cristy6b3da3a2010-06-20 02:21:46 +00007373 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007374 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007375 if (combine_image == (Image *) NULL)
7376 {
7377 status=MagickFalse;
7378 break;
7379 }
7380 *images=DestroyImageList(*images);
7381 *images=combine_image;
7382 break;
7383 }
7384 if (LocaleCompare("composite",option+1) == 0)
7385 {
7386 Image
7387 *mask_image,
7388 *composite_image,
7389 *image;
7390
7391 RectangleInfo
7392 geometry;
7393
cristy6b3da3a2010-06-20 02:21:46 +00007394 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007395 image=RemoveFirstImageFromList(images);
7396 composite_image=RemoveFirstImageFromList(images);
7397 if (composite_image == (Image *) NULL)
7398 {
7399 status=MagickFalse;
7400 break;
7401 }
7402 (void) TransformImage(&composite_image,(char *) NULL,
7403 composite_image->geometry);
7404 SetGeometry(composite_image,&geometry);
7405 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7406 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7407 &geometry);
7408 mask_image=RemoveFirstImageFromList(images);
7409 if (mask_image != (Image *) NULL)
7410 {
7411 if ((image->compose == DisplaceCompositeOp) ||
7412 (image->compose == DistortCompositeOp))
7413 {
7414 /*
7415 Merge Y displacement into X displacement image.
7416 */
7417 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7418 mask_image,0,0);
7419 mask_image=DestroyImage(mask_image);
7420 }
7421 else
7422 {
7423 /*
7424 Set a blending mask for the composition.
7425 */
anthonya129f702011-04-14 01:08:48 +00007426 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007427 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007428 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007429 }
7430 }
cristyf4ad9df2011-07-08 16:49:03 +00007431 (void) CompositeImage(image,image->compose,composite_image,
7432 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007433 if (mask_image != (Image *) NULL)
7434 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007435 composite_image=DestroyImage(composite_image);
7436 InheritException(exception,&image->exception);
7437 *images=DestroyImageList(*images);
7438 *images=image;
7439 break;
7440 }
anthony9f4f0342011-03-28 11:47:22 +00007441#if 0
7442This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007443 if (LocaleCompare("crop",option+1) == 0)
7444 {
7445 MagickStatusType
7446 flags;
7447
7448 RectangleInfo
7449 geometry;
7450
anthonye9c27192011-03-27 08:07:06 +00007451 /*
anthony9f4f0342011-03-28 11:47:22 +00007452 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007453 */
cristy6b3da3a2010-06-20 02:21:46 +00007454 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007455 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7456 if (((geometry.width == 0) && (geometry.height == 0)) ||
7457 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7458 break;
7459 (void) TransformImages(images,argv[i+1],(char *) NULL);
7460 InheritException(exception,&(*images)->exception);
7461 break;
7462 }
anthony9f4f0342011-03-28 11:47:22 +00007463#endif
cristy3ed852e2009-09-05 21:47:34 +00007464 break;
7465 }
7466 case 'd':
7467 {
7468 if (LocaleCompare("deconstruct",option+1) == 0)
7469 {
7470 Image
7471 *deconstruct_image;
7472
cristy6b3da3a2010-06-20 02:21:46 +00007473 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007474 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007475 exception);
cristy3ed852e2009-09-05 21:47:34 +00007476 if (deconstruct_image == (Image *) NULL)
7477 {
7478 status=MagickFalse;
7479 break;
7480 }
7481 *images=DestroyImageList(*images);
7482 *images=deconstruct_image;
7483 break;
7484 }
7485 if (LocaleCompare("delete",option+1) == 0)
7486 {
7487 if (*option == '+')
7488 DeleteImages(images,"-1",exception);
7489 else
7490 DeleteImages(images,argv[i+1],exception);
7491 break;
7492 }
7493 if (LocaleCompare("dither",option+1) == 0)
7494 {
7495 if (*option == '+')
7496 {
7497 quantize_info->dither=MagickFalse;
7498 break;
7499 }
7500 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007501 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007502 MagickDitherOptions,MagickFalse,argv[i+1]);
7503 break;
7504 }
cristyecb10ff2011-03-22 13:14:03 +00007505 if (LocaleCompare("duplicate",option+1) == 0)
7506 {
cristy72988482011-03-29 16:34:38 +00007507 Image
7508 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007509
anthony2b6bcae2011-03-23 13:05:34 +00007510 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007511 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7512 else
7513 {
7514 const char
7515 *p;
7516
anthony2b6bcae2011-03-23 13:05:34 +00007517 size_t
7518 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007519
anthony2b6bcae2011-03-23 13:05:34 +00007520 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007521 p=strchr(argv[i+1],',');
7522 if (p == (const char *) NULL)
7523 duplicate_images=DuplicateImages(*images,number_duplicates,
7524 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007525 else
cristy72988482011-03-29 16:34:38 +00007526 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7527 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007528 }
7529 AppendImageToList(images, duplicate_images);
7530 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007531 break;
7532 }
cristy3ed852e2009-09-05 21:47:34 +00007533 break;
7534 }
cristyd18ae7c2010-03-07 17:39:52 +00007535 case 'e':
7536 {
7537 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7538 {
7539 Image
7540 *evaluate_image;
7541
7542 MagickEvaluateOperator
7543 op;
7544
cristy6b3da3a2010-06-20 02:21:46 +00007545 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007546 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007547 MagickFalse,argv[i+1]);
7548 evaluate_image=EvaluateImages(*images,op,exception);
7549 if (evaluate_image == (Image *) NULL)
7550 {
7551 status=MagickFalse;
7552 break;
7553 }
7554 *images=DestroyImageList(*images);
7555 *images=evaluate_image;
7556 break;
7557 }
7558 break;
7559 }
cristy3ed852e2009-09-05 21:47:34 +00007560 case 'f':
7561 {
cristyf0a247f2009-10-04 00:20:03 +00007562 if (LocaleCompare("fft",option+1) == 0)
7563 {
7564 Image
7565 *fourier_image;
7566
7567 /*
7568 Implements the discrete Fourier transform (DFT).
7569 */
cristy6b3da3a2010-06-20 02:21:46 +00007570 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007571 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7572 MagickTrue : MagickFalse,exception);
7573 if (fourier_image == (Image *) NULL)
7574 break;
7575 *images=DestroyImage(*images);
7576 *images=fourier_image;
7577 break;
7578 }
cristy3ed852e2009-09-05 21:47:34 +00007579 if (LocaleCompare("flatten",option+1) == 0)
7580 {
7581 Image
7582 *flatten_image;
7583
cristy6b3da3a2010-06-20 02:21:46 +00007584 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007585 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7586 if (flatten_image == (Image *) NULL)
7587 break;
7588 *images=DestroyImageList(*images);
7589 *images=flatten_image;
7590 break;
7591 }
7592 if (LocaleCompare("fx",option+1) == 0)
7593 {
7594 Image
7595 *fx_image;
7596
cristy6b3da3a2010-06-20 02:21:46 +00007597 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007598 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007599 if (fx_image == (Image *) NULL)
7600 {
7601 status=MagickFalse;
7602 break;
7603 }
7604 *images=DestroyImageList(*images);
7605 *images=fx_image;
7606 break;
7607 }
7608 break;
7609 }
7610 case 'h':
7611 {
7612 if (LocaleCompare("hald-clut",option+1) == 0)
7613 {
7614 Image
7615 *hald_image,
7616 *image;
7617
cristy6b3da3a2010-06-20 02:21:46 +00007618 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007619 image=RemoveFirstImageFromList(images);
7620 hald_image=RemoveFirstImageFromList(images);
7621 if (hald_image == (Image *) NULL)
7622 {
7623 status=MagickFalse;
7624 break;
7625 }
cristy7c0a0a42011-08-23 17:57:25 +00007626 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007627 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007628 if (*images != (Image *) NULL)
7629 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007630 *images=image;
7631 break;
7632 }
7633 break;
7634 }
7635 case 'i':
7636 {
7637 if (LocaleCompare("ift",option+1) == 0)
7638 {
7639 Image
cristy8587f882009-11-13 20:28:49 +00007640 *fourier_image,
7641 *magnitude_image,
7642 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007643
7644 /*
7645 Implements the inverse fourier discrete Fourier transform (DFT).
7646 */
cristy6b3da3a2010-06-20 02:21:46 +00007647 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007648 magnitude_image=RemoveFirstImageFromList(images);
7649 phase_image=RemoveFirstImageFromList(images);
7650 if (phase_image == (Image *) NULL)
7651 {
7652 status=MagickFalse;
7653 break;
7654 }
7655 fourier_image=InverseFourierTransformImage(magnitude_image,
7656 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007657 if (fourier_image == (Image *) NULL)
7658 break;
cristy0aff6ea2009-11-14 01:40:53 +00007659 if (*images != (Image *) NULL)
7660 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007661 *images=fourier_image;
7662 break;
7663 }
7664 if (LocaleCompare("insert",option+1) == 0)
7665 {
7666 Image
7667 *p,
7668 *q;
7669
7670 index=0;
7671 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007672 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007673 p=RemoveLastImageFromList(images);
7674 if (p == (Image *) NULL)
7675 {
7676 (void) ThrowMagickException(exception,GetMagickModule(),
7677 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7678 status=MagickFalse;
7679 break;
7680 }
7681 q=p;
7682 if (index == 0)
7683 PrependImageToList(images,q);
7684 else
cristybb503372010-05-27 20:51:26 +00007685 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007686 AppendImageToList(images,q);
7687 else
7688 {
7689 q=GetImageFromList(*images,index-1);
7690 if (q == (Image *) NULL)
7691 {
7692 (void) ThrowMagickException(exception,GetMagickModule(),
7693 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7694 status=MagickFalse;
7695 break;
7696 }
7697 InsertImageInList(&q,p);
7698 }
7699 *images=GetFirstImageInList(q);
7700 break;
7701 }
7702 break;
7703 }
7704 case 'l':
7705 {
7706 if (LocaleCompare("layers",option+1) == 0)
7707 {
7708 Image
7709 *layers;
7710
7711 ImageLayerMethod
7712 method;
7713
cristy6b3da3a2010-06-20 02:21:46 +00007714 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007715 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007716 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007717 MagickFalse,argv[i+1]);
7718 switch (method)
7719 {
7720 case CoalesceLayer:
7721 {
7722 layers=CoalesceImages(*images,exception);
7723 break;
7724 }
7725 case CompareAnyLayer:
7726 case CompareClearLayer:
7727 case CompareOverlayLayer:
7728 default:
7729 {
cristy8a9106f2011-07-05 14:39:26 +00007730 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007731 break;
7732 }
7733 case MergeLayer:
7734 case FlattenLayer:
7735 case MosaicLayer:
7736 case TrimBoundsLayer:
7737 {
7738 layers=MergeImageLayers(*images,method,exception);
7739 break;
7740 }
7741 case DisposeLayer:
7742 {
7743 layers=DisposeImages(*images,exception);
7744 break;
7745 }
7746 case OptimizeImageLayer:
7747 {
7748 layers=OptimizeImageLayers(*images,exception);
7749 break;
7750 }
7751 case OptimizePlusLayer:
7752 {
7753 layers=OptimizePlusImageLayers(*images,exception);
7754 break;
7755 }
7756 case OptimizeTransLayer:
7757 {
7758 OptimizeImageTransparency(*images,exception);
7759 break;
7760 }
7761 case RemoveDupsLayer:
7762 {
7763 RemoveDuplicateLayers(images,exception);
7764 break;
7765 }
7766 case RemoveZeroLayer:
7767 {
7768 RemoveZeroDelayLayers(images,exception);
7769 break;
7770 }
7771 case OptimizeLayer:
7772 {
7773 /*
7774 General Purpose, GIF Animation Optimizer.
7775 */
7776 layers=CoalesceImages(*images,exception);
7777 if (layers == (Image *) NULL)
7778 {
7779 status=MagickFalse;
7780 break;
7781 }
cristy3ed852e2009-09-05 21:47:34 +00007782 *images=DestroyImageList(*images);
7783 *images=layers;
7784 layers=OptimizeImageLayers(*images,exception);
7785 if (layers == (Image *) NULL)
7786 {
7787 status=MagickFalse;
7788 break;
7789 }
cristy3ed852e2009-09-05 21:47:34 +00007790 *images=DestroyImageList(*images);
7791 *images=layers;
7792 layers=(Image *) NULL;
7793 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007794 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7795 exception);
cristy3ed852e2009-09-05 21:47:34 +00007796 break;
7797 }
7798 case CompositeLayer:
7799 {
7800 CompositeOperator
7801 compose;
7802
7803 Image
7804 *source;
7805
7806 RectangleInfo
7807 geometry;
7808
7809 /*
7810 Split image sequence at the first 'NULL:' image.
7811 */
7812 source=(*images);
7813 while (source != (Image *) NULL)
7814 {
7815 source=GetNextImageInList(source);
7816 if ((source != (Image *) NULL) &&
7817 (LocaleCompare(source->magick,"NULL") == 0))
7818 break;
7819 }
7820 if (source != (Image *) NULL)
7821 {
7822 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7823 (GetNextImageInList(source) == (Image *) NULL))
7824 source=(Image *) NULL;
7825 else
7826 {
7827 /*
7828 Separate the two lists, junk the null: image.
7829 */
7830 source=SplitImageList(source->previous);
7831 DeleteImageFromList(&source);
7832 }
7833 }
7834 if (source == (Image *) NULL)
7835 {
7836 (void) ThrowMagickException(exception,GetMagickModule(),
7837 OptionError,"MissingNullSeparator","layers Composite");
7838 status=MagickFalse;
7839 break;
7840 }
7841 /*
7842 Adjust offset with gravity and virtual canvas.
7843 */
7844 SetGeometry(*images,&geometry);
7845 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7846 geometry.width=source->page.width != 0 ?
7847 source->page.width : source->columns;
7848 geometry.height=source->page.height != 0 ?
7849 source->page.height : source->rows;
7850 GravityAdjustGeometry((*images)->page.width != 0 ?
7851 (*images)->page.width : (*images)->columns,
7852 (*images)->page.height != 0 ? (*images)->page.height :
7853 (*images)->rows,(*images)->gravity,&geometry);
7854 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007855 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007856 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007857 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007858 MagickComposeOptions,MagickFalse,option);
7859 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7860 exception);
7861 source=DestroyImageList(source);
7862 break;
7863 }
7864 }
7865 if (layers == (Image *) NULL)
7866 break;
7867 InheritException(exception,&layers->exception);
7868 *images=DestroyImageList(*images);
7869 *images=layers;
7870 break;
7871 }
7872 break;
7873 }
7874 case 'm':
7875 {
7876 if (LocaleCompare("map",option+1) == 0)
7877 {
cristy6b3da3a2010-06-20 02:21:46 +00007878 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007879 if (*option == '+')
7880 {
cristy018f07f2011-09-04 21:15:19 +00007881 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7882 exception);
cristy3ed852e2009-09-05 21:47:34 +00007883 break;
7884 }
7885 i++;
7886 break;
7887 }
cristyf40785b2010-03-06 02:27:27 +00007888 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007889 {
7890 Image
cristyf40785b2010-03-06 02:27:27 +00007891 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007892
cristyd18ae7c2010-03-07 17:39:52 +00007893 /*
7894 Maximum image sequence (deprecated).
7895 */
cristy6b3da3a2010-06-20 02:21:46 +00007896 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007897 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007898 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007899 {
7900 status=MagickFalse;
7901 break;
7902 }
7903 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007904 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007905 break;
7906 }
cristyf40785b2010-03-06 02:27:27 +00007907 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007908 {
7909 Image
cristyf40785b2010-03-06 02:27:27 +00007910 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007911
cristyd18ae7c2010-03-07 17:39:52 +00007912 /*
7913 Minimum image sequence (deprecated).
7914 */
cristy6b3da3a2010-06-20 02:21:46 +00007915 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007916 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007917 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007918 {
7919 status=MagickFalse;
7920 break;
7921 }
7922 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007923 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007924 break;
7925 }
cristy3ed852e2009-09-05 21:47:34 +00007926 if (LocaleCompare("morph",option+1) == 0)
7927 {
7928 Image
7929 *morph_image;
7930
cristy6b3da3a2010-06-20 02:21:46 +00007931 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007932 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007933 exception);
7934 if (morph_image == (Image *) NULL)
7935 {
7936 status=MagickFalse;
7937 break;
7938 }
7939 *images=DestroyImageList(*images);
7940 *images=morph_image;
7941 break;
7942 }
7943 if (LocaleCompare("mosaic",option+1) == 0)
7944 {
7945 Image
7946 *mosaic_image;
7947
cristy6b3da3a2010-06-20 02:21:46 +00007948 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007949 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7950 if (mosaic_image == (Image *) NULL)
7951 {
7952 status=MagickFalse;
7953 break;
7954 }
7955 *images=DestroyImageList(*images);
7956 *images=mosaic_image;
7957 break;
7958 }
7959 break;
7960 }
7961 case 'p':
7962 {
7963 if (LocaleCompare("print",option+1) == 0)
7964 {
7965 char
7966 *string;
7967
cristy6b3da3a2010-06-20 02:21:46 +00007968 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007969 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7970 exception);
cristy3ed852e2009-09-05 21:47:34 +00007971 if (string == (char *) NULL)
7972 break;
cristyb51dff52011-05-19 16:55:47 +00007973 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007974 string=DestroyString(string);
7975 }
7976 if (LocaleCompare("process",option+1) == 0)
7977 {
7978 char
7979 **arguments;
7980
7981 int
7982 j,
7983 number_arguments;
7984
cristy6b3da3a2010-06-20 02:21:46 +00007985 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007986 arguments=StringToArgv(argv[i+1],&number_arguments);
7987 if (arguments == (char **) NULL)
7988 break;
7989 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7990 {
7991 char
7992 breaker,
7993 quote,
7994 *token;
7995
7996 const char
7997 *arguments;
7998
7999 int
8000 next,
8001 status;
8002
8003 size_t
8004 length;
8005
8006 TokenInfo
8007 *token_info;
8008
8009 /*
8010 Support old style syntax, filter="-option arg".
8011 */
8012 length=strlen(argv[i+1]);
8013 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008014 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008015 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8016 sizeof(*token));
8017 if (token == (char *) NULL)
8018 break;
8019 next=0;
8020 arguments=argv[i+1];
8021 token_info=AcquireTokenInfo();
8022 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8023 "\"",'\0',&breaker,&next,&quote);
8024 token_info=DestroyTokenInfo(token_info);
8025 if (status == 0)
8026 {
8027 const char
8028 *argv;
8029
8030 argv=(&(arguments[next]));
8031 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8032 exception);
8033 }
8034 token=DestroyString(token);
8035 break;
8036 }
cristy91c0da22010-05-02 01:44:07 +00008037 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008038 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8039 number_arguments-2,(const char **) arguments+2,exception);
8040 for (j=0; j < number_arguments; j++)
8041 arguments[j]=DestroyString(arguments[j]);
8042 arguments=(char **) RelinquishMagickMemory(arguments);
8043 break;
8044 }
8045 break;
8046 }
8047 case 'r':
8048 {
8049 if (LocaleCompare("reverse",option+1) == 0)
8050 {
8051 ReverseImageList(images);
8052 InheritException(exception,&(*images)->exception);
8053 break;
8054 }
8055 break;
8056 }
8057 case 's':
8058 {
cristy4285d782011-02-09 20:12:28 +00008059 if (LocaleCompare("smush",option+1) == 0)
8060 {
8061 Image
8062 *smush_image;
8063
8064 ssize_t
8065 offset;
8066
8067 (void) SyncImagesSettings(mogrify_info,*images);
8068 offset=(ssize_t) StringToLong(argv[i+1]);
8069 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8070 MagickFalse,offset,exception);
8071 if (smush_image == (Image *) NULL)
8072 {
8073 status=MagickFalse;
8074 break;
8075 }
8076 *images=DestroyImageList(*images);
8077 *images=smush_image;
8078 break;
8079 }
cristy3ed852e2009-09-05 21:47:34 +00008080 if (LocaleCompare("swap",option+1) == 0)
8081 {
8082 Image
8083 *p,
8084 *q,
8085 *swap;
8086
cristybb503372010-05-27 20:51:26 +00008087 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008088 swap_index;
8089
8090 index=(-1);
8091 swap_index=(-2);
8092 if (*option != '+')
8093 {
8094 GeometryInfo
8095 geometry_info;
8096
8097 MagickStatusType
8098 flags;
8099
8100 swap_index=(-1);
8101 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008102 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008103 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008104 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008105 }
8106 p=GetImageFromList(*images,index);
8107 q=GetImageFromList(*images,swap_index);
8108 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8109 {
8110 (void) ThrowMagickException(exception,GetMagickModule(),
8111 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8112 status=MagickFalse;
8113 break;
8114 }
8115 if (p == q)
8116 break;
8117 swap=CloneImage(p,0,0,MagickTrue,exception);
8118 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8119 ReplaceImageInList(&q,swap);
8120 *images=GetFirstImageInList(q);
8121 break;
8122 }
8123 break;
8124 }
8125 case 'w':
8126 {
8127 if (LocaleCompare("write",option+1) == 0)
8128 {
cristy071dd7b2010-04-09 13:04:54 +00008129 char
cristy06609ee2010-03-17 20:21:27 +00008130 key[MaxTextExtent];
8131
cristy3ed852e2009-09-05 21:47:34 +00008132 Image
8133 *write_images;
8134
8135 ImageInfo
8136 *write_info;
8137
cristy6b3da3a2010-06-20 02:21:46 +00008138 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008139 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008140 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008141 write_images=(*images);
8142 if (*option == '+')
8143 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008144 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008145 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8146 write_info=DestroyImageInfo(write_info);
8147 if (*option == '+')
8148 write_images=DestroyImageList(write_images);
8149 break;
8150 }
8151 break;
8152 }
8153 default:
8154 break;
8155 }
8156 i+=count;
8157 }
8158 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008159 mogrify_info=DestroyImageInfo(mogrify_info);
8160 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008161 return(status != 0 ? MagickTrue : MagickFalse);
8162}
8163
8164/*
8165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8166% %
8167% %
8168% %
8169+ M o g r i f y I m a g e s %
8170% %
8171% %
8172% %
8173%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8174%
8175% MogrifyImages() applies image processing options to a sequence of images as
8176% prescribed by command line options.
8177%
8178% The format of the MogrifyImage method is:
8179%
8180% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8181% const MagickBooleanType post,const int argc,const char **argv,
8182% Image **images,Exceptioninfo *exception)
8183%
8184% A description of each parameter follows:
8185%
8186% o image_info: the image info..
8187%
8188% o post: If true, post process image list operators otherwise pre-process.
8189%
8190% o argc: Specifies a pointer to an integer describing the number of
8191% elements in the argument vector.
8192%
8193% o argv: Specifies a pointer to a text array containing the command line
8194% arguments.
8195%
anthonye9c27192011-03-27 08:07:06 +00008196% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008197%
8198% o exception: return any errors or warnings in this structure.
8199%
8200*/
8201WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8202 const MagickBooleanType post,const int argc,const char **argv,
8203 Image **images,ExceptionInfo *exception)
8204{
8205#define MogrifyImageTag "Mogrify/Image"
8206
anthonye9c27192011-03-27 08:07:06 +00008207 MagickStatusType
8208 status;
cristy3ed852e2009-09-05 21:47:34 +00008209
cristy0e9f9c12010-02-11 03:00:47 +00008210 MagickBooleanType
8211 proceed;
8212
anthonye9c27192011-03-27 08:07:06 +00008213 size_t
8214 n;
cristy3ed852e2009-09-05 21:47:34 +00008215
cristybb503372010-05-27 20:51:26 +00008216 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008217 i;
8218
cristy3ed852e2009-09-05 21:47:34 +00008219 assert(image_info != (ImageInfo *) NULL);
8220 assert(image_info->signature == MagickSignature);
8221 if (images == (Image **) NULL)
8222 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008223 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008224 assert((*images)->signature == MagickSignature);
8225 if ((*images)->debug != MagickFalse)
8226 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8227 (*images)->filename);
8228 if ((argc <= 0) || (*argv == (char *) NULL))
8229 return(MagickTrue);
8230 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8231 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008232 status=0;
anthonye9c27192011-03-27 08:07:06 +00008233
anthonyce2716b2011-04-22 09:51:34 +00008234#if 0
cristy1e604812011-05-19 18:07:50 +00008235 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8236 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008237#endif
8238
anthonye9c27192011-03-27 08:07:06 +00008239 /*
8240 Pre-process multi-image sequence operators
8241 */
cristy3ed852e2009-09-05 21:47:34 +00008242 if (post == MagickFalse)
8243 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008244 /*
8245 For each image, process simple single image operators
8246 */
8247 i=0;
8248 n=GetImageListLength(*images);
8249 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008250 {
anthonyce2716b2011-04-22 09:51:34 +00008251#if 0
cristy1e604812011-05-19 18:07:50 +00008252 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8253 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008254#endif
anthonye9c27192011-03-27 08:07:06 +00008255 status&=MogrifyImage(image_info,argc,argv,images,exception);
8256 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008257 if (proceed == MagickFalse)
8258 break;
anthonye9c27192011-03-27 08:07:06 +00008259 if ( (*images)->next == (Image *) NULL )
8260 break;
8261 *images=(*images)->next;
8262 i++;
cristy3ed852e2009-09-05 21:47:34 +00008263 }
anthonye9c27192011-03-27 08:07:06 +00008264 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008265#if 0
cristy1e604812011-05-19 18:07:50 +00008266 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8267 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008268#endif
anthonye9c27192011-03-27 08:07:06 +00008269
8270 /*
8271 Post-process, multi-image sequence operators
8272 */
8273 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008274 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008275 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008276 return(status != 0 ? MagickTrue : MagickFalse);
8277}