blob: 4acb036fcd48559fca30888d15a8bbe94c046fa2 [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;
775 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
776 InheritException(exception,&(*image)->exception);
777 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 {
1031 (void) SetImageClipMask(*image,(Image *) NULL);
1032 InheritException(exception,&(*image)->exception);
1033 break;
1034 }
1035 (void) ClipImage(*image);
1036 InheritException(exception,&(*image)->exception);
1037 break;
1038 }
1039 if (LocaleCompare("clip-mask",option+1) == 0)
1040 {
1041 CacheView
1042 *mask_view;
1043
1044 Image
1045 *mask_image;
1046
cristy4c08aed2011-07-01 19:47:50 +00001047 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001048 *restrict q;
1049
1050 register ssize_t
1051 x;
1052
1053 ssize_t
1054 y;
1055
1056 (void) SyncImageSettings(mogrify_info,*image);
1057 if (*option == '+')
1058 {
1059 /*
1060 Remove a mask.
1061 */
1062 (void) SetImageMask(*image,(Image *) NULL);
1063 InheritException(exception,&(*image)->exception);
1064 break;
1065 }
1066 /*
1067 Set the image mask.
1068 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1069 */
1070 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1071 if (mask_image == (Image *) NULL)
1072 break;
cristy574cc262011-08-05 01:23:58 +00001073 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001074 return(MagickFalse);
1075 mask_view=AcquireCacheView(mask_image);
1076 for (y=0; y < (ssize_t) mask_image->rows; y++)
1077 {
1078 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1079 exception);
cristyacd2ed22011-08-30 01:44:23 +00001080 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001081 break;
1082 for (x=0; x < (ssize_t) mask_image->columns; x++)
1083 {
1084 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001085 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1086 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1087 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1088 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001089 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001090 }
1091 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1092 break;
1093 }
1094 mask_view=DestroyCacheView(mask_view);
1095 mask_image->matte=MagickTrue;
1096 (void) SetImageClipMask(*image,mask_image);
1097 mask_image=DestroyImage(mask_image);
1098 InheritException(exception,&(*image)->exception);
1099 break;
1100 }
1101 if (LocaleCompare("clip-path",option+1) == 0)
1102 {
1103 (void) SyncImageSettings(mogrify_info,*image);
1104 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1105 MagickFalse);
1106 InheritException(exception,&(*image)->exception);
1107 break;
1108 }
1109 if (LocaleCompare("colorize",option+1) == 0)
1110 {
1111 /*
1112 Colorize the image.
1113 */
1114 (void) SyncImageSettings(mogrify_info,*image);
1115 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1116 exception);
1117 break;
1118 }
1119 if (LocaleCompare("color-matrix",option+1) == 0)
1120 {
1121 KernelInfo
1122 *kernel;
1123
1124 (void) SyncImageSettings(mogrify_info,*image);
1125 kernel=AcquireKernelInfo(argv[i+1]);
1126 if (kernel == (KernelInfo *) NULL)
1127 break;
1128 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1129 kernel=DestroyKernelInfo(kernel);
1130 break;
1131 }
1132 if (LocaleCompare("colors",option+1) == 0)
1133 {
1134 /*
1135 Reduce the number of colors in the image.
1136 */
1137 (void) SyncImageSettings(mogrify_info,*image);
1138 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1139 if (quantize_info->number_colors == 0)
1140 break;
1141 if (((*image)->storage_class == DirectClass) ||
1142 (*image)->colors > quantize_info->number_colors)
1143 (void) QuantizeImage(quantize_info,*image);
1144 else
1145 (void) CompressImageColormap(*image);
1146 InheritException(exception,&(*image)->exception);
1147 break;
1148 }
1149 if (LocaleCompare("colorspace",option+1) == 0)
1150 {
1151 ColorspaceType
1152 colorspace;
1153
1154 (void) SyncImageSettings(mogrify_info,*image);
1155 if (*option == '+')
1156 {
1157 (void) TransformImageColorspace(*image,RGBColorspace);
1158 InheritException(exception,&(*image)->exception);
1159 break;
1160 }
1161 colorspace=(ColorspaceType) ParseCommandOption(
1162 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1163 (void) TransformImageColorspace(*image,colorspace);
1164 InheritException(exception,&(*image)->exception);
1165 break;
1166 }
1167 if (LocaleCompare("contrast",option+1) == 0)
1168 {
1169 (void) SyncImageSettings(mogrify_info,*image);
1170 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001171 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001172 break;
1173 }
1174 if (LocaleCompare("contrast-stretch",option+1) == 0)
1175 {
1176 double
1177 black_point,
1178 white_point;
1179
1180 MagickStatusType
1181 flags;
1182
1183 /*
1184 Contrast stretch image.
1185 */
1186 (void) SyncImageSettings(mogrify_info,*image);
1187 flags=ParseGeometry(argv[i+1],&geometry_info);
1188 black_point=geometry_info.rho;
1189 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1190 black_point;
1191 if ((flags & PercentValue) != 0)
1192 {
1193 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1194 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1195 }
1196 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1197 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001198 (void) ContrastStretchImage(*image,black_point,white_point,
1199 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001200 InheritException(exception,&(*image)->exception);
1201 break;
1202 }
1203 if (LocaleCompare("convolve",option+1) == 0)
1204 {
anthonydf8ebac2011-04-27 09:03:19 +00001205 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001206 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001207
anthonydf8ebac2011-04-27 09:03:19 +00001208 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001209 kernel_info=AcquireKernelInfo(argv[i+1]);
1210 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001211 break;
cristy0a922382011-07-16 15:30:34 +00001212 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001213 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001214 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001215 break;
1216 }
1217 if (LocaleCompare("crop",option+1) == 0)
1218 {
1219 /*
1220 Crop a image to a smaller size
1221 */
1222 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001223 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001224 break;
1225 }
1226 if (LocaleCompare("cycle",option+1) == 0)
1227 {
1228 /*
1229 Cycle an image colormap.
1230 */
1231 (void) SyncImageSettings(mogrify_info,*image);
1232 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1233 InheritException(exception,&(*image)->exception);
1234 break;
1235 }
1236 break;
1237 }
1238 case 'd':
1239 {
1240 if (LocaleCompare("decipher",option+1) == 0)
1241 {
1242 StringInfo
1243 *passkey;
1244
1245 /*
1246 Decipher pixels.
1247 */
1248 (void) SyncImageSettings(mogrify_info,*image);
1249 passkey=FileToStringInfo(argv[i+1],~0,exception);
1250 if (passkey != (StringInfo *) NULL)
1251 {
1252 (void) PasskeyDecipherImage(*image,passkey,exception);
1253 passkey=DestroyStringInfo(passkey);
1254 }
1255 break;
1256 }
1257 if (LocaleCompare("density",option+1) == 0)
1258 {
1259 /*
1260 Set image density.
1261 */
1262 (void) CloneString(&draw_info->density,argv[i+1]);
1263 break;
1264 }
1265 if (LocaleCompare("depth",option+1) == 0)
1266 {
1267 (void) SyncImageSettings(mogrify_info,*image);
1268 if (*option == '+')
1269 {
1270 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1271 break;
1272 }
1273 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1274 break;
1275 }
1276 if (LocaleCompare("deskew",option+1) == 0)
1277 {
1278 double
1279 threshold;
1280
1281 /*
1282 Straighten the image.
1283 */
1284 (void) SyncImageSettings(mogrify_info,*image);
1285 if (*option == '+')
1286 threshold=40.0*QuantumRange/100.0;
1287 else
1288 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1289 mogrify_image=DeskewImage(*image,threshold,exception);
1290 break;
1291 }
1292 if (LocaleCompare("despeckle",option+1) == 0)
1293 {
1294 /*
1295 Reduce the speckles within an image.
1296 */
1297 (void) SyncImageSettings(mogrify_info,*image);
1298 mogrify_image=DespeckleImage(*image,exception);
1299 break;
1300 }
1301 if (LocaleCompare("display",option+1) == 0)
1302 {
1303 (void) CloneString(&draw_info->server_name,argv[i+1]);
1304 break;
1305 }
1306 if (LocaleCompare("distort",option+1) == 0)
1307 {
1308 char
1309 *args,
1310 token[MaxTextExtent];
1311
1312 const char
1313 *p;
1314
1315 DistortImageMethod
1316 method;
1317
1318 double
1319 *arguments;
1320
1321 register ssize_t
1322 x;
1323
1324 size_t
1325 number_arguments;
1326
1327 /*
1328 Distort image.
1329 */
1330 (void) SyncImageSettings(mogrify_info,*image);
1331 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1332 MagickFalse,argv[i+1]);
1333 if ( method == ResizeDistortion )
1334 {
1335 /* Special Case - Argument is actually a resize geometry!
1336 ** Convert that to an appropriate distortion argument array.
1337 */
1338 double
1339 resize_args[2];
1340 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1341 exception);
1342 resize_args[0]=(double)geometry.width;
1343 resize_args[1]=(double)geometry.height;
1344 mogrify_image=DistortImage(*image,method,(size_t)2,
1345 resize_args,MagickTrue,exception);
1346 break;
1347 }
1348 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1349 InheritException(exception,&(*image)->exception);
1350 if (args == (char *) NULL)
1351 break;
1352 p=(char *) args;
1353 for (x=0; *p != '\0'; x++)
1354 {
1355 GetMagickToken(p,&p,token);
1356 if (*token == ',')
1357 GetMagickToken(p,&p,token);
1358 }
1359 number_arguments=(size_t) x;
1360 arguments=(double *) AcquireQuantumMemory(number_arguments,
1361 sizeof(*arguments));
1362 if (arguments == (double *) NULL)
1363 ThrowWandFatalException(ResourceLimitFatalError,
1364 "MemoryAllocationFailed",(*image)->filename);
1365 (void) ResetMagickMemory(arguments,0,number_arguments*
1366 sizeof(*arguments));
1367 p=(char *) args;
1368 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1369 {
1370 GetMagickToken(p,&p,token);
1371 if (*token == ',')
1372 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001373 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001374 }
1375 args=DestroyString(args);
1376 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1377 (*option == '+') ? MagickTrue : MagickFalse,exception);
1378 arguments=(double *) RelinquishMagickMemory(arguments);
1379 break;
1380 }
1381 if (LocaleCompare("dither",option+1) == 0)
1382 {
1383 if (*option == '+')
1384 {
1385 quantize_info->dither=MagickFalse;
1386 break;
1387 }
1388 quantize_info->dither=MagickTrue;
1389 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1390 MagickDitherOptions,MagickFalse,argv[i+1]);
1391 if (quantize_info->dither_method == NoDitherMethod)
1392 quantize_info->dither=MagickFalse;
1393 break;
1394 }
1395 if (LocaleCompare("draw",option+1) == 0)
1396 {
1397 /*
1398 Draw image.
1399 */
1400 (void) SyncImageSettings(mogrify_info,*image);
1401 (void) CloneString(&draw_info->primitive,argv[i+1]);
1402 (void) DrawImage(*image,draw_info);
1403 InheritException(exception,&(*image)->exception);
1404 break;
1405 }
1406 break;
1407 }
1408 case 'e':
1409 {
1410 if (LocaleCompare("edge",option+1) == 0)
1411 {
1412 /*
1413 Enhance edges in the image.
1414 */
1415 (void) SyncImageSettings(mogrify_info,*image);
1416 flags=ParseGeometry(argv[i+1],&geometry_info);
1417 if ((flags & SigmaValue) == 0)
1418 geometry_info.sigma=1.0;
1419 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1420 break;
1421 }
1422 if (LocaleCompare("emboss",option+1) == 0)
1423 {
1424 /*
1425 Gaussian embossen image.
1426 */
1427 (void) SyncImageSettings(mogrify_info,*image);
1428 flags=ParseGeometry(argv[i+1],&geometry_info);
1429 if ((flags & SigmaValue) == 0)
1430 geometry_info.sigma=1.0;
1431 mogrify_image=EmbossImage(*image,geometry_info.rho,
1432 geometry_info.sigma,exception);
1433 break;
1434 }
1435 if (LocaleCompare("encipher",option+1) == 0)
1436 {
1437 StringInfo
1438 *passkey;
1439
1440 /*
1441 Encipher pixels.
1442 */
1443 (void) SyncImageSettings(mogrify_info,*image);
1444 passkey=FileToStringInfo(argv[i+1],~0,exception);
1445 if (passkey != (StringInfo *) NULL)
1446 {
1447 (void) PasskeyEncipherImage(*image,passkey,exception);
1448 passkey=DestroyStringInfo(passkey);
1449 }
1450 break;
1451 }
1452 if (LocaleCompare("encoding",option+1) == 0)
1453 {
1454 (void) CloneString(&draw_info->encoding,argv[i+1]);
1455 break;
1456 }
1457 if (LocaleCompare("enhance",option+1) == 0)
1458 {
1459 /*
1460 Enhance image.
1461 */
1462 (void) SyncImageSettings(mogrify_info,*image);
1463 mogrify_image=EnhanceImage(*image,exception);
1464 break;
1465 }
1466 if (LocaleCompare("equalize",option+1) == 0)
1467 {
1468 /*
1469 Equalize image.
1470 */
1471 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001472 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001473 break;
1474 }
1475 if (LocaleCompare("evaluate",option+1) == 0)
1476 {
1477 double
1478 constant;
1479
1480 MagickEvaluateOperator
1481 op;
1482
1483 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001484 op=(MagickEvaluateOperator) ParseCommandOption(
1485 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001486 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001487 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001488 break;
1489 }
1490 if (LocaleCompare("extent",option+1) == 0)
1491 {
1492 /*
1493 Set the image extent.
1494 */
1495 (void) SyncImageSettings(mogrify_info,*image);
1496 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1497 if (geometry.width == 0)
1498 geometry.width=(*image)->columns;
1499 if (geometry.height == 0)
1500 geometry.height=(*image)->rows;
1501 mogrify_image=ExtentImage(*image,&geometry,exception);
1502 break;
1503 }
1504 break;
1505 }
1506 case 'f':
1507 {
1508 if (LocaleCompare("family",option+1) == 0)
1509 {
1510 if (*option == '+')
1511 {
1512 if (draw_info->family != (char *) NULL)
1513 draw_info->family=DestroyString(draw_info->family);
1514 break;
1515 }
1516 (void) CloneString(&draw_info->family,argv[i+1]);
1517 break;
1518 }
1519 if (LocaleCompare("features",option+1) == 0)
1520 {
1521 if (*option == '+')
1522 {
1523 (void) DeleteImageArtifact(*image,"identify:features");
1524 break;
1525 }
1526 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1527 break;
1528 }
1529 if (LocaleCompare("fill",option+1) == 0)
1530 {
1531 ExceptionInfo
1532 *sans;
1533
cristy4c08aed2011-07-01 19:47:50 +00001534 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001535 if (*option == '+')
1536 {
1537 (void) QueryMagickColor("none",&fill,exception);
1538 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1539 if (draw_info->fill_pattern != (Image *) NULL)
1540 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1541 break;
1542 }
1543 sans=AcquireExceptionInfo();
1544 (void) QueryMagickColor(argv[i+1],&fill,sans);
1545 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1546 sans=DestroyExceptionInfo(sans);
1547 if (status == MagickFalse)
1548 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1549 exception);
1550 break;
1551 }
1552 if (LocaleCompare("flip",option+1) == 0)
1553 {
1554 /*
1555 Flip image scanlines.
1556 */
1557 (void) SyncImageSettings(mogrify_info,*image);
1558 mogrify_image=FlipImage(*image,exception);
1559 break;
1560 }
anthonydf8ebac2011-04-27 09:03:19 +00001561 if (LocaleCompare("floodfill",option+1) == 0)
1562 {
cristy4c08aed2011-07-01 19:47:50 +00001563 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001564 target;
1565
1566 /*
1567 Floodfill image.
1568 */
1569 (void) SyncImageSettings(mogrify_info,*image);
1570 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1571 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001572 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001573 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001574 break;
1575 }
anthony3d2f4862011-05-01 13:48:16 +00001576 if (LocaleCompare("flop",option+1) == 0)
1577 {
1578 /*
1579 Flop image scanlines.
1580 */
1581 (void) SyncImageSettings(mogrify_info,*image);
1582 mogrify_image=FlopImage(*image,exception);
1583 break;
1584 }
anthonydf8ebac2011-04-27 09:03:19 +00001585 if (LocaleCompare("font",option+1) == 0)
1586 {
1587 if (*option == '+')
1588 {
1589 if (draw_info->font != (char *) NULL)
1590 draw_info->font=DestroyString(draw_info->font);
1591 break;
1592 }
1593 (void) CloneString(&draw_info->font,argv[i+1]);
1594 break;
1595 }
1596 if (LocaleCompare("format",option+1) == 0)
1597 {
1598 format=argv[i+1];
1599 break;
1600 }
1601 if (LocaleCompare("frame",option+1) == 0)
1602 {
1603 FrameInfo
1604 frame_info;
1605
1606 /*
1607 Surround image with an ornamental border.
1608 */
1609 (void) SyncImageSettings(mogrify_info,*image);
1610 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1611 frame_info.width=geometry.width;
1612 frame_info.height=geometry.height;
1613 if ((flags & HeightValue) == 0)
1614 frame_info.height=geometry.width;
1615 frame_info.outer_bevel=geometry.x;
1616 frame_info.inner_bevel=geometry.y;
1617 frame_info.x=(ssize_t) frame_info.width;
1618 frame_info.y=(ssize_t) frame_info.height;
1619 frame_info.width=(*image)->columns+2*frame_info.width;
1620 frame_info.height=(*image)->rows+2*frame_info.height;
1621 mogrify_image=FrameImage(*image,&frame_info,exception);
1622 break;
1623 }
1624 if (LocaleCompare("function",option+1) == 0)
1625 {
1626 char
1627 *arguments,
1628 token[MaxTextExtent];
1629
1630 const char
1631 *p;
1632
1633 double
1634 *parameters;
1635
1636 MagickFunction
1637 function;
1638
1639 register ssize_t
1640 x;
1641
1642 size_t
1643 number_parameters;
1644
1645 /*
1646 Function Modify Image Values
1647 */
1648 (void) SyncImageSettings(mogrify_info,*image);
1649 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1650 MagickFalse,argv[i+1]);
1651 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1652 InheritException(exception,&(*image)->exception);
1653 if (arguments == (char *) NULL)
1654 break;
1655 p=(char *) arguments;
1656 for (x=0; *p != '\0'; x++)
1657 {
1658 GetMagickToken(p,&p,token);
1659 if (*token == ',')
1660 GetMagickToken(p,&p,token);
1661 }
1662 number_parameters=(size_t) x;
1663 parameters=(double *) AcquireQuantumMemory(number_parameters,
1664 sizeof(*parameters));
1665 if (parameters == (double *) NULL)
1666 ThrowWandFatalException(ResourceLimitFatalError,
1667 "MemoryAllocationFailed",(*image)->filename);
1668 (void) ResetMagickMemory(parameters,0,number_parameters*
1669 sizeof(*parameters));
1670 p=(char *) arguments;
1671 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1672 {
1673 GetMagickToken(p,&p,token);
1674 if (*token == ',')
1675 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001676 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001677 }
1678 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001679 (void) FunctionImage(*image,function,number_parameters,parameters,
1680 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001681 parameters=(double *) RelinquishMagickMemory(parameters);
1682 break;
1683 }
1684 break;
1685 }
1686 case 'g':
1687 {
1688 if (LocaleCompare("gamma",option+1) == 0)
1689 {
1690 /*
1691 Gamma image.
1692 */
1693 (void) SyncImageSettings(mogrify_info,*image);
1694 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001695 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001696 else
cristyb3e7c6c2011-07-24 01:43:55 +00001697 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1698 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001699 break;
1700 }
1701 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1702 (LocaleCompare("gaussian",option+1) == 0))
1703 {
1704 /*
1705 Gaussian blur image.
1706 */
1707 (void) SyncImageSettings(mogrify_info,*image);
1708 flags=ParseGeometry(argv[i+1],&geometry_info);
1709 if ((flags & SigmaValue) == 0)
1710 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001711 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1712 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001713 break;
1714 }
1715 if (LocaleCompare("geometry",option+1) == 0)
1716 {
1717 /*
1718 Record Image offset, Resize last image.
1719 */
1720 (void) SyncImageSettings(mogrify_info,*image);
1721 if (*option == '+')
1722 {
1723 if ((*image)->geometry != (char *) NULL)
1724 (*image)->geometry=DestroyString((*image)->geometry);
1725 break;
1726 }
1727 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1728 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1729 (void) CloneString(&(*image)->geometry,argv[i+1]);
1730 else
1731 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1732 (*image)->filter,(*image)->blur,exception);
1733 break;
1734 }
1735 if (LocaleCompare("gravity",option+1) == 0)
1736 {
1737 if (*option == '+')
1738 {
1739 draw_info->gravity=UndefinedGravity;
1740 break;
1741 }
1742 draw_info->gravity=(GravityType) ParseCommandOption(
1743 MagickGravityOptions,MagickFalse,argv[i+1]);
1744 break;
1745 }
1746 break;
1747 }
1748 case 'h':
1749 {
1750 if (LocaleCompare("highlight-color",option+1) == 0)
1751 {
1752 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1753 break;
1754 }
1755 break;
1756 }
1757 case 'i':
1758 {
1759 if (LocaleCompare("identify",option+1) == 0)
1760 {
1761 char
1762 *text;
1763
1764 (void) SyncImageSettings(mogrify_info,*image);
1765 if (format == (char *) NULL)
1766 {
cristya4037272011-08-28 15:11:39 +00001767 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1768 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001769 break;
1770 }
1771 text=InterpretImageProperties(mogrify_info,*image,format);
1772 InheritException(exception,&(*image)->exception);
1773 if (text == (char *) NULL)
1774 break;
1775 (void) fputs(text,stdout);
1776 (void) fputc('\n',stdout);
1777 text=DestroyString(text);
1778 break;
1779 }
1780 if (LocaleCompare("implode",option+1) == 0)
1781 {
1782 /*
1783 Implode image.
1784 */
1785 (void) SyncImageSettings(mogrify_info,*image);
1786 (void) ParseGeometry(argv[i+1],&geometry_info);
1787 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1788 break;
1789 }
1790 if (LocaleCompare("interline-spacing",option+1) == 0)
1791 {
1792 if (*option == '+')
1793 (void) ParseGeometry("0",&geometry_info);
1794 else
1795 (void) ParseGeometry(argv[i+1],&geometry_info);
1796 draw_info->interline_spacing=geometry_info.rho;
1797 break;
1798 }
1799 if (LocaleCompare("interword-spacing",option+1) == 0)
1800 {
1801 if (*option == '+')
1802 (void) ParseGeometry("0",&geometry_info);
1803 else
1804 (void) ParseGeometry(argv[i+1],&geometry_info);
1805 draw_info->interword_spacing=geometry_info.rho;
1806 break;
1807 }
1808 break;
1809 }
1810 case 'k':
1811 {
1812 if (LocaleCompare("kerning",option+1) == 0)
1813 {
1814 if (*option == '+')
1815 (void) ParseGeometry("0",&geometry_info);
1816 else
1817 (void) ParseGeometry(argv[i+1],&geometry_info);
1818 draw_info->kerning=geometry_info.rho;
1819 break;
1820 }
1821 break;
1822 }
1823 case 'l':
1824 {
1825 if (LocaleCompare("lat",option+1) == 0)
1826 {
1827 /*
1828 Local adaptive threshold image.
1829 */
1830 (void) SyncImageSettings(mogrify_info,*image);
1831 flags=ParseGeometry(argv[i+1],&geometry_info);
1832 if ((flags & PercentValue) != 0)
1833 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1834 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001835 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001836 geometry_info.xi,exception);
1837 break;
1838 }
1839 if (LocaleCompare("level",option+1) == 0)
1840 {
1841 MagickRealType
1842 black_point,
1843 gamma,
1844 white_point;
1845
1846 MagickStatusType
1847 flags;
1848
1849 /*
1850 Parse levels.
1851 */
1852 (void) SyncImageSettings(mogrify_info,*image);
1853 flags=ParseGeometry(argv[i+1],&geometry_info);
1854 black_point=geometry_info.rho;
1855 white_point=(MagickRealType) QuantumRange;
1856 if ((flags & SigmaValue) != 0)
1857 white_point=geometry_info.sigma;
1858 gamma=1.0;
1859 if ((flags & XiValue) != 0)
1860 gamma=geometry_info.xi;
1861 if ((flags & PercentValue) != 0)
1862 {
1863 black_point*=(MagickRealType) (QuantumRange/100.0);
1864 white_point*=(MagickRealType) (QuantumRange/100.0);
1865 }
1866 if ((flags & SigmaValue) == 0)
1867 white_point=(MagickRealType) QuantumRange-black_point;
1868 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001869 (void) LevelizeImage(*image,black_point,white_point,gamma,
1870 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001871 else
cristy01e9afd2011-08-10 17:38:41 +00001872 (void) LevelImage(*image,black_point,white_point,gamma,
1873 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001874 InheritException(exception,&(*image)->exception);
1875 break;
1876 }
1877 if (LocaleCompare("level-colors",option+1) == 0)
1878 {
1879 char
1880 token[MaxTextExtent];
1881
1882 const char
1883 *p;
1884
cristy4c08aed2011-07-01 19:47:50 +00001885 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001886 black_point,
1887 white_point;
1888
1889 p=(const char *) argv[i+1];
1890 GetMagickToken(p,&p,token); /* get black point color */
1891 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1892 (void) QueryMagickColor(token,&black_point,exception);
1893 else
1894 (void) QueryMagickColor("#000000",&black_point,exception);
1895 if (isalpha((int) token[0]) || (token[0] == '#'))
1896 GetMagickToken(p,&p,token);
1897 if (*token == '\0')
1898 white_point=black_point; /* set everything to that color */
1899 else
1900 {
1901 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1902 GetMagickToken(p,&p,token); /* Get white point color. */
1903 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1904 (void) QueryMagickColor(token,&white_point,exception);
1905 else
1906 (void) QueryMagickColor("#ffffff",&white_point,exception);
1907 }
cristy490408a2011-07-07 14:42:05 +00001908 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001909 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001910 break;
1911 }
1912 if (LocaleCompare("linear-stretch",option+1) == 0)
1913 {
1914 double
1915 black_point,
1916 white_point;
1917
1918 MagickStatusType
1919 flags;
1920
1921 (void) SyncImageSettings(mogrify_info,*image);
1922 flags=ParseGeometry(argv[i+1],&geometry_info);
1923 black_point=geometry_info.rho;
1924 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1925 if ((flags & SigmaValue) != 0)
1926 white_point=geometry_info.sigma;
1927 if ((flags & PercentValue) != 0)
1928 {
1929 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1930 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1931 }
1932 if ((flags & SigmaValue) == 0)
1933 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1934 black_point;
cristy33bd5152011-08-24 01:42:24 +00001935 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001936 InheritException(exception,&(*image)->exception);
1937 break;
1938 }
1939 if (LocaleCompare("linewidth",option+1) == 0)
1940 {
cristyc1acd842011-05-19 23:05:47 +00001941 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1942 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001943 break;
1944 }
1945 if (LocaleCompare("liquid-rescale",option+1) == 0)
1946 {
1947 /*
1948 Liquid rescale image.
1949 */
1950 (void) SyncImageSettings(mogrify_info,*image);
1951 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1952 if ((flags & XValue) == 0)
1953 geometry.x=1;
1954 if ((flags & YValue) == 0)
1955 geometry.y=0;
1956 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1957 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1958 break;
1959 }
1960 if (LocaleCompare("lowlight-color",option+1) == 0)
1961 {
1962 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1963 break;
1964 }
1965 break;
1966 }
1967 case 'm':
1968 {
1969 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001970 {
cristy3ed852e2009-09-05 21:47:34 +00001971 Image
anthonydf8ebac2011-04-27 09:03:19 +00001972 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001973
anthonydf8ebac2011-04-27 09:03:19 +00001974 /*
1975 Transform image colors to match this set of colors.
1976 */
1977 (void) SyncImageSettings(mogrify_info,*image);
1978 if (*option == '+')
1979 break;
1980 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1981 if (remap_image == (Image *) NULL)
1982 break;
1983 (void) RemapImage(quantize_info,*image,remap_image);
1984 InheritException(exception,&(*image)->exception);
1985 remap_image=DestroyImage(remap_image);
1986 break;
1987 }
1988 if (LocaleCompare("mask",option+1) == 0)
1989 {
1990 Image
1991 *mask;
1992
1993 (void) SyncImageSettings(mogrify_info,*image);
1994 if (*option == '+')
1995 {
1996 /*
1997 Remove a mask.
1998 */
1999 (void) SetImageMask(*image,(Image *) NULL);
2000 InheritException(exception,&(*image)->exception);
2001 break;
2002 }
2003 /*
2004 Set the image mask.
2005 */
2006 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2007 if (mask == (Image *) NULL)
2008 break;
2009 (void) SetImageMask(*image,mask);
2010 mask=DestroyImage(mask);
2011 InheritException(exception,&(*image)->exception);
2012 break;
2013 }
2014 if (LocaleCompare("matte",option+1) == 0)
2015 {
2016 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002017 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002018 break;
2019 }
2020 if (LocaleCompare("median",option+1) == 0)
2021 {
2022 /*
2023 Median filter image.
2024 */
2025 (void) SyncImageSettings(mogrify_info,*image);
2026 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002027 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2028 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002029 break;
2030 }
2031 if (LocaleCompare("mode",option+1) == 0)
2032 {
2033 /*
2034 Mode image.
2035 */
2036 (void) SyncImageSettings(mogrify_info,*image);
2037 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002038 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2039 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002040 break;
2041 }
2042 if (LocaleCompare("modulate",option+1) == 0)
2043 {
2044 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002045 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002046 break;
2047 }
2048 if (LocaleCompare("monitor",option+1) == 0)
2049 {
2050 if (*option == '+')
2051 {
2052 (void) SetImageProgressMonitor(*image,
2053 (MagickProgressMonitor) NULL,(void *) NULL);
2054 break;
2055 }
2056 (void) SetImageProgressMonitor(*image,MonitorProgress,
2057 (void *) NULL);
2058 break;
2059 }
2060 if (LocaleCompare("monochrome",option+1) == 0)
2061 {
2062 (void) SyncImageSettings(mogrify_info,*image);
2063 (void) SetImageType(*image,BilevelType);
2064 InheritException(exception,&(*image)->exception);
2065 break;
2066 }
2067 if (LocaleCompare("morphology",option+1) == 0)
2068 {
2069 char
2070 token[MaxTextExtent];
2071
2072 const char
2073 *p;
2074
2075 KernelInfo
2076 *kernel;
2077
2078 MorphologyMethod
2079 method;
2080
2081 ssize_t
2082 iterations;
2083
2084 /*
2085 Morphological Image Operation
2086 */
2087 (void) SyncImageSettings(mogrify_info,*image);
2088 p=argv[i+1];
2089 GetMagickToken(p,&p,token);
2090 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2091 MagickFalse,token);
2092 iterations=1L;
2093 GetMagickToken(p,&p,token);
2094 if ((*p == ':') || (*p == ','))
2095 GetMagickToken(p,&p,token);
2096 if ((*p != '\0'))
2097 iterations=(ssize_t) StringToLong(p);
2098 kernel=AcquireKernelInfo(argv[i+2]);
2099 if (kernel == (KernelInfo *) NULL)
2100 {
2101 (void) ThrowMagickException(exception,GetMagickModule(),
2102 OptionError,"UnabletoParseKernel","morphology");
2103 status=MagickFalse;
2104 break;
2105 }
cristyf4ad9df2011-07-08 16:49:03 +00002106 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2107 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002108 kernel=DestroyKernelInfo(kernel);
2109 break;
2110 }
2111 if (LocaleCompare("motion-blur",option+1) == 0)
2112 {
2113 /*
2114 Motion blur image.
2115 */
2116 (void) SyncImageSettings(mogrify_info,*image);
2117 flags=ParseGeometry(argv[i+1],&geometry_info);
2118 if ((flags & SigmaValue) == 0)
2119 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002120 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2121 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002122 break;
2123 }
2124 break;
2125 }
2126 case 'n':
2127 {
2128 if (LocaleCompare("negate",option+1) == 0)
2129 {
2130 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002131 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002132 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002133 break;
2134 }
2135 if (LocaleCompare("noise",option+1) == 0)
2136 {
2137 (void) SyncImageSettings(mogrify_info,*image);
2138 if (*option == '-')
2139 {
2140 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002141 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2142 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002143 }
2144 else
2145 {
2146 NoiseType
2147 noise;
2148
2149 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2150 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002151 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002152 }
2153 break;
2154 }
2155 if (LocaleCompare("normalize",option+1) == 0)
2156 {
2157 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002158 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002159 break;
2160 }
2161 break;
2162 }
2163 case 'o':
2164 {
2165 if (LocaleCompare("opaque",option+1) == 0)
2166 {
cristy4c08aed2011-07-01 19:47:50 +00002167 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002168 target;
2169
2170 (void) SyncImageSettings(mogrify_info,*image);
2171 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002172 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002173 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002174 break;
2175 }
2176 if (LocaleCompare("ordered-dither",option+1) == 0)
2177 {
2178 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002179 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002180 break;
2181 }
2182 break;
2183 }
2184 case 'p':
2185 {
2186 if (LocaleCompare("paint",option+1) == 0)
2187 {
anthonydf8ebac2011-04-27 09:03:19 +00002188 (void) SyncImageSettings(mogrify_info,*image);
2189 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002190 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2191 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002192 break;
2193 }
2194 if (LocaleCompare("pen",option+1) == 0)
2195 {
2196 if (*option == '+')
2197 {
2198 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2199 break;
2200 }
2201 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2202 break;
2203 }
2204 if (LocaleCompare("pointsize",option+1) == 0)
2205 {
2206 if (*option == '+')
2207 (void) ParseGeometry("12",&geometry_info);
2208 else
2209 (void) ParseGeometry(argv[i+1],&geometry_info);
2210 draw_info->pointsize=geometry_info.rho;
2211 break;
2212 }
2213 if (LocaleCompare("polaroid",option+1) == 0)
2214 {
2215 double
2216 angle;
2217
2218 RandomInfo
2219 *random_info;
2220
2221 /*
2222 Simulate a Polaroid picture.
2223 */
2224 (void) SyncImageSettings(mogrify_info,*image);
2225 random_info=AcquireRandomInfo();
2226 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2227 random_info=DestroyRandomInfo(random_info);
2228 if (*option == '-')
2229 {
2230 SetGeometryInfo(&geometry_info);
2231 flags=ParseGeometry(argv[i+1],&geometry_info);
2232 angle=geometry_info.rho;
2233 }
2234 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2235 break;
2236 }
2237 if (LocaleCompare("posterize",option+1) == 0)
2238 {
2239 /*
2240 Posterize image.
2241 */
2242 (void) SyncImageSettings(mogrify_info,*image);
2243 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2244 quantize_info->dither);
2245 InheritException(exception,&(*image)->exception);
2246 break;
2247 }
2248 if (LocaleCompare("preview",option+1) == 0)
2249 {
2250 PreviewType
2251 preview_type;
2252
2253 /*
2254 Preview image.
2255 */
2256 (void) SyncImageSettings(mogrify_info,*image);
2257 if (*option == '+')
2258 preview_type=UndefinedPreview;
2259 else
2260 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2261 MagickFalse,argv[i+1]);
2262 mogrify_image=PreviewImage(*image,preview_type,exception);
2263 break;
2264 }
2265 if (LocaleCompare("profile",option+1) == 0)
2266 {
2267 const char
2268 *name;
2269
2270 const StringInfo
2271 *profile;
2272
2273 Image
2274 *profile_image;
2275
2276 ImageInfo
2277 *profile_info;
2278
2279 (void) SyncImageSettings(mogrify_info,*image);
2280 if (*option == '+')
2281 {
2282 /*
2283 Remove a profile from the image.
2284 */
2285 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2286 NULL,0,MagickTrue);
2287 InheritException(exception,&(*image)->exception);
2288 break;
2289 }
2290 /*
2291 Associate a profile with the image.
2292 */
2293 profile_info=CloneImageInfo(mogrify_info);
2294 profile=GetImageProfile(*image,"iptc");
2295 if (profile != (StringInfo *) NULL)
2296 profile_info->profile=(void *) CloneStringInfo(profile);
2297 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2298 profile_info=DestroyImageInfo(profile_info);
2299 if (profile_image == (Image *) NULL)
2300 {
2301 StringInfo
2302 *profile;
2303
2304 profile_info=CloneImageInfo(mogrify_info);
2305 (void) CopyMagickString(profile_info->filename,argv[i+1],
2306 MaxTextExtent);
2307 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2308 if (profile != (StringInfo *) NULL)
2309 {
2310 (void) ProfileImage(*image,profile_info->magick,
2311 GetStringInfoDatum(profile),(size_t)
2312 GetStringInfoLength(profile),MagickFalse);
2313 profile=DestroyStringInfo(profile);
2314 }
2315 profile_info=DestroyImageInfo(profile_info);
2316 break;
2317 }
2318 ResetImageProfileIterator(profile_image);
2319 name=GetNextImageProfile(profile_image);
2320 while (name != (const char *) NULL)
2321 {
2322 profile=GetImageProfile(profile_image,name);
2323 if (profile != (StringInfo *) NULL)
2324 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2325 (size_t) GetStringInfoLength(profile),MagickFalse);
2326 name=GetNextImageProfile(profile_image);
2327 }
2328 profile_image=DestroyImage(profile_image);
2329 break;
2330 }
2331 break;
2332 }
2333 case 'q':
2334 {
2335 if (LocaleCompare("quantize",option+1) == 0)
2336 {
2337 if (*option == '+')
2338 {
2339 quantize_info->colorspace=UndefinedColorspace;
2340 break;
2341 }
2342 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2343 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2344 break;
2345 }
2346 break;
2347 }
2348 case 'r':
2349 {
2350 if (LocaleCompare("radial-blur",option+1) == 0)
2351 {
2352 /*
2353 Radial blur image.
2354 */
2355 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002356 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2357 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002358 break;
2359 }
2360 if (LocaleCompare("raise",option+1) == 0)
2361 {
2362 /*
2363 Surround image with a raise of solid color.
2364 */
2365 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2366 if ((flags & SigmaValue) == 0)
2367 geometry.height=geometry.width;
2368 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002369 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002370 break;
2371 }
2372 if (LocaleCompare("random-threshold",option+1) == 0)
2373 {
2374 /*
2375 Threshold image.
2376 */
2377 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002378 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002379 break;
2380 }
2381 if (LocaleCompare("recolor",option+1) == 0)
2382 {
2383 KernelInfo
2384 *kernel;
2385
2386 (void) SyncImageSettings(mogrify_info,*image);
2387 kernel=AcquireKernelInfo(argv[i+1]);
2388 if (kernel == (KernelInfo *) NULL)
2389 break;
2390 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2391 kernel=DestroyKernelInfo(kernel);
2392 break;
2393 }
2394 if (LocaleCompare("region",option+1) == 0)
2395 {
2396 (void) SyncImageSettings(mogrify_info,*image);
2397 if (region_image != (Image *) NULL)
2398 {
2399 /*
2400 Composite region.
2401 */
2402 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002403 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2404 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002405 InheritException(exception,&region_image->exception);
2406 *image=DestroyImage(*image);
2407 *image=region_image;
2408 region_image = (Image *) NULL;
2409 }
2410 if (*option == '+')
2411 break;
2412 /*
2413 Apply transformations to a selected region of the image.
2414 */
cristy3ed852e2009-09-05 21:47:34 +00002415 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2416 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002417 mogrify_image=CropImage(*image,&region_geometry,exception);
2418 if (mogrify_image == (Image *) NULL)
2419 break;
2420 region_image=(*image);
2421 *image=mogrify_image;
2422 mogrify_image=(Image *) NULL;
2423 break;
cristy3ed852e2009-09-05 21:47:34 +00002424 }
anthonydf8ebac2011-04-27 09:03:19 +00002425 if (LocaleCompare("render",option+1) == 0)
2426 {
2427 (void) SyncImageSettings(mogrify_info,*image);
2428 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2429 break;
2430 }
2431 if (LocaleCompare("remap",option+1) == 0)
2432 {
2433 Image
2434 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002435
anthonydf8ebac2011-04-27 09:03:19 +00002436 /*
2437 Transform image colors to match this set of colors.
2438 */
2439 (void) SyncImageSettings(mogrify_info,*image);
2440 if (*option == '+')
2441 break;
2442 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2443 if (remap_image == (Image *) NULL)
2444 break;
2445 (void) RemapImage(quantize_info,*image,remap_image);
2446 InheritException(exception,&(*image)->exception);
2447 remap_image=DestroyImage(remap_image);
2448 break;
2449 }
2450 if (LocaleCompare("repage",option+1) == 0)
2451 {
2452 if (*option == '+')
2453 {
2454 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2455 break;
2456 }
2457 (void) ResetImagePage(*image,argv[i+1]);
2458 InheritException(exception,&(*image)->exception);
2459 break;
2460 }
2461 if (LocaleCompare("resample",option+1) == 0)
2462 {
2463 /*
2464 Resample image.
2465 */
2466 (void) SyncImageSettings(mogrify_info,*image);
2467 flags=ParseGeometry(argv[i+1],&geometry_info);
2468 if ((flags & SigmaValue) == 0)
2469 geometry_info.sigma=geometry_info.rho;
2470 mogrify_image=ResampleImage(*image,geometry_info.rho,
2471 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2472 break;
2473 }
2474 if (LocaleCompare("resize",option+1) == 0)
2475 {
2476 /*
2477 Resize image.
2478 */
2479 (void) SyncImageSettings(mogrify_info,*image);
2480 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2481 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2482 (*image)->filter,(*image)->blur,exception);
2483 break;
2484 }
2485 if (LocaleCompare("roll",option+1) == 0)
2486 {
2487 /*
2488 Roll image.
2489 */
2490 (void) SyncImageSettings(mogrify_info,*image);
2491 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2492 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2493 break;
2494 }
2495 if (LocaleCompare("rotate",option+1) == 0)
2496 {
2497 char
2498 *geometry;
2499
2500 /*
2501 Check for conditional image rotation.
2502 */
2503 (void) SyncImageSettings(mogrify_info,*image);
2504 if (strchr(argv[i+1],'>') != (char *) NULL)
2505 if ((*image)->columns <= (*image)->rows)
2506 break;
2507 if (strchr(argv[i+1],'<') != (char *) NULL)
2508 if ((*image)->columns >= (*image)->rows)
2509 break;
2510 /*
2511 Rotate image.
2512 */
2513 geometry=ConstantString(argv[i+1]);
2514 (void) SubstituteString(&geometry,">","");
2515 (void) SubstituteString(&geometry,"<","");
2516 (void) ParseGeometry(geometry,&geometry_info);
2517 geometry=DestroyString(geometry);
2518 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2519 break;
2520 }
2521 break;
2522 }
2523 case 's':
2524 {
2525 if (LocaleCompare("sample",option+1) == 0)
2526 {
2527 /*
2528 Sample image with pixel replication.
2529 */
2530 (void) SyncImageSettings(mogrify_info,*image);
2531 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2532 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2533 exception);
2534 break;
2535 }
2536 if (LocaleCompare("scale",option+1) == 0)
2537 {
2538 /*
2539 Resize image.
2540 */
2541 (void) SyncImageSettings(mogrify_info,*image);
2542 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2543 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2544 exception);
2545 break;
2546 }
2547 if (LocaleCompare("selective-blur",option+1) == 0)
2548 {
2549 /*
2550 Selectively blur pixels within a contrast threshold.
2551 */
2552 (void) SyncImageSettings(mogrify_info,*image);
2553 flags=ParseGeometry(argv[i+1],&geometry_info);
2554 if ((flags & PercentValue) != 0)
2555 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002556 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2557 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002558 break;
2559 }
2560 if (LocaleCompare("separate",option+1) == 0)
2561 {
2562 /*
2563 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002564 */
2565 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002566 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002567 break;
2568 }
2569 if (LocaleCompare("sepia-tone",option+1) == 0)
2570 {
2571 double
2572 threshold;
2573
2574 /*
2575 Sepia-tone image.
2576 */
2577 (void) SyncImageSettings(mogrify_info,*image);
2578 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2579 mogrify_image=SepiaToneImage(*image,threshold,exception);
2580 break;
2581 }
2582 if (LocaleCompare("segment",option+1) == 0)
2583 {
2584 /*
2585 Segment image.
2586 */
2587 (void) SyncImageSettings(mogrify_info,*image);
2588 flags=ParseGeometry(argv[i+1],&geometry_info);
2589 if ((flags & SigmaValue) == 0)
2590 geometry_info.sigma=1.0;
2591 (void) SegmentImage(*image,(*image)->colorspace,
2592 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2593 InheritException(exception,&(*image)->exception);
2594 break;
2595 }
2596 if (LocaleCompare("set",option+1) == 0)
2597 {
2598 char
2599 *value;
2600
2601 /*
2602 Set image option.
2603 */
2604 if (*option == '+')
2605 {
2606 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2607 (void) DeleteImageRegistry(argv[i+1]+9);
2608 else
2609 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2610 {
2611 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2612 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2613 }
2614 else
2615 (void) DeleteImageProperty(*image,argv[i+1]);
2616 break;
2617 }
2618 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2619 if (value == (char *) NULL)
2620 break;
2621 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2622 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2623 exception);
2624 else
2625 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2626 {
2627 (void) SetImageOption(image_info,argv[i+1]+7,value);
2628 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2629 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2630 }
2631 else
2632 (void) SetImageProperty(*image,argv[i+1],value);
2633 value=DestroyString(value);
2634 break;
2635 }
2636 if (LocaleCompare("shade",option+1) == 0)
2637 {
2638 /*
2639 Shade image.
2640 */
2641 (void) SyncImageSettings(mogrify_info,*image);
2642 flags=ParseGeometry(argv[i+1],&geometry_info);
2643 if ((flags & SigmaValue) == 0)
2644 geometry_info.sigma=1.0;
2645 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2646 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2647 break;
2648 }
2649 if (LocaleCompare("shadow",option+1) == 0)
2650 {
2651 /*
2652 Shadow image.
2653 */
2654 (void) SyncImageSettings(mogrify_info,*image);
2655 flags=ParseGeometry(argv[i+1],&geometry_info);
2656 if ((flags & SigmaValue) == 0)
2657 geometry_info.sigma=1.0;
2658 if ((flags & XiValue) == 0)
2659 geometry_info.xi=4.0;
2660 if ((flags & PsiValue) == 0)
2661 geometry_info.psi=4.0;
2662 mogrify_image=ShadowImage(*image,geometry_info.rho,
2663 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2664 ceil(geometry_info.psi-0.5),exception);
2665 break;
2666 }
2667 if (LocaleCompare("sharpen",option+1) == 0)
2668 {
2669 /*
2670 Sharpen image.
2671 */
2672 (void) SyncImageSettings(mogrify_info,*image);
2673 flags=ParseGeometry(argv[i+1],&geometry_info);
2674 if ((flags & SigmaValue) == 0)
2675 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002676 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002677 geometry_info.sigma,exception);
2678 break;
2679 }
2680 if (LocaleCompare("shave",option+1) == 0)
2681 {
2682 /*
2683 Shave the image edges.
2684 */
2685 (void) SyncImageSettings(mogrify_info,*image);
2686 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2687 mogrify_image=ShaveImage(*image,&geometry,exception);
2688 break;
2689 }
2690 if (LocaleCompare("shear",option+1) == 0)
2691 {
2692 /*
2693 Shear image.
2694 */
2695 (void) SyncImageSettings(mogrify_info,*image);
2696 flags=ParseGeometry(argv[i+1],&geometry_info);
2697 if ((flags & SigmaValue) == 0)
2698 geometry_info.sigma=geometry_info.rho;
2699 mogrify_image=ShearImage(*image,geometry_info.rho,
2700 geometry_info.sigma,exception);
2701 break;
2702 }
2703 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2704 {
2705 /*
2706 Sigmoidal non-linearity contrast control.
2707 */
2708 (void) SyncImageSettings(mogrify_info,*image);
2709 flags=ParseGeometry(argv[i+1],&geometry_info);
2710 if ((flags & SigmaValue) == 0)
2711 geometry_info.sigma=(double) QuantumRange/2.0;
2712 if ((flags & PercentValue) != 0)
2713 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2714 100.0;
cristy9ee60942011-07-06 14:54:38 +00002715 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002716 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2717 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002718 break;
2719 }
2720 if (LocaleCompare("sketch",option+1) == 0)
2721 {
2722 /*
2723 Sketch image.
2724 */
2725 (void) SyncImageSettings(mogrify_info,*image);
2726 flags=ParseGeometry(argv[i+1],&geometry_info);
2727 if ((flags & SigmaValue) == 0)
2728 geometry_info.sigma=1.0;
2729 mogrify_image=SketchImage(*image,geometry_info.rho,
2730 geometry_info.sigma,geometry_info.xi,exception);
2731 break;
2732 }
2733 if (LocaleCompare("solarize",option+1) == 0)
2734 {
2735 double
2736 threshold;
2737
2738 (void) SyncImageSettings(mogrify_info,*image);
2739 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002740 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002741 break;
2742 }
2743 if (LocaleCompare("sparse-color",option+1) == 0)
2744 {
2745 SparseColorMethod
2746 method;
2747
2748 char
2749 *arguments;
2750
2751 /*
2752 Sparse Color Interpolated Gradient
2753 */
2754 (void) SyncImageSettings(mogrify_info,*image);
2755 method=(SparseColorMethod) ParseCommandOption(
2756 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2757 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2758 InheritException(exception,&(*image)->exception);
2759 if (arguments == (char *) NULL)
2760 break;
cristy3884f692011-07-08 18:00:18 +00002761 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002762 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2763 arguments=DestroyString(arguments);
2764 break;
2765 }
2766 if (LocaleCompare("splice",option+1) == 0)
2767 {
2768 /*
2769 Splice a solid color into the image.
2770 */
2771 (void) SyncImageSettings(mogrify_info,*image);
2772 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2773 mogrify_image=SpliceImage(*image,&geometry,exception);
2774 break;
2775 }
2776 if (LocaleCompare("spread",option+1) == 0)
2777 {
2778 /*
2779 Spread an image.
2780 */
2781 (void) SyncImageSettings(mogrify_info,*image);
2782 (void) ParseGeometry(argv[i+1],&geometry_info);
2783 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2784 break;
2785 }
2786 if (LocaleCompare("statistic",option+1) == 0)
2787 {
2788 StatisticType
2789 type;
2790
2791 (void) SyncImageSettings(mogrify_info,*image);
2792 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2793 MagickFalse,argv[i+1]);
2794 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002795 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2796 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002797 break;
2798 }
2799 if (LocaleCompare("stretch",option+1) == 0)
2800 {
2801 if (*option == '+')
2802 {
2803 draw_info->stretch=UndefinedStretch;
2804 break;
2805 }
2806 draw_info->stretch=(StretchType) ParseCommandOption(
2807 MagickStretchOptions,MagickFalse,argv[i+1]);
2808 break;
2809 }
2810 if (LocaleCompare("strip",option+1) == 0)
2811 {
2812 /*
2813 Strip image of profiles and comments.
2814 */
2815 (void) SyncImageSettings(mogrify_info,*image);
2816 (void) StripImage(*image);
2817 InheritException(exception,&(*image)->exception);
2818 break;
2819 }
2820 if (LocaleCompare("stroke",option+1) == 0)
2821 {
2822 ExceptionInfo
2823 *sans;
2824
2825 if (*option == '+')
2826 {
2827 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2828 if (draw_info->stroke_pattern != (Image *) NULL)
2829 draw_info->stroke_pattern=DestroyImage(
2830 draw_info->stroke_pattern);
2831 break;
2832 }
2833 sans=AcquireExceptionInfo();
2834 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2835 sans=DestroyExceptionInfo(sans);
2836 if (status == MagickFalse)
2837 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2838 exception);
2839 break;
2840 }
2841 if (LocaleCompare("strokewidth",option+1) == 0)
2842 {
cristyc1acd842011-05-19 23:05:47 +00002843 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2844 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002845 break;
2846 }
2847 if (LocaleCompare("style",option+1) == 0)
2848 {
2849 if (*option == '+')
2850 {
2851 draw_info->style=UndefinedStyle;
2852 break;
2853 }
2854 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2855 MagickFalse,argv[i+1]);
2856 break;
2857 }
2858 if (LocaleCompare("swirl",option+1) == 0)
2859 {
2860 /*
2861 Swirl image.
2862 */
2863 (void) SyncImageSettings(mogrify_info,*image);
2864 (void) ParseGeometry(argv[i+1],&geometry_info);
2865 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2866 break;
2867 }
2868 break;
2869 }
2870 case 't':
2871 {
2872 if (LocaleCompare("threshold",option+1) == 0)
2873 {
2874 double
2875 threshold;
2876
2877 /*
2878 Threshold image.
2879 */
2880 (void) SyncImageSettings(mogrify_info,*image);
2881 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002882 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002883 else
2884 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002885 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002886 InheritException(exception,&(*image)->exception);
2887 break;
2888 }
2889 if (LocaleCompare("thumbnail",option+1) == 0)
2890 {
2891 /*
2892 Thumbnail image.
2893 */
2894 (void) SyncImageSettings(mogrify_info,*image);
2895 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2896 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2897 exception);
2898 break;
2899 }
2900 if (LocaleCompare("tile",option+1) == 0)
2901 {
2902 if (*option == '+')
2903 {
2904 if (draw_info->fill_pattern != (Image *) NULL)
2905 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2906 break;
2907 }
2908 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2909 exception);
2910 break;
2911 }
2912 if (LocaleCompare("tint",option+1) == 0)
2913 {
2914 /*
2915 Tint the image.
2916 */
2917 (void) SyncImageSettings(mogrify_info,*image);
2918 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2919 break;
2920 }
2921 if (LocaleCompare("transform",option+1) == 0)
2922 {
2923 /*
2924 Affine transform image.
2925 */
2926 (void) SyncImageSettings(mogrify_info,*image);
2927 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2928 exception);
2929 break;
2930 }
2931 if (LocaleCompare("transparent",option+1) == 0)
2932 {
cristy4c08aed2011-07-01 19:47:50 +00002933 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002934 target;
2935
2936 (void) SyncImageSettings(mogrify_info,*image);
2937 (void) QueryMagickColor(argv[i+1],&target,exception);
2938 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002939 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2940 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002941 break;
2942 }
2943 if (LocaleCompare("transpose",option+1) == 0)
2944 {
2945 /*
2946 Transpose image scanlines.
2947 */
2948 (void) SyncImageSettings(mogrify_info,*image);
2949 mogrify_image=TransposeImage(*image,exception);
2950 break;
2951 }
2952 if (LocaleCompare("transverse",option+1) == 0)
2953 {
2954 /*
2955 Transverse image scanlines.
2956 */
2957 (void) SyncImageSettings(mogrify_info,*image);
2958 mogrify_image=TransverseImage(*image,exception);
2959 break;
2960 }
2961 if (LocaleCompare("treedepth",option+1) == 0)
2962 {
2963 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2964 break;
2965 }
2966 if (LocaleCompare("trim",option+1) == 0)
2967 {
2968 /*
2969 Trim image.
2970 */
2971 (void) SyncImageSettings(mogrify_info,*image);
2972 mogrify_image=TrimImage(*image,exception);
2973 break;
2974 }
2975 if (LocaleCompare("type",option+1) == 0)
2976 {
2977 ImageType
2978 type;
2979
2980 (void) SyncImageSettings(mogrify_info,*image);
2981 if (*option == '+')
2982 type=UndefinedType;
2983 else
2984 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2985 argv[i+1]);
2986 (*image)->type=UndefinedType;
2987 (void) SetImageType(*image,type);
2988 InheritException(exception,&(*image)->exception);
2989 break;
2990 }
2991 break;
2992 }
2993 case 'u':
2994 {
2995 if (LocaleCompare("undercolor",option+1) == 0)
2996 {
2997 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
2998 exception);
2999 break;
3000 }
3001 if (LocaleCompare("unique",option+1) == 0)
3002 {
3003 if (*option == '+')
3004 {
3005 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3006 break;
3007 }
3008 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3009 (void) SetImageArtifact(*image,"verbose","true");
3010 break;
3011 }
3012 if (LocaleCompare("unique-colors",option+1) == 0)
3013 {
3014 /*
3015 Unique image colors.
3016 */
3017 (void) SyncImageSettings(mogrify_info,*image);
3018 mogrify_image=UniqueImageColors(*image,exception);
3019 break;
3020 }
3021 if (LocaleCompare("unsharp",option+1) == 0)
3022 {
3023 /*
3024 Unsharp mask image.
3025 */
3026 (void) SyncImageSettings(mogrify_info,*image);
3027 flags=ParseGeometry(argv[i+1],&geometry_info);
3028 if ((flags & SigmaValue) == 0)
3029 geometry_info.sigma=1.0;
3030 if ((flags & XiValue) == 0)
3031 geometry_info.xi=1.0;
3032 if ((flags & PsiValue) == 0)
3033 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003034 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3035 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003036 break;
3037 }
3038 break;
3039 }
3040 case 'v':
3041 {
3042 if (LocaleCompare("verbose",option+1) == 0)
3043 {
3044 (void) SetImageArtifact(*image,option+1,
3045 *option == '+' ? "false" : "true");
3046 break;
3047 }
3048 if (LocaleCompare("vignette",option+1) == 0)
3049 {
3050 /*
3051 Vignette image.
3052 */
3053 (void) SyncImageSettings(mogrify_info,*image);
3054 flags=ParseGeometry(argv[i+1],&geometry_info);
3055 if ((flags & SigmaValue) == 0)
3056 geometry_info.sigma=1.0;
3057 if ((flags & XiValue) == 0)
3058 geometry_info.xi=0.1*(*image)->columns;
3059 if ((flags & PsiValue) == 0)
3060 geometry_info.psi=0.1*(*image)->rows;
3061 mogrify_image=VignetteImage(*image,geometry_info.rho,
3062 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3063 ceil(geometry_info.psi-0.5),exception);
3064 break;
3065 }
3066 if (LocaleCompare("virtual-pixel",option+1) == 0)
3067 {
3068 if (*option == '+')
3069 {
3070 (void) SetImageVirtualPixelMethod(*image,
3071 UndefinedVirtualPixelMethod);
3072 break;
3073 }
3074 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3075 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3076 argv[i+1]));
3077 break;
3078 }
3079 break;
3080 }
3081 case 'w':
3082 {
3083 if (LocaleCompare("wave",option+1) == 0)
3084 {
3085 /*
3086 Wave image.
3087 */
3088 (void) SyncImageSettings(mogrify_info,*image);
3089 flags=ParseGeometry(argv[i+1],&geometry_info);
3090 if ((flags & SigmaValue) == 0)
3091 geometry_info.sigma=1.0;
3092 mogrify_image=WaveImage(*image,geometry_info.rho,
3093 geometry_info.sigma,exception);
3094 break;
3095 }
3096 if (LocaleCompare("weight",option+1) == 0)
3097 {
3098 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3099 if (LocaleCompare(argv[i+1],"all") == 0)
3100 draw_info->weight=0;
3101 if (LocaleCompare(argv[i+1],"bold") == 0)
3102 draw_info->weight=700;
3103 if (LocaleCompare(argv[i+1],"bolder") == 0)
3104 if (draw_info->weight <= 800)
3105 draw_info->weight+=100;
3106 if (LocaleCompare(argv[i+1],"lighter") == 0)
3107 if (draw_info->weight >= 100)
3108 draw_info->weight-=100;
3109 if (LocaleCompare(argv[i+1],"normal") == 0)
3110 draw_info->weight=400;
3111 break;
3112 }
3113 if (LocaleCompare("white-threshold",option+1) == 0)
3114 {
3115 /*
3116 White threshold image.
3117 */
3118 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003119 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003120 InheritException(exception,&(*image)->exception);
3121 break;
3122 }
3123 break;
3124 }
3125 default:
3126 break;
3127 }
3128 /*
3129 Replace current image with any image that was generated
3130 */
3131 if (mogrify_image != (Image *) NULL)
3132 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003133 i+=count;
3134 }
3135 if (region_image != (Image *) NULL)
3136 {
anthonydf8ebac2011-04-27 09:03:19 +00003137 /*
3138 Composite transformed region onto image.
3139 */
cristy6b3da3a2010-06-20 02:21:46 +00003140 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003141 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003142 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3143 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003144 InheritException(exception,&region_image->exception);
3145 *image=DestroyImage(*image);
3146 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003147 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003148 }
3149 /*
3150 Free resources.
3151 */
anthonydf8ebac2011-04-27 09:03:19 +00003152 quantize_info=DestroyQuantizeInfo(quantize_info);
3153 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003154 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003155 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003156 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003157 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003158}
3159
3160/*
3161%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3162% %
3163% %
3164% %
cristy5063d812010-10-19 16:28:10 +00003165+ 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 +00003166% %
3167% %
3168% %
3169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3170%
3171% MogrifyImageCommand() transforms an image or a sequence of images. These
3172% transforms include image scaling, image rotation, color reduction, and
3173% others. The transmogrified image overwrites the original image.
3174%
3175% The format of the MogrifyImageCommand method is:
3176%
3177% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3178% const char **argv,char **metadata,ExceptionInfo *exception)
3179%
3180% A description of each parameter follows:
3181%
3182% o image_info: the image info.
3183%
3184% o argc: the number of elements in the argument vector.
3185%
3186% o argv: A text array containing the command line arguments.
3187%
3188% o metadata: any metadata is returned here.
3189%
3190% o exception: return any errors or warnings in this structure.
3191%
3192*/
3193
3194static MagickBooleanType MogrifyUsage(void)
3195{
3196 static const char
3197 *miscellaneous[]=
3198 {
3199 "-debug events display copious debugging information",
3200 "-help print program options",
3201 "-list type print a list of supported option arguments",
3202 "-log format format of debugging information",
3203 "-version print version information",
3204 (char *) NULL
3205 },
3206 *operators[]=
3207 {
3208 "-adaptive-blur geometry",
3209 " adaptively blur pixels; decrease effect near edges",
3210 "-adaptive-resize geometry",
3211 " adaptively resize image using 'mesh' interpolation",
3212 "-adaptive-sharpen geometry",
3213 " adaptively sharpen pixels; increase effect near edges",
3214 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3215 " transparent, extract, background, or shape",
3216 "-annotate geometry text",
3217 " annotate the image with text",
3218 "-auto-gamma automagically adjust gamma level of image",
3219 "-auto-level automagically adjust color levels of image",
3220 "-auto-orient automagically orient (rotate) image",
3221 "-bench iterations measure performance",
3222 "-black-threshold value",
3223 " force all pixels below the threshold into black",
3224 "-blue-shift simulate a scene at nighttime in the moonlight",
3225 "-blur geometry reduce image noise and reduce detail levels",
3226 "-border geometry surround image with a border of color",
3227 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003228 "-brightness-contrast geometry",
3229 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003230 "-cdl filename color correct with a color decision list",
3231 "-charcoal radius simulate a charcoal drawing",
3232 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003233 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003234 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003235 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003236 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003237 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003238 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003239 "-contrast enhance or reduce the image contrast",
3240 "-contrast-stretch geometry",
3241 " improve contrast by `stretching' the intensity range",
3242 "-convolve coefficients",
3243 " apply a convolution kernel to the image",
3244 "-cycle amount cycle the image colormap",
3245 "-decipher filename convert cipher pixels to plain pixels",
3246 "-deskew threshold straighten an image",
3247 "-despeckle reduce the speckles within an image",
3248 "-distort method args",
3249 " distort images according to given method ad args",
3250 "-draw string annotate the image with a graphic primitive",
3251 "-edge radius apply a filter to detect edges in the image",
3252 "-encipher filename convert plain pixels to cipher pixels",
3253 "-emboss radius emboss an image",
3254 "-enhance apply a digital filter to enhance a noisy image",
3255 "-equalize perform histogram equalization to an image",
3256 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003257 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003258 "-extent geometry set the image size",
3259 "-extract geometry extract area from image",
3260 "-fft implements the discrete Fourier transform (DFT)",
3261 "-flip flip image vertically",
3262 "-floodfill geometry color",
3263 " floodfill the image with color",
3264 "-flop flop image horizontally",
3265 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003266 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003267 " apply function over image values",
3268 "-gamma value level of gamma correction",
3269 "-gaussian-blur geometry",
3270 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003271 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003272 "-identify identify the format and characteristics of the image",
3273 "-ift implements the inverse discrete Fourier transform (DFT)",
3274 "-implode amount implode image pixels about the center",
3275 "-lat geometry local adaptive thresholding",
3276 "-layers method optimize, merge, or compare image layers",
3277 "-level value adjust the level of image contrast",
3278 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003279 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003280 "-linear-stretch geometry",
3281 " improve contrast by `stretching with saturation'",
3282 "-liquid-rescale geometry",
3283 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003284 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003285 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003286 "-modulate value vary the brightness, saturation, and hue",
3287 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003288 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003289 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003290 "-motion-blur geometry",
3291 " simulate motion blur",
3292 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003293 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003294 "-normalize transform image to span the full range of colors",
3295 "-opaque color change this color to the fill color",
3296 "-ordered-dither NxN",
3297 " add a noise pattern to the image with specific",
3298 " amplitudes",
3299 "-paint radius simulate an oil painting",
3300 "-polaroid angle simulate a Polaroid picture",
3301 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003302 "-profile filename add, delete, or apply an image profile",
3303 "-quantize colorspace reduce colors in this colorspace",
3304 "-radial-blur angle radial blur the image",
3305 "-raise value lighten/darken image edges to create a 3-D effect",
3306 "-random-threshold low,high",
3307 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003308 "-region geometry apply options to a portion of the image",
3309 "-render render vector graphics",
3310 "-repage geometry size and location of an image canvas",
3311 "-resample geometry change the resolution of an image",
3312 "-resize geometry resize the image",
3313 "-roll geometry roll an image vertically or horizontally",
3314 "-rotate degrees apply Paeth rotation to the image",
3315 "-sample geometry scale image with pixel sampling",
3316 "-scale geometry scale the image",
3317 "-segment values segment an image",
3318 "-selective-blur geometry",
3319 " selectively blur pixels within a contrast threshold",
3320 "-sepia-tone threshold",
3321 " simulate a sepia-toned photo",
3322 "-set property value set an image property",
3323 "-shade degrees shade the image using a distant light source",
3324 "-shadow geometry simulate an image shadow",
3325 "-sharpen geometry sharpen the image",
3326 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003327 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003328 "-sigmoidal-contrast geometry",
3329 " increase the contrast without saturating highlights or shadows",
3330 "-sketch geometry simulate a pencil sketch",
3331 "-solarize threshold negate all pixels above the threshold level",
3332 "-sparse-color method args",
3333 " fill in a image based on a few color points",
3334 "-splice geometry splice the background color into the image",
3335 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003336 "-statistic type radius",
3337 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003338 "-strip strip image of all profiles and comments",
3339 "-swirl degrees swirl image pixels about the center",
3340 "-threshold value threshold the image",
3341 "-thumbnail geometry create a thumbnail of the image",
3342 "-tile filename tile image when filling a graphic primitive",
3343 "-tint value tint the image with the fill color",
3344 "-transform affine transform image",
3345 "-transparent color make this color transparent within the image",
3346 "-transpose flip image vertically and rotate 90 degrees",
3347 "-transverse flop image horizontally and rotate 270 degrees",
3348 "-trim trim image edges",
3349 "-type type image type",
3350 "-unique-colors discard all but one of any pixel color",
3351 "-unsharp geometry sharpen the image",
3352 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003353 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003354 "-white-threshold value",
3355 " force all pixels above the threshold into white",
3356 (char *) NULL
3357 },
3358 *sequence_operators[]=
3359 {
cristy4285d782011-02-09 20:12:28 +00003360 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003361 "-clut apply a color lookup table to the image",
3362 "-coalesce merge a sequence of images",
3363 "-combine combine a sequence of images",
3364 "-composite composite image",
3365 "-crop geometry cut out a rectangular region of the image",
3366 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003367 "-evaluate-sequence operator",
3368 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003369 "-flatten flatten a sequence of images",
3370 "-fx expression apply mathematical expression to an image channel(s)",
3371 "-hald-clut apply a Hald color lookup table to the image",
3372 "-morph value morph an image sequence",
3373 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003374 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003375 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003376 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003377 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003378 "-write filename write images to this file",
3379 (char *) NULL
3380 },
3381 *settings[]=
3382 {
3383 "-adjoin join images into a single multi-image file",
3384 "-affine matrix affine transform matrix",
3385 "-alpha option activate, deactivate, reset, or set the alpha channel",
3386 "-antialias remove pixel-aliasing",
3387 "-authenticate password",
3388 " decipher image with this password",
3389 "-attenuate value lessen (or intensify) when adding noise to an image",
3390 "-background color background color",
3391 "-bias value add bias when convolving an image",
3392 "-black-point-compensation",
3393 " use black point compensation",
3394 "-blue-primary point chromaticity blue primary point",
3395 "-bordercolor color border color",
3396 "-caption string assign a caption to an image",
3397 "-channel type apply option to select image channels",
3398 "-colors value preferred number of colors in the image",
3399 "-colorspace type alternate image colorspace",
3400 "-comment string annotate image with comment",
3401 "-compose operator set image composite operator",
3402 "-compress type type of pixel compression when writing the image",
3403 "-define format:option",
3404 " define one or more image format options",
3405 "-delay value display the next image after pausing",
3406 "-density geometry horizontal and vertical density of the image",
3407 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003408 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003409 "-display server get image or font from this X server",
3410 "-dispose method layer disposal method",
3411 "-dither method apply error diffusion to image",
3412 "-encoding type text encoding type",
3413 "-endian type endianness (MSB or LSB) of the image",
3414 "-family name render text with this font family",
3415 "-fill color color to use when filling a graphic primitive",
3416 "-filter type use this filter when resizing an image",
3417 "-font name render text with this font",
3418 "-format \"string\" output formatted image characteristics",
3419 "-fuzz distance colors within this distance are considered equal",
3420 "-gravity type horizontal and vertical text placement",
3421 "-green-primary point chromaticity green primary point",
3422 "-intent type type of rendering intent when managing the image color",
3423 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003424 "-interline-spacing value",
3425 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003426 "-interpolate method pixel color interpolation method",
3427 "-interword-spacing value",
3428 " set the space between two words",
3429 "-kerning value set the space between two letters",
3430 "-label string assign a label to an image",
3431 "-limit type value pixel cache resource limit",
3432 "-loop iterations add Netscape loop extension to your GIF animation",
3433 "-mask filename associate a mask with the image",
3434 "-mattecolor color frame color",
3435 "-monitor monitor progress",
3436 "-orient type image orientation",
3437 "-page geometry size and location of an image canvas (setting)",
3438 "-ping efficiently determine image attributes",
3439 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003440 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003441 "-preview type image preview type",
3442 "-quality value JPEG/MIFF/PNG compression level",
3443 "-quiet suppress all warning messages",
3444 "-red-primary point chromaticity red primary point",
3445 "-regard-warnings pay attention to warning messages",
3446 "-remap filename transform image colors to match this set of colors",
3447 "-respect-parentheses settings remain in effect until parenthesis boundary",
3448 "-sampling-factor geometry",
3449 " horizontal and vertical sampling factor",
3450 "-scene value image scene number",
3451 "-seed value seed a new sequence of pseudo-random numbers",
3452 "-size geometry width and height of image",
3453 "-stretch type render text with this font stretch",
3454 "-stroke color graphic primitive stroke color",
3455 "-strokewidth value graphic primitive stroke width",
3456 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003457 "-synchronize synchronize image to storage device",
3458 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003459 "-texture filename name of texture to tile onto the image background",
3460 "-tile-offset geometry",
3461 " tile offset",
3462 "-treedepth value color tree depth",
3463 "-transparent-color color",
3464 " transparent color",
3465 "-undercolor color annotation bounding box color",
3466 "-units type the units of image resolution",
3467 "-verbose print detailed information about the image",
3468 "-view FlashPix viewing transforms",
3469 "-virtual-pixel method",
3470 " virtual pixel access method",
3471 "-weight type render text with this font weight",
3472 "-white-point point chromaticity white point",
3473 (char *) NULL
3474 },
3475 *stack_operators[]=
3476 {
anthonyb69c4b32011-03-23 04:37:44 +00003477 "-delete indexes delete the image from the image sequence",
3478 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003479 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003480 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003481 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003482 "-swap indexes swap two images in the image sequence",
3483 (char *) NULL
3484 };
3485
3486 const char
3487 **p;
3488
cristybb503372010-05-27 20:51:26 +00003489 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003490 (void) printf("Copyright: %s\n",GetMagickCopyright());
3491 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003492 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3493 GetClientName());
3494 (void) printf("\nImage Settings:\n");
3495 for (p=settings; *p != (char *) NULL; p++)
3496 (void) printf(" %s\n",*p);
3497 (void) printf("\nImage Operators:\n");
3498 for (p=operators; *p != (char *) NULL; p++)
3499 (void) printf(" %s\n",*p);
3500 (void) printf("\nImage Sequence Operators:\n");
3501 for (p=sequence_operators; *p != (char *) NULL; p++)
3502 (void) printf(" %s\n",*p);
3503 (void) printf("\nImage Stack Operators:\n");
3504 for (p=stack_operators; *p != (char *) NULL; p++)
3505 (void) printf(" %s\n",*p);
3506 (void) printf("\nMiscellaneous Options:\n");
3507 for (p=miscellaneous; *p != (char *) NULL; p++)
3508 (void) printf(" %s\n",*p);
3509 (void) printf(
3510 "\nBy default, the image format of `file' is determined by its magic\n");
3511 (void) printf(
3512 "number. To specify a particular image format, precede the filename\n");
3513 (void) printf(
3514 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3515 (void) printf(
3516 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3517 (void) printf("'-' for standard input or output.\n");
3518 return(MagickFalse);
3519}
3520
3521WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3522 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3523{
3524#define DestroyMogrify() \
3525{ \
3526 if (format != (char *) NULL) \
3527 format=DestroyString(format); \
3528 if (path != (char *) NULL) \
3529 path=DestroyString(path); \
3530 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003531 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003532 argv[i]=DestroyString(argv[i]); \
3533 argv=(char **) RelinquishMagickMemory(argv); \
3534}
3535#define ThrowMogrifyException(asperity,tag,option) \
3536{ \
3537 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3538 option); \
3539 DestroyMogrify(); \
3540 return(MagickFalse); \
3541}
3542#define ThrowMogrifyInvalidArgumentException(option,argument) \
3543{ \
3544 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3545 "InvalidArgument","`%s': %s",argument,option); \
3546 DestroyMogrify(); \
3547 return(MagickFalse); \
3548}
3549
3550 char
3551 *format,
3552 *option,
3553 *path;
3554
3555 Image
3556 *image;
3557
3558 ImageStack
3559 image_stack[MaxImageStackDepth+1];
3560
cristy3ed852e2009-09-05 21:47:34 +00003561 MagickBooleanType
3562 global_colormap;
3563
3564 MagickBooleanType
3565 fire,
cristyebbcfea2011-02-25 02:43:54 +00003566 pend,
3567 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003568
3569 MagickStatusType
3570 status;
3571
cristyebbcfea2011-02-25 02:43:54 +00003572 register ssize_t
3573 i;
3574
3575 ssize_t
3576 j,
3577 k;
3578
cristy3ed852e2009-09-05 21:47:34 +00003579 /*
3580 Set defaults.
3581 */
3582 assert(image_info != (ImageInfo *) NULL);
3583 assert(image_info->signature == MagickSignature);
3584 if (image_info->debug != MagickFalse)
3585 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3586 assert(exception != (ExceptionInfo *) NULL);
3587 if (argc == 2)
3588 {
3589 option=argv[1];
3590 if ((LocaleCompare("version",option+1) == 0) ||
3591 (LocaleCompare("-version",option+1) == 0))
3592 {
cristyb51dff52011-05-19 16:55:47 +00003593 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003594 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003595 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3596 GetMagickCopyright());
3597 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3598 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003599 return(MagickFalse);
3600 }
3601 }
3602 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003603 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003604 format=(char *) NULL;
3605 path=(char *) NULL;
3606 global_colormap=MagickFalse;
3607 k=0;
3608 j=1;
3609 NewImageStack();
3610 option=(char *) NULL;
3611 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003612 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003613 status=MagickTrue;
3614 /*
3615 Parse command line.
3616 */
3617 ReadCommandlLine(argc,&argv);
3618 status=ExpandFilenames(&argc,&argv);
3619 if (status == MagickFalse)
3620 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3621 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003622 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003623 {
3624 option=argv[i];
3625 if (LocaleCompare(option,"(") == 0)
3626 {
3627 FireImageStack(MagickFalse,MagickTrue,pend);
3628 if (k == MaxImageStackDepth)
3629 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3630 option);
3631 PushImageStack();
3632 continue;
3633 }
3634 if (LocaleCompare(option,")") == 0)
3635 {
3636 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3637 if (k == 0)
3638 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3639 PopImageStack();
3640 continue;
3641 }
cristy042ee782011-04-22 18:48:30 +00003642 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003643 {
3644 char
3645 backup_filename[MaxTextExtent],
3646 *filename;
3647
3648 Image
3649 *images;
3650
3651 /*
3652 Option is a file name: begin by reading image from specified file.
3653 */
3654 FireImageStack(MagickFalse,MagickFalse,pend);
3655 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003656 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003657 filename=argv[++i];
3658 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3659 images=ReadImages(image_info,exception);
3660 status&=(images != (Image *) NULL) &&
3661 (exception->severity < ErrorException);
3662 if (images == (Image *) NULL)
3663 continue;
cristydaa76602010-06-30 13:05:11 +00003664 if (format != (char *) NULL)
3665 (void) CopyMagickString(images->filename,images->magick_filename,
3666 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003667 if (path != (char *) NULL)
3668 {
3669 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003670 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003671 path,*DirectorySeparator,filename);
3672 }
3673 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003674 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003675 AppendImageStack(images);
3676 FinalizeImageSettings(image_info,image,MagickFalse);
3677 if (global_colormap != MagickFalse)
3678 {
3679 QuantizeInfo
3680 *quantize_info;
3681
3682 quantize_info=AcquireQuantizeInfo(image_info);
3683 (void) RemapImages(quantize_info,images,(Image *) NULL);
3684 quantize_info=DestroyQuantizeInfo(quantize_info);
3685 }
3686 *backup_filename='\0';
3687 if ((LocaleCompare(image->filename,"-") != 0) &&
3688 (IsPathWritable(image->filename) != MagickFalse))
3689 {
cristybb503372010-05-27 20:51:26 +00003690 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003691 i;
3692
3693 /*
3694 Rename image file as backup.
3695 */
3696 (void) CopyMagickString(backup_filename,image->filename,
3697 MaxTextExtent);
3698 for (i=0; i < 6; i++)
3699 {
3700 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3701 if (IsPathAccessible(backup_filename) == MagickFalse)
3702 break;
3703 }
3704 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3705 (rename(image->filename,backup_filename) != 0))
3706 *backup_filename='\0';
3707 }
3708 /*
3709 Write transmogrified image to disk.
3710 */
3711 image_info->synchronize=MagickTrue;
3712 status&=WriteImages(image_info,image,image->filename,exception);
3713 if ((status == MagickFalse) && (*backup_filename != '\0'))
3714 (void) remove(backup_filename);
3715 RemoveAllImageStack();
3716 continue;
3717 }
3718 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3719 switch (*(option+1))
3720 {
3721 case 'a':
3722 {
3723 if (LocaleCompare("adaptive-blur",option+1) == 0)
3724 {
3725 i++;
cristybb503372010-05-27 20:51:26 +00003726 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003727 ThrowMogrifyException(OptionError,"MissingArgument",option);
3728 if (IsGeometry(argv[i]) == MagickFalse)
3729 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3730 break;
3731 }
3732 if (LocaleCompare("adaptive-resize",option+1) == 0)
3733 {
3734 i++;
cristybb503372010-05-27 20:51:26 +00003735 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003736 ThrowMogrifyException(OptionError,"MissingArgument",option);
3737 if (IsGeometry(argv[i]) == MagickFalse)
3738 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3739 break;
3740 }
3741 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3742 {
3743 i++;
cristybb503372010-05-27 20:51:26 +00003744 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003745 ThrowMogrifyException(OptionError,"MissingArgument",option);
3746 if (IsGeometry(argv[i]) == MagickFalse)
3747 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3748 break;
3749 }
3750 if (LocaleCompare("affine",option+1) == 0)
3751 {
3752 if (*option == '+')
3753 break;
3754 i++;
cristybb503372010-05-27 20:51:26 +00003755 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003756 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003757 break;
3758 }
3759 if (LocaleCompare("alpha",option+1) == 0)
3760 {
cristybb503372010-05-27 20:51:26 +00003761 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003762 type;
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);
cristy042ee782011-04-22 18:48:30 +00003769 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003770 if (type < 0)
3771 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3772 argv[i]);
3773 break;
3774 }
3775 if (LocaleCompare("annotate",option+1) == 0)
3776 {
3777 if (*option == '+')
3778 break;
3779 i++;
cristybb503372010-05-27 20:51:26 +00003780 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003781 ThrowMogrifyException(OptionError,"MissingArgument",option);
3782 if (IsGeometry(argv[i]) == MagickFalse)
3783 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003784 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003785 ThrowMogrifyException(OptionError,"MissingArgument",option);
3786 i++;
3787 break;
3788 }
3789 if (LocaleCompare("antialias",option+1) == 0)
3790 break;
3791 if (LocaleCompare("append",option+1) == 0)
3792 break;
3793 if (LocaleCompare("attenuate",option+1) == 0)
3794 {
3795 if (*option == '+')
3796 break;
3797 i++;
cristybb503372010-05-27 20:51:26 +00003798 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003799 ThrowMogrifyException(OptionError,"MissingArgument",option);
3800 if (IsGeometry(argv[i]) == MagickFalse)
3801 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3802 break;
3803 }
3804 if (LocaleCompare("authenticate",option+1) == 0)
3805 {
3806 if (*option == '+')
3807 break;
3808 i++;
cristybb503372010-05-27 20:51:26 +00003809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003810 ThrowMogrifyException(OptionError,"MissingArgument",option);
3811 break;
3812 }
3813 if (LocaleCompare("auto-gamma",option+1) == 0)
3814 break;
3815 if (LocaleCompare("auto-level",option+1) == 0)
3816 break;
3817 if (LocaleCompare("auto-orient",option+1) == 0)
3818 break;
3819 if (LocaleCompare("average",option+1) == 0)
3820 break;
3821 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3822 }
3823 case 'b':
3824 {
3825 if (LocaleCompare("background",option+1) == 0)
3826 {
3827 if (*option == '+')
3828 break;
3829 i++;
cristybb503372010-05-27 20:51:26 +00003830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003831 ThrowMogrifyException(OptionError,"MissingArgument",option);
3832 break;
3833 }
3834 if (LocaleCompare("bias",option+1) == 0)
3835 {
3836 if (*option == '+')
3837 break;
3838 i++;
cristybb503372010-05-27 20:51:26 +00003839 if (i == (ssize_t) (argc-1))
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("black-point-compensation",option+1) == 0)
3846 break;
3847 if (LocaleCompare("black-threshold",option+1) == 0)
3848 {
3849 if (*option == '+')
3850 break;
3851 i++;
cristybb503372010-05-27 20:51:26 +00003852 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003853 ThrowMogrifyException(OptionError,"MissingArgument",option);
3854 if (IsGeometry(argv[i]) == MagickFalse)
3855 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3856 break;
3857 }
3858 if (LocaleCompare("blue-primary",option+1) == 0)
3859 {
3860 if (*option == '+')
3861 break;
3862 i++;
cristybb503372010-05-27 20:51:26 +00003863 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003864 ThrowMogrifyException(OptionError,"MissingArgument",option);
3865 if (IsGeometry(argv[i]) == MagickFalse)
3866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3867 break;
3868 }
3869 if (LocaleCompare("blue-shift",option+1) == 0)
3870 {
3871 i++;
cristybb503372010-05-27 20:51:26 +00003872 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003873 ThrowMogrifyException(OptionError,"MissingArgument",option);
3874 if (IsGeometry(argv[i]) == MagickFalse)
3875 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3876 break;
3877 }
3878 if (LocaleCompare("blur",option+1) == 0)
3879 {
3880 i++;
cristybb503372010-05-27 20:51:26 +00003881 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003882 ThrowMogrifyException(OptionError,"MissingArgument",option);
3883 if (IsGeometry(argv[i]) == MagickFalse)
3884 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3885 break;
3886 }
3887 if (LocaleCompare("border",option+1) == 0)
3888 {
3889 if (*option == '+')
3890 break;
3891 i++;
cristybb503372010-05-27 20:51:26 +00003892 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003893 ThrowMogrifyException(OptionError,"MissingArgument",option);
3894 if (IsGeometry(argv[i]) == MagickFalse)
3895 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3896 break;
3897 }
3898 if (LocaleCompare("bordercolor",option+1) == 0)
3899 {
3900 if (*option == '+')
3901 break;
3902 i++;
cristybb503372010-05-27 20:51:26 +00003903 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003904 ThrowMogrifyException(OptionError,"MissingArgument",option);
3905 break;
3906 }
3907 if (LocaleCompare("box",option+1) == 0)
3908 {
3909 if (*option == '+')
3910 break;
3911 i++;
cristybb503372010-05-27 20:51:26 +00003912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003913 ThrowMogrifyException(OptionError,"MissingArgument",option);
3914 break;
3915 }
cristya28d6b82010-01-11 20:03:47 +00003916 if (LocaleCompare("brightness-contrast",option+1) == 0)
3917 {
3918 i++;
cristybb503372010-05-27 20:51:26 +00003919 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003920 ThrowMogrifyException(OptionError,"MissingArgument",option);
3921 if (IsGeometry(argv[i]) == MagickFalse)
3922 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3923 break;
3924 }
cristy3ed852e2009-09-05 21:47:34 +00003925 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3926 }
3927 case 'c':
3928 {
3929 if (LocaleCompare("cache",option+1) == 0)
3930 {
3931 if (*option == '+')
3932 break;
3933 i++;
cristybb503372010-05-27 20:51:26 +00003934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003935 ThrowMogrifyException(OptionError,"MissingArgument",option);
3936 if (IsGeometry(argv[i]) == MagickFalse)
3937 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3938 break;
3939 }
3940 if (LocaleCompare("caption",option+1) == 0)
3941 {
3942 if (*option == '+')
3943 break;
3944 i++;
cristybb503372010-05-27 20:51:26 +00003945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003946 ThrowMogrifyException(OptionError,"MissingArgument",option);
3947 break;
3948 }
3949 if (LocaleCompare("channel",option+1) == 0)
3950 {
cristybb503372010-05-27 20:51:26 +00003951 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003952 channel;
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 channel=ParseChannelOption(argv[i]);
3960 if (channel < 0)
3961 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3962 argv[i]);
3963 break;
3964 }
3965 if (LocaleCompare("cdl",option+1) == 0)
3966 {
3967 if (*option == '+')
3968 break;
3969 i++;
cristybb503372010-05-27 20:51:26 +00003970 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003971 ThrowMogrifyException(OptionError,"MissingArgument",option);
3972 break;
3973 }
3974 if (LocaleCompare("charcoal",option+1) == 0)
3975 {
3976 if (*option == '+')
3977 break;
3978 i++;
cristybb503372010-05-27 20:51:26 +00003979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003980 ThrowMogrifyException(OptionError,"MissingArgument",option);
3981 if (IsGeometry(argv[i]) == MagickFalse)
3982 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3983 break;
3984 }
3985 if (LocaleCompare("chop",option+1) == 0)
3986 {
3987 if (*option == '+')
3988 break;
3989 i++;
cristybb503372010-05-27 20:51:26 +00003990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003991 ThrowMogrifyException(OptionError,"MissingArgument",option);
3992 if (IsGeometry(argv[i]) == MagickFalse)
3993 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3994 break;
3995 }
cristy1eb45dd2009-09-25 16:38:06 +00003996 if (LocaleCompare("clamp",option+1) == 0)
3997 break;
3998 if (LocaleCompare("clip",option+1) == 0)
3999 break;
cristy3ed852e2009-09-05 21:47:34 +00004000 if (LocaleCompare("clip-mask",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 break;
4008 }
4009 if (LocaleCompare("clut",option+1) == 0)
4010 break;
4011 if (LocaleCompare("coalesce",option+1) == 0)
4012 break;
4013 if (LocaleCompare("colorize",option+1) == 0)
4014 {
4015 if (*option == '+')
4016 break;
4017 i++;
cristybb503372010-05-27 20:51:26 +00004018 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004019 ThrowMogrifyException(OptionError,"MissingArgument",option);
4020 if (IsGeometry(argv[i]) == MagickFalse)
4021 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4022 break;
4023 }
cristye6365592010-04-02 17:31:23 +00004024 if (LocaleCompare("color-matrix",option+1) == 0)
4025 {
cristyb6bd4ad2010-08-08 01:12:27 +00004026 KernelInfo
4027 *kernel_info;
4028
cristye6365592010-04-02 17:31:23 +00004029 if (*option == '+')
4030 break;
4031 i++;
cristybb503372010-05-27 20:51:26 +00004032 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004033 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004034 kernel_info=AcquireKernelInfo(argv[i]);
4035 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004036 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004037 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004038 break;
4039 }
cristy3ed852e2009-09-05 21:47:34 +00004040 if (LocaleCompare("colors",option+1) == 0)
4041 {
4042 if (*option == '+')
4043 break;
4044 i++;
cristybb503372010-05-27 20:51:26 +00004045 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004046 ThrowMogrifyException(OptionError,"MissingArgument",option);
4047 if (IsGeometry(argv[i]) == MagickFalse)
4048 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4049 break;
4050 }
4051 if (LocaleCompare("colorspace",option+1) == 0)
4052 {
cristybb503372010-05-27 20:51:26 +00004053 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004054 colorspace;
4055
4056 if (*option == '+')
4057 break;
4058 i++;
cristybb503372010-05-27 20:51:26 +00004059 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004060 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004061 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004062 argv[i]);
4063 if (colorspace < 0)
4064 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4065 argv[i]);
4066 break;
4067 }
4068 if (LocaleCompare("combine",option+1) == 0)
4069 break;
4070 if (LocaleCompare("comment",option+1) == 0)
4071 {
4072 if (*option == '+')
4073 break;
4074 i++;
cristybb503372010-05-27 20:51:26 +00004075 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004076 ThrowMogrifyException(OptionError,"MissingArgument",option);
4077 break;
4078 }
4079 if (LocaleCompare("composite",option+1) == 0)
4080 break;
4081 if (LocaleCompare("compress",option+1) == 0)
4082 {
cristybb503372010-05-27 20:51:26 +00004083 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004084 compress;
4085
4086 if (*option == '+')
4087 break;
4088 i++;
cristybb503372010-05-27 20:51:26 +00004089 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004090 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004091 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004092 argv[i]);
4093 if (compress < 0)
4094 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4095 argv[i]);
4096 break;
4097 }
cristy22879752009-10-25 23:55:40 +00004098 if (LocaleCompare("concurrent",option+1) == 0)
4099 break;
cristy3ed852e2009-09-05 21:47:34 +00004100 if (LocaleCompare("contrast",option+1) == 0)
4101 break;
4102 if (LocaleCompare("contrast-stretch",option+1) == 0)
4103 {
4104 i++;
cristybb503372010-05-27 20:51:26 +00004105 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004106 ThrowMogrifyException(OptionError,"MissingArgument",option);
4107 if (IsGeometry(argv[i]) == MagickFalse)
4108 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4109 break;
4110 }
4111 if (LocaleCompare("convolve",option+1) == 0)
4112 {
cristyb6bd4ad2010-08-08 01:12:27 +00004113 KernelInfo
4114 *kernel_info;
4115
cristy3ed852e2009-09-05 21:47:34 +00004116 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);
cristyb6bd4ad2010-08-08 01:12:27 +00004121 kernel_info=AcquireKernelInfo(argv[i]);
4122 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004123 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004124 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004125 break;
4126 }
4127 if (LocaleCompare("crop",option+1) == 0)
4128 {
4129 if (*option == '+')
4130 break;
4131 i++;
cristybb503372010-05-27 20:51:26 +00004132 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004133 ThrowMogrifyException(OptionError,"MissingArgument",option);
4134 if (IsGeometry(argv[i]) == MagickFalse)
4135 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4136 break;
4137 }
4138 if (LocaleCompare("cycle",option+1) == 0)
4139 {
4140 if (*option == '+')
4141 break;
4142 i++;
cristybb503372010-05-27 20:51:26 +00004143 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004144 ThrowMogrifyException(OptionError,"MissingArgument",option);
4145 if (IsGeometry(argv[i]) == MagickFalse)
4146 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4147 break;
4148 }
4149 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4150 }
4151 case 'd':
4152 {
4153 if (LocaleCompare("decipher",option+1) == 0)
4154 {
4155 if (*option == '+')
4156 break;
4157 i++;
cristybb503372010-05-27 20:51:26 +00004158 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004159 ThrowMogrifyException(OptionError,"MissingArgument",option);
4160 break;
4161 }
4162 if (LocaleCompare("deconstruct",option+1) == 0)
4163 break;
4164 if (LocaleCompare("debug",option+1) == 0)
4165 {
cristybb503372010-05-27 20:51:26 +00004166 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004167 event;
4168
4169 if (*option == '+')
4170 break;
4171 i++;
cristybb503372010-05-27 20:51:26 +00004172 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004173 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004174 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004175 if (event < 0)
4176 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4177 argv[i]);
4178 (void) SetLogEventMask(argv[i]);
4179 break;
4180 }
4181 if (LocaleCompare("define",option+1) == 0)
4182 {
4183 i++;
cristybb503372010-05-27 20:51:26 +00004184 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004185 ThrowMogrifyException(OptionError,"MissingArgument",option);
4186 if (*option == '+')
4187 {
4188 const char
4189 *define;
4190
4191 define=GetImageOption(image_info,argv[i]);
4192 if (define == (const char *) NULL)
4193 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4194 break;
4195 }
4196 break;
4197 }
4198 if (LocaleCompare("delay",option+1) == 0)
4199 {
4200 if (*option == '+')
4201 break;
4202 i++;
cristybb503372010-05-27 20:51:26 +00004203 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004204 ThrowMogrifyException(OptionError,"MissingArgument",option);
4205 if (IsGeometry(argv[i]) == MagickFalse)
4206 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4207 break;
4208 }
cristyecb10ff2011-03-22 13:14:03 +00004209 if (LocaleCompare("delete",option+1) == 0)
4210 {
4211 if (*option == '+')
4212 break;
4213 i++;
4214 if (i == (ssize_t) (argc-1))
4215 ThrowMogrifyException(OptionError,"MissingArgument",option);
4216 if (IsGeometry(argv[i]) == MagickFalse)
4217 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4218 break;
4219 }
cristy3ed852e2009-09-05 21:47:34 +00004220 if (LocaleCompare("density",option+1) == 0)
4221 {
4222 if (*option == '+')
4223 break;
4224 i++;
cristybb503372010-05-27 20:51:26 +00004225 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004226 ThrowMogrifyException(OptionError,"MissingArgument",option);
4227 if (IsGeometry(argv[i]) == MagickFalse)
4228 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4229 break;
4230 }
4231 if (LocaleCompare("depth",option+1) == 0)
4232 {
4233 if (*option == '+')
4234 break;
4235 i++;
cristybb503372010-05-27 20:51:26 +00004236 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004237 ThrowMogrifyException(OptionError,"MissingArgument",option);
4238 if (IsGeometry(argv[i]) == MagickFalse)
4239 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4240 break;
4241 }
4242 if (LocaleCompare("deskew",option+1) == 0)
4243 {
4244 if (*option == '+')
4245 break;
4246 i++;
cristybb503372010-05-27 20:51:26 +00004247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004248 ThrowMogrifyException(OptionError,"MissingArgument",option);
4249 if (IsGeometry(argv[i]) == MagickFalse)
4250 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4251 break;
4252 }
4253 if (LocaleCompare("despeckle",option+1) == 0)
4254 break;
4255 if (LocaleCompare("dft",option+1) == 0)
4256 break;
cristyc9b12952010-03-28 01:12:28 +00004257 if (LocaleCompare("direction",option+1) == 0)
4258 {
cristybb503372010-05-27 20:51:26 +00004259 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004260 direction;
4261
4262 if (*option == '+')
4263 break;
4264 i++;
cristybb503372010-05-27 20:51:26 +00004265 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004266 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004267 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004268 argv[i]);
4269 if (direction < 0)
4270 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4271 argv[i]);
4272 break;
4273 }
cristy3ed852e2009-09-05 21:47:34 +00004274 if (LocaleCompare("display",option+1) == 0)
4275 {
4276 if (*option == '+')
4277 break;
4278 i++;
cristybb503372010-05-27 20:51:26 +00004279 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004280 ThrowMogrifyException(OptionError,"MissingArgument",option);
4281 break;
4282 }
4283 if (LocaleCompare("dispose",option+1) == 0)
4284 {
cristybb503372010-05-27 20:51:26 +00004285 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004286 dispose;
4287
4288 if (*option == '+')
4289 break;
4290 i++;
cristybb503372010-05-27 20:51:26 +00004291 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004292 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004293 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004294 if (dispose < 0)
4295 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4296 argv[i]);
4297 break;
4298 }
4299 if (LocaleCompare("distort",option+1) == 0)
4300 {
cristybb503372010-05-27 20:51:26 +00004301 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004302 op;
4303
4304 i++;
cristybb503372010-05-27 20:51:26 +00004305 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004306 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004307 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004308 if (op < 0)
4309 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4310 argv[i]);
4311 i++;
cristybb503372010-05-27 20:51:26 +00004312 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004313 ThrowMogrifyException(OptionError,"MissingArgument",option);
4314 break;
4315 }
4316 if (LocaleCompare("dither",option+1) == 0)
4317 {
cristybb503372010-05-27 20:51:26 +00004318 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004319 method;
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);
cristy042ee782011-04-22 18:48:30 +00004326 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004327 if (method < 0)
4328 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4329 argv[i]);
4330 break;
4331 }
4332 if (LocaleCompare("draw",option+1) == 0)
4333 {
4334 if (*option == '+')
4335 break;
4336 i++;
cristybb503372010-05-27 20:51:26 +00004337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004338 ThrowMogrifyException(OptionError,"MissingArgument",option);
4339 break;
4340 }
cristyecb10ff2011-03-22 13:14:03 +00004341 if (LocaleCompare("duplicate",option+1) == 0)
4342 {
4343 if (*option == '+')
4344 break;
4345 i++;
4346 if (i == (ssize_t) (argc-1))
4347 ThrowMogrifyException(OptionError,"MissingArgument",option);
4348 if (IsGeometry(argv[i]) == MagickFalse)
4349 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4350 break;
4351 }
cristy22879752009-10-25 23:55:40 +00004352 if (LocaleCompare("duration",option+1) == 0)
4353 {
4354 if (*option == '+')
4355 break;
4356 i++;
cristybb503372010-05-27 20:51:26 +00004357 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004358 ThrowMogrifyException(OptionError,"MissingArgument",option);
4359 if (IsGeometry(argv[i]) == MagickFalse)
4360 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4361 break;
4362 }
cristy3ed852e2009-09-05 21:47:34 +00004363 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4364 }
4365 case 'e':
4366 {
4367 if (LocaleCompare("edge",option+1) == 0)
4368 {
4369 if (*option == '+')
4370 break;
4371 i++;
cristybb503372010-05-27 20:51:26 +00004372 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004373 ThrowMogrifyException(OptionError,"MissingArgument",option);
4374 if (IsGeometry(argv[i]) == MagickFalse)
4375 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4376 break;
4377 }
4378 if (LocaleCompare("emboss",option+1) == 0)
4379 {
4380 if (*option == '+')
4381 break;
4382 i++;
cristybb503372010-05-27 20:51:26 +00004383 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004384 ThrowMogrifyException(OptionError,"MissingArgument",option);
4385 if (IsGeometry(argv[i]) == MagickFalse)
4386 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4387 break;
4388 }
4389 if (LocaleCompare("encipher",option+1) == 0)
4390 {
4391 if (*option == '+')
4392 break;
4393 i++;
cristybb503372010-05-27 20:51:26 +00004394 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004395 ThrowMogrifyException(OptionError,"MissingArgument",option);
4396 break;
4397 }
4398 if (LocaleCompare("encoding",option+1) == 0)
4399 {
4400 if (*option == '+')
4401 break;
4402 i++;
cristybb503372010-05-27 20:51:26 +00004403 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004404 ThrowMogrifyException(OptionError,"MissingArgument",option);
4405 break;
4406 }
4407 if (LocaleCompare("endian",option+1) == 0)
4408 {
cristybb503372010-05-27 20:51:26 +00004409 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004410 endian;
4411
4412 if (*option == '+')
4413 break;
4414 i++;
cristybb503372010-05-27 20:51:26 +00004415 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004416 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004417 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004418 if (endian < 0)
4419 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4420 argv[i]);
4421 break;
4422 }
4423 if (LocaleCompare("enhance",option+1) == 0)
4424 break;
4425 if (LocaleCompare("equalize",option+1) == 0)
4426 break;
4427 if (LocaleCompare("evaluate",option+1) == 0)
4428 {
cristybb503372010-05-27 20:51:26 +00004429 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004430 op;
4431
4432 if (*option == '+')
4433 break;
4434 i++;
cristybb503372010-05-27 20:51:26 +00004435 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004436 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004437 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004438 if (op < 0)
4439 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4440 argv[i]);
4441 i++;
cristybb503372010-05-27 20:51:26 +00004442 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004443 ThrowMogrifyException(OptionError,"MissingArgument",option);
4444 if (IsGeometry(argv[i]) == MagickFalse)
4445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4446 break;
4447 }
cristyd18ae7c2010-03-07 17:39:52 +00004448 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4449 {
cristybb503372010-05-27 20:51:26 +00004450 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004451 op;
4452
4453 if (*option == '+')
4454 break;
4455 i++;
cristybb503372010-05-27 20:51:26 +00004456 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004457 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004458 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004459 if (op < 0)
4460 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4461 argv[i]);
4462 break;
4463 }
cristy3ed852e2009-09-05 21:47:34 +00004464 if (LocaleCompare("extent",option+1) == 0)
4465 {
4466 if (*option == '+')
4467 break;
4468 i++;
cristybb503372010-05-27 20:51:26 +00004469 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004470 ThrowMogrifyException(OptionError,"MissingArgument",option);
4471 if (IsGeometry(argv[i]) == MagickFalse)
4472 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4473 break;
4474 }
4475 if (LocaleCompare("extract",option+1) == 0)
4476 {
4477 if (*option == '+')
4478 break;
4479 i++;
cristybb503372010-05-27 20:51:26 +00004480 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004481 ThrowMogrifyException(OptionError,"MissingArgument",option);
4482 if (IsGeometry(argv[i]) == MagickFalse)
4483 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4484 break;
4485 }
4486 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4487 }
4488 case 'f':
4489 {
4490 if (LocaleCompare("family",option+1) == 0)
4491 {
4492 if (*option == '+')
4493 break;
4494 i++;
cristybb503372010-05-27 20:51:26 +00004495 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004496 ThrowMogrifyException(OptionError,"MissingArgument",option);
4497 break;
4498 }
4499 if (LocaleCompare("fill",option+1) == 0)
4500 {
4501 if (*option == '+')
4502 break;
4503 i++;
cristybb503372010-05-27 20:51:26 +00004504 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004505 ThrowMogrifyException(OptionError,"MissingArgument",option);
4506 break;
4507 }
4508 if (LocaleCompare("filter",option+1) == 0)
4509 {
cristybb503372010-05-27 20:51:26 +00004510 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004511 filter;
4512
4513 if (*option == '+')
4514 break;
4515 i++;
cristybb503372010-05-27 20:51:26 +00004516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004517 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004518 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004519 if (filter < 0)
4520 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4521 argv[i]);
4522 break;
4523 }
4524 if (LocaleCompare("flatten",option+1) == 0)
4525 break;
4526 if (LocaleCompare("flip",option+1) == 0)
4527 break;
4528 if (LocaleCompare("flop",option+1) == 0)
4529 break;
4530 if (LocaleCompare("floodfill",option+1) == 0)
4531 {
4532 if (*option == '+')
4533 break;
4534 i++;
cristybb503372010-05-27 20:51:26 +00004535 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004536 ThrowMogrifyException(OptionError,"MissingArgument",option);
4537 if (IsGeometry(argv[i]) == MagickFalse)
4538 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4539 i++;
cristybb503372010-05-27 20:51:26 +00004540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004541 ThrowMogrifyException(OptionError,"MissingArgument",option);
4542 break;
4543 }
4544 if (LocaleCompare("font",option+1) == 0)
4545 {
4546 if (*option == '+')
4547 break;
4548 i++;
cristybb503372010-05-27 20:51:26 +00004549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004550 ThrowMogrifyException(OptionError,"MissingArgument",option);
4551 break;
4552 }
4553 if (LocaleCompare("format",option+1) == 0)
4554 {
4555 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4556 (void) CloneString(&format,(char *) NULL);
4557 if (*option == '+')
4558 break;
4559 i++;
cristybb503372010-05-27 20:51:26 +00004560 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004561 ThrowMogrifyException(OptionError,"MissingArgument",option);
4562 (void) CloneString(&format,argv[i]);
4563 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4564 (void) ConcatenateMagickString(image_info->filename,":",
4565 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004566 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004567 if (*image_info->magick == '\0')
4568 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4569 format);
4570 break;
4571 }
4572 if (LocaleCompare("frame",option+1) == 0)
4573 {
4574 if (*option == '+')
4575 break;
4576 i++;
cristybb503372010-05-27 20:51:26 +00004577 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004578 ThrowMogrifyException(OptionError,"MissingArgument",option);
4579 if (IsGeometry(argv[i]) == MagickFalse)
4580 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4581 break;
4582 }
4583 if (LocaleCompare("function",option+1) == 0)
4584 {
cristybb503372010-05-27 20:51:26 +00004585 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004586 op;
4587
4588 if (*option == '+')
4589 break;
4590 i++;
cristybb503372010-05-27 20:51:26 +00004591 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004592 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004593 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004594 if (op < 0)
4595 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4596 i++;
cristybb503372010-05-27 20:51:26 +00004597 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004598 ThrowMogrifyException(OptionError,"MissingArgument",option);
4599 break;
4600 }
4601 if (LocaleCompare("fuzz",option+1) == 0)
4602 {
4603 if (*option == '+')
4604 break;
4605 i++;
cristybb503372010-05-27 20:51:26 +00004606 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004607 ThrowMogrifyException(OptionError,"MissingArgument",option);
4608 if (IsGeometry(argv[i]) == MagickFalse)
4609 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4610 break;
4611 }
4612 if (LocaleCompare("fx",option+1) == 0)
4613 {
4614 if (*option == '+')
4615 break;
4616 i++;
cristybb503372010-05-27 20:51:26 +00004617 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004618 ThrowMogrifyException(OptionError,"MissingArgument",option);
4619 break;
4620 }
4621 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4622 }
4623 case 'g':
4624 {
4625 if (LocaleCompare("gamma",option+1) == 0)
4626 {
4627 i++;
cristybb503372010-05-27 20:51:26 +00004628 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004629 ThrowMogrifyException(OptionError,"MissingArgument",option);
4630 if (IsGeometry(argv[i]) == MagickFalse)
4631 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4632 break;
4633 }
4634 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4635 (LocaleCompare("gaussian",option+1) == 0))
4636 {
4637 i++;
cristybb503372010-05-27 20:51:26 +00004638 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004639 ThrowMogrifyException(OptionError,"MissingArgument",option);
4640 if (IsGeometry(argv[i]) == MagickFalse)
4641 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4642 break;
4643 }
4644 if (LocaleCompare("geometry",option+1) == 0)
4645 {
4646 if (*option == '+')
4647 break;
4648 i++;
cristybb503372010-05-27 20:51:26 +00004649 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004650 ThrowMogrifyException(OptionError,"MissingArgument",option);
4651 if (IsGeometry(argv[i]) == MagickFalse)
4652 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4653 break;
4654 }
4655 if (LocaleCompare("gravity",option+1) == 0)
4656 {
cristybb503372010-05-27 20:51:26 +00004657 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004658 gravity;
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);
cristy042ee782011-04-22 18:48:30 +00004665 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004666 if (gravity < 0)
4667 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4668 argv[i]);
4669 break;
4670 }
4671 if (LocaleCompare("green-primary",option+1) == 0)
4672 {
4673 if (*option == '+')
4674 break;
4675 i++;
cristybb503372010-05-27 20:51:26 +00004676 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004677 ThrowMogrifyException(OptionError,"MissingArgument",option);
4678 if (IsGeometry(argv[i]) == MagickFalse)
4679 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4680 break;
4681 }
4682 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4683 }
4684 case 'h':
4685 {
4686 if (LocaleCompare("hald-clut",option+1) == 0)
4687 break;
4688 if ((LocaleCompare("help",option+1) == 0) ||
4689 (LocaleCompare("-help",option+1) == 0))
4690 return(MogrifyUsage());
4691 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4692 }
4693 case 'i':
4694 {
4695 if (LocaleCompare("identify",option+1) == 0)
4696 break;
4697 if (LocaleCompare("idft",option+1) == 0)
4698 break;
4699 if (LocaleCompare("implode",option+1) == 0)
4700 {
4701 if (*option == '+')
4702 break;
4703 i++;
cristybb503372010-05-27 20:51:26 +00004704 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004705 ThrowMogrifyException(OptionError,"MissingArgument",option);
4706 if (IsGeometry(argv[i]) == MagickFalse)
4707 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4708 break;
4709 }
4710 if (LocaleCompare("intent",option+1) == 0)
4711 {
cristybb503372010-05-27 20:51:26 +00004712 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004713 intent;
4714
4715 if (*option == '+')
4716 break;
4717 i++;
cristybb503372010-05-27 20:51:26 +00004718 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004719 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004720 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004721 if (intent < 0)
4722 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4723 argv[i]);
4724 break;
4725 }
4726 if (LocaleCompare("interlace",option+1) == 0)
4727 {
cristybb503372010-05-27 20:51:26 +00004728 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004729 interlace;
4730
4731 if (*option == '+')
4732 break;
4733 i++;
cristybb503372010-05-27 20:51:26 +00004734 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004735 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004736 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004737 argv[i]);
4738 if (interlace < 0)
4739 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4740 argv[i]);
4741 break;
4742 }
cristyb32b90a2009-09-07 21:45:48 +00004743 if (LocaleCompare("interline-spacing",option+1) == 0)
4744 {
4745 if (*option == '+')
4746 break;
4747 i++;
cristybb503372010-05-27 20:51:26 +00004748 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004749 ThrowMogrifyException(OptionError,"MissingArgument",option);
4750 if (IsGeometry(argv[i]) == MagickFalse)
4751 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4752 break;
4753 }
cristy3ed852e2009-09-05 21:47:34 +00004754 if (LocaleCompare("interpolate",option+1) == 0)
4755 {
cristybb503372010-05-27 20:51:26 +00004756 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004757 interpolate;
4758
4759 if (*option == '+')
4760 break;
4761 i++;
cristybb503372010-05-27 20:51:26 +00004762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004763 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004764 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004765 argv[i]);
4766 if (interpolate < 0)
4767 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4768 argv[i]);
4769 break;
4770 }
4771 if (LocaleCompare("interword-spacing",option+1) == 0)
4772 {
4773 if (*option == '+')
4774 break;
4775 i++;
cristybb503372010-05-27 20:51:26 +00004776 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004777 ThrowMogrifyException(OptionError,"MissingArgument",option);
4778 if (IsGeometry(argv[i]) == MagickFalse)
4779 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4780 break;
4781 }
4782 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4783 }
4784 case 'k':
4785 {
4786 if (LocaleCompare("kerning",option+1) == 0)
4787 {
4788 if (*option == '+')
4789 break;
4790 i++;
cristybb503372010-05-27 20:51:26 +00004791 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004792 ThrowMogrifyException(OptionError,"MissingArgument",option);
4793 if (IsGeometry(argv[i]) == MagickFalse)
4794 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4795 break;
4796 }
4797 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4798 }
4799 case 'l':
4800 {
4801 if (LocaleCompare("label",option+1) == 0)
4802 {
4803 if (*option == '+')
4804 break;
4805 i++;
cristybb503372010-05-27 20:51:26 +00004806 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004807 ThrowMogrifyException(OptionError,"MissingArgument",option);
4808 break;
4809 }
4810 if (LocaleCompare("lat",option+1) == 0)
4811 {
4812 if (*option == '+')
4813 break;
4814 i++;
cristybb503372010-05-27 20:51:26 +00004815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004816 ThrowMogrifyException(OptionError,"MissingArgument",option);
4817 if (IsGeometry(argv[i]) == MagickFalse)
4818 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4819 }
4820 if (LocaleCompare("layers",option+1) == 0)
4821 {
cristybb503372010-05-27 20:51:26 +00004822 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004823 type;
4824
4825 if (*option == '+')
4826 break;
4827 i++;
cristybb503372010-05-27 20:51:26 +00004828 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004829 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004830 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004831 if (type < 0)
4832 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4833 argv[i]);
4834 break;
4835 }
4836 if (LocaleCompare("level",option+1) == 0)
4837 {
4838 i++;
cristybb503372010-05-27 20:51:26 +00004839 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004840 ThrowMogrifyException(OptionError,"MissingArgument",option);
4841 if (IsGeometry(argv[i]) == MagickFalse)
4842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4843 break;
4844 }
4845 if (LocaleCompare("level-colors",option+1) == 0)
4846 {
4847 i++;
cristybb503372010-05-27 20:51:26 +00004848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004849 ThrowMogrifyException(OptionError,"MissingArgument",option);
4850 break;
4851 }
4852 if (LocaleCompare("linewidth",option+1) == 0)
4853 {
4854 if (*option == '+')
4855 break;
4856 i++;
cristybb503372010-05-27 20:51:26 +00004857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004858 ThrowMogrifyException(OptionError,"MissingArgument",option);
4859 if (IsGeometry(argv[i]) == MagickFalse)
4860 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4861 break;
4862 }
4863 if (LocaleCompare("limit",option+1) == 0)
4864 {
4865 char
4866 *p;
4867
4868 double
4869 value;
4870
cristybb503372010-05-27 20:51:26 +00004871 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004872 resource;
4873
4874 if (*option == '+')
4875 break;
4876 i++;
cristybb503372010-05-27 20:51:26 +00004877 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004878 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004879 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004880 argv[i]);
4881 if (resource < 0)
4882 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4883 argv[i]);
4884 i++;
cristybb503372010-05-27 20:51:26 +00004885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004886 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004887 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004888 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004889 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4890 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4891 break;
4892 }
4893 if (LocaleCompare("liquid-rescale",option+1) == 0)
4894 {
4895 i++;
cristybb503372010-05-27 20:51:26 +00004896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004897 ThrowMogrifyException(OptionError,"MissingArgument",option);
4898 if (IsGeometry(argv[i]) == MagickFalse)
4899 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4900 break;
4901 }
4902 if (LocaleCompare("list",option+1) == 0)
4903 {
cristybb503372010-05-27 20:51:26 +00004904 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004905 list;
4906
4907 if (*option == '+')
4908 break;
4909 i++;
cristybb503372010-05-27 20:51:26 +00004910 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004911 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004912 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004913 if (list < 0)
4914 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004915 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004916 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004917 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004918 }
4919 if (LocaleCompare("log",option+1) == 0)
4920 {
4921 if (*option == '+')
4922 break;
4923 i++;
cristybb503372010-05-27 20:51:26 +00004924 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004925 (strchr(argv[i],'%') == (char *) NULL))
4926 ThrowMogrifyException(OptionError,"MissingArgument",option);
4927 break;
4928 }
4929 if (LocaleCompare("loop",option+1) == 0)
4930 {
4931 if (*option == '+')
4932 break;
4933 i++;
cristybb503372010-05-27 20:51:26 +00004934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004935 ThrowMogrifyException(OptionError,"MissingArgument",option);
4936 if (IsGeometry(argv[i]) == MagickFalse)
4937 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4938 break;
4939 }
4940 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4941 }
4942 case 'm':
4943 {
4944 if (LocaleCompare("map",option+1) == 0)
4945 {
4946 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4947 if (*option == '+')
4948 break;
4949 i++;
cristybb503372010-05-27 20:51:26 +00004950 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004951 ThrowMogrifyException(OptionError,"MissingArgument",option);
4952 break;
4953 }
4954 if (LocaleCompare("mask",option+1) == 0)
4955 {
4956 if (*option == '+')
4957 break;
4958 i++;
cristybb503372010-05-27 20:51:26 +00004959 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004960 ThrowMogrifyException(OptionError,"MissingArgument",option);
4961 break;
4962 }
4963 if (LocaleCompare("matte",option+1) == 0)
4964 break;
4965 if (LocaleCompare("mattecolor",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 break;
4973 }
cristyf40785b2010-03-06 02:27:27 +00004974 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004975 break;
cristyf40785b2010-03-06 02:27:27 +00004976 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004977 break;
cristy3ed852e2009-09-05 21:47:34 +00004978 if (LocaleCompare("modulate",option+1) == 0)
4979 {
4980 if (*option == '+')
4981 break;
4982 i++;
cristybb503372010-05-27 20:51:26 +00004983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004984 ThrowMogrifyException(OptionError,"MissingArgument",option);
4985 if (IsGeometry(argv[i]) == MagickFalse)
4986 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4987 break;
4988 }
4989 if (LocaleCompare("median",option+1) == 0)
4990 {
4991 if (*option == '+')
4992 break;
4993 i++;
cristybb503372010-05-27 20:51:26 +00004994 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004995 ThrowMogrifyException(OptionError,"MissingArgument",option);
4996 if (IsGeometry(argv[i]) == MagickFalse)
4997 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4998 break;
4999 }
cristy69ec32d2011-02-27 23:57:09 +00005000 if (LocaleCompare("mode",option+1) == 0)
5001 {
5002 if (*option == '+')
5003 break;
5004 i++;
5005 if (i == (ssize_t) argc)
5006 ThrowMogrifyException(OptionError,"MissingArgument",option);
5007 if (IsGeometry(argv[i]) == MagickFalse)
5008 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5009 break;
5010 }
cristy3ed852e2009-09-05 21:47:34 +00005011 if (LocaleCompare("monitor",option+1) == 0)
5012 break;
5013 if (LocaleCompare("monochrome",option+1) == 0)
5014 break;
5015 if (LocaleCompare("morph",option+1) == 0)
5016 {
5017 if (*option == '+')
5018 break;
5019 i++;
cristybb503372010-05-27 20:51:26 +00005020 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005021 ThrowMogrifyException(OptionError,"MissingArgument",option);
5022 if (IsGeometry(argv[i]) == MagickFalse)
5023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5024 break;
5025 }
anthony29188a82010-01-22 10:12:34 +00005026 if (LocaleCompare("morphology",option+1) == 0)
5027 {
anthony29188a82010-01-22 10:12:34 +00005028 char
5029 token[MaxTextExtent];
5030
cristyb6bd4ad2010-08-08 01:12:27 +00005031 KernelInfo
5032 *kernel_info;
5033
5034 ssize_t
5035 op;
5036
anthony29188a82010-01-22 10:12:34 +00005037 i++;
cristybb503372010-05-27 20:51:26 +00005038 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005039 ThrowMogrifyException(OptionError,"MissingArgument",option);
5040 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005041 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005042 if (op < 0)
5043 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005044 token);
anthony29188a82010-01-22 10:12:34 +00005045 i++;
cristybb503372010-05-27 20:51:26 +00005046 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005047 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005048 kernel_info=AcquireKernelInfo(argv[i]);
5049 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005050 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005051 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005052 break;
5053 }
cristy3ed852e2009-09-05 21:47:34 +00005054 if (LocaleCompare("mosaic",option+1) == 0)
5055 break;
5056 if (LocaleCompare("motion-blur",option+1) == 0)
5057 {
5058 if (*option == '+')
5059 break;
5060 i++;
cristybb503372010-05-27 20:51:26 +00005061 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005062 ThrowMogrifyException(OptionError,"MissingArgument",option);
5063 if (IsGeometry(argv[i]) == MagickFalse)
5064 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5065 break;
5066 }
5067 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5068 }
5069 case 'n':
5070 {
5071 if (LocaleCompare("negate",option+1) == 0)
5072 break;
5073 if (LocaleCompare("noise",option+1) == 0)
5074 {
5075 i++;
cristybb503372010-05-27 20:51:26 +00005076 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005077 ThrowMogrifyException(OptionError,"MissingArgument",option);
5078 if (*option == '+')
5079 {
cristybb503372010-05-27 20:51:26 +00005080 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005081 noise;
5082
cristy042ee782011-04-22 18:48:30 +00005083 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005084 if (noise < 0)
5085 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5086 argv[i]);
5087 break;
5088 }
5089 if (IsGeometry(argv[i]) == MagickFalse)
5090 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5091 break;
5092 }
5093 if (LocaleCompare("noop",option+1) == 0)
5094 break;
5095 if (LocaleCompare("normalize",option+1) == 0)
5096 break;
5097 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5098 }
5099 case 'o':
5100 {
5101 if (LocaleCompare("opaque",option+1) == 0)
5102 {
cristy3ed852e2009-09-05 21:47:34 +00005103 i++;
cristybb503372010-05-27 20:51:26 +00005104 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005105 ThrowMogrifyException(OptionError,"MissingArgument",option);
5106 break;
5107 }
5108 if (LocaleCompare("ordered-dither",option+1) == 0)
5109 {
5110 if (*option == '+')
5111 break;
5112 i++;
cristybb503372010-05-27 20:51:26 +00005113 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005114 ThrowMogrifyException(OptionError,"MissingArgument",option);
5115 break;
5116 }
5117 if (LocaleCompare("orient",option+1) == 0)
5118 {
cristybb503372010-05-27 20:51:26 +00005119 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005120 orientation;
5121
5122 orientation=UndefinedOrientation;
5123 if (*option == '+')
5124 break;
5125 i++;
cristybb503372010-05-27 20:51:26 +00005126 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005127 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005128 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005129 argv[i]);
5130 if (orientation < 0)
5131 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5132 argv[i]);
5133 break;
5134 }
5135 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5136 }
5137 case 'p':
5138 {
5139 if (LocaleCompare("page",option+1) == 0)
5140 {
5141 if (*option == '+')
5142 break;
5143 i++;
cristybb503372010-05-27 20:51:26 +00005144 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005145 ThrowMogrifyException(OptionError,"MissingArgument",option);
5146 break;
5147 }
5148 if (LocaleCompare("paint",option+1) == 0)
5149 {
5150 if (*option == '+')
5151 break;
5152 i++;
cristybb503372010-05-27 20:51:26 +00005153 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005154 ThrowMogrifyException(OptionError,"MissingArgument",option);
5155 if (IsGeometry(argv[i]) == MagickFalse)
5156 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5157 break;
5158 }
5159 if (LocaleCompare("path",option+1) == 0)
5160 {
5161 (void) CloneString(&path,(char *) NULL);
5162 if (*option == '+')
5163 break;
5164 i++;
cristybb503372010-05-27 20:51:26 +00005165 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005166 ThrowMogrifyException(OptionError,"MissingArgument",option);
5167 (void) CloneString(&path,argv[i]);
5168 break;
5169 }
5170 if (LocaleCompare("pointsize",option+1) == 0)
5171 {
5172 if (*option == '+')
5173 break;
5174 i++;
cristybb503372010-05-27 20:51:26 +00005175 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005176 ThrowMogrifyException(OptionError,"MissingArgument",option);
5177 if (IsGeometry(argv[i]) == MagickFalse)
5178 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5179 break;
5180 }
5181 if (LocaleCompare("polaroid",option+1) == 0)
5182 {
5183 if (*option == '+')
5184 break;
5185 i++;
cristybb503372010-05-27 20:51:26 +00005186 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005187 ThrowMogrifyException(OptionError,"MissingArgument",option);
5188 if (IsGeometry(argv[i]) == MagickFalse)
5189 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5190 break;
5191 }
5192 if (LocaleCompare("posterize",option+1) == 0)
5193 {
5194 if (*option == '+')
5195 break;
5196 i++;
cristybb503372010-05-27 20:51:26 +00005197 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005198 ThrowMogrifyException(OptionError,"MissingArgument",option);
5199 if (IsGeometry(argv[i]) == MagickFalse)
5200 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5201 break;
5202 }
cristye7f51092010-01-17 00:39:37 +00005203 if (LocaleCompare("precision",option+1) == 0)
5204 {
5205 if (*option == '+')
5206 break;
5207 i++;
cristybb503372010-05-27 20:51:26 +00005208 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005209 ThrowMogrifyException(OptionError,"MissingArgument",option);
5210 if (IsGeometry(argv[i]) == MagickFalse)
5211 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5212 break;
5213 }
cristy3ed852e2009-09-05 21:47:34 +00005214 if (LocaleCompare("print",option+1) == 0)
5215 {
5216 if (*option == '+')
5217 break;
5218 i++;
cristybb503372010-05-27 20:51:26 +00005219 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005220 ThrowMogrifyException(OptionError,"MissingArgument",option);
5221 break;
5222 }
5223 if (LocaleCompare("process",option+1) == 0)
5224 {
5225 if (*option == '+')
5226 break;
5227 i++;
cristybb503372010-05-27 20:51:26 +00005228 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005229 ThrowMogrifyException(OptionError,"MissingArgument",option);
5230 break;
5231 }
5232 if (LocaleCompare("profile",option+1) == 0)
5233 {
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 break;
5238 }
5239 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5240 }
5241 case 'q':
5242 {
5243 if (LocaleCompare("quality",option+1) == 0)
5244 {
5245 if (*option == '+')
5246 break;
5247 i++;
cristybb503372010-05-27 20:51:26 +00005248 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005249 ThrowMogrifyException(OptionError,"MissingArgument",option);
5250 if (IsGeometry(argv[i]) == MagickFalse)
5251 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5252 break;
5253 }
5254 if (LocaleCompare("quantize",option+1) == 0)
5255 {
cristybb503372010-05-27 20:51:26 +00005256 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005257 colorspace;
5258
5259 if (*option == '+')
5260 break;
5261 i++;
cristybb503372010-05-27 20:51:26 +00005262 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005263 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005264 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005265 argv[i]);
5266 if (colorspace < 0)
5267 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5268 argv[i]);
5269 break;
5270 }
5271 if (LocaleCompare("quiet",option+1) == 0)
5272 break;
5273 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5274 }
5275 case 'r':
5276 {
5277 if (LocaleCompare("radial-blur",option+1) == 0)
5278 {
5279 i++;
cristybb503372010-05-27 20:51:26 +00005280 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005281 ThrowMogrifyException(OptionError,"MissingArgument",option);
5282 if (IsGeometry(argv[i]) == MagickFalse)
5283 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5284 break;
5285 }
5286 if (LocaleCompare("raise",option+1) == 0)
5287 {
5288 i++;
cristybb503372010-05-27 20:51:26 +00005289 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005290 ThrowMogrifyException(OptionError,"MissingArgument",option);
5291 if (IsGeometry(argv[i]) == MagickFalse)
5292 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5293 break;
5294 }
5295 if (LocaleCompare("random-threshold",option+1) == 0)
5296 {
5297 if (*option == '+')
5298 break;
5299 i++;
cristybb503372010-05-27 20:51:26 +00005300 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005301 ThrowMogrifyException(OptionError,"MissingArgument",option);
5302 if (IsGeometry(argv[i]) == MagickFalse)
5303 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5304 break;
5305 }
cristye6365592010-04-02 17:31:23 +00005306 if (LocaleCompare("recolor",option+1) == 0)
5307 {
5308 if (*option == '+')
5309 break;
5310 i++;
cristybb503372010-05-27 20:51:26 +00005311 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005312 ThrowMogrifyException(OptionError,"MissingArgument",option);
5313 if (IsGeometry(argv[i]) == MagickFalse)
5314 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5315 break;
5316 }
cristy3ed852e2009-09-05 21:47:34 +00005317 if (LocaleCompare("red-primary",option+1) == 0)
5318 {
5319 if (*option == '+')
5320 break;
5321 i++;
cristybb503372010-05-27 20:51:26 +00005322 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005323 ThrowMogrifyException(OptionError,"MissingArgument",option);
5324 if (IsGeometry(argv[i]) == MagickFalse)
5325 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5326 }
cristy9f2083a2010-04-22 19:48:05 +00005327 if (LocaleCompare("regard-warnings",option+1) == 0)
5328 break;
cristy3ed852e2009-09-05 21:47:34 +00005329 if (LocaleCompare("region",option+1) == 0)
5330 {
5331 if (*option == '+')
5332 break;
5333 i++;
cristybb503372010-05-27 20:51:26 +00005334 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005335 ThrowMogrifyException(OptionError,"MissingArgument",option);
5336 if (IsGeometry(argv[i]) == MagickFalse)
5337 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5338 break;
5339 }
cristyf0c78232010-03-15 12:53:40 +00005340 if (LocaleCompare("remap",option+1) == 0)
5341 {
5342 if (*option == '+')
5343 break;
5344 i++;
cristybb503372010-05-27 20:51:26 +00005345 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005346 ThrowMogrifyException(OptionError,"MissingArgument",option);
5347 break;
5348 }
cristy3ed852e2009-09-05 21:47:34 +00005349 if (LocaleCompare("render",option+1) == 0)
5350 break;
5351 if (LocaleCompare("repage",option+1) == 0)
5352 {
5353 if (*option == '+')
5354 break;
5355 i++;
cristybb503372010-05-27 20:51:26 +00005356 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005357 ThrowMogrifyException(OptionError,"MissingArgument",option);
5358 if (IsGeometry(argv[i]) == MagickFalse)
5359 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5360 break;
5361 }
5362 if (LocaleCompare("resample",option+1) == 0)
5363 {
5364 if (*option == '+')
5365 break;
5366 i++;
cristybb503372010-05-27 20:51:26 +00005367 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005368 ThrowMogrifyException(OptionError,"MissingArgument",option);
5369 if (IsGeometry(argv[i]) == MagickFalse)
5370 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5371 break;
5372 }
5373 if (LocaleCompare("resize",option+1) == 0)
5374 {
5375 if (*option == '+')
5376 break;
5377 i++;
cristybb503372010-05-27 20:51:26 +00005378 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005379 ThrowMogrifyException(OptionError,"MissingArgument",option);
5380 if (IsGeometry(argv[i]) == MagickFalse)
5381 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5382 break;
5383 }
cristyebbcfea2011-02-25 02:43:54 +00005384 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5385 {
5386 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5387 break;
5388 }
cristy3ed852e2009-09-05 21:47:34 +00005389 if (LocaleCompare("reverse",option+1) == 0)
5390 break;
5391 if (LocaleCompare("roll",option+1) == 0)
5392 {
5393 if (*option == '+')
5394 break;
5395 i++;
cristybb503372010-05-27 20:51:26 +00005396 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005397 ThrowMogrifyException(OptionError,"MissingArgument",option);
5398 if (IsGeometry(argv[i]) == MagickFalse)
5399 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5400 break;
5401 }
5402 if (LocaleCompare("rotate",option+1) == 0)
5403 {
5404 i++;
cristybb503372010-05-27 20:51:26 +00005405 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005406 ThrowMogrifyException(OptionError,"MissingArgument",option);
5407 if (IsGeometry(argv[i]) == MagickFalse)
5408 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5409 break;
5410 }
5411 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5412 }
5413 case 's':
5414 {
5415 if (LocaleCompare("sample",option+1) == 0)
5416 {
5417 if (*option == '+')
5418 break;
5419 i++;
cristybb503372010-05-27 20:51:26 +00005420 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005421 ThrowMogrifyException(OptionError,"MissingArgument",option);
5422 if (IsGeometry(argv[i]) == MagickFalse)
5423 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5424 break;
5425 }
5426 if (LocaleCompare("sampling-factor",option+1) == 0)
5427 {
5428 if (*option == '+')
5429 break;
5430 i++;
cristybb503372010-05-27 20:51:26 +00005431 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005432 ThrowMogrifyException(OptionError,"MissingArgument",option);
5433 if (IsGeometry(argv[i]) == MagickFalse)
5434 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5435 break;
5436 }
5437 if (LocaleCompare("scale",option+1) == 0)
5438 {
5439 if (*option == '+')
5440 break;
5441 i++;
cristybb503372010-05-27 20:51:26 +00005442 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005443 ThrowMogrifyException(OptionError,"MissingArgument",option);
5444 if (IsGeometry(argv[i]) == MagickFalse)
5445 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5446 break;
5447 }
5448 if (LocaleCompare("scene",option+1) == 0)
5449 {
5450 if (*option == '+')
5451 break;
5452 i++;
cristybb503372010-05-27 20:51:26 +00005453 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005454 ThrowMogrifyException(OptionError,"MissingArgument",option);
5455 if (IsGeometry(argv[i]) == MagickFalse)
5456 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5457 break;
5458 }
5459 if (LocaleCompare("seed",option+1) == 0)
5460 {
5461 if (*option == '+')
5462 break;
5463 i++;
cristybb503372010-05-27 20:51:26 +00005464 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005465 ThrowMogrifyException(OptionError,"MissingArgument",option);
5466 if (IsGeometry(argv[i]) == MagickFalse)
5467 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5468 break;
5469 }
5470 if (LocaleCompare("segment",option+1) == 0)
5471 {
5472 if (*option == '+')
5473 break;
5474 i++;
cristybb503372010-05-27 20:51:26 +00005475 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005476 ThrowMogrifyException(OptionError,"MissingArgument",option);
5477 if (IsGeometry(argv[i]) == MagickFalse)
5478 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5479 break;
5480 }
5481 if (LocaleCompare("selective-blur",option+1) == 0)
5482 {
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("separate",option+1) == 0)
5491 break;
5492 if (LocaleCompare("sepia-tone",option+1) == 0)
5493 {
5494 if (*option == '+')
5495 break;
5496 i++;
cristybb503372010-05-27 20:51:26 +00005497 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005498 ThrowMogrifyException(OptionError,"MissingArgument",option);
5499 if (IsGeometry(argv[i]) == MagickFalse)
5500 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5501 break;
5502 }
5503 if (LocaleCompare("set",option+1) == 0)
5504 {
5505 i++;
cristybb503372010-05-27 20:51:26 +00005506 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005507 ThrowMogrifyException(OptionError,"MissingArgument",option);
5508 if (*option == '+')
5509 break;
5510 i++;
cristybb503372010-05-27 20:51:26 +00005511 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005512 ThrowMogrifyException(OptionError,"MissingArgument",option);
5513 break;
5514 }
5515 if (LocaleCompare("shade",option+1) == 0)
5516 {
5517 i++;
cristybb503372010-05-27 20:51:26 +00005518 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005519 ThrowMogrifyException(OptionError,"MissingArgument",option);
5520 if (IsGeometry(argv[i]) == MagickFalse)
5521 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5522 break;
5523 }
5524 if (LocaleCompare("shadow",option+1) == 0)
5525 {
5526 if (*option == '+')
5527 break;
5528 i++;
cristybb503372010-05-27 20:51:26 +00005529 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005530 ThrowMogrifyException(OptionError,"MissingArgument",option);
5531 if (IsGeometry(argv[i]) == MagickFalse)
5532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5533 break;
5534 }
5535 if (LocaleCompare("sharpen",option+1) == 0)
5536 {
5537 i++;
cristybb503372010-05-27 20:51:26 +00005538 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005539 ThrowMogrifyException(OptionError,"MissingArgument",option);
5540 if (IsGeometry(argv[i]) == MagickFalse)
5541 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5542 break;
5543 }
5544 if (LocaleCompare("shave",option+1) == 0)
5545 {
5546 if (*option == '+')
5547 break;
5548 i++;
cristybb503372010-05-27 20:51:26 +00005549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005550 ThrowMogrifyException(OptionError,"MissingArgument",option);
5551 if (IsGeometry(argv[i]) == MagickFalse)
5552 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5553 break;
5554 }
5555 if (LocaleCompare("shear",option+1) == 0)
5556 {
5557 i++;
cristybb503372010-05-27 20:51:26 +00005558 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005559 ThrowMogrifyException(OptionError,"MissingArgument",option);
5560 if (IsGeometry(argv[i]) == MagickFalse)
5561 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5562 break;
5563 }
5564 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5565 {
5566 i++;
cristybb503372010-05-27 20:51:26 +00005567 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005568 ThrowMogrifyException(OptionError,"MissingArgument",option);
5569 if (IsGeometry(argv[i]) == MagickFalse)
5570 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5571 break;
5572 }
5573 if (LocaleCompare("size",option+1) == 0)
5574 {
5575 if (*option == '+')
5576 break;
5577 i++;
cristybb503372010-05-27 20:51:26 +00005578 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005579 ThrowMogrifyException(OptionError,"MissingArgument",option);
5580 if (IsGeometry(argv[i]) == MagickFalse)
5581 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5582 break;
5583 }
5584 if (LocaleCompare("sketch",option+1) == 0)
5585 {
5586 if (*option == '+')
5587 break;
5588 i++;
cristybb503372010-05-27 20:51:26 +00005589 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005590 ThrowMogrifyException(OptionError,"MissingArgument",option);
5591 if (IsGeometry(argv[i]) == MagickFalse)
5592 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5593 break;
5594 }
cristy4285d782011-02-09 20:12:28 +00005595 if (LocaleCompare("smush",option+1) == 0)
5596 {
cristy4285d782011-02-09 20:12:28 +00005597 i++;
5598 if (i == (ssize_t) argc)
5599 ThrowMogrifyException(OptionError,"MissingArgument",option);
5600 if (IsGeometry(argv[i]) == MagickFalse)
5601 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005602 i++;
5603 break;
5604 }
cristy3ed852e2009-09-05 21:47:34 +00005605 if (LocaleCompare("solarize",option+1) == 0)
5606 {
5607 if (*option == '+')
5608 break;
5609 i++;
cristybb503372010-05-27 20:51:26 +00005610 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005611 ThrowMogrifyException(OptionError,"MissingArgument",option);
5612 if (IsGeometry(argv[i]) == MagickFalse)
5613 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5614 break;
5615 }
5616 if (LocaleCompare("sparse-color",option+1) == 0)
5617 {
cristybb503372010-05-27 20:51:26 +00005618 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005619 op;
5620
5621 i++;
cristybb503372010-05-27 20:51:26 +00005622 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005623 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005624 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005625 if (op < 0)
5626 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5627 argv[i]);
5628 i++;
cristybb503372010-05-27 20:51:26 +00005629 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005630 ThrowMogrifyException(OptionError,"MissingArgument",option);
5631 break;
5632 }
5633 if (LocaleCompare("spread",option+1) == 0)
5634 {
5635 if (*option == '+')
5636 break;
5637 i++;
cristybb503372010-05-27 20:51:26 +00005638 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005639 ThrowMogrifyException(OptionError,"MissingArgument",option);
5640 if (IsGeometry(argv[i]) == MagickFalse)
5641 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5642 break;
5643 }
cristy0834d642011-03-18 18:26:08 +00005644 if (LocaleCompare("statistic",option+1) == 0)
5645 {
5646 ssize_t
5647 op;
5648
5649 if (*option == '+')
5650 break;
5651 i++;
5652 if (i == (ssize_t) argc)
5653 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005654 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005655 if (op < 0)
5656 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5657 argv[i]);
5658 i++;
5659 if (i == (ssize_t) (argc-1))
5660 ThrowMogrifyException(OptionError,"MissingArgument",option);
5661 if (IsGeometry(argv[i]) == MagickFalse)
5662 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5663 break;
5664 }
cristy3ed852e2009-09-05 21:47:34 +00005665 if (LocaleCompare("stretch",option+1) == 0)
5666 {
cristybb503372010-05-27 20:51:26 +00005667 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005668 stretch;
5669
5670 if (*option == '+')
5671 break;
5672 i++;
cristybb503372010-05-27 20:51:26 +00005673 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005674 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005675 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005676 if (stretch < 0)
5677 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5678 argv[i]);
5679 break;
5680 }
5681 if (LocaleCompare("strip",option+1) == 0)
5682 break;
5683 if (LocaleCompare("stroke",option+1) == 0)
5684 {
5685 if (*option == '+')
5686 break;
5687 i++;
cristybb503372010-05-27 20:51:26 +00005688 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005689 ThrowMogrifyException(OptionError,"MissingArgument",option);
5690 break;
5691 }
5692 if (LocaleCompare("strokewidth",option+1) == 0)
5693 {
5694 if (*option == '+')
5695 break;
5696 i++;
cristybb503372010-05-27 20:51:26 +00005697 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005698 ThrowMogrifyException(OptionError,"MissingArgument",option);
5699 if (IsGeometry(argv[i]) == MagickFalse)
5700 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5701 break;
5702 }
5703 if (LocaleCompare("style",option+1) == 0)
5704 {
cristybb503372010-05-27 20:51:26 +00005705 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005706 style;
5707
5708 if (*option == '+')
5709 break;
5710 i++;
cristybb503372010-05-27 20:51:26 +00005711 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005712 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005713 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005714 if (style < 0)
5715 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5716 argv[i]);
5717 break;
5718 }
cristyecb10ff2011-03-22 13:14:03 +00005719 if (LocaleCompare("swap",option+1) == 0)
5720 {
5721 if (*option == '+')
5722 break;
5723 i++;
5724 if (i == (ssize_t) (argc-1))
5725 ThrowMogrifyException(OptionError,"MissingArgument",option);
5726 if (IsGeometry(argv[i]) == MagickFalse)
5727 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5728 break;
5729 }
cristy3ed852e2009-09-05 21:47:34 +00005730 if (LocaleCompare("swirl",option+1) == 0)
5731 {
5732 if (*option == '+')
5733 break;
5734 i++;
cristybb503372010-05-27 20:51:26 +00005735 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005736 ThrowMogrifyException(OptionError,"MissingArgument",option);
5737 if (IsGeometry(argv[i]) == MagickFalse)
5738 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5739 break;
5740 }
cristyd9a29192010-10-16 16:49:53 +00005741 if (LocaleCompare("synchronize",option+1) == 0)
5742 break;
cristy3ed852e2009-09-05 21:47:34 +00005743 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5744 }
5745 case 't':
5746 {
5747 if (LocaleCompare("taint",option+1) == 0)
5748 break;
5749 if (LocaleCompare("texture",option+1) == 0)
5750 {
5751 if (*option == '+')
5752 break;
5753 i++;
cristybb503372010-05-27 20:51:26 +00005754 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005755 ThrowMogrifyException(OptionError,"MissingArgument",option);
5756 break;
5757 }
5758 if (LocaleCompare("tile",option+1) == 0)
5759 {
5760 if (*option == '+')
5761 break;
5762 i++;
cristybb503372010-05-27 20:51:26 +00005763 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005764 ThrowMogrifyException(OptionError,"MissingArgument",option);
5765 break;
5766 }
5767 if (LocaleCompare("tile-offset",option+1) == 0)
5768 {
5769 if (*option == '+')
5770 break;
5771 i++;
cristybb503372010-05-27 20:51:26 +00005772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005773 ThrowMogrifyException(OptionError,"MissingArgument",option);
5774 if (IsGeometry(argv[i]) == MagickFalse)
5775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5776 break;
5777 }
5778 if (LocaleCompare("tint",option+1) == 0)
5779 {
5780 if (*option == '+')
5781 break;
5782 i++;
cristybb503372010-05-27 20:51:26 +00005783 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005784 ThrowMogrifyException(OptionError,"MissingArgument",option);
5785 if (IsGeometry(argv[i]) == MagickFalse)
5786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5787 break;
5788 }
5789 if (LocaleCompare("transform",option+1) == 0)
5790 break;
5791 if (LocaleCompare("transpose",option+1) == 0)
5792 break;
5793 if (LocaleCompare("transverse",option+1) == 0)
5794 break;
5795 if (LocaleCompare("threshold",option+1) == 0)
5796 {
5797 if (*option == '+')
5798 break;
5799 i++;
cristybb503372010-05-27 20:51:26 +00005800 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005801 ThrowMogrifyException(OptionError,"MissingArgument",option);
5802 if (IsGeometry(argv[i]) == MagickFalse)
5803 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5804 break;
5805 }
5806 if (LocaleCompare("thumbnail",option+1) == 0)
5807 {
5808 if (*option == '+')
5809 break;
5810 i++;
cristybb503372010-05-27 20:51:26 +00005811 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005812 ThrowMogrifyException(OptionError,"MissingArgument",option);
5813 if (IsGeometry(argv[i]) == MagickFalse)
5814 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5815 break;
5816 }
5817 if (LocaleCompare("transparent",option+1) == 0)
5818 {
5819 i++;
cristybb503372010-05-27 20:51:26 +00005820 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005821 ThrowMogrifyException(OptionError,"MissingArgument",option);
5822 break;
5823 }
5824 if (LocaleCompare("transparent-color",option+1) == 0)
5825 {
5826 if (*option == '+')
5827 break;
5828 i++;
cristybb503372010-05-27 20:51:26 +00005829 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005830 ThrowMogrifyException(OptionError,"MissingArgument",option);
5831 break;
5832 }
5833 if (LocaleCompare("treedepth",option+1) == 0)
5834 {
5835 if (*option == '+')
5836 break;
5837 i++;
cristybb503372010-05-27 20:51:26 +00005838 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005839 ThrowMogrifyException(OptionError,"MissingArgument",option);
5840 if (IsGeometry(argv[i]) == MagickFalse)
5841 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5842 break;
5843 }
5844 if (LocaleCompare("trim",option+1) == 0)
5845 break;
5846 if (LocaleCompare("type",option+1) == 0)
5847 {
cristybb503372010-05-27 20:51:26 +00005848 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005849 type;
5850
5851 if (*option == '+')
5852 break;
5853 i++;
cristybb503372010-05-27 20:51:26 +00005854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005855 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005856 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005857 if (type < 0)
5858 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5859 argv[i]);
5860 break;
5861 }
5862 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5863 }
5864 case 'u':
5865 {
5866 if (LocaleCompare("undercolor",option+1) == 0)
5867 {
5868 if (*option == '+')
5869 break;
5870 i++;
cristybb503372010-05-27 20:51:26 +00005871 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005872 ThrowMogrifyException(OptionError,"MissingArgument",option);
5873 break;
5874 }
5875 if (LocaleCompare("unique-colors",option+1) == 0)
5876 break;
5877 if (LocaleCompare("units",option+1) == 0)
5878 {
cristybb503372010-05-27 20:51:26 +00005879 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005880 units;
5881
5882 if (*option == '+')
5883 break;
5884 i++;
cristybb503372010-05-27 20:51:26 +00005885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005886 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005887 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005888 argv[i]);
5889 if (units < 0)
5890 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5891 argv[i]);
5892 break;
5893 }
5894 if (LocaleCompare("unsharp",option+1) == 0)
5895 {
5896 i++;
cristybb503372010-05-27 20:51:26 +00005897 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005898 ThrowMogrifyException(OptionError,"MissingArgument",option);
5899 if (IsGeometry(argv[i]) == MagickFalse)
5900 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5901 break;
5902 }
5903 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5904 }
5905 case 'v':
5906 {
5907 if (LocaleCompare("verbose",option+1) == 0)
5908 {
5909 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5910 break;
5911 }
5912 if ((LocaleCompare("version",option+1) == 0) ||
5913 (LocaleCompare("-version",option+1) == 0))
5914 {
cristyb51dff52011-05-19 16:55:47 +00005915 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005916 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005917 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5918 GetMagickCopyright());
5919 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5920 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005921 break;
5922 }
5923 if (LocaleCompare("view",option+1) == 0)
5924 {
5925 if (*option == '+')
5926 break;
5927 i++;
cristybb503372010-05-27 20:51:26 +00005928 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005929 ThrowMogrifyException(OptionError,"MissingArgument",option);
5930 break;
5931 }
5932 if (LocaleCompare("vignette",option+1) == 0)
5933 {
5934 if (*option == '+')
5935 break;
5936 i++;
cristybb503372010-05-27 20:51:26 +00005937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005938 ThrowMogrifyException(OptionError,"MissingArgument",option);
5939 if (IsGeometry(argv[i]) == MagickFalse)
5940 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5941 break;
5942 }
5943 if (LocaleCompare("virtual-pixel",option+1) == 0)
5944 {
cristybb503372010-05-27 20:51:26 +00005945 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005946 method;
5947
5948 if (*option == '+')
5949 break;
5950 i++;
cristybb503372010-05-27 20:51:26 +00005951 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005952 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005953 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005954 argv[i]);
5955 if (method < 0)
5956 ThrowMogrifyException(OptionError,
5957 "UnrecognizedVirtualPixelMethod",argv[i]);
5958 break;
5959 }
5960 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5961 }
5962 case 'w':
5963 {
5964 if (LocaleCompare("wave",option+1) == 0)
5965 {
5966 i++;
cristybb503372010-05-27 20:51:26 +00005967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005968 ThrowMogrifyException(OptionError,"MissingArgument",option);
5969 if (IsGeometry(argv[i]) == MagickFalse)
5970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5971 break;
5972 }
5973 if (LocaleCompare("weight",option+1) == 0)
5974 {
5975 if (*option == '+')
5976 break;
5977 i++;
cristybb503372010-05-27 20:51:26 +00005978 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005979 ThrowMogrifyException(OptionError,"MissingArgument",option);
5980 break;
5981 }
5982 if (LocaleCompare("white-point",option+1) == 0)
5983 {
5984 if (*option == '+')
5985 break;
5986 i++;
cristybb503372010-05-27 20:51:26 +00005987 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005988 ThrowMogrifyException(OptionError,"MissingArgument",option);
5989 if (IsGeometry(argv[i]) == MagickFalse)
5990 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5991 break;
5992 }
5993 if (LocaleCompare("white-threshold",option+1) == 0)
5994 {
5995 if (*option == '+')
5996 break;
5997 i++;
cristybb503372010-05-27 20:51:26 +00005998 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005999 ThrowMogrifyException(OptionError,"MissingArgument",option);
6000 if (IsGeometry(argv[i]) == MagickFalse)
6001 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6002 break;
6003 }
6004 if (LocaleCompare("write",option+1) == 0)
6005 {
6006 i++;
cristybb503372010-05-27 20:51:26 +00006007 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006008 ThrowMogrifyException(OptionError,"MissingArgument",option);
6009 break;
6010 }
6011 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6012 }
6013 case '?':
6014 break;
6015 default:
6016 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6017 }
cristy042ee782011-04-22 18:48:30 +00006018 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6019 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006020 if (fire != MagickFalse)
6021 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6022 }
6023 if (k != 0)
6024 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006025 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006026 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6027 DestroyMogrify();
6028 return(status != 0 ? MagickTrue : MagickFalse);
6029}
6030
6031/*
6032%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6033% %
6034% %
6035% %
6036+ M o g r i f y I m a g e I n f o %
6037% %
6038% %
6039% %
6040%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6041%
6042% MogrifyImageInfo() applies image processing settings to the image as
6043% prescribed by command line options.
6044%
6045% The format of the MogrifyImageInfo method is:
6046%
6047% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6048% const char **argv,ExceptionInfo *exception)
6049%
6050% A description of each parameter follows:
6051%
6052% o image_info: the image info..
6053%
6054% o argc: Specifies a pointer to an integer describing the number of
6055% elements in the argument vector.
6056%
6057% o argv: Specifies a pointer to a text array containing the command line
6058% arguments.
6059%
6060% o exception: return any errors or warnings in this structure.
6061%
6062*/
6063WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6064 const int argc,const char **argv,ExceptionInfo *exception)
6065{
6066 const char
6067 *option;
6068
6069 GeometryInfo
6070 geometry_info;
6071
cristybb503372010-05-27 20:51:26 +00006072 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006073 count;
6074
cristybb503372010-05-27 20:51:26 +00006075 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006076 i;
6077
6078 /*
6079 Initialize method variables.
6080 */
6081 assert(image_info != (ImageInfo *) NULL);
6082 assert(image_info->signature == MagickSignature);
6083 if (image_info->debug != MagickFalse)
6084 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6085 image_info->filename);
6086 if (argc < 0)
6087 return(MagickTrue);
6088 /*
6089 Set the image settings.
6090 */
cristybb503372010-05-27 20:51:26 +00006091 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006092 {
6093 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006094 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006095 continue;
cristy042ee782011-04-22 18:48:30 +00006096 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006097 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006098 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006099 break;
6100 switch (*(option+1))
6101 {
6102 case 'a':
6103 {
6104 if (LocaleCompare("adjoin",option+1) == 0)
6105 {
6106 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6107 break;
6108 }
6109 if (LocaleCompare("antialias",option+1) == 0)
6110 {
6111 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6112 break;
6113 }
6114 if (LocaleCompare("attenuate",option+1) == 0)
6115 {
6116 if (*option == '+')
6117 {
6118 (void) DeleteImageOption(image_info,option+1);
6119 break;
6120 }
6121 (void) SetImageOption(image_info,option+1,argv[i+1]);
6122 break;
6123 }
6124 if (LocaleCompare("authenticate",option+1) == 0)
6125 {
6126 if (*option == '+')
6127 (void) CloneString(&image_info->authenticate,(char *) NULL);
6128 else
6129 (void) CloneString(&image_info->authenticate,argv[i+1]);
6130 break;
6131 }
6132 break;
6133 }
6134 case 'b':
6135 {
6136 if (LocaleCompare("background",option+1) == 0)
6137 {
6138 if (*option == '+')
6139 {
6140 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006141 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006142 &image_info->background_color,exception);
6143 break;
6144 }
6145 (void) SetImageOption(image_info,option+1,argv[i+1]);
6146 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6147 exception);
6148 break;
6149 }
6150 if (LocaleCompare("bias",option+1) == 0)
6151 {
6152 if (*option == '+')
6153 {
6154 (void) SetImageOption(image_info,option+1,"0.0");
6155 break;
6156 }
6157 (void) SetImageOption(image_info,option+1,argv[i+1]);
6158 break;
6159 }
6160 if (LocaleCompare("black-point-compensation",option+1) == 0)
6161 {
6162 if (*option == '+')
6163 {
6164 (void) SetImageOption(image_info,option+1,"false");
6165 break;
6166 }
6167 (void) SetImageOption(image_info,option+1,"true");
6168 break;
6169 }
6170 if (LocaleCompare("blue-primary",option+1) == 0)
6171 {
6172 if (*option == '+')
6173 {
6174 (void) SetImageOption(image_info,option+1,"0.0");
6175 break;
6176 }
6177 (void) SetImageOption(image_info,option+1,argv[i+1]);
6178 break;
6179 }
6180 if (LocaleCompare("bordercolor",option+1) == 0)
6181 {
6182 if (*option == '+')
6183 {
6184 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006185 (void) QueryColorDatabase(MogrifyBorderColor,
6186 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006187 break;
6188 }
6189 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6190 exception);
6191 (void) SetImageOption(image_info,option+1,argv[i+1]);
6192 break;
6193 }
6194 if (LocaleCompare("box",option+1) == 0)
6195 {
6196 if (*option == '+')
6197 {
6198 (void) SetImageOption(image_info,"undercolor","none");
6199 break;
6200 }
6201 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6202 break;
6203 }
6204 break;
6205 }
6206 case 'c':
6207 {
6208 if (LocaleCompare("cache",option+1) == 0)
6209 {
6210 MagickSizeType
6211 limit;
6212
6213 limit=MagickResourceInfinity;
6214 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006215 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006216 (void) SetMagickResourceLimit(MemoryResource,limit);
6217 (void) SetMagickResourceLimit(MapResource,2*limit);
6218 break;
6219 }
6220 if (LocaleCompare("caption",option+1) == 0)
6221 {
6222 if (*option == '+')
6223 {
6224 (void) DeleteImageOption(image_info,option+1);
6225 break;
6226 }
6227 (void) SetImageOption(image_info,option+1,argv[i+1]);
6228 break;
6229 }
6230 if (LocaleCompare("channel",option+1) == 0)
6231 {
6232 if (*option == '+')
6233 {
6234 image_info->channel=DefaultChannels;
6235 break;
6236 }
6237 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6238 break;
6239 }
6240 if (LocaleCompare("colors",option+1) == 0)
6241 {
cristye27293e2009-12-18 02:53:20 +00006242 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006243 break;
6244 }
6245 if (LocaleCompare("colorspace",option+1) == 0)
6246 {
6247 if (*option == '+')
6248 {
6249 image_info->colorspace=UndefinedColorspace;
6250 (void) SetImageOption(image_info,option+1,"undefined");
6251 break;
6252 }
cristy042ee782011-04-22 18:48:30 +00006253 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006254 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6255 (void) SetImageOption(image_info,option+1,argv[i+1]);
6256 break;
6257 }
cristy3ed852e2009-09-05 21:47:34 +00006258 if (LocaleCompare("comment",option+1) == 0)
6259 {
6260 if (*option == '+')
6261 {
6262 (void) DeleteImageOption(image_info,option+1);
6263 break;
6264 }
6265 (void) SetImageOption(image_info,option+1,argv[i+1]);
6266 break;
6267 }
6268 if (LocaleCompare("compose",option+1) == 0)
6269 {
6270 if (*option == '+')
6271 {
6272 (void) SetImageOption(image_info,option+1,"undefined");
6273 break;
6274 }
6275 (void) SetImageOption(image_info,option+1,argv[i+1]);
6276 break;
6277 }
6278 if (LocaleCompare("compress",option+1) == 0)
6279 {
6280 if (*option == '+')
6281 {
6282 image_info->compression=UndefinedCompression;
6283 (void) SetImageOption(image_info,option+1,"undefined");
6284 break;
6285 }
cristy042ee782011-04-22 18:48:30 +00006286 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006287 MagickCompressOptions,MagickFalse,argv[i+1]);
6288 (void) SetImageOption(image_info,option+1,argv[i+1]);
6289 break;
6290 }
6291 break;
6292 }
6293 case 'd':
6294 {
6295 if (LocaleCompare("debug",option+1) == 0)
6296 {
6297 if (*option == '+')
6298 (void) SetLogEventMask("none");
6299 else
6300 (void) SetLogEventMask(argv[i+1]);
6301 image_info->debug=IsEventLogging();
6302 break;
6303 }
6304 if (LocaleCompare("define",option+1) == 0)
6305 {
6306 if (*option == '+')
6307 {
6308 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6309 (void) DeleteImageRegistry(argv[i+1]+9);
6310 else
6311 (void) DeleteImageOption(image_info,argv[i+1]);
6312 break;
6313 }
6314 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6315 {
6316 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6317 exception);
6318 break;
6319 }
6320 (void) DefineImageOption(image_info,argv[i+1]);
6321 break;
6322 }
6323 if (LocaleCompare("delay",option+1) == 0)
6324 {
6325 if (*option == '+')
6326 {
6327 (void) SetImageOption(image_info,option+1,"0");
6328 break;
6329 }
6330 (void) SetImageOption(image_info,option+1,argv[i+1]);
6331 break;
6332 }
6333 if (LocaleCompare("density",option+1) == 0)
6334 {
6335 /*
6336 Set image density.
6337 */
6338 if (*option == '+')
6339 {
6340 if (image_info->density != (char *) NULL)
6341 image_info->density=DestroyString(image_info->density);
6342 (void) SetImageOption(image_info,option+1,"72");
6343 break;
6344 }
6345 (void) CloneString(&image_info->density,argv[i+1]);
6346 (void) SetImageOption(image_info,option+1,argv[i+1]);
6347 break;
6348 }
6349 if (LocaleCompare("depth",option+1) == 0)
6350 {
6351 if (*option == '+')
6352 {
6353 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6354 break;
6355 }
cristye27293e2009-12-18 02:53:20 +00006356 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006357 break;
6358 }
cristyc9b12952010-03-28 01:12:28 +00006359 if (LocaleCompare("direction",option+1) == 0)
6360 {
6361 if (*option == '+')
6362 {
6363 (void) SetImageOption(image_info,option+1,"undefined");
6364 break;
6365 }
6366 (void) SetImageOption(image_info,option+1,argv[i+1]);
6367 break;
6368 }
cristy3ed852e2009-09-05 21:47:34 +00006369 if (LocaleCompare("display",option+1) == 0)
6370 {
6371 if (*option == '+')
6372 {
6373 if (image_info->server_name != (char *) NULL)
6374 image_info->server_name=DestroyString(
6375 image_info->server_name);
6376 break;
6377 }
6378 (void) CloneString(&image_info->server_name,argv[i+1]);
6379 break;
6380 }
6381 if (LocaleCompare("dispose",option+1) == 0)
6382 {
6383 if (*option == '+')
6384 {
6385 (void) SetImageOption(image_info,option+1,"undefined");
6386 break;
6387 }
6388 (void) SetImageOption(image_info,option+1,argv[i+1]);
6389 break;
6390 }
6391 if (LocaleCompare("dither",option+1) == 0)
6392 {
6393 if (*option == '+')
6394 {
6395 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006396 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006397 break;
6398 }
6399 (void) SetImageOption(image_info,option+1,argv[i+1]);
6400 image_info->dither=MagickTrue;
6401 break;
6402 }
6403 break;
6404 }
6405 case 'e':
6406 {
6407 if (LocaleCompare("encoding",option+1) == 0)
6408 {
6409 if (*option == '+')
6410 {
6411 (void) SetImageOption(image_info,option+1,"undefined");
6412 break;
6413 }
6414 (void) SetImageOption(image_info,option+1,argv[i+1]);
6415 break;
6416 }
6417 if (LocaleCompare("endian",option+1) == 0)
6418 {
6419 if (*option == '+')
6420 {
6421 image_info->endian=UndefinedEndian;
6422 (void) SetImageOption(image_info,option+1,"undefined");
6423 break;
6424 }
cristy042ee782011-04-22 18:48:30 +00006425 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006426 MagickEndianOptions,MagickFalse,argv[i+1]);
6427 (void) SetImageOption(image_info,option+1,argv[i+1]);
6428 break;
6429 }
6430 if (LocaleCompare("extract",option+1) == 0)
6431 {
6432 /*
6433 Set image extract geometry.
6434 */
6435 if (*option == '+')
6436 {
6437 if (image_info->extract != (char *) NULL)
6438 image_info->extract=DestroyString(image_info->extract);
6439 break;
6440 }
6441 (void) CloneString(&image_info->extract,argv[i+1]);
6442 break;
6443 }
6444 break;
6445 }
6446 case 'f':
6447 {
6448 if (LocaleCompare("fill",option+1) == 0)
6449 {
6450 if (*option == '+')
6451 {
6452 (void) SetImageOption(image_info,option+1,"none");
6453 break;
6454 }
6455 (void) SetImageOption(image_info,option+1,argv[i+1]);
6456 break;
6457 }
6458 if (LocaleCompare("filter",option+1) == 0)
6459 {
6460 if (*option == '+')
6461 {
6462 (void) SetImageOption(image_info,option+1,"undefined");
6463 break;
6464 }
6465 (void) SetImageOption(image_info,option+1,argv[i+1]);
6466 break;
6467 }
6468 if (LocaleCompare("font",option+1) == 0)
6469 {
6470 if (*option == '+')
6471 {
6472 if (image_info->font != (char *) NULL)
6473 image_info->font=DestroyString(image_info->font);
6474 break;
6475 }
6476 (void) CloneString(&image_info->font,argv[i+1]);
6477 break;
6478 }
6479 if (LocaleCompare("format",option+1) == 0)
6480 {
6481 register const char
6482 *q;
6483
6484 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006485 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006486 image_info->ping=MagickFalse;
6487 (void) SetImageOption(image_info,option+1,argv[i+1]);
6488 break;
6489 }
6490 if (LocaleCompare("fuzz",option+1) == 0)
6491 {
6492 if (*option == '+')
6493 {
6494 image_info->fuzz=0.0;
6495 (void) SetImageOption(image_info,option+1,"0");
6496 break;
6497 }
cristyf2f27272009-12-17 14:48:46 +00006498 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006499 1.0);
6500 (void) SetImageOption(image_info,option+1,argv[i+1]);
6501 break;
6502 }
6503 break;
6504 }
6505 case 'g':
6506 {
6507 if (LocaleCompare("gravity",option+1) == 0)
6508 {
6509 if (*option == '+')
6510 {
6511 (void) SetImageOption(image_info,option+1,"undefined");
6512 break;
6513 }
6514 (void) SetImageOption(image_info,option+1,argv[i+1]);
6515 break;
6516 }
6517 if (LocaleCompare("green-primary",option+1) == 0)
6518 {
6519 if (*option == '+')
6520 {
6521 (void) SetImageOption(image_info,option+1,"0.0");
6522 break;
6523 }
6524 (void) SetImageOption(image_info,option+1,argv[i+1]);
6525 break;
6526 }
6527 break;
6528 }
6529 case 'i':
6530 {
6531 if (LocaleCompare("intent",option+1) == 0)
6532 {
6533 if (*option == '+')
6534 {
6535 (void) SetImageOption(image_info,option+1,"undefined");
6536 break;
6537 }
6538 (void) SetImageOption(image_info,option+1,argv[i+1]);
6539 break;
6540 }
6541 if (LocaleCompare("interlace",option+1) == 0)
6542 {
6543 if (*option == '+')
6544 {
6545 image_info->interlace=UndefinedInterlace;
6546 (void) SetImageOption(image_info,option+1,"undefined");
6547 break;
6548 }
cristy042ee782011-04-22 18:48:30 +00006549 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006550 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6551 (void) SetImageOption(image_info,option+1,argv[i+1]);
6552 break;
6553 }
cristyb32b90a2009-09-07 21:45:48 +00006554 if (LocaleCompare("interline-spacing",option+1) == 0)
6555 {
6556 if (*option == '+')
6557 {
6558 (void) SetImageOption(image_info,option+1,"undefined");
6559 break;
6560 }
6561 (void) SetImageOption(image_info,option+1,argv[i+1]);
6562 break;
6563 }
cristy3ed852e2009-09-05 21:47:34 +00006564 if (LocaleCompare("interpolate",option+1) == 0)
6565 {
6566 if (*option == '+')
6567 {
6568 (void) SetImageOption(image_info,option+1,"undefined");
6569 break;
6570 }
6571 (void) SetImageOption(image_info,option+1,argv[i+1]);
6572 break;
6573 }
6574 if (LocaleCompare("interword-spacing",option+1) == 0)
6575 {
6576 if (*option == '+')
6577 {
6578 (void) SetImageOption(image_info,option+1,"undefined");
6579 break;
6580 }
6581 (void) SetImageOption(image_info,option+1,argv[i+1]);
6582 break;
6583 }
6584 break;
6585 }
6586 case 'k':
6587 {
6588 if (LocaleCompare("kerning",option+1) == 0)
6589 {
6590 if (*option == '+')
6591 {
6592 (void) SetImageOption(image_info,option+1,"undefined");
6593 break;
6594 }
6595 (void) SetImageOption(image_info,option+1,argv[i+1]);
6596 break;
6597 }
6598 break;
6599 }
6600 case 'l':
6601 {
6602 if (LocaleCompare("label",option+1) == 0)
6603 {
6604 if (*option == '+')
6605 {
6606 (void) DeleteImageOption(image_info,option+1);
6607 break;
6608 }
6609 (void) SetImageOption(image_info,option+1,argv[i+1]);
6610 break;
6611 }
6612 if (LocaleCompare("limit",option+1) == 0)
6613 {
6614 MagickSizeType
6615 limit;
6616
6617 ResourceType
6618 type;
6619
6620 if (*option == '+')
6621 break;
cristy042ee782011-04-22 18:48:30 +00006622 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006623 MagickFalse,argv[i+1]);
6624 limit=MagickResourceInfinity;
6625 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006626 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006627 (void) SetMagickResourceLimit(type,limit);
6628 break;
6629 }
6630 if (LocaleCompare("list",option+1) == 0)
6631 {
cristybb503372010-05-27 20:51:26 +00006632 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006633 list;
6634
6635 /*
6636 Display configuration list.
6637 */
cristy042ee782011-04-22 18:48:30 +00006638 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006639 switch (list)
6640 {
6641 case MagickCoderOptions:
6642 {
6643 (void) ListCoderInfo((FILE *) NULL,exception);
6644 break;
6645 }
6646 case MagickColorOptions:
6647 {
6648 (void) ListColorInfo((FILE *) NULL,exception);
6649 break;
6650 }
6651 case MagickConfigureOptions:
6652 {
6653 (void) ListConfigureInfo((FILE *) NULL,exception);
6654 break;
6655 }
6656 case MagickDelegateOptions:
6657 {
6658 (void) ListDelegateInfo((FILE *) NULL,exception);
6659 break;
6660 }
6661 case MagickFontOptions:
6662 {
6663 (void) ListTypeInfo((FILE *) NULL,exception);
6664 break;
6665 }
6666 case MagickFormatOptions:
6667 {
6668 (void) ListMagickInfo((FILE *) NULL,exception);
6669 break;
6670 }
6671 case MagickLocaleOptions:
6672 {
6673 (void) ListLocaleInfo((FILE *) NULL,exception);
6674 break;
6675 }
6676 case MagickLogOptions:
6677 {
6678 (void) ListLogInfo((FILE *) NULL,exception);
6679 break;
6680 }
6681 case MagickMagicOptions:
6682 {
6683 (void) ListMagicInfo((FILE *) NULL,exception);
6684 break;
6685 }
6686 case MagickMimeOptions:
6687 {
6688 (void) ListMimeInfo((FILE *) NULL,exception);
6689 break;
6690 }
6691 case MagickModuleOptions:
6692 {
6693 (void) ListModuleInfo((FILE *) NULL,exception);
6694 break;
6695 }
6696 case MagickPolicyOptions:
6697 {
6698 (void) ListPolicyInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickResourceOptions:
6702 {
6703 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickThresholdOptions:
6707 {
6708 (void) ListThresholdMaps((FILE *) NULL,exception);
6709 break;
6710 }
6711 default:
6712 {
cristy042ee782011-04-22 18:48:30 +00006713 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006714 exception);
6715 break;
6716 }
6717 }
cristyaeb2cbc2010-05-07 13:28:58 +00006718 break;
cristy3ed852e2009-09-05 21:47:34 +00006719 }
6720 if (LocaleCompare("log",option+1) == 0)
6721 {
6722 if (*option == '+')
6723 break;
6724 (void) SetLogFormat(argv[i+1]);
6725 break;
6726 }
6727 if (LocaleCompare("loop",option+1) == 0)
6728 {
6729 if (*option == '+')
6730 {
6731 (void) SetImageOption(image_info,option+1,"0");
6732 break;
6733 }
6734 (void) SetImageOption(image_info,option+1,argv[i+1]);
6735 break;
6736 }
6737 break;
6738 }
6739 case 'm':
6740 {
6741 if (LocaleCompare("matte",option+1) == 0)
6742 {
6743 if (*option == '+')
6744 {
6745 (void) SetImageOption(image_info,option+1,"false");
6746 break;
6747 }
6748 (void) SetImageOption(image_info,option+1,"true");
6749 break;
6750 }
6751 if (LocaleCompare("mattecolor",option+1) == 0)
6752 {
6753 if (*option == '+')
6754 {
6755 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006756 (void) QueryColorDatabase(MogrifyMatteColor,
6757 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006758 break;
6759 }
6760 (void) SetImageOption(image_info,option+1,argv[i+1]);
6761 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6762 exception);
6763 break;
6764 }
6765 if (LocaleCompare("monitor",option+1) == 0)
6766 {
6767 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6768 (void *) NULL);
6769 break;
6770 }
6771 if (LocaleCompare("monochrome",option+1) == 0)
6772 {
6773 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6774 break;
6775 }
6776 break;
6777 }
6778 case 'o':
6779 {
6780 if (LocaleCompare("orient",option+1) == 0)
6781 {
6782 if (*option == '+')
6783 {
6784 image_info->orientation=UndefinedOrientation;
6785 (void) SetImageOption(image_info,option+1,"undefined");
6786 break;
6787 }
cristy042ee782011-04-22 18:48:30 +00006788 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006789 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006790 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006791 break;
6792 }
6793 }
6794 case 'p':
6795 {
6796 if (LocaleCompare("page",option+1) == 0)
6797 {
6798 char
6799 *canonical_page,
6800 page[MaxTextExtent];
6801
6802 const char
6803 *image_option;
6804
6805 MagickStatusType
6806 flags;
6807
6808 RectangleInfo
6809 geometry;
6810
6811 if (*option == '+')
6812 {
6813 (void) DeleteImageOption(image_info,option+1);
6814 (void) CloneString(&image_info->page,(char *) NULL);
6815 break;
6816 }
6817 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6818 image_option=GetImageOption(image_info,"page");
6819 if (image_option != (const char *) NULL)
6820 flags=ParseAbsoluteGeometry(image_option,&geometry);
6821 canonical_page=GetPageGeometry(argv[i+1]);
6822 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6823 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006824 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006825 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006826 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006827 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006828 (unsigned long) geometry.width,(unsigned long) geometry.height,
6829 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006830 (void) SetImageOption(image_info,option+1,page);
6831 (void) CloneString(&image_info->page,page);
6832 break;
6833 }
6834 if (LocaleCompare("pen",option+1) == 0)
6835 {
6836 if (*option == '+')
6837 {
6838 (void) SetImageOption(image_info,option+1,"none");
6839 break;
6840 }
6841 (void) SetImageOption(image_info,option+1,argv[i+1]);
6842 break;
6843 }
6844 if (LocaleCompare("ping",option+1) == 0)
6845 {
6846 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6847 break;
6848 }
6849 if (LocaleCompare("pointsize",option+1) == 0)
6850 {
6851 if (*option == '+')
6852 geometry_info.rho=0.0;
6853 else
6854 (void) ParseGeometry(argv[i+1],&geometry_info);
6855 image_info->pointsize=geometry_info.rho;
6856 break;
6857 }
cristye7f51092010-01-17 00:39:37 +00006858 if (LocaleCompare("precision",option+1) == 0)
6859 {
cristybf2766a2010-01-17 03:33:23 +00006860 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006861 break;
6862 }
cristy3ed852e2009-09-05 21:47:34 +00006863 if (LocaleCompare("preview",option+1) == 0)
6864 {
6865 /*
6866 Preview image.
6867 */
6868 if (*option == '+')
6869 {
6870 image_info->preview_type=UndefinedPreview;
6871 break;
6872 }
cristy042ee782011-04-22 18:48:30 +00006873 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006874 MagickPreviewOptions,MagickFalse,argv[i+1]);
6875 break;
6876 }
6877 break;
6878 }
6879 case 'q':
6880 {
6881 if (LocaleCompare("quality",option+1) == 0)
6882 {
6883 /*
6884 Set image compression quality.
6885 */
6886 if (*option == '+')
6887 {
6888 image_info->quality=UndefinedCompressionQuality;
6889 (void) SetImageOption(image_info,option+1,"0");
6890 break;
6891 }
cristye27293e2009-12-18 02:53:20 +00006892 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006893 (void) SetImageOption(image_info,option+1,argv[i+1]);
6894 break;
6895 }
6896 if (LocaleCompare("quiet",option+1) == 0)
6897 {
6898 static WarningHandler
6899 warning_handler = (WarningHandler) NULL;
6900
6901 if (*option == '+')
6902 {
6903 /*
6904 Restore error or warning messages.
6905 */
6906 warning_handler=SetWarningHandler(warning_handler);
6907 break;
6908 }
6909 /*
6910 Suppress error or warning messages.
6911 */
6912 warning_handler=SetWarningHandler((WarningHandler) NULL);
6913 break;
6914 }
6915 break;
6916 }
6917 case 'r':
6918 {
6919 if (LocaleCompare("red-primary",option+1) == 0)
6920 {
6921 if (*option == '+')
6922 {
6923 (void) SetImageOption(image_info,option+1,"0.0");
6924 break;
6925 }
6926 (void) SetImageOption(image_info,option+1,argv[i+1]);
6927 break;
6928 }
6929 break;
6930 }
6931 case 's':
6932 {
6933 if (LocaleCompare("sampling-factor",option+1) == 0)
6934 {
6935 /*
6936 Set image sampling factor.
6937 */
6938 if (*option == '+')
6939 {
6940 if (image_info->sampling_factor != (char *) NULL)
6941 image_info->sampling_factor=DestroyString(
6942 image_info->sampling_factor);
6943 break;
6944 }
6945 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6946 break;
6947 }
6948 if (LocaleCompare("scene",option+1) == 0)
6949 {
6950 /*
6951 Set image scene.
6952 */
6953 if (*option == '+')
6954 {
6955 image_info->scene=0;
6956 (void) SetImageOption(image_info,option+1,"0");
6957 break;
6958 }
cristye27293e2009-12-18 02:53:20 +00006959 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006960 (void) SetImageOption(image_info,option+1,argv[i+1]);
6961 break;
6962 }
6963 if (LocaleCompare("seed",option+1) == 0)
6964 {
cristybb503372010-05-27 20:51:26 +00006965 size_t
cristy3ed852e2009-09-05 21:47:34 +00006966 seed;
6967
6968 if (*option == '+')
6969 {
cristybb503372010-05-27 20:51:26 +00006970 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006971 SeedPseudoRandomGenerator(seed);
6972 break;
6973 }
cristye27293e2009-12-18 02:53:20 +00006974 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006975 SeedPseudoRandomGenerator(seed);
6976 break;
6977 }
6978 if (LocaleCompare("size",option+1) == 0)
6979 {
6980 if (*option == '+')
6981 {
6982 if (image_info->size != (char *) NULL)
6983 image_info->size=DestroyString(image_info->size);
6984 break;
6985 }
6986 (void) CloneString(&image_info->size,argv[i+1]);
6987 break;
6988 }
6989 if (LocaleCompare("stroke",option+1) == 0)
6990 {
6991 if (*option == '+')
6992 {
6993 (void) SetImageOption(image_info,option+1,"none");
6994 break;
6995 }
6996 (void) SetImageOption(image_info,option+1,argv[i+1]);
6997 break;
6998 }
6999 if (LocaleCompare("strokewidth",option+1) == 0)
7000 {
7001 if (*option == '+')
7002 {
7003 (void) SetImageOption(image_info,option+1,"0");
7004 break;
7005 }
7006 (void) SetImageOption(image_info,option+1,argv[i+1]);
7007 break;
7008 }
cristyd9a29192010-10-16 16:49:53 +00007009 if (LocaleCompare("synchronize",option+1) == 0)
7010 {
7011 if (*option == '+')
7012 {
7013 image_info->synchronize=MagickFalse;
7014 break;
7015 }
7016 image_info->synchronize=MagickTrue;
7017 break;
7018 }
cristy3ed852e2009-09-05 21:47:34 +00007019 break;
7020 }
7021 case 't':
7022 {
7023 if (LocaleCompare("taint",option+1) == 0)
7024 {
7025 if (*option == '+')
7026 {
7027 (void) SetImageOption(image_info,option+1,"false");
7028 break;
7029 }
7030 (void) SetImageOption(image_info,option+1,"true");
7031 break;
7032 }
7033 if (LocaleCompare("texture",option+1) == 0)
7034 {
7035 if (*option == '+')
7036 {
7037 if (image_info->texture != (char *) NULL)
7038 image_info->texture=DestroyString(image_info->texture);
7039 break;
7040 }
7041 (void) CloneString(&image_info->texture,argv[i+1]);
7042 break;
7043 }
7044 if (LocaleCompare("tile-offset",option+1) == 0)
7045 {
7046 if (*option == '+')
7047 {
7048 (void) SetImageOption(image_info,option+1,"0");
7049 break;
7050 }
7051 (void) SetImageOption(image_info,option+1,argv[i+1]);
7052 break;
7053 }
7054 if (LocaleCompare("transparent-color",option+1) == 0)
7055 {
7056 if (*option == '+')
7057 {
7058 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7059 (void) SetImageOption(image_info,option+1,"none");
7060 break;
7061 }
7062 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7063 exception);
7064 (void) SetImageOption(image_info,option+1,argv[i+1]);
7065 break;
7066 }
7067 if (LocaleCompare("type",option+1) == 0)
7068 {
7069 if (*option == '+')
7070 {
cristy5f1c1ff2010-12-23 21:38:06 +00007071 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007072 (void) SetImageOption(image_info,option+1,"undefined");
7073 break;
7074 }
cristy042ee782011-04-22 18:48:30 +00007075 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007076 MagickFalse,argv[i+1]);
7077 (void) SetImageOption(image_info,option+1,argv[i+1]);
7078 break;
7079 }
7080 break;
7081 }
7082 case 'u':
7083 {
7084 if (LocaleCompare("undercolor",option+1) == 0)
7085 {
7086 if (*option == '+')
7087 {
7088 (void) DeleteImageOption(image_info,option+1);
7089 break;
7090 }
7091 (void) SetImageOption(image_info,option+1,argv[i+1]);
7092 break;
7093 }
7094 if (LocaleCompare("units",option+1) == 0)
7095 {
7096 if (*option == '+')
7097 {
7098 image_info->units=UndefinedResolution;
7099 (void) SetImageOption(image_info,option+1,"undefined");
7100 break;
7101 }
cristy042ee782011-04-22 18:48:30 +00007102 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007103 MagickResolutionOptions,MagickFalse,argv[i+1]);
7104 (void) SetImageOption(image_info,option+1,argv[i+1]);
7105 break;
7106 }
7107 break;
7108 }
7109 case 'v':
7110 {
7111 if (LocaleCompare("verbose",option+1) == 0)
7112 {
7113 if (*option == '+')
7114 {
7115 image_info->verbose=MagickFalse;
7116 break;
7117 }
7118 image_info->verbose=MagickTrue;
7119 image_info->ping=MagickFalse;
7120 break;
7121 }
7122 if (LocaleCompare("view",option+1) == 0)
7123 {
7124 if (*option == '+')
7125 {
7126 if (image_info->view != (char *) NULL)
7127 image_info->view=DestroyString(image_info->view);
7128 break;
7129 }
7130 (void) CloneString(&image_info->view,argv[i+1]);
7131 break;
7132 }
7133 if (LocaleCompare("virtual-pixel",option+1) == 0)
7134 {
7135 if (*option == '+')
7136 {
7137 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7138 (void) SetImageOption(image_info,option+1,"undefined");
7139 break;
7140 }
7141 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007142 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007143 argv[i+1]);
7144 (void) SetImageOption(image_info,option+1,argv[i+1]);
7145 break;
7146 }
7147 break;
7148 }
7149 case 'w':
7150 {
7151 if (LocaleCompare("white-point",option+1) == 0)
7152 {
7153 if (*option == '+')
7154 {
7155 (void) SetImageOption(image_info,option+1,"0.0");
7156 break;
7157 }
7158 (void) SetImageOption(image_info,option+1,argv[i+1]);
7159 break;
7160 }
7161 break;
7162 }
7163 default:
7164 break;
7165 }
7166 i+=count;
7167 }
7168 return(MagickTrue);
7169}
7170
7171/*
7172%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7173% %
7174% %
7175% %
7176+ M o g r i f y I m a g e L i s t %
7177% %
7178% %
7179% %
7180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7181%
7182% MogrifyImageList() applies any command line options that might affect the
7183% entire image list (e.g. -append, -coalesce, etc.).
7184%
7185% The format of the MogrifyImage method is:
7186%
7187% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7188% const char **argv,Image **images,ExceptionInfo *exception)
7189%
7190% A description of each parameter follows:
7191%
7192% o image_info: the image info..
7193%
7194% o argc: Specifies a pointer to an integer describing the number of
7195% elements in the argument vector.
7196%
7197% o argv: Specifies a pointer to a text array containing the command line
7198% arguments.
7199%
anthonye9c27192011-03-27 08:07:06 +00007200% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007201%
7202% o exception: return any errors or warnings in this structure.
7203%
7204*/
7205WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7206 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7207{
cristy3ed852e2009-09-05 21:47:34 +00007208 const char
7209 *option;
7210
cristy6b3da3a2010-06-20 02:21:46 +00007211 ImageInfo
7212 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007213
7214 MagickStatusType
7215 status;
7216
7217 QuantizeInfo
7218 *quantize_info;
7219
cristybb503372010-05-27 20:51:26 +00007220 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007221 i;
7222
cristy6b3da3a2010-06-20 02:21:46 +00007223 ssize_t
7224 count,
7225 index;
7226
cristy3ed852e2009-09-05 21:47:34 +00007227 /*
7228 Apply options to the image list.
7229 */
7230 assert(image_info != (ImageInfo *) NULL);
7231 assert(image_info->signature == MagickSignature);
7232 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007233 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007234 assert((*images)->signature == MagickSignature);
7235 if ((*images)->debug != MagickFalse)
7236 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7237 (*images)->filename);
7238 if ((argc <= 0) || (*argv == (char *) NULL))
7239 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007240 mogrify_info=CloneImageInfo(image_info);
7241 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007242 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007243 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007244 {
cristy74fe8f12009-10-03 19:09:01 +00007245 if (*images == (Image *) NULL)
7246 break;
cristy3ed852e2009-09-05 21:47:34 +00007247 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007248 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007249 continue;
cristy042ee782011-04-22 18:48:30 +00007250 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007251 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007252 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007253 break;
cristy6b3da3a2010-06-20 02:21:46 +00007254 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007255 switch (*(option+1))
7256 {
7257 case 'a':
7258 {
7259 if (LocaleCompare("affinity",option+1) == 0)
7260 {
cristy6b3da3a2010-06-20 02:21:46 +00007261 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007262 if (*option == '+')
7263 {
7264 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7265 InheritException(exception,&(*images)->exception);
7266 break;
7267 }
7268 i++;
7269 break;
7270 }
7271 if (LocaleCompare("append",option+1) == 0)
7272 {
7273 Image
7274 *append_image;
7275
cristy6b3da3a2010-06-20 02:21:46 +00007276 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007277 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7278 MagickFalse,exception);
7279 if (append_image == (Image *) NULL)
7280 {
7281 status=MagickFalse;
7282 break;
7283 }
7284 *images=DestroyImageList(*images);
7285 *images=append_image;
7286 break;
7287 }
7288 if (LocaleCompare("average",option+1) == 0)
7289 {
7290 Image
7291 *average_image;
7292
cristyd18ae7c2010-03-07 17:39:52 +00007293 /*
7294 Average an image sequence (deprecated).
7295 */
cristy6b3da3a2010-06-20 02:21:46 +00007296 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007297 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7298 exception);
cristy3ed852e2009-09-05 21:47:34 +00007299 if (average_image == (Image *) NULL)
7300 {
7301 status=MagickFalse;
7302 break;
7303 }
7304 *images=DestroyImageList(*images);
7305 *images=average_image;
7306 break;
7307 }
7308 break;
7309 }
7310 case 'c':
7311 {
7312 if (LocaleCompare("channel",option+1) == 0)
7313 {
cristyf4ad9df2011-07-08 16:49:03 +00007314 ChannelType
7315 channel;
7316
cristy3ed852e2009-09-05 21:47:34 +00007317 if (*option == '+')
7318 {
7319 channel=DefaultChannels;
7320 break;
7321 }
7322 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007323 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007324 break;
7325 }
7326 if (LocaleCompare("clut",option+1) == 0)
7327 {
7328 Image
7329 *clut_image,
7330 *image;
7331
cristy6b3da3a2010-06-20 02:21:46 +00007332 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007333 image=RemoveFirstImageFromList(images);
7334 clut_image=RemoveFirstImageFromList(images);
7335 if (clut_image == (Image *) NULL)
7336 {
7337 status=MagickFalse;
7338 break;
7339 }
cristy444eda62011-08-10 02:07:46 +00007340 (void) ClutImage(image,clut_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007341 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007342 *images=DestroyImageList(*images);
7343 *images=image;
7344 break;
7345 }
7346 if (LocaleCompare("coalesce",option+1) == 0)
7347 {
7348 Image
7349 *coalesce_image;
7350
cristy6b3da3a2010-06-20 02:21:46 +00007351 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007352 coalesce_image=CoalesceImages(*images,exception);
7353 if (coalesce_image == (Image *) NULL)
7354 {
7355 status=MagickFalse;
7356 break;
7357 }
7358 *images=DestroyImageList(*images);
7359 *images=coalesce_image;
7360 break;
7361 }
7362 if (LocaleCompare("combine",option+1) == 0)
7363 {
7364 Image
7365 *combine_image;
7366
cristy6b3da3a2010-06-20 02:21:46 +00007367 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007368 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007369 if (combine_image == (Image *) NULL)
7370 {
7371 status=MagickFalse;
7372 break;
7373 }
7374 *images=DestroyImageList(*images);
7375 *images=combine_image;
7376 break;
7377 }
7378 if (LocaleCompare("composite",option+1) == 0)
7379 {
7380 Image
7381 *mask_image,
7382 *composite_image,
7383 *image;
7384
7385 RectangleInfo
7386 geometry;
7387
cristy6b3da3a2010-06-20 02:21:46 +00007388 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007389 image=RemoveFirstImageFromList(images);
7390 composite_image=RemoveFirstImageFromList(images);
7391 if (composite_image == (Image *) NULL)
7392 {
7393 status=MagickFalse;
7394 break;
7395 }
7396 (void) TransformImage(&composite_image,(char *) NULL,
7397 composite_image->geometry);
7398 SetGeometry(composite_image,&geometry);
7399 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7400 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7401 &geometry);
7402 mask_image=RemoveFirstImageFromList(images);
7403 if (mask_image != (Image *) NULL)
7404 {
7405 if ((image->compose == DisplaceCompositeOp) ||
7406 (image->compose == DistortCompositeOp))
7407 {
7408 /*
7409 Merge Y displacement into X displacement image.
7410 */
7411 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7412 mask_image,0,0);
7413 mask_image=DestroyImage(mask_image);
7414 }
7415 else
7416 {
7417 /*
7418 Set a blending mask for the composition.
7419 */
anthonya129f702011-04-14 01:08:48 +00007420 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007421 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007422 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007423 }
7424 }
cristyf4ad9df2011-07-08 16:49:03 +00007425 (void) CompositeImage(image,image->compose,composite_image,
7426 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007427 if (mask_image != (Image *) NULL)
7428 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007429 composite_image=DestroyImage(composite_image);
7430 InheritException(exception,&image->exception);
7431 *images=DestroyImageList(*images);
7432 *images=image;
7433 break;
7434 }
anthony9f4f0342011-03-28 11:47:22 +00007435#if 0
7436This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007437 if (LocaleCompare("crop",option+1) == 0)
7438 {
7439 MagickStatusType
7440 flags;
7441
7442 RectangleInfo
7443 geometry;
7444
anthonye9c27192011-03-27 08:07:06 +00007445 /*
anthony9f4f0342011-03-28 11:47:22 +00007446 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007447 */
cristy6b3da3a2010-06-20 02:21:46 +00007448 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007449 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7450 if (((geometry.width == 0) && (geometry.height == 0)) ||
7451 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7452 break;
7453 (void) TransformImages(images,argv[i+1],(char *) NULL);
7454 InheritException(exception,&(*images)->exception);
7455 break;
7456 }
anthony9f4f0342011-03-28 11:47:22 +00007457#endif
cristy3ed852e2009-09-05 21:47:34 +00007458 break;
7459 }
7460 case 'd':
7461 {
7462 if (LocaleCompare("deconstruct",option+1) == 0)
7463 {
7464 Image
7465 *deconstruct_image;
7466
cristy6b3da3a2010-06-20 02:21:46 +00007467 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007468 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007469 exception);
cristy3ed852e2009-09-05 21:47:34 +00007470 if (deconstruct_image == (Image *) NULL)
7471 {
7472 status=MagickFalse;
7473 break;
7474 }
7475 *images=DestroyImageList(*images);
7476 *images=deconstruct_image;
7477 break;
7478 }
7479 if (LocaleCompare("delete",option+1) == 0)
7480 {
7481 if (*option == '+')
7482 DeleteImages(images,"-1",exception);
7483 else
7484 DeleteImages(images,argv[i+1],exception);
7485 break;
7486 }
7487 if (LocaleCompare("dither",option+1) == 0)
7488 {
7489 if (*option == '+')
7490 {
7491 quantize_info->dither=MagickFalse;
7492 break;
7493 }
7494 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007495 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007496 MagickDitherOptions,MagickFalse,argv[i+1]);
7497 break;
7498 }
cristyecb10ff2011-03-22 13:14:03 +00007499 if (LocaleCompare("duplicate",option+1) == 0)
7500 {
cristy72988482011-03-29 16:34:38 +00007501 Image
7502 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007503
anthony2b6bcae2011-03-23 13:05:34 +00007504 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007505 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7506 else
7507 {
7508 const char
7509 *p;
7510
anthony2b6bcae2011-03-23 13:05:34 +00007511 size_t
7512 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007513
anthony2b6bcae2011-03-23 13:05:34 +00007514 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007515 p=strchr(argv[i+1],',');
7516 if (p == (const char *) NULL)
7517 duplicate_images=DuplicateImages(*images,number_duplicates,
7518 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007519 else
cristy72988482011-03-29 16:34:38 +00007520 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7521 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007522 }
7523 AppendImageToList(images, duplicate_images);
7524 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007525 break;
7526 }
cristy3ed852e2009-09-05 21:47:34 +00007527 break;
7528 }
cristyd18ae7c2010-03-07 17:39:52 +00007529 case 'e':
7530 {
7531 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7532 {
7533 Image
7534 *evaluate_image;
7535
7536 MagickEvaluateOperator
7537 op;
7538
cristy6b3da3a2010-06-20 02:21:46 +00007539 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007540 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007541 MagickFalse,argv[i+1]);
7542 evaluate_image=EvaluateImages(*images,op,exception);
7543 if (evaluate_image == (Image *) NULL)
7544 {
7545 status=MagickFalse;
7546 break;
7547 }
7548 *images=DestroyImageList(*images);
7549 *images=evaluate_image;
7550 break;
7551 }
7552 break;
7553 }
cristy3ed852e2009-09-05 21:47:34 +00007554 case 'f':
7555 {
cristyf0a247f2009-10-04 00:20:03 +00007556 if (LocaleCompare("fft",option+1) == 0)
7557 {
7558 Image
7559 *fourier_image;
7560
7561 /*
7562 Implements the discrete Fourier transform (DFT).
7563 */
cristy6b3da3a2010-06-20 02:21:46 +00007564 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007565 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7566 MagickTrue : MagickFalse,exception);
7567 if (fourier_image == (Image *) NULL)
7568 break;
7569 *images=DestroyImage(*images);
7570 *images=fourier_image;
7571 break;
7572 }
cristy3ed852e2009-09-05 21:47:34 +00007573 if (LocaleCompare("flatten",option+1) == 0)
7574 {
7575 Image
7576 *flatten_image;
7577
cristy6b3da3a2010-06-20 02:21:46 +00007578 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007579 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7580 if (flatten_image == (Image *) NULL)
7581 break;
7582 *images=DestroyImageList(*images);
7583 *images=flatten_image;
7584 break;
7585 }
7586 if (LocaleCompare("fx",option+1) == 0)
7587 {
7588 Image
7589 *fx_image;
7590
cristy6b3da3a2010-06-20 02:21:46 +00007591 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007592 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007593 if (fx_image == (Image *) NULL)
7594 {
7595 status=MagickFalse;
7596 break;
7597 }
7598 *images=DestroyImageList(*images);
7599 *images=fx_image;
7600 break;
7601 }
7602 break;
7603 }
7604 case 'h':
7605 {
7606 if (LocaleCompare("hald-clut",option+1) == 0)
7607 {
7608 Image
7609 *hald_image,
7610 *image;
7611
cristy6b3da3a2010-06-20 02:21:46 +00007612 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007613 image=RemoveFirstImageFromList(images);
7614 hald_image=RemoveFirstImageFromList(images);
7615 if (hald_image == (Image *) NULL)
7616 {
7617 status=MagickFalse;
7618 break;
7619 }
cristy7c0a0a42011-08-23 17:57:25 +00007620 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007621 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007622 if (*images != (Image *) NULL)
7623 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007624 *images=image;
7625 break;
7626 }
7627 break;
7628 }
7629 case 'i':
7630 {
7631 if (LocaleCompare("ift",option+1) == 0)
7632 {
7633 Image
cristy8587f882009-11-13 20:28:49 +00007634 *fourier_image,
7635 *magnitude_image,
7636 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007637
7638 /*
7639 Implements the inverse fourier discrete Fourier transform (DFT).
7640 */
cristy6b3da3a2010-06-20 02:21:46 +00007641 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007642 magnitude_image=RemoveFirstImageFromList(images);
7643 phase_image=RemoveFirstImageFromList(images);
7644 if (phase_image == (Image *) NULL)
7645 {
7646 status=MagickFalse;
7647 break;
7648 }
7649 fourier_image=InverseFourierTransformImage(magnitude_image,
7650 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007651 if (fourier_image == (Image *) NULL)
7652 break;
cristy0aff6ea2009-11-14 01:40:53 +00007653 if (*images != (Image *) NULL)
7654 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007655 *images=fourier_image;
7656 break;
7657 }
7658 if (LocaleCompare("insert",option+1) == 0)
7659 {
7660 Image
7661 *p,
7662 *q;
7663
7664 index=0;
7665 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007666 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007667 p=RemoveLastImageFromList(images);
7668 if (p == (Image *) NULL)
7669 {
7670 (void) ThrowMagickException(exception,GetMagickModule(),
7671 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7672 status=MagickFalse;
7673 break;
7674 }
7675 q=p;
7676 if (index == 0)
7677 PrependImageToList(images,q);
7678 else
cristybb503372010-05-27 20:51:26 +00007679 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007680 AppendImageToList(images,q);
7681 else
7682 {
7683 q=GetImageFromList(*images,index-1);
7684 if (q == (Image *) NULL)
7685 {
7686 (void) ThrowMagickException(exception,GetMagickModule(),
7687 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7688 status=MagickFalse;
7689 break;
7690 }
7691 InsertImageInList(&q,p);
7692 }
7693 *images=GetFirstImageInList(q);
7694 break;
7695 }
7696 break;
7697 }
7698 case 'l':
7699 {
7700 if (LocaleCompare("layers",option+1) == 0)
7701 {
7702 Image
7703 *layers;
7704
7705 ImageLayerMethod
7706 method;
7707
cristy6b3da3a2010-06-20 02:21:46 +00007708 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007709 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007710 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007711 MagickFalse,argv[i+1]);
7712 switch (method)
7713 {
7714 case CoalesceLayer:
7715 {
7716 layers=CoalesceImages(*images,exception);
7717 break;
7718 }
7719 case CompareAnyLayer:
7720 case CompareClearLayer:
7721 case CompareOverlayLayer:
7722 default:
7723 {
cristy8a9106f2011-07-05 14:39:26 +00007724 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007725 break;
7726 }
7727 case MergeLayer:
7728 case FlattenLayer:
7729 case MosaicLayer:
7730 case TrimBoundsLayer:
7731 {
7732 layers=MergeImageLayers(*images,method,exception);
7733 break;
7734 }
7735 case DisposeLayer:
7736 {
7737 layers=DisposeImages(*images,exception);
7738 break;
7739 }
7740 case OptimizeImageLayer:
7741 {
7742 layers=OptimizeImageLayers(*images,exception);
7743 break;
7744 }
7745 case OptimizePlusLayer:
7746 {
7747 layers=OptimizePlusImageLayers(*images,exception);
7748 break;
7749 }
7750 case OptimizeTransLayer:
7751 {
7752 OptimizeImageTransparency(*images,exception);
7753 break;
7754 }
7755 case RemoveDupsLayer:
7756 {
7757 RemoveDuplicateLayers(images,exception);
7758 break;
7759 }
7760 case RemoveZeroLayer:
7761 {
7762 RemoveZeroDelayLayers(images,exception);
7763 break;
7764 }
7765 case OptimizeLayer:
7766 {
7767 /*
7768 General Purpose, GIF Animation Optimizer.
7769 */
7770 layers=CoalesceImages(*images,exception);
7771 if (layers == (Image *) NULL)
7772 {
7773 status=MagickFalse;
7774 break;
7775 }
7776 InheritException(exception,&layers->exception);
7777 *images=DestroyImageList(*images);
7778 *images=layers;
7779 layers=OptimizeImageLayers(*images,exception);
7780 if (layers == (Image *) NULL)
7781 {
7782 status=MagickFalse;
7783 break;
7784 }
7785 InheritException(exception,&layers->exception);
7786 *images=DestroyImageList(*images);
7787 *images=layers;
7788 layers=(Image *) NULL;
7789 OptimizeImageTransparency(*images,exception);
7790 InheritException(exception,&(*images)->exception);
7791 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7792 break;
7793 }
7794 case CompositeLayer:
7795 {
7796 CompositeOperator
7797 compose;
7798
7799 Image
7800 *source;
7801
7802 RectangleInfo
7803 geometry;
7804
7805 /*
7806 Split image sequence at the first 'NULL:' image.
7807 */
7808 source=(*images);
7809 while (source != (Image *) NULL)
7810 {
7811 source=GetNextImageInList(source);
7812 if ((source != (Image *) NULL) &&
7813 (LocaleCompare(source->magick,"NULL") == 0))
7814 break;
7815 }
7816 if (source != (Image *) NULL)
7817 {
7818 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7819 (GetNextImageInList(source) == (Image *) NULL))
7820 source=(Image *) NULL;
7821 else
7822 {
7823 /*
7824 Separate the two lists, junk the null: image.
7825 */
7826 source=SplitImageList(source->previous);
7827 DeleteImageFromList(&source);
7828 }
7829 }
7830 if (source == (Image *) NULL)
7831 {
7832 (void) ThrowMagickException(exception,GetMagickModule(),
7833 OptionError,"MissingNullSeparator","layers Composite");
7834 status=MagickFalse;
7835 break;
7836 }
7837 /*
7838 Adjust offset with gravity and virtual canvas.
7839 */
7840 SetGeometry(*images,&geometry);
7841 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7842 geometry.width=source->page.width != 0 ?
7843 source->page.width : source->columns;
7844 geometry.height=source->page.height != 0 ?
7845 source->page.height : source->rows;
7846 GravityAdjustGeometry((*images)->page.width != 0 ?
7847 (*images)->page.width : (*images)->columns,
7848 (*images)->page.height != 0 ? (*images)->page.height :
7849 (*images)->rows,(*images)->gravity,&geometry);
7850 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007851 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007852 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007853 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007854 MagickComposeOptions,MagickFalse,option);
7855 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7856 exception);
7857 source=DestroyImageList(source);
7858 break;
7859 }
7860 }
7861 if (layers == (Image *) NULL)
7862 break;
7863 InheritException(exception,&layers->exception);
7864 *images=DestroyImageList(*images);
7865 *images=layers;
7866 break;
7867 }
7868 break;
7869 }
7870 case 'm':
7871 {
7872 if (LocaleCompare("map",option+1) == 0)
7873 {
cristy6b3da3a2010-06-20 02:21:46 +00007874 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007875 if (*option == '+')
7876 {
7877 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7878 InheritException(exception,&(*images)->exception);
7879 break;
7880 }
7881 i++;
7882 break;
7883 }
cristyf40785b2010-03-06 02:27:27 +00007884 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007885 {
7886 Image
cristyf40785b2010-03-06 02:27:27 +00007887 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007888
cristyd18ae7c2010-03-07 17:39:52 +00007889 /*
7890 Maximum image sequence (deprecated).
7891 */
cristy6b3da3a2010-06-20 02:21:46 +00007892 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007893 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007894 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007895 {
7896 status=MagickFalse;
7897 break;
7898 }
7899 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007900 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007901 break;
7902 }
cristyf40785b2010-03-06 02:27:27 +00007903 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007904 {
7905 Image
cristyf40785b2010-03-06 02:27:27 +00007906 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007907
cristyd18ae7c2010-03-07 17:39:52 +00007908 /*
7909 Minimum image sequence (deprecated).
7910 */
cristy6b3da3a2010-06-20 02:21:46 +00007911 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007912 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007913 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007914 {
7915 status=MagickFalse;
7916 break;
7917 }
7918 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007919 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007920 break;
7921 }
cristy3ed852e2009-09-05 21:47:34 +00007922 if (LocaleCompare("morph",option+1) == 0)
7923 {
7924 Image
7925 *morph_image;
7926
cristy6b3da3a2010-06-20 02:21:46 +00007927 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007928 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007929 exception);
7930 if (morph_image == (Image *) NULL)
7931 {
7932 status=MagickFalse;
7933 break;
7934 }
7935 *images=DestroyImageList(*images);
7936 *images=morph_image;
7937 break;
7938 }
7939 if (LocaleCompare("mosaic",option+1) == 0)
7940 {
7941 Image
7942 *mosaic_image;
7943
cristy6b3da3a2010-06-20 02:21:46 +00007944 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007945 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7946 if (mosaic_image == (Image *) NULL)
7947 {
7948 status=MagickFalse;
7949 break;
7950 }
7951 *images=DestroyImageList(*images);
7952 *images=mosaic_image;
7953 break;
7954 }
7955 break;
7956 }
7957 case 'p':
7958 {
7959 if (LocaleCompare("print",option+1) == 0)
7960 {
7961 char
7962 *string;
7963
cristy6b3da3a2010-06-20 02:21:46 +00007964 (void) SyncImagesSettings(mogrify_info,*images);
7965 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007966 if (string == (char *) NULL)
7967 break;
7968 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007969 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007970 string=DestroyString(string);
7971 }
7972 if (LocaleCompare("process",option+1) == 0)
7973 {
7974 char
7975 **arguments;
7976
7977 int
7978 j,
7979 number_arguments;
7980
cristy6b3da3a2010-06-20 02:21:46 +00007981 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007982 arguments=StringToArgv(argv[i+1],&number_arguments);
7983 if (arguments == (char **) NULL)
7984 break;
7985 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7986 {
7987 char
7988 breaker,
7989 quote,
7990 *token;
7991
7992 const char
7993 *arguments;
7994
7995 int
7996 next,
7997 status;
7998
7999 size_t
8000 length;
8001
8002 TokenInfo
8003 *token_info;
8004
8005 /*
8006 Support old style syntax, filter="-option arg".
8007 */
8008 length=strlen(argv[i+1]);
8009 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008010 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008011 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8012 sizeof(*token));
8013 if (token == (char *) NULL)
8014 break;
8015 next=0;
8016 arguments=argv[i+1];
8017 token_info=AcquireTokenInfo();
8018 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8019 "\"",'\0',&breaker,&next,&quote);
8020 token_info=DestroyTokenInfo(token_info);
8021 if (status == 0)
8022 {
8023 const char
8024 *argv;
8025
8026 argv=(&(arguments[next]));
8027 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8028 exception);
8029 }
8030 token=DestroyString(token);
8031 break;
8032 }
cristy91c0da22010-05-02 01:44:07 +00008033 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008034 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8035 number_arguments-2,(const char **) arguments+2,exception);
8036 for (j=0; j < number_arguments; j++)
8037 arguments[j]=DestroyString(arguments[j]);
8038 arguments=(char **) RelinquishMagickMemory(arguments);
8039 break;
8040 }
8041 break;
8042 }
8043 case 'r':
8044 {
8045 if (LocaleCompare("reverse",option+1) == 0)
8046 {
8047 ReverseImageList(images);
8048 InheritException(exception,&(*images)->exception);
8049 break;
8050 }
8051 break;
8052 }
8053 case 's':
8054 {
cristy4285d782011-02-09 20:12:28 +00008055 if (LocaleCompare("smush",option+1) == 0)
8056 {
8057 Image
8058 *smush_image;
8059
8060 ssize_t
8061 offset;
8062
8063 (void) SyncImagesSettings(mogrify_info,*images);
8064 offset=(ssize_t) StringToLong(argv[i+1]);
8065 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8066 MagickFalse,offset,exception);
8067 if (smush_image == (Image *) NULL)
8068 {
8069 status=MagickFalse;
8070 break;
8071 }
8072 *images=DestroyImageList(*images);
8073 *images=smush_image;
8074 break;
8075 }
cristy3ed852e2009-09-05 21:47:34 +00008076 if (LocaleCompare("swap",option+1) == 0)
8077 {
8078 Image
8079 *p,
8080 *q,
8081 *swap;
8082
cristybb503372010-05-27 20:51:26 +00008083 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008084 swap_index;
8085
8086 index=(-1);
8087 swap_index=(-2);
8088 if (*option != '+')
8089 {
8090 GeometryInfo
8091 geometry_info;
8092
8093 MagickStatusType
8094 flags;
8095
8096 swap_index=(-1);
8097 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008098 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008099 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008100 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008101 }
8102 p=GetImageFromList(*images,index);
8103 q=GetImageFromList(*images,swap_index);
8104 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8105 {
8106 (void) ThrowMagickException(exception,GetMagickModule(),
8107 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8108 status=MagickFalse;
8109 break;
8110 }
8111 if (p == q)
8112 break;
8113 swap=CloneImage(p,0,0,MagickTrue,exception);
8114 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8115 ReplaceImageInList(&q,swap);
8116 *images=GetFirstImageInList(q);
8117 break;
8118 }
8119 break;
8120 }
8121 case 'w':
8122 {
8123 if (LocaleCompare("write",option+1) == 0)
8124 {
cristy071dd7b2010-04-09 13:04:54 +00008125 char
cristy06609ee2010-03-17 20:21:27 +00008126 key[MaxTextExtent];
8127
cristy3ed852e2009-09-05 21:47:34 +00008128 Image
8129 *write_images;
8130
8131 ImageInfo
8132 *write_info;
8133
cristy6b3da3a2010-06-20 02:21:46 +00008134 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008135 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008136 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008137 write_images=(*images);
8138 if (*option == '+')
8139 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008140 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008141 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8142 write_info=DestroyImageInfo(write_info);
8143 if (*option == '+')
8144 write_images=DestroyImageList(write_images);
8145 break;
8146 }
8147 break;
8148 }
8149 default:
8150 break;
8151 }
8152 i+=count;
8153 }
8154 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008155 mogrify_info=DestroyImageInfo(mogrify_info);
8156 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008157 return(status != 0 ? MagickTrue : MagickFalse);
8158}
8159
8160/*
8161%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8162% %
8163% %
8164% %
8165+ M o g r i f y I m a g e s %
8166% %
8167% %
8168% %
8169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8170%
8171% MogrifyImages() applies image processing options to a sequence of images as
8172% prescribed by command line options.
8173%
8174% The format of the MogrifyImage method is:
8175%
8176% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8177% const MagickBooleanType post,const int argc,const char **argv,
8178% Image **images,Exceptioninfo *exception)
8179%
8180% A description of each parameter follows:
8181%
8182% o image_info: the image info..
8183%
8184% o post: If true, post process image list operators otherwise pre-process.
8185%
8186% o argc: Specifies a pointer to an integer describing the number of
8187% elements in the argument vector.
8188%
8189% o argv: Specifies a pointer to a text array containing the command line
8190% arguments.
8191%
anthonye9c27192011-03-27 08:07:06 +00008192% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008193%
8194% o exception: return any errors or warnings in this structure.
8195%
8196*/
8197WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8198 const MagickBooleanType post,const int argc,const char **argv,
8199 Image **images,ExceptionInfo *exception)
8200{
8201#define MogrifyImageTag "Mogrify/Image"
8202
anthonye9c27192011-03-27 08:07:06 +00008203 MagickStatusType
8204 status;
cristy3ed852e2009-09-05 21:47:34 +00008205
cristy0e9f9c12010-02-11 03:00:47 +00008206 MagickBooleanType
8207 proceed;
8208
anthonye9c27192011-03-27 08:07:06 +00008209 size_t
8210 n;
cristy3ed852e2009-09-05 21:47:34 +00008211
cristybb503372010-05-27 20:51:26 +00008212 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008213 i;
8214
cristy3ed852e2009-09-05 21:47:34 +00008215 assert(image_info != (ImageInfo *) NULL);
8216 assert(image_info->signature == MagickSignature);
8217 if (images == (Image **) NULL)
8218 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008219 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008220 assert((*images)->signature == MagickSignature);
8221 if ((*images)->debug != MagickFalse)
8222 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8223 (*images)->filename);
8224 if ((argc <= 0) || (*argv == (char *) NULL))
8225 return(MagickTrue);
8226 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8227 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008228 status=0;
anthonye9c27192011-03-27 08:07:06 +00008229
anthonyce2716b2011-04-22 09:51:34 +00008230#if 0
cristy1e604812011-05-19 18:07:50 +00008231 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8232 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008233#endif
8234
anthonye9c27192011-03-27 08:07:06 +00008235 /*
8236 Pre-process multi-image sequence operators
8237 */
cristy3ed852e2009-09-05 21:47:34 +00008238 if (post == MagickFalse)
8239 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008240 /*
8241 For each image, process simple single image operators
8242 */
8243 i=0;
8244 n=GetImageListLength(*images);
8245 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008246 {
anthonyce2716b2011-04-22 09:51:34 +00008247#if 0
cristy1e604812011-05-19 18:07:50 +00008248 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8249 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008250#endif
anthonye9c27192011-03-27 08:07:06 +00008251 status&=MogrifyImage(image_info,argc,argv,images,exception);
8252 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008253 if (proceed == MagickFalse)
8254 break;
anthonye9c27192011-03-27 08:07:06 +00008255 if ( (*images)->next == (Image *) NULL )
8256 break;
8257 *images=(*images)->next;
8258 i++;
cristy3ed852e2009-09-05 21:47:34 +00008259 }
anthonye9c27192011-03-27 08:07:06 +00008260 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008261#if 0
cristy1e604812011-05-19 18:07:50 +00008262 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8263 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008264#endif
anthonye9c27192011-03-27 08:07:06 +00008265
8266 /*
8267 Post-process, multi-image sequence operators
8268 */
8269 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008270 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008271 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008272 return(status != 0 ? MagickTrue : MagickFalse);
8273}