blob: e6a1ddea9447866c642c29ca29aea22df96fa73e [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;
cristyf4ad9df2011-07-08 16:49:03 +0000709 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
710 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000711 break;
cristy3ed852e2009-09-05 21:47:34 +0000712 }
anthonydf8ebac2011-04-27 09:03:19 +0000713 if (LocaleCompare("adaptive-resize",option+1) == 0)
714 {
715 /*
716 Adaptive resize image.
717 */
718 (void) SyncImageSettings(mogrify_info,*image);
719 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
720 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
721 geometry.height,exception);
722 break;
723 }
724 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
725 {
726 /*
727 Adaptive sharpen image.
728 */
729 (void) SyncImageSettings(mogrify_info,*image);
730 flags=ParseGeometry(argv[i+1],&geometry_info);
731 if ((flags & SigmaValue) == 0)
732 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000733 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
734 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000735 break;
736 }
737 if (LocaleCompare("affine",option+1) == 0)
738 {
739 /*
740 Affine matrix.
741 */
742 if (*option == '+')
743 {
744 GetAffineMatrix(&draw_info->affine);
745 break;
746 }
747 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
748 break;
749 }
750 if (LocaleCompare("alpha",option+1) == 0)
751 {
752 AlphaChannelType
753 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000754
anthonydf8ebac2011-04-27 09:03:19 +0000755 (void) SyncImageSettings(mogrify_info,*image);
756 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
757 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000758 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000759 break;
760 }
761 if (LocaleCompare("annotate",option+1) == 0)
762 {
763 char
764 *text,
765 geometry[MaxTextExtent];
766
767 /*
768 Annotate image.
769 */
770 (void) SyncImageSettings(mogrify_info,*image);
771 SetGeometryInfo(&geometry_info);
772 flags=ParseGeometry(argv[i+1],&geometry_info);
773 if ((flags & SigmaValue) == 0)
774 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000775 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
776 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000777 if (text == (char *) NULL)
778 break;
779 (void) CloneString(&draw_info->text,text);
780 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000781 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000782 geometry_info.xi,geometry_info.psi);
783 (void) CloneString(&draw_info->geometry,geometry);
784 draw_info->affine.sx=cos(DegreesToRadians(
785 fmod(geometry_info.rho,360.0)));
786 draw_info->affine.rx=sin(DegreesToRadians(
787 fmod(geometry_info.rho,360.0)));
788 draw_info->affine.ry=(-sin(DegreesToRadians(
789 fmod(geometry_info.sigma,360.0))));
790 draw_info->affine.sy=cos(DegreesToRadians(
791 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000792 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000793 break;
794 }
795 if (LocaleCompare("antialias",option+1) == 0)
796 {
797 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
798 MagickFalse;
799 draw_info->text_antialias=(*option == '-') ? MagickTrue :
800 MagickFalse;
801 break;
802 }
803 if (LocaleCompare("auto-gamma",option+1) == 0)
804 {
805 /*
806 Auto Adjust Gamma of image based on its mean
807 */
808 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000809 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000810 break;
811 }
812 if (LocaleCompare("auto-level",option+1) == 0)
813 {
814 /*
815 Perfectly Normalize (max/min stretch) the image
816 */
817 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000818 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000819 break;
820 }
821 if (LocaleCompare("auto-orient",option+1) == 0)
822 {
823 (void) SyncImageSettings(mogrify_info,*image);
824 switch ((*image)->orientation)
825 {
826 case TopRightOrientation:
827 {
828 mogrify_image=FlopImage(*image,exception);
829 break;
830 }
831 case BottomRightOrientation:
832 {
833 mogrify_image=RotateImage(*image,180.0,exception);
834 break;
835 }
836 case BottomLeftOrientation:
837 {
838 mogrify_image=FlipImage(*image,exception);
839 break;
840 }
841 case LeftTopOrientation:
842 {
843 mogrify_image=TransposeImage(*image,exception);
844 break;
845 }
846 case RightTopOrientation:
847 {
848 mogrify_image=RotateImage(*image,90.0,exception);
849 break;
850 }
851 case RightBottomOrientation:
852 {
853 mogrify_image=TransverseImage(*image,exception);
854 break;
855 }
856 case LeftBottomOrientation:
857 {
858 mogrify_image=RotateImage(*image,270.0,exception);
859 break;
860 }
861 default:
862 break;
863 }
864 if (mogrify_image != (Image *) NULL)
865 mogrify_image->orientation=TopLeftOrientation;
866 break;
867 }
868 break;
869 }
870 case 'b':
871 {
872 if (LocaleCompare("black-threshold",option+1) == 0)
873 {
874 /*
875 Black threshold image.
876 */
877 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000878 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000879 InheritException(exception,&(*image)->exception);
880 break;
881 }
882 if (LocaleCompare("blue-shift",option+1) == 0)
883 {
884 /*
885 Blue shift image.
886 */
887 (void) SyncImageSettings(mogrify_info,*image);
888 geometry_info.rho=1.5;
889 if (*option == '-')
890 flags=ParseGeometry(argv[i+1],&geometry_info);
891 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
892 break;
893 }
894 if (LocaleCompare("blur",option+1) == 0)
895 {
896 /*
897 Gaussian blur image.
898 */
899 (void) SyncImageSettings(mogrify_info,*image);
900 flags=ParseGeometry(argv[i+1],&geometry_info);
901 if ((flags & SigmaValue) == 0)
902 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000903 mogrify_image=BlurImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +0000904 geometry_info.sigma,exception);
905 break;
906 }
907 if (LocaleCompare("border",option+1) == 0)
908 {
909 /*
910 Surround image with a border of solid color.
911 */
912 (void) SyncImageSettings(mogrify_info,*image);
913 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
914 if ((flags & SigmaValue) == 0)
915 geometry.height=geometry.width;
916 mogrify_image=BorderImage(*image,&geometry,exception);
917 break;
918 }
919 if (LocaleCompare("bordercolor",option+1) == 0)
920 {
921 if (*option == '+')
922 {
cristy638895a2011-08-06 23:19:14 +0000923 (void) QueryColorDatabase(MogrifyBorderColor,&draw_info->border_color,
anthonydf8ebac2011-04-27 09:03:19 +0000924 exception);
925 break;
926 }
927 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
928 exception);
929 break;
930 }
931 if (LocaleCompare("box",option+1) == 0)
932 {
933 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
934 exception);
935 break;
936 }
937 if (LocaleCompare("brightness-contrast",option+1) == 0)
938 {
939 double
940 brightness,
941 contrast;
942
943 GeometryInfo
944 geometry_info;
945
946 MagickStatusType
947 flags;
948
949 /*
950 Brightness / contrast image.
951 */
952 (void) SyncImageSettings(mogrify_info,*image);
953 flags=ParseGeometry(argv[i+1],&geometry_info);
954 brightness=geometry_info.rho;
955 contrast=0.0;
956 if ((flags & SigmaValue) != 0)
957 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000958 (void) BrightnessContrastImage(*image,brightness,contrast,
959 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000960 InheritException(exception,&(*image)->exception);
961 break;
962 }
963 break;
964 }
965 case 'c':
966 {
967 if (LocaleCompare("cdl",option+1) == 0)
968 {
969 char
970 *color_correction_collection;
971
972 /*
973 Color correct with a color decision list.
974 */
975 (void) SyncImageSettings(mogrify_info,*image);
976 color_correction_collection=FileToString(argv[i+1],~0,exception);
977 if (color_correction_collection == (char *) NULL)
978 break;
cristy1bfa9f02011-08-11 02:35:43 +0000979 (void) ColorDecisionListImage(*image,color_correction_collection,
980 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000981 InheritException(exception,&(*image)->exception);
982 break;
983 }
984 if (LocaleCompare("channel",option+1) == 0)
985 {
986 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000987 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000988 else
cristyfa806a72011-07-04 02:06:13 +0000989 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +0000990 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000991 break;
992 }
993 if (LocaleCompare("charcoal",option+1) == 0)
994 {
995 /*
996 Charcoal image.
997 */
998 (void) SyncImageSettings(mogrify_info,*image);
999 flags=ParseGeometry(argv[i+1],&geometry_info);
1000 if ((flags & SigmaValue) == 0)
1001 geometry_info.sigma=1.0;
1002 mogrify_image=CharcoalImage(*image,geometry_info.rho,
1003 geometry_info.sigma,exception);
1004 break;
1005 }
1006 if (LocaleCompare("chop",option+1) == 0)
1007 {
1008 /*
1009 Chop the image.
1010 */
1011 (void) SyncImageSettings(mogrify_info,*image);
1012 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1013 mogrify_image=ChopImage(*image,&geometry,exception);
1014 break;
1015 }
1016 if (LocaleCompare("clamp",option+1) == 0)
1017 {
1018 /*
1019 Clamp image.
1020 */
1021 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001022 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001023 InheritException(exception,&(*image)->exception);
1024 break;
1025 }
1026 if (LocaleCompare("clip",option+1) == 0)
1027 {
1028 (void) SyncImageSettings(mogrify_info,*image);
1029 if (*option == '+')
1030 {
cristy018f07f2011-09-04 21:15:19 +00001031 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001032 break;
1033 }
cristy018f07f2011-09-04 21:15:19 +00001034 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001035 break;
1036 }
1037 if (LocaleCompare("clip-mask",option+1) == 0)
1038 {
1039 CacheView
1040 *mask_view;
1041
1042 Image
1043 *mask_image;
1044
cristy4c08aed2011-07-01 19:47:50 +00001045 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001046 *restrict q;
1047
1048 register ssize_t
1049 x;
1050
1051 ssize_t
1052 y;
1053
1054 (void) SyncImageSettings(mogrify_info,*image);
1055 if (*option == '+')
1056 {
1057 /*
1058 Remove a mask.
1059 */
cristy018f07f2011-09-04 21:15:19 +00001060 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001061 break;
1062 }
1063 /*
1064 Set the image mask.
1065 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1066 */
1067 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1068 if (mask_image == (Image *) NULL)
1069 break;
cristy574cc262011-08-05 01:23:58 +00001070 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001071 return(MagickFalse);
1072 mask_view=AcquireCacheView(mask_image);
1073 for (y=0; y < (ssize_t) mask_image->rows; y++)
1074 {
1075 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1076 exception);
cristyacd2ed22011-08-30 01:44:23 +00001077 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001078 break;
1079 for (x=0; x < (ssize_t) mask_image->columns; x++)
1080 {
1081 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001082 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1083 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1084 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1085 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001086 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001087 }
1088 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1089 break;
1090 }
1091 mask_view=DestroyCacheView(mask_view);
1092 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001093 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001094 InheritException(exception,&(*image)->exception);
1095 break;
1096 }
1097 if (LocaleCompare("clip-path",option+1) == 0)
1098 {
1099 (void) SyncImageSettings(mogrify_info,*image);
1100 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001101 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001102 break;
1103 }
1104 if (LocaleCompare("colorize",option+1) == 0)
1105 {
1106 /*
1107 Colorize the image.
1108 */
1109 (void) SyncImageSettings(mogrify_info,*image);
1110 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1111 exception);
1112 break;
1113 }
1114 if (LocaleCompare("color-matrix",option+1) == 0)
1115 {
1116 KernelInfo
1117 *kernel;
1118
1119 (void) SyncImageSettings(mogrify_info,*image);
1120 kernel=AcquireKernelInfo(argv[i+1]);
1121 if (kernel == (KernelInfo *) NULL)
1122 break;
1123 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1124 kernel=DestroyKernelInfo(kernel);
1125 break;
1126 }
1127 if (LocaleCompare("colors",option+1) == 0)
1128 {
1129 /*
1130 Reduce the number of colors in the image.
1131 */
1132 (void) SyncImageSettings(mogrify_info,*image);
1133 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1134 if (quantize_info->number_colors == 0)
1135 break;
1136 if (((*image)->storage_class == DirectClass) ||
1137 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001138 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001139 else
cristy018f07f2011-09-04 21:15:19 +00001140 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001141 break;
1142 }
1143 if (LocaleCompare("colorspace",option+1) == 0)
1144 {
1145 ColorspaceType
1146 colorspace;
1147
1148 (void) SyncImageSettings(mogrify_info,*image);
1149 if (*option == '+')
1150 {
1151 (void) TransformImageColorspace(*image,RGBColorspace);
1152 InheritException(exception,&(*image)->exception);
1153 break;
1154 }
1155 colorspace=(ColorspaceType) ParseCommandOption(
1156 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1157 (void) TransformImageColorspace(*image,colorspace);
1158 InheritException(exception,&(*image)->exception);
1159 break;
1160 }
1161 if (LocaleCompare("contrast",option+1) == 0)
1162 {
1163 (void) SyncImageSettings(mogrify_info,*image);
1164 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001165 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001166 break;
1167 }
1168 if (LocaleCompare("contrast-stretch",option+1) == 0)
1169 {
1170 double
1171 black_point,
1172 white_point;
1173
1174 MagickStatusType
1175 flags;
1176
1177 /*
1178 Contrast stretch image.
1179 */
1180 (void) SyncImageSettings(mogrify_info,*image);
1181 flags=ParseGeometry(argv[i+1],&geometry_info);
1182 black_point=geometry_info.rho;
1183 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1184 black_point;
1185 if ((flags & PercentValue) != 0)
1186 {
1187 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1188 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1189 }
1190 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1191 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001192 (void) ContrastStretchImage(*image,black_point,white_point,
1193 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001194 InheritException(exception,&(*image)->exception);
1195 break;
1196 }
1197 if (LocaleCompare("convolve",option+1) == 0)
1198 {
anthonydf8ebac2011-04-27 09:03:19 +00001199 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001200 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001201
anthonydf8ebac2011-04-27 09:03:19 +00001202 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001203 kernel_info=AcquireKernelInfo(argv[i+1]);
1204 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001205 break;
cristy0a922382011-07-16 15:30:34 +00001206 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001207 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001208 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001209 break;
1210 }
1211 if (LocaleCompare("crop",option+1) == 0)
1212 {
1213 /*
1214 Crop a image to a smaller size
1215 */
1216 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001217 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001218 break;
1219 }
1220 if (LocaleCompare("cycle",option+1) == 0)
1221 {
1222 /*
1223 Cycle an image colormap.
1224 */
1225 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00001226 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1227 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001228 break;
1229 }
1230 break;
1231 }
1232 case 'd':
1233 {
1234 if (LocaleCompare("decipher",option+1) == 0)
1235 {
1236 StringInfo
1237 *passkey;
1238
1239 /*
1240 Decipher pixels.
1241 */
1242 (void) SyncImageSettings(mogrify_info,*image);
1243 passkey=FileToStringInfo(argv[i+1],~0,exception);
1244 if (passkey != (StringInfo *) NULL)
1245 {
1246 (void) PasskeyDecipherImage(*image,passkey,exception);
1247 passkey=DestroyStringInfo(passkey);
1248 }
1249 break;
1250 }
1251 if (LocaleCompare("density",option+1) == 0)
1252 {
1253 /*
1254 Set image density.
1255 */
1256 (void) CloneString(&draw_info->density,argv[i+1]);
1257 break;
1258 }
1259 if (LocaleCompare("depth",option+1) == 0)
1260 {
1261 (void) SyncImageSettings(mogrify_info,*image);
1262 if (*option == '+')
1263 {
1264 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1265 break;
1266 }
1267 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1268 break;
1269 }
1270 if (LocaleCompare("deskew",option+1) == 0)
1271 {
1272 double
1273 threshold;
1274
1275 /*
1276 Straighten the image.
1277 */
1278 (void) SyncImageSettings(mogrify_info,*image);
1279 if (*option == '+')
1280 threshold=40.0*QuantumRange/100.0;
1281 else
1282 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1283 mogrify_image=DeskewImage(*image,threshold,exception);
1284 break;
1285 }
1286 if (LocaleCompare("despeckle",option+1) == 0)
1287 {
1288 /*
1289 Reduce the speckles within an image.
1290 */
1291 (void) SyncImageSettings(mogrify_info,*image);
1292 mogrify_image=DespeckleImage(*image,exception);
1293 break;
1294 }
1295 if (LocaleCompare("display",option+1) == 0)
1296 {
1297 (void) CloneString(&draw_info->server_name,argv[i+1]);
1298 break;
1299 }
1300 if (LocaleCompare("distort",option+1) == 0)
1301 {
1302 char
1303 *args,
1304 token[MaxTextExtent];
1305
1306 const char
1307 *p;
1308
1309 DistortImageMethod
1310 method;
1311
1312 double
1313 *arguments;
1314
1315 register ssize_t
1316 x;
1317
1318 size_t
1319 number_arguments;
1320
1321 /*
1322 Distort image.
1323 */
1324 (void) SyncImageSettings(mogrify_info,*image);
1325 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1326 MagickFalse,argv[i+1]);
1327 if ( method == ResizeDistortion )
1328 {
1329 /* Special Case - Argument is actually a resize geometry!
1330 ** Convert that to an appropriate distortion argument array.
1331 */
1332 double
1333 resize_args[2];
1334 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1335 exception);
1336 resize_args[0]=(double)geometry.width;
1337 resize_args[1]=(double)geometry.height;
1338 mogrify_image=DistortImage(*image,method,(size_t)2,
1339 resize_args,MagickTrue,exception);
1340 break;
1341 }
cristy018f07f2011-09-04 21:15:19 +00001342 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1343 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001344 if (args == (char *) NULL)
1345 break;
1346 p=(char *) args;
1347 for (x=0; *p != '\0'; x++)
1348 {
1349 GetMagickToken(p,&p,token);
1350 if (*token == ',')
1351 GetMagickToken(p,&p,token);
1352 }
1353 number_arguments=(size_t) x;
1354 arguments=(double *) AcquireQuantumMemory(number_arguments,
1355 sizeof(*arguments));
1356 if (arguments == (double *) NULL)
1357 ThrowWandFatalException(ResourceLimitFatalError,
1358 "MemoryAllocationFailed",(*image)->filename);
1359 (void) ResetMagickMemory(arguments,0,number_arguments*
1360 sizeof(*arguments));
1361 p=(char *) args;
1362 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1363 {
1364 GetMagickToken(p,&p,token);
1365 if (*token == ',')
1366 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001367 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001368 }
1369 args=DestroyString(args);
1370 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1371 (*option == '+') ? MagickTrue : MagickFalse,exception);
1372 arguments=(double *) RelinquishMagickMemory(arguments);
1373 break;
1374 }
1375 if (LocaleCompare("dither",option+1) == 0)
1376 {
1377 if (*option == '+')
1378 {
1379 quantize_info->dither=MagickFalse;
1380 break;
1381 }
1382 quantize_info->dither=MagickTrue;
1383 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1384 MagickDitherOptions,MagickFalse,argv[i+1]);
1385 if (quantize_info->dither_method == NoDitherMethod)
1386 quantize_info->dither=MagickFalse;
1387 break;
1388 }
1389 if (LocaleCompare("draw",option+1) == 0)
1390 {
1391 /*
1392 Draw image.
1393 */
1394 (void) SyncImageSettings(mogrify_info,*image);
1395 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001396 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001397 break;
1398 }
1399 break;
1400 }
1401 case 'e':
1402 {
1403 if (LocaleCompare("edge",option+1) == 0)
1404 {
1405 /*
1406 Enhance edges in the image.
1407 */
1408 (void) SyncImageSettings(mogrify_info,*image);
1409 flags=ParseGeometry(argv[i+1],&geometry_info);
1410 if ((flags & SigmaValue) == 0)
1411 geometry_info.sigma=1.0;
1412 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1413 break;
1414 }
1415 if (LocaleCompare("emboss",option+1) == 0)
1416 {
1417 /*
1418 Gaussian embossen image.
1419 */
1420 (void) SyncImageSettings(mogrify_info,*image);
1421 flags=ParseGeometry(argv[i+1],&geometry_info);
1422 if ((flags & SigmaValue) == 0)
1423 geometry_info.sigma=1.0;
1424 mogrify_image=EmbossImage(*image,geometry_info.rho,
1425 geometry_info.sigma,exception);
1426 break;
1427 }
1428 if (LocaleCompare("encipher",option+1) == 0)
1429 {
1430 StringInfo
1431 *passkey;
1432
1433 /*
1434 Encipher pixels.
1435 */
1436 (void) SyncImageSettings(mogrify_info,*image);
1437 passkey=FileToStringInfo(argv[i+1],~0,exception);
1438 if (passkey != (StringInfo *) NULL)
1439 {
1440 (void) PasskeyEncipherImage(*image,passkey,exception);
1441 passkey=DestroyStringInfo(passkey);
1442 }
1443 break;
1444 }
1445 if (LocaleCompare("encoding",option+1) == 0)
1446 {
1447 (void) CloneString(&draw_info->encoding,argv[i+1]);
1448 break;
1449 }
1450 if (LocaleCompare("enhance",option+1) == 0)
1451 {
1452 /*
1453 Enhance image.
1454 */
1455 (void) SyncImageSettings(mogrify_info,*image);
1456 mogrify_image=EnhanceImage(*image,exception);
1457 break;
1458 }
1459 if (LocaleCompare("equalize",option+1) == 0)
1460 {
1461 /*
1462 Equalize image.
1463 */
1464 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001465 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001466 break;
1467 }
1468 if (LocaleCompare("evaluate",option+1) == 0)
1469 {
1470 double
1471 constant;
1472
1473 MagickEvaluateOperator
1474 op;
1475
1476 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001477 op=(MagickEvaluateOperator) ParseCommandOption(
1478 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001479 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001480 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001481 break;
1482 }
1483 if (LocaleCompare("extent",option+1) == 0)
1484 {
1485 /*
1486 Set the image extent.
1487 */
1488 (void) SyncImageSettings(mogrify_info,*image);
1489 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1490 if (geometry.width == 0)
1491 geometry.width=(*image)->columns;
1492 if (geometry.height == 0)
1493 geometry.height=(*image)->rows;
1494 mogrify_image=ExtentImage(*image,&geometry,exception);
1495 break;
1496 }
1497 break;
1498 }
1499 case 'f':
1500 {
1501 if (LocaleCompare("family",option+1) == 0)
1502 {
1503 if (*option == '+')
1504 {
1505 if (draw_info->family != (char *) NULL)
1506 draw_info->family=DestroyString(draw_info->family);
1507 break;
1508 }
1509 (void) CloneString(&draw_info->family,argv[i+1]);
1510 break;
1511 }
1512 if (LocaleCompare("features",option+1) == 0)
1513 {
1514 if (*option == '+')
1515 {
1516 (void) DeleteImageArtifact(*image,"identify:features");
1517 break;
1518 }
1519 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1520 break;
1521 }
1522 if (LocaleCompare("fill",option+1) == 0)
1523 {
1524 ExceptionInfo
1525 *sans;
1526
cristy4c08aed2011-07-01 19:47:50 +00001527 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001528 if (*option == '+')
1529 {
1530 (void) QueryMagickColor("none",&fill,exception);
1531 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1532 if (draw_info->fill_pattern != (Image *) NULL)
1533 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1534 break;
1535 }
1536 sans=AcquireExceptionInfo();
1537 (void) QueryMagickColor(argv[i+1],&fill,sans);
1538 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1539 sans=DestroyExceptionInfo(sans);
1540 if (status == MagickFalse)
1541 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1542 exception);
1543 break;
1544 }
1545 if (LocaleCompare("flip",option+1) == 0)
1546 {
1547 /*
1548 Flip image scanlines.
1549 */
1550 (void) SyncImageSettings(mogrify_info,*image);
1551 mogrify_image=FlipImage(*image,exception);
1552 break;
1553 }
anthonydf8ebac2011-04-27 09:03:19 +00001554 if (LocaleCompare("floodfill",option+1) == 0)
1555 {
cristy4c08aed2011-07-01 19:47:50 +00001556 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001557 target;
1558
1559 /*
1560 Floodfill image.
1561 */
1562 (void) SyncImageSettings(mogrify_info,*image);
1563 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1564 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001565 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001566 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001567 break;
1568 }
anthony3d2f4862011-05-01 13:48:16 +00001569 if (LocaleCompare("flop",option+1) == 0)
1570 {
1571 /*
1572 Flop image scanlines.
1573 */
1574 (void) SyncImageSettings(mogrify_info,*image);
1575 mogrify_image=FlopImage(*image,exception);
1576 break;
1577 }
anthonydf8ebac2011-04-27 09:03:19 +00001578 if (LocaleCompare("font",option+1) == 0)
1579 {
1580 if (*option == '+')
1581 {
1582 if (draw_info->font != (char *) NULL)
1583 draw_info->font=DestroyString(draw_info->font);
1584 break;
1585 }
1586 (void) CloneString(&draw_info->font,argv[i+1]);
1587 break;
1588 }
1589 if (LocaleCompare("format",option+1) == 0)
1590 {
1591 format=argv[i+1];
1592 break;
1593 }
1594 if (LocaleCompare("frame",option+1) == 0)
1595 {
1596 FrameInfo
1597 frame_info;
1598
1599 /*
1600 Surround image with an ornamental border.
1601 */
1602 (void) SyncImageSettings(mogrify_info,*image);
1603 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1604 frame_info.width=geometry.width;
1605 frame_info.height=geometry.height;
1606 if ((flags & HeightValue) == 0)
1607 frame_info.height=geometry.width;
1608 frame_info.outer_bevel=geometry.x;
1609 frame_info.inner_bevel=geometry.y;
1610 frame_info.x=(ssize_t) frame_info.width;
1611 frame_info.y=(ssize_t) frame_info.height;
1612 frame_info.width=(*image)->columns+2*frame_info.width;
1613 frame_info.height=(*image)->rows+2*frame_info.height;
1614 mogrify_image=FrameImage(*image,&frame_info,exception);
1615 break;
1616 }
1617 if (LocaleCompare("function",option+1) == 0)
1618 {
1619 char
1620 *arguments,
1621 token[MaxTextExtent];
1622
1623 const char
1624 *p;
1625
1626 double
1627 *parameters;
1628
1629 MagickFunction
1630 function;
1631
1632 register ssize_t
1633 x;
1634
1635 size_t
1636 number_parameters;
1637
1638 /*
1639 Function Modify Image Values
1640 */
1641 (void) SyncImageSettings(mogrify_info,*image);
1642 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1643 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001644 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1645 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001646 if (arguments == (char *) NULL)
1647 break;
1648 p=(char *) arguments;
1649 for (x=0; *p != '\0'; x++)
1650 {
1651 GetMagickToken(p,&p,token);
1652 if (*token == ',')
1653 GetMagickToken(p,&p,token);
1654 }
1655 number_parameters=(size_t) x;
1656 parameters=(double *) AcquireQuantumMemory(number_parameters,
1657 sizeof(*parameters));
1658 if (parameters == (double *) NULL)
1659 ThrowWandFatalException(ResourceLimitFatalError,
1660 "MemoryAllocationFailed",(*image)->filename);
1661 (void) ResetMagickMemory(parameters,0,number_parameters*
1662 sizeof(*parameters));
1663 p=(char *) arguments;
1664 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1665 {
1666 GetMagickToken(p,&p,token);
1667 if (*token == ',')
1668 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001669 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001670 }
1671 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001672 (void) FunctionImage(*image,function,number_parameters,parameters,
1673 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001674 parameters=(double *) RelinquishMagickMemory(parameters);
1675 break;
1676 }
1677 break;
1678 }
1679 case 'g':
1680 {
1681 if (LocaleCompare("gamma",option+1) == 0)
1682 {
1683 /*
1684 Gamma image.
1685 */
1686 (void) SyncImageSettings(mogrify_info,*image);
1687 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001688 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001689 else
cristyb3e7c6c2011-07-24 01:43:55 +00001690 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1691 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001692 break;
1693 }
1694 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1695 (LocaleCompare("gaussian",option+1) == 0))
1696 {
1697 /*
1698 Gaussian blur image.
1699 */
1700 (void) SyncImageSettings(mogrify_info,*image);
1701 flags=ParseGeometry(argv[i+1],&geometry_info);
1702 if ((flags & SigmaValue) == 0)
1703 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001704 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1705 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001706 break;
1707 }
1708 if (LocaleCompare("geometry",option+1) == 0)
1709 {
1710 /*
1711 Record Image offset, Resize last image.
1712 */
1713 (void) SyncImageSettings(mogrify_info,*image);
1714 if (*option == '+')
1715 {
1716 if ((*image)->geometry != (char *) NULL)
1717 (*image)->geometry=DestroyString((*image)->geometry);
1718 break;
1719 }
1720 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1721 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1722 (void) CloneString(&(*image)->geometry,argv[i+1]);
1723 else
1724 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1725 (*image)->filter,(*image)->blur,exception);
1726 break;
1727 }
1728 if (LocaleCompare("gravity",option+1) == 0)
1729 {
1730 if (*option == '+')
1731 {
1732 draw_info->gravity=UndefinedGravity;
1733 break;
1734 }
1735 draw_info->gravity=(GravityType) ParseCommandOption(
1736 MagickGravityOptions,MagickFalse,argv[i+1]);
1737 break;
1738 }
1739 break;
1740 }
1741 case 'h':
1742 {
1743 if (LocaleCompare("highlight-color",option+1) == 0)
1744 {
1745 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1746 break;
1747 }
1748 break;
1749 }
1750 case 'i':
1751 {
1752 if (LocaleCompare("identify",option+1) == 0)
1753 {
1754 char
1755 *text;
1756
1757 (void) SyncImageSettings(mogrify_info,*image);
1758 if (format == (char *) NULL)
1759 {
cristya4037272011-08-28 15:11:39 +00001760 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1761 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001762 break;
1763 }
cristy018f07f2011-09-04 21:15:19 +00001764 text=InterpretImageProperties(mogrify_info,*image,format,
1765 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001766 if (text == (char *) NULL)
1767 break;
1768 (void) fputs(text,stdout);
1769 (void) fputc('\n',stdout);
1770 text=DestroyString(text);
1771 break;
1772 }
1773 if (LocaleCompare("implode",option+1) == 0)
1774 {
1775 /*
1776 Implode image.
1777 */
1778 (void) SyncImageSettings(mogrify_info,*image);
1779 (void) ParseGeometry(argv[i+1],&geometry_info);
1780 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1781 break;
1782 }
1783 if (LocaleCompare("interline-spacing",option+1) == 0)
1784 {
1785 if (*option == '+')
1786 (void) ParseGeometry("0",&geometry_info);
1787 else
1788 (void) ParseGeometry(argv[i+1],&geometry_info);
1789 draw_info->interline_spacing=geometry_info.rho;
1790 break;
1791 }
1792 if (LocaleCompare("interword-spacing",option+1) == 0)
1793 {
1794 if (*option == '+')
1795 (void) ParseGeometry("0",&geometry_info);
1796 else
1797 (void) ParseGeometry(argv[i+1],&geometry_info);
1798 draw_info->interword_spacing=geometry_info.rho;
1799 break;
1800 }
1801 break;
1802 }
1803 case 'k':
1804 {
1805 if (LocaleCompare("kerning",option+1) == 0)
1806 {
1807 if (*option == '+')
1808 (void) ParseGeometry("0",&geometry_info);
1809 else
1810 (void) ParseGeometry(argv[i+1],&geometry_info);
1811 draw_info->kerning=geometry_info.rho;
1812 break;
1813 }
1814 break;
1815 }
1816 case 'l':
1817 {
1818 if (LocaleCompare("lat",option+1) == 0)
1819 {
1820 /*
1821 Local adaptive threshold image.
1822 */
1823 (void) SyncImageSettings(mogrify_info,*image);
1824 flags=ParseGeometry(argv[i+1],&geometry_info);
1825 if ((flags & PercentValue) != 0)
1826 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1827 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001828 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001829 geometry_info.xi,exception);
1830 break;
1831 }
1832 if (LocaleCompare("level",option+1) == 0)
1833 {
1834 MagickRealType
1835 black_point,
1836 gamma,
1837 white_point;
1838
1839 MagickStatusType
1840 flags;
1841
1842 /*
1843 Parse levels.
1844 */
1845 (void) SyncImageSettings(mogrify_info,*image);
1846 flags=ParseGeometry(argv[i+1],&geometry_info);
1847 black_point=geometry_info.rho;
1848 white_point=(MagickRealType) QuantumRange;
1849 if ((flags & SigmaValue) != 0)
1850 white_point=geometry_info.sigma;
1851 gamma=1.0;
1852 if ((flags & XiValue) != 0)
1853 gamma=geometry_info.xi;
1854 if ((flags & PercentValue) != 0)
1855 {
1856 black_point*=(MagickRealType) (QuantumRange/100.0);
1857 white_point*=(MagickRealType) (QuantumRange/100.0);
1858 }
1859 if ((flags & SigmaValue) == 0)
1860 white_point=(MagickRealType) QuantumRange-black_point;
1861 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001862 (void) LevelizeImage(*image,black_point,white_point,gamma,
1863 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001864 else
cristy01e9afd2011-08-10 17:38:41 +00001865 (void) LevelImage(*image,black_point,white_point,gamma,
1866 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001867 InheritException(exception,&(*image)->exception);
1868 break;
1869 }
1870 if (LocaleCompare("level-colors",option+1) == 0)
1871 {
1872 char
1873 token[MaxTextExtent];
1874
1875 const char
1876 *p;
1877
cristy4c08aed2011-07-01 19:47:50 +00001878 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001879 black_point,
1880 white_point;
1881
1882 p=(const char *) argv[i+1];
1883 GetMagickToken(p,&p,token); /* get black point color */
1884 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1885 (void) QueryMagickColor(token,&black_point,exception);
1886 else
1887 (void) QueryMagickColor("#000000",&black_point,exception);
1888 if (isalpha((int) token[0]) || (token[0] == '#'))
1889 GetMagickToken(p,&p,token);
1890 if (*token == '\0')
1891 white_point=black_point; /* set everything to that color */
1892 else
1893 {
1894 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1895 GetMagickToken(p,&p,token); /* Get white point color. */
1896 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1897 (void) QueryMagickColor(token,&white_point,exception);
1898 else
1899 (void) QueryMagickColor("#ffffff",&white_point,exception);
1900 }
cristy490408a2011-07-07 14:42:05 +00001901 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001902 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001903 break;
1904 }
1905 if (LocaleCompare("linear-stretch",option+1) == 0)
1906 {
1907 double
1908 black_point,
1909 white_point;
1910
1911 MagickStatusType
1912 flags;
1913
1914 (void) SyncImageSettings(mogrify_info,*image);
1915 flags=ParseGeometry(argv[i+1],&geometry_info);
1916 black_point=geometry_info.rho;
1917 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1918 if ((flags & SigmaValue) != 0)
1919 white_point=geometry_info.sigma;
1920 if ((flags & PercentValue) != 0)
1921 {
1922 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1923 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1924 }
1925 if ((flags & SigmaValue) == 0)
1926 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1927 black_point;
cristy33bd5152011-08-24 01:42:24 +00001928 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001929 InheritException(exception,&(*image)->exception);
1930 break;
1931 }
1932 if (LocaleCompare("linewidth",option+1) == 0)
1933 {
cristyc1acd842011-05-19 23:05:47 +00001934 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1935 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001936 break;
1937 }
1938 if (LocaleCompare("liquid-rescale",option+1) == 0)
1939 {
1940 /*
1941 Liquid rescale image.
1942 */
1943 (void) SyncImageSettings(mogrify_info,*image);
1944 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1945 if ((flags & XValue) == 0)
1946 geometry.x=1;
1947 if ((flags & YValue) == 0)
1948 geometry.y=0;
1949 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1950 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1951 break;
1952 }
1953 if (LocaleCompare("lowlight-color",option+1) == 0)
1954 {
1955 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1956 break;
1957 }
1958 break;
1959 }
1960 case 'm':
1961 {
1962 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001963 {
cristy3ed852e2009-09-05 21:47:34 +00001964 Image
anthonydf8ebac2011-04-27 09:03:19 +00001965 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001966
anthonydf8ebac2011-04-27 09:03:19 +00001967 /*
1968 Transform image colors to match this set of colors.
1969 */
1970 (void) SyncImageSettings(mogrify_info,*image);
1971 if (*option == '+')
1972 break;
1973 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1974 if (remap_image == (Image *) NULL)
1975 break;
cristy018f07f2011-09-04 21:15:19 +00001976 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001977 remap_image=DestroyImage(remap_image);
1978 break;
1979 }
1980 if (LocaleCompare("mask",option+1) == 0)
1981 {
1982 Image
1983 *mask;
1984
1985 (void) SyncImageSettings(mogrify_info,*image);
1986 if (*option == '+')
1987 {
1988 /*
1989 Remove a mask.
1990 */
cristy018f07f2011-09-04 21:15:19 +00001991 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001992 break;
1993 }
1994 /*
1995 Set the image mask.
1996 */
1997 mask=GetImageCache(mogrify_info,argv[i+1],exception);
1998 if (mask == (Image *) NULL)
1999 break;
cristy018f07f2011-09-04 21:15:19 +00002000 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002001 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002002 break;
2003 }
2004 if (LocaleCompare("matte",option+1) == 0)
2005 {
2006 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002007 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002008 break;
2009 }
2010 if (LocaleCompare("median",option+1) == 0)
2011 {
2012 /*
2013 Median filter image.
2014 */
2015 (void) SyncImageSettings(mogrify_info,*image);
2016 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002017 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2018 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002019 break;
2020 }
2021 if (LocaleCompare("mode",option+1) == 0)
2022 {
2023 /*
2024 Mode image.
2025 */
2026 (void) SyncImageSettings(mogrify_info,*image);
2027 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002028 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2029 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002030 break;
2031 }
2032 if (LocaleCompare("modulate",option+1) == 0)
2033 {
2034 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002035 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002036 break;
2037 }
2038 if (LocaleCompare("monitor",option+1) == 0)
2039 {
2040 if (*option == '+')
2041 {
2042 (void) SetImageProgressMonitor(*image,
2043 (MagickProgressMonitor) NULL,(void *) NULL);
2044 break;
2045 }
2046 (void) SetImageProgressMonitor(*image,MonitorProgress,
2047 (void *) NULL);
2048 break;
2049 }
2050 if (LocaleCompare("monochrome",option+1) == 0)
2051 {
2052 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00002053 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002054 break;
2055 }
2056 if (LocaleCompare("morphology",option+1) == 0)
2057 {
2058 char
2059 token[MaxTextExtent];
2060
2061 const char
2062 *p;
2063
2064 KernelInfo
2065 *kernel;
2066
2067 MorphologyMethod
2068 method;
2069
2070 ssize_t
2071 iterations;
2072
2073 /*
2074 Morphological Image Operation
2075 */
2076 (void) SyncImageSettings(mogrify_info,*image);
2077 p=argv[i+1];
2078 GetMagickToken(p,&p,token);
2079 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2080 MagickFalse,token);
2081 iterations=1L;
2082 GetMagickToken(p,&p,token);
2083 if ((*p == ':') || (*p == ','))
2084 GetMagickToken(p,&p,token);
2085 if ((*p != '\0'))
2086 iterations=(ssize_t) StringToLong(p);
2087 kernel=AcquireKernelInfo(argv[i+2]);
2088 if (kernel == (KernelInfo *) NULL)
2089 {
2090 (void) ThrowMagickException(exception,GetMagickModule(),
2091 OptionError,"UnabletoParseKernel","morphology");
2092 status=MagickFalse;
2093 break;
2094 }
cristyf4ad9df2011-07-08 16:49:03 +00002095 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2096 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002097 kernel=DestroyKernelInfo(kernel);
2098 break;
2099 }
2100 if (LocaleCompare("motion-blur",option+1) == 0)
2101 {
2102 /*
2103 Motion blur image.
2104 */
2105 (void) SyncImageSettings(mogrify_info,*image);
2106 flags=ParseGeometry(argv[i+1],&geometry_info);
2107 if ((flags & SigmaValue) == 0)
2108 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002109 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2110 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002111 break;
2112 }
2113 break;
2114 }
2115 case 'n':
2116 {
2117 if (LocaleCompare("negate",option+1) == 0)
2118 {
2119 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002120 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002121 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002122 break;
2123 }
2124 if (LocaleCompare("noise",option+1) == 0)
2125 {
2126 (void) SyncImageSettings(mogrify_info,*image);
2127 if (*option == '-')
2128 {
2129 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002130 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2131 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002132 }
2133 else
2134 {
2135 NoiseType
2136 noise;
2137
2138 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2139 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002140 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002141 }
2142 break;
2143 }
2144 if (LocaleCompare("normalize",option+1) == 0)
2145 {
2146 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002147 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002148 break;
2149 }
2150 break;
2151 }
2152 case 'o':
2153 {
2154 if (LocaleCompare("opaque",option+1) == 0)
2155 {
cristy4c08aed2011-07-01 19:47:50 +00002156 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002157 target;
2158
2159 (void) SyncImageSettings(mogrify_info,*image);
2160 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002161 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002162 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002163 break;
2164 }
2165 if (LocaleCompare("ordered-dither",option+1) == 0)
2166 {
2167 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002168 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002169 break;
2170 }
2171 break;
2172 }
2173 case 'p':
2174 {
2175 if (LocaleCompare("paint",option+1) == 0)
2176 {
anthonydf8ebac2011-04-27 09:03:19 +00002177 (void) SyncImageSettings(mogrify_info,*image);
2178 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002179 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2180 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002181 break;
2182 }
2183 if (LocaleCompare("pen",option+1) == 0)
2184 {
2185 if (*option == '+')
2186 {
2187 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2188 break;
2189 }
2190 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2191 break;
2192 }
2193 if (LocaleCompare("pointsize",option+1) == 0)
2194 {
2195 if (*option == '+')
2196 (void) ParseGeometry("12",&geometry_info);
2197 else
2198 (void) ParseGeometry(argv[i+1],&geometry_info);
2199 draw_info->pointsize=geometry_info.rho;
2200 break;
2201 }
2202 if (LocaleCompare("polaroid",option+1) == 0)
2203 {
2204 double
2205 angle;
2206
2207 RandomInfo
2208 *random_info;
2209
2210 /*
2211 Simulate a Polaroid picture.
2212 */
2213 (void) SyncImageSettings(mogrify_info,*image);
2214 random_info=AcquireRandomInfo();
2215 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2216 random_info=DestroyRandomInfo(random_info);
2217 if (*option == '-')
2218 {
2219 SetGeometryInfo(&geometry_info);
2220 flags=ParseGeometry(argv[i+1],&geometry_info);
2221 angle=geometry_info.rho;
2222 }
2223 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2224 break;
2225 }
2226 if (LocaleCompare("posterize",option+1) == 0)
2227 {
2228 /*
2229 Posterize image.
2230 */
2231 (void) SyncImageSettings(mogrify_info,*image);
2232 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002233 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002234 break;
2235 }
2236 if (LocaleCompare("preview",option+1) == 0)
2237 {
2238 PreviewType
2239 preview_type;
2240
2241 /*
2242 Preview image.
2243 */
2244 (void) SyncImageSettings(mogrify_info,*image);
2245 if (*option == '+')
2246 preview_type=UndefinedPreview;
2247 else
2248 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2249 MagickFalse,argv[i+1]);
2250 mogrify_image=PreviewImage(*image,preview_type,exception);
2251 break;
2252 }
2253 if (LocaleCompare("profile",option+1) == 0)
2254 {
2255 const char
2256 *name;
2257
2258 const StringInfo
2259 *profile;
2260
2261 Image
2262 *profile_image;
2263
2264 ImageInfo
2265 *profile_info;
2266
2267 (void) SyncImageSettings(mogrify_info,*image);
2268 if (*option == '+')
2269 {
2270 /*
2271 Remove a profile from the image.
2272 */
2273 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2274 NULL,0,MagickTrue);
2275 InheritException(exception,&(*image)->exception);
2276 break;
2277 }
2278 /*
2279 Associate a profile with the image.
2280 */
2281 profile_info=CloneImageInfo(mogrify_info);
2282 profile=GetImageProfile(*image,"iptc");
2283 if (profile != (StringInfo *) NULL)
2284 profile_info->profile=(void *) CloneStringInfo(profile);
2285 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2286 profile_info=DestroyImageInfo(profile_info);
2287 if (profile_image == (Image *) NULL)
2288 {
2289 StringInfo
2290 *profile;
2291
2292 profile_info=CloneImageInfo(mogrify_info);
2293 (void) CopyMagickString(profile_info->filename,argv[i+1],
2294 MaxTextExtent);
2295 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2296 if (profile != (StringInfo *) NULL)
2297 {
2298 (void) ProfileImage(*image,profile_info->magick,
2299 GetStringInfoDatum(profile),(size_t)
2300 GetStringInfoLength(profile),MagickFalse);
2301 profile=DestroyStringInfo(profile);
2302 }
2303 profile_info=DestroyImageInfo(profile_info);
2304 break;
2305 }
2306 ResetImageProfileIterator(profile_image);
2307 name=GetNextImageProfile(profile_image);
2308 while (name != (const char *) NULL)
2309 {
2310 profile=GetImageProfile(profile_image,name);
2311 if (profile != (StringInfo *) NULL)
2312 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2313 (size_t) GetStringInfoLength(profile),MagickFalse);
2314 name=GetNextImageProfile(profile_image);
2315 }
2316 profile_image=DestroyImage(profile_image);
2317 break;
2318 }
2319 break;
2320 }
2321 case 'q':
2322 {
2323 if (LocaleCompare("quantize",option+1) == 0)
2324 {
2325 if (*option == '+')
2326 {
2327 quantize_info->colorspace=UndefinedColorspace;
2328 break;
2329 }
2330 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2331 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2332 break;
2333 }
2334 break;
2335 }
2336 case 'r':
2337 {
2338 if (LocaleCompare("radial-blur",option+1) == 0)
2339 {
2340 /*
2341 Radial blur image.
2342 */
2343 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002344 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2345 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002346 break;
2347 }
2348 if (LocaleCompare("raise",option+1) == 0)
2349 {
2350 /*
2351 Surround image with a raise of solid color.
2352 */
2353 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2354 if ((flags & SigmaValue) == 0)
2355 geometry.height=geometry.width;
2356 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002357 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002358 break;
2359 }
2360 if (LocaleCompare("random-threshold",option+1) == 0)
2361 {
2362 /*
2363 Threshold image.
2364 */
2365 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002366 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002367 break;
2368 }
2369 if (LocaleCompare("recolor",option+1) == 0)
2370 {
2371 KernelInfo
2372 *kernel;
2373
2374 (void) SyncImageSettings(mogrify_info,*image);
2375 kernel=AcquireKernelInfo(argv[i+1]);
2376 if (kernel == (KernelInfo *) NULL)
2377 break;
2378 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2379 kernel=DestroyKernelInfo(kernel);
2380 break;
2381 }
2382 if (LocaleCompare("region",option+1) == 0)
2383 {
2384 (void) SyncImageSettings(mogrify_info,*image);
2385 if (region_image != (Image *) NULL)
2386 {
2387 /*
2388 Composite region.
2389 */
2390 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002391 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2392 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002393 InheritException(exception,&region_image->exception);
2394 *image=DestroyImage(*image);
2395 *image=region_image;
2396 region_image = (Image *) NULL;
2397 }
2398 if (*option == '+')
2399 break;
2400 /*
2401 Apply transformations to a selected region of the image.
2402 */
cristy3ed852e2009-09-05 21:47:34 +00002403 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2404 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002405 mogrify_image=CropImage(*image,&region_geometry,exception);
2406 if (mogrify_image == (Image *) NULL)
2407 break;
2408 region_image=(*image);
2409 *image=mogrify_image;
2410 mogrify_image=(Image *) NULL;
2411 break;
cristy3ed852e2009-09-05 21:47:34 +00002412 }
anthonydf8ebac2011-04-27 09:03:19 +00002413 if (LocaleCompare("render",option+1) == 0)
2414 {
2415 (void) SyncImageSettings(mogrify_info,*image);
2416 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2417 break;
2418 }
2419 if (LocaleCompare("remap",option+1) == 0)
2420 {
2421 Image
2422 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002423
anthonydf8ebac2011-04-27 09:03:19 +00002424 /*
2425 Transform image colors to match this set of colors.
2426 */
2427 (void) SyncImageSettings(mogrify_info,*image);
2428 if (*option == '+')
2429 break;
2430 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2431 if (remap_image == (Image *) NULL)
2432 break;
cristy018f07f2011-09-04 21:15:19 +00002433 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002434 remap_image=DestroyImage(remap_image);
2435 break;
2436 }
2437 if (LocaleCompare("repage",option+1) == 0)
2438 {
2439 if (*option == '+')
2440 {
2441 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2442 break;
2443 }
2444 (void) ResetImagePage(*image,argv[i+1]);
2445 InheritException(exception,&(*image)->exception);
2446 break;
2447 }
2448 if (LocaleCompare("resample",option+1) == 0)
2449 {
2450 /*
2451 Resample image.
2452 */
2453 (void) SyncImageSettings(mogrify_info,*image);
2454 flags=ParseGeometry(argv[i+1],&geometry_info);
2455 if ((flags & SigmaValue) == 0)
2456 geometry_info.sigma=geometry_info.rho;
2457 mogrify_image=ResampleImage(*image,geometry_info.rho,
2458 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2459 break;
2460 }
2461 if (LocaleCompare("resize",option+1) == 0)
2462 {
2463 /*
2464 Resize image.
2465 */
2466 (void) SyncImageSettings(mogrify_info,*image);
2467 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2468 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2469 (*image)->filter,(*image)->blur,exception);
2470 break;
2471 }
2472 if (LocaleCompare("roll",option+1) == 0)
2473 {
2474 /*
2475 Roll image.
2476 */
2477 (void) SyncImageSettings(mogrify_info,*image);
2478 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2479 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2480 break;
2481 }
2482 if (LocaleCompare("rotate",option+1) == 0)
2483 {
2484 char
2485 *geometry;
2486
2487 /*
2488 Check for conditional image rotation.
2489 */
2490 (void) SyncImageSettings(mogrify_info,*image);
2491 if (strchr(argv[i+1],'>') != (char *) NULL)
2492 if ((*image)->columns <= (*image)->rows)
2493 break;
2494 if (strchr(argv[i+1],'<') != (char *) NULL)
2495 if ((*image)->columns >= (*image)->rows)
2496 break;
2497 /*
2498 Rotate image.
2499 */
2500 geometry=ConstantString(argv[i+1]);
2501 (void) SubstituteString(&geometry,">","");
2502 (void) SubstituteString(&geometry,"<","");
2503 (void) ParseGeometry(geometry,&geometry_info);
2504 geometry=DestroyString(geometry);
2505 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2506 break;
2507 }
2508 break;
2509 }
2510 case 's':
2511 {
2512 if (LocaleCompare("sample",option+1) == 0)
2513 {
2514 /*
2515 Sample image with pixel replication.
2516 */
2517 (void) SyncImageSettings(mogrify_info,*image);
2518 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2519 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2520 exception);
2521 break;
2522 }
2523 if (LocaleCompare("scale",option+1) == 0)
2524 {
2525 /*
2526 Resize image.
2527 */
2528 (void) SyncImageSettings(mogrify_info,*image);
2529 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2530 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2531 exception);
2532 break;
2533 }
2534 if (LocaleCompare("selective-blur",option+1) == 0)
2535 {
2536 /*
2537 Selectively blur pixels within a contrast threshold.
2538 */
2539 (void) SyncImageSettings(mogrify_info,*image);
2540 flags=ParseGeometry(argv[i+1],&geometry_info);
2541 if ((flags & PercentValue) != 0)
2542 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002543 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2544 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002545 break;
2546 }
2547 if (LocaleCompare("separate",option+1) == 0)
2548 {
2549 /*
2550 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002551 */
2552 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002553 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002554 break;
2555 }
2556 if (LocaleCompare("sepia-tone",option+1) == 0)
2557 {
2558 double
2559 threshold;
2560
2561 /*
2562 Sepia-tone image.
2563 */
2564 (void) SyncImageSettings(mogrify_info,*image);
2565 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2566 mogrify_image=SepiaToneImage(*image,threshold,exception);
2567 break;
2568 }
2569 if (LocaleCompare("segment",option+1) == 0)
2570 {
2571 /*
2572 Segment image.
2573 */
2574 (void) SyncImageSettings(mogrify_info,*image);
2575 flags=ParseGeometry(argv[i+1],&geometry_info);
2576 if ((flags & SigmaValue) == 0)
2577 geometry_info.sigma=1.0;
2578 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002579 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2580 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002581 break;
2582 }
2583 if (LocaleCompare("set",option+1) == 0)
2584 {
2585 char
2586 *value;
2587
2588 /*
2589 Set image option.
2590 */
2591 if (*option == '+')
2592 {
2593 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2594 (void) DeleteImageRegistry(argv[i+1]+9);
2595 else
2596 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2597 {
2598 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2599 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2600 }
2601 else
2602 (void) DeleteImageProperty(*image,argv[i+1]);
2603 break;
2604 }
cristy018f07f2011-09-04 21:15:19 +00002605 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2606 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002607 if (value == (char *) NULL)
2608 break;
2609 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2610 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2611 exception);
2612 else
2613 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2614 {
2615 (void) SetImageOption(image_info,argv[i+1]+7,value);
2616 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2617 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2618 }
2619 else
2620 (void) SetImageProperty(*image,argv[i+1],value);
2621 value=DestroyString(value);
2622 break;
2623 }
2624 if (LocaleCompare("shade",option+1) == 0)
2625 {
2626 /*
2627 Shade image.
2628 */
2629 (void) SyncImageSettings(mogrify_info,*image);
2630 flags=ParseGeometry(argv[i+1],&geometry_info);
2631 if ((flags & SigmaValue) == 0)
2632 geometry_info.sigma=1.0;
2633 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2634 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2635 break;
2636 }
2637 if (LocaleCompare("shadow",option+1) == 0)
2638 {
2639 /*
2640 Shadow image.
2641 */
2642 (void) SyncImageSettings(mogrify_info,*image);
2643 flags=ParseGeometry(argv[i+1],&geometry_info);
2644 if ((flags & SigmaValue) == 0)
2645 geometry_info.sigma=1.0;
2646 if ((flags & XiValue) == 0)
2647 geometry_info.xi=4.0;
2648 if ((flags & PsiValue) == 0)
2649 geometry_info.psi=4.0;
2650 mogrify_image=ShadowImage(*image,geometry_info.rho,
2651 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2652 ceil(geometry_info.psi-0.5),exception);
2653 break;
2654 }
2655 if (LocaleCompare("sharpen",option+1) == 0)
2656 {
2657 /*
2658 Sharpen image.
2659 */
2660 (void) SyncImageSettings(mogrify_info,*image);
2661 flags=ParseGeometry(argv[i+1],&geometry_info);
2662 if ((flags & SigmaValue) == 0)
2663 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002664 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002665 geometry_info.sigma,exception);
2666 break;
2667 }
2668 if (LocaleCompare("shave",option+1) == 0)
2669 {
2670 /*
2671 Shave the image edges.
2672 */
2673 (void) SyncImageSettings(mogrify_info,*image);
2674 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2675 mogrify_image=ShaveImage(*image,&geometry,exception);
2676 break;
2677 }
2678 if (LocaleCompare("shear",option+1) == 0)
2679 {
2680 /*
2681 Shear image.
2682 */
2683 (void) SyncImageSettings(mogrify_info,*image);
2684 flags=ParseGeometry(argv[i+1],&geometry_info);
2685 if ((flags & SigmaValue) == 0)
2686 geometry_info.sigma=geometry_info.rho;
2687 mogrify_image=ShearImage(*image,geometry_info.rho,
2688 geometry_info.sigma,exception);
2689 break;
2690 }
2691 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2692 {
2693 /*
2694 Sigmoidal non-linearity contrast control.
2695 */
2696 (void) SyncImageSettings(mogrify_info,*image);
2697 flags=ParseGeometry(argv[i+1],&geometry_info);
2698 if ((flags & SigmaValue) == 0)
2699 geometry_info.sigma=(double) QuantumRange/2.0;
2700 if ((flags & PercentValue) != 0)
2701 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2702 100.0;
cristy9ee60942011-07-06 14:54:38 +00002703 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002704 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2705 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002706 break;
2707 }
2708 if (LocaleCompare("sketch",option+1) == 0)
2709 {
2710 /*
2711 Sketch image.
2712 */
2713 (void) SyncImageSettings(mogrify_info,*image);
2714 flags=ParseGeometry(argv[i+1],&geometry_info);
2715 if ((flags & SigmaValue) == 0)
2716 geometry_info.sigma=1.0;
2717 mogrify_image=SketchImage(*image,geometry_info.rho,
2718 geometry_info.sigma,geometry_info.xi,exception);
2719 break;
2720 }
2721 if (LocaleCompare("solarize",option+1) == 0)
2722 {
2723 double
2724 threshold;
2725
2726 (void) SyncImageSettings(mogrify_info,*image);
2727 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002728 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002729 break;
2730 }
2731 if (LocaleCompare("sparse-color",option+1) == 0)
2732 {
2733 SparseColorMethod
2734 method;
2735
2736 char
2737 *arguments;
2738
2739 /*
2740 Sparse Color Interpolated Gradient
2741 */
2742 (void) SyncImageSettings(mogrify_info,*image);
2743 method=(SparseColorMethod) ParseCommandOption(
2744 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002745 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2746 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002747 if (arguments == (char *) NULL)
2748 break;
cristy3884f692011-07-08 18:00:18 +00002749 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002750 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2751 arguments=DestroyString(arguments);
2752 break;
2753 }
2754 if (LocaleCompare("splice",option+1) == 0)
2755 {
2756 /*
2757 Splice a solid color into the image.
2758 */
2759 (void) SyncImageSettings(mogrify_info,*image);
2760 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2761 mogrify_image=SpliceImage(*image,&geometry,exception);
2762 break;
2763 }
2764 if (LocaleCompare("spread",option+1) == 0)
2765 {
2766 /*
2767 Spread an image.
2768 */
2769 (void) SyncImageSettings(mogrify_info,*image);
2770 (void) ParseGeometry(argv[i+1],&geometry_info);
2771 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2772 break;
2773 }
2774 if (LocaleCompare("statistic",option+1) == 0)
2775 {
2776 StatisticType
2777 type;
2778
2779 (void) SyncImageSettings(mogrify_info,*image);
2780 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2781 MagickFalse,argv[i+1]);
2782 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002783 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2784 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002785 break;
2786 }
2787 if (LocaleCompare("stretch",option+1) == 0)
2788 {
2789 if (*option == '+')
2790 {
2791 draw_info->stretch=UndefinedStretch;
2792 break;
2793 }
2794 draw_info->stretch=(StretchType) ParseCommandOption(
2795 MagickStretchOptions,MagickFalse,argv[i+1]);
2796 break;
2797 }
2798 if (LocaleCompare("strip",option+1) == 0)
2799 {
2800 /*
2801 Strip image of profiles and comments.
2802 */
2803 (void) SyncImageSettings(mogrify_info,*image);
2804 (void) StripImage(*image);
2805 InheritException(exception,&(*image)->exception);
2806 break;
2807 }
2808 if (LocaleCompare("stroke",option+1) == 0)
2809 {
2810 ExceptionInfo
2811 *sans;
2812
2813 if (*option == '+')
2814 {
2815 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2816 if (draw_info->stroke_pattern != (Image *) NULL)
2817 draw_info->stroke_pattern=DestroyImage(
2818 draw_info->stroke_pattern);
2819 break;
2820 }
2821 sans=AcquireExceptionInfo();
2822 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2823 sans=DestroyExceptionInfo(sans);
2824 if (status == MagickFalse)
2825 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2826 exception);
2827 break;
2828 }
2829 if (LocaleCompare("strokewidth",option+1) == 0)
2830 {
cristyc1acd842011-05-19 23:05:47 +00002831 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2832 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002833 break;
2834 }
2835 if (LocaleCompare("style",option+1) == 0)
2836 {
2837 if (*option == '+')
2838 {
2839 draw_info->style=UndefinedStyle;
2840 break;
2841 }
2842 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2843 MagickFalse,argv[i+1]);
2844 break;
2845 }
2846 if (LocaleCompare("swirl",option+1) == 0)
2847 {
2848 /*
2849 Swirl image.
2850 */
2851 (void) SyncImageSettings(mogrify_info,*image);
2852 (void) ParseGeometry(argv[i+1],&geometry_info);
2853 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2854 break;
2855 }
2856 break;
2857 }
2858 case 't':
2859 {
2860 if (LocaleCompare("threshold",option+1) == 0)
2861 {
2862 double
2863 threshold;
2864
2865 /*
2866 Threshold image.
2867 */
2868 (void) SyncImageSettings(mogrify_info,*image);
2869 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002870 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002871 else
2872 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002873 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002874 InheritException(exception,&(*image)->exception);
2875 break;
2876 }
2877 if (LocaleCompare("thumbnail",option+1) == 0)
2878 {
2879 /*
2880 Thumbnail image.
2881 */
2882 (void) SyncImageSettings(mogrify_info,*image);
2883 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2884 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2885 exception);
2886 break;
2887 }
2888 if (LocaleCompare("tile",option+1) == 0)
2889 {
2890 if (*option == '+')
2891 {
2892 if (draw_info->fill_pattern != (Image *) NULL)
2893 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2894 break;
2895 }
2896 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2897 exception);
2898 break;
2899 }
2900 if (LocaleCompare("tint",option+1) == 0)
2901 {
2902 /*
2903 Tint the image.
2904 */
2905 (void) SyncImageSettings(mogrify_info,*image);
2906 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2907 break;
2908 }
2909 if (LocaleCompare("transform",option+1) == 0)
2910 {
2911 /*
2912 Affine transform image.
2913 */
2914 (void) SyncImageSettings(mogrify_info,*image);
2915 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2916 exception);
2917 break;
2918 }
2919 if (LocaleCompare("transparent",option+1) == 0)
2920 {
cristy4c08aed2011-07-01 19:47:50 +00002921 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002922 target;
2923
2924 (void) SyncImageSettings(mogrify_info,*image);
2925 (void) QueryMagickColor(argv[i+1],&target,exception);
2926 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002927 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2928 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002929 break;
2930 }
2931 if (LocaleCompare("transpose",option+1) == 0)
2932 {
2933 /*
2934 Transpose image scanlines.
2935 */
2936 (void) SyncImageSettings(mogrify_info,*image);
2937 mogrify_image=TransposeImage(*image,exception);
2938 break;
2939 }
2940 if (LocaleCompare("transverse",option+1) == 0)
2941 {
2942 /*
2943 Transverse image scanlines.
2944 */
2945 (void) SyncImageSettings(mogrify_info,*image);
2946 mogrify_image=TransverseImage(*image,exception);
2947 break;
2948 }
2949 if (LocaleCompare("treedepth",option+1) == 0)
2950 {
2951 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2952 break;
2953 }
2954 if (LocaleCompare("trim",option+1) == 0)
2955 {
2956 /*
2957 Trim image.
2958 */
2959 (void) SyncImageSettings(mogrify_info,*image);
2960 mogrify_image=TrimImage(*image,exception);
2961 break;
2962 }
2963 if (LocaleCompare("type",option+1) == 0)
2964 {
2965 ImageType
2966 type;
2967
2968 (void) SyncImageSettings(mogrify_info,*image);
2969 if (*option == '+')
2970 type=UndefinedType;
2971 else
2972 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2973 argv[i+1]);
2974 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00002975 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002976 break;
2977 }
2978 break;
2979 }
2980 case 'u':
2981 {
2982 if (LocaleCompare("undercolor",option+1) == 0)
2983 {
2984 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
2985 exception);
2986 break;
2987 }
2988 if (LocaleCompare("unique",option+1) == 0)
2989 {
2990 if (*option == '+')
2991 {
2992 (void) DeleteImageArtifact(*image,"identify:unique-colors");
2993 break;
2994 }
2995 (void) SetImageArtifact(*image,"identify:unique-colors","true");
2996 (void) SetImageArtifact(*image,"verbose","true");
2997 break;
2998 }
2999 if (LocaleCompare("unique-colors",option+1) == 0)
3000 {
3001 /*
3002 Unique image colors.
3003 */
3004 (void) SyncImageSettings(mogrify_info,*image);
3005 mogrify_image=UniqueImageColors(*image,exception);
3006 break;
3007 }
3008 if (LocaleCompare("unsharp",option+1) == 0)
3009 {
3010 /*
3011 Unsharp mask image.
3012 */
3013 (void) SyncImageSettings(mogrify_info,*image);
3014 flags=ParseGeometry(argv[i+1],&geometry_info);
3015 if ((flags & SigmaValue) == 0)
3016 geometry_info.sigma=1.0;
3017 if ((flags & XiValue) == 0)
3018 geometry_info.xi=1.0;
3019 if ((flags & PsiValue) == 0)
3020 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003021 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3022 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003023 break;
3024 }
3025 break;
3026 }
3027 case 'v':
3028 {
3029 if (LocaleCompare("verbose",option+1) == 0)
3030 {
3031 (void) SetImageArtifact(*image,option+1,
3032 *option == '+' ? "false" : "true");
3033 break;
3034 }
3035 if (LocaleCompare("vignette",option+1) == 0)
3036 {
3037 /*
3038 Vignette image.
3039 */
3040 (void) SyncImageSettings(mogrify_info,*image);
3041 flags=ParseGeometry(argv[i+1],&geometry_info);
3042 if ((flags & SigmaValue) == 0)
3043 geometry_info.sigma=1.0;
3044 if ((flags & XiValue) == 0)
3045 geometry_info.xi=0.1*(*image)->columns;
3046 if ((flags & PsiValue) == 0)
3047 geometry_info.psi=0.1*(*image)->rows;
3048 mogrify_image=VignetteImage(*image,geometry_info.rho,
3049 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3050 ceil(geometry_info.psi-0.5),exception);
3051 break;
3052 }
3053 if (LocaleCompare("virtual-pixel",option+1) == 0)
3054 {
3055 if (*option == '+')
3056 {
3057 (void) SetImageVirtualPixelMethod(*image,
3058 UndefinedVirtualPixelMethod);
3059 break;
3060 }
3061 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3062 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3063 argv[i+1]));
3064 break;
3065 }
3066 break;
3067 }
3068 case 'w':
3069 {
3070 if (LocaleCompare("wave",option+1) == 0)
3071 {
3072 /*
3073 Wave image.
3074 */
3075 (void) SyncImageSettings(mogrify_info,*image);
3076 flags=ParseGeometry(argv[i+1],&geometry_info);
3077 if ((flags & SigmaValue) == 0)
3078 geometry_info.sigma=1.0;
3079 mogrify_image=WaveImage(*image,geometry_info.rho,
3080 geometry_info.sigma,exception);
3081 break;
3082 }
3083 if (LocaleCompare("weight",option+1) == 0)
3084 {
3085 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3086 if (LocaleCompare(argv[i+1],"all") == 0)
3087 draw_info->weight=0;
3088 if (LocaleCompare(argv[i+1],"bold") == 0)
3089 draw_info->weight=700;
3090 if (LocaleCompare(argv[i+1],"bolder") == 0)
3091 if (draw_info->weight <= 800)
3092 draw_info->weight+=100;
3093 if (LocaleCompare(argv[i+1],"lighter") == 0)
3094 if (draw_info->weight >= 100)
3095 draw_info->weight-=100;
3096 if (LocaleCompare(argv[i+1],"normal") == 0)
3097 draw_info->weight=400;
3098 break;
3099 }
3100 if (LocaleCompare("white-threshold",option+1) == 0)
3101 {
3102 /*
3103 White threshold image.
3104 */
3105 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003106 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003107 InheritException(exception,&(*image)->exception);
3108 break;
3109 }
3110 break;
3111 }
3112 default:
3113 break;
3114 }
3115 /*
3116 Replace current image with any image that was generated
3117 */
3118 if (mogrify_image != (Image *) NULL)
3119 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003120 i+=count;
3121 }
3122 if (region_image != (Image *) NULL)
3123 {
anthonydf8ebac2011-04-27 09:03:19 +00003124 /*
3125 Composite transformed region onto image.
3126 */
cristy6b3da3a2010-06-20 02:21:46 +00003127 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003128 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003129 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3130 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003131 InheritException(exception,&region_image->exception);
3132 *image=DestroyImage(*image);
3133 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003134 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003135 }
3136 /*
3137 Free resources.
3138 */
anthonydf8ebac2011-04-27 09:03:19 +00003139 quantize_info=DestroyQuantizeInfo(quantize_info);
3140 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003141 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003142 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003143 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003144 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003145}
3146
3147/*
3148%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3149% %
3150% %
3151% %
cristy5063d812010-10-19 16:28:10 +00003152+ 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 +00003153% %
3154% %
3155% %
3156%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3157%
3158% MogrifyImageCommand() transforms an image or a sequence of images. These
3159% transforms include image scaling, image rotation, color reduction, and
3160% others. The transmogrified image overwrites the original image.
3161%
3162% The format of the MogrifyImageCommand method is:
3163%
3164% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3165% const char **argv,char **metadata,ExceptionInfo *exception)
3166%
3167% A description of each parameter follows:
3168%
3169% o image_info: the image info.
3170%
3171% o argc: the number of elements in the argument vector.
3172%
3173% o argv: A text array containing the command line arguments.
3174%
3175% o metadata: any metadata is returned here.
3176%
3177% o exception: return any errors or warnings in this structure.
3178%
3179*/
3180
3181static MagickBooleanType MogrifyUsage(void)
3182{
3183 static const char
3184 *miscellaneous[]=
3185 {
3186 "-debug events display copious debugging information",
3187 "-help print program options",
3188 "-list type print a list of supported option arguments",
3189 "-log format format of debugging information",
3190 "-version print version information",
3191 (char *) NULL
3192 },
3193 *operators[]=
3194 {
3195 "-adaptive-blur geometry",
3196 " adaptively blur pixels; decrease effect near edges",
3197 "-adaptive-resize geometry",
3198 " adaptively resize image using 'mesh' interpolation",
3199 "-adaptive-sharpen geometry",
3200 " adaptively sharpen pixels; increase effect near edges",
3201 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3202 " transparent, extract, background, or shape",
3203 "-annotate geometry text",
3204 " annotate the image with text",
3205 "-auto-gamma automagically adjust gamma level of image",
3206 "-auto-level automagically adjust color levels of image",
3207 "-auto-orient automagically orient (rotate) image",
3208 "-bench iterations measure performance",
3209 "-black-threshold value",
3210 " force all pixels below the threshold into black",
3211 "-blue-shift simulate a scene at nighttime in the moonlight",
3212 "-blur geometry reduce image noise and reduce detail levels",
3213 "-border geometry surround image with a border of color",
3214 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003215 "-brightness-contrast geometry",
3216 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003217 "-cdl filename color correct with a color decision list",
3218 "-charcoal radius simulate a charcoal drawing",
3219 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003220 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003221 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003222 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003223 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003224 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003225 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003226 "-contrast enhance or reduce the image contrast",
3227 "-contrast-stretch geometry",
3228 " improve contrast by `stretching' the intensity range",
3229 "-convolve coefficients",
3230 " apply a convolution kernel to the image",
3231 "-cycle amount cycle the image colormap",
3232 "-decipher filename convert cipher pixels to plain pixels",
3233 "-deskew threshold straighten an image",
3234 "-despeckle reduce the speckles within an image",
3235 "-distort method args",
3236 " distort images according to given method ad args",
3237 "-draw string annotate the image with a graphic primitive",
3238 "-edge radius apply a filter to detect edges in the image",
3239 "-encipher filename convert plain pixels to cipher pixels",
3240 "-emboss radius emboss an image",
3241 "-enhance apply a digital filter to enhance a noisy image",
3242 "-equalize perform histogram equalization to an image",
3243 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003244 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003245 "-extent geometry set the image size",
3246 "-extract geometry extract area from image",
3247 "-fft implements the discrete Fourier transform (DFT)",
3248 "-flip flip image vertically",
3249 "-floodfill geometry color",
3250 " floodfill the image with color",
3251 "-flop flop image horizontally",
3252 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003253 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003254 " apply function over image values",
3255 "-gamma value level of gamma correction",
3256 "-gaussian-blur geometry",
3257 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003258 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003259 "-identify identify the format and characteristics of the image",
3260 "-ift implements the inverse discrete Fourier transform (DFT)",
3261 "-implode amount implode image pixels about the center",
3262 "-lat geometry local adaptive thresholding",
3263 "-layers method optimize, merge, or compare image layers",
3264 "-level value adjust the level of image contrast",
3265 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003266 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003267 "-linear-stretch geometry",
3268 " improve contrast by `stretching with saturation'",
3269 "-liquid-rescale geometry",
3270 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003271 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003272 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003273 "-modulate value vary the brightness, saturation, and hue",
3274 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003275 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003276 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003277 "-motion-blur geometry",
3278 " simulate motion blur",
3279 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003280 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003281 "-normalize transform image to span the full range of colors",
3282 "-opaque color change this color to the fill color",
3283 "-ordered-dither NxN",
3284 " add a noise pattern to the image with specific",
3285 " amplitudes",
3286 "-paint radius simulate an oil painting",
3287 "-polaroid angle simulate a Polaroid picture",
3288 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003289 "-profile filename add, delete, or apply an image profile",
3290 "-quantize colorspace reduce colors in this colorspace",
3291 "-radial-blur angle radial blur the image",
3292 "-raise value lighten/darken image edges to create a 3-D effect",
3293 "-random-threshold low,high",
3294 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003295 "-region geometry apply options to a portion of the image",
3296 "-render render vector graphics",
3297 "-repage geometry size and location of an image canvas",
3298 "-resample geometry change the resolution of an image",
3299 "-resize geometry resize the image",
3300 "-roll geometry roll an image vertically or horizontally",
3301 "-rotate degrees apply Paeth rotation to the image",
3302 "-sample geometry scale image with pixel sampling",
3303 "-scale geometry scale the image",
3304 "-segment values segment an image",
3305 "-selective-blur geometry",
3306 " selectively blur pixels within a contrast threshold",
3307 "-sepia-tone threshold",
3308 " simulate a sepia-toned photo",
3309 "-set property value set an image property",
3310 "-shade degrees shade the image using a distant light source",
3311 "-shadow geometry simulate an image shadow",
3312 "-sharpen geometry sharpen the image",
3313 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003314 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003315 "-sigmoidal-contrast geometry",
3316 " increase the contrast without saturating highlights or shadows",
3317 "-sketch geometry simulate a pencil sketch",
3318 "-solarize threshold negate all pixels above the threshold level",
3319 "-sparse-color method args",
3320 " fill in a image based on a few color points",
3321 "-splice geometry splice the background color into the image",
3322 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003323 "-statistic type radius",
3324 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003325 "-strip strip image of all profiles and comments",
3326 "-swirl degrees swirl image pixels about the center",
3327 "-threshold value threshold the image",
3328 "-thumbnail geometry create a thumbnail of the image",
3329 "-tile filename tile image when filling a graphic primitive",
3330 "-tint value tint the image with the fill color",
3331 "-transform affine transform image",
3332 "-transparent color make this color transparent within the image",
3333 "-transpose flip image vertically and rotate 90 degrees",
3334 "-transverse flop image horizontally and rotate 270 degrees",
3335 "-trim trim image edges",
3336 "-type type image type",
3337 "-unique-colors discard all but one of any pixel color",
3338 "-unsharp geometry sharpen the image",
3339 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003340 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003341 "-white-threshold value",
3342 " force all pixels above the threshold into white",
3343 (char *) NULL
3344 },
3345 *sequence_operators[]=
3346 {
cristy4285d782011-02-09 20:12:28 +00003347 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003348 "-clut apply a color lookup table to the image",
3349 "-coalesce merge a sequence of images",
3350 "-combine combine a sequence of images",
3351 "-composite composite image",
3352 "-crop geometry cut out a rectangular region of the image",
3353 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003354 "-evaluate-sequence operator",
3355 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003356 "-flatten flatten a sequence of images",
3357 "-fx expression apply mathematical expression to an image channel(s)",
3358 "-hald-clut apply a Hald color lookup table to the image",
3359 "-morph value morph an image sequence",
3360 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003361 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003362 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003363 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003364 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003365 "-write filename write images to this file",
3366 (char *) NULL
3367 },
3368 *settings[]=
3369 {
3370 "-adjoin join images into a single multi-image file",
3371 "-affine matrix affine transform matrix",
3372 "-alpha option activate, deactivate, reset, or set the alpha channel",
3373 "-antialias remove pixel-aliasing",
3374 "-authenticate password",
3375 " decipher image with this password",
3376 "-attenuate value lessen (or intensify) when adding noise to an image",
3377 "-background color background color",
3378 "-bias value add bias when convolving an image",
3379 "-black-point-compensation",
3380 " use black point compensation",
3381 "-blue-primary point chromaticity blue primary point",
3382 "-bordercolor color border color",
3383 "-caption string assign a caption to an image",
3384 "-channel type apply option to select image channels",
3385 "-colors value preferred number of colors in the image",
3386 "-colorspace type alternate image colorspace",
3387 "-comment string annotate image with comment",
3388 "-compose operator set image composite operator",
3389 "-compress type type of pixel compression when writing the image",
3390 "-define format:option",
3391 " define one or more image format options",
3392 "-delay value display the next image after pausing",
3393 "-density geometry horizontal and vertical density of the image",
3394 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003395 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003396 "-display server get image or font from this X server",
3397 "-dispose method layer disposal method",
3398 "-dither method apply error diffusion to image",
3399 "-encoding type text encoding type",
3400 "-endian type endianness (MSB or LSB) of the image",
3401 "-family name render text with this font family",
3402 "-fill color color to use when filling a graphic primitive",
3403 "-filter type use this filter when resizing an image",
3404 "-font name render text with this font",
3405 "-format \"string\" output formatted image characteristics",
3406 "-fuzz distance colors within this distance are considered equal",
3407 "-gravity type horizontal and vertical text placement",
3408 "-green-primary point chromaticity green primary point",
3409 "-intent type type of rendering intent when managing the image color",
3410 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003411 "-interline-spacing value",
3412 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003413 "-interpolate method pixel color interpolation method",
3414 "-interword-spacing value",
3415 " set the space between two words",
3416 "-kerning value set the space between two letters",
3417 "-label string assign a label to an image",
3418 "-limit type value pixel cache resource limit",
3419 "-loop iterations add Netscape loop extension to your GIF animation",
3420 "-mask filename associate a mask with the image",
3421 "-mattecolor color frame color",
3422 "-monitor monitor progress",
3423 "-orient type image orientation",
3424 "-page geometry size and location of an image canvas (setting)",
3425 "-ping efficiently determine image attributes",
3426 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003427 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003428 "-preview type image preview type",
3429 "-quality value JPEG/MIFF/PNG compression level",
3430 "-quiet suppress all warning messages",
3431 "-red-primary point chromaticity red primary point",
3432 "-regard-warnings pay attention to warning messages",
3433 "-remap filename transform image colors to match this set of colors",
3434 "-respect-parentheses settings remain in effect until parenthesis boundary",
3435 "-sampling-factor geometry",
3436 " horizontal and vertical sampling factor",
3437 "-scene value image scene number",
3438 "-seed value seed a new sequence of pseudo-random numbers",
3439 "-size geometry width and height of image",
3440 "-stretch type render text with this font stretch",
3441 "-stroke color graphic primitive stroke color",
3442 "-strokewidth value graphic primitive stroke width",
3443 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003444 "-synchronize synchronize image to storage device",
3445 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003446 "-texture filename name of texture to tile onto the image background",
3447 "-tile-offset geometry",
3448 " tile offset",
3449 "-treedepth value color tree depth",
3450 "-transparent-color color",
3451 " transparent color",
3452 "-undercolor color annotation bounding box color",
3453 "-units type the units of image resolution",
3454 "-verbose print detailed information about the image",
3455 "-view FlashPix viewing transforms",
3456 "-virtual-pixel method",
3457 " virtual pixel access method",
3458 "-weight type render text with this font weight",
3459 "-white-point point chromaticity white point",
3460 (char *) NULL
3461 },
3462 *stack_operators[]=
3463 {
anthonyb69c4b32011-03-23 04:37:44 +00003464 "-delete indexes delete the image from the image sequence",
3465 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003466 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003467 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003468 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003469 "-swap indexes swap two images in the image sequence",
3470 (char *) NULL
3471 };
3472
3473 const char
3474 **p;
3475
cristybb503372010-05-27 20:51:26 +00003476 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003477 (void) printf("Copyright: %s\n",GetMagickCopyright());
3478 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003479 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3480 GetClientName());
3481 (void) printf("\nImage Settings:\n");
3482 for (p=settings; *p != (char *) NULL; p++)
3483 (void) printf(" %s\n",*p);
3484 (void) printf("\nImage Operators:\n");
3485 for (p=operators; *p != (char *) NULL; p++)
3486 (void) printf(" %s\n",*p);
3487 (void) printf("\nImage Sequence Operators:\n");
3488 for (p=sequence_operators; *p != (char *) NULL; p++)
3489 (void) printf(" %s\n",*p);
3490 (void) printf("\nImage Stack Operators:\n");
3491 for (p=stack_operators; *p != (char *) NULL; p++)
3492 (void) printf(" %s\n",*p);
3493 (void) printf("\nMiscellaneous Options:\n");
3494 for (p=miscellaneous; *p != (char *) NULL; p++)
3495 (void) printf(" %s\n",*p);
3496 (void) printf(
3497 "\nBy default, the image format of `file' is determined by its magic\n");
3498 (void) printf(
3499 "number. To specify a particular image format, precede the filename\n");
3500 (void) printf(
3501 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3502 (void) printf(
3503 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3504 (void) printf("'-' for standard input or output.\n");
3505 return(MagickFalse);
3506}
3507
3508WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3509 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3510{
3511#define DestroyMogrify() \
3512{ \
3513 if (format != (char *) NULL) \
3514 format=DestroyString(format); \
3515 if (path != (char *) NULL) \
3516 path=DestroyString(path); \
3517 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003518 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003519 argv[i]=DestroyString(argv[i]); \
3520 argv=(char **) RelinquishMagickMemory(argv); \
3521}
3522#define ThrowMogrifyException(asperity,tag,option) \
3523{ \
3524 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3525 option); \
3526 DestroyMogrify(); \
3527 return(MagickFalse); \
3528}
3529#define ThrowMogrifyInvalidArgumentException(option,argument) \
3530{ \
3531 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3532 "InvalidArgument","`%s': %s",argument,option); \
3533 DestroyMogrify(); \
3534 return(MagickFalse); \
3535}
3536
3537 char
3538 *format,
3539 *option,
3540 *path;
3541
3542 Image
3543 *image;
3544
3545 ImageStack
3546 image_stack[MaxImageStackDepth+1];
3547
cristy3ed852e2009-09-05 21:47:34 +00003548 MagickBooleanType
3549 global_colormap;
3550
3551 MagickBooleanType
3552 fire,
cristyebbcfea2011-02-25 02:43:54 +00003553 pend,
3554 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003555
3556 MagickStatusType
3557 status;
3558
cristyebbcfea2011-02-25 02:43:54 +00003559 register ssize_t
3560 i;
3561
3562 ssize_t
3563 j,
3564 k;
3565
cristy3ed852e2009-09-05 21:47:34 +00003566 /*
3567 Set defaults.
3568 */
3569 assert(image_info != (ImageInfo *) NULL);
3570 assert(image_info->signature == MagickSignature);
3571 if (image_info->debug != MagickFalse)
3572 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3573 assert(exception != (ExceptionInfo *) NULL);
3574 if (argc == 2)
3575 {
3576 option=argv[1];
3577 if ((LocaleCompare("version",option+1) == 0) ||
3578 (LocaleCompare("-version",option+1) == 0))
3579 {
cristyb51dff52011-05-19 16:55:47 +00003580 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003581 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003582 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3583 GetMagickCopyright());
3584 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3585 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003586 return(MagickFalse);
3587 }
3588 }
3589 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003590 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003591 format=(char *) NULL;
3592 path=(char *) NULL;
3593 global_colormap=MagickFalse;
3594 k=0;
3595 j=1;
3596 NewImageStack();
3597 option=(char *) NULL;
3598 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003599 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003600 status=MagickTrue;
3601 /*
3602 Parse command line.
3603 */
3604 ReadCommandlLine(argc,&argv);
3605 status=ExpandFilenames(&argc,&argv);
3606 if (status == MagickFalse)
3607 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3608 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003609 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003610 {
3611 option=argv[i];
3612 if (LocaleCompare(option,"(") == 0)
3613 {
3614 FireImageStack(MagickFalse,MagickTrue,pend);
3615 if (k == MaxImageStackDepth)
3616 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3617 option);
3618 PushImageStack();
3619 continue;
3620 }
3621 if (LocaleCompare(option,")") == 0)
3622 {
3623 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3624 if (k == 0)
3625 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3626 PopImageStack();
3627 continue;
3628 }
cristy042ee782011-04-22 18:48:30 +00003629 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003630 {
3631 char
3632 backup_filename[MaxTextExtent],
3633 *filename;
3634
3635 Image
3636 *images;
3637
3638 /*
3639 Option is a file name: begin by reading image from specified file.
3640 */
3641 FireImageStack(MagickFalse,MagickFalse,pend);
3642 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003643 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003644 filename=argv[++i];
3645 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3646 images=ReadImages(image_info,exception);
3647 status&=(images != (Image *) NULL) &&
3648 (exception->severity < ErrorException);
3649 if (images == (Image *) NULL)
3650 continue;
cristydaa76602010-06-30 13:05:11 +00003651 if (format != (char *) NULL)
3652 (void) CopyMagickString(images->filename,images->magick_filename,
3653 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003654 if (path != (char *) NULL)
3655 {
3656 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003657 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003658 path,*DirectorySeparator,filename);
3659 }
3660 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003661 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003662 AppendImageStack(images);
3663 FinalizeImageSettings(image_info,image,MagickFalse);
3664 if (global_colormap != MagickFalse)
3665 {
3666 QuantizeInfo
3667 *quantize_info;
3668
3669 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003670 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003671 quantize_info=DestroyQuantizeInfo(quantize_info);
3672 }
3673 *backup_filename='\0';
3674 if ((LocaleCompare(image->filename,"-") != 0) &&
3675 (IsPathWritable(image->filename) != MagickFalse))
3676 {
cristybb503372010-05-27 20:51:26 +00003677 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003678 i;
3679
3680 /*
3681 Rename image file as backup.
3682 */
3683 (void) CopyMagickString(backup_filename,image->filename,
3684 MaxTextExtent);
3685 for (i=0; i < 6; i++)
3686 {
3687 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3688 if (IsPathAccessible(backup_filename) == MagickFalse)
3689 break;
3690 }
3691 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3692 (rename(image->filename,backup_filename) != 0))
3693 *backup_filename='\0';
3694 }
3695 /*
3696 Write transmogrified image to disk.
3697 */
3698 image_info->synchronize=MagickTrue;
3699 status&=WriteImages(image_info,image,image->filename,exception);
3700 if ((status == MagickFalse) && (*backup_filename != '\0'))
3701 (void) remove(backup_filename);
3702 RemoveAllImageStack();
3703 continue;
3704 }
3705 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3706 switch (*(option+1))
3707 {
3708 case 'a':
3709 {
3710 if (LocaleCompare("adaptive-blur",option+1) == 0)
3711 {
3712 i++;
cristybb503372010-05-27 20:51:26 +00003713 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003714 ThrowMogrifyException(OptionError,"MissingArgument",option);
3715 if (IsGeometry(argv[i]) == MagickFalse)
3716 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3717 break;
3718 }
3719 if (LocaleCompare("adaptive-resize",option+1) == 0)
3720 {
3721 i++;
cristybb503372010-05-27 20:51:26 +00003722 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003723 ThrowMogrifyException(OptionError,"MissingArgument",option);
3724 if (IsGeometry(argv[i]) == MagickFalse)
3725 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3726 break;
3727 }
3728 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3729 {
3730 i++;
cristybb503372010-05-27 20:51:26 +00003731 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003732 ThrowMogrifyException(OptionError,"MissingArgument",option);
3733 if (IsGeometry(argv[i]) == MagickFalse)
3734 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3735 break;
3736 }
3737 if (LocaleCompare("affine",option+1) == 0)
3738 {
3739 if (*option == '+')
3740 break;
3741 i++;
cristybb503372010-05-27 20:51:26 +00003742 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003743 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003744 break;
3745 }
3746 if (LocaleCompare("alpha",option+1) == 0)
3747 {
cristybb503372010-05-27 20:51:26 +00003748 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003749 type;
3750
3751 if (*option == '+')
3752 break;
3753 i++;
cristybb503372010-05-27 20:51:26 +00003754 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003755 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003756 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003757 if (type < 0)
3758 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3759 argv[i]);
3760 break;
3761 }
3762 if (LocaleCompare("annotate",option+1) == 0)
3763 {
3764 if (*option == '+')
3765 break;
3766 i++;
cristybb503372010-05-27 20:51:26 +00003767 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003768 ThrowMogrifyException(OptionError,"MissingArgument",option);
3769 if (IsGeometry(argv[i]) == MagickFalse)
3770 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003771 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003772 ThrowMogrifyException(OptionError,"MissingArgument",option);
3773 i++;
3774 break;
3775 }
3776 if (LocaleCompare("antialias",option+1) == 0)
3777 break;
3778 if (LocaleCompare("append",option+1) == 0)
3779 break;
3780 if (LocaleCompare("attenuate",option+1) == 0)
3781 {
3782 if (*option == '+')
3783 break;
3784 i++;
cristybb503372010-05-27 20:51:26 +00003785 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003786 ThrowMogrifyException(OptionError,"MissingArgument",option);
3787 if (IsGeometry(argv[i]) == MagickFalse)
3788 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3789 break;
3790 }
3791 if (LocaleCompare("authenticate",option+1) == 0)
3792 {
3793 if (*option == '+')
3794 break;
3795 i++;
cristybb503372010-05-27 20:51:26 +00003796 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003797 ThrowMogrifyException(OptionError,"MissingArgument",option);
3798 break;
3799 }
3800 if (LocaleCompare("auto-gamma",option+1) == 0)
3801 break;
3802 if (LocaleCompare("auto-level",option+1) == 0)
3803 break;
3804 if (LocaleCompare("auto-orient",option+1) == 0)
3805 break;
3806 if (LocaleCompare("average",option+1) == 0)
3807 break;
3808 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3809 }
3810 case 'b':
3811 {
3812 if (LocaleCompare("background",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("bias",option+1) == 0)
3822 {
3823 if (*option == '+')
3824 break;
3825 i++;
cristybb503372010-05-27 20:51:26 +00003826 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003827 ThrowMogrifyException(OptionError,"MissingArgument",option);
3828 if (IsGeometry(argv[i]) == MagickFalse)
3829 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3830 break;
3831 }
3832 if (LocaleCompare("black-point-compensation",option+1) == 0)
3833 break;
3834 if (LocaleCompare("black-threshold",option+1) == 0)
3835 {
3836 if (*option == '+')
3837 break;
3838 i++;
cristybb503372010-05-27 20:51:26 +00003839 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003840 ThrowMogrifyException(OptionError,"MissingArgument",option);
3841 if (IsGeometry(argv[i]) == MagickFalse)
3842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3843 break;
3844 }
3845 if (LocaleCompare("blue-primary",option+1) == 0)
3846 {
3847 if (*option == '+')
3848 break;
3849 i++;
cristybb503372010-05-27 20:51:26 +00003850 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003851 ThrowMogrifyException(OptionError,"MissingArgument",option);
3852 if (IsGeometry(argv[i]) == MagickFalse)
3853 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3854 break;
3855 }
3856 if (LocaleCompare("blue-shift",option+1) == 0)
3857 {
3858 i++;
cristybb503372010-05-27 20:51:26 +00003859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003860 ThrowMogrifyException(OptionError,"MissingArgument",option);
3861 if (IsGeometry(argv[i]) == MagickFalse)
3862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3863 break;
3864 }
3865 if (LocaleCompare("blur",option+1) == 0)
3866 {
3867 i++;
cristybb503372010-05-27 20:51:26 +00003868 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003869 ThrowMogrifyException(OptionError,"MissingArgument",option);
3870 if (IsGeometry(argv[i]) == MagickFalse)
3871 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3872 break;
3873 }
3874 if (LocaleCompare("border",option+1) == 0)
3875 {
3876 if (*option == '+')
3877 break;
3878 i++;
cristybb503372010-05-27 20:51:26 +00003879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003880 ThrowMogrifyException(OptionError,"MissingArgument",option);
3881 if (IsGeometry(argv[i]) == MagickFalse)
3882 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3883 break;
3884 }
3885 if (LocaleCompare("bordercolor",option+1) == 0)
3886 {
3887 if (*option == '+')
3888 break;
3889 i++;
cristybb503372010-05-27 20:51:26 +00003890 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003891 ThrowMogrifyException(OptionError,"MissingArgument",option);
3892 break;
3893 }
3894 if (LocaleCompare("box",option+1) == 0)
3895 {
3896 if (*option == '+')
3897 break;
3898 i++;
cristybb503372010-05-27 20:51:26 +00003899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003900 ThrowMogrifyException(OptionError,"MissingArgument",option);
3901 break;
3902 }
cristya28d6b82010-01-11 20:03:47 +00003903 if (LocaleCompare("brightness-contrast",option+1) == 0)
3904 {
3905 i++;
cristybb503372010-05-27 20:51:26 +00003906 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003907 ThrowMogrifyException(OptionError,"MissingArgument",option);
3908 if (IsGeometry(argv[i]) == MagickFalse)
3909 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3910 break;
3911 }
cristy3ed852e2009-09-05 21:47:34 +00003912 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3913 }
3914 case 'c':
3915 {
3916 if (LocaleCompare("cache",option+1) == 0)
3917 {
3918 if (*option == '+')
3919 break;
3920 i++;
cristybb503372010-05-27 20:51:26 +00003921 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003922 ThrowMogrifyException(OptionError,"MissingArgument",option);
3923 if (IsGeometry(argv[i]) == MagickFalse)
3924 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3925 break;
3926 }
3927 if (LocaleCompare("caption",option+1) == 0)
3928 {
3929 if (*option == '+')
3930 break;
3931 i++;
cristybb503372010-05-27 20:51:26 +00003932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003933 ThrowMogrifyException(OptionError,"MissingArgument",option);
3934 break;
3935 }
3936 if (LocaleCompare("channel",option+1) == 0)
3937 {
cristybb503372010-05-27 20:51:26 +00003938 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003939 channel;
3940
3941 if (*option == '+')
3942 break;
3943 i++;
cristybb503372010-05-27 20:51:26 +00003944 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003945 ThrowMogrifyException(OptionError,"MissingArgument",option);
3946 channel=ParseChannelOption(argv[i]);
3947 if (channel < 0)
3948 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3949 argv[i]);
3950 break;
3951 }
3952 if (LocaleCompare("cdl",option+1) == 0)
3953 {
3954 if (*option == '+')
3955 break;
3956 i++;
cristybb503372010-05-27 20:51:26 +00003957 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003958 ThrowMogrifyException(OptionError,"MissingArgument",option);
3959 break;
3960 }
3961 if (LocaleCompare("charcoal",option+1) == 0)
3962 {
3963 if (*option == '+')
3964 break;
3965 i++;
cristybb503372010-05-27 20:51:26 +00003966 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003967 ThrowMogrifyException(OptionError,"MissingArgument",option);
3968 if (IsGeometry(argv[i]) == MagickFalse)
3969 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3970 break;
3971 }
3972 if (LocaleCompare("chop",option+1) == 0)
3973 {
3974 if (*option == '+')
3975 break;
3976 i++;
cristybb503372010-05-27 20:51:26 +00003977 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003978 ThrowMogrifyException(OptionError,"MissingArgument",option);
3979 if (IsGeometry(argv[i]) == MagickFalse)
3980 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3981 break;
3982 }
cristy1eb45dd2009-09-25 16:38:06 +00003983 if (LocaleCompare("clamp",option+1) == 0)
3984 break;
3985 if (LocaleCompare("clip",option+1) == 0)
3986 break;
cristy3ed852e2009-09-05 21:47:34 +00003987 if (LocaleCompare("clip-mask",option+1) == 0)
3988 {
3989 if (*option == '+')
3990 break;
3991 i++;
cristybb503372010-05-27 20:51:26 +00003992 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003993 ThrowMogrifyException(OptionError,"MissingArgument",option);
3994 break;
3995 }
3996 if (LocaleCompare("clut",option+1) == 0)
3997 break;
3998 if (LocaleCompare("coalesce",option+1) == 0)
3999 break;
4000 if (LocaleCompare("colorize",option+1) == 0)
4001 {
4002 if (*option == '+')
4003 break;
4004 i++;
cristybb503372010-05-27 20:51:26 +00004005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004006 ThrowMogrifyException(OptionError,"MissingArgument",option);
4007 if (IsGeometry(argv[i]) == MagickFalse)
4008 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4009 break;
4010 }
cristye6365592010-04-02 17:31:23 +00004011 if (LocaleCompare("color-matrix",option+1) == 0)
4012 {
cristyb6bd4ad2010-08-08 01:12:27 +00004013 KernelInfo
4014 *kernel_info;
4015
cristye6365592010-04-02 17:31:23 +00004016 if (*option == '+')
4017 break;
4018 i++;
cristybb503372010-05-27 20:51:26 +00004019 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004020 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004021 kernel_info=AcquireKernelInfo(argv[i]);
4022 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004024 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004025 break;
4026 }
cristy3ed852e2009-09-05 21:47:34 +00004027 if (LocaleCompare("colors",option+1) == 0)
4028 {
4029 if (*option == '+')
4030 break;
4031 i++;
cristybb503372010-05-27 20:51:26 +00004032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004033 ThrowMogrifyException(OptionError,"MissingArgument",option);
4034 if (IsGeometry(argv[i]) == MagickFalse)
4035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4036 break;
4037 }
4038 if (LocaleCompare("colorspace",option+1) == 0)
4039 {
cristybb503372010-05-27 20:51:26 +00004040 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004041 colorspace;
4042
4043 if (*option == '+')
4044 break;
4045 i++;
cristybb503372010-05-27 20:51:26 +00004046 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004047 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004048 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004049 argv[i]);
4050 if (colorspace < 0)
4051 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4052 argv[i]);
4053 break;
4054 }
4055 if (LocaleCompare("combine",option+1) == 0)
4056 break;
4057 if (LocaleCompare("comment",option+1) == 0)
4058 {
4059 if (*option == '+')
4060 break;
4061 i++;
cristybb503372010-05-27 20:51:26 +00004062 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004063 ThrowMogrifyException(OptionError,"MissingArgument",option);
4064 break;
4065 }
4066 if (LocaleCompare("composite",option+1) == 0)
4067 break;
4068 if (LocaleCompare("compress",option+1) == 0)
4069 {
cristybb503372010-05-27 20:51:26 +00004070 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004071 compress;
4072
4073 if (*option == '+')
4074 break;
4075 i++;
cristybb503372010-05-27 20:51:26 +00004076 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004077 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004078 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004079 argv[i]);
4080 if (compress < 0)
4081 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4082 argv[i]);
4083 break;
4084 }
cristy22879752009-10-25 23:55:40 +00004085 if (LocaleCompare("concurrent",option+1) == 0)
4086 break;
cristy3ed852e2009-09-05 21:47:34 +00004087 if (LocaleCompare("contrast",option+1) == 0)
4088 break;
4089 if (LocaleCompare("contrast-stretch",option+1) == 0)
4090 {
4091 i++;
cristybb503372010-05-27 20:51:26 +00004092 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004093 ThrowMogrifyException(OptionError,"MissingArgument",option);
4094 if (IsGeometry(argv[i]) == MagickFalse)
4095 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4096 break;
4097 }
4098 if (LocaleCompare("convolve",option+1) == 0)
4099 {
cristyb6bd4ad2010-08-08 01:12:27 +00004100 KernelInfo
4101 *kernel_info;
4102
cristy3ed852e2009-09-05 21:47:34 +00004103 if (*option == '+')
4104 break;
4105 i++;
cristybb503372010-05-27 20:51:26 +00004106 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004107 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004108 kernel_info=AcquireKernelInfo(argv[i]);
4109 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004110 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004111 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004112 break;
4113 }
4114 if (LocaleCompare("crop",option+1) == 0)
4115 {
4116 if (*option == '+')
4117 break;
4118 i++;
cristybb503372010-05-27 20:51:26 +00004119 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004120 ThrowMogrifyException(OptionError,"MissingArgument",option);
4121 if (IsGeometry(argv[i]) == MagickFalse)
4122 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4123 break;
4124 }
4125 if (LocaleCompare("cycle",option+1) == 0)
4126 {
4127 if (*option == '+')
4128 break;
4129 i++;
cristybb503372010-05-27 20:51:26 +00004130 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004131 ThrowMogrifyException(OptionError,"MissingArgument",option);
4132 if (IsGeometry(argv[i]) == MagickFalse)
4133 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4134 break;
4135 }
4136 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4137 }
4138 case 'd':
4139 {
4140 if (LocaleCompare("decipher",option+1) == 0)
4141 {
4142 if (*option == '+')
4143 break;
4144 i++;
cristybb503372010-05-27 20:51:26 +00004145 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004146 ThrowMogrifyException(OptionError,"MissingArgument",option);
4147 break;
4148 }
4149 if (LocaleCompare("deconstruct",option+1) == 0)
4150 break;
4151 if (LocaleCompare("debug",option+1) == 0)
4152 {
cristybb503372010-05-27 20:51:26 +00004153 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004154 event;
4155
4156 if (*option == '+')
4157 break;
4158 i++;
cristybb503372010-05-27 20:51:26 +00004159 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004160 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004161 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004162 if (event < 0)
4163 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4164 argv[i]);
4165 (void) SetLogEventMask(argv[i]);
4166 break;
4167 }
4168 if (LocaleCompare("define",option+1) == 0)
4169 {
4170 i++;
cristybb503372010-05-27 20:51:26 +00004171 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004172 ThrowMogrifyException(OptionError,"MissingArgument",option);
4173 if (*option == '+')
4174 {
4175 const char
4176 *define;
4177
4178 define=GetImageOption(image_info,argv[i]);
4179 if (define == (const char *) NULL)
4180 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4181 break;
4182 }
4183 break;
4184 }
4185 if (LocaleCompare("delay",option+1) == 0)
4186 {
4187 if (*option == '+')
4188 break;
4189 i++;
cristybb503372010-05-27 20:51:26 +00004190 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004191 ThrowMogrifyException(OptionError,"MissingArgument",option);
4192 if (IsGeometry(argv[i]) == MagickFalse)
4193 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4194 break;
4195 }
cristyecb10ff2011-03-22 13:14:03 +00004196 if (LocaleCompare("delete",option+1) == 0)
4197 {
4198 if (*option == '+')
4199 break;
4200 i++;
4201 if (i == (ssize_t) (argc-1))
4202 ThrowMogrifyException(OptionError,"MissingArgument",option);
4203 if (IsGeometry(argv[i]) == MagickFalse)
4204 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4205 break;
4206 }
cristy3ed852e2009-09-05 21:47:34 +00004207 if (LocaleCompare("density",option+1) == 0)
4208 {
4209 if (*option == '+')
4210 break;
4211 i++;
cristybb503372010-05-27 20:51:26 +00004212 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004213 ThrowMogrifyException(OptionError,"MissingArgument",option);
4214 if (IsGeometry(argv[i]) == MagickFalse)
4215 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4216 break;
4217 }
4218 if (LocaleCompare("depth",option+1) == 0)
4219 {
4220 if (*option == '+')
4221 break;
4222 i++;
cristybb503372010-05-27 20:51:26 +00004223 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004224 ThrowMogrifyException(OptionError,"MissingArgument",option);
4225 if (IsGeometry(argv[i]) == MagickFalse)
4226 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4227 break;
4228 }
4229 if (LocaleCompare("deskew",option+1) == 0)
4230 {
4231 if (*option == '+')
4232 break;
4233 i++;
cristybb503372010-05-27 20:51:26 +00004234 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004235 ThrowMogrifyException(OptionError,"MissingArgument",option);
4236 if (IsGeometry(argv[i]) == MagickFalse)
4237 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4238 break;
4239 }
4240 if (LocaleCompare("despeckle",option+1) == 0)
4241 break;
4242 if (LocaleCompare("dft",option+1) == 0)
4243 break;
cristyc9b12952010-03-28 01:12:28 +00004244 if (LocaleCompare("direction",option+1) == 0)
4245 {
cristybb503372010-05-27 20:51:26 +00004246 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004247 direction;
4248
4249 if (*option == '+')
4250 break;
4251 i++;
cristybb503372010-05-27 20:51:26 +00004252 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004253 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004254 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004255 argv[i]);
4256 if (direction < 0)
4257 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4258 argv[i]);
4259 break;
4260 }
cristy3ed852e2009-09-05 21:47:34 +00004261 if (LocaleCompare("display",option+1) == 0)
4262 {
4263 if (*option == '+')
4264 break;
4265 i++;
cristybb503372010-05-27 20:51:26 +00004266 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004267 ThrowMogrifyException(OptionError,"MissingArgument",option);
4268 break;
4269 }
4270 if (LocaleCompare("dispose",option+1) == 0)
4271 {
cristybb503372010-05-27 20:51:26 +00004272 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004273 dispose;
4274
4275 if (*option == '+')
4276 break;
4277 i++;
cristybb503372010-05-27 20:51:26 +00004278 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004279 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004280 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004281 if (dispose < 0)
4282 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4283 argv[i]);
4284 break;
4285 }
4286 if (LocaleCompare("distort",option+1) == 0)
4287 {
cristybb503372010-05-27 20:51:26 +00004288 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004289 op;
4290
4291 i++;
cristybb503372010-05-27 20:51:26 +00004292 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004293 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004294 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004295 if (op < 0)
4296 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4297 argv[i]);
4298 i++;
cristybb503372010-05-27 20:51:26 +00004299 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004300 ThrowMogrifyException(OptionError,"MissingArgument",option);
4301 break;
4302 }
4303 if (LocaleCompare("dither",option+1) == 0)
4304 {
cristybb503372010-05-27 20:51:26 +00004305 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004306 method;
4307
4308 if (*option == '+')
4309 break;
4310 i++;
cristybb503372010-05-27 20:51:26 +00004311 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004312 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004313 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004314 if (method < 0)
4315 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4316 argv[i]);
4317 break;
4318 }
4319 if (LocaleCompare("draw",option+1) == 0)
4320 {
4321 if (*option == '+')
4322 break;
4323 i++;
cristybb503372010-05-27 20:51:26 +00004324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004325 ThrowMogrifyException(OptionError,"MissingArgument",option);
4326 break;
4327 }
cristyecb10ff2011-03-22 13:14:03 +00004328 if (LocaleCompare("duplicate",option+1) == 0)
4329 {
4330 if (*option == '+')
4331 break;
4332 i++;
4333 if (i == (ssize_t) (argc-1))
4334 ThrowMogrifyException(OptionError,"MissingArgument",option);
4335 if (IsGeometry(argv[i]) == MagickFalse)
4336 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4337 break;
4338 }
cristy22879752009-10-25 23:55:40 +00004339 if (LocaleCompare("duration",option+1) == 0)
4340 {
4341 if (*option == '+')
4342 break;
4343 i++;
cristybb503372010-05-27 20:51:26 +00004344 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004345 ThrowMogrifyException(OptionError,"MissingArgument",option);
4346 if (IsGeometry(argv[i]) == MagickFalse)
4347 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4348 break;
4349 }
cristy3ed852e2009-09-05 21:47:34 +00004350 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4351 }
4352 case 'e':
4353 {
4354 if (LocaleCompare("edge",option+1) == 0)
4355 {
4356 if (*option == '+')
4357 break;
4358 i++;
cristybb503372010-05-27 20:51:26 +00004359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004360 ThrowMogrifyException(OptionError,"MissingArgument",option);
4361 if (IsGeometry(argv[i]) == MagickFalse)
4362 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4363 break;
4364 }
4365 if (LocaleCompare("emboss",option+1) == 0)
4366 {
4367 if (*option == '+')
4368 break;
4369 i++;
cristybb503372010-05-27 20:51:26 +00004370 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004371 ThrowMogrifyException(OptionError,"MissingArgument",option);
4372 if (IsGeometry(argv[i]) == MagickFalse)
4373 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4374 break;
4375 }
4376 if (LocaleCompare("encipher",option+1) == 0)
4377 {
4378 if (*option == '+')
4379 break;
4380 i++;
cristybb503372010-05-27 20:51:26 +00004381 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004382 ThrowMogrifyException(OptionError,"MissingArgument",option);
4383 break;
4384 }
4385 if (LocaleCompare("encoding",option+1) == 0)
4386 {
4387 if (*option == '+')
4388 break;
4389 i++;
cristybb503372010-05-27 20:51:26 +00004390 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004391 ThrowMogrifyException(OptionError,"MissingArgument",option);
4392 break;
4393 }
4394 if (LocaleCompare("endian",option+1) == 0)
4395 {
cristybb503372010-05-27 20:51:26 +00004396 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004397 endian;
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);
cristy042ee782011-04-22 18:48:30 +00004404 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004405 if (endian < 0)
4406 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4407 argv[i]);
4408 break;
4409 }
4410 if (LocaleCompare("enhance",option+1) == 0)
4411 break;
4412 if (LocaleCompare("equalize",option+1) == 0)
4413 break;
4414 if (LocaleCompare("evaluate",option+1) == 0)
4415 {
cristybb503372010-05-27 20:51:26 +00004416 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004417 op;
4418
4419 if (*option == '+')
4420 break;
4421 i++;
cristybb503372010-05-27 20:51:26 +00004422 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004423 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004424 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004425 if (op < 0)
4426 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4427 argv[i]);
4428 i++;
cristybb503372010-05-27 20:51:26 +00004429 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004430 ThrowMogrifyException(OptionError,"MissingArgument",option);
4431 if (IsGeometry(argv[i]) == MagickFalse)
4432 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4433 break;
4434 }
cristyd18ae7c2010-03-07 17:39:52 +00004435 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4436 {
cristybb503372010-05-27 20:51:26 +00004437 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004438 op;
4439
4440 if (*option == '+')
4441 break;
4442 i++;
cristybb503372010-05-27 20:51:26 +00004443 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004444 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004445 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004446 if (op < 0)
4447 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4448 argv[i]);
4449 break;
4450 }
cristy3ed852e2009-09-05 21:47:34 +00004451 if (LocaleCompare("extent",option+1) == 0)
4452 {
4453 if (*option == '+')
4454 break;
4455 i++;
cristybb503372010-05-27 20:51:26 +00004456 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004457 ThrowMogrifyException(OptionError,"MissingArgument",option);
4458 if (IsGeometry(argv[i]) == MagickFalse)
4459 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4460 break;
4461 }
4462 if (LocaleCompare("extract",option+1) == 0)
4463 {
4464 if (*option == '+')
4465 break;
4466 i++;
cristybb503372010-05-27 20:51:26 +00004467 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004468 ThrowMogrifyException(OptionError,"MissingArgument",option);
4469 if (IsGeometry(argv[i]) == MagickFalse)
4470 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4471 break;
4472 }
4473 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4474 }
4475 case 'f':
4476 {
4477 if (LocaleCompare("family",option+1) == 0)
4478 {
4479 if (*option == '+')
4480 break;
4481 i++;
cristybb503372010-05-27 20:51:26 +00004482 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004483 ThrowMogrifyException(OptionError,"MissingArgument",option);
4484 break;
4485 }
4486 if (LocaleCompare("fill",option+1) == 0)
4487 {
4488 if (*option == '+')
4489 break;
4490 i++;
cristybb503372010-05-27 20:51:26 +00004491 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004492 ThrowMogrifyException(OptionError,"MissingArgument",option);
4493 break;
4494 }
4495 if (LocaleCompare("filter",option+1) == 0)
4496 {
cristybb503372010-05-27 20:51:26 +00004497 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004498 filter;
4499
4500 if (*option == '+')
4501 break;
4502 i++;
cristybb503372010-05-27 20:51:26 +00004503 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004504 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004505 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004506 if (filter < 0)
4507 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4508 argv[i]);
4509 break;
4510 }
4511 if (LocaleCompare("flatten",option+1) == 0)
4512 break;
4513 if (LocaleCompare("flip",option+1) == 0)
4514 break;
4515 if (LocaleCompare("flop",option+1) == 0)
4516 break;
4517 if (LocaleCompare("floodfill",option+1) == 0)
4518 {
4519 if (*option == '+')
4520 break;
4521 i++;
cristybb503372010-05-27 20:51:26 +00004522 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004523 ThrowMogrifyException(OptionError,"MissingArgument",option);
4524 if (IsGeometry(argv[i]) == MagickFalse)
4525 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4526 i++;
cristybb503372010-05-27 20:51:26 +00004527 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004528 ThrowMogrifyException(OptionError,"MissingArgument",option);
4529 break;
4530 }
4531 if (LocaleCompare("font",option+1) == 0)
4532 {
4533 if (*option == '+')
4534 break;
4535 i++;
cristybb503372010-05-27 20:51:26 +00004536 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004537 ThrowMogrifyException(OptionError,"MissingArgument",option);
4538 break;
4539 }
4540 if (LocaleCompare("format",option+1) == 0)
4541 {
4542 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4543 (void) CloneString(&format,(char *) NULL);
4544 if (*option == '+')
4545 break;
4546 i++;
cristybb503372010-05-27 20:51:26 +00004547 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004548 ThrowMogrifyException(OptionError,"MissingArgument",option);
4549 (void) CloneString(&format,argv[i]);
4550 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4551 (void) ConcatenateMagickString(image_info->filename,":",
4552 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004553 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004554 if (*image_info->magick == '\0')
4555 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4556 format);
4557 break;
4558 }
4559 if (LocaleCompare("frame",option+1) == 0)
4560 {
4561 if (*option == '+')
4562 break;
4563 i++;
cristybb503372010-05-27 20:51:26 +00004564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004565 ThrowMogrifyException(OptionError,"MissingArgument",option);
4566 if (IsGeometry(argv[i]) == MagickFalse)
4567 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4568 break;
4569 }
4570 if (LocaleCompare("function",option+1) == 0)
4571 {
cristybb503372010-05-27 20:51:26 +00004572 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004573 op;
4574
4575 if (*option == '+')
4576 break;
4577 i++;
cristybb503372010-05-27 20:51:26 +00004578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004579 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004580 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004581 if (op < 0)
4582 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4583 i++;
cristybb503372010-05-27 20:51:26 +00004584 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004585 ThrowMogrifyException(OptionError,"MissingArgument",option);
4586 break;
4587 }
4588 if (LocaleCompare("fuzz",option+1) == 0)
4589 {
4590 if (*option == '+')
4591 break;
4592 i++;
cristybb503372010-05-27 20:51:26 +00004593 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004594 ThrowMogrifyException(OptionError,"MissingArgument",option);
4595 if (IsGeometry(argv[i]) == MagickFalse)
4596 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4597 break;
4598 }
4599 if (LocaleCompare("fx",option+1) == 0)
4600 {
4601 if (*option == '+')
4602 break;
4603 i++;
cristybb503372010-05-27 20:51:26 +00004604 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004605 ThrowMogrifyException(OptionError,"MissingArgument",option);
4606 break;
4607 }
4608 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4609 }
4610 case 'g':
4611 {
4612 if (LocaleCompare("gamma",option+1) == 0)
4613 {
4614 i++;
cristybb503372010-05-27 20:51:26 +00004615 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004616 ThrowMogrifyException(OptionError,"MissingArgument",option);
4617 if (IsGeometry(argv[i]) == MagickFalse)
4618 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4619 break;
4620 }
4621 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4622 (LocaleCompare("gaussian",option+1) == 0))
4623 {
4624 i++;
cristybb503372010-05-27 20:51:26 +00004625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004626 ThrowMogrifyException(OptionError,"MissingArgument",option);
4627 if (IsGeometry(argv[i]) == MagickFalse)
4628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4629 break;
4630 }
4631 if (LocaleCompare("geometry",option+1) == 0)
4632 {
4633 if (*option == '+')
4634 break;
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("gravity",option+1) == 0)
4643 {
cristybb503372010-05-27 20:51:26 +00004644 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004645 gravity;
4646
4647 if (*option == '+')
4648 break;
4649 i++;
cristybb503372010-05-27 20:51:26 +00004650 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004651 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004652 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004653 if (gravity < 0)
4654 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4655 argv[i]);
4656 break;
4657 }
4658 if (LocaleCompare("green-primary",option+1) == 0)
4659 {
4660 if (*option == '+')
4661 break;
4662 i++;
cristybb503372010-05-27 20:51:26 +00004663 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004664 ThrowMogrifyException(OptionError,"MissingArgument",option);
4665 if (IsGeometry(argv[i]) == MagickFalse)
4666 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4667 break;
4668 }
4669 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4670 }
4671 case 'h':
4672 {
4673 if (LocaleCompare("hald-clut",option+1) == 0)
4674 break;
4675 if ((LocaleCompare("help",option+1) == 0) ||
4676 (LocaleCompare("-help",option+1) == 0))
4677 return(MogrifyUsage());
4678 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4679 }
4680 case 'i':
4681 {
4682 if (LocaleCompare("identify",option+1) == 0)
4683 break;
4684 if (LocaleCompare("idft",option+1) == 0)
4685 break;
4686 if (LocaleCompare("implode",option+1) == 0)
4687 {
4688 if (*option == '+')
4689 break;
4690 i++;
cristybb503372010-05-27 20:51:26 +00004691 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004692 ThrowMogrifyException(OptionError,"MissingArgument",option);
4693 if (IsGeometry(argv[i]) == MagickFalse)
4694 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4695 break;
4696 }
4697 if (LocaleCompare("intent",option+1) == 0)
4698 {
cristybb503372010-05-27 20:51:26 +00004699 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004700 intent;
4701
4702 if (*option == '+')
4703 break;
4704 i++;
cristybb503372010-05-27 20:51:26 +00004705 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004706 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004707 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004708 if (intent < 0)
4709 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4710 argv[i]);
4711 break;
4712 }
4713 if (LocaleCompare("interlace",option+1) == 0)
4714 {
cristybb503372010-05-27 20:51:26 +00004715 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004716 interlace;
4717
4718 if (*option == '+')
4719 break;
4720 i++;
cristybb503372010-05-27 20:51:26 +00004721 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004722 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004723 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004724 argv[i]);
4725 if (interlace < 0)
4726 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4727 argv[i]);
4728 break;
4729 }
cristyb32b90a2009-09-07 21:45:48 +00004730 if (LocaleCompare("interline-spacing",option+1) == 0)
4731 {
4732 if (*option == '+')
4733 break;
4734 i++;
cristybb503372010-05-27 20:51:26 +00004735 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004736 ThrowMogrifyException(OptionError,"MissingArgument",option);
4737 if (IsGeometry(argv[i]) == MagickFalse)
4738 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4739 break;
4740 }
cristy3ed852e2009-09-05 21:47:34 +00004741 if (LocaleCompare("interpolate",option+1) == 0)
4742 {
cristybb503372010-05-27 20:51:26 +00004743 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004744 interpolate;
4745
4746 if (*option == '+')
4747 break;
4748 i++;
cristybb503372010-05-27 20:51:26 +00004749 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004750 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004751 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004752 argv[i]);
4753 if (interpolate < 0)
4754 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4755 argv[i]);
4756 break;
4757 }
4758 if (LocaleCompare("interword-spacing",option+1) == 0)
4759 {
4760 if (*option == '+')
4761 break;
4762 i++;
cristybb503372010-05-27 20:51:26 +00004763 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004764 ThrowMogrifyException(OptionError,"MissingArgument",option);
4765 if (IsGeometry(argv[i]) == MagickFalse)
4766 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4767 break;
4768 }
4769 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4770 }
4771 case 'k':
4772 {
4773 if (LocaleCompare("kerning",option+1) == 0)
4774 {
4775 if (*option == '+')
4776 break;
4777 i++;
cristybb503372010-05-27 20:51:26 +00004778 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004779 ThrowMogrifyException(OptionError,"MissingArgument",option);
4780 if (IsGeometry(argv[i]) == MagickFalse)
4781 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4782 break;
4783 }
4784 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4785 }
4786 case 'l':
4787 {
4788 if (LocaleCompare("label",option+1) == 0)
4789 {
4790 if (*option == '+')
4791 break;
4792 i++;
cristybb503372010-05-27 20:51:26 +00004793 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004794 ThrowMogrifyException(OptionError,"MissingArgument",option);
4795 break;
4796 }
4797 if (LocaleCompare("lat",option+1) == 0)
4798 {
4799 if (*option == '+')
4800 break;
4801 i++;
cristybb503372010-05-27 20:51:26 +00004802 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004803 ThrowMogrifyException(OptionError,"MissingArgument",option);
4804 if (IsGeometry(argv[i]) == MagickFalse)
4805 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4806 }
4807 if (LocaleCompare("layers",option+1) == 0)
4808 {
cristybb503372010-05-27 20:51:26 +00004809 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004810 type;
4811
4812 if (*option == '+')
4813 break;
4814 i++;
cristybb503372010-05-27 20:51:26 +00004815 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004816 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004817 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004818 if (type < 0)
4819 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4820 argv[i]);
4821 break;
4822 }
4823 if (LocaleCompare("level",option+1) == 0)
4824 {
4825 i++;
cristybb503372010-05-27 20:51:26 +00004826 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004827 ThrowMogrifyException(OptionError,"MissingArgument",option);
4828 if (IsGeometry(argv[i]) == MagickFalse)
4829 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4830 break;
4831 }
4832 if (LocaleCompare("level-colors",option+1) == 0)
4833 {
4834 i++;
cristybb503372010-05-27 20:51:26 +00004835 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004836 ThrowMogrifyException(OptionError,"MissingArgument",option);
4837 break;
4838 }
4839 if (LocaleCompare("linewidth",option+1) == 0)
4840 {
4841 if (*option == '+')
4842 break;
4843 i++;
cristybb503372010-05-27 20:51:26 +00004844 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004845 ThrowMogrifyException(OptionError,"MissingArgument",option);
4846 if (IsGeometry(argv[i]) == MagickFalse)
4847 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4848 break;
4849 }
4850 if (LocaleCompare("limit",option+1) == 0)
4851 {
4852 char
4853 *p;
4854
4855 double
4856 value;
4857
cristybb503372010-05-27 20:51:26 +00004858 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004859 resource;
4860
4861 if (*option == '+')
4862 break;
4863 i++;
cristybb503372010-05-27 20:51:26 +00004864 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004865 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004866 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004867 argv[i]);
4868 if (resource < 0)
4869 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4870 argv[i]);
4871 i++;
cristybb503372010-05-27 20:51:26 +00004872 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004873 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004874 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004875 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004876 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4877 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4878 break;
4879 }
4880 if (LocaleCompare("liquid-rescale",option+1) == 0)
4881 {
4882 i++;
cristybb503372010-05-27 20:51:26 +00004883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004884 ThrowMogrifyException(OptionError,"MissingArgument",option);
4885 if (IsGeometry(argv[i]) == MagickFalse)
4886 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4887 break;
4888 }
4889 if (LocaleCompare("list",option+1) == 0)
4890 {
cristybb503372010-05-27 20:51:26 +00004891 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004892 list;
4893
4894 if (*option == '+')
4895 break;
4896 i++;
cristybb503372010-05-27 20:51:26 +00004897 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004898 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004899 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004900 if (list < 0)
4901 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004902 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004903 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004904 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004905 }
4906 if (LocaleCompare("log",option+1) == 0)
4907 {
4908 if (*option == '+')
4909 break;
4910 i++;
cristybb503372010-05-27 20:51:26 +00004911 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004912 (strchr(argv[i],'%') == (char *) NULL))
4913 ThrowMogrifyException(OptionError,"MissingArgument",option);
4914 break;
4915 }
4916 if (LocaleCompare("loop",option+1) == 0)
4917 {
4918 if (*option == '+')
4919 break;
4920 i++;
cristybb503372010-05-27 20:51:26 +00004921 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004922 ThrowMogrifyException(OptionError,"MissingArgument",option);
4923 if (IsGeometry(argv[i]) == MagickFalse)
4924 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4925 break;
4926 }
4927 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4928 }
4929 case 'm':
4930 {
4931 if (LocaleCompare("map",option+1) == 0)
4932 {
4933 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4934 if (*option == '+')
4935 break;
4936 i++;
cristybb503372010-05-27 20:51:26 +00004937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004938 ThrowMogrifyException(OptionError,"MissingArgument",option);
4939 break;
4940 }
4941 if (LocaleCompare("mask",option+1) == 0)
4942 {
4943 if (*option == '+')
4944 break;
4945 i++;
cristybb503372010-05-27 20:51:26 +00004946 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004947 ThrowMogrifyException(OptionError,"MissingArgument",option);
4948 break;
4949 }
4950 if (LocaleCompare("matte",option+1) == 0)
4951 break;
4952 if (LocaleCompare("mattecolor",option+1) == 0)
4953 {
4954 if (*option == '+')
4955 break;
4956 i++;
cristybb503372010-05-27 20:51:26 +00004957 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004958 ThrowMogrifyException(OptionError,"MissingArgument",option);
4959 break;
4960 }
cristyf40785b2010-03-06 02:27:27 +00004961 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004962 break;
cristyf40785b2010-03-06 02:27:27 +00004963 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004964 break;
cristy3ed852e2009-09-05 21:47:34 +00004965 if (LocaleCompare("modulate",option+1) == 0)
4966 {
4967 if (*option == '+')
4968 break;
4969 i++;
cristybb503372010-05-27 20:51:26 +00004970 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004971 ThrowMogrifyException(OptionError,"MissingArgument",option);
4972 if (IsGeometry(argv[i]) == MagickFalse)
4973 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4974 break;
4975 }
4976 if (LocaleCompare("median",option+1) == 0)
4977 {
4978 if (*option == '+')
4979 break;
4980 i++;
cristybb503372010-05-27 20:51:26 +00004981 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004982 ThrowMogrifyException(OptionError,"MissingArgument",option);
4983 if (IsGeometry(argv[i]) == MagickFalse)
4984 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4985 break;
4986 }
cristy69ec32d2011-02-27 23:57:09 +00004987 if (LocaleCompare("mode",option+1) == 0)
4988 {
4989 if (*option == '+')
4990 break;
4991 i++;
4992 if (i == (ssize_t) argc)
4993 ThrowMogrifyException(OptionError,"MissingArgument",option);
4994 if (IsGeometry(argv[i]) == MagickFalse)
4995 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4996 break;
4997 }
cristy3ed852e2009-09-05 21:47:34 +00004998 if (LocaleCompare("monitor",option+1) == 0)
4999 break;
5000 if (LocaleCompare("monochrome",option+1) == 0)
5001 break;
5002 if (LocaleCompare("morph",option+1) == 0)
5003 {
5004 if (*option == '+')
5005 break;
5006 i++;
cristybb503372010-05-27 20:51:26 +00005007 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005008 ThrowMogrifyException(OptionError,"MissingArgument",option);
5009 if (IsGeometry(argv[i]) == MagickFalse)
5010 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5011 break;
5012 }
anthony29188a82010-01-22 10:12:34 +00005013 if (LocaleCompare("morphology",option+1) == 0)
5014 {
anthony29188a82010-01-22 10:12:34 +00005015 char
5016 token[MaxTextExtent];
5017
cristyb6bd4ad2010-08-08 01:12:27 +00005018 KernelInfo
5019 *kernel_info;
5020
5021 ssize_t
5022 op;
5023
anthony29188a82010-01-22 10:12:34 +00005024 i++;
cristybb503372010-05-27 20:51:26 +00005025 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005026 ThrowMogrifyException(OptionError,"MissingArgument",option);
5027 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005028 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005029 if (op < 0)
5030 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005031 token);
anthony29188a82010-01-22 10:12:34 +00005032 i++;
cristybb503372010-05-27 20:51:26 +00005033 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005034 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005035 kernel_info=AcquireKernelInfo(argv[i]);
5036 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005037 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005038 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005039 break;
5040 }
cristy3ed852e2009-09-05 21:47:34 +00005041 if (LocaleCompare("mosaic",option+1) == 0)
5042 break;
5043 if (LocaleCompare("motion-blur",option+1) == 0)
5044 {
5045 if (*option == '+')
5046 break;
5047 i++;
cristybb503372010-05-27 20:51:26 +00005048 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005049 ThrowMogrifyException(OptionError,"MissingArgument",option);
5050 if (IsGeometry(argv[i]) == MagickFalse)
5051 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5052 break;
5053 }
5054 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5055 }
5056 case 'n':
5057 {
5058 if (LocaleCompare("negate",option+1) == 0)
5059 break;
5060 if (LocaleCompare("noise",option+1) == 0)
5061 {
5062 i++;
cristybb503372010-05-27 20:51:26 +00005063 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005064 ThrowMogrifyException(OptionError,"MissingArgument",option);
5065 if (*option == '+')
5066 {
cristybb503372010-05-27 20:51:26 +00005067 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005068 noise;
5069
cristy042ee782011-04-22 18:48:30 +00005070 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005071 if (noise < 0)
5072 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5073 argv[i]);
5074 break;
5075 }
5076 if (IsGeometry(argv[i]) == MagickFalse)
5077 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5078 break;
5079 }
5080 if (LocaleCompare("noop",option+1) == 0)
5081 break;
5082 if (LocaleCompare("normalize",option+1) == 0)
5083 break;
5084 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5085 }
5086 case 'o':
5087 {
5088 if (LocaleCompare("opaque",option+1) == 0)
5089 {
cristy3ed852e2009-09-05 21:47:34 +00005090 i++;
cristybb503372010-05-27 20:51:26 +00005091 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005092 ThrowMogrifyException(OptionError,"MissingArgument",option);
5093 break;
5094 }
5095 if (LocaleCompare("ordered-dither",option+1) == 0)
5096 {
5097 if (*option == '+')
5098 break;
5099 i++;
cristybb503372010-05-27 20:51:26 +00005100 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005101 ThrowMogrifyException(OptionError,"MissingArgument",option);
5102 break;
5103 }
5104 if (LocaleCompare("orient",option+1) == 0)
5105 {
cristybb503372010-05-27 20:51:26 +00005106 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005107 orientation;
5108
5109 orientation=UndefinedOrientation;
5110 if (*option == '+')
5111 break;
5112 i++;
cristybb503372010-05-27 20:51:26 +00005113 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005114 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005115 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005116 argv[i]);
5117 if (orientation < 0)
5118 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5119 argv[i]);
5120 break;
5121 }
5122 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5123 }
5124 case 'p':
5125 {
5126 if (LocaleCompare("page",option+1) == 0)
5127 {
5128 if (*option == '+')
5129 break;
5130 i++;
cristybb503372010-05-27 20:51:26 +00005131 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005132 ThrowMogrifyException(OptionError,"MissingArgument",option);
5133 break;
5134 }
5135 if (LocaleCompare("paint",option+1) == 0)
5136 {
5137 if (*option == '+')
5138 break;
5139 i++;
cristybb503372010-05-27 20:51:26 +00005140 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005141 ThrowMogrifyException(OptionError,"MissingArgument",option);
5142 if (IsGeometry(argv[i]) == MagickFalse)
5143 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5144 break;
5145 }
5146 if (LocaleCompare("path",option+1) == 0)
5147 {
5148 (void) CloneString(&path,(char *) NULL);
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 (void) CloneString(&path,argv[i]);
5155 break;
5156 }
5157 if (LocaleCompare("pointsize",option+1) == 0)
5158 {
5159 if (*option == '+')
5160 break;
5161 i++;
cristybb503372010-05-27 20:51:26 +00005162 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005163 ThrowMogrifyException(OptionError,"MissingArgument",option);
5164 if (IsGeometry(argv[i]) == MagickFalse)
5165 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5166 break;
5167 }
5168 if (LocaleCompare("polaroid",option+1) == 0)
5169 {
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 if (IsGeometry(argv[i]) == MagickFalse)
5176 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5177 break;
5178 }
5179 if (LocaleCompare("posterize",option+1) == 0)
5180 {
5181 if (*option == '+')
5182 break;
5183 i++;
cristybb503372010-05-27 20:51:26 +00005184 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005185 ThrowMogrifyException(OptionError,"MissingArgument",option);
5186 if (IsGeometry(argv[i]) == MagickFalse)
5187 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5188 break;
5189 }
cristye7f51092010-01-17 00:39:37 +00005190 if (LocaleCompare("precision",option+1) == 0)
5191 {
5192 if (*option == '+')
5193 break;
5194 i++;
cristybb503372010-05-27 20:51:26 +00005195 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005196 ThrowMogrifyException(OptionError,"MissingArgument",option);
5197 if (IsGeometry(argv[i]) == MagickFalse)
5198 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5199 break;
5200 }
cristy3ed852e2009-09-05 21:47:34 +00005201 if (LocaleCompare("print",option+1) == 0)
5202 {
5203 if (*option == '+')
5204 break;
5205 i++;
cristybb503372010-05-27 20:51:26 +00005206 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005207 ThrowMogrifyException(OptionError,"MissingArgument",option);
5208 break;
5209 }
5210 if (LocaleCompare("process",option+1) == 0)
5211 {
5212 if (*option == '+')
5213 break;
5214 i++;
cristybb503372010-05-27 20:51:26 +00005215 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005216 ThrowMogrifyException(OptionError,"MissingArgument",option);
5217 break;
5218 }
5219 if (LocaleCompare("profile",option+1) == 0)
5220 {
5221 i++;
cristybb503372010-05-27 20:51:26 +00005222 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005223 ThrowMogrifyException(OptionError,"MissingArgument",option);
5224 break;
5225 }
5226 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5227 }
5228 case 'q':
5229 {
5230 if (LocaleCompare("quality",option+1) == 0)
5231 {
5232 if (*option == '+')
5233 break;
5234 i++;
cristybb503372010-05-27 20:51:26 +00005235 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005236 ThrowMogrifyException(OptionError,"MissingArgument",option);
5237 if (IsGeometry(argv[i]) == MagickFalse)
5238 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5239 break;
5240 }
5241 if (LocaleCompare("quantize",option+1) == 0)
5242 {
cristybb503372010-05-27 20:51:26 +00005243 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005244 colorspace;
5245
5246 if (*option == '+')
5247 break;
5248 i++;
cristybb503372010-05-27 20:51:26 +00005249 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005250 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005251 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005252 argv[i]);
5253 if (colorspace < 0)
5254 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5255 argv[i]);
5256 break;
5257 }
5258 if (LocaleCompare("quiet",option+1) == 0)
5259 break;
5260 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5261 }
5262 case 'r':
5263 {
5264 if (LocaleCompare("radial-blur",option+1) == 0)
5265 {
5266 i++;
cristybb503372010-05-27 20:51:26 +00005267 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005268 ThrowMogrifyException(OptionError,"MissingArgument",option);
5269 if (IsGeometry(argv[i]) == MagickFalse)
5270 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5271 break;
5272 }
5273 if (LocaleCompare("raise",option+1) == 0)
5274 {
5275 i++;
cristybb503372010-05-27 20:51:26 +00005276 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005277 ThrowMogrifyException(OptionError,"MissingArgument",option);
5278 if (IsGeometry(argv[i]) == MagickFalse)
5279 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5280 break;
5281 }
5282 if (LocaleCompare("random-threshold",option+1) == 0)
5283 {
5284 if (*option == '+')
5285 break;
5286 i++;
cristybb503372010-05-27 20:51:26 +00005287 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005288 ThrowMogrifyException(OptionError,"MissingArgument",option);
5289 if (IsGeometry(argv[i]) == MagickFalse)
5290 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5291 break;
5292 }
cristye6365592010-04-02 17:31:23 +00005293 if (LocaleCompare("recolor",option+1) == 0)
5294 {
5295 if (*option == '+')
5296 break;
5297 i++;
cristybb503372010-05-27 20:51:26 +00005298 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005299 ThrowMogrifyException(OptionError,"MissingArgument",option);
5300 if (IsGeometry(argv[i]) == MagickFalse)
5301 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5302 break;
5303 }
cristy3ed852e2009-09-05 21:47:34 +00005304 if (LocaleCompare("red-primary",option+1) == 0)
5305 {
5306 if (*option == '+')
5307 break;
5308 i++;
cristybb503372010-05-27 20:51:26 +00005309 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005310 ThrowMogrifyException(OptionError,"MissingArgument",option);
5311 if (IsGeometry(argv[i]) == MagickFalse)
5312 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5313 }
cristy9f2083a2010-04-22 19:48:05 +00005314 if (LocaleCompare("regard-warnings",option+1) == 0)
5315 break;
cristy3ed852e2009-09-05 21:47:34 +00005316 if (LocaleCompare("region",option+1) == 0)
5317 {
5318 if (*option == '+')
5319 break;
5320 i++;
cristybb503372010-05-27 20:51:26 +00005321 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005322 ThrowMogrifyException(OptionError,"MissingArgument",option);
5323 if (IsGeometry(argv[i]) == MagickFalse)
5324 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5325 break;
5326 }
cristyf0c78232010-03-15 12:53:40 +00005327 if (LocaleCompare("remap",option+1) == 0)
5328 {
5329 if (*option == '+')
5330 break;
5331 i++;
cristybb503372010-05-27 20:51:26 +00005332 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005333 ThrowMogrifyException(OptionError,"MissingArgument",option);
5334 break;
5335 }
cristy3ed852e2009-09-05 21:47:34 +00005336 if (LocaleCompare("render",option+1) == 0)
5337 break;
5338 if (LocaleCompare("repage",option+1) == 0)
5339 {
5340 if (*option == '+')
5341 break;
5342 i++;
cristybb503372010-05-27 20:51:26 +00005343 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005344 ThrowMogrifyException(OptionError,"MissingArgument",option);
5345 if (IsGeometry(argv[i]) == MagickFalse)
5346 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5347 break;
5348 }
5349 if (LocaleCompare("resample",option+1) == 0)
5350 {
5351 if (*option == '+')
5352 break;
5353 i++;
cristybb503372010-05-27 20:51:26 +00005354 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005355 ThrowMogrifyException(OptionError,"MissingArgument",option);
5356 if (IsGeometry(argv[i]) == MagickFalse)
5357 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5358 break;
5359 }
5360 if (LocaleCompare("resize",option+1) == 0)
5361 {
5362 if (*option == '+')
5363 break;
5364 i++;
cristybb503372010-05-27 20:51:26 +00005365 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005366 ThrowMogrifyException(OptionError,"MissingArgument",option);
5367 if (IsGeometry(argv[i]) == MagickFalse)
5368 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5369 break;
5370 }
cristyebbcfea2011-02-25 02:43:54 +00005371 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5372 {
5373 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5374 break;
5375 }
cristy3ed852e2009-09-05 21:47:34 +00005376 if (LocaleCompare("reverse",option+1) == 0)
5377 break;
5378 if (LocaleCompare("roll",option+1) == 0)
5379 {
5380 if (*option == '+')
5381 break;
5382 i++;
cristybb503372010-05-27 20:51:26 +00005383 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005384 ThrowMogrifyException(OptionError,"MissingArgument",option);
5385 if (IsGeometry(argv[i]) == MagickFalse)
5386 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5387 break;
5388 }
5389 if (LocaleCompare("rotate",option+1) == 0)
5390 {
5391 i++;
cristybb503372010-05-27 20:51:26 +00005392 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005393 ThrowMogrifyException(OptionError,"MissingArgument",option);
5394 if (IsGeometry(argv[i]) == MagickFalse)
5395 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5396 break;
5397 }
5398 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5399 }
5400 case 's':
5401 {
5402 if (LocaleCompare("sample",option+1) == 0)
5403 {
5404 if (*option == '+')
5405 break;
5406 i++;
cristybb503372010-05-27 20:51:26 +00005407 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005408 ThrowMogrifyException(OptionError,"MissingArgument",option);
5409 if (IsGeometry(argv[i]) == MagickFalse)
5410 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5411 break;
5412 }
5413 if (LocaleCompare("sampling-factor",option+1) == 0)
5414 {
5415 if (*option == '+')
5416 break;
5417 i++;
cristybb503372010-05-27 20:51:26 +00005418 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005419 ThrowMogrifyException(OptionError,"MissingArgument",option);
5420 if (IsGeometry(argv[i]) == MagickFalse)
5421 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5422 break;
5423 }
5424 if (LocaleCompare("scale",option+1) == 0)
5425 {
5426 if (*option == '+')
5427 break;
5428 i++;
cristybb503372010-05-27 20:51:26 +00005429 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005430 ThrowMogrifyException(OptionError,"MissingArgument",option);
5431 if (IsGeometry(argv[i]) == MagickFalse)
5432 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5433 break;
5434 }
5435 if (LocaleCompare("scene",option+1) == 0)
5436 {
5437 if (*option == '+')
5438 break;
5439 i++;
cristybb503372010-05-27 20:51:26 +00005440 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005441 ThrowMogrifyException(OptionError,"MissingArgument",option);
5442 if (IsGeometry(argv[i]) == MagickFalse)
5443 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5444 break;
5445 }
5446 if (LocaleCompare("seed",option+1) == 0)
5447 {
5448 if (*option == '+')
5449 break;
5450 i++;
cristybb503372010-05-27 20:51:26 +00005451 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005452 ThrowMogrifyException(OptionError,"MissingArgument",option);
5453 if (IsGeometry(argv[i]) == MagickFalse)
5454 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5455 break;
5456 }
5457 if (LocaleCompare("segment",option+1) == 0)
5458 {
5459 if (*option == '+')
5460 break;
5461 i++;
cristybb503372010-05-27 20:51:26 +00005462 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005463 ThrowMogrifyException(OptionError,"MissingArgument",option);
5464 if (IsGeometry(argv[i]) == MagickFalse)
5465 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5466 break;
5467 }
5468 if (LocaleCompare("selective-blur",option+1) == 0)
5469 {
5470 i++;
cristybb503372010-05-27 20:51:26 +00005471 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005472 ThrowMogrifyException(OptionError,"MissingArgument",option);
5473 if (IsGeometry(argv[i]) == MagickFalse)
5474 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5475 break;
5476 }
5477 if (LocaleCompare("separate",option+1) == 0)
5478 break;
5479 if (LocaleCompare("sepia-tone",option+1) == 0)
5480 {
5481 if (*option == '+')
5482 break;
5483 i++;
cristybb503372010-05-27 20:51:26 +00005484 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005485 ThrowMogrifyException(OptionError,"MissingArgument",option);
5486 if (IsGeometry(argv[i]) == MagickFalse)
5487 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5488 break;
5489 }
5490 if (LocaleCompare("set",option+1) == 0)
5491 {
5492 i++;
cristybb503372010-05-27 20:51:26 +00005493 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005494 ThrowMogrifyException(OptionError,"MissingArgument",option);
5495 if (*option == '+')
5496 break;
5497 i++;
cristybb503372010-05-27 20:51:26 +00005498 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005499 ThrowMogrifyException(OptionError,"MissingArgument",option);
5500 break;
5501 }
5502 if (LocaleCompare("shade",option+1) == 0)
5503 {
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("shadow",option+1) == 0)
5512 {
5513 if (*option == '+')
5514 break;
5515 i++;
cristybb503372010-05-27 20:51:26 +00005516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005517 ThrowMogrifyException(OptionError,"MissingArgument",option);
5518 if (IsGeometry(argv[i]) == MagickFalse)
5519 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5520 break;
5521 }
5522 if (LocaleCompare("sharpen",option+1) == 0)
5523 {
5524 i++;
cristybb503372010-05-27 20:51:26 +00005525 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005526 ThrowMogrifyException(OptionError,"MissingArgument",option);
5527 if (IsGeometry(argv[i]) == MagickFalse)
5528 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5529 break;
5530 }
5531 if (LocaleCompare("shave",option+1) == 0)
5532 {
5533 if (*option == '+')
5534 break;
5535 i++;
cristybb503372010-05-27 20:51:26 +00005536 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005537 ThrowMogrifyException(OptionError,"MissingArgument",option);
5538 if (IsGeometry(argv[i]) == MagickFalse)
5539 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5540 break;
5541 }
5542 if (LocaleCompare("shear",option+1) == 0)
5543 {
5544 i++;
cristybb503372010-05-27 20:51:26 +00005545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005546 ThrowMogrifyException(OptionError,"MissingArgument",option);
5547 if (IsGeometry(argv[i]) == MagickFalse)
5548 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5549 break;
5550 }
5551 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5552 {
5553 i++;
cristybb503372010-05-27 20:51:26 +00005554 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005555 ThrowMogrifyException(OptionError,"MissingArgument",option);
5556 if (IsGeometry(argv[i]) == MagickFalse)
5557 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5558 break;
5559 }
5560 if (LocaleCompare("size",option+1) == 0)
5561 {
5562 if (*option == '+')
5563 break;
5564 i++;
cristybb503372010-05-27 20:51:26 +00005565 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005566 ThrowMogrifyException(OptionError,"MissingArgument",option);
5567 if (IsGeometry(argv[i]) == MagickFalse)
5568 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5569 break;
5570 }
5571 if (LocaleCompare("sketch",option+1) == 0)
5572 {
5573 if (*option == '+')
5574 break;
5575 i++;
cristybb503372010-05-27 20:51:26 +00005576 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005577 ThrowMogrifyException(OptionError,"MissingArgument",option);
5578 if (IsGeometry(argv[i]) == MagickFalse)
5579 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5580 break;
5581 }
cristy4285d782011-02-09 20:12:28 +00005582 if (LocaleCompare("smush",option+1) == 0)
5583 {
cristy4285d782011-02-09 20:12:28 +00005584 i++;
5585 if (i == (ssize_t) argc)
5586 ThrowMogrifyException(OptionError,"MissingArgument",option);
5587 if (IsGeometry(argv[i]) == MagickFalse)
5588 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005589 i++;
5590 break;
5591 }
cristy3ed852e2009-09-05 21:47:34 +00005592 if (LocaleCompare("solarize",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 }
5603 if (LocaleCompare("sparse-color",option+1) == 0)
5604 {
cristybb503372010-05-27 20:51:26 +00005605 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005606 op;
5607
5608 i++;
cristybb503372010-05-27 20:51:26 +00005609 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005610 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005611 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005612 if (op < 0)
5613 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5614 argv[i]);
5615 i++;
cristybb503372010-05-27 20:51:26 +00005616 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005617 ThrowMogrifyException(OptionError,"MissingArgument",option);
5618 break;
5619 }
5620 if (LocaleCompare("spread",option+1) == 0)
5621 {
5622 if (*option == '+')
5623 break;
5624 i++;
cristybb503372010-05-27 20:51:26 +00005625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005626 ThrowMogrifyException(OptionError,"MissingArgument",option);
5627 if (IsGeometry(argv[i]) == MagickFalse)
5628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5629 break;
5630 }
cristy0834d642011-03-18 18:26:08 +00005631 if (LocaleCompare("statistic",option+1) == 0)
5632 {
5633 ssize_t
5634 op;
5635
5636 if (*option == '+')
5637 break;
5638 i++;
5639 if (i == (ssize_t) argc)
5640 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005641 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005642 if (op < 0)
5643 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5644 argv[i]);
5645 i++;
5646 if (i == (ssize_t) (argc-1))
5647 ThrowMogrifyException(OptionError,"MissingArgument",option);
5648 if (IsGeometry(argv[i]) == MagickFalse)
5649 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5650 break;
5651 }
cristy3ed852e2009-09-05 21:47:34 +00005652 if (LocaleCompare("stretch",option+1) == 0)
5653 {
cristybb503372010-05-27 20:51:26 +00005654 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005655 stretch;
5656
5657 if (*option == '+')
5658 break;
5659 i++;
cristybb503372010-05-27 20:51:26 +00005660 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005661 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005662 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005663 if (stretch < 0)
5664 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5665 argv[i]);
5666 break;
5667 }
5668 if (LocaleCompare("strip",option+1) == 0)
5669 break;
5670 if (LocaleCompare("stroke",option+1) == 0)
5671 {
5672 if (*option == '+')
5673 break;
5674 i++;
cristybb503372010-05-27 20:51:26 +00005675 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005676 ThrowMogrifyException(OptionError,"MissingArgument",option);
5677 break;
5678 }
5679 if (LocaleCompare("strokewidth",option+1) == 0)
5680 {
5681 if (*option == '+')
5682 break;
5683 i++;
cristybb503372010-05-27 20:51:26 +00005684 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005685 ThrowMogrifyException(OptionError,"MissingArgument",option);
5686 if (IsGeometry(argv[i]) == MagickFalse)
5687 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5688 break;
5689 }
5690 if (LocaleCompare("style",option+1) == 0)
5691 {
cristybb503372010-05-27 20:51:26 +00005692 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005693 style;
5694
5695 if (*option == '+')
5696 break;
5697 i++;
cristybb503372010-05-27 20:51:26 +00005698 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005699 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005700 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005701 if (style < 0)
5702 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5703 argv[i]);
5704 break;
5705 }
cristyecb10ff2011-03-22 13:14:03 +00005706 if (LocaleCompare("swap",option+1) == 0)
5707 {
5708 if (*option == '+')
5709 break;
5710 i++;
5711 if (i == (ssize_t) (argc-1))
5712 ThrowMogrifyException(OptionError,"MissingArgument",option);
5713 if (IsGeometry(argv[i]) == MagickFalse)
5714 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5715 break;
5716 }
cristy3ed852e2009-09-05 21:47:34 +00005717 if (LocaleCompare("swirl",option+1) == 0)
5718 {
5719 if (*option == '+')
5720 break;
5721 i++;
cristybb503372010-05-27 20:51:26 +00005722 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005723 ThrowMogrifyException(OptionError,"MissingArgument",option);
5724 if (IsGeometry(argv[i]) == MagickFalse)
5725 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5726 break;
5727 }
cristyd9a29192010-10-16 16:49:53 +00005728 if (LocaleCompare("synchronize",option+1) == 0)
5729 break;
cristy3ed852e2009-09-05 21:47:34 +00005730 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5731 }
5732 case 't':
5733 {
5734 if (LocaleCompare("taint",option+1) == 0)
5735 break;
5736 if (LocaleCompare("texture",option+1) == 0)
5737 {
5738 if (*option == '+')
5739 break;
5740 i++;
cristybb503372010-05-27 20:51:26 +00005741 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005742 ThrowMogrifyException(OptionError,"MissingArgument",option);
5743 break;
5744 }
5745 if (LocaleCompare("tile",option+1) == 0)
5746 {
5747 if (*option == '+')
5748 break;
5749 i++;
cristybb503372010-05-27 20:51:26 +00005750 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005751 ThrowMogrifyException(OptionError,"MissingArgument",option);
5752 break;
5753 }
5754 if (LocaleCompare("tile-offset",option+1) == 0)
5755 {
5756 if (*option == '+')
5757 break;
5758 i++;
cristybb503372010-05-27 20:51:26 +00005759 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005760 ThrowMogrifyException(OptionError,"MissingArgument",option);
5761 if (IsGeometry(argv[i]) == MagickFalse)
5762 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5763 break;
5764 }
5765 if (LocaleCompare("tint",option+1) == 0)
5766 {
5767 if (*option == '+')
5768 break;
5769 i++;
cristybb503372010-05-27 20:51:26 +00005770 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005771 ThrowMogrifyException(OptionError,"MissingArgument",option);
5772 if (IsGeometry(argv[i]) == MagickFalse)
5773 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5774 break;
5775 }
5776 if (LocaleCompare("transform",option+1) == 0)
5777 break;
5778 if (LocaleCompare("transpose",option+1) == 0)
5779 break;
5780 if (LocaleCompare("transverse",option+1) == 0)
5781 break;
5782 if (LocaleCompare("threshold",option+1) == 0)
5783 {
5784 if (*option == '+')
5785 break;
5786 i++;
cristybb503372010-05-27 20:51:26 +00005787 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005788 ThrowMogrifyException(OptionError,"MissingArgument",option);
5789 if (IsGeometry(argv[i]) == MagickFalse)
5790 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5791 break;
5792 }
5793 if (LocaleCompare("thumbnail",option+1) == 0)
5794 {
5795 if (*option == '+')
5796 break;
5797 i++;
cristybb503372010-05-27 20:51:26 +00005798 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005799 ThrowMogrifyException(OptionError,"MissingArgument",option);
5800 if (IsGeometry(argv[i]) == MagickFalse)
5801 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5802 break;
5803 }
5804 if (LocaleCompare("transparent",option+1) == 0)
5805 {
5806 i++;
cristybb503372010-05-27 20:51:26 +00005807 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005808 ThrowMogrifyException(OptionError,"MissingArgument",option);
5809 break;
5810 }
5811 if (LocaleCompare("transparent-color",option+1) == 0)
5812 {
5813 if (*option == '+')
5814 break;
5815 i++;
cristybb503372010-05-27 20:51:26 +00005816 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005817 ThrowMogrifyException(OptionError,"MissingArgument",option);
5818 break;
5819 }
5820 if (LocaleCompare("treedepth",option+1) == 0)
5821 {
5822 if (*option == '+')
5823 break;
5824 i++;
cristybb503372010-05-27 20:51:26 +00005825 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005826 ThrowMogrifyException(OptionError,"MissingArgument",option);
5827 if (IsGeometry(argv[i]) == MagickFalse)
5828 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5829 break;
5830 }
5831 if (LocaleCompare("trim",option+1) == 0)
5832 break;
5833 if (LocaleCompare("type",option+1) == 0)
5834 {
cristybb503372010-05-27 20:51:26 +00005835 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005836 type;
5837
5838 if (*option == '+')
5839 break;
5840 i++;
cristybb503372010-05-27 20:51:26 +00005841 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005842 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005843 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005844 if (type < 0)
5845 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5846 argv[i]);
5847 break;
5848 }
5849 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5850 }
5851 case 'u':
5852 {
5853 if (LocaleCompare("undercolor",option+1) == 0)
5854 {
5855 if (*option == '+')
5856 break;
5857 i++;
cristybb503372010-05-27 20:51:26 +00005858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005859 ThrowMogrifyException(OptionError,"MissingArgument",option);
5860 break;
5861 }
5862 if (LocaleCompare("unique-colors",option+1) == 0)
5863 break;
5864 if (LocaleCompare("units",option+1) == 0)
5865 {
cristybb503372010-05-27 20:51:26 +00005866 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005867 units;
5868
5869 if (*option == '+')
5870 break;
5871 i++;
cristybb503372010-05-27 20:51:26 +00005872 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005873 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005874 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005875 argv[i]);
5876 if (units < 0)
5877 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5878 argv[i]);
5879 break;
5880 }
5881 if (LocaleCompare("unsharp",option+1) == 0)
5882 {
5883 i++;
cristybb503372010-05-27 20:51:26 +00005884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005885 ThrowMogrifyException(OptionError,"MissingArgument",option);
5886 if (IsGeometry(argv[i]) == MagickFalse)
5887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5888 break;
5889 }
5890 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5891 }
5892 case 'v':
5893 {
5894 if (LocaleCompare("verbose",option+1) == 0)
5895 {
5896 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5897 break;
5898 }
5899 if ((LocaleCompare("version",option+1) == 0) ||
5900 (LocaleCompare("-version",option+1) == 0))
5901 {
cristyb51dff52011-05-19 16:55:47 +00005902 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005903 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005904 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5905 GetMagickCopyright());
5906 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5907 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005908 break;
5909 }
5910 if (LocaleCompare("view",option+1) == 0)
5911 {
5912 if (*option == '+')
5913 break;
5914 i++;
cristybb503372010-05-27 20:51:26 +00005915 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005916 ThrowMogrifyException(OptionError,"MissingArgument",option);
5917 break;
5918 }
5919 if (LocaleCompare("vignette",option+1) == 0)
5920 {
5921 if (*option == '+')
5922 break;
5923 i++;
cristybb503372010-05-27 20:51:26 +00005924 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005925 ThrowMogrifyException(OptionError,"MissingArgument",option);
5926 if (IsGeometry(argv[i]) == MagickFalse)
5927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5928 break;
5929 }
5930 if (LocaleCompare("virtual-pixel",option+1) == 0)
5931 {
cristybb503372010-05-27 20:51:26 +00005932 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005933 method;
5934
5935 if (*option == '+')
5936 break;
5937 i++;
cristybb503372010-05-27 20:51:26 +00005938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005939 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005940 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005941 argv[i]);
5942 if (method < 0)
5943 ThrowMogrifyException(OptionError,
5944 "UnrecognizedVirtualPixelMethod",argv[i]);
5945 break;
5946 }
5947 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5948 }
5949 case 'w':
5950 {
5951 if (LocaleCompare("wave",option+1) == 0)
5952 {
5953 i++;
cristybb503372010-05-27 20:51:26 +00005954 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005955 ThrowMogrifyException(OptionError,"MissingArgument",option);
5956 if (IsGeometry(argv[i]) == MagickFalse)
5957 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5958 break;
5959 }
5960 if (LocaleCompare("weight",option+1) == 0)
5961 {
5962 if (*option == '+')
5963 break;
5964 i++;
cristybb503372010-05-27 20:51:26 +00005965 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005966 ThrowMogrifyException(OptionError,"MissingArgument",option);
5967 break;
5968 }
5969 if (LocaleCompare("white-point",option+1) == 0)
5970 {
5971 if (*option == '+')
5972 break;
5973 i++;
cristybb503372010-05-27 20:51:26 +00005974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005975 ThrowMogrifyException(OptionError,"MissingArgument",option);
5976 if (IsGeometry(argv[i]) == MagickFalse)
5977 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5978 break;
5979 }
5980 if (LocaleCompare("white-threshold",option+1) == 0)
5981 {
5982 if (*option == '+')
5983 break;
5984 i++;
cristybb503372010-05-27 20:51:26 +00005985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005986 ThrowMogrifyException(OptionError,"MissingArgument",option);
5987 if (IsGeometry(argv[i]) == MagickFalse)
5988 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5989 break;
5990 }
5991 if (LocaleCompare("write",option+1) == 0)
5992 {
5993 i++;
cristybb503372010-05-27 20:51:26 +00005994 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005995 ThrowMogrifyException(OptionError,"MissingArgument",option);
5996 break;
5997 }
5998 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5999 }
6000 case '?':
6001 break;
6002 default:
6003 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6004 }
cristy042ee782011-04-22 18:48:30 +00006005 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6006 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006007 if (fire != MagickFalse)
6008 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6009 }
6010 if (k != 0)
6011 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006012 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006013 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6014 DestroyMogrify();
6015 return(status != 0 ? MagickTrue : MagickFalse);
6016}
6017
6018/*
6019%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6020% %
6021% %
6022% %
6023+ M o g r i f y I m a g e I n f o %
6024% %
6025% %
6026% %
6027%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6028%
6029% MogrifyImageInfo() applies image processing settings to the image as
6030% prescribed by command line options.
6031%
6032% The format of the MogrifyImageInfo method is:
6033%
6034% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6035% const char **argv,ExceptionInfo *exception)
6036%
6037% A description of each parameter follows:
6038%
6039% o image_info: the image info..
6040%
6041% o argc: Specifies a pointer to an integer describing the number of
6042% elements in the argument vector.
6043%
6044% o argv: Specifies a pointer to a text array containing the command line
6045% arguments.
6046%
6047% o exception: return any errors or warnings in this structure.
6048%
6049*/
6050WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6051 const int argc,const char **argv,ExceptionInfo *exception)
6052{
6053 const char
6054 *option;
6055
6056 GeometryInfo
6057 geometry_info;
6058
cristybb503372010-05-27 20:51:26 +00006059 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006060 count;
6061
cristybb503372010-05-27 20:51:26 +00006062 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006063 i;
6064
6065 /*
6066 Initialize method variables.
6067 */
6068 assert(image_info != (ImageInfo *) NULL);
6069 assert(image_info->signature == MagickSignature);
6070 if (image_info->debug != MagickFalse)
6071 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6072 image_info->filename);
6073 if (argc < 0)
6074 return(MagickTrue);
6075 /*
6076 Set the image settings.
6077 */
cristybb503372010-05-27 20:51:26 +00006078 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006079 {
6080 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006081 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006082 continue;
cristy042ee782011-04-22 18:48:30 +00006083 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006084 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006085 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006086 break;
6087 switch (*(option+1))
6088 {
6089 case 'a':
6090 {
6091 if (LocaleCompare("adjoin",option+1) == 0)
6092 {
6093 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6094 break;
6095 }
6096 if (LocaleCompare("antialias",option+1) == 0)
6097 {
6098 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6099 break;
6100 }
6101 if (LocaleCompare("attenuate",option+1) == 0)
6102 {
6103 if (*option == '+')
6104 {
6105 (void) DeleteImageOption(image_info,option+1);
6106 break;
6107 }
6108 (void) SetImageOption(image_info,option+1,argv[i+1]);
6109 break;
6110 }
6111 if (LocaleCompare("authenticate",option+1) == 0)
6112 {
6113 if (*option == '+')
6114 (void) CloneString(&image_info->authenticate,(char *) NULL);
6115 else
6116 (void) CloneString(&image_info->authenticate,argv[i+1]);
6117 break;
6118 }
6119 break;
6120 }
6121 case 'b':
6122 {
6123 if (LocaleCompare("background",option+1) == 0)
6124 {
6125 if (*option == '+')
6126 {
6127 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006128 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006129 &image_info->background_color,exception);
6130 break;
6131 }
6132 (void) SetImageOption(image_info,option+1,argv[i+1]);
6133 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6134 exception);
6135 break;
6136 }
6137 if (LocaleCompare("bias",option+1) == 0)
6138 {
6139 if (*option == '+')
6140 {
6141 (void) SetImageOption(image_info,option+1,"0.0");
6142 break;
6143 }
6144 (void) SetImageOption(image_info,option+1,argv[i+1]);
6145 break;
6146 }
6147 if (LocaleCompare("black-point-compensation",option+1) == 0)
6148 {
6149 if (*option == '+')
6150 {
6151 (void) SetImageOption(image_info,option+1,"false");
6152 break;
6153 }
6154 (void) SetImageOption(image_info,option+1,"true");
6155 break;
6156 }
6157 if (LocaleCompare("blue-primary",option+1) == 0)
6158 {
6159 if (*option == '+')
6160 {
6161 (void) SetImageOption(image_info,option+1,"0.0");
6162 break;
6163 }
6164 (void) SetImageOption(image_info,option+1,argv[i+1]);
6165 break;
6166 }
6167 if (LocaleCompare("bordercolor",option+1) == 0)
6168 {
6169 if (*option == '+')
6170 {
6171 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006172 (void) QueryColorDatabase(MogrifyBorderColor,
6173 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006174 break;
6175 }
6176 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6177 exception);
6178 (void) SetImageOption(image_info,option+1,argv[i+1]);
6179 break;
6180 }
6181 if (LocaleCompare("box",option+1) == 0)
6182 {
6183 if (*option == '+')
6184 {
6185 (void) SetImageOption(image_info,"undercolor","none");
6186 break;
6187 }
6188 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6189 break;
6190 }
6191 break;
6192 }
6193 case 'c':
6194 {
6195 if (LocaleCompare("cache",option+1) == 0)
6196 {
6197 MagickSizeType
6198 limit;
6199
6200 limit=MagickResourceInfinity;
6201 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006202 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006203 (void) SetMagickResourceLimit(MemoryResource,limit);
6204 (void) SetMagickResourceLimit(MapResource,2*limit);
6205 break;
6206 }
6207 if (LocaleCompare("caption",option+1) == 0)
6208 {
6209 if (*option == '+')
6210 {
6211 (void) DeleteImageOption(image_info,option+1);
6212 break;
6213 }
6214 (void) SetImageOption(image_info,option+1,argv[i+1]);
6215 break;
6216 }
6217 if (LocaleCompare("channel",option+1) == 0)
6218 {
6219 if (*option == '+')
6220 {
6221 image_info->channel=DefaultChannels;
6222 break;
6223 }
6224 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6225 break;
6226 }
6227 if (LocaleCompare("colors",option+1) == 0)
6228 {
cristye27293e2009-12-18 02:53:20 +00006229 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006230 break;
6231 }
6232 if (LocaleCompare("colorspace",option+1) == 0)
6233 {
6234 if (*option == '+')
6235 {
6236 image_info->colorspace=UndefinedColorspace;
6237 (void) SetImageOption(image_info,option+1,"undefined");
6238 break;
6239 }
cristy042ee782011-04-22 18:48:30 +00006240 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006241 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6242 (void) SetImageOption(image_info,option+1,argv[i+1]);
6243 break;
6244 }
cristy3ed852e2009-09-05 21:47:34 +00006245 if (LocaleCompare("comment",option+1) == 0)
6246 {
6247 if (*option == '+')
6248 {
6249 (void) DeleteImageOption(image_info,option+1);
6250 break;
6251 }
6252 (void) SetImageOption(image_info,option+1,argv[i+1]);
6253 break;
6254 }
6255 if (LocaleCompare("compose",option+1) == 0)
6256 {
6257 if (*option == '+')
6258 {
6259 (void) SetImageOption(image_info,option+1,"undefined");
6260 break;
6261 }
6262 (void) SetImageOption(image_info,option+1,argv[i+1]);
6263 break;
6264 }
6265 if (LocaleCompare("compress",option+1) == 0)
6266 {
6267 if (*option == '+')
6268 {
6269 image_info->compression=UndefinedCompression;
6270 (void) SetImageOption(image_info,option+1,"undefined");
6271 break;
6272 }
cristy042ee782011-04-22 18:48:30 +00006273 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006274 MagickCompressOptions,MagickFalse,argv[i+1]);
6275 (void) SetImageOption(image_info,option+1,argv[i+1]);
6276 break;
6277 }
6278 break;
6279 }
6280 case 'd':
6281 {
6282 if (LocaleCompare("debug",option+1) == 0)
6283 {
6284 if (*option == '+')
6285 (void) SetLogEventMask("none");
6286 else
6287 (void) SetLogEventMask(argv[i+1]);
6288 image_info->debug=IsEventLogging();
6289 break;
6290 }
6291 if (LocaleCompare("define",option+1) == 0)
6292 {
6293 if (*option == '+')
6294 {
6295 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6296 (void) DeleteImageRegistry(argv[i+1]+9);
6297 else
6298 (void) DeleteImageOption(image_info,argv[i+1]);
6299 break;
6300 }
6301 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6302 {
6303 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6304 exception);
6305 break;
6306 }
6307 (void) DefineImageOption(image_info,argv[i+1]);
6308 break;
6309 }
6310 if (LocaleCompare("delay",option+1) == 0)
6311 {
6312 if (*option == '+')
6313 {
6314 (void) SetImageOption(image_info,option+1,"0");
6315 break;
6316 }
6317 (void) SetImageOption(image_info,option+1,argv[i+1]);
6318 break;
6319 }
6320 if (LocaleCompare("density",option+1) == 0)
6321 {
6322 /*
6323 Set image density.
6324 */
6325 if (*option == '+')
6326 {
6327 if (image_info->density != (char *) NULL)
6328 image_info->density=DestroyString(image_info->density);
6329 (void) SetImageOption(image_info,option+1,"72");
6330 break;
6331 }
6332 (void) CloneString(&image_info->density,argv[i+1]);
6333 (void) SetImageOption(image_info,option+1,argv[i+1]);
6334 break;
6335 }
6336 if (LocaleCompare("depth",option+1) == 0)
6337 {
6338 if (*option == '+')
6339 {
6340 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6341 break;
6342 }
cristye27293e2009-12-18 02:53:20 +00006343 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006344 break;
6345 }
cristyc9b12952010-03-28 01:12:28 +00006346 if (LocaleCompare("direction",option+1) == 0)
6347 {
6348 if (*option == '+')
6349 {
6350 (void) SetImageOption(image_info,option+1,"undefined");
6351 break;
6352 }
6353 (void) SetImageOption(image_info,option+1,argv[i+1]);
6354 break;
6355 }
cristy3ed852e2009-09-05 21:47:34 +00006356 if (LocaleCompare("display",option+1) == 0)
6357 {
6358 if (*option == '+')
6359 {
6360 if (image_info->server_name != (char *) NULL)
6361 image_info->server_name=DestroyString(
6362 image_info->server_name);
6363 break;
6364 }
6365 (void) CloneString(&image_info->server_name,argv[i+1]);
6366 break;
6367 }
6368 if (LocaleCompare("dispose",option+1) == 0)
6369 {
6370 if (*option == '+')
6371 {
6372 (void) SetImageOption(image_info,option+1,"undefined");
6373 break;
6374 }
6375 (void) SetImageOption(image_info,option+1,argv[i+1]);
6376 break;
6377 }
6378 if (LocaleCompare("dither",option+1) == 0)
6379 {
6380 if (*option == '+')
6381 {
6382 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006383 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006384 break;
6385 }
6386 (void) SetImageOption(image_info,option+1,argv[i+1]);
6387 image_info->dither=MagickTrue;
6388 break;
6389 }
6390 break;
6391 }
6392 case 'e':
6393 {
6394 if (LocaleCompare("encoding",option+1) == 0)
6395 {
6396 if (*option == '+')
6397 {
6398 (void) SetImageOption(image_info,option+1,"undefined");
6399 break;
6400 }
6401 (void) SetImageOption(image_info,option+1,argv[i+1]);
6402 break;
6403 }
6404 if (LocaleCompare("endian",option+1) == 0)
6405 {
6406 if (*option == '+')
6407 {
6408 image_info->endian=UndefinedEndian;
6409 (void) SetImageOption(image_info,option+1,"undefined");
6410 break;
6411 }
cristy042ee782011-04-22 18:48:30 +00006412 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006413 MagickEndianOptions,MagickFalse,argv[i+1]);
6414 (void) SetImageOption(image_info,option+1,argv[i+1]);
6415 break;
6416 }
6417 if (LocaleCompare("extract",option+1) == 0)
6418 {
6419 /*
6420 Set image extract geometry.
6421 */
6422 if (*option == '+')
6423 {
6424 if (image_info->extract != (char *) NULL)
6425 image_info->extract=DestroyString(image_info->extract);
6426 break;
6427 }
6428 (void) CloneString(&image_info->extract,argv[i+1]);
6429 break;
6430 }
6431 break;
6432 }
6433 case 'f':
6434 {
6435 if (LocaleCompare("fill",option+1) == 0)
6436 {
6437 if (*option == '+')
6438 {
6439 (void) SetImageOption(image_info,option+1,"none");
6440 break;
6441 }
6442 (void) SetImageOption(image_info,option+1,argv[i+1]);
6443 break;
6444 }
6445 if (LocaleCompare("filter",option+1) == 0)
6446 {
6447 if (*option == '+')
6448 {
6449 (void) SetImageOption(image_info,option+1,"undefined");
6450 break;
6451 }
6452 (void) SetImageOption(image_info,option+1,argv[i+1]);
6453 break;
6454 }
6455 if (LocaleCompare("font",option+1) == 0)
6456 {
6457 if (*option == '+')
6458 {
6459 if (image_info->font != (char *) NULL)
6460 image_info->font=DestroyString(image_info->font);
6461 break;
6462 }
6463 (void) CloneString(&image_info->font,argv[i+1]);
6464 break;
6465 }
6466 if (LocaleCompare("format",option+1) == 0)
6467 {
6468 register const char
6469 *q;
6470
6471 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006472 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006473 image_info->ping=MagickFalse;
6474 (void) SetImageOption(image_info,option+1,argv[i+1]);
6475 break;
6476 }
6477 if (LocaleCompare("fuzz",option+1) == 0)
6478 {
6479 if (*option == '+')
6480 {
6481 image_info->fuzz=0.0;
6482 (void) SetImageOption(image_info,option+1,"0");
6483 break;
6484 }
cristyf2f27272009-12-17 14:48:46 +00006485 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006486 1.0);
6487 (void) SetImageOption(image_info,option+1,argv[i+1]);
6488 break;
6489 }
6490 break;
6491 }
6492 case 'g':
6493 {
6494 if (LocaleCompare("gravity",option+1) == 0)
6495 {
6496 if (*option == '+')
6497 {
6498 (void) SetImageOption(image_info,option+1,"undefined");
6499 break;
6500 }
6501 (void) SetImageOption(image_info,option+1,argv[i+1]);
6502 break;
6503 }
6504 if (LocaleCompare("green-primary",option+1) == 0)
6505 {
6506 if (*option == '+')
6507 {
6508 (void) SetImageOption(image_info,option+1,"0.0");
6509 break;
6510 }
6511 (void) SetImageOption(image_info,option+1,argv[i+1]);
6512 break;
6513 }
6514 break;
6515 }
6516 case 'i':
6517 {
6518 if (LocaleCompare("intent",option+1) == 0)
6519 {
6520 if (*option == '+')
6521 {
6522 (void) SetImageOption(image_info,option+1,"undefined");
6523 break;
6524 }
6525 (void) SetImageOption(image_info,option+1,argv[i+1]);
6526 break;
6527 }
6528 if (LocaleCompare("interlace",option+1) == 0)
6529 {
6530 if (*option == '+')
6531 {
6532 image_info->interlace=UndefinedInterlace;
6533 (void) SetImageOption(image_info,option+1,"undefined");
6534 break;
6535 }
cristy042ee782011-04-22 18:48:30 +00006536 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006537 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6538 (void) SetImageOption(image_info,option+1,argv[i+1]);
6539 break;
6540 }
cristyb32b90a2009-09-07 21:45:48 +00006541 if (LocaleCompare("interline-spacing",option+1) == 0)
6542 {
6543 if (*option == '+')
6544 {
6545 (void) SetImageOption(image_info,option+1,"undefined");
6546 break;
6547 }
6548 (void) SetImageOption(image_info,option+1,argv[i+1]);
6549 break;
6550 }
cristy3ed852e2009-09-05 21:47:34 +00006551 if (LocaleCompare("interpolate",option+1) == 0)
6552 {
6553 if (*option == '+')
6554 {
6555 (void) SetImageOption(image_info,option+1,"undefined");
6556 break;
6557 }
6558 (void) SetImageOption(image_info,option+1,argv[i+1]);
6559 break;
6560 }
6561 if (LocaleCompare("interword-spacing",option+1) == 0)
6562 {
6563 if (*option == '+')
6564 {
6565 (void) SetImageOption(image_info,option+1,"undefined");
6566 break;
6567 }
6568 (void) SetImageOption(image_info,option+1,argv[i+1]);
6569 break;
6570 }
6571 break;
6572 }
6573 case 'k':
6574 {
6575 if (LocaleCompare("kerning",option+1) == 0)
6576 {
6577 if (*option == '+')
6578 {
6579 (void) SetImageOption(image_info,option+1,"undefined");
6580 break;
6581 }
6582 (void) SetImageOption(image_info,option+1,argv[i+1]);
6583 break;
6584 }
6585 break;
6586 }
6587 case 'l':
6588 {
6589 if (LocaleCompare("label",option+1) == 0)
6590 {
6591 if (*option == '+')
6592 {
6593 (void) DeleteImageOption(image_info,option+1);
6594 break;
6595 }
6596 (void) SetImageOption(image_info,option+1,argv[i+1]);
6597 break;
6598 }
6599 if (LocaleCompare("limit",option+1) == 0)
6600 {
6601 MagickSizeType
6602 limit;
6603
6604 ResourceType
6605 type;
6606
6607 if (*option == '+')
6608 break;
cristy042ee782011-04-22 18:48:30 +00006609 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006610 MagickFalse,argv[i+1]);
6611 limit=MagickResourceInfinity;
6612 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006613 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006614 (void) SetMagickResourceLimit(type,limit);
6615 break;
6616 }
6617 if (LocaleCompare("list",option+1) == 0)
6618 {
cristybb503372010-05-27 20:51:26 +00006619 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006620 list;
6621
6622 /*
6623 Display configuration list.
6624 */
cristy042ee782011-04-22 18:48:30 +00006625 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006626 switch (list)
6627 {
6628 case MagickCoderOptions:
6629 {
6630 (void) ListCoderInfo((FILE *) NULL,exception);
6631 break;
6632 }
6633 case MagickColorOptions:
6634 {
6635 (void) ListColorInfo((FILE *) NULL,exception);
6636 break;
6637 }
6638 case MagickConfigureOptions:
6639 {
6640 (void) ListConfigureInfo((FILE *) NULL,exception);
6641 break;
6642 }
6643 case MagickDelegateOptions:
6644 {
6645 (void) ListDelegateInfo((FILE *) NULL,exception);
6646 break;
6647 }
6648 case MagickFontOptions:
6649 {
6650 (void) ListTypeInfo((FILE *) NULL,exception);
6651 break;
6652 }
6653 case MagickFormatOptions:
6654 {
6655 (void) ListMagickInfo((FILE *) NULL,exception);
6656 break;
6657 }
6658 case MagickLocaleOptions:
6659 {
6660 (void) ListLocaleInfo((FILE *) NULL,exception);
6661 break;
6662 }
6663 case MagickLogOptions:
6664 {
6665 (void) ListLogInfo((FILE *) NULL,exception);
6666 break;
6667 }
6668 case MagickMagicOptions:
6669 {
6670 (void) ListMagicInfo((FILE *) NULL,exception);
6671 break;
6672 }
6673 case MagickMimeOptions:
6674 {
6675 (void) ListMimeInfo((FILE *) NULL,exception);
6676 break;
6677 }
6678 case MagickModuleOptions:
6679 {
6680 (void) ListModuleInfo((FILE *) NULL,exception);
6681 break;
6682 }
6683 case MagickPolicyOptions:
6684 {
6685 (void) ListPolicyInfo((FILE *) NULL,exception);
6686 break;
6687 }
6688 case MagickResourceOptions:
6689 {
6690 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6691 break;
6692 }
6693 case MagickThresholdOptions:
6694 {
6695 (void) ListThresholdMaps((FILE *) NULL,exception);
6696 break;
6697 }
6698 default:
6699 {
cristy042ee782011-04-22 18:48:30 +00006700 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006701 exception);
6702 break;
6703 }
6704 }
cristyaeb2cbc2010-05-07 13:28:58 +00006705 break;
cristy3ed852e2009-09-05 21:47:34 +00006706 }
6707 if (LocaleCompare("log",option+1) == 0)
6708 {
6709 if (*option == '+')
6710 break;
6711 (void) SetLogFormat(argv[i+1]);
6712 break;
6713 }
6714 if (LocaleCompare("loop",option+1) == 0)
6715 {
6716 if (*option == '+')
6717 {
6718 (void) SetImageOption(image_info,option+1,"0");
6719 break;
6720 }
6721 (void) SetImageOption(image_info,option+1,argv[i+1]);
6722 break;
6723 }
6724 break;
6725 }
6726 case 'm':
6727 {
6728 if (LocaleCompare("matte",option+1) == 0)
6729 {
6730 if (*option == '+')
6731 {
6732 (void) SetImageOption(image_info,option+1,"false");
6733 break;
6734 }
6735 (void) SetImageOption(image_info,option+1,"true");
6736 break;
6737 }
6738 if (LocaleCompare("mattecolor",option+1) == 0)
6739 {
6740 if (*option == '+')
6741 {
6742 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006743 (void) QueryColorDatabase(MogrifyMatteColor,
6744 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006745 break;
6746 }
6747 (void) SetImageOption(image_info,option+1,argv[i+1]);
6748 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6749 exception);
6750 break;
6751 }
6752 if (LocaleCompare("monitor",option+1) == 0)
6753 {
6754 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6755 (void *) NULL);
6756 break;
6757 }
6758 if (LocaleCompare("monochrome",option+1) == 0)
6759 {
6760 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6761 break;
6762 }
6763 break;
6764 }
6765 case 'o':
6766 {
6767 if (LocaleCompare("orient",option+1) == 0)
6768 {
6769 if (*option == '+')
6770 {
6771 image_info->orientation=UndefinedOrientation;
6772 (void) SetImageOption(image_info,option+1,"undefined");
6773 break;
6774 }
cristy042ee782011-04-22 18:48:30 +00006775 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006776 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006777 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006778 break;
6779 }
6780 }
6781 case 'p':
6782 {
6783 if (LocaleCompare("page",option+1) == 0)
6784 {
6785 char
6786 *canonical_page,
6787 page[MaxTextExtent];
6788
6789 const char
6790 *image_option;
6791
6792 MagickStatusType
6793 flags;
6794
6795 RectangleInfo
6796 geometry;
6797
6798 if (*option == '+')
6799 {
6800 (void) DeleteImageOption(image_info,option+1);
6801 (void) CloneString(&image_info->page,(char *) NULL);
6802 break;
6803 }
6804 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6805 image_option=GetImageOption(image_info,"page");
6806 if (image_option != (const char *) NULL)
6807 flags=ParseAbsoluteGeometry(image_option,&geometry);
6808 canonical_page=GetPageGeometry(argv[i+1]);
6809 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6810 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006811 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006812 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006813 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006814 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006815 (unsigned long) geometry.width,(unsigned long) geometry.height,
6816 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006817 (void) SetImageOption(image_info,option+1,page);
6818 (void) CloneString(&image_info->page,page);
6819 break;
6820 }
6821 if (LocaleCompare("pen",option+1) == 0)
6822 {
6823 if (*option == '+')
6824 {
6825 (void) SetImageOption(image_info,option+1,"none");
6826 break;
6827 }
6828 (void) SetImageOption(image_info,option+1,argv[i+1]);
6829 break;
6830 }
6831 if (LocaleCompare("ping",option+1) == 0)
6832 {
6833 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6834 break;
6835 }
6836 if (LocaleCompare("pointsize",option+1) == 0)
6837 {
6838 if (*option == '+')
6839 geometry_info.rho=0.0;
6840 else
6841 (void) ParseGeometry(argv[i+1],&geometry_info);
6842 image_info->pointsize=geometry_info.rho;
6843 break;
6844 }
cristye7f51092010-01-17 00:39:37 +00006845 if (LocaleCompare("precision",option+1) == 0)
6846 {
cristybf2766a2010-01-17 03:33:23 +00006847 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006848 break;
6849 }
cristy3ed852e2009-09-05 21:47:34 +00006850 if (LocaleCompare("preview",option+1) == 0)
6851 {
6852 /*
6853 Preview image.
6854 */
6855 if (*option == '+')
6856 {
6857 image_info->preview_type=UndefinedPreview;
6858 break;
6859 }
cristy042ee782011-04-22 18:48:30 +00006860 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006861 MagickPreviewOptions,MagickFalse,argv[i+1]);
6862 break;
6863 }
6864 break;
6865 }
6866 case 'q':
6867 {
6868 if (LocaleCompare("quality",option+1) == 0)
6869 {
6870 /*
6871 Set image compression quality.
6872 */
6873 if (*option == '+')
6874 {
6875 image_info->quality=UndefinedCompressionQuality;
6876 (void) SetImageOption(image_info,option+1,"0");
6877 break;
6878 }
cristye27293e2009-12-18 02:53:20 +00006879 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006880 (void) SetImageOption(image_info,option+1,argv[i+1]);
6881 break;
6882 }
6883 if (LocaleCompare("quiet",option+1) == 0)
6884 {
6885 static WarningHandler
6886 warning_handler = (WarningHandler) NULL;
6887
6888 if (*option == '+')
6889 {
6890 /*
6891 Restore error or warning messages.
6892 */
6893 warning_handler=SetWarningHandler(warning_handler);
6894 break;
6895 }
6896 /*
6897 Suppress error or warning messages.
6898 */
6899 warning_handler=SetWarningHandler((WarningHandler) NULL);
6900 break;
6901 }
6902 break;
6903 }
6904 case 'r':
6905 {
6906 if (LocaleCompare("red-primary",option+1) == 0)
6907 {
6908 if (*option == '+')
6909 {
6910 (void) SetImageOption(image_info,option+1,"0.0");
6911 break;
6912 }
6913 (void) SetImageOption(image_info,option+1,argv[i+1]);
6914 break;
6915 }
6916 break;
6917 }
6918 case 's':
6919 {
6920 if (LocaleCompare("sampling-factor",option+1) == 0)
6921 {
6922 /*
6923 Set image sampling factor.
6924 */
6925 if (*option == '+')
6926 {
6927 if (image_info->sampling_factor != (char *) NULL)
6928 image_info->sampling_factor=DestroyString(
6929 image_info->sampling_factor);
6930 break;
6931 }
6932 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6933 break;
6934 }
6935 if (LocaleCompare("scene",option+1) == 0)
6936 {
6937 /*
6938 Set image scene.
6939 */
6940 if (*option == '+')
6941 {
6942 image_info->scene=0;
6943 (void) SetImageOption(image_info,option+1,"0");
6944 break;
6945 }
cristye27293e2009-12-18 02:53:20 +00006946 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006947 (void) SetImageOption(image_info,option+1,argv[i+1]);
6948 break;
6949 }
6950 if (LocaleCompare("seed",option+1) == 0)
6951 {
cristybb503372010-05-27 20:51:26 +00006952 size_t
cristy3ed852e2009-09-05 21:47:34 +00006953 seed;
6954
6955 if (*option == '+')
6956 {
cristybb503372010-05-27 20:51:26 +00006957 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006958 SeedPseudoRandomGenerator(seed);
6959 break;
6960 }
cristye27293e2009-12-18 02:53:20 +00006961 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006962 SeedPseudoRandomGenerator(seed);
6963 break;
6964 }
6965 if (LocaleCompare("size",option+1) == 0)
6966 {
6967 if (*option == '+')
6968 {
6969 if (image_info->size != (char *) NULL)
6970 image_info->size=DestroyString(image_info->size);
6971 break;
6972 }
6973 (void) CloneString(&image_info->size,argv[i+1]);
6974 break;
6975 }
6976 if (LocaleCompare("stroke",option+1) == 0)
6977 {
6978 if (*option == '+')
6979 {
6980 (void) SetImageOption(image_info,option+1,"none");
6981 break;
6982 }
6983 (void) SetImageOption(image_info,option+1,argv[i+1]);
6984 break;
6985 }
6986 if (LocaleCompare("strokewidth",option+1) == 0)
6987 {
6988 if (*option == '+')
6989 {
6990 (void) SetImageOption(image_info,option+1,"0");
6991 break;
6992 }
6993 (void) SetImageOption(image_info,option+1,argv[i+1]);
6994 break;
6995 }
cristyd9a29192010-10-16 16:49:53 +00006996 if (LocaleCompare("synchronize",option+1) == 0)
6997 {
6998 if (*option == '+')
6999 {
7000 image_info->synchronize=MagickFalse;
7001 break;
7002 }
7003 image_info->synchronize=MagickTrue;
7004 break;
7005 }
cristy3ed852e2009-09-05 21:47:34 +00007006 break;
7007 }
7008 case 't':
7009 {
7010 if (LocaleCompare("taint",option+1) == 0)
7011 {
7012 if (*option == '+')
7013 {
7014 (void) SetImageOption(image_info,option+1,"false");
7015 break;
7016 }
7017 (void) SetImageOption(image_info,option+1,"true");
7018 break;
7019 }
7020 if (LocaleCompare("texture",option+1) == 0)
7021 {
7022 if (*option == '+')
7023 {
7024 if (image_info->texture != (char *) NULL)
7025 image_info->texture=DestroyString(image_info->texture);
7026 break;
7027 }
7028 (void) CloneString(&image_info->texture,argv[i+1]);
7029 break;
7030 }
7031 if (LocaleCompare("tile-offset",option+1) == 0)
7032 {
7033 if (*option == '+')
7034 {
7035 (void) SetImageOption(image_info,option+1,"0");
7036 break;
7037 }
7038 (void) SetImageOption(image_info,option+1,argv[i+1]);
7039 break;
7040 }
7041 if (LocaleCompare("transparent-color",option+1) == 0)
7042 {
7043 if (*option == '+')
7044 {
7045 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7046 (void) SetImageOption(image_info,option+1,"none");
7047 break;
7048 }
7049 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7050 exception);
7051 (void) SetImageOption(image_info,option+1,argv[i+1]);
7052 break;
7053 }
7054 if (LocaleCompare("type",option+1) == 0)
7055 {
7056 if (*option == '+')
7057 {
cristy5f1c1ff2010-12-23 21:38:06 +00007058 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007059 (void) SetImageOption(image_info,option+1,"undefined");
7060 break;
7061 }
cristy042ee782011-04-22 18:48:30 +00007062 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007063 MagickFalse,argv[i+1]);
7064 (void) SetImageOption(image_info,option+1,argv[i+1]);
7065 break;
7066 }
7067 break;
7068 }
7069 case 'u':
7070 {
7071 if (LocaleCompare("undercolor",option+1) == 0)
7072 {
7073 if (*option == '+')
7074 {
7075 (void) DeleteImageOption(image_info,option+1);
7076 break;
7077 }
7078 (void) SetImageOption(image_info,option+1,argv[i+1]);
7079 break;
7080 }
7081 if (LocaleCompare("units",option+1) == 0)
7082 {
7083 if (*option == '+')
7084 {
7085 image_info->units=UndefinedResolution;
7086 (void) SetImageOption(image_info,option+1,"undefined");
7087 break;
7088 }
cristy042ee782011-04-22 18:48:30 +00007089 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007090 MagickResolutionOptions,MagickFalse,argv[i+1]);
7091 (void) SetImageOption(image_info,option+1,argv[i+1]);
7092 break;
7093 }
7094 break;
7095 }
7096 case 'v':
7097 {
7098 if (LocaleCompare("verbose",option+1) == 0)
7099 {
7100 if (*option == '+')
7101 {
7102 image_info->verbose=MagickFalse;
7103 break;
7104 }
7105 image_info->verbose=MagickTrue;
7106 image_info->ping=MagickFalse;
7107 break;
7108 }
7109 if (LocaleCompare("view",option+1) == 0)
7110 {
7111 if (*option == '+')
7112 {
7113 if (image_info->view != (char *) NULL)
7114 image_info->view=DestroyString(image_info->view);
7115 break;
7116 }
7117 (void) CloneString(&image_info->view,argv[i+1]);
7118 break;
7119 }
7120 if (LocaleCompare("virtual-pixel",option+1) == 0)
7121 {
7122 if (*option == '+')
7123 {
7124 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7125 (void) SetImageOption(image_info,option+1,"undefined");
7126 break;
7127 }
7128 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007129 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007130 argv[i+1]);
7131 (void) SetImageOption(image_info,option+1,argv[i+1]);
7132 break;
7133 }
7134 break;
7135 }
7136 case 'w':
7137 {
7138 if (LocaleCompare("white-point",option+1) == 0)
7139 {
7140 if (*option == '+')
7141 {
7142 (void) SetImageOption(image_info,option+1,"0.0");
7143 break;
7144 }
7145 (void) SetImageOption(image_info,option+1,argv[i+1]);
7146 break;
7147 }
7148 break;
7149 }
7150 default:
7151 break;
7152 }
7153 i+=count;
7154 }
7155 return(MagickTrue);
7156}
7157
7158/*
7159%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7160% %
7161% %
7162% %
7163+ M o g r i f y I m a g e L i s t %
7164% %
7165% %
7166% %
7167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7168%
7169% MogrifyImageList() applies any command line options that might affect the
7170% entire image list (e.g. -append, -coalesce, etc.).
7171%
7172% The format of the MogrifyImage method is:
7173%
7174% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7175% const char **argv,Image **images,ExceptionInfo *exception)
7176%
7177% A description of each parameter follows:
7178%
7179% o image_info: the image info..
7180%
7181% o argc: Specifies a pointer to an integer describing the number of
7182% elements in the argument vector.
7183%
7184% o argv: Specifies a pointer to a text array containing the command line
7185% arguments.
7186%
anthonye9c27192011-03-27 08:07:06 +00007187% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007188%
7189% o exception: return any errors or warnings in this structure.
7190%
7191*/
7192WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7193 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7194{
cristy3ed852e2009-09-05 21:47:34 +00007195 const char
7196 *option;
7197
cristy6b3da3a2010-06-20 02:21:46 +00007198 ImageInfo
7199 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007200
7201 MagickStatusType
7202 status;
7203
7204 QuantizeInfo
7205 *quantize_info;
7206
cristybb503372010-05-27 20:51:26 +00007207 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007208 i;
7209
cristy6b3da3a2010-06-20 02:21:46 +00007210 ssize_t
7211 count,
7212 index;
7213
cristy3ed852e2009-09-05 21:47:34 +00007214 /*
7215 Apply options to the image list.
7216 */
7217 assert(image_info != (ImageInfo *) NULL);
7218 assert(image_info->signature == MagickSignature);
7219 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007220 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007221 assert((*images)->signature == MagickSignature);
7222 if ((*images)->debug != MagickFalse)
7223 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7224 (*images)->filename);
7225 if ((argc <= 0) || (*argv == (char *) NULL))
7226 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007227 mogrify_info=CloneImageInfo(image_info);
7228 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007229 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007230 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007231 {
cristy74fe8f12009-10-03 19:09:01 +00007232 if (*images == (Image *) NULL)
7233 break;
cristy3ed852e2009-09-05 21:47:34 +00007234 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007235 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007236 continue;
cristy042ee782011-04-22 18:48:30 +00007237 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007238 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007239 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007240 break;
cristy6b3da3a2010-06-20 02:21:46 +00007241 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007242 switch (*(option+1))
7243 {
7244 case 'a':
7245 {
7246 if (LocaleCompare("affinity",option+1) == 0)
7247 {
cristy6b3da3a2010-06-20 02:21:46 +00007248 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007249 if (*option == '+')
7250 {
cristy018f07f2011-09-04 21:15:19 +00007251 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7252 exception);
cristy3ed852e2009-09-05 21:47:34 +00007253 break;
7254 }
7255 i++;
7256 break;
7257 }
7258 if (LocaleCompare("append",option+1) == 0)
7259 {
7260 Image
7261 *append_image;
7262
cristy6b3da3a2010-06-20 02:21:46 +00007263 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007264 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7265 MagickFalse,exception);
7266 if (append_image == (Image *) NULL)
7267 {
7268 status=MagickFalse;
7269 break;
7270 }
7271 *images=DestroyImageList(*images);
7272 *images=append_image;
7273 break;
7274 }
7275 if (LocaleCompare("average",option+1) == 0)
7276 {
7277 Image
7278 *average_image;
7279
cristyd18ae7c2010-03-07 17:39:52 +00007280 /*
7281 Average an image sequence (deprecated).
7282 */
cristy6b3da3a2010-06-20 02:21:46 +00007283 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007284 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7285 exception);
cristy3ed852e2009-09-05 21:47:34 +00007286 if (average_image == (Image *) NULL)
7287 {
7288 status=MagickFalse;
7289 break;
7290 }
7291 *images=DestroyImageList(*images);
7292 *images=average_image;
7293 break;
7294 }
7295 break;
7296 }
7297 case 'c':
7298 {
7299 if (LocaleCompare("channel",option+1) == 0)
7300 {
cristyf4ad9df2011-07-08 16:49:03 +00007301 ChannelType
7302 channel;
7303
cristy3ed852e2009-09-05 21:47:34 +00007304 if (*option == '+')
7305 {
7306 channel=DefaultChannels;
7307 break;
7308 }
7309 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007310 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007311 break;
7312 }
7313 if (LocaleCompare("clut",option+1) == 0)
7314 {
7315 Image
7316 *clut_image,
7317 *image;
7318
cristy6b3da3a2010-06-20 02:21:46 +00007319 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007320 image=RemoveFirstImageFromList(images);
7321 clut_image=RemoveFirstImageFromList(images);
7322 if (clut_image == (Image *) NULL)
7323 {
7324 status=MagickFalse;
7325 break;
7326 }
cristy444eda62011-08-10 02:07:46 +00007327 (void) ClutImage(image,clut_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007328 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007329 *images=DestroyImageList(*images);
7330 *images=image;
7331 break;
7332 }
7333 if (LocaleCompare("coalesce",option+1) == 0)
7334 {
7335 Image
7336 *coalesce_image;
7337
cristy6b3da3a2010-06-20 02:21:46 +00007338 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007339 coalesce_image=CoalesceImages(*images,exception);
7340 if (coalesce_image == (Image *) NULL)
7341 {
7342 status=MagickFalse;
7343 break;
7344 }
7345 *images=DestroyImageList(*images);
7346 *images=coalesce_image;
7347 break;
7348 }
7349 if (LocaleCompare("combine",option+1) == 0)
7350 {
7351 Image
7352 *combine_image;
7353
cristy6b3da3a2010-06-20 02:21:46 +00007354 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007355 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007356 if (combine_image == (Image *) NULL)
7357 {
7358 status=MagickFalse;
7359 break;
7360 }
7361 *images=DestroyImageList(*images);
7362 *images=combine_image;
7363 break;
7364 }
7365 if (LocaleCompare("composite",option+1) == 0)
7366 {
7367 Image
7368 *mask_image,
7369 *composite_image,
7370 *image;
7371
7372 RectangleInfo
7373 geometry;
7374
cristy6b3da3a2010-06-20 02:21:46 +00007375 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007376 image=RemoveFirstImageFromList(images);
7377 composite_image=RemoveFirstImageFromList(images);
7378 if (composite_image == (Image *) NULL)
7379 {
7380 status=MagickFalse;
7381 break;
7382 }
7383 (void) TransformImage(&composite_image,(char *) NULL,
7384 composite_image->geometry);
7385 SetGeometry(composite_image,&geometry);
7386 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7387 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7388 &geometry);
7389 mask_image=RemoveFirstImageFromList(images);
7390 if (mask_image != (Image *) NULL)
7391 {
7392 if ((image->compose == DisplaceCompositeOp) ||
7393 (image->compose == DistortCompositeOp))
7394 {
7395 /*
7396 Merge Y displacement into X displacement image.
7397 */
7398 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7399 mask_image,0,0);
7400 mask_image=DestroyImage(mask_image);
7401 }
7402 else
7403 {
7404 /*
7405 Set a blending mask for the composition.
7406 */
anthonya129f702011-04-14 01:08:48 +00007407 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007408 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007409 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007410 }
7411 }
cristyf4ad9df2011-07-08 16:49:03 +00007412 (void) CompositeImage(image,image->compose,composite_image,
7413 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007414 if (mask_image != (Image *) NULL)
7415 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007416 composite_image=DestroyImage(composite_image);
7417 InheritException(exception,&image->exception);
7418 *images=DestroyImageList(*images);
7419 *images=image;
7420 break;
7421 }
anthony9f4f0342011-03-28 11:47:22 +00007422#if 0
7423This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007424 if (LocaleCompare("crop",option+1) == 0)
7425 {
7426 MagickStatusType
7427 flags;
7428
7429 RectangleInfo
7430 geometry;
7431
anthonye9c27192011-03-27 08:07:06 +00007432 /*
anthony9f4f0342011-03-28 11:47:22 +00007433 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007434 */
cristy6b3da3a2010-06-20 02:21:46 +00007435 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007436 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7437 if (((geometry.width == 0) && (geometry.height == 0)) ||
7438 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7439 break;
7440 (void) TransformImages(images,argv[i+1],(char *) NULL);
7441 InheritException(exception,&(*images)->exception);
7442 break;
7443 }
anthony9f4f0342011-03-28 11:47:22 +00007444#endif
cristy3ed852e2009-09-05 21:47:34 +00007445 break;
7446 }
7447 case 'd':
7448 {
7449 if (LocaleCompare("deconstruct",option+1) == 0)
7450 {
7451 Image
7452 *deconstruct_image;
7453
cristy6b3da3a2010-06-20 02:21:46 +00007454 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007455 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007456 exception);
cristy3ed852e2009-09-05 21:47:34 +00007457 if (deconstruct_image == (Image *) NULL)
7458 {
7459 status=MagickFalse;
7460 break;
7461 }
7462 *images=DestroyImageList(*images);
7463 *images=deconstruct_image;
7464 break;
7465 }
7466 if (LocaleCompare("delete",option+1) == 0)
7467 {
7468 if (*option == '+')
7469 DeleteImages(images,"-1",exception);
7470 else
7471 DeleteImages(images,argv[i+1],exception);
7472 break;
7473 }
7474 if (LocaleCompare("dither",option+1) == 0)
7475 {
7476 if (*option == '+')
7477 {
7478 quantize_info->dither=MagickFalse;
7479 break;
7480 }
7481 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007482 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007483 MagickDitherOptions,MagickFalse,argv[i+1]);
7484 break;
7485 }
cristyecb10ff2011-03-22 13:14:03 +00007486 if (LocaleCompare("duplicate",option+1) == 0)
7487 {
cristy72988482011-03-29 16:34:38 +00007488 Image
7489 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007490
anthony2b6bcae2011-03-23 13:05:34 +00007491 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007492 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7493 else
7494 {
7495 const char
7496 *p;
7497
anthony2b6bcae2011-03-23 13:05:34 +00007498 size_t
7499 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007500
anthony2b6bcae2011-03-23 13:05:34 +00007501 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007502 p=strchr(argv[i+1],',');
7503 if (p == (const char *) NULL)
7504 duplicate_images=DuplicateImages(*images,number_duplicates,
7505 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007506 else
cristy72988482011-03-29 16:34:38 +00007507 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7508 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007509 }
7510 AppendImageToList(images, duplicate_images);
7511 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007512 break;
7513 }
cristy3ed852e2009-09-05 21:47:34 +00007514 break;
7515 }
cristyd18ae7c2010-03-07 17:39:52 +00007516 case 'e':
7517 {
7518 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7519 {
7520 Image
7521 *evaluate_image;
7522
7523 MagickEvaluateOperator
7524 op;
7525
cristy6b3da3a2010-06-20 02:21:46 +00007526 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007527 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007528 MagickFalse,argv[i+1]);
7529 evaluate_image=EvaluateImages(*images,op,exception);
7530 if (evaluate_image == (Image *) NULL)
7531 {
7532 status=MagickFalse;
7533 break;
7534 }
7535 *images=DestroyImageList(*images);
7536 *images=evaluate_image;
7537 break;
7538 }
7539 break;
7540 }
cristy3ed852e2009-09-05 21:47:34 +00007541 case 'f':
7542 {
cristyf0a247f2009-10-04 00:20:03 +00007543 if (LocaleCompare("fft",option+1) == 0)
7544 {
7545 Image
7546 *fourier_image;
7547
7548 /*
7549 Implements the discrete Fourier transform (DFT).
7550 */
cristy6b3da3a2010-06-20 02:21:46 +00007551 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007552 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7553 MagickTrue : MagickFalse,exception);
7554 if (fourier_image == (Image *) NULL)
7555 break;
7556 *images=DestroyImage(*images);
7557 *images=fourier_image;
7558 break;
7559 }
cristy3ed852e2009-09-05 21:47:34 +00007560 if (LocaleCompare("flatten",option+1) == 0)
7561 {
7562 Image
7563 *flatten_image;
7564
cristy6b3da3a2010-06-20 02:21:46 +00007565 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007566 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7567 if (flatten_image == (Image *) NULL)
7568 break;
7569 *images=DestroyImageList(*images);
7570 *images=flatten_image;
7571 break;
7572 }
7573 if (LocaleCompare("fx",option+1) == 0)
7574 {
7575 Image
7576 *fx_image;
7577
cristy6b3da3a2010-06-20 02:21:46 +00007578 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007579 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007580 if (fx_image == (Image *) NULL)
7581 {
7582 status=MagickFalse;
7583 break;
7584 }
7585 *images=DestroyImageList(*images);
7586 *images=fx_image;
7587 break;
7588 }
7589 break;
7590 }
7591 case 'h':
7592 {
7593 if (LocaleCompare("hald-clut",option+1) == 0)
7594 {
7595 Image
7596 *hald_image,
7597 *image;
7598
cristy6b3da3a2010-06-20 02:21:46 +00007599 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007600 image=RemoveFirstImageFromList(images);
7601 hald_image=RemoveFirstImageFromList(images);
7602 if (hald_image == (Image *) NULL)
7603 {
7604 status=MagickFalse;
7605 break;
7606 }
cristy7c0a0a42011-08-23 17:57:25 +00007607 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007608 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007609 if (*images != (Image *) NULL)
7610 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007611 *images=image;
7612 break;
7613 }
7614 break;
7615 }
7616 case 'i':
7617 {
7618 if (LocaleCompare("ift",option+1) == 0)
7619 {
7620 Image
cristy8587f882009-11-13 20:28:49 +00007621 *fourier_image,
7622 *magnitude_image,
7623 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007624
7625 /*
7626 Implements the inverse fourier discrete Fourier transform (DFT).
7627 */
cristy6b3da3a2010-06-20 02:21:46 +00007628 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007629 magnitude_image=RemoveFirstImageFromList(images);
7630 phase_image=RemoveFirstImageFromList(images);
7631 if (phase_image == (Image *) NULL)
7632 {
7633 status=MagickFalse;
7634 break;
7635 }
7636 fourier_image=InverseFourierTransformImage(magnitude_image,
7637 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007638 if (fourier_image == (Image *) NULL)
7639 break;
cristy0aff6ea2009-11-14 01:40:53 +00007640 if (*images != (Image *) NULL)
7641 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007642 *images=fourier_image;
7643 break;
7644 }
7645 if (LocaleCompare("insert",option+1) == 0)
7646 {
7647 Image
7648 *p,
7649 *q;
7650
7651 index=0;
7652 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007653 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007654 p=RemoveLastImageFromList(images);
7655 if (p == (Image *) NULL)
7656 {
7657 (void) ThrowMagickException(exception,GetMagickModule(),
7658 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7659 status=MagickFalse;
7660 break;
7661 }
7662 q=p;
7663 if (index == 0)
7664 PrependImageToList(images,q);
7665 else
cristybb503372010-05-27 20:51:26 +00007666 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007667 AppendImageToList(images,q);
7668 else
7669 {
7670 q=GetImageFromList(*images,index-1);
7671 if (q == (Image *) NULL)
7672 {
7673 (void) ThrowMagickException(exception,GetMagickModule(),
7674 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7675 status=MagickFalse;
7676 break;
7677 }
7678 InsertImageInList(&q,p);
7679 }
7680 *images=GetFirstImageInList(q);
7681 break;
7682 }
7683 break;
7684 }
7685 case 'l':
7686 {
7687 if (LocaleCompare("layers",option+1) == 0)
7688 {
7689 Image
7690 *layers;
7691
7692 ImageLayerMethod
7693 method;
7694
cristy6b3da3a2010-06-20 02:21:46 +00007695 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007696 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007697 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007698 MagickFalse,argv[i+1]);
7699 switch (method)
7700 {
7701 case CoalesceLayer:
7702 {
7703 layers=CoalesceImages(*images,exception);
7704 break;
7705 }
7706 case CompareAnyLayer:
7707 case CompareClearLayer:
7708 case CompareOverlayLayer:
7709 default:
7710 {
cristy8a9106f2011-07-05 14:39:26 +00007711 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007712 break;
7713 }
7714 case MergeLayer:
7715 case FlattenLayer:
7716 case MosaicLayer:
7717 case TrimBoundsLayer:
7718 {
7719 layers=MergeImageLayers(*images,method,exception);
7720 break;
7721 }
7722 case DisposeLayer:
7723 {
7724 layers=DisposeImages(*images,exception);
7725 break;
7726 }
7727 case OptimizeImageLayer:
7728 {
7729 layers=OptimizeImageLayers(*images,exception);
7730 break;
7731 }
7732 case OptimizePlusLayer:
7733 {
7734 layers=OptimizePlusImageLayers(*images,exception);
7735 break;
7736 }
7737 case OptimizeTransLayer:
7738 {
7739 OptimizeImageTransparency(*images,exception);
7740 break;
7741 }
7742 case RemoveDupsLayer:
7743 {
7744 RemoveDuplicateLayers(images,exception);
7745 break;
7746 }
7747 case RemoveZeroLayer:
7748 {
7749 RemoveZeroDelayLayers(images,exception);
7750 break;
7751 }
7752 case OptimizeLayer:
7753 {
7754 /*
7755 General Purpose, GIF Animation Optimizer.
7756 */
7757 layers=CoalesceImages(*images,exception);
7758 if (layers == (Image *) NULL)
7759 {
7760 status=MagickFalse;
7761 break;
7762 }
cristy3ed852e2009-09-05 21:47:34 +00007763 *images=DestroyImageList(*images);
7764 *images=layers;
7765 layers=OptimizeImageLayers(*images,exception);
7766 if (layers == (Image *) NULL)
7767 {
7768 status=MagickFalse;
7769 break;
7770 }
cristy3ed852e2009-09-05 21:47:34 +00007771 *images=DestroyImageList(*images);
7772 *images=layers;
7773 layers=(Image *) NULL;
7774 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007775 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7776 exception);
cristy3ed852e2009-09-05 21:47:34 +00007777 break;
7778 }
7779 case CompositeLayer:
7780 {
7781 CompositeOperator
7782 compose;
7783
7784 Image
7785 *source;
7786
7787 RectangleInfo
7788 geometry;
7789
7790 /*
7791 Split image sequence at the first 'NULL:' image.
7792 */
7793 source=(*images);
7794 while (source != (Image *) NULL)
7795 {
7796 source=GetNextImageInList(source);
7797 if ((source != (Image *) NULL) &&
7798 (LocaleCompare(source->magick,"NULL") == 0))
7799 break;
7800 }
7801 if (source != (Image *) NULL)
7802 {
7803 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7804 (GetNextImageInList(source) == (Image *) NULL))
7805 source=(Image *) NULL;
7806 else
7807 {
7808 /*
7809 Separate the two lists, junk the null: image.
7810 */
7811 source=SplitImageList(source->previous);
7812 DeleteImageFromList(&source);
7813 }
7814 }
7815 if (source == (Image *) NULL)
7816 {
7817 (void) ThrowMagickException(exception,GetMagickModule(),
7818 OptionError,"MissingNullSeparator","layers Composite");
7819 status=MagickFalse;
7820 break;
7821 }
7822 /*
7823 Adjust offset with gravity and virtual canvas.
7824 */
7825 SetGeometry(*images,&geometry);
7826 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7827 geometry.width=source->page.width != 0 ?
7828 source->page.width : source->columns;
7829 geometry.height=source->page.height != 0 ?
7830 source->page.height : source->rows;
7831 GravityAdjustGeometry((*images)->page.width != 0 ?
7832 (*images)->page.width : (*images)->columns,
7833 (*images)->page.height != 0 ? (*images)->page.height :
7834 (*images)->rows,(*images)->gravity,&geometry);
7835 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007836 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007837 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007838 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007839 MagickComposeOptions,MagickFalse,option);
7840 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7841 exception);
7842 source=DestroyImageList(source);
7843 break;
7844 }
7845 }
7846 if (layers == (Image *) NULL)
7847 break;
7848 InheritException(exception,&layers->exception);
7849 *images=DestroyImageList(*images);
7850 *images=layers;
7851 break;
7852 }
7853 break;
7854 }
7855 case 'm':
7856 {
7857 if (LocaleCompare("map",option+1) == 0)
7858 {
cristy6b3da3a2010-06-20 02:21:46 +00007859 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007860 if (*option == '+')
7861 {
cristy018f07f2011-09-04 21:15:19 +00007862 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7863 exception);
cristy3ed852e2009-09-05 21:47:34 +00007864 break;
7865 }
7866 i++;
7867 break;
7868 }
cristyf40785b2010-03-06 02:27:27 +00007869 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007870 {
7871 Image
cristyf40785b2010-03-06 02:27:27 +00007872 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007873
cristyd18ae7c2010-03-07 17:39:52 +00007874 /*
7875 Maximum image sequence (deprecated).
7876 */
cristy6b3da3a2010-06-20 02:21:46 +00007877 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007878 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007879 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007880 {
7881 status=MagickFalse;
7882 break;
7883 }
7884 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007885 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007886 break;
7887 }
cristyf40785b2010-03-06 02:27:27 +00007888 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007889 {
7890 Image
cristyf40785b2010-03-06 02:27:27 +00007891 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007892
cristyd18ae7c2010-03-07 17:39:52 +00007893 /*
7894 Minimum image sequence (deprecated).
7895 */
cristy6b3da3a2010-06-20 02:21:46 +00007896 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007897 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007898 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007899 {
7900 status=MagickFalse;
7901 break;
7902 }
7903 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007904 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007905 break;
7906 }
cristy3ed852e2009-09-05 21:47:34 +00007907 if (LocaleCompare("morph",option+1) == 0)
7908 {
7909 Image
7910 *morph_image;
7911
cristy6b3da3a2010-06-20 02:21:46 +00007912 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007913 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007914 exception);
7915 if (morph_image == (Image *) NULL)
7916 {
7917 status=MagickFalse;
7918 break;
7919 }
7920 *images=DestroyImageList(*images);
7921 *images=morph_image;
7922 break;
7923 }
7924 if (LocaleCompare("mosaic",option+1) == 0)
7925 {
7926 Image
7927 *mosaic_image;
7928
cristy6b3da3a2010-06-20 02:21:46 +00007929 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007930 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7931 if (mosaic_image == (Image *) NULL)
7932 {
7933 status=MagickFalse;
7934 break;
7935 }
7936 *images=DestroyImageList(*images);
7937 *images=mosaic_image;
7938 break;
7939 }
7940 break;
7941 }
7942 case 'p':
7943 {
7944 if (LocaleCompare("print",option+1) == 0)
7945 {
7946 char
7947 *string;
7948
cristy6b3da3a2010-06-20 02:21:46 +00007949 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007950 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7951 exception);
cristy3ed852e2009-09-05 21:47:34 +00007952 if (string == (char *) NULL)
7953 break;
cristyb51dff52011-05-19 16:55:47 +00007954 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007955 string=DestroyString(string);
7956 }
7957 if (LocaleCompare("process",option+1) == 0)
7958 {
7959 char
7960 **arguments;
7961
7962 int
7963 j,
7964 number_arguments;
7965
cristy6b3da3a2010-06-20 02:21:46 +00007966 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007967 arguments=StringToArgv(argv[i+1],&number_arguments);
7968 if (arguments == (char **) NULL)
7969 break;
7970 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7971 {
7972 char
7973 breaker,
7974 quote,
7975 *token;
7976
7977 const char
7978 *arguments;
7979
7980 int
7981 next,
7982 status;
7983
7984 size_t
7985 length;
7986
7987 TokenInfo
7988 *token_info;
7989
7990 /*
7991 Support old style syntax, filter="-option arg".
7992 */
7993 length=strlen(argv[i+1]);
7994 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00007995 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00007996 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
7997 sizeof(*token));
7998 if (token == (char *) NULL)
7999 break;
8000 next=0;
8001 arguments=argv[i+1];
8002 token_info=AcquireTokenInfo();
8003 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8004 "\"",'\0',&breaker,&next,&quote);
8005 token_info=DestroyTokenInfo(token_info);
8006 if (status == 0)
8007 {
8008 const char
8009 *argv;
8010
8011 argv=(&(arguments[next]));
8012 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8013 exception);
8014 }
8015 token=DestroyString(token);
8016 break;
8017 }
cristy91c0da22010-05-02 01:44:07 +00008018 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008019 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8020 number_arguments-2,(const char **) arguments+2,exception);
8021 for (j=0; j < number_arguments; j++)
8022 arguments[j]=DestroyString(arguments[j]);
8023 arguments=(char **) RelinquishMagickMemory(arguments);
8024 break;
8025 }
8026 break;
8027 }
8028 case 'r':
8029 {
8030 if (LocaleCompare("reverse",option+1) == 0)
8031 {
8032 ReverseImageList(images);
8033 InheritException(exception,&(*images)->exception);
8034 break;
8035 }
8036 break;
8037 }
8038 case 's':
8039 {
cristy4285d782011-02-09 20:12:28 +00008040 if (LocaleCompare("smush",option+1) == 0)
8041 {
8042 Image
8043 *smush_image;
8044
8045 ssize_t
8046 offset;
8047
8048 (void) SyncImagesSettings(mogrify_info,*images);
8049 offset=(ssize_t) StringToLong(argv[i+1]);
8050 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8051 MagickFalse,offset,exception);
8052 if (smush_image == (Image *) NULL)
8053 {
8054 status=MagickFalse;
8055 break;
8056 }
8057 *images=DestroyImageList(*images);
8058 *images=smush_image;
8059 break;
8060 }
cristy3ed852e2009-09-05 21:47:34 +00008061 if (LocaleCompare("swap",option+1) == 0)
8062 {
8063 Image
8064 *p,
8065 *q,
8066 *swap;
8067
cristybb503372010-05-27 20:51:26 +00008068 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008069 swap_index;
8070
8071 index=(-1);
8072 swap_index=(-2);
8073 if (*option != '+')
8074 {
8075 GeometryInfo
8076 geometry_info;
8077
8078 MagickStatusType
8079 flags;
8080
8081 swap_index=(-1);
8082 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008083 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008084 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008085 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008086 }
8087 p=GetImageFromList(*images,index);
8088 q=GetImageFromList(*images,swap_index);
8089 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8090 {
8091 (void) ThrowMagickException(exception,GetMagickModule(),
8092 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8093 status=MagickFalse;
8094 break;
8095 }
8096 if (p == q)
8097 break;
8098 swap=CloneImage(p,0,0,MagickTrue,exception);
8099 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8100 ReplaceImageInList(&q,swap);
8101 *images=GetFirstImageInList(q);
8102 break;
8103 }
8104 break;
8105 }
8106 case 'w':
8107 {
8108 if (LocaleCompare("write",option+1) == 0)
8109 {
cristy071dd7b2010-04-09 13:04:54 +00008110 char
cristy06609ee2010-03-17 20:21:27 +00008111 key[MaxTextExtent];
8112
cristy3ed852e2009-09-05 21:47:34 +00008113 Image
8114 *write_images;
8115
8116 ImageInfo
8117 *write_info;
8118
cristy6b3da3a2010-06-20 02:21:46 +00008119 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008120 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008121 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008122 write_images=(*images);
8123 if (*option == '+')
8124 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008125 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008126 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8127 write_info=DestroyImageInfo(write_info);
8128 if (*option == '+')
8129 write_images=DestroyImageList(write_images);
8130 break;
8131 }
8132 break;
8133 }
8134 default:
8135 break;
8136 }
8137 i+=count;
8138 }
8139 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008140 mogrify_info=DestroyImageInfo(mogrify_info);
8141 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008142 return(status != 0 ? MagickTrue : MagickFalse);
8143}
8144
8145/*
8146%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8147% %
8148% %
8149% %
8150+ M o g r i f y I m a g e s %
8151% %
8152% %
8153% %
8154%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8155%
8156% MogrifyImages() applies image processing options to a sequence of images as
8157% prescribed by command line options.
8158%
8159% The format of the MogrifyImage method is:
8160%
8161% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8162% const MagickBooleanType post,const int argc,const char **argv,
8163% Image **images,Exceptioninfo *exception)
8164%
8165% A description of each parameter follows:
8166%
8167% o image_info: the image info..
8168%
8169% o post: If true, post process image list operators otherwise pre-process.
8170%
8171% o argc: Specifies a pointer to an integer describing the number of
8172% elements in the argument vector.
8173%
8174% o argv: Specifies a pointer to a text array containing the command line
8175% arguments.
8176%
anthonye9c27192011-03-27 08:07:06 +00008177% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008178%
8179% o exception: return any errors or warnings in this structure.
8180%
8181*/
8182WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8183 const MagickBooleanType post,const int argc,const char **argv,
8184 Image **images,ExceptionInfo *exception)
8185{
8186#define MogrifyImageTag "Mogrify/Image"
8187
anthonye9c27192011-03-27 08:07:06 +00008188 MagickStatusType
8189 status;
cristy3ed852e2009-09-05 21:47:34 +00008190
cristy0e9f9c12010-02-11 03:00:47 +00008191 MagickBooleanType
8192 proceed;
8193
anthonye9c27192011-03-27 08:07:06 +00008194 size_t
8195 n;
cristy3ed852e2009-09-05 21:47:34 +00008196
cristybb503372010-05-27 20:51:26 +00008197 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008198 i;
8199
cristy3ed852e2009-09-05 21:47:34 +00008200 assert(image_info != (ImageInfo *) NULL);
8201 assert(image_info->signature == MagickSignature);
8202 if (images == (Image **) NULL)
8203 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008204 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008205 assert((*images)->signature == MagickSignature);
8206 if ((*images)->debug != MagickFalse)
8207 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8208 (*images)->filename);
8209 if ((argc <= 0) || (*argv == (char *) NULL))
8210 return(MagickTrue);
8211 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8212 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008213 status=0;
anthonye9c27192011-03-27 08:07:06 +00008214
anthonyce2716b2011-04-22 09:51:34 +00008215#if 0
cristy1e604812011-05-19 18:07:50 +00008216 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8217 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008218#endif
8219
anthonye9c27192011-03-27 08:07:06 +00008220 /*
8221 Pre-process multi-image sequence operators
8222 */
cristy3ed852e2009-09-05 21:47:34 +00008223 if (post == MagickFalse)
8224 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008225 /*
8226 For each image, process simple single image operators
8227 */
8228 i=0;
8229 n=GetImageListLength(*images);
8230 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008231 {
anthonyce2716b2011-04-22 09:51:34 +00008232#if 0
cristy1e604812011-05-19 18:07:50 +00008233 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8234 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008235#endif
anthonye9c27192011-03-27 08:07:06 +00008236 status&=MogrifyImage(image_info,argc,argv,images,exception);
8237 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008238 if (proceed == MagickFalse)
8239 break;
anthonye9c27192011-03-27 08:07:06 +00008240 if ( (*images)->next == (Image *) NULL )
8241 break;
8242 *images=(*images)->next;
8243 i++;
cristy3ed852e2009-09-05 21:47:34 +00008244 }
anthonye9c27192011-03-27 08:07:06 +00008245 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008246#if 0
cristy1e604812011-05-19 18:07:50 +00008247 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8248 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008249#endif
anthonye9c27192011-03-27 08:07:06 +00008250
8251 /*
8252 Post-process, multi-image sequence operators
8253 */
8254 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008255 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008256 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008257 return(status != 0 ? MagickTrue : MagickFalse);
8258}