blob: bfcee27065172ec2726baf98baf383d2f6d80e6d [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);
cristy6435bd92011-09-10 02:10:07 +00002362 flags=ParseGeometry(argv[i+1],&geometry_info);
2363 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2364 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002365 break;
2366 }
2367 if (LocaleCompare("raise",option+1) == 0)
2368 {
2369 /*
2370 Surround image with a raise of solid color.
2371 */
2372 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2373 if ((flags & SigmaValue) == 0)
2374 geometry.height=geometry.width;
2375 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002376 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002377 break;
2378 }
2379 if (LocaleCompare("random-threshold",option+1) == 0)
2380 {
2381 /*
2382 Threshold image.
2383 */
2384 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002385 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002386 break;
2387 }
2388 if (LocaleCompare("recolor",option+1) == 0)
2389 {
2390 KernelInfo
2391 *kernel;
2392
2393 (void) SyncImageSettings(mogrify_info,*image);
2394 kernel=AcquireKernelInfo(argv[i+1]);
2395 if (kernel == (KernelInfo *) NULL)
2396 break;
2397 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2398 kernel=DestroyKernelInfo(kernel);
2399 break;
2400 }
2401 if (LocaleCompare("region",option+1) == 0)
2402 {
2403 (void) SyncImageSettings(mogrify_info,*image);
2404 if (region_image != (Image *) NULL)
2405 {
2406 /*
2407 Composite region.
2408 */
2409 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002410 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2411 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002412 InheritException(exception,&region_image->exception);
2413 *image=DestroyImage(*image);
2414 *image=region_image;
2415 region_image = (Image *) NULL;
2416 }
2417 if (*option == '+')
2418 break;
2419 /*
2420 Apply transformations to a selected region of the image.
2421 */
cristy3ed852e2009-09-05 21:47:34 +00002422 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2423 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002424 mogrify_image=CropImage(*image,&region_geometry,exception);
2425 if (mogrify_image == (Image *) NULL)
2426 break;
2427 region_image=(*image);
2428 *image=mogrify_image;
2429 mogrify_image=(Image *) NULL;
2430 break;
cristy3ed852e2009-09-05 21:47:34 +00002431 }
anthonydf8ebac2011-04-27 09:03:19 +00002432 if (LocaleCompare("render",option+1) == 0)
2433 {
2434 (void) SyncImageSettings(mogrify_info,*image);
2435 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2436 break;
2437 }
2438 if (LocaleCompare("remap",option+1) == 0)
2439 {
2440 Image
2441 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002442
anthonydf8ebac2011-04-27 09:03:19 +00002443 /*
2444 Transform image colors to match this set of colors.
2445 */
2446 (void) SyncImageSettings(mogrify_info,*image);
2447 if (*option == '+')
2448 break;
2449 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2450 if (remap_image == (Image *) NULL)
2451 break;
cristy018f07f2011-09-04 21:15:19 +00002452 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002453 remap_image=DestroyImage(remap_image);
2454 break;
2455 }
2456 if (LocaleCompare("repage",option+1) == 0)
2457 {
2458 if (*option == '+')
2459 {
2460 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2461 break;
2462 }
2463 (void) ResetImagePage(*image,argv[i+1]);
2464 InheritException(exception,&(*image)->exception);
2465 break;
2466 }
2467 if (LocaleCompare("resample",option+1) == 0)
2468 {
2469 /*
2470 Resample image.
2471 */
2472 (void) SyncImageSettings(mogrify_info,*image);
2473 flags=ParseGeometry(argv[i+1],&geometry_info);
2474 if ((flags & SigmaValue) == 0)
2475 geometry_info.sigma=geometry_info.rho;
2476 mogrify_image=ResampleImage(*image,geometry_info.rho,
2477 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2478 break;
2479 }
2480 if (LocaleCompare("resize",option+1) == 0)
2481 {
2482 /*
2483 Resize image.
2484 */
2485 (void) SyncImageSettings(mogrify_info,*image);
2486 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2487 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2488 (*image)->filter,(*image)->blur,exception);
2489 break;
2490 }
2491 if (LocaleCompare("roll",option+1) == 0)
2492 {
2493 /*
2494 Roll image.
2495 */
2496 (void) SyncImageSettings(mogrify_info,*image);
2497 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2498 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2499 break;
2500 }
2501 if (LocaleCompare("rotate",option+1) == 0)
2502 {
2503 char
2504 *geometry;
2505
2506 /*
2507 Check for conditional image rotation.
2508 */
2509 (void) SyncImageSettings(mogrify_info,*image);
2510 if (strchr(argv[i+1],'>') != (char *) NULL)
2511 if ((*image)->columns <= (*image)->rows)
2512 break;
2513 if (strchr(argv[i+1],'<') != (char *) NULL)
2514 if ((*image)->columns >= (*image)->rows)
2515 break;
2516 /*
2517 Rotate image.
2518 */
2519 geometry=ConstantString(argv[i+1]);
2520 (void) SubstituteString(&geometry,">","");
2521 (void) SubstituteString(&geometry,"<","");
2522 (void) ParseGeometry(geometry,&geometry_info);
2523 geometry=DestroyString(geometry);
2524 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2525 break;
2526 }
2527 break;
2528 }
2529 case 's':
2530 {
2531 if (LocaleCompare("sample",option+1) == 0)
2532 {
2533 /*
2534 Sample image with pixel replication.
2535 */
2536 (void) SyncImageSettings(mogrify_info,*image);
2537 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2538 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2539 exception);
2540 break;
2541 }
2542 if (LocaleCompare("scale",option+1) == 0)
2543 {
2544 /*
2545 Resize image.
2546 */
2547 (void) SyncImageSettings(mogrify_info,*image);
2548 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2549 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2550 exception);
2551 break;
2552 }
2553 if (LocaleCompare("selective-blur",option+1) == 0)
2554 {
2555 /*
2556 Selectively blur pixels within a contrast threshold.
2557 */
2558 (void) SyncImageSettings(mogrify_info,*image);
2559 flags=ParseGeometry(argv[i+1],&geometry_info);
2560 if ((flags & PercentValue) != 0)
2561 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002562 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2563 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002564 break;
2565 }
2566 if (LocaleCompare("separate",option+1) == 0)
2567 {
2568 /*
2569 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002570 */
2571 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002572 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002573 break;
2574 }
2575 if (LocaleCompare("sepia-tone",option+1) == 0)
2576 {
2577 double
2578 threshold;
2579
2580 /*
2581 Sepia-tone image.
2582 */
2583 (void) SyncImageSettings(mogrify_info,*image);
2584 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2585 mogrify_image=SepiaToneImage(*image,threshold,exception);
2586 break;
2587 }
2588 if (LocaleCompare("segment",option+1) == 0)
2589 {
2590 /*
2591 Segment image.
2592 */
2593 (void) SyncImageSettings(mogrify_info,*image);
2594 flags=ParseGeometry(argv[i+1],&geometry_info);
2595 if ((flags & SigmaValue) == 0)
2596 geometry_info.sigma=1.0;
2597 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002598 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2599 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002600 break;
2601 }
2602 if (LocaleCompare("set",option+1) == 0)
2603 {
2604 char
2605 *value;
2606
2607 /*
2608 Set image option.
2609 */
2610 if (*option == '+')
2611 {
2612 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2613 (void) DeleteImageRegistry(argv[i+1]+9);
2614 else
2615 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2616 {
2617 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2618 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2619 }
2620 else
2621 (void) DeleteImageProperty(*image,argv[i+1]);
2622 break;
2623 }
cristy018f07f2011-09-04 21:15:19 +00002624 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2625 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002626 if (value == (char *) NULL)
2627 break;
2628 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2629 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2630 exception);
2631 else
2632 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2633 {
2634 (void) SetImageOption(image_info,argv[i+1]+7,value);
2635 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2636 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2637 }
2638 else
2639 (void) SetImageProperty(*image,argv[i+1],value);
2640 value=DestroyString(value);
2641 break;
2642 }
2643 if (LocaleCompare("shade",option+1) == 0)
2644 {
2645 /*
2646 Shade image.
2647 */
2648 (void) SyncImageSettings(mogrify_info,*image);
2649 flags=ParseGeometry(argv[i+1],&geometry_info);
2650 if ((flags & SigmaValue) == 0)
2651 geometry_info.sigma=1.0;
2652 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2653 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2654 break;
2655 }
2656 if (LocaleCompare("shadow",option+1) == 0)
2657 {
2658 /*
2659 Shadow image.
2660 */
2661 (void) SyncImageSettings(mogrify_info,*image);
2662 flags=ParseGeometry(argv[i+1],&geometry_info);
2663 if ((flags & SigmaValue) == 0)
2664 geometry_info.sigma=1.0;
2665 if ((flags & XiValue) == 0)
2666 geometry_info.xi=4.0;
2667 if ((flags & PsiValue) == 0)
2668 geometry_info.psi=4.0;
2669 mogrify_image=ShadowImage(*image,geometry_info.rho,
2670 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2671 ceil(geometry_info.psi-0.5),exception);
2672 break;
2673 }
2674 if (LocaleCompare("sharpen",option+1) == 0)
2675 {
2676 /*
2677 Sharpen image.
2678 */
2679 (void) SyncImageSettings(mogrify_info,*image);
2680 flags=ParseGeometry(argv[i+1],&geometry_info);
2681 if ((flags & SigmaValue) == 0)
2682 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002683 if ((flags & XiValue) == 0)
2684 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002685 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002686 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002687 break;
2688 }
2689 if (LocaleCompare("shave",option+1) == 0)
2690 {
2691 /*
2692 Shave the image edges.
2693 */
2694 (void) SyncImageSettings(mogrify_info,*image);
2695 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2696 mogrify_image=ShaveImage(*image,&geometry,exception);
2697 break;
2698 }
2699 if (LocaleCompare("shear",option+1) == 0)
2700 {
2701 /*
2702 Shear image.
2703 */
2704 (void) SyncImageSettings(mogrify_info,*image);
2705 flags=ParseGeometry(argv[i+1],&geometry_info);
2706 if ((flags & SigmaValue) == 0)
2707 geometry_info.sigma=geometry_info.rho;
2708 mogrify_image=ShearImage(*image,geometry_info.rho,
2709 geometry_info.sigma,exception);
2710 break;
2711 }
2712 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2713 {
2714 /*
2715 Sigmoidal non-linearity contrast control.
2716 */
2717 (void) SyncImageSettings(mogrify_info,*image);
2718 flags=ParseGeometry(argv[i+1],&geometry_info);
2719 if ((flags & SigmaValue) == 0)
2720 geometry_info.sigma=(double) QuantumRange/2.0;
2721 if ((flags & PercentValue) != 0)
2722 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2723 100.0;
cristy9ee60942011-07-06 14:54:38 +00002724 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002725 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2726 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002727 break;
2728 }
2729 if (LocaleCompare("sketch",option+1) == 0)
2730 {
2731 /*
2732 Sketch image.
2733 */
2734 (void) SyncImageSettings(mogrify_info,*image);
2735 flags=ParseGeometry(argv[i+1],&geometry_info);
2736 if ((flags & SigmaValue) == 0)
2737 geometry_info.sigma=1.0;
2738 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002739 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002740 break;
2741 }
2742 if (LocaleCompare("solarize",option+1) == 0)
2743 {
2744 double
2745 threshold;
2746
2747 (void) SyncImageSettings(mogrify_info,*image);
2748 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002749 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002750 break;
2751 }
2752 if (LocaleCompare("sparse-color",option+1) == 0)
2753 {
2754 SparseColorMethod
2755 method;
2756
2757 char
2758 *arguments;
2759
2760 /*
2761 Sparse Color Interpolated Gradient
2762 */
2763 (void) SyncImageSettings(mogrify_info,*image);
2764 method=(SparseColorMethod) ParseCommandOption(
2765 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002766 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2767 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002768 if (arguments == (char *) NULL)
2769 break;
cristy3884f692011-07-08 18:00:18 +00002770 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002771 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2772 arguments=DestroyString(arguments);
2773 break;
2774 }
2775 if (LocaleCompare("splice",option+1) == 0)
2776 {
2777 /*
2778 Splice a solid color into the image.
2779 */
2780 (void) SyncImageSettings(mogrify_info,*image);
2781 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2782 mogrify_image=SpliceImage(*image,&geometry,exception);
2783 break;
2784 }
2785 if (LocaleCompare("spread",option+1) == 0)
2786 {
2787 /*
2788 Spread an image.
2789 */
2790 (void) SyncImageSettings(mogrify_info,*image);
2791 (void) ParseGeometry(argv[i+1],&geometry_info);
2792 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2793 break;
2794 }
2795 if (LocaleCompare("statistic",option+1) == 0)
2796 {
2797 StatisticType
2798 type;
2799
2800 (void) SyncImageSettings(mogrify_info,*image);
2801 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2802 MagickFalse,argv[i+1]);
2803 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002804 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2805 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002806 break;
2807 }
2808 if (LocaleCompare("stretch",option+1) == 0)
2809 {
2810 if (*option == '+')
2811 {
2812 draw_info->stretch=UndefinedStretch;
2813 break;
2814 }
2815 draw_info->stretch=(StretchType) ParseCommandOption(
2816 MagickStretchOptions,MagickFalse,argv[i+1]);
2817 break;
2818 }
2819 if (LocaleCompare("strip",option+1) == 0)
2820 {
2821 /*
2822 Strip image of profiles and comments.
2823 */
2824 (void) SyncImageSettings(mogrify_info,*image);
2825 (void) StripImage(*image);
2826 InheritException(exception,&(*image)->exception);
2827 break;
2828 }
2829 if (LocaleCompare("stroke",option+1) == 0)
2830 {
2831 ExceptionInfo
2832 *sans;
2833
2834 if (*option == '+')
2835 {
2836 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2837 if (draw_info->stroke_pattern != (Image *) NULL)
2838 draw_info->stroke_pattern=DestroyImage(
2839 draw_info->stroke_pattern);
2840 break;
2841 }
2842 sans=AcquireExceptionInfo();
2843 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2844 sans=DestroyExceptionInfo(sans);
2845 if (status == MagickFalse)
2846 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2847 exception);
2848 break;
2849 }
2850 if (LocaleCompare("strokewidth",option+1) == 0)
2851 {
cristyc1acd842011-05-19 23:05:47 +00002852 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2853 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002854 break;
2855 }
2856 if (LocaleCompare("style",option+1) == 0)
2857 {
2858 if (*option == '+')
2859 {
2860 draw_info->style=UndefinedStyle;
2861 break;
2862 }
2863 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2864 MagickFalse,argv[i+1]);
2865 break;
2866 }
2867 if (LocaleCompare("swirl",option+1) == 0)
2868 {
2869 /*
2870 Swirl image.
2871 */
2872 (void) SyncImageSettings(mogrify_info,*image);
2873 (void) ParseGeometry(argv[i+1],&geometry_info);
2874 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2875 break;
2876 }
2877 break;
2878 }
2879 case 't':
2880 {
2881 if (LocaleCompare("threshold",option+1) == 0)
2882 {
2883 double
2884 threshold;
2885
2886 /*
2887 Threshold image.
2888 */
2889 (void) SyncImageSettings(mogrify_info,*image);
2890 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002891 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002892 else
2893 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002894 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002895 InheritException(exception,&(*image)->exception);
2896 break;
2897 }
2898 if (LocaleCompare("thumbnail",option+1) == 0)
2899 {
2900 /*
2901 Thumbnail image.
2902 */
2903 (void) SyncImageSettings(mogrify_info,*image);
2904 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2905 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2906 exception);
2907 break;
2908 }
2909 if (LocaleCompare("tile",option+1) == 0)
2910 {
2911 if (*option == '+')
2912 {
2913 if (draw_info->fill_pattern != (Image *) NULL)
2914 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2915 break;
2916 }
2917 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2918 exception);
2919 break;
2920 }
2921 if (LocaleCompare("tint",option+1) == 0)
2922 {
2923 /*
2924 Tint the image.
2925 */
2926 (void) SyncImageSettings(mogrify_info,*image);
2927 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2928 break;
2929 }
2930 if (LocaleCompare("transform",option+1) == 0)
2931 {
2932 /*
2933 Affine transform image.
2934 */
2935 (void) SyncImageSettings(mogrify_info,*image);
2936 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2937 exception);
2938 break;
2939 }
2940 if (LocaleCompare("transparent",option+1) == 0)
2941 {
cristy4c08aed2011-07-01 19:47:50 +00002942 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002943 target;
2944
2945 (void) SyncImageSettings(mogrify_info,*image);
2946 (void) QueryMagickColor(argv[i+1],&target,exception);
2947 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002948 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2949 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002950 break;
2951 }
2952 if (LocaleCompare("transpose",option+1) == 0)
2953 {
2954 /*
2955 Transpose image scanlines.
2956 */
2957 (void) SyncImageSettings(mogrify_info,*image);
2958 mogrify_image=TransposeImage(*image,exception);
2959 break;
2960 }
2961 if (LocaleCompare("transverse",option+1) == 0)
2962 {
2963 /*
2964 Transverse image scanlines.
2965 */
2966 (void) SyncImageSettings(mogrify_info,*image);
2967 mogrify_image=TransverseImage(*image,exception);
2968 break;
2969 }
2970 if (LocaleCompare("treedepth",option+1) == 0)
2971 {
2972 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2973 break;
2974 }
2975 if (LocaleCompare("trim",option+1) == 0)
2976 {
2977 /*
2978 Trim image.
2979 */
2980 (void) SyncImageSettings(mogrify_info,*image);
2981 mogrify_image=TrimImage(*image,exception);
2982 break;
2983 }
2984 if (LocaleCompare("type",option+1) == 0)
2985 {
2986 ImageType
2987 type;
2988
2989 (void) SyncImageSettings(mogrify_info,*image);
2990 if (*option == '+')
2991 type=UndefinedType;
2992 else
2993 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2994 argv[i+1]);
2995 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00002996 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002997 break;
2998 }
2999 break;
3000 }
3001 case 'u':
3002 {
3003 if (LocaleCompare("undercolor",option+1) == 0)
3004 {
3005 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3006 exception);
3007 break;
3008 }
3009 if (LocaleCompare("unique",option+1) == 0)
3010 {
3011 if (*option == '+')
3012 {
3013 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3014 break;
3015 }
3016 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3017 (void) SetImageArtifact(*image,"verbose","true");
3018 break;
3019 }
3020 if (LocaleCompare("unique-colors",option+1) == 0)
3021 {
3022 /*
3023 Unique image colors.
3024 */
3025 (void) SyncImageSettings(mogrify_info,*image);
3026 mogrify_image=UniqueImageColors(*image,exception);
3027 break;
3028 }
3029 if (LocaleCompare("unsharp",option+1) == 0)
3030 {
3031 /*
3032 Unsharp mask image.
3033 */
3034 (void) SyncImageSettings(mogrify_info,*image);
3035 flags=ParseGeometry(argv[i+1],&geometry_info);
3036 if ((flags & SigmaValue) == 0)
3037 geometry_info.sigma=1.0;
3038 if ((flags & XiValue) == 0)
3039 geometry_info.xi=1.0;
3040 if ((flags & PsiValue) == 0)
3041 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003042 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3043 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003044 break;
3045 }
3046 break;
3047 }
3048 case 'v':
3049 {
3050 if (LocaleCompare("verbose",option+1) == 0)
3051 {
3052 (void) SetImageArtifact(*image,option+1,
3053 *option == '+' ? "false" : "true");
3054 break;
3055 }
3056 if (LocaleCompare("vignette",option+1) == 0)
3057 {
3058 /*
3059 Vignette image.
3060 */
3061 (void) SyncImageSettings(mogrify_info,*image);
3062 flags=ParseGeometry(argv[i+1],&geometry_info);
3063 if ((flags & SigmaValue) == 0)
3064 geometry_info.sigma=1.0;
3065 if ((flags & XiValue) == 0)
3066 geometry_info.xi=0.1*(*image)->columns;
3067 if ((flags & PsiValue) == 0)
3068 geometry_info.psi=0.1*(*image)->rows;
3069 mogrify_image=VignetteImage(*image,geometry_info.rho,
3070 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3071 ceil(geometry_info.psi-0.5),exception);
3072 break;
3073 }
3074 if (LocaleCompare("virtual-pixel",option+1) == 0)
3075 {
3076 if (*option == '+')
3077 {
3078 (void) SetImageVirtualPixelMethod(*image,
3079 UndefinedVirtualPixelMethod);
3080 break;
3081 }
3082 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3083 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3084 argv[i+1]));
3085 break;
3086 }
3087 break;
3088 }
3089 case 'w':
3090 {
3091 if (LocaleCompare("wave",option+1) == 0)
3092 {
3093 /*
3094 Wave image.
3095 */
3096 (void) SyncImageSettings(mogrify_info,*image);
3097 flags=ParseGeometry(argv[i+1],&geometry_info);
3098 if ((flags & SigmaValue) == 0)
3099 geometry_info.sigma=1.0;
3100 mogrify_image=WaveImage(*image,geometry_info.rho,
3101 geometry_info.sigma,exception);
3102 break;
3103 }
3104 if (LocaleCompare("weight",option+1) == 0)
3105 {
3106 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3107 if (LocaleCompare(argv[i+1],"all") == 0)
3108 draw_info->weight=0;
3109 if (LocaleCompare(argv[i+1],"bold") == 0)
3110 draw_info->weight=700;
3111 if (LocaleCompare(argv[i+1],"bolder") == 0)
3112 if (draw_info->weight <= 800)
3113 draw_info->weight+=100;
3114 if (LocaleCompare(argv[i+1],"lighter") == 0)
3115 if (draw_info->weight >= 100)
3116 draw_info->weight-=100;
3117 if (LocaleCompare(argv[i+1],"normal") == 0)
3118 draw_info->weight=400;
3119 break;
3120 }
3121 if (LocaleCompare("white-threshold",option+1) == 0)
3122 {
3123 /*
3124 White threshold image.
3125 */
3126 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003127 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003128 InheritException(exception,&(*image)->exception);
3129 break;
3130 }
3131 break;
3132 }
3133 default:
3134 break;
3135 }
3136 /*
3137 Replace current image with any image that was generated
3138 */
3139 if (mogrify_image != (Image *) NULL)
3140 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003141 i+=count;
3142 }
3143 if (region_image != (Image *) NULL)
3144 {
anthonydf8ebac2011-04-27 09:03:19 +00003145 /*
3146 Composite transformed region onto image.
3147 */
cristy6b3da3a2010-06-20 02:21:46 +00003148 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003149 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003150 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3151 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003152 InheritException(exception,&region_image->exception);
3153 *image=DestroyImage(*image);
3154 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003155 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003156 }
3157 /*
3158 Free resources.
3159 */
anthonydf8ebac2011-04-27 09:03:19 +00003160 quantize_info=DestroyQuantizeInfo(quantize_info);
3161 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003162 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003163 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003164 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003165 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003166}
3167
3168/*
3169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3170% %
3171% %
3172% %
cristy5063d812010-10-19 16:28:10 +00003173+ 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 +00003174% %
3175% %
3176% %
3177%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3178%
3179% MogrifyImageCommand() transforms an image or a sequence of images. These
3180% transforms include image scaling, image rotation, color reduction, and
3181% others. The transmogrified image overwrites the original image.
3182%
3183% The format of the MogrifyImageCommand method is:
3184%
3185% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3186% const char **argv,char **metadata,ExceptionInfo *exception)
3187%
3188% A description of each parameter follows:
3189%
3190% o image_info: the image info.
3191%
3192% o argc: the number of elements in the argument vector.
3193%
3194% o argv: A text array containing the command line arguments.
3195%
3196% o metadata: any metadata is returned here.
3197%
3198% o exception: return any errors or warnings in this structure.
3199%
3200*/
3201
3202static MagickBooleanType MogrifyUsage(void)
3203{
3204 static const char
3205 *miscellaneous[]=
3206 {
3207 "-debug events display copious debugging information",
3208 "-help print program options",
3209 "-list type print a list of supported option arguments",
3210 "-log format format of debugging information",
3211 "-version print version information",
3212 (char *) NULL
3213 },
3214 *operators[]=
3215 {
3216 "-adaptive-blur geometry",
3217 " adaptively blur pixels; decrease effect near edges",
3218 "-adaptive-resize geometry",
3219 " adaptively resize image using 'mesh' interpolation",
3220 "-adaptive-sharpen geometry",
3221 " adaptively sharpen pixels; increase effect near edges",
3222 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3223 " transparent, extract, background, or shape",
3224 "-annotate geometry text",
3225 " annotate the image with text",
3226 "-auto-gamma automagically adjust gamma level of image",
3227 "-auto-level automagically adjust color levels of image",
3228 "-auto-orient automagically orient (rotate) image",
3229 "-bench iterations measure performance",
3230 "-black-threshold value",
3231 " force all pixels below the threshold into black",
3232 "-blue-shift simulate a scene at nighttime in the moonlight",
3233 "-blur geometry reduce image noise and reduce detail levels",
3234 "-border geometry surround image with a border of color",
3235 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003236 "-brightness-contrast geometry",
3237 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003238 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003239 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003240 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003241 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003242 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003243 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003244 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003245 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003246 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003247 "-contrast enhance or reduce the image contrast",
3248 "-contrast-stretch geometry",
3249 " improve contrast by `stretching' the intensity range",
3250 "-convolve coefficients",
3251 " apply a convolution kernel to the image",
3252 "-cycle amount cycle the image colormap",
3253 "-decipher filename convert cipher pixels to plain pixels",
3254 "-deskew threshold straighten an image",
3255 "-despeckle reduce the speckles within an image",
3256 "-distort method args",
3257 " distort images according to given method ad args",
3258 "-draw string annotate the image with a graphic primitive",
3259 "-edge radius apply a filter to detect edges in the image",
3260 "-encipher filename convert plain pixels to cipher pixels",
3261 "-emboss radius emboss an image",
3262 "-enhance apply a digital filter to enhance a noisy image",
3263 "-equalize perform histogram equalization to an image",
3264 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003265 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003266 "-extent geometry set the image size",
3267 "-extract geometry extract area from image",
3268 "-fft implements the discrete Fourier transform (DFT)",
3269 "-flip flip image vertically",
3270 "-floodfill geometry color",
3271 " floodfill the image with color",
3272 "-flop flop image horizontally",
3273 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003274 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003275 " apply function over image values",
3276 "-gamma value level of gamma correction",
3277 "-gaussian-blur geometry",
3278 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003279 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003280 "-identify identify the format and characteristics of the image",
3281 "-ift implements the inverse discrete Fourier transform (DFT)",
3282 "-implode amount implode image pixels about the center",
3283 "-lat geometry local adaptive thresholding",
3284 "-layers method optimize, merge, or compare image layers",
3285 "-level value adjust the level of image contrast",
3286 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003287 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003288 "-linear-stretch geometry",
3289 " improve contrast by `stretching with saturation'",
3290 "-liquid-rescale geometry",
3291 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003292 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003293 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003294 "-modulate value vary the brightness, saturation, and hue",
3295 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003296 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003297 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003298 "-motion-blur geometry",
3299 " simulate motion blur",
3300 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003301 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003302 "-normalize transform image to span the full range of colors",
3303 "-opaque color change this color to the fill color",
3304 "-ordered-dither NxN",
3305 " add a noise pattern to the image with specific",
3306 " amplitudes",
3307 "-paint radius simulate an oil painting",
3308 "-polaroid angle simulate a Polaroid picture",
3309 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003310 "-profile filename add, delete, or apply an image profile",
3311 "-quantize colorspace reduce colors in this colorspace",
3312 "-radial-blur angle radial blur the image",
3313 "-raise value lighten/darken image edges to create a 3-D effect",
3314 "-random-threshold low,high",
3315 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003316 "-region geometry apply options to a portion of the image",
3317 "-render render vector graphics",
3318 "-repage geometry size and location of an image canvas",
3319 "-resample geometry change the resolution of an image",
3320 "-resize geometry resize the image",
3321 "-roll geometry roll an image vertically or horizontally",
3322 "-rotate degrees apply Paeth rotation to the image",
3323 "-sample geometry scale image with pixel sampling",
3324 "-scale geometry scale the image",
3325 "-segment values segment an image",
3326 "-selective-blur geometry",
3327 " selectively blur pixels within a contrast threshold",
3328 "-sepia-tone threshold",
3329 " simulate a sepia-toned photo",
3330 "-set property value set an image property",
3331 "-shade degrees shade the image using a distant light source",
3332 "-shadow geometry simulate an image shadow",
3333 "-sharpen geometry sharpen the image",
3334 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003335 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003336 "-sigmoidal-contrast geometry",
3337 " increase the contrast without saturating highlights or shadows",
3338 "-sketch geometry simulate a pencil sketch",
3339 "-solarize threshold negate all pixels above the threshold level",
3340 "-sparse-color method args",
3341 " fill in a image based on a few color points",
3342 "-splice geometry splice the background color into the image",
3343 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003344 "-statistic type radius",
3345 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003346 "-strip strip image of all profiles and comments",
3347 "-swirl degrees swirl image pixels about the center",
3348 "-threshold value threshold the image",
3349 "-thumbnail geometry create a thumbnail of the image",
3350 "-tile filename tile image when filling a graphic primitive",
3351 "-tint value tint the image with the fill color",
3352 "-transform affine transform image",
3353 "-transparent color make this color transparent within the image",
3354 "-transpose flip image vertically and rotate 90 degrees",
3355 "-transverse flop image horizontally and rotate 270 degrees",
3356 "-trim trim image edges",
3357 "-type type image type",
3358 "-unique-colors discard all but one of any pixel color",
3359 "-unsharp geometry sharpen the image",
3360 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003361 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003362 "-white-threshold value",
3363 " force all pixels above the threshold into white",
3364 (char *) NULL
3365 },
3366 *sequence_operators[]=
3367 {
cristy4285d782011-02-09 20:12:28 +00003368 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003369 "-clut apply a color lookup table to the image",
3370 "-coalesce merge a sequence of images",
3371 "-combine combine a sequence of images",
3372 "-composite composite image",
3373 "-crop geometry cut out a rectangular region of the image",
3374 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003375 "-evaluate-sequence operator",
3376 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003377 "-flatten flatten a sequence of images",
3378 "-fx expression apply mathematical expression to an image channel(s)",
3379 "-hald-clut apply a Hald color lookup table to the image",
3380 "-morph value morph an image sequence",
3381 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003382 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003383 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003384 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003385 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003386 "-write filename write images to this file",
3387 (char *) NULL
3388 },
3389 *settings[]=
3390 {
3391 "-adjoin join images into a single multi-image file",
3392 "-affine matrix affine transform matrix",
3393 "-alpha option activate, deactivate, reset, or set the alpha channel",
3394 "-antialias remove pixel-aliasing",
3395 "-authenticate password",
3396 " decipher image with this password",
3397 "-attenuate value lessen (or intensify) when adding noise to an image",
3398 "-background color background color",
3399 "-bias value add bias when convolving an image",
3400 "-black-point-compensation",
3401 " use black point compensation",
3402 "-blue-primary point chromaticity blue primary point",
3403 "-bordercolor color border color",
3404 "-caption string assign a caption to an image",
3405 "-channel type apply option to select image channels",
3406 "-colors value preferred number of colors in the image",
3407 "-colorspace type alternate image colorspace",
3408 "-comment string annotate image with comment",
3409 "-compose operator set image composite operator",
3410 "-compress type type of pixel compression when writing the image",
3411 "-define format:option",
3412 " define one or more image format options",
3413 "-delay value display the next image after pausing",
3414 "-density geometry horizontal and vertical density of the image",
3415 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003416 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003417 "-display server get image or font from this X server",
3418 "-dispose method layer disposal method",
3419 "-dither method apply error diffusion to image",
3420 "-encoding type text encoding type",
3421 "-endian type endianness (MSB or LSB) of the image",
3422 "-family name render text with this font family",
3423 "-fill color color to use when filling a graphic primitive",
3424 "-filter type use this filter when resizing an image",
3425 "-font name render text with this font",
3426 "-format \"string\" output formatted image characteristics",
3427 "-fuzz distance colors within this distance are considered equal",
3428 "-gravity type horizontal and vertical text placement",
3429 "-green-primary point chromaticity green primary point",
3430 "-intent type type of rendering intent when managing the image color",
3431 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003432 "-interline-spacing value",
3433 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003434 "-interpolate method pixel color interpolation method",
3435 "-interword-spacing value",
3436 " set the space between two words",
3437 "-kerning value set the space between two letters",
3438 "-label string assign a label to an image",
3439 "-limit type value pixel cache resource limit",
3440 "-loop iterations add Netscape loop extension to your GIF animation",
3441 "-mask filename associate a mask with the image",
3442 "-mattecolor color frame color",
3443 "-monitor monitor progress",
3444 "-orient type image orientation",
3445 "-page geometry size and location of an image canvas (setting)",
3446 "-ping efficiently determine image attributes",
3447 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003448 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003449 "-preview type image preview type",
3450 "-quality value JPEG/MIFF/PNG compression level",
3451 "-quiet suppress all warning messages",
3452 "-red-primary point chromaticity red primary point",
3453 "-regard-warnings pay attention to warning messages",
3454 "-remap filename transform image colors to match this set of colors",
3455 "-respect-parentheses settings remain in effect until parenthesis boundary",
3456 "-sampling-factor geometry",
3457 " horizontal and vertical sampling factor",
3458 "-scene value image scene number",
3459 "-seed value seed a new sequence of pseudo-random numbers",
3460 "-size geometry width and height of image",
3461 "-stretch type render text with this font stretch",
3462 "-stroke color graphic primitive stroke color",
3463 "-strokewidth value graphic primitive stroke width",
3464 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003465 "-synchronize synchronize image to storage device",
3466 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003467 "-texture filename name of texture to tile onto the image background",
3468 "-tile-offset geometry",
3469 " tile offset",
3470 "-treedepth value color tree depth",
3471 "-transparent-color color",
3472 " transparent color",
3473 "-undercolor color annotation bounding box color",
3474 "-units type the units of image resolution",
3475 "-verbose print detailed information about the image",
3476 "-view FlashPix viewing transforms",
3477 "-virtual-pixel method",
3478 " virtual pixel access method",
3479 "-weight type render text with this font weight",
3480 "-white-point point chromaticity white point",
3481 (char *) NULL
3482 },
3483 *stack_operators[]=
3484 {
anthonyb69c4b32011-03-23 04:37:44 +00003485 "-delete indexes delete the image from the image sequence",
3486 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003487 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003488 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003489 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003490 "-swap indexes swap two images in the image sequence",
3491 (char *) NULL
3492 };
3493
3494 const char
3495 **p;
3496
cristybb503372010-05-27 20:51:26 +00003497 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003498 (void) printf("Copyright: %s\n",GetMagickCopyright());
3499 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003500 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3501 GetClientName());
3502 (void) printf("\nImage Settings:\n");
3503 for (p=settings; *p != (char *) NULL; p++)
3504 (void) printf(" %s\n",*p);
3505 (void) printf("\nImage Operators:\n");
3506 for (p=operators; *p != (char *) NULL; p++)
3507 (void) printf(" %s\n",*p);
3508 (void) printf("\nImage Sequence Operators:\n");
3509 for (p=sequence_operators; *p != (char *) NULL; p++)
3510 (void) printf(" %s\n",*p);
3511 (void) printf("\nImage Stack Operators:\n");
3512 for (p=stack_operators; *p != (char *) NULL; p++)
3513 (void) printf(" %s\n",*p);
3514 (void) printf("\nMiscellaneous Options:\n");
3515 for (p=miscellaneous; *p != (char *) NULL; p++)
3516 (void) printf(" %s\n",*p);
3517 (void) printf(
3518 "\nBy default, the image format of `file' is determined by its magic\n");
3519 (void) printf(
3520 "number. To specify a particular image format, precede the filename\n");
3521 (void) printf(
3522 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3523 (void) printf(
3524 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3525 (void) printf("'-' for standard input or output.\n");
3526 return(MagickFalse);
3527}
3528
3529WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3530 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3531{
3532#define DestroyMogrify() \
3533{ \
3534 if (format != (char *) NULL) \
3535 format=DestroyString(format); \
3536 if (path != (char *) NULL) \
3537 path=DestroyString(path); \
3538 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003539 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003540 argv[i]=DestroyString(argv[i]); \
3541 argv=(char **) RelinquishMagickMemory(argv); \
3542}
3543#define ThrowMogrifyException(asperity,tag,option) \
3544{ \
3545 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3546 option); \
3547 DestroyMogrify(); \
3548 return(MagickFalse); \
3549}
3550#define ThrowMogrifyInvalidArgumentException(option,argument) \
3551{ \
3552 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3553 "InvalidArgument","`%s': %s",argument,option); \
3554 DestroyMogrify(); \
3555 return(MagickFalse); \
3556}
3557
3558 char
3559 *format,
3560 *option,
3561 *path;
3562
3563 Image
3564 *image;
3565
3566 ImageStack
3567 image_stack[MaxImageStackDepth+1];
3568
cristy3ed852e2009-09-05 21:47:34 +00003569 MagickBooleanType
3570 global_colormap;
3571
3572 MagickBooleanType
3573 fire,
cristyebbcfea2011-02-25 02:43:54 +00003574 pend,
3575 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003576
3577 MagickStatusType
3578 status;
3579
cristyebbcfea2011-02-25 02:43:54 +00003580 register ssize_t
3581 i;
3582
3583 ssize_t
3584 j,
3585 k;
3586
cristy3ed852e2009-09-05 21:47:34 +00003587 /*
3588 Set defaults.
3589 */
3590 assert(image_info != (ImageInfo *) NULL);
3591 assert(image_info->signature == MagickSignature);
3592 if (image_info->debug != MagickFalse)
3593 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3594 assert(exception != (ExceptionInfo *) NULL);
3595 if (argc == 2)
3596 {
3597 option=argv[1];
3598 if ((LocaleCompare("version",option+1) == 0) ||
3599 (LocaleCompare("-version",option+1) == 0))
3600 {
cristyb51dff52011-05-19 16:55:47 +00003601 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003602 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003603 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3604 GetMagickCopyright());
3605 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3606 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003607 return(MagickFalse);
3608 }
3609 }
3610 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003611 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003612 format=(char *) NULL;
3613 path=(char *) NULL;
3614 global_colormap=MagickFalse;
3615 k=0;
3616 j=1;
3617 NewImageStack();
3618 option=(char *) NULL;
3619 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003620 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003621 status=MagickTrue;
3622 /*
3623 Parse command line.
3624 */
3625 ReadCommandlLine(argc,&argv);
3626 status=ExpandFilenames(&argc,&argv);
3627 if (status == MagickFalse)
3628 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3629 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003630 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003631 {
3632 option=argv[i];
3633 if (LocaleCompare(option,"(") == 0)
3634 {
3635 FireImageStack(MagickFalse,MagickTrue,pend);
3636 if (k == MaxImageStackDepth)
3637 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3638 option);
3639 PushImageStack();
3640 continue;
3641 }
3642 if (LocaleCompare(option,")") == 0)
3643 {
3644 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3645 if (k == 0)
3646 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3647 PopImageStack();
3648 continue;
3649 }
cristy042ee782011-04-22 18:48:30 +00003650 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003651 {
3652 char
3653 backup_filename[MaxTextExtent],
3654 *filename;
3655
3656 Image
3657 *images;
3658
3659 /*
3660 Option is a file name: begin by reading image from specified file.
3661 */
3662 FireImageStack(MagickFalse,MagickFalse,pend);
3663 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003664 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003665 filename=argv[++i];
3666 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3667 images=ReadImages(image_info,exception);
3668 status&=(images != (Image *) NULL) &&
3669 (exception->severity < ErrorException);
3670 if (images == (Image *) NULL)
3671 continue;
cristydaa76602010-06-30 13:05:11 +00003672 if (format != (char *) NULL)
3673 (void) CopyMagickString(images->filename,images->magick_filename,
3674 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003675 if (path != (char *) NULL)
3676 {
3677 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003678 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003679 path,*DirectorySeparator,filename);
3680 }
3681 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003682 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003683 AppendImageStack(images);
3684 FinalizeImageSettings(image_info,image,MagickFalse);
3685 if (global_colormap != MagickFalse)
3686 {
3687 QuantizeInfo
3688 *quantize_info;
3689
3690 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003691 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003692 quantize_info=DestroyQuantizeInfo(quantize_info);
3693 }
3694 *backup_filename='\0';
3695 if ((LocaleCompare(image->filename,"-") != 0) &&
3696 (IsPathWritable(image->filename) != MagickFalse))
3697 {
cristybb503372010-05-27 20:51:26 +00003698 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003699 i;
3700
3701 /*
3702 Rename image file as backup.
3703 */
3704 (void) CopyMagickString(backup_filename,image->filename,
3705 MaxTextExtent);
3706 for (i=0; i < 6; i++)
3707 {
3708 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3709 if (IsPathAccessible(backup_filename) == MagickFalse)
3710 break;
3711 }
3712 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3713 (rename(image->filename,backup_filename) != 0))
3714 *backup_filename='\0';
3715 }
3716 /*
3717 Write transmogrified image to disk.
3718 */
3719 image_info->synchronize=MagickTrue;
3720 status&=WriteImages(image_info,image,image->filename,exception);
3721 if ((status == MagickFalse) && (*backup_filename != '\0'))
3722 (void) remove(backup_filename);
3723 RemoveAllImageStack();
3724 continue;
3725 }
3726 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3727 switch (*(option+1))
3728 {
3729 case 'a':
3730 {
3731 if (LocaleCompare("adaptive-blur",option+1) == 0)
3732 {
3733 i++;
cristybb503372010-05-27 20:51:26 +00003734 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003735 ThrowMogrifyException(OptionError,"MissingArgument",option);
3736 if (IsGeometry(argv[i]) == MagickFalse)
3737 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3738 break;
3739 }
3740 if (LocaleCompare("adaptive-resize",option+1) == 0)
3741 {
3742 i++;
cristybb503372010-05-27 20:51:26 +00003743 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003744 ThrowMogrifyException(OptionError,"MissingArgument",option);
3745 if (IsGeometry(argv[i]) == MagickFalse)
3746 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3747 break;
3748 }
3749 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3750 {
3751 i++;
cristybb503372010-05-27 20:51:26 +00003752 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003753 ThrowMogrifyException(OptionError,"MissingArgument",option);
3754 if (IsGeometry(argv[i]) == MagickFalse)
3755 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3756 break;
3757 }
3758 if (LocaleCompare("affine",option+1) == 0)
3759 {
3760 if (*option == '+')
3761 break;
3762 i++;
cristybb503372010-05-27 20:51:26 +00003763 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003764 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003765 break;
3766 }
3767 if (LocaleCompare("alpha",option+1) == 0)
3768 {
cristybb503372010-05-27 20:51:26 +00003769 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003770 type;
3771
3772 if (*option == '+')
3773 break;
3774 i++;
cristybb503372010-05-27 20:51:26 +00003775 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003776 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003777 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003778 if (type < 0)
3779 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3780 argv[i]);
3781 break;
3782 }
3783 if (LocaleCompare("annotate",option+1) == 0)
3784 {
3785 if (*option == '+')
3786 break;
3787 i++;
cristybb503372010-05-27 20:51:26 +00003788 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003789 ThrowMogrifyException(OptionError,"MissingArgument",option);
3790 if (IsGeometry(argv[i]) == MagickFalse)
3791 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003792 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003793 ThrowMogrifyException(OptionError,"MissingArgument",option);
3794 i++;
3795 break;
3796 }
3797 if (LocaleCompare("antialias",option+1) == 0)
3798 break;
3799 if (LocaleCompare("append",option+1) == 0)
3800 break;
3801 if (LocaleCompare("attenuate",option+1) == 0)
3802 {
3803 if (*option == '+')
3804 break;
3805 i++;
cristybb503372010-05-27 20:51:26 +00003806 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003807 ThrowMogrifyException(OptionError,"MissingArgument",option);
3808 if (IsGeometry(argv[i]) == MagickFalse)
3809 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3810 break;
3811 }
3812 if (LocaleCompare("authenticate",option+1) == 0)
3813 {
3814 if (*option == '+')
3815 break;
3816 i++;
cristybb503372010-05-27 20:51:26 +00003817 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003818 ThrowMogrifyException(OptionError,"MissingArgument",option);
3819 break;
3820 }
3821 if (LocaleCompare("auto-gamma",option+1) == 0)
3822 break;
3823 if (LocaleCompare("auto-level",option+1) == 0)
3824 break;
3825 if (LocaleCompare("auto-orient",option+1) == 0)
3826 break;
3827 if (LocaleCompare("average",option+1) == 0)
3828 break;
3829 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3830 }
3831 case 'b':
3832 {
3833 if (LocaleCompare("background",option+1) == 0)
3834 {
3835 if (*option == '+')
3836 break;
3837 i++;
cristybb503372010-05-27 20:51:26 +00003838 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003839 ThrowMogrifyException(OptionError,"MissingArgument",option);
3840 break;
3841 }
3842 if (LocaleCompare("bias",option+1) == 0)
3843 {
3844 if (*option == '+')
3845 break;
3846 i++;
cristybb503372010-05-27 20:51:26 +00003847 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003848 ThrowMogrifyException(OptionError,"MissingArgument",option);
3849 if (IsGeometry(argv[i]) == MagickFalse)
3850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3851 break;
3852 }
3853 if (LocaleCompare("black-point-compensation",option+1) == 0)
3854 break;
3855 if (LocaleCompare("black-threshold",option+1) == 0)
3856 {
3857 if (*option == '+')
3858 break;
3859 i++;
cristybb503372010-05-27 20:51:26 +00003860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003861 ThrowMogrifyException(OptionError,"MissingArgument",option);
3862 if (IsGeometry(argv[i]) == MagickFalse)
3863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3864 break;
3865 }
3866 if (LocaleCompare("blue-primary",option+1) == 0)
3867 {
3868 if (*option == '+')
3869 break;
3870 i++;
cristybb503372010-05-27 20:51:26 +00003871 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003872 ThrowMogrifyException(OptionError,"MissingArgument",option);
3873 if (IsGeometry(argv[i]) == MagickFalse)
3874 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3875 break;
3876 }
3877 if (LocaleCompare("blue-shift",option+1) == 0)
3878 {
3879 i++;
cristybb503372010-05-27 20:51:26 +00003880 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003881 ThrowMogrifyException(OptionError,"MissingArgument",option);
3882 if (IsGeometry(argv[i]) == MagickFalse)
3883 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3884 break;
3885 }
3886 if (LocaleCompare("blur",option+1) == 0)
3887 {
3888 i++;
cristybb503372010-05-27 20:51:26 +00003889 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003890 ThrowMogrifyException(OptionError,"MissingArgument",option);
3891 if (IsGeometry(argv[i]) == MagickFalse)
3892 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3893 break;
3894 }
3895 if (LocaleCompare("border",option+1) == 0)
3896 {
3897 if (*option == '+')
3898 break;
3899 i++;
cristybb503372010-05-27 20:51:26 +00003900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003901 ThrowMogrifyException(OptionError,"MissingArgument",option);
3902 if (IsGeometry(argv[i]) == MagickFalse)
3903 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3904 break;
3905 }
3906 if (LocaleCompare("bordercolor",option+1) == 0)
3907 {
3908 if (*option == '+')
3909 break;
3910 i++;
cristybb503372010-05-27 20:51:26 +00003911 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003912 ThrowMogrifyException(OptionError,"MissingArgument",option);
3913 break;
3914 }
3915 if (LocaleCompare("box",option+1) == 0)
3916 {
3917 if (*option == '+')
3918 break;
3919 i++;
cristybb503372010-05-27 20:51:26 +00003920 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003921 ThrowMogrifyException(OptionError,"MissingArgument",option);
3922 break;
3923 }
cristya28d6b82010-01-11 20:03:47 +00003924 if (LocaleCompare("brightness-contrast",option+1) == 0)
3925 {
3926 i++;
cristybb503372010-05-27 20:51:26 +00003927 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003928 ThrowMogrifyException(OptionError,"MissingArgument",option);
3929 if (IsGeometry(argv[i]) == MagickFalse)
3930 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3931 break;
3932 }
cristy3ed852e2009-09-05 21:47:34 +00003933 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3934 }
3935 case 'c':
3936 {
3937 if (LocaleCompare("cache",option+1) == 0)
3938 {
3939 if (*option == '+')
3940 break;
3941 i++;
cristybb503372010-05-27 20:51:26 +00003942 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003943 ThrowMogrifyException(OptionError,"MissingArgument",option);
3944 if (IsGeometry(argv[i]) == MagickFalse)
3945 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3946 break;
3947 }
3948 if (LocaleCompare("caption",option+1) == 0)
3949 {
3950 if (*option == '+')
3951 break;
3952 i++;
cristybb503372010-05-27 20:51:26 +00003953 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003954 ThrowMogrifyException(OptionError,"MissingArgument",option);
3955 break;
3956 }
3957 if (LocaleCompare("channel",option+1) == 0)
3958 {
cristybb503372010-05-27 20:51:26 +00003959 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003960 channel;
3961
3962 if (*option == '+')
3963 break;
3964 i++;
cristybb503372010-05-27 20:51:26 +00003965 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003966 ThrowMogrifyException(OptionError,"MissingArgument",option);
3967 channel=ParseChannelOption(argv[i]);
3968 if (channel < 0)
3969 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3970 argv[i]);
3971 break;
3972 }
3973 if (LocaleCompare("cdl",option+1) == 0)
3974 {
3975 if (*option == '+')
3976 break;
3977 i++;
cristybb503372010-05-27 20:51:26 +00003978 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003979 ThrowMogrifyException(OptionError,"MissingArgument",option);
3980 break;
3981 }
3982 if (LocaleCompare("charcoal",option+1) == 0)
3983 {
3984 if (*option == '+')
3985 break;
3986 i++;
cristybb503372010-05-27 20:51:26 +00003987 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003988 ThrowMogrifyException(OptionError,"MissingArgument",option);
3989 if (IsGeometry(argv[i]) == MagickFalse)
3990 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3991 break;
3992 }
3993 if (LocaleCompare("chop",option+1) == 0)
3994 {
3995 if (*option == '+')
3996 break;
3997 i++;
cristybb503372010-05-27 20:51:26 +00003998 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003999 ThrowMogrifyException(OptionError,"MissingArgument",option);
4000 if (IsGeometry(argv[i]) == MagickFalse)
4001 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4002 break;
4003 }
cristy1eb45dd2009-09-25 16:38:06 +00004004 if (LocaleCompare("clamp",option+1) == 0)
4005 break;
4006 if (LocaleCompare("clip",option+1) == 0)
4007 break;
cristy3ed852e2009-09-05 21:47:34 +00004008 if (LocaleCompare("clip-mask",option+1) == 0)
4009 {
4010 if (*option == '+')
4011 break;
4012 i++;
cristybb503372010-05-27 20:51:26 +00004013 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004014 ThrowMogrifyException(OptionError,"MissingArgument",option);
4015 break;
4016 }
4017 if (LocaleCompare("clut",option+1) == 0)
4018 break;
4019 if (LocaleCompare("coalesce",option+1) == 0)
4020 break;
4021 if (LocaleCompare("colorize",option+1) == 0)
4022 {
4023 if (*option == '+')
4024 break;
4025 i++;
cristybb503372010-05-27 20:51:26 +00004026 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004027 ThrowMogrifyException(OptionError,"MissingArgument",option);
4028 if (IsGeometry(argv[i]) == MagickFalse)
4029 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4030 break;
4031 }
cristye6365592010-04-02 17:31:23 +00004032 if (LocaleCompare("color-matrix",option+1) == 0)
4033 {
cristyb6bd4ad2010-08-08 01:12:27 +00004034 KernelInfo
4035 *kernel_info;
4036
cristye6365592010-04-02 17:31:23 +00004037 if (*option == '+')
4038 break;
4039 i++;
cristybb503372010-05-27 20:51:26 +00004040 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004041 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004042 kernel_info=AcquireKernelInfo(argv[i]);
4043 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004044 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004045 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004046 break;
4047 }
cristy3ed852e2009-09-05 21:47:34 +00004048 if (LocaleCompare("colors",option+1) == 0)
4049 {
4050 if (*option == '+')
4051 break;
4052 i++;
cristybb503372010-05-27 20:51:26 +00004053 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004054 ThrowMogrifyException(OptionError,"MissingArgument",option);
4055 if (IsGeometry(argv[i]) == MagickFalse)
4056 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4057 break;
4058 }
4059 if (LocaleCompare("colorspace",option+1) == 0)
4060 {
cristybb503372010-05-27 20:51:26 +00004061 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004062 colorspace;
4063
4064 if (*option == '+')
4065 break;
4066 i++;
cristybb503372010-05-27 20:51:26 +00004067 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004068 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004069 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004070 argv[i]);
4071 if (colorspace < 0)
4072 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4073 argv[i]);
4074 break;
4075 }
4076 if (LocaleCompare("combine",option+1) == 0)
4077 break;
4078 if (LocaleCompare("comment",option+1) == 0)
4079 {
4080 if (*option == '+')
4081 break;
4082 i++;
cristybb503372010-05-27 20:51:26 +00004083 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004084 ThrowMogrifyException(OptionError,"MissingArgument",option);
4085 break;
4086 }
4087 if (LocaleCompare("composite",option+1) == 0)
4088 break;
4089 if (LocaleCompare("compress",option+1) == 0)
4090 {
cristybb503372010-05-27 20:51:26 +00004091 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004092 compress;
4093
4094 if (*option == '+')
4095 break;
4096 i++;
cristybb503372010-05-27 20:51:26 +00004097 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004098 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004099 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004100 argv[i]);
4101 if (compress < 0)
4102 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4103 argv[i]);
4104 break;
4105 }
cristy22879752009-10-25 23:55:40 +00004106 if (LocaleCompare("concurrent",option+1) == 0)
4107 break;
cristy3ed852e2009-09-05 21:47:34 +00004108 if (LocaleCompare("contrast",option+1) == 0)
4109 break;
4110 if (LocaleCompare("contrast-stretch",option+1) == 0)
4111 {
4112 i++;
cristybb503372010-05-27 20:51:26 +00004113 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004114 ThrowMogrifyException(OptionError,"MissingArgument",option);
4115 if (IsGeometry(argv[i]) == MagickFalse)
4116 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4117 break;
4118 }
4119 if (LocaleCompare("convolve",option+1) == 0)
4120 {
cristyb6bd4ad2010-08-08 01:12:27 +00004121 KernelInfo
4122 *kernel_info;
4123
cristy3ed852e2009-09-05 21:47:34 +00004124 if (*option == '+')
4125 break;
4126 i++;
cristybb503372010-05-27 20:51:26 +00004127 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004128 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004129 kernel_info=AcquireKernelInfo(argv[i]);
4130 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004131 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004132 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004133 break;
4134 }
4135 if (LocaleCompare("crop",option+1) == 0)
4136 {
4137 if (*option == '+')
4138 break;
4139 i++;
cristybb503372010-05-27 20:51:26 +00004140 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004141 ThrowMogrifyException(OptionError,"MissingArgument",option);
4142 if (IsGeometry(argv[i]) == MagickFalse)
4143 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4144 break;
4145 }
4146 if (LocaleCompare("cycle",option+1) == 0)
4147 {
4148 if (*option == '+')
4149 break;
4150 i++;
cristybb503372010-05-27 20:51:26 +00004151 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004152 ThrowMogrifyException(OptionError,"MissingArgument",option);
4153 if (IsGeometry(argv[i]) == MagickFalse)
4154 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4155 break;
4156 }
4157 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4158 }
4159 case 'd':
4160 {
4161 if (LocaleCompare("decipher",option+1) == 0)
4162 {
4163 if (*option == '+')
4164 break;
4165 i++;
cristybb503372010-05-27 20:51:26 +00004166 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004167 ThrowMogrifyException(OptionError,"MissingArgument",option);
4168 break;
4169 }
4170 if (LocaleCompare("deconstruct",option+1) == 0)
4171 break;
4172 if (LocaleCompare("debug",option+1) == 0)
4173 {
cristybb503372010-05-27 20:51:26 +00004174 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004175 event;
4176
4177 if (*option == '+')
4178 break;
4179 i++;
cristybb503372010-05-27 20:51:26 +00004180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004181 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004182 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004183 if (event < 0)
4184 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4185 argv[i]);
4186 (void) SetLogEventMask(argv[i]);
4187 break;
4188 }
4189 if (LocaleCompare("define",option+1) == 0)
4190 {
4191 i++;
cristybb503372010-05-27 20:51:26 +00004192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004193 ThrowMogrifyException(OptionError,"MissingArgument",option);
4194 if (*option == '+')
4195 {
4196 const char
4197 *define;
4198
4199 define=GetImageOption(image_info,argv[i]);
4200 if (define == (const char *) NULL)
4201 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4202 break;
4203 }
4204 break;
4205 }
4206 if (LocaleCompare("delay",option+1) == 0)
4207 {
4208 if (*option == '+')
4209 break;
4210 i++;
cristybb503372010-05-27 20:51:26 +00004211 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004212 ThrowMogrifyException(OptionError,"MissingArgument",option);
4213 if (IsGeometry(argv[i]) == MagickFalse)
4214 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4215 break;
4216 }
cristyecb10ff2011-03-22 13:14:03 +00004217 if (LocaleCompare("delete",option+1) == 0)
4218 {
4219 if (*option == '+')
4220 break;
4221 i++;
4222 if (i == (ssize_t) (argc-1))
4223 ThrowMogrifyException(OptionError,"MissingArgument",option);
4224 if (IsGeometry(argv[i]) == MagickFalse)
4225 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4226 break;
4227 }
cristy3ed852e2009-09-05 21:47:34 +00004228 if (LocaleCompare("density",option+1) == 0)
4229 {
4230 if (*option == '+')
4231 break;
4232 i++;
cristybb503372010-05-27 20:51:26 +00004233 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004234 ThrowMogrifyException(OptionError,"MissingArgument",option);
4235 if (IsGeometry(argv[i]) == MagickFalse)
4236 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4237 break;
4238 }
4239 if (LocaleCompare("depth",option+1) == 0)
4240 {
4241 if (*option == '+')
4242 break;
4243 i++;
cristybb503372010-05-27 20:51:26 +00004244 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004245 ThrowMogrifyException(OptionError,"MissingArgument",option);
4246 if (IsGeometry(argv[i]) == MagickFalse)
4247 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4248 break;
4249 }
4250 if (LocaleCompare("deskew",option+1) == 0)
4251 {
4252 if (*option == '+')
4253 break;
4254 i++;
cristybb503372010-05-27 20:51:26 +00004255 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004256 ThrowMogrifyException(OptionError,"MissingArgument",option);
4257 if (IsGeometry(argv[i]) == MagickFalse)
4258 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4259 break;
4260 }
4261 if (LocaleCompare("despeckle",option+1) == 0)
4262 break;
4263 if (LocaleCompare("dft",option+1) == 0)
4264 break;
cristyc9b12952010-03-28 01:12:28 +00004265 if (LocaleCompare("direction",option+1) == 0)
4266 {
cristybb503372010-05-27 20:51:26 +00004267 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004268 direction;
4269
4270 if (*option == '+')
4271 break;
4272 i++;
cristybb503372010-05-27 20:51:26 +00004273 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004274 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004275 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004276 argv[i]);
4277 if (direction < 0)
4278 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4279 argv[i]);
4280 break;
4281 }
cristy3ed852e2009-09-05 21:47:34 +00004282 if (LocaleCompare("display",option+1) == 0)
4283 {
4284 if (*option == '+')
4285 break;
4286 i++;
cristybb503372010-05-27 20:51:26 +00004287 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004288 ThrowMogrifyException(OptionError,"MissingArgument",option);
4289 break;
4290 }
4291 if (LocaleCompare("dispose",option+1) == 0)
4292 {
cristybb503372010-05-27 20:51:26 +00004293 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004294 dispose;
4295
4296 if (*option == '+')
4297 break;
4298 i++;
cristybb503372010-05-27 20:51:26 +00004299 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004300 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004301 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004302 if (dispose < 0)
4303 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4304 argv[i]);
4305 break;
4306 }
4307 if (LocaleCompare("distort",option+1) == 0)
4308 {
cristybb503372010-05-27 20:51:26 +00004309 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004310 op;
4311
4312 i++;
cristybb503372010-05-27 20:51:26 +00004313 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004314 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004315 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004316 if (op < 0)
4317 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4318 argv[i]);
4319 i++;
cristybb503372010-05-27 20:51:26 +00004320 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004321 ThrowMogrifyException(OptionError,"MissingArgument",option);
4322 break;
4323 }
4324 if (LocaleCompare("dither",option+1) == 0)
4325 {
cristybb503372010-05-27 20:51:26 +00004326 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004327 method;
4328
4329 if (*option == '+')
4330 break;
4331 i++;
cristybb503372010-05-27 20:51:26 +00004332 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004333 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004334 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004335 if (method < 0)
4336 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4337 argv[i]);
4338 break;
4339 }
4340 if (LocaleCompare("draw",option+1) == 0)
4341 {
4342 if (*option == '+')
4343 break;
4344 i++;
cristybb503372010-05-27 20:51:26 +00004345 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004346 ThrowMogrifyException(OptionError,"MissingArgument",option);
4347 break;
4348 }
cristyecb10ff2011-03-22 13:14:03 +00004349 if (LocaleCompare("duplicate",option+1) == 0)
4350 {
4351 if (*option == '+')
4352 break;
4353 i++;
4354 if (i == (ssize_t) (argc-1))
4355 ThrowMogrifyException(OptionError,"MissingArgument",option);
4356 if (IsGeometry(argv[i]) == MagickFalse)
4357 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4358 break;
4359 }
cristy22879752009-10-25 23:55:40 +00004360 if (LocaleCompare("duration",option+1) == 0)
4361 {
4362 if (*option == '+')
4363 break;
4364 i++;
cristybb503372010-05-27 20:51:26 +00004365 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004366 ThrowMogrifyException(OptionError,"MissingArgument",option);
4367 if (IsGeometry(argv[i]) == MagickFalse)
4368 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4369 break;
4370 }
cristy3ed852e2009-09-05 21:47:34 +00004371 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4372 }
4373 case 'e':
4374 {
4375 if (LocaleCompare("edge",option+1) == 0)
4376 {
4377 if (*option == '+')
4378 break;
4379 i++;
cristybb503372010-05-27 20:51:26 +00004380 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004381 ThrowMogrifyException(OptionError,"MissingArgument",option);
4382 if (IsGeometry(argv[i]) == MagickFalse)
4383 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4384 break;
4385 }
4386 if (LocaleCompare("emboss",option+1) == 0)
4387 {
4388 if (*option == '+')
4389 break;
4390 i++;
cristybb503372010-05-27 20:51:26 +00004391 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004392 ThrowMogrifyException(OptionError,"MissingArgument",option);
4393 if (IsGeometry(argv[i]) == MagickFalse)
4394 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4395 break;
4396 }
4397 if (LocaleCompare("encipher",option+1) == 0)
4398 {
4399 if (*option == '+')
4400 break;
4401 i++;
cristybb503372010-05-27 20:51:26 +00004402 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004403 ThrowMogrifyException(OptionError,"MissingArgument",option);
4404 break;
4405 }
4406 if (LocaleCompare("encoding",option+1) == 0)
4407 {
4408 if (*option == '+')
4409 break;
4410 i++;
cristybb503372010-05-27 20:51:26 +00004411 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004412 ThrowMogrifyException(OptionError,"MissingArgument",option);
4413 break;
4414 }
4415 if (LocaleCompare("endian",option+1) == 0)
4416 {
cristybb503372010-05-27 20:51:26 +00004417 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004418 endian;
4419
4420 if (*option == '+')
4421 break;
4422 i++;
cristybb503372010-05-27 20:51:26 +00004423 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004424 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004425 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004426 if (endian < 0)
4427 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4428 argv[i]);
4429 break;
4430 }
4431 if (LocaleCompare("enhance",option+1) == 0)
4432 break;
4433 if (LocaleCompare("equalize",option+1) == 0)
4434 break;
4435 if (LocaleCompare("evaluate",option+1) == 0)
4436 {
cristybb503372010-05-27 20:51:26 +00004437 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004438 op;
4439
4440 if (*option == '+')
4441 break;
4442 i++;
cristybb503372010-05-27 20:51:26 +00004443 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004444 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004445 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004446 if (op < 0)
4447 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4448 argv[i]);
4449 i++;
cristybb503372010-05-27 20:51:26 +00004450 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004451 ThrowMogrifyException(OptionError,"MissingArgument",option);
4452 if (IsGeometry(argv[i]) == MagickFalse)
4453 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4454 break;
4455 }
cristyd18ae7c2010-03-07 17:39:52 +00004456 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4457 {
cristybb503372010-05-27 20:51:26 +00004458 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004459 op;
4460
4461 if (*option == '+')
4462 break;
4463 i++;
cristybb503372010-05-27 20:51:26 +00004464 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004465 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004466 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004467 if (op < 0)
4468 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4469 argv[i]);
4470 break;
4471 }
cristy3ed852e2009-09-05 21:47:34 +00004472 if (LocaleCompare("extent",option+1) == 0)
4473 {
4474 if (*option == '+')
4475 break;
4476 i++;
cristybb503372010-05-27 20:51:26 +00004477 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004478 ThrowMogrifyException(OptionError,"MissingArgument",option);
4479 if (IsGeometry(argv[i]) == MagickFalse)
4480 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4481 break;
4482 }
4483 if (LocaleCompare("extract",option+1) == 0)
4484 {
4485 if (*option == '+')
4486 break;
4487 i++;
cristybb503372010-05-27 20:51:26 +00004488 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004489 ThrowMogrifyException(OptionError,"MissingArgument",option);
4490 if (IsGeometry(argv[i]) == MagickFalse)
4491 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4492 break;
4493 }
4494 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4495 }
4496 case 'f':
4497 {
4498 if (LocaleCompare("family",option+1) == 0)
4499 {
4500 if (*option == '+')
4501 break;
4502 i++;
cristybb503372010-05-27 20:51:26 +00004503 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004504 ThrowMogrifyException(OptionError,"MissingArgument",option);
4505 break;
4506 }
4507 if (LocaleCompare("fill",option+1) == 0)
4508 {
4509 if (*option == '+')
4510 break;
4511 i++;
cristybb503372010-05-27 20:51:26 +00004512 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004513 ThrowMogrifyException(OptionError,"MissingArgument",option);
4514 break;
4515 }
4516 if (LocaleCompare("filter",option+1) == 0)
4517 {
cristybb503372010-05-27 20:51:26 +00004518 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004519 filter;
4520
4521 if (*option == '+')
4522 break;
4523 i++;
cristybb503372010-05-27 20:51:26 +00004524 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004525 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004526 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004527 if (filter < 0)
4528 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4529 argv[i]);
4530 break;
4531 }
4532 if (LocaleCompare("flatten",option+1) == 0)
4533 break;
4534 if (LocaleCompare("flip",option+1) == 0)
4535 break;
4536 if (LocaleCompare("flop",option+1) == 0)
4537 break;
4538 if (LocaleCompare("floodfill",option+1) == 0)
4539 {
4540 if (*option == '+')
4541 break;
4542 i++;
cristybb503372010-05-27 20:51:26 +00004543 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004544 ThrowMogrifyException(OptionError,"MissingArgument",option);
4545 if (IsGeometry(argv[i]) == MagickFalse)
4546 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4547 i++;
cristybb503372010-05-27 20:51:26 +00004548 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004549 ThrowMogrifyException(OptionError,"MissingArgument",option);
4550 break;
4551 }
4552 if (LocaleCompare("font",option+1) == 0)
4553 {
4554 if (*option == '+')
4555 break;
4556 i++;
cristybb503372010-05-27 20:51:26 +00004557 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004558 ThrowMogrifyException(OptionError,"MissingArgument",option);
4559 break;
4560 }
4561 if (LocaleCompare("format",option+1) == 0)
4562 {
4563 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4564 (void) CloneString(&format,(char *) NULL);
4565 if (*option == '+')
4566 break;
4567 i++;
cristybb503372010-05-27 20:51:26 +00004568 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004569 ThrowMogrifyException(OptionError,"MissingArgument",option);
4570 (void) CloneString(&format,argv[i]);
4571 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4572 (void) ConcatenateMagickString(image_info->filename,":",
4573 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004574 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004575 if (*image_info->magick == '\0')
4576 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4577 format);
4578 break;
4579 }
4580 if (LocaleCompare("frame",option+1) == 0)
4581 {
4582 if (*option == '+')
4583 break;
4584 i++;
cristybb503372010-05-27 20:51:26 +00004585 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004586 ThrowMogrifyException(OptionError,"MissingArgument",option);
4587 if (IsGeometry(argv[i]) == MagickFalse)
4588 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4589 break;
4590 }
4591 if (LocaleCompare("function",option+1) == 0)
4592 {
cristybb503372010-05-27 20:51:26 +00004593 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004594 op;
4595
4596 if (*option == '+')
4597 break;
4598 i++;
cristybb503372010-05-27 20:51:26 +00004599 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004600 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004601 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004602 if (op < 0)
4603 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4604 i++;
cristybb503372010-05-27 20:51:26 +00004605 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004606 ThrowMogrifyException(OptionError,"MissingArgument",option);
4607 break;
4608 }
4609 if (LocaleCompare("fuzz",option+1) == 0)
4610 {
4611 if (*option == '+')
4612 break;
4613 i++;
cristybb503372010-05-27 20:51:26 +00004614 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004615 ThrowMogrifyException(OptionError,"MissingArgument",option);
4616 if (IsGeometry(argv[i]) == MagickFalse)
4617 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4618 break;
4619 }
4620 if (LocaleCompare("fx",option+1) == 0)
4621 {
4622 if (*option == '+')
4623 break;
4624 i++;
cristybb503372010-05-27 20:51:26 +00004625 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004626 ThrowMogrifyException(OptionError,"MissingArgument",option);
4627 break;
4628 }
4629 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4630 }
4631 case 'g':
4632 {
4633 if (LocaleCompare("gamma",option+1) == 0)
4634 {
4635 i++;
cristybb503372010-05-27 20:51:26 +00004636 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004637 ThrowMogrifyException(OptionError,"MissingArgument",option);
4638 if (IsGeometry(argv[i]) == MagickFalse)
4639 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4640 break;
4641 }
4642 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4643 (LocaleCompare("gaussian",option+1) == 0))
4644 {
4645 i++;
cristybb503372010-05-27 20:51:26 +00004646 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004647 ThrowMogrifyException(OptionError,"MissingArgument",option);
4648 if (IsGeometry(argv[i]) == MagickFalse)
4649 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4650 break;
4651 }
4652 if (LocaleCompare("geometry",option+1) == 0)
4653 {
4654 if (*option == '+')
4655 break;
4656 i++;
cristybb503372010-05-27 20:51:26 +00004657 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004658 ThrowMogrifyException(OptionError,"MissingArgument",option);
4659 if (IsGeometry(argv[i]) == MagickFalse)
4660 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4661 break;
4662 }
4663 if (LocaleCompare("gravity",option+1) == 0)
4664 {
cristybb503372010-05-27 20:51:26 +00004665 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004666 gravity;
4667
4668 if (*option == '+')
4669 break;
4670 i++;
cristybb503372010-05-27 20:51:26 +00004671 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004672 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004673 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004674 if (gravity < 0)
4675 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4676 argv[i]);
4677 break;
4678 }
4679 if (LocaleCompare("green-primary",option+1) == 0)
4680 {
4681 if (*option == '+')
4682 break;
4683 i++;
cristybb503372010-05-27 20:51:26 +00004684 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004685 ThrowMogrifyException(OptionError,"MissingArgument",option);
4686 if (IsGeometry(argv[i]) == MagickFalse)
4687 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4688 break;
4689 }
4690 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4691 }
4692 case 'h':
4693 {
4694 if (LocaleCompare("hald-clut",option+1) == 0)
4695 break;
4696 if ((LocaleCompare("help",option+1) == 0) ||
4697 (LocaleCompare("-help",option+1) == 0))
4698 return(MogrifyUsage());
4699 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4700 }
4701 case 'i':
4702 {
4703 if (LocaleCompare("identify",option+1) == 0)
4704 break;
4705 if (LocaleCompare("idft",option+1) == 0)
4706 break;
4707 if (LocaleCompare("implode",option+1) == 0)
4708 {
4709 if (*option == '+')
4710 break;
4711 i++;
cristybb503372010-05-27 20:51:26 +00004712 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004713 ThrowMogrifyException(OptionError,"MissingArgument",option);
4714 if (IsGeometry(argv[i]) == MagickFalse)
4715 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4716 break;
4717 }
4718 if (LocaleCompare("intent",option+1) == 0)
4719 {
cristybb503372010-05-27 20:51:26 +00004720 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004721 intent;
4722
4723 if (*option == '+')
4724 break;
4725 i++;
cristybb503372010-05-27 20:51:26 +00004726 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004727 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004728 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004729 if (intent < 0)
4730 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4731 argv[i]);
4732 break;
4733 }
4734 if (LocaleCompare("interlace",option+1) == 0)
4735 {
cristybb503372010-05-27 20:51:26 +00004736 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004737 interlace;
4738
4739 if (*option == '+')
4740 break;
4741 i++;
cristybb503372010-05-27 20:51:26 +00004742 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004743 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004744 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004745 argv[i]);
4746 if (interlace < 0)
4747 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4748 argv[i]);
4749 break;
4750 }
cristyb32b90a2009-09-07 21:45:48 +00004751 if (LocaleCompare("interline-spacing",option+1) == 0)
4752 {
4753 if (*option == '+')
4754 break;
4755 i++;
cristybb503372010-05-27 20:51:26 +00004756 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004757 ThrowMogrifyException(OptionError,"MissingArgument",option);
4758 if (IsGeometry(argv[i]) == MagickFalse)
4759 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4760 break;
4761 }
cristy3ed852e2009-09-05 21:47:34 +00004762 if (LocaleCompare("interpolate",option+1) == 0)
4763 {
cristybb503372010-05-27 20:51:26 +00004764 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004765 interpolate;
4766
4767 if (*option == '+')
4768 break;
4769 i++;
cristybb503372010-05-27 20:51:26 +00004770 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004771 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004772 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004773 argv[i]);
4774 if (interpolate < 0)
4775 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4776 argv[i]);
4777 break;
4778 }
4779 if (LocaleCompare("interword-spacing",option+1) == 0)
4780 {
4781 if (*option == '+')
4782 break;
4783 i++;
cristybb503372010-05-27 20:51:26 +00004784 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004785 ThrowMogrifyException(OptionError,"MissingArgument",option);
4786 if (IsGeometry(argv[i]) == MagickFalse)
4787 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4788 break;
4789 }
4790 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4791 }
4792 case 'k':
4793 {
4794 if (LocaleCompare("kerning",option+1) == 0)
4795 {
4796 if (*option == '+')
4797 break;
4798 i++;
cristybb503372010-05-27 20:51:26 +00004799 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004800 ThrowMogrifyException(OptionError,"MissingArgument",option);
4801 if (IsGeometry(argv[i]) == MagickFalse)
4802 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4803 break;
4804 }
4805 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4806 }
4807 case 'l':
4808 {
4809 if (LocaleCompare("label",option+1) == 0)
4810 {
4811 if (*option == '+')
4812 break;
4813 i++;
cristybb503372010-05-27 20:51:26 +00004814 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004815 ThrowMogrifyException(OptionError,"MissingArgument",option);
4816 break;
4817 }
4818 if (LocaleCompare("lat",option+1) == 0)
4819 {
4820 if (*option == '+')
4821 break;
4822 i++;
cristybb503372010-05-27 20:51:26 +00004823 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004824 ThrowMogrifyException(OptionError,"MissingArgument",option);
4825 if (IsGeometry(argv[i]) == MagickFalse)
4826 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4827 }
4828 if (LocaleCompare("layers",option+1) == 0)
4829 {
cristybb503372010-05-27 20:51:26 +00004830 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004831 type;
4832
4833 if (*option == '+')
4834 break;
4835 i++;
cristybb503372010-05-27 20:51:26 +00004836 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004837 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004838 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004839 if (type < 0)
4840 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4841 argv[i]);
4842 break;
4843 }
4844 if (LocaleCompare("level",option+1) == 0)
4845 {
4846 i++;
cristybb503372010-05-27 20:51:26 +00004847 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004848 ThrowMogrifyException(OptionError,"MissingArgument",option);
4849 if (IsGeometry(argv[i]) == MagickFalse)
4850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4851 break;
4852 }
4853 if (LocaleCompare("level-colors",option+1) == 0)
4854 {
4855 i++;
cristybb503372010-05-27 20:51:26 +00004856 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004857 ThrowMogrifyException(OptionError,"MissingArgument",option);
4858 break;
4859 }
4860 if (LocaleCompare("linewidth",option+1) == 0)
4861 {
4862 if (*option == '+')
4863 break;
4864 i++;
cristybb503372010-05-27 20:51:26 +00004865 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004866 ThrowMogrifyException(OptionError,"MissingArgument",option);
4867 if (IsGeometry(argv[i]) == MagickFalse)
4868 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4869 break;
4870 }
4871 if (LocaleCompare("limit",option+1) == 0)
4872 {
4873 char
4874 *p;
4875
4876 double
4877 value;
4878
cristybb503372010-05-27 20:51:26 +00004879 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004880 resource;
4881
4882 if (*option == '+')
4883 break;
4884 i++;
cristybb503372010-05-27 20:51:26 +00004885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004886 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004887 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004888 argv[i]);
4889 if (resource < 0)
4890 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4891 argv[i]);
4892 i++;
cristybb503372010-05-27 20:51:26 +00004893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004894 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004895 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004896 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004897 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4898 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4899 break;
4900 }
4901 if (LocaleCompare("liquid-rescale",option+1) == 0)
4902 {
4903 i++;
cristybb503372010-05-27 20:51:26 +00004904 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004905 ThrowMogrifyException(OptionError,"MissingArgument",option);
4906 if (IsGeometry(argv[i]) == MagickFalse)
4907 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4908 break;
4909 }
4910 if (LocaleCompare("list",option+1) == 0)
4911 {
cristybb503372010-05-27 20:51:26 +00004912 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004913 list;
4914
4915 if (*option == '+')
4916 break;
4917 i++;
cristybb503372010-05-27 20:51:26 +00004918 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004919 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004920 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004921 if (list < 0)
4922 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004923 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004924 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004925 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004926 }
4927 if (LocaleCompare("log",option+1) == 0)
4928 {
4929 if (*option == '+')
4930 break;
4931 i++;
cristybb503372010-05-27 20:51:26 +00004932 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004933 (strchr(argv[i],'%') == (char *) NULL))
4934 ThrowMogrifyException(OptionError,"MissingArgument",option);
4935 break;
4936 }
4937 if (LocaleCompare("loop",option+1) == 0)
4938 {
4939 if (*option == '+')
4940 break;
4941 i++;
cristybb503372010-05-27 20:51:26 +00004942 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004943 ThrowMogrifyException(OptionError,"MissingArgument",option);
4944 if (IsGeometry(argv[i]) == MagickFalse)
4945 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4946 break;
4947 }
4948 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4949 }
4950 case 'm':
4951 {
4952 if (LocaleCompare("map",option+1) == 0)
4953 {
4954 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4955 if (*option == '+')
4956 break;
4957 i++;
cristybb503372010-05-27 20:51:26 +00004958 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004959 ThrowMogrifyException(OptionError,"MissingArgument",option);
4960 break;
4961 }
4962 if (LocaleCompare("mask",option+1) == 0)
4963 {
4964 if (*option == '+')
4965 break;
4966 i++;
cristybb503372010-05-27 20:51:26 +00004967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004968 ThrowMogrifyException(OptionError,"MissingArgument",option);
4969 break;
4970 }
4971 if (LocaleCompare("matte",option+1) == 0)
4972 break;
4973 if (LocaleCompare("mattecolor",option+1) == 0)
4974 {
4975 if (*option == '+')
4976 break;
4977 i++;
cristybb503372010-05-27 20:51:26 +00004978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004979 ThrowMogrifyException(OptionError,"MissingArgument",option);
4980 break;
4981 }
cristyf40785b2010-03-06 02:27:27 +00004982 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004983 break;
cristyf40785b2010-03-06 02:27:27 +00004984 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004985 break;
cristy3ed852e2009-09-05 21:47:34 +00004986 if (LocaleCompare("modulate",option+1) == 0)
4987 {
4988 if (*option == '+')
4989 break;
4990 i++;
cristybb503372010-05-27 20:51:26 +00004991 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004992 ThrowMogrifyException(OptionError,"MissingArgument",option);
4993 if (IsGeometry(argv[i]) == MagickFalse)
4994 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4995 break;
4996 }
4997 if (LocaleCompare("median",option+1) == 0)
4998 {
4999 if (*option == '+')
5000 break;
5001 i++;
cristybb503372010-05-27 20:51:26 +00005002 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005003 ThrowMogrifyException(OptionError,"MissingArgument",option);
5004 if (IsGeometry(argv[i]) == MagickFalse)
5005 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5006 break;
5007 }
cristy69ec32d2011-02-27 23:57:09 +00005008 if (LocaleCompare("mode",option+1) == 0)
5009 {
5010 if (*option == '+')
5011 break;
5012 i++;
5013 if (i == (ssize_t) argc)
5014 ThrowMogrifyException(OptionError,"MissingArgument",option);
5015 if (IsGeometry(argv[i]) == MagickFalse)
5016 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5017 break;
5018 }
cristy3ed852e2009-09-05 21:47:34 +00005019 if (LocaleCompare("monitor",option+1) == 0)
5020 break;
5021 if (LocaleCompare("monochrome",option+1) == 0)
5022 break;
5023 if (LocaleCompare("morph",option+1) == 0)
5024 {
5025 if (*option == '+')
5026 break;
5027 i++;
cristybb503372010-05-27 20:51:26 +00005028 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005029 ThrowMogrifyException(OptionError,"MissingArgument",option);
5030 if (IsGeometry(argv[i]) == MagickFalse)
5031 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5032 break;
5033 }
anthony29188a82010-01-22 10:12:34 +00005034 if (LocaleCompare("morphology",option+1) == 0)
5035 {
anthony29188a82010-01-22 10:12:34 +00005036 char
5037 token[MaxTextExtent];
5038
cristyb6bd4ad2010-08-08 01:12:27 +00005039 KernelInfo
5040 *kernel_info;
5041
5042 ssize_t
5043 op;
5044
anthony29188a82010-01-22 10:12:34 +00005045 i++;
cristybb503372010-05-27 20:51:26 +00005046 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005047 ThrowMogrifyException(OptionError,"MissingArgument",option);
5048 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005049 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005050 if (op < 0)
5051 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005052 token);
anthony29188a82010-01-22 10:12:34 +00005053 i++;
cristybb503372010-05-27 20:51:26 +00005054 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005055 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005056 kernel_info=AcquireKernelInfo(argv[i]);
5057 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005058 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005059 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005060 break;
5061 }
cristy3ed852e2009-09-05 21:47:34 +00005062 if (LocaleCompare("mosaic",option+1) == 0)
5063 break;
5064 if (LocaleCompare("motion-blur",option+1) == 0)
5065 {
5066 if (*option == '+')
5067 break;
5068 i++;
cristybb503372010-05-27 20:51:26 +00005069 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005070 ThrowMogrifyException(OptionError,"MissingArgument",option);
5071 if (IsGeometry(argv[i]) == MagickFalse)
5072 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5073 break;
5074 }
5075 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5076 }
5077 case 'n':
5078 {
5079 if (LocaleCompare("negate",option+1) == 0)
5080 break;
5081 if (LocaleCompare("noise",option+1) == 0)
5082 {
5083 i++;
cristybb503372010-05-27 20:51:26 +00005084 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005085 ThrowMogrifyException(OptionError,"MissingArgument",option);
5086 if (*option == '+')
5087 {
cristybb503372010-05-27 20:51:26 +00005088 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005089 noise;
5090
cristy042ee782011-04-22 18:48:30 +00005091 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005092 if (noise < 0)
5093 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5094 argv[i]);
5095 break;
5096 }
5097 if (IsGeometry(argv[i]) == MagickFalse)
5098 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5099 break;
5100 }
5101 if (LocaleCompare("noop",option+1) == 0)
5102 break;
5103 if (LocaleCompare("normalize",option+1) == 0)
5104 break;
5105 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5106 }
5107 case 'o':
5108 {
5109 if (LocaleCompare("opaque",option+1) == 0)
5110 {
cristy3ed852e2009-09-05 21:47:34 +00005111 i++;
cristybb503372010-05-27 20:51:26 +00005112 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005113 ThrowMogrifyException(OptionError,"MissingArgument",option);
5114 break;
5115 }
5116 if (LocaleCompare("ordered-dither",option+1) == 0)
5117 {
5118 if (*option == '+')
5119 break;
5120 i++;
cristybb503372010-05-27 20:51:26 +00005121 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005122 ThrowMogrifyException(OptionError,"MissingArgument",option);
5123 break;
5124 }
5125 if (LocaleCompare("orient",option+1) == 0)
5126 {
cristybb503372010-05-27 20:51:26 +00005127 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005128 orientation;
5129
5130 orientation=UndefinedOrientation;
5131 if (*option == '+')
5132 break;
5133 i++;
cristybb503372010-05-27 20:51:26 +00005134 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005135 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005136 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005137 argv[i]);
5138 if (orientation < 0)
5139 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5140 argv[i]);
5141 break;
5142 }
5143 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5144 }
5145 case 'p':
5146 {
5147 if (LocaleCompare("page",option+1) == 0)
5148 {
5149 if (*option == '+')
5150 break;
5151 i++;
cristybb503372010-05-27 20:51:26 +00005152 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005153 ThrowMogrifyException(OptionError,"MissingArgument",option);
5154 break;
5155 }
5156 if (LocaleCompare("paint",option+1) == 0)
5157 {
5158 if (*option == '+')
5159 break;
5160 i++;
cristybb503372010-05-27 20:51:26 +00005161 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005162 ThrowMogrifyException(OptionError,"MissingArgument",option);
5163 if (IsGeometry(argv[i]) == MagickFalse)
5164 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5165 break;
5166 }
5167 if (LocaleCompare("path",option+1) == 0)
5168 {
5169 (void) CloneString(&path,(char *) NULL);
5170 if (*option == '+')
5171 break;
5172 i++;
cristybb503372010-05-27 20:51:26 +00005173 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005174 ThrowMogrifyException(OptionError,"MissingArgument",option);
5175 (void) CloneString(&path,argv[i]);
5176 break;
5177 }
5178 if (LocaleCompare("pointsize",option+1) == 0)
5179 {
5180 if (*option == '+')
5181 break;
5182 i++;
cristybb503372010-05-27 20:51:26 +00005183 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005184 ThrowMogrifyException(OptionError,"MissingArgument",option);
5185 if (IsGeometry(argv[i]) == MagickFalse)
5186 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5187 break;
5188 }
5189 if (LocaleCompare("polaroid",option+1) == 0)
5190 {
5191 if (*option == '+')
5192 break;
5193 i++;
cristybb503372010-05-27 20:51:26 +00005194 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005195 ThrowMogrifyException(OptionError,"MissingArgument",option);
5196 if (IsGeometry(argv[i]) == MagickFalse)
5197 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5198 break;
5199 }
5200 if (LocaleCompare("posterize",option+1) == 0)
5201 {
5202 if (*option == '+')
5203 break;
5204 i++;
cristybb503372010-05-27 20:51:26 +00005205 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005206 ThrowMogrifyException(OptionError,"MissingArgument",option);
5207 if (IsGeometry(argv[i]) == MagickFalse)
5208 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5209 break;
5210 }
cristye7f51092010-01-17 00:39:37 +00005211 if (LocaleCompare("precision",option+1) == 0)
5212 {
5213 if (*option == '+')
5214 break;
5215 i++;
cristybb503372010-05-27 20:51:26 +00005216 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005217 ThrowMogrifyException(OptionError,"MissingArgument",option);
5218 if (IsGeometry(argv[i]) == MagickFalse)
5219 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5220 break;
5221 }
cristy3ed852e2009-09-05 21:47:34 +00005222 if (LocaleCompare("print",option+1) == 0)
5223 {
5224 if (*option == '+')
5225 break;
5226 i++;
cristybb503372010-05-27 20:51:26 +00005227 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005228 ThrowMogrifyException(OptionError,"MissingArgument",option);
5229 break;
5230 }
5231 if (LocaleCompare("process",option+1) == 0)
5232 {
5233 if (*option == '+')
5234 break;
5235 i++;
cristybb503372010-05-27 20:51:26 +00005236 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005237 ThrowMogrifyException(OptionError,"MissingArgument",option);
5238 break;
5239 }
5240 if (LocaleCompare("profile",option+1) == 0)
5241 {
5242 i++;
cristybb503372010-05-27 20:51:26 +00005243 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005244 ThrowMogrifyException(OptionError,"MissingArgument",option);
5245 break;
5246 }
5247 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5248 }
5249 case 'q':
5250 {
5251 if (LocaleCompare("quality",option+1) == 0)
5252 {
5253 if (*option == '+')
5254 break;
5255 i++;
cristybb503372010-05-27 20:51:26 +00005256 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005257 ThrowMogrifyException(OptionError,"MissingArgument",option);
5258 if (IsGeometry(argv[i]) == MagickFalse)
5259 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5260 break;
5261 }
5262 if (LocaleCompare("quantize",option+1) == 0)
5263 {
cristybb503372010-05-27 20:51:26 +00005264 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005265 colorspace;
5266
5267 if (*option == '+')
5268 break;
5269 i++;
cristybb503372010-05-27 20:51:26 +00005270 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005271 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005272 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005273 argv[i]);
5274 if (colorspace < 0)
5275 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5276 argv[i]);
5277 break;
5278 }
5279 if (LocaleCompare("quiet",option+1) == 0)
5280 break;
5281 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5282 }
5283 case 'r':
5284 {
5285 if (LocaleCompare("radial-blur",option+1) == 0)
5286 {
5287 i++;
cristybb503372010-05-27 20:51:26 +00005288 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005289 ThrowMogrifyException(OptionError,"MissingArgument",option);
5290 if (IsGeometry(argv[i]) == MagickFalse)
5291 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5292 break;
5293 }
5294 if (LocaleCompare("raise",option+1) == 0)
5295 {
5296 i++;
cristybb503372010-05-27 20:51:26 +00005297 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005298 ThrowMogrifyException(OptionError,"MissingArgument",option);
5299 if (IsGeometry(argv[i]) == MagickFalse)
5300 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5301 break;
5302 }
5303 if (LocaleCompare("random-threshold",option+1) == 0)
5304 {
5305 if (*option == '+')
5306 break;
5307 i++;
cristybb503372010-05-27 20:51:26 +00005308 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005309 ThrowMogrifyException(OptionError,"MissingArgument",option);
5310 if (IsGeometry(argv[i]) == MagickFalse)
5311 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5312 break;
5313 }
cristye6365592010-04-02 17:31:23 +00005314 if (LocaleCompare("recolor",option+1) == 0)
5315 {
5316 if (*option == '+')
5317 break;
5318 i++;
cristybb503372010-05-27 20:51:26 +00005319 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005320 ThrowMogrifyException(OptionError,"MissingArgument",option);
5321 if (IsGeometry(argv[i]) == MagickFalse)
5322 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5323 break;
5324 }
cristy3ed852e2009-09-05 21:47:34 +00005325 if (LocaleCompare("red-primary",option+1) == 0)
5326 {
5327 if (*option == '+')
5328 break;
5329 i++;
cristybb503372010-05-27 20:51:26 +00005330 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005331 ThrowMogrifyException(OptionError,"MissingArgument",option);
5332 if (IsGeometry(argv[i]) == MagickFalse)
5333 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5334 }
cristy9f2083a2010-04-22 19:48:05 +00005335 if (LocaleCompare("regard-warnings",option+1) == 0)
5336 break;
cristy3ed852e2009-09-05 21:47:34 +00005337 if (LocaleCompare("region",option+1) == 0)
5338 {
5339 if (*option == '+')
5340 break;
5341 i++;
cristybb503372010-05-27 20:51:26 +00005342 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005343 ThrowMogrifyException(OptionError,"MissingArgument",option);
5344 if (IsGeometry(argv[i]) == MagickFalse)
5345 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5346 break;
5347 }
cristyf0c78232010-03-15 12:53:40 +00005348 if (LocaleCompare("remap",option+1) == 0)
5349 {
5350 if (*option == '+')
5351 break;
5352 i++;
cristybb503372010-05-27 20:51:26 +00005353 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005354 ThrowMogrifyException(OptionError,"MissingArgument",option);
5355 break;
5356 }
cristy3ed852e2009-09-05 21:47:34 +00005357 if (LocaleCompare("render",option+1) == 0)
5358 break;
5359 if (LocaleCompare("repage",option+1) == 0)
5360 {
5361 if (*option == '+')
5362 break;
5363 i++;
cristybb503372010-05-27 20:51:26 +00005364 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005365 ThrowMogrifyException(OptionError,"MissingArgument",option);
5366 if (IsGeometry(argv[i]) == MagickFalse)
5367 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5368 break;
5369 }
5370 if (LocaleCompare("resample",option+1) == 0)
5371 {
5372 if (*option == '+')
5373 break;
5374 i++;
cristybb503372010-05-27 20:51:26 +00005375 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005376 ThrowMogrifyException(OptionError,"MissingArgument",option);
5377 if (IsGeometry(argv[i]) == MagickFalse)
5378 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5379 break;
5380 }
5381 if (LocaleCompare("resize",option+1) == 0)
5382 {
5383 if (*option == '+')
5384 break;
5385 i++;
cristybb503372010-05-27 20:51:26 +00005386 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005387 ThrowMogrifyException(OptionError,"MissingArgument",option);
5388 if (IsGeometry(argv[i]) == MagickFalse)
5389 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5390 break;
5391 }
cristyebbcfea2011-02-25 02:43:54 +00005392 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5393 {
5394 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5395 break;
5396 }
cristy3ed852e2009-09-05 21:47:34 +00005397 if (LocaleCompare("reverse",option+1) == 0)
5398 break;
5399 if (LocaleCompare("roll",option+1) == 0)
5400 {
5401 if (*option == '+')
5402 break;
5403 i++;
cristybb503372010-05-27 20:51:26 +00005404 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005405 ThrowMogrifyException(OptionError,"MissingArgument",option);
5406 if (IsGeometry(argv[i]) == MagickFalse)
5407 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5408 break;
5409 }
5410 if (LocaleCompare("rotate",option+1) == 0)
5411 {
5412 i++;
cristybb503372010-05-27 20:51:26 +00005413 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005414 ThrowMogrifyException(OptionError,"MissingArgument",option);
5415 if (IsGeometry(argv[i]) == MagickFalse)
5416 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5417 break;
5418 }
5419 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5420 }
5421 case 's':
5422 {
5423 if (LocaleCompare("sample",option+1) == 0)
5424 {
5425 if (*option == '+')
5426 break;
5427 i++;
cristybb503372010-05-27 20:51:26 +00005428 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005429 ThrowMogrifyException(OptionError,"MissingArgument",option);
5430 if (IsGeometry(argv[i]) == MagickFalse)
5431 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5432 break;
5433 }
5434 if (LocaleCompare("sampling-factor",option+1) == 0)
5435 {
5436 if (*option == '+')
5437 break;
5438 i++;
cristybb503372010-05-27 20:51:26 +00005439 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005440 ThrowMogrifyException(OptionError,"MissingArgument",option);
5441 if (IsGeometry(argv[i]) == MagickFalse)
5442 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5443 break;
5444 }
5445 if (LocaleCompare("scale",option+1) == 0)
5446 {
5447 if (*option == '+')
5448 break;
5449 i++;
cristybb503372010-05-27 20:51:26 +00005450 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005451 ThrowMogrifyException(OptionError,"MissingArgument",option);
5452 if (IsGeometry(argv[i]) == MagickFalse)
5453 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5454 break;
5455 }
5456 if (LocaleCompare("scene",option+1) == 0)
5457 {
5458 if (*option == '+')
5459 break;
5460 i++;
cristybb503372010-05-27 20:51:26 +00005461 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005462 ThrowMogrifyException(OptionError,"MissingArgument",option);
5463 if (IsGeometry(argv[i]) == MagickFalse)
5464 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5465 break;
5466 }
5467 if (LocaleCompare("seed",option+1) == 0)
5468 {
5469 if (*option == '+')
5470 break;
5471 i++;
cristybb503372010-05-27 20:51:26 +00005472 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005473 ThrowMogrifyException(OptionError,"MissingArgument",option);
5474 if (IsGeometry(argv[i]) == MagickFalse)
5475 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5476 break;
5477 }
5478 if (LocaleCompare("segment",option+1) == 0)
5479 {
5480 if (*option == '+')
5481 break;
5482 i++;
cristybb503372010-05-27 20:51:26 +00005483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005484 ThrowMogrifyException(OptionError,"MissingArgument",option);
5485 if (IsGeometry(argv[i]) == MagickFalse)
5486 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5487 break;
5488 }
5489 if (LocaleCompare("selective-blur",option+1) == 0)
5490 {
5491 i++;
cristybb503372010-05-27 20:51:26 +00005492 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005493 ThrowMogrifyException(OptionError,"MissingArgument",option);
5494 if (IsGeometry(argv[i]) == MagickFalse)
5495 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5496 break;
5497 }
5498 if (LocaleCompare("separate",option+1) == 0)
5499 break;
5500 if (LocaleCompare("sepia-tone",option+1) == 0)
5501 {
5502 if (*option == '+')
5503 break;
5504 i++;
cristybb503372010-05-27 20:51:26 +00005505 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005506 ThrowMogrifyException(OptionError,"MissingArgument",option);
5507 if (IsGeometry(argv[i]) == MagickFalse)
5508 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5509 break;
5510 }
5511 if (LocaleCompare("set",option+1) == 0)
5512 {
5513 i++;
cristybb503372010-05-27 20:51:26 +00005514 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005515 ThrowMogrifyException(OptionError,"MissingArgument",option);
5516 if (*option == '+')
5517 break;
5518 i++;
cristybb503372010-05-27 20:51:26 +00005519 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005520 ThrowMogrifyException(OptionError,"MissingArgument",option);
5521 break;
5522 }
5523 if (LocaleCompare("shade",option+1) == 0)
5524 {
5525 i++;
cristybb503372010-05-27 20:51:26 +00005526 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005527 ThrowMogrifyException(OptionError,"MissingArgument",option);
5528 if (IsGeometry(argv[i]) == MagickFalse)
5529 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5530 break;
5531 }
5532 if (LocaleCompare("shadow",option+1) == 0)
5533 {
5534 if (*option == '+')
5535 break;
5536 i++;
cristybb503372010-05-27 20:51:26 +00005537 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005538 ThrowMogrifyException(OptionError,"MissingArgument",option);
5539 if (IsGeometry(argv[i]) == MagickFalse)
5540 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5541 break;
5542 }
5543 if (LocaleCompare("sharpen",option+1) == 0)
5544 {
5545 i++;
cristybb503372010-05-27 20:51:26 +00005546 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005547 ThrowMogrifyException(OptionError,"MissingArgument",option);
5548 if (IsGeometry(argv[i]) == MagickFalse)
5549 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5550 break;
5551 }
5552 if (LocaleCompare("shave",option+1) == 0)
5553 {
5554 if (*option == '+')
5555 break;
5556 i++;
cristybb503372010-05-27 20:51:26 +00005557 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005558 ThrowMogrifyException(OptionError,"MissingArgument",option);
5559 if (IsGeometry(argv[i]) == MagickFalse)
5560 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5561 break;
5562 }
5563 if (LocaleCompare("shear",option+1) == 0)
5564 {
5565 i++;
cristybb503372010-05-27 20:51:26 +00005566 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005567 ThrowMogrifyException(OptionError,"MissingArgument",option);
5568 if (IsGeometry(argv[i]) == MagickFalse)
5569 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5570 break;
5571 }
5572 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5573 {
5574 i++;
cristybb503372010-05-27 20:51:26 +00005575 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005576 ThrowMogrifyException(OptionError,"MissingArgument",option);
5577 if (IsGeometry(argv[i]) == MagickFalse)
5578 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5579 break;
5580 }
5581 if (LocaleCompare("size",option+1) == 0)
5582 {
5583 if (*option == '+')
5584 break;
5585 i++;
cristybb503372010-05-27 20:51:26 +00005586 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005587 ThrowMogrifyException(OptionError,"MissingArgument",option);
5588 if (IsGeometry(argv[i]) == MagickFalse)
5589 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5590 break;
5591 }
5592 if (LocaleCompare("sketch",option+1) == 0)
5593 {
5594 if (*option == '+')
5595 break;
5596 i++;
cristybb503372010-05-27 20:51:26 +00005597 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005598 ThrowMogrifyException(OptionError,"MissingArgument",option);
5599 if (IsGeometry(argv[i]) == MagickFalse)
5600 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5601 break;
5602 }
cristy4285d782011-02-09 20:12:28 +00005603 if (LocaleCompare("smush",option+1) == 0)
5604 {
cristy4285d782011-02-09 20:12:28 +00005605 i++;
5606 if (i == (ssize_t) argc)
5607 ThrowMogrifyException(OptionError,"MissingArgument",option);
5608 if (IsGeometry(argv[i]) == MagickFalse)
5609 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005610 i++;
5611 break;
5612 }
cristy3ed852e2009-09-05 21:47:34 +00005613 if (LocaleCompare("solarize",option+1) == 0)
5614 {
5615 if (*option == '+')
5616 break;
5617 i++;
cristybb503372010-05-27 20:51:26 +00005618 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005619 ThrowMogrifyException(OptionError,"MissingArgument",option);
5620 if (IsGeometry(argv[i]) == MagickFalse)
5621 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5622 break;
5623 }
5624 if (LocaleCompare("sparse-color",option+1) == 0)
5625 {
cristybb503372010-05-27 20:51:26 +00005626 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005627 op;
5628
5629 i++;
cristybb503372010-05-27 20:51:26 +00005630 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005631 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005632 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005633 if (op < 0)
5634 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5635 argv[i]);
5636 i++;
cristybb503372010-05-27 20:51:26 +00005637 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005638 ThrowMogrifyException(OptionError,"MissingArgument",option);
5639 break;
5640 }
5641 if (LocaleCompare("spread",option+1) == 0)
5642 {
5643 if (*option == '+')
5644 break;
5645 i++;
cristybb503372010-05-27 20:51:26 +00005646 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005647 ThrowMogrifyException(OptionError,"MissingArgument",option);
5648 if (IsGeometry(argv[i]) == MagickFalse)
5649 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5650 break;
5651 }
cristy0834d642011-03-18 18:26:08 +00005652 if (LocaleCompare("statistic",option+1) == 0)
5653 {
5654 ssize_t
5655 op;
5656
5657 if (*option == '+')
5658 break;
5659 i++;
5660 if (i == (ssize_t) argc)
5661 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005662 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005663 if (op < 0)
5664 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5665 argv[i]);
5666 i++;
5667 if (i == (ssize_t) (argc-1))
5668 ThrowMogrifyException(OptionError,"MissingArgument",option);
5669 if (IsGeometry(argv[i]) == MagickFalse)
5670 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5671 break;
5672 }
cristy3ed852e2009-09-05 21:47:34 +00005673 if (LocaleCompare("stretch",option+1) == 0)
5674 {
cristybb503372010-05-27 20:51:26 +00005675 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005676 stretch;
5677
5678 if (*option == '+')
5679 break;
5680 i++;
cristybb503372010-05-27 20:51:26 +00005681 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005682 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005683 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005684 if (stretch < 0)
5685 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5686 argv[i]);
5687 break;
5688 }
5689 if (LocaleCompare("strip",option+1) == 0)
5690 break;
5691 if (LocaleCompare("stroke",option+1) == 0)
5692 {
5693 if (*option == '+')
5694 break;
5695 i++;
cristybb503372010-05-27 20:51:26 +00005696 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005697 ThrowMogrifyException(OptionError,"MissingArgument",option);
5698 break;
5699 }
5700 if (LocaleCompare("strokewidth",option+1) == 0)
5701 {
5702 if (*option == '+')
5703 break;
5704 i++;
cristybb503372010-05-27 20:51:26 +00005705 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005706 ThrowMogrifyException(OptionError,"MissingArgument",option);
5707 if (IsGeometry(argv[i]) == MagickFalse)
5708 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5709 break;
5710 }
5711 if (LocaleCompare("style",option+1) == 0)
5712 {
cristybb503372010-05-27 20:51:26 +00005713 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005714 style;
5715
5716 if (*option == '+')
5717 break;
5718 i++;
cristybb503372010-05-27 20:51:26 +00005719 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005720 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005721 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005722 if (style < 0)
5723 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5724 argv[i]);
5725 break;
5726 }
cristyecb10ff2011-03-22 13:14:03 +00005727 if (LocaleCompare("swap",option+1) == 0)
5728 {
5729 if (*option == '+')
5730 break;
5731 i++;
5732 if (i == (ssize_t) (argc-1))
5733 ThrowMogrifyException(OptionError,"MissingArgument",option);
5734 if (IsGeometry(argv[i]) == MagickFalse)
5735 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5736 break;
5737 }
cristy3ed852e2009-09-05 21:47:34 +00005738 if (LocaleCompare("swirl",option+1) == 0)
5739 {
5740 if (*option == '+')
5741 break;
5742 i++;
cristybb503372010-05-27 20:51:26 +00005743 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005744 ThrowMogrifyException(OptionError,"MissingArgument",option);
5745 if (IsGeometry(argv[i]) == MagickFalse)
5746 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5747 break;
5748 }
cristyd9a29192010-10-16 16:49:53 +00005749 if (LocaleCompare("synchronize",option+1) == 0)
5750 break;
cristy3ed852e2009-09-05 21:47:34 +00005751 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5752 }
5753 case 't':
5754 {
5755 if (LocaleCompare("taint",option+1) == 0)
5756 break;
5757 if (LocaleCompare("texture",option+1) == 0)
5758 {
5759 if (*option == '+')
5760 break;
5761 i++;
cristybb503372010-05-27 20:51:26 +00005762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005763 ThrowMogrifyException(OptionError,"MissingArgument",option);
5764 break;
5765 }
5766 if (LocaleCompare("tile",option+1) == 0)
5767 {
5768 if (*option == '+')
5769 break;
5770 i++;
cristybb503372010-05-27 20:51:26 +00005771 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005772 ThrowMogrifyException(OptionError,"MissingArgument",option);
5773 break;
5774 }
5775 if (LocaleCompare("tile-offset",option+1) == 0)
5776 {
5777 if (*option == '+')
5778 break;
5779 i++;
cristybb503372010-05-27 20:51:26 +00005780 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005781 ThrowMogrifyException(OptionError,"MissingArgument",option);
5782 if (IsGeometry(argv[i]) == MagickFalse)
5783 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5784 break;
5785 }
5786 if (LocaleCompare("tint",option+1) == 0)
5787 {
5788 if (*option == '+')
5789 break;
5790 i++;
cristybb503372010-05-27 20:51:26 +00005791 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005792 ThrowMogrifyException(OptionError,"MissingArgument",option);
5793 if (IsGeometry(argv[i]) == MagickFalse)
5794 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5795 break;
5796 }
5797 if (LocaleCompare("transform",option+1) == 0)
5798 break;
5799 if (LocaleCompare("transpose",option+1) == 0)
5800 break;
5801 if (LocaleCompare("transverse",option+1) == 0)
5802 break;
5803 if (LocaleCompare("threshold",option+1) == 0)
5804 {
5805 if (*option == '+')
5806 break;
5807 i++;
cristybb503372010-05-27 20:51:26 +00005808 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005809 ThrowMogrifyException(OptionError,"MissingArgument",option);
5810 if (IsGeometry(argv[i]) == MagickFalse)
5811 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5812 break;
5813 }
5814 if (LocaleCompare("thumbnail",option+1) == 0)
5815 {
5816 if (*option == '+')
5817 break;
5818 i++;
cristybb503372010-05-27 20:51:26 +00005819 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005820 ThrowMogrifyException(OptionError,"MissingArgument",option);
5821 if (IsGeometry(argv[i]) == MagickFalse)
5822 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5823 break;
5824 }
5825 if (LocaleCompare("transparent",option+1) == 0)
5826 {
5827 i++;
cristybb503372010-05-27 20:51:26 +00005828 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005829 ThrowMogrifyException(OptionError,"MissingArgument",option);
5830 break;
5831 }
5832 if (LocaleCompare("transparent-color",option+1) == 0)
5833 {
5834 if (*option == '+')
5835 break;
5836 i++;
cristybb503372010-05-27 20:51:26 +00005837 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005838 ThrowMogrifyException(OptionError,"MissingArgument",option);
5839 break;
5840 }
5841 if (LocaleCompare("treedepth",option+1) == 0)
5842 {
5843 if (*option == '+')
5844 break;
5845 i++;
cristybb503372010-05-27 20:51:26 +00005846 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005847 ThrowMogrifyException(OptionError,"MissingArgument",option);
5848 if (IsGeometry(argv[i]) == MagickFalse)
5849 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5850 break;
5851 }
5852 if (LocaleCompare("trim",option+1) == 0)
5853 break;
5854 if (LocaleCompare("type",option+1) == 0)
5855 {
cristybb503372010-05-27 20:51:26 +00005856 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005857 type;
5858
5859 if (*option == '+')
5860 break;
5861 i++;
cristybb503372010-05-27 20:51:26 +00005862 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005863 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005864 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005865 if (type < 0)
5866 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5867 argv[i]);
5868 break;
5869 }
5870 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5871 }
5872 case 'u':
5873 {
5874 if (LocaleCompare("undercolor",option+1) == 0)
5875 {
5876 if (*option == '+')
5877 break;
5878 i++;
cristybb503372010-05-27 20:51:26 +00005879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005880 ThrowMogrifyException(OptionError,"MissingArgument",option);
5881 break;
5882 }
5883 if (LocaleCompare("unique-colors",option+1) == 0)
5884 break;
5885 if (LocaleCompare("units",option+1) == 0)
5886 {
cristybb503372010-05-27 20:51:26 +00005887 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005888 units;
5889
5890 if (*option == '+')
5891 break;
5892 i++;
cristybb503372010-05-27 20:51:26 +00005893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005894 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005895 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005896 argv[i]);
5897 if (units < 0)
5898 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5899 argv[i]);
5900 break;
5901 }
5902 if (LocaleCompare("unsharp",option+1) == 0)
5903 {
5904 i++;
cristybb503372010-05-27 20:51:26 +00005905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005906 ThrowMogrifyException(OptionError,"MissingArgument",option);
5907 if (IsGeometry(argv[i]) == MagickFalse)
5908 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5909 break;
5910 }
5911 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5912 }
5913 case 'v':
5914 {
5915 if (LocaleCompare("verbose",option+1) == 0)
5916 {
5917 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5918 break;
5919 }
5920 if ((LocaleCompare("version",option+1) == 0) ||
5921 (LocaleCompare("-version",option+1) == 0))
5922 {
cristyb51dff52011-05-19 16:55:47 +00005923 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005924 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005925 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5926 GetMagickCopyright());
5927 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5928 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005929 break;
5930 }
5931 if (LocaleCompare("view",option+1) == 0)
5932 {
5933 if (*option == '+')
5934 break;
5935 i++;
cristybb503372010-05-27 20:51:26 +00005936 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005937 ThrowMogrifyException(OptionError,"MissingArgument",option);
5938 break;
5939 }
5940 if (LocaleCompare("vignette",option+1) == 0)
5941 {
5942 if (*option == '+')
5943 break;
5944 i++;
cristybb503372010-05-27 20:51:26 +00005945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005946 ThrowMogrifyException(OptionError,"MissingArgument",option);
5947 if (IsGeometry(argv[i]) == MagickFalse)
5948 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5949 break;
5950 }
5951 if (LocaleCompare("virtual-pixel",option+1) == 0)
5952 {
cristybb503372010-05-27 20:51:26 +00005953 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005954 method;
5955
5956 if (*option == '+')
5957 break;
5958 i++;
cristybb503372010-05-27 20:51:26 +00005959 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005960 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005961 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005962 argv[i]);
5963 if (method < 0)
5964 ThrowMogrifyException(OptionError,
5965 "UnrecognizedVirtualPixelMethod",argv[i]);
5966 break;
5967 }
5968 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5969 }
5970 case 'w':
5971 {
5972 if (LocaleCompare("wave",option+1) == 0)
5973 {
5974 i++;
cristybb503372010-05-27 20:51:26 +00005975 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005976 ThrowMogrifyException(OptionError,"MissingArgument",option);
5977 if (IsGeometry(argv[i]) == MagickFalse)
5978 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5979 break;
5980 }
5981 if (LocaleCompare("weight",option+1) == 0)
5982 {
5983 if (*option == '+')
5984 break;
5985 i++;
cristybb503372010-05-27 20:51:26 +00005986 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005987 ThrowMogrifyException(OptionError,"MissingArgument",option);
5988 break;
5989 }
5990 if (LocaleCompare("white-point",option+1) == 0)
5991 {
5992 if (*option == '+')
5993 break;
5994 i++;
cristybb503372010-05-27 20:51:26 +00005995 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005996 ThrowMogrifyException(OptionError,"MissingArgument",option);
5997 if (IsGeometry(argv[i]) == MagickFalse)
5998 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5999 break;
6000 }
6001 if (LocaleCompare("white-threshold",option+1) == 0)
6002 {
6003 if (*option == '+')
6004 break;
6005 i++;
cristybb503372010-05-27 20:51:26 +00006006 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006007 ThrowMogrifyException(OptionError,"MissingArgument",option);
6008 if (IsGeometry(argv[i]) == MagickFalse)
6009 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6010 break;
6011 }
6012 if (LocaleCompare("write",option+1) == 0)
6013 {
6014 i++;
cristybb503372010-05-27 20:51:26 +00006015 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006016 ThrowMogrifyException(OptionError,"MissingArgument",option);
6017 break;
6018 }
6019 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6020 }
6021 case '?':
6022 break;
6023 default:
6024 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6025 }
cristy042ee782011-04-22 18:48:30 +00006026 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6027 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006028 if (fire != MagickFalse)
6029 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6030 }
6031 if (k != 0)
6032 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006033 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006034 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6035 DestroyMogrify();
6036 return(status != 0 ? MagickTrue : MagickFalse);
6037}
6038
6039/*
6040%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6041% %
6042% %
6043% %
6044+ M o g r i f y I m a g e I n f o %
6045% %
6046% %
6047% %
6048%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6049%
6050% MogrifyImageInfo() applies image processing settings to the image as
6051% prescribed by command line options.
6052%
6053% The format of the MogrifyImageInfo method is:
6054%
6055% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6056% const char **argv,ExceptionInfo *exception)
6057%
6058% A description of each parameter follows:
6059%
6060% o image_info: the image info..
6061%
6062% o argc: Specifies a pointer to an integer describing the number of
6063% elements in the argument vector.
6064%
6065% o argv: Specifies a pointer to a text array containing the command line
6066% arguments.
6067%
6068% o exception: return any errors or warnings in this structure.
6069%
6070*/
6071WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6072 const int argc,const char **argv,ExceptionInfo *exception)
6073{
6074 const char
6075 *option;
6076
6077 GeometryInfo
6078 geometry_info;
6079
cristybb503372010-05-27 20:51:26 +00006080 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006081 count;
6082
cristybb503372010-05-27 20:51:26 +00006083 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006084 i;
6085
6086 /*
6087 Initialize method variables.
6088 */
6089 assert(image_info != (ImageInfo *) NULL);
6090 assert(image_info->signature == MagickSignature);
6091 if (image_info->debug != MagickFalse)
6092 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6093 image_info->filename);
6094 if (argc < 0)
6095 return(MagickTrue);
6096 /*
6097 Set the image settings.
6098 */
cristybb503372010-05-27 20:51:26 +00006099 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006100 {
6101 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006102 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006103 continue;
cristy042ee782011-04-22 18:48:30 +00006104 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006105 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006106 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006107 break;
6108 switch (*(option+1))
6109 {
6110 case 'a':
6111 {
6112 if (LocaleCompare("adjoin",option+1) == 0)
6113 {
6114 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6115 break;
6116 }
6117 if (LocaleCompare("antialias",option+1) == 0)
6118 {
6119 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6120 break;
6121 }
6122 if (LocaleCompare("attenuate",option+1) == 0)
6123 {
6124 if (*option == '+')
6125 {
6126 (void) DeleteImageOption(image_info,option+1);
6127 break;
6128 }
6129 (void) SetImageOption(image_info,option+1,argv[i+1]);
6130 break;
6131 }
6132 if (LocaleCompare("authenticate",option+1) == 0)
6133 {
6134 if (*option == '+')
6135 (void) CloneString(&image_info->authenticate,(char *) NULL);
6136 else
6137 (void) CloneString(&image_info->authenticate,argv[i+1]);
6138 break;
6139 }
6140 break;
6141 }
6142 case 'b':
6143 {
6144 if (LocaleCompare("background",option+1) == 0)
6145 {
6146 if (*option == '+')
6147 {
6148 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006149 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006150 &image_info->background_color,exception);
6151 break;
6152 }
6153 (void) SetImageOption(image_info,option+1,argv[i+1]);
6154 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6155 exception);
6156 break;
6157 }
6158 if (LocaleCompare("bias",option+1) == 0)
6159 {
6160 if (*option == '+')
6161 {
6162 (void) SetImageOption(image_info,option+1,"0.0");
6163 break;
6164 }
6165 (void) SetImageOption(image_info,option+1,argv[i+1]);
6166 break;
6167 }
6168 if (LocaleCompare("black-point-compensation",option+1) == 0)
6169 {
6170 if (*option == '+')
6171 {
6172 (void) SetImageOption(image_info,option+1,"false");
6173 break;
6174 }
6175 (void) SetImageOption(image_info,option+1,"true");
6176 break;
6177 }
6178 if (LocaleCompare("blue-primary",option+1) == 0)
6179 {
6180 if (*option == '+')
6181 {
6182 (void) SetImageOption(image_info,option+1,"0.0");
6183 break;
6184 }
6185 (void) SetImageOption(image_info,option+1,argv[i+1]);
6186 break;
6187 }
6188 if (LocaleCompare("bordercolor",option+1) == 0)
6189 {
6190 if (*option == '+')
6191 {
6192 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006193 (void) QueryColorDatabase(MogrifyBorderColor,
6194 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006195 break;
6196 }
6197 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6198 exception);
6199 (void) SetImageOption(image_info,option+1,argv[i+1]);
6200 break;
6201 }
6202 if (LocaleCompare("box",option+1) == 0)
6203 {
6204 if (*option == '+')
6205 {
6206 (void) SetImageOption(image_info,"undercolor","none");
6207 break;
6208 }
6209 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6210 break;
6211 }
6212 break;
6213 }
6214 case 'c':
6215 {
6216 if (LocaleCompare("cache",option+1) == 0)
6217 {
6218 MagickSizeType
6219 limit;
6220
6221 limit=MagickResourceInfinity;
6222 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006223 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006224 (void) SetMagickResourceLimit(MemoryResource,limit);
6225 (void) SetMagickResourceLimit(MapResource,2*limit);
6226 break;
6227 }
6228 if (LocaleCompare("caption",option+1) == 0)
6229 {
6230 if (*option == '+')
6231 {
6232 (void) DeleteImageOption(image_info,option+1);
6233 break;
6234 }
6235 (void) SetImageOption(image_info,option+1,argv[i+1]);
6236 break;
6237 }
6238 if (LocaleCompare("channel",option+1) == 0)
6239 {
6240 if (*option == '+')
6241 {
6242 image_info->channel=DefaultChannels;
6243 break;
6244 }
6245 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6246 break;
6247 }
6248 if (LocaleCompare("colors",option+1) == 0)
6249 {
cristye27293e2009-12-18 02:53:20 +00006250 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006251 break;
6252 }
6253 if (LocaleCompare("colorspace",option+1) == 0)
6254 {
6255 if (*option == '+')
6256 {
6257 image_info->colorspace=UndefinedColorspace;
6258 (void) SetImageOption(image_info,option+1,"undefined");
6259 break;
6260 }
cristy042ee782011-04-22 18:48:30 +00006261 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006262 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6263 (void) SetImageOption(image_info,option+1,argv[i+1]);
6264 break;
6265 }
cristy3ed852e2009-09-05 21:47:34 +00006266 if (LocaleCompare("comment",option+1) == 0)
6267 {
6268 if (*option == '+')
6269 {
6270 (void) DeleteImageOption(image_info,option+1);
6271 break;
6272 }
6273 (void) SetImageOption(image_info,option+1,argv[i+1]);
6274 break;
6275 }
6276 if (LocaleCompare("compose",option+1) == 0)
6277 {
6278 if (*option == '+')
6279 {
6280 (void) SetImageOption(image_info,option+1,"undefined");
6281 break;
6282 }
6283 (void) SetImageOption(image_info,option+1,argv[i+1]);
6284 break;
6285 }
6286 if (LocaleCompare("compress",option+1) == 0)
6287 {
6288 if (*option == '+')
6289 {
6290 image_info->compression=UndefinedCompression;
6291 (void) SetImageOption(image_info,option+1,"undefined");
6292 break;
6293 }
cristy042ee782011-04-22 18:48:30 +00006294 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006295 MagickCompressOptions,MagickFalse,argv[i+1]);
6296 (void) SetImageOption(image_info,option+1,argv[i+1]);
6297 break;
6298 }
6299 break;
6300 }
6301 case 'd':
6302 {
6303 if (LocaleCompare("debug",option+1) == 0)
6304 {
6305 if (*option == '+')
6306 (void) SetLogEventMask("none");
6307 else
6308 (void) SetLogEventMask(argv[i+1]);
6309 image_info->debug=IsEventLogging();
6310 break;
6311 }
6312 if (LocaleCompare("define",option+1) == 0)
6313 {
6314 if (*option == '+')
6315 {
6316 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6317 (void) DeleteImageRegistry(argv[i+1]+9);
6318 else
6319 (void) DeleteImageOption(image_info,argv[i+1]);
6320 break;
6321 }
6322 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6323 {
6324 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6325 exception);
6326 break;
6327 }
6328 (void) DefineImageOption(image_info,argv[i+1]);
6329 break;
6330 }
6331 if (LocaleCompare("delay",option+1) == 0)
6332 {
6333 if (*option == '+')
6334 {
6335 (void) SetImageOption(image_info,option+1,"0");
6336 break;
6337 }
6338 (void) SetImageOption(image_info,option+1,argv[i+1]);
6339 break;
6340 }
6341 if (LocaleCompare("density",option+1) == 0)
6342 {
6343 /*
6344 Set image density.
6345 */
6346 if (*option == '+')
6347 {
6348 if (image_info->density != (char *) NULL)
6349 image_info->density=DestroyString(image_info->density);
6350 (void) SetImageOption(image_info,option+1,"72");
6351 break;
6352 }
6353 (void) CloneString(&image_info->density,argv[i+1]);
6354 (void) SetImageOption(image_info,option+1,argv[i+1]);
6355 break;
6356 }
6357 if (LocaleCompare("depth",option+1) == 0)
6358 {
6359 if (*option == '+')
6360 {
6361 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6362 break;
6363 }
cristye27293e2009-12-18 02:53:20 +00006364 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006365 break;
6366 }
cristyc9b12952010-03-28 01:12:28 +00006367 if (LocaleCompare("direction",option+1) == 0)
6368 {
6369 if (*option == '+')
6370 {
6371 (void) SetImageOption(image_info,option+1,"undefined");
6372 break;
6373 }
6374 (void) SetImageOption(image_info,option+1,argv[i+1]);
6375 break;
6376 }
cristy3ed852e2009-09-05 21:47:34 +00006377 if (LocaleCompare("display",option+1) == 0)
6378 {
6379 if (*option == '+')
6380 {
6381 if (image_info->server_name != (char *) NULL)
6382 image_info->server_name=DestroyString(
6383 image_info->server_name);
6384 break;
6385 }
6386 (void) CloneString(&image_info->server_name,argv[i+1]);
6387 break;
6388 }
6389 if (LocaleCompare("dispose",option+1) == 0)
6390 {
6391 if (*option == '+')
6392 {
6393 (void) SetImageOption(image_info,option+1,"undefined");
6394 break;
6395 }
6396 (void) SetImageOption(image_info,option+1,argv[i+1]);
6397 break;
6398 }
6399 if (LocaleCompare("dither",option+1) == 0)
6400 {
6401 if (*option == '+')
6402 {
6403 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006404 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006405 break;
6406 }
6407 (void) SetImageOption(image_info,option+1,argv[i+1]);
6408 image_info->dither=MagickTrue;
6409 break;
6410 }
6411 break;
6412 }
6413 case 'e':
6414 {
6415 if (LocaleCompare("encoding",option+1) == 0)
6416 {
6417 if (*option == '+')
6418 {
6419 (void) SetImageOption(image_info,option+1,"undefined");
6420 break;
6421 }
6422 (void) SetImageOption(image_info,option+1,argv[i+1]);
6423 break;
6424 }
6425 if (LocaleCompare("endian",option+1) == 0)
6426 {
6427 if (*option == '+')
6428 {
6429 image_info->endian=UndefinedEndian;
6430 (void) SetImageOption(image_info,option+1,"undefined");
6431 break;
6432 }
cristy042ee782011-04-22 18:48:30 +00006433 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006434 MagickEndianOptions,MagickFalse,argv[i+1]);
6435 (void) SetImageOption(image_info,option+1,argv[i+1]);
6436 break;
6437 }
6438 if (LocaleCompare("extract",option+1) == 0)
6439 {
6440 /*
6441 Set image extract geometry.
6442 */
6443 if (*option == '+')
6444 {
6445 if (image_info->extract != (char *) NULL)
6446 image_info->extract=DestroyString(image_info->extract);
6447 break;
6448 }
6449 (void) CloneString(&image_info->extract,argv[i+1]);
6450 break;
6451 }
6452 break;
6453 }
6454 case 'f':
6455 {
6456 if (LocaleCompare("fill",option+1) == 0)
6457 {
6458 if (*option == '+')
6459 {
6460 (void) SetImageOption(image_info,option+1,"none");
6461 break;
6462 }
6463 (void) SetImageOption(image_info,option+1,argv[i+1]);
6464 break;
6465 }
6466 if (LocaleCompare("filter",option+1) == 0)
6467 {
6468 if (*option == '+')
6469 {
6470 (void) SetImageOption(image_info,option+1,"undefined");
6471 break;
6472 }
6473 (void) SetImageOption(image_info,option+1,argv[i+1]);
6474 break;
6475 }
6476 if (LocaleCompare("font",option+1) == 0)
6477 {
6478 if (*option == '+')
6479 {
6480 if (image_info->font != (char *) NULL)
6481 image_info->font=DestroyString(image_info->font);
6482 break;
6483 }
6484 (void) CloneString(&image_info->font,argv[i+1]);
6485 break;
6486 }
6487 if (LocaleCompare("format",option+1) == 0)
6488 {
6489 register const char
6490 *q;
6491
6492 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006493 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006494 image_info->ping=MagickFalse;
6495 (void) SetImageOption(image_info,option+1,argv[i+1]);
6496 break;
6497 }
6498 if (LocaleCompare("fuzz",option+1) == 0)
6499 {
6500 if (*option == '+')
6501 {
6502 image_info->fuzz=0.0;
6503 (void) SetImageOption(image_info,option+1,"0");
6504 break;
6505 }
cristyf2f27272009-12-17 14:48:46 +00006506 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006507 1.0);
6508 (void) SetImageOption(image_info,option+1,argv[i+1]);
6509 break;
6510 }
6511 break;
6512 }
6513 case 'g':
6514 {
6515 if (LocaleCompare("gravity",option+1) == 0)
6516 {
6517 if (*option == '+')
6518 {
6519 (void) SetImageOption(image_info,option+1,"undefined");
6520 break;
6521 }
6522 (void) SetImageOption(image_info,option+1,argv[i+1]);
6523 break;
6524 }
6525 if (LocaleCompare("green-primary",option+1) == 0)
6526 {
6527 if (*option == '+')
6528 {
6529 (void) SetImageOption(image_info,option+1,"0.0");
6530 break;
6531 }
6532 (void) SetImageOption(image_info,option+1,argv[i+1]);
6533 break;
6534 }
6535 break;
6536 }
6537 case 'i':
6538 {
6539 if (LocaleCompare("intent",option+1) == 0)
6540 {
6541 if (*option == '+')
6542 {
6543 (void) SetImageOption(image_info,option+1,"undefined");
6544 break;
6545 }
6546 (void) SetImageOption(image_info,option+1,argv[i+1]);
6547 break;
6548 }
6549 if (LocaleCompare("interlace",option+1) == 0)
6550 {
6551 if (*option == '+')
6552 {
6553 image_info->interlace=UndefinedInterlace;
6554 (void) SetImageOption(image_info,option+1,"undefined");
6555 break;
6556 }
cristy042ee782011-04-22 18:48:30 +00006557 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006558 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6559 (void) SetImageOption(image_info,option+1,argv[i+1]);
6560 break;
6561 }
cristyb32b90a2009-09-07 21:45:48 +00006562 if (LocaleCompare("interline-spacing",option+1) == 0)
6563 {
6564 if (*option == '+')
6565 {
6566 (void) SetImageOption(image_info,option+1,"undefined");
6567 break;
6568 }
6569 (void) SetImageOption(image_info,option+1,argv[i+1]);
6570 break;
6571 }
cristy3ed852e2009-09-05 21:47:34 +00006572 if (LocaleCompare("interpolate",option+1) == 0)
6573 {
6574 if (*option == '+')
6575 {
6576 (void) SetImageOption(image_info,option+1,"undefined");
6577 break;
6578 }
6579 (void) SetImageOption(image_info,option+1,argv[i+1]);
6580 break;
6581 }
6582 if (LocaleCompare("interword-spacing",option+1) == 0)
6583 {
6584 if (*option == '+')
6585 {
6586 (void) SetImageOption(image_info,option+1,"undefined");
6587 break;
6588 }
6589 (void) SetImageOption(image_info,option+1,argv[i+1]);
6590 break;
6591 }
6592 break;
6593 }
6594 case 'k':
6595 {
6596 if (LocaleCompare("kerning",option+1) == 0)
6597 {
6598 if (*option == '+')
6599 {
6600 (void) SetImageOption(image_info,option+1,"undefined");
6601 break;
6602 }
6603 (void) SetImageOption(image_info,option+1,argv[i+1]);
6604 break;
6605 }
6606 break;
6607 }
6608 case 'l':
6609 {
6610 if (LocaleCompare("label",option+1) == 0)
6611 {
6612 if (*option == '+')
6613 {
6614 (void) DeleteImageOption(image_info,option+1);
6615 break;
6616 }
6617 (void) SetImageOption(image_info,option+1,argv[i+1]);
6618 break;
6619 }
6620 if (LocaleCompare("limit",option+1) == 0)
6621 {
6622 MagickSizeType
6623 limit;
6624
6625 ResourceType
6626 type;
6627
6628 if (*option == '+')
6629 break;
cristy042ee782011-04-22 18:48:30 +00006630 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006631 MagickFalse,argv[i+1]);
6632 limit=MagickResourceInfinity;
6633 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006634 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006635 (void) SetMagickResourceLimit(type,limit);
6636 break;
6637 }
6638 if (LocaleCompare("list",option+1) == 0)
6639 {
cristybb503372010-05-27 20:51:26 +00006640 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006641 list;
6642
6643 /*
6644 Display configuration list.
6645 */
cristy042ee782011-04-22 18:48:30 +00006646 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006647 switch (list)
6648 {
6649 case MagickCoderOptions:
6650 {
6651 (void) ListCoderInfo((FILE *) NULL,exception);
6652 break;
6653 }
6654 case MagickColorOptions:
6655 {
6656 (void) ListColorInfo((FILE *) NULL,exception);
6657 break;
6658 }
6659 case MagickConfigureOptions:
6660 {
6661 (void) ListConfigureInfo((FILE *) NULL,exception);
6662 break;
6663 }
6664 case MagickDelegateOptions:
6665 {
6666 (void) ListDelegateInfo((FILE *) NULL,exception);
6667 break;
6668 }
6669 case MagickFontOptions:
6670 {
6671 (void) ListTypeInfo((FILE *) NULL,exception);
6672 break;
6673 }
6674 case MagickFormatOptions:
6675 {
6676 (void) ListMagickInfo((FILE *) NULL,exception);
6677 break;
6678 }
6679 case MagickLocaleOptions:
6680 {
6681 (void) ListLocaleInfo((FILE *) NULL,exception);
6682 break;
6683 }
6684 case MagickLogOptions:
6685 {
6686 (void) ListLogInfo((FILE *) NULL,exception);
6687 break;
6688 }
6689 case MagickMagicOptions:
6690 {
6691 (void) ListMagicInfo((FILE *) NULL,exception);
6692 break;
6693 }
6694 case MagickMimeOptions:
6695 {
6696 (void) ListMimeInfo((FILE *) NULL,exception);
6697 break;
6698 }
6699 case MagickModuleOptions:
6700 {
6701 (void) ListModuleInfo((FILE *) NULL,exception);
6702 break;
6703 }
6704 case MagickPolicyOptions:
6705 {
6706 (void) ListPolicyInfo((FILE *) NULL,exception);
6707 break;
6708 }
6709 case MagickResourceOptions:
6710 {
6711 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6712 break;
6713 }
6714 case MagickThresholdOptions:
6715 {
6716 (void) ListThresholdMaps((FILE *) NULL,exception);
6717 break;
6718 }
6719 default:
6720 {
cristy042ee782011-04-22 18:48:30 +00006721 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006722 exception);
6723 break;
6724 }
6725 }
cristyaeb2cbc2010-05-07 13:28:58 +00006726 break;
cristy3ed852e2009-09-05 21:47:34 +00006727 }
6728 if (LocaleCompare("log",option+1) == 0)
6729 {
6730 if (*option == '+')
6731 break;
6732 (void) SetLogFormat(argv[i+1]);
6733 break;
6734 }
6735 if (LocaleCompare("loop",option+1) == 0)
6736 {
6737 if (*option == '+')
6738 {
6739 (void) SetImageOption(image_info,option+1,"0");
6740 break;
6741 }
6742 (void) SetImageOption(image_info,option+1,argv[i+1]);
6743 break;
6744 }
6745 break;
6746 }
6747 case 'm':
6748 {
6749 if (LocaleCompare("matte",option+1) == 0)
6750 {
6751 if (*option == '+')
6752 {
6753 (void) SetImageOption(image_info,option+1,"false");
6754 break;
6755 }
6756 (void) SetImageOption(image_info,option+1,"true");
6757 break;
6758 }
6759 if (LocaleCompare("mattecolor",option+1) == 0)
6760 {
6761 if (*option == '+')
6762 {
6763 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006764 (void) QueryColorDatabase(MogrifyMatteColor,
6765 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006766 break;
6767 }
6768 (void) SetImageOption(image_info,option+1,argv[i+1]);
6769 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6770 exception);
6771 break;
6772 }
6773 if (LocaleCompare("monitor",option+1) == 0)
6774 {
6775 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6776 (void *) NULL);
6777 break;
6778 }
6779 if (LocaleCompare("monochrome",option+1) == 0)
6780 {
6781 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6782 break;
6783 }
6784 break;
6785 }
6786 case 'o':
6787 {
6788 if (LocaleCompare("orient",option+1) == 0)
6789 {
6790 if (*option == '+')
6791 {
6792 image_info->orientation=UndefinedOrientation;
6793 (void) SetImageOption(image_info,option+1,"undefined");
6794 break;
6795 }
cristy042ee782011-04-22 18:48:30 +00006796 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006797 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006798 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006799 break;
6800 }
6801 }
6802 case 'p':
6803 {
6804 if (LocaleCompare("page",option+1) == 0)
6805 {
6806 char
6807 *canonical_page,
6808 page[MaxTextExtent];
6809
6810 const char
6811 *image_option;
6812
6813 MagickStatusType
6814 flags;
6815
6816 RectangleInfo
6817 geometry;
6818
6819 if (*option == '+')
6820 {
6821 (void) DeleteImageOption(image_info,option+1);
6822 (void) CloneString(&image_info->page,(char *) NULL);
6823 break;
6824 }
6825 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6826 image_option=GetImageOption(image_info,"page");
6827 if (image_option != (const char *) NULL)
6828 flags=ParseAbsoluteGeometry(image_option,&geometry);
6829 canonical_page=GetPageGeometry(argv[i+1]);
6830 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6831 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006832 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006833 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006834 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006835 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006836 (unsigned long) geometry.width,(unsigned long) geometry.height,
6837 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006838 (void) SetImageOption(image_info,option+1,page);
6839 (void) CloneString(&image_info->page,page);
6840 break;
6841 }
6842 if (LocaleCompare("pen",option+1) == 0)
6843 {
6844 if (*option == '+')
6845 {
6846 (void) SetImageOption(image_info,option+1,"none");
6847 break;
6848 }
6849 (void) SetImageOption(image_info,option+1,argv[i+1]);
6850 break;
6851 }
6852 if (LocaleCompare("ping",option+1) == 0)
6853 {
6854 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6855 break;
6856 }
6857 if (LocaleCompare("pointsize",option+1) == 0)
6858 {
6859 if (*option == '+')
6860 geometry_info.rho=0.0;
6861 else
6862 (void) ParseGeometry(argv[i+1],&geometry_info);
6863 image_info->pointsize=geometry_info.rho;
6864 break;
6865 }
cristye7f51092010-01-17 00:39:37 +00006866 if (LocaleCompare("precision",option+1) == 0)
6867 {
cristybf2766a2010-01-17 03:33:23 +00006868 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006869 break;
6870 }
cristy3ed852e2009-09-05 21:47:34 +00006871 if (LocaleCompare("preview",option+1) == 0)
6872 {
6873 /*
6874 Preview image.
6875 */
6876 if (*option == '+')
6877 {
6878 image_info->preview_type=UndefinedPreview;
6879 break;
6880 }
cristy042ee782011-04-22 18:48:30 +00006881 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006882 MagickPreviewOptions,MagickFalse,argv[i+1]);
6883 break;
6884 }
6885 break;
6886 }
6887 case 'q':
6888 {
6889 if (LocaleCompare("quality",option+1) == 0)
6890 {
6891 /*
6892 Set image compression quality.
6893 */
6894 if (*option == '+')
6895 {
6896 image_info->quality=UndefinedCompressionQuality;
6897 (void) SetImageOption(image_info,option+1,"0");
6898 break;
6899 }
cristye27293e2009-12-18 02:53:20 +00006900 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006901 (void) SetImageOption(image_info,option+1,argv[i+1]);
6902 break;
6903 }
6904 if (LocaleCompare("quiet",option+1) == 0)
6905 {
6906 static WarningHandler
6907 warning_handler = (WarningHandler) NULL;
6908
6909 if (*option == '+')
6910 {
6911 /*
6912 Restore error or warning messages.
6913 */
6914 warning_handler=SetWarningHandler(warning_handler);
6915 break;
6916 }
6917 /*
6918 Suppress error or warning messages.
6919 */
6920 warning_handler=SetWarningHandler((WarningHandler) NULL);
6921 break;
6922 }
6923 break;
6924 }
6925 case 'r':
6926 {
6927 if (LocaleCompare("red-primary",option+1) == 0)
6928 {
6929 if (*option == '+')
6930 {
6931 (void) SetImageOption(image_info,option+1,"0.0");
6932 break;
6933 }
6934 (void) SetImageOption(image_info,option+1,argv[i+1]);
6935 break;
6936 }
6937 break;
6938 }
6939 case 's':
6940 {
6941 if (LocaleCompare("sampling-factor",option+1) == 0)
6942 {
6943 /*
6944 Set image sampling factor.
6945 */
6946 if (*option == '+')
6947 {
6948 if (image_info->sampling_factor != (char *) NULL)
6949 image_info->sampling_factor=DestroyString(
6950 image_info->sampling_factor);
6951 break;
6952 }
6953 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6954 break;
6955 }
6956 if (LocaleCompare("scene",option+1) == 0)
6957 {
6958 /*
6959 Set image scene.
6960 */
6961 if (*option == '+')
6962 {
6963 image_info->scene=0;
6964 (void) SetImageOption(image_info,option+1,"0");
6965 break;
6966 }
cristye27293e2009-12-18 02:53:20 +00006967 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006968 (void) SetImageOption(image_info,option+1,argv[i+1]);
6969 break;
6970 }
6971 if (LocaleCompare("seed",option+1) == 0)
6972 {
cristybb503372010-05-27 20:51:26 +00006973 size_t
cristy3ed852e2009-09-05 21:47:34 +00006974 seed;
6975
6976 if (*option == '+')
6977 {
cristybb503372010-05-27 20:51:26 +00006978 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006979 SeedPseudoRandomGenerator(seed);
6980 break;
6981 }
cristye27293e2009-12-18 02:53:20 +00006982 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006983 SeedPseudoRandomGenerator(seed);
6984 break;
6985 }
6986 if (LocaleCompare("size",option+1) == 0)
6987 {
6988 if (*option == '+')
6989 {
6990 if (image_info->size != (char *) NULL)
6991 image_info->size=DestroyString(image_info->size);
6992 break;
6993 }
6994 (void) CloneString(&image_info->size,argv[i+1]);
6995 break;
6996 }
6997 if (LocaleCompare("stroke",option+1) == 0)
6998 {
6999 if (*option == '+')
7000 {
7001 (void) SetImageOption(image_info,option+1,"none");
7002 break;
7003 }
7004 (void) SetImageOption(image_info,option+1,argv[i+1]);
7005 break;
7006 }
7007 if (LocaleCompare("strokewidth",option+1) == 0)
7008 {
7009 if (*option == '+')
7010 {
7011 (void) SetImageOption(image_info,option+1,"0");
7012 break;
7013 }
7014 (void) SetImageOption(image_info,option+1,argv[i+1]);
7015 break;
7016 }
cristyd9a29192010-10-16 16:49:53 +00007017 if (LocaleCompare("synchronize",option+1) == 0)
7018 {
7019 if (*option == '+')
7020 {
7021 image_info->synchronize=MagickFalse;
7022 break;
7023 }
7024 image_info->synchronize=MagickTrue;
7025 break;
7026 }
cristy3ed852e2009-09-05 21:47:34 +00007027 break;
7028 }
7029 case 't':
7030 {
7031 if (LocaleCompare("taint",option+1) == 0)
7032 {
7033 if (*option == '+')
7034 {
7035 (void) SetImageOption(image_info,option+1,"false");
7036 break;
7037 }
7038 (void) SetImageOption(image_info,option+1,"true");
7039 break;
7040 }
7041 if (LocaleCompare("texture",option+1) == 0)
7042 {
7043 if (*option == '+')
7044 {
7045 if (image_info->texture != (char *) NULL)
7046 image_info->texture=DestroyString(image_info->texture);
7047 break;
7048 }
7049 (void) CloneString(&image_info->texture,argv[i+1]);
7050 break;
7051 }
7052 if (LocaleCompare("tile-offset",option+1) == 0)
7053 {
7054 if (*option == '+')
7055 {
7056 (void) SetImageOption(image_info,option+1,"0");
7057 break;
7058 }
7059 (void) SetImageOption(image_info,option+1,argv[i+1]);
7060 break;
7061 }
7062 if (LocaleCompare("transparent-color",option+1) == 0)
7063 {
7064 if (*option == '+')
7065 {
7066 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7067 (void) SetImageOption(image_info,option+1,"none");
7068 break;
7069 }
7070 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7071 exception);
7072 (void) SetImageOption(image_info,option+1,argv[i+1]);
7073 break;
7074 }
7075 if (LocaleCompare("type",option+1) == 0)
7076 {
7077 if (*option == '+')
7078 {
cristy5f1c1ff2010-12-23 21:38:06 +00007079 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007080 (void) SetImageOption(image_info,option+1,"undefined");
7081 break;
7082 }
cristy042ee782011-04-22 18:48:30 +00007083 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007084 MagickFalse,argv[i+1]);
7085 (void) SetImageOption(image_info,option+1,argv[i+1]);
7086 break;
7087 }
7088 break;
7089 }
7090 case 'u':
7091 {
7092 if (LocaleCompare("undercolor",option+1) == 0)
7093 {
7094 if (*option == '+')
7095 {
7096 (void) DeleteImageOption(image_info,option+1);
7097 break;
7098 }
7099 (void) SetImageOption(image_info,option+1,argv[i+1]);
7100 break;
7101 }
7102 if (LocaleCompare("units",option+1) == 0)
7103 {
7104 if (*option == '+')
7105 {
7106 image_info->units=UndefinedResolution;
7107 (void) SetImageOption(image_info,option+1,"undefined");
7108 break;
7109 }
cristy042ee782011-04-22 18:48:30 +00007110 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007111 MagickResolutionOptions,MagickFalse,argv[i+1]);
7112 (void) SetImageOption(image_info,option+1,argv[i+1]);
7113 break;
7114 }
7115 break;
7116 }
7117 case 'v':
7118 {
7119 if (LocaleCompare("verbose",option+1) == 0)
7120 {
7121 if (*option == '+')
7122 {
7123 image_info->verbose=MagickFalse;
7124 break;
7125 }
7126 image_info->verbose=MagickTrue;
7127 image_info->ping=MagickFalse;
7128 break;
7129 }
7130 if (LocaleCompare("view",option+1) == 0)
7131 {
7132 if (*option == '+')
7133 {
7134 if (image_info->view != (char *) NULL)
7135 image_info->view=DestroyString(image_info->view);
7136 break;
7137 }
7138 (void) CloneString(&image_info->view,argv[i+1]);
7139 break;
7140 }
7141 if (LocaleCompare("virtual-pixel",option+1) == 0)
7142 {
7143 if (*option == '+')
7144 {
7145 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7146 (void) SetImageOption(image_info,option+1,"undefined");
7147 break;
7148 }
7149 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007150 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007151 argv[i+1]);
7152 (void) SetImageOption(image_info,option+1,argv[i+1]);
7153 break;
7154 }
7155 break;
7156 }
7157 case 'w':
7158 {
7159 if (LocaleCompare("white-point",option+1) == 0)
7160 {
7161 if (*option == '+')
7162 {
7163 (void) SetImageOption(image_info,option+1,"0.0");
7164 break;
7165 }
7166 (void) SetImageOption(image_info,option+1,argv[i+1]);
7167 break;
7168 }
7169 break;
7170 }
7171 default:
7172 break;
7173 }
7174 i+=count;
7175 }
7176 return(MagickTrue);
7177}
7178
7179/*
7180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7181% %
7182% %
7183% %
7184+ M o g r i f y I m a g e L i s t %
7185% %
7186% %
7187% %
7188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7189%
7190% MogrifyImageList() applies any command line options that might affect the
7191% entire image list (e.g. -append, -coalesce, etc.).
7192%
7193% The format of the MogrifyImage method is:
7194%
7195% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7196% const char **argv,Image **images,ExceptionInfo *exception)
7197%
7198% A description of each parameter follows:
7199%
7200% o image_info: the image info..
7201%
7202% o argc: Specifies a pointer to an integer describing the number of
7203% elements in the argument vector.
7204%
7205% o argv: Specifies a pointer to a text array containing the command line
7206% arguments.
7207%
anthonye9c27192011-03-27 08:07:06 +00007208% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007209%
7210% o exception: return any errors or warnings in this structure.
7211%
7212*/
7213WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7214 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7215{
cristy3ed852e2009-09-05 21:47:34 +00007216 const char
7217 *option;
7218
cristy6b3da3a2010-06-20 02:21:46 +00007219 ImageInfo
7220 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007221
7222 MagickStatusType
7223 status;
7224
7225 QuantizeInfo
7226 *quantize_info;
7227
cristybb503372010-05-27 20:51:26 +00007228 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007229 i;
7230
cristy6b3da3a2010-06-20 02:21:46 +00007231 ssize_t
7232 count,
7233 index;
7234
cristy3ed852e2009-09-05 21:47:34 +00007235 /*
7236 Apply options to the image list.
7237 */
7238 assert(image_info != (ImageInfo *) NULL);
7239 assert(image_info->signature == MagickSignature);
7240 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007241 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007242 assert((*images)->signature == MagickSignature);
7243 if ((*images)->debug != MagickFalse)
7244 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7245 (*images)->filename);
7246 if ((argc <= 0) || (*argv == (char *) NULL))
7247 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007248 mogrify_info=CloneImageInfo(image_info);
7249 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007250 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007251 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007252 {
cristy74fe8f12009-10-03 19:09:01 +00007253 if (*images == (Image *) NULL)
7254 break;
cristy3ed852e2009-09-05 21:47:34 +00007255 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007256 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007257 continue;
cristy042ee782011-04-22 18:48:30 +00007258 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007259 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007260 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007261 break;
cristy6b3da3a2010-06-20 02:21:46 +00007262 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007263 switch (*(option+1))
7264 {
7265 case 'a':
7266 {
7267 if (LocaleCompare("affinity",option+1) == 0)
7268 {
cristy6b3da3a2010-06-20 02:21:46 +00007269 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007270 if (*option == '+')
7271 {
cristy018f07f2011-09-04 21:15:19 +00007272 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7273 exception);
cristy3ed852e2009-09-05 21:47:34 +00007274 break;
7275 }
7276 i++;
7277 break;
7278 }
7279 if (LocaleCompare("append",option+1) == 0)
7280 {
7281 Image
7282 *append_image;
7283
cristy6b3da3a2010-06-20 02:21:46 +00007284 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007285 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7286 MagickFalse,exception);
7287 if (append_image == (Image *) NULL)
7288 {
7289 status=MagickFalse;
7290 break;
7291 }
7292 *images=DestroyImageList(*images);
7293 *images=append_image;
7294 break;
7295 }
7296 if (LocaleCompare("average",option+1) == 0)
7297 {
7298 Image
7299 *average_image;
7300
cristyd18ae7c2010-03-07 17:39:52 +00007301 /*
7302 Average an image sequence (deprecated).
7303 */
cristy6b3da3a2010-06-20 02:21:46 +00007304 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007305 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7306 exception);
cristy3ed852e2009-09-05 21:47:34 +00007307 if (average_image == (Image *) NULL)
7308 {
7309 status=MagickFalse;
7310 break;
7311 }
7312 *images=DestroyImageList(*images);
7313 *images=average_image;
7314 break;
7315 }
7316 break;
7317 }
7318 case 'c':
7319 {
7320 if (LocaleCompare("channel",option+1) == 0)
7321 {
cristyf4ad9df2011-07-08 16:49:03 +00007322 ChannelType
7323 channel;
7324
cristy3ed852e2009-09-05 21:47:34 +00007325 if (*option == '+')
7326 {
7327 channel=DefaultChannels;
7328 break;
7329 }
7330 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007331 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007332 break;
7333 }
7334 if (LocaleCompare("clut",option+1) == 0)
7335 {
7336 Image
7337 *clut_image,
7338 *image;
7339
cristy6b3da3a2010-06-20 02:21:46 +00007340 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007341 image=RemoveFirstImageFromList(images);
7342 clut_image=RemoveFirstImageFromList(images);
7343 if (clut_image == (Image *) NULL)
7344 {
7345 status=MagickFalse;
7346 break;
7347 }
cristy444eda62011-08-10 02:07:46 +00007348 (void) ClutImage(image,clut_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007349 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007350 *images=DestroyImageList(*images);
7351 *images=image;
7352 break;
7353 }
7354 if (LocaleCompare("coalesce",option+1) == 0)
7355 {
7356 Image
7357 *coalesce_image;
7358
cristy6b3da3a2010-06-20 02:21:46 +00007359 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007360 coalesce_image=CoalesceImages(*images,exception);
7361 if (coalesce_image == (Image *) NULL)
7362 {
7363 status=MagickFalse;
7364 break;
7365 }
7366 *images=DestroyImageList(*images);
7367 *images=coalesce_image;
7368 break;
7369 }
7370 if (LocaleCompare("combine",option+1) == 0)
7371 {
7372 Image
7373 *combine_image;
7374
cristy6b3da3a2010-06-20 02:21:46 +00007375 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007376 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007377 if (combine_image == (Image *) NULL)
7378 {
7379 status=MagickFalse;
7380 break;
7381 }
7382 *images=DestroyImageList(*images);
7383 *images=combine_image;
7384 break;
7385 }
7386 if (LocaleCompare("composite",option+1) == 0)
7387 {
7388 Image
7389 *mask_image,
7390 *composite_image,
7391 *image;
7392
7393 RectangleInfo
7394 geometry;
7395
cristy6b3da3a2010-06-20 02:21:46 +00007396 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007397 image=RemoveFirstImageFromList(images);
7398 composite_image=RemoveFirstImageFromList(images);
7399 if (composite_image == (Image *) NULL)
7400 {
7401 status=MagickFalse;
7402 break;
7403 }
7404 (void) TransformImage(&composite_image,(char *) NULL,
7405 composite_image->geometry);
7406 SetGeometry(composite_image,&geometry);
7407 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7408 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7409 &geometry);
7410 mask_image=RemoveFirstImageFromList(images);
7411 if (mask_image != (Image *) NULL)
7412 {
7413 if ((image->compose == DisplaceCompositeOp) ||
7414 (image->compose == DistortCompositeOp))
7415 {
7416 /*
7417 Merge Y displacement into X displacement image.
7418 */
7419 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7420 mask_image,0,0);
7421 mask_image=DestroyImage(mask_image);
7422 }
7423 else
7424 {
7425 /*
7426 Set a blending mask for the composition.
7427 */
anthonya129f702011-04-14 01:08:48 +00007428 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007429 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007430 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007431 }
7432 }
cristyf4ad9df2011-07-08 16:49:03 +00007433 (void) CompositeImage(image,image->compose,composite_image,
7434 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007435 if (mask_image != (Image *) NULL)
7436 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007437 composite_image=DestroyImage(composite_image);
7438 InheritException(exception,&image->exception);
7439 *images=DestroyImageList(*images);
7440 *images=image;
7441 break;
7442 }
anthony9f4f0342011-03-28 11:47:22 +00007443#if 0
7444This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007445 if (LocaleCompare("crop",option+1) == 0)
7446 {
7447 MagickStatusType
7448 flags;
7449
7450 RectangleInfo
7451 geometry;
7452
anthonye9c27192011-03-27 08:07:06 +00007453 /*
anthony9f4f0342011-03-28 11:47:22 +00007454 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007455 */
cristy6b3da3a2010-06-20 02:21:46 +00007456 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007457 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7458 if (((geometry.width == 0) && (geometry.height == 0)) ||
7459 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7460 break;
7461 (void) TransformImages(images,argv[i+1],(char *) NULL);
7462 InheritException(exception,&(*images)->exception);
7463 break;
7464 }
anthony9f4f0342011-03-28 11:47:22 +00007465#endif
cristy3ed852e2009-09-05 21:47:34 +00007466 break;
7467 }
7468 case 'd':
7469 {
7470 if (LocaleCompare("deconstruct",option+1) == 0)
7471 {
7472 Image
7473 *deconstruct_image;
7474
cristy6b3da3a2010-06-20 02:21:46 +00007475 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007476 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007477 exception);
cristy3ed852e2009-09-05 21:47:34 +00007478 if (deconstruct_image == (Image *) NULL)
7479 {
7480 status=MagickFalse;
7481 break;
7482 }
7483 *images=DestroyImageList(*images);
7484 *images=deconstruct_image;
7485 break;
7486 }
7487 if (LocaleCompare("delete",option+1) == 0)
7488 {
7489 if (*option == '+')
7490 DeleteImages(images,"-1",exception);
7491 else
7492 DeleteImages(images,argv[i+1],exception);
7493 break;
7494 }
7495 if (LocaleCompare("dither",option+1) == 0)
7496 {
7497 if (*option == '+')
7498 {
7499 quantize_info->dither=MagickFalse;
7500 break;
7501 }
7502 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007503 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007504 MagickDitherOptions,MagickFalse,argv[i+1]);
7505 break;
7506 }
cristyecb10ff2011-03-22 13:14:03 +00007507 if (LocaleCompare("duplicate",option+1) == 0)
7508 {
cristy72988482011-03-29 16:34:38 +00007509 Image
7510 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007511
anthony2b6bcae2011-03-23 13:05:34 +00007512 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007513 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7514 else
7515 {
7516 const char
7517 *p;
7518
anthony2b6bcae2011-03-23 13:05:34 +00007519 size_t
7520 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007521
anthony2b6bcae2011-03-23 13:05:34 +00007522 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007523 p=strchr(argv[i+1],',');
7524 if (p == (const char *) NULL)
7525 duplicate_images=DuplicateImages(*images,number_duplicates,
7526 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007527 else
cristy72988482011-03-29 16:34:38 +00007528 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7529 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007530 }
7531 AppendImageToList(images, duplicate_images);
7532 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007533 break;
7534 }
cristy3ed852e2009-09-05 21:47:34 +00007535 break;
7536 }
cristyd18ae7c2010-03-07 17:39:52 +00007537 case 'e':
7538 {
7539 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7540 {
7541 Image
7542 *evaluate_image;
7543
7544 MagickEvaluateOperator
7545 op;
7546
cristy6b3da3a2010-06-20 02:21:46 +00007547 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007548 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007549 MagickFalse,argv[i+1]);
7550 evaluate_image=EvaluateImages(*images,op,exception);
7551 if (evaluate_image == (Image *) NULL)
7552 {
7553 status=MagickFalse;
7554 break;
7555 }
7556 *images=DestroyImageList(*images);
7557 *images=evaluate_image;
7558 break;
7559 }
7560 break;
7561 }
cristy3ed852e2009-09-05 21:47:34 +00007562 case 'f':
7563 {
cristyf0a247f2009-10-04 00:20:03 +00007564 if (LocaleCompare("fft",option+1) == 0)
7565 {
7566 Image
7567 *fourier_image;
7568
7569 /*
7570 Implements the discrete Fourier transform (DFT).
7571 */
cristy6b3da3a2010-06-20 02:21:46 +00007572 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007573 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7574 MagickTrue : MagickFalse,exception);
7575 if (fourier_image == (Image *) NULL)
7576 break;
7577 *images=DestroyImage(*images);
7578 *images=fourier_image;
7579 break;
7580 }
cristy3ed852e2009-09-05 21:47:34 +00007581 if (LocaleCompare("flatten",option+1) == 0)
7582 {
7583 Image
7584 *flatten_image;
7585
cristy6b3da3a2010-06-20 02:21:46 +00007586 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007587 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7588 if (flatten_image == (Image *) NULL)
7589 break;
7590 *images=DestroyImageList(*images);
7591 *images=flatten_image;
7592 break;
7593 }
7594 if (LocaleCompare("fx",option+1) == 0)
7595 {
7596 Image
7597 *fx_image;
7598
cristy6b3da3a2010-06-20 02:21:46 +00007599 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007600 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007601 if (fx_image == (Image *) NULL)
7602 {
7603 status=MagickFalse;
7604 break;
7605 }
7606 *images=DestroyImageList(*images);
7607 *images=fx_image;
7608 break;
7609 }
7610 break;
7611 }
7612 case 'h':
7613 {
7614 if (LocaleCompare("hald-clut",option+1) == 0)
7615 {
7616 Image
7617 *hald_image,
7618 *image;
7619
cristy6b3da3a2010-06-20 02:21:46 +00007620 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007621 image=RemoveFirstImageFromList(images);
7622 hald_image=RemoveFirstImageFromList(images);
7623 if (hald_image == (Image *) NULL)
7624 {
7625 status=MagickFalse;
7626 break;
7627 }
cristy7c0a0a42011-08-23 17:57:25 +00007628 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007629 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007630 if (*images != (Image *) NULL)
7631 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007632 *images=image;
7633 break;
7634 }
7635 break;
7636 }
7637 case 'i':
7638 {
7639 if (LocaleCompare("ift",option+1) == 0)
7640 {
7641 Image
cristy8587f882009-11-13 20:28:49 +00007642 *fourier_image,
7643 *magnitude_image,
7644 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007645
7646 /*
7647 Implements the inverse fourier discrete Fourier transform (DFT).
7648 */
cristy6b3da3a2010-06-20 02:21:46 +00007649 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007650 magnitude_image=RemoveFirstImageFromList(images);
7651 phase_image=RemoveFirstImageFromList(images);
7652 if (phase_image == (Image *) NULL)
7653 {
7654 status=MagickFalse;
7655 break;
7656 }
7657 fourier_image=InverseFourierTransformImage(magnitude_image,
7658 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007659 if (fourier_image == (Image *) NULL)
7660 break;
cristy0aff6ea2009-11-14 01:40:53 +00007661 if (*images != (Image *) NULL)
7662 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007663 *images=fourier_image;
7664 break;
7665 }
7666 if (LocaleCompare("insert",option+1) == 0)
7667 {
7668 Image
7669 *p,
7670 *q;
7671
7672 index=0;
7673 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007674 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007675 p=RemoveLastImageFromList(images);
7676 if (p == (Image *) NULL)
7677 {
7678 (void) ThrowMagickException(exception,GetMagickModule(),
7679 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7680 status=MagickFalse;
7681 break;
7682 }
7683 q=p;
7684 if (index == 0)
7685 PrependImageToList(images,q);
7686 else
cristybb503372010-05-27 20:51:26 +00007687 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007688 AppendImageToList(images,q);
7689 else
7690 {
7691 q=GetImageFromList(*images,index-1);
7692 if (q == (Image *) NULL)
7693 {
7694 (void) ThrowMagickException(exception,GetMagickModule(),
7695 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7696 status=MagickFalse;
7697 break;
7698 }
7699 InsertImageInList(&q,p);
7700 }
7701 *images=GetFirstImageInList(q);
7702 break;
7703 }
7704 break;
7705 }
7706 case 'l':
7707 {
7708 if (LocaleCompare("layers",option+1) == 0)
7709 {
7710 Image
7711 *layers;
7712
7713 ImageLayerMethod
7714 method;
7715
cristy6b3da3a2010-06-20 02:21:46 +00007716 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007717 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007718 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007719 MagickFalse,argv[i+1]);
7720 switch (method)
7721 {
7722 case CoalesceLayer:
7723 {
7724 layers=CoalesceImages(*images,exception);
7725 break;
7726 }
7727 case CompareAnyLayer:
7728 case CompareClearLayer:
7729 case CompareOverlayLayer:
7730 default:
7731 {
cristy8a9106f2011-07-05 14:39:26 +00007732 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007733 break;
7734 }
7735 case MergeLayer:
7736 case FlattenLayer:
7737 case MosaicLayer:
7738 case TrimBoundsLayer:
7739 {
7740 layers=MergeImageLayers(*images,method,exception);
7741 break;
7742 }
7743 case DisposeLayer:
7744 {
7745 layers=DisposeImages(*images,exception);
7746 break;
7747 }
7748 case OptimizeImageLayer:
7749 {
7750 layers=OptimizeImageLayers(*images,exception);
7751 break;
7752 }
7753 case OptimizePlusLayer:
7754 {
7755 layers=OptimizePlusImageLayers(*images,exception);
7756 break;
7757 }
7758 case OptimizeTransLayer:
7759 {
7760 OptimizeImageTransparency(*images,exception);
7761 break;
7762 }
7763 case RemoveDupsLayer:
7764 {
7765 RemoveDuplicateLayers(images,exception);
7766 break;
7767 }
7768 case RemoveZeroLayer:
7769 {
7770 RemoveZeroDelayLayers(images,exception);
7771 break;
7772 }
7773 case OptimizeLayer:
7774 {
7775 /*
7776 General Purpose, GIF Animation Optimizer.
7777 */
7778 layers=CoalesceImages(*images,exception);
7779 if (layers == (Image *) NULL)
7780 {
7781 status=MagickFalse;
7782 break;
7783 }
cristy3ed852e2009-09-05 21:47:34 +00007784 *images=DestroyImageList(*images);
7785 *images=layers;
7786 layers=OptimizeImageLayers(*images,exception);
7787 if (layers == (Image *) NULL)
7788 {
7789 status=MagickFalse;
7790 break;
7791 }
cristy3ed852e2009-09-05 21:47:34 +00007792 *images=DestroyImageList(*images);
7793 *images=layers;
7794 layers=(Image *) NULL;
7795 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007796 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7797 exception);
cristy3ed852e2009-09-05 21:47:34 +00007798 break;
7799 }
7800 case CompositeLayer:
7801 {
7802 CompositeOperator
7803 compose;
7804
7805 Image
7806 *source;
7807
7808 RectangleInfo
7809 geometry;
7810
7811 /*
7812 Split image sequence at the first 'NULL:' image.
7813 */
7814 source=(*images);
7815 while (source != (Image *) NULL)
7816 {
7817 source=GetNextImageInList(source);
7818 if ((source != (Image *) NULL) &&
7819 (LocaleCompare(source->magick,"NULL") == 0))
7820 break;
7821 }
7822 if (source != (Image *) NULL)
7823 {
7824 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7825 (GetNextImageInList(source) == (Image *) NULL))
7826 source=(Image *) NULL;
7827 else
7828 {
7829 /*
7830 Separate the two lists, junk the null: image.
7831 */
7832 source=SplitImageList(source->previous);
7833 DeleteImageFromList(&source);
7834 }
7835 }
7836 if (source == (Image *) NULL)
7837 {
7838 (void) ThrowMagickException(exception,GetMagickModule(),
7839 OptionError,"MissingNullSeparator","layers Composite");
7840 status=MagickFalse;
7841 break;
7842 }
7843 /*
7844 Adjust offset with gravity and virtual canvas.
7845 */
7846 SetGeometry(*images,&geometry);
7847 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7848 geometry.width=source->page.width != 0 ?
7849 source->page.width : source->columns;
7850 geometry.height=source->page.height != 0 ?
7851 source->page.height : source->rows;
7852 GravityAdjustGeometry((*images)->page.width != 0 ?
7853 (*images)->page.width : (*images)->columns,
7854 (*images)->page.height != 0 ? (*images)->page.height :
7855 (*images)->rows,(*images)->gravity,&geometry);
7856 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007857 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007858 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007859 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007860 MagickComposeOptions,MagickFalse,option);
7861 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7862 exception);
7863 source=DestroyImageList(source);
7864 break;
7865 }
7866 }
7867 if (layers == (Image *) NULL)
7868 break;
7869 InheritException(exception,&layers->exception);
7870 *images=DestroyImageList(*images);
7871 *images=layers;
7872 break;
7873 }
7874 break;
7875 }
7876 case 'm':
7877 {
7878 if (LocaleCompare("map",option+1) == 0)
7879 {
cristy6b3da3a2010-06-20 02:21:46 +00007880 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007881 if (*option == '+')
7882 {
cristy018f07f2011-09-04 21:15:19 +00007883 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7884 exception);
cristy3ed852e2009-09-05 21:47:34 +00007885 break;
7886 }
7887 i++;
7888 break;
7889 }
cristyf40785b2010-03-06 02:27:27 +00007890 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007891 {
7892 Image
cristyf40785b2010-03-06 02:27:27 +00007893 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007894
cristyd18ae7c2010-03-07 17:39:52 +00007895 /*
7896 Maximum image sequence (deprecated).
7897 */
cristy6b3da3a2010-06-20 02:21:46 +00007898 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007899 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007900 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007901 {
7902 status=MagickFalse;
7903 break;
7904 }
7905 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007906 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007907 break;
7908 }
cristyf40785b2010-03-06 02:27:27 +00007909 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007910 {
7911 Image
cristyf40785b2010-03-06 02:27:27 +00007912 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007913
cristyd18ae7c2010-03-07 17:39:52 +00007914 /*
7915 Minimum image sequence (deprecated).
7916 */
cristy6b3da3a2010-06-20 02:21:46 +00007917 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007918 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007919 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007920 {
7921 status=MagickFalse;
7922 break;
7923 }
7924 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007925 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007926 break;
7927 }
cristy3ed852e2009-09-05 21:47:34 +00007928 if (LocaleCompare("morph",option+1) == 0)
7929 {
7930 Image
7931 *morph_image;
7932
cristy6b3da3a2010-06-20 02:21:46 +00007933 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007934 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007935 exception);
7936 if (morph_image == (Image *) NULL)
7937 {
7938 status=MagickFalse;
7939 break;
7940 }
7941 *images=DestroyImageList(*images);
7942 *images=morph_image;
7943 break;
7944 }
7945 if (LocaleCompare("mosaic",option+1) == 0)
7946 {
7947 Image
7948 *mosaic_image;
7949
cristy6b3da3a2010-06-20 02:21:46 +00007950 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007951 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7952 if (mosaic_image == (Image *) NULL)
7953 {
7954 status=MagickFalse;
7955 break;
7956 }
7957 *images=DestroyImageList(*images);
7958 *images=mosaic_image;
7959 break;
7960 }
7961 break;
7962 }
7963 case 'p':
7964 {
7965 if (LocaleCompare("print",option+1) == 0)
7966 {
7967 char
7968 *string;
7969
cristy6b3da3a2010-06-20 02:21:46 +00007970 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007971 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7972 exception);
cristy3ed852e2009-09-05 21:47:34 +00007973 if (string == (char *) NULL)
7974 break;
cristyb51dff52011-05-19 16:55:47 +00007975 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007976 string=DestroyString(string);
7977 }
7978 if (LocaleCompare("process",option+1) == 0)
7979 {
7980 char
7981 **arguments;
7982
7983 int
7984 j,
7985 number_arguments;
7986
cristy6b3da3a2010-06-20 02:21:46 +00007987 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007988 arguments=StringToArgv(argv[i+1],&number_arguments);
7989 if (arguments == (char **) NULL)
7990 break;
7991 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7992 {
7993 char
7994 breaker,
7995 quote,
7996 *token;
7997
7998 const char
7999 *arguments;
8000
8001 int
8002 next,
8003 status;
8004
8005 size_t
8006 length;
8007
8008 TokenInfo
8009 *token_info;
8010
8011 /*
8012 Support old style syntax, filter="-option arg".
8013 */
8014 length=strlen(argv[i+1]);
8015 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008016 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008017 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8018 sizeof(*token));
8019 if (token == (char *) NULL)
8020 break;
8021 next=0;
8022 arguments=argv[i+1];
8023 token_info=AcquireTokenInfo();
8024 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8025 "\"",'\0',&breaker,&next,&quote);
8026 token_info=DestroyTokenInfo(token_info);
8027 if (status == 0)
8028 {
8029 const char
8030 *argv;
8031
8032 argv=(&(arguments[next]));
8033 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8034 exception);
8035 }
8036 token=DestroyString(token);
8037 break;
8038 }
cristy91c0da22010-05-02 01:44:07 +00008039 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008040 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8041 number_arguments-2,(const char **) arguments+2,exception);
8042 for (j=0; j < number_arguments; j++)
8043 arguments[j]=DestroyString(arguments[j]);
8044 arguments=(char **) RelinquishMagickMemory(arguments);
8045 break;
8046 }
8047 break;
8048 }
8049 case 'r':
8050 {
8051 if (LocaleCompare("reverse",option+1) == 0)
8052 {
8053 ReverseImageList(images);
8054 InheritException(exception,&(*images)->exception);
8055 break;
8056 }
8057 break;
8058 }
8059 case 's':
8060 {
cristy4285d782011-02-09 20:12:28 +00008061 if (LocaleCompare("smush",option+1) == 0)
8062 {
8063 Image
8064 *smush_image;
8065
8066 ssize_t
8067 offset;
8068
8069 (void) SyncImagesSettings(mogrify_info,*images);
8070 offset=(ssize_t) StringToLong(argv[i+1]);
8071 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8072 MagickFalse,offset,exception);
8073 if (smush_image == (Image *) NULL)
8074 {
8075 status=MagickFalse;
8076 break;
8077 }
8078 *images=DestroyImageList(*images);
8079 *images=smush_image;
8080 break;
8081 }
cristy3ed852e2009-09-05 21:47:34 +00008082 if (LocaleCompare("swap",option+1) == 0)
8083 {
8084 Image
8085 *p,
8086 *q,
8087 *swap;
8088
cristybb503372010-05-27 20:51:26 +00008089 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008090 swap_index;
8091
8092 index=(-1);
8093 swap_index=(-2);
8094 if (*option != '+')
8095 {
8096 GeometryInfo
8097 geometry_info;
8098
8099 MagickStatusType
8100 flags;
8101
8102 swap_index=(-1);
8103 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008104 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008105 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008106 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008107 }
8108 p=GetImageFromList(*images,index);
8109 q=GetImageFromList(*images,swap_index);
8110 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8111 {
8112 (void) ThrowMagickException(exception,GetMagickModule(),
8113 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8114 status=MagickFalse;
8115 break;
8116 }
8117 if (p == q)
8118 break;
8119 swap=CloneImage(p,0,0,MagickTrue,exception);
8120 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8121 ReplaceImageInList(&q,swap);
8122 *images=GetFirstImageInList(q);
8123 break;
8124 }
8125 break;
8126 }
8127 case 'w':
8128 {
8129 if (LocaleCompare("write",option+1) == 0)
8130 {
cristy071dd7b2010-04-09 13:04:54 +00008131 char
cristy06609ee2010-03-17 20:21:27 +00008132 key[MaxTextExtent];
8133
cristy3ed852e2009-09-05 21:47:34 +00008134 Image
8135 *write_images;
8136
8137 ImageInfo
8138 *write_info;
8139
cristy6b3da3a2010-06-20 02:21:46 +00008140 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008141 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008142 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008143 write_images=(*images);
8144 if (*option == '+')
8145 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008146 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008147 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8148 write_info=DestroyImageInfo(write_info);
8149 if (*option == '+')
8150 write_images=DestroyImageList(write_images);
8151 break;
8152 }
8153 break;
8154 }
8155 default:
8156 break;
8157 }
8158 i+=count;
8159 }
8160 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008161 mogrify_info=DestroyImageInfo(mogrify_info);
8162 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008163 return(status != 0 ? MagickTrue : MagickFalse);
8164}
8165
8166/*
8167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8168% %
8169% %
8170% %
8171+ M o g r i f y I m a g e s %
8172% %
8173% %
8174% %
8175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8176%
8177% MogrifyImages() applies image processing options to a sequence of images as
8178% prescribed by command line options.
8179%
8180% The format of the MogrifyImage method is:
8181%
8182% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8183% const MagickBooleanType post,const int argc,const char **argv,
8184% Image **images,Exceptioninfo *exception)
8185%
8186% A description of each parameter follows:
8187%
8188% o image_info: the image info..
8189%
8190% o post: If true, post process image list operators otherwise pre-process.
8191%
8192% o argc: Specifies a pointer to an integer describing the number of
8193% elements in the argument vector.
8194%
8195% o argv: Specifies a pointer to a text array containing the command line
8196% arguments.
8197%
anthonye9c27192011-03-27 08:07:06 +00008198% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008199%
8200% o exception: return any errors or warnings in this structure.
8201%
8202*/
8203WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8204 const MagickBooleanType post,const int argc,const char **argv,
8205 Image **images,ExceptionInfo *exception)
8206{
8207#define MogrifyImageTag "Mogrify/Image"
8208
anthonye9c27192011-03-27 08:07:06 +00008209 MagickStatusType
8210 status;
cristy3ed852e2009-09-05 21:47:34 +00008211
cristy0e9f9c12010-02-11 03:00:47 +00008212 MagickBooleanType
8213 proceed;
8214
anthonye9c27192011-03-27 08:07:06 +00008215 size_t
8216 n;
cristy3ed852e2009-09-05 21:47:34 +00008217
cristybb503372010-05-27 20:51:26 +00008218 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008219 i;
8220
cristy3ed852e2009-09-05 21:47:34 +00008221 assert(image_info != (ImageInfo *) NULL);
8222 assert(image_info->signature == MagickSignature);
8223 if (images == (Image **) NULL)
8224 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008225 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008226 assert((*images)->signature == MagickSignature);
8227 if ((*images)->debug != MagickFalse)
8228 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8229 (*images)->filename);
8230 if ((argc <= 0) || (*argv == (char *) NULL))
8231 return(MagickTrue);
8232 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8233 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008234 status=0;
anthonye9c27192011-03-27 08:07:06 +00008235
anthonyce2716b2011-04-22 09:51:34 +00008236#if 0
cristy1e604812011-05-19 18:07:50 +00008237 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8238 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008239#endif
8240
anthonye9c27192011-03-27 08:07:06 +00008241 /*
8242 Pre-process multi-image sequence operators
8243 */
cristy3ed852e2009-09-05 21:47:34 +00008244 if (post == MagickFalse)
8245 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008246 /*
8247 For each image, process simple single image operators
8248 */
8249 i=0;
8250 n=GetImageListLength(*images);
8251 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008252 {
anthonyce2716b2011-04-22 09:51:34 +00008253#if 0
cristy1e604812011-05-19 18:07:50 +00008254 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8255 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008256#endif
anthonye9c27192011-03-27 08:07:06 +00008257 status&=MogrifyImage(image_info,argc,argv,images,exception);
8258 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008259 if (proceed == MagickFalse)
8260 break;
anthonye9c27192011-03-27 08:07:06 +00008261 if ( (*images)->next == (Image *) NULL )
8262 break;
8263 *images=(*images)->next;
8264 i++;
cristy3ed852e2009-09-05 21:47:34 +00008265 }
anthonye9c27192011-03-27 08:07:06 +00008266 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008267#if 0
cristy1e604812011-05-19 18:07:50 +00008268 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8269 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008270#endif
anthonye9c27192011-03-27 08:07:06 +00008271
8272 /*
8273 Post-process, multi-image sequence operators
8274 */
8275 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008276 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008277 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008278 return(status != 0 ? MagickTrue : MagickFalse);
8279}