blob: d2dd3830f35e74f7d2965dd6c9b1e578a62000ce [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)));
792 (void) AnnotateImage(*image,draw_info);
793 InheritException(exception,&(*image)->exception);
794 break;
795 }
796 if (LocaleCompare("antialias",option+1) == 0)
797 {
798 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
799 MagickFalse;
800 draw_info->text_antialias=(*option == '-') ? MagickTrue :
801 MagickFalse;
802 break;
803 }
804 if (LocaleCompare("auto-gamma",option+1) == 0)
805 {
806 /*
807 Auto Adjust Gamma of image based on its mean
808 */
809 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000810 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000811 break;
812 }
813 if (LocaleCompare("auto-level",option+1) == 0)
814 {
815 /*
816 Perfectly Normalize (max/min stretch) the image
817 */
818 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000819 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000820 break;
821 }
822 if (LocaleCompare("auto-orient",option+1) == 0)
823 {
824 (void) SyncImageSettings(mogrify_info,*image);
825 switch ((*image)->orientation)
826 {
827 case TopRightOrientation:
828 {
829 mogrify_image=FlopImage(*image,exception);
830 break;
831 }
832 case BottomRightOrientation:
833 {
834 mogrify_image=RotateImage(*image,180.0,exception);
835 break;
836 }
837 case BottomLeftOrientation:
838 {
839 mogrify_image=FlipImage(*image,exception);
840 break;
841 }
842 case LeftTopOrientation:
843 {
844 mogrify_image=TransposeImage(*image,exception);
845 break;
846 }
847 case RightTopOrientation:
848 {
849 mogrify_image=RotateImage(*image,90.0,exception);
850 break;
851 }
852 case RightBottomOrientation:
853 {
854 mogrify_image=TransverseImage(*image,exception);
855 break;
856 }
857 case LeftBottomOrientation:
858 {
859 mogrify_image=RotateImage(*image,270.0,exception);
860 break;
861 }
862 default:
863 break;
864 }
865 if (mogrify_image != (Image *) NULL)
866 mogrify_image->orientation=TopLeftOrientation;
867 break;
868 }
869 break;
870 }
871 case 'b':
872 {
873 if (LocaleCompare("black-threshold",option+1) == 0)
874 {
875 /*
876 Black threshold image.
877 */
878 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000879 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000880 InheritException(exception,&(*image)->exception);
881 break;
882 }
883 if (LocaleCompare("blue-shift",option+1) == 0)
884 {
885 /*
886 Blue shift image.
887 */
888 (void) SyncImageSettings(mogrify_info,*image);
889 geometry_info.rho=1.5;
890 if (*option == '-')
891 flags=ParseGeometry(argv[i+1],&geometry_info);
892 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
893 break;
894 }
895 if (LocaleCompare("blur",option+1) == 0)
896 {
897 /*
898 Gaussian blur image.
899 */
900 (void) SyncImageSettings(mogrify_info,*image);
901 flags=ParseGeometry(argv[i+1],&geometry_info);
902 if ((flags & SigmaValue) == 0)
903 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000904 mogrify_image=BlurImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +0000905 geometry_info.sigma,exception);
906 break;
907 }
908 if (LocaleCompare("border",option+1) == 0)
909 {
910 /*
911 Surround image with a border of solid color.
912 */
913 (void) SyncImageSettings(mogrify_info,*image);
914 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
915 if ((flags & SigmaValue) == 0)
916 geometry.height=geometry.width;
917 mogrify_image=BorderImage(*image,&geometry,exception);
918 break;
919 }
920 if (LocaleCompare("bordercolor",option+1) == 0)
921 {
922 if (*option == '+')
923 {
cristy638895a2011-08-06 23:19:14 +0000924 (void) QueryColorDatabase(MogrifyBorderColor,&draw_info->border_color,
anthonydf8ebac2011-04-27 09:03:19 +0000925 exception);
926 break;
927 }
928 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
929 exception);
930 break;
931 }
932 if (LocaleCompare("box",option+1) == 0)
933 {
934 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
935 exception);
936 break;
937 }
938 if (LocaleCompare("brightness-contrast",option+1) == 0)
939 {
940 double
941 brightness,
942 contrast;
943
944 GeometryInfo
945 geometry_info;
946
947 MagickStatusType
948 flags;
949
950 /*
951 Brightness / contrast image.
952 */
953 (void) SyncImageSettings(mogrify_info,*image);
954 flags=ParseGeometry(argv[i+1],&geometry_info);
955 brightness=geometry_info.rho;
956 contrast=0.0;
957 if ((flags & SigmaValue) != 0)
958 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000959 (void) BrightnessContrastImage(*image,brightness,contrast,
960 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000961 InheritException(exception,&(*image)->exception);
962 break;
963 }
964 break;
965 }
966 case 'c':
967 {
968 if (LocaleCompare("cdl",option+1) == 0)
969 {
970 char
971 *color_correction_collection;
972
973 /*
974 Color correct with a color decision list.
975 */
976 (void) SyncImageSettings(mogrify_info,*image);
977 color_correction_collection=FileToString(argv[i+1],~0,exception);
978 if (color_correction_collection == (char *) NULL)
979 break;
cristy1bfa9f02011-08-11 02:35:43 +0000980 (void) ColorDecisionListImage(*image,color_correction_collection,
981 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000982 InheritException(exception,&(*image)->exception);
983 break;
984 }
985 if (LocaleCompare("channel",option+1) == 0)
986 {
987 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000988 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000989 else
cristyfa806a72011-07-04 02:06:13 +0000990 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +0000991 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000992 break;
993 }
994 if (LocaleCompare("charcoal",option+1) == 0)
995 {
996 /*
997 Charcoal image.
998 */
999 (void) SyncImageSettings(mogrify_info,*image);
1000 flags=ParseGeometry(argv[i+1],&geometry_info);
1001 if ((flags & SigmaValue) == 0)
1002 geometry_info.sigma=1.0;
1003 mogrify_image=CharcoalImage(*image,geometry_info.rho,
1004 geometry_info.sigma,exception);
1005 break;
1006 }
1007 if (LocaleCompare("chop",option+1) == 0)
1008 {
1009 /*
1010 Chop the image.
1011 */
1012 (void) SyncImageSettings(mogrify_info,*image);
1013 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1014 mogrify_image=ChopImage(*image,&geometry,exception);
1015 break;
1016 }
1017 if (LocaleCompare("clamp",option+1) == 0)
1018 {
1019 /*
1020 Clamp image.
1021 */
1022 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001023 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001024 InheritException(exception,&(*image)->exception);
1025 break;
1026 }
1027 if (LocaleCompare("clip",option+1) == 0)
1028 {
1029 (void) SyncImageSettings(mogrify_info,*image);
1030 if (*option == '+')
1031 {
1032 (void) SetImageClipMask(*image,(Image *) NULL);
1033 InheritException(exception,&(*image)->exception);
1034 break;
1035 }
1036 (void) ClipImage(*image);
1037 InheritException(exception,&(*image)->exception);
1038 break;
1039 }
1040 if (LocaleCompare("clip-mask",option+1) == 0)
1041 {
1042 CacheView
1043 *mask_view;
1044
1045 Image
1046 *mask_image;
1047
cristy4c08aed2011-07-01 19:47:50 +00001048 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001049 *restrict q;
1050
1051 register ssize_t
1052 x;
1053
1054 ssize_t
1055 y;
1056
1057 (void) SyncImageSettings(mogrify_info,*image);
1058 if (*option == '+')
1059 {
1060 /*
1061 Remove a mask.
1062 */
1063 (void) SetImageMask(*image,(Image *) NULL);
1064 InheritException(exception,&(*image)->exception);
1065 break;
1066 }
1067 /*
1068 Set the image mask.
1069 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1070 */
1071 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1072 if (mask_image == (Image *) NULL)
1073 break;
cristy574cc262011-08-05 01:23:58 +00001074 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001075 return(MagickFalse);
1076 mask_view=AcquireCacheView(mask_image);
1077 for (y=0; y < (ssize_t) mask_image->rows; y++)
1078 {
1079 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1080 exception);
cristy4c08aed2011-07-01 19:47:50 +00001081 if (q == (const Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001082 break;
1083 for (x=0; x < (ssize_t) mask_image->columns; x++)
1084 {
1085 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001086 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1087 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1088 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1089 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001090 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001091 }
1092 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1093 break;
1094 }
1095 mask_view=DestroyCacheView(mask_view);
1096 mask_image->matte=MagickTrue;
1097 (void) SetImageClipMask(*image,mask_image);
1098 mask_image=DestroyImage(mask_image);
1099 InheritException(exception,&(*image)->exception);
1100 break;
1101 }
1102 if (LocaleCompare("clip-path",option+1) == 0)
1103 {
1104 (void) SyncImageSettings(mogrify_info,*image);
1105 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1106 MagickFalse);
1107 InheritException(exception,&(*image)->exception);
1108 break;
1109 }
1110 if (LocaleCompare("colorize",option+1) == 0)
1111 {
1112 /*
1113 Colorize the image.
1114 */
1115 (void) SyncImageSettings(mogrify_info,*image);
1116 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1117 exception);
1118 break;
1119 }
1120 if (LocaleCompare("color-matrix",option+1) == 0)
1121 {
1122 KernelInfo
1123 *kernel;
1124
1125 (void) SyncImageSettings(mogrify_info,*image);
1126 kernel=AcquireKernelInfo(argv[i+1]);
1127 if (kernel == (KernelInfo *) NULL)
1128 break;
1129 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1130 kernel=DestroyKernelInfo(kernel);
1131 break;
1132 }
1133 if (LocaleCompare("colors",option+1) == 0)
1134 {
1135 /*
1136 Reduce the number of colors in the image.
1137 */
1138 (void) SyncImageSettings(mogrify_info,*image);
1139 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1140 if (quantize_info->number_colors == 0)
1141 break;
1142 if (((*image)->storage_class == DirectClass) ||
1143 (*image)->colors > quantize_info->number_colors)
1144 (void) QuantizeImage(quantize_info,*image);
1145 else
1146 (void) CompressImageColormap(*image);
1147 InheritException(exception,&(*image)->exception);
1148 break;
1149 }
1150 if (LocaleCompare("colorspace",option+1) == 0)
1151 {
1152 ColorspaceType
1153 colorspace;
1154
1155 (void) SyncImageSettings(mogrify_info,*image);
1156 if (*option == '+')
1157 {
1158 (void) TransformImageColorspace(*image,RGBColorspace);
1159 InheritException(exception,&(*image)->exception);
1160 break;
1161 }
1162 colorspace=(ColorspaceType) ParseCommandOption(
1163 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1164 (void) TransformImageColorspace(*image,colorspace);
1165 InheritException(exception,&(*image)->exception);
1166 break;
1167 }
1168 if (LocaleCompare("contrast",option+1) == 0)
1169 {
1170 (void) SyncImageSettings(mogrify_info,*image);
1171 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001172 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001173 break;
1174 }
1175 if (LocaleCompare("contrast-stretch",option+1) == 0)
1176 {
1177 double
1178 black_point,
1179 white_point;
1180
1181 MagickStatusType
1182 flags;
1183
1184 /*
1185 Contrast stretch image.
1186 */
1187 (void) SyncImageSettings(mogrify_info,*image);
1188 flags=ParseGeometry(argv[i+1],&geometry_info);
1189 black_point=geometry_info.rho;
1190 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1191 black_point;
1192 if ((flags & PercentValue) != 0)
1193 {
1194 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1195 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1196 }
1197 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1198 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001199 (void) ContrastStretchImage(*image,black_point,white_point,
1200 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001201 InheritException(exception,&(*image)->exception);
1202 break;
1203 }
1204 if (LocaleCompare("convolve",option+1) == 0)
1205 {
anthonydf8ebac2011-04-27 09:03:19 +00001206 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001207 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001208
anthonydf8ebac2011-04-27 09:03:19 +00001209 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001210 kernel_info=AcquireKernelInfo(argv[i+1]);
1211 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001212 break;
cristy0a922382011-07-16 15:30:34 +00001213 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001214 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001215 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001216 break;
1217 }
1218 if (LocaleCompare("crop",option+1) == 0)
1219 {
1220 /*
1221 Crop a image to a smaller size
1222 */
1223 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001224 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001225 break;
1226 }
1227 if (LocaleCompare("cycle",option+1) == 0)
1228 {
1229 /*
1230 Cycle an image colormap.
1231 */
1232 (void) SyncImageSettings(mogrify_info,*image);
1233 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1234 InheritException(exception,&(*image)->exception);
1235 break;
1236 }
1237 break;
1238 }
1239 case 'd':
1240 {
1241 if (LocaleCompare("decipher",option+1) == 0)
1242 {
1243 StringInfo
1244 *passkey;
1245
1246 /*
1247 Decipher pixels.
1248 */
1249 (void) SyncImageSettings(mogrify_info,*image);
1250 passkey=FileToStringInfo(argv[i+1],~0,exception);
1251 if (passkey != (StringInfo *) NULL)
1252 {
1253 (void) PasskeyDecipherImage(*image,passkey,exception);
1254 passkey=DestroyStringInfo(passkey);
1255 }
1256 break;
1257 }
1258 if (LocaleCompare("density",option+1) == 0)
1259 {
1260 /*
1261 Set image density.
1262 */
1263 (void) CloneString(&draw_info->density,argv[i+1]);
1264 break;
1265 }
1266 if (LocaleCompare("depth",option+1) == 0)
1267 {
1268 (void) SyncImageSettings(mogrify_info,*image);
1269 if (*option == '+')
1270 {
1271 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1272 break;
1273 }
1274 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1275 break;
1276 }
1277 if (LocaleCompare("deskew",option+1) == 0)
1278 {
1279 double
1280 threshold;
1281
1282 /*
1283 Straighten the image.
1284 */
1285 (void) SyncImageSettings(mogrify_info,*image);
1286 if (*option == '+')
1287 threshold=40.0*QuantumRange/100.0;
1288 else
1289 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1290 mogrify_image=DeskewImage(*image,threshold,exception);
1291 break;
1292 }
1293 if (LocaleCompare("despeckle",option+1) == 0)
1294 {
1295 /*
1296 Reduce the speckles within an image.
1297 */
1298 (void) SyncImageSettings(mogrify_info,*image);
1299 mogrify_image=DespeckleImage(*image,exception);
1300 break;
1301 }
1302 if (LocaleCompare("display",option+1) == 0)
1303 {
1304 (void) CloneString(&draw_info->server_name,argv[i+1]);
1305 break;
1306 }
1307 if (LocaleCompare("distort",option+1) == 0)
1308 {
1309 char
1310 *args,
1311 token[MaxTextExtent];
1312
1313 const char
1314 *p;
1315
1316 DistortImageMethod
1317 method;
1318
1319 double
1320 *arguments;
1321
1322 register ssize_t
1323 x;
1324
1325 size_t
1326 number_arguments;
1327
1328 /*
1329 Distort image.
1330 */
1331 (void) SyncImageSettings(mogrify_info,*image);
1332 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1333 MagickFalse,argv[i+1]);
1334 if ( method == ResizeDistortion )
1335 {
1336 /* Special Case - Argument is actually a resize geometry!
1337 ** Convert that to an appropriate distortion argument array.
1338 */
1339 double
1340 resize_args[2];
1341 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1342 exception);
1343 resize_args[0]=(double)geometry.width;
1344 resize_args[1]=(double)geometry.height;
1345 mogrify_image=DistortImage(*image,method,(size_t)2,
1346 resize_args,MagickTrue,exception);
1347 break;
1348 }
1349 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1350 InheritException(exception,&(*image)->exception);
1351 if (args == (char *) NULL)
1352 break;
1353 p=(char *) args;
1354 for (x=0; *p != '\0'; x++)
1355 {
1356 GetMagickToken(p,&p,token);
1357 if (*token == ',')
1358 GetMagickToken(p,&p,token);
1359 }
1360 number_arguments=(size_t) x;
1361 arguments=(double *) AcquireQuantumMemory(number_arguments,
1362 sizeof(*arguments));
1363 if (arguments == (double *) NULL)
1364 ThrowWandFatalException(ResourceLimitFatalError,
1365 "MemoryAllocationFailed",(*image)->filename);
1366 (void) ResetMagickMemory(arguments,0,number_arguments*
1367 sizeof(*arguments));
1368 p=(char *) args;
1369 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1370 {
1371 GetMagickToken(p,&p,token);
1372 if (*token == ',')
1373 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001374 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001375 }
1376 args=DestroyString(args);
1377 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1378 (*option == '+') ? MagickTrue : MagickFalse,exception);
1379 arguments=(double *) RelinquishMagickMemory(arguments);
1380 break;
1381 }
1382 if (LocaleCompare("dither",option+1) == 0)
1383 {
1384 if (*option == '+')
1385 {
1386 quantize_info->dither=MagickFalse;
1387 break;
1388 }
1389 quantize_info->dither=MagickTrue;
1390 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1391 MagickDitherOptions,MagickFalse,argv[i+1]);
1392 if (quantize_info->dither_method == NoDitherMethod)
1393 quantize_info->dither=MagickFalse;
1394 break;
1395 }
1396 if (LocaleCompare("draw",option+1) == 0)
1397 {
1398 /*
1399 Draw image.
1400 */
1401 (void) SyncImageSettings(mogrify_info,*image);
1402 (void) CloneString(&draw_info->primitive,argv[i+1]);
1403 (void) DrawImage(*image,draw_info);
1404 InheritException(exception,&(*image)->exception);
1405 break;
1406 }
1407 break;
1408 }
1409 case 'e':
1410 {
1411 if (LocaleCompare("edge",option+1) == 0)
1412 {
1413 /*
1414 Enhance edges in the image.
1415 */
1416 (void) SyncImageSettings(mogrify_info,*image);
1417 flags=ParseGeometry(argv[i+1],&geometry_info);
1418 if ((flags & SigmaValue) == 0)
1419 geometry_info.sigma=1.0;
1420 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1421 break;
1422 }
1423 if (LocaleCompare("emboss",option+1) == 0)
1424 {
1425 /*
1426 Gaussian embossen image.
1427 */
1428 (void) SyncImageSettings(mogrify_info,*image);
1429 flags=ParseGeometry(argv[i+1],&geometry_info);
1430 if ((flags & SigmaValue) == 0)
1431 geometry_info.sigma=1.0;
1432 mogrify_image=EmbossImage(*image,geometry_info.rho,
1433 geometry_info.sigma,exception);
1434 break;
1435 }
1436 if (LocaleCompare("encipher",option+1) == 0)
1437 {
1438 StringInfo
1439 *passkey;
1440
1441 /*
1442 Encipher pixels.
1443 */
1444 (void) SyncImageSettings(mogrify_info,*image);
1445 passkey=FileToStringInfo(argv[i+1],~0,exception);
1446 if (passkey != (StringInfo *) NULL)
1447 {
1448 (void) PasskeyEncipherImage(*image,passkey,exception);
1449 passkey=DestroyStringInfo(passkey);
1450 }
1451 break;
1452 }
1453 if (LocaleCompare("encoding",option+1) == 0)
1454 {
1455 (void) CloneString(&draw_info->encoding,argv[i+1]);
1456 break;
1457 }
1458 if (LocaleCompare("enhance",option+1) == 0)
1459 {
1460 /*
1461 Enhance image.
1462 */
1463 (void) SyncImageSettings(mogrify_info,*image);
1464 mogrify_image=EnhanceImage(*image,exception);
1465 break;
1466 }
1467 if (LocaleCompare("equalize",option+1) == 0)
1468 {
1469 /*
1470 Equalize image.
1471 */
1472 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001473 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001474 break;
1475 }
1476 if (LocaleCompare("evaluate",option+1) == 0)
1477 {
1478 double
1479 constant;
1480
1481 MagickEvaluateOperator
1482 op;
1483
1484 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001485 op=(MagickEvaluateOperator) ParseCommandOption(
1486 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001487 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001488 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001489 break;
1490 }
1491 if (LocaleCompare("extent",option+1) == 0)
1492 {
1493 /*
1494 Set the image extent.
1495 */
1496 (void) SyncImageSettings(mogrify_info,*image);
1497 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1498 if (geometry.width == 0)
1499 geometry.width=(*image)->columns;
1500 if (geometry.height == 0)
1501 geometry.height=(*image)->rows;
1502 mogrify_image=ExtentImage(*image,&geometry,exception);
1503 break;
1504 }
1505 break;
1506 }
1507 case 'f':
1508 {
1509 if (LocaleCompare("family",option+1) == 0)
1510 {
1511 if (*option == '+')
1512 {
1513 if (draw_info->family != (char *) NULL)
1514 draw_info->family=DestroyString(draw_info->family);
1515 break;
1516 }
1517 (void) CloneString(&draw_info->family,argv[i+1]);
1518 break;
1519 }
1520 if (LocaleCompare("features",option+1) == 0)
1521 {
1522 if (*option == '+')
1523 {
1524 (void) DeleteImageArtifact(*image,"identify:features");
1525 break;
1526 }
1527 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1528 break;
1529 }
1530 if (LocaleCompare("fill",option+1) == 0)
1531 {
1532 ExceptionInfo
1533 *sans;
1534
cristy4c08aed2011-07-01 19:47:50 +00001535 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001536 if (*option == '+')
1537 {
1538 (void) QueryMagickColor("none",&fill,exception);
1539 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1540 if (draw_info->fill_pattern != (Image *) NULL)
1541 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1542 break;
1543 }
1544 sans=AcquireExceptionInfo();
1545 (void) QueryMagickColor(argv[i+1],&fill,sans);
1546 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1547 sans=DestroyExceptionInfo(sans);
1548 if (status == MagickFalse)
1549 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1550 exception);
1551 break;
1552 }
1553 if (LocaleCompare("flip",option+1) == 0)
1554 {
1555 /*
1556 Flip image scanlines.
1557 */
1558 (void) SyncImageSettings(mogrify_info,*image);
1559 mogrify_image=FlipImage(*image,exception);
1560 break;
1561 }
anthonydf8ebac2011-04-27 09:03:19 +00001562 if (LocaleCompare("floodfill",option+1) == 0)
1563 {
cristy4c08aed2011-07-01 19:47:50 +00001564 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001565 target;
1566
1567 /*
1568 Floodfill image.
1569 */
1570 (void) SyncImageSettings(mogrify_info,*image);
1571 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1572 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001573 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001574 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001575 break;
1576 }
anthony3d2f4862011-05-01 13:48:16 +00001577 if (LocaleCompare("flop",option+1) == 0)
1578 {
1579 /*
1580 Flop image scanlines.
1581 */
1582 (void) SyncImageSettings(mogrify_info,*image);
1583 mogrify_image=FlopImage(*image,exception);
1584 break;
1585 }
anthonydf8ebac2011-04-27 09:03:19 +00001586 if (LocaleCompare("font",option+1) == 0)
1587 {
1588 if (*option == '+')
1589 {
1590 if (draw_info->font != (char *) NULL)
1591 draw_info->font=DestroyString(draw_info->font);
1592 break;
1593 }
1594 (void) CloneString(&draw_info->font,argv[i+1]);
1595 break;
1596 }
1597 if (LocaleCompare("format",option+1) == 0)
1598 {
1599 format=argv[i+1];
1600 break;
1601 }
1602 if (LocaleCompare("frame",option+1) == 0)
1603 {
1604 FrameInfo
1605 frame_info;
1606
1607 /*
1608 Surround image with an ornamental border.
1609 */
1610 (void) SyncImageSettings(mogrify_info,*image);
1611 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1612 frame_info.width=geometry.width;
1613 frame_info.height=geometry.height;
1614 if ((flags & HeightValue) == 0)
1615 frame_info.height=geometry.width;
1616 frame_info.outer_bevel=geometry.x;
1617 frame_info.inner_bevel=geometry.y;
1618 frame_info.x=(ssize_t) frame_info.width;
1619 frame_info.y=(ssize_t) frame_info.height;
1620 frame_info.width=(*image)->columns+2*frame_info.width;
1621 frame_info.height=(*image)->rows+2*frame_info.height;
1622 mogrify_image=FrameImage(*image,&frame_info,exception);
1623 break;
1624 }
1625 if (LocaleCompare("function",option+1) == 0)
1626 {
1627 char
1628 *arguments,
1629 token[MaxTextExtent];
1630
1631 const char
1632 *p;
1633
1634 double
1635 *parameters;
1636
1637 MagickFunction
1638 function;
1639
1640 register ssize_t
1641 x;
1642
1643 size_t
1644 number_parameters;
1645
1646 /*
1647 Function Modify Image Values
1648 */
1649 (void) SyncImageSettings(mogrify_info,*image);
1650 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1651 MagickFalse,argv[i+1]);
1652 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1653 InheritException(exception,&(*image)->exception);
1654 if (arguments == (char *) NULL)
1655 break;
1656 p=(char *) arguments;
1657 for (x=0; *p != '\0'; x++)
1658 {
1659 GetMagickToken(p,&p,token);
1660 if (*token == ',')
1661 GetMagickToken(p,&p,token);
1662 }
1663 number_parameters=(size_t) x;
1664 parameters=(double *) AcquireQuantumMemory(number_parameters,
1665 sizeof(*parameters));
1666 if (parameters == (double *) NULL)
1667 ThrowWandFatalException(ResourceLimitFatalError,
1668 "MemoryAllocationFailed",(*image)->filename);
1669 (void) ResetMagickMemory(parameters,0,number_parameters*
1670 sizeof(*parameters));
1671 p=(char *) arguments;
1672 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1673 {
1674 GetMagickToken(p,&p,token);
1675 if (*token == ',')
1676 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001677 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001678 }
1679 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001680 (void) FunctionImage(*image,function,number_parameters,parameters,
1681 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001682 parameters=(double *) RelinquishMagickMemory(parameters);
1683 break;
1684 }
1685 break;
1686 }
1687 case 'g':
1688 {
1689 if (LocaleCompare("gamma",option+1) == 0)
1690 {
1691 /*
1692 Gamma image.
1693 */
1694 (void) SyncImageSettings(mogrify_info,*image);
1695 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001696 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001697 else
cristyb3e7c6c2011-07-24 01:43:55 +00001698 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1699 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001700 break;
1701 }
1702 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1703 (LocaleCompare("gaussian",option+1) == 0))
1704 {
1705 /*
1706 Gaussian blur image.
1707 */
1708 (void) SyncImageSettings(mogrify_info,*image);
1709 flags=ParseGeometry(argv[i+1],&geometry_info);
1710 if ((flags & SigmaValue) == 0)
1711 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001712 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1713 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001714 break;
1715 }
1716 if (LocaleCompare("geometry",option+1) == 0)
1717 {
1718 /*
1719 Record Image offset, Resize last image.
1720 */
1721 (void) SyncImageSettings(mogrify_info,*image);
1722 if (*option == '+')
1723 {
1724 if ((*image)->geometry != (char *) NULL)
1725 (*image)->geometry=DestroyString((*image)->geometry);
1726 break;
1727 }
1728 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1729 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1730 (void) CloneString(&(*image)->geometry,argv[i+1]);
1731 else
1732 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1733 (*image)->filter,(*image)->blur,exception);
1734 break;
1735 }
1736 if (LocaleCompare("gravity",option+1) == 0)
1737 {
1738 if (*option == '+')
1739 {
1740 draw_info->gravity=UndefinedGravity;
1741 break;
1742 }
1743 draw_info->gravity=(GravityType) ParseCommandOption(
1744 MagickGravityOptions,MagickFalse,argv[i+1]);
1745 break;
1746 }
1747 break;
1748 }
1749 case 'h':
1750 {
1751 if (LocaleCompare("highlight-color",option+1) == 0)
1752 {
1753 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1754 break;
1755 }
1756 break;
1757 }
1758 case 'i':
1759 {
1760 if (LocaleCompare("identify",option+1) == 0)
1761 {
1762 char
1763 *text;
1764
1765 (void) SyncImageSettings(mogrify_info,*image);
1766 if (format == (char *) NULL)
1767 {
1768 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1769 InheritException(exception,&(*image)->exception);
1770 break;
1771 }
1772 text=InterpretImageProperties(mogrify_info,*image,format);
1773 InheritException(exception,&(*image)->exception);
1774 if (text == (char *) NULL)
1775 break;
1776 (void) fputs(text,stdout);
1777 (void) fputc('\n',stdout);
1778 text=DestroyString(text);
1779 break;
1780 }
1781 if (LocaleCompare("implode",option+1) == 0)
1782 {
1783 /*
1784 Implode image.
1785 */
1786 (void) SyncImageSettings(mogrify_info,*image);
1787 (void) ParseGeometry(argv[i+1],&geometry_info);
1788 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1789 break;
1790 }
1791 if (LocaleCompare("interline-spacing",option+1) == 0)
1792 {
1793 if (*option == '+')
1794 (void) ParseGeometry("0",&geometry_info);
1795 else
1796 (void) ParseGeometry(argv[i+1],&geometry_info);
1797 draw_info->interline_spacing=geometry_info.rho;
1798 break;
1799 }
1800 if (LocaleCompare("interword-spacing",option+1) == 0)
1801 {
1802 if (*option == '+')
1803 (void) ParseGeometry("0",&geometry_info);
1804 else
1805 (void) ParseGeometry(argv[i+1],&geometry_info);
1806 draw_info->interword_spacing=geometry_info.rho;
1807 break;
1808 }
1809 break;
1810 }
1811 case 'k':
1812 {
1813 if (LocaleCompare("kerning",option+1) == 0)
1814 {
1815 if (*option == '+')
1816 (void) ParseGeometry("0",&geometry_info);
1817 else
1818 (void) ParseGeometry(argv[i+1],&geometry_info);
1819 draw_info->kerning=geometry_info.rho;
1820 break;
1821 }
1822 break;
1823 }
1824 case 'l':
1825 {
1826 if (LocaleCompare("lat",option+1) == 0)
1827 {
1828 /*
1829 Local adaptive threshold image.
1830 */
1831 (void) SyncImageSettings(mogrify_info,*image);
1832 flags=ParseGeometry(argv[i+1],&geometry_info);
1833 if ((flags & PercentValue) != 0)
1834 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1835 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001836 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001837 geometry_info.xi,exception);
1838 break;
1839 }
1840 if (LocaleCompare("level",option+1) == 0)
1841 {
1842 MagickRealType
1843 black_point,
1844 gamma,
1845 white_point;
1846
1847 MagickStatusType
1848 flags;
1849
1850 /*
1851 Parse levels.
1852 */
1853 (void) SyncImageSettings(mogrify_info,*image);
1854 flags=ParseGeometry(argv[i+1],&geometry_info);
1855 black_point=geometry_info.rho;
1856 white_point=(MagickRealType) QuantumRange;
1857 if ((flags & SigmaValue) != 0)
1858 white_point=geometry_info.sigma;
1859 gamma=1.0;
1860 if ((flags & XiValue) != 0)
1861 gamma=geometry_info.xi;
1862 if ((flags & PercentValue) != 0)
1863 {
1864 black_point*=(MagickRealType) (QuantumRange/100.0);
1865 white_point*=(MagickRealType) (QuantumRange/100.0);
1866 }
1867 if ((flags & SigmaValue) == 0)
1868 white_point=(MagickRealType) QuantumRange-black_point;
1869 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001870 (void) LevelizeImage(*image,black_point,white_point,gamma,
1871 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001872 else
cristy01e9afd2011-08-10 17:38:41 +00001873 (void) LevelImage(*image,black_point,white_point,gamma,
1874 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001875 InheritException(exception,&(*image)->exception);
1876 break;
1877 }
1878 if (LocaleCompare("level-colors",option+1) == 0)
1879 {
1880 char
1881 token[MaxTextExtent];
1882
1883 const char
1884 *p;
1885
cristy4c08aed2011-07-01 19:47:50 +00001886 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001887 black_point,
1888 white_point;
1889
1890 p=(const char *) argv[i+1];
1891 GetMagickToken(p,&p,token); /* get black point color */
1892 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1893 (void) QueryMagickColor(token,&black_point,exception);
1894 else
1895 (void) QueryMagickColor("#000000",&black_point,exception);
1896 if (isalpha((int) token[0]) || (token[0] == '#'))
1897 GetMagickToken(p,&p,token);
1898 if (*token == '\0')
1899 white_point=black_point; /* set everything to that color */
1900 else
1901 {
1902 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1903 GetMagickToken(p,&p,token); /* Get white point color. */
1904 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1905 (void) QueryMagickColor(token,&white_point,exception);
1906 else
1907 (void) QueryMagickColor("#ffffff",&white_point,exception);
1908 }
cristy490408a2011-07-07 14:42:05 +00001909 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001910 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001911 break;
1912 }
1913 if (LocaleCompare("linear-stretch",option+1) == 0)
1914 {
1915 double
1916 black_point,
1917 white_point;
1918
1919 MagickStatusType
1920 flags;
1921
1922 (void) SyncImageSettings(mogrify_info,*image);
1923 flags=ParseGeometry(argv[i+1],&geometry_info);
1924 black_point=geometry_info.rho;
1925 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1926 if ((flags & SigmaValue) != 0)
1927 white_point=geometry_info.sigma;
1928 if ((flags & PercentValue) != 0)
1929 {
1930 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1931 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1932 }
1933 if ((flags & SigmaValue) == 0)
1934 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1935 black_point;
cristy33bd5152011-08-24 01:42:24 +00001936 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001937 InheritException(exception,&(*image)->exception);
1938 break;
1939 }
1940 if (LocaleCompare("linewidth",option+1) == 0)
1941 {
cristyc1acd842011-05-19 23:05:47 +00001942 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1943 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001944 break;
1945 }
1946 if (LocaleCompare("liquid-rescale",option+1) == 0)
1947 {
1948 /*
1949 Liquid rescale image.
1950 */
1951 (void) SyncImageSettings(mogrify_info,*image);
1952 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1953 if ((flags & XValue) == 0)
1954 geometry.x=1;
1955 if ((flags & YValue) == 0)
1956 geometry.y=0;
1957 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1958 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1959 break;
1960 }
1961 if (LocaleCompare("lowlight-color",option+1) == 0)
1962 {
1963 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1964 break;
1965 }
1966 break;
1967 }
1968 case 'm':
1969 {
1970 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001971 {
cristy3ed852e2009-09-05 21:47:34 +00001972 Image
anthonydf8ebac2011-04-27 09:03:19 +00001973 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001974
anthonydf8ebac2011-04-27 09:03:19 +00001975 /*
1976 Transform image colors to match this set of colors.
1977 */
1978 (void) SyncImageSettings(mogrify_info,*image);
1979 if (*option == '+')
1980 break;
1981 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1982 if (remap_image == (Image *) NULL)
1983 break;
1984 (void) RemapImage(quantize_info,*image,remap_image);
1985 InheritException(exception,&(*image)->exception);
1986 remap_image=DestroyImage(remap_image);
1987 break;
1988 }
1989 if (LocaleCompare("mask",option+1) == 0)
1990 {
1991 Image
1992 *mask;
1993
1994 (void) SyncImageSettings(mogrify_info,*image);
1995 if (*option == '+')
1996 {
1997 /*
1998 Remove a mask.
1999 */
2000 (void) SetImageMask(*image,(Image *) NULL);
2001 InheritException(exception,&(*image)->exception);
2002 break;
2003 }
2004 /*
2005 Set the image mask.
2006 */
2007 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2008 if (mask == (Image *) NULL)
2009 break;
2010 (void) SetImageMask(*image,mask);
2011 mask=DestroyImage(mask);
2012 InheritException(exception,&(*image)->exception);
2013 break;
2014 }
2015 if (LocaleCompare("matte",option+1) == 0)
2016 {
2017 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002018 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002019 break;
2020 }
2021 if (LocaleCompare("median",option+1) == 0)
2022 {
2023 /*
2024 Median filter image.
2025 */
2026 (void) SyncImageSettings(mogrify_info,*image);
2027 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002028 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2029 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002030 break;
2031 }
2032 if (LocaleCompare("mode",option+1) == 0)
2033 {
2034 /*
2035 Mode image.
2036 */
2037 (void) SyncImageSettings(mogrify_info,*image);
2038 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002039 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2040 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002041 break;
2042 }
2043 if (LocaleCompare("modulate",option+1) == 0)
2044 {
2045 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002046 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002047 break;
2048 }
2049 if (LocaleCompare("monitor",option+1) == 0)
2050 {
2051 if (*option == '+')
2052 {
2053 (void) SetImageProgressMonitor(*image,
2054 (MagickProgressMonitor) NULL,(void *) NULL);
2055 break;
2056 }
2057 (void) SetImageProgressMonitor(*image,MonitorProgress,
2058 (void *) NULL);
2059 break;
2060 }
2061 if (LocaleCompare("monochrome",option+1) == 0)
2062 {
2063 (void) SyncImageSettings(mogrify_info,*image);
2064 (void) SetImageType(*image,BilevelType);
2065 InheritException(exception,&(*image)->exception);
2066 break;
2067 }
2068 if (LocaleCompare("morphology",option+1) == 0)
2069 {
2070 char
2071 token[MaxTextExtent];
2072
2073 const char
2074 *p;
2075
2076 KernelInfo
2077 *kernel;
2078
2079 MorphologyMethod
2080 method;
2081
2082 ssize_t
2083 iterations;
2084
2085 /*
2086 Morphological Image Operation
2087 */
2088 (void) SyncImageSettings(mogrify_info,*image);
2089 p=argv[i+1];
2090 GetMagickToken(p,&p,token);
2091 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2092 MagickFalse,token);
2093 iterations=1L;
2094 GetMagickToken(p,&p,token);
2095 if ((*p == ':') || (*p == ','))
2096 GetMagickToken(p,&p,token);
2097 if ((*p != '\0'))
2098 iterations=(ssize_t) StringToLong(p);
2099 kernel=AcquireKernelInfo(argv[i+2]);
2100 if (kernel == (KernelInfo *) NULL)
2101 {
2102 (void) ThrowMagickException(exception,GetMagickModule(),
2103 OptionError,"UnabletoParseKernel","morphology");
2104 status=MagickFalse;
2105 break;
2106 }
cristyf4ad9df2011-07-08 16:49:03 +00002107 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2108 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002109 kernel=DestroyKernelInfo(kernel);
2110 break;
2111 }
2112 if (LocaleCompare("motion-blur",option+1) == 0)
2113 {
2114 /*
2115 Motion blur image.
2116 */
2117 (void) SyncImageSettings(mogrify_info,*image);
2118 flags=ParseGeometry(argv[i+1],&geometry_info);
2119 if ((flags & SigmaValue) == 0)
2120 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002121 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2122 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002123 break;
2124 }
2125 break;
2126 }
2127 case 'n':
2128 {
2129 if (LocaleCompare("negate",option+1) == 0)
2130 {
2131 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002132 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002133 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002134 break;
2135 }
2136 if (LocaleCompare("noise",option+1) == 0)
2137 {
2138 (void) SyncImageSettings(mogrify_info,*image);
2139 if (*option == '-')
2140 {
2141 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002142 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2143 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002144 }
2145 else
2146 {
2147 NoiseType
2148 noise;
2149
2150 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2151 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002152 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002153 }
2154 break;
2155 }
2156 if (LocaleCompare("normalize",option+1) == 0)
2157 {
2158 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002159 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002160 break;
2161 }
2162 break;
2163 }
2164 case 'o':
2165 {
2166 if (LocaleCompare("opaque",option+1) == 0)
2167 {
cristy4c08aed2011-07-01 19:47:50 +00002168 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002169 target;
2170
2171 (void) SyncImageSettings(mogrify_info,*image);
2172 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002173 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002174 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002175 break;
2176 }
2177 if (LocaleCompare("ordered-dither",option+1) == 0)
2178 {
2179 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002180 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002181 break;
2182 }
2183 break;
2184 }
2185 case 'p':
2186 {
2187 if (LocaleCompare("paint",option+1) == 0)
2188 {
anthonydf8ebac2011-04-27 09:03:19 +00002189 (void) SyncImageSettings(mogrify_info,*image);
2190 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002191 mogrify_image=OilPaintImage(*image,geometry_info.rho,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 :
2369 MagickFalse);
2370 InheritException(exception,&(*image)->exception);
2371 break;
2372 }
2373 if (LocaleCompare("random-threshold",option+1) == 0)
2374 {
2375 /*
2376 Threshold image.
2377 */
2378 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002379 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002380 break;
2381 }
2382 if (LocaleCompare("recolor",option+1) == 0)
2383 {
2384 KernelInfo
2385 *kernel;
2386
2387 (void) SyncImageSettings(mogrify_info,*image);
2388 kernel=AcquireKernelInfo(argv[i+1]);
2389 if (kernel == (KernelInfo *) NULL)
2390 break;
2391 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2392 kernel=DestroyKernelInfo(kernel);
2393 break;
2394 }
2395 if (LocaleCompare("region",option+1) == 0)
2396 {
2397 (void) SyncImageSettings(mogrify_info,*image);
2398 if (region_image != (Image *) NULL)
2399 {
2400 /*
2401 Composite region.
2402 */
2403 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002404 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2405 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002406 InheritException(exception,&region_image->exception);
2407 *image=DestroyImage(*image);
2408 *image=region_image;
2409 region_image = (Image *) NULL;
2410 }
2411 if (*option == '+')
2412 break;
2413 /*
2414 Apply transformations to a selected region of the image.
2415 */
cristy3ed852e2009-09-05 21:47:34 +00002416 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2417 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002418 mogrify_image=CropImage(*image,&region_geometry,exception);
2419 if (mogrify_image == (Image *) NULL)
2420 break;
2421 region_image=(*image);
2422 *image=mogrify_image;
2423 mogrify_image=(Image *) NULL;
2424 break;
cristy3ed852e2009-09-05 21:47:34 +00002425 }
anthonydf8ebac2011-04-27 09:03:19 +00002426 if (LocaleCompare("render",option+1) == 0)
2427 {
2428 (void) SyncImageSettings(mogrify_info,*image);
2429 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2430 break;
2431 }
2432 if (LocaleCompare("remap",option+1) == 0)
2433 {
2434 Image
2435 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002436
anthonydf8ebac2011-04-27 09:03:19 +00002437 /*
2438 Transform image colors to match this set of colors.
2439 */
2440 (void) SyncImageSettings(mogrify_info,*image);
2441 if (*option == '+')
2442 break;
2443 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2444 if (remap_image == (Image *) NULL)
2445 break;
2446 (void) RemapImage(quantize_info,*image,remap_image);
2447 InheritException(exception,&(*image)->exception);
2448 remap_image=DestroyImage(remap_image);
2449 break;
2450 }
2451 if (LocaleCompare("repage",option+1) == 0)
2452 {
2453 if (*option == '+')
2454 {
2455 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2456 break;
2457 }
2458 (void) ResetImagePage(*image,argv[i+1]);
2459 InheritException(exception,&(*image)->exception);
2460 break;
2461 }
2462 if (LocaleCompare("resample",option+1) == 0)
2463 {
2464 /*
2465 Resample image.
2466 */
2467 (void) SyncImageSettings(mogrify_info,*image);
2468 flags=ParseGeometry(argv[i+1],&geometry_info);
2469 if ((flags & SigmaValue) == 0)
2470 geometry_info.sigma=geometry_info.rho;
2471 mogrify_image=ResampleImage(*image,geometry_info.rho,
2472 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2473 break;
2474 }
2475 if (LocaleCompare("resize",option+1) == 0)
2476 {
2477 /*
2478 Resize image.
2479 */
2480 (void) SyncImageSettings(mogrify_info,*image);
2481 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2482 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2483 (*image)->filter,(*image)->blur,exception);
2484 break;
2485 }
2486 if (LocaleCompare("roll",option+1) == 0)
2487 {
2488 /*
2489 Roll image.
2490 */
2491 (void) SyncImageSettings(mogrify_info,*image);
2492 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2493 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2494 break;
2495 }
2496 if (LocaleCompare("rotate",option+1) == 0)
2497 {
2498 char
2499 *geometry;
2500
2501 /*
2502 Check for conditional image rotation.
2503 */
2504 (void) SyncImageSettings(mogrify_info,*image);
2505 if (strchr(argv[i+1],'>') != (char *) NULL)
2506 if ((*image)->columns <= (*image)->rows)
2507 break;
2508 if (strchr(argv[i+1],'<') != (char *) NULL)
2509 if ((*image)->columns >= (*image)->rows)
2510 break;
2511 /*
2512 Rotate image.
2513 */
2514 geometry=ConstantString(argv[i+1]);
2515 (void) SubstituteString(&geometry,">","");
2516 (void) SubstituteString(&geometry,"<","");
2517 (void) ParseGeometry(geometry,&geometry_info);
2518 geometry=DestroyString(geometry);
2519 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2520 break;
2521 }
2522 break;
2523 }
2524 case 's':
2525 {
2526 if (LocaleCompare("sample",option+1) == 0)
2527 {
2528 /*
2529 Sample image with pixel replication.
2530 */
2531 (void) SyncImageSettings(mogrify_info,*image);
2532 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2533 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2534 exception);
2535 break;
2536 }
2537 if (LocaleCompare("scale",option+1) == 0)
2538 {
2539 /*
2540 Resize image.
2541 */
2542 (void) SyncImageSettings(mogrify_info,*image);
2543 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2544 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2545 exception);
2546 break;
2547 }
2548 if (LocaleCompare("selective-blur",option+1) == 0)
2549 {
2550 /*
2551 Selectively blur pixels within a contrast threshold.
2552 */
2553 (void) SyncImageSettings(mogrify_info,*image);
2554 flags=ParseGeometry(argv[i+1],&geometry_info);
2555 if ((flags & PercentValue) != 0)
2556 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002557 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2558 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002559 break;
2560 }
2561 if (LocaleCompare("separate",option+1) == 0)
2562 {
2563 /*
2564 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002565 */
2566 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002567 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002568 break;
2569 }
2570 if (LocaleCompare("sepia-tone",option+1) == 0)
2571 {
2572 double
2573 threshold;
2574
2575 /*
2576 Sepia-tone image.
2577 */
2578 (void) SyncImageSettings(mogrify_info,*image);
2579 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2580 mogrify_image=SepiaToneImage(*image,threshold,exception);
2581 break;
2582 }
2583 if (LocaleCompare("segment",option+1) == 0)
2584 {
2585 /*
2586 Segment image.
2587 */
2588 (void) SyncImageSettings(mogrify_info,*image);
2589 flags=ParseGeometry(argv[i+1],&geometry_info);
2590 if ((flags & SigmaValue) == 0)
2591 geometry_info.sigma=1.0;
2592 (void) SegmentImage(*image,(*image)->colorspace,
2593 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2594 InheritException(exception,&(*image)->exception);
2595 break;
2596 }
2597 if (LocaleCompare("set",option+1) == 0)
2598 {
2599 char
2600 *value;
2601
2602 /*
2603 Set image option.
2604 */
2605 if (*option == '+')
2606 {
2607 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2608 (void) DeleteImageRegistry(argv[i+1]+9);
2609 else
2610 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2611 {
2612 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2613 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2614 }
2615 else
2616 (void) DeleteImageProperty(*image,argv[i+1]);
2617 break;
2618 }
2619 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2620 if (value == (char *) NULL)
2621 break;
2622 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2623 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2624 exception);
2625 else
2626 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2627 {
2628 (void) SetImageOption(image_info,argv[i+1]+7,value);
2629 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2630 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2631 }
2632 else
2633 (void) SetImageProperty(*image,argv[i+1],value);
2634 value=DestroyString(value);
2635 break;
2636 }
2637 if (LocaleCompare("shade",option+1) == 0)
2638 {
2639 /*
2640 Shade image.
2641 */
2642 (void) SyncImageSettings(mogrify_info,*image);
2643 flags=ParseGeometry(argv[i+1],&geometry_info);
2644 if ((flags & SigmaValue) == 0)
2645 geometry_info.sigma=1.0;
2646 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2647 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2648 break;
2649 }
2650 if (LocaleCompare("shadow",option+1) == 0)
2651 {
2652 /*
2653 Shadow image.
2654 */
2655 (void) SyncImageSettings(mogrify_info,*image);
2656 flags=ParseGeometry(argv[i+1],&geometry_info);
2657 if ((flags & SigmaValue) == 0)
2658 geometry_info.sigma=1.0;
2659 if ((flags & XiValue) == 0)
2660 geometry_info.xi=4.0;
2661 if ((flags & PsiValue) == 0)
2662 geometry_info.psi=4.0;
2663 mogrify_image=ShadowImage(*image,geometry_info.rho,
2664 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2665 ceil(geometry_info.psi-0.5),exception);
2666 break;
2667 }
2668 if (LocaleCompare("sharpen",option+1) == 0)
2669 {
2670 /*
2671 Sharpen image.
2672 */
2673 (void) SyncImageSettings(mogrify_info,*image);
2674 flags=ParseGeometry(argv[i+1],&geometry_info);
2675 if ((flags & SigmaValue) == 0)
2676 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002677 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002678 geometry_info.sigma,exception);
2679 break;
2680 }
2681 if (LocaleCompare("shave",option+1) == 0)
2682 {
2683 /*
2684 Shave the image edges.
2685 */
2686 (void) SyncImageSettings(mogrify_info,*image);
2687 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2688 mogrify_image=ShaveImage(*image,&geometry,exception);
2689 break;
2690 }
2691 if (LocaleCompare("shear",option+1) == 0)
2692 {
2693 /*
2694 Shear image.
2695 */
2696 (void) SyncImageSettings(mogrify_info,*image);
2697 flags=ParseGeometry(argv[i+1],&geometry_info);
2698 if ((flags & SigmaValue) == 0)
2699 geometry_info.sigma=geometry_info.rho;
2700 mogrify_image=ShearImage(*image,geometry_info.rho,
2701 geometry_info.sigma,exception);
2702 break;
2703 }
2704 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2705 {
2706 /*
2707 Sigmoidal non-linearity contrast control.
2708 */
2709 (void) SyncImageSettings(mogrify_info,*image);
2710 flags=ParseGeometry(argv[i+1],&geometry_info);
2711 if ((flags & SigmaValue) == 0)
2712 geometry_info.sigma=(double) QuantumRange/2.0;
2713 if ((flags & PercentValue) != 0)
2714 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2715 100.0;
cristy9ee60942011-07-06 14:54:38 +00002716 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002717 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2718 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002719 break;
2720 }
2721 if (LocaleCompare("sketch",option+1) == 0)
2722 {
2723 /*
2724 Sketch image.
2725 */
2726 (void) SyncImageSettings(mogrify_info,*image);
2727 flags=ParseGeometry(argv[i+1],&geometry_info);
2728 if ((flags & SigmaValue) == 0)
2729 geometry_info.sigma=1.0;
2730 mogrify_image=SketchImage(*image,geometry_info.rho,
2731 geometry_info.sigma,geometry_info.xi,exception);
2732 break;
2733 }
2734 if (LocaleCompare("solarize",option+1) == 0)
2735 {
2736 double
2737 threshold;
2738
2739 (void) SyncImageSettings(mogrify_info,*image);
2740 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2741 (void) SolarizeImage(*image,threshold);
2742 InheritException(exception,&(*image)->exception);
2743 break;
2744 }
2745 if (LocaleCompare("sparse-color",option+1) == 0)
2746 {
2747 SparseColorMethod
2748 method;
2749
2750 char
2751 *arguments;
2752
2753 /*
2754 Sparse Color Interpolated Gradient
2755 */
2756 (void) SyncImageSettings(mogrify_info,*image);
2757 method=(SparseColorMethod) ParseCommandOption(
2758 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2759 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2760 InheritException(exception,&(*image)->exception);
2761 if (arguments == (char *) NULL)
2762 break;
cristy3884f692011-07-08 18:00:18 +00002763 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002764 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2765 arguments=DestroyString(arguments);
2766 break;
2767 }
2768 if (LocaleCompare("splice",option+1) == 0)
2769 {
2770 /*
2771 Splice a solid color into the image.
2772 */
2773 (void) SyncImageSettings(mogrify_info,*image);
2774 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2775 mogrify_image=SpliceImage(*image,&geometry,exception);
2776 break;
2777 }
2778 if (LocaleCompare("spread",option+1) == 0)
2779 {
2780 /*
2781 Spread an image.
2782 */
2783 (void) SyncImageSettings(mogrify_info,*image);
2784 (void) ParseGeometry(argv[i+1],&geometry_info);
2785 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2786 break;
2787 }
2788 if (LocaleCompare("statistic",option+1) == 0)
2789 {
2790 StatisticType
2791 type;
2792
2793 (void) SyncImageSettings(mogrify_info,*image);
2794 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2795 MagickFalse,argv[i+1]);
2796 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002797 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2798 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002799 break;
2800 }
2801 if (LocaleCompare("stretch",option+1) == 0)
2802 {
2803 if (*option == '+')
2804 {
2805 draw_info->stretch=UndefinedStretch;
2806 break;
2807 }
2808 draw_info->stretch=(StretchType) ParseCommandOption(
2809 MagickStretchOptions,MagickFalse,argv[i+1]);
2810 break;
2811 }
2812 if (LocaleCompare("strip",option+1) == 0)
2813 {
2814 /*
2815 Strip image of profiles and comments.
2816 */
2817 (void) SyncImageSettings(mogrify_info,*image);
2818 (void) StripImage(*image);
2819 InheritException(exception,&(*image)->exception);
2820 break;
2821 }
2822 if (LocaleCompare("stroke",option+1) == 0)
2823 {
2824 ExceptionInfo
2825 *sans;
2826
2827 if (*option == '+')
2828 {
2829 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2830 if (draw_info->stroke_pattern != (Image *) NULL)
2831 draw_info->stroke_pattern=DestroyImage(
2832 draw_info->stroke_pattern);
2833 break;
2834 }
2835 sans=AcquireExceptionInfo();
2836 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2837 sans=DestroyExceptionInfo(sans);
2838 if (status == MagickFalse)
2839 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2840 exception);
2841 break;
2842 }
2843 if (LocaleCompare("strokewidth",option+1) == 0)
2844 {
cristyc1acd842011-05-19 23:05:47 +00002845 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2846 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002847 break;
2848 }
2849 if (LocaleCompare("style",option+1) == 0)
2850 {
2851 if (*option == '+')
2852 {
2853 draw_info->style=UndefinedStyle;
2854 break;
2855 }
2856 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2857 MagickFalse,argv[i+1]);
2858 break;
2859 }
2860 if (LocaleCompare("swirl",option+1) == 0)
2861 {
2862 /*
2863 Swirl image.
2864 */
2865 (void) SyncImageSettings(mogrify_info,*image);
2866 (void) ParseGeometry(argv[i+1],&geometry_info);
2867 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2868 break;
2869 }
2870 break;
2871 }
2872 case 't':
2873 {
2874 if (LocaleCompare("threshold",option+1) == 0)
2875 {
2876 double
2877 threshold;
2878
2879 /*
2880 Threshold image.
2881 */
2882 (void) SyncImageSettings(mogrify_info,*image);
2883 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002884 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002885 else
2886 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002887 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002888 InheritException(exception,&(*image)->exception);
2889 break;
2890 }
2891 if (LocaleCompare("thumbnail",option+1) == 0)
2892 {
2893 /*
2894 Thumbnail image.
2895 */
2896 (void) SyncImageSettings(mogrify_info,*image);
2897 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2898 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2899 exception);
2900 break;
2901 }
2902 if (LocaleCompare("tile",option+1) == 0)
2903 {
2904 if (*option == '+')
2905 {
2906 if (draw_info->fill_pattern != (Image *) NULL)
2907 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2908 break;
2909 }
2910 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2911 exception);
2912 break;
2913 }
2914 if (LocaleCompare("tint",option+1) == 0)
2915 {
2916 /*
2917 Tint the image.
2918 */
2919 (void) SyncImageSettings(mogrify_info,*image);
2920 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2921 break;
2922 }
2923 if (LocaleCompare("transform",option+1) == 0)
2924 {
2925 /*
2926 Affine transform image.
2927 */
2928 (void) SyncImageSettings(mogrify_info,*image);
2929 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2930 exception);
2931 break;
2932 }
2933 if (LocaleCompare("transparent",option+1) == 0)
2934 {
cristy4c08aed2011-07-01 19:47:50 +00002935 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002936 target;
2937
2938 (void) SyncImageSettings(mogrify_info,*image);
2939 (void) QueryMagickColor(argv[i+1],&target,exception);
2940 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002941 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2942 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002943 break;
2944 }
2945 if (LocaleCompare("transpose",option+1) == 0)
2946 {
2947 /*
2948 Transpose image scanlines.
2949 */
2950 (void) SyncImageSettings(mogrify_info,*image);
2951 mogrify_image=TransposeImage(*image,exception);
2952 break;
2953 }
2954 if (LocaleCompare("transverse",option+1) == 0)
2955 {
2956 /*
2957 Transverse image scanlines.
2958 */
2959 (void) SyncImageSettings(mogrify_info,*image);
2960 mogrify_image=TransverseImage(*image,exception);
2961 break;
2962 }
2963 if (LocaleCompare("treedepth",option+1) == 0)
2964 {
2965 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2966 break;
2967 }
2968 if (LocaleCompare("trim",option+1) == 0)
2969 {
2970 /*
2971 Trim image.
2972 */
2973 (void) SyncImageSettings(mogrify_info,*image);
2974 mogrify_image=TrimImage(*image,exception);
2975 break;
2976 }
2977 if (LocaleCompare("type",option+1) == 0)
2978 {
2979 ImageType
2980 type;
2981
2982 (void) SyncImageSettings(mogrify_info,*image);
2983 if (*option == '+')
2984 type=UndefinedType;
2985 else
2986 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2987 argv[i+1]);
2988 (*image)->type=UndefinedType;
2989 (void) SetImageType(*image,type);
2990 InheritException(exception,&(*image)->exception);
2991 break;
2992 }
2993 break;
2994 }
2995 case 'u':
2996 {
2997 if (LocaleCompare("undercolor",option+1) == 0)
2998 {
2999 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3000 exception);
3001 break;
3002 }
3003 if (LocaleCompare("unique",option+1) == 0)
3004 {
3005 if (*option == '+')
3006 {
3007 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3008 break;
3009 }
3010 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3011 (void) SetImageArtifact(*image,"verbose","true");
3012 break;
3013 }
3014 if (LocaleCompare("unique-colors",option+1) == 0)
3015 {
3016 /*
3017 Unique image colors.
3018 */
3019 (void) SyncImageSettings(mogrify_info,*image);
3020 mogrify_image=UniqueImageColors(*image,exception);
3021 break;
3022 }
3023 if (LocaleCompare("unsharp",option+1) == 0)
3024 {
3025 /*
3026 Unsharp mask image.
3027 */
3028 (void) SyncImageSettings(mogrify_info,*image);
3029 flags=ParseGeometry(argv[i+1],&geometry_info);
3030 if ((flags & SigmaValue) == 0)
3031 geometry_info.sigma=1.0;
3032 if ((flags & XiValue) == 0)
3033 geometry_info.xi=1.0;
3034 if ((flags & PsiValue) == 0)
3035 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003036 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3037 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003038 break;
3039 }
3040 break;
3041 }
3042 case 'v':
3043 {
3044 if (LocaleCompare("verbose",option+1) == 0)
3045 {
3046 (void) SetImageArtifact(*image,option+1,
3047 *option == '+' ? "false" : "true");
3048 break;
3049 }
3050 if (LocaleCompare("vignette",option+1) == 0)
3051 {
3052 /*
3053 Vignette image.
3054 */
3055 (void) SyncImageSettings(mogrify_info,*image);
3056 flags=ParseGeometry(argv[i+1],&geometry_info);
3057 if ((flags & SigmaValue) == 0)
3058 geometry_info.sigma=1.0;
3059 if ((flags & XiValue) == 0)
3060 geometry_info.xi=0.1*(*image)->columns;
3061 if ((flags & PsiValue) == 0)
3062 geometry_info.psi=0.1*(*image)->rows;
3063 mogrify_image=VignetteImage(*image,geometry_info.rho,
3064 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3065 ceil(geometry_info.psi-0.5),exception);
3066 break;
3067 }
3068 if (LocaleCompare("virtual-pixel",option+1) == 0)
3069 {
3070 if (*option == '+')
3071 {
3072 (void) SetImageVirtualPixelMethod(*image,
3073 UndefinedVirtualPixelMethod);
3074 break;
3075 }
3076 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3077 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3078 argv[i+1]));
3079 break;
3080 }
3081 break;
3082 }
3083 case 'w':
3084 {
3085 if (LocaleCompare("wave",option+1) == 0)
3086 {
3087 /*
3088 Wave image.
3089 */
3090 (void) SyncImageSettings(mogrify_info,*image);
3091 flags=ParseGeometry(argv[i+1],&geometry_info);
3092 if ((flags & SigmaValue) == 0)
3093 geometry_info.sigma=1.0;
3094 mogrify_image=WaveImage(*image,geometry_info.rho,
3095 geometry_info.sigma,exception);
3096 break;
3097 }
3098 if (LocaleCompare("weight",option+1) == 0)
3099 {
3100 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3101 if (LocaleCompare(argv[i+1],"all") == 0)
3102 draw_info->weight=0;
3103 if (LocaleCompare(argv[i+1],"bold") == 0)
3104 draw_info->weight=700;
3105 if (LocaleCompare(argv[i+1],"bolder") == 0)
3106 if (draw_info->weight <= 800)
3107 draw_info->weight+=100;
3108 if (LocaleCompare(argv[i+1],"lighter") == 0)
3109 if (draw_info->weight >= 100)
3110 draw_info->weight-=100;
3111 if (LocaleCompare(argv[i+1],"normal") == 0)
3112 draw_info->weight=400;
3113 break;
3114 }
3115 if (LocaleCompare("white-threshold",option+1) == 0)
3116 {
3117 /*
3118 White threshold image.
3119 */
3120 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003121 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003122 InheritException(exception,&(*image)->exception);
3123 break;
3124 }
3125 break;
3126 }
3127 default:
3128 break;
3129 }
3130 /*
3131 Replace current image with any image that was generated
3132 */
3133 if (mogrify_image != (Image *) NULL)
3134 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003135 i+=count;
3136 }
3137 if (region_image != (Image *) NULL)
3138 {
anthonydf8ebac2011-04-27 09:03:19 +00003139 /*
3140 Composite transformed region onto image.
3141 */
cristy6b3da3a2010-06-20 02:21:46 +00003142 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003143 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003144 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3145 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003146 InheritException(exception,&region_image->exception);
3147 *image=DestroyImage(*image);
3148 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003149 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003150 }
3151 /*
3152 Free resources.
3153 */
anthonydf8ebac2011-04-27 09:03:19 +00003154 quantize_info=DestroyQuantizeInfo(quantize_info);
3155 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003156 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003157 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003158 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003159 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003160}
3161
3162/*
3163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3164% %
3165% %
3166% %
cristy5063d812010-10-19 16:28:10 +00003167+ 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 +00003168% %
3169% %
3170% %
3171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3172%
3173% MogrifyImageCommand() transforms an image or a sequence of images. These
3174% transforms include image scaling, image rotation, color reduction, and
3175% others. The transmogrified image overwrites the original image.
3176%
3177% The format of the MogrifyImageCommand method is:
3178%
3179% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3180% const char **argv,char **metadata,ExceptionInfo *exception)
3181%
3182% A description of each parameter follows:
3183%
3184% o image_info: the image info.
3185%
3186% o argc: the number of elements in the argument vector.
3187%
3188% o argv: A text array containing the command line arguments.
3189%
3190% o metadata: any metadata is returned here.
3191%
3192% o exception: return any errors or warnings in this structure.
3193%
3194*/
3195
3196static MagickBooleanType MogrifyUsage(void)
3197{
3198 static const char
3199 *miscellaneous[]=
3200 {
3201 "-debug events display copious debugging information",
3202 "-help print program options",
3203 "-list type print a list of supported option arguments",
3204 "-log format format of debugging information",
3205 "-version print version information",
3206 (char *) NULL
3207 },
3208 *operators[]=
3209 {
3210 "-adaptive-blur geometry",
3211 " adaptively blur pixels; decrease effect near edges",
3212 "-adaptive-resize geometry",
3213 " adaptively resize image using 'mesh' interpolation",
3214 "-adaptive-sharpen geometry",
3215 " adaptively sharpen pixels; increase effect near edges",
3216 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3217 " transparent, extract, background, or shape",
3218 "-annotate geometry text",
3219 " annotate the image with text",
3220 "-auto-gamma automagically adjust gamma level of image",
3221 "-auto-level automagically adjust color levels of image",
3222 "-auto-orient automagically orient (rotate) image",
3223 "-bench iterations measure performance",
3224 "-black-threshold value",
3225 " force all pixels below the threshold into black",
3226 "-blue-shift simulate a scene at nighttime in the moonlight",
3227 "-blur geometry reduce image noise and reduce detail levels",
3228 "-border geometry surround image with a border of color",
3229 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003230 "-brightness-contrast geometry",
3231 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003232 "-cdl filename color correct with a color decision list",
3233 "-charcoal radius simulate a charcoal drawing",
3234 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003235 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003236 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003237 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003238 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003239 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003240 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003241 "-contrast enhance or reduce the image contrast",
3242 "-contrast-stretch geometry",
3243 " improve contrast by `stretching' the intensity range",
3244 "-convolve coefficients",
3245 " apply a convolution kernel to the image",
3246 "-cycle amount cycle the image colormap",
3247 "-decipher filename convert cipher pixels to plain pixels",
3248 "-deskew threshold straighten an image",
3249 "-despeckle reduce the speckles within an image",
3250 "-distort method args",
3251 " distort images according to given method ad args",
3252 "-draw string annotate the image with a graphic primitive",
3253 "-edge radius apply a filter to detect edges in the image",
3254 "-encipher filename convert plain pixels to cipher pixels",
3255 "-emboss radius emboss an image",
3256 "-enhance apply a digital filter to enhance a noisy image",
3257 "-equalize perform histogram equalization to an image",
3258 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003259 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003260 "-extent geometry set the image size",
3261 "-extract geometry extract area from image",
3262 "-fft implements the discrete Fourier transform (DFT)",
3263 "-flip flip image vertically",
3264 "-floodfill geometry color",
3265 " floodfill the image with color",
3266 "-flop flop image horizontally",
3267 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003268 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003269 " apply function over image values",
3270 "-gamma value level of gamma correction",
3271 "-gaussian-blur geometry",
3272 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003273 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003274 "-identify identify the format and characteristics of the image",
3275 "-ift implements the inverse discrete Fourier transform (DFT)",
3276 "-implode amount implode image pixels about the center",
3277 "-lat geometry local adaptive thresholding",
3278 "-layers method optimize, merge, or compare image layers",
3279 "-level value adjust the level of image contrast",
3280 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003281 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003282 "-linear-stretch geometry",
3283 " improve contrast by `stretching with saturation'",
3284 "-liquid-rescale geometry",
3285 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003286 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003287 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003288 "-modulate value vary the brightness, saturation, and hue",
3289 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003290 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003291 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003292 "-motion-blur geometry",
3293 " simulate motion blur",
3294 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003295 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003296 "-normalize transform image to span the full range of colors",
3297 "-opaque color change this color to the fill color",
3298 "-ordered-dither NxN",
3299 " add a noise pattern to the image with specific",
3300 " amplitudes",
3301 "-paint radius simulate an oil painting",
3302 "-polaroid angle simulate a Polaroid picture",
3303 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003304 "-profile filename add, delete, or apply an image profile",
3305 "-quantize colorspace reduce colors in this colorspace",
3306 "-radial-blur angle radial blur the image",
3307 "-raise value lighten/darken image edges to create a 3-D effect",
3308 "-random-threshold low,high",
3309 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003310 "-region geometry apply options to a portion of the image",
3311 "-render render vector graphics",
3312 "-repage geometry size and location of an image canvas",
3313 "-resample geometry change the resolution of an image",
3314 "-resize geometry resize the image",
3315 "-roll geometry roll an image vertically or horizontally",
3316 "-rotate degrees apply Paeth rotation to the image",
3317 "-sample geometry scale image with pixel sampling",
3318 "-scale geometry scale the image",
3319 "-segment values segment an image",
3320 "-selective-blur geometry",
3321 " selectively blur pixels within a contrast threshold",
3322 "-sepia-tone threshold",
3323 " simulate a sepia-toned photo",
3324 "-set property value set an image property",
3325 "-shade degrees shade the image using a distant light source",
3326 "-shadow geometry simulate an image shadow",
3327 "-sharpen geometry sharpen the image",
3328 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003329 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003330 "-sigmoidal-contrast geometry",
3331 " increase the contrast without saturating highlights or shadows",
3332 "-sketch geometry simulate a pencil sketch",
3333 "-solarize threshold negate all pixels above the threshold level",
3334 "-sparse-color method args",
3335 " fill in a image based on a few color points",
3336 "-splice geometry splice the background color into the image",
3337 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003338 "-statistic type radius",
3339 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003340 "-strip strip image of all profiles and comments",
3341 "-swirl degrees swirl image pixels about the center",
3342 "-threshold value threshold the image",
3343 "-thumbnail geometry create a thumbnail of the image",
3344 "-tile filename tile image when filling a graphic primitive",
3345 "-tint value tint the image with the fill color",
3346 "-transform affine transform image",
3347 "-transparent color make this color transparent within the image",
3348 "-transpose flip image vertically and rotate 90 degrees",
3349 "-transverse flop image horizontally and rotate 270 degrees",
3350 "-trim trim image edges",
3351 "-type type image type",
3352 "-unique-colors discard all but one of any pixel color",
3353 "-unsharp geometry sharpen the image",
3354 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003355 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003356 "-white-threshold value",
3357 " force all pixels above the threshold into white",
3358 (char *) NULL
3359 },
3360 *sequence_operators[]=
3361 {
cristy4285d782011-02-09 20:12:28 +00003362 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003363 "-clut apply a color lookup table to the image",
3364 "-coalesce merge a sequence of images",
3365 "-combine combine a sequence of images",
3366 "-composite composite image",
3367 "-crop geometry cut out a rectangular region of the image",
3368 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003369 "-evaluate-sequence operator",
3370 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003371 "-flatten flatten a sequence of images",
3372 "-fx expression apply mathematical expression to an image channel(s)",
3373 "-hald-clut apply a Hald color lookup table to the image",
3374 "-morph value morph an image sequence",
3375 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003376 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003377 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003378 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003379 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003380 "-write filename write images to this file",
3381 (char *) NULL
3382 },
3383 *settings[]=
3384 {
3385 "-adjoin join images into a single multi-image file",
3386 "-affine matrix affine transform matrix",
3387 "-alpha option activate, deactivate, reset, or set the alpha channel",
3388 "-antialias remove pixel-aliasing",
3389 "-authenticate password",
3390 " decipher image with this password",
3391 "-attenuate value lessen (or intensify) when adding noise to an image",
3392 "-background color background color",
3393 "-bias value add bias when convolving an image",
3394 "-black-point-compensation",
3395 " use black point compensation",
3396 "-blue-primary point chromaticity blue primary point",
3397 "-bordercolor color border color",
3398 "-caption string assign a caption to an image",
3399 "-channel type apply option to select image channels",
3400 "-colors value preferred number of colors in the image",
3401 "-colorspace type alternate image colorspace",
3402 "-comment string annotate image with comment",
3403 "-compose operator set image composite operator",
3404 "-compress type type of pixel compression when writing the image",
3405 "-define format:option",
3406 " define one or more image format options",
3407 "-delay value display the next image after pausing",
3408 "-density geometry horizontal and vertical density of the image",
3409 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003410 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003411 "-display server get image or font from this X server",
3412 "-dispose method layer disposal method",
3413 "-dither method apply error diffusion to image",
3414 "-encoding type text encoding type",
3415 "-endian type endianness (MSB or LSB) of the image",
3416 "-family name render text with this font family",
3417 "-fill color color to use when filling a graphic primitive",
3418 "-filter type use this filter when resizing an image",
3419 "-font name render text with this font",
3420 "-format \"string\" output formatted image characteristics",
3421 "-fuzz distance colors within this distance are considered equal",
3422 "-gravity type horizontal and vertical text placement",
3423 "-green-primary point chromaticity green primary point",
3424 "-intent type type of rendering intent when managing the image color",
3425 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003426 "-interline-spacing value",
3427 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003428 "-interpolate method pixel color interpolation method",
3429 "-interword-spacing value",
3430 " set the space between two words",
3431 "-kerning value set the space between two letters",
3432 "-label string assign a label to an image",
3433 "-limit type value pixel cache resource limit",
3434 "-loop iterations add Netscape loop extension to your GIF animation",
3435 "-mask filename associate a mask with the image",
3436 "-mattecolor color frame color",
3437 "-monitor monitor progress",
3438 "-orient type image orientation",
3439 "-page geometry size and location of an image canvas (setting)",
3440 "-ping efficiently determine image attributes",
3441 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003442 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003443 "-preview type image preview type",
3444 "-quality value JPEG/MIFF/PNG compression level",
3445 "-quiet suppress all warning messages",
3446 "-red-primary point chromaticity red primary point",
3447 "-regard-warnings pay attention to warning messages",
3448 "-remap filename transform image colors to match this set of colors",
3449 "-respect-parentheses settings remain in effect until parenthesis boundary",
3450 "-sampling-factor geometry",
3451 " horizontal and vertical sampling factor",
3452 "-scene value image scene number",
3453 "-seed value seed a new sequence of pseudo-random numbers",
3454 "-size geometry width and height of image",
3455 "-stretch type render text with this font stretch",
3456 "-stroke color graphic primitive stroke color",
3457 "-strokewidth value graphic primitive stroke width",
3458 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003459 "-synchronize synchronize image to storage device",
3460 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003461 "-texture filename name of texture to tile onto the image background",
3462 "-tile-offset geometry",
3463 " tile offset",
3464 "-treedepth value color tree depth",
3465 "-transparent-color color",
3466 " transparent color",
3467 "-undercolor color annotation bounding box color",
3468 "-units type the units of image resolution",
3469 "-verbose print detailed information about the image",
3470 "-view FlashPix viewing transforms",
3471 "-virtual-pixel method",
3472 " virtual pixel access method",
3473 "-weight type render text with this font weight",
3474 "-white-point point chromaticity white point",
3475 (char *) NULL
3476 },
3477 *stack_operators[]=
3478 {
anthonyb69c4b32011-03-23 04:37:44 +00003479 "-delete indexes delete the image from the image sequence",
3480 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003481 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003482 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003483 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003484 "-swap indexes swap two images in the image sequence",
3485 (char *) NULL
3486 };
3487
3488 const char
3489 **p;
3490
cristybb503372010-05-27 20:51:26 +00003491 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003492 (void) printf("Copyright: %s\n",GetMagickCopyright());
3493 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003494 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3495 GetClientName());
3496 (void) printf("\nImage Settings:\n");
3497 for (p=settings; *p != (char *) NULL; p++)
3498 (void) printf(" %s\n",*p);
3499 (void) printf("\nImage Operators:\n");
3500 for (p=operators; *p != (char *) NULL; p++)
3501 (void) printf(" %s\n",*p);
3502 (void) printf("\nImage Sequence Operators:\n");
3503 for (p=sequence_operators; *p != (char *) NULL; p++)
3504 (void) printf(" %s\n",*p);
3505 (void) printf("\nImage Stack Operators:\n");
3506 for (p=stack_operators; *p != (char *) NULL; p++)
3507 (void) printf(" %s\n",*p);
3508 (void) printf("\nMiscellaneous Options:\n");
3509 for (p=miscellaneous; *p != (char *) NULL; p++)
3510 (void) printf(" %s\n",*p);
3511 (void) printf(
3512 "\nBy default, the image format of `file' is determined by its magic\n");
3513 (void) printf(
3514 "number. To specify a particular image format, precede the filename\n");
3515 (void) printf(
3516 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3517 (void) printf(
3518 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3519 (void) printf("'-' for standard input or output.\n");
3520 return(MagickFalse);
3521}
3522
3523WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3524 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3525{
3526#define DestroyMogrify() \
3527{ \
3528 if (format != (char *) NULL) \
3529 format=DestroyString(format); \
3530 if (path != (char *) NULL) \
3531 path=DestroyString(path); \
3532 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003533 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003534 argv[i]=DestroyString(argv[i]); \
3535 argv=(char **) RelinquishMagickMemory(argv); \
3536}
3537#define ThrowMogrifyException(asperity,tag,option) \
3538{ \
3539 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3540 option); \
3541 DestroyMogrify(); \
3542 return(MagickFalse); \
3543}
3544#define ThrowMogrifyInvalidArgumentException(option,argument) \
3545{ \
3546 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3547 "InvalidArgument","`%s': %s",argument,option); \
3548 DestroyMogrify(); \
3549 return(MagickFalse); \
3550}
3551
3552 char
3553 *format,
3554 *option,
3555 *path;
3556
3557 Image
3558 *image;
3559
3560 ImageStack
3561 image_stack[MaxImageStackDepth+1];
3562
cristy3ed852e2009-09-05 21:47:34 +00003563 MagickBooleanType
3564 global_colormap;
3565
3566 MagickBooleanType
3567 fire,
cristyebbcfea2011-02-25 02:43:54 +00003568 pend,
3569 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003570
3571 MagickStatusType
3572 status;
3573
cristyebbcfea2011-02-25 02:43:54 +00003574 register ssize_t
3575 i;
3576
3577 ssize_t
3578 j,
3579 k;
3580
cristy3ed852e2009-09-05 21:47:34 +00003581 /*
3582 Set defaults.
3583 */
3584 assert(image_info != (ImageInfo *) NULL);
3585 assert(image_info->signature == MagickSignature);
3586 if (image_info->debug != MagickFalse)
3587 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3588 assert(exception != (ExceptionInfo *) NULL);
3589 if (argc == 2)
3590 {
3591 option=argv[1];
3592 if ((LocaleCompare("version",option+1) == 0) ||
3593 (LocaleCompare("-version",option+1) == 0))
3594 {
cristyb51dff52011-05-19 16:55:47 +00003595 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003596 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003597 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3598 GetMagickCopyright());
3599 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3600 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003601 return(MagickFalse);
3602 }
3603 }
3604 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003605 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003606 format=(char *) NULL;
3607 path=(char *) NULL;
3608 global_colormap=MagickFalse;
3609 k=0;
3610 j=1;
3611 NewImageStack();
3612 option=(char *) NULL;
3613 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003614 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003615 status=MagickTrue;
3616 /*
3617 Parse command line.
3618 */
3619 ReadCommandlLine(argc,&argv);
3620 status=ExpandFilenames(&argc,&argv);
3621 if (status == MagickFalse)
3622 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3623 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003624 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003625 {
3626 option=argv[i];
3627 if (LocaleCompare(option,"(") == 0)
3628 {
3629 FireImageStack(MagickFalse,MagickTrue,pend);
3630 if (k == MaxImageStackDepth)
3631 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3632 option);
3633 PushImageStack();
3634 continue;
3635 }
3636 if (LocaleCompare(option,")") == 0)
3637 {
3638 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3639 if (k == 0)
3640 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3641 PopImageStack();
3642 continue;
3643 }
cristy042ee782011-04-22 18:48:30 +00003644 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003645 {
3646 char
3647 backup_filename[MaxTextExtent],
3648 *filename;
3649
3650 Image
3651 *images;
3652
3653 /*
3654 Option is a file name: begin by reading image from specified file.
3655 */
3656 FireImageStack(MagickFalse,MagickFalse,pend);
3657 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003658 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003659 filename=argv[++i];
3660 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3661 images=ReadImages(image_info,exception);
3662 status&=(images != (Image *) NULL) &&
3663 (exception->severity < ErrorException);
3664 if (images == (Image *) NULL)
3665 continue;
cristydaa76602010-06-30 13:05:11 +00003666 if (format != (char *) NULL)
3667 (void) CopyMagickString(images->filename,images->magick_filename,
3668 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003669 if (path != (char *) NULL)
3670 {
3671 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003672 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003673 path,*DirectorySeparator,filename);
3674 }
3675 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003676 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003677 AppendImageStack(images);
3678 FinalizeImageSettings(image_info,image,MagickFalse);
3679 if (global_colormap != MagickFalse)
3680 {
3681 QuantizeInfo
3682 *quantize_info;
3683
3684 quantize_info=AcquireQuantizeInfo(image_info);
3685 (void) RemapImages(quantize_info,images,(Image *) NULL);
3686 quantize_info=DestroyQuantizeInfo(quantize_info);
3687 }
3688 *backup_filename='\0';
3689 if ((LocaleCompare(image->filename,"-") != 0) &&
3690 (IsPathWritable(image->filename) != MagickFalse))
3691 {
cristybb503372010-05-27 20:51:26 +00003692 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003693 i;
3694
3695 /*
3696 Rename image file as backup.
3697 */
3698 (void) CopyMagickString(backup_filename,image->filename,
3699 MaxTextExtent);
3700 for (i=0; i < 6; i++)
3701 {
3702 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3703 if (IsPathAccessible(backup_filename) == MagickFalse)
3704 break;
3705 }
3706 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3707 (rename(image->filename,backup_filename) != 0))
3708 *backup_filename='\0';
3709 }
3710 /*
3711 Write transmogrified image to disk.
3712 */
3713 image_info->synchronize=MagickTrue;
3714 status&=WriteImages(image_info,image,image->filename,exception);
3715 if ((status == MagickFalse) && (*backup_filename != '\0'))
3716 (void) remove(backup_filename);
3717 RemoveAllImageStack();
3718 continue;
3719 }
3720 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3721 switch (*(option+1))
3722 {
3723 case 'a':
3724 {
3725 if (LocaleCompare("adaptive-blur",option+1) == 0)
3726 {
3727 i++;
cristybb503372010-05-27 20:51:26 +00003728 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003729 ThrowMogrifyException(OptionError,"MissingArgument",option);
3730 if (IsGeometry(argv[i]) == MagickFalse)
3731 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3732 break;
3733 }
3734 if (LocaleCompare("adaptive-resize",option+1) == 0)
3735 {
3736 i++;
cristybb503372010-05-27 20:51:26 +00003737 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003738 ThrowMogrifyException(OptionError,"MissingArgument",option);
3739 if (IsGeometry(argv[i]) == MagickFalse)
3740 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3741 break;
3742 }
3743 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3744 {
3745 i++;
cristybb503372010-05-27 20:51:26 +00003746 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003747 ThrowMogrifyException(OptionError,"MissingArgument",option);
3748 if (IsGeometry(argv[i]) == MagickFalse)
3749 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3750 break;
3751 }
3752 if (LocaleCompare("affine",option+1) == 0)
3753 {
3754 if (*option == '+')
3755 break;
3756 i++;
cristybb503372010-05-27 20:51:26 +00003757 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003758 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003759 break;
3760 }
3761 if (LocaleCompare("alpha",option+1) == 0)
3762 {
cristybb503372010-05-27 20:51:26 +00003763 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003764 type;
3765
3766 if (*option == '+')
3767 break;
3768 i++;
cristybb503372010-05-27 20:51:26 +00003769 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003770 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003771 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003772 if (type < 0)
3773 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3774 argv[i]);
3775 break;
3776 }
3777 if (LocaleCompare("annotate",option+1) == 0)
3778 {
3779 if (*option == '+')
3780 break;
3781 i++;
cristybb503372010-05-27 20:51:26 +00003782 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003783 ThrowMogrifyException(OptionError,"MissingArgument",option);
3784 if (IsGeometry(argv[i]) == MagickFalse)
3785 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003786 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003787 ThrowMogrifyException(OptionError,"MissingArgument",option);
3788 i++;
3789 break;
3790 }
3791 if (LocaleCompare("antialias",option+1) == 0)
3792 break;
3793 if (LocaleCompare("append",option+1) == 0)
3794 break;
3795 if (LocaleCompare("attenuate",option+1) == 0)
3796 {
3797 if (*option == '+')
3798 break;
3799 i++;
cristybb503372010-05-27 20:51:26 +00003800 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003801 ThrowMogrifyException(OptionError,"MissingArgument",option);
3802 if (IsGeometry(argv[i]) == MagickFalse)
3803 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3804 break;
3805 }
3806 if (LocaleCompare("authenticate",option+1) == 0)
3807 {
3808 if (*option == '+')
3809 break;
3810 i++;
cristybb503372010-05-27 20:51:26 +00003811 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003812 ThrowMogrifyException(OptionError,"MissingArgument",option);
3813 break;
3814 }
3815 if (LocaleCompare("auto-gamma",option+1) == 0)
3816 break;
3817 if (LocaleCompare("auto-level",option+1) == 0)
3818 break;
3819 if (LocaleCompare("auto-orient",option+1) == 0)
3820 break;
3821 if (LocaleCompare("average",option+1) == 0)
3822 break;
3823 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3824 }
3825 case 'b':
3826 {
3827 if (LocaleCompare("background",option+1) == 0)
3828 {
3829 if (*option == '+')
3830 break;
3831 i++;
cristybb503372010-05-27 20:51:26 +00003832 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003833 ThrowMogrifyException(OptionError,"MissingArgument",option);
3834 break;
3835 }
3836 if (LocaleCompare("bias",option+1) == 0)
3837 {
3838 if (*option == '+')
3839 break;
3840 i++;
cristybb503372010-05-27 20:51:26 +00003841 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003842 ThrowMogrifyException(OptionError,"MissingArgument",option);
3843 if (IsGeometry(argv[i]) == MagickFalse)
3844 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3845 break;
3846 }
3847 if (LocaleCompare("black-point-compensation",option+1) == 0)
3848 break;
3849 if (LocaleCompare("black-threshold",option+1) == 0)
3850 {
3851 if (*option == '+')
3852 break;
3853 i++;
cristybb503372010-05-27 20:51:26 +00003854 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003855 ThrowMogrifyException(OptionError,"MissingArgument",option);
3856 if (IsGeometry(argv[i]) == MagickFalse)
3857 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3858 break;
3859 }
3860 if (LocaleCompare("blue-primary",option+1) == 0)
3861 {
3862 if (*option == '+')
3863 break;
3864 i++;
cristybb503372010-05-27 20:51:26 +00003865 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003866 ThrowMogrifyException(OptionError,"MissingArgument",option);
3867 if (IsGeometry(argv[i]) == MagickFalse)
3868 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3869 break;
3870 }
3871 if (LocaleCompare("blue-shift",option+1) == 0)
3872 {
3873 i++;
cristybb503372010-05-27 20:51:26 +00003874 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003875 ThrowMogrifyException(OptionError,"MissingArgument",option);
3876 if (IsGeometry(argv[i]) == MagickFalse)
3877 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3878 break;
3879 }
3880 if (LocaleCompare("blur",option+1) == 0)
3881 {
3882 i++;
cristybb503372010-05-27 20:51:26 +00003883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003884 ThrowMogrifyException(OptionError,"MissingArgument",option);
3885 if (IsGeometry(argv[i]) == MagickFalse)
3886 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3887 break;
3888 }
3889 if (LocaleCompare("border",option+1) == 0)
3890 {
3891 if (*option == '+')
3892 break;
3893 i++;
cristybb503372010-05-27 20:51:26 +00003894 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003895 ThrowMogrifyException(OptionError,"MissingArgument",option);
3896 if (IsGeometry(argv[i]) == MagickFalse)
3897 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3898 break;
3899 }
3900 if (LocaleCompare("bordercolor",option+1) == 0)
3901 {
3902 if (*option == '+')
3903 break;
3904 i++;
cristybb503372010-05-27 20:51:26 +00003905 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003906 ThrowMogrifyException(OptionError,"MissingArgument",option);
3907 break;
3908 }
3909 if (LocaleCompare("box",option+1) == 0)
3910 {
3911 if (*option == '+')
3912 break;
3913 i++;
cristybb503372010-05-27 20:51:26 +00003914 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003915 ThrowMogrifyException(OptionError,"MissingArgument",option);
3916 break;
3917 }
cristya28d6b82010-01-11 20:03:47 +00003918 if (LocaleCompare("brightness-contrast",option+1) == 0)
3919 {
3920 i++;
cristybb503372010-05-27 20:51:26 +00003921 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003922 ThrowMogrifyException(OptionError,"MissingArgument",option);
3923 if (IsGeometry(argv[i]) == MagickFalse)
3924 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3925 break;
3926 }
cristy3ed852e2009-09-05 21:47:34 +00003927 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3928 }
3929 case 'c':
3930 {
3931 if (LocaleCompare("cache",option+1) == 0)
3932 {
3933 if (*option == '+')
3934 break;
3935 i++;
cristybb503372010-05-27 20:51:26 +00003936 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003937 ThrowMogrifyException(OptionError,"MissingArgument",option);
3938 if (IsGeometry(argv[i]) == MagickFalse)
3939 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3940 break;
3941 }
3942 if (LocaleCompare("caption",option+1) == 0)
3943 {
3944 if (*option == '+')
3945 break;
3946 i++;
cristybb503372010-05-27 20:51:26 +00003947 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003948 ThrowMogrifyException(OptionError,"MissingArgument",option);
3949 break;
3950 }
3951 if (LocaleCompare("channel",option+1) == 0)
3952 {
cristybb503372010-05-27 20:51:26 +00003953 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003954 channel;
3955
3956 if (*option == '+')
3957 break;
3958 i++;
cristybb503372010-05-27 20:51:26 +00003959 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003960 ThrowMogrifyException(OptionError,"MissingArgument",option);
3961 channel=ParseChannelOption(argv[i]);
3962 if (channel < 0)
3963 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3964 argv[i]);
3965 break;
3966 }
3967 if (LocaleCompare("cdl",option+1) == 0)
3968 {
3969 if (*option == '+')
3970 break;
3971 i++;
cristybb503372010-05-27 20:51:26 +00003972 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003973 ThrowMogrifyException(OptionError,"MissingArgument",option);
3974 break;
3975 }
3976 if (LocaleCompare("charcoal",option+1) == 0)
3977 {
3978 if (*option == '+')
3979 break;
3980 i++;
cristybb503372010-05-27 20:51:26 +00003981 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003982 ThrowMogrifyException(OptionError,"MissingArgument",option);
3983 if (IsGeometry(argv[i]) == MagickFalse)
3984 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3985 break;
3986 }
3987 if (LocaleCompare("chop",option+1) == 0)
3988 {
3989 if (*option == '+')
3990 break;
3991 i++;
cristybb503372010-05-27 20:51:26 +00003992 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003993 ThrowMogrifyException(OptionError,"MissingArgument",option);
3994 if (IsGeometry(argv[i]) == MagickFalse)
3995 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3996 break;
3997 }
cristy1eb45dd2009-09-25 16:38:06 +00003998 if (LocaleCompare("clamp",option+1) == 0)
3999 break;
4000 if (LocaleCompare("clip",option+1) == 0)
4001 break;
cristy3ed852e2009-09-05 21:47:34 +00004002 if (LocaleCompare("clip-mask",option+1) == 0)
4003 {
4004 if (*option == '+')
4005 break;
4006 i++;
cristybb503372010-05-27 20:51:26 +00004007 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004008 ThrowMogrifyException(OptionError,"MissingArgument",option);
4009 break;
4010 }
4011 if (LocaleCompare("clut",option+1) == 0)
4012 break;
4013 if (LocaleCompare("coalesce",option+1) == 0)
4014 break;
4015 if (LocaleCompare("colorize",option+1) == 0)
4016 {
4017 if (*option == '+')
4018 break;
4019 i++;
cristybb503372010-05-27 20:51:26 +00004020 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004021 ThrowMogrifyException(OptionError,"MissingArgument",option);
4022 if (IsGeometry(argv[i]) == MagickFalse)
4023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4024 break;
4025 }
cristye6365592010-04-02 17:31:23 +00004026 if (LocaleCompare("color-matrix",option+1) == 0)
4027 {
cristyb6bd4ad2010-08-08 01:12:27 +00004028 KernelInfo
4029 *kernel_info;
4030
cristye6365592010-04-02 17:31:23 +00004031 if (*option == '+')
4032 break;
4033 i++;
cristybb503372010-05-27 20:51:26 +00004034 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004035 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004036 kernel_info=AcquireKernelInfo(argv[i]);
4037 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004038 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004039 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004040 break;
4041 }
cristy3ed852e2009-09-05 21:47:34 +00004042 if (LocaleCompare("colors",option+1) == 0)
4043 {
4044 if (*option == '+')
4045 break;
4046 i++;
cristybb503372010-05-27 20:51:26 +00004047 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004048 ThrowMogrifyException(OptionError,"MissingArgument",option);
4049 if (IsGeometry(argv[i]) == MagickFalse)
4050 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4051 break;
4052 }
4053 if (LocaleCompare("colorspace",option+1) == 0)
4054 {
cristybb503372010-05-27 20:51:26 +00004055 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004056 colorspace;
4057
4058 if (*option == '+')
4059 break;
4060 i++;
cristybb503372010-05-27 20:51:26 +00004061 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004062 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004063 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004064 argv[i]);
4065 if (colorspace < 0)
4066 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4067 argv[i]);
4068 break;
4069 }
4070 if (LocaleCompare("combine",option+1) == 0)
4071 break;
4072 if (LocaleCompare("comment",option+1) == 0)
4073 {
4074 if (*option == '+')
4075 break;
4076 i++;
cristybb503372010-05-27 20:51:26 +00004077 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004078 ThrowMogrifyException(OptionError,"MissingArgument",option);
4079 break;
4080 }
4081 if (LocaleCompare("composite",option+1) == 0)
4082 break;
4083 if (LocaleCompare("compress",option+1) == 0)
4084 {
cristybb503372010-05-27 20:51:26 +00004085 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004086 compress;
4087
4088 if (*option == '+')
4089 break;
4090 i++;
cristybb503372010-05-27 20:51:26 +00004091 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004092 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004093 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004094 argv[i]);
4095 if (compress < 0)
4096 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4097 argv[i]);
4098 break;
4099 }
cristy22879752009-10-25 23:55:40 +00004100 if (LocaleCompare("concurrent",option+1) == 0)
4101 break;
cristy3ed852e2009-09-05 21:47:34 +00004102 if (LocaleCompare("contrast",option+1) == 0)
4103 break;
4104 if (LocaleCompare("contrast-stretch",option+1) == 0)
4105 {
4106 i++;
cristybb503372010-05-27 20:51:26 +00004107 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004108 ThrowMogrifyException(OptionError,"MissingArgument",option);
4109 if (IsGeometry(argv[i]) == MagickFalse)
4110 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4111 break;
4112 }
4113 if (LocaleCompare("convolve",option+1) == 0)
4114 {
cristyb6bd4ad2010-08-08 01:12:27 +00004115 KernelInfo
4116 *kernel_info;
4117
cristy3ed852e2009-09-05 21:47:34 +00004118 if (*option == '+')
4119 break;
4120 i++;
cristybb503372010-05-27 20:51:26 +00004121 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004122 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004123 kernel_info=AcquireKernelInfo(argv[i]);
4124 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004125 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004126 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004127 break;
4128 }
4129 if (LocaleCompare("crop",option+1) == 0)
4130 {
4131 if (*option == '+')
4132 break;
4133 i++;
cristybb503372010-05-27 20:51:26 +00004134 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004135 ThrowMogrifyException(OptionError,"MissingArgument",option);
4136 if (IsGeometry(argv[i]) == MagickFalse)
4137 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4138 break;
4139 }
4140 if (LocaleCompare("cycle",option+1) == 0)
4141 {
4142 if (*option == '+')
4143 break;
4144 i++;
cristybb503372010-05-27 20:51:26 +00004145 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004146 ThrowMogrifyException(OptionError,"MissingArgument",option);
4147 if (IsGeometry(argv[i]) == MagickFalse)
4148 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4149 break;
4150 }
4151 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4152 }
4153 case 'd':
4154 {
4155 if (LocaleCompare("decipher",option+1) == 0)
4156 {
4157 if (*option == '+')
4158 break;
4159 i++;
cristybb503372010-05-27 20:51:26 +00004160 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004161 ThrowMogrifyException(OptionError,"MissingArgument",option);
4162 break;
4163 }
4164 if (LocaleCompare("deconstruct",option+1) == 0)
4165 break;
4166 if (LocaleCompare("debug",option+1) == 0)
4167 {
cristybb503372010-05-27 20:51:26 +00004168 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004169 event;
4170
4171 if (*option == '+')
4172 break;
4173 i++;
cristybb503372010-05-27 20:51:26 +00004174 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004175 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004176 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004177 if (event < 0)
4178 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4179 argv[i]);
4180 (void) SetLogEventMask(argv[i]);
4181 break;
4182 }
4183 if (LocaleCompare("define",option+1) == 0)
4184 {
4185 i++;
cristybb503372010-05-27 20:51:26 +00004186 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004187 ThrowMogrifyException(OptionError,"MissingArgument",option);
4188 if (*option == '+')
4189 {
4190 const char
4191 *define;
4192
4193 define=GetImageOption(image_info,argv[i]);
4194 if (define == (const char *) NULL)
4195 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4196 break;
4197 }
4198 break;
4199 }
4200 if (LocaleCompare("delay",option+1) == 0)
4201 {
4202 if (*option == '+')
4203 break;
4204 i++;
cristybb503372010-05-27 20:51:26 +00004205 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004206 ThrowMogrifyException(OptionError,"MissingArgument",option);
4207 if (IsGeometry(argv[i]) == MagickFalse)
4208 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4209 break;
4210 }
cristyecb10ff2011-03-22 13:14:03 +00004211 if (LocaleCompare("delete",option+1) == 0)
4212 {
4213 if (*option == '+')
4214 break;
4215 i++;
4216 if (i == (ssize_t) (argc-1))
4217 ThrowMogrifyException(OptionError,"MissingArgument",option);
4218 if (IsGeometry(argv[i]) == MagickFalse)
4219 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4220 break;
4221 }
cristy3ed852e2009-09-05 21:47:34 +00004222 if (LocaleCompare("density",option+1) == 0)
4223 {
4224 if (*option == '+')
4225 break;
4226 i++;
cristybb503372010-05-27 20:51:26 +00004227 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004228 ThrowMogrifyException(OptionError,"MissingArgument",option);
4229 if (IsGeometry(argv[i]) == MagickFalse)
4230 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4231 break;
4232 }
4233 if (LocaleCompare("depth",option+1) == 0)
4234 {
4235 if (*option == '+')
4236 break;
4237 i++;
cristybb503372010-05-27 20:51:26 +00004238 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004239 ThrowMogrifyException(OptionError,"MissingArgument",option);
4240 if (IsGeometry(argv[i]) == MagickFalse)
4241 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4242 break;
4243 }
4244 if (LocaleCompare("deskew",option+1) == 0)
4245 {
4246 if (*option == '+')
4247 break;
4248 i++;
cristybb503372010-05-27 20:51:26 +00004249 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004250 ThrowMogrifyException(OptionError,"MissingArgument",option);
4251 if (IsGeometry(argv[i]) == MagickFalse)
4252 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4253 break;
4254 }
4255 if (LocaleCompare("despeckle",option+1) == 0)
4256 break;
4257 if (LocaleCompare("dft",option+1) == 0)
4258 break;
cristyc9b12952010-03-28 01:12:28 +00004259 if (LocaleCompare("direction",option+1) == 0)
4260 {
cristybb503372010-05-27 20:51:26 +00004261 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004262 direction;
4263
4264 if (*option == '+')
4265 break;
4266 i++;
cristybb503372010-05-27 20:51:26 +00004267 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004268 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004269 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004270 argv[i]);
4271 if (direction < 0)
4272 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4273 argv[i]);
4274 break;
4275 }
cristy3ed852e2009-09-05 21:47:34 +00004276 if (LocaleCompare("display",option+1) == 0)
4277 {
4278 if (*option == '+')
4279 break;
4280 i++;
cristybb503372010-05-27 20:51:26 +00004281 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004282 ThrowMogrifyException(OptionError,"MissingArgument",option);
4283 break;
4284 }
4285 if (LocaleCompare("dispose",option+1) == 0)
4286 {
cristybb503372010-05-27 20:51:26 +00004287 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004288 dispose;
4289
4290 if (*option == '+')
4291 break;
4292 i++;
cristybb503372010-05-27 20:51:26 +00004293 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004294 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004295 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004296 if (dispose < 0)
4297 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4298 argv[i]);
4299 break;
4300 }
4301 if (LocaleCompare("distort",option+1) == 0)
4302 {
cristybb503372010-05-27 20:51:26 +00004303 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004304 op;
4305
4306 i++;
cristybb503372010-05-27 20:51:26 +00004307 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004308 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004309 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004310 if (op < 0)
4311 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4312 argv[i]);
4313 i++;
cristybb503372010-05-27 20:51:26 +00004314 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004315 ThrowMogrifyException(OptionError,"MissingArgument",option);
4316 break;
4317 }
4318 if (LocaleCompare("dither",option+1) == 0)
4319 {
cristybb503372010-05-27 20:51:26 +00004320 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004321 method;
4322
4323 if (*option == '+')
4324 break;
4325 i++;
cristybb503372010-05-27 20:51:26 +00004326 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004327 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004328 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004329 if (method < 0)
4330 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4331 argv[i]);
4332 break;
4333 }
4334 if (LocaleCompare("draw",option+1) == 0)
4335 {
4336 if (*option == '+')
4337 break;
4338 i++;
cristybb503372010-05-27 20:51:26 +00004339 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004340 ThrowMogrifyException(OptionError,"MissingArgument",option);
4341 break;
4342 }
cristyecb10ff2011-03-22 13:14:03 +00004343 if (LocaleCompare("duplicate",option+1) == 0)
4344 {
4345 if (*option == '+')
4346 break;
4347 i++;
4348 if (i == (ssize_t) (argc-1))
4349 ThrowMogrifyException(OptionError,"MissingArgument",option);
4350 if (IsGeometry(argv[i]) == MagickFalse)
4351 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4352 break;
4353 }
cristy22879752009-10-25 23:55:40 +00004354 if (LocaleCompare("duration",option+1) == 0)
4355 {
4356 if (*option == '+')
4357 break;
4358 i++;
cristybb503372010-05-27 20:51:26 +00004359 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004360 ThrowMogrifyException(OptionError,"MissingArgument",option);
4361 if (IsGeometry(argv[i]) == MagickFalse)
4362 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4363 break;
4364 }
cristy3ed852e2009-09-05 21:47:34 +00004365 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4366 }
4367 case 'e':
4368 {
4369 if (LocaleCompare("edge",option+1) == 0)
4370 {
4371 if (*option == '+')
4372 break;
4373 i++;
cristybb503372010-05-27 20:51:26 +00004374 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004375 ThrowMogrifyException(OptionError,"MissingArgument",option);
4376 if (IsGeometry(argv[i]) == MagickFalse)
4377 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4378 break;
4379 }
4380 if (LocaleCompare("emboss",option+1) == 0)
4381 {
4382 if (*option == '+')
4383 break;
4384 i++;
cristybb503372010-05-27 20:51:26 +00004385 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004386 ThrowMogrifyException(OptionError,"MissingArgument",option);
4387 if (IsGeometry(argv[i]) == MagickFalse)
4388 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4389 break;
4390 }
4391 if (LocaleCompare("encipher",option+1) == 0)
4392 {
4393 if (*option == '+')
4394 break;
4395 i++;
cristybb503372010-05-27 20:51:26 +00004396 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004397 ThrowMogrifyException(OptionError,"MissingArgument",option);
4398 break;
4399 }
4400 if (LocaleCompare("encoding",option+1) == 0)
4401 {
4402 if (*option == '+')
4403 break;
4404 i++;
cristybb503372010-05-27 20:51:26 +00004405 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004406 ThrowMogrifyException(OptionError,"MissingArgument",option);
4407 break;
4408 }
4409 if (LocaleCompare("endian",option+1) == 0)
4410 {
cristybb503372010-05-27 20:51:26 +00004411 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004412 endian;
4413
4414 if (*option == '+')
4415 break;
4416 i++;
cristybb503372010-05-27 20:51:26 +00004417 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004418 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004419 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004420 if (endian < 0)
4421 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4422 argv[i]);
4423 break;
4424 }
4425 if (LocaleCompare("enhance",option+1) == 0)
4426 break;
4427 if (LocaleCompare("equalize",option+1) == 0)
4428 break;
4429 if (LocaleCompare("evaluate",option+1) == 0)
4430 {
cristybb503372010-05-27 20:51:26 +00004431 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004432 op;
4433
4434 if (*option == '+')
4435 break;
4436 i++;
cristybb503372010-05-27 20:51:26 +00004437 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004438 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004439 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004440 if (op < 0)
4441 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4442 argv[i]);
4443 i++;
cristybb503372010-05-27 20:51:26 +00004444 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004445 ThrowMogrifyException(OptionError,"MissingArgument",option);
4446 if (IsGeometry(argv[i]) == MagickFalse)
4447 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4448 break;
4449 }
cristyd18ae7c2010-03-07 17:39:52 +00004450 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4451 {
cristybb503372010-05-27 20:51:26 +00004452 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004453 op;
4454
4455 if (*option == '+')
4456 break;
4457 i++;
cristybb503372010-05-27 20:51:26 +00004458 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004459 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004460 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004461 if (op < 0)
4462 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4463 argv[i]);
4464 break;
4465 }
cristy3ed852e2009-09-05 21:47:34 +00004466 if (LocaleCompare("extent",option+1) == 0)
4467 {
4468 if (*option == '+')
4469 break;
4470 i++;
cristybb503372010-05-27 20:51:26 +00004471 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004472 ThrowMogrifyException(OptionError,"MissingArgument",option);
4473 if (IsGeometry(argv[i]) == MagickFalse)
4474 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4475 break;
4476 }
4477 if (LocaleCompare("extract",option+1) == 0)
4478 {
4479 if (*option == '+')
4480 break;
4481 i++;
cristybb503372010-05-27 20:51:26 +00004482 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004483 ThrowMogrifyException(OptionError,"MissingArgument",option);
4484 if (IsGeometry(argv[i]) == MagickFalse)
4485 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4486 break;
4487 }
4488 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4489 }
4490 case 'f':
4491 {
4492 if (LocaleCompare("family",option+1) == 0)
4493 {
4494 if (*option == '+')
4495 break;
4496 i++;
cristybb503372010-05-27 20:51:26 +00004497 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004498 ThrowMogrifyException(OptionError,"MissingArgument",option);
4499 break;
4500 }
4501 if (LocaleCompare("fill",option+1) == 0)
4502 {
4503 if (*option == '+')
4504 break;
4505 i++;
cristybb503372010-05-27 20:51:26 +00004506 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004507 ThrowMogrifyException(OptionError,"MissingArgument",option);
4508 break;
4509 }
4510 if (LocaleCompare("filter",option+1) == 0)
4511 {
cristybb503372010-05-27 20:51:26 +00004512 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004513 filter;
4514
4515 if (*option == '+')
4516 break;
4517 i++;
cristybb503372010-05-27 20:51:26 +00004518 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004519 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004520 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004521 if (filter < 0)
4522 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4523 argv[i]);
4524 break;
4525 }
4526 if (LocaleCompare("flatten",option+1) == 0)
4527 break;
4528 if (LocaleCompare("flip",option+1) == 0)
4529 break;
4530 if (LocaleCompare("flop",option+1) == 0)
4531 break;
4532 if (LocaleCompare("floodfill",option+1) == 0)
4533 {
4534 if (*option == '+')
4535 break;
4536 i++;
cristybb503372010-05-27 20:51:26 +00004537 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004538 ThrowMogrifyException(OptionError,"MissingArgument",option);
4539 if (IsGeometry(argv[i]) == MagickFalse)
4540 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4541 i++;
cristybb503372010-05-27 20:51:26 +00004542 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004543 ThrowMogrifyException(OptionError,"MissingArgument",option);
4544 break;
4545 }
4546 if (LocaleCompare("font",option+1) == 0)
4547 {
4548 if (*option == '+')
4549 break;
4550 i++;
cristybb503372010-05-27 20:51:26 +00004551 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004552 ThrowMogrifyException(OptionError,"MissingArgument",option);
4553 break;
4554 }
4555 if (LocaleCompare("format",option+1) == 0)
4556 {
4557 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4558 (void) CloneString(&format,(char *) NULL);
4559 if (*option == '+')
4560 break;
4561 i++;
cristybb503372010-05-27 20:51:26 +00004562 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004563 ThrowMogrifyException(OptionError,"MissingArgument",option);
4564 (void) CloneString(&format,argv[i]);
4565 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4566 (void) ConcatenateMagickString(image_info->filename,":",
4567 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004568 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004569 if (*image_info->magick == '\0')
4570 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4571 format);
4572 break;
4573 }
4574 if (LocaleCompare("frame",option+1) == 0)
4575 {
4576 if (*option == '+')
4577 break;
4578 i++;
cristybb503372010-05-27 20:51:26 +00004579 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004580 ThrowMogrifyException(OptionError,"MissingArgument",option);
4581 if (IsGeometry(argv[i]) == MagickFalse)
4582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4583 break;
4584 }
4585 if (LocaleCompare("function",option+1) == 0)
4586 {
cristybb503372010-05-27 20:51:26 +00004587 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004588 op;
4589
4590 if (*option == '+')
4591 break;
4592 i++;
cristybb503372010-05-27 20:51:26 +00004593 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004594 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004595 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004596 if (op < 0)
4597 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4598 i++;
cristybb503372010-05-27 20:51:26 +00004599 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004600 ThrowMogrifyException(OptionError,"MissingArgument",option);
4601 break;
4602 }
4603 if (LocaleCompare("fuzz",option+1) == 0)
4604 {
4605 if (*option == '+')
4606 break;
4607 i++;
cristybb503372010-05-27 20:51:26 +00004608 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004609 ThrowMogrifyException(OptionError,"MissingArgument",option);
4610 if (IsGeometry(argv[i]) == MagickFalse)
4611 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4612 break;
4613 }
4614 if (LocaleCompare("fx",option+1) == 0)
4615 {
4616 if (*option == '+')
4617 break;
4618 i++;
cristybb503372010-05-27 20:51:26 +00004619 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004620 ThrowMogrifyException(OptionError,"MissingArgument",option);
4621 break;
4622 }
4623 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4624 }
4625 case 'g':
4626 {
4627 if (LocaleCompare("gamma",option+1) == 0)
4628 {
4629 i++;
cristybb503372010-05-27 20:51:26 +00004630 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004631 ThrowMogrifyException(OptionError,"MissingArgument",option);
4632 if (IsGeometry(argv[i]) == MagickFalse)
4633 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4634 break;
4635 }
4636 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4637 (LocaleCompare("gaussian",option+1) == 0))
4638 {
4639 i++;
cristybb503372010-05-27 20:51:26 +00004640 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004641 ThrowMogrifyException(OptionError,"MissingArgument",option);
4642 if (IsGeometry(argv[i]) == MagickFalse)
4643 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4644 break;
4645 }
4646 if (LocaleCompare("geometry",option+1) == 0)
4647 {
4648 if (*option == '+')
4649 break;
4650 i++;
cristybb503372010-05-27 20:51:26 +00004651 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004652 ThrowMogrifyException(OptionError,"MissingArgument",option);
4653 if (IsGeometry(argv[i]) == MagickFalse)
4654 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4655 break;
4656 }
4657 if (LocaleCompare("gravity",option+1) == 0)
4658 {
cristybb503372010-05-27 20:51:26 +00004659 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004660 gravity;
4661
4662 if (*option == '+')
4663 break;
4664 i++;
cristybb503372010-05-27 20:51:26 +00004665 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004666 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004667 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004668 if (gravity < 0)
4669 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4670 argv[i]);
4671 break;
4672 }
4673 if (LocaleCompare("green-primary",option+1) == 0)
4674 {
4675 if (*option == '+')
4676 break;
4677 i++;
cristybb503372010-05-27 20:51:26 +00004678 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004679 ThrowMogrifyException(OptionError,"MissingArgument",option);
4680 if (IsGeometry(argv[i]) == MagickFalse)
4681 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4682 break;
4683 }
4684 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4685 }
4686 case 'h':
4687 {
4688 if (LocaleCompare("hald-clut",option+1) == 0)
4689 break;
4690 if ((LocaleCompare("help",option+1) == 0) ||
4691 (LocaleCompare("-help",option+1) == 0))
4692 return(MogrifyUsage());
4693 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4694 }
4695 case 'i':
4696 {
4697 if (LocaleCompare("identify",option+1) == 0)
4698 break;
4699 if (LocaleCompare("idft",option+1) == 0)
4700 break;
4701 if (LocaleCompare("implode",option+1) == 0)
4702 {
4703 if (*option == '+')
4704 break;
4705 i++;
cristybb503372010-05-27 20:51:26 +00004706 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004707 ThrowMogrifyException(OptionError,"MissingArgument",option);
4708 if (IsGeometry(argv[i]) == MagickFalse)
4709 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4710 break;
4711 }
4712 if (LocaleCompare("intent",option+1) == 0)
4713 {
cristybb503372010-05-27 20:51:26 +00004714 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004715 intent;
4716
4717 if (*option == '+')
4718 break;
4719 i++;
cristybb503372010-05-27 20:51:26 +00004720 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004721 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004722 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004723 if (intent < 0)
4724 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4725 argv[i]);
4726 break;
4727 }
4728 if (LocaleCompare("interlace",option+1) == 0)
4729 {
cristybb503372010-05-27 20:51:26 +00004730 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004731 interlace;
4732
4733 if (*option == '+')
4734 break;
4735 i++;
cristybb503372010-05-27 20:51:26 +00004736 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004737 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004738 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004739 argv[i]);
4740 if (interlace < 0)
4741 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4742 argv[i]);
4743 break;
4744 }
cristyb32b90a2009-09-07 21:45:48 +00004745 if (LocaleCompare("interline-spacing",option+1) == 0)
4746 {
4747 if (*option == '+')
4748 break;
4749 i++;
cristybb503372010-05-27 20:51:26 +00004750 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004751 ThrowMogrifyException(OptionError,"MissingArgument",option);
4752 if (IsGeometry(argv[i]) == MagickFalse)
4753 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4754 break;
4755 }
cristy3ed852e2009-09-05 21:47:34 +00004756 if (LocaleCompare("interpolate",option+1) == 0)
4757 {
cristybb503372010-05-27 20:51:26 +00004758 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004759 interpolate;
4760
4761 if (*option == '+')
4762 break;
4763 i++;
cristybb503372010-05-27 20:51:26 +00004764 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004765 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004766 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004767 argv[i]);
4768 if (interpolate < 0)
4769 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4770 argv[i]);
4771 break;
4772 }
4773 if (LocaleCompare("interword-spacing",option+1) == 0)
4774 {
4775 if (*option == '+')
4776 break;
4777 i++;
cristybb503372010-05-27 20:51:26 +00004778 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004779 ThrowMogrifyException(OptionError,"MissingArgument",option);
4780 if (IsGeometry(argv[i]) == MagickFalse)
4781 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4782 break;
4783 }
4784 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4785 }
4786 case 'k':
4787 {
4788 if (LocaleCompare("kerning",option+1) == 0)
4789 {
4790 if (*option == '+')
4791 break;
4792 i++;
cristybb503372010-05-27 20:51:26 +00004793 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004794 ThrowMogrifyException(OptionError,"MissingArgument",option);
4795 if (IsGeometry(argv[i]) == MagickFalse)
4796 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4797 break;
4798 }
4799 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4800 }
4801 case 'l':
4802 {
4803 if (LocaleCompare("label",option+1) == 0)
4804 {
4805 if (*option == '+')
4806 break;
4807 i++;
cristybb503372010-05-27 20:51:26 +00004808 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004809 ThrowMogrifyException(OptionError,"MissingArgument",option);
4810 break;
4811 }
4812 if (LocaleCompare("lat",option+1) == 0)
4813 {
4814 if (*option == '+')
4815 break;
4816 i++;
cristybb503372010-05-27 20:51:26 +00004817 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004818 ThrowMogrifyException(OptionError,"MissingArgument",option);
4819 if (IsGeometry(argv[i]) == MagickFalse)
4820 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4821 }
4822 if (LocaleCompare("layers",option+1) == 0)
4823 {
cristybb503372010-05-27 20:51:26 +00004824 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004825 type;
4826
4827 if (*option == '+')
4828 break;
4829 i++;
cristybb503372010-05-27 20:51:26 +00004830 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004831 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004832 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004833 if (type < 0)
4834 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4835 argv[i]);
4836 break;
4837 }
4838 if (LocaleCompare("level",option+1) == 0)
4839 {
4840 i++;
cristybb503372010-05-27 20:51:26 +00004841 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004842 ThrowMogrifyException(OptionError,"MissingArgument",option);
4843 if (IsGeometry(argv[i]) == MagickFalse)
4844 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4845 break;
4846 }
4847 if (LocaleCompare("level-colors",option+1) == 0)
4848 {
4849 i++;
cristybb503372010-05-27 20:51:26 +00004850 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004851 ThrowMogrifyException(OptionError,"MissingArgument",option);
4852 break;
4853 }
4854 if (LocaleCompare("linewidth",option+1) == 0)
4855 {
4856 if (*option == '+')
4857 break;
4858 i++;
cristybb503372010-05-27 20:51:26 +00004859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004860 ThrowMogrifyException(OptionError,"MissingArgument",option);
4861 if (IsGeometry(argv[i]) == MagickFalse)
4862 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4863 break;
4864 }
4865 if (LocaleCompare("limit",option+1) == 0)
4866 {
4867 char
4868 *p;
4869
4870 double
4871 value;
4872
cristybb503372010-05-27 20:51:26 +00004873 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004874 resource;
4875
4876 if (*option == '+')
4877 break;
4878 i++;
cristybb503372010-05-27 20:51:26 +00004879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004880 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004881 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004882 argv[i]);
4883 if (resource < 0)
4884 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4885 argv[i]);
4886 i++;
cristybb503372010-05-27 20:51:26 +00004887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004888 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004889 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004890 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004891 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4892 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4893 break;
4894 }
4895 if (LocaleCompare("liquid-rescale",option+1) == 0)
4896 {
4897 i++;
cristybb503372010-05-27 20:51:26 +00004898 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004899 ThrowMogrifyException(OptionError,"MissingArgument",option);
4900 if (IsGeometry(argv[i]) == MagickFalse)
4901 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4902 break;
4903 }
4904 if (LocaleCompare("list",option+1) == 0)
4905 {
cristybb503372010-05-27 20:51:26 +00004906 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004907 list;
4908
4909 if (*option == '+')
4910 break;
4911 i++;
cristybb503372010-05-27 20:51:26 +00004912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004913 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004914 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004915 if (list < 0)
4916 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004917 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004918 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004919 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004920 }
4921 if (LocaleCompare("log",option+1) == 0)
4922 {
4923 if (*option == '+')
4924 break;
4925 i++;
cristybb503372010-05-27 20:51:26 +00004926 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004927 (strchr(argv[i],'%') == (char *) NULL))
4928 ThrowMogrifyException(OptionError,"MissingArgument",option);
4929 break;
4930 }
4931 if (LocaleCompare("loop",option+1) == 0)
4932 {
4933 if (*option == '+')
4934 break;
4935 i++;
cristybb503372010-05-27 20:51:26 +00004936 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004937 ThrowMogrifyException(OptionError,"MissingArgument",option);
4938 if (IsGeometry(argv[i]) == MagickFalse)
4939 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4940 break;
4941 }
4942 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4943 }
4944 case 'm':
4945 {
4946 if (LocaleCompare("map",option+1) == 0)
4947 {
4948 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4949 if (*option == '+')
4950 break;
4951 i++;
cristybb503372010-05-27 20:51:26 +00004952 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004953 ThrowMogrifyException(OptionError,"MissingArgument",option);
4954 break;
4955 }
4956 if (LocaleCompare("mask",option+1) == 0)
4957 {
4958 if (*option == '+')
4959 break;
4960 i++;
cristybb503372010-05-27 20:51:26 +00004961 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004962 ThrowMogrifyException(OptionError,"MissingArgument",option);
4963 break;
4964 }
4965 if (LocaleCompare("matte",option+1) == 0)
4966 break;
4967 if (LocaleCompare("mattecolor",option+1) == 0)
4968 {
4969 if (*option == '+')
4970 break;
4971 i++;
cristybb503372010-05-27 20:51:26 +00004972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004973 ThrowMogrifyException(OptionError,"MissingArgument",option);
4974 break;
4975 }
cristyf40785b2010-03-06 02:27:27 +00004976 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004977 break;
cristyf40785b2010-03-06 02:27:27 +00004978 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004979 break;
cristy3ed852e2009-09-05 21:47:34 +00004980 if (LocaleCompare("modulate",option+1) == 0)
4981 {
4982 if (*option == '+')
4983 break;
4984 i++;
cristybb503372010-05-27 20:51:26 +00004985 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004986 ThrowMogrifyException(OptionError,"MissingArgument",option);
4987 if (IsGeometry(argv[i]) == MagickFalse)
4988 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4989 break;
4990 }
4991 if (LocaleCompare("median",option+1) == 0)
4992 {
4993 if (*option == '+')
4994 break;
4995 i++;
cristybb503372010-05-27 20:51:26 +00004996 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004997 ThrowMogrifyException(OptionError,"MissingArgument",option);
4998 if (IsGeometry(argv[i]) == MagickFalse)
4999 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5000 break;
5001 }
cristy69ec32d2011-02-27 23:57:09 +00005002 if (LocaleCompare("mode",option+1) == 0)
5003 {
5004 if (*option == '+')
5005 break;
5006 i++;
5007 if (i == (ssize_t) argc)
5008 ThrowMogrifyException(OptionError,"MissingArgument",option);
5009 if (IsGeometry(argv[i]) == MagickFalse)
5010 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5011 break;
5012 }
cristy3ed852e2009-09-05 21:47:34 +00005013 if (LocaleCompare("monitor",option+1) == 0)
5014 break;
5015 if (LocaleCompare("monochrome",option+1) == 0)
5016 break;
5017 if (LocaleCompare("morph",option+1) == 0)
5018 {
5019 if (*option == '+')
5020 break;
5021 i++;
cristybb503372010-05-27 20:51:26 +00005022 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005023 ThrowMogrifyException(OptionError,"MissingArgument",option);
5024 if (IsGeometry(argv[i]) == MagickFalse)
5025 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5026 break;
5027 }
anthony29188a82010-01-22 10:12:34 +00005028 if (LocaleCompare("morphology",option+1) == 0)
5029 {
anthony29188a82010-01-22 10:12:34 +00005030 char
5031 token[MaxTextExtent];
5032
cristyb6bd4ad2010-08-08 01:12:27 +00005033 KernelInfo
5034 *kernel_info;
5035
5036 ssize_t
5037 op;
5038
anthony29188a82010-01-22 10:12:34 +00005039 i++;
cristybb503372010-05-27 20:51:26 +00005040 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005041 ThrowMogrifyException(OptionError,"MissingArgument",option);
5042 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005043 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005044 if (op < 0)
5045 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005046 token);
anthony29188a82010-01-22 10:12:34 +00005047 i++;
cristybb503372010-05-27 20:51:26 +00005048 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005049 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005050 kernel_info=AcquireKernelInfo(argv[i]);
5051 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005052 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005053 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005054 break;
5055 }
cristy3ed852e2009-09-05 21:47:34 +00005056 if (LocaleCompare("mosaic",option+1) == 0)
5057 break;
5058 if (LocaleCompare("motion-blur",option+1) == 0)
5059 {
5060 if (*option == '+')
5061 break;
5062 i++;
cristybb503372010-05-27 20:51:26 +00005063 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005064 ThrowMogrifyException(OptionError,"MissingArgument",option);
5065 if (IsGeometry(argv[i]) == MagickFalse)
5066 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5067 break;
5068 }
5069 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5070 }
5071 case 'n':
5072 {
5073 if (LocaleCompare("negate",option+1) == 0)
5074 break;
5075 if (LocaleCompare("noise",option+1) == 0)
5076 {
5077 i++;
cristybb503372010-05-27 20:51:26 +00005078 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005079 ThrowMogrifyException(OptionError,"MissingArgument",option);
5080 if (*option == '+')
5081 {
cristybb503372010-05-27 20:51:26 +00005082 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005083 noise;
5084
cristy042ee782011-04-22 18:48:30 +00005085 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005086 if (noise < 0)
5087 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5088 argv[i]);
5089 break;
5090 }
5091 if (IsGeometry(argv[i]) == MagickFalse)
5092 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5093 break;
5094 }
5095 if (LocaleCompare("noop",option+1) == 0)
5096 break;
5097 if (LocaleCompare("normalize",option+1) == 0)
5098 break;
5099 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5100 }
5101 case 'o':
5102 {
5103 if (LocaleCompare("opaque",option+1) == 0)
5104 {
cristy3ed852e2009-09-05 21:47:34 +00005105 i++;
cristybb503372010-05-27 20:51:26 +00005106 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005107 ThrowMogrifyException(OptionError,"MissingArgument",option);
5108 break;
5109 }
5110 if (LocaleCompare("ordered-dither",option+1) == 0)
5111 {
5112 if (*option == '+')
5113 break;
5114 i++;
cristybb503372010-05-27 20:51:26 +00005115 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005116 ThrowMogrifyException(OptionError,"MissingArgument",option);
5117 break;
5118 }
5119 if (LocaleCompare("orient",option+1) == 0)
5120 {
cristybb503372010-05-27 20:51:26 +00005121 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005122 orientation;
5123
5124 orientation=UndefinedOrientation;
5125 if (*option == '+')
5126 break;
5127 i++;
cristybb503372010-05-27 20:51:26 +00005128 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005129 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005130 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005131 argv[i]);
5132 if (orientation < 0)
5133 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5134 argv[i]);
5135 break;
5136 }
5137 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5138 }
5139 case 'p':
5140 {
5141 if (LocaleCompare("page",option+1) == 0)
5142 {
5143 if (*option == '+')
5144 break;
5145 i++;
cristybb503372010-05-27 20:51:26 +00005146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005147 ThrowMogrifyException(OptionError,"MissingArgument",option);
5148 break;
5149 }
5150 if (LocaleCompare("paint",option+1) == 0)
5151 {
5152 if (*option == '+')
5153 break;
5154 i++;
cristybb503372010-05-27 20:51:26 +00005155 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005156 ThrowMogrifyException(OptionError,"MissingArgument",option);
5157 if (IsGeometry(argv[i]) == MagickFalse)
5158 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5159 break;
5160 }
5161 if (LocaleCompare("path",option+1) == 0)
5162 {
5163 (void) CloneString(&path,(char *) NULL);
5164 if (*option == '+')
5165 break;
5166 i++;
cristybb503372010-05-27 20:51:26 +00005167 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005168 ThrowMogrifyException(OptionError,"MissingArgument",option);
5169 (void) CloneString(&path,argv[i]);
5170 break;
5171 }
5172 if (LocaleCompare("pointsize",option+1) == 0)
5173 {
5174 if (*option == '+')
5175 break;
5176 i++;
cristybb503372010-05-27 20:51:26 +00005177 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005178 ThrowMogrifyException(OptionError,"MissingArgument",option);
5179 if (IsGeometry(argv[i]) == MagickFalse)
5180 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5181 break;
5182 }
5183 if (LocaleCompare("polaroid",option+1) == 0)
5184 {
5185 if (*option == '+')
5186 break;
5187 i++;
cristybb503372010-05-27 20:51:26 +00005188 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005189 ThrowMogrifyException(OptionError,"MissingArgument",option);
5190 if (IsGeometry(argv[i]) == MagickFalse)
5191 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5192 break;
5193 }
5194 if (LocaleCompare("posterize",option+1) == 0)
5195 {
5196 if (*option == '+')
5197 break;
5198 i++;
cristybb503372010-05-27 20:51:26 +00005199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005200 ThrowMogrifyException(OptionError,"MissingArgument",option);
5201 if (IsGeometry(argv[i]) == MagickFalse)
5202 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5203 break;
5204 }
cristye7f51092010-01-17 00:39:37 +00005205 if (LocaleCompare("precision",option+1) == 0)
5206 {
5207 if (*option == '+')
5208 break;
5209 i++;
cristybb503372010-05-27 20:51:26 +00005210 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005211 ThrowMogrifyException(OptionError,"MissingArgument",option);
5212 if (IsGeometry(argv[i]) == MagickFalse)
5213 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5214 break;
5215 }
cristy3ed852e2009-09-05 21:47:34 +00005216 if (LocaleCompare("print",option+1) == 0)
5217 {
5218 if (*option == '+')
5219 break;
5220 i++;
cristybb503372010-05-27 20:51:26 +00005221 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005222 ThrowMogrifyException(OptionError,"MissingArgument",option);
5223 break;
5224 }
5225 if (LocaleCompare("process",option+1) == 0)
5226 {
5227 if (*option == '+')
5228 break;
5229 i++;
cristybb503372010-05-27 20:51:26 +00005230 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005231 ThrowMogrifyException(OptionError,"MissingArgument",option);
5232 break;
5233 }
5234 if (LocaleCompare("profile",option+1) == 0)
5235 {
5236 i++;
cristybb503372010-05-27 20:51:26 +00005237 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005238 ThrowMogrifyException(OptionError,"MissingArgument",option);
5239 break;
5240 }
5241 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5242 }
5243 case 'q':
5244 {
5245 if (LocaleCompare("quality",option+1) == 0)
5246 {
5247 if (*option == '+')
5248 break;
5249 i++;
cristybb503372010-05-27 20:51:26 +00005250 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005251 ThrowMogrifyException(OptionError,"MissingArgument",option);
5252 if (IsGeometry(argv[i]) == MagickFalse)
5253 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5254 break;
5255 }
5256 if (LocaleCompare("quantize",option+1) == 0)
5257 {
cristybb503372010-05-27 20:51:26 +00005258 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005259 colorspace;
5260
5261 if (*option == '+')
5262 break;
5263 i++;
cristybb503372010-05-27 20:51:26 +00005264 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005265 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005266 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005267 argv[i]);
5268 if (colorspace < 0)
5269 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5270 argv[i]);
5271 break;
5272 }
5273 if (LocaleCompare("quiet",option+1) == 0)
5274 break;
5275 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5276 }
5277 case 'r':
5278 {
5279 if (LocaleCompare("radial-blur",option+1) == 0)
5280 {
5281 i++;
cristybb503372010-05-27 20:51:26 +00005282 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005283 ThrowMogrifyException(OptionError,"MissingArgument",option);
5284 if (IsGeometry(argv[i]) == MagickFalse)
5285 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5286 break;
5287 }
5288 if (LocaleCompare("raise",option+1) == 0)
5289 {
5290 i++;
cristybb503372010-05-27 20:51:26 +00005291 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005292 ThrowMogrifyException(OptionError,"MissingArgument",option);
5293 if (IsGeometry(argv[i]) == MagickFalse)
5294 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5295 break;
5296 }
5297 if (LocaleCompare("random-threshold",option+1) == 0)
5298 {
5299 if (*option == '+')
5300 break;
5301 i++;
cristybb503372010-05-27 20:51:26 +00005302 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005303 ThrowMogrifyException(OptionError,"MissingArgument",option);
5304 if (IsGeometry(argv[i]) == MagickFalse)
5305 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5306 break;
5307 }
cristye6365592010-04-02 17:31:23 +00005308 if (LocaleCompare("recolor",option+1) == 0)
5309 {
5310 if (*option == '+')
5311 break;
5312 i++;
cristybb503372010-05-27 20:51:26 +00005313 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005314 ThrowMogrifyException(OptionError,"MissingArgument",option);
5315 if (IsGeometry(argv[i]) == MagickFalse)
5316 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5317 break;
5318 }
cristy3ed852e2009-09-05 21:47:34 +00005319 if (LocaleCompare("red-primary",option+1) == 0)
5320 {
5321 if (*option == '+')
5322 break;
5323 i++;
cristybb503372010-05-27 20:51:26 +00005324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005325 ThrowMogrifyException(OptionError,"MissingArgument",option);
5326 if (IsGeometry(argv[i]) == MagickFalse)
5327 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5328 }
cristy9f2083a2010-04-22 19:48:05 +00005329 if (LocaleCompare("regard-warnings",option+1) == 0)
5330 break;
cristy3ed852e2009-09-05 21:47:34 +00005331 if (LocaleCompare("region",option+1) == 0)
5332 {
5333 if (*option == '+')
5334 break;
5335 i++;
cristybb503372010-05-27 20:51:26 +00005336 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005337 ThrowMogrifyException(OptionError,"MissingArgument",option);
5338 if (IsGeometry(argv[i]) == MagickFalse)
5339 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5340 break;
5341 }
cristyf0c78232010-03-15 12:53:40 +00005342 if (LocaleCompare("remap",option+1) == 0)
5343 {
5344 if (*option == '+')
5345 break;
5346 i++;
cristybb503372010-05-27 20:51:26 +00005347 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005348 ThrowMogrifyException(OptionError,"MissingArgument",option);
5349 break;
5350 }
cristy3ed852e2009-09-05 21:47:34 +00005351 if (LocaleCompare("render",option+1) == 0)
5352 break;
5353 if (LocaleCompare("repage",option+1) == 0)
5354 {
5355 if (*option == '+')
5356 break;
5357 i++;
cristybb503372010-05-27 20:51:26 +00005358 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005359 ThrowMogrifyException(OptionError,"MissingArgument",option);
5360 if (IsGeometry(argv[i]) == MagickFalse)
5361 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5362 break;
5363 }
5364 if (LocaleCompare("resample",option+1) == 0)
5365 {
5366 if (*option == '+')
5367 break;
5368 i++;
cristybb503372010-05-27 20:51:26 +00005369 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005370 ThrowMogrifyException(OptionError,"MissingArgument",option);
5371 if (IsGeometry(argv[i]) == MagickFalse)
5372 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5373 break;
5374 }
5375 if (LocaleCompare("resize",option+1) == 0)
5376 {
5377 if (*option == '+')
5378 break;
5379 i++;
cristybb503372010-05-27 20:51:26 +00005380 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005381 ThrowMogrifyException(OptionError,"MissingArgument",option);
5382 if (IsGeometry(argv[i]) == MagickFalse)
5383 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5384 break;
5385 }
cristyebbcfea2011-02-25 02:43:54 +00005386 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5387 {
5388 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5389 break;
5390 }
cristy3ed852e2009-09-05 21:47:34 +00005391 if (LocaleCompare("reverse",option+1) == 0)
5392 break;
5393 if (LocaleCompare("roll",option+1) == 0)
5394 {
5395 if (*option == '+')
5396 break;
5397 i++;
cristybb503372010-05-27 20:51:26 +00005398 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005399 ThrowMogrifyException(OptionError,"MissingArgument",option);
5400 if (IsGeometry(argv[i]) == MagickFalse)
5401 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5402 break;
5403 }
5404 if (LocaleCompare("rotate",option+1) == 0)
5405 {
5406 i++;
cristybb503372010-05-27 20:51:26 +00005407 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005408 ThrowMogrifyException(OptionError,"MissingArgument",option);
5409 if (IsGeometry(argv[i]) == MagickFalse)
5410 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5411 break;
5412 }
5413 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5414 }
5415 case 's':
5416 {
5417 if (LocaleCompare("sample",option+1) == 0)
5418 {
5419 if (*option == '+')
5420 break;
5421 i++;
cristybb503372010-05-27 20:51:26 +00005422 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005423 ThrowMogrifyException(OptionError,"MissingArgument",option);
5424 if (IsGeometry(argv[i]) == MagickFalse)
5425 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5426 break;
5427 }
5428 if (LocaleCompare("sampling-factor",option+1) == 0)
5429 {
5430 if (*option == '+')
5431 break;
5432 i++;
cristybb503372010-05-27 20:51:26 +00005433 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005434 ThrowMogrifyException(OptionError,"MissingArgument",option);
5435 if (IsGeometry(argv[i]) == MagickFalse)
5436 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5437 break;
5438 }
5439 if (LocaleCompare("scale",option+1) == 0)
5440 {
5441 if (*option == '+')
5442 break;
5443 i++;
cristybb503372010-05-27 20:51:26 +00005444 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005445 ThrowMogrifyException(OptionError,"MissingArgument",option);
5446 if (IsGeometry(argv[i]) == MagickFalse)
5447 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5448 break;
5449 }
5450 if (LocaleCompare("scene",option+1) == 0)
5451 {
5452 if (*option == '+')
5453 break;
5454 i++;
cristybb503372010-05-27 20:51:26 +00005455 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005456 ThrowMogrifyException(OptionError,"MissingArgument",option);
5457 if (IsGeometry(argv[i]) == MagickFalse)
5458 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5459 break;
5460 }
5461 if (LocaleCompare("seed",option+1) == 0)
5462 {
5463 if (*option == '+')
5464 break;
5465 i++;
cristybb503372010-05-27 20:51:26 +00005466 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005467 ThrowMogrifyException(OptionError,"MissingArgument",option);
5468 if (IsGeometry(argv[i]) == MagickFalse)
5469 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5470 break;
5471 }
5472 if (LocaleCompare("segment",option+1) == 0)
5473 {
5474 if (*option == '+')
5475 break;
5476 i++;
cristybb503372010-05-27 20:51:26 +00005477 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005478 ThrowMogrifyException(OptionError,"MissingArgument",option);
5479 if (IsGeometry(argv[i]) == MagickFalse)
5480 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5481 break;
5482 }
5483 if (LocaleCompare("selective-blur",option+1) == 0)
5484 {
5485 i++;
cristybb503372010-05-27 20:51:26 +00005486 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005487 ThrowMogrifyException(OptionError,"MissingArgument",option);
5488 if (IsGeometry(argv[i]) == MagickFalse)
5489 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5490 break;
5491 }
5492 if (LocaleCompare("separate",option+1) == 0)
5493 break;
5494 if (LocaleCompare("sepia-tone",option+1) == 0)
5495 {
5496 if (*option == '+')
5497 break;
5498 i++;
cristybb503372010-05-27 20:51:26 +00005499 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005500 ThrowMogrifyException(OptionError,"MissingArgument",option);
5501 if (IsGeometry(argv[i]) == MagickFalse)
5502 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5503 break;
5504 }
5505 if (LocaleCompare("set",option+1) == 0)
5506 {
5507 i++;
cristybb503372010-05-27 20:51:26 +00005508 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005509 ThrowMogrifyException(OptionError,"MissingArgument",option);
5510 if (*option == '+')
5511 break;
5512 i++;
cristybb503372010-05-27 20:51:26 +00005513 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005514 ThrowMogrifyException(OptionError,"MissingArgument",option);
5515 break;
5516 }
5517 if (LocaleCompare("shade",option+1) == 0)
5518 {
5519 i++;
cristybb503372010-05-27 20:51:26 +00005520 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005521 ThrowMogrifyException(OptionError,"MissingArgument",option);
5522 if (IsGeometry(argv[i]) == MagickFalse)
5523 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5524 break;
5525 }
5526 if (LocaleCompare("shadow",option+1) == 0)
5527 {
5528 if (*option == '+')
5529 break;
5530 i++;
cristybb503372010-05-27 20:51:26 +00005531 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005532 ThrowMogrifyException(OptionError,"MissingArgument",option);
5533 if (IsGeometry(argv[i]) == MagickFalse)
5534 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5535 break;
5536 }
5537 if (LocaleCompare("sharpen",option+1) == 0)
5538 {
5539 i++;
cristybb503372010-05-27 20:51:26 +00005540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005541 ThrowMogrifyException(OptionError,"MissingArgument",option);
5542 if (IsGeometry(argv[i]) == MagickFalse)
5543 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5544 break;
5545 }
5546 if (LocaleCompare("shave",option+1) == 0)
5547 {
5548 if (*option == '+')
5549 break;
5550 i++;
cristybb503372010-05-27 20:51:26 +00005551 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005552 ThrowMogrifyException(OptionError,"MissingArgument",option);
5553 if (IsGeometry(argv[i]) == MagickFalse)
5554 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5555 break;
5556 }
5557 if (LocaleCompare("shear",option+1) == 0)
5558 {
5559 i++;
cristybb503372010-05-27 20:51:26 +00005560 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005561 ThrowMogrifyException(OptionError,"MissingArgument",option);
5562 if (IsGeometry(argv[i]) == MagickFalse)
5563 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5564 break;
5565 }
5566 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5567 {
5568 i++;
cristybb503372010-05-27 20:51:26 +00005569 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005570 ThrowMogrifyException(OptionError,"MissingArgument",option);
5571 if (IsGeometry(argv[i]) == MagickFalse)
5572 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5573 break;
5574 }
5575 if (LocaleCompare("size",option+1) == 0)
5576 {
5577 if (*option == '+')
5578 break;
5579 i++;
cristybb503372010-05-27 20:51:26 +00005580 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005581 ThrowMogrifyException(OptionError,"MissingArgument",option);
5582 if (IsGeometry(argv[i]) == MagickFalse)
5583 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5584 break;
5585 }
5586 if (LocaleCompare("sketch",option+1) == 0)
5587 {
5588 if (*option == '+')
5589 break;
5590 i++;
cristybb503372010-05-27 20:51:26 +00005591 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005592 ThrowMogrifyException(OptionError,"MissingArgument",option);
5593 if (IsGeometry(argv[i]) == MagickFalse)
5594 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5595 break;
5596 }
cristy4285d782011-02-09 20:12:28 +00005597 if (LocaleCompare("smush",option+1) == 0)
5598 {
cristy4285d782011-02-09 20:12:28 +00005599 i++;
5600 if (i == (ssize_t) argc)
5601 ThrowMogrifyException(OptionError,"MissingArgument",option);
5602 if (IsGeometry(argv[i]) == MagickFalse)
5603 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005604 i++;
5605 break;
5606 }
cristy3ed852e2009-09-05 21:47:34 +00005607 if (LocaleCompare("solarize",option+1) == 0)
5608 {
5609 if (*option == '+')
5610 break;
5611 i++;
cristybb503372010-05-27 20:51:26 +00005612 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005613 ThrowMogrifyException(OptionError,"MissingArgument",option);
5614 if (IsGeometry(argv[i]) == MagickFalse)
5615 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5616 break;
5617 }
5618 if (LocaleCompare("sparse-color",option+1) == 0)
5619 {
cristybb503372010-05-27 20:51:26 +00005620 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005621 op;
5622
5623 i++;
cristybb503372010-05-27 20:51:26 +00005624 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005625 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005626 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005627 if (op < 0)
5628 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5629 argv[i]);
5630 i++;
cristybb503372010-05-27 20:51:26 +00005631 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005632 ThrowMogrifyException(OptionError,"MissingArgument",option);
5633 break;
5634 }
5635 if (LocaleCompare("spread",option+1) == 0)
5636 {
5637 if (*option == '+')
5638 break;
5639 i++;
cristybb503372010-05-27 20:51:26 +00005640 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005641 ThrowMogrifyException(OptionError,"MissingArgument",option);
5642 if (IsGeometry(argv[i]) == MagickFalse)
5643 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5644 break;
5645 }
cristy0834d642011-03-18 18:26:08 +00005646 if (LocaleCompare("statistic",option+1) == 0)
5647 {
5648 ssize_t
5649 op;
5650
5651 if (*option == '+')
5652 break;
5653 i++;
5654 if (i == (ssize_t) argc)
5655 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005656 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005657 if (op < 0)
5658 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5659 argv[i]);
5660 i++;
5661 if (i == (ssize_t) (argc-1))
5662 ThrowMogrifyException(OptionError,"MissingArgument",option);
5663 if (IsGeometry(argv[i]) == MagickFalse)
5664 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5665 break;
5666 }
cristy3ed852e2009-09-05 21:47:34 +00005667 if (LocaleCompare("stretch",option+1) == 0)
5668 {
cristybb503372010-05-27 20:51:26 +00005669 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005670 stretch;
5671
5672 if (*option == '+')
5673 break;
5674 i++;
cristybb503372010-05-27 20:51:26 +00005675 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005676 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005677 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005678 if (stretch < 0)
5679 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5680 argv[i]);
5681 break;
5682 }
5683 if (LocaleCompare("strip",option+1) == 0)
5684 break;
5685 if (LocaleCompare("stroke",option+1) == 0)
5686 {
5687 if (*option == '+')
5688 break;
5689 i++;
cristybb503372010-05-27 20:51:26 +00005690 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005691 ThrowMogrifyException(OptionError,"MissingArgument",option);
5692 break;
5693 }
5694 if (LocaleCompare("strokewidth",option+1) == 0)
5695 {
5696 if (*option == '+')
5697 break;
5698 i++;
cristybb503372010-05-27 20:51:26 +00005699 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005700 ThrowMogrifyException(OptionError,"MissingArgument",option);
5701 if (IsGeometry(argv[i]) == MagickFalse)
5702 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5703 break;
5704 }
5705 if (LocaleCompare("style",option+1) == 0)
5706 {
cristybb503372010-05-27 20:51:26 +00005707 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005708 style;
5709
5710 if (*option == '+')
5711 break;
5712 i++;
cristybb503372010-05-27 20:51:26 +00005713 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005714 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005715 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005716 if (style < 0)
5717 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5718 argv[i]);
5719 break;
5720 }
cristyecb10ff2011-03-22 13:14:03 +00005721 if (LocaleCompare("swap",option+1) == 0)
5722 {
5723 if (*option == '+')
5724 break;
5725 i++;
5726 if (i == (ssize_t) (argc-1))
5727 ThrowMogrifyException(OptionError,"MissingArgument",option);
5728 if (IsGeometry(argv[i]) == MagickFalse)
5729 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5730 break;
5731 }
cristy3ed852e2009-09-05 21:47:34 +00005732 if (LocaleCompare("swirl",option+1) == 0)
5733 {
5734 if (*option == '+')
5735 break;
5736 i++;
cristybb503372010-05-27 20:51:26 +00005737 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005738 ThrowMogrifyException(OptionError,"MissingArgument",option);
5739 if (IsGeometry(argv[i]) == MagickFalse)
5740 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5741 break;
5742 }
cristyd9a29192010-10-16 16:49:53 +00005743 if (LocaleCompare("synchronize",option+1) == 0)
5744 break;
cristy3ed852e2009-09-05 21:47:34 +00005745 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5746 }
5747 case 't':
5748 {
5749 if (LocaleCompare("taint",option+1) == 0)
5750 break;
5751 if (LocaleCompare("texture",option+1) == 0)
5752 {
5753 if (*option == '+')
5754 break;
5755 i++;
cristybb503372010-05-27 20:51:26 +00005756 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005757 ThrowMogrifyException(OptionError,"MissingArgument",option);
5758 break;
5759 }
5760 if (LocaleCompare("tile",option+1) == 0)
5761 {
5762 if (*option == '+')
5763 break;
5764 i++;
cristybb503372010-05-27 20:51:26 +00005765 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005766 ThrowMogrifyException(OptionError,"MissingArgument",option);
5767 break;
5768 }
5769 if (LocaleCompare("tile-offset",option+1) == 0)
5770 {
5771 if (*option == '+')
5772 break;
5773 i++;
cristybb503372010-05-27 20:51:26 +00005774 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005775 ThrowMogrifyException(OptionError,"MissingArgument",option);
5776 if (IsGeometry(argv[i]) == MagickFalse)
5777 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5778 break;
5779 }
5780 if (LocaleCompare("tint",option+1) == 0)
5781 {
5782 if (*option == '+')
5783 break;
5784 i++;
cristybb503372010-05-27 20:51:26 +00005785 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005786 ThrowMogrifyException(OptionError,"MissingArgument",option);
5787 if (IsGeometry(argv[i]) == MagickFalse)
5788 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5789 break;
5790 }
5791 if (LocaleCompare("transform",option+1) == 0)
5792 break;
5793 if (LocaleCompare("transpose",option+1) == 0)
5794 break;
5795 if (LocaleCompare("transverse",option+1) == 0)
5796 break;
5797 if (LocaleCompare("threshold",option+1) == 0)
5798 {
5799 if (*option == '+')
5800 break;
5801 i++;
cristybb503372010-05-27 20:51:26 +00005802 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005803 ThrowMogrifyException(OptionError,"MissingArgument",option);
5804 if (IsGeometry(argv[i]) == MagickFalse)
5805 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5806 break;
5807 }
5808 if (LocaleCompare("thumbnail",option+1) == 0)
5809 {
5810 if (*option == '+')
5811 break;
5812 i++;
cristybb503372010-05-27 20:51:26 +00005813 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005814 ThrowMogrifyException(OptionError,"MissingArgument",option);
5815 if (IsGeometry(argv[i]) == MagickFalse)
5816 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5817 break;
5818 }
5819 if (LocaleCompare("transparent",option+1) == 0)
5820 {
5821 i++;
cristybb503372010-05-27 20:51:26 +00005822 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005823 ThrowMogrifyException(OptionError,"MissingArgument",option);
5824 break;
5825 }
5826 if (LocaleCompare("transparent-color",option+1) == 0)
5827 {
5828 if (*option == '+')
5829 break;
5830 i++;
cristybb503372010-05-27 20:51:26 +00005831 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005832 ThrowMogrifyException(OptionError,"MissingArgument",option);
5833 break;
5834 }
5835 if (LocaleCompare("treedepth",option+1) == 0)
5836 {
5837 if (*option == '+')
5838 break;
5839 i++;
cristybb503372010-05-27 20:51:26 +00005840 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005841 ThrowMogrifyException(OptionError,"MissingArgument",option);
5842 if (IsGeometry(argv[i]) == MagickFalse)
5843 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5844 break;
5845 }
5846 if (LocaleCompare("trim",option+1) == 0)
5847 break;
5848 if (LocaleCompare("type",option+1) == 0)
5849 {
cristybb503372010-05-27 20:51:26 +00005850 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005851 type;
5852
5853 if (*option == '+')
5854 break;
5855 i++;
cristybb503372010-05-27 20:51:26 +00005856 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005857 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005858 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005859 if (type < 0)
5860 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5861 argv[i]);
5862 break;
5863 }
5864 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5865 }
5866 case 'u':
5867 {
5868 if (LocaleCompare("undercolor",option+1) == 0)
5869 {
5870 if (*option == '+')
5871 break;
5872 i++;
cristybb503372010-05-27 20:51:26 +00005873 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005874 ThrowMogrifyException(OptionError,"MissingArgument",option);
5875 break;
5876 }
5877 if (LocaleCompare("unique-colors",option+1) == 0)
5878 break;
5879 if (LocaleCompare("units",option+1) == 0)
5880 {
cristybb503372010-05-27 20:51:26 +00005881 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005882 units;
5883
5884 if (*option == '+')
5885 break;
5886 i++;
cristybb503372010-05-27 20:51:26 +00005887 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005888 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005889 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005890 argv[i]);
5891 if (units < 0)
5892 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5893 argv[i]);
5894 break;
5895 }
5896 if (LocaleCompare("unsharp",option+1) == 0)
5897 {
5898 i++;
cristybb503372010-05-27 20:51:26 +00005899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005900 ThrowMogrifyException(OptionError,"MissingArgument",option);
5901 if (IsGeometry(argv[i]) == MagickFalse)
5902 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5903 break;
5904 }
5905 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5906 }
5907 case 'v':
5908 {
5909 if (LocaleCompare("verbose",option+1) == 0)
5910 {
5911 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5912 break;
5913 }
5914 if ((LocaleCompare("version",option+1) == 0) ||
5915 (LocaleCompare("-version",option+1) == 0))
5916 {
cristyb51dff52011-05-19 16:55:47 +00005917 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005918 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005919 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5920 GetMagickCopyright());
5921 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5922 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005923 break;
5924 }
5925 if (LocaleCompare("view",option+1) == 0)
5926 {
5927 if (*option == '+')
5928 break;
5929 i++;
cristybb503372010-05-27 20:51:26 +00005930 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005931 ThrowMogrifyException(OptionError,"MissingArgument",option);
5932 break;
5933 }
5934 if (LocaleCompare("vignette",option+1) == 0)
5935 {
5936 if (*option == '+')
5937 break;
5938 i++;
cristybb503372010-05-27 20:51:26 +00005939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005940 ThrowMogrifyException(OptionError,"MissingArgument",option);
5941 if (IsGeometry(argv[i]) == MagickFalse)
5942 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5943 break;
5944 }
5945 if (LocaleCompare("virtual-pixel",option+1) == 0)
5946 {
cristybb503372010-05-27 20:51:26 +00005947 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005948 method;
5949
5950 if (*option == '+')
5951 break;
5952 i++;
cristybb503372010-05-27 20:51:26 +00005953 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005954 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005955 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005956 argv[i]);
5957 if (method < 0)
5958 ThrowMogrifyException(OptionError,
5959 "UnrecognizedVirtualPixelMethod",argv[i]);
5960 break;
5961 }
5962 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5963 }
5964 case 'w':
5965 {
5966 if (LocaleCompare("wave",option+1) == 0)
5967 {
5968 i++;
cristybb503372010-05-27 20:51:26 +00005969 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005970 ThrowMogrifyException(OptionError,"MissingArgument",option);
5971 if (IsGeometry(argv[i]) == MagickFalse)
5972 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5973 break;
5974 }
5975 if (LocaleCompare("weight",option+1) == 0)
5976 {
5977 if (*option == '+')
5978 break;
5979 i++;
cristybb503372010-05-27 20:51:26 +00005980 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005981 ThrowMogrifyException(OptionError,"MissingArgument",option);
5982 break;
5983 }
5984 if (LocaleCompare("white-point",option+1) == 0)
5985 {
5986 if (*option == '+')
5987 break;
5988 i++;
cristybb503372010-05-27 20:51:26 +00005989 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005990 ThrowMogrifyException(OptionError,"MissingArgument",option);
5991 if (IsGeometry(argv[i]) == MagickFalse)
5992 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5993 break;
5994 }
5995 if (LocaleCompare("white-threshold",option+1) == 0)
5996 {
5997 if (*option == '+')
5998 break;
5999 i++;
cristybb503372010-05-27 20:51:26 +00006000 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006001 ThrowMogrifyException(OptionError,"MissingArgument",option);
6002 if (IsGeometry(argv[i]) == MagickFalse)
6003 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6004 break;
6005 }
6006 if (LocaleCompare("write",option+1) == 0)
6007 {
6008 i++;
cristybb503372010-05-27 20:51:26 +00006009 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006010 ThrowMogrifyException(OptionError,"MissingArgument",option);
6011 break;
6012 }
6013 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6014 }
6015 case '?':
6016 break;
6017 default:
6018 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6019 }
cristy042ee782011-04-22 18:48:30 +00006020 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6021 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006022 if (fire != MagickFalse)
6023 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6024 }
6025 if (k != 0)
6026 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006027 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006028 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6029 DestroyMogrify();
6030 return(status != 0 ? MagickTrue : MagickFalse);
6031}
6032
6033/*
6034%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6035% %
6036% %
6037% %
6038+ M o g r i f y I m a g e I n f o %
6039% %
6040% %
6041% %
6042%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6043%
6044% MogrifyImageInfo() applies image processing settings to the image as
6045% prescribed by command line options.
6046%
6047% The format of the MogrifyImageInfo method is:
6048%
6049% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6050% const char **argv,ExceptionInfo *exception)
6051%
6052% A description of each parameter follows:
6053%
6054% o image_info: the image info..
6055%
6056% o argc: Specifies a pointer to an integer describing the number of
6057% elements in the argument vector.
6058%
6059% o argv: Specifies a pointer to a text array containing the command line
6060% arguments.
6061%
6062% o exception: return any errors or warnings in this structure.
6063%
6064*/
6065WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6066 const int argc,const char **argv,ExceptionInfo *exception)
6067{
6068 const char
6069 *option;
6070
6071 GeometryInfo
6072 geometry_info;
6073
cristybb503372010-05-27 20:51:26 +00006074 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006075 count;
6076
cristybb503372010-05-27 20:51:26 +00006077 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006078 i;
6079
6080 /*
6081 Initialize method variables.
6082 */
6083 assert(image_info != (ImageInfo *) NULL);
6084 assert(image_info->signature == MagickSignature);
6085 if (image_info->debug != MagickFalse)
6086 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6087 image_info->filename);
6088 if (argc < 0)
6089 return(MagickTrue);
6090 /*
6091 Set the image settings.
6092 */
cristybb503372010-05-27 20:51:26 +00006093 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006094 {
6095 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006096 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006097 continue;
cristy042ee782011-04-22 18:48:30 +00006098 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006099 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006100 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006101 break;
6102 switch (*(option+1))
6103 {
6104 case 'a':
6105 {
6106 if (LocaleCompare("adjoin",option+1) == 0)
6107 {
6108 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6109 break;
6110 }
6111 if (LocaleCompare("antialias",option+1) == 0)
6112 {
6113 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6114 break;
6115 }
6116 if (LocaleCompare("attenuate",option+1) == 0)
6117 {
6118 if (*option == '+')
6119 {
6120 (void) DeleteImageOption(image_info,option+1);
6121 break;
6122 }
6123 (void) SetImageOption(image_info,option+1,argv[i+1]);
6124 break;
6125 }
6126 if (LocaleCompare("authenticate",option+1) == 0)
6127 {
6128 if (*option == '+')
6129 (void) CloneString(&image_info->authenticate,(char *) NULL);
6130 else
6131 (void) CloneString(&image_info->authenticate,argv[i+1]);
6132 break;
6133 }
6134 break;
6135 }
6136 case 'b':
6137 {
6138 if (LocaleCompare("background",option+1) == 0)
6139 {
6140 if (*option == '+')
6141 {
6142 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006143 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006144 &image_info->background_color,exception);
6145 break;
6146 }
6147 (void) SetImageOption(image_info,option+1,argv[i+1]);
6148 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6149 exception);
6150 break;
6151 }
6152 if (LocaleCompare("bias",option+1) == 0)
6153 {
6154 if (*option == '+')
6155 {
6156 (void) SetImageOption(image_info,option+1,"0.0");
6157 break;
6158 }
6159 (void) SetImageOption(image_info,option+1,argv[i+1]);
6160 break;
6161 }
6162 if (LocaleCompare("black-point-compensation",option+1) == 0)
6163 {
6164 if (*option == '+')
6165 {
6166 (void) SetImageOption(image_info,option+1,"false");
6167 break;
6168 }
6169 (void) SetImageOption(image_info,option+1,"true");
6170 break;
6171 }
6172 if (LocaleCompare("blue-primary",option+1) == 0)
6173 {
6174 if (*option == '+')
6175 {
6176 (void) SetImageOption(image_info,option+1,"0.0");
6177 break;
6178 }
6179 (void) SetImageOption(image_info,option+1,argv[i+1]);
6180 break;
6181 }
6182 if (LocaleCompare("bordercolor",option+1) == 0)
6183 {
6184 if (*option == '+')
6185 {
6186 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006187 (void) QueryColorDatabase(MogrifyBorderColor,
6188 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006189 break;
6190 }
6191 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6192 exception);
6193 (void) SetImageOption(image_info,option+1,argv[i+1]);
6194 break;
6195 }
6196 if (LocaleCompare("box",option+1) == 0)
6197 {
6198 if (*option == '+')
6199 {
6200 (void) SetImageOption(image_info,"undercolor","none");
6201 break;
6202 }
6203 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6204 break;
6205 }
6206 break;
6207 }
6208 case 'c':
6209 {
6210 if (LocaleCompare("cache",option+1) == 0)
6211 {
6212 MagickSizeType
6213 limit;
6214
6215 limit=MagickResourceInfinity;
6216 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006217 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006218 (void) SetMagickResourceLimit(MemoryResource,limit);
6219 (void) SetMagickResourceLimit(MapResource,2*limit);
6220 break;
6221 }
6222 if (LocaleCompare("caption",option+1) == 0)
6223 {
6224 if (*option == '+')
6225 {
6226 (void) DeleteImageOption(image_info,option+1);
6227 break;
6228 }
6229 (void) SetImageOption(image_info,option+1,argv[i+1]);
6230 break;
6231 }
6232 if (LocaleCompare("channel",option+1) == 0)
6233 {
6234 if (*option == '+')
6235 {
6236 image_info->channel=DefaultChannels;
6237 break;
6238 }
6239 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6240 break;
6241 }
6242 if (LocaleCompare("colors",option+1) == 0)
6243 {
cristye27293e2009-12-18 02:53:20 +00006244 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006245 break;
6246 }
6247 if (LocaleCompare("colorspace",option+1) == 0)
6248 {
6249 if (*option == '+')
6250 {
6251 image_info->colorspace=UndefinedColorspace;
6252 (void) SetImageOption(image_info,option+1,"undefined");
6253 break;
6254 }
cristy042ee782011-04-22 18:48:30 +00006255 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006256 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6257 (void) SetImageOption(image_info,option+1,argv[i+1]);
6258 break;
6259 }
cristy3ed852e2009-09-05 21:47:34 +00006260 if (LocaleCompare("comment",option+1) == 0)
6261 {
6262 if (*option == '+')
6263 {
6264 (void) DeleteImageOption(image_info,option+1);
6265 break;
6266 }
6267 (void) SetImageOption(image_info,option+1,argv[i+1]);
6268 break;
6269 }
6270 if (LocaleCompare("compose",option+1) == 0)
6271 {
6272 if (*option == '+')
6273 {
6274 (void) SetImageOption(image_info,option+1,"undefined");
6275 break;
6276 }
6277 (void) SetImageOption(image_info,option+1,argv[i+1]);
6278 break;
6279 }
6280 if (LocaleCompare("compress",option+1) == 0)
6281 {
6282 if (*option == '+')
6283 {
6284 image_info->compression=UndefinedCompression;
6285 (void) SetImageOption(image_info,option+1,"undefined");
6286 break;
6287 }
cristy042ee782011-04-22 18:48:30 +00006288 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006289 MagickCompressOptions,MagickFalse,argv[i+1]);
6290 (void) SetImageOption(image_info,option+1,argv[i+1]);
6291 break;
6292 }
6293 break;
6294 }
6295 case 'd':
6296 {
6297 if (LocaleCompare("debug",option+1) == 0)
6298 {
6299 if (*option == '+')
6300 (void) SetLogEventMask("none");
6301 else
6302 (void) SetLogEventMask(argv[i+1]);
6303 image_info->debug=IsEventLogging();
6304 break;
6305 }
6306 if (LocaleCompare("define",option+1) == 0)
6307 {
6308 if (*option == '+')
6309 {
6310 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6311 (void) DeleteImageRegistry(argv[i+1]+9);
6312 else
6313 (void) DeleteImageOption(image_info,argv[i+1]);
6314 break;
6315 }
6316 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6317 {
6318 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6319 exception);
6320 break;
6321 }
6322 (void) DefineImageOption(image_info,argv[i+1]);
6323 break;
6324 }
6325 if (LocaleCompare("delay",option+1) == 0)
6326 {
6327 if (*option == '+')
6328 {
6329 (void) SetImageOption(image_info,option+1,"0");
6330 break;
6331 }
6332 (void) SetImageOption(image_info,option+1,argv[i+1]);
6333 break;
6334 }
6335 if (LocaleCompare("density",option+1) == 0)
6336 {
6337 /*
6338 Set image density.
6339 */
6340 if (*option == '+')
6341 {
6342 if (image_info->density != (char *) NULL)
6343 image_info->density=DestroyString(image_info->density);
6344 (void) SetImageOption(image_info,option+1,"72");
6345 break;
6346 }
6347 (void) CloneString(&image_info->density,argv[i+1]);
6348 (void) SetImageOption(image_info,option+1,argv[i+1]);
6349 break;
6350 }
6351 if (LocaleCompare("depth",option+1) == 0)
6352 {
6353 if (*option == '+')
6354 {
6355 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6356 break;
6357 }
cristye27293e2009-12-18 02:53:20 +00006358 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006359 break;
6360 }
cristyc9b12952010-03-28 01:12:28 +00006361 if (LocaleCompare("direction",option+1) == 0)
6362 {
6363 if (*option == '+')
6364 {
6365 (void) SetImageOption(image_info,option+1,"undefined");
6366 break;
6367 }
6368 (void) SetImageOption(image_info,option+1,argv[i+1]);
6369 break;
6370 }
cristy3ed852e2009-09-05 21:47:34 +00006371 if (LocaleCompare("display",option+1) == 0)
6372 {
6373 if (*option == '+')
6374 {
6375 if (image_info->server_name != (char *) NULL)
6376 image_info->server_name=DestroyString(
6377 image_info->server_name);
6378 break;
6379 }
6380 (void) CloneString(&image_info->server_name,argv[i+1]);
6381 break;
6382 }
6383 if (LocaleCompare("dispose",option+1) == 0)
6384 {
6385 if (*option == '+')
6386 {
6387 (void) SetImageOption(image_info,option+1,"undefined");
6388 break;
6389 }
6390 (void) SetImageOption(image_info,option+1,argv[i+1]);
6391 break;
6392 }
6393 if (LocaleCompare("dither",option+1) == 0)
6394 {
6395 if (*option == '+')
6396 {
6397 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006398 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006399 break;
6400 }
6401 (void) SetImageOption(image_info,option+1,argv[i+1]);
6402 image_info->dither=MagickTrue;
6403 break;
6404 }
6405 break;
6406 }
6407 case 'e':
6408 {
6409 if (LocaleCompare("encoding",option+1) == 0)
6410 {
6411 if (*option == '+')
6412 {
6413 (void) SetImageOption(image_info,option+1,"undefined");
6414 break;
6415 }
6416 (void) SetImageOption(image_info,option+1,argv[i+1]);
6417 break;
6418 }
6419 if (LocaleCompare("endian",option+1) == 0)
6420 {
6421 if (*option == '+')
6422 {
6423 image_info->endian=UndefinedEndian;
6424 (void) SetImageOption(image_info,option+1,"undefined");
6425 break;
6426 }
cristy042ee782011-04-22 18:48:30 +00006427 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006428 MagickEndianOptions,MagickFalse,argv[i+1]);
6429 (void) SetImageOption(image_info,option+1,argv[i+1]);
6430 break;
6431 }
6432 if (LocaleCompare("extract",option+1) == 0)
6433 {
6434 /*
6435 Set image extract geometry.
6436 */
6437 if (*option == '+')
6438 {
6439 if (image_info->extract != (char *) NULL)
6440 image_info->extract=DestroyString(image_info->extract);
6441 break;
6442 }
6443 (void) CloneString(&image_info->extract,argv[i+1]);
6444 break;
6445 }
6446 break;
6447 }
6448 case 'f':
6449 {
6450 if (LocaleCompare("fill",option+1) == 0)
6451 {
6452 if (*option == '+')
6453 {
6454 (void) SetImageOption(image_info,option+1,"none");
6455 break;
6456 }
6457 (void) SetImageOption(image_info,option+1,argv[i+1]);
6458 break;
6459 }
6460 if (LocaleCompare("filter",option+1) == 0)
6461 {
6462 if (*option == '+')
6463 {
6464 (void) SetImageOption(image_info,option+1,"undefined");
6465 break;
6466 }
6467 (void) SetImageOption(image_info,option+1,argv[i+1]);
6468 break;
6469 }
6470 if (LocaleCompare("font",option+1) == 0)
6471 {
6472 if (*option == '+')
6473 {
6474 if (image_info->font != (char *) NULL)
6475 image_info->font=DestroyString(image_info->font);
6476 break;
6477 }
6478 (void) CloneString(&image_info->font,argv[i+1]);
6479 break;
6480 }
6481 if (LocaleCompare("format",option+1) == 0)
6482 {
6483 register const char
6484 *q;
6485
6486 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006487 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006488 image_info->ping=MagickFalse;
6489 (void) SetImageOption(image_info,option+1,argv[i+1]);
6490 break;
6491 }
6492 if (LocaleCompare("fuzz",option+1) == 0)
6493 {
6494 if (*option == '+')
6495 {
6496 image_info->fuzz=0.0;
6497 (void) SetImageOption(image_info,option+1,"0");
6498 break;
6499 }
cristyf2f27272009-12-17 14:48:46 +00006500 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006501 1.0);
6502 (void) SetImageOption(image_info,option+1,argv[i+1]);
6503 break;
6504 }
6505 break;
6506 }
6507 case 'g':
6508 {
6509 if (LocaleCompare("gravity",option+1) == 0)
6510 {
6511 if (*option == '+')
6512 {
6513 (void) SetImageOption(image_info,option+1,"undefined");
6514 break;
6515 }
6516 (void) SetImageOption(image_info,option+1,argv[i+1]);
6517 break;
6518 }
6519 if (LocaleCompare("green-primary",option+1) == 0)
6520 {
6521 if (*option == '+')
6522 {
6523 (void) SetImageOption(image_info,option+1,"0.0");
6524 break;
6525 }
6526 (void) SetImageOption(image_info,option+1,argv[i+1]);
6527 break;
6528 }
6529 break;
6530 }
6531 case 'i':
6532 {
6533 if (LocaleCompare("intent",option+1) == 0)
6534 {
6535 if (*option == '+')
6536 {
6537 (void) SetImageOption(image_info,option+1,"undefined");
6538 break;
6539 }
6540 (void) SetImageOption(image_info,option+1,argv[i+1]);
6541 break;
6542 }
6543 if (LocaleCompare("interlace",option+1) == 0)
6544 {
6545 if (*option == '+')
6546 {
6547 image_info->interlace=UndefinedInterlace;
6548 (void) SetImageOption(image_info,option+1,"undefined");
6549 break;
6550 }
cristy042ee782011-04-22 18:48:30 +00006551 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006552 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6553 (void) SetImageOption(image_info,option+1,argv[i+1]);
6554 break;
6555 }
cristyb32b90a2009-09-07 21:45:48 +00006556 if (LocaleCompare("interline-spacing",option+1) == 0)
6557 {
6558 if (*option == '+')
6559 {
6560 (void) SetImageOption(image_info,option+1,"undefined");
6561 break;
6562 }
6563 (void) SetImageOption(image_info,option+1,argv[i+1]);
6564 break;
6565 }
cristy3ed852e2009-09-05 21:47:34 +00006566 if (LocaleCompare("interpolate",option+1) == 0)
6567 {
6568 if (*option == '+')
6569 {
6570 (void) SetImageOption(image_info,option+1,"undefined");
6571 break;
6572 }
6573 (void) SetImageOption(image_info,option+1,argv[i+1]);
6574 break;
6575 }
6576 if (LocaleCompare("interword-spacing",option+1) == 0)
6577 {
6578 if (*option == '+')
6579 {
6580 (void) SetImageOption(image_info,option+1,"undefined");
6581 break;
6582 }
6583 (void) SetImageOption(image_info,option+1,argv[i+1]);
6584 break;
6585 }
6586 break;
6587 }
6588 case 'k':
6589 {
6590 if (LocaleCompare("kerning",option+1) == 0)
6591 {
6592 if (*option == '+')
6593 {
6594 (void) SetImageOption(image_info,option+1,"undefined");
6595 break;
6596 }
6597 (void) SetImageOption(image_info,option+1,argv[i+1]);
6598 break;
6599 }
6600 break;
6601 }
6602 case 'l':
6603 {
6604 if (LocaleCompare("label",option+1) == 0)
6605 {
6606 if (*option == '+')
6607 {
6608 (void) DeleteImageOption(image_info,option+1);
6609 break;
6610 }
6611 (void) SetImageOption(image_info,option+1,argv[i+1]);
6612 break;
6613 }
6614 if (LocaleCompare("limit",option+1) == 0)
6615 {
6616 MagickSizeType
6617 limit;
6618
6619 ResourceType
6620 type;
6621
6622 if (*option == '+')
6623 break;
cristy042ee782011-04-22 18:48:30 +00006624 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006625 MagickFalse,argv[i+1]);
6626 limit=MagickResourceInfinity;
6627 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006628 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006629 (void) SetMagickResourceLimit(type,limit);
6630 break;
6631 }
6632 if (LocaleCompare("list",option+1) == 0)
6633 {
cristybb503372010-05-27 20:51:26 +00006634 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006635 list;
6636
6637 /*
6638 Display configuration list.
6639 */
cristy042ee782011-04-22 18:48:30 +00006640 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006641 switch (list)
6642 {
6643 case MagickCoderOptions:
6644 {
6645 (void) ListCoderInfo((FILE *) NULL,exception);
6646 break;
6647 }
6648 case MagickColorOptions:
6649 {
6650 (void) ListColorInfo((FILE *) NULL,exception);
6651 break;
6652 }
6653 case MagickConfigureOptions:
6654 {
6655 (void) ListConfigureInfo((FILE *) NULL,exception);
6656 break;
6657 }
6658 case MagickDelegateOptions:
6659 {
6660 (void) ListDelegateInfo((FILE *) NULL,exception);
6661 break;
6662 }
6663 case MagickFontOptions:
6664 {
6665 (void) ListTypeInfo((FILE *) NULL,exception);
6666 break;
6667 }
6668 case MagickFormatOptions:
6669 {
6670 (void) ListMagickInfo((FILE *) NULL,exception);
6671 break;
6672 }
6673 case MagickLocaleOptions:
6674 {
6675 (void) ListLocaleInfo((FILE *) NULL,exception);
6676 break;
6677 }
6678 case MagickLogOptions:
6679 {
6680 (void) ListLogInfo((FILE *) NULL,exception);
6681 break;
6682 }
6683 case MagickMagicOptions:
6684 {
6685 (void) ListMagicInfo((FILE *) NULL,exception);
6686 break;
6687 }
6688 case MagickMimeOptions:
6689 {
6690 (void) ListMimeInfo((FILE *) NULL,exception);
6691 break;
6692 }
6693 case MagickModuleOptions:
6694 {
6695 (void) ListModuleInfo((FILE *) NULL,exception);
6696 break;
6697 }
6698 case MagickPolicyOptions:
6699 {
6700 (void) ListPolicyInfo((FILE *) NULL,exception);
6701 break;
6702 }
6703 case MagickResourceOptions:
6704 {
6705 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6706 break;
6707 }
6708 case MagickThresholdOptions:
6709 {
6710 (void) ListThresholdMaps((FILE *) NULL,exception);
6711 break;
6712 }
6713 default:
6714 {
cristy042ee782011-04-22 18:48:30 +00006715 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006716 exception);
6717 break;
6718 }
6719 }
cristyaeb2cbc2010-05-07 13:28:58 +00006720 break;
cristy3ed852e2009-09-05 21:47:34 +00006721 }
6722 if (LocaleCompare("log",option+1) == 0)
6723 {
6724 if (*option == '+')
6725 break;
6726 (void) SetLogFormat(argv[i+1]);
6727 break;
6728 }
6729 if (LocaleCompare("loop",option+1) == 0)
6730 {
6731 if (*option == '+')
6732 {
6733 (void) SetImageOption(image_info,option+1,"0");
6734 break;
6735 }
6736 (void) SetImageOption(image_info,option+1,argv[i+1]);
6737 break;
6738 }
6739 break;
6740 }
6741 case 'm':
6742 {
6743 if (LocaleCompare("matte",option+1) == 0)
6744 {
6745 if (*option == '+')
6746 {
6747 (void) SetImageOption(image_info,option+1,"false");
6748 break;
6749 }
6750 (void) SetImageOption(image_info,option+1,"true");
6751 break;
6752 }
6753 if (LocaleCompare("mattecolor",option+1) == 0)
6754 {
6755 if (*option == '+')
6756 {
6757 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006758 (void) QueryColorDatabase(MogrifyMatteColor,
6759 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006760 break;
6761 }
6762 (void) SetImageOption(image_info,option+1,argv[i+1]);
6763 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6764 exception);
6765 break;
6766 }
6767 if (LocaleCompare("monitor",option+1) == 0)
6768 {
6769 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6770 (void *) NULL);
6771 break;
6772 }
6773 if (LocaleCompare("monochrome",option+1) == 0)
6774 {
6775 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6776 break;
6777 }
6778 break;
6779 }
6780 case 'o':
6781 {
6782 if (LocaleCompare("orient",option+1) == 0)
6783 {
6784 if (*option == '+')
6785 {
6786 image_info->orientation=UndefinedOrientation;
6787 (void) SetImageOption(image_info,option+1,"undefined");
6788 break;
6789 }
cristy042ee782011-04-22 18:48:30 +00006790 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006791 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006792 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006793 break;
6794 }
6795 }
6796 case 'p':
6797 {
6798 if (LocaleCompare("page",option+1) == 0)
6799 {
6800 char
6801 *canonical_page,
6802 page[MaxTextExtent];
6803
6804 const char
6805 *image_option;
6806
6807 MagickStatusType
6808 flags;
6809
6810 RectangleInfo
6811 geometry;
6812
6813 if (*option == '+')
6814 {
6815 (void) DeleteImageOption(image_info,option+1);
6816 (void) CloneString(&image_info->page,(char *) NULL);
6817 break;
6818 }
6819 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6820 image_option=GetImageOption(image_info,"page");
6821 if (image_option != (const char *) NULL)
6822 flags=ParseAbsoluteGeometry(image_option,&geometry);
6823 canonical_page=GetPageGeometry(argv[i+1]);
6824 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6825 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006826 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006827 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006828 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006829 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006830 (unsigned long) geometry.width,(unsigned long) geometry.height,
6831 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006832 (void) SetImageOption(image_info,option+1,page);
6833 (void) CloneString(&image_info->page,page);
6834 break;
6835 }
6836 if (LocaleCompare("pen",option+1) == 0)
6837 {
6838 if (*option == '+')
6839 {
6840 (void) SetImageOption(image_info,option+1,"none");
6841 break;
6842 }
6843 (void) SetImageOption(image_info,option+1,argv[i+1]);
6844 break;
6845 }
6846 if (LocaleCompare("ping",option+1) == 0)
6847 {
6848 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6849 break;
6850 }
6851 if (LocaleCompare("pointsize",option+1) == 0)
6852 {
6853 if (*option == '+')
6854 geometry_info.rho=0.0;
6855 else
6856 (void) ParseGeometry(argv[i+1],&geometry_info);
6857 image_info->pointsize=geometry_info.rho;
6858 break;
6859 }
cristye7f51092010-01-17 00:39:37 +00006860 if (LocaleCompare("precision",option+1) == 0)
6861 {
cristybf2766a2010-01-17 03:33:23 +00006862 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006863 break;
6864 }
cristy3ed852e2009-09-05 21:47:34 +00006865 if (LocaleCompare("preview",option+1) == 0)
6866 {
6867 /*
6868 Preview image.
6869 */
6870 if (*option == '+')
6871 {
6872 image_info->preview_type=UndefinedPreview;
6873 break;
6874 }
cristy042ee782011-04-22 18:48:30 +00006875 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006876 MagickPreviewOptions,MagickFalse,argv[i+1]);
6877 break;
6878 }
6879 break;
6880 }
6881 case 'q':
6882 {
6883 if (LocaleCompare("quality",option+1) == 0)
6884 {
6885 /*
6886 Set image compression quality.
6887 */
6888 if (*option == '+')
6889 {
6890 image_info->quality=UndefinedCompressionQuality;
6891 (void) SetImageOption(image_info,option+1,"0");
6892 break;
6893 }
cristye27293e2009-12-18 02:53:20 +00006894 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006895 (void) SetImageOption(image_info,option+1,argv[i+1]);
6896 break;
6897 }
6898 if (LocaleCompare("quiet",option+1) == 0)
6899 {
6900 static WarningHandler
6901 warning_handler = (WarningHandler) NULL;
6902
6903 if (*option == '+')
6904 {
6905 /*
6906 Restore error or warning messages.
6907 */
6908 warning_handler=SetWarningHandler(warning_handler);
6909 break;
6910 }
6911 /*
6912 Suppress error or warning messages.
6913 */
6914 warning_handler=SetWarningHandler((WarningHandler) NULL);
6915 break;
6916 }
6917 break;
6918 }
6919 case 'r':
6920 {
6921 if (LocaleCompare("red-primary",option+1) == 0)
6922 {
6923 if (*option == '+')
6924 {
6925 (void) SetImageOption(image_info,option+1,"0.0");
6926 break;
6927 }
6928 (void) SetImageOption(image_info,option+1,argv[i+1]);
6929 break;
6930 }
6931 break;
6932 }
6933 case 's':
6934 {
6935 if (LocaleCompare("sampling-factor",option+1) == 0)
6936 {
6937 /*
6938 Set image sampling factor.
6939 */
6940 if (*option == '+')
6941 {
6942 if (image_info->sampling_factor != (char *) NULL)
6943 image_info->sampling_factor=DestroyString(
6944 image_info->sampling_factor);
6945 break;
6946 }
6947 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6948 break;
6949 }
6950 if (LocaleCompare("scene",option+1) == 0)
6951 {
6952 /*
6953 Set image scene.
6954 */
6955 if (*option == '+')
6956 {
6957 image_info->scene=0;
6958 (void) SetImageOption(image_info,option+1,"0");
6959 break;
6960 }
cristye27293e2009-12-18 02:53:20 +00006961 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006962 (void) SetImageOption(image_info,option+1,argv[i+1]);
6963 break;
6964 }
6965 if (LocaleCompare("seed",option+1) == 0)
6966 {
cristybb503372010-05-27 20:51:26 +00006967 size_t
cristy3ed852e2009-09-05 21:47:34 +00006968 seed;
6969
6970 if (*option == '+')
6971 {
cristybb503372010-05-27 20:51:26 +00006972 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006973 SeedPseudoRandomGenerator(seed);
6974 break;
6975 }
cristye27293e2009-12-18 02:53:20 +00006976 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006977 SeedPseudoRandomGenerator(seed);
6978 break;
6979 }
6980 if (LocaleCompare("size",option+1) == 0)
6981 {
6982 if (*option == '+')
6983 {
6984 if (image_info->size != (char *) NULL)
6985 image_info->size=DestroyString(image_info->size);
6986 break;
6987 }
6988 (void) CloneString(&image_info->size,argv[i+1]);
6989 break;
6990 }
6991 if (LocaleCompare("stroke",option+1) == 0)
6992 {
6993 if (*option == '+')
6994 {
6995 (void) SetImageOption(image_info,option+1,"none");
6996 break;
6997 }
6998 (void) SetImageOption(image_info,option+1,argv[i+1]);
6999 break;
7000 }
7001 if (LocaleCompare("strokewidth",option+1) == 0)
7002 {
7003 if (*option == '+')
7004 {
7005 (void) SetImageOption(image_info,option+1,"0");
7006 break;
7007 }
7008 (void) SetImageOption(image_info,option+1,argv[i+1]);
7009 break;
7010 }
cristyd9a29192010-10-16 16:49:53 +00007011 if (LocaleCompare("synchronize",option+1) == 0)
7012 {
7013 if (*option == '+')
7014 {
7015 image_info->synchronize=MagickFalse;
7016 break;
7017 }
7018 image_info->synchronize=MagickTrue;
7019 break;
7020 }
cristy3ed852e2009-09-05 21:47:34 +00007021 break;
7022 }
7023 case 't':
7024 {
7025 if (LocaleCompare("taint",option+1) == 0)
7026 {
7027 if (*option == '+')
7028 {
7029 (void) SetImageOption(image_info,option+1,"false");
7030 break;
7031 }
7032 (void) SetImageOption(image_info,option+1,"true");
7033 break;
7034 }
7035 if (LocaleCompare("texture",option+1) == 0)
7036 {
7037 if (*option == '+')
7038 {
7039 if (image_info->texture != (char *) NULL)
7040 image_info->texture=DestroyString(image_info->texture);
7041 break;
7042 }
7043 (void) CloneString(&image_info->texture,argv[i+1]);
7044 break;
7045 }
7046 if (LocaleCompare("tile-offset",option+1) == 0)
7047 {
7048 if (*option == '+')
7049 {
7050 (void) SetImageOption(image_info,option+1,"0");
7051 break;
7052 }
7053 (void) SetImageOption(image_info,option+1,argv[i+1]);
7054 break;
7055 }
7056 if (LocaleCompare("transparent-color",option+1) == 0)
7057 {
7058 if (*option == '+')
7059 {
7060 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7061 (void) SetImageOption(image_info,option+1,"none");
7062 break;
7063 }
7064 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7065 exception);
7066 (void) SetImageOption(image_info,option+1,argv[i+1]);
7067 break;
7068 }
7069 if (LocaleCompare("type",option+1) == 0)
7070 {
7071 if (*option == '+')
7072 {
cristy5f1c1ff2010-12-23 21:38:06 +00007073 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007074 (void) SetImageOption(image_info,option+1,"undefined");
7075 break;
7076 }
cristy042ee782011-04-22 18:48:30 +00007077 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007078 MagickFalse,argv[i+1]);
7079 (void) SetImageOption(image_info,option+1,argv[i+1]);
7080 break;
7081 }
7082 break;
7083 }
7084 case 'u':
7085 {
7086 if (LocaleCompare("undercolor",option+1) == 0)
7087 {
7088 if (*option == '+')
7089 {
7090 (void) DeleteImageOption(image_info,option+1);
7091 break;
7092 }
7093 (void) SetImageOption(image_info,option+1,argv[i+1]);
7094 break;
7095 }
7096 if (LocaleCompare("units",option+1) == 0)
7097 {
7098 if (*option == '+')
7099 {
7100 image_info->units=UndefinedResolution;
7101 (void) SetImageOption(image_info,option+1,"undefined");
7102 break;
7103 }
cristy042ee782011-04-22 18:48:30 +00007104 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007105 MagickResolutionOptions,MagickFalse,argv[i+1]);
7106 (void) SetImageOption(image_info,option+1,argv[i+1]);
7107 break;
7108 }
7109 break;
7110 }
7111 case 'v':
7112 {
7113 if (LocaleCompare("verbose",option+1) == 0)
7114 {
7115 if (*option == '+')
7116 {
7117 image_info->verbose=MagickFalse;
7118 break;
7119 }
7120 image_info->verbose=MagickTrue;
7121 image_info->ping=MagickFalse;
7122 break;
7123 }
7124 if (LocaleCompare("view",option+1) == 0)
7125 {
7126 if (*option == '+')
7127 {
7128 if (image_info->view != (char *) NULL)
7129 image_info->view=DestroyString(image_info->view);
7130 break;
7131 }
7132 (void) CloneString(&image_info->view,argv[i+1]);
7133 break;
7134 }
7135 if (LocaleCompare("virtual-pixel",option+1) == 0)
7136 {
7137 if (*option == '+')
7138 {
7139 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7140 (void) SetImageOption(image_info,option+1,"undefined");
7141 break;
7142 }
7143 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007144 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007145 argv[i+1]);
7146 (void) SetImageOption(image_info,option+1,argv[i+1]);
7147 break;
7148 }
7149 break;
7150 }
7151 case 'w':
7152 {
7153 if (LocaleCompare("white-point",option+1) == 0)
7154 {
7155 if (*option == '+')
7156 {
7157 (void) SetImageOption(image_info,option+1,"0.0");
7158 break;
7159 }
7160 (void) SetImageOption(image_info,option+1,argv[i+1]);
7161 break;
7162 }
7163 break;
7164 }
7165 default:
7166 break;
7167 }
7168 i+=count;
7169 }
7170 return(MagickTrue);
7171}
7172
7173/*
7174%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7175% %
7176% %
7177% %
7178+ M o g r i f y I m a g e L i s t %
7179% %
7180% %
7181% %
7182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7183%
7184% MogrifyImageList() applies any command line options that might affect the
7185% entire image list (e.g. -append, -coalesce, etc.).
7186%
7187% The format of the MogrifyImage method is:
7188%
7189% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7190% const char **argv,Image **images,ExceptionInfo *exception)
7191%
7192% A description of each parameter follows:
7193%
7194% o image_info: the image info..
7195%
7196% o argc: Specifies a pointer to an integer describing the number of
7197% elements in the argument vector.
7198%
7199% o argv: Specifies a pointer to a text array containing the command line
7200% arguments.
7201%
anthonye9c27192011-03-27 08:07:06 +00007202% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007203%
7204% o exception: return any errors or warnings in this structure.
7205%
7206*/
7207WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7208 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7209{
cristy3ed852e2009-09-05 21:47:34 +00007210 const char
7211 *option;
7212
cristy6b3da3a2010-06-20 02:21:46 +00007213 ImageInfo
7214 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007215
7216 MagickStatusType
7217 status;
7218
7219 QuantizeInfo
7220 *quantize_info;
7221
cristybb503372010-05-27 20:51:26 +00007222 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007223 i;
7224
cristy6b3da3a2010-06-20 02:21:46 +00007225 ssize_t
7226 count,
7227 index;
7228
cristy3ed852e2009-09-05 21:47:34 +00007229 /*
7230 Apply options to the image list.
7231 */
7232 assert(image_info != (ImageInfo *) NULL);
7233 assert(image_info->signature == MagickSignature);
7234 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007235 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007236 assert((*images)->signature == MagickSignature);
7237 if ((*images)->debug != MagickFalse)
7238 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7239 (*images)->filename);
7240 if ((argc <= 0) || (*argv == (char *) NULL))
7241 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007242 mogrify_info=CloneImageInfo(image_info);
7243 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007244 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007245 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007246 {
cristy74fe8f12009-10-03 19:09:01 +00007247 if (*images == (Image *) NULL)
7248 break;
cristy3ed852e2009-09-05 21:47:34 +00007249 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007250 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007251 continue;
cristy042ee782011-04-22 18:48:30 +00007252 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007253 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007254 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007255 break;
cristy6b3da3a2010-06-20 02:21:46 +00007256 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007257 switch (*(option+1))
7258 {
7259 case 'a':
7260 {
7261 if (LocaleCompare("affinity",option+1) == 0)
7262 {
cristy6b3da3a2010-06-20 02:21:46 +00007263 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007264 if (*option == '+')
7265 {
7266 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7267 InheritException(exception,&(*images)->exception);
7268 break;
7269 }
7270 i++;
7271 break;
7272 }
7273 if (LocaleCompare("append",option+1) == 0)
7274 {
7275 Image
7276 *append_image;
7277
cristy6b3da3a2010-06-20 02:21:46 +00007278 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007279 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7280 MagickFalse,exception);
7281 if (append_image == (Image *) NULL)
7282 {
7283 status=MagickFalse;
7284 break;
7285 }
7286 *images=DestroyImageList(*images);
7287 *images=append_image;
7288 break;
7289 }
7290 if (LocaleCompare("average",option+1) == 0)
7291 {
7292 Image
7293 *average_image;
7294
cristyd18ae7c2010-03-07 17:39:52 +00007295 /*
7296 Average an image sequence (deprecated).
7297 */
cristy6b3da3a2010-06-20 02:21:46 +00007298 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007299 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7300 exception);
cristy3ed852e2009-09-05 21:47:34 +00007301 if (average_image == (Image *) NULL)
7302 {
7303 status=MagickFalse;
7304 break;
7305 }
7306 *images=DestroyImageList(*images);
7307 *images=average_image;
7308 break;
7309 }
7310 break;
7311 }
7312 case 'c':
7313 {
7314 if (LocaleCompare("channel",option+1) == 0)
7315 {
cristyf4ad9df2011-07-08 16:49:03 +00007316 ChannelType
7317 channel;
7318
cristy3ed852e2009-09-05 21:47:34 +00007319 if (*option == '+')
7320 {
7321 channel=DefaultChannels;
7322 break;
7323 }
7324 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007325 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007326 break;
7327 }
7328 if (LocaleCompare("clut",option+1) == 0)
7329 {
7330 Image
7331 *clut_image,
7332 *image;
7333
cristy6b3da3a2010-06-20 02:21:46 +00007334 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007335 image=RemoveFirstImageFromList(images);
7336 clut_image=RemoveFirstImageFromList(images);
7337 if (clut_image == (Image *) NULL)
7338 {
7339 status=MagickFalse;
7340 break;
7341 }
cristy444eda62011-08-10 02:07:46 +00007342 (void) ClutImage(image,clut_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007343 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007344 *images=DestroyImageList(*images);
7345 *images=image;
7346 break;
7347 }
7348 if (LocaleCompare("coalesce",option+1) == 0)
7349 {
7350 Image
7351 *coalesce_image;
7352
cristy6b3da3a2010-06-20 02:21:46 +00007353 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007354 coalesce_image=CoalesceImages(*images,exception);
7355 if (coalesce_image == (Image *) NULL)
7356 {
7357 status=MagickFalse;
7358 break;
7359 }
7360 *images=DestroyImageList(*images);
7361 *images=coalesce_image;
7362 break;
7363 }
7364 if (LocaleCompare("combine",option+1) == 0)
7365 {
7366 Image
7367 *combine_image;
7368
cristy6b3da3a2010-06-20 02:21:46 +00007369 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007370 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007371 if (combine_image == (Image *) NULL)
7372 {
7373 status=MagickFalse;
7374 break;
7375 }
7376 *images=DestroyImageList(*images);
7377 *images=combine_image;
7378 break;
7379 }
7380 if (LocaleCompare("composite",option+1) == 0)
7381 {
7382 Image
7383 *mask_image,
7384 *composite_image,
7385 *image;
7386
7387 RectangleInfo
7388 geometry;
7389
cristy6b3da3a2010-06-20 02:21:46 +00007390 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007391 image=RemoveFirstImageFromList(images);
7392 composite_image=RemoveFirstImageFromList(images);
7393 if (composite_image == (Image *) NULL)
7394 {
7395 status=MagickFalse;
7396 break;
7397 }
7398 (void) TransformImage(&composite_image,(char *) NULL,
7399 composite_image->geometry);
7400 SetGeometry(composite_image,&geometry);
7401 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7402 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7403 &geometry);
7404 mask_image=RemoveFirstImageFromList(images);
7405 if (mask_image != (Image *) NULL)
7406 {
7407 if ((image->compose == DisplaceCompositeOp) ||
7408 (image->compose == DistortCompositeOp))
7409 {
7410 /*
7411 Merge Y displacement into X displacement image.
7412 */
7413 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7414 mask_image,0,0);
7415 mask_image=DestroyImage(mask_image);
7416 }
7417 else
7418 {
7419 /*
7420 Set a blending mask for the composition.
7421 */
anthonya129f702011-04-14 01:08:48 +00007422 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007423 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007424 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007425 }
7426 }
cristyf4ad9df2011-07-08 16:49:03 +00007427 (void) CompositeImage(image,image->compose,composite_image,
7428 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007429 if (mask_image != (Image *) NULL)
7430 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007431 composite_image=DestroyImage(composite_image);
7432 InheritException(exception,&image->exception);
7433 *images=DestroyImageList(*images);
7434 *images=image;
7435 break;
7436 }
anthony9f4f0342011-03-28 11:47:22 +00007437#if 0
7438This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007439 if (LocaleCompare("crop",option+1) == 0)
7440 {
7441 MagickStatusType
7442 flags;
7443
7444 RectangleInfo
7445 geometry;
7446
anthonye9c27192011-03-27 08:07:06 +00007447 /*
anthony9f4f0342011-03-28 11:47:22 +00007448 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007449 */
cristy6b3da3a2010-06-20 02:21:46 +00007450 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007451 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7452 if (((geometry.width == 0) && (geometry.height == 0)) ||
7453 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7454 break;
7455 (void) TransformImages(images,argv[i+1],(char *) NULL);
7456 InheritException(exception,&(*images)->exception);
7457 break;
7458 }
anthony9f4f0342011-03-28 11:47:22 +00007459#endif
cristy3ed852e2009-09-05 21:47:34 +00007460 break;
7461 }
7462 case 'd':
7463 {
7464 if (LocaleCompare("deconstruct",option+1) == 0)
7465 {
7466 Image
7467 *deconstruct_image;
7468
cristy6b3da3a2010-06-20 02:21:46 +00007469 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007470 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007471 exception);
cristy3ed852e2009-09-05 21:47:34 +00007472 if (deconstruct_image == (Image *) NULL)
7473 {
7474 status=MagickFalse;
7475 break;
7476 }
7477 *images=DestroyImageList(*images);
7478 *images=deconstruct_image;
7479 break;
7480 }
7481 if (LocaleCompare("delete",option+1) == 0)
7482 {
7483 if (*option == '+')
7484 DeleteImages(images,"-1",exception);
7485 else
7486 DeleteImages(images,argv[i+1],exception);
7487 break;
7488 }
7489 if (LocaleCompare("dither",option+1) == 0)
7490 {
7491 if (*option == '+')
7492 {
7493 quantize_info->dither=MagickFalse;
7494 break;
7495 }
7496 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007497 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007498 MagickDitherOptions,MagickFalse,argv[i+1]);
7499 break;
7500 }
cristyecb10ff2011-03-22 13:14:03 +00007501 if (LocaleCompare("duplicate",option+1) == 0)
7502 {
cristy72988482011-03-29 16:34:38 +00007503 Image
7504 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007505
anthony2b6bcae2011-03-23 13:05:34 +00007506 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007507 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7508 else
7509 {
7510 const char
7511 *p;
7512
anthony2b6bcae2011-03-23 13:05:34 +00007513 size_t
7514 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007515
anthony2b6bcae2011-03-23 13:05:34 +00007516 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007517 p=strchr(argv[i+1],',');
7518 if (p == (const char *) NULL)
7519 duplicate_images=DuplicateImages(*images,number_duplicates,
7520 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007521 else
cristy72988482011-03-29 16:34:38 +00007522 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7523 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007524 }
7525 AppendImageToList(images, duplicate_images);
7526 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007527 break;
7528 }
cristy3ed852e2009-09-05 21:47:34 +00007529 break;
7530 }
cristyd18ae7c2010-03-07 17:39:52 +00007531 case 'e':
7532 {
7533 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7534 {
7535 Image
7536 *evaluate_image;
7537
7538 MagickEvaluateOperator
7539 op;
7540
cristy6b3da3a2010-06-20 02:21:46 +00007541 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007542 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007543 MagickFalse,argv[i+1]);
7544 evaluate_image=EvaluateImages(*images,op,exception);
7545 if (evaluate_image == (Image *) NULL)
7546 {
7547 status=MagickFalse;
7548 break;
7549 }
7550 *images=DestroyImageList(*images);
7551 *images=evaluate_image;
7552 break;
7553 }
7554 break;
7555 }
cristy3ed852e2009-09-05 21:47:34 +00007556 case 'f':
7557 {
cristyf0a247f2009-10-04 00:20:03 +00007558 if (LocaleCompare("fft",option+1) == 0)
7559 {
7560 Image
7561 *fourier_image;
7562
7563 /*
7564 Implements the discrete Fourier transform (DFT).
7565 */
cristy6b3da3a2010-06-20 02:21:46 +00007566 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007567 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7568 MagickTrue : MagickFalse,exception);
7569 if (fourier_image == (Image *) NULL)
7570 break;
7571 *images=DestroyImage(*images);
7572 *images=fourier_image;
7573 break;
7574 }
cristy3ed852e2009-09-05 21:47:34 +00007575 if (LocaleCompare("flatten",option+1) == 0)
7576 {
7577 Image
7578 *flatten_image;
7579
cristy6b3da3a2010-06-20 02:21:46 +00007580 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007581 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7582 if (flatten_image == (Image *) NULL)
7583 break;
7584 *images=DestroyImageList(*images);
7585 *images=flatten_image;
7586 break;
7587 }
7588 if (LocaleCompare("fx",option+1) == 0)
7589 {
7590 Image
7591 *fx_image;
7592
cristy6b3da3a2010-06-20 02:21:46 +00007593 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007594 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007595 if (fx_image == (Image *) NULL)
7596 {
7597 status=MagickFalse;
7598 break;
7599 }
7600 *images=DestroyImageList(*images);
7601 *images=fx_image;
7602 break;
7603 }
7604 break;
7605 }
7606 case 'h':
7607 {
7608 if (LocaleCompare("hald-clut",option+1) == 0)
7609 {
7610 Image
7611 *hald_image,
7612 *image;
7613
cristy6b3da3a2010-06-20 02:21:46 +00007614 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007615 image=RemoveFirstImageFromList(images);
7616 hald_image=RemoveFirstImageFromList(images);
7617 if (hald_image == (Image *) NULL)
7618 {
7619 status=MagickFalse;
7620 break;
7621 }
cristy7c0a0a42011-08-23 17:57:25 +00007622 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007623 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007624 if (*images != (Image *) NULL)
7625 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007626 *images=image;
7627 break;
7628 }
7629 break;
7630 }
7631 case 'i':
7632 {
7633 if (LocaleCompare("ift",option+1) == 0)
7634 {
7635 Image
cristy8587f882009-11-13 20:28:49 +00007636 *fourier_image,
7637 *magnitude_image,
7638 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007639
7640 /*
7641 Implements the inverse fourier discrete Fourier transform (DFT).
7642 */
cristy6b3da3a2010-06-20 02:21:46 +00007643 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007644 magnitude_image=RemoveFirstImageFromList(images);
7645 phase_image=RemoveFirstImageFromList(images);
7646 if (phase_image == (Image *) NULL)
7647 {
7648 status=MagickFalse;
7649 break;
7650 }
7651 fourier_image=InverseFourierTransformImage(magnitude_image,
7652 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007653 if (fourier_image == (Image *) NULL)
7654 break;
cristy0aff6ea2009-11-14 01:40:53 +00007655 if (*images != (Image *) NULL)
7656 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007657 *images=fourier_image;
7658 break;
7659 }
7660 if (LocaleCompare("insert",option+1) == 0)
7661 {
7662 Image
7663 *p,
7664 *q;
7665
7666 index=0;
7667 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007668 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007669 p=RemoveLastImageFromList(images);
7670 if (p == (Image *) NULL)
7671 {
7672 (void) ThrowMagickException(exception,GetMagickModule(),
7673 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7674 status=MagickFalse;
7675 break;
7676 }
7677 q=p;
7678 if (index == 0)
7679 PrependImageToList(images,q);
7680 else
cristybb503372010-05-27 20:51:26 +00007681 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007682 AppendImageToList(images,q);
7683 else
7684 {
7685 q=GetImageFromList(*images,index-1);
7686 if (q == (Image *) NULL)
7687 {
7688 (void) ThrowMagickException(exception,GetMagickModule(),
7689 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7690 status=MagickFalse;
7691 break;
7692 }
7693 InsertImageInList(&q,p);
7694 }
7695 *images=GetFirstImageInList(q);
7696 break;
7697 }
7698 break;
7699 }
7700 case 'l':
7701 {
7702 if (LocaleCompare("layers",option+1) == 0)
7703 {
7704 Image
7705 *layers;
7706
7707 ImageLayerMethod
7708 method;
7709
cristy6b3da3a2010-06-20 02:21:46 +00007710 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007711 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007712 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007713 MagickFalse,argv[i+1]);
7714 switch (method)
7715 {
7716 case CoalesceLayer:
7717 {
7718 layers=CoalesceImages(*images,exception);
7719 break;
7720 }
7721 case CompareAnyLayer:
7722 case CompareClearLayer:
7723 case CompareOverlayLayer:
7724 default:
7725 {
cristy8a9106f2011-07-05 14:39:26 +00007726 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007727 break;
7728 }
7729 case MergeLayer:
7730 case FlattenLayer:
7731 case MosaicLayer:
7732 case TrimBoundsLayer:
7733 {
7734 layers=MergeImageLayers(*images,method,exception);
7735 break;
7736 }
7737 case DisposeLayer:
7738 {
7739 layers=DisposeImages(*images,exception);
7740 break;
7741 }
7742 case OptimizeImageLayer:
7743 {
7744 layers=OptimizeImageLayers(*images,exception);
7745 break;
7746 }
7747 case OptimizePlusLayer:
7748 {
7749 layers=OptimizePlusImageLayers(*images,exception);
7750 break;
7751 }
7752 case OptimizeTransLayer:
7753 {
7754 OptimizeImageTransparency(*images,exception);
7755 break;
7756 }
7757 case RemoveDupsLayer:
7758 {
7759 RemoveDuplicateLayers(images,exception);
7760 break;
7761 }
7762 case RemoveZeroLayer:
7763 {
7764 RemoveZeroDelayLayers(images,exception);
7765 break;
7766 }
7767 case OptimizeLayer:
7768 {
7769 /*
7770 General Purpose, GIF Animation Optimizer.
7771 */
7772 layers=CoalesceImages(*images,exception);
7773 if (layers == (Image *) NULL)
7774 {
7775 status=MagickFalse;
7776 break;
7777 }
7778 InheritException(exception,&layers->exception);
7779 *images=DestroyImageList(*images);
7780 *images=layers;
7781 layers=OptimizeImageLayers(*images,exception);
7782 if (layers == (Image *) NULL)
7783 {
7784 status=MagickFalse;
7785 break;
7786 }
7787 InheritException(exception,&layers->exception);
7788 *images=DestroyImageList(*images);
7789 *images=layers;
7790 layers=(Image *) NULL;
7791 OptimizeImageTransparency(*images,exception);
7792 InheritException(exception,&(*images)->exception);
7793 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7794 break;
7795 }
7796 case CompositeLayer:
7797 {
7798 CompositeOperator
7799 compose;
7800
7801 Image
7802 *source;
7803
7804 RectangleInfo
7805 geometry;
7806
7807 /*
7808 Split image sequence at the first 'NULL:' image.
7809 */
7810 source=(*images);
7811 while (source != (Image *) NULL)
7812 {
7813 source=GetNextImageInList(source);
7814 if ((source != (Image *) NULL) &&
7815 (LocaleCompare(source->magick,"NULL") == 0))
7816 break;
7817 }
7818 if (source != (Image *) NULL)
7819 {
7820 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7821 (GetNextImageInList(source) == (Image *) NULL))
7822 source=(Image *) NULL;
7823 else
7824 {
7825 /*
7826 Separate the two lists, junk the null: image.
7827 */
7828 source=SplitImageList(source->previous);
7829 DeleteImageFromList(&source);
7830 }
7831 }
7832 if (source == (Image *) NULL)
7833 {
7834 (void) ThrowMagickException(exception,GetMagickModule(),
7835 OptionError,"MissingNullSeparator","layers Composite");
7836 status=MagickFalse;
7837 break;
7838 }
7839 /*
7840 Adjust offset with gravity and virtual canvas.
7841 */
7842 SetGeometry(*images,&geometry);
7843 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7844 geometry.width=source->page.width != 0 ?
7845 source->page.width : source->columns;
7846 geometry.height=source->page.height != 0 ?
7847 source->page.height : source->rows;
7848 GravityAdjustGeometry((*images)->page.width != 0 ?
7849 (*images)->page.width : (*images)->columns,
7850 (*images)->page.height != 0 ? (*images)->page.height :
7851 (*images)->rows,(*images)->gravity,&geometry);
7852 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007853 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007854 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007855 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007856 MagickComposeOptions,MagickFalse,option);
7857 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7858 exception);
7859 source=DestroyImageList(source);
7860 break;
7861 }
7862 }
7863 if (layers == (Image *) NULL)
7864 break;
7865 InheritException(exception,&layers->exception);
7866 *images=DestroyImageList(*images);
7867 *images=layers;
7868 break;
7869 }
7870 break;
7871 }
7872 case 'm':
7873 {
7874 if (LocaleCompare("map",option+1) == 0)
7875 {
cristy6b3da3a2010-06-20 02:21:46 +00007876 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007877 if (*option == '+')
7878 {
7879 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7880 InheritException(exception,&(*images)->exception);
7881 break;
7882 }
7883 i++;
7884 break;
7885 }
cristyf40785b2010-03-06 02:27:27 +00007886 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007887 {
7888 Image
cristyf40785b2010-03-06 02:27:27 +00007889 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007890
cristyd18ae7c2010-03-07 17:39:52 +00007891 /*
7892 Maximum image sequence (deprecated).
7893 */
cristy6b3da3a2010-06-20 02:21:46 +00007894 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007895 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007896 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007897 {
7898 status=MagickFalse;
7899 break;
7900 }
7901 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007902 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007903 break;
7904 }
cristyf40785b2010-03-06 02:27:27 +00007905 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007906 {
7907 Image
cristyf40785b2010-03-06 02:27:27 +00007908 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007909
cristyd18ae7c2010-03-07 17:39:52 +00007910 /*
7911 Minimum image sequence (deprecated).
7912 */
cristy6b3da3a2010-06-20 02:21:46 +00007913 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007914 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007915 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007916 {
7917 status=MagickFalse;
7918 break;
7919 }
7920 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007921 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007922 break;
7923 }
cristy3ed852e2009-09-05 21:47:34 +00007924 if (LocaleCompare("morph",option+1) == 0)
7925 {
7926 Image
7927 *morph_image;
7928
cristy6b3da3a2010-06-20 02:21:46 +00007929 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007930 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007931 exception);
7932 if (morph_image == (Image *) NULL)
7933 {
7934 status=MagickFalse;
7935 break;
7936 }
7937 *images=DestroyImageList(*images);
7938 *images=morph_image;
7939 break;
7940 }
7941 if (LocaleCompare("mosaic",option+1) == 0)
7942 {
7943 Image
7944 *mosaic_image;
7945
cristy6b3da3a2010-06-20 02:21:46 +00007946 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007947 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7948 if (mosaic_image == (Image *) NULL)
7949 {
7950 status=MagickFalse;
7951 break;
7952 }
7953 *images=DestroyImageList(*images);
7954 *images=mosaic_image;
7955 break;
7956 }
7957 break;
7958 }
7959 case 'p':
7960 {
7961 if (LocaleCompare("print",option+1) == 0)
7962 {
7963 char
7964 *string;
7965
cristy6b3da3a2010-06-20 02:21:46 +00007966 (void) SyncImagesSettings(mogrify_info,*images);
7967 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007968 if (string == (char *) NULL)
7969 break;
7970 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007971 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007972 string=DestroyString(string);
7973 }
7974 if (LocaleCompare("process",option+1) == 0)
7975 {
7976 char
7977 **arguments;
7978
7979 int
7980 j,
7981 number_arguments;
7982
cristy6b3da3a2010-06-20 02:21:46 +00007983 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007984 arguments=StringToArgv(argv[i+1],&number_arguments);
7985 if (arguments == (char **) NULL)
7986 break;
7987 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7988 {
7989 char
7990 breaker,
7991 quote,
7992 *token;
7993
7994 const char
7995 *arguments;
7996
7997 int
7998 next,
7999 status;
8000
8001 size_t
8002 length;
8003
8004 TokenInfo
8005 *token_info;
8006
8007 /*
8008 Support old style syntax, filter="-option arg".
8009 */
8010 length=strlen(argv[i+1]);
8011 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008012 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008013 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8014 sizeof(*token));
8015 if (token == (char *) NULL)
8016 break;
8017 next=0;
8018 arguments=argv[i+1];
8019 token_info=AcquireTokenInfo();
8020 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8021 "\"",'\0',&breaker,&next,&quote);
8022 token_info=DestroyTokenInfo(token_info);
8023 if (status == 0)
8024 {
8025 const char
8026 *argv;
8027
8028 argv=(&(arguments[next]));
8029 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8030 exception);
8031 }
8032 token=DestroyString(token);
8033 break;
8034 }
cristy91c0da22010-05-02 01:44:07 +00008035 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008036 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8037 number_arguments-2,(const char **) arguments+2,exception);
8038 for (j=0; j < number_arguments; j++)
8039 arguments[j]=DestroyString(arguments[j]);
8040 arguments=(char **) RelinquishMagickMemory(arguments);
8041 break;
8042 }
8043 break;
8044 }
8045 case 'r':
8046 {
8047 if (LocaleCompare("reverse",option+1) == 0)
8048 {
8049 ReverseImageList(images);
8050 InheritException(exception,&(*images)->exception);
8051 break;
8052 }
8053 break;
8054 }
8055 case 's':
8056 {
cristy4285d782011-02-09 20:12:28 +00008057 if (LocaleCompare("smush",option+1) == 0)
8058 {
8059 Image
8060 *smush_image;
8061
8062 ssize_t
8063 offset;
8064
8065 (void) SyncImagesSettings(mogrify_info,*images);
8066 offset=(ssize_t) StringToLong(argv[i+1]);
8067 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8068 MagickFalse,offset,exception);
8069 if (smush_image == (Image *) NULL)
8070 {
8071 status=MagickFalse;
8072 break;
8073 }
8074 *images=DestroyImageList(*images);
8075 *images=smush_image;
8076 break;
8077 }
cristy3ed852e2009-09-05 21:47:34 +00008078 if (LocaleCompare("swap",option+1) == 0)
8079 {
8080 Image
8081 *p,
8082 *q,
8083 *swap;
8084
cristybb503372010-05-27 20:51:26 +00008085 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008086 swap_index;
8087
8088 index=(-1);
8089 swap_index=(-2);
8090 if (*option != '+')
8091 {
8092 GeometryInfo
8093 geometry_info;
8094
8095 MagickStatusType
8096 flags;
8097
8098 swap_index=(-1);
8099 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008100 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008101 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008102 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008103 }
8104 p=GetImageFromList(*images,index);
8105 q=GetImageFromList(*images,swap_index);
8106 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8107 {
8108 (void) ThrowMagickException(exception,GetMagickModule(),
8109 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8110 status=MagickFalse;
8111 break;
8112 }
8113 if (p == q)
8114 break;
8115 swap=CloneImage(p,0,0,MagickTrue,exception);
8116 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8117 ReplaceImageInList(&q,swap);
8118 *images=GetFirstImageInList(q);
8119 break;
8120 }
8121 break;
8122 }
8123 case 'w':
8124 {
8125 if (LocaleCompare("write",option+1) == 0)
8126 {
cristy071dd7b2010-04-09 13:04:54 +00008127 char
cristy06609ee2010-03-17 20:21:27 +00008128 key[MaxTextExtent];
8129
cristy3ed852e2009-09-05 21:47:34 +00008130 Image
8131 *write_images;
8132
8133 ImageInfo
8134 *write_info;
8135
cristy6b3da3a2010-06-20 02:21:46 +00008136 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008137 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008138 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008139 write_images=(*images);
8140 if (*option == '+')
8141 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008142 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008143 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8144 write_info=DestroyImageInfo(write_info);
8145 if (*option == '+')
8146 write_images=DestroyImageList(write_images);
8147 break;
8148 }
8149 break;
8150 }
8151 default:
8152 break;
8153 }
8154 i+=count;
8155 }
8156 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008157 mogrify_info=DestroyImageInfo(mogrify_info);
8158 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008159 return(status != 0 ? MagickTrue : MagickFalse);
8160}
8161
8162/*
8163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8164% %
8165% %
8166% %
8167+ M o g r i f y I m a g e s %
8168% %
8169% %
8170% %
8171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8172%
8173% MogrifyImages() applies image processing options to a sequence of images as
8174% prescribed by command line options.
8175%
8176% The format of the MogrifyImage method is:
8177%
8178% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8179% const MagickBooleanType post,const int argc,const char **argv,
8180% Image **images,Exceptioninfo *exception)
8181%
8182% A description of each parameter follows:
8183%
8184% o image_info: the image info..
8185%
8186% o post: If true, post process image list operators otherwise pre-process.
8187%
8188% o argc: Specifies a pointer to an integer describing the number of
8189% elements in the argument vector.
8190%
8191% o argv: Specifies a pointer to a text array containing the command line
8192% arguments.
8193%
anthonye9c27192011-03-27 08:07:06 +00008194% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008195%
8196% o exception: return any errors or warnings in this structure.
8197%
8198*/
8199WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8200 const MagickBooleanType post,const int argc,const char **argv,
8201 Image **images,ExceptionInfo *exception)
8202{
8203#define MogrifyImageTag "Mogrify/Image"
8204
anthonye9c27192011-03-27 08:07:06 +00008205 MagickStatusType
8206 status;
cristy3ed852e2009-09-05 21:47:34 +00008207
cristy0e9f9c12010-02-11 03:00:47 +00008208 MagickBooleanType
8209 proceed;
8210
anthonye9c27192011-03-27 08:07:06 +00008211 size_t
8212 n;
cristy3ed852e2009-09-05 21:47:34 +00008213
cristybb503372010-05-27 20:51:26 +00008214 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008215 i;
8216
cristy3ed852e2009-09-05 21:47:34 +00008217 assert(image_info != (ImageInfo *) NULL);
8218 assert(image_info->signature == MagickSignature);
8219 if (images == (Image **) NULL)
8220 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008221 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008222 assert((*images)->signature == MagickSignature);
8223 if ((*images)->debug != MagickFalse)
8224 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8225 (*images)->filename);
8226 if ((argc <= 0) || (*argv == (char *) NULL))
8227 return(MagickTrue);
8228 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8229 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008230 status=0;
anthonye9c27192011-03-27 08:07:06 +00008231
anthonyce2716b2011-04-22 09:51:34 +00008232#if 0
cristy1e604812011-05-19 18:07:50 +00008233 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8234 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008235#endif
8236
anthonye9c27192011-03-27 08:07:06 +00008237 /*
8238 Pre-process multi-image sequence operators
8239 */
cristy3ed852e2009-09-05 21:47:34 +00008240 if (post == MagickFalse)
8241 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008242 /*
8243 For each image, process simple single image operators
8244 */
8245 i=0;
8246 n=GetImageListLength(*images);
8247 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008248 {
anthonyce2716b2011-04-22 09:51:34 +00008249#if 0
cristy1e604812011-05-19 18:07:50 +00008250 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8251 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008252#endif
anthonye9c27192011-03-27 08:07:06 +00008253 status&=MogrifyImage(image_info,argc,argv,images,exception);
8254 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008255 if (proceed == MagickFalse)
8256 break;
anthonye9c27192011-03-27 08:07:06 +00008257 if ( (*images)->next == (Image *) NULL )
8258 break;
8259 *images=(*images)->next;
8260 i++;
cristy3ed852e2009-09-05 21:47:34 +00008261 }
anthonye9c27192011-03-27 08:07:06 +00008262 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008263#if 0
cristy1e604812011-05-19 18:07:50 +00008264 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8265 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008266#endif
anthonye9c27192011-03-27 08:07:06 +00008267
8268 /*
8269 Post-process, multi-image sequence operators
8270 */
8271 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008272 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008273 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008274 return(status != 0 ? MagickTrue : MagickFalse);
8275}