blob: 0120b22aa3f38cdc5a2c63eb49e75598bf31ed9f [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,
cristyf7ef0252011-09-09 14:50:06 +00002125 geometry_info.sigma,geometry_info.xi,geometry_info.psi,
2126 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002127 break;
2128 }
2129 break;
2130 }
2131 case 'n':
2132 {
2133 if (LocaleCompare("negate",option+1) == 0)
2134 {
2135 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002136 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002137 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002138 break;
2139 }
2140 if (LocaleCompare("noise",option+1) == 0)
2141 {
2142 (void) SyncImageSettings(mogrify_info,*image);
2143 if (*option == '-')
2144 {
cristyf36cbcb2011-09-07 13:28:22 +00002145 flags=ParseGeometry(argv[i+1],&geometry_info);
2146 if ((flags & SigmaValue) == 0)
2147 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002148 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002149 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002150 }
2151 else
2152 {
2153 NoiseType
2154 noise;
2155
2156 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2157 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002158 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002159 }
2160 break;
2161 }
2162 if (LocaleCompare("normalize",option+1) == 0)
2163 {
2164 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002165 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002166 break;
2167 }
2168 break;
2169 }
2170 case 'o':
2171 {
2172 if (LocaleCompare("opaque",option+1) == 0)
2173 {
cristy4c08aed2011-07-01 19:47:50 +00002174 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002175 target;
2176
2177 (void) SyncImageSettings(mogrify_info,*image);
2178 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002179 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002180 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002181 break;
2182 }
2183 if (LocaleCompare("ordered-dither",option+1) == 0)
2184 {
2185 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002186 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002187 break;
2188 }
2189 break;
2190 }
2191 case 'p':
2192 {
2193 if (LocaleCompare("paint",option+1) == 0)
2194 {
anthonydf8ebac2011-04-27 09:03:19 +00002195 (void) SyncImageSettings(mogrify_info,*image);
2196 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002197 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2198 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002199 break;
2200 }
2201 if (LocaleCompare("pen",option+1) == 0)
2202 {
2203 if (*option == '+')
2204 {
2205 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2206 break;
2207 }
2208 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2209 break;
2210 }
2211 if (LocaleCompare("pointsize",option+1) == 0)
2212 {
2213 if (*option == '+')
2214 (void) ParseGeometry("12",&geometry_info);
2215 else
2216 (void) ParseGeometry(argv[i+1],&geometry_info);
2217 draw_info->pointsize=geometry_info.rho;
2218 break;
2219 }
2220 if (LocaleCompare("polaroid",option+1) == 0)
2221 {
2222 double
2223 angle;
2224
2225 RandomInfo
2226 *random_info;
2227
2228 /*
2229 Simulate a Polaroid picture.
2230 */
2231 (void) SyncImageSettings(mogrify_info,*image);
2232 random_info=AcquireRandomInfo();
2233 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2234 random_info=DestroyRandomInfo(random_info);
2235 if (*option == '-')
2236 {
2237 SetGeometryInfo(&geometry_info);
2238 flags=ParseGeometry(argv[i+1],&geometry_info);
2239 angle=geometry_info.rho;
2240 }
2241 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2242 break;
2243 }
2244 if (LocaleCompare("posterize",option+1) == 0)
2245 {
2246 /*
2247 Posterize image.
2248 */
2249 (void) SyncImageSettings(mogrify_info,*image);
2250 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002251 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002252 break;
2253 }
2254 if (LocaleCompare("preview",option+1) == 0)
2255 {
2256 PreviewType
2257 preview_type;
2258
2259 /*
2260 Preview image.
2261 */
2262 (void) SyncImageSettings(mogrify_info,*image);
2263 if (*option == '+')
2264 preview_type=UndefinedPreview;
2265 else
2266 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2267 MagickFalse,argv[i+1]);
2268 mogrify_image=PreviewImage(*image,preview_type,exception);
2269 break;
2270 }
2271 if (LocaleCompare("profile",option+1) == 0)
2272 {
2273 const char
2274 *name;
2275
2276 const StringInfo
2277 *profile;
2278
2279 Image
2280 *profile_image;
2281
2282 ImageInfo
2283 *profile_info;
2284
2285 (void) SyncImageSettings(mogrify_info,*image);
2286 if (*option == '+')
2287 {
2288 /*
2289 Remove a profile from the image.
2290 */
2291 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2292 NULL,0,MagickTrue);
2293 InheritException(exception,&(*image)->exception);
2294 break;
2295 }
2296 /*
2297 Associate a profile with the image.
2298 */
2299 profile_info=CloneImageInfo(mogrify_info);
2300 profile=GetImageProfile(*image,"iptc");
2301 if (profile != (StringInfo *) NULL)
2302 profile_info->profile=(void *) CloneStringInfo(profile);
2303 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2304 profile_info=DestroyImageInfo(profile_info);
2305 if (profile_image == (Image *) NULL)
2306 {
2307 StringInfo
2308 *profile;
2309
2310 profile_info=CloneImageInfo(mogrify_info);
2311 (void) CopyMagickString(profile_info->filename,argv[i+1],
2312 MaxTextExtent);
2313 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2314 if (profile != (StringInfo *) NULL)
2315 {
2316 (void) ProfileImage(*image,profile_info->magick,
2317 GetStringInfoDatum(profile),(size_t)
2318 GetStringInfoLength(profile),MagickFalse);
2319 profile=DestroyStringInfo(profile);
2320 }
2321 profile_info=DestroyImageInfo(profile_info);
2322 break;
2323 }
2324 ResetImageProfileIterator(profile_image);
2325 name=GetNextImageProfile(profile_image);
2326 while (name != (const char *) NULL)
2327 {
2328 profile=GetImageProfile(profile_image,name);
2329 if (profile != (StringInfo *) NULL)
2330 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2331 (size_t) GetStringInfoLength(profile),MagickFalse);
2332 name=GetNextImageProfile(profile_image);
2333 }
2334 profile_image=DestroyImage(profile_image);
2335 break;
2336 }
2337 break;
2338 }
2339 case 'q':
2340 {
2341 if (LocaleCompare("quantize",option+1) == 0)
2342 {
2343 if (*option == '+')
2344 {
2345 quantize_info->colorspace=UndefinedColorspace;
2346 break;
2347 }
2348 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2349 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2350 break;
2351 }
2352 break;
2353 }
2354 case 'r':
2355 {
2356 if (LocaleCompare("radial-blur",option+1) == 0)
2357 {
2358 /*
2359 Radial blur image.
2360 */
2361 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002362 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2363 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002364 break;
2365 }
2366 if (LocaleCompare("raise",option+1) == 0)
2367 {
2368 /*
2369 Surround image with a raise of solid color.
2370 */
2371 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2372 if ((flags & SigmaValue) == 0)
2373 geometry.height=geometry.width;
2374 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002375 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002376 break;
2377 }
2378 if (LocaleCompare("random-threshold",option+1) == 0)
2379 {
2380 /*
2381 Threshold image.
2382 */
2383 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002384 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002385 break;
2386 }
2387 if (LocaleCompare("recolor",option+1) == 0)
2388 {
2389 KernelInfo
2390 *kernel;
2391
2392 (void) SyncImageSettings(mogrify_info,*image);
2393 kernel=AcquireKernelInfo(argv[i+1]);
2394 if (kernel == (KernelInfo *) NULL)
2395 break;
2396 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2397 kernel=DestroyKernelInfo(kernel);
2398 break;
2399 }
2400 if (LocaleCompare("region",option+1) == 0)
2401 {
2402 (void) SyncImageSettings(mogrify_info,*image);
2403 if (region_image != (Image *) NULL)
2404 {
2405 /*
2406 Composite region.
2407 */
2408 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002409 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2410 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002411 InheritException(exception,&region_image->exception);
2412 *image=DestroyImage(*image);
2413 *image=region_image;
2414 region_image = (Image *) NULL;
2415 }
2416 if (*option == '+')
2417 break;
2418 /*
2419 Apply transformations to a selected region of the image.
2420 */
cristy3ed852e2009-09-05 21:47:34 +00002421 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2422 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002423 mogrify_image=CropImage(*image,&region_geometry,exception);
2424 if (mogrify_image == (Image *) NULL)
2425 break;
2426 region_image=(*image);
2427 *image=mogrify_image;
2428 mogrify_image=(Image *) NULL;
2429 break;
cristy3ed852e2009-09-05 21:47:34 +00002430 }
anthonydf8ebac2011-04-27 09:03:19 +00002431 if (LocaleCompare("render",option+1) == 0)
2432 {
2433 (void) SyncImageSettings(mogrify_info,*image);
2434 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2435 break;
2436 }
2437 if (LocaleCompare("remap",option+1) == 0)
2438 {
2439 Image
2440 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002441
anthonydf8ebac2011-04-27 09:03:19 +00002442 /*
2443 Transform image colors to match this set of colors.
2444 */
2445 (void) SyncImageSettings(mogrify_info,*image);
2446 if (*option == '+')
2447 break;
2448 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2449 if (remap_image == (Image *) NULL)
2450 break;
cristy018f07f2011-09-04 21:15:19 +00002451 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002452 remap_image=DestroyImage(remap_image);
2453 break;
2454 }
2455 if (LocaleCompare("repage",option+1) == 0)
2456 {
2457 if (*option == '+')
2458 {
2459 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2460 break;
2461 }
2462 (void) ResetImagePage(*image,argv[i+1]);
2463 InheritException(exception,&(*image)->exception);
2464 break;
2465 }
2466 if (LocaleCompare("resample",option+1) == 0)
2467 {
2468 /*
2469 Resample image.
2470 */
2471 (void) SyncImageSettings(mogrify_info,*image);
2472 flags=ParseGeometry(argv[i+1],&geometry_info);
2473 if ((flags & SigmaValue) == 0)
2474 geometry_info.sigma=geometry_info.rho;
2475 mogrify_image=ResampleImage(*image,geometry_info.rho,
2476 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2477 break;
2478 }
2479 if (LocaleCompare("resize",option+1) == 0)
2480 {
2481 /*
2482 Resize image.
2483 */
2484 (void) SyncImageSettings(mogrify_info,*image);
2485 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2486 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2487 (*image)->filter,(*image)->blur,exception);
2488 break;
2489 }
2490 if (LocaleCompare("roll",option+1) == 0)
2491 {
2492 /*
2493 Roll image.
2494 */
2495 (void) SyncImageSettings(mogrify_info,*image);
2496 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2497 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2498 break;
2499 }
2500 if (LocaleCompare("rotate",option+1) == 0)
2501 {
2502 char
2503 *geometry;
2504
2505 /*
2506 Check for conditional image rotation.
2507 */
2508 (void) SyncImageSettings(mogrify_info,*image);
2509 if (strchr(argv[i+1],'>') != (char *) NULL)
2510 if ((*image)->columns <= (*image)->rows)
2511 break;
2512 if (strchr(argv[i+1],'<') != (char *) NULL)
2513 if ((*image)->columns >= (*image)->rows)
2514 break;
2515 /*
2516 Rotate image.
2517 */
2518 geometry=ConstantString(argv[i+1]);
2519 (void) SubstituteString(&geometry,">","");
2520 (void) SubstituteString(&geometry,"<","");
2521 (void) ParseGeometry(geometry,&geometry_info);
2522 geometry=DestroyString(geometry);
2523 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2524 break;
2525 }
2526 break;
2527 }
2528 case 's':
2529 {
2530 if (LocaleCompare("sample",option+1) == 0)
2531 {
2532 /*
2533 Sample image with pixel replication.
2534 */
2535 (void) SyncImageSettings(mogrify_info,*image);
2536 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2537 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2538 exception);
2539 break;
2540 }
2541 if (LocaleCompare("scale",option+1) == 0)
2542 {
2543 /*
2544 Resize image.
2545 */
2546 (void) SyncImageSettings(mogrify_info,*image);
2547 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2548 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2549 exception);
2550 break;
2551 }
2552 if (LocaleCompare("selective-blur",option+1) == 0)
2553 {
2554 /*
2555 Selectively blur pixels within a contrast threshold.
2556 */
2557 (void) SyncImageSettings(mogrify_info,*image);
2558 flags=ParseGeometry(argv[i+1],&geometry_info);
2559 if ((flags & PercentValue) != 0)
2560 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002561 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2562 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002563 break;
2564 }
2565 if (LocaleCompare("separate",option+1) == 0)
2566 {
2567 /*
2568 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002569 */
2570 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002571 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002572 break;
2573 }
2574 if (LocaleCompare("sepia-tone",option+1) == 0)
2575 {
2576 double
2577 threshold;
2578
2579 /*
2580 Sepia-tone image.
2581 */
2582 (void) SyncImageSettings(mogrify_info,*image);
2583 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2584 mogrify_image=SepiaToneImage(*image,threshold,exception);
2585 break;
2586 }
2587 if (LocaleCompare("segment",option+1) == 0)
2588 {
2589 /*
2590 Segment image.
2591 */
2592 (void) SyncImageSettings(mogrify_info,*image);
2593 flags=ParseGeometry(argv[i+1],&geometry_info);
2594 if ((flags & SigmaValue) == 0)
2595 geometry_info.sigma=1.0;
2596 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002597 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2598 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002599 break;
2600 }
2601 if (LocaleCompare("set",option+1) == 0)
2602 {
2603 char
2604 *value;
2605
2606 /*
2607 Set image option.
2608 */
2609 if (*option == '+')
2610 {
2611 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2612 (void) DeleteImageRegistry(argv[i+1]+9);
2613 else
2614 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2615 {
2616 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2617 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2618 }
2619 else
2620 (void) DeleteImageProperty(*image,argv[i+1]);
2621 break;
2622 }
cristy018f07f2011-09-04 21:15:19 +00002623 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2624 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002625 if (value == (char *) NULL)
2626 break;
2627 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2628 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2629 exception);
2630 else
2631 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2632 {
2633 (void) SetImageOption(image_info,argv[i+1]+7,value);
2634 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2635 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2636 }
2637 else
2638 (void) SetImageProperty(*image,argv[i+1],value);
2639 value=DestroyString(value);
2640 break;
2641 }
2642 if (LocaleCompare("shade",option+1) == 0)
2643 {
2644 /*
2645 Shade image.
2646 */
2647 (void) SyncImageSettings(mogrify_info,*image);
2648 flags=ParseGeometry(argv[i+1],&geometry_info);
2649 if ((flags & SigmaValue) == 0)
2650 geometry_info.sigma=1.0;
2651 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2652 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2653 break;
2654 }
2655 if (LocaleCompare("shadow",option+1) == 0)
2656 {
2657 /*
2658 Shadow image.
2659 */
2660 (void) SyncImageSettings(mogrify_info,*image);
2661 flags=ParseGeometry(argv[i+1],&geometry_info);
2662 if ((flags & SigmaValue) == 0)
2663 geometry_info.sigma=1.0;
2664 if ((flags & XiValue) == 0)
2665 geometry_info.xi=4.0;
2666 if ((flags & PsiValue) == 0)
2667 geometry_info.psi=4.0;
2668 mogrify_image=ShadowImage(*image,geometry_info.rho,
2669 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2670 ceil(geometry_info.psi-0.5),exception);
2671 break;
2672 }
2673 if (LocaleCompare("sharpen",option+1) == 0)
2674 {
2675 /*
2676 Sharpen image.
2677 */
2678 (void) SyncImageSettings(mogrify_info,*image);
2679 flags=ParseGeometry(argv[i+1],&geometry_info);
2680 if ((flags & SigmaValue) == 0)
2681 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002682 if ((flags & XiValue) == 0)
2683 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002684 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002685 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002686 break;
2687 }
2688 if (LocaleCompare("shave",option+1) == 0)
2689 {
2690 /*
2691 Shave the image edges.
2692 */
2693 (void) SyncImageSettings(mogrify_info,*image);
2694 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2695 mogrify_image=ShaveImage(*image,&geometry,exception);
2696 break;
2697 }
2698 if (LocaleCompare("shear",option+1) == 0)
2699 {
2700 /*
2701 Shear image.
2702 */
2703 (void) SyncImageSettings(mogrify_info,*image);
2704 flags=ParseGeometry(argv[i+1],&geometry_info);
2705 if ((flags & SigmaValue) == 0)
2706 geometry_info.sigma=geometry_info.rho;
2707 mogrify_image=ShearImage(*image,geometry_info.rho,
2708 geometry_info.sigma,exception);
2709 break;
2710 }
2711 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2712 {
2713 /*
2714 Sigmoidal non-linearity contrast control.
2715 */
2716 (void) SyncImageSettings(mogrify_info,*image);
2717 flags=ParseGeometry(argv[i+1],&geometry_info);
2718 if ((flags & SigmaValue) == 0)
2719 geometry_info.sigma=(double) QuantumRange/2.0;
2720 if ((flags & PercentValue) != 0)
2721 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2722 100.0;
cristy9ee60942011-07-06 14:54:38 +00002723 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002724 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2725 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002726 break;
2727 }
2728 if (LocaleCompare("sketch",option+1) == 0)
2729 {
2730 /*
2731 Sketch image.
2732 */
2733 (void) SyncImageSettings(mogrify_info,*image);
2734 flags=ParseGeometry(argv[i+1],&geometry_info);
2735 if ((flags & SigmaValue) == 0)
2736 geometry_info.sigma=1.0;
2737 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002738 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002739 break;
2740 }
2741 if (LocaleCompare("solarize",option+1) == 0)
2742 {
2743 double
2744 threshold;
2745
2746 (void) SyncImageSettings(mogrify_info,*image);
2747 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002748 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002749 break;
2750 }
2751 if (LocaleCompare("sparse-color",option+1) == 0)
2752 {
2753 SparseColorMethod
2754 method;
2755
2756 char
2757 *arguments;
2758
2759 /*
2760 Sparse Color Interpolated Gradient
2761 */
2762 (void) SyncImageSettings(mogrify_info,*image);
2763 method=(SparseColorMethod) ParseCommandOption(
2764 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002765 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2766 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002767 if (arguments == (char *) NULL)
2768 break;
cristy3884f692011-07-08 18:00:18 +00002769 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002770 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2771 arguments=DestroyString(arguments);
2772 break;
2773 }
2774 if (LocaleCompare("splice",option+1) == 0)
2775 {
2776 /*
2777 Splice a solid color into the image.
2778 */
2779 (void) SyncImageSettings(mogrify_info,*image);
2780 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2781 mogrify_image=SpliceImage(*image,&geometry,exception);
2782 break;
2783 }
2784 if (LocaleCompare("spread",option+1) == 0)
2785 {
2786 /*
2787 Spread an image.
2788 */
2789 (void) SyncImageSettings(mogrify_info,*image);
2790 (void) ParseGeometry(argv[i+1],&geometry_info);
2791 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2792 break;
2793 }
2794 if (LocaleCompare("statistic",option+1) == 0)
2795 {
2796 StatisticType
2797 type;
2798
2799 (void) SyncImageSettings(mogrify_info,*image);
2800 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2801 MagickFalse,argv[i+1]);
2802 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002803 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2804 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002805 break;
2806 }
2807 if (LocaleCompare("stretch",option+1) == 0)
2808 {
2809 if (*option == '+')
2810 {
2811 draw_info->stretch=UndefinedStretch;
2812 break;
2813 }
2814 draw_info->stretch=(StretchType) ParseCommandOption(
2815 MagickStretchOptions,MagickFalse,argv[i+1]);
2816 break;
2817 }
2818 if (LocaleCompare("strip",option+1) == 0)
2819 {
2820 /*
2821 Strip image of profiles and comments.
2822 */
2823 (void) SyncImageSettings(mogrify_info,*image);
2824 (void) StripImage(*image);
2825 InheritException(exception,&(*image)->exception);
2826 break;
2827 }
2828 if (LocaleCompare("stroke",option+1) == 0)
2829 {
2830 ExceptionInfo
2831 *sans;
2832
2833 if (*option == '+')
2834 {
2835 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2836 if (draw_info->stroke_pattern != (Image *) NULL)
2837 draw_info->stroke_pattern=DestroyImage(
2838 draw_info->stroke_pattern);
2839 break;
2840 }
2841 sans=AcquireExceptionInfo();
2842 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2843 sans=DestroyExceptionInfo(sans);
2844 if (status == MagickFalse)
2845 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2846 exception);
2847 break;
2848 }
2849 if (LocaleCompare("strokewidth",option+1) == 0)
2850 {
cristyc1acd842011-05-19 23:05:47 +00002851 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2852 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002853 break;
2854 }
2855 if (LocaleCompare("style",option+1) == 0)
2856 {
2857 if (*option == '+')
2858 {
2859 draw_info->style=UndefinedStyle;
2860 break;
2861 }
2862 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2863 MagickFalse,argv[i+1]);
2864 break;
2865 }
2866 if (LocaleCompare("swirl",option+1) == 0)
2867 {
2868 /*
2869 Swirl image.
2870 */
2871 (void) SyncImageSettings(mogrify_info,*image);
2872 (void) ParseGeometry(argv[i+1],&geometry_info);
2873 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2874 break;
2875 }
2876 break;
2877 }
2878 case 't':
2879 {
2880 if (LocaleCompare("threshold",option+1) == 0)
2881 {
2882 double
2883 threshold;
2884
2885 /*
2886 Threshold image.
2887 */
2888 (void) SyncImageSettings(mogrify_info,*image);
2889 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002890 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002891 else
2892 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002893 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002894 InheritException(exception,&(*image)->exception);
2895 break;
2896 }
2897 if (LocaleCompare("thumbnail",option+1) == 0)
2898 {
2899 /*
2900 Thumbnail image.
2901 */
2902 (void) SyncImageSettings(mogrify_info,*image);
2903 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2904 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2905 exception);
2906 break;
2907 }
2908 if (LocaleCompare("tile",option+1) == 0)
2909 {
2910 if (*option == '+')
2911 {
2912 if (draw_info->fill_pattern != (Image *) NULL)
2913 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2914 break;
2915 }
2916 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2917 exception);
2918 break;
2919 }
2920 if (LocaleCompare("tint",option+1) == 0)
2921 {
2922 /*
2923 Tint the image.
2924 */
2925 (void) SyncImageSettings(mogrify_info,*image);
2926 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2927 break;
2928 }
2929 if (LocaleCompare("transform",option+1) == 0)
2930 {
2931 /*
2932 Affine transform image.
2933 */
2934 (void) SyncImageSettings(mogrify_info,*image);
2935 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2936 exception);
2937 break;
2938 }
2939 if (LocaleCompare("transparent",option+1) == 0)
2940 {
cristy4c08aed2011-07-01 19:47:50 +00002941 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002942 target;
2943
2944 (void) SyncImageSettings(mogrify_info,*image);
2945 (void) QueryMagickColor(argv[i+1],&target,exception);
2946 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002947 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2948 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002949 break;
2950 }
2951 if (LocaleCompare("transpose",option+1) == 0)
2952 {
2953 /*
2954 Transpose image scanlines.
2955 */
2956 (void) SyncImageSettings(mogrify_info,*image);
2957 mogrify_image=TransposeImage(*image,exception);
2958 break;
2959 }
2960 if (LocaleCompare("transverse",option+1) == 0)
2961 {
2962 /*
2963 Transverse image scanlines.
2964 */
2965 (void) SyncImageSettings(mogrify_info,*image);
2966 mogrify_image=TransverseImage(*image,exception);
2967 break;
2968 }
2969 if (LocaleCompare("treedepth",option+1) == 0)
2970 {
2971 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2972 break;
2973 }
2974 if (LocaleCompare("trim",option+1) == 0)
2975 {
2976 /*
2977 Trim image.
2978 */
2979 (void) SyncImageSettings(mogrify_info,*image);
2980 mogrify_image=TrimImage(*image,exception);
2981 break;
2982 }
2983 if (LocaleCompare("type",option+1) == 0)
2984 {
2985 ImageType
2986 type;
2987
2988 (void) SyncImageSettings(mogrify_info,*image);
2989 if (*option == '+')
2990 type=UndefinedType;
2991 else
2992 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2993 argv[i+1]);
2994 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00002995 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002996 break;
2997 }
2998 break;
2999 }
3000 case 'u':
3001 {
3002 if (LocaleCompare("undercolor",option+1) == 0)
3003 {
3004 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3005 exception);
3006 break;
3007 }
3008 if (LocaleCompare("unique",option+1) == 0)
3009 {
3010 if (*option == '+')
3011 {
3012 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3013 break;
3014 }
3015 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3016 (void) SetImageArtifact(*image,"verbose","true");
3017 break;
3018 }
3019 if (LocaleCompare("unique-colors",option+1) == 0)
3020 {
3021 /*
3022 Unique image colors.
3023 */
3024 (void) SyncImageSettings(mogrify_info,*image);
3025 mogrify_image=UniqueImageColors(*image,exception);
3026 break;
3027 }
3028 if (LocaleCompare("unsharp",option+1) == 0)
3029 {
3030 /*
3031 Unsharp mask image.
3032 */
3033 (void) SyncImageSettings(mogrify_info,*image);
3034 flags=ParseGeometry(argv[i+1],&geometry_info);
3035 if ((flags & SigmaValue) == 0)
3036 geometry_info.sigma=1.0;
3037 if ((flags & XiValue) == 0)
3038 geometry_info.xi=1.0;
3039 if ((flags & PsiValue) == 0)
3040 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003041 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3042 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003043 break;
3044 }
3045 break;
3046 }
3047 case 'v':
3048 {
3049 if (LocaleCompare("verbose",option+1) == 0)
3050 {
3051 (void) SetImageArtifact(*image,option+1,
3052 *option == '+' ? "false" : "true");
3053 break;
3054 }
3055 if (LocaleCompare("vignette",option+1) == 0)
3056 {
3057 /*
3058 Vignette image.
3059 */
3060 (void) SyncImageSettings(mogrify_info,*image);
3061 flags=ParseGeometry(argv[i+1],&geometry_info);
3062 if ((flags & SigmaValue) == 0)
3063 geometry_info.sigma=1.0;
3064 if ((flags & XiValue) == 0)
3065 geometry_info.xi=0.1*(*image)->columns;
3066 if ((flags & PsiValue) == 0)
3067 geometry_info.psi=0.1*(*image)->rows;
3068 mogrify_image=VignetteImage(*image,geometry_info.rho,
3069 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3070 ceil(geometry_info.psi-0.5),exception);
3071 break;
3072 }
3073 if (LocaleCompare("virtual-pixel",option+1) == 0)
3074 {
3075 if (*option == '+')
3076 {
3077 (void) SetImageVirtualPixelMethod(*image,
3078 UndefinedVirtualPixelMethod);
3079 break;
3080 }
3081 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3082 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3083 argv[i+1]));
3084 break;
3085 }
3086 break;
3087 }
3088 case 'w':
3089 {
3090 if (LocaleCompare("wave",option+1) == 0)
3091 {
3092 /*
3093 Wave image.
3094 */
3095 (void) SyncImageSettings(mogrify_info,*image);
3096 flags=ParseGeometry(argv[i+1],&geometry_info);
3097 if ((flags & SigmaValue) == 0)
3098 geometry_info.sigma=1.0;
3099 mogrify_image=WaveImage(*image,geometry_info.rho,
3100 geometry_info.sigma,exception);
3101 break;
3102 }
3103 if (LocaleCompare("weight",option+1) == 0)
3104 {
3105 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3106 if (LocaleCompare(argv[i+1],"all") == 0)
3107 draw_info->weight=0;
3108 if (LocaleCompare(argv[i+1],"bold") == 0)
3109 draw_info->weight=700;
3110 if (LocaleCompare(argv[i+1],"bolder") == 0)
3111 if (draw_info->weight <= 800)
3112 draw_info->weight+=100;
3113 if (LocaleCompare(argv[i+1],"lighter") == 0)
3114 if (draw_info->weight >= 100)
3115 draw_info->weight-=100;
3116 if (LocaleCompare(argv[i+1],"normal") == 0)
3117 draw_info->weight=400;
3118 break;
3119 }
3120 if (LocaleCompare("white-threshold",option+1) == 0)
3121 {
3122 /*
3123 White threshold image.
3124 */
3125 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003126 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003127 InheritException(exception,&(*image)->exception);
3128 break;
3129 }
3130 break;
3131 }
3132 default:
3133 break;
3134 }
3135 /*
3136 Replace current image with any image that was generated
3137 */
3138 if (mogrify_image != (Image *) NULL)
3139 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003140 i+=count;
3141 }
3142 if (region_image != (Image *) NULL)
3143 {
anthonydf8ebac2011-04-27 09:03:19 +00003144 /*
3145 Composite transformed region onto image.
3146 */
cristy6b3da3a2010-06-20 02:21:46 +00003147 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003148 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003149 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3150 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003151 InheritException(exception,&region_image->exception);
3152 *image=DestroyImage(*image);
3153 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003154 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003155 }
3156 /*
3157 Free resources.
3158 */
anthonydf8ebac2011-04-27 09:03:19 +00003159 quantize_info=DestroyQuantizeInfo(quantize_info);
3160 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003161 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003162 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003163 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003164 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003165}
3166
3167/*
3168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3169% %
3170% %
3171% %
cristy5063d812010-10-19 16:28:10 +00003172+ 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 +00003173% %
3174% %
3175% %
3176%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3177%
3178% MogrifyImageCommand() transforms an image or a sequence of images. These
3179% transforms include image scaling, image rotation, color reduction, and
3180% others. The transmogrified image overwrites the original image.
3181%
3182% The format of the MogrifyImageCommand method is:
3183%
3184% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3185% const char **argv,char **metadata,ExceptionInfo *exception)
3186%
3187% A description of each parameter follows:
3188%
3189% o image_info: the image info.
3190%
3191% o argc: the number of elements in the argument vector.
3192%
3193% o argv: A text array containing the command line arguments.
3194%
3195% o metadata: any metadata is returned here.
3196%
3197% o exception: return any errors or warnings in this structure.
3198%
3199*/
3200
3201static MagickBooleanType MogrifyUsage(void)
3202{
3203 static const char
3204 *miscellaneous[]=
3205 {
3206 "-debug events display copious debugging information",
3207 "-help print program options",
3208 "-list type print a list of supported option arguments",
3209 "-log format format of debugging information",
3210 "-version print version information",
3211 (char *) NULL
3212 },
3213 *operators[]=
3214 {
3215 "-adaptive-blur geometry",
3216 " adaptively blur pixels; decrease effect near edges",
3217 "-adaptive-resize geometry",
3218 " adaptively resize image using 'mesh' interpolation",
3219 "-adaptive-sharpen geometry",
3220 " adaptively sharpen pixels; increase effect near edges",
3221 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3222 " transparent, extract, background, or shape",
3223 "-annotate geometry text",
3224 " annotate the image with text",
3225 "-auto-gamma automagically adjust gamma level of image",
3226 "-auto-level automagically adjust color levels of image",
3227 "-auto-orient automagically orient (rotate) image",
3228 "-bench iterations measure performance",
3229 "-black-threshold value",
3230 " force all pixels below the threshold into black",
3231 "-blue-shift simulate a scene at nighttime in the moonlight",
3232 "-blur geometry reduce image noise and reduce detail levels",
3233 "-border geometry surround image with a border of color",
3234 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003235 "-brightness-contrast geometry",
3236 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003237 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003238 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003239 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003240 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003241 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003242 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003243 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003244 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003245 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003246 "-contrast enhance or reduce the image contrast",
3247 "-contrast-stretch geometry",
3248 " improve contrast by `stretching' the intensity range",
3249 "-convolve coefficients",
3250 " apply a convolution kernel to the image",
3251 "-cycle amount cycle the image colormap",
3252 "-decipher filename convert cipher pixels to plain pixels",
3253 "-deskew threshold straighten an image",
3254 "-despeckle reduce the speckles within an image",
3255 "-distort method args",
3256 " distort images according to given method ad args",
3257 "-draw string annotate the image with a graphic primitive",
3258 "-edge radius apply a filter to detect edges in the image",
3259 "-encipher filename convert plain pixels to cipher pixels",
3260 "-emboss radius emboss an image",
3261 "-enhance apply a digital filter to enhance a noisy image",
3262 "-equalize perform histogram equalization to an image",
3263 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003264 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003265 "-extent geometry set the image size",
3266 "-extract geometry extract area from image",
3267 "-fft implements the discrete Fourier transform (DFT)",
3268 "-flip flip image vertically",
3269 "-floodfill geometry color",
3270 " floodfill the image with color",
3271 "-flop flop image horizontally",
3272 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003273 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003274 " apply function over image values",
3275 "-gamma value level of gamma correction",
3276 "-gaussian-blur geometry",
3277 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003278 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003279 "-identify identify the format and characteristics of the image",
3280 "-ift implements the inverse discrete Fourier transform (DFT)",
3281 "-implode amount implode image pixels about the center",
3282 "-lat geometry local adaptive thresholding",
3283 "-layers method optimize, merge, or compare image layers",
3284 "-level value adjust the level of image contrast",
3285 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003286 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003287 "-linear-stretch geometry",
3288 " improve contrast by `stretching with saturation'",
3289 "-liquid-rescale geometry",
3290 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003291 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003292 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003293 "-modulate value vary the brightness, saturation, and hue",
3294 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003295 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003296 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003297 "-motion-blur geometry",
3298 " simulate motion blur",
3299 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003300 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003301 "-normalize transform image to span the full range of colors",
3302 "-opaque color change this color to the fill color",
3303 "-ordered-dither NxN",
3304 " add a noise pattern to the image with specific",
3305 " amplitudes",
3306 "-paint radius simulate an oil painting",
3307 "-polaroid angle simulate a Polaroid picture",
3308 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003309 "-profile filename add, delete, or apply an image profile",
3310 "-quantize colorspace reduce colors in this colorspace",
3311 "-radial-blur angle radial blur the image",
3312 "-raise value lighten/darken image edges to create a 3-D effect",
3313 "-random-threshold low,high",
3314 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003315 "-region geometry apply options to a portion of the image",
3316 "-render render vector graphics",
3317 "-repage geometry size and location of an image canvas",
3318 "-resample geometry change the resolution of an image",
3319 "-resize geometry resize the image",
3320 "-roll geometry roll an image vertically or horizontally",
3321 "-rotate degrees apply Paeth rotation to the image",
3322 "-sample geometry scale image with pixel sampling",
3323 "-scale geometry scale the image",
3324 "-segment values segment an image",
3325 "-selective-blur geometry",
3326 " selectively blur pixels within a contrast threshold",
3327 "-sepia-tone threshold",
3328 " simulate a sepia-toned photo",
3329 "-set property value set an image property",
3330 "-shade degrees shade the image using a distant light source",
3331 "-shadow geometry simulate an image shadow",
3332 "-sharpen geometry sharpen the image",
3333 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003334 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003335 "-sigmoidal-contrast geometry",
3336 " increase the contrast without saturating highlights or shadows",
3337 "-sketch geometry simulate a pencil sketch",
3338 "-solarize threshold negate all pixels above the threshold level",
3339 "-sparse-color method args",
3340 " fill in a image based on a few color points",
3341 "-splice geometry splice the background color into the image",
3342 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003343 "-statistic type radius",
3344 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003345 "-strip strip image of all profiles and comments",
3346 "-swirl degrees swirl image pixels about the center",
3347 "-threshold value threshold the image",
3348 "-thumbnail geometry create a thumbnail of the image",
3349 "-tile filename tile image when filling a graphic primitive",
3350 "-tint value tint the image with the fill color",
3351 "-transform affine transform image",
3352 "-transparent color make this color transparent within the image",
3353 "-transpose flip image vertically and rotate 90 degrees",
3354 "-transverse flop image horizontally and rotate 270 degrees",
3355 "-trim trim image edges",
3356 "-type type image type",
3357 "-unique-colors discard all but one of any pixel color",
3358 "-unsharp geometry sharpen the image",
3359 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003360 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003361 "-white-threshold value",
3362 " force all pixels above the threshold into white",
3363 (char *) NULL
3364 },
3365 *sequence_operators[]=
3366 {
cristy4285d782011-02-09 20:12:28 +00003367 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003368 "-clut apply a color lookup table to the image",
3369 "-coalesce merge a sequence of images",
3370 "-combine combine a sequence of images",
3371 "-composite composite image",
3372 "-crop geometry cut out a rectangular region of the image",
3373 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003374 "-evaluate-sequence operator",
3375 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003376 "-flatten flatten a sequence of images",
3377 "-fx expression apply mathematical expression to an image channel(s)",
3378 "-hald-clut apply a Hald color lookup table to the image",
3379 "-morph value morph an image sequence",
3380 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003381 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003382 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003383 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003384 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003385 "-write filename write images to this file",
3386 (char *) NULL
3387 },
3388 *settings[]=
3389 {
3390 "-adjoin join images into a single multi-image file",
3391 "-affine matrix affine transform matrix",
3392 "-alpha option activate, deactivate, reset, or set the alpha channel",
3393 "-antialias remove pixel-aliasing",
3394 "-authenticate password",
3395 " decipher image with this password",
3396 "-attenuate value lessen (or intensify) when adding noise to an image",
3397 "-background color background color",
3398 "-bias value add bias when convolving an image",
3399 "-black-point-compensation",
3400 " use black point compensation",
3401 "-blue-primary point chromaticity blue primary point",
3402 "-bordercolor color border color",
3403 "-caption string assign a caption to an image",
3404 "-channel type apply option to select image channels",
3405 "-colors value preferred number of colors in the image",
3406 "-colorspace type alternate image colorspace",
3407 "-comment string annotate image with comment",
3408 "-compose operator set image composite operator",
3409 "-compress type type of pixel compression when writing the image",
3410 "-define format:option",
3411 " define one or more image format options",
3412 "-delay value display the next image after pausing",
3413 "-density geometry horizontal and vertical density of the image",
3414 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003415 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003416 "-display server get image or font from this X server",
3417 "-dispose method layer disposal method",
3418 "-dither method apply error diffusion to image",
3419 "-encoding type text encoding type",
3420 "-endian type endianness (MSB or LSB) of the image",
3421 "-family name render text with this font family",
3422 "-fill color color to use when filling a graphic primitive",
3423 "-filter type use this filter when resizing an image",
3424 "-font name render text with this font",
3425 "-format \"string\" output formatted image characteristics",
3426 "-fuzz distance colors within this distance are considered equal",
3427 "-gravity type horizontal and vertical text placement",
3428 "-green-primary point chromaticity green primary point",
3429 "-intent type type of rendering intent when managing the image color",
3430 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003431 "-interline-spacing value",
3432 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003433 "-interpolate method pixel color interpolation method",
3434 "-interword-spacing value",
3435 " set the space between two words",
3436 "-kerning value set the space between two letters",
3437 "-label string assign a label to an image",
3438 "-limit type value pixel cache resource limit",
3439 "-loop iterations add Netscape loop extension to your GIF animation",
3440 "-mask filename associate a mask with the image",
3441 "-mattecolor color frame color",
3442 "-monitor monitor progress",
3443 "-orient type image orientation",
3444 "-page geometry size and location of an image canvas (setting)",
3445 "-ping efficiently determine image attributes",
3446 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003447 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003448 "-preview type image preview type",
3449 "-quality value JPEG/MIFF/PNG compression level",
3450 "-quiet suppress all warning messages",
3451 "-red-primary point chromaticity red primary point",
3452 "-regard-warnings pay attention to warning messages",
3453 "-remap filename transform image colors to match this set of colors",
3454 "-respect-parentheses settings remain in effect until parenthesis boundary",
3455 "-sampling-factor geometry",
3456 " horizontal and vertical sampling factor",
3457 "-scene value image scene number",
3458 "-seed value seed a new sequence of pseudo-random numbers",
3459 "-size geometry width and height of image",
3460 "-stretch type render text with this font stretch",
3461 "-stroke color graphic primitive stroke color",
3462 "-strokewidth value graphic primitive stroke width",
3463 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003464 "-synchronize synchronize image to storage device",
3465 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003466 "-texture filename name of texture to tile onto the image background",
3467 "-tile-offset geometry",
3468 " tile offset",
3469 "-treedepth value color tree depth",
3470 "-transparent-color color",
3471 " transparent color",
3472 "-undercolor color annotation bounding box color",
3473 "-units type the units of image resolution",
3474 "-verbose print detailed information about the image",
3475 "-view FlashPix viewing transforms",
3476 "-virtual-pixel method",
3477 " virtual pixel access method",
3478 "-weight type render text with this font weight",
3479 "-white-point point chromaticity white point",
3480 (char *) NULL
3481 },
3482 *stack_operators[]=
3483 {
anthonyb69c4b32011-03-23 04:37:44 +00003484 "-delete indexes delete the image from the image sequence",
3485 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003486 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003487 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003488 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003489 "-swap indexes swap two images in the image sequence",
3490 (char *) NULL
3491 };
3492
3493 const char
3494 **p;
3495
cristybb503372010-05-27 20:51:26 +00003496 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003497 (void) printf("Copyright: %s\n",GetMagickCopyright());
3498 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003499 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3500 GetClientName());
3501 (void) printf("\nImage Settings:\n");
3502 for (p=settings; *p != (char *) NULL; p++)
3503 (void) printf(" %s\n",*p);
3504 (void) printf("\nImage Operators:\n");
3505 for (p=operators; *p != (char *) NULL; p++)
3506 (void) printf(" %s\n",*p);
3507 (void) printf("\nImage Sequence Operators:\n");
3508 for (p=sequence_operators; *p != (char *) NULL; p++)
3509 (void) printf(" %s\n",*p);
3510 (void) printf("\nImage Stack Operators:\n");
3511 for (p=stack_operators; *p != (char *) NULL; p++)
3512 (void) printf(" %s\n",*p);
3513 (void) printf("\nMiscellaneous Options:\n");
3514 for (p=miscellaneous; *p != (char *) NULL; p++)
3515 (void) printf(" %s\n",*p);
3516 (void) printf(
3517 "\nBy default, the image format of `file' is determined by its magic\n");
3518 (void) printf(
3519 "number. To specify a particular image format, precede the filename\n");
3520 (void) printf(
3521 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3522 (void) printf(
3523 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3524 (void) printf("'-' for standard input or output.\n");
3525 return(MagickFalse);
3526}
3527
3528WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3529 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3530{
3531#define DestroyMogrify() \
3532{ \
3533 if (format != (char *) NULL) \
3534 format=DestroyString(format); \
3535 if (path != (char *) NULL) \
3536 path=DestroyString(path); \
3537 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003538 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003539 argv[i]=DestroyString(argv[i]); \
3540 argv=(char **) RelinquishMagickMemory(argv); \
3541}
3542#define ThrowMogrifyException(asperity,tag,option) \
3543{ \
3544 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3545 option); \
3546 DestroyMogrify(); \
3547 return(MagickFalse); \
3548}
3549#define ThrowMogrifyInvalidArgumentException(option,argument) \
3550{ \
3551 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3552 "InvalidArgument","`%s': %s",argument,option); \
3553 DestroyMogrify(); \
3554 return(MagickFalse); \
3555}
3556
3557 char
3558 *format,
3559 *option,
3560 *path;
3561
3562 Image
3563 *image;
3564
3565 ImageStack
3566 image_stack[MaxImageStackDepth+1];
3567
cristy3ed852e2009-09-05 21:47:34 +00003568 MagickBooleanType
3569 global_colormap;
3570
3571 MagickBooleanType
3572 fire,
cristyebbcfea2011-02-25 02:43:54 +00003573 pend,
3574 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003575
3576 MagickStatusType
3577 status;
3578
cristyebbcfea2011-02-25 02:43:54 +00003579 register ssize_t
3580 i;
3581
3582 ssize_t
3583 j,
3584 k;
3585
cristy3ed852e2009-09-05 21:47:34 +00003586 /*
3587 Set defaults.
3588 */
3589 assert(image_info != (ImageInfo *) NULL);
3590 assert(image_info->signature == MagickSignature);
3591 if (image_info->debug != MagickFalse)
3592 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3593 assert(exception != (ExceptionInfo *) NULL);
3594 if (argc == 2)
3595 {
3596 option=argv[1];
3597 if ((LocaleCompare("version",option+1) == 0) ||
3598 (LocaleCompare("-version",option+1) == 0))
3599 {
cristyb51dff52011-05-19 16:55:47 +00003600 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003601 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003602 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3603 GetMagickCopyright());
3604 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3605 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003606 return(MagickFalse);
3607 }
3608 }
3609 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003610 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003611 format=(char *) NULL;
3612 path=(char *) NULL;
3613 global_colormap=MagickFalse;
3614 k=0;
3615 j=1;
3616 NewImageStack();
3617 option=(char *) NULL;
3618 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003619 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003620 status=MagickTrue;
3621 /*
3622 Parse command line.
3623 */
3624 ReadCommandlLine(argc,&argv);
3625 status=ExpandFilenames(&argc,&argv);
3626 if (status == MagickFalse)
3627 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3628 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003629 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003630 {
3631 option=argv[i];
3632 if (LocaleCompare(option,"(") == 0)
3633 {
3634 FireImageStack(MagickFalse,MagickTrue,pend);
3635 if (k == MaxImageStackDepth)
3636 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3637 option);
3638 PushImageStack();
3639 continue;
3640 }
3641 if (LocaleCompare(option,")") == 0)
3642 {
3643 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3644 if (k == 0)
3645 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3646 PopImageStack();
3647 continue;
3648 }
cristy042ee782011-04-22 18:48:30 +00003649 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003650 {
3651 char
3652 backup_filename[MaxTextExtent],
3653 *filename;
3654
3655 Image
3656 *images;
3657
3658 /*
3659 Option is a file name: begin by reading image from specified file.
3660 */
3661 FireImageStack(MagickFalse,MagickFalse,pend);
3662 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003663 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003664 filename=argv[++i];
3665 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3666 images=ReadImages(image_info,exception);
3667 status&=(images != (Image *) NULL) &&
3668 (exception->severity < ErrorException);
3669 if (images == (Image *) NULL)
3670 continue;
cristydaa76602010-06-30 13:05:11 +00003671 if (format != (char *) NULL)
3672 (void) CopyMagickString(images->filename,images->magick_filename,
3673 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003674 if (path != (char *) NULL)
3675 {
3676 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003677 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003678 path,*DirectorySeparator,filename);
3679 }
3680 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003681 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003682 AppendImageStack(images);
3683 FinalizeImageSettings(image_info,image,MagickFalse);
3684 if (global_colormap != MagickFalse)
3685 {
3686 QuantizeInfo
3687 *quantize_info;
3688
3689 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003690 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003691 quantize_info=DestroyQuantizeInfo(quantize_info);
3692 }
3693 *backup_filename='\0';
3694 if ((LocaleCompare(image->filename,"-") != 0) &&
3695 (IsPathWritable(image->filename) != MagickFalse))
3696 {
cristybb503372010-05-27 20:51:26 +00003697 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003698 i;
3699
3700 /*
3701 Rename image file as backup.
3702 */
3703 (void) CopyMagickString(backup_filename,image->filename,
3704 MaxTextExtent);
3705 for (i=0; i < 6; i++)
3706 {
3707 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3708 if (IsPathAccessible(backup_filename) == MagickFalse)
3709 break;
3710 }
3711 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3712 (rename(image->filename,backup_filename) != 0))
3713 *backup_filename='\0';
3714 }
3715 /*
3716 Write transmogrified image to disk.
3717 */
3718 image_info->synchronize=MagickTrue;
3719 status&=WriteImages(image_info,image,image->filename,exception);
3720 if ((status == MagickFalse) && (*backup_filename != '\0'))
3721 (void) remove(backup_filename);
3722 RemoveAllImageStack();
3723 continue;
3724 }
3725 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3726 switch (*(option+1))
3727 {
3728 case 'a':
3729 {
3730 if (LocaleCompare("adaptive-blur",option+1) == 0)
3731 {
3732 i++;
cristybb503372010-05-27 20:51:26 +00003733 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003734 ThrowMogrifyException(OptionError,"MissingArgument",option);
3735 if (IsGeometry(argv[i]) == MagickFalse)
3736 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3737 break;
3738 }
3739 if (LocaleCompare("adaptive-resize",option+1) == 0)
3740 {
3741 i++;
cristybb503372010-05-27 20:51:26 +00003742 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003743 ThrowMogrifyException(OptionError,"MissingArgument",option);
3744 if (IsGeometry(argv[i]) == MagickFalse)
3745 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3746 break;
3747 }
3748 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3749 {
3750 i++;
cristybb503372010-05-27 20:51:26 +00003751 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003752 ThrowMogrifyException(OptionError,"MissingArgument",option);
3753 if (IsGeometry(argv[i]) == MagickFalse)
3754 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3755 break;
3756 }
3757 if (LocaleCompare("affine",option+1) == 0)
3758 {
3759 if (*option == '+')
3760 break;
3761 i++;
cristybb503372010-05-27 20:51:26 +00003762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003763 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003764 break;
3765 }
3766 if (LocaleCompare("alpha",option+1) == 0)
3767 {
cristybb503372010-05-27 20:51:26 +00003768 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003769 type;
3770
3771 if (*option == '+')
3772 break;
3773 i++;
cristybb503372010-05-27 20:51:26 +00003774 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003775 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003776 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003777 if (type < 0)
3778 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3779 argv[i]);
3780 break;
3781 }
3782 if (LocaleCompare("annotate",option+1) == 0)
3783 {
3784 if (*option == '+')
3785 break;
3786 i++;
cristybb503372010-05-27 20:51:26 +00003787 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003788 ThrowMogrifyException(OptionError,"MissingArgument",option);
3789 if (IsGeometry(argv[i]) == MagickFalse)
3790 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003791 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003792 ThrowMogrifyException(OptionError,"MissingArgument",option);
3793 i++;
3794 break;
3795 }
3796 if (LocaleCompare("antialias",option+1) == 0)
3797 break;
3798 if (LocaleCompare("append",option+1) == 0)
3799 break;
3800 if (LocaleCompare("attenuate",option+1) == 0)
3801 {
3802 if (*option == '+')
3803 break;
3804 i++;
cristybb503372010-05-27 20:51:26 +00003805 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003806 ThrowMogrifyException(OptionError,"MissingArgument",option);
3807 if (IsGeometry(argv[i]) == MagickFalse)
3808 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3809 break;
3810 }
3811 if (LocaleCompare("authenticate",option+1) == 0)
3812 {
3813 if (*option == '+')
3814 break;
3815 i++;
cristybb503372010-05-27 20:51:26 +00003816 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003817 ThrowMogrifyException(OptionError,"MissingArgument",option);
3818 break;
3819 }
3820 if (LocaleCompare("auto-gamma",option+1) == 0)
3821 break;
3822 if (LocaleCompare("auto-level",option+1) == 0)
3823 break;
3824 if (LocaleCompare("auto-orient",option+1) == 0)
3825 break;
3826 if (LocaleCompare("average",option+1) == 0)
3827 break;
3828 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3829 }
3830 case 'b':
3831 {
3832 if (LocaleCompare("background",option+1) == 0)
3833 {
3834 if (*option == '+')
3835 break;
3836 i++;
cristybb503372010-05-27 20:51:26 +00003837 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003838 ThrowMogrifyException(OptionError,"MissingArgument",option);
3839 break;
3840 }
3841 if (LocaleCompare("bias",option+1) == 0)
3842 {
3843 if (*option == '+')
3844 break;
3845 i++;
cristybb503372010-05-27 20:51:26 +00003846 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003847 ThrowMogrifyException(OptionError,"MissingArgument",option);
3848 if (IsGeometry(argv[i]) == MagickFalse)
3849 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3850 break;
3851 }
3852 if (LocaleCompare("black-point-compensation",option+1) == 0)
3853 break;
3854 if (LocaleCompare("black-threshold",option+1) == 0)
3855 {
3856 if (*option == '+')
3857 break;
3858 i++;
cristybb503372010-05-27 20:51:26 +00003859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003860 ThrowMogrifyException(OptionError,"MissingArgument",option);
3861 if (IsGeometry(argv[i]) == MagickFalse)
3862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3863 break;
3864 }
3865 if (LocaleCompare("blue-primary",option+1) == 0)
3866 {
3867 if (*option == '+')
3868 break;
3869 i++;
cristybb503372010-05-27 20:51:26 +00003870 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003871 ThrowMogrifyException(OptionError,"MissingArgument",option);
3872 if (IsGeometry(argv[i]) == MagickFalse)
3873 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3874 break;
3875 }
3876 if (LocaleCompare("blue-shift",option+1) == 0)
3877 {
3878 i++;
cristybb503372010-05-27 20:51:26 +00003879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003880 ThrowMogrifyException(OptionError,"MissingArgument",option);
3881 if (IsGeometry(argv[i]) == MagickFalse)
3882 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3883 break;
3884 }
3885 if (LocaleCompare("blur",option+1) == 0)
3886 {
3887 i++;
cristybb503372010-05-27 20:51:26 +00003888 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003889 ThrowMogrifyException(OptionError,"MissingArgument",option);
3890 if (IsGeometry(argv[i]) == MagickFalse)
3891 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3892 break;
3893 }
3894 if (LocaleCompare("border",option+1) == 0)
3895 {
3896 if (*option == '+')
3897 break;
3898 i++;
cristybb503372010-05-27 20:51:26 +00003899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003900 ThrowMogrifyException(OptionError,"MissingArgument",option);
3901 if (IsGeometry(argv[i]) == MagickFalse)
3902 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3903 break;
3904 }
3905 if (LocaleCompare("bordercolor",option+1) == 0)
3906 {
3907 if (*option == '+')
3908 break;
3909 i++;
cristybb503372010-05-27 20:51:26 +00003910 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003911 ThrowMogrifyException(OptionError,"MissingArgument",option);
3912 break;
3913 }
3914 if (LocaleCompare("box",option+1) == 0)
3915 {
3916 if (*option == '+')
3917 break;
3918 i++;
cristybb503372010-05-27 20:51:26 +00003919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003920 ThrowMogrifyException(OptionError,"MissingArgument",option);
3921 break;
3922 }
cristya28d6b82010-01-11 20:03:47 +00003923 if (LocaleCompare("brightness-contrast",option+1) == 0)
3924 {
3925 i++;
cristybb503372010-05-27 20:51:26 +00003926 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003927 ThrowMogrifyException(OptionError,"MissingArgument",option);
3928 if (IsGeometry(argv[i]) == MagickFalse)
3929 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3930 break;
3931 }
cristy3ed852e2009-09-05 21:47:34 +00003932 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3933 }
3934 case 'c':
3935 {
3936 if (LocaleCompare("cache",option+1) == 0)
3937 {
3938 if (*option == '+')
3939 break;
3940 i++;
cristybb503372010-05-27 20:51:26 +00003941 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003942 ThrowMogrifyException(OptionError,"MissingArgument",option);
3943 if (IsGeometry(argv[i]) == MagickFalse)
3944 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3945 break;
3946 }
3947 if (LocaleCompare("caption",option+1) == 0)
3948 {
3949 if (*option == '+')
3950 break;
3951 i++;
cristybb503372010-05-27 20:51:26 +00003952 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003953 ThrowMogrifyException(OptionError,"MissingArgument",option);
3954 break;
3955 }
3956 if (LocaleCompare("channel",option+1) == 0)
3957 {
cristybb503372010-05-27 20:51:26 +00003958 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003959 channel;
3960
3961 if (*option == '+')
3962 break;
3963 i++;
cristybb503372010-05-27 20:51:26 +00003964 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003965 ThrowMogrifyException(OptionError,"MissingArgument",option);
3966 channel=ParseChannelOption(argv[i]);
3967 if (channel < 0)
3968 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3969 argv[i]);
3970 break;
3971 }
3972 if (LocaleCompare("cdl",option+1) == 0)
3973 {
3974 if (*option == '+')
3975 break;
3976 i++;
cristybb503372010-05-27 20:51:26 +00003977 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003978 ThrowMogrifyException(OptionError,"MissingArgument",option);
3979 break;
3980 }
3981 if (LocaleCompare("charcoal",option+1) == 0)
3982 {
3983 if (*option == '+')
3984 break;
3985 i++;
cristybb503372010-05-27 20:51:26 +00003986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003987 ThrowMogrifyException(OptionError,"MissingArgument",option);
3988 if (IsGeometry(argv[i]) == MagickFalse)
3989 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3990 break;
3991 }
3992 if (LocaleCompare("chop",option+1) == 0)
3993 {
3994 if (*option == '+')
3995 break;
3996 i++;
cristybb503372010-05-27 20:51:26 +00003997 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003998 ThrowMogrifyException(OptionError,"MissingArgument",option);
3999 if (IsGeometry(argv[i]) == MagickFalse)
4000 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4001 break;
4002 }
cristy1eb45dd2009-09-25 16:38:06 +00004003 if (LocaleCompare("clamp",option+1) == 0)
4004 break;
4005 if (LocaleCompare("clip",option+1) == 0)
4006 break;
cristy3ed852e2009-09-05 21:47:34 +00004007 if (LocaleCompare("clip-mask",option+1) == 0)
4008 {
4009 if (*option == '+')
4010 break;
4011 i++;
cristybb503372010-05-27 20:51:26 +00004012 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004013 ThrowMogrifyException(OptionError,"MissingArgument",option);
4014 break;
4015 }
4016 if (LocaleCompare("clut",option+1) == 0)
4017 break;
4018 if (LocaleCompare("coalesce",option+1) == 0)
4019 break;
4020 if (LocaleCompare("colorize",option+1) == 0)
4021 {
4022 if (*option == '+')
4023 break;
4024 i++;
cristybb503372010-05-27 20:51:26 +00004025 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004026 ThrowMogrifyException(OptionError,"MissingArgument",option);
4027 if (IsGeometry(argv[i]) == MagickFalse)
4028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4029 break;
4030 }
cristye6365592010-04-02 17:31:23 +00004031 if (LocaleCompare("color-matrix",option+1) == 0)
4032 {
cristyb6bd4ad2010-08-08 01:12:27 +00004033 KernelInfo
4034 *kernel_info;
4035
cristye6365592010-04-02 17:31:23 +00004036 if (*option == '+')
4037 break;
4038 i++;
cristybb503372010-05-27 20:51:26 +00004039 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004040 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004041 kernel_info=AcquireKernelInfo(argv[i]);
4042 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004043 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004044 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004045 break;
4046 }
cristy3ed852e2009-09-05 21:47:34 +00004047 if (LocaleCompare("colors",option+1) == 0)
4048 {
4049 if (*option == '+')
4050 break;
4051 i++;
cristybb503372010-05-27 20:51:26 +00004052 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004053 ThrowMogrifyException(OptionError,"MissingArgument",option);
4054 if (IsGeometry(argv[i]) == MagickFalse)
4055 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4056 break;
4057 }
4058 if (LocaleCompare("colorspace",option+1) == 0)
4059 {
cristybb503372010-05-27 20:51:26 +00004060 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004061 colorspace;
4062
4063 if (*option == '+')
4064 break;
4065 i++;
cristybb503372010-05-27 20:51:26 +00004066 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004067 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004068 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004069 argv[i]);
4070 if (colorspace < 0)
4071 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4072 argv[i]);
4073 break;
4074 }
4075 if (LocaleCompare("combine",option+1) == 0)
4076 break;
4077 if (LocaleCompare("comment",option+1) == 0)
4078 {
4079 if (*option == '+')
4080 break;
4081 i++;
cristybb503372010-05-27 20:51:26 +00004082 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004083 ThrowMogrifyException(OptionError,"MissingArgument",option);
4084 break;
4085 }
4086 if (LocaleCompare("composite",option+1) == 0)
4087 break;
4088 if (LocaleCompare("compress",option+1) == 0)
4089 {
cristybb503372010-05-27 20:51:26 +00004090 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004091 compress;
4092
4093 if (*option == '+')
4094 break;
4095 i++;
cristybb503372010-05-27 20:51:26 +00004096 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004097 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004098 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004099 argv[i]);
4100 if (compress < 0)
4101 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4102 argv[i]);
4103 break;
4104 }
cristy22879752009-10-25 23:55:40 +00004105 if (LocaleCompare("concurrent",option+1) == 0)
4106 break;
cristy3ed852e2009-09-05 21:47:34 +00004107 if (LocaleCompare("contrast",option+1) == 0)
4108 break;
4109 if (LocaleCompare("contrast-stretch",option+1) == 0)
4110 {
4111 i++;
cristybb503372010-05-27 20:51:26 +00004112 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004113 ThrowMogrifyException(OptionError,"MissingArgument",option);
4114 if (IsGeometry(argv[i]) == MagickFalse)
4115 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4116 break;
4117 }
4118 if (LocaleCompare("convolve",option+1) == 0)
4119 {
cristyb6bd4ad2010-08-08 01:12:27 +00004120 KernelInfo
4121 *kernel_info;
4122
cristy3ed852e2009-09-05 21:47:34 +00004123 if (*option == '+')
4124 break;
4125 i++;
cristybb503372010-05-27 20:51:26 +00004126 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004127 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004128 kernel_info=AcquireKernelInfo(argv[i]);
4129 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004130 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004131 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004132 break;
4133 }
4134 if (LocaleCompare("crop",option+1) == 0)
4135 {
4136 if (*option == '+')
4137 break;
4138 i++;
cristybb503372010-05-27 20:51:26 +00004139 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004140 ThrowMogrifyException(OptionError,"MissingArgument",option);
4141 if (IsGeometry(argv[i]) == MagickFalse)
4142 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4143 break;
4144 }
4145 if (LocaleCompare("cycle",option+1) == 0)
4146 {
4147 if (*option == '+')
4148 break;
4149 i++;
cristybb503372010-05-27 20:51:26 +00004150 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004151 ThrowMogrifyException(OptionError,"MissingArgument",option);
4152 if (IsGeometry(argv[i]) == MagickFalse)
4153 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4154 break;
4155 }
4156 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4157 }
4158 case 'd':
4159 {
4160 if (LocaleCompare("decipher",option+1) == 0)
4161 {
4162 if (*option == '+')
4163 break;
4164 i++;
cristybb503372010-05-27 20:51:26 +00004165 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004166 ThrowMogrifyException(OptionError,"MissingArgument",option);
4167 break;
4168 }
4169 if (LocaleCompare("deconstruct",option+1) == 0)
4170 break;
4171 if (LocaleCompare("debug",option+1) == 0)
4172 {
cristybb503372010-05-27 20:51:26 +00004173 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004174 event;
4175
4176 if (*option == '+')
4177 break;
4178 i++;
cristybb503372010-05-27 20:51:26 +00004179 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004180 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004181 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004182 if (event < 0)
4183 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4184 argv[i]);
4185 (void) SetLogEventMask(argv[i]);
4186 break;
4187 }
4188 if (LocaleCompare("define",option+1) == 0)
4189 {
4190 i++;
cristybb503372010-05-27 20:51:26 +00004191 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004192 ThrowMogrifyException(OptionError,"MissingArgument",option);
4193 if (*option == '+')
4194 {
4195 const char
4196 *define;
4197
4198 define=GetImageOption(image_info,argv[i]);
4199 if (define == (const char *) NULL)
4200 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4201 break;
4202 }
4203 break;
4204 }
4205 if (LocaleCompare("delay",option+1) == 0)
4206 {
4207 if (*option == '+')
4208 break;
4209 i++;
cristybb503372010-05-27 20:51:26 +00004210 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004211 ThrowMogrifyException(OptionError,"MissingArgument",option);
4212 if (IsGeometry(argv[i]) == MagickFalse)
4213 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4214 break;
4215 }
cristyecb10ff2011-03-22 13:14:03 +00004216 if (LocaleCompare("delete",option+1) == 0)
4217 {
4218 if (*option == '+')
4219 break;
4220 i++;
4221 if (i == (ssize_t) (argc-1))
4222 ThrowMogrifyException(OptionError,"MissingArgument",option);
4223 if (IsGeometry(argv[i]) == MagickFalse)
4224 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4225 break;
4226 }
cristy3ed852e2009-09-05 21:47:34 +00004227 if (LocaleCompare("density",option+1) == 0)
4228 {
4229 if (*option == '+')
4230 break;
4231 i++;
cristybb503372010-05-27 20:51:26 +00004232 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004233 ThrowMogrifyException(OptionError,"MissingArgument",option);
4234 if (IsGeometry(argv[i]) == MagickFalse)
4235 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4236 break;
4237 }
4238 if (LocaleCompare("depth",option+1) == 0)
4239 {
4240 if (*option == '+')
4241 break;
4242 i++;
cristybb503372010-05-27 20:51:26 +00004243 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004244 ThrowMogrifyException(OptionError,"MissingArgument",option);
4245 if (IsGeometry(argv[i]) == MagickFalse)
4246 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4247 break;
4248 }
4249 if (LocaleCompare("deskew",option+1) == 0)
4250 {
4251 if (*option == '+')
4252 break;
4253 i++;
cristybb503372010-05-27 20:51:26 +00004254 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004255 ThrowMogrifyException(OptionError,"MissingArgument",option);
4256 if (IsGeometry(argv[i]) == MagickFalse)
4257 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4258 break;
4259 }
4260 if (LocaleCompare("despeckle",option+1) == 0)
4261 break;
4262 if (LocaleCompare("dft",option+1) == 0)
4263 break;
cristyc9b12952010-03-28 01:12:28 +00004264 if (LocaleCompare("direction",option+1) == 0)
4265 {
cristybb503372010-05-27 20:51:26 +00004266 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004267 direction;
4268
4269 if (*option == '+')
4270 break;
4271 i++;
cristybb503372010-05-27 20:51:26 +00004272 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004273 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004274 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004275 argv[i]);
4276 if (direction < 0)
4277 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4278 argv[i]);
4279 break;
4280 }
cristy3ed852e2009-09-05 21:47:34 +00004281 if (LocaleCompare("display",option+1) == 0)
4282 {
4283 if (*option == '+')
4284 break;
4285 i++;
cristybb503372010-05-27 20:51:26 +00004286 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004287 ThrowMogrifyException(OptionError,"MissingArgument",option);
4288 break;
4289 }
4290 if (LocaleCompare("dispose",option+1) == 0)
4291 {
cristybb503372010-05-27 20:51:26 +00004292 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004293 dispose;
4294
4295 if (*option == '+')
4296 break;
4297 i++;
cristybb503372010-05-27 20:51:26 +00004298 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004299 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004300 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004301 if (dispose < 0)
4302 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4303 argv[i]);
4304 break;
4305 }
4306 if (LocaleCompare("distort",option+1) == 0)
4307 {
cristybb503372010-05-27 20:51:26 +00004308 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004309 op;
4310
4311 i++;
cristybb503372010-05-27 20:51:26 +00004312 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004313 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004314 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004315 if (op < 0)
4316 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4317 argv[i]);
4318 i++;
cristybb503372010-05-27 20:51:26 +00004319 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004320 ThrowMogrifyException(OptionError,"MissingArgument",option);
4321 break;
4322 }
4323 if (LocaleCompare("dither",option+1) == 0)
4324 {
cristybb503372010-05-27 20:51:26 +00004325 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004326 method;
4327
4328 if (*option == '+')
4329 break;
4330 i++;
cristybb503372010-05-27 20:51:26 +00004331 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004332 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004333 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004334 if (method < 0)
4335 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4336 argv[i]);
4337 break;
4338 }
4339 if (LocaleCompare("draw",option+1) == 0)
4340 {
4341 if (*option == '+')
4342 break;
4343 i++;
cristybb503372010-05-27 20:51:26 +00004344 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004345 ThrowMogrifyException(OptionError,"MissingArgument",option);
4346 break;
4347 }
cristyecb10ff2011-03-22 13:14:03 +00004348 if (LocaleCompare("duplicate",option+1) == 0)
4349 {
4350 if (*option == '+')
4351 break;
4352 i++;
4353 if (i == (ssize_t) (argc-1))
4354 ThrowMogrifyException(OptionError,"MissingArgument",option);
4355 if (IsGeometry(argv[i]) == MagickFalse)
4356 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4357 break;
4358 }
cristy22879752009-10-25 23:55:40 +00004359 if (LocaleCompare("duration",option+1) == 0)
4360 {
4361 if (*option == '+')
4362 break;
4363 i++;
cristybb503372010-05-27 20:51:26 +00004364 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004365 ThrowMogrifyException(OptionError,"MissingArgument",option);
4366 if (IsGeometry(argv[i]) == MagickFalse)
4367 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4368 break;
4369 }
cristy3ed852e2009-09-05 21:47:34 +00004370 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4371 }
4372 case 'e':
4373 {
4374 if (LocaleCompare("edge",option+1) == 0)
4375 {
4376 if (*option == '+')
4377 break;
4378 i++;
cristybb503372010-05-27 20:51:26 +00004379 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004380 ThrowMogrifyException(OptionError,"MissingArgument",option);
4381 if (IsGeometry(argv[i]) == MagickFalse)
4382 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4383 break;
4384 }
4385 if (LocaleCompare("emboss",option+1) == 0)
4386 {
4387 if (*option == '+')
4388 break;
4389 i++;
cristybb503372010-05-27 20:51:26 +00004390 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004391 ThrowMogrifyException(OptionError,"MissingArgument",option);
4392 if (IsGeometry(argv[i]) == MagickFalse)
4393 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4394 break;
4395 }
4396 if (LocaleCompare("encipher",option+1) == 0)
4397 {
4398 if (*option == '+')
4399 break;
4400 i++;
cristybb503372010-05-27 20:51:26 +00004401 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004402 ThrowMogrifyException(OptionError,"MissingArgument",option);
4403 break;
4404 }
4405 if (LocaleCompare("encoding",option+1) == 0)
4406 {
4407 if (*option == '+')
4408 break;
4409 i++;
cristybb503372010-05-27 20:51:26 +00004410 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004411 ThrowMogrifyException(OptionError,"MissingArgument",option);
4412 break;
4413 }
4414 if (LocaleCompare("endian",option+1) == 0)
4415 {
cristybb503372010-05-27 20:51:26 +00004416 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004417 endian;
4418
4419 if (*option == '+')
4420 break;
4421 i++;
cristybb503372010-05-27 20:51:26 +00004422 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004423 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004424 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004425 if (endian < 0)
4426 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4427 argv[i]);
4428 break;
4429 }
4430 if (LocaleCompare("enhance",option+1) == 0)
4431 break;
4432 if (LocaleCompare("equalize",option+1) == 0)
4433 break;
4434 if (LocaleCompare("evaluate",option+1) == 0)
4435 {
cristybb503372010-05-27 20:51:26 +00004436 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004437 op;
4438
4439 if (*option == '+')
4440 break;
4441 i++;
cristybb503372010-05-27 20:51:26 +00004442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004443 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004444 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004445 if (op < 0)
4446 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4447 argv[i]);
4448 i++;
cristybb503372010-05-27 20:51:26 +00004449 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004450 ThrowMogrifyException(OptionError,"MissingArgument",option);
4451 if (IsGeometry(argv[i]) == MagickFalse)
4452 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4453 break;
4454 }
cristyd18ae7c2010-03-07 17:39:52 +00004455 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4456 {
cristybb503372010-05-27 20:51:26 +00004457 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004458 op;
4459
4460 if (*option == '+')
4461 break;
4462 i++;
cristybb503372010-05-27 20:51:26 +00004463 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004464 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004465 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004466 if (op < 0)
4467 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4468 argv[i]);
4469 break;
4470 }
cristy3ed852e2009-09-05 21:47:34 +00004471 if (LocaleCompare("extent",option+1) == 0)
4472 {
4473 if (*option == '+')
4474 break;
4475 i++;
cristybb503372010-05-27 20:51:26 +00004476 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004477 ThrowMogrifyException(OptionError,"MissingArgument",option);
4478 if (IsGeometry(argv[i]) == MagickFalse)
4479 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4480 break;
4481 }
4482 if (LocaleCompare("extract",option+1) == 0)
4483 {
4484 if (*option == '+')
4485 break;
4486 i++;
cristybb503372010-05-27 20:51:26 +00004487 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004488 ThrowMogrifyException(OptionError,"MissingArgument",option);
4489 if (IsGeometry(argv[i]) == MagickFalse)
4490 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4491 break;
4492 }
4493 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4494 }
4495 case 'f':
4496 {
4497 if (LocaleCompare("family",option+1) == 0)
4498 {
4499 if (*option == '+')
4500 break;
4501 i++;
cristybb503372010-05-27 20:51:26 +00004502 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004503 ThrowMogrifyException(OptionError,"MissingArgument",option);
4504 break;
4505 }
4506 if (LocaleCompare("fill",option+1) == 0)
4507 {
4508 if (*option == '+')
4509 break;
4510 i++;
cristybb503372010-05-27 20:51:26 +00004511 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004512 ThrowMogrifyException(OptionError,"MissingArgument",option);
4513 break;
4514 }
4515 if (LocaleCompare("filter",option+1) == 0)
4516 {
cristybb503372010-05-27 20:51:26 +00004517 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004518 filter;
4519
4520 if (*option == '+')
4521 break;
4522 i++;
cristybb503372010-05-27 20:51:26 +00004523 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004524 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004525 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004526 if (filter < 0)
4527 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4528 argv[i]);
4529 break;
4530 }
4531 if (LocaleCompare("flatten",option+1) == 0)
4532 break;
4533 if (LocaleCompare("flip",option+1) == 0)
4534 break;
4535 if (LocaleCompare("flop",option+1) == 0)
4536 break;
4537 if (LocaleCompare("floodfill",option+1) == 0)
4538 {
4539 if (*option == '+')
4540 break;
4541 i++;
cristybb503372010-05-27 20:51:26 +00004542 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004543 ThrowMogrifyException(OptionError,"MissingArgument",option);
4544 if (IsGeometry(argv[i]) == MagickFalse)
4545 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4546 i++;
cristybb503372010-05-27 20:51:26 +00004547 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004548 ThrowMogrifyException(OptionError,"MissingArgument",option);
4549 break;
4550 }
4551 if (LocaleCompare("font",option+1) == 0)
4552 {
4553 if (*option == '+')
4554 break;
4555 i++;
cristybb503372010-05-27 20:51:26 +00004556 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004557 ThrowMogrifyException(OptionError,"MissingArgument",option);
4558 break;
4559 }
4560 if (LocaleCompare("format",option+1) == 0)
4561 {
4562 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4563 (void) CloneString(&format,(char *) NULL);
4564 if (*option == '+')
4565 break;
4566 i++;
cristybb503372010-05-27 20:51:26 +00004567 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004568 ThrowMogrifyException(OptionError,"MissingArgument",option);
4569 (void) CloneString(&format,argv[i]);
4570 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4571 (void) ConcatenateMagickString(image_info->filename,":",
4572 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004573 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004574 if (*image_info->magick == '\0')
4575 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4576 format);
4577 break;
4578 }
4579 if (LocaleCompare("frame",option+1) == 0)
4580 {
4581 if (*option == '+')
4582 break;
4583 i++;
cristybb503372010-05-27 20:51:26 +00004584 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004585 ThrowMogrifyException(OptionError,"MissingArgument",option);
4586 if (IsGeometry(argv[i]) == MagickFalse)
4587 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4588 break;
4589 }
4590 if (LocaleCompare("function",option+1) == 0)
4591 {
cristybb503372010-05-27 20:51:26 +00004592 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004593 op;
4594
4595 if (*option == '+')
4596 break;
4597 i++;
cristybb503372010-05-27 20:51:26 +00004598 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004599 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004600 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004601 if (op < 0)
4602 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4603 i++;
cristybb503372010-05-27 20:51:26 +00004604 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004605 ThrowMogrifyException(OptionError,"MissingArgument",option);
4606 break;
4607 }
4608 if (LocaleCompare("fuzz",option+1) == 0)
4609 {
4610 if (*option == '+')
4611 break;
4612 i++;
cristybb503372010-05-27 20:51:26 +00004613 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004614 ThrowMogrifyException(OptionError,"MissingArgument",option);
4615 if (IsGeometry(argv[i]) == MagickFalse)
4616 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4617 break;
4618 }
4619 if (LocaleCompare("fx",option+1) == 0)
4620 {
4621 if (*option == '+')
4622 break;
4623 i++;
cristybb503372010-05-27 20:51:26 +00004624 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004625 ThrowMogrifyException(OptionError,"MissingArgument",option);
4626 break;
4627 }
4628 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4629 }
4630 case 'g':
4631 {
4632 if (LocaleCompare("gamma",option+1) == 0)
4633 {
4634 i++;
cristybb503372010-05-27 20:51:26 +00004635 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004636 ThrowMogrifyException(OptionError,"MissingArgument",option);
4637 if (IsGeometry(argv[i]) == MagickFalse)
4638 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4639 break;
4640 }
4641 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4642 (LocaleCompare("gaussian",option+1) == 0))
4643 {
4644 i++;
cristybb503372010-05-27 20:51:26 +00004645 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004646 ThrowMogrifyException(OptionError,"MissingArgument",option);
4647 if (IsGeometry(argv[i]) == MagickFalse)
4648 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4649 break;
4650 }
4651 if (LocaleCompare("geometry",option+1) == 0)
4652 {
4653 if (*option == '+')
4654 break;
4655 i++;
cristybb503372010-05-27 20:51:26 +00004656 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004657 ThrowMogrifyException(OptionError,"MissingArgument",option);
4658 if (IsGeometry(argv[i]) == MagickFalse)
4659 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4660 break;
4661 }
4662 if (LocaleCompare("gravity",option+1) == 0)
4663 {
cristybb503372010-05-27 20:51:26 +00004664 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004665 gravity;
4666
4667 if (*option == '+')
4668 break;
4669 i++;
cristybb503372010-05-27 20:51:26 +00004670 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004671 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004672 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004673 if (gravity < 0)
4674 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4675 argv[i]);
4676 break;
4677 }
4678 if (LocaleCompare("green-primary",option+1) == 0)
4679 {
4680 if (*option == '+')
4681 break;
4682 i++;
cristybb503372010-05-27 20:51:26 +00004683 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004684 ThrowMogrifyException(OptionError,"MissingArgument",option);
4685 if (IsGeometry(argv[i]) == MagickFalse)
4686 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4687 break;
4688 }
4689 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4690 }
4691 case 'h':
4692 {
4693 if (LocaleCompare("hald-clut",option+1) == 0)
4694 break;
4695 if ((LocaleCompare("help",option+1) == 0) ||
4696 (LocaleCompare("-help",option+1) == 0))
4697 return(MogrifyUsage());
4698 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4699 }
4700 case 'i':
4701 {
4702 if (LocaleCompare("identify",option+1) == 0)
4703 break;
4704 if (LocaleCompare("idft",option+1) == 0)
4705 break;
4706 if (LocaleCompare("implode",option+1) == 0)
4707 {
4708 if (*option == '+')
4709 break;
4710 i++;
cristybb503372010-05-27 20:51:26 +00004711 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004712 ThrowMogrifyException(OptionError,"MissingArgument",option);
4713 if (IsGeometry(argv[i]) == MagickFalse)
4714 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4715 break;
4716 }
4717 if (LocaleCompare("intent",option+1) == 0)
4718 {
cristybb503372010-05-27 20:51:26 +00004719 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004720 intent;
4721
4722 if (*option == '+')
4723 break;
4724 i++;
cristybb503372010-05-27 20:51:26 +00004725 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004726 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004727 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004728 if (intent < 0)
4729 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4730 argv[i]);
4731 break;
4732 }
4733 if (LocaleCompare("interlace",option+1) == 0)
4734 {
cristybb503372010-05-27 20:51:26 +00004735 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004736 interlace;
4737
4738 if (*option == '+')
4739 break;
4740 i++;
cristybb503372010-05-27 20:51:26 +00004741 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004742 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004743 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004744 argv[i]);
4745 if (interlace < 0)
4746 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4747 argv[i]);
4748 break;
4749 }
cristyb32b90a2009-09-07 21:45:48 +00004750 if (LocaleCompare("interline-spacing",option+1) == 0)
4751 {
4752 if (*option == '+')
4753 break;
4754 i++;
cristybb503372010-05-27 20:51:26 +00004755 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004756 ThrowMogrifyException(OptionError,"MissingArgument",option);
4757 if (IsGeometry(argv[i]) == MagickFalse)
4758 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4759 break;
4760 }
cristy3ed852e2009-09-05 21:47:34 +00004761 if (LocaleCompare("interpolate",option+1) == 0)
4762 {
cristybb503372010-05-27 20:51:26 +00004763 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004764 interpolate;
4765
4766 if (*option == '+')
4767 break;
4768 i++;
cristybb503372010-05-27 20:51:26 +00004769 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004770 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004771 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004772 argv[i]);
4773 if (interpolate < 0)
4774 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4775 argv[i]);
4776 break;
4777 }
4778 if (LocaleCompare("interword-spacing",option+1) == 0)
4779 {
4780 if (*option == '+')
4781 break;
4782 i++;
cristybb503372010-05-27 20:51:26 +00004783 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004784 ThrowMogrifyException(OptionError,"MissingArgument",option);
4785 if (IsGeometry(argv[i]) == MagickFalse)
4786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4787 break;
4788 }
4789 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4790 }
4791 case 'k':
4792 {
4793 if (LocaleCompare("kerning",option+1) == 0)
4794 {
4795 if (*option == '+')
4796 break;
4797 i++;
cristybb503372010-05-27 20:51:26 +00004798 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004799 ThrowMogrifyException(OptionError,"MissingArgument",option);
4800 if (IsGeometry(argv[i]) == MagickFalse)
4801 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4802 break;
4803 }
4804 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4805 }
4806 case 'l':
4807 {
4808 if (LocaleCompare("label",option+1) == 0)
4809 {
4810 if (*option == '+')
4811 break;
4812 i++;
cristybb503372010-05-27 20:51:26 +00004813 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004814 ThrowMogrifyException(OptionError,"MissingArgument",option);
4815 break;
4816 }
4817 if (LocaleCompare("lat",option+1) == 0)
4818 {
4819 if (*option == '+')
4820 break;
4821 i++;
cristybb503372010-05-27 20:51:26 +00004822 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004823 ThrowMogrifyException(OptionError,"MissingArgument",option);
4824 if (IsGeometry(argv[i]) == MagickFalse)
4825 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4826 }
4827 if (LocaleCompare("layers",option+1) == 0)
4828 {
cristybb503372010-05-27 20:51:26 +00004829 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004830 type;
4831
4832 if (*option == '+')
4833 break;
4834 i++;
cristybb503372010-05-27 20:51:26 +00004835 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004836 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004837 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004838 if (type < 0)
4839 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4840 argv[i]);
4841 break;
4842 }
4843 if (LocaleCompare("level",option+1) == 0)
4844 {
4845 i++;
cristybb503372010-05-27 20:51:26 +00004846 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004847 ThrowMogrifyException(OptionError,"MissingArgument",option);
4848 if (IsGeometry(argv[i]) == MagickFalse)
4849 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4850 break;
4851 }
4852 if (LocaleCompare("level-colors",option+1) == 0)
4853 {
4854 i++;
cristybb503372010-05-27 20:51:26 +00004855 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004856 ThrowMogrifyException(OptionError,"MissingArgument",option);
4857 break;
4858 }
4859 if (LocaleCompare("linewidth",option+1) == 0)
4860 {
4861 if (*option == '+')
4862 break;
4863 i++;
cristybb503372010-05-27 20:51:26 +00004864 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004865 ThrowMogrifyException(OptionError,"MissingArgument",option);
4866 if (IsGeometry(argv[i]) == MagickFalse)
4867 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4868 break;
4869 }
4870 if (LocaleCompare("limit",option+1) == 0)
4871 {
4872 char
4873 *p;
4874
4875 double
4876 value;
4877
cristybb503372010-05-27 20:51:26 +00004878 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004879 resource;
4880
4881 if (*option == '+')
4882 break;
4883 i++;
cristybb503372010-05-27 20:51:26 +00004884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004885 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004886 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004887 argv[i]);
4888 if (resource < 0)
4889 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4890 argv[i]);
4891 i++;
cristybb503372010-05-27 20:51:26 +00004892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004893 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004894 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004895 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004896 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4897 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4898 break;
4899 }
4900 if (LocaleCompare("liquid-rescale",option+1) == 0)
4901 {
4902 i++;
cristybb503372010-05-27 20:51:26 +00004903 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004904 ThrowMogrifyException(OptionError,"MissingArgument",option);
4905 if (IsGeometry(argv[i]) == MagickFalse)
4906 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4907 break;
4908 }
4909 if (LocaleCompare("list",option+1) == 0)
4910 {
cristybb503372010-05-27 20:51:26 +00004911 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004912 list;
4913
4914 if (*option == '+')
4915 break;
4916 i++;
cristybb503372010-05-27 20:51:26 +00004917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004918 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004919 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004920 if (list < 0)
4921 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004922 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004923 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004924 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004925 }
4926 if (LocaleCompare("log",option+1) == 0)
4927 {
4928 if (*option == '+')
4929 break;
4930 i++;
cristybb503372010-05-27 20:51:26 +00004931 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004932 (strchr(argv[i],'%') == (char *) NULL))
4933 ThrowMogrifyException(OptionError,"MissingArgument",option);
4934 break;
4935 }
4936 if (LocaleCompare("loop",option+1) == 0)
4937 {
4938 if (*option == '+')
4939 break;
4940 i++;
cristybb503372010-05-27 20:51:26 +00004941 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004942 ThrowMogrifyException(OptionError,"MissingArgument",option);
4943 if (IsGeometry(argv[i]) == MagickFalse)
4944 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4945 break;
4946 }
4947 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4948 }
4949 case 'm':
4950 {
4951 if (LocaleCompare("map",option+1) == 0)
4952 {
4953 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4954 if (*option == '+')
4955 break;
4956 i++;
cristybb503372010-05-27 20:51:26 +00004957 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004958 ThrowMogrifyException(OptionError,"MissingArgument",option);
4959 break;
4960 }
4961 if (LocaleCompare("mask",option+1) == 0)
4962 {
4963 if (*option == '+')
4964 break;
4965 i++;
cristybb503372010-05-27 20:51:26 +00004966 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004967 ThrowMogrifyException(OptionError,"MissingArgument",option);
4968 break;
4969 }
4970 if (LocaleCompare("matte",option+1) == 0)
4971 break;
4972 if (LocaleCompare("mattecolor",option+1) == 0)
4973 {
4974 if (*option == '+')
4975 break;
4976 i++;
cristybb503372010-05-27 20:51:26 +00004977 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004978 ThrowMogrifyException(OptionError,"MissingArgument",option);
4979 break;
4980 }
cristyf40785b2010-03-06 02:27:27 +00004981 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004982 break;
cristyf40785b2010-03-06 02:27:27 +00004983 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004984 break;
cristy3ed852e2009-09-05 21:47:34 +00004985 if (LocaleCompare("modulate",option+1) == 0)
4986 {
4987 if (*option == '+')
4988 break;
4989 i++;
cristybb503372010-05-27 20:51:26 +00004990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004991 ThrowMogrifyException(OptionError,"MissingArgument",option);
4992 if (IsGeometry(argv[i]) == MagickFalse)
4993 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4994 break;
4995 }
4996 if (LocaleCompare("median",option+1) == 0)
4997 {
4998 if (*option == '+')
4999 break;
5000 i++;
cristybb503372010-05-27 20:51:26 +00005001 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005002 ThrowMogrifyException(OptionError,"MissingArgument",option);
5003 if (IsGeometry(argv[i]) == MagickFalse)
5004 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5005 break;
5006 }
cristy69ec32d2011-02-27 23:57:09 +00005007 if (LocaleCompare("mode",option+1) == 0)
5008 {
5009 if (*option == '+')
5010 break;
5011 i++;
5012 if (i == (ssize_t) argc)
5013 ThrowMogrifyException(OptionError,"MissingArgument",option);
5014 if (IsGeometry(argv[i]) == MagickFalse)
5015 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5016 break;
5017 }
cristy3ed852e2009-09-05 21:47:34 +00005018 if (LocaleCompare("monitor",option+1) == 0)
5019 break;
5020 if (LocaleCompare("monochrome",option+1) == 0)
5021 break;
5022 if (LocaleCompare("morph",option+1) == 0)
5023 {
5024 if (*option == '+')
5025 break;
5026 i++;
cristybb503372010-05-27 20:51:26 +00005027 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005028 ThrowMogrifyException(OptionError,"MissingArgument",option);
5029 if (IsGeometry(argv[i]) == MagickFalse)
5030 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5031 break;
5032 }
anthony29188a82010-01-22 10:12:34 +00005033 if (LocaleCompare("morphology",option+1) == 0)
5034 {
anthony29188a82010-01-22 10:12:34 +00005035 char
5036 token[MaxTextExtent];
5037
cristyb6bd4ad2010-08-08 01:12:27 +00005038 KernelInfo
5039 *kernel_info;
5040
5041 ssize_t
5042 op;
5043
anthony29188a82010-01-22 10:12:34 +00005044 i++;
cristybb503372010-05-27 20:51:26 +00005045 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005046 ThrowMogrifyException(OptionError,"MissingArgument",option);
5047 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005048 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005049 if (op < 0)
5050 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005051 token);
anthony29188a82010-01-22 10:12:34 +00005052 i++;
cristybb503372010-05-27 20:51:26 +00005053 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005054 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005055 kernel_info=AcquireKernelInfo(argv[i]);
5056 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005057 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005058 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005059 break;
5060 }
cristy3ed852e2009-09-05 21:47:34 +00005061 if (LocaleCompare("mosaic",option+1) == 0)
5062 break;
5063 if (LocaleCompare("motion-blur",option+1) == 0)
5064 {
5065 if (*option == '+')
5066 break;
5067 i++;
cristybb503372010-05-27 20:51:26 +00005068 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005069 ThrowMogrifyException(OptionError,"MissingArgument",option);
5070 if (IsGeometry(argv[i]) == MagickFalse)
5071 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5072 break;
5073 }
5074 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5075 }
5076 case 'n':
5077 {
5078 if (LocaleCompare("negate",option+1) == 0)
5079 break;
5080 if (LocaleCompare("noise",option+1) == 0)
5081 {
5082 i++;
cristybb503372010-05-27 20:51:26 +00005083 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005084 ThrowMogrifyException(OptionError,"MissingArgument",option);
5085 if (*option == '+')
5086 {
cristybb503372010-05-27 20:51:26 +00005087 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005088 noise;
5089
cristy042ee782011-04-22 18:48:30 +00005090 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005091 if (noise < 0)
5092 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5093 argv[i]);
5094 break;
5095 }
5096 if (IsGeometry(argv[i]) == MagickFalse)
5097 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5098 break;
5099 }
5100 if (LocaleCompare("noop",option+1) == 0)
5101 break;
5102 if (LocaleCompare("normalize",option+1) == 0)
5103 break;
5104 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5105 }
5106 case 'o':
5107 {
5108 if (LocaleCompare("opaque",option+1) == 0)
5109 {
cristy3ed852e2009-09-05 21:47:34 +00005110 i++;
cristybb503372010-05-27 20:51:26 +00005111 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005112 ThrowMogrifyException(OptionError,"MissingArgument",option);
5113 break;
5114 }
5115 if (LocaleCompare("ordered-dither",option+1) == 0)
5116 {
5117 if (*option == '+')
5118 break;
5119 i++;
cristybb503372010-05-27 20:51:26 +00005120 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005121 ThrowMogrifyException(OptionError,"MissingArgument",option);
5122 break;
5123 }
5124 if (LocaleCompare("orient",option+1) == 0)
5125 {
cristybb503372010-05-27 20:51:26 +00005126 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005127 orientation;
5128
5129 orientation=UndefinedOrientation;
5130 if (*option == '+')
5131 break;
5132 i++;
cristybb503372010-05-27 20:51:26 +00005133 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005134 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005135 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005136 argv[i]);
5137 if (orientation < 0)
5138 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5139 argv[i]);
5140 break;
5141 }
5142 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5143 }
5144 case 'p':
5145 {
5146 if (LocaleCompare("page",option+1) == 0)
5147 {
5148 if (*option == '+')
5149 break;
5150 i++;
cristybb503372010-05-27 20:51:26 +00005151 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005152 ThrowMogrifyException(OptionError,"MissingArgument",option);
5153 break;
5154 }
5155 if (LocaleCompare("paint",option+1) == 0)
5156 {
5157 if (*option == '+')
5158 break;
5159 i++;
cristybb503372010-05-27 20:51:26 +00005160 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005161 ThrowMogrifyException(OptionError,"MissingArgument",option);
5162 if (IsGeometry(argv[i]) == MagickFalse)
5163 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5164 break;
5165 }
5166 if (LocaleCompare("path",option+1) == 0)
5167 {
5168 (void) CloneString(&path,(char *) NULL);
5169 if (*option == '+')
5170 break;
5171 i++;
cristybb503372010-05-27 20:51:26 +00005172 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005173 ThrowMogrifyException(OptionError,"MissingArgument",option);
5174 (void) CloneString(&path,argv[i]);
5175 break;
5176 }
5177 if (LocaleCompare("pointsize",option+1) == 0)
5178 {
5179 if (*option == '+')
5180 break;
5181 i++;
cristybb503372010-05-27 20:51:26 +00005182 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005183 ThrowMogrifyException(OptionError,"MissingArgument",option);
5184 if (IsGeometry(argv[i]) == MagickFalse)
5185 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5186 break;
5187 }
5188 if (LocaleCompare("polaroid",option+1) == 0)
5189 {
5190 if (*option == '+')
5191 break;
5192 i++;
cristybb503372010-05-27 20:51:26 +00005193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005194 ThrowMogrifyException(OptionError,"MissingArgument",option);
5195 if (IsGeometry(argv[i]) == MagickFalse)
5196 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5197 break;
5198 }
5199 if (LocaleCompare("posterize",option+1) == 0)
5200 {
5201 if (*option == '+')
5202 break;
5203 i++;
cristybb503372010-05-27 20:51:26 +00005204 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005205 ThrowMogrifyException(OptionError,"MissingArgument",option);
5206 if (IsGeometry(argv[i]) == MagickFalse)
5207 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5208 break;
5209 }
cristye7f51092010-01-17 00:39:37 +00005210 if (LocaleCompare("precision",option+1) == 0)
5211 {
5212 if (*option == '+')
5213 break;
5214 i++;
cristybb503372010-05-27 20:51:26 +00005215 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005216 ThrowMogrifyException(OptionError,"MissingArgument",option);
5217 if (IsGeometry(argv[i]) == MagickFalse)
5218 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5219 break;
5220 }
cristy3ed852e2009-09-05 21:47:34 +00005221 if (LocaleCompare("print",option+1) == 0)
5222 {
5223 if (*option == '+')
5224 break;
5225 i++;
cristybb503372010-05-27 20:51:26 +00005226 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005227 ThrowMogrifyException(OptionError,"MissingArgument",option);
5228 break;
5229 }
5230 if (LocaleCompare("process",option+1) == 0)
5231 {
5232 if (*option == '+')
5233 break;
5234 i++;
cristybb503372010-05-27 20:51:26 +00005235 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005236 ThrowMogrifyException(OptionError,"MissingArgument",option);
5237 break;
5238 }
5239 if (LocaleCompare("profile",option+1) == 0)
5240 {
5241 i++;
cristybb503372010-05-27 20:51:26 +00005242 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005243 ThrowMogrifyException(OptionError,"MissingArgument",option);
5244 break;
5245 }
5246 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5247 }
5248 case 'q':
5249 {
5250 if (LocaleCompare("quality",option+1) == 0)
5251 {
5252 if (*option == '+')
5253 break;
5254 i++;
cristybb503372010-05-27 20:51:26 +00005255 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005256 ThrowMogrifyException(OptionError,"MissingArgument",option);
5257 if (IsGeometry(argv[i]) == MagickFalse)
5258 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5259 break;
5260 }
5261 if (LocaleCompare("quantize",option+1) == 0)
5262 {
cristybb503372010-05-27 20:51:26 +00005263 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005264 colorspace;
5265
5266 if (*option == '+')
5267 break;
5268 i++;
cristybb503372010-05-27 20:51:26 +00005269 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005270 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005271 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005272 argv[i]);
5273 if (colorspace < 0)
5274 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5275 argv[i]);
5276 break;
5277 }
5278 if (LocaleCompare("quiet",option+1) == 0)
5279 break;
5280 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5281 }
5282 case 'r':
5283 {
5284 if (LocaleCompare("radial-blur",option+1) == 0)
5285 {
5286 i++;
cristybb503372010-05-27 20:51:26 +00005287 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005288 ThrowMogrifyException(OptionError,"MissingArgument",option);
5289 if (IsGeometry(argv[i]) == MagickFalse)
5290 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5291 break;
5292 }
5293 if (LocaleCompare("raise",option+1) == 0)
5294 {
5295 i++;
cristybb503372010-05-27 20:51:26 +00005296 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005297 ThrowMogrifyException(OptionError,"MissingArgument",option);
5298 if (IsGeometry(argv[i]) == MagickFalse)
5299 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5300 break;
5301 }
5302 if (LocaleCompare("random-threshold",option+1) == 0)
5303 {
5304 if (*option == '+')
5305 break;
5306 i++;
cristybb503372010-05-27 20:51:26 +00005307 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005308 ThrowMogrifyException(OptionError,"MissingArgument",option);
5309 if (IsGeometry(argv[i]) == MagickFalse)
5310 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5311 break;
5312 }
cristye6365592010-04-02 17:31:23 +00005313 if (LocaleCompare("recolor",option+1) == 0)
5314 {
5315 if (*option == '+')
5316 break;
5317 i++;
cristybb503372010-05-27 20:51:26 +00005318 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005319 ThrowMogrifyException(OptionError,"MissingArgument",option);
5320 if (IsGeometry(argv[i]) == MagickFalse)
5321 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5322 break;
5323 }
cristy3ed852e2009-09-05 21:47:34 +00005324 if (LocaleCompare("red-primary",option+1) == 0)
5325 {
5326 if (*option == '+')
5327 break;
5328 i++;
cristybb503372010-05-27 20:51:26 +00005329 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005330 ThrowMogrifyException(OptionError,"MissingArgument",option);
5331 if (IsGeometry(argv[i]) == MagickFalse)
5332 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5333 }
cristy9f2083a2010-04-22 19:48:05 +00005334 if (LocaleCompare("regard-warnings",option+1) == 0)
5335 break;
cristy3ed852e2009-09-05 21:47:34 +00005336 if (LocaleCompare("region",option+1) == 0)
5337 {
5338 if (*option == '+')
5339 break;
5340 i++;
cristybb503372010-05-27 20:51:26 +00005341 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005342 ThrowMogrifyException(OptionError,"MissingArgument",option);
5343 if (IsGeometry(argv[i]) == MagickFalse)
5344 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5345 break;
5346 }
cristyf0c78232010-03-15 12:53:40 +00005347 if (LocaleCompare("remap",option+1) == 0)
5348 {
5349 if (*option == '+')
5350 break;
5351 i++;
cristybb503372010-05-27 20:51:26 +00005352 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005353 ThrowMogrifyException(OptionError,"MissingArgument",option);
5354 break;
5355 }
cristy3ed852e2009-09-05 21:47:34 +00005356 if (LocaleCompare("render",option+1) == 0)
5357 break;
5358 if (LocaleCompare("repage",option+1) == 0)
5359 {
5360 if (*option == '+')
5361 break;
5362 i++;
cristybb503372010-05-27 20:51:26 +00005363 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005364 ThrowMogrifyException(OptionError,"MissingArgument",option);
5365 if (IsGeometry(argv[i]) == MagickFalse)
5366 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5367 break;
5368 }
5369 if (LocaleCompare("resample",option+1) == 0)
5370 {
5371 if (*option == '+')
5372 break;
5373 i++;
cristybb503372010-05-27 20:51:26 +00005374 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005375 ThrowMogrifyException(OptionError,"MissingArgument",option);
5376 if (IsGeometry(argv[i]) == MagickFalse)
5377 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5378 break;
5379 }
5380 if (LocaleCompare("resize",option+1) == 0)
5381 {
5382 if (*option == '+')
5383 break;
5384 i++;
cristybb503372010-05-27 20:51:26 +00005385 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005386 ThrowMogrifyException(OptionError,"MissingArgument",option);
5387 if (IsGeometry(argv[i]) == MagickFalse)
5388 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5389 break;
5390 }
cristyebbcfea2011-02-25 02:43:54 +00005391 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5392 {
5393 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5394 break;
5395 }
cristy3ed852e2009-09-05 21:47:34 +00005396 if (LocaleCompare("reverse",option+1) == 0)
5397 break;
5398 if (LocaleCompare("roll",option+1) == 0)
5399 {
5400 if (*option == '+')
5401 break;
5402 i++;
cristybb503372010-05-27 20:51:26 +00005403 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005404 ThrowMogrifyException(OptionError,"MissingArgument",option);
5405 if (IsGeometry(argv[i]) == MagickFalse)
5406 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5407 break;
5408 }
5409 if (LocaleCompare("rotate",option+1) == 0)
5410 {
5411 i++;
cristybb503372010-05-27 20:51:26 +00005412 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005413 ThrowMogrifyException(OptionError,"MissingArgument",option);
5414 if (IsGeometry(argv[i]) == MagickFalse)
5415 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5416 break;
5417 }
5418 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5419 }
5420 case 's':
5421 {
5422 if (LocaleCompare("sample",option+1) == 0)
5423 {
5424 if (*option == '+')
5425 break;
5426 i++;
cristybb503372010-05-27 20:51:26 +00005427 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005428 ThrowMogrifyException(OptionError,"MissingArgument",option);
5429 if (IsGeometry(argv[i]) == MagickFalse)
5430 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5431 break;
5432 }
5433 if (LocaleCompare("sampling-factor",option+1) == 0)
5434 {
5435 if (*option == '+')
5436 break;
5437 i++;
cristybb503372010-05-27 20:51:26 +00005438 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005439 ThrowMogrifyException(OptionError,"MissingArgument",option);
5440 if (IsGeometry(argv[i]) == MagickFalse)
5441 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5442 break;
5443 }
5444 if (LocaleCompare("scale",option+1) == 0)
5445 {
5446 if (*option == '+')
5447 break;
5448 i++;
cristybb503372010-05-27 20:51:26 +00005449 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005450 ThrowMogrifyException(OptionError,"MissingArgument",option);
5451 if (IsGeometry(argv[i]) == MagickFalse)
5452 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5453 break;
5454 }
5455 if (LocaleCompare("scene",option+1) == 0)
5456 {
5457 if (*option == '+')
5458 break;
5459 i++;
cristybb503372010-05-27 20:51:26 +00005460 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005461 ThrowMogrifyException(OptionError,"MissingArgument",option);
5462 if (IsGeometry(argv[i]) == MagickFalse)
5463 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5464 break;
5465 }
5466 if (LocaleCompare("seed",option+1) == 0)
5467 {
5468 if (*option == '+')
5469 break;
5470 i++;
cristybb503372010-05-27 20:51:26 +00005471 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005472 ThrowMogrifyException(OptionError,"MissingArgument",option);
5473 if (IsGeometry(argv[i]) == MagickFalse)
5474 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5475 break;
5476 }
5477 if (LocaleCompare("segment",option+1) == 0)
5478 {
5479 if (*option == '+')
5480 break;
5481 i++;
cristybb503372010-05-27 20:51:26 +00005482 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005483 ThrowMogrifyException(OptionError,"MissingArgument",option);
5484 if (IsGeometry(argv[i]) == MagickFalse)
5485 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5486 break;
5487 }
5488 if (LocaleCompare("selective-blur",option+1) == 0)
5489 {
5490 i++;
cristybb503372010-05-27 20:51:26 +00005491 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005492 ThrowMogrifyException(OptionError,"MissingArgument",option);
5493 if (IsGeometry(argv[i]) == MagickFalse)
5494 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5495 break;
5496 }
5497 if (LocaleCompare("separate",option+1) == 0)
5498 break;
5499 if (LocaleCompare("sepia-tone",option+1) == 0)
5500 {
5501 if (*option == '+')
5502 break;
5503 i++;
cristybb503372010-05-27 20:51:26 +00005504 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005505 ThrowMogrifyException(OptionError,"MissingArgument",option);
5506 if (IsGeometry(argv[i]) == MagickFalse)
5507 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5508 break;
5509 }
5510 if (LocaleCompare("set",option+1) == 0)
5511 {
5512 i++;
cristybb503372010-05-27 20:51:26 +00005513 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005514 ThrowMogrifyException(OptionError,"MissingArgument",option);
5515 if (*option == '+')
5516 break;
5517 i++;
cristybb503372010-05-27 20:51:26 +00005518 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005519 ThrowMogrifyException(OptionError,"MissingArgument",option);
5520 break;
5521 }
5522 if (LocaleCompare("shade",option+1) == 0)
5523 {
5524 i++;
cristybb503372010-05-27 20:51:26 +00005525 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005526 ThrowMogrifyException(OptionError,"MissingArgument",option);
5527 if (IsGeometry(argv[i]) == MagickFalse)
5528 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5529 break;
5530 }
5531 if (LocaleCompare("shadow",option+1) == 0)
5532 {
5533 if (*option == '+')
5534 break;
5535 i++;
cristybb503372010-05-27 20:51:26 +00005536 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005537 ThrowMogrifyException(OptionError,"MissingArgument",option);
5538 if (IsGeometry(argv[i]) == MagickFalse)
5539 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5540 break;
5541 }
5542 if (LocaleCompare("sharpen",option+1) == 0)
5543 {
5544 i++;
cristybb503372010-05-27 20:51:26 +00005545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005546 ThrowMogrifyException(OptionError,"MissingArgument",option);
5547 if (IsGeometry(argv[i]) == MagickFalse)
5548 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5549 break;
5550 }
5551 if (LocaleCompare("shave",option+1) == 0)
5552 {
5553 if (*option == '+')
5554 break;
5555 i++;
cristybb503372010-05-27 20:51:26 +00005556 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005557 ThrowMogrifyException(OptionError,"MissingArgument",option);
5558 if (IsGeometry(argv[i]) == MagickFalse)
5559 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5560 break;
5561 }
5562 if (LocaleCompare("shear",option+1) == 0)
5563 {
5564 i++;
cristybb503372010-05-27 20:51:26 +00005565 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005566 ThrowMogrifyException(OptionError,"MissingArgument",option);
5567 if (IsGeometry(argv[i]) == MagickFalse)
5568 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5569 break;
5570 }
5571 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5572 {
5573 i++;
cristybb503372010-05-27 20:51:26 +00005574 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005575 ThrowMogrifyException(OptionError,"MissingArgument",option);
5576 if (IsGeometry(argv[i]) == MagickFalse)
5577 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5578 break;
5579 }
5580 if (LocaleCompare("size",option+1) == 0)
5581 {
5582 if (*option == '+')
5583 break;
5584 i++;
cristybb503372010-05-27 20:51:26 +00005585 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005586 ThrowMogrifyException(OptionError,"MissingArgument",option);
5587 if (IsGeometry(argv[i]) == MagickFalse)
5588 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5589 break;
5590 }
5591 if (LocaleCompare("sketch",option+1) == 0)
5592 {
5593 if (*option == '+')
5594 break;
5595 i++;
cristybb503372010-05-27 20:51:26 +00005596 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005597 ThrowMogrifyException(OptionError,"MissingArgument",option);
5598 if (IsGeometry(argv[i]) == MagickFalse)
5599 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5600 break;
5601 }
cristy4285d782011-02-09 20:12:28 +00005602 if (LocaleCompare("smush",option+1) == 0)
5603 {
cristy4285d782011-02-09 20:12:28 +00005604 i++;
5605 if (i == (ssize_t) argc)
5606 ThrowMogrifyException(OptionError,"MissingArgument",option);
5607 if (IsGeometry(argv[i]) == MagickFalse)
5608 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005609 i++;
5610 break;
5611 }
cristy3ed852e2009-09-05 21:47:34 +00005612 if (LocaleCompare("solarize",option+1) == 0)
5613 {
5614 if (*option == '+')
5615 break;
5616 i++;
cristybb503372010-05-27 20:51:26 +00005617 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005618 ThrowMogrifyException(OptionError,"MissingArgument",option);
5619 if (IsGeometry(argv[i]) == MagickFalse)
5620 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5621 break;
5622 }
5623 if (LocaleCompare("sparse-color",option+1) == 0)
5624 {
cristybb503372010-05-27 20:51:26 +00005625 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005626 op;
5627
5628 i++;
cristybb503372010-05-27 20:51:26 +00005629 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005630 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005631 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005632 if (op < 0)
5633 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5634 argv[i]);
5635 i++;
cristybb503372010-05-27 20:51:26 +00005636 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005637 ThrowMogrifyException(OptionError,"MissingArgument",option);
5638 break;
5639 }
5640 if (LocaleCompare("spread",option+1) == 0)
5641 {
5642 if (*option == '+')
5643 break;
5644 i++;
cristybb503372010-05-27 20:51:26 +00005645 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005646 ThrowMogrifyException(OptionError,"MissingArgument",option);
5647 if (IsGeometry(argv[i]) == MagickFalse)
5648 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5649 break;
5650 }
cristy0834d642011-03-18 18:26:08 +00005651 if (LocaleCompare("statistic",option+1) == 0)
5652 {
5653 ssize_t
5654 op;
5655
5656 if (*option == '+')
5657 break;
5658 i++;
5659 if (i == (ssize_t) argc)
5660 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005661 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005662 if (op < 0)
5663 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5664 argv[i]);
5665 i++;
5666 if (i == (ssize_t) (argc-1))
5667 ThrowMogrifyException(OptionError,"MissingArgument",option);
5668 if (IsGeometry(argv[i]) == MagickFalse)
5669 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5670 break;
5671 }
cristy3ed852e2009-09-05 21:47:34 +00005672 if (LocaleCompare("stretch",option+1) == 0)
5673 {
cristybb503372010-05-27 20:51:26 +00005674 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005675 stretch;
5676
5677 if (*option == '+')
5678 break;
5679 i++;
cristybb503372010-05-27 20:51:26 +00005680 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005681 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005682 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005683 if (stretch < 0)
5684 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5685 argv[i]);
5686 break;
5687 }
5688 if (LocaleCompare("strip",option+1) == 0)
5689 break;
5690 if (LocaleCompare("stroke",option+1) == 0)
5691 {
5692 if (*option == '+')
5693 break;
5694 i++;
cristybb503372010-05-27 20:51:26 +00005695 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005696 ThrowMogrifyException(OptionError,"MissingArgument",option);
5697 break;
5698 }
5699 if (LocaleCompare("strokewidth",option+1) == 0)
5700 {
5701 if (*option == '+')
5702 break;
5703 i++;
cristybb503372010-05-27 20:51:26 +00005704 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005705 ThrowMogrifyException(OptionError,"MissingArgument",option);
5706 if (IsGeometry(argv[i]) == MagickFalse)
5707 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5708 break;
5709 }
5710 if (LocaleCompare("style",option+1) == 0)
5711 {
cristybb503372010-05-27 20:51:26 +00005712 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005713 style;
5714
5715 if (*option == '+')
5716 break;
5717 i++;
cristybb503372010-05-27 20:51:26 +00005718 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005719 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005720 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005721 if (style < 0)
5722 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5723 argv[i]);
5724 break;
5725 }
cristyecb10ff2011-03-22 13:14:03 +00005726 if (LocaleCompare("swap",option+1) == 0)
5727 {
5728 if (*option == '+')
5729 break;
5730 i++;
5731 if (i == (ssize_t) (argc-1))
5732 ThrowMogrifyException(OptionError,"MissingArgument",option);
5733 if (IsGeometry(argv[i]) == MagickFalse)
5734 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5735 break;
5736 }
cristy3ed852e2009-09-05 21:47:34 +00005737 if (LocaleCompare("swirl",option+1) == 0)
5738 {
5739 if (*option == '+')
5740 break;
5741 i++;
cristybb503372010-05-27 20:51:26 +00005742 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005743 ThrowMogrifyException(OptionError,"MissingArgument",option);
5744 if (IsGeometry(argv[i]) == MagickFalse)
5745 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5746 break;
5747 }
cristyd9a29192010-10-16 16:49:53 +00005748 if (LocaleCompare("synchronize",option+1) == 0)
5749 break;
cristy3ed852e2009-09-05 21:47:34 +00005750 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5751 }
5752 case 't':
5753 {
5754 if (LocaleCompare("taint",option+1) == 0)
5755 break;
5756 if (LocaleCompare("texture",option+1) == 0)
5757 {
5758 if (*option == '+')
5759 break;
5760 i++;
cristybb503372010-05-27 20:51:26 +00005761 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005762 ThrowMogrifyException(OptionError,"MissingArgument",option);
5763 break;
5764 }
5765 if (LocaleCompare("tile",option+1) == 0)
5766 {
5767 if (*option == '+')
5768 break;
5769 i++;
cristybb503372010-05-27 20:51:26 +00005770 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005771 ThrowMogrifyException(OptionError,"MissingArgument",option);
5772 break;
5773 }
5774 if (LocaleCompare("tile-offset",option+1) == 0)
5775 {
5776 if (*option == '+')
5777 break;
5778 i++;
cristybb503372010-05-27 20:51:26 +00005779 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005780 ThrowMogrifyException(OptionError,"MissingArgument",option);
5781 if (IsGeometry(argv[i]) == MagickFalse)
5782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5783 break;
5784 }
5785 if (LocaleCompare("tint",option+1) == 0)
5786 {
5787 if (*option == '+')
5788 break;
5789 i++;
cristybb503372010-05-27 20:51:26 +00005790 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005791 ThrowMogrifyException(OptionError,"MissingArgument",option);
5792 if (IsGeometry(argv[i]) == MagickFalse)
5793 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5794 break;
5795 }
5796 if (LocaleCompare("transform",option+1) == 0)
5797 break;
5798 if (LocaleCompare("transpose",option+1) == 0)
5799 break;
5800 if (LocaleCompare("transverse",option+1) == 0)
5801 break;
5802 if (LocaleCompare("threshold",option+1) == 0)
5803 {
5804 if (*option == '+')
5805 break;
5806 i++;
cristybb503372010-05-27 20:51:26 +00005807 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005808 ThrowMogrifyException(OptionError,"MissingArgument",option);
5809 if (IsGeometry(argv[i]) == MagickFalse)
5810 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5811 break;
5812 }
5813 if (LocaleCompare("thumbnail",option+1) == 0)
5814 {
5815 if (*option == '+')
5816 break;
5817 i++;
cristybb503372010-05-27 20:51:26 +00005818 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005819 ThrowMogrifyException(OptionError,"MissingArgument",option);
5820 if (IsGeometry(argv[i]) == MagickFalse)
5821 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5822 break;
5823 }
5824 if (LocaleCompare("transparent",option+1) == 0)
5825 {
5826 i++;
cristybb503372010-05-27 20:51:26 +00005827 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005828 ThrowMogrifyException(OptionError,"MissingArgument",option);
5829 break;
5830 }
5831 if (LocaleCompare("transparent-color",option+1) == 0)
5832 {
5833 if (*option == '+')
5834 break;
5835 i++;
cristybb503372010-05-27 20:51:26 +00005836 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005837 ThrowMogrifyException(OptionError,"MissingArgument",option);
5838 break;
5839 }
5840 if (LocaleCompare("treedepth",option+1) == 0)
5841 {
5842 if (*option == '+')
5843 break;
5844 i++;
cristybb503372010-05-27 20:51:26 +00005845 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005846 ThrowMogrifyException(OptionError,"MissingArgument",option);
5847 if (IsGeometry(argv[i]) == MagickFalse)
5848 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5849 break;
5850 }
5851 if (LocaleCompare("trim",option+1) == 0)
5852 break;
5853 if (LocaleCompare("type",option+1) == 0)
5854 {
cristybb503372010-05-27 20:51:26 +00005855 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005856 type;
5857
5858 if (*option == '+')
5859 break;
5860 i++;
cristybb503372010-05-27 20:51:26 +00005861 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005862 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005863 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005864 if (type < 0)
5865 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5866 argv[i]);
5867 break;
5868 }
5869 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5870 }
5871 case 'u':
5872 {
5873 if (LocaleCompare("undercolor",option+1) == 0)
5874 {
5875 if (*option == '+')
5876 break;
5877 i++;
cristybb503372010-05-27 20:51:26 +00005878 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005879 ThrowMogrifyException(OptionError,"MissingArgument",option);
5880 break;
5881 }
5882 if (LocaleCompare("unique-colors",option+1) == 0)
5883 break;
5884 if (LocaleCompare("units",option+1) == 0)
5885 {
cristybb503372010-05-27 20:51:26 +00005886 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005887 units;
5888
5889 if (*option == '+')
5890 break;
5891 i++;
cristybb503372010-05-27 20:51:26 +00005892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005893 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005894 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005895 argv[i]);
5896 if (units < 0)
5897 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5898 argv[i]);
5899 break;
5900 }
5901 if (LocaleCompare("unsharp",option+1) == 0)
5902 {
5903 i++;
cristybb503372010-05-27 20:51:26 +00005904 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005905 ThrowMogrifyException(OptionError,"MissingArgument",option);
5906 if (IsGeometry(argv[i]) == MagickFalse)
5907 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5908 break;
5909 }
5910 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5911 }
5912 case 'v':
5913 {
5914 if (LocaleCompare("verbose",option+1) == 0)
5915 {
5916 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5917 break;
5918 }
5919 if ((LocaleCompare("version",option+1) == 0) ||
5920 (LocaleCompare("-version",option+1) == 0))
5921 {
cristyb51dff52011-05-19 16:55:47 +00005922 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005923 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005924 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5925 GetMagickCopyright());
5926 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5927 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005928 break;
5929 }
5930 if (LocaleCompare("view",option+1) == 0)
5931 {
5932 if (*option == '+')
5933 break;
5934 i++;
cristybb503372010-05-27 20:51:26 +00005935 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005936 ThrowMogrifyException(OptionError,"MissingArgument",option);
5937 break;
5938 }
5939 if (LocaleCompare("vignette",option+1) == 0)
5940 {
5941 if (*option == '+')
5942 break;
5943 i++;
cristybb503372010-05-27 20:51:26 +00005944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005945 ThrowMogrifyException(OptionError,"MissingArgument",option);
5946 if (IsGeometry(argv[i]) == MagickFalse)
5947 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5948 break;
5949 }
5950 if (LocaleCompare("virtual-pixel",option+1) == 0)
5951 {
cristybb503372010-05-27 20:51:26 +00005952 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005953 method;
5954
5955 if (*option == '+')
5956 break;
5957 i++;
cristybb503372010-05-27 20:51:26 +00005958 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005959 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005960 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005961 argv[i]);
5962 if (method < 0)
5963 ThrowMogrifyException(OptionError,
5964 "UnrecognizedVirtualPixelMethod",argv[i]);
5965 break;
5966 }
5967 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5968 }
5969 case 'w':
5970 {
5971 if (LocaleCompare("wave",option+1) == 0)
5972 {
5973 i++;
cristybb503372010-05-27 20:51:26 +00005974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005975 ThrowMogrifyException(OptionError,"MissingArgument",option);
5976 if (IsGeometry(argv[i]) == MagickFalse)
5977 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5978 break;
5979 }
5980 if (LocaleCompare("weight",option+1) == 0)
5981 {
5982 if (*option == '+')
5983 break;
5984 i++;
cristybb503372010-05-27 20:51:26 +00005985 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005986 ThrowMogrifyException(OptionError,"MissingArgument",option);
5987 break;
5988 }
5989 if (LocaleCompare("white-point",option+1) == 0)
5990 {
5991 if (*option == '+')
5992 break;
5993 i++;
cristybb503372010-05-27 20:51:26 +00005994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005995 ThrowMogrifyException(OptionError,"MissingArgument",option);
5996 if (IsGeometry(argv[i]) == MagickFalse)
5997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5998 break;
5999 }
6000 if (LocaleCompare("white-threshold",option+1) == 0)
6001 {
6002 if (*option == '+')
6003 break;
6004 i++;
cristybb503372010-05-27 20:51:26 +00006005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006006 ThrowMogrifyException(OptionError,"MissingArgument",option);
6007 if (IsGeometry(argv[i]) == MagickFalse)
6008 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6009 break;
6010 }
6011 if (LocaleCompare("write",option+1) == 0)
6012 {
6013 i++;
cristybb503372010-05-27 20:51:26 +00006014 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006015 ThrowMogrifyException(OptionError,"MissingArgument",option);
6016 break;
6017 }
6018 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6019 }
6020 case '?':
6021 break;
6022 default:
6023 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6024 }
cristy042ee782011-04-22 18:48:30 +00006025 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6026 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006027 if (fire != MagickFalse)
6028 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6029 }
6030 if (k != 0)
6031 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006032 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006033 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6034 DestroyMogrify();
6035 return(status != 0 ? MagickTrue : MagickFalse);
6036}
6037
6038/*
6039%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6040% %
6041% %
6042% %
6043+ M o g r i f y I m a g e I n f o %
6044% %
6045% %
6046% %
6047%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6048%
6049% MogrifyImageInfo() applies image processing settings to the image as
6050% prescribed by command line options.
6051%
6052% The format of the MogrifyImageInfo method is:
6053%
6054% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6055% const char **argv,ExceptionInfo *exception)
6056%
6057% A description of each parameter follows:
6058%
6059% o image_info: the image info..
6060%
6061% o argc: Specifies a pointer to an integer describing the number of
6062% elements in the argument vector.
6063%
6064% o argv: Specifies a pointer to a text array containing the command line
6065% arguments.
6066%
6067% o exception: return any errors or warnings in this structure.
6068%
6069*/
6070WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6071 const int argc,const char **argv,ExceptionInfo *exception)
6072{
6073 const char
6074 *option;
6075
6076 GeometryInfo
6077 geometry_info;
6078
cristybb503372010-05-27 20:51:26 +00006079 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006080 count;
6081
cristybb503372010-05-27 20:51:26 +00006082 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006083 i;
6084
6085 /*
6086 Initialize method variables.
6087 */
6088 assert(image_info != (ImageInfo *) NULL);
6089 assert(image_info->signature == MagickSignature);
6090 if (image_info->debug != MagickFalse)
6091 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6092 image_info->filename);
6093 if (argc < 0)
6094 return(MagickTrue);
6095 /*
6096 Set the image settings.
6097 */
cristybb503372010-05-27 20:51:26 +00006098 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006099 {
6100 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006101 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006102 continue;
cristy042ee782011-04-22 18:48:30 +00006103 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006104 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006105 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006106 break;
6107 switch (*(option+1))
6108 {
6109 case 'a':
6110 {
6111 if (LocaleCompare("adjoin",option+1) == 0)
6112 {
6113 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6114 break;
6115 }
6116 if (LocaleCompare("antialias",option+1) == 0)
6117 {
6118 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6119 break;
6120 }
6121 if (LocaleCompare("attenuate",option+1) == 0)
6122 {
6123 if (*option == '+')
6124 {
6125 (void) DeleteImageOption(image_info,option+1);
6126 break;
6127 }
6128 (void) SetImageOption(image_info,option+1,argv[i+1]);
6129 break;
6130 }
6131 if (LocaleCompare("authenticate",option+1) == 0)
6132 {
6133 if (*option == '+')
6134 (void) CloneString(&image_info->authenticate,(char *) NULL);
6135 else
6136 (void) CloneString(&image_info->authenticate,argv[i+1]);
6137 break;
6138 }
6139 break;
6140 }
6141 case 'b':
6142 {
6143 if (LocaleCompare("background",option+1) == 0)
6144 {
6145 if (*option == '+')
6146 {
6147 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006148 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006149 &image_info->background_color,exception);
6150 break;
6151 }
6152 (void) SetImageOption(image_info,option+1,argv[i+1]);
6153 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6154 exception);
6155 break;
6156 }
6157 if (LocaleCompare("bias",option+1) == 0)
6158 {
6159 if (*option == '+')
6160 {
6161 (void) SetImageOption(image_info,option+1,"0.0");
6162 break;
6163 }
6164 (void) SetImageOption(image_info,option+1,argv[i+1]);
6165 break;
6166 }
6167 if (LocaleCompare("black-point-compensation",option+1) == 0)
6168 {
6169 if (*option == '+')
6170 {
6171 (void) SetImageOption(image_info,option+1,"false");
6172 break;
6173 }
6174 (void) SetImageOption(image_info,option+1,"true");
6175 break;
6176 }
6177 if (LocaleCompare("blue-primary",option+1) == 0)
6178 {
6179 if (*option == '+')
6180 {
6181 (void) SetImageOption(image_info,option+1,"0.0");
6182 break;
6183 }
6184 (void) SetImageOption(image_info,option+1,argv[i+1]);
6185 break;
6186 }
6187 if (LocaleCompare("bordercolor",option+1) == 0)
6188 {
6189 if (*option == '+')
6190 {
6191 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006192 (void) QueryColorDatabase(MogrifyBorderColor,
6193 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006194 break;
6195 }
6196 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6197 exception);
6198 (void) SetImageOption(image_info,option+1,argv[i+1]);
6199 break;
6200 }
6201 if (LocaleCompare("box",option+1) == 0)
6202 {
6203 if (*option == '+')
6204 {
6205 (void) SetImageOption(image_info,"undercolor","none");
6206 break;
6207 }
6208 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6209 break;
6210 }
6211 break;
6212 }
6213 case 'c':
6214 {
6215 if (LocaleCompare("cache",option+1) == 0)
6216 {
6217 MagickSizeType
6218 limit;
6219
6220 limit=MagickResourceInfinity;
6221 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006222 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006223 (void) SetMagickResourceLimit(MemoryResource,limit);
6224 (void) SetMagickResourceLimit(MapResource,2*limit);
6225 break;
6226 }
6227 if (LocaleCompare("caption",option+1) == 0)
6228 {
6229 if (*option == '+')
6230 {
6231 (void) DeleteImageOption(image_info,option+1);
6232 break;
6233 }
6234 (void) SetImageOption(image_info,option+1,argv[i+1]);
6235 break;
6236 }
6237 if (LocaleCompare("channel",option+1) == 0)
6238 {
6239 if (*option == '+')
6240 {
6241 image_info->channel=DefaultChannels;
6242 break;
6243 }
6244 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6245 break;
6246 }
6247 if (LocaleCompare("colors",option+1) == 0)
6248 {
cristye27293e2009-12-18 02:53:20 +00006249 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006250 break;
6251 }
6252 if (LocaleCompare("colorspace",option+1) == 0)
6253 {
6254 if (*option == '+')
6255 {
6256 image_info->colorspace=UndefinedColorspace;
6257 (void) SetImageOption(image_info,option+1,"undefined");
6258 break;
6259 }
cristy042ee782011-04-22 18:48:30 +00006260 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006261 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6262 (void) SetImageOption(image_info,option+1,argv[i+1]);
6263 break;
6264 }
cristy3ed852e2009-09-05 21:47:34 +00006265 if (LocaleCompare("comment",option+1) == 0)
6266 {
6267 if (*option == '+')
6268 {
6269 (void) DeleteImageOption(image_info,option+1);
6270 break;
6271 }
6272 (void) SetImageOption(image_info,option+1,argv[i+1]);
6273 break;
6274 }
6275 if (LocaleCompare("compose",option+1) == 0)
6276 {
6277 if (*option == '+')
6278 {
6279 (void) SetImageOption(image_info,option+1,"undefined");
6280 break;
6281 }
6282 (void) SetImageOption(image_info,option+1,argv[i+1]);
6283 break;
6284 }
6285 if (LocaleCompare("compress",option+1) == 0)
6286 {
6287 if (*option == '+')
6288 {
6289 image_info->compression=UndefinedCompression;
6290 (void) SetImageOption(image_info,option+1,"undefined");
6291 break;
6292 }
cristy042ee782011-04-22 18:48:30 +00006293 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006294 MagickCompressOptions,MagickFalse,argv[i+1]);
6295 (void) SetImageOption(image_info,option+1,argv[i+1]);
6296 break;
6297 }
6298 break;
6299 }
6300 case 'd':
6301 {
6302 if (LocaleCompare("debug",option+1) == 0)
6303 {
6304 if (*option == '+')
6305 (void) SetLogEventMask("none");
6306 else
6307 (void) SetLogEventMask(argv[i+1]);
6308 image_info->debug=IsEventLogging();
6309 break;
6310 }
6311 if (LocaleCompare("define",option+1) == 0)
6312 {
6313 if (*option == '+')
6314 {
6315 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6316 (void) DeleteImageRegistry(argv[i+1]+9);
6317 else
6318 (void) DeleteImageOption(image_info,argv[i+1]);
6319 break;
6320 }
6321 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6322 {
6323 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6324 exception);
6325 break;
6326 }
6327 (void) DefineImageOption(image_info,argv[i+1]);
6328 break;
6329 }
6330 if (LocaleCompare("delay",option+1) == 0)
6331 {
6332 if (*option == '+')
6333 {
6334 (void) SetImageOption(image_info,option+1,"0");
6335 break;
6336 }
6337 (void) SetImageOption(image_info,option+1,argv[i+1]);
6338 break;
6339 }
6340 if (LocaleCompare("density",option+1) == 0)
6341 {
6342 /*
6343 Set image density.
6344 */
6345 if (*option == '+')
6346 {
6347 if (image_info->density != (char *) NULL)
6348 image_info->density=DestroyString(image_info->density);
6349 (void) SetImageOption(image_info,option+1,"72");
6350 break;
6351 }
6352 (void) CloneString(&image_info->density,argv[i+1]);
6353 (void) SetImageOption(image_info,option+1,argv[i+1]);
6354 break;
6355 }
6356 if (LocaleCompare("depth",option+1) == 0)
6357 {
6358 if (*option == '+')
6359 {
6360 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6361 break;
6362 }
cristye27293e2009-12-18 02:53:20 +00006363 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006364 break;
6365 }
cristyc9b12952010-03-28 01:12:28 +00006366 if (LocaleCompare("direction",option+1) == 0)
6367 {
6368 if (*option == '+')
6369 {
6370 (void) SetImageOption(image_info,option+1,"undefined");
6371 break;
6372 }
6373 (void) SetImageOption(image_info,option+1,argv[i+1]);
6374 break;
6375 }
cristy3ed852e2009-09-05 21:47:34 +00006376 if (LocaleCompare("display",option+1) == 0)
6377 {
6378 if (*option == '+')
6379 {
6380 if (image_info->server_name != (char *) NULL)
6381 image_info->server_name=DestroyString(
6382 image_info->server_name);
6383 break;
6384 }
6385 (void) CloneString(&image_info->server_name,argv[i+1]);
6386 break;
6387 }
6388 if (LocaleCompare("dispose",option+1) == 0)
6389 {
6390 if (*option == '+')
6391 {
6392 (void) SetImageOption(image_info,option+1,"undefined");
6393 break;
6394 }
6395 (void) SetImageOption(image_info,option+1,argv[i+1]);
6396 break;
6397 }
6398 if (LocaleCompare("dither",option+1) == 0)
6399 {
6400 if (*option == '+')
6401 {
6402 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006403 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006404 break;
6405 }
6406 (void) SetImageOption(image_info,option+1,argv[i+1]);
6407 image_info->dither=MagickTrue;
6408 break;
6409 }
6410 break;
6411 }
6412 case 'e':
6413 {
6414 if (LocaleCompare("encoding",option+1) == 0)
6415 {
6416 if (*option == '+')
6417 {
6418 (void) SetImageOption(image_info,option+1,"undefined");
6419 break;
6420 }
6421 (void) SetImageOption(image_info,option+1,argv[i+1]);
6422 break;
6423 }
6424 if (LocaleCompare("endian",option+1) == 0)
6425 {
6426 if (*option == '+')
6427 {
6428 image_info->endian=UndefinedEndian;
6429 (void) SetImageOption(image_info,option+1,"undefined");
6430 break;
6431 }
cristy042ee782011-04-22 18:48:30 +00006432 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006433 MagickEndianOptions,MagickFalse,argv[i+1]);
6434 (void) SetImageOption(image_info,option+1,argv[i+1]);
6435 break;
6436 }
6437 if (LocaleCompare("extract",option+1) == 0)
6438 {
6439 /*
6440 Set image extract geometry.
6441 */
6442 if (*option == '+')
6443 {
6444 if (image_info->extract != (char *) NULL)
6445 image_info->extract=DestroyString(image_info->extract);
6446 break;
6447 }
6448 (void) CloneString(&image_info->extract,argv[i+1]);
6449 break;
6450 }
6451 break;
6452 }
6453 case 'f':
6454 {
6455 if (LocaleCompare("fill",option+1) == 0)
6456 {
6457 if (*option == '+')
6458 {
6459 (void) SetImageOption(image_info,option+1,"none");
6460 break;
6461 }
6462 (void) SetImageOption(image_info,option+1,argv[i+1]);
6463 break;
6464 }
6465 if (LocaleCompare("filter",option+1) == 0)
6466 {
6467 if (*option == '+')
6468 {
6469 (void) SetImageOption(image_info,option+1,"undefined");
6470 break;
6471 }
6472 (void) SetImageOption(image_info,option+1,argv[i+1]);
6473 break;
6474 }
6475 if (LocaleCompare("font",option+1) == 0)
6476 {
6477 if (*option == '+')
6478 {
6479 if (image_info->font != (char *) NULL)
6480 image_info->font=DestroyString(image_info->font);
6481 break;
6482 }
6483 (void) CloneString(&image_info->font,argv[i+1]);
6484 break;
6485 }
6486 if (LocaleCompare("format",option+1) == 0)
6487 {
6488 register const char
6489 *q;
6490
6491 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006492 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006493 image_info->ping=MagickFalse;
6494 (void) SetImageOption(image_info,option+1,argv[i+1]);
6495 break;
6496 }
6497 if (LocaleCompare("fuzz",option+1) == 0)
6498 {
6499 if (*option == '+')
6500 {
6501 image_info->fuzz=0.0;
6502 (void) SetImageOption(image_info,option+1,"0");
6503 break;
6504 }
cristyf2f27272009-12-17 14:48:46 +00006505 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006506 1.0);
6507 (void) SetImageOption(image_info,option+1,argv[i+1]);
6508 break;
6509 }
6510 break;
6511 }
6512 case 'g':
6513 {
6514 if (LocaleCompare("gravity",option+1) == 0)
6515 {
6516 if (*option == '+')
6517 {
6518 (void) SetImageOption(image_info,option+1,"undefined");
6519 break;
6520 }
6521 (void) SetImageOption(image_info,option+1,argv[i+1]);
6522 break;
6523 }
6524 if (LocaleCompare("green-primary",option+1) == 0)
6525 {
6526 if (*option == '+')
6527 {
6528 (void) SetImageOption(image_info,option+1,"0.0");
6529 break;
6530 }
6531 (void) SetImageOption(image_info,option+1,argv[i+1]);
6532 break;
6533 }
6534 break;
6535 }
6536 case 'i':
6537 {
6538 if (LocaleCompare("intent",option+1) == 0)
6539 {
6540 if (*option == '+')
6541 {
6542 (void) SetImageOption(image_info,option+1,"undefined");
6543 break;
6544 }
6545 (void) SetImageOption(image_info,option+1,argv[i+1]);
6546 break;
6547 }
6548 if (LocaleCompare("interlace",option+1) == 0)
6549 {
6550 if (*option == '+')
6551 {
6552 image_info->interlace=UndefinedInterlace;
6553 (void) SetImageOption(image_info,option+1,"undefined");
6554 break;
6555 }
cristy042ee782011-04-22 18:48:30 +00006556 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006557 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6558 (void) SetImageOption(image_info,option+1,argv[i+1]);
6559 break;
6560 }
cristyb32b90a2009-09-07 21:45:48 +00006561 if (LocaleCompare("interline-spacing",option+1) == 0)
6562 {
6563 if (*option == '+')
6564 {
6565 (void) SetImageOption(image_info,option+1,"undefined");
6566 break;
6567 }
6568 (void) SetImageOption(image_info,option+1,argv[i+1]);
6569 break;
6570 }
cristy3ed852e2009-09-05 21:47:34 +00006571 if (LocaleCompare("interpolate",option+1) == 0)
6572 {
6573 if (*option == '+')
6574 {
6575 (void) SetImageOption(image_info,option+1,"undefined");
6576 break;
6577 }
6578 (void) SetImageOption(image_info,option+1,argv[i+1]);
6579 break;
6580 }
6581 if (LocaleCompare("interword-spacing",option+1) == 0)
6582 {
6583 if (*option == '+')
6584 {
6585 (void) SetImageOption(image_info,option+1,"undefined");
6586 break;
6587 }
6588 (void) SetImageOption(image_info,option+1,argv[i+1]);
6589 break;
6590 }
6591 break;
6592 }
6593 case 'k':
6594 {
6595 if (LocaleCompare("kerning",option+1) == 0)
6596 {
6597 if (*option == '+')
6598 {
6599 (void) SetImageOption(image_info,option+1,"undefined");
6600 break;
6601 }
6602 (void) SetImageOption(image_info,option+1,argv[i+1]);
6603 break;
6604 }
6605 break;
6606 }
6607 case 'l':
6608 {
6609 if (LocaleCompare("label",option+1) == 0)
6610 {
6611 if (*option == '+')
6612 {
6613 (void) DeleteImageOption(image_info,option+1);
6614 break;
6615 }
6616 (void) SetImageOption(image_info,option+1,argv[i+1]);
6617 break;
6618 }
6619 if (LocaleCompare("limit",option+1) == 0)
6620 {
6621 MagickSizeType
6622 limit;
6623
6624 ResourceType
6625 type;
6626
6627 if (*option == '+')
6628 break;
cristy042ee782011-04-22 18:48:30 +00006629 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006630 MagickFalse,argv[i+1]);
6631 limit=MagickResourceInfinity;
6632 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006633 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006634 (void) SetMagickResourceLimit(type,limit);
6635 break;
6636 }
6637 if (LocaleCompare("list",option+1) == 0)
6638 {
cristybb503372010-05-27 20:51:26 +00006639 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006640 list;
6641
6642 /*
6643 Display configuration list.
6644 */
cristy042ee782011-04-22 18:48:30 +00006645 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006646 switch (list)
6647 {
6648 case MagickCoderOptions:
6649 {
6650 (void) ListCoderInfo((FILE *) NULL,exception);
6651 break;
6652 }
6653 case MagickColorOptions:
6654 {
6655 (void) ListColorInfo((FILE *) NULL,exception);
6656 break;
6657 }
6658 case MagickConfigureOptions:
6659 {
6660 (void) ListConfigureInfo((FILE *) NULL,exception);
6661 break;
6662 }
6663 case MagickDelegateOptions:
6664 {
6665 (void) ListDelegateInfo((FILE *) NULL,exception);
6666 break;
6667 }
6668 case MagickFontOptions:
6669 {
6670 (void) ListTypeInfo((FILE *) NULL,exception);
6671 break;
6672 }
6673 case MagickFormatOptions:
6674 {
6675 (void) ListMagickInfo((FILE *) NULL,exception);
6676 break;
6677 }
6678 case MagickLocaleOptions:
6679 {
6680 (void) ListLocaleInfo((FILE *) NULL,exception);
6681 break;
6682 }
6683 case MagickLogOptions:
6684 {
6685 (void) ListLogInfo((FILE *) NULL,exception);
6686 break;
6687 }
6688 case MagickMagicOptions:
6689 {
6690 (void) ListMagicInfo((FILE *) NULL,exception);
6691 break;
6692 }
6693 case MagickMimeOptions:
6694 {
6695 (void) ListMimeInfo((FILE *) NULL,exception);
6696 break;
6697 }
6698 case MagickModuleOptions:
6699 {
6700 (void) ListModuleInfo((FILE *) NULL,exception);
6701 break;
6702 }
6703 case MagickPolicyOptions:
6704 {
6705 (void) ListPolicyInfo((FILE *) NULL,exception);
6706 break;
6707 }
6708 case MagickResourceOptions:
6709 {
6710 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6711 break;
6712 }
6713 case MagickThresholdOptions:
6714 {
6715 (void) ListThresholdMaps((FILE *) NULL,exception);
6716 break;
6717 }
6718 default:
6719 {
cristy042ee782011-04-22 18:48:30 +00006720 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006721 exception);
6722 break;
6723 }
6724 }
cristyaeb2cbc2010-05-07 13:28:58 +00006725 break;
cristy3ed852e2009-09-05 21:47:34 +00006726 }
6727 if (LocaleCompare("log",option+1) == 0)
6728 {
6729 if (*option == '+')
6730 break;
6731 (void) SetLogFormat(argv[i+1]);
6732 break;
6733 }
6734 if (LocaleCompare("loop",option+1) == 0)
6735 {
6736 if (*option == '+')
6737 {
6738 (void) SetImageOption(image_info,option+1,"0");
6739 break;
6740 }
6741 (void) SetImageOption(image_info,option+1,argv[i+1]);
6742 break;
6743 }
6744 break;
6745 }
6746 case 'm':
6747 {
6748 if (LocaleCompare("matte",option+1) == 0)
6749 {
6750 if (*option == '+')
6751 {
6752 (void) SetImageOption(image_info,option+1,"false");
6753 break;
6754 }
6755 (void) SetImageOption(image_info,option+1,"true");
6756 break;
6757 }
6758 if (LocaleCompare("mattecolor",option+1) == 0)
6759 {
6760 if (*option == '+')
6761 {
6762 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006763 (void) QueryColorDatabase(MogrifyMatteColor,
6764 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006765 break;
6766 }
6767 (void) SetImageOption(image_info,option+1,argv[i+1]);
6768 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6769 exception);
6770 break;
6771 }
6772 if (LocaleCompare("monitor",option+1) == 0)
6773 {
6774 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6775 (void *) NULL);
6776 break;
6777 }
6778 if (LocaleCompare("monochrome",option+1) == 0)
6779 {
6780 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6781 break;
6782 }
6783 break;
6784 }
6785 case 'o':
6786 {
6787 if (LocaleCompare("orient",option+1) == 0)
6788 {
6789 if (*option == '+')
6790 {
6791 image_info->orientation=UndefinedOrientation;
6792 (void) SetImageOption(image_info,option+1,"undefined");
6793 break;
6794 }
cristy042ee782011-04-22 18:48:30 +00006795 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006796 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006797 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006798 break;
6799 }
6800 }
6801 case 'p':
6802 {
6803 if (LocaleCompare("page",option+1) == 0)
6804 {
6805 char
6806 *canonical_page,
6807 page[MaxTextExtent];
6808
6809 const char
6810 *image_option;
6811
6812 MagickStatusType
6813 flags;
6814
6815 RectangleInfo
6816 geometry;
6817
6818 if (*option == '+')
6819 {
6820 (void) DeleteImageOption(image_info,option+1);
6821 (void) CloneString(&image_info->page,(char *) NULL);
6822 break;
6823 }
6824 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6825 image_option=GetImageOption(image_info,"page");
6826 if (image_option != (const char *) NULL)
6827 flags=ParseAbsoluteGeometry(image_option,&geometry);
6828 canonical_page=GetPageGeometry(argv[i+1]);
6829 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6830 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006831 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006832 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006833 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006834 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006835 (unsigned long) geometry.width,(unsigned long) geometry.height,
6836 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006837 (void) SetImageOption(image_info,option+1,page);
6838 (void) CloneString(&image_info->page,page);
6839 break;
6840 }
6841 if (LocaleCompare("pen",option+1) == 0)
6842 {
6843 if (*option == '+')
6844 {
6845 (void) SetImageOption(image_info,option+1,"none");
6846 break;
6847 }
6848 (void) SetImageOption(image_info,option+1,argv[i+1]);
6849 break;
6850 }
6851 if (LocaleCompare("ping",option+1) == 0)
6852 {
6853 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6854 break;
6855 }
6856 if (LocaleCompare("pointsize",option+1) == 0)
6857 {
6858 if (*option == '+')
6859 geometry_info.rho=0.0;
6860 else
6861 (void) ParseGeometry(argv[i+1],&geometry_info);
6862 image_info->pointsize=geometry_info.rho;
6863 break;
6864 }
cristye7f51092010-01-17 00:39:37 +00006865 if (LocaleCompare("precision",option+1) == 0)
6866 {
cristybf2766a2010-01-17 03:33:23 +00006867 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006868 break;
6869 }
cristy3ed852e2009-09-05 21:47:34 +00006870 if (LocaleCompare("preview",option+1) == 0)
6871 {
6872 /*
6873 Preview image.
6874 */
6875 if (*option == '+')
6876 {
6877 image_info->preview_type=UndefinedPreview;
6878 break;
6879 }
cristy042ee782011-04-22 18:48:30 +00006880 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006881 MagickPreviewOptions,MagickFalse,argv[i+1]);
6882 break;
6883 }
6884 break;
6885 }
6886 case 'q':
6887 {
6888 if (LocaleCompare("quality",option+1) == 0)
6889 {
6890 /*
6891 Set image compression quality.
6892 */
6893 if (*option == '+')
6894 {
6895 image_info->quality=UndefinedCompressionQuality;
6896 (void) SetImageOption(image_info,option+1,"0");
6897 break;
6898 }
cristye27293e2009-12-18 02:53:20 +00006899 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006900 (void) SetImageOption(image_info,option+1,argv[i+1]);
6901 break;
6902 }
6903 if (LocaleCompare("quiet",option+1) == 0)
6904 {
6905 static WarningHandler
6906 warning_handler = (WarningHandler) NULL;
6907
6908 if (*option == '+')
6909 {
6910 /*
6911 Restore error or warning messages.
6912 */
6913 warning_handler=SetWarningHandler(warning_handler);
6914 break;
6915 }
6916 /*
6917 Suppress error or warning messages.
6918 */
6919 warning_handler=SetWarningHandler((WarningHandler) NULL);
6920 break;
6921 }
6922 break;
6923 }
6924 case 'r':
6925 {
6926 if (LocaleCompare("red-primary",option+1) == 0)
6927 {
6928 if (*option == '+')
6929 {
6930 (void) SetImageOption(image_info,option+1,"0.0");
6931 break;
6932 }
6933 (void) SetImageOption(image_info,option+1,argv[i+1]);
6934 break;
6935 }
6936 break;
6937 }
6938 case 's':
6939 {
6940 if (LocaleCompare("sampling-factor",option+1) == 0)
6941 {
6942 /*
6943 Set image sampling factor.
6944 */
6945 if (*option == '+')
6946 {
6947 if (image_info->sampling_factor != (char *) NULL)
6948 image_info->sampling_factor=DestroyString(
6949 image_info->sampling_factor);
6950 break;
6951 }
6952 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6953 break;
6954 }
6955 if (LocaleCompare("scene",option+1) == 0)
6956 {
6957 /*
6958 Set image scene.
6959 */
6960 if (*option == '+')
6961 {
6962 image_info->scene=0;
6963 (void) SetImageOption(image_info,option+1,"0");
6964 break;
6965 }
cristye27293e2009-12-18 02:53:20 +00006966 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006967 (void) SetImageOption(image_info,option+1,argv[i+1]);
6968 break;
6969 }
6970 if (LocaleCompare("seed",option+1) == 0)
6971 {
cristybb503372010-05-27 20:51:26 +00006972 size_t
cristy3ed852e2009-09-05 21:47:34 +00006973 seed;
6974
6975 if (*option == '+')
6976 {
cristybb503372010-05-27 20:51:26 +00006977 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006978 SeedPseudoRandomGenerator(seed);
6979 break;
6980 }
cristye27293e2009-12-18 02:53:20 +00006981 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006982 SeedPseudoRandomGenerator(seed);
6983 break;
6984 }
6985 if (LocaleCompare("size",option+1) == 0)
6986 {
6987 if (*option == '+')
6988 {
6989 if (image_info->size != (char *) NULL)
6990 image_info->size=DestroyString(image_info->size);
6991 break;
6992 }
6993 (void) CloneString(&image_info->size,argv[i+1]);
6994 break;
6995 }
6996 if (LocaleCompare("stroke",option+1) == 0)
6997 {
6998 if (*option == '+')
6999 {
7000 (void) SetImageOption(image_info,option+1,"none");
7001 break;
7002 }
7003 (void) SetImageOption(image_info,option+1,argv[i+1]);
7004 break;
7005 }
7006 if (LocaleCompare("strokewidth",option+1) == 0)
7007 {
7008 if (*option == '+')
7009 {
7010 (void) SetImageOption(image_info,option+1,"0");
7011 break;
7012 }
7013 (void) SetImageOption(image_info,option+1,argv[i+1]);
7014 break;
7015 }
cristyd9a29192010-10-16 16:49:53 +00007016 if (LocaleCompare("synchronize",option+1) == 0)
7017 {
7018 if (*option == '+')
7019 {
7020 image_info->synchronize=MagickFalse;
7021 break;
7022 }
7023 image_info->synchronize=MagickTrue;
7024 break;
7025 }
cristy3ed852e2009-09-05 21:47:34 +00007026 break;
7027 }
7028 case 't':
7029 {
7030 if (LocaleCompare("taint",option+1) == 0)
7031 {
7032 if (*option == '+')
7033 {
7034 (void) SetImageOption(image_info,option+1,"false");
7035 break;
7036 }
7037 (void) SetImageOption(image_info,option+1,"true");
7038 break;
7039 }
7040 if (LocaleCompare("texture",option+1) == 0)
7041 {
7042 if (*option == '+')
7043 {
7044 if (image_info->texture != (char *) NULL)
7045 image_info->texture=DestroyString(image_info->texture);
7046 break;
7047 }
7048 (void) CloneString(&image_info->texture,argv[i+1]);
7049 break;
7050 }
7051 if (LocaleCompare("tile-offset",option+1) == 0)
7052 {
7053 if (*option == '+')
7054 {
7055 (void) SetImageOption(image_info,option+1,"0");
7056 break;
7057 }
7058 (void) SetImageOption(image_info,option+1,argv[i+1]);
7059 break;
7060 }
7061 if (LocaleCompare("transparent-color",option+1) == 0)
7062 {
7063 if (*option == '+')
7064 {
7065 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7066 (void) SetImageOption(image_info,option+1,"none");
7067 break;
7068 }
7069 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7070 exception);
7071 (void) SetImageOption(image_info,option+1,argv[i+1]);
7072 break;
7073 }
7074 if (LocaleCompare("type",option+1) == 0)
7075 {
7076 if (*option == '+')
7077 {
cristy5f1c1ff2010-12-23 21:38:06 +00007078 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007079 (void) SetImageOption(image_info,option+1,"undefined");
7080 break;
7081 }
cristy042ee782011-04-22 18:48:30 +00007082 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007083 MagickFalse,argv[i+1]);
7084 (void) SetImageOption(image_info,option+1,argv[i+1]);
7085 break;
7086 }
7087 break;
7088 }
7089 case 'u':
7090 {
7091 if (LocaleCompare("undercolor",option+1) == 0)
7092 {
7093 if (*option == '+')
7094 {
7095 (void) DeleteImageOption(image_info,option+1);
7096 break;
7097 }
7098 (void) SetImageOption(image_info,option+1,argv[i+1]);
7099 break;
7100 }
7101 if (LocaleCompare("units",option+1) == 0)
7102 {
7103 if (*option == '+')
7104 {
7105 image_info->units=UndefinedResolution;
7106 (void) SetImageOption(image_info,option+1,"undefined");
7107 break;
7108 }
cristy042ee782011-04-22 18:48:30 +00007109 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007110 MagickResolutionOptions,MagickFalse,argv[i+1]);
7111 (void) SetImageOption(image_info,option+1,argv[i+1]);
7112 break;
7113 }
7114 break;
7115 }
7116 case 'v':
7117 {
7118 if (LocaleCompare("verbose",option+1) == 0)
7119 {
7120 if (*option == '+')
7121 {
7122 image_info->verbose=MagickFalse;
7123 break;
7124 }
7125 image_info->verbose=MagickTrue;
7126 image_info->ping=MagickFalse;
7127 break;
7128 }
7129 if (LocaleCompare("view",option+1) == 0)
7130 {
7131 if (*option == '+')
7132 {
7133 if (image_info->view != (char *) NULL)
7134 image_info->view=DestroyString(image_info->view);
7135 break;
7136 }
7137 (void) CloneString(&image_info->view,argv[i+1]);
7138 break;
7139 }
7140 if (LocaleCompare("virtual-pixel",option+1) == 0)
7141 {
7142 if (*option == '+')
7143 {
7144 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7145 (void) SetImageOption(image_info,option+1,"undefined");
7146 break;
7147 }
7148 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007149 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007150 argv[i+1]);
7151 (void) SetImageOption(image_info,option+1,argv[i+1]);
7152 break;
7153 }
7154 break;
7155 }
7156 case 'w':
7157 {
7158 if (LocaleCompare("white-point",option+1) == 0)
7159 {
7160 if (*option == '+')
7161 {
7162 (void) SetImageOption(image_info,option+1,"0.0");
7163 break;
7164 }
7165 (void) SetImageOption(image_info,option+1,argv[i+1]);
7166 break;
7167 }
7168 break;
7169 }
7170 default:
7171 break;
7172 }
7173 i+=count;
7174 }
7175 return(MagickTrue);
7176}
7177
7178/*
7179%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7180% %
7181% %
7182% %
7183+ M o g r i f y I m a g e L i s t %
7184% %
7185% %
7186% %
7187%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7188%
7189% MogrifyImageList() applies any command line options that might affect the
7190% entire image list (e.g. -append, -coalesce, etc.).
7191%
7192% The format of the MogrifyImage method is:
7193%
7194% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7195% const char **argv,Image **images,ExceptionInfo *exception)
7196%
7197% A description of each parameter follows:
7198%
7199% o image_info: the image info..
7200%
7201% o argc: Specifies a pointer to an integer describing the number of
7202% elements in the argument vector.
7203%
7204% o argv: Specifies a pointer to a text array containing the command line
7205% arguments.
7206%
anthonye9c27192011-03-27 08:07:06 +00007207% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007208%
7209% o exception: return any errors or warnings in this structure.
7210%
7211*/
7212WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7213 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7214{
cristy3ed852e2009-09-05 21:47:34 +00007215 const char
7216 *option;
7217
cristy6b3da3a2010-06-20 02:21:46 +00007218 ImageInfo
7219 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007220
7221 MagickStatusType
7222 status;
7223
7224 QuantizeInfo
7225 *quantize_info;
7226
cristybb503372010-05-27 20:51:26 +00007227 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007228 i;
7229
cristy6b3da3a2010-06-20 02:21:46 +00007230 ssize_t
7231 count,
7232 index;
7233
cristy3ed852e2009-09-05 21:47:34 +00007234 /*
7235 Apply options to the image list.
7236 */
7237 assert(image_info != (ImageInfo *) NULL);
7238 assert(image_info->signature == MagickSignature);
7239 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007240 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007241 assert((*images)->signature == MagickSignature);
7242 if ((*images)->debug != MagickFalse)
7243 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7244 (*images)->filename);
7245 if ((argc <= 0) || (*argv == (char *) NULL))
7246 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007247 mogrify_info=CloneImageInfo(image_info);
7248 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007249 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007250 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007251 {
cristy74fe8f12009-10-03 19:09:01 +00007252 if (*images == (Image *) NULL)
7253 break;
cristy3ed852e2009-09-05 21:47:34 +00007254 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007255 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007256 continue;
cristy042ee782011-04-22 18:48:30 +00007257 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007258 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007259 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007260 break;
cristy6b3da3a2010-06-20 02:21:46 +00007261 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007262 switch (*(option+1))
7263 {
7264 case 'a':
7265 {
7266 if (LocaleCompare("affinity",option+1) == 0)
7267 {
cristy6b3da3a2010-06-20 02:21:46 +00007268 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007269 if (*option == '+')
7270 {
cristy018f07f2011-09-04 21:15:19 +00007271 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7272 exception);
cristy3ed852e2009-09-05 21:47:34 +00007273 break;
7274 }
7275 i++;
7276 break;
7277 }
7278 if (LocaleCompare("append",option+1) == 0)
7279 {
7280 Image
7281 *append_image;
7282
cristy6b3da3a2010-06-20 02:21:46 +00007283 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007284 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7285 MagickFalse,exception);
7286 if (append_image == (Image *) NULL)
7287 {
7288 status=MagickFalse;
7289 break;
7290 }
7291 *images=DestroyImageList(*images);
7292 *images=append_image;
7293 break;
7294 }
7295 if (LocaleCompare("average",option+1) == 0)
7296 {
7297 Image
7298 *average_image;
7299
cristyd18ae7c2010-03-07 17:39:52 +00007300 /*
7301 Average an image sequence (deprecated).
7302 */
cristy6b3da3a2010-06-20 02:21:46 +00007303 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007304 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7305 exception);
cristy3ed852e2009-09-05 21:47:34 +00007306 if (average_image == (Image *) NULL)
7307 {
7308 status=MagickFalse;
7309 break;
7310 }
7311 *images=DestroyImageList(*images);
7312 *images=average_image;
7313 break;
7314 }
7315 break;
7316 }
7317 case 'c':
7318 {
7319 if (LocaleCompare("channel",option+1) == 0)
7320 {
cristyf4ad9df2011-07-08 16:49:03 +00007321 ChannelType
7322 channel;
7323
cristy3ed852e2009-09-05 21:47:34 +00007324 if (*option == '+')
7325 {
7326 channel=DefaultChannels;
7327 break;
7328 }
7329 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007330 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007331 break;
7332 }
7333 if (LocaleCompare("clut",option+1) == 0)
7334 {
7335 Image
7336 *clut_image,
7337 *image;
7338
cristy6b3da3a2010-06-20 02:21:46 +00007339 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007340 image=RemoveFirstImageFromList(images);
7341 clut_image=RemoveFirstImageFromList(images);
7342 if (clut_image == (Image *) NULL)
7343 {
7344 status=MagickFalse;
7345 break;
7346 }
cristy444eda62011-08-10 02:07:46 +00007347 (void) ClutImage(image,clut_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007348 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007349 *images=DestroyImageList(*images);
7350 *images=image;
7351 break;
7352 }
7353 if (LocaleCompare("coalesce",option+1) == 0)
7354 {
7355 Image
7356 *coalesce_image;
7357
cristy6b3da3a2010-06-20 02:21:46 +00007358 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007359 coalesce_image=CoalesceImages(*images,exception);
7360 if (coalesce_image == (Image *) NULL)
7361 {
7362 status=MagickFalse;
7363 break;
7364 }
7365 *images=DestroyImageList(*images);
7366 *images=coalesce_image;
7367 break;
7368 }
7369 if (LocaleCompare("combine",option+1) == 0)
7370 {
7371 Image
7372 *combine_image;
7373
cristy6b3da3a2010-06-20 02:21:46 +00007374 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007375 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007376 if (combine_image == (Image *) NULL)
7377 {
7378 status=MagickFalse;
7379 break;
7380 }
7381 *images=DestroyImageList(*images);
7382 *images=combine_image;
7383 break;
7384 }
7385 if (LocaleCompare("composite",option+1) == 0)
7386 {
7387 Image
7388 *mask_image,
7389 *composite_image,
7390 *image;
7391
7392 RectangleInfo
7393 geometry;
7394
cristy6b3da3a2010-06-20 02:21:46 +00007395 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007396 image=RemoveFirstImageFromList(images);
7397 composite_image=RemoveFirstImageFromList(images);
7398 if (composite_image == (Image *) NULL)
7399 {
7400 status=MagickFalse;
7401 break;
7402 }
7403 (void) TransformImage(&composite_image,(char *) NULL,
7404 composite_image->geometry);
7405 SetGeometry(composite_image,&geometry);
7406 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7407 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7408 &geometry);
7409 mask_image=RemoveFirstImageFromList(images);
7410 if (mask_image != (Image *) NULL)
7411 {
7412 if ((image->compose == DisplaceCompositeOp) ||
7413 (image->compose == DistortCompositeOp))
7414 {
7415 /*
7416 Merge Y displacement into X displacement image.
7417 */
7418 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7419 mask_image,0,0);
7420 mask_image=DestroyImage(mask_image);
7421 }
7422 else
7423 {
7424 /*
7425 Set a blending mask for the composition.
7426 */
anthonya129f702011-04-14 01:08:48 +00007427 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007428 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007429 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007430 }
7431 }
cristyf4ad9df2011-07-08 16:49:03 +00007432 (void) CompositeImage(image,image->compose,composite_image,
7433 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007434 if (mask_image != (Image *) NULL)
7435 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007436 composite_image=DestroyImage(composite_image);
7437 InheritException(exception,&image->exception);
7438 *images=DestroyImageList(*images);
7439 *images=image;
7440 break;
7441 }
anthony9f4f0342011-03-28 11:47:22 +00007442#if 0
7443This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007444 if (LocaleCompare("crop",option+1) == 0)
7445 {
7446 MagickStatusType
7447 flags;
7448
7449 RectangleInfo
7450 geometry;
7451
anthonye9c27192011-03-27 08:07:06 +00007452 /*
anthony9f4f0342011-03-28 11:47:22 +00007453 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007454 */
cristy6b3da3a2010-06-20 02:21:46 +00007455 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007456 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7457 if (((geometry.width == 0) && (geometry.height == 0)) ||
7458 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7459 break;
7460 (void) TransformImages(images,argv[i+1],(char *) NULL);
7461 InheritException(exception,&(*images)->exception);
7462 break;
7463 }
anthony9f4f0342011-03-28 11:47:22 +00007464#endif
cristy3ed852e2009-09-05 21:47:34 +00007465 break;
7466 }
7467 case 'd':
7468 {
7469 if (LocaleCompare("deconstruct",option+1) == 0)
7470 {
7471 Image
7472 *deconstruct_image;
7473
cristy6b3da3a2010-06-20 02:21:46 +00007474 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007475 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007476 exception);
cristy3ed852e2009-09-05 21:47:34 +00007477 if (deconstruct_image == (Image *) NULL)
7478 {
7479 status=MagickFalse;
7480 break;
7481 }
7482 *images=DestroyImageList(*images);
7483 *images=deconstruct_image;
7484 break;
7485 }
7486 if (LocaleCompare("delete",option+1) == 0)
7487 {
7488 if (*option == '+')
7489 DeleteImages(images,"-1",exception);
7490 else
7491 DeleteImages(images,argv[i+1],exception);
7492 break;
7493 }
7494 if (LocaleCompare("dither",option+1) == 0)
7495 {
7496 if (*option == '+')
7497 {
7498 quantize_info->dither=MagickFalse;
7499 break;
7500 }
7501 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007502 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007503 MagickDitherOptions,MagickFalse,argv[i+1]);
7504 break;
7505 }
cristyecb10ff2011-03-22 13:14:03 +00007506 if (LocaleCompare("duplicate",option+1) == 0)
7507 {
cristy72988482011-03-29 16:34:38 +00007508 Image
7509 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007510
anthony2b6bcae2011-03-23 13:05:34 +00007511 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007512 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7513 else
7514 {
7515 const char
7516 *p;
7517
anthony2b6bcae2011-03-23 13:05:34 +00007518 size_t
7519 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007520
anthony2b6bcae2011-03-23 13:05:34 +00007521 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007522 p=strchr(argv[i+1],',');
7523 if (p == (const char *) NULL)
7524 duplicate_images=DuplicateImages(*images,number_duplicates,
7525 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007526 else
cristy72988482011-03-29 16:34:38 +00007527 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7528 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007529 }
7530 AppendImageToList(images, duplicate_images);
7531 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007532 break;
7533 }
cristy3ed852e2009-09-05 21:47:34 +00007534 break;
7535 }
cristyd18ae7c2010-03-07 17:39:52 +00007536 case 'e':
7537 {
7538 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7539 {
7540 Image
7541 *evaluate_image;
7542
7543 MagickEvaluateOperator
7544 op;
7545
cristy6b3da3a2010-06-20 02:21:46 +00007546 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007547 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007548 MagickFalse,argv[i+1]);
7549 evaluate_image=EvaluateImages(*images,op,exception);
7550 if (evaluate_image == (Image *) NULL)
7551 {
7552 status=MagickFalse;
7553 break;
7554 }
7555 *images=DestroyImageList(*images);
7556 *images=evaluate_image;
7557 break;
7558 }
7559 break;
7560 }
cristy3ed852e2009-09-05 21:47:34 +00007561 case 'f':
7562 {
cristyf0a247f2009-10-04 00:20:03 +00007563 if (LocaleCompare("fft",option+1) == 0)
7564 {
7565 Image
7566 *fourier_image;
7567
7568 /*
7569 Implements the discrete Fourier transform (DFT).
7570 */
cristy6b3da3a2010-06-20 02:21:46 +00007571 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007572 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7573 MagickTrue : MagickFalse,exception);
7574 if (fourier_image == (Image *) NULL)
7575 break;
7576 *images=DestroyImage(*images);
7577 *images=fourier_image;
7578 break;
7579 }
cristy3ed852e2009-09-05 21:47:34 +00007580 if (LocaleCompare("flatten",option+1) == 0)
7581 {
7582 Image
7583 *flatten_image;
7584
cristy6b3da3a2010-06-20 02:21:46 +00007585 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007586 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7587 if (flatten_image == (Image *) NULL)
7588 break;
7589 *images=DestroyImageList(*images);
7590 *images=flatten_image;
7591 break;
7592 }
7593 if (LocaleCompare("fx",option+1) == 0)
7594 {
7595 Image
7596 *fx_image;
7597
cristy6b3da3a2010-06-20 02:21:46 +00007598 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007599 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007600 if (fx_image == (Image *) NULL)
7601 {
7602 status=MagickFalse;
7603 break;
7604 }
7605 *images=DestroyImageList(*images);
7606 *images=fx_image;
7607 break;
7608 }
7609 break;
7610 }
7611 case 'h':
7612 {
7613 if (LocaleCompare("hald-clut",option+1) == 0)
7614 {
7615 Image
7616 *hald_image,
7617 *image;
7618
cristy6b3da3a2010-06-20 02:21:46 +00007619 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007620 image=RemoveFirstImageFromList(images);
7621 hald_image=RemoveFirstImageFromList(images);
7622 if (hald_image == (Image *) NULL)
7623 {
7624 status=MagickFalse;
7625 break;
7626 }
cristy7c0a0a42011-08-23 17:57:25 +00007627 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007628 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007629 if (*images != (Image *) NULL)
7630 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007631 *images=image;
7632 break;
7633 }
7634 break;
7635 }
7636 case 'i':
7637 {
7638 if (LocaleCompare("ift",option+1) == 0)
7639 {
7640 Image
cristy8587f882009-11-13 20:28:49 +00007641 *fourier_image,
7642 *magnitude_image,
7643 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007644
7645 /*
7646 Implements the inverse fourier discrete Fourier transform (DFT).
7647 */
cristy6b3da3a2010-06-20 02:21:46 +00007648 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007649 magnitude_image=RemoveFirstImageFromList(images);
7650 phase_image=RemoveFirstImageFromList(images);
7651 if (phase_image == (Image *) NULL)
7652 {
7653 status=MagickFalse;
7654 break;
7655 }
7656 fourier_image=InverseFourierTransformImage(magnitude_image,
7657 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007658 if (fourier_image == (Image *) NULL)
7659 break;
cristy0aff6ea2009-11-14 01:40:53 +00007660 if (*images != (Image *) NULL)
7661 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007662 *images=fourier_image;
7663 break;
7664 }
7665 if (LocaleCompare("insert",option+1) == 0)
7666 {
7667 Image
7668 *p,
7669 *q;
7670
7671 index=0;
7672 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007673 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007674 p=RemoveLastImageFromList(images);
7675 if (p == (Image *) NULL)
7676 {
7677 (void) ThrowMagickException(exception,GetMagickModule(),
7678 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7679 status=MagickFalse;
7680 break;
7681 }
7682 q=p;
7683 if (index == 0)
7684 PrependImageToList(images,q);
7685 else
cristybb503372010-05-27 20:51:26 +00007686 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007687 AppendImageToList(images,q);
7688 else
7689 {
7690 q=GetImageFromList(*images,index-1);
7691 if (q == (Image *) NULL)
7692 {
7693 (void) ThrowMagickException(exception,GetMagickModule(),
7694 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7695 status=MagickFalse;
7696 break;
7697 }
7698 InsertImageInList(&q,p);
7699 }
7700 *images=GetFirstImageInList(q);
7701 break;
7702 }
7703 break;
7704 }
7705 case 'l':
7706 {
7707 if (LocaleCompare("layers",option+1) == 0)
7708 {
7709 Image
7710 *layers;
7711
7712 ImageLayerMethod
7713 method;
7714
cristy6b3da3a2010-06-20 02:21:46 +00007715 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007716 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007717 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007718 MagickFalse,argv[i+1]);
7719 switch (method)
7720 {
7721 case CoalesceLayer:
7722 {
7723 layers=CoalesceImages(*images,exception);
7724 break;
7725 }
7726 case CompareAnyLayer:
7727 case CompareClearLayer:
7728 case CompareOverlayLayer:
7729 default:
7730 {
cristy8a9106f2011-07-05 14:39:26 +00007731 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007732 break;
7733 }
7734 case MergeLayer:
7735 case FlattenLayer:
7736 case MosaicLayer:
7737 case TrimBoundsLayer:
7738 {
7739 layers=MergeImageLayers(*images,method,exception);
7740 break;
7741 }
7742 case DisposeLayer:
7743 {
7744 layers=DisposeImages(*images,exception);
7745 break;
7746 }
7747 case OptimizeImageLayer:
7748 {
7749 layers=OptimizeImageLayers(*images,exception);
7750 break;
7751 }
7752 case OptimizePlusLayer:
7753 {
7754 layers=OptimizePlusImageLayers(*images,exception);
7755 break;
7756 }
7757 case OptimizeTransLayer:
7758 {
7759 OptimizeImageTransparency(*images,exception);
7760 break;
7761 }
7762 case RemoveDupsLayer:
7763 {
7764 RemoveDuplicateLayers(images,exception);
7765 break;
7766 }
7767 case RemoveZeroLayer:
7768 {
7769 RemoveZeroDelayLayers(images,exception);
7770 break;
7771 }
7772 case OptimizeLayer:
7773 {
7774 /*
7775 General Purpose, GIF Animation Optimizer.
7776 */
7777 layers=CoalesceImages(*images,exception);
7778 if (layers == (Image *) NULL)
7779 {
7780 status=MagickFalse;
7781 break;
7782 }
cristy3ed852e2009-09-05 21:47:34 +00007783 *images=DestroyImageList(*images);
7784 *images=layers;
7785 layers=OptimizeImageLayers(*images,exception);
7786 if (layers == (Image *) NULL)
7787 {
7788 status=MagickFalse;
7789 break;
7790 }
cristy3ed852e2009-09-05 21:47:34 +00007791 *images=DestroyImageList(*images);
7792 *images=layers;
7793 layers=(Image *) NULL;
7794 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007795 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7796 exception);
cristy3ed852e2009-09-05 21:47:34 +00007797 break;
7798 }
7799 case CompositeLayer:
7800 {
7801 CompositeOperator
7802 compose;
7803
7804 Image
7805 *source;
7806
7807 RectangleInfo
7808 geometry;
7809
7810 /*
7811 Split image sequence at the first 'NULL:' image.
7812 */
7813 source=(*images);
7814 while (source != (Image *) NULL)
7815 {
7816 source=GetNextImageInList(source);
7817 if ((source != (Image *) NULL) &&
7818 (LocaleCompare(source->magick,"NULL") == 0))
7819 break;
7820 }
7821 if (source != (Image *) NULL)
7822 {
7823 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7824 (GetNextImageInList(source) == (Image *) NULL))
7825 source=(Image *) NULL;
7826 else
7827 {
7828 /*
7829 Separate the two lists, junk the null: image.
7830 */
7831 source=SplitImageList(source->previous);
7832 DeleteImageFromList(&source);
7833 }
7834 }
7835 if (source == (Image *) NULL)
7836 {
7837 (void) ThrowMagickException(exception,GetMagickModule(),
7838 OptionError,"MissingNullSeparator","layers Composite");
7839 status=MagickFalse;
7840 break;
7841 }
7842 /*
7843 Adjust offset with gravity and virtual canvas.
7844 */
7845 SetGeometry(*images,&geometry);
7846 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7847 geometry.width=source->page.width != 0 ?
7848 source->page.width : source->columns;
7849 geometry.height=source->page.height != 0 ?
7850 source->page.height : source->rows;
7851 GravityAdjustGeometry((*images)->page.width != 0 ?
7852 (*images)->page.width : (*images)->columns,
7853 (*images)->page.height != 0 ? (*images)->page.height :
7854 (*images)->rows,(*images)->gravity,&geometry);
7855 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007856 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007857 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007858 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007859 MagickComposeOptions,MagickFalse,option);
7860 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7861 exception);
7862 source=DestroyImageList(source);
7863 break;
7864 }
7865 }
7866 if (layers == (Image *) NULL)
7867 break;
7868 InheritException(exception,&layers->exception);
7869 *images=DestroyImageList(*images);
7870 *images=layers;
7871 break;
7872 }
7873 break;
7874 }
7875 case 'm':
7876 {
7877 if (LocaleCompare("map",option+1) == 0)
7878 {
cristy6b3da3a2010-06-20 02:21:46 +00007879 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007880 if (*option == '+')
7881 {
cristy018f07f2011-09-04 21:15:19 +00007882 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7883 exception);
cristy3ed852e2009-09-05 21:47:34 +00007884 break;
7885 }
7886 i++;
7887 break;
7888 }
cristyf40785b2010-03-06 02:27:27 +00007889 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007890 {
7891 Image
cristyf40785b2010-03-06 02:27:27 +00007892 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007893
cristyd18ae7c2010-03-07 17:39:52 +00007894 /*
7895 Maximum image sequence (deprecated).
7896 */
cristy6b3da3a2010-06-20 02:21:46 +00007897 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007898 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007899 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007900 {
7901 status=MagickFalse;
7902 break;
7903 }
7904 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007905 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007906 break;
7907 }
cristyf40785b2010-03-06 02:27:27 +00007908 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007909 {
7910 Image
cristyf40785b2010-03-06 02:27:27 +00007911 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007912
cristyd18ae7c2010-03-07 17:39:52 +00007913 /*
7914 Minimum image sequence (deprecated).
7915 */
cristy6b3da3a2010-06-20 02:21:46 +00007916 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007917 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007918 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007919 {
7920 status=MagickFalse;
7921 break;
7922 }
7923 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007924 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007925 break;
7926 }
cristy3ed852e2009-09-05 21:47:34 +00007927 if (LocaleCompare("morph",option+1) == 0)
7928 {
7929 Image
7930 *morph_image;
7931
cristy6b3da3a2010-06-20 02:21:46 +00007932 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007933 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007934 exception);
7935 if (morph_image == (Image *) NULL)
7936 {
7937 status=MagickFalse;
7938 break;
7939 }
7940 *images=DestroyImageList(*images);
7941 *images=morph_image;
7942 break;
7943 }
7944 if (LocaleCompare("mosaic",option+1) == 0)
7945 {
7946 Image
7947 *mosaic_image;
7948
cristy6b3da3a2010-06-20 02:21:46 +00007949 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007950 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7951 if (mosaic_image == (Image *) NULL)
7952 {
7953 status=MagickFalse;
7954 break;
7955 }
7956 *images=DestroyImageList(*images);
7957 *images=mosaic_image;
7958 break;
7959 }
7960 break;
7961 }
7962 case 'p':
7963 {
7964 if (LocaleCompare("print",option+1) == 0)
7965 {
7966 char
7967 *string;
7968
cristy6b3da3a2010-06-20 02:21:46 +00007969 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007970 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7971 exception);
cristy3ed852e2009-09-05 21:47:34 +00007972 if (string == (char *) NULL)
7973 break;
cristyb51dff52011-05-19 16:55:47 +00007974 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007975 string=DestroyString(string);
7976 }
7977 if (LocaleCompare("process",option+1) == 0)
7978 {
7979 char
7980 **arguments;
7981
7982 int
7983 j,
7984 number_arguments;
7985
cristy6b3da3a2010-06-20 02:21:46 +00007986 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007987 arguments=StringToArgv(argv[i+1],&number_arguments);
7988 if (arguments == (char **) NULL)
7989 break;
7990 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7991 {
7992 char
7993 breaker,
7994 quote,
7995 *token;
7996
7997 const char
7998 *arguments;
7999
8000 int
8001 next,
8002 status;
8003
8004 size_t
8005 length;
8006
8007 TokenInfo
8008 *token_info;
8009
8010 /*
8011 Support old style syntax, filter="-option arg".
8012 */
8013 length=strlen(argv[i+1]);
8014 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008015 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008016 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8017 sizeof(*token));
8018 if (token == (char *) NULL)
8019 break;
8020 next=0;
8021 arguments=argv[i+1];
8022 token_info=AcquireTokenInfo();
8023 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8024 "\"",'\0',&breaker,&next,&quote);
8025 token_info=DestroyTokenInfo(token_info);
8026 if (status == 0)
8027 {
8028 const char
8029 *argv;
8030
8031 argv=(&(arguments[next]));
8032 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8033 exception);
8034 }
8035 token=DestroyString(token);
8036 break;
8037 }
cristy91c0da22010-05-02 01:44:07 +00008038 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008039 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8040 number_arguments-2,(const char **) arguments+2,exception);
8041 for (j=0; j < number_arguments; j++)
8042 arguments[j]=DestroyString(arguments[j]);
8043 arguments=(char **) RelinquishMagickMemory(arguments);
8044 break;
8045 }
8046 break;
8047 }
8048 case 'r':
8049 {
8050 if (LocaleCompare("reverse",option+1) == 0)
8051 {
8052 ReverseImageList(images);
8053 InheritException(exception,&(*images)->exception);
8054 break;
8055 }
8056 break;
8057 }
8058 case 's':
8059 {
cristy4285d782011-02-09 20:12:28 +00008060 if (LocaleCompare("smush",option+1) == 0)
8061 {
8062 Image
8063 *smush_image;
8064
8065 ssize_t
8066 offset;
8067
8068 (void) SyncImagesSettings(mogrify_info,*images);
8069 offset=(ssize_t) StringToLong(argv[i+1]);
8070 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8071 MagickFalse,offset,exception);
8072 if (smush_image == (Image *) NULL)
8073 {
8074 status=MagickFalse;
8075 break;
8076 }
8077 *images=DestroyImageList(*images);
8078 *images=smush_image;
8079 break;
8080 }
cristy3ed852e2009-09-05 21:47:34 +00008081 if (LocaleCompare("swap",option+1) == 0)
8082 {
8083 Image
8084 *p,
8085 *q,
8086 *swap;
8087
cristybb503372010-05-27 20:51:26 +00008088 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008089 swap_index;
8090
8091 index=(-1);
8092 swap_index=(-2);
8093 if (*option != '+')
8094 {
8095 GeometryInfo
8096 geometry_info;
8097
8098 MagickStatusType
8099 flags;
8100
8101 swap_index=(-1);
8102 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008103 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008104 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008105 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008106 }
8107 p=GetImageFromList(*images,index);
8108 q=GetImageFromList(*images,swap_index);
8109 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8110 {
8111 (void) ThrowMagickException(exception,GetMagickModule(),
8112 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8113 status=MagickFalse;
8114 break;
8115 }
8116 if (p == q)
8117 break;
8118 swap=CloneImage(p,0,0,MagickTrue,exception);
8119 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8120 ReplaceImageInList(&q,swap);
8121 *images=GetFirstImageInList(q);
8122 break;
8123 }
8124 break;
8125 }
8126 case 'w':
8127 {
8128 if (LocaleCompare("write",option+1) == 0)
8129 {
cristy071dd7b2010-04-09 13:04:54 +00008130 char
cristy06609ee2010-03-17 20:21:27 +00008131 key[MaxTextExtent];
8132
cristy3ed852e2009-09-05 21:47:34 +00008133 Image
8134 *write_images;
8135
8136 ImageInfo
8137 *write_info;
8138
cristy6b3da3a2010-06-20 02:21:46 +00008139 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008140 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008141 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008142 write_images=(*images);
8143 if (*option == '+')
8144 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008145 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008146 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8147 write_info=DestroyImageInfo(write_info);
8148 if (*option == '+')
8149 write_images=DestroyImageList(write_images);
8150 break;
8151 }
8152 break;
8153 }
8154 default:
8155 break;
8156 }
8157 i+=count;
8158 }
8159 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008160 mogrify_info=DestroyImageInfo(mogrify_info);
8161 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008162 return(status != 0 ? MagickTrue : MagickFalse);
8163}
8164
8165/*
8166%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8167% %
8168% %
8169% %
8170+ M o g r i f y I m a g e s %
8171% %
8172% %
8173% %
8174%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8175%
8176% MogrifyImages() applies image processing options to a sequence of images as
8177% prescribed by command line options.
8178%
8179% The format of the MogrifyImage method is:
8180%
8181% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8182% const MagickBooleanType post,const int argc,const char **argv,
8183% Image **images,Exceptioninfo *exception)
8184%
8185% A description of each parameter follows:
8186%
8187% o image_info: the image info..
8188%
8189% o post: If true, post process image list operators otherwise pre-process.
8190%
8191% o argc: Specifies a pointer to an integer describing the number of
8192% elements in the argument vector.
8193%
8194% o argv: Specifies a pointer to a text array containing the command line
8195% arguments.
8196%
anthonye9c27192011-03-27 08:07:06 +00008197% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008198%
8199% o exception: return any errors or warnings in this structure.
8200%
8201*/
8202WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8203 const MagickBooleanType post,const int argc,const char **argv,
8204 Image **images,ExceptionInfo *exception)
8205{
8206#define MogrifyImageTag "Mogrify/Image"
8207
anthonye9c27192011-03-27 08:07:06 +00008208 MagickStatusType
8209 status;
cristy3ed852e2009-09-05 21:47:34 +00008210
cristy0e9f9c12010-02-11 03:00:47 +00008211 MagickBooleanType
8212 proceed;
8213
anthonye9c27192011-03-27 08:07:06 +00008214 size_t
8215 n;
cristy3ed852e2009-09-05 21:47:34 +00008216
cristybb503372010-05-27 20:51:26 +00008217 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008218 i;
8219
cristy3ed852e2009-09-05 21:47:34 +00008220 assert(image_info != (ImageInfo *) NULL);
8221 assert(image_info->signature == MagickSignature);
8222 if (images == (Image **) NULL)
8223 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008224 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008225 assert((*images)->signature == MagickSignature);
8226 if ((*images)->debug != MagickFalse)
8227 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8228 (*images)->filename);
8229 if ((argc <= 0) || (*argv == (char *) NULL))
8230 return(MagickTrue);
8231 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8232 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008233 status=0;
anthonye9c27192011-03-27 08:07:06 +00008234
anthonyce2716b2011-04-22 09:51:34 +00008235#if 0
cristy1e604812011-05-19 18:07:50 +00008236 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8237 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008238#endif
8239
anthonye9c27192011-03-27 08:07:06 +00008240 /*
8241 Pre-process multi-image sequence operators
8242 */
cristy3ed852e2009-09-05 21:47:34 +00008243 if (post == MagickFalse)
8244 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008245 /*
8246 For each image, process simple single image operators
8247 */
8248 i=0;
8249 n=GetImageListLength(*images);
8250 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008251 {
anthonyce2716b2011-04-22 09:51:34 +00008252#if 0
cristy1e604812011-05-19 18:07:50 +00008253 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8254 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008255#endif
anthonye9c27192011-03-27 08:07:06 +00008256 status&=MogrifyImage(image_info,argc,argv,images,exception);
8257 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008258 if (proceed == MagickFalse)
8259 break;
anthonye9c27192011-03-27 08:07:06 +00008260 if ( (*images)->next == (Image *) NULL )
8261 break;
8262 *images=(*images)->next;
8263 i++;
cristy3ed852e2009-09-05 21:47:34 +00008264 }
anthonye9c27192011-03-27 08:07:06 +00008265 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008266#if 0
cristy1e604812011-05-19 18:07:50 +00008267 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8268 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008269#endif
anthonye9c27192011-03-27 08:07:06 +00008270
8271 /*
8272 Post-process, multi-image sequence operators
8273 */
8274 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008275 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008276 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008277 return(status != 0 ? MagickTrue : MagickFalse);
8278}