blob: 547a93b8cc43873a578f67d2b9b2fc6a56728513 [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,
cristy4c11c2b2011-09-05 20:17:07 +0000710 geometry_info.sigma,geometry_info.xi,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,
cristy4c11c2b2011-09-05 20:17:07 +0000734 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000735 break;
736 }
737 if (LocaleCompare("affine",option+1) == 0)
738 {
739 /*
740 Affine matrix.
741 */
742 if (*option == '+')
743 {
744 GetAffineMatrix(&draw_info->affine);
745 break;
746 }
747 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
748 break;
749 }
750 if (LocaleCompare("alpha",option+1) == 0)
751 {
752 AlphaChannelType
753 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000754
anthonydf8ebac2011-04-27 09:03:19 +0000755 (void) SyncImageSettings(mogrify_info,*image);
756 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
757 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000758 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000759 break;
760 }
761 if (LocaleCompare("annotate",option+1) == 0)
762 {
763 char
764 *text,
765 geometry[MaxTextExtent];
766
767 /*
768 Annotate image.
769 */
770 (void) SyncImageSettings(mogrify_info,*image);
771 SetGeometryInfo(&geometry_info);
772 flags=ParseGeometry(argv[i+1],&geometry_info);
773 if ((flags & SigmaValue) == 0)
774 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000775 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
776 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000777 if (text == (char *) NULL)
778 break;
779 (void) CloneString(&draw_info->text,text);
780 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000781 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000782 geometry_info.xi,geometry_info.psi);
783 (void) CloneString(&draw_info->geometry,geometry);
784 draw_info->affine.sx=cos(DegreesToRadians(
785 fmod(geometry_info.rho,360.0)));
786 draw_info->affine.rx=sin(DegreesToRadians(
787 fmod(geometry_info.rho,360.0)));
788 draw_info->affine.ry=(-sin(DegreesToRadians(
789 fmod(geometry_info.sigma,360.0))));
790 draw_info->affine.sy=cos(DegreesToRadians(
791 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000792 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000793 break;
794 }
795 if (LocaleCompare("antialias",option+1) == 0)
796 {
797 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
798 MagickFalse;
799 draw_info->text_antialias=(*option == '-') ? MagickTrue :
800 MagickFalse;
801 break;
802 }
803 if (LocaleCompare("auto-gamma",option+1) == 0)
804 {
805 /*
806 Auto Adjust Gamma of image based on its mean
807 */
808 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000809 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000810 break;
811 }
812 if (LocaleCompare("auto-level",option+1) == 0)
813 {
814 /*
815 Perfectly Normalize (max/min stretch) the image
816 */
817 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000818 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000819 break;
820 }
821 if (LocaleCompare("auto-orient",option+1) == 0)
822 {
823 (void) SyncImageSettings(mogrify_info,*image);
824 switch ((*image)->orientation)
825 {
826 case TopRightOrientation:
827 {
828 mogrify_image=FlopImage(*image,exception);
829 break;
830 }
831 case BottomRightOrientation:
832 {
833 mogrify_image=RotateImage(*image,180.0,exception);
834 break;
835 }
836 case BottomLeftOrientation:
837 {
838 mogrify_image=FlipImage(*image,exception);
839 break;
840 }
841 case LeftTopOrientation:
842 {
843 mogrify_image=TransposeImage(*image,exception);
844 break;
845 }
846 case RightTopOrientation:
847 {
848 mogrify_image=RotateImage(*image,90.0,exception);
849 break;
850 }
851 case RightBottomOrientation:
852 {
853 mogrify_image=TransverseImage(*image,exception);
854 break;
855 }
856 case LeftBottomOrientation:
857 {
858 mogrify_image=RotateImage(*image,270.0,exception);
859 break;
860 }
861 default:
862 break;
863 }
864 if (mogrify_image != (Image *) NULL)
865 mogrify_image->orientation=TopLeftOrientation;
866 break;
867 }
868 break;
869 }
870 case 'b':
871 {
872 if (LocaleCompare("black-threshold",option+1) == 0)
873 {
874 /*
875 Black threshold image.
876 */
877 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000878 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000879 InheritException(exception,&(*image)->exception);
880 break;
881 }
882 if (LocaleCompare("blue-shift",option+1) == 0)
883 {
884 /*
885 Blue shift image.
886 */
887 (void) SyncImageSettings(mogrify_info,*image);
888 geometry_info.rho=1.5;
889 if (*option == '-')
890 flags=ParseGeometry(argv[i+1],&geometry_info);
891 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
892 break;
893 }
894 if (LocaleCompare("blur",option+1) == 0)
895 {
896 /*
897 Gaussian blur image.
898 */
899 (void) SyncImageSettings(mogrify_info,*image);
900 flags=ParseGeometry(argv[i+1],&geometry_info);
901 if ((flags & SigmaValue) == 0)
902 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000903 mogrify_image=BlurImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +0000904 geometry_info.sigma,exception);
905 break;
906 }
907 if (LocaleCompare("border",option+1) == 0)
908 {
909 /*
910 Surround image with a border of solid color.
911 */
912 (void) SyncImageSettings(mogrify_info,*image);
913 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
914 if ((flags & SigmaValue) == 0)
915 geometry.height=geometry.width;
916 mogrify_image=BorderImage(*image,&geometry,exception);
917 break;
918 }
919 if (LocaleCompare("bordercolor",option+1) == 0)
920 {
921 if (*option == '+')
922 {
cristy638895a2011-08-06 23:19:14 +0000923 (void) QueryColorDatabase(MogrifyBorderColor,&draw_info->border_color,
anthonydf8ebac2011-04-27 09:03:19 +0000924 exception);
925 break;
926 }
927 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
928 exception);
929 break;
930 }
931 if (LocaleCompare("box",option+1) == 0)
932 {
933 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
934 exception);
935 break;
936 }
937 if (LocaleCompare("brightness-contrast",option+1) == 0)
938 {
939 double
940 brightness,
941 contrast;
942
943 GeometryInfo
944 geometry_info;
945
946 MagickStatusType
947 flags;
948
949 /*
950 Brightness / contrast image.
951 */
952 (void) SyncImageSettings(mogrify_info,*image);
953 flags=ParseGeometry(argv[i+1],&geometry_info);
954 brightness=geometry_info.rho;
955 contrast=0.0;
956 if ((flags & SigmaValue) != 0)
957 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000958 (void) BrightnessContrastImage(*image,brightness,contrast,
959 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000960 InheritException(exception,&(*image)->exception);
961 break;
962 }
963 break;
964 }
965 case 'c':
966 {
967 if (LocaleCompare("cdl",option+1) == 0)
968 {
969 char
970 *color_correction_collection;
971
972 /*
973 Color correct with a color decision list.
974 */
975 (void) SyncImageSettings(mogrify_info,*image);
976 color_correction_collection=FileToString(argv[i+1],~0,exception);
977 if (color_correction_collection == (char *) NULL)
978 break;
cristy1bfa9f02011-08-11 02:35:43 +0000979 (void) ColorDecisionListImage(*image,color_correction_collection,
980 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000981 InheritException(exception,&(*image)->exception);
982 break;
983 }
984 if (LocaleCompare("channel",option+1) == 0)
985 {
986 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000987 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000988 else
cristyfa806a72011-07-04 02:06:13 +0000989 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +0000990 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000991 break;
992 }
993 if (LocaleCompare("charcoal",option+1) == 0)
994 {
995 /*
996 Charcoal image.
997 */
998 (void) SyncImageSettings(mogrify_info,*image);
999 flags=ParseGeometry(argv[i+1],&geometry_info);
1000 if ((flags & SigmaValue) == 0)
1001 geometry_info.sigma=1.0;
1002 mogrify_image=CharcoalImage(*image,geometry_info.rho,
1003 geometry_info.sigma,exception);
1004 break;
1005 }
1006 if (LocaleCompare("chop",option+1) == 0)
1007 {
1008 /*
1009 Chop the image.
1010 */
1011 (void) SyncImageSettings(mogrify_info,*image);
1012 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1013 mogrify_image=ChopImage(*image,&geometry,exception);
1014 break;
1015 }
1016 if (LocaleCompare("clamp",option+1) == 0)
1017 {
1018 /*
1019 Clamp image.
1020 */
1021 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001022 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001023 InheritException(exception,&(*image)->exception);
1024 break;
1025 }
1026 if (LocaleCompare("clip",option+1) == 0)
1027 {
1028 (void) SyncImageSettings(mogrify_info,*image);
1029 if (*option == '+')
1030 {
cristy018f07f2011-09-04 21:15:19 +00001031 (void) SetImageClipMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001032 break;
1033 }
cristy018f07f2011-09-04 21:15:19 +00001034 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001035 break;
1036 }
1037 if (LocaleCompare("clip-mask",option+1) == 0)
1038 {
1039 CacheView
1040 *mask_view;
1041
1042 Image
1043 *mask_image;
1044
cristy4c08aed2011-07-01 19:47:50 +00001045 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001046 *restrict q;
1047
1048 register ssize_t
1049 x;
1050
1051 ssize_t
1052 y;
1053
1054 (void) SyncImageSettings(mogrify_info,*image);
1055 if (*option == '+')
1056 {
1057 /*
1058 Remove a mask.
1059 */
cristy018f07f2011-09-04 21:15:19 +00001060 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001061 break;
1062 }
1063 /*
1064 Set the image mask.
1065 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1066 */
1067 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1068 if (mask_image == (Image *) NULL)
1069 break;
cristy574cc262011-08-05 01:23:58 +00001070 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001071 return(MagickFalse);
1072 mask_view=AcquireCacheView(mask_image);
1073 for (y=0; y < (ssize_t) mask_image->rows; y++)
1074 {
1075 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1076 exception);
cristyacd2ed22011-08-30 01:44:23 +00001077 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001078 break;
1079 for (x=0; x < (ssize_t) mask_image->columns; x++)
1080 {
1081 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001082 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1083 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1084 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1085 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001086 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001087 }
1088 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1089 break;
1090 }
1091 mask_view=DestroyCacheView(mask_view);
1092 mask_image->matte=MagickTrue;
cristy018f07f2011-09-04 21:15:19 +00001093 (void) SetImageClipMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001094 InheritException(exception,&(*image)->exception);
1095 break;
1096 }
1097 if (LocaleCompare("clip-path",option+1) == 0)
1098 {
1099 (void) SyncImageSettings(mogrify_info,*image);
1100 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001101 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001102 break;
1103 }
1104 if (LocaleCompare("colorize",option+1) == 0)
1105 {
1106 /*
1107 Colorize the image.
1108 */
1109 (void) SyncImageSettings(mogrify_info,*image);
1110 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1111 exception);
1112 break;
1113 }
1114 if (LocaleCompare("color-matrix",option+1) == 0)
1115 {
1116 KernelInfo
1117 *kernel;
1118
1119 (void) SyncImageSettings(mogrify_info,*image);
1120 kernel=AcquireKernelInfo(argv[i+1]);
1121 if (kernel == (KernelInfo *) NULL)
1122 break;
1123 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1124 kernel=DestroyKernelInfo(kernel);
1125 break;
1126 }
1127 if (LocaleCompare("colors",option+1) == 0)
1128 {
1129 /*
1130 Reduce the number of colors in the image.
1131 */
1132 (void) SyncImageSettings(mogrify_info,*image);
1133 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1134 if (quantize_info->number_colors == 0)
1135 break;
1136 if (((*image)->storage_class == DirectClass) ||
1137 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001138 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001139 else
cristy018f07f2011-09-04 21:15:19 +00001140 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001141 break;
1142 }
1143 if (LocaleCompare("colorspace",option+1) == 0)
1144 {
1145 ColorspaceType
1146 colorspace;
1147
1148 (void) SyncImageSettings(mogrify_info,*image);
1149 if (*option == '+')
1150 {
1151 (void) TransformImageColorspace(*image,RGBColorspace);
1152 InheritException(exception,&(*image)->exception);
1153 break;
1154 }
1155 colorspace=(ColorspaceType) ParseCommandOption(
1156 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1157 (void) TransformImageColorspace(*image,colorspace);
1158 InheritException(exception,&(*image)->exception);
1159 break;
1160 }
1161 if (LocaleCompare("contrast",option+1) == 0)
1162 {
1163 (void) SyncImageSettings(mogrify_info,*image);
1164 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001165 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001166 break;
1167 }
1168 if (LocaleCompare("contrast-stretch",option+1) == 0)
1169 {
1170 double
1171 black_point,
1172 white_point;
1173
1174 MagickStatusType
1175 flags;
1176
1177 /*
1178 Contrast stretch image.
1179 */
1180 (void) SyncImageSettings(mogrify_info,*image);
1181 flags=ParseGeometry(argv[i+1],&geometry_info);
1182 black_point=geometry_info.rho;
1183 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1184 black_point;
1185 if ((flags & PercentValue) != 0)
1186 {
1187 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1188 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1189 }
1190 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1191 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001192 (void) ContrastStretchImage(*image,black_point,white_point,
1193 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001194 InheritException(exception,&(*image)->exception);
1195 break;
1196 }
1197 if (LocaleCompare("convolve",option+1) == 0)
1198 {
anthonydf8ebac2011-04-27 09:03:19 +00001199 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001200 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001201
anthonydf8ebac2011-04-27 09:03:19 +00001202 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001203 kernel_info=AcquireKernelInfo(argv[i+1]);
1204 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001205 break;
cristy0a922382011-07-16 15:30:34 +00001206 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001207 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001208 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001209 break;
1210 }
1211 if (LocaleCompare("crop",option+1) == 0)
1212 {
1213 /*
1214 Crop a image to a smaller size
1215 */
1216 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001217 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001218 break;
1219 }
1220 if (LocaleCompare("cycle",option+1) == 0)
1221 {
1222 /*
1223 Cycle an image colormap.
1224 */
1225 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00001226 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1227 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001228 break;
1229 }
1230 break;
1231 }
1232 case 'd':
1233 {
1234 if (LocaleCompare("decipher",option+1) == 0)
1235 {
1236 StringInfo
1237 *passkey;
1238
1239 /*
1240 Decipher pixels.
1241 */
1242 (void) SyncImageSettings(mogrify_info,*image);
1243 passkey=FileToStringInfo(argv[i+1],~0,exception);
1244 if (passkey != (StringInfo *) NULL)
1245 {
1246 (void) PasskeyDecipherImage(*image,passkey,exception);
1247 passkey=DestroyStringInfo(passkey);
1248 }
1249 break;
1250 }
1251 if (LocaleCompare("density",option+1) == 0)
1252 {
1253 /*
1254 Set image density.
1255 */
1256 (void) CloneString(&draw_info->density,argv[i+1]);
1257 break;
1258 }
1259 if (LocaleCompare("depth",option+1) == 0)
1260 {
1261 (void) SyncImageSettings(mogrify_info,*image);
1262 if (*option == '+')
1263 {
1264 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1265 break;
1266 }
1267 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1268 break;
1269 }
1270 if (LocaleCompare("deskew",option+1) == 0)
1271 {
1272 double
1273 threshold;
1274
1275 /*
1276 Straighten the image.
1277 */
1278 (void) SyncImageSettings(mogrify_info,*image);
1279 if (*option == '+')
1280 threshold=40.0*QuantumRange/100.0;
1281 else
1282 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1283 mogrify_image=DeskewImage(*image,threshold,exception);
1284 break;
1285 }
1286 if (LocaleCompare("despeckle",option+1) == 0)
1287 {
1288 /*
1289 Reduce the speckles within an image.
1290 */
1291 (void) SyncImageSettings(mogrify_info,*image);
1292 mogrify_image=DespeckleImage(*image,exception);
1293 break;
1294 }
1295 if (LocaleCompare("display",option+1) == 0)
1296 {
1297 (void) CloneString(&draw_info->server_name,argv[i+1]);
1298 break;
1299 }
1300 if (LocaleCompare("distort",option+1) == 0)
1301 {
1302 char
1303 *args,
1304 token[MaxTextExtent];
1305
1306 const char
1307 *p;
1308
1309 DistortImageMethod
1310 method;
1311
1312 double
1313 *arguments;
1314
1315 register ssize_t
1316 x;
1317
1318 size_t
1319 number_arguments;
1320
1321 /*
1322 Distort image.
1323 */
1324 (void) SyncImageSettings(mogrify_info,*image);
1325 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1326 MagickFalse,argv[i+1]);
1327 if ( method == ResizeDistortion )
1328 {
1329 /* Special Case - Argument is actually a resize geometry!
1330 ** Convert that to an appropriate distortion argument array.
1331 */
1332 double
1333 resize_args[2];
1334 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1335 exception);
1336 resize_args[0]=(double)geometry.width;
1337 resize_args[1]=(double)geometry.height;
1338 mogrify_image=DistortImage(*image,method,(size_t)2,
1339 resize_args,MagickTrue,exception);
1340 break;
1341 }
cristy018f07f2011-09-04 21:15:19 +00001342 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1343 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001344 if (args == (char *) NULL)
1345 break;
1346 p=(char *) args;
1347 for (x=0; *p != '\0'; x++)
1348 {
1349 GetMagickToken(p,&p,token);
1350 if (*token == ',')
1351 GetMagickToken(p,&p,token);
1352 }
1353 number_arguments=(size_t) x;
1354 arguments=(double *) AcquireQuantumMemory(number_arguments,
1355 sizeof(*arguments));
1356 if (arguments == (double *) NULL)
1357 ThrowWandFatalException(ResourceLimitFatalError,
1358 "MemoryAllocationFailed",(*image)->filename);
1359 (void) ResetMagickMemory(arguments,0,number_arguments*
1360 sizeof(*arguments));
1361 p=(char *) args;
1362 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1363 {
1364 GetMagickToken(p,&p,token);
1365 if (*token == ',')
1366 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001367 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001368 }
1369 args=DestroyString(args);
1370 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1371 (*option == '+') ? MagickTrue : MagickFalse,exception);
1372 arguments=(double *) RelinquishMagickMemory(arguments);
1373 break;
1374 }
1375 if (LocaleCompare("dither",option+1) == 0)
1376 {
1377 if (*option == '+')
1378 {
1379 quantize_info->dither=MagickFalse;
1380 break;
1381 }
1382 quantize_info->dither=MagickTrue;
1383 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1384 MagickDitherOptions,MagickFalse,argv[i+1]);
1385 if (quantize_info->dither_method == NoDitherMethod)
1386 quantize_info->dither=MagickFalse;
1387 break;
1388 }
1389 if (LocaleCompare("draw",option+1) == 0)
1390 {
1391 /*
1392 Draw image.
1393 */
1394 (void) SyncImageSettings(mogrify_info,*image);
1395 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001396 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001397 break;
1398 }
1399 break;
1400 }
1401 case 'e':
1402 {
1403 if (LocaleCompare("edge",option+1) == 0)
1404 {
1405 /*
1406 Enhance edges in the image.
1407 */
1408 (void) SyncImageSettings(mogrify_info,*image);
1409 flags=ParseGeometry(argv[i+1],&geometry_info);
1410 if ((flags & SigmaValue) == 0)
1411 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001412 mogrify_image=EdgeImage(*image,geometry_info.rho,
1413 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001414 break;
1415 }
1416 if (LocaleCompare("emboss",option+1) == 0)
1417 {
1418 /*
1419 Gaussian embossen image.
1420 */
1421 (void) SyncImageSettings(mogrify_info,*image);
1422 flags=ParseGeometry(argv[i+1],&geometry_info);
1423 if ((flags & SigmaValue) == 0)
1424 geometry_info.sigma=1.0;
1425 mogrify_image=EmbossImage(*image,geometry_info.rho,
1426 geometry_info.sigma,exception);
1427 break;
1428 }
1429 if (LocaleCompare("encipher",option+1) == 0)
1430 {
1431 StringInfo
1432 *passkey;
1433
1434 /*
1435 Encipher pixels.
1436 */
1437 (void) SyncImageSettings(mogrify_info,*image);
1438 passkey=FileToStringInfo(argv[i+1],~0,exception);
1439 if (passkey != (StringInfo *) NULL)
1440 {
1441 (void) PasskeyEncipherImage(*image,passkey,exception);
1442 passkey=DestroyStringInfo(passkey);
1443 }
1444 break;
1445 }
1446 if (LocaleCompare("encoding",option+1) == 0)
1447 {
1448 (void) CloneString(&draw_info->encoding,argv[i+1]);
1449 break;
1450 }
1451 if (LocaleCompare("enhance",option+1) == 0)
1452 {
1453 /*
1454 Enhance image.
1455 */
1456 (void) SyncImageSettings(mogrify_info,*image);
1457 mogrify_image=EnhanceImage(*image,exception);
1458 break;
1459 }
1460 if (LocaleCompare("equalize",option+1) == 0)
1461 {
1462 /*
1463 Equalize image.
1464 */
1465 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001466 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001467 break;
1468 }
1469 if (LocaleCompare("evaluate",option+1) == 0)
1470 {
1471 double
1472 constant;
1473
1474 MagickEvaluateOperator
1475 op;
1476
1477 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001478 op=(MagickEvaluateOperator) ParseCommandOption(
1479 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001480 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001481 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001482 break;
1483 }
1484 if (LocaleCompare("extent",option+1) == 0)
1485 {
1486 /*
1487 Set the image extent.
1488 */
1489 (void) SyncImageSettings(mogrify_info,*image);
1490 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1491 if (geometry.width == 0)
1492 geometry.width=(*image)->columns;
1493 if (geometry.height == 0)
1494 geometry.height=(*image)->rows;
1495 mogrify_image=ExtentImage(*image,&geometry,exception);
1496 break;
1497 }
1498 break;
1499 }
1500 case 'f':
1501 {
1502 if (LocaleCompare("family",option+1) == 0)
1503 {
1504 if (*option == '+')
1505 {
1506 if (draw_info->family != (char *) NULL)
1507 draw_info->family=DestroyString(draw_info->family);
1508 break;
1509 }
1510 (void) CloneString(&draw_info->family,argv[i+1]);
1511 break;
1512 }
1513 if (LocaleCompare("features",option+1) == 0)
1514 {
1515 if (*option == '+')
1516 {
1517 (void) DeleteImageArtifact(*image,"identify:features");
1518 break;
1519 }
1520 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1521 break;
1522 }
1523 if (LocaleCompare("fill",option+1) == 0)
1524 {
1525 ExceptionInfo
1526 *sans;
1527
cristy4c08aed2011-07-01 19:47:50 +00001528 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001529 if (*option == '+')
1530 {
1531 (void) QueryMagickColor("none",&fill,exception);
1532 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1533 if (draw_info->fill_pattern != (Image *) NULL)
1534 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1535 break;
1536 }
1537 sans=AcquireExceptionInfo();
1538 (void) QueryMagickColor(argv[i+1],&fill,sans);
1539 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1540 sans=DestroyExceptionInfo(sans);
1541 if (status == MagickFalse)
1542 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1543 exception);
1544 break;
1545 }
1546 if (LocaleCompare("flip",option+1) == 0)
1547 {
1548 /*
1549 Flip image scanlines.
1550 */
1551 (void) SyncImageSettings(mogrify_info,*image);
1552 mogrify_image=FlipImage(*image,exception);
1553 break;
1554 }
anthonydf8ebac2011-04-27 09:03:19 +00001555 if (LocaleCompare("floodfill",option+1) == 0)
1556 {
cristy4c08aed2011-07-01 19:47:50 +00001557 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001558 target;
1559
1560 /*
1561 Floodfill image.
1562 */
1563 (void) SyncImageSettings(mogrify_info,*image);
1564 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1565 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001566 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001567 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001568 break;
1569 }
anthony3d2f4862011-05-01 13:48:16 +00001570 if (LocaleCompare("flop",option+1) == 0)
1571 {
1572 /*
1573 Flop image scanlines.
1574 */
1575 (void) SyncImageSettings(mogrify_info,*image);
1576 mogrify_image=FlopImage(*image,exception);
1577 break;
1578 }
anthonydf8ebac2011-04-27 09:03:19 +00001579 if (LocaleCompare("font",option+1) == 0)
1580 {
1581 if (*option == '+')
1582 {
1583 if (draw_info->font != (char *) NULL)
1584 draw_info->font=DestroyString(draw_info->font);
1585 break;
1586 }
1587 (void) CloneString(&draw_info->font,argv[i+1]);
1588 break;
1589 }
1590 if (LocaleCompare("format",option+1) == 0)
1591 {
1592 format=argv[i+1];
1593 break;
1594 }
1595 if (LocaleCompare("frame",option+1) == 0)
1596 {
1597 FrameInfo
1598 frame_info;
1599
1600 /*
1601 Surround image with an ornamental border.
1602 */
1603 (void) SyncImageSettings(mogrify_info,*image);
1604 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1605 frame_info.width=geometry.width;
1606 frame_info.height=geometry.height;
1607 if ((flags & HeightValue) == 0)
1608 frame_info.height=geometry.width;
1609 frame_info.outer_bevel=geometry.x;
1610 frame_info.inner_bevel=geometry.y;
1611 frame_info.x=(ssize_t) frame_info.width;
1612 frame_info.y=(ssize_t) frame_info.height;
1613 frame_info.width=(*image)->columns+2*frame_info.width;
1614 frame_info.height=(*image)->rows+2*frame_info.height;
1615 mogrify_image=FrameImage(*image,&frame_info,exception);
1616 break;
1617 }
1618 if (LocaleCompare("function",option+1) == 0)
1619 {
1620 char
1621 *arguments,
1622 token[MaxTextExtent];
1623
1624 const char
1625 *p;
1626
1627 double
1628 *parameters;
1629
1630 MagickFunction
1631 function;
1632
1633 register ssize_t
1634 x;
1635
1636 size_t
1637 number_parameters;
1638
1639 /*
1640 Function Modify Image Values
1641 */
1642 (void) SyncImageSettings(mogrify_info,*image);
1643 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1644 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001645 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1646 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001647 if (arguments == (char *) NULL)
1648 break;
1649 p=(char *) arguments;
1650 for (x=0; *p != '\0'; x++)
1651 {
1652 GetMagickToken(p,&p,token);
1653 if (*token == ',')
1654 GetMagickToken(p,&p,token);
1655 }
1656 number_parameters=(size_t) x;
1657 parameters=(double *) AcquireQuantumMemory(number_parameters,
1658 sizeof(*parameters));
1659 if (parameters == (double *) NULL)
1660 ThrowWandFatalException(ResourceLimitFatalError,
1661 "MemoryAllocationFailed",(*image)->filename);
1662 (void) ResetMagickMemory(parameters,0,number_parameters*
1663 sizeof(*parameters));
1664 p=(char *) arguments;
1665 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1666 {
1667 GetMagickToken(p,&p,token);
1668 if (*token == ',')
1669 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001670 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001671 }
1672 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001673 (void) FunctionImage(*image,function,number_parameters,parameters,
1674 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001675 parameters=(double *) RelinquishMagickMemory(parameters);
1676 break;
1677 }
1678 break;
1679 }
1680 case 'g':
1681 {
1682 if (LocaleCompare("gamma",option+1) == 0)
1683 {
1684 /*
1685 Gamma image.
1686 */
1687 (void) SyncImageSettings(mogrify_info,*image);
1688 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001689 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001690 else
cristyb3e7c6c2011-07-24 01:43:55 +00001691 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1692 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001693 break;
1694 }
1695 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1696 (LocaleCompare("gaussian",option+1) == 0))
1697 {
1698 /*
1699 Gaussian blur image.
1700 */
1701 (void) SyncImageSettings(mogrify_info,*image);
1702 flags=ParseGeometry(argv[i+1],&geometry_info);
1703 if ((flags & SigmaValue) == 0)
1704 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001705 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1706 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001707 break;
1708 }
1709 if (LocaleCompare("geometry",option+1) == 0)
1710 {
1711 /*
1712 Record Image offset, Resize last image.
1713 */
1714 (void) SyncImageSettings(mogrify_info,*image);
1715 if (*option == '+')
1716 {
1717 if ((*image)->geometry != (char *) NULL)
1718 (*image)->geometry=DestroyString((*image)->geometry);
1719 break;
1720 }
1721 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1722 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1723 (void) CloneString(&(*image)->geometry,argv[i+1]);
1724 else
1725 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1726 (*image)->filter,(*image)->blur,exception);
1727 break;
1728 }
1729 if (LocaleCompare("gravity",option+1) == 0)
1730 {
1731 if (*option == '+')
1732 {
1733 draw_info->gravity=UndefinedGravity;
1734 break;
1735 }
1736 draw_info->gravity=(GravityType) ParseCommandOption(
1737 MagickGravityOptions,MagickFalse,argv[i+1]);
1738 break;
1739 }
1740 break;
1741 }
1742 case 'h':
1743 {
1744 if (LocaleCompare("highlight-color",option+1) == 0)
1745 {
1746 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1747 break;
1748 }
1749 break;
1750 }
1751 case 'i':
1752 {
1753 if (LocaleCompare("identify",option+1) == 0)
1754 {
1755 char
1756 *text;
1757
1758 (void) SyncImageSettings(mogrify_info,*image);
1759 if (format == (char *) NULL)
1760 {
cristya4037272011-08-28 15:11:39 +00001761 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1762 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001763 break;
1764 }
cristy018f07f2011-09-04 21:15:19 +00001765 text=InterpretImageProperties(mogrify_info,*image,format,
1766 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001767 if (text == (char *) NULL)
1768 break;
1769 (void) fputs(text,stdout);
1770 (void) fputc('\n',stdout);
1771 text=DestroyString(text);
1772 break;
1773 }
1774 if (LocaleCompare("implode",option+1) == 0)
1775 {
1776 /*
1777 Implode image.
1778 */
1779 (void) SyncImageSettings(mogrify_info,*image);
1780 (void) ParseGeometry(argv[i+1],&geometry_info);
1781 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1782 break;
1783 }
1784 if (LocaleCompare("interline-spacing",option+1) == 0)
1785 {
1786 if (*option == '+')
1787 (void) ParseGeometry("0",&geometry_info);
1788 else
1789 (void) ParseGeometry(argv[i+1],&geometry_info);
1790 draw_info->interline_spacing=geometry_info.rho;
1791 break;
1792 }
1793 if (LocaleCompare("interword-spacing",option+1) == 0)
1794 {
1795 if (*option == '+')
1796 (void) ParseGeometry("0",&geometry_info);
1797 else
1798 (void) ParseGeometry(argv[i+1],&geometry_info);
1799 draw_info->interword_spacing=geometry_info.rho;
1800 break;
1801 }
1802 break;
1803 }
1804 case 'k':
1805 {
1806 if (LocaleCompare("kerning",option+1) == 0)
1807 {
1808 if (*option == '+')
1809 (void) ParseGeometry("0",&geometry_info);
1810 else
1811 (void) ParseGeometry(argv[i+1],&geometry_info);
1812 draw_info->kerning=geometry_info.rho;
1813 break;
1814 }
1815 break;
1816 }
1817 case 'l':
1818 {
1819 if (LocaleCompare("lat",option+1) == 0)
1820 {
1821 /*
1822 Local adaptive threshold image.
1823 */
1824 (void) SyncImageSettings(mogrify_info,*image);
1825 flags=ParseGeometry(argv[i+1],&geometry_info);
1826 if ((flags & PercentValue) != 0)
1827 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1828 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001829 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001830 geometry_info.xi,exception);
1831 break;
1832 }
1833 if (LocaleCompare("level",option+1) == 0)
1834 {
1835 MagickRealType
1836 black_point,
1837 gamma,
1838 white_point;
1839
1840 MagickStatusType
1841 flags;
1842
1843 /*
1844 Parse levels.
1845 */
1846 (void) SyncImageSettings(mogrify_info,*image);
1847 flags=ParseGeometry(argv[i+1],&geometry_info);
1848 black_point=geometry_info.rho;
1849 white_point=(MagickRealType) QuantumRange;
1850 if ((flags & SigmaValue) != 0)
1851 white_point=geometry_info.sigma;
1852 gamma=1.0;
1853 if ((flags & XiValue) != 0)
1854 gamma=geometry_info.xi;
1855 if ((flags & PercentValue) != 0)
1856 {
1857 black_point*=(MagickRealType) (QuantumRange/100.0);
1858 white_point*=(MagickRealType) (QuantumRange/100.0);
1859 }
1860 if ((flags & SigmaValue) == 0)
1861 white_point=(MagickRealType) QuantumRange-black_point;
1862 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001863 (void) LevelizeImage(*image,black_point,white_point,gamma,
1864 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001865 else
cristy01e9afd2011-08-10 17:38:41 +00001866 (void) LevelImage(*image,black_point,white_point,gamma,
1867 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001868 InheritException(exception,&(*image)->exception);
1869 break;
1870 }
1871 if (LocaleCompare("level-colors",option+1) == 0)
1872 {
1873 char
1874 token[MaxTextExtent];
1875
1876 const char
1877 *p;
1878
cristy4c08aed2011-07-01 19:47:50 +00001879 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001880 black_point,
1881 white_point;
1882
1883 p=(const char *) argv[i+1];
1884 GetMagickToken(p,&p,token); /* get black point color */
1885 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1886 (void) QueryMagickColor(token,&black_point,exception);
1887 else
1888 (void) QueryMagickColor("#000000",&black_point,exception);
1889 if (isalpha((int) token[0]) || (token[0] == '#'))
1890 GetMagickToken(p,&p,token);
1891 if (*token == '\0')
1892 white_point=black_point; /* set everything to that color */
1893 else
1894 {
1895 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1896 GetMagickToken(p,&p,token); /* Get white point color. */
1897 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1898 (void) QueryMagickColor(token,&white_point,exception);
1899 else
1900 (void) QueryMagickColor("#ffffff",&white_point,exception);
1901 }
cristy490408a2011-07-07 14:42:05 +00001902 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001903 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001904 break;
1905 }
1906 if (LocaleCompare("linear-stretch",option+1) == 0)
1907 {
1908 double
1909 black_point,
1910 white_point;
1911
1912 MagickStatusType
1913 flags;
1914
1915 (void) SyncImageSettings(mogrify_info,*image);
1916 flags=ParseGeometry(argv[i+1],&geometry_info);
1917 black_point=geometry_info.rho;
1918 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1919 if ((flags & SigmaValue) != 0)
1920 white_point=geometry_info.sigma;
1921 if ((flags & PercentValue) != 0)
1922 {
1923 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1924 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1925 }
1926 if ((flags & SigmaValue) == 0)
1927 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1928 black_point;
cristy33bd5152011-08-24 01:42:24 +00001929 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001930 InheritException(exception,&(*image)->exception);
1931 break;
1932 }
1933 if (LocaleCompare("linewidth",option+1) == 0)
1934 {
cristyc1acd842011-05-19 23:05:47 +00001935 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1936 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001937 break;
1938 }
1939 if (LocaleCompare("liquid-rescale",option+1) == 0)
1940 {
1941 /*
1942 Liquid rescale image.
1943 */
1944 (void) SyncImageSettings(mogrify_info,*image);
1945 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1946 if ((flags & XValue) == 0)
1947 geometry.x=1;
1948 if ((flags & YValue) == 0)
1949 geometry.y=0;
1950 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1951 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1952 break;
1953 }
1954 if (LocaleCompare("lowlight-color",option+1) == 0)
1955 {
1956 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1957 break;
1958 }
1959 break;
1960 }
1961 case 'm':
1962 {
1963 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001964 {
cristy3ed852e2009-09-05 21:47:34 +00001965 Image
anthonydf8ebac2011-04-27 09:03:19 +00001966 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001967
anthonydf8ebac2011-04-27 09:03:19 +00001968 /*
1969 Transform image colors to match this set of colors.
1970 */
1971 (void) SyncImageSettings(mogrify_info,*image);
1972 if (*option == '+')
1973 break;
1974 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1975 if (remap_image == (Image *) NULL)
1976 break;
cristy018f07f2011-09-04 21:15:19 +00001977 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001978 remap_image=DestroyImage(remap_image);
1979 break;
1980 }
1981 if (LocaleCompare("mask",option+1) == 0)
1982 {
1983 Image
1984 *mask;
1985
1986 (void) SyncImageSettings(mogrify_info,*image);
1987 if (*option == '+')
1988 {
1989 /*
1990 Remove a mask.
1991 */
cristy018f07f2011-09-04 21:15:19 +00001992 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001993 break;
1994 }
1995 /*
1996 Set the image mask.
1997 */
1998 mask=GetImageCache(mogrify_info,argv[i+1],exception);
1999 if (mask == (Image *) NULL)
2000 break;
cristy018f07f2011-09-04 21:15:19 +00002001 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002002 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002003 break;
2004 }
2005 if (LocaleCompare("matte",option+1) == 0)
2006 {
2007 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002008 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002009 break;
2010 }
2011 if (LocaleCompare("median",option+1) == 0)
2012 {
2013 /*
2014 Median filter image.
2015 */
2016 (void) SyncImageSettings(mogrify_info,*image);
2017 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002018 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2019 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002020 break;
2021 }
2022 if (LocaleCompare("mode",option+1) == 0)
2023 {
2024 /*
2025 Mode image.
2026 */
2027 (void) SyncImageSettings(mogrify_info,*image);
2028 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002029 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2030 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002031 break;
2032 }
2033 if (LocaleCompare("modulate",option+1) == 0)
2034 {
2035 (void) SyncImageSettings(mogrify_info,*image);
cristy33bd5152011-08-24 01:42:24 +00002036 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002037 break;
2038 }
2039 if (LocaleCompare("monitor",option+1) == 0)
2040 {
2041 if (*option == '+')
2042 {
2043 (void) SetImageProgressMonitor(*image,
2044 (MagickProgressMonitor) NULL,(void *) NULL);
2045 break;
2046 }
2047 (void) SetImageProgressMonitor(*image,MonitorProgress,
2048 (void *) NULL);
2049 break;
2050 }
2051 if (LocaleCompare("monochrome",option+1) == 0)
2052 {
2053 (void) SyncImageSettings(mogrify_info,*image);
cristy018f07f2011-09-04 21:15:19 +00002054 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002055 break;
2056 }
2057 if (LocaleCompare("morphology",option+1) == 0)
2058 {
2059 char
2060 token[MaxTextExtent];
2061
2062 const char
2063 *p;
2064
2065 KernelInfo
2066 *kernel;
2067
2068 MorphologyMethod
2069 method;
2070
2071 ssize_t
2072 iterations;
2073
2074 /*
2075 Morphological Image Operation
2076 */
2077 (void) SyncImageSettings(mogrify_info,*image);
2078 p=argv[i+1];
2079 GetMagickToken(p,&p,token);
2080 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2081 MagickFalse,token);
2082 iterations=1L;
2083 GetMagickToken(p,&p,token);
2084 if ((*p == ':') || (*p == ','))
2085 GetMagickToken(p,&p,token);
2086 if ((*p != '\0'))
2087 iterations=(ssize_t) StringToLong(p);
2088 kernel=AcquireKernelInfo(argv[i+2]);
2089 if (kernel == (KernelInfo *) NULL)
2090 {
2091 (void) ThrowMagickException(exception,GetMagickModule(),
2092 OptionError,"UnabletoParseKernel","morphology");
2093 status=MagickFalse;
2094 break;
2095 }
cristyf4ad9df2011-07-08 16:49:03 +00002096 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2097 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002098 kernel=DestroyKernelInfo(kernel);
2099 break;
2100 }
2101 if (LocaleCompare("motion-blur",option+1) == 0)
2102 {
2103 /*
2104 Motion blur image.
2105 */
2106 (void) SyncImageSettings(mogrify_info,*image);
2107 flags=ParseGeometry(argv[i+1],&geometry_info);
2108 if ((flags & SigmaValue) == 0)
2109 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002110 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2111 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002112 break;
2113 }
2114 break;
2115 }
2116 case 'n':
2117 {
2118 if (LocaleCompare("negate",option+1) == 0)
2119 {
2120 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002121 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002122 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002123 break;
2124 }
2125 if (LocaleCompare("noise",option+1) == 0)
2126 {
2127 (void) SyncImageSettings(mogrify_info,*image);
2128 if (*option == '-')
2129 {
2130 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002131 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2132 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002133 }
2134 else
2135 {
2136 NoiseType
2137 noise;
2138
2139 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2140 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002141 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002142 }
2143 break;
2144 }
2145 if (LocaleCompare("normalize",option+1) == 0)
2146 {
2147 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002148 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002149 break;
2150 }
2151 break;
2152 }
2153 case 'o':
2154 {
2155 if (LocaleCompare("opaque",option+1) == 0)
2156 {
cristy4c08aed2011-07-01 19:47:50 +00002157 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002158 target;
2159
2160 (void) SyncImageSettings(mogrify_info,*image);
2161 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002162 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002163 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002164 break;
2165 }
2166 if (LocaleCompare("ordered-dither",option+1) == 0)
2167 {
2168 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002169 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002170 break;
2171 }
2172 break;
2173 }
2174 case 'p':
2175 {
2176 if (LocaleCompare("paint",option+1) == 0)
2177 {
anthonydf8ebac2011-04-27 09:03:19 +00002178 (void) SyncImageSettings(mogrify_info,*image);
2179 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002180 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2181 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002182 break;
2183 }
2184 if (LocaleCompare("pen",option+1) == 0)
2185 {
2186 if (*option == '+')
2187 {
2188 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2189 break;
2190 }
2191 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2192 break;
2193 }
2194 if (LocaleCompare("pointsize",option+1) == 0)
2195 {
2196 if (*option == '+')
2197 (void) ParseGeometry("12",&geometry_info);
2198 else
2199 (void) ParseGeometry(argv[i+1],&geometry_info);
2200 draw_info->pointsize=geometry_info.rho;
2201 break;
2202 }
2203 if (LocaleCompare("polaroid",option+1) == 0)
2204 {
2205 double
2206 angle;
2207
2208 RandomInfo
2209 *random_info;
2210
2211 /*
2212 Simulate a Polaroid picture.
2213 */
2214 (void) SyncImageSettings(mogrify_info,*image);
2215 random_info=AcquireRandomInfo();
2216 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2217 random_info=DestroyRandomInfo(random_info);
2218 if (*option == '-')
2219 {
2220 SetGeometryInfo(&geometry_info);
2221 flags=ParseGeometry(argv[i+1],&geometry_info);
2222 angle=geometry_info.rho;
2223 }
2224 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2225 break;
2226 }
2227 if (LocaleCompare("posterize",option+1) == 0)
2228 {
2229 /*
2230 Posterize image.
2231 */
2232 (void) SyncImageSettings(mogrify_info,*image);
2233 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002234 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002235 break;
2236 }
2237 if (LocaleCompare("preview",option+1) == 0)
2238 {
2239 PreviewType
2240 preview_type;
2241
2242 /*
2243 Preview image.
2244 */
2245 (void) SyncImageSettings(mogrify_info,*image);
2246 if (*option == '+')
2247 preview_type=UndefinedPreview;
2248 else
2249 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2250 MagickFalse,argv[i+1]);
2251 mogrify_image=PreviewImage(*image,preview_type,exception);
2252 break;
2253 }
2254 if (LocaleCompare("profile",option+1) == 0)
2255 {
2256 const char
2257 *name;
2258
2259 const StringInfo
2260 *profile;
2261
2262 Image
2263 *profile_image;
2264
2265 ImageInfo
2266 *profile_info;
2267
2268 (void) SyncImageSettings(mogrify_info,*image);
2269 if (*option == '+')
2270 {
2271 /*
2272 Remove a profile from the image.
2273 */
2274 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2275 NULL,0,MagickTrue);
2276 InheritException(exception,&(*image)->exception);
2277 break;
2278 }
2279 /*
2280 Associate a profile with the image.
2281 */
2282 profile_info=CloneImageInfo(mogrify_info);
2283 profile=GetImageProfile(*image,"iptc");
2284 if (profile != (StringInfo *) NULL)
2285 profile_info->profile=(void *) CloneStringInfo(profile);
2286 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2287 profile_info=DestroyImageInfo(profile_info);
2288 if (profile_image == (Image *) NULL)
2289 {
2290 StringInfo
2291 *profile;
2292
2293 profile_info=CloneImageInfo(mogrify_info);
2294 (void) CopyMagickString(profile_info->filename,argv[i+1],
2295 MaxTextExtent);
2296 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2297 if (profile != (StringInfo *) NULL)
2298 {
2299 (void) ProfileImage(*image,profile_info->magick,
2300 GetStringInfoDatum(profile),(size_t)
2301 GetStringInfoLength(profile),MagickFalse);
2302 profile=DestroyStringInfo(profile);
2303 }
2304 profile_info=DestroyImageInfo(profile_info);
2305 break;
2306 }
2307 ResetImageProfileIterator(profile_image);
2308 name=GetNextImageProfile(profile_image);
2309 while (name != (const char *) NULL)
2310 {
2311 profile=GetImageProfile(profile_image,name);
2312 if (profile != (StringInfo *) NULL)
2313 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2314 (size_t) GetStringInfoLength(profile),MagickFalse);
2315 name=GetNextImageProfile(profile_image);
2316 }
2317 profile_image=DestroyImage(profile_image);
2318 break;
2319 }
2320 break;
2321 }
2322 case 'q':
2323 {
2324 if (LocaleCompare("quantize",option+1) == 0)
2325 {
2326 if (*option == '+')
2327 {
2328 quantize_info->colorspace=UndefinedColorspace;
2329 break;
2330 }
2331 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2332 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2333 break;
2334 }
2335 break;
2336 }
2337 case 'r':
2338 {
2339 if (LocaleCompare("radial-blur",option+1) == 0)
2340 {
2341 /*
2342 Radial blur image.
2343 */
2344 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002345 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2346 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002347 break;
2348 }
2349 if (LocaleCompare("raise",option+1) == 0)
2350 {
2351 /*
2352 Surround image with a raise of solid color.
2353 */
2354 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2355 if ((flags & SigmaValue) == 0)
2356 geometry.height=geometry.width;
2357 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002358 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002359 break;
2360 }
2361 if (LocaleCompare("random-threshold",option+1) == 0)
2362 {
2363 /*
2364 Threshold image.
2365 */
2366 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002367 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002368 break;
2369 }
2370 if (LocaleCompare("recolor",option+1) == 0)
2371 {
2372 KernelInfo
2373 *kernel;
2374
2375 (void) SyncImageSettings(mogrify_info,*image);
2376 kernel=AcquireKernelInfo(argv[i+1]);
2377 if (kernel == (KernelInfo *) NULL)
2378 break;
2379 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2380 kernel=DestroyKernelInfo(kernel);
2381 break;
2382 }
2383 if (LocaleCompare("region",option+1) == 0)
2384 {
2385 (void) SyncImageSettings(mogrify_info,*image);
2386 if (region_image != (Image *) NULL)
2387 {
2388 /*
2389 Composite region.
2390 */
2391 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002392 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2393 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002394 InheritException(exception,&region_image->exception);
2395 *image=DestroyImage(*image);
2396 *image=region_image;
2397 region_image = (Image *) NULL;
2398 }
2399 if (*option == '+')
2400 break;
2401 /*
2402 Apply transformations to a selected region of the image.
2403 */
cristy3ed852e2009-09-05 21:47:34 +00002404 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2405 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002406 mogrify_image=CropImage(*image,&region_geometry,exception);
2407 if (mogrify_image == (Image *) NULL)
2408 break;
2409 region_image=(*image);
2410 *image=mogrify_image;
2411 mogrify_image=(Image *) NULL;
2412 break;
cristy3ed852e2009-09-05 21:47:34 +00002413 }
anthonydf8ebac2011-04-27 09:03:19 +00002414 if (LocaleCompare("render",option+1) == 0)
2415 {
2416 (void) SyncImageSettings(mogrify_info,*image);
2417 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2418 break;
2419 }
2420 if (LocaleCompare("remap",option+1) == 0)
2421 {
2422 Image
2423 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002424
anthonydf8ebac2011-04-27 09:03:19 +00002425 /*
2426 Transform image colors to match this set of colors.
2427 */
2428 (void) SyncImageSettings(mogrify_info,*image);
2429 if (*option == '+')
2430 break;
2431 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2432 if (remap_image == (Image *) NULL)
2433 break;
cristy018f07f2011-09-04 21:15:19 +00002434 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002435 remap_image=DestroyImage(remap_image);
2436 break;
2437 }
2438 if (LocaleCompare("repage",option+1) == 0)
2439 {
2440 if (*option == '+')
2441 {
2442 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2443 break;
2444 }
2445 (void) ResetImagePage(*image,argv[i+1]);
2446 InheritException(exception,&(*image)->exception);
2447 break;
2448 }
2449 if (LocaleCompare("resample",option+1) == 0)
2450 {
2451 /*
2452 Resample image.
2453 */
2454 (void) SyncImageSettings(mogrify_info,*image);
2455 flags=ParseGeometry(argv[i+1],&geometry_info);
2456 if ((flags & SigmaValue) == 0)
2457 geometry_info.sigma=geometry_info.rho;
2458 mogrify_image=ResampleImage(*image,geometry_info.rho,
2459 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2460 break;
2461 }
2462 if (LocaleCompare("resize",option+1) == 0)
2463 {
2464 /*
2465 Resize image.
2466 */
2467 (void) SyncImageSettings(mogrify_info,*image);
2468 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2469 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2470 (*image)->filter,(*image)->blur,exception);
2471 break;
2472 }
2473 if (LocaleCompare("roll",option+1) == 0)
2474 {
2475 /*
2476 Roll image.
2477 */
2478 (void) SyncImageSettings(mogrify_info,*image);
2479 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2480 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2481 break;
2482 }
2483 if (LocaleCompare("rotate",option+1) == 0)
2484 {
2485 char
2486 *geometry;
2487
2488 /*
2489 Check for conditional image rotation.
2490 */
2491 (void) SyncImageSettings(mogrify_info,*image);
2492 if (strchr(argv[i+1],'>') != (char *) NULL)
2493 if ((*image)->columns <= (*image)->rows)
2494 break;
2495 if (strchr(argv[i+1],'<') != (char *) NULL)
2496 if ((*image)->columns >= (*image)->rows)
2497 break;
2498 /*
2499 Rotate image.
2500 */
2501 geometry=ConstantString(argv[i+1]);
2502 (void) SubstituteString(&geometry,">","");
2503 (void) SubstituteString(&geometry,"<","");
2504 (void) ParseGeometry(geometry,&geometry_info);
2505 geometry=DestroyString(geometry);
2506 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2507 break;
2508 }
2509 break;
2510 }
2511 case 's':
2512 {
2513 if (LocaleCompare("sample",option+1) == 0)
2514 {
2515 /*
2516 Sample image with pixel replication.
2517 */
2518 (void) SyncImageSettings(mogrify_info,*image);
2519 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2520 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2521 exception);
2522 break;
2523 }
2524 if (LocaleCompare("scale",option+1) == 0)
2525 {
2526 /*
2527 Resize image.
2528 */
2529 (void) SyncImageSettings(mogrify_info,*image);
2530 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2531 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2532 exception);
2533 break;
2534 }
2535 if (LocaleCompare("selective-blur",option+1) == 0)
2536 {
2537 /*
2538 Selectively blur pixels within a contrast threshold.
2539 */
2540 (void) SyncImageSettings(mogrify_info,*image);
2541 flags=ParseGeometry(argv[i+1],&geometry_info);
2542 if ((flags & PercentValue) != 0)
2543 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002544 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2545 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002546 break;
2547 }
2548 if (LocaleCompare("separate",option+1) == 0)
2549 {
2550 /*
2551 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002552 */
2553 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002554 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002555 break;
2556 }
2557 if (LocaleCompare("sepia-tone",option+1) == 0)
2558 {
2559 double
2560 threshold;
2561
2562 /*
2563 Sepia-tone image.
2564 */
2565 (void) SyncImageSettings(mogrify_info,*image);
2566 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2567 mogrify_image=SepiaToneImage(*image,threshold,exception);
2568 break;
2569 }
2570 if (LocaleCompare("segment",option+1) == 0)
2571 {
2572 /*
2573 Segment image.
2574 */
2575 (void) SyncImageSettings(mogrify_info,*image);
2576 flags=ParseGeometry(argv[i+1],&geometry_info);
2577 if ((flags & SigmaValue) == 0)
2578 geometry_info.sigma=1.0;
2579 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002580 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2581 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002582 break;
2583 }
2584 if (LocaleCompare("set",option+1) == 0)
2585 {
2586 char
2587 *value;
2588
2589 /*
2590 Set image option.
2591 */
2592 if (*option == '+')
2593 {
2594 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2595 (void) DeleteImageRegistry(argv[i+1]+9);
2596 else
2597 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2598 {
2599 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2600 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2601 }
2602 else
2603 (void) DeleteImageProperty(*image,argv[i+1]);
2604 break;
2605 }
cristy018f07f2011-09-04 21:15:19 +00002606 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2607 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002608 if (value == (char *) NULL)
2609 break;
2610 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2611 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2612 exception);
2613 else
2614 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2615 {
2616 (void) SetImageOption(image_info,argv[i+1]+7,value);
2617 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2618 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2619 }
2620 else
2621 (void) SetImageProperty(*image,argv[i+1],value);
2622 value=DestroyString(value);
2623 break;
2624 }
2625 if (LocaleCompare("shade",option+1) == 0)
2626 {
2627 /*
2628 Shade image.
2629 */
2630 (void) SyncImageSettings(mogrify_info,*image);
2631 flags=ParseGeometry(argv[i+1],&geometry_info);
2632 if ((flags & SigmaValue) == 0)
2633 geometry_info.sigma=1.0;
2634 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2635 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2636 break;
2637 }
2638 if (LocaleCompare("shadow",option+1) == 0)
2639 {
2640 /*
2641 Shadow image.
2642 */
2643 (void) SyncImageSettings(mogrify_info,*image);
2644 flags=ParseGeometry(argv[i+1],&geometry_info);
2645 if ((flags & SigmaValue) == 0)
2646 geometry_info.sigma=1.0;
2647 if ((flags & XiValue) == 0)
2648 geometry_info.xi=4.0;
2649 if ((flags & PsiValue) == 0)
2650 geometry_info.psi=4.0;
2651 mogrify_image=ShadowImage(*image,geometry_info.rho,
2652 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2653 ceil(geometry_info.psi-0.5),exception);
2654 break;
2655 }
2656 if (LocaleCompare("sharpen",option+1) == 0)
2657 {
2658 /*
2659 Sharpen image.
2660 */
2661 (void) SyncImageSettings(mogrify_info,*image);
2662 flags=ParseGeometry(argv[i+1],&geometry_info);
2663 if ((flags & SigmaValue) == 0)
2664 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002665 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002666 geometry_info.sigma,exception);
2667 break;
2668 }
2669 if (LocaleCompare("shave",option+1) == 0)
2670 {
2671 /*
2672 Shave the image edges.
2673 */
2674 (void) SyncImageSettings(mogrify_info,*image);
2675 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2676 mogrify_image=ShaveImage(*image,&geometry,exception);
2677 break;
2678 }
2679 if (LocaleCompare("shear",option+1) == 0)
2680 {
2681 /*
2682 Shear image.
2683 */
2684 (void) SyncImageSettings(mogrify_info,*image);
2685 flags=ParseGeometry(argv[i+1],&geometry_info);
2686 if ((flags & SigmaValue) == 0)
2687 geometry_info.sigma=geometry_info.rho;
2688 mogrify_image=ShearImage(*image,geometry_info.rho,
2689 geometry_info.sigma,exception);
2690 break;
2691 }
2692 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2693 {
2694 /*
2695 Sigmoidal non-linearity contrast control.
2696 */
2697 (void) SyncImageSettings(mogrify_info,*image);
2698 flags=ParseGeometry(argv[i+1],&geometry_info);
2699 if ((flags & SigmaValue) == 0)
2700 geometry_info.sigma=(double) QuantumRange/2.0;
2701 if ((flags & PercentValue) != 0)
2702 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2703 100.0;
cristy9ee60942011-07-06 14:54:38 +00002704 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002705 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2706 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002707 break;
2708 }
2709 if (LocaleCompare("sketch",option+1) == 0)
2710 {
2711 /*
2712 Sketch image.
2713 */
2714 (void) SyncImageSettings(mogrify_info,*image);
2715 flags=ParseGeometry(argv[i+1],&geometry_info);
2716 if ((flags & SigmaValue) == 0)
2717 geometry_info.sigma=1.0;
2718 mogrify_image=SketchImage(*image,geometry_info.rho,
2719 geometry_info.sigma,geometry_info.xi,exception);
2720 break;
2721 }
2722 if (LocaleCompare("solarize",option+1) == 0)
2723 {
2724 double
2725 threshold;
2726
2727 (void) SyncImageSettings(mogrify_info,*image);
2728 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristy5cbc0162011-08-29 00:36:28 +00002729 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002730 break;
2731 }
2732 if (LocaleCompare("sparse-color",option+1) == 0)
2733 {
2734 SparseColorMethod
2735 method;
2736
2737 char
2738 *arguments;
2739
2740 /*
2741 Sparse Color Interpolated Gradient
2742 */
2743 (void) SyncImageSettings(mogrify_info,*image);
2744 method=(SparseColorMethod) ParseCommandOption(
2745 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002746 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2747 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002748 if (arguments == (char *) NULL)
2749 break;
cristy3884f692011-07-08 18:00:18 +00002750 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002751 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2752 arguments=DestroyString(arguments);
2753 break;
2754 }
2755 if (LocaleCompare("splice",option+1) == 0)
2756 {
2757 /*
2758 Splice a solid color into the image.
2759 */
2760 (void) SyncImageSettings(mogrify_info,*image);
2761 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2762 mogrify_image=SpliceImage(*image,&geometry,exception);
2763 break;
2764 }
2765 if (LocaleCompare("spread",option+1) == 0)
2766 {
2767 /*
2768 Spread an image.
2769 */
2770 (void) SyncImageSettings(mogrify_info,*image);
2771 (void) ParseGeometry(argv[i+1],&geometry_info);
2772 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2773 break;
2774 }
2775 if (LocaleCompare("statistic",option+1) == 0)
2776 {
2777 StatisticType
2778 type;
2779
2780 (void) SyncImageSettings(mogrify_info,*image);
2781 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2782 MagickFalse,argv[i+1]);
2783 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002784 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2785 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002786 break;
2787 }
2788 if (LocaleCompare("stretch",option+1) == 0)
2789 {
2790 if (*option == '+')
2791 {
2792 draw_info->stretch=UndefinedStretch;
2793 break;
2794 }
2795 draw_info->stretch=(StretchType) ParseCommandOption(
2796 MagickStretchOptions,MagickFalse,argv[i+1]);
2797 break;
2798 }
2799 if (LocaleCompare("strip",option+1) == 0)
2800 {
2801 /*
2802 Strip image of profiles and comments.
2803 */
2804 (void) SyncImageSettings(mogrify_info,*image);
2805 (void) StripImage(*image);
2806 InheritException(exception,&(*image)->exception);
2807 break;
2808 }
2809 if (LocaleCompare("stroke",option+1) == 0)
2810 {
2811 ExceptionInfo
2812 *sans;
2813
2814 if (*option == '+')
2815 {
2816 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2817 if (draw_info->stroke_pattern != (Image *) NULL)
2818 draw_info->stroke_pattern=DestroyImage(
2819 draw_info->stroke_pattern);
2820 break;
2821 }
2822 sans=AcquireExceptionInfo();
2823 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2824 sans=DestroyExceptionInfo(sans);
2825 if (status == MagickFalse)
2826 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2827 exception);
2828 break;
2829 }
2830 if (LocaleCompare("strokewidth",option+1) == 0)
2831 {
cristyc1acd842011-05-19 23:05:47 +00002832 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2833 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002834 break;
2835 }
2836 if (LocaleCompare("style",option+1) == 0)
2837 {
2838 if (*option == '+')
2839 {
2840 draw_info->style=UndefinedStyle;
2841 break;
2842 }
2843 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2844 MagickFalse,argv[i+1]);
2845 break;
2846 }
2847 if (LocaleCompare("swirl",option+1) == 0)
2848 {
2849 /*
2850 Swirl image.
2851 */
2852 (void) SyncImageSettings(mogrify_info,*image);
2853 (void) ParseGeometry(argv[i+1],&geometry_info);
2854 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2855 break;
2856 }
2857 break;
2858 }
2859 case 't':
2860 {
2861 if (LocaleCompare("threshold",option+1) == 0)
2862 {
2863 double
2864 threshold;
2865
2866 /*
2867 Threshold image.
2868 */
2869 (void) SyncImageSettings(mogrify_info,*image);
2870 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002871 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002872 else
2873 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002874 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002875 InheritException(exception,&(*image)->exception);
2876 break;
2877 }
2878 if (LocaleCompare("thumbnail",option+1) == 0)
2879 {
2880 /*
2881 Thumbnail image.
2882 */
2883 (void) SyncImageSettings(mogrify_info,*image);
2884 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2885 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2886 exception);
2887 break;
2888 }
2889 if (LocaleCompare("tile",option+1) == 0)
2890 {
2891 if (*option == '+')
2892 {
2893 if (draw_info->fill_pattern != (Image *) NULL)
2894 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2895 break;
2896 }
2897 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2898 exception);
2899 break;
2900 }
2901 if (LocaleCompare("tint",option+1) == 0)
2902 {
2903 /*
2904 Tint the image.
2905 */
2906 (void) SyncImageSettings(mogrify_info,*image);
2907 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2908 break;
2909 }
2910 if (LocaleCompare("transform",option+1) == 0)
2911 {
2912 /*
2913 Affine transform image.
2914 */
2915 (void) SyncImageSettings(mogrify_info,*image);
2916 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2917 exception);
2918 break;
2919 }
2920 if (LocaleCompare("transparent",option+1) == 0)
2921 {
cristy4c08aed2011-07-01 19:47:50 +00002922 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002923 target;
2924
2925 (void) SyncImageSettings(mogrify_info,*image);
2926 (void) QueryMagickColor(argv[i+1],&target,exception);
2927 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002928 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
2929 &(*image)->exception);
anthonydf8ebac2011-04-27 09:03:19 +00002930 break;
2931 }
2932 if (LocaleCompare("transpose",option+1) == 0)
2933 {
2934 /*
2935 Transpose image scanlines.
2936 */
2937 (void) SyncImageSettings(mogrify_info,*image);
2938 mogrify_image=TransposeImage(*image,exception);
2939 break;
2940 }
2941 if (LocaleCompare("transverse",option+1) == 0)
2942 {
2943 /*
2944 Transverse image scanlines.
2945 */
2946 (void) SyncImageSettings(mogrify_info,*image);
2947 mogrify_image=TransverseImage(*image,exception);
2948 break;
2949 }
2950 if (LocaleCompare("treedepth",option+1) == 0)
2951 {
2952 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2953 break;
2954 }
2955 if (LocaleCompare("trim",option+1) == 0)
2956 {
2957 /*
2958 Trim image.
2959 */
2960 (void) SyncImageSettings(mogrify_info,*image);
2961 mogrify_image=TrimImage(*image,exception);
2962 break;
2963 }
2964 if (LocaleCompare("type",option+1) == 0)
2965 {
2966 ImageType
2967 type;
2968
2969 (void) SyncImageSettings(mogrify_info,*image);
2970 if (*option == '+')
2971 type=UndefinedType;
2972 else
2973 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2974 argv[i+1]);
2975 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00002976 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002977 break;
2978 }
2979 break;
2980 }
2981 case 'u':
2982 {
2983 if (LocaleCompare("undercolor",option+1) == 0)
2984 {
2985 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
2986 exception);
2987 break;
2988 }
2989 if (LocaleCompare("unique",option+1) == 0)
2990 {
2991 if (*option == '+')
2992 {
2993 (void) DeleteImageArtifact(*image,"identify:unique-colors");
2994 break;
2995 }
2996 (void) SetImageArtifact(*image,"identify:unique-colors","true");
2997 (void) SetImageArtifact(*image,"verbose","true");
2998 break;
2999 }
3000 if (LocaleCompare("unique-colors",option+1) == 0)
3001 {
3002 /*
3003 Unique image colors.
3004 */
3005 (void) SyncImageSettings(mogrify_info,*image);
3006 mogrify_image=UniqueImageColors(*image,exception);
3007 break;
3008 }
3009 if (LocaleCompare("unsharp",option+1) == 0)
3010 {
3011 /*
3012 Unsharp mask image.
3013 */
3014 (void) SyncImageSettings(mogrify_info,*image);
3015 flags=ParseGeometry(argv[i+1],&geometry_info);
3016 if ((flags & SigmaValue) == 0)
3017 geometry_info.sigma=1.0;
3018 if ((flags & XiValue) == 0)
3019 geometry_info.xi=1.0;
3020 if ((flags & PsiValue) == 0)
3021 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003022 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3023 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003024 break;
3025 }
3026 break;
3027 }
3028 case 'v':
3029 {
3030 if (LocaleCompare("verbose",option+1) == 0)
3031 {
3032 (void) SetImageArtifact(*image,option+1,
3033 *option == '+' ? "false" : "true");
3034 break;
3035 }
3036 if (LocaleCompare("vignette",option+1) == 0)
3037 {
3038 /*
3039 Vignette image.
3040 */
3041 (void) SyncImageSettings(mogrify_info,*image);
3042 flags=ParseGeometry(argv[i+1],&geometry_info);
3043 if ((flags & SigmaValue) == 0)
3044 geometry_info.sigma=1.0;
3045 if ((flags & XiValue) == 0)
3046 geometry_info.xi=0.1*(*image)->columns;
3047 if ((flags & PsiValue) == 0)
3048 geometry_info.psi=0.1*(*image)->rows;
3049 mogrify_image=VignetteImage(*image,geometry_info.rho,
3050 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3051 ceil(geometry_info.psi-0.5),exception);
3052 break;
3053 }
3054 if (LocaleCompare("virtual-pixel",option+1) == 0)
3055 {
3056 if (*option == '+')
3057 {
3058 (void) SetImageVirtualPixelMethod(*image,
3059 UndefinedVirtualPixelMethod);
3060 break;
3061 }
3062 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3063 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3064 argv[i+1]));
3065 break;
3066 }
3067 break;
3068 }
3069 case 'w':
3070 {
3071 if (LocaleCompare("wave",option+1) == 0)
3072 {
3073 /*
3074 Wave image.
3075 */
3076 (void) SyncImageSettings(mogrify_info,*image);
3077 flags=ParseGeometry(argv[i+1],&geometry_info);
3078 if ((flags & SigmaValue) == 0)
3079 geometry_info.sigma=1.0;
3080 mogrify_image=WaveImage(*image,geometry_info.rho,
3081 geometry_info.sigma,exception);
3082 break;
3083 }
3084 if (LocaleCompare("weight",option+1) == 0)
3085 {
3086 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3087 if (LocaleCompare(argv[i+1],"all") == 0)
3088 draw_info->weight=0;
3089 if (LocaleCompare(argv[i+1],"bold") == 0)
3090 draw_info->weight=700;
3091 if (LocaleCompare(argv[i+1],"bolder") == 0)
3092 if (draw_info->weight <= 800)
3093 draw_info->weight+=100;
3094 if (LocaleCompare(argv[i+1],"lighter") == 0)
3095 if (draw_info->weight >= 100)
3096 draw_info->weight-=100;
3097 if (LocaleCompare(argv[i+1],"normal") == 0)
3098 draw_info->weight=400;
3099 break;
3100 }
3101 if (LocaleCompare("white-threshold",option+1) == 0)
3102 {
3103 /*
3104 White threshold image.
3105 */
3106 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003107 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003108 InheritException(exception,&(*image)->exception);
3109 break;
3110 }
3111 break;
3112 }
3113 default:
3114 break;
3115 }
3116 /*
3117 Replace current image with any image that was generated
3118 */
3119 if (mogrify_image != (Image *) NULL)
3120 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003121 i+=count;
3122 }
3123 if (region_image != (Image *) NULL)
3124 {
anthonydf8ebac2011-04-27 09:03:19 +00003125 /*
3126 Composite transformed region onto image.
3127 */
cristy6b3da3a2010-06-20 02:21:46 +00003128 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003129 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003130 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3131 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003132 InheritException(exception,&region_image->exception);
3133 *image=DestroyImage(*image);
3134 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003135 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003136 }
3137 /*
3138 Free resources.
3139 */
anthonydf8ebac2011-04-27 09:03:19 +00003140 quantize_info=DestroyQuantizeInfo(quantize_info);
3141 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003142 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003143 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003144 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003145 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003146}
3147
3148/*
3149%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3150% %
3151% %
3152% %
cristy5063d812010-10-19 16:28:10 +00003153+ 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 +00003154% %
3155% %
3156% %
3157%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3158%
3159% MogrifyImageCommand() transforms an image or a sequence of images. These
3160% transforms include image scaling, image rotation, color reduction, and
3161% others. The transmogrified image overwrites the original image.
3162%
3163% The format of the MogrifyImageCommand method is:
3164%
3165% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3166% const char **argv,char **metadata,ExceptionInfo *exception)
3167%
3168% A description of each parameter follows:
3169%
3170% o image_info: the image info.
3171%
3172% o argc: the number of elements in the argument vector.
3173%
3174% o argv: A text array containing the command line arguments.
3175%
3176% o metadata: any metadata is returned here.
3177%
3178% o exception: return any errors or warnings in this structure.
3179%
3180*/
3181
3182static MagickBooleanType MogrifyUsage(void)
3183{
3184 static const char
3185 *miscellaneous[]=
3186 {
3187 "-debug events display copious debugging information",
3188 "-help print program options",
3189 "-list type print a list of supported option arguments",
3190 "-log format format of debugging information",
3191 "-version print version information",
3192 (char *) NULL
3193 },
3194 *operators[]=
3195 {
3196 "-adaptive-blur geometry",
3197 " adaptively blur pixels; decrease effect near edges",
3198 "-adaptive-resize geometry",
3199 " adaptively resize image using 'mesh' interpolation",
3200 "-adaptive-sharpen geometry",
3201 " adaptively sharpen pixels; increase effect near edges",
3202 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3203 " transparent, extract, background, or shape",
3204 "-annotate geometry text",
3205 " annotate the image with text",
3206 "-auto-gamma automagically adjust gamma level of image",
3207 "-auto-level automagically adjust color levels of image",
3208 "-auto-orient automagically orient (rotate) image",
3209 "-bench iterations measure performance",
3210 "-black-threshold value",
3211 " force all pixels below the threshold into black",
3212 "-blue-shift simulate a scene at nighttime in the moonlight",
3213 "-blur geometry reduce image noise and reduce detail levels",
3214 "-border geometry surround image with a border of color",
3215 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003216 "-brightness-contrast geometry",
3217 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003218 "-cdl filename color correct with a color decision list",
3219 "-charcoal radius simulate a charcoal drawing",
3220 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003221 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003222 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003223 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003224 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003225 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003226 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003227 "-contrast enhance or reduce the image contrast",
3228 "-contrast-stretch geometry",
3229 " improve contrast by `stretching' the intensity range",
3230 "-convolve coefficients",
3231 " apply a convolution kernel to the image",
3232 "-cycle amount cycle the image colormap",
3233 "-decipher filename convert cipher pixels to plain pixels",
3234 "-deskew threshold straighten an image",
3235 "-despeckle reduce the speckles within an image",
3236 "-distort method args",
3237 " distort images according to given method ad args",
3238 "-draw string annotate the image with a graphic primitive",
3239 "-edge radius apply a filter to detect edges in the image",
3240 "-encipher filename convert plain pixels to cipher pixels",
3241 "-emboss radius emboss an image",
3242 "-enhance apply a digital filter to enhance a noisy image",
3243 "-equalize perform histogram equalization to an image",
3244 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003245 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003246 "-extent geometry set the image size",
3247 "-extract geometry extract area from image",
3248 "-fft implements the discrete Fourier transform (DFT)",
3249 "-flip flip image vertically",
3250 "-floodfill geometry color",
3251 " floodfill the image with color",
3252 "-flop flop image horizontally",
3253 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003254 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003255 " apply function over image values",
3256 "-gamma value level of gamma correction",
3257 "-gaussian-blur geometry",
3258 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003259 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003260 "-identify identify the format and characteristics of the image",
3261 "-ift implements the inverse discrete Fourier transform (DFT)",
3262 "-implode amount implode image pixels about the center",
3263 "-lat geometry local adaptive thresholding",
3264 "-layers method optimize, merge, or compare image layers",
3265 "-level value adjust the level of image contrast",
3266 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003267 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003268 "-linear-stretch geometry",
3269 " improve contrast by `stretching with saturation'",
3270 "-liquid-rescale geometry",
3271 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003272 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003273 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003274 "-modulate value vary the brightness, saturation, and hue",
3275 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003276 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003277 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003278 "-motion-blur geometry",
3279 " simulate motion blur",
3280 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003281 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003282 "-normalize transform image to span the full range of colors",
3283 "-opaque color change this color to the fill color",
3284 "-ordered-dither NxN",
3285 " add a noise pattern to the image with specific",
3286 " amplitudes",
3287 "-paint radius simulate an oil painting",
3288 "-polaroid angle simulate a Polaroid picture",
3289 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003290 "-profile filename add, delete, or apply an image profile",
3291 "-quantize colorspace reduce colors in this colorspace",
3292 "-radial-blur angle radial blur the image",
3293 "-raise value lighten/darken image edges to create a 3-D effect",
3294 "-random-threshold low,high",
3295 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003296 "-region geometry apply options to a portion of the image",
3297 "-render render vector graphics",
3298 "-repage geometry size and location of an image canvas",
3299 "-resample geometry change the resolution of an image",
3300 "-resize geometry resize the image",
3301 "-roll geometry roll an image vertically or horizontally",
3302 "-rotate degrees apply Paeth rotation to the image",
3303 "-sample geometry scale image with pixel sampling",
3304 "-scale geometry scale the image",
3305 "-segment values segment an image",
3306 "-selective-blur geometry",
3307 " selectively blur pixels within a contrast threshold",
3308 "-sepia-tone threshold",
3309 " simulate a sepia-toned photo",
3310 "-set property value set an image property",
3311 "-shade degrees shade the image using a distant light source",
3312 "-shadow geometry simulate an image shadow",
3313 "-sharpen geometry sharpen the image",
3314 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003315 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003316 "-sigmoidal-contrast geometry",
3317 " increase the contrast without saturating highlights or shadows",
3318 "-sketch geometry simulate a pencil sketch",
3319 "-solarize threshold negate all pixels above the threshold level",
3320 "-sparse-color method args",
3321 " fill in a image based on a few color points",
3322 "-splice geometry splice the background color into the image",
3323 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003324 "-statistic type radius",
3325 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003326 "-strip strip image of all profiles and comments",
3327 "-swirl degrees swirl image pixels about the center",
3328 "-threshold value threshold the image",
3329 "-thumbnail geometry create a thumbnail of the image",
3330 "-tile filename tile image when filling a graphic primitive",
3331 "-tint value tint the image with the fill color",
3332 "-transform affine transform image",
3333 "-transparent color make this color transparent within the image",
3334 "-transpose flip image vertically and rotate 90 degrees",
3335 "-transverse flop image horizontally and rotate 270 degrees",
3336 "-trim trim image edges",
3337 "-type type image type",
3338 "-unique-colors discard all but one of any pixel color",
3339 "-unsharp geometry sharpen the image",
3340 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003341 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003342 "-white-threshold value",
3343 " force all pixels above the threshold into white",
3344 (char *) NULL
3345 },
3346 *sequence_operators[]=
3347 {
cristy4285d782011-02-09 20:12:28 +00003348 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003349 "-clut apply a color lookup table to the image",
3350 "-coalesce merge a sequence of images",
3351 "-combine combine a sequence of images",
3352 "-composite composite image",
3353 "-crop geometry cut out a rectangular region of the image",
3354 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003355 "-evaluate-sequence operator",
3356 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003357 "-flatten flatten a sequence of images",
3358 "-fx expression apply mathematical expression to an image channel(s)",
3359 "-hald-clut apply a Hald color lookup table to the image",
3360 "-morph value morph an image sequence",
3361 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003362 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003363 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003364 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003365 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003366 "-write filename write images to this file",
3367 (char *) NULL
3368 },
3369 *settings[]=
3370 {
3371 "-adjoin join images into a single multi-image file",
3372 "-affine matrix affine transform matrix",
3373 "-alpha option activate, deactivate, reset, or set the alpha channel",
3374 "-antialias remove pixel-aliasing",
3375 "-authenticate password",
3376 " decipher image with this password",
3377 "-attenuate value lessen (or intensify) when adding noise to an image",
3378 "-background color background color",
3379 "-bias value add bias when convolving an image",
3380 "-black-point-compensation",
3381 " use black point compensation",
3382 "-blue-primary point chromaticity blue primary point",
3383 "-bordercolor color border color",
3384 "-caption string assign a caption to an image",
3385 "-channel type apply option to select image channels",
3386 "-colors value preferred number of colors in the image",
3387 "-colorspace type alternate image colorspace",
3388 "-comment string annotate image with comment",
3389 "-compose operator set image composite operator",
3390 "-compress type type of pixel compression when writing the image",
3391 "-define format:option",
3392 " define one or more image format options",
3393 "-delay value display the next image after pausing",
3394 "-density geometry horizontal and vertical density of the image",
3395 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003396 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003397 "-display server get image or font from this X server",
3398 "-dispose method layer disposal method",
3399 "-dither method apply error diffusion to image",
3400 "-encoding type text encoding type",
3401 "-endian type endianness (MSB or LSB) of the image",
3402 "-family name render text with this font family",
3403 "-fill color color to use when filling a graphic primitive",
3404 "-filter type use this filter when resizing an image",
3405 "-font name render text with this font",
3406 "-format \"string\" output formatted image characteristics",
3407 "-fuzz distance colors within this distance are considered equal",
3408 "-gravity type horizontal and vertical text placement",
3409 "-green-primary point chromaticity green primary point",
3410 "-intent type type of rendering intent when managing the image color",
3411 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003412 "-interline-spacing value",
3413 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003414 "-interpolate method pixel color interpolation method",
3415 "-interword-spacing value",
3416 " set the space between two words",
3417 "-kerning value set the space between two letters",
3418 "-label string assign a label to an image",
3419 "-limit type value pixel cache resource limit",
3420 "-loop iterations add Netscape loop extension to your GIF animation",
3421 "-mask filename associate a mask with the image",
3422 "-mattecolor color frame color",
3423 "-monitor monitor progress",
3424 "-orient type image orientation",
3425 "-page geometry size and location of an image canvas (setting)",
3426 "-ping efficiently determine image attributes",
3427 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003428 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003429 "-preview type image preview type",
3430 "-quality value JPEG/MIFF/PNG compression level",
3431 "-quiet suppress all warning messages",
3432 "-red-primary point chromaticity red primary point",
3433 "-regard-warnings pay attention to warning messages",
3434 "-remap filename transform image colors to match this set of colors",
3435 "-respect-parentheses settings remain in effect until parenthesis boundary",
3436 "-sampling-factor geometry",
3437 " horizontal and vertical sampling factor",
3438 "-scene value image scene number",
3439 "-seed value seed a new sequence of pseudo-random numbers",
3440 "-size geometry width and height of image",
3441 "-stretch type render text with this font stretch",
3442 "-stroke color graphic primitive stroke color",
3443 "-strokewidth value graphic primitive stroke width",
3444 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003445 "-synchronize synchronize image to storage device",
3446 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003447 "-texture filename name of texture to tile onto the image background",
3448 "-tile-offset geometry",
3449 " tile offset",
3450 "-treedepth value color tree depth",
3451 "-transparent-color color",
3452 " transparent color",
3453 "-undercolor color annotation bounding box color",
3454 "-units type the units of image resolution",
3455 "-verbose print detailed information about the image",
3456 "-view FlashPix viewing transforms",
3457 "-virtual-pixel method",
3458 " virtual pixel access method",
3459 "-weight type render text with this font weight",
3460 "-white-point point chromaticity white point",
3461 (char *) NULL
3462 },
3463 *stack_operators[]=
3464 {
anthonyb69c4b32011-03-23 04:37:44 +00003465 "-delete indexes delete the image from the image sequence",
3466 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003467 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003468 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003469 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003470 "-swap indexes swap two images in the image sequence",
3471 (char *) NULL
3472 };
3473
3474 const char
3475 **p;
3476
cristybb503372010-05-27 20:51:26 +00003477 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003478 (void) printf("Copyright: %s\n",GetMagickCopyright());
3479 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003480 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3481 GetClientName());
3482 (void) printf("\nImage Settings:\n");
3483 for (p=settings; *p != (char *) NULL; p++)
3484 (void) printf(" %s\n",*p);
3485 (void) printf("\nImage Operators:\n");
3486 for (p=operators; *p != (char *) NULL; p++)
3487 (void) printf(" %s\n",*p);
3488 (void) printf("\nImage Sequence Operators:\n");
3489 for (p=sequence_operators; *p != (char *) NULL; p++)
3490 (void) printf(" %s\n",*p);
3491 (void) printf("\nImage Stack Operators:\n");
3492 for (p=stack_operators; *p != (char *) NULL; p++)
3493 (void) printf(" %s\n",*p);
3494 (void) printf("\nMiscellaneous Options:\n");
3495 for (p=miscellaneous; *p != (char *) NULL; p++)
3496 (void) printf(" %s\n",*p);
3497 (void) printf(
3498 "\nBy default, the image format of `file' is determined by its magic\n");
3499 (void) printf(
3500 "number. To specify a particular image format, precede the filename\n");
3501 (void) printf(
3502 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3503 (void) printf(
3504 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3505 (void) printf("'-' for standard input or output.\n");
3506 return(MagickFalse);
3507}
3508
3509WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3510 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3511{
3512#define DestroyMogrify() \
3513{ \
3514 if (format != (char *) NULL) \
3515 format=DestroyString(format); \
3516 if (path != (char *) NULL) \
3517 path=DestroyString(path); \
3518 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003519 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003520 argv[i]=DestroyString(argv[i]); \
3521 argv=(char **) RelinquishMagickMemory(argv); \
3522}
3523#define ThrowMogrifyException(asperity,tag,option) \
3524{ \
3525 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3526 option); \
3527 DestroyMogrify(); \
3528 return(MagickFalse); \
3529}
3530#define ThrowMogrifyInvalidArgumentException(option,argument) \
3531{ \
3532 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3533 "InvalidArgument","`%s': %s",argument,option); \
3534 DestroyMogrify(); \
3535 return(MagickFalse); \
3536}
3537
3538 char
3539 *format,
3540 *option,
3541 *path;
3542
3543 Image
3544 *image;
3545
3546 ImageStack
3547 image_stack[MaxImageStackDepth+1];
3548
cristy3ed852e2009-09-05 21:47:34 +00003549 MagickBooleanType
3550 global_colormap;
3551
3552 MagickBooleanType
3553 fire,
cristyebbcfea2011-02-25 02:43:54 +00003554 pend,
3555 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003556
3557 MagickStatusType
3558 status;
3559
cristyebbcfea2011-02-25 02:43:54 +00003560 register ssize_t
3561 i;
3562
3563 ssize_t
3564 j,
3565 k;
3566
cristy3ed852e2009-09-05 21:47:34 +00003567 /*
3568 Set defaults.
3569 */
3570 assert(image_info != (ImageInfo *) NULL);
3571 assert(image_info->signature == MagickSignature);
3572 if (image_info->debug != MagickFalse)
3573 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3574 assert(exception != (ExceptionInfo *) NULL);
3575 if (argc == 2)
3576 {
3577 option=argv[1];
3578 if ((LocaleCompare("version",option+1) == 0) ||
3579 (LocaleCompare("-version",option+1) == 0))
3580 {
cristyb51dff52011-05-19 16:55:47 +00003581 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003582 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003583 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3584 GetMagickCopyright());
3585 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3586 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003587 return(MagickFalse);
3588 }
3589 }
3590 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003591 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003592 format=(char *) NULL;
3593 path=(char *) NULL;
3594 global_colormap=MagickFalse;
3595 k=0;
3596 j=1;
3597 NewImageStack();
3598 option=(char *) NULL;
3599 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003600 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003601 status=MagickTrue;
3602 /*
3603 Parse command line.
3604 */
3605 ReadCommandlLine(argc,&argv);
3606 status=ExpandFilenames(&argc,&argv);
3607 if (status == MagickFalse)
3608 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3609 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003610 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003611 {
3612 option=argv[i];
3613 if (LocaleCompare(option,"(") == 0)
3614 {
3615 FireImageStack(MagickFalse,MagickTrue,pend);
3616 if (k == MaxImageStackDepth)
3617 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3618 option);
3619 PushImageStack();
3620 continue;
3621 }
3622 if (LocaleCompare(option,")") == 0)
3623 {
3624 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3625 if (k == 0)
3626 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3627 PopImageStack();
3628 continue;
3629 }
cristy042ee782011-04-22 18:48:30 +00003630 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003631 {
3632 char
3633 backup_filename[MaxTextExtent],
3634 *filename;
3635
3636 Image
3637 *images;
3638
3639 /*
3640 Option is a file name: begin by reading image from specified file.
3641 */
3642 FireImageStack(MagickFalse,MagickFalse,pend);
3643 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003644 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003645 filename=argv[++i];
3646 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3647 images=ReadImages(image_info,exception);
3648 status&=(images != (Image *) NULL) &&
3649 (exception->severity < ErrorException);
3650 if (images == (Image *) NULL)
3651 continue;
cristydaa76602010-06-30 13:05:11 +00003652 if (format != (char *) NULL)
3653 (void) CopyMagickString(images->filename,images->magick_filename,
3654 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003655 if (path != (char *) NULL)
3656 {
3657 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003658 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003659 path,*DirectorySeparator,filename);
3660 }
3661 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003662 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003663 AppendImageStack(images);
3664 FinalizeImageSettings(image_info,image,MagickFalse);
3665 if (global_colormap != MagickFalse)
3666 {
3667 QuantizeInfo
3668 *quantize_info;
3669
3670 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003671 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003672 quantize_info=DestroyQuantizeInfo(quantize_info);
3673 }
3674 *backup_filename='\0';
3675 if ((LocaleCompare(image->filename,"-") != 0) &&
3676 (IsPathWritable(image->filename) != MagickFalse))
3677 {
cristybb503372010-05-27 20:51:26 +00003678 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003679 i;
3680
3681 /*
3682 Rename image file as backup.
3683 */
3684 (void) CopyMagickString(backup_filename,image->filename,
3685 MaxTextExtent);
3686 for (i=0; i < 6; i++)
3687 {
3688 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3689 if (IsPathAccessible(backup_filename) == MagickFalse)
3690 break;
3691 }
3692 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3693 (rename(image->filename,backup_filename) != 0))
3694 *backup_filename='\0';
3695 }
3696 /*
3697 Write transmogrified image to disk.
3698 */
3699 image_info->synchronize=MagickTrue;
3700 status&=WriteImages(image_info,image,image->filename,exception);
3701 if ((status == MagickFalse) && (*backup_filename != '\0'))
3702 (void) remove(backup_filename);
3703 RemoveAllImageStack();
3704 continue;
3705 }
3706 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3707 switch (*(option+1))
3708 {
3709 case 'a':
3710 {
3711 if (LocaleCompare("adaptive-blur",option+1) == 0)
3712 {
3713 i++;
cristybb503372010-05-27 20:51:26 +00003714 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003715 ThrowMogrifyException(OptionError,"MissingArgument",option);
3716 if (IsGeometry(argv[i]) == MagickFalse)
3717 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3718 break;
3719 }
3720 if (LocaleCompare("adaptive-resize",option+1) == 0)
3721 {
3722 i++;
cristybb503372010-05-27 20:51:26 +00003723 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003724 ThrowMogrifyException(OptionError,"MissingArgument",option);
3725 if (IsGeometry(argv[i]) == MagickFalse)
3726 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3727 break;
3728 }
3729 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3730 {
3731 i++;
cristybb503372010-05-27 20:51:26 +00003732 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003733 ThrowMogrifyException(OptionError,"MissingArgument",option);
3734 if (IsGeometry(argv[i]) == MagickFalse)
3735 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3736 break;
3737 }
3738 if (LocaleCompare("affine",option+1) == 0)
3739 {
3740 if (*option == '+')
3741 break;
3742 i++;
cristybb503372010-05-27 20:51:26 +00003743 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003744 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003745 break;
3746 }
3747 if (LocaleCompare("alpha",option+1) == 0)
3748 {
cristybb503372010-05-27 20:51:26 +00003749 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003750 type;
3751
3752 if (*option == '+')
3753 break;
3754 i++;
cristybb503372010-05-27 20:51:26 +00003755 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003756 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003757 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003758 if (type < 0)
3759 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3760 argv[i]);
3761 break;
3762 }
3763 if (LocaleCompare("annotate",option+1) == 0)
3764 {
3765 if (*option == '+')
3766 break;
3767 i++;
cristybb503372010-05-27 20:51:26 +00003768 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003769 ThrowMogrifyException(OptionError,"MissingArgument",option);
3770 if (IsGeometry(argv[i]) == MagickFalse)
3771 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003773 ThrowMogrifyException(OptionError,"MissingArgument",option);
3774 i++;
3775 break;
3776 }
3777 if (LocaleCompare("antialias",option+1) == 0)
3778 break;
3779 if (LocaleCompare("append",option+1) == 0)
3780 break;
3781 if (LocaleCompare("attenuate",option+1) == 0)
3782 {
3783 if (*option == '+')
3784 break;
3785 i++;
cristybb503372010-05-27 20:51:26 +00003786 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003787 ThrowMogrifyException(OptionError,"MissingArgument",option);
3788 if (IsGeometry(argv[i]) == MagickFalse)
3789 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3790 break;
3791 }
3792 if (LocaleCompare("authenticate",option+1) == 0)
3793 {
3794 if (*option == '+')
3795 break;
3796 i++;
cristybb503372010-05-27 20:51:26 +00003797 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003798 ThrowMogrifyException(OptionError,"MissingArgument",option);
3799 break;
3800 }
3801 if (LocaleCompare("auto-gamma",option+1) == 0)
3802 break;
3803 if (LocaleCompare("auto-level",option+1) == 0)
3804 break;
3805 if (LocaleCompare("auto-orient",option+1) == 0)
3806 break;
3807 if (LocaleCompare("average",option+1) == 0)
3808 break;
3809 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3810 }
3811 case 'b':
3812 {
3813 if (LocaleCompare("background",option+1) == 0)
3814 {
3815 if (*option == '+')
3816 break;
3817 i++;
cristybb503372010-05-27 20:51:26 +00003818 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003819 ThrowMogrifyException(OptionError,"MissingArgument",option);
3820 break;
3821 }
3822 if (LocaleCompare("bias",option+1) == 0)
3823 {
3824 if (*option == '+')
3825 break;
3826 i++;
cristybb503372010-05-27 20:51:26 +00003827 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003828 ThrowMogrifyException(OptionError,"MissingArgument",option);
3829 if (IsGeometry(argv[i]) == MagickFalse)
3830 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3831 break;
3832 }
3833 if (LocaleCompare("black-point-compensation",option+1) == 0)
3834 break;
3835 if (LocaleCompare("black-threshold",option+1) == 0)
3836 {
3837 if (*option == '+')
3838 break;
3839 i++;
cristybb503372010-05-27 20:51:26 +00003840 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003841 ThrowMogrifyException(OptionError,"MissingArgument",option);
3842 if (IsGeometry(argv[i]) == MagickFalse)
3843 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3844 break;
3845 }
3846 if (LocaleCompare("blue-primary",option+1) == 0)
3847 {
3848 if (*option == '+')
3849 break;
3850 i++;
cristybb503372010-05-27 20:51:26 +00003851 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003852 ThrowMogrifyException(OptionError,"MissingArgument",option);
3853 if (IsGeometry(argv[i]) == MagickFalse)
3854 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3855 break;
3856 }
3857 if (LocaleCompare("blue-shift",option+1) == 0)
3858 {
3859 i++;
cristybb503372010-05-27 20:51:26 +00003860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003861 ThrowMogrifyException(OptionError,"MissingArgument",option);
3862 if (IsGeometry(argv[i]) == MagickFalse)
3863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3864 break;
3865 }
3866 if (LocaleCompare("blur",option+1) == 0)
3867 {
3868 i++;
cristybb503372010-05-27 20:51:26 +00003869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003870 ThrowMogrifyException(OptionError,"MissingArgument",option);
3871 if (IsGeometry(argv[i]) == MagickFalse)
3872 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3873 break;
3874 }
3875 if (LocaleCompare("border",option+1) == 0)
3876 {
3877 if (*option == '+')
3878 break;
3879 i++;
cristybb503372010-05-27 20:51:26 +00003880 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003881 ThrowMogrifyException(OptionError,"MissingArgument",option);
3882 if (IsGeometry(argv[i]) == MagickFalse)
3883 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3884 break;
3885 }
3886 if (LocaleCompare("bordercolor",option+1) == 0)
3887 {
3888 if (*option == '+')
3889 break;
3890 i++;
cristybb503372010-05-27 20:51:26 +00003891 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003892 ThrowMogrifyException(OptionError,"MissingArgument",option);
3893 break;
3894 }
3895 if (LocaleCompare("box",option+1) == 0)
3896 {
3897 if (*option == '+')
3898 break;
3899 i++;
cristybb503372010-05-27 20:51:26 +00003900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003901 ThrowMogrifyException(OptionError,"MissingArgument",option);
3902 break;
3903 }
cristya28d6b82010-01-11 20:03:47 +00003904 if (LocaleCompare("brightness-contrast",option+1) == 0)
3905 {
3906 i++;
cristybb503372010-05-27 20:51:26 +00003907 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003908 ThrowMogrifyException(OptionError,"MissingArgument",option);
3909 if (IsGeometry(argv[i]) == MagickFalse)
3910 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3911 break;
3912 }
cristy3ed852e2009-09-05 21:47:34 +00003913 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3914 }
3915 case 'c':
3916 {
3917 if (LocaleCompare("cache",option+1) == 0)
3918 {
3919 if (*option == '+')
3920 break;
3921 i++;
cristybb503372010-05-27 20:51:26 +00003922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003923 ThrowMogrifyException(OptionError,"MissingArgument",option);
3924 if (IsGeometry(argv[i]) == MagickFalse)
3925 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3926 break;
3927 }
3928 if (LocaleCompare("caption",option+1) == 0)
3929 {
3930 if (*option == '+')
3931 break;
3932 i++;
cristybb503372010-05-27 20:51:26 +00003933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003934 ThrowMogrifyException(OptionError,"MissingArgument",option);
3935 break;
3936 }
3937 if (LocaleCompare("channel",option+1) == 0)
3938 {
cristybb503372010-05-27 20:51:26 +00003939 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003940 channel;
3941
3942 if (*option == '+')
3943 break;
3944 i++;
cristybb503372010-05-27 20:51:26 +00003945 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003946 ThrowMogrifyException(OptionError,"MissingArgument",option);
3947 channel=ParseChannelOption(argv[i]);
3948 if (channel < 0)
3949 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3950 argv[i]);
3951 break;
3952 }
3953 if (LocaleCompare("cdl",option+1) == 0)
3954 {
3955 if (*option == '+')
3956 break;
3957 i++;
cristybb503372010-05-27 20:51:26 +00003958 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003959 ThrowMogrifyException(OptionError,"MissingArgument",option);
3960 break;
3961 }
3962 if (LocaleCompare("charcoal",option+1) == 0)
3963 {
3964 if (*option == '+')
3965 break;
3966 i++;
cristybb503372010-05-27 20:51:26 +00003967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003968 ThrowMogrifyException(OptionError,"MissingArgument",option);
3969 if (IsGeometry(argv[i]) == MagickFalse)
3970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3971 break;
3972 }
3973 if (LocaleCompare("chop",option+1) == 0)
3974 {
3975 if (*option == '+')
3976 break;
3977 i++;
cristybb503372010-05-27 20:51:26 +00003978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003979 ThrowMogrifyException(OptionError,"MissingArgument",option);
3980 if (IsGeometry(argv[i]) == MagickFalse)
3981 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3982 break;
3983 }
cristy1eb45dd2009-09-25 16:38:06 +00003984 if (LocaleCompare("clamp",option+1) == 0)
3985 break;
3986 if (LocaleCompare("clip",option+1) == 0)
3987 break;
cristy3ed852e2009-09-05 21:47:34 +00003988 if (LocaleCompare("clip-mask",option+1) == 0)
3989 {
3990 if (*option == '+')
3991 break;
3992 i++;
cristybb503372010-05-27 20:51:26 +00003993 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003994 ThrowMogrifyException(OptionError,"MissingArgument",option);
3995 break;
3996 }
3997 if (LocaleCompare("clut",option+1) == 0)
3998 break;
3999 if (LocaleCompare("coalesce",option+1) == 0)
4000 break;
4001 if (LocaleCompare("colorize",option+1) == 0)
4002 {
4003 if (*option == '+')
4004 break;
4005 i++;
cristybb503372010-05-27 20:51:26 +00004006 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004007 ThrowMogrifyException(OptionError,"MissingArgument",option);
4008 if (IsGeometry(argv[i]) == MagickFalse)
4009 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4010 break;
4011 }
cristye6365592010-04-02 17:31:23 +00004012 if (LocaleCompare("color-matrix",option+1) == 0)
4013 {
cristyb6bd4ad2010-08-08 01:12:27 +00004014 KernelInfo
4015 *kernel_info;
4016
cristye6365592010-04-02 17:31:23 +00004017 if (*option == '+')
4018 break;
4019 i++;
cristybb503372010-05-27 20:51:26 +00004020 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004021 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004022 kernel_info=AcquireKernelInfo(argv[i]);
4023 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004024 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004025 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004026 break;
4027 }
cristy3ed852e2009-09-05 21:47:34 +00004028 if (LocaleCompare("colors",option+1) == 0)
4029 {
4030 if (*option == '+')
4031 break;
4032 i++;
cristybb503372010-05-27 20:51:26 +00004033 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004034 ThrowMogrifyException(OptionError,"MissingArgument",option);
4035 if (IsGeometry(argv[i]) == MagickFalse)
4036 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4037 break;
4038 }
4039 if (LocaleCompare("colorspace",option+1) == 0)
4040 {
cristybb503372010-05-27 20:51:26 +00004041 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004042 colorspace;
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);
cristy042ee782011-04-22 18:48:30 +00004049 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004050 argv[i]);
4051 if (colorspace < 0)
4052 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4053 argv[i]);
4054 break;
4055 }
4056 if (LocaleCompare("combine",option+1) == 0)
4057 break;
4058 if (LocaleCompare("comment",option+1) == 0)
4059 {
4060 if (*option == '+')
4061 break;
4062 i++;
cristybb503372010-05-27 20:51:26 +00004063 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004064 ThrowMogrifyException(OptionError,"MissingArgument",option);
4065 break;
4066 }
4067 if (LocaleCompare("composite",option+1) == 0)
4068 break;
4069 if (LocaleCompare("compress",option+1) == 0)
4070 {
cristybb503372010-05-27 20:51:26 +00004071 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004072 compress;
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);
cristy042ee782011-04-22 18:48:30 +00004079 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004080 argv[i]);
4081 if (compress < 0)
4082 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4083 argv[i]);
4084 break;
4085 }
cristy22879752009-10-25 23:55:40 +00004086 if (LocaleCompare("concurrent",option+1) == 0)
4087 break;
cristy3ed852e2009-09-05 21:47:34 +00004088 if (LocaleCompare("contrast",option+1) == 0)
4089 break;
4090 if (LocaleCompare("contrast-stretch",option+1) == 0)
4091 {
4092 i++;
cristybb503372010-05-27 20:51:26 +00004093 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004094 ThrowMogrifyException(OptionError,"MissingArgument",option);
4095 if (IsGeometry(argv[i]) == MagickFalse)
4096 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4097 break;
4098 }
4099 if (LocaleCompare("convolve",option+1) == 0)
4100 {
cristyb6bd4ad2010-08-08 01:12:27 +00004101 KernelInfo
4102 *kernel_info;
4103
cristy3ed852e2009-09-05 21:47:34 +00004104 if (*option == '+')
4105 break;
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);
cristyb6bd4ad2010-08-08 01:12:27 +00004109 kernel_info=AcquireKernelInfo(argv[i]);
4110 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004111 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004112 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004113 break;
4114 }
4115 if (LocaleCompare("crop",option+1) == 0)
4116 {
4117 if (*option == '+')
4118 break;
4119 i++;
cristybb503372010-05-27 20:51:26 +00004120 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004121 ThrowMogrifyException(OptionError,"MissingArgument",option);
4122 if (IsGeometry(argv[i]) == MagickFalse)
4123 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4124 break;
4125 }
4126 if (LocaleCompare("cycle",option+1) == 0)
4127 {
4128 if (*option == '+')
4129 break;
4130 i++;
cristybb503372010-05-27 20:51:26 +00004131 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004132 ThrowMogrifyException(OptionError,"MissingArgument",option);
4133 if (IsGeometry(argv[i]) == MagickFalse)
4134 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4135 break;
4136 }
4137 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4138 }
4139 case 'd':
4140 {
4141 if (LocaleCompare("decipher",option+1) == 0)
4142 {
4143 if (*option == '+')
4144 break;
4145 i++;
cristybb503372010-05-27 20:51:26 +00004146 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004147 ThrowMogrifyException(OptionError,"MissingArgument",option);
4148 break;
4149 }
4150 if (LocaleCompare("deconstruct",option+1) == 0)
4151 break;
4152 if (LocaleCompare("debug",option+1) == 0)
4153 {
cristybb503372010-05-27 20:51:26 +00004154 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004155 event;
4156
4157 if (*option == '+')
4158 break;
4159 i++;
cristybb503372010-05-27 20:51:26 +00004160 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004161 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004162 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004163 if (event < 0)
4164 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4165 argv[i]);
4166 (void) SetLogEventMask(argv[i]);
4167 break;
4168 }
4169 if (LocaleCompare("define",option+1) == 0)
4170 {
4171 i++;
cristybb503372010-05-27 20:51:26 +00004172 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004173 ThrowMogrifyException(OptionError,"MissingArgument",option);
4174 if (*option == '+')
4175 {
4176 const char
4177 *define;
4178
4179 define=GetImageOption(image_info,argv[i]);
4180 if (define == (const char *) NULL)
4181 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4182 break;
4183 }
4184 break;
4185 }
4186 if (LocaleCompare("delay",option+1) == 0)
4187 {
4188 if (*option == '+')
4189 break;
4190 i++;
cristybb503372010-05-27 20:51:26 +00004191 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004192 ThrowMogrifyException(OptionError,"MissingArgument",option);
4193 if (IsGeometry(argv[i]) == MagickFalse)
4194 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4195 break;
4196 }
cristyecb10ff2011-03-22 13:14:03 +00004197 if (LocaleCompare("delete",option+1) == 0)
4198 {
4199 if (*option == '+')
4200 break;
4201 i++;
4202 if (i == (ssize_t) (argc-1))
4203 ThrowMogrifyException(OptionError,"MissingArgument",option);
4204 if (IsGeometry(argv[i]) == MagickFalse)
4205 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4206 break;
4207 }
cristy3ed852e2009-09-05 21:47:34 +00004208 if (LocaleCompare("density",option+1) == 0)
4209 {
4210 if (*option == '+')
4211 break;
4212 i++;
cristybb503372010-05-27 20:51:26 +00004213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004214 ThrowMogrifyException(OptionError,"MissingArgument",option);
4215 if (IsGeometry(argv[i]) == MagickFalse)
4216 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4217 break;
4218 }
4219 if (LocaleCompare("depth",option+1) == 0)
4220 {
4221 if (*option == '+')
4222 break;
4223 i++;
cristybb503372010-05-27 20:51:26 +00004224 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004225 ThrowMogrifyException(OptionError,"MissingArgument",option);
4226 if (IsGeometry(argv[i]) == MagickFalse)
4227 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4228 break;
4229 }
4230 if (LocaleCompare("deskew",option+1) == 0)
4231 {
4232 if (*option == '+')
4233 break;
4234 i++;
cristybb503372010-05-27 20:51:26 +00004235 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004236 ThrowMogrifyException(OptionError,"MissingArgument",option);
4237 if (IsGeometry(argv[i]) == MagickFalse)
4238 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4239 break;
4240 }
4241 if (LocaleCompare("despeckle",option+1) == 0)
4242 break;
4243 if (LocaleCompare("dft",option+1) == 0)
4244 break;
cristyc9b12952010-03-28 01:12:28 +00004245 if (LocaleCompare("direction",option+1) == 0)
4246 {
cristybb503372010-05-27 20:51:26 +00004247 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004248 direction;
4249
4250 if (*option == '+')
4251 break;
4252 i++;
cristybb503372010-05-27 20:51:26 +00004253 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004254 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004255 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004256 argv[i]);
4257 if (direction < 0)
4258 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4259 argv[i]);
4260 break;
4261 }
cristy3ed852e2009-09-05 21:47:34 +00004262 if (LocaleCompare("display",option+1) == 0)
4263 {
4264 if (*option == '+')
4265 break;
4266 i++;
cristybb503372010-05-27 20:51:26 +00004267 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004268 ThrowMogrifyException(OptionError,"MissingArgument",option);
4269 break;
4270 }
4271 if (LocaleCompare("dispose",option+1) == 0)
4272 {
cristybb503372010-05-27 20:51:26 +00004273 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004274 dispose;
4275
4276 if (*option == '+')
4277 break;
4278 i++;
cristybb503372010-05-27 20:51:26 +00004279 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004280 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004281 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004282 if (dispose < 0)
4283 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4284 argv[i]);
4285 break;
4286 }
4287 if (LocaleCompare("distort",option+1) == 0)
4288 {
cristybb503372010-05-27 20:51:26 +00004289 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004290 op;
4291
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 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004296 if (op < 0)
4297 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4298 argv[i]);
4299 i++;
cristybb503372010-05-27 20:51:26 +00004300 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004301 ThrowMogrifyException(OptionError,"MissingArgument",option);
4302 break;
4303 }
4304 if (LocaleCompare("dither",option+1) == 0)
4305 {
cristybb503372010-05-27 20:51:26 +00004306 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004307 method;
4308
4309 if (*option == '+')
4310 break;
4311 i++;
cristybb503372010-05-27 20:51:26 +00004312 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004313 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004314 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004315 if (method < 0)
4316 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4317 argv[i]);
4318 break;
4319 }
4320 if (LocaleCompare("draw",option+1) == 0)
4321 {
4322 if (*option == '+')
4323 break;
4324 i++;
cristybb503372010-05-27 20:51:26 +00004325 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004326 ThrowMogrifyException(OptionError,"MissingArgument",option);
4327 break;
4328 }
cristyecb10ff2011-03-22 13:14:03 +00004329 if (LocaleCompare("duplicate",option+1) == 0)
4330 {
4331 if (*option == '+')
4332 break;
4333 i++;
4334 if (i == (ssize_t) (argc-1))
4335 ThrowMogrifyException(OptionError,"MissingArgument",option);
4336 if (IsGeometry(argv[i]) == MagickFalse)
4337 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4338 break;
4339 }
cristy22879752009-10-25 23:55:40 +00004340 if (LocaleCompare("duration",option+1) == 0)
4341 {
4342 if (*option == '+')
4343 break;
4344 i++;
cristybb503372010-05-27 20:51:26 +00004345 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004346 ThrowMogrifyException(OptionError,"MissingArgument",option);
4347 if (IsGeometry(argv[i]) == MagickFalse)
4348 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4349 break;
4350 }
cristy3ed852e2009-09-05 21:47:34 +00004351 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4352 }
4353 case 'e':
4354 {
4355 if (LocaleCompare("edge",option+1) == 0)
4356 {
4357 if (*option == '+')
4358 break;
4359 i++;
cristybb503372010-05-27 20:51:26 +00004360 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004361 ThrowMogrifyException(OptionError,"MissingArgument",option);
4362 if (IsGeometry(argv[i]) == MagickFalse)
4363 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4364 break;
4365 }
4366 if (LocaleCompare("emboss",option+1) == 0)
4367 {
4368 if (*option == '+')
4369 break;
4370 i++;
cristybb503372010-05-27 20:51:26 +00004371 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004372 ThrowMogrifyException(OptionError,"MissingArgument",option);
4373 if (IsGeometry(argv[i]) == MagickFalse)
4374 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4375 break;
4376 }
4377 if (LocaleCompare("encipher",option+1) == 0)
4378 {
4379 if (*option == '+')
4380 break;
4381 i++;
cristybb503372010-05-27 20:51:26 +00004382 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004383 ThrowMogrifyException(OptionError,"MissingArgument",option);
4384 break;
4385 }
4386 if (LocaleCompare("encoding",option+1) == 0)
4387 {
4388 if (*option == '+')
4389 break;
4390 i++;
cristybb503372010-05-27 20:51:26 +00004391 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004392 ThrowMogrifyException(OptionError,"MissingArgument",option);
4393 break;
4394 }
4395 if (LocaleCompare("endian",option+1) == 0)
4396 {
cristybb503372010-05-27 20:51:26 +00004397 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004398 endian;
4399
4400 if (*option == '+')
4401 break;
4402 i++;
cristybb503372010-05-27 20:51:26 +00004403 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004404 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004405 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004406 if (endian < 0)
4407 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4408 argv[i]);
4409 break;
4410 }
4411 if (LocaleCompare("enhance",option+1) == 0)
4412 break;
4413 if (LocaleCompare("equalize",option+1) == 0)
4414 break;
4415 if (LocaleCompare("evaluate",option+1) == 0)
4416 {
cristybb503372010-05-27 20:51:26 +00004417 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004418 op;
4419
4420 if (*option == '+')
4421 break;
4422 i++;
cristybb503372010-05-27 20:51:26 +00004423 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004424 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004425 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004426 if (op < 0)
4427 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4428 argv[i]);
4429 i++;
cristybb503372010-05-27 20:51:26 +00004430 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004431 ThrowMogrifyException(OptionError,"MissingArgument",option);
4432 if (IsGeometry(argv[i]) == MagickFalse)
4433 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4434 break;
4435 }
cristyd18ae7c2010-03-07 17:39:52 +00004436 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4437 {
cristybb503372010-05-27 20:51:26 +00004438 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004439 op;
4440
4441 if (*option == '+')
4442 break;
4443 i++;
cristybb503372010-05-27 20:51:26 +00004444 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004445 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004446 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004447 if (op < 0)
4448 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4449 argv[i]);
4450 break;
4451 }
cristy3ed852e2009-09-05 21:47:34 +00004452 if (LocaleCompare("extent",option+1) == 0)
4453 {
4454 if (*option == '+')
4455 break;
4456 i++;
cristybb503372010-05-27 20:51:26 +00004457 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004458 ThrowMogrifyException(OptionError,"MissingArgument",option);
4459 if (IsGeometry(argv[i]) == MagickFalse)
4460 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4461 break;
4462 }
4463 if (LocaleCompare("extract",option+1) == 0)
4464 {
4465 if (*option == '+')
4466 break;
4467 i++;
cristybb503372010-05-27 20:51:26 +00004468 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004469 ThrowMogrifyException(OptionError,"MissingArgument",option);
4470 if (IsGeometry(argv[i]) == MagickFalse)
4471 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4472 break;
4473 }
4474 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4475 }
4476 case 'f':
4477 {
4478 if (LocaleCompare("family",option+1) == 0)
4479 {
4480 if (*option == '+')
4481 break;
4482 i++;
cristybb503372010-05-27 20:51:26 +00004483 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004484 ThrowMogrifyException(OptionError,"MissingArgument",option);
4485 break;
4486 }
4487 if (LocaleCompare("fill",option+1) == 0)
4488 {
4489 if (*option == '+')
4490 break;
4491 i++;
cristybb503372010-05-27 20:51:26 +00004492 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004493 ThrowMogrifyException(OptionError,"MissingArgument",option);
4494 break;
4495 }
4496 if (LocaleCompare("filter",option+1) == 0)
4497 {
cristybb503372010-05-27 20:51:26 +00004498 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004499 filter;
4500
4501 if (*option == '+')
4502 break;
4503 i++;
cristybb503372010-05-27 20:51:26 +00004504 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004505 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004506 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004507 if (filter < 0)
4508 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4509 argv[i]);
4510 break;
4511 }
4512 if (LocaleCompare("flatten",option+1) == 0)
4513 break;
4514 if (LocaleCompare("flip",option+1) == 0)
4515 break;
4516 if (LocaleCompare("flop",option+1) == 0)
4517 break;
4518 if (LocaleCompare("floodfill",option+1) == 0)
4519 {
4520 if (*option == '+')
4521 break;
4522 i++;
cristybb503372010-05-27 20:51:26 +00004523 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004524 ThrowMogrifyException(OptionError,"MissingArgument",option);
4525 if (IsGeometry(argv[i]) == MagickFalse)
4526 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4527 i++;
cristybb503372010-05-27 20:51:26 +00004528 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004529 ThrowMogrifyException(OptionError,"MissingArgument",option);
4530 break;
4531 }
4532 if (LocaleCompare("font",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 break;
4540 }
4541 if (LocaleCompare("format",option+1) == 0)
4542 {
4543 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4544 (void) CloneString(&format,(char *) NULL);
4545 if (*option == '+')
4546 break;
4547 i++;
cristybb503372010-05-27 20:51:26 +00004548 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004549 ThrowMogrifyException(OptionError,"MissingArgument",option);
4550 (void) CloneString(&format,argv[i]);
4551 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4552 (void) ConcatenateMagickString(image_info->filename,":",
4553 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004554 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004555 if (*image_info->magick == '\0')
4556 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4557 format);
4558 break;
4559 }
4560 if (LocaleCompare("frame",option+1) == 0)
4561 {
4562 if (*option == '+')
4563 break;
4564 i++;
cristybb503372010-05-27 20:51:26 +00004565 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004566 ThrowMogrifyException(OptionError,"MissingArgument",option);
4567 if (IsGeometry(argv[i]) == MagickFalse)
4568 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4569 break;
4570 }
4571 if (LocaleCompare("function",option+1) == 0)
4572 {
cristybb503372010-05-27 20:51:26 +00004573 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004574 op;
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);
cristy042ee782011-04-22 18:48:30 +00004581 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004582 if (op < 0)
4583 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4584 i++;
cristybb503372010-05-27 20:51:26 +00004585 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004586 ThrowMogrifyException(OptionError,"MissingArgument",option);
4587 break;
4588 }
4589 if (LocaleCompare("fuzz",option+1) == 0)
4590 {
4591 if (*option == '+')
4592 break;
4593 i++;
cristybb503372010-05-27 20:51:26 +00004594 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004595 ThrowMogrifyException(OptionError,"MissingArgument",option);
4596 if (IsGeometry(argv[i]) == MagickFalse)
4597 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4598 break;
4599 }
4600 if (LocaleCompare("fx",option+1) == 0)
4601 {
4602 if (*option == '+')
4603 break;
4604 i++;
cristybb503372010-05-27 20:51:26 +00004605 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004606 ThrowMogrifyException(OptionError,"MissingArgument",option);
4607 break;
4608 }
4609 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4610 }
4611 case 'g':
4612 {
4613 if (LocaleCompare("gamma",option+1) == 0)
4614 {
4615 i++;
cristybb503372010-05-27 20:51:26 +00004616 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004617 ThrowMogrifyException(OptionError,"MissingArgument",option);
4618 if (IsGeometry(argv[i]) == MagickFalse)
4619 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4620 break;
4621 }
4622 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4623 (LocaleCompare("gaussian",option+1) == 0))
4624 {
4625 i++;
cristybb503372010-05-27 20:51:26 +00004626 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004627 ThrowMogrifyException(OptionError,"MissingArgument",option);
4628 if (IsGeometry(argv[i]) == MagickFalse)
4629 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4630 break;
4631 }
4632 if (LocaleCompare("geometry",option+1) == 0)
4633 {
4634 if (*option == '+')
4635 break;
4636 i++;
cristybb503372010-05-27 20:51:26 +00004637 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004638 ThrowMogrifyException(OptionError,"MissingArgument",option);
4639 if (IsGeometry(argv[i]) == MagickFalse)
4640 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4641 break;
4642 }
4643 if (LocaleCompare("gravity",option+1) == 0)
4644 {
cristybb503372010-05-27 20:51:26 +00004645 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004646 gravity;
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);
cristy042ee782011-04-22 18:48:30 +00004653 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004654 if (gravity < 0)
4655 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4656 argv[i]);
4657 break;
4658 }
4659 if (LocaleCompare("green-primary",option+1) == 0)
4660 {
4661 if (*option == '+')
4662 break;
4663 i++;
cristybb503372010-05-27 20:51:26 +00004664 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004665 ThrowMogrifyException(OptionError,"MissingArgument",option);
4666 if (IsGeometry(argv[i]) == MagickFalse)
4667 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4668 break;
4669 }
4670 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4671 }
4672 case 'h':
4673 {
4674 if (LocaleCompare("hald-clut",option+1) == 0)
4675 break;
4676 if ((LocaleCompare("help",option+1) == 0) ||
4677 (LocaleCompare("-help",option+1) == 0))
4678 return(MogrifyUsage());
4679 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4680 }
4681 case 'i':
4682 {
4683 if (LocaleCompare("identify",option+1) == 0)
4684 break;
4685 if (LocaleCompare("idft",option+1) == 0)
4686 break;
4687 if (LocaleCompare("implode",option+1) == 0)
4688 {
4689 if (*option == '+')
4690 break;
4691 i++;
cristybb503372010-05-27 20:51:26 +00004692 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004693 ThrowMogrifyException(OptionError,"MissingArgument",option);
4694 if (IsGeometry(argv[i]) == MagickFalse)
4695 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4696 break;
4697 }
4698 if (LocaleCompare("intent",option+1) == 0)
4699 {
cristybb503372010-05-27 20:51:26 +00004700 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004701 intent;
4702
4703 if (*option == '+')
4704 break;
4705 i++;
cristybb503372010-05-27 20:51:26 +00004706 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004707 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004708 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004709 if (intent < 0)
4710 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4711 argv[i]);
4712 break;
4713 }
4714 if (LocaleCompare("interlace",option+1) == 0)
4715 {
cristybb503372010-05-27 20:51:26 +00004716 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004717 interlace;
4718
4719 if (*option == '+')
4720 break;
4721 i++;
cristybb503372010-05-27 20:51:26 +00004722 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004723 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004724 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004725 argv[i]);
4726 if (interlace < 0)
4727 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4728 argv[i]);
4729 break;
4730 }
cristyb32b90a2009-09-07 21:45:48 +00004731 if (LocaleCompare("interline-spacing",option+1) == 0)
4732 {
4733 if (*option == '+')
4734 break;
4735 i++;
cristybb503372010-05-27 20:51:26 +00004736 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004737 ThrowMogrifyException(OptionError,"MissingArgument",option);
4738 if (IsGeometry(argv[i]) == MagickFalse)
4739 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4740 break;
4741 }
cristy3ed852e2009-09-05 21:47:34 +00004742 if (LocaleCompare("interpolate",option+1) == 0)
4743 {
cristybb503372010-05-27 20:51:26 +00004744 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004745 interpolate;
4746
4747 if (*option == '+')
4748 break;
4749 i++;
cristybb503372010-05-27 20:51:26 +00004750 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004751 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004752 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004753 argv[i]);
4754 if (interpolate < 0)
4755 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4756 argv[i]);
4757 break;
4758 }
4759 if (LocaleCompare("interword-spacing",option+1) == 0)
4760 {
4761 if (*option == '+')
4762 break;
4763 i++;
cristybb503372010-05-27 20:51:26 +00004764 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004765 ThrowMogrifyException(OptionError,"MissingArgument",option);
4766 if (IsGeometry(argv[i]) == MagickFalse)
4767 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4768 break;
4769 }
4770 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4771 }
4772 case 'k':
4773 {
4774 if (LocaleCompare("kerning",option+1) == 0)
4775 {
4776 if (*option == '+')
4777 break;
4778 i++;
cristybb503372010-05-27 20:51:26 +00004779 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004780 ThrowMogrifyException(OptionError,"MissingArgument",option);
4781 if (IsGeometry(argv[i]) == MagickFalse)
4782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4783 break;
4784 }
4785 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4786 }
4787 case 'l':
4788 {
4789 if (LocaleCompare("label",option+1) == 0)
4790 {
4791 if (*option == '+')
4792 break;
4793 i++;
cristybb503372010-05-27 20:51:26 +00004794 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004795 ThrowMogrifyException(OptionError,"MissingArgument",option);
4796 break;
4797 }
4798 if (LocaleCompare("lat",option+1) == 0)
4799 {
4800 if (*option == '+')
4801 break;
4802 i++;
cristybb503372010-05-27 20:51:26 +00004803 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004804 ThrowMogrifyException(OptionError,"MissingArgument",option);
4805 if (IsGeometry(argv[i]) == MagickFalse)
4806 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4807 }
4808 if (LocaleCompare("layers",option+1) == 0)
4809 {
cristybb503372010-05-27 20:51:26 +00004810 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004811 type;
4812
4813 if (*option == '+')
4814 break;
4815 i++;
cristybb503372010-05-27 20:51:26 +00004816 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004817 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004818 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004819 if (type < 0)
4820 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4821 argv[i]);
4822 break;
4823 }
4824 if (LocaleCompare("level",option+1) == 0)
4825 {
4826 i++;
cristybb503372010-05-27 20:51:26 +00004827 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004828 ThrowMogrifyException(OptionError,"MissingArgument",option);
4829 if (IsGeometry(argv[i]) == MagickFalse)
4830 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4831 break;
4832 }
4833 if (LocaleCompare("level-colors",option+1) == 0)
4834 {
4835 i++;
cristybb503372010-05-27 20:51:26 +00004836 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004837 ThrowMogrifyException(OptionError,"MissingArgument",option);
4838 break;
4839 }
4840 if (LocaleCompare("linewidth",option+1) == 0)
4841 {
4842 if (*option == '+')
4843 break;
4844 i++;
cristybb503372010-05-27 20:51:26 +00004845 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004846 ThrowMogrifyException(OptionError,"MissingArgument",option);
4847 if (IsGeometry(argv[i]) == MagickFalse)
4848 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4849 break;
4850 }
4851 if (LocaleCompare("limit",option+1) == 0)
4852 {
4853 char
4854 *p;
4855
4856 double
4857 value;
4858
cristybb503372010-05-27 20:51:26 +00004859 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004860 resource;
4861
4862 if (*option == '+')
4863 break;
4864 i++;
cristybb503372010-05-27 20:51:26 +00004865 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004866 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004867 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004868 argv[i]);
4869 if (resource < 0)
4870 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4871 argv[i]);
4872 i++;
cristybb503372010-05-27 20:51:26 +00004873 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004874 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004875 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004876 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004877 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4879 break;
4880 }
4881 if (LocaleCompare("liquid-rescale",option+1) == 0)
4882 {
4883 i++;
cristybb503372010-05-27 20:51:26 +00004884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004885 ThrowMogrifyException(OptionError,"MissingArgument",option);
4886 if (IsGeometry(argv[i]) == MagickFalse)
4887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4888 break;
4889 }
4890 if (LocaleCompare("list",option+1) == 0)
4891 {
cristybb503372010-05-27 20:51:26 +00004892 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004893 list;
4894
4895 if (*option == '+')
4896 break;
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);
cristy042ee782011-04-22 18:48:30 +00004900 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004901 if (list < 0)
4902 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004903 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004904 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004905 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004906 }
4907 if (LocaleCompare("log",option+1) == 0)
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 (strchr(argv[i],'%') == (char *) NULL))
4914 ThrowMogrifyException(OptionError,"MissingArgument",option);
4915 break;
4916 }
4917 if (LocaleCompare("loop",option+1) == 0)
4918 {
4919 if (*option == '+')
4920 break;
4921 i++;
cristybb503372010-05-27 20:51:26 +00004922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004923 ThrowMogrifyException(OptionError,"MissingArgument",option);
4924 if (IsGeometry(argv[i]) == MagickFalse)
4925 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4926 break;
4927 }
4928 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4929 }
4930 case 'm':
4931 {
4932 if (LocaleCompare("map",option+1) == 0)
4933 {
4934 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4935 if (*option == '+')
4936 break;
4937 i++;
cristybb503372010-05-27 20:51:26 +00004938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004939 ThrowMogrifyException(OptionError,"MissingArgument",option);
4940 break;
4941 }
4942 if (LocaleCompare("mask",option+1) == 0)
4943 {
4944 if (*option == '+')
4945 break;
4946 i++;
cristybb503372010-05-27 20:51:26 +00004947 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004948 ThrowMogrifyException(OptionError,"MissingArgument",option);
4949 break;
4950 }
4951 if (LocaleCompare("matte",option+1) == 0)
4952 break;
4953 if (LocaleCompare("mattecolor",option+1) == 0)
4954 {
4955 if (*option == '+')
4956 break;
4957 i++;
cristybb503372010-05-27 20:51:26 +00004958 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004959 ThrowMogrifyException(OptionError,"MissingArgument",option);
4960 break;
4961 }
cristyf40785b2010-03-06 02:27:27 +00004962 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004963 break;
cristyf40785b2010-03-06 02:27:27 +00004964 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004965 break;
cristy3ed852e2009-09-05 21:47:34 +00004966 if (LocaleCompare("modulate",option+1) == 0)
4967 {
4968 if (*option == '+')
4969 break;
4970 i++;
cristybb503372010-05-27 20:51:26 +00004971 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004972 ThrowMogrifyException(OptionError,"MissingArgument",option);
4973 if (IsGeometry(argv[i]) == MagickFalse)
4974 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4975 break;
4976 }
4977 if (LocaleCompare("median",option+1) == 0)
4978 {
4979 if (*option == '+')
4980 break;
4981 i++;
cristybb503372010-05-27 20:51:26 +00004982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004983 ThrowMogrifyException(OptionError,"MissingArgument",option);
4984 if (IsGeometry(argv[i]) == MagickFalse)
4985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4986 break;
4987 }
cristy69ec32d2011-02-27 23:57:09 +00004988 if (LocaleCompare("mode",option+1) == 0)
4989 {
4990 if (*option == '+')
4991 break;
4992 i++;
4993 if (i == (ssize_t) argc)
4994 ThrowMogrifyException(OptionError,"MissingArgument",option);
4995 if (IsGeometry(argv[i]) == MagickFalse)
4996 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4997 break;
4998 }
cristy3ed852e2009-09-05 21:47:34 +00004999 if (LocaleCompare("monitor",option+1) == 0)
5000 break;
5001 if (LocaleCompare("monochrome",option+1) == 0)
5002 break;
5003 if (LocaleCompare("morph",option+1) == 0)
5004 {
5005 if (*option == '+')
5006 break;
5007 i++;
cristybb503372010-05-27 20:51:26 +00005008 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005009 ThrowMogrifyException(OptionError,"MissingArgument",option);
5010 if (IsGeometry(argv[i]) == MagickFalse)
5011 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5012 break;
5013 }
anthony29188a82010-01-22 10:12:34 +00005014 if (LocaleCompare("morphology",option+1) == 0)
5015 {
anthony29188a82010-01-22 10:12:34 +00005016 char
5017 token[MaxTextExtent];
5018
cristyb6bd4ad2010-08-08 01:12:27 +00005019 KernelInfo
5020 *kernel_info;
5021
5022 ssize_t
5023 op;
5024
anthony29188a82010-01-22 10:12:34 +00005025 i++;
cristybb503372010-05-27 20:51:26 +00005026 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005027 ThrowMogrifyException(OptionError,"MissingArgument",option);
5028 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005029 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005030 if (op < 0)
5031 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005032 token);
anthony29188a82010-01-22 10:12:34 +00005033 i++;
cristybb503372010-05-27 20:51:26 +00005034 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005035 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005036 kernel_info=AcquireKernelInfo(argv[i]);
5037 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005038 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005039 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005040 break;
5041 }
cristy3ed852e2009-09-05 21:47:34 +00005042 if (LocaleCompare("mosaic",option+1) == 0)
5043 break;
5044 if (LocaleCompare("motion-blur",option+1) == 0)
5045 {
5046 if (*option == '+')
5047 break;
5048 i++;
cristybb503372010-05-27 20:51:26 +00005049 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005050 ThrowMogrifyException(OptionError,"MissingArgument",option);
5051 if (IsGeometry(argv[i]) == MagickFalse)
5052 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5053 break;
5054 }
5055 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5056 }
5057 case 'n':
5058 {
5059 if (LocaleCompare("negate",option+1) == 0)
5060 break;
5061 if (LocaleCompare("noise",option+1) == 0)
5062 {
5063 i++;
cristybb503372010-05-27 20:51:26 +00005064 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005065 ThrowMogrifyException(OptionError,"MissingArgument",option);
5066 if (*option == '+')
5067 {
cristybb503372010-05-27 20:51:26 +00005068 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005069 noise;
5070
cristy042ee782011-04-22 18:48:30 +00005071 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005072 if (noise < 0)
5073 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5074 argv[i]);
5075 break;
5076 }
5077 if (IsGeometry(argv[i]) == MagickFalse)
5078 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5079 break;
5080 }
5081 if (LocaleCompare("noop",option+1) == 0)
5082 break;
5083 if (LocaleCompare("normalize",option+1) == 0)
5084 break;
5085 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5086 }
5087 case 'o':
5088 {
5089 if (LocaleCompare("opaque",option+1) == 0)
5090 {
cristy3ed852e2009-09-05 21:47:34 +00005091 i++;
cristybb503372010-05-27 20:51:26 +00005092 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005093 ThrowMogrifyException(OptionError,"MissingArgument",option);
5094 break;
5095 }
5096 if (LocaleCompare("ordered-dither",option+1) == 0)
5097 {
5098 if (*option == '+')
5099 break;
5100 i++;
cristybb503372010-05-27 20:51:26 +00005101 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005102 ThrowMogrifyException(OptionError,"MissingArgument",option);
5103 break;
5104 }
5105 if (LocaleCompare("orient",option+1) == 0)
5106 {
cristybb503372010-05-27 20:51:26 +00005107 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005108 orientation;
5109
5110 orientation=UndefinedOrientation;
5111 if (*option == '+')
5112 break;
5113 i++;
cristybb503372010-05-27 20:51:26 +00005114 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005115 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005116 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005117 argv[i]);
5118 if (orientation < 0)
5119 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5120 argv[i]);
5121 break;
5122 }
5123 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5124 }
5125 case 'p':
5126 {
5127 if (LocaleCompare("page",option+1) == 0)
5128 {
5129 if (*option == '+')
5130 break;
5131 i++;
cristybb503372010-05-27 20:51:26 +00005132 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005133 ThrowMogrifyException(OptionError,"MissingArgument",option);
5134 break;
5135 }
5136 if (LocaleCompare("paint",option+1) == 0)
5137 {
5138 if (*option == '+')
5139 break;
5140 i++;
cristybb503372010-05-27 20:51:26 +00005141 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005142 ThrowMogrifyException(OptionError,"MissingArgument",option);
5143 if (IsGeometry(argv[i]) == MagickFalse)
5144 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5145 break;
5146 }
5147 if (LocaleCompare("path",option+1) == 0)
5148 {
5149 (void) CloneString(&path,(char *) NULL);
5150 if (*option == '+')
5151 break;
5152 i++;
cristybb503372010-05-27 20:51:26 +00005153 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005154 ThrowMogrifyException(OptionError,"MissingArgument",option);
5155 (void) CloneString(&path,argv[i]);
5156 break;
5157 }
5158 if (LocaleCompare("pointsize",option+1) == 0)
5159 {
5160 if (*option == '+')
5161 break;
5162 i++;
cristybb503372010-05-27 20:51:26 +00005163 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005164 ThrowMogrifyException(OptionError,"MissingArgument",option);
5165 if (IsGeometry(argv[i]) == MagickFalse)
5166 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5167 break;
5168 }
5169 if (LocaleCompare("polaroid",option+1) == 0)
5170 {
5171 if (*option == '+')
5172 break;
5173 i++;
cristybb503372010-05-27 20:51:26 +00005174 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005175 ThrowMogrifyException(OptionError,"MissingArgument",option);
5176 if (IsGeometry(argv[i]) == MagickFalse)
5177 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5178 break;
5179 }
5180 if (LocaleCompare("posterize",option+1) == 0)
5181 {
5182 if (*option == '+')
5183 break;
5184 i++;
cristybb503372010-05-27 20:51:26 +00005185 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005186 ThrowMogrifyException(OptionError,"MissingArgument",option);
5187 if (IsGeometry(argv[i]) == MagickFalse)
5188 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5189 break;
5190 }
cristye7f51092010-01-17 00:39:37 +00005191 if (LocaleCompare("precision",option+1) == 0)
5192 {
5193 if (*option == '+')
5194 break;
5195 i++;
cristybb503372010-05-27 20:51:26 +00005196 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005197 ThrowMogrifyException(OptionError,"MissingArgument",option);
5198 if (IsGeometry(argv[i]) == MagickFalse)
5199 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5200 break;
5201 }
cristy3ed852e2009-09-05 21:47:34 +00005202 if (LocaleCompare("print",option+1) == 0)
5203 {
5204 if (*option == '+')
5205 break;
5206 i++;
cristybb503372010-05-27 20:51:26 +00005207 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005208 ThrowMogrifyException(OptionError,"MissingArgument",option);
5209 break;
5210 }
5211 if (LocaleCompare("process",option+1) == 0)
5212 {
5213 if (*option == '+')
5214 break;
5215 i++;
cristybb503372010-05-27 20:51:26 +00005216 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005217 ThrowMogrifyException(OptionError,"MissingArgument",option);
5218 break;
5219 }
5220 if (LocaleCompare("profile",option+1) == 0)
5221 {
5222 i++;
cristybb503372010-05-27 20:51:26 +00005223 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005224 ThrowMogrifyException(OptionError,"MissingArgument",option);
5225 break;
5226 }
5227 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5228 }
5229 case 'q':
5230 {
5231 if (LocaleCompare("quality",option+1) == 0)
5232 {
5233 if (*option == '+')
5234 break;
5235 i++;
cristybb503372010-05-27 20:51:26 +00005236 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005237 ThrowMogrifyException(OptionError,"MissingArgument",option);
5238 if (IsGeometry(argv[i]) == MagickFalse)
5239 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5240 break;
5241 }
5242 if (LocaleCompare("quantize",option+1) == 0)
5243 {
cristybb503372010-05-27 20:51:26 +00005244 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005245 colorspace;
5246
5247 if (*option == '+')
5248 break;
5249 i++;
cristybb503372010-05-27 20:51:26 +00005250 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005251 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005252 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005253 argv[i]);
5254 if (colorspace < 0)
5255 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5256 argv[i]);
5257 break;
5258 }
5259 if (LocaleCompare("quiet",option+1) == 0)
5260 break;
5261 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5262 }
5263 case 'r':
5264 {
5265 if (LocaleCompare("radial-blur",option+1) == 0)
5266 {
5267 i++;
cristybb503372010-05-27 20:51:26 +00005268 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005269 ThrowMogrifyException(OptionError,"MissingArgument",option);
5270 if (IsGeometry(argv[i]) == MagickFalse)
5271 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5272 break;
5273 }
5274 if (LocaleCompare("raise",option+1) == 0)
5275 {
5276 i++;
cristybb503372010-05-27 20:51:26 +00005277 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005278 ThrowMogrifyException(OptionError,"MissingArgument",option);
5279 if (IsGeometry(argv[i]) == MagickFalse)
5280 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5281 break;
5282 }
5283 if (LocaleCompare("random-threshold",option+1) == 0)
5284 {
5285 if (*option == '+')
5286 break;
5287 i++;
cristybb503372010-05-27 20:51:26 +00005288 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005289 ThrowMogrifyException(OptionError,"MissingArgument",option);
5290 if (IsGeometry(argv[i]) == MagickFalse)
5291 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5292 break;
5293 }
cristye6365592010-04-02 17:31:23 +00005294 if (LocaleCompare("recolor",option+1) == 0)
5295 {
5296 if (*option == '+')
5297 break;
5298 i++;
cristybb503372010-05-27 20:51:26 +00005299 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005300 ThrowMogrifyException(OptionError,"MissingArgument",option);
5301 if (IsGeometry(argv[i]) == MagickFalse)
5302 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5303 break;
5304 }
cristy3ed852e2009-09-05 21:47:34 +00005305 if (LocaleCompare("red-primary",option+1) == 0)
5306 {
5307 if (*option == '+')
5308 break;
5309 i++;
cristybb503372010-05-27 20:51:26 +00005310 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005311 ThrowMogrifyException(OptionError,"MissingArgument",option);
5312 if (IsGeometry(argv[i]) == MagickFalse)
5313 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5314 }
cristy9f2083a2010-04-22 19:48:05 +00005315 if (LocaleCompare("regard-warnings",option+1) == 0)
5316 break;
cristy3ed852e2009-09-05 21:47:34 +00005317 if (LocaleCompare("region",option+1) == 0)
5318 {
5319 if (*option == '+')
5320 break;
5321 i++;
cristybb503372010-05-27 20:51:26 +00005322 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005323 ThrowMogrifyException(OptionError,"MissingArgument",option);
5324 if (IsGeometry(argv[i]) == MagickFalse)
5325 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5326 break;
5327 }
cristyf0c78232010-03-15 12:53:40 +00005328 if (LocaleCompare("remap",option+1) == 0)
5329 {
5330 if (*option == '+')
5331 break;
5332 i++;
cristybb503372010-05-27 20:51:26 +00005333 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005334 ThrowMogrifyException(OptionError,"MissingArgument",option);
5335 break;
5336 }
cristy3ed852e2009-09-05 21:47:34 +00005337 if (LocaleCompare("render",option+1) == 0)
5338 break;
5339 if (LocaleCompare("repage",option+1) == 0)
5340 {
5341 if (*option == '+')
5342 break;
5343 i++;
cristybb503372010-05-27 20:51:26 +00005344 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005345 ThrowMogrifyException(OptionError,"MissingArgument",option);
5346 if (IsGeometry(argv[i]) == MagickFalse)
5347 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5348 break;
5349 }
5350 if (LocaleCompare("resample",option+1) == 0)
5351 {
5352 if (*option == '+')
5353 break;
5354 i++;
cristybb503372010-05-27 20:51:26 +00005355 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005356 ThrowMogrifyException(OptionError,"MissingArgument",option);
5357 if (IsGeometry(argv[i]) == MagickFalse)
5358 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5359 break;
5360 }
5361 if (LocaleCompare("resize",option+1) == 0)
5362 {
5363 if (*option == '+')
5364 break;
5365 i++;
cristybb503372010-05-27 20:51:26 +00005366 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005367 ThrowMogrifyException(OptionError,"MissingArgument",option);
5368 if (IsGeometry(argv[i]) == MagickFalse)
5369 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5370 break;
5371 }
cristyebbcfea2011-02-25 02:43:54 +00005372 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5373 {
5374 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5375 break;
5376 }
cristy3ed852e2009-09-05 21:47:34 +00005377 if (LocaleCompare("reverse",option+1) == 0)
5378 break;
5379 if (LocaleCompare("roll",option+1) == 0)
5380 {
5381 if (*option == '+')
5382 break;
5383 i++;
cristybb503372010-05-27 20:51:26 +00005384 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005385 ThrowMogrifyException(OptionError,"MissingArgument",option);
5386 if (IsGeometry(argv[i]) == MagickFalse)
5387 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5388 break;
5389 }
5390 if (LocaleCompare("rotate",option+1) == 0)
5391 {
5392 i++;
cristybb503372010-05-27 20:51:26 +00005393 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005394 ThrowMogrifyException(OptionError,"MissingArgument",option);
5395 if (IsGeometry(argv[i]) == MagickFalse)
5396 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5397 break;
5398 }
5399 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5400 }
5401 case 's':
5402 {
5403 if (LocaleCompare("sample",option+1) == 0)
5404 {
5405 if (*option == '+')
5406 break;
5407 i++;
cristybb503372010-05-27 20:51:26 +00005408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005409 ThrowMogrifyException(OptionError,"MissingArgument",option);
5410 if (IsGeometry(argv[i]) == MagickFalse)
5411 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5412 break;
5413 }
5414 if (LocaleCompare("sampling-factor",option+1) == 0)
5415 {
5416 if (*option == '+')
5417 break;
5418 i++;
cristybb503372010-05-27 20:51:26 +00005419 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005420 ThrowMogrifyException(OptionError,"MissingArgument",option);
5421 if (IsGeometry(argv[i]) == MagickFalse)
5422 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5423 break;
5424 }
5425 if (LocaleCompare("scale",option+1) == 0)
5426 {
5427 if (*option == '+')
5428 break;
5429 i++;
cristybb503372010-05-27 20:51:26 +00005430 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005431 ThrowMogrifyException(OptionError,"MissingArgument",option);
5432 if (IsGeometry(argv[i]) == MagickFalse)
5433 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5434 break;
5435 }
5436 if (LocaleCompare("scene",option+1) == 0)
5437 {
5438 if (*option == '+')
5439 break;
5440 i++;
cristybb503372010-05-27 20:51:26 +00005441 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005442 ThrowMogrifyException(OptionError,"MissingArgument",option);
5443 if (IsGeometry(argv[i]) == MagickFalse)
5444 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5445 break;
5446 }
5447 if (LocaleCompare("seed",option+1) == 0)
5448 {
5449 if (*option == '+')
5450 break;
5451 i++;
cristybb503372010-05-27 20:51:26 +00005452 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005453 ThrowMogrifyException(OptionError,"MissingArgument",option);
5454 if (IsGeometry(argv[i]) == MagickFalse)
5455 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5456 break;
5457 }
5458 if (LocaleCompare("segment",option+1) == 0)
5459 {
5460 if (*option == '+')
5461 break;
5462 i++;
cristybb503372010-05-27 20:51:26 +00005463 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005464 ThrowMogrifyException(OptionError,"MissingArgument",option);
5465 if (IsGeometry(argv[i]) == MagickFalse)
5466 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5467 break;
5468 }
5469 if (LocaleCompare("selective-blur",option+1) == 0)
5470 {
5471 i++;
cristybb503372010-05-27 20:51:26 +00005472 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005473 ThrowMogrifyException(OptionError,"MissingArgument",option);
5474 if (IsGeometry(argv[i]) == MagickFalse)
5475 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5476 break;
5477 }
5478 if (LocaleCompare("separate",option+1) == 0)
5479 break;
5480 if (LocaleCompare("sepia-tone",option+1) == 0)
5481 {
5482 if (*option == '+')
5483 break;
5484 i++;
cristybb503372010-05-27 20:51:26 +00005485 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005486 ThrowMogrifyException(OptionError,"MissingArgument",option);
5487 if (IsGeometry(argv[i]) == MagickFalse)
5488 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5489 break;
5490 }
5491 if (LocaleCompare("set",option+1) == 0)
5492 {
5493 i++;
cristybb503372010-05-27 20:51:26 +00005494 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005495 ThrowMogrifyException(OptionError,"MissingArgument",option);
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 break;
5502 }
5503 if (LocaleCompare("shade",option+1) == 0)
5504 {
5505 i++;
cristybb503372010-05-27 20:51:26 +00005506 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005507 ThrowMogrifyException(OptionError,"MissingArgument",option);
5508 if (IsGeometry(argv[i]) == MagickFalse)
5509 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5510 break;
5511 }
5512 if (LocaleCompare("shadow",option+1) == 0)
5513 {
5514 if (*option == '+')
5515 break;
5516 i++;
cristybb503372010-05-27 20:51:26 +00005517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005518 ThrowMogrifyException(OptionError,"MissingArgument",option);
5519 if (IsGeometry(argv[i]) == MagickFalse)
5520 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5521 break;
5522 }
5523 if (LocaleCompare("sharpen",option+1) == 0)
5524 {
5525 i++;
cristybb503372010-05-27 20:51:26 +00005526 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005527 ThrowMogrifyException(OptionError,"MissingArgument",option);
5528 if (IsGeometry(argv[i]) == MagickFalse)
5529 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5530 break;
5531 }
5532 if (LocaleCompare("shave",option+1) == 0)
5533 {
5534 if (*option == '+')
5535 break;
5536 i++;
cristybb503372010-05-27 20:51:26 +00005537 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005538 ThrowMogrifyException(OptionError,"MissingArgument",option);
5539 if (IsGeometry(argv[i]) == MagickFalse)
5540 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5541 break;
5542 }
5543 if (LocaleCompare("shear",option+1) == 0)
5544 {
5545 i++;
cristybb503372010-05-27 20:51:26 +00005546 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005547 ThrowMogrifyException(OptionError,"MissingArgument",option);
5548 if (IsGeometry(argv[i]) == MagickFalse)
5549 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5550 break;
5551 }
5552 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5553 {
5554 i++;
cristybb503372010-05-27 20:51:26 +00005555 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005556 ThrowMogrifyException(OptionError,"MissingArgument",option);
5557 if (IsGeometry(argv[i]) == MagickFalse)
5558 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5559 break;
5560 }
5561 if (LocaleCompare("size",option+1) == 0)
5562 {
5563 if (*option == '+')
5564 break;
5565 i++;
cristybb503372010-05-27 20:51:26 +00005566 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005567 ThrowMogrifyException(OptionError,"MissingArgument",option);
5568 if (IsGeometry(argv[i]) == MagickFalse)
5569 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5570 break;
5571 }
5572 if (LocaleCompare("sketch",option+1) == 0)
5573 {
5574 if (*option == '+')
5575 break;
5576 i++;
cristybb503372010-05-27 20:51:26 +00005577 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005578 ThrowMogrifyException(OptionError,"MissingArgument",option);
5579 if (IsGeometry(argv[i]) == MagickFalse)
5580 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5581 break;
5582 }
cristy4285d782011-02-09 20:12:28 +00005583 if (LocaleCompare("smush",option+1) == 0)
5584 {
cristy4285d782011-02-09 20:12:28 +00005585 i++;
5586 if (i == (ssize_t) argc)
5587 ThrowMogrifyException(OptionError,"MissingArgument",option);
5588 if (IsGeometry(argv[i]) == MagickFalse)
5589 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005590 i++;
5591 break;
5592 }
cristy3ed852e2009-09-05 21:47:34 +00005593 if (LocaleCompare("solarize",option+1) == 0)
5594 {
5595 if (*option == '+')
5596 break;
5597 i++;
cristybb503372010-05-27 20:51:26 +00005598 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005599 ThrowMogrifyException(OptionError,"MissingArgument",option);
5600 if (IsGeometry(argv[i]) == MagickFalse)
5601 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5602 break;
5603 }
5604 if (LocaleCompare("sparse-color",option+1) == 0)
5605 {
cristybb503372010-05-27 20:51:26 +00005606 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005607 op;
5608
5609 i++;
cristybb503372010-05-27 20:51:26 +00005610 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005611 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005612 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005613 if (op < 0)
5614 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5615 argv[i]);
5616 i++;
cristybb503372010-05-27 20:51:26 +00005617 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005618 ThrowMogrifyException(OptionError,"MissingArgument",option);
5619 break;
5620 }
5621 if (LocaleCompare("spread",option+1) == 0)
5622 {
5623 if (*option == '+')
5624 break;
5625 i++;
cristybb503372010-05-27 20:51:26 +00005626 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005627 ThrowMogrifyException(OptionError,"MissingArgument",option);
5628 if (IsGeometry(argv[i]) == MagickFalse)
5629 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5630 break;
5631 }
cristy0834d642011-03-18 18:26:08 +00005632 if (LocaleCompare("statistic",option+1) == 0)
5633 {
5634 ssize_t
5635 op;
5636
5637 if (*option == '+')
5638 break;
5639 i++;
5640 if (i == (ssize_t) argc)
5641 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005642 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005643 if (op < 0)
5644 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5645 argv[i]);
5646 i++;
5647 if (i == (ssize_t) (argc-1))
5648 ThrowMogrifyException(OptionError,"MissingArgument",option);
5649 if (IsGeometry(argv[i]) == MagickFalse)
5650 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5651 break;
5652 }
cristy3ed852e2009-09-05 21:47:34 +00005653 if (LocaleCompare("stretch",option+1) == 0)
5654 {
cristybb503372010-05-27 20:51:26 +00005655 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005656 stretch;
5657
5658 if (*option == '+')
5659 break;
5660 i++;
cristybb503372010-05-27 20:51:26 +00005661 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005662 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005663 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005664 if (stretch < 0)
5665 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5666 argv[i]);
5667 break;
5668 }
5669 if (LocaleCompare("strip",option+1) == 0)
5670 break;
5671 if (LocaleCompare("stroke",option+1) == 0)
5672 {
5673 if (*option == '+')
5674 break;
5675 i++;
cristybb503372010-05-27 20:51:26 +00005676 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005677 ThrowMogrifyException(OptionError,"MissingArgument",option);
5678 break;
5679 }
5680 if (LocaleCompare("strokewidth",option+1) == 0)
5681 {
5682 if (*option == '+')
5683 break;
5684 i++;
cristybb503372010-05-27 20:51:26 +00005685 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005686 ThrowMogrifyException(OptionError,"MissingArgument",option);
5687 if (IsGeometry(argv[i]) == MagickFalse)
5688 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5689 break;
5690 }
5691 if (LocaleCompare("style",option+1) == 0)
5692 {
cristybb503372010-05-27 20:51:26 +00005693 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005694 style;
5695
5696 if (*option == '+')
5697 break;
5698 i++;
cristybb503372010-05-27 20:51:26 +00005699 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005700 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005701 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005702 if (style < 0)
5703 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5704 argv[i]);
5705 break;
5706 }
cristyecb10ff2011-03-22 13:14:03 +00005707 if (LocaleCompare("swap",option+1) == 0)
5708 {
5709 if (*option == '+')
5710 break;
5711 i++;
5712 if (i == (ssize_t) (argc-1))
5713 ThrowMogrifyException(OptionError,"MissingArgument",option);
5714 if (IsGeometry(argv[i]) == MagickFalse)
5715 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5716 break;
5717 }
cristy3ed852e2009-09-05 21:47:34 +00005718 if (LocaleCompare("swirl",option+1) == 0)
5719 {
5720 if (*option == '+')
5721 break;
5722 i++;
cristybb503372010-05-27 20:51:26 +00005723 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005724 ThrowMogrifyException(OptionError,"MissingArgument",option);
5725 if (IsGeometry(argv[i]) == MagickFalse)
5726 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5727 break;
5728 }
cristyd9a29192010-10-16 16:49:53 +00005729 if (LocaleCompare("synchronize",option+1) == 0)
5730 break;
cristy3ed852e2009-09-05 21:47:34 +00005731 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5732 }
5733 case 't':
5734 {
5735 if (LocaleCompare("taint",option+1) == 0)
5736 break;
5737 if (LocaleCompare("texture",option+1) == 0)
5738 {
5739 if (*option == '+')
5740 break;
5741 i++;
cristybb503372010-05-27 20:51:26 +00005742 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005743 ThrowMogrifyException(OptionError,"MissingArgument",option);
5744 break;
5745 }
5746 if (LocaleCompare("tile",option+1) == 0)
5747 {
5748 if (*option == '+')
5749 break;
5750 i++;
cristybb503372010-05-27 20:51:26 +00005751 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005752 ThrowMogrifyException(OptionError,"MissingArgument",option);
5753 break;
5754 }
5755 if (LocaleCompare("tile-offset",option+1) == 0)
5756 {
5757 if (*option == '+')
5758 break;
5759 i++;
cristybb503372010-05-27 20:51:26 +00005760 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005761 ThrowMogrifyException(OptionError,"MissingArgument",option);
5762 if (IsGeometry(argv[i]) == MagickFalse)
5763 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5764 break;
5765 }
5766 if (LocaleCompare("tint",option+1) == 0)
5767 {
5768 if (*option == '+')
5769 break;
5770 i++;
cristybb503372010-05-27 20:51:26 +00005771 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005772 ThrowMogrifyException(OptionError,"MissingArgument",option);
5773 if (IsGeometry(argv[i]) == MagickFalse)
5774 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5775 break;
5776 }
5777 if (LocaleCompare("transform",option+1) == 0)
5778 break;
5779 if (LocaleCompare("transpose",option+1) == 0)
5780 break;
5781 if (LocaleCompare("transverse",option+1) == 0)
5782 break;
5783 if (LocaleCompare("threshold",option+1) == 0)
5784 {
5785 if (*option == '+')
5786 break;
5787 i++;
cristybb503372010-05-27 20:51:26 +00005788 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005789 ThrowMogrifyException(OptionError,"MissingArgument",option);
5790 if (IsGeometry(argv[i]) == MagickFalse)
5791 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5792 break;
5793 }
5794 if (LocaleCompare("thumbnail",option+1) == 0)
5795 {
5796 if (*option == '+')
5797 break;
5798 i++;
cristybb503372010-05-27 20:51:26 +00005799 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005800 ThrowMogrifyException(OptionError,"MissingArgument",option);
5801 if (IsGeometry(argv[i]) == MagickFalse)
5802 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5803 break;
5804 }
5805 if (LocaleCompare("transparent",option+1) == 0)
5806 {
5807 i++;
cristybb503372010-05-27 20:51:26 +00005808 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005809 ThrowMogrifyException(OptionError,"MissingArgument",option);
5810 break;
5811 }
5812 if (LocaleCompare("transparent-color",option+1) == 0)
5813 {
5814 if (*option == '+')
5815 break;
5816 i++;
cristybb503372010-05-27 20:51:26 +00005817 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005818 ThrowMogrifyException(OptionError,"MissingArgument",option);
5819 break;
5820 }
5821 if (LocaleCompare("treedepth",option+1) == 0)
5822 {
5823 if (*option == '+')
5824 break;
5825 i++;
cristybb503372010-05-27 20:51:26 +00005826 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005827 ThrowMogrifyException(OptionError,"MissingArgument",option);
5828 if (IsGeometry(argv[i]) == MagickFalse)
5829 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5830 break;
5831 }
5832 if (LocaleCompare("trim",option+1) == 0)
5833 break;
5834 if (LocaleCompare("type",option+1) == 0)
5835 {
cristybb503372010-05-27 20:51:26 +00005836 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005837 type;
5838
5839 if (*option == '+')
5840 break;
5841 i++;
cristybb503372010-05-27 20:51:26 +00005842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005843 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005844 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005845 if (type < 0)
5846 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5847 argv[i]);
5848 break;
5849 }
5850 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5851 }
5852 case 'u':
5853 {
5854 if (LocaleCompare("undercolor",option+1) == 0)
5855 {
5856 if (*option == '+')
5857 break;
5858 i++;
cristybb503372010-05-27 20:51:26 +00005859 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005860 ThrowMogrifyException(OptionError,"MissingArgument",option);
5861 break;
5862 }
5863 if (LocaleCompare("unique-colors",option+1) == 0)
5864 break;
5865 if (LocaleCompare("units",option+1) == 0)
5866 {
cristybb503372010-05-27 20:51:26 +00005867 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005868 units;
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);
cristy042ee782011-04-22 18:48:30 +00005875 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005876 argv[i]);
5877 if (units < 0)
5878 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5879 argv[i]);
5880 break;
5881 }
5882 if (LocaleCompare("unsharp",option+1) == 0)
5883 {
5884 i++;
cristybb503372010-05-27 20:51:26 +00005885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005886 ThrowMogrifyException(OptionError,"MissingArgument",option);
5887 if (IsGeometry(argv[i]) == MagickFalse)
5888 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5889 break;
5890 }
5891 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5892 }
5893 case 'v':
5894 {
5895 if (LocaleCompare("verbose",option+1) == 0)
5896 {
5897 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5898 break;
5899 }
5900 if ((LocaleCompare("version",option+1) == 0) ||
5901 (LocaleCompare("-version",option+1) == 0))
5902 {
cristyb51dff52011-05-19 16:55:47 +00005903 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005904 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005905 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5906 GetMagickCopyright());
5907 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5908 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005909 break;
5910 }
5911 if (LocaleCompare("view",option+1) == 0)
5912 {
5913 if (*option == '+')
5914 break;
5915 i++;
cristybb503372010-05-27 20:51:26 +00005916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005917 ThrowMogrifyException(OptionError,"MissingArgument",option);
5918 break;
5919 }
5920 if (LocaleCompare("vignette",option+1) == 0)
5921 {
5922 if (*option == '+')
5923 break;
5924 i++;
cristybb503372010-05-27 20:51:26 +00005925 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005926 ThrowMogrifyException(OptionError,"MissingArgument",option);
5927 if (IsGeometry(argv[i]) == MagickFalse)
5928 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5929 break;
5930 }
5931 if (LocaleCompare("virtual-pixel",option+1) == 0)
5932 {
cristybb503372010-05-27 20:51:26 +00005933 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005934 method;
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);
cristy042ee782011-04-22 18:48:30 +00005941 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005942 argv[i]);
5943 if (method < 0)
5944 ThrowMogrifyException(OptionError,
5945 "UnrecognizedVirtualPixelMethod",argv[i]);
5946 break;
5947 }
5948 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5949 }
5950 case 'w':
5951 {
5952 if (LocaleCompare("wave",option+1) == 0)
5953 {
5954 i++;
cristybb503372010-05-27 20:51:26 +00005955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005956 ThrowMogrifyException(OptionError,"MissingArgument",option);
5957 if (IsGeometry(argv[i]) == MagickFalse)
5958 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5959 break;
5960 }
5961 if (LocaleCompare("weight",option+1) == 0)
5962 {
5963 if (*option == '+')
5964 break;
5965 i++;
cristybb503372010-05-27 20:51:26 +00005966 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005967 ThrowMogrifyException(OptionError,"MissingArgument",option);
5968 break;
5969 }
5970 if (LocaleCompare("white-point",option+1) == 0)
5971 {
5972 if (*option == '+')
5973 break;
5974 i++;
cristybb503372010-05-27 20:51:26 +00005975 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005976 ThrowMogrifyException(OptionError,"MissingArgument",option);
5977 if (IsGeometry(argv[i]) == MagickFalse)
5978 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5979 break;
5980 }
5981 if (LocaleCompare("white-threshold",option+1) == 0)
5982 {
5983 if (*option == '+')
5984 break;
5985 i++;
cristybb503372010-05-27 20:51:26 +00005986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005987 ThrowMogrifyException(OptionError,"MissingArgument",option);
5988 if (IsGeometry(argv[i]) == MagickFalse)
5989 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5990 break;
5991 }
5992 if (LocaleCompare("write",option+1) == 0)
5993 {
5994 i++;
cristybb503372010-05-27 20:51:26 +00005995 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005996 ThrowMogrifyException(OptionError,"MissingArgument",option);
5997 break;
5998 }
5999 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6000 }
6001 case '?':
6002 break;
6003 default:
6004 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6005 }
cristy042ee782011-04-22 18:48:30 +00006006 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6007 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006008 if (fire != MagickFalse)
6009 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6010 }
6011 if (k != 0)
6012 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006013 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006014 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6015 DestroyMogrify();
6016 return(status != 0 ? MagickTrue : MagickFalse);
6017}
6018
6019/*
6020%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6021% %
6022% %
6023% %
6024+ M o g r i f y I m a g e I n f o %
6025% %
6026% %
6027% %
6028%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6029%
6030% MogrifyImageInfo() applies image processing settings to the image as
6031% prescribed by command line options.
6032%
6033% The format of the MogrifyImageInfo method is:
6034%
6035% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6036% const char **argv,ExceptionInfo *exception)
6037%
6038% A description of each parameter follows:
6039%
6040% o image_info: the image info..
6041%
6042% o argc: Specifies a pointer to an integer describing the number of
6043% elements in the argument vector.
6044%
6045% o argv: Specifies a pointer to a text array containing the command line
6046% arguments.
6047%
6048% o exception: return any errors or warnings in this structure.
6049%
6050*/
6051WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6052 const int argc,const char **argv,ExceptionInfo *exception)
6053{
6054 const char
6055 *option;
6056
6057 GeometryInfo
6058 geometry_info;
6059
cristybb503372010-05-27 20:51:26 +00006060 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006061 count;
6062
cristybb503372010-05-27 20:51:26 +00006063 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006064 i;
6065
6066 /*
6067 Initialize method variables.
6068 */
6069 assert(image_info != (ImageInfo *) NULL);
6070 assert(image_info->signature == MagickSignature);
6071 if (image_info->debug != MagickFalse)
6072 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6073 image_info->filename);
6074 if (argc < 0)
6075 return(MagickTrue);
6076 /*
6077 Set the image settings.
6078 */
cristybb503372010-05-27 20:51:26 +00006079 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006080 {
6081 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006082 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006083 continue;
cristy042ee782011-04-22 18:48:30 +00006084 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006085 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006086 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006087 break;
6088 switch (*(option+1))
6089 {
6090 case 'a':
6091 {
6092 if (LocaleCompare("adjoin",option+1) == 0)
6093 {
6094 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6095 break;
6096 }
6097 if (LocaleCompare("antialias",option+1) == 0)
6098 {
6099 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6100 break;
6101 }
6102 if (LocaleCompare("attenuate",option+1) == 0)
6103 {
6104 if (*option == '+')
6105 {
6106 (void) DeleteImageOption(image_info,option+1);
6107 break;
6108 }
6109 (void) SetImageOption(image_info,option+1,argv[i+1]);
6110 break;
6111 }
6112 if (LocaleCompare("authenticate",option+1) == 0)
6113 {
6114 if (*option == '+')
6115 (void) CloneString(&image_info->authenticate,(char *) NULL);
6116 else
6117 (void) CloneString(&image_info->authenticate,argv[i+1]);
6118 break;
6119 }
6120 break;
6121 }
6122 case 'b':
6123 {
6124 if (LocaleCompare("background",option+1) == 0)
6125 {
6126 if (*option == '+')
6127 {
6128 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006129 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006130 &image_info->background_color,exception);
6131 break;
6132 }
6133 (void) SetImageOption(image_info,option+1,argv[i+1]);
6134 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6135 exception);
6136 break;
6137 }
6138 if (LocaleCompare("bias",option+1) == 0)
6139 {
6140 if (*option == '+')
6141 {
6142 (void) SetImageOption(image_info,option+1,"0.0");
6143 break;
6144 }
6145 (void) SetImageOption(image_info,option+1,argv[i+1]);
6146 break;
6147 }
6148 if (LocaleCompare("black-point-compensation",option+1) == 0)
6149 {
6150 if (*option == '+')
6151 {
6152 (void) SetImageOption(image_info,option+1,"false");
6153 break;
6154 }
6155 (void) SetImageOption(image_info,option+1,"true");
6156 break;
6157 }
6158 if (LocaleCompare("blue-primary",option+1) == 0)
6159 {
6160 if (*option == '+')
6161 {
6162 (void) SetImageOption(image_info,option+1,"0.0");
6163 break;
6164 }
6165 (void) SetImageOption(image_info,option+1,argv[i+1]);
6166 break;
6167 }
6168 if (LocaleCompare("bordercolor",option+1) == 0)
6169 {
6170 if (*option == '+')
6171 {
6172 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006173 (void) QueryColorDatabase(MogrifyBorderColor,
6174 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006175 break;
6176 }
6177 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6178 exception);
6179 (void) SetImageOption(image_info,option+1,argv[i+1]);
6180 break;
6181 }
6182 if (LocaleCompare("box",option+1) == 0)
6183 {
6184 if (*option == '+')
6185 {
6186 (void) SetImageOption(image_info,"undercolor","none");
6187 break;
6188 }
6189 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6190 break;
6191 }
6192 break;
6193 }
6194 case 'c':
6195 {
6196 if (LocaleCompare("cache",option+1) == 0)
6197 {
6198 MagickSizeType
6199 limit;
6200
6201 limit=MagickResourceInfinity;
6202 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006203 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006204 (void) SetMagickResourceLimit(MemoryResource,limit);
6205 (void) SetMagickResourceLimit(MapResource,2*limit);
6206 break;
6207 }
6208 if (LocaleCompare("caption",option+1) == 0)
6209 {
6210 if (*option == '+')
6211 {
6212 (void) DeleteImageOption(image_info,option+1);
6213 break;
6214 }
6215 (void) SetImageOption(image_info,option+1,argv[i+1]);
6216 break;
6217 }
6218 if (LocaleCompare("channel",option+1) == 0)
6219 {
6220 if (*option == '+')
6221 {
6222 image_info->channel=DefaultChannels;
6223 break;
6224 }
6225 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6226 break;
6227 }
6228 if (LocaleCompare("colors",option+1) == 0)
6229 {
cristye27293e2009-12-18 02:53:20 +00006230 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006231 break;
6232 }
6233 if (LocaleCompare("colorspace",option+1) == 0)
6234 {
6235 if (*option == '+')
6236 {
6237 image_info->colorspace=UndefinedColorspace;
6238 (void) SetImageOption(image_info,option+1,"undefined");
6239 break;
6240 }
cristy042ee782011-04-22 18:48:30 +00006241 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006242 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6243 (void) SetImageOption(image_info,option+1,argv[i+1]);
6244 break;
6245 }
cristy3ed852e2009-09-05 21:47:34 +00006246 if (LocaleCompare("comment",option+1) == 0)
6247 {
6248 if (*option == '+')
6249 {
6250 (void) DeleteImageOption(image_info,option+1);
6251 break;
6252 }
6253 (void) SetImageOption(image_info,option+1,argv[i+1]);
6254 break;
6255 }
6256 if (LocaleCompare("compose",option+1) == 0)
6257 {
6258 if (*option == '+')
6259 {
6260 (void) SetImageOption(image_info,option+1,"undefined");
6261 break;
6262 }
6263 (void) SetImageOption(image_info,option+1,argv[i+1]);
6264 break;
6265 }
6266 if (LocaleCompare("compress",option+1) == 0)
6267 {
6268 if (*option == '+')
6269 {
6270 image_info->compression=UndefinedCompression;
6271 (void) SetImageOption(image_info,option+1,"undefined");
6272 break;
6273 }
cristy042ee782011-04-22 18:48:30 +00006274 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006275 MagickCompressOptions,MagickFalse,argv[i+1]);
6276 (void) SetImageOption(image_info,option+1,argv[i+1]);
6277 break;
6278 }
6279 break;
6280 }
6281 case 'd':
6282 {
6283 if (LocaleCompare("debug",option+1) == 0)
6284 {
6285 if (*option == '+')
6286 (void) SetLogEventMask("none");
6287 else
6288 (void) SetLogEventMask(argv[i+1]);
6289 image_info->debug=IsEventLogging();
6290 break;
6291 }
6292 if (LocaleCompare("define",option+1) == 0)
6293 {
6294 if (*option == '+')
6295 {
6296 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6297 (void) DeleteImageRegistry(argv[i+1]+9);
6298 else
6299 (void) DeleteImageOption(image_info,argv[i+1]);
6300 break;
6301 }
6302 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6303 {
6304 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6305 exception);
6306 break;
6307 }
6308 (void) DefineImageOption(image_info,argv[i+1]);
6309 break;
6310 }
6311 if (LocaleCompare("delay",option+1) == 0)
6312 {
6313 if (*option == '+')
6314 {
6315 (void) SetImageOption(image_info,option+1,"0");
6316 break;
6317 }
6318 (void) SetImageOption(image_info,option+1,argv[i+1]);
6319 break;
6320 }
6321 if (LocaleCompare("density",option+1) == 0)
6322 {
6323 /*
6324 Set image density.
6325 */
6326 if (*option == '+')
6327 {
6328 if (image_info->density != (char *) NULL)
6329 image_info->density=DestroyString(image_info->density);
6330 (void) SetImageOption(image_info,option+1,"72");
6331 break;
6332 }
6333 (void) CloneString(&image_info->density,argv[i+1]);
6334 (void) SetImageOption(image_info,option+1,argv[i+1]);
6335 break;
6336 }
6337 if (LocaleCompare("depth",option+1) == 0)
6338 {
6339 if (*option == '+')
6340 {
6341 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6342 break;
6343 }
cristye27293e2009-12-18 02:53:20 +00006344 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006345 break;
6346 }
cristyc9b12952010-03-28 01:12:28 +00006347 if (LocaleCompare("direction",option+1) == 0)
6348 {
6349 if (*option == '+')
6350 {
6351 (void) SetImageOption(image_info,option+1,"undefined");
6352 break;
6353 }
6354 (void) SetImageOption(image_info,option+1,argv[i+1]);
6355 break;
6356 }
cristy3ed852e2009-09-05 21:47:34 +00006357 if (LocaleCompare("display",option+1) == 0)
6358 {
6359 if (*option == '+')
6360 {
6361 if (image_info->server_name != (char *) NULL)
6362 image_info->server_name=DestroyString(
6363 image_info->server_name);
6364 break;
6365 }
6366 (void) CloneString(&image_info->server_name,argv[i+1]);
6367 break;
6368 }
6369 if (LocaleCompare("dispose",option+1) == 0)
6370 {
6371 if (*option == '+')
6372 {
6373 (void) SetImageOption(image_info,option+1,"undefined");
6374 break;
6375 }
6376 (void) SetImageOption(image_info,option+1,argv[i+1]);
6377 break;
6378 }
6379 if (LocaleCompare("dither",option+1) == 0)
6380 {
6381 if (*option == '+')
6382 {
6383 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006384 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006385 break;
6386 }
6387 (void) SetImageOption(image_info,option+1,argv[i+1]);
6388 image_info->dither=MagickTrue;
6389 break;
6390 }
6391 break;
6392 }
6393 case 'e':
6394 {
6395 if (LocaleCompare("encoding",option+1) == 0)
6396 {
6397 if (*option == '+')
6398 {
6399 (void) SetImageOption(image_info,option+1,"undefined");
6400 break;
6401 }
6402 (void) SetImageOption(image_info,option+1,argv[i+1]);
6403 break;
6404 }
6405 if (LocaleCompare("endian",option+1) == 0)
6406 {
6407 if (*option == '+')
6408 {
6409 image_info->endian=UndefinedEndian;
6410 (void) SetImageOption(image_info,option+1,"undefined");
6411 break;
6412 }
cristy042ee782011-04-22 18:48:30 +00006413 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006414 MagickEndianOptions,MagickFalse,argv[i+1]);
6415 (void) SetImageOption(image_info,option+1,argv[i+1]);
6416 break;
6417 }
6418 if (LocaleCompare("extract",option+1) == 0)
6419 {
6420 /*
6421 Set image extract geometry.
6422 */
6423 if (*option == '+')
6424 {
6425 if (image_info->extract != (char *) NULL)
6426 image_info->extract=DestroyString(image_info->extract);
6427 break;
6428 }
6429 (void) CloneString(&image_info->extract,argv[i+1]);
6430 break;
6431 }
6432 break;
6433 }
6434 case 'f':
6435 {
6436 if (LocaleCompare("fill",option+1) == 0)
6437 {
6438 if (*option == '+')
6439 {
6440 (void) SetImageOption(image_info,option+1,"none");
6441 break;
6442 }
6443 (void) SetImageOption(image_info,option+1,argv[i+1]);
6444 break;
6445 }
6446 if (LocaleCompare("filter",option+1) == 0)
6447 {
6448 if (*option == '+')
6449 {
6450 (void) SetImageOption(image_info,option+1,"undefined");
6451 break;
6452 }
6453 (void) SetImageOption(image_info,option+1,argv[i+1]);
6454 break;
6455 }
6456 if (LocaleCompare("font",option+1) == 0)
6457 {
6458 if (*option == '+')
6459 {
6460 if (image_info->font != (char *) NULL)
6461 image_info->font=DestroyString(image_info->font);
6462 break;
6463 }
6464 (void) CloneString(&image_info->font,argv[i+1]);
6465 break;
6466 }
6467 if (LocaleCompare("format",option+1) == 0)
6468 {
6469 register const char
6470 *q;
6471
6472 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006473 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006474 image_info->ping=MagickFalse;
6475 (void) SetImageOption(image_info,option+1,argv[i+1]);
6476 break;
6477 }
6478 if (LocaleCompare("fuzz",option+1) == 0)
6479 {
6480 if (*option == '+')
6481 {
6482 image_info->fuzz=0.0;
6483 (void) SetImageOption(image_info,option+1,"0");
6484 break;
6485 }
cristyf2f27272009-12-17 14:48:46 +00006486 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006487 1.0);
6488 (void) SetImageOption(image_info,option+1,argv[i+1]);
6489 break;
6490 }
6491 break;
6492 }
6493 case 'g':
6494 {
6495 if (LocaleCompare("gravity",option+1) == 0)
6496 {
6497 if (*option == '+')
6498 {
6499 (void) SetImageOption(image_info,option+1,"undefined");
6500 break;
6501 }
6502 (void) SetImageOption(image_info,option+1,argv[i+1]);
6503 break;
6504 }
6505 if (LocaleCompare("green-primary",option+1) == 0)
6506 {
6507 if (*option == '+')
6508 {
6509 (void) SetImageOption(image_info,option+1,"0.0");
6510 break;
6511 }
6512 (void) SetImageOption(image_info,option+1,argv[i+1]);
6513 break;
6514 }
6515 break;
6516 }
6517 case 'i':
6518 {
6519 if (LocaleCompare("intent",option+1) == 0)
6520 {
6521 if (*option == '+')
6522 {
6523 (void) SetImageOption(image_info,option+1,"undefined");
6524 break;
6525 }
6526 (void) SetImageOption(image_info,option+1,argv[i+1]);
6527 break;
6528 }
6529 if (LocaleCompare("interlace",option+1) == 0)
6530 {
6531 if (*option == '+')
6532 {
6533 image_info->interlace=UndefinedInterlace;
6534 (void) SetImageOption(image_info,option+1,"undefined");
6535 break;
6536 }
cristy042ee782011-04-22 18:48:30 +00006537 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006538 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6539 (void) SetImageOption(image_info,option+1,argv[i+1]);
6540 break;
6541 }
cristyb32b90a2009-09-07 21:45:48 +00006542 if (LocaleCompare("interline-spacing",option+1) == 0)
6543 {
6544 if (*option == '+')
6545 {
6546 (void) SetImageOption(image_info,option+1,"undefined");
6547 break;
6548 }
6549 (void) SetImageOption(image_info,option+1,argv[i+1]);
6550 break;
6551 }
cristy3ed852e2009-09-05 21:47:34 +00006552 if (LocaleCompare("interpolate",option+1) == 0)
6553 {
6554 if (*option == '+')
6555 {
6556 (void) SetImageOption(image_info,option+1,"undefined");
6557 break;
6558 }
6559 (void) SetImageOption(image_info,option+1,argv[i+1]);
6560 break;
6561 }
6562 if (LocaleCompare("interword-spacing",option+1) == 0)
6563 {
6564 if (*option == '+')
6565 {
6566 (void) SetImageOption(image_info,option+1,"undefined");
6567 break;
6568 }
6569 (void) SetImageOption(image_info,option+1,argv[i+1]);
6570 break;
6571 }
6572 break;
6573 }
6574 case 'k':
6575 {
6576 if (LocaleCompare("kerning",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 'l':
6589 {
6590 if (LocaleCompare("label",option+1) == 0)
6591 {
6592 if (*option == '+')
6593 {
6594 (void) DeleteImageOption(image_info,option+1);
6595 break;
6596 }
6597 (void) SetImageOption(image_info,option+1,argv[i+1]);
6598 break;
6599 }
6600 if (LocaleCompare("limit",option+1) == 0)
6601 {
6602 MagickSizeType
6603 limit;
6604
6605 ResourceType
6606 type;
6607
6608 if (*option == '+')
6609 break;
cristy042ee782011-04-22 18:48:30 +00006610 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006611 MagickFalse,argv[i+1]);
6612 limit=MagickResourceInfinity;
6613 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006614 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006615 (void) SetMagickResourceLimit(type,limit);
6616 break;
6617 }
6618 if (LocaleCompare("list",option+1) == 0)
6619 {
cristybb503372010-05-27 20:51:26 +00006620 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006621 list;
6622
6623 /*
6624 Display configuration list.
6625 */
cristy042ee782011-04-22 18:48:30 +00006626 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006627 switch (list)
6628 {
6629 case MagickCoderOptions:
6630 {
6631 (void) ListCoderInfo((FILE *) NULL,exception);
6632 break;
6633 }
6634 case MagickColorOptions:
6635 {
6636 (void) ListColorInfo((FILE *) NULL,exception);
6637 break;
6638 }
6639 case MagickConfigureOptions:
6640 {
6641 (void) ListConfigureInfo((FILE *) NULL,exception);
6642 break;
6643 }
6644 case MagickDelegateOptions:
6645 {
6646 (void) ListDelegateInfo((FILE *) NULL,exception);
6647 break;
6648 }
6649 case MagickFontOptions:
6650 {
6651 (void) ListTypeInfo((FILE *) NULL,exception);
6652 break;
6653 }
6654 case MagickFormatOptions:
6655 {
6656 (void) ListMagickInfo((FILE *) NULL,exception);
6657 break;
6658 }
6659 case MagickLocaleOptions:
6660 {
6661 (void) ListLocaleInfo((FILE *) NULL,exception);
6662 break;
6663 }
6664 case MagickLogOptions:
6665 {
6666 (void) ListLogInfo((FILE *) NULL,exception);
6667 break;
6668 }
6669 case MagickMagicOptions:
6670 {
6671 (void) ListMagicInfo((FILE *) NULL,exception);
6672 break;
6673 }
6674 case MagickMimeOptions:
6675 {
6676 (void) ListMimeInfo((FILE *) NULL,exception);
6677 break;
6678 }
6679 case MagickModuleOptions:
6680 {
6681 (void) ListModuleInfo((FILE *) NULL,exception);
6682 break;
6683 }
6684 case MagickPolicyOptions:
6685 {
6686 (void) ListPolicyInfo((FILE *) NULL,exception);
6687 break;
6688 }
6689 case MagickResourceOptions:
6690 {
6691 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6692 break;
6693 }
6694 case MagickThresholdOptions:
6695 {
6696 (void) ListThresholdMaps((FILE *) NULL,exception);
6697 break;
6698 }
6699 default:
6700 {
cristy042ee782011-04-22 18:48:30 +00006701 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006702 exception);
6703 break;
6704 }
6705 }
cristyaeb2cbc2010-05-07 13:28:58 +00006706 break;
cristy3ed852e2009-09-05 21:47:34 +00006707 }
6708 if (LocaleCompare("log",option+1) == 0)
6709 {
6710 if (*option == '+')
6711 break;
6712 (void) SetLogFormat(argv[i+1]);
6713 break;
6714 }
6715 if (LocaleCompare("loop",option+1) == 0)
6716 {
6717 if (*option == '+')
6718 {
6719 (void) SetImageOption(image_info,option+1,"0");
6720 break;
6721 }
6722 (void) SetImageOption(image_info,option+1,argv[i+1]);
6723 break;
6724 }
6725 break;
6726 }
6727 case 'm':
6728 {
6729 if (LocaleCompare("matte",option+1) == 0)
6730 {
6731 if (*option == '+')
6732 {
6733 (void) SetImageOption(image_info,option+1,"false");
6734 break;
6735 }
6736 (void) SetImageOption(image_info,option+1,"true");
6737 break;
6738 }
6739 if (LocaleCompare("mattecolor",option+1) == 0)
6740 {
6741 if (*option == '+')
6742 {
6743 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006744 (void) QueryColorDatabase(MogrifyMatteColor,
6745 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006746 break;
6747 }
6748 (void) SetImageOption(image_info,option+1,argv[i+1]);
6749 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6750 exception);
6751 break;
6752 }
6753 if (LocaleCompare("monitor",option+1) == 0)
6754 {
6755 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6756 (void *) NULL);
6757 break;
6758 }
6759 if (LocaleCompare("monochrome",option+1) == 0)
6760 {
6761 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6762 break;
6763 }
6764 break;
6765 }
6766 case 'o':
6767 {
6768 if (LocaleCompare("orient",option+1) == 0)
6769 {
6770 if (*option == '+')
6771 {
6772 image_info->orientation=UndefinedOrientation;
6773 (void) SetImageOption(image_info,option+1,"undefined");
6774 break;
6775 }
cristy042ee782011-04-22 18:48:30 +00006776 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006777 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006778 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006779 break;
6780 }
6781 }
6782 case 'p':
6783 {
6784 if (LocaleCompare("page",option+1) == 0)
6785 {
6786 char
6787 *canonical_page,
6788 page[MaxTextExtent];
6789
6790 const char
6791 *image_option;
6792
6793 MagickStatusType
6794 flags;
6795
6796 RectangleInfo
6797 geometry;
6798
6799 if (*option == '+')
6800 {
6801 (void) DeleteImageOption(image_info,option+1);
6802 (void) CloneString(&image_info->page,(char *) NULL);
6803 break;
6804 }
6805 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6806 image_option=GetImageOption(image_info,"page");
6807 if (image_option != (const char *) NULL)
6808 flags=ParseAbsoluteGeometry(image_option,&geometry);
6809 canonical_page=GetPageGeometry(argv[i+1]);
6810 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6811 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006812 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006813 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006814 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006815 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006816 (unsigned long) geometry.width,(unsigned long) geometry.height,
6817 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006818 (void) SetImageOption(image_info,option+1,page);
6819 (void) CloneString(&image_info->page,page);
6820 break;
6821 }
6822 if (LocaleCompare("pen",option+1) == 0)
6823 {
6824 if (*option == '+')
6825 {
6826 (void) SetImageOption(image_info,option+1,"none");
6827 break;
6828 }
6829 (void) SetImageOption(image_info,option+1,argv[i+1]);
6830 break;
6831 }
6832 if (LocaleCompare("ping",option+1) == 0)
6833 {
6834 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6835 break;
6836 }
6837 if (LocaleCompare("pointsize",option+1) == 0)
6838 {
6839 if (*option == '+')
6840 geometry_info.rho=0.0;
6841 else
6842 (void) ParseGeometry(argv[i+1],&geometry_info);
6843 image_info->pointsize=geometry_info.rho;
6844 break;
6845 }
cristye7f51092010-01-17 00:39:37 +00006846 if (LocaleCompare("precision",option+1) == 0)
6847 {
cristybf2766a2010-01-17 03:33:23 +00006848 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006849 break;
6850 }
cristy3ed852e2009-09-05 21:47:34 +00006851 if (LocaleCompare("preview",option+1) == 0)
6852 {
6853 /*
6854 Preview image.
6855 */
6856 if (*option == '+')
6857 {
6858 image_info->preview_type=UndefinedPreview;
6859 break;
6860 }
cristy042ee782011-04-22 18:48:30 +00006861 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006862 MagickPreviewOptions,MagickFalse,argv[i+1]);
6863 break;
6864 }
6865 break;
6866 }
6867 case 'q':
6868 {
6869 if (LocaleCompare("quality",option+1) == 0)
6870 {
6871 /*
6872 Set image compression quality.
6873 */
6874 if (*option == '+')
6875 {
6876 image_info->quality=UndefinedCompressionQuality;
6877 (void) SetImageOption(image_info,option+1,"0");
6878 break;
6879 }
cristye27293e2009-12-18 02:53:20 +00006880 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006881 (void) SetImageOption(image_info,option+1,argv[i+1]);
6882 break;
6883 }
6884 if (LocaleCompare("quiet",option+1) == 0)
6885 {
6886 static WarningHandler
6887 warning_handler = (WarningHandler) NULL;
6888
6889 if (*option == '+')
6890 {
6891 /*
6892 Restore error or warning messages.
6893 */
6894 warning_handler=SetWarningHandler(warning_handler);
6895 break;
6896 }
6897 /*
6898 Suppress error or warning messages.
6899 */
6900 warning_handler=SetWarningHandler((WarningHandler) NULL);
6901 break;
6902 }
6903 break;
6904 }
6905 case 'r':
6906 {
6907 if (LocaleCompare("red-primary",option+1) == 0)
6908 {
6909 if (*option == '+')
6910 {
6911 (void) SetImageOption(image_info,option+1,"0.0");
6912 break;
6913 }
6914 (void) SetImageOption(image_info,option+1,argv[i+1]);
6915 break;
6916 }
6917 break;
6918 }
6919 case 's':
6920 {
6921 if (LocaleCompare("sampling-factor",option+1) == 0)
6922 {
6923 /*
6924 Set image sampling factor.
6925 */
6926 if (*option == '+')
6927 {
6928 if (image_info->sampling_factor != (char *) NULL)
6929 image_info->sampling_factor=DestroyString(
6930 image_info->sampling_factor);
6931 break;
6932 }
6933 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6934 break;
6935 }
6936 if (LocaleCompare("scene",option+1) == 0)
6937 {
6938 /*
6939 Set image scene.
6940 */
6941 if (*option == '+')
6942 {
6943 image_info->scene=0;
6944 (void) SetImageOption(image_info,option+1,"0");
6945 break;
6946 }
cristye27293e2009-12-18 02:53:20 +00006947 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006948 (void) SetImageOption(image_info,option+1,argv[i+1]);
6949 break;
6950 }
6951 if (LocaleCompare("seed",option+1) == 0)
6952 {
cristybb503372010-05-27 20:51:26 +00006953 size_t
cristy3ed852e2009-09-05 21:47:34 +00006954 seed;
6955
6956 if (*option == '+')
6957 {
cristybb503372010-05-27 20:51:26 +00006958 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006959 SeedPseudoRandomGenerator(seed);
6960 break;
6961 }
cristye27293e2009-12-18 02:53:20 +00006962 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006963 SeedPseudoRandomGenerator(seed);
6964 break;
6965 }
6966 if (LocaleCompare("size",option+1) == 0)
6967 {
6968 if (*option == '+')
6969 {
6970 if (image_info->size != (char *) NULL)
6971 image_info->size=DestroyString(image_info->size);
6972 break;
6973 }
6974 (void) CloneString(&image_info->size,argv[i+1]);
6975 break;
6976 }
6977 if (LocaleCompare("stroke",option+1) == 0)
6978 {
6979 if (*option == '+')
6980 {
6981 (void) SetImageOption(image_info,option+1,"none");
6982 break;
6983 }
6984 (void) SetImageOption(image_info,option+1,argv[i+1]);
6985 break;
6986 }
6987 if (LocaleCompare("strokewidth",option+1) == 0)
6988 {
6989 if (*option == '+')
6990 {
6991 (void) SetImageOption(image_info,option+1,"0");
6992 break;
6993 }
6994 (void) SetImageOption(image_info,option+1,argv[i+1]);
6995 break;
6996 }
cristyd9a29192010-10-16 16:49:53 +00006997 if (LocaleCompare("synchronize",option+1) == 0)
6998 {
6999 if (*option == '+')
7000 {
7001 image_info->synchronize=MagickFalse;
7002 break;
7003 }
7004 image_info->synchronize=MagickTrue;
7005 break;
7006 }
cristy3ed852e2009-09-05 21:47:34 +00007007 break;
7008 }
7009 case 't':
7010 {
7011 if (LocaleCompare("taint",option+1) == 0)
7012 {
7013 if (*option == '+')
7014 {
7015 (void) SetImageOption(image_info,option+1,"false");
7016 break;
7017 }
7018 (void) SetImageOption(image_info,option+1,"true");
7019 break;
7020 }
7021 if (LocaleCompare("texture",option+1) == 0)
7022 {
7023 if (*option == '+')
7024 {
7025 if (image_info->texture != (char *) NULL)
7026 image_info->texture=DestroyString(image_info->texture);
7027 break;
7028 }
7029 (void) CloneString(&image_info->texture,argv[i+1]);
7030 break;
7031 }
7032 if (LocaleCompare("tile-offset",option+1) == 0)
7033 {
7034 if (*option == '+')
7035 {
7036 (void) SetImageOption(image_info,option+1,"0");
7037 break;
7038 }
7039 (void) SetImageOption(image_info,option+1,argv[i+1]);
7040 break;
7041 }
7042 if (LocaleCompare("transparent-color",option+1) == 0)
7043 {
7044 if (*option == '+')
7045 {
7046 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7047 (void) SetImageOption(image_info,option+1,"none");
7048 break;
7049 }
7050 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7051 exception);
7052 (void) SetImageOption(image_info,option+1,argv[i+1]);
7053 break;
7054 }
7055 if (LocaleCompare("type",option+1) == 0)
7056 {
7057 if (*option == '+')
7058 {
cristy5f1c1ff2010-12-23 21:38:06 +00007059 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007060 (void) SetImageOption(image_info,option+1,"undefined");
7061 break;
7062 }
cristy042ee782011-04-22 18:48:30 +00007063 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007064 MagickFalse,argv[i+1]);
7065 (void) SetImageOption(image_info,option+1,argv[i+1]);
7066 break;
7067 }
7068 break;
7069 }
7070 case 'u':
7071 {
7072 if (LocaleCompare("undercolor",option+1) == 0)
7073 {
7074 if (*option == '+')
7075 {
7076 (void) DeleteImageOption(image_info,option+1);
7077 break;
7078 }
7079 (void) SetImageOption(image_info,option+1,argv[i+1]);
7080 break;
7081 }
7082 if (LocaleCompare("units",option+1) == 0)
7083 {
7084 if (*option == '+')
7085 {
7086 image_info->units=UndefinedResolution;
7087 (void) SetImageOption(image_info,option+1,"undefined");
7088 break;
7089 }
cristy042ee782011-04-22 18:48:30 +00007090 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007091 MagickResolutionOptions,MagickFalse,argv[i+1]);
7092 (void) SetImageOption(image_info,option+1,argv[i+1]);
7093 break;
7094 }
7095 break;
7096 }
7097 case 'v':
7098 {
7099 if (LocaleCompare("verbose",option+1) == 0)
7100 {
7101 if (*option == '+')
7102 {
7103 image_info->verbose=MagickFalse;
7104 break;
7105 }
7106 image_info->verbose=MagickTrue;
7107 image_info->ping=MagickFalse;
7108 break;
7109 }
7110 if (LocaleCompare("view",option+1) == 0)
7111 {
7112 if (*option == '+')
7113 {
7114 if (image_info->view != (char *) NULL)
7115 image_info->view=DestroyString(image_info->view);
7116 break;
7117 }
7118 (void) CloneString(&image_info->view,argv[i+1]);
7119 break;
7120 }
7121 if (LocaleCompare("virtual-pixel",option+1) == 0)
7122 {
7123 if (*option == '+')
7124 {
7125 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7126 (void) SetImageOption(image_info,option+1,"undefined");
7127 break;
7128 }
7129 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007130 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007131 argv[i+1]);
7132 (void) SetImageOption(image_info,option+1,argv[i+1]);
7133 break;
7134 }
7135 break;
7136 }
7137 case 'w':
7138 {
7139 if (LocaleCompare("white-point",option+1) == 0)
7140 {
7141 if (*option == '+')
7142 {
7143 (void) SetImageOption(image_info,option+1,"0.0");
7144 break;
7145 }
7146 (void) SetImageOption(image_info,option+1,argv[i+1]);
7147 break;
7148 }
7149 break;
7150 }
7151 default:
7152 break;
7153 }
7154 i+=count;
7155 }
7156 return(MagickTrue);
7157}
7158
7159/*
7160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7161% %
7162% %
7163% %
7164+ M o g r i f y I m a g e L i s t %
7165% %
7166% %
7167% %
7168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7169%
7170% MogrifyImageList() applies any command line options that might affect the
7171% entire image list (e.g. -append, -coalesce, etc.).
7172%
7173% The format of the MogrifyImage method is:
7174%
7175% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7176% const char **argv,Image **images,ExceptionInfo *exception)
7177%
7178% A description of each parameter follows:
7179%
7180% o image_info: the image info..
7181%
7182% o argc: Specifies a pointer to an integer describing the number of
7183% elements in the argument vector.
7184%
7185% o argv: Specifies a pointer to a text array containing the command line
7186% arguments.
7187%
anthonye9c27192011-03-27 08:07:06 +00007188% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007189%
7190% o exception: return any errors or warnings in this structure.
7191%
7192*/
7193WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7194 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7195{
cristy3ed852e2009-09-05 21:47:34 +00007196 const char
7197 *option;
7198
cristy6b3da3a2010-06-20 02:21:46 +00007199 ImageInfo
7200 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007201
7202 MagickStatusType
7203 status;
7204
7205 QuantizeInfo
7206 *quantize_info;
7207
cristybb503372010-05-27 20:51:26 +00007208 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007209 i;
7210
cristy6b3da3a2010-06-20 02:21:46 +00007211 ssize_t
7212 count,
7213 index;
7214
cristy3ed852e2009-09-05 21:47:34 +00007215 /*
7216 Apply options to the image list.
7217 */
7218 assert(image_info != (ImageInfo *) NULL);
7219 assert(image_info->signature == MagickSignature);
7220 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007221 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007222 assert((*images)->signature == MagickSignature);
7223 if ((*images)->debug != MagickFalse)
7224 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7225 (*images)->filename);
7226 if ((argc <= 0) || (*argv == (char *) NULL))
7227 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007228 mogrify_info=CloneImageInfo(image_info);
7229 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007230 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007231 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007232 {
cristy74fe8f12009-10-03 19:09:01 +00007233 if (*images == (Image *) NULL)
7234 break;
cristy3ed852e2009-09-05 21:47:34 +00007235 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007236 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007237 continue;
cristy042ee782011-04-22 18:48:30 +00007238 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007239 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007240 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007241 break;
cristy6b3da3a2010-06-20 02:21:46 +00007242 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007243 switch (*(option+1))
7244 {
7245 case 'a':
7246 {
7247 if (LocaleCompare("affinity",option+1) == 0)
7248 {
cristy6b3da3a2010-06-20 02:21:46 +00007249 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007250 if (*option == '+')
7251 {
cristy018f07f2011-09-04 21:15:19 +00007252 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7253 exception);
cristy3ed852e2009-09-05 21:47:34 +00007254 break;
7255 }
7256 i++;
7257 break;
7258 }
7259 if (LocaleCompare("append",option+1) == 0)
7260 {
7261 Image
7262 *append_image;
7263
cristy6b3da3a2010-06-20 02:21:46 +00007264 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007265 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7266 MagickFalse,exception);
7267 if (append_image == (Image *) NULL)
7268 {
7269 status=MagickFalse;
7270 break;
7271 }
7272 *images=DestroyImageList(*images);
7273 *images=append_image;
7274 break;
7275 }
7276 if (LocaleCompare("average",option+1) == 0)
7277 {
7278 Image
7279 *average_image;
7280
cristyd18ae7c2010-03-07 17:39:52 +00007281 /*
7282 Average an image sequence (deprecated).
7283 */
cristy6b3da3a2010-06-20 02:21:46 +00007284 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007285 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7286 exception);
cristy3ed852e2009-09-05 21:47:34 +00007287 if (average_image == (Image *) NULL)
7288 {
7289 status=MagickFalse;
7290 break;
7291 }
7292 *images=DestroyImageList(*images);
7293 *images=average_image;
7294 break;
7295 }
7296 break;
7297 }
7298 case 'c':
7299 {
7300 if (LocaleCompare("channel",option+1) == 0)
7301 {
cristyf4ad9df2011-07-08 16:49:03 +00007302 ChannelType
7303 channel;
7304
cristy3ed852e2009-09-05 21:47:34 +00007305 if (*option == '+')
7306 {
7307 channel=DefaultChannels;
7308 break;
7309 }
7310 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007311 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007312 break;
7313 }
7314 if (LocaleCompare("clut",option+1) == 0)
7315 {
7316 Image
7317 *clut_image,
7318 *image;
7319
cristy6b3da3a2010-06-20 02:21:46 +00007320 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007321 image=RemoveFirstImageFromList(images);
7322 clut_image=RemoveFirstImageFromList(images);
7323 if (clut_image == (Image *) NULL)
7324 {
7325 status=MagickFalse;
7326 break;
7327 }
cristy444eda62011-08-10 02:07:46 +00007328 (void) ClutImage(image,clut_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007329 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007330 *images=DestroyImageList(*images);
7331 *images=image;
7332 break;
7333 }
7334 if (LocaleCompare("coalesce",option+1) == 0)
7335 {
7336 Image
7337 *coalesce_image;
7338
cristy6b3da3a2010-06-20 02:21:46 +00007339 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007340 coalesce_image=CoalesceImages(*images,exception);
7341 if (coalesce_image == (Image *) NULL)
7342 {
7343 status=MagickFalse;
7344 break;
7345 }
7346 *images=DestroyImageList(*images);
7347 *images=coalesce_image;
7348 break;
7349 }
7350 if (LocaleCompare("combine",option+1) == 0)
7351 {
7352 Image
7353 *combine_image;
7354
cristy6b3da3a2010-06-20 02:21:46 +00007355 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007356 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007357 if (combine_image == (Image *) NULL)
7358 {
7359 status=MagickFalse;
7360 break;
7361 }
7362 *images=DestroyImageList(*images);
7363 *images=combine_image;
7364 break;
7365 }
7366 if (LocaleCompare("composite",option+1) == 0)
7367 {
7368 Image
7369 *mask_image,
7370 *composite_image,
7371 *image;
7372
7373 RectangleInfo
7374 geometry;
7375
cristy6b3da3a2010-06-20 02:21:46 +00007376 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007377 image=RemoveFirstImageFromList(images);
7378 composite_image=RemoveFirstImageFromList(images);
7379 if (composite_image == (Image *) NULL)
7380 {
7381 status=MagickFalse;
7382 break;
7383 }
7384 (void) TransformImage(&composite_image,(char *) NULL,
7385 composite_image->geometry);
7386 SetGeometry(composite_image,&geometry);
7387 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7388 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7389 &geometry);
7390 mask_image=RemoveFirstImageFromList(images);
7391 if (mask_image != (Image *) NULL)
7392 {
7393 if ((image->compose == DisplaceCompositeOp) ||
7394 (image->compose == DistortCompositeOp))
7395 {
7396 /*
7397 Merge Y displacement into X displacement image.
7398 */
7399 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7400 mask_image,0,0);
7401 mask_image=DestroyImage(mask_image);
7402 }
7403 else
7404 {
7405 /*
7406 Set a blending mask for the composition.
7407 */
anthonya129f702011-04-14 01:08:48 +00007408 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007409 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007410 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007411 }
7412 }
cristyf4ad9df2011-07-08 16:49:03 +00007413 (void) CompositeImage(image,image->compose,composite_image,
7414 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007415 if (mask_image != (Image *) NULL)
7416 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007417 composite_image=DestroyImage(composite_image);
7418 InheritException(exception,&image->exception);
7419 *images=DestroyImageList(*images);
7420 *images=image;
7421 break;
7422 }
anthony9f4f0342011-03-28 11:47:22 +00007423#if 0
7424This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007425 if (LocaleCompare("crop",option+1) == 0)
7426 {
7427 MagickStatusType
7428 flags;
7429
7430 RectangleInfo
7431 geometry;
7432
anthonye9c27192011-03-27 08:07:06 +00007433 /*
anthony9f4f0342011-03-28 11:47:22 +00007434 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007435 */
cristy6b3da3a2010-06-20 02:21:46 +00007436 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007437 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7438 if (((geometry.width == 0) && (geometry.height == 0)) ||
7439 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7440 break;
7441 (void) TransformImages(images,argv[i+1],(char *) NULL);
7442 InheritException(exception,&(*images)->exception);
7443 break;
7444 }
anthony9f4f0342011-03-28 11:47:22 +00007445#endif
cristy3ed852e2009-09-05 21:47:34 +00007446 break;
7447 }
7448 case 'd':
7449 {
7450 if (LocaleCompare("deconstruct",option+1) == 0)
7451 {
7452 Image
7453 *deconstruct_image;
7454
cristy6b3da3a2010-06-20 02:21:46 +00007455 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007456 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007457 exception);
cristy3ed852e2009-09-05 21:47:34 +00007458 if (deconstruct_image == (Image *) NULL)
7459 {
7460 status=MagickFalse;
7461 break;
7462 }
7463 *images=DestroyImageList(*images);
7464 *images=deconstruct_image;
7465 break;
7466 }
7467 if (LocaleCompare("delete",option+1) == 0)
7468 {
7469 if (*option == '+')
7470 DeleteImages(images,"-1",exception);
7471 else
7472 DeleteImages(images,argv[i+1],exception);
7473 break;
7474 }
7475 if (LocaleCompare("dither",option+1) == 0)
7476 {
7477 if (*option == '+')
7478 {
7479 quantize_info->dither=MagickFalse;
7480 break;
7481 }
7482 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007483 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007484 MagickDitherOptions,MagickFalse,argv[i+1]);
7485 break;
7486 }
cristyecb10ff2011-03-22 13:14:03 +00007487 if (LocaleCompare("duplicate",option+1) == 0)
7488 {
cristy72988482011-03-29 16:34:38 +00007489 Image
7490 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007491
anthony2b6bcae2011-03-23 13:05:34 +00007492 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007493 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7494 else
7495 {
7496 const char
7497 *p;
7498
anthony2b6bcae2011-03-23 13:05:34 +00007499 size_t
7500 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007501
anthony2b6bcae2011-03-23 13:05:34 +00007502 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007503 p=strchr(argv[i+1],',');
7504 if (p == (const char *) NULL)
7505 duplicate_images=DuplicateImages(*images,number_duplicates,
7506 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007507 else
cristy72988482011-03-29 16:34:38 +00007508 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7509 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007510 }
7511 AppendImageToList(images, duplicate_images);
7512 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007513 break;
7514 }
cristy3ed852e2009-09-05 21:47:34 +00007515 break;
7516 }
cristyd18ae7c2010-03-07 17:39:52 +00007517 case 'e':
7518 {
7519 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7520 {
7521 Image
7522 *evaluate_image;
7523
7524 MagickEvaluateOperator
7525 op;
7526
cristy6b3da3a2010-06-20 02:21:46 +00007527 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007528 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007529 MagickFalse,argv[i+1]);
7530 evaluate_image=EvaluateImages(*images,op,exception);
7531 if (evaluate_image == (Image *) NULL)
7532 {
7533 status=MagickFalse;
7534 break;
7535 }
7536 *images=DestroyImageList(*images);
7537 *images=evaluate_image;
7538 break;
7539 }
7540 break;
7541 }
cristy3ed852e2009-09-05 21:47:34 +00007542 case 'f':
7543 {
cristyf0a247f2009-10-04 00:20:03 +00007544 if (LocaleCompare("fft",option+1) == 0)
7545 {
7546 Image
7547 *fourier_image;
7548
7549 /*
7550 Implements the discrete Fourier transform (DFT).
7551 */
cristy6b3da3a2010-06-20 02:21:46 +00007552 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007553 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7554 MagickTrue : MagickFalse,exception);
7555 if (fourier_image == (Image *) NULL)
7556 break;
7557 *images=DestroyImage(*images);
7558 *images=fourier_image;
7559 break;
7560 }
cristy3ed852e2009-09-05 21:47:34 +00007561 if (LocaleCompare("flatten",option+1) == 0)
7562 {
7563 Image
7564 *flatten_image;
7565
cristy6b3da3a2010-06-20 02:21:46 +00007566 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007567 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7568 if (flatten_image == (Image *) NULL)
7569 break;
7570 *images=DestroyImageList(*images);
7571 *images=flatten_image;
7572 break;
7573 }
7574 if (LocaleCompare("fx",option+1) == 0)
7575 {
7576 Image
7577 *fx_image;
7578
cristy6b3da3a2010-06-20 02:21:46 +00007579 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007580 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007581 if (fx_image == (Image *) NULL)
7582 {
7583 status=MagickFalse;
7584 break;
7585 }
7586 *images=DestroyImageList(*images);
7587 *images=fx_image;
7588 break;
7589 }
7590 break;
7591 }
7592 case 'h':
7593 {
7594 if (LocaleCompare("hald-clut",option+1) == 0)
7595 {
7596 Image
7597 *hald_image,
7598 *image;
7599
cristy6b3da3a2010-06-20 02:21:46 +00007600 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007601 image=RemoveFirstImageFromList(images);
7602 hald_image=RemoveFirstImageFromList(images);
7603 if (hald_image == (Image *) NULL)
7604 {
7605 status=MagickFalse;
7606 break;
7607 }
cristy7c0a0a42011-08-23 17:57:25 +00007608 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007609 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007610 if (*images != (Image *) NULL)
7611 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007612 *images=image;
7613 break;
7614 }
7615 break;
7616 }
7617 case 'i':
7618 {
7619 if (LocaleCompare("ift",option+1) == 0)
7620 {
7621 Image
cristy8587f882009-11-13 20:28:49 +00007622 *fourier_image,
7623 *magnitude_image,
7624 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007625
7626 /*
7627 Implements the inverse fourier discrete Fourier transform (DFT).
7628 */
cristy6b3da3a2010-06-20 02:21:46 +00007629 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007630 magnitude_image=RemoveFirstImageFromList(images);
7631 phase_image=RemoveFirstImageFromList(images);
7632 if (phase_image == (Image *) NULL)
7633 {
7634 status=MagickFalse;
7635 break;
7636 }
7637 fourier_image=InverseFourierTransformImage(magnitude_image,
7638 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007639 if (fourier_image == (Image *) NULL)
7640 break;
cristy0aff6ea2009-11-14 01:40:53 +00007641 if (*images != (Image *) NULL)
7642 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007643 *images=fourier_image;
7644 break;
7645 }
7646 if (LocaleCompare("insert",option+1) == 0)
7647 {
7648 Image
7649 *p,
7650 *q;
7651
7652 index=0;
7653 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007654 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007655 p=RemoveLastImageFromList(images);
7656 if (p == (Image *) NULL)
7657 {
7658 (void) ThrowMagickException(exception,GetMagickModule(),
7659 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7660 status=MagickFalse;
7661 break;
7662 }
7663 q=p;
7664 if (index == 0)
7665 PrependImageToList(images,q);
7666 else
cristybb503372010-05-27 20:51:26 +00007667 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007668 AppendImageToList(images,q);
7669 else
7670 {
7671 q=GetImageFromList(*images,index-1);
7672 if (q == (Image *) NULL)
7673 {
7674 (void) ThrowMagickException(exception,GetMagickModule(),
7675 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7676 status=MagickFalse;
7677 break;
7678 }
7679 InsertImageInList(&q,p);
7680 }
7681 *images=GetFirstImageInList(q);
7682 break;
7683 }
7684 break;
7685 }
7686 case 'l':
7687 {
7688 if (LocaleCompare("layers",option+1) == 0)
7689 {
7690 Image
7691 *layers;
7692
7693 ImageLayerMethod
7694 method;
7695
cristy6b3da3a2010-06-20 02:21:46 +00007696 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007697 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007698 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007699 MagickFalse,argv[i+1]);
7700 switch (method)
7701 {
7702 case CoalesceLayer:
7703 {
7704 layers=CoalesceImages(*images,exception);
7705 break;
7706 }
7707 case CompareAnyLayer:
7708 case CompareClearLayer:
7709 case CompareOverlayLayer:
7710 default:
7711 {
cristy8a9106f2011-07-05 14:39:26 +00007712 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007713 break;
7714 }
7715 case MergeLayer:
7716 case FlattenLayer:
7717 case MosaicLayer:
7718 case TrimBoundsLayer:
7719 {
7720 layers=MergeImageLayers(*images,method,exception);
7721 break;
7722 }
7723 case DisposeLayer:
7724 {
7725 layers=DisposeImages(*images,exception);
7726 break;
7727 }
7728 case OptimizeImageLayer:
7729 {
7730 layers=OptimizeImageLayers(*images,exception);
7731 break;
7732 }
7733 case OptimizePlusLayer:
7734 {
7735 layers=OptimizePlusImageLayers(*images,exception);
7736 break;
7737 }
7738 case OptimizeTransLayer:
7739 {
7740 OptimizeImageTransparency(*images,exception);
7741 break;
7742 }
7743 case RemoveDupsLayer:
7744 {
7745 RemoveDuplicateLayers(images,exception);
7746 break;
7747 }
7748 case RemoveZeroLayer:
7749 {
7750 RemoveZeroDelayLayers(images,exception);
7751 break;
7752 }
7753 case OptimizeLayer:
7754 {
7755 /*
7756 General Purpose, GIF Animation Optimizer.
7757 */
7758 layers=CoalesceImages(*images,exception);
7759 if (layers == (Image *) NULL)
7760 {
7761 status=MagickFalse;
7762 break;
7763 }
cristy3ed852e2009-09-05 21:47:34 +00007764 *images=DestroyImageList(*images);
7765 *images=layers;
7766 layers=OptimizeImageLayers(*images,exception);
7767 if (layers == (Image *) NULL)
7768 {
7769 status=MagickFalse;
7770 break;
7771 }
cristy3ed852e2009-09-05 21:47:34 +00007772 *images=DestroyImageList(*images);
7773 *images=layers;
7774 layers=(Image *) NULL;
7775 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007776 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7777 exception);
cristy3ed852e2009-09-05 21:47:34 +00007778 break;
7779 }
7780 case CompositeLayer:
7781 {
7782 CompositeOperator
7783 compose;
7784
7785 Image
7786 *source;
7787
7788 RectangleInfo
7789 geometry;
7790
7791 /*
7792 Split image sequence at the first 'NULL:' image.
7793 */
7794 source=(*images);
7795 while (source != (Image *) NULL)
7796 {
7797 source=GetNextImageInList(source);
7798 if ((source != (Image *) NULL) &&
7799 (LocaleCompare(source->magick,"NULL") == 0))
7800 break;
7801 }
7802 if (source != (Image *) NULL)
7803 {
7804 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7805 (GetNextImageInList(source) == (Image *) NULL))
7806 source=(Image *) NULL;
7807 else
7808 {
7809 /*
7810 Separate the two lists, junk the null: image.
7811 */
7812 source=SplitImageList(source->previous);
7813 DeleteImageFromList(&source);
7814 }
7815 }
7816 if (source == (Image *) NULL)
7817 {
7818 (void) ThrowMagickException(exception,GetMagickModule(),
7819 OptionError,"MissingNullSeparator","layers Composite");
7820 status=MagickFalse;
7821 break;
7822 }
7823 /*
7824 Adjust offset with gravity and virtual canvas.
7825 */
7826 SetGeometry(*images,&geometry);
7827 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7828 geometry.width=source->page.width != 0 ?
7829 source->page.width : source->columns;
7830 geometry.height=source->page.height != 0 ?
7831 source->page.height : source->rows;
7832 GravityAdjustGeometry((*images)->page.width != 0 ?
7833 (*images)->page.width : (*images)->columns,
7834 (*images)->page.height != 0 ? (*images)->page.height :
7835 (*images)->rows,(*images)->gravity,&geometry);
7836 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007837 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007838 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007839 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007840 MagickComposeOptions,MagickFalse,option);
7841 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7842 exception);
7843 source=DestroyImageList(source);
7844 break;
7845 }
7846 }
7847 if (layers == (Image *) NULL)
7848 break;
7849 InheritException(exception,&layers->exception);
7850 *images=DestroyImageList(*images);
7851 *images=layers;
7852 break;
7853 }
7854 break;
7855 }
7856 case 'm':
7857 {
7858 if (LocaleCompare("map",option+1) == 0)
7859 {
cristy6b3da3a2010-06-20 02:21:46 +00007860 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007861 if (*option == '+')
7862 {
cristy018f07f2011-09-04 21:15:19 +00007863 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7864 exception);
cristy3ed852e2009-09-05 21:47:34 +00007865 break;
7866 }
7867 i++;
7868 break;
7869 }
cristyf40785b2010-03-06 02:27:27 +00007870 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007871 {
7872 Image
cristyf40785b2010-03-06 02:27:27 +00007873 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007874
cristyd18ae7c2010-03-07 17:39:52 +00007875 /*
7876 Maximum image sequence (deprecated).
7877 */
cristy6b3da3a2010-06-20 02:21:46 +00007878 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007879 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007880 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007881 {
7882 status=MagickFalse;
7883 break;
7884 }
7885 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007886 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007887 break;
7888 }
cristyf40785b2010-03-06 02:27:27 +00007889 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007890 {
7891 Image
cristyf40785b2010-03-06 02:27:27 +00007892 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007893
cristyd18ae7c2010-03-07 17:39:52 +00007894 /*
7895 Minimum image sequence (deprecated).
7896 */
cristy6b3da3a2010-06-20 02:21:46 +00007897 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007898 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007899 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007900 {
7901 status=MagickFalse;
7902 break;
7903 }
7904 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007905 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007906 break;
7907 }
cristy3ed852e2009-09-05 21:47:34 +00007908 if (LocaleCompare("morph",option+1) == 0)
7909 {
7910 Image
7911 *morph_image;
7912
cristy6b3da3a2010-06-20 02:21:46 +00007913 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007914 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007915 exception);
7916 if (morph_image == (Image *) NULL)
7917 {
7918 status=MagickFalse;
7919 break;
7920 }
7921 *images=DestroyImageList(*images);
7922 *images=morph_image;
7923 break;
7924 }
7925 if (LocaleCompare("mosaic",option+1) == 0)
7926 {
7927 Image
7928 *mosaic_image;
7929
cristy6b3da3a2010-06-20 02:21:46 +00007930 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007931 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7932 if (mosaic_image == (Image *) NULL)
7933 {
7934 status=MagickFalse;
7935 break;
7936 }
7937 *images=DestroyImageList(*images);
7938 *images=mosaic_image;
7939 break;
7940 }
7941 break;
7942 }
7943 case 'p':
7944 {
7945 if (LocaleCompare("print",option+1) == 0)
7946 {
7947 char
7948 *string;
7949
cristy6b3da3a2010-06-20 02:21:46 +00007950 (void) SyncImagesSettings(mogrify_info,*images);
cristy018f07f2011-09-04 21:15:19 +00007951 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7952 exception);
cristy3ed852e2009-09-05 21:47:34 +00007953 if (string == (char *) NULL)
7954 break;
cristyb51dff52011-05-19 16:55:47 +00007955 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007956 string=DestroyString(string);
7957 }
7958 if (LocaleCompare("process",option+1) == 0)
7959 {
7960 char
7961 **arguments;
7962
7963 int
7964 j,
7965 number_arguments;
7966
cristy6b3da3a2010-06-20 02:21:46 +00007967 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007968 arguments=StringToArgv(argv[i+1],&number_arguments);
7969 if (arguments == (char **) NULL)
7970 break;
7971 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7972 {
7973 char
7974 breaker,
7975 quote,
7976 *token;
7977
7978 const char
7979 *arguments;
7980
7981 int
7982 next,
7983 status;
7984
7985 size_t
7986 length;
7987
7988 TokenInfo
7989 *token_info;
7990
7991 /*
7992 Support old style syntax, filter="-option arg".
7993 */
7994 length=strlen(argv[i+1]);
7995 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00007996 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00007997 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
7998 sizeof(*token));
7999 if (token == (char *) NULL)
8000 break;
8001 next=0;
8002 arguments=argv[i+1];
8003 token_info=AcquireTokenInfo();
8004 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8005 "\"",'\0',&breaker,&next,&quote);
8006 token_info=DestroyTokenInfo(token_info);
8007 if (status == 0)
8008 {
8009 const char
8010 *argv;
8011
8012 argv=(&(arguments[next]));
8013 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8014 exception);
8015 }
8016 token=DestroyString(token);
8017 break;
8018 }
cristy91c0da22010-05-02 01:44:07 +00008019 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008020 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8021 number_arguments-2,(const char **) arguments+2,exception);
8022 for (j=0; j < number_arguments; j++)
8023 arguments[j]=DestroyString(arguments[j]);
8024 arguments=(char **) RelinquishMagickMemory(arguments);
8025 break;
8026 }
8027 break;
8028 }
8029 case 'r':
8030 {
8031 if (LocaleCompare("reverse",option+1) == 0)
8032 {
8033 ReverseImageList(images);
8034 InheritException(exception,&(*images)->exception);
8035 break;
8036 }
8037 break;
8038 }
8039 case 's':
8040 {
cristy4285d782011-02-09 20:12:28 +00008041 if (LocaleCompare("smush",option+1) == 0)
8042 {
8043 Image
8044 *smush_image;
8045
8046 ssize_t
8047 offset;
8048
8049 (void) SyncImagesSettings(mogrify_info,*images);
8050 offset=(ssize_t) StringToLong(argv[i+1]);
8051 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8052 MagickFalse,offset,exception);
8053 if (smush_image == (Image *) NULL)
8054 {
8055 status=MagickFalse;
8056 break;
8057 }
8058 *images=DestroyImageList(*images);
8059 *images=smush_image;
8060 break;
8061 }
cristy3ed852e2009-09-05 21:47:34 +00008062 if (LocaleCompare("swap",option+1) == 0)
8063 {
8064 Image
8065 *p,
8066 *q,
8067 *swap;
8068
cristybb503372010-05-27 20:51:26 +00008069 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008070 swap_index;
8071
8072 index=(-1);
8073 swap_index=(-2);
8074 if (*option != '+')
8075 {
8076 GeometryInfo
8077 geometry_info;
8078
8079 MagickStatusType
8080 flags;
8081
8082 swap_index=(-1);
8083 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008084 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008085 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008086 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008087 }
8088 p=GetImageFromList(*images,index);
8089 q=GetImageFromList(*images,swap_index);
8090 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8091 {
8092 (void) ThrowMagickException(exception,GetMagickModule(),
8093 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8094 status=MagickFalse;
8095 break;
8096 }
8097 if (p == q)
8098 break;
8099 swap=CloneImage(p,0,0,MagickTrue,exception);
8100 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8101 ReplaceImageInList(&q,swap);
8102 *images=GetFirstImageInList(q);
8103 break;
8104 }
8105 break;
8106 }
8107 case 'w':
8108 {
8109 if (LocaleCompare("write",option+1) == 0)
8110 {
cristy071dd7b2010-04-09 13:04:54 +00008111 char
cristy06609ee2010-03-17 20:21:27 +00008112 key[MaxTextExtent];
8113
cristy3ed852e2009-09-05 21:47:34 +00008114 Image
8115 *write_images;
8116
8117 ImageInfo
8118 *write_info;
8119
cristy6b3da3a2010-06-20 02:21:46 +00008120 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008121 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008122 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008123 write_images=(*images);
8124 if (*option == '+')
8125 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008126 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008127 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8128 write_info=DestroyImageInfo(write_info);
8129 if (*option == '+')
8130 write_images=DestroyImageList(write_images);
8131 break;
8132 }
8133 break;
8134 }
8135 default:
8136 break;
8137 }
8138 i+=count;
8139 }
8140 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008141 mogrify_info=DestroyImageInfo(mogrify_info);
8142 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008143 return(status != 0 ? MagickTrue : MagickFalse);
8144}
8145
8146/*
8147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8148% %
8149% %
8150% %
8151+ M o g r i f y I m a g e s %
8152% %
8153% %
8154% %
8155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8156%
8157% MogrifyImages() applies image processing options to a sequence of images as
8158% prescribed by command line options.
8159%
8160% The format of the MogrifyImage method is:
8161%
8162% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8163% const MagickBooleanType post,const int argc,const char **argv,
8164% Image **images,Exceptioninfo *exception)
8165%
8166% A description of each parameter follows:
8167%
8168% o image_info: the image info..
8169%
8170% o post: If true, post process image list operators otherwise pre-process.
8171%
8172% o argc: Specifies a pointer to an integer describing the number of
8173% elements in the argument vector.
8174%
8175% o argv: Specifies a pointer to a text array containing the command line
8176% arguments.
8177%
anthonye9c27192011-03-27 08:07:06 +00008178% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008179%
8180% o exception: return any errors or warnings in this structure.
8181%
8182*/
8183WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8184 const MagickBooleanType post,const int argc,const char **argv,
8185 Image **images,ExceptionInfo *exception)
8186{
8187#define MogrifyImageTag "Mogrify/Image"
8188
anthonye9c27192011-03-27 08:07:06 +00008189 MagickStatusType
8190 status;
cristy3ed852e2009-09-05 21:47:34 +00008191
cristy0e9f9c12010-02-11 03:00:47 +00008192 MagickBooleanType
8193 proceed;
8194
anthonye9c27192011-03-27 08:07:06 +00008195 size_t
8196 n;
cristy3ed852e2009-09-05 21:47:34 +00008197
cristybb503372010-05-27 20:51:26 +00008198 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008199 i;
8200
cristy3ed852e2009-09-05 21:47:34 +00008201 assert(image_info != (ImageInfo *) NULL);
8202 assert(image_info->signature == MagickSignature);
8203 if (images == (Image **) NULL)
8204 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008205 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008206 assert((*images)->signature == MagickSignature);
8207 if ((*images)->debug != MagickFalse)
8208 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8209 (*images)->filename);
8210 if ((argc <= 0) || (*argv == (char *) NULL))
8211 return(MagickTrue);
8212 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8213 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008214 status=0;
anthonye9c27192011-03-27 08:07:06 +00008215
anthonyce2716b2011-04-22 09:51:34 +00008216#if 0
cristy1e604812011-05-19 18:07:50 +00008217 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8218 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008219#endif
8220
anthonye9c27192011-03-27 08:07:06 +00008221 /*
8222 Pre-process multi-image sequence operators
8223 */
cristy3ed852e2009-09-05 21:47:34 +00008224 if (post == MagickFalse)
8225 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008226 /*
8227 For each image, process simple single image operators
8228 */
8229 i=0;
8230 n=GetImageListLength(*images);
8231 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008232 {
anthonyce2716b2011-04-22 09:51:34 +00008233#if 0
cristy1e604812011-05-19 18:07:50 +00008234 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8235 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008236#endif
anthonye9c27192011-03-27 08:07:06 +00008237 status&=MogrifyImage(image_info,argc,argv,images,exception);
8238 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008239 if (proceed == MagickFalse)
8240 break;
anthonye9c27192011-03-27 08:07:06 +00008241 if ( (*images)->next == (Image *) NULL )
8242 break;
8243 *images=(*images)->next;
8244 i++;
cristy3ed852e2009-09-05 21:47:34 +00008245 }
anthonye9c27192011-03-27 08:07:06 +00008246 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008247#if 0
cristy1e604812011-05-19 18:07:50 +00008248 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8249 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008250#endif
anthonye9c27192011-03-27 08:07:06 +00008251
8252 /*
8253 Post-process, multi-image sequence operators
8254 */
8255 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008256 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008257 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008258 return(status != 0 ? MagickTrue : MagickFalse);
8259}