blob: a06d28f5bfb89eb42b60a00e47277270bf28e11f [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
54#include "MagickCore/thread-private.h"
55#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000056
57/*
cristy154fa9d2011-08-05 14:25:15 +000058 Constant declaration.
59*/
cristy3a557c02011-08-06 19:48:02 +000060static const char
cristy638895a2011-08-06 23:19:14 +000061 MogrifyBackgroundColor[] = "#ffffff", /* white */
62 MogrifyBorderColor[] = "#dfdfdf", /* gray */
63 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000064
65/*
cristy3ed852e2009-09-05 21:47:34 +000066 Define declarations.
67*/
68#define UndefinedCompressionQuality 0UL
69
70/*
cristy3ed852e2009-09-05 21:47:34 +000071%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% %
73% %
74% %
cristy5063d812010-10-19 16:28:10 +000075% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000076% %
77% %
78% %
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80%
81% MagickCommandGenesis() applies image processing options to an image as
82% prescribed by command line options.
83%
84% The format of the MagickCommandGenesis method is:
85%
86% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000087% MagickCommand command,int argc,char **argv,char **metadata,
88% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000089%
90% A description of each parameter follows:
91%
92% o image_info: the image info.
93%
cristy5063d812010-10-19 16:28:10 +000094% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000095% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000096% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
97% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000098%
99% o argc: Specifies a pointer to an integer describing the number of
100% elements in the argument vector.
101%
102% o argv: Specifies a pointer to a text array containing the command line
103% arguments.
104%
cristy5063d812010-10-19 16:28:10 +0000105% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000106%
107% o exception: return any errors or warnings in this structure.
108%
109*/
110WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
111 MagickCommand command,int argc,char **argv,char **metadata,
112 ExceptionInfo *exception)
113{
114 char
115 *option;
116
117 double
118 duration,
119 elapsed_time,
120 user_time;
121
cristy3980b0d2009-10-25 14:37:13 +0000122 MagickBooleanType
123 concurrent,
124 regard_warnings,
125 status;
126
cristybb503372010-05-27 20:51:26 +0000127 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000128 i;
129
130 TimerInfo
131 *timer;
132
cristybb503372010-05-27 20:51:26 +0000133 size_t
cristy3980b0d2009-10-25 14:37:13 +0000134 iterations;
135
cristyd0a94fa2010-03-12 14:18:11 +0000136 (void) setlocale(LC_ALL,"");
137 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000138 concurrent=MagickFalse;
139 duration=(-1.0);
140 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000141 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000142 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000143 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000144 {
145 option=argv[i];
146 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
147 continue;
148 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000149 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000150 if (LocaleCompare("concurrent",option+1) == 0)
151 concurrent=MagickTrue;
152 if (LocaleCompare("debug",option+1) == 0)
153 (void) SetLogEventMask(argv[++i]);
154 if (LocaleCompare("duration",option+1) == 0)
cristyc1acd842011-05-19 23:05:47 +0000155 duration=InterpretLocaleValue(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000156 if (LocaleCompare("regard-warnings",option+1) == 0)
157 regard_warnings=MagickTrue;
158 }
159 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000160 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000161 {
cristybb503372010-05-27 20:51:26 +0000162 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000163 {
cristy33557d72009-11-06 00:54:33 +0000164 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000165 continue;
166 if (duration > 0)
167 {
168 if (GetElapsedTime(timer) > duration)
169 continue;
170 (void) ContinueTimer(timer);
171 }
172 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000173 if (exception->severity != UndefinedException)
174 {
175 if ((exception->severity > ErrorException) ||
176 (regard_warnings != MagickFalse))
177 status=MagickTrue;
178 CatchException(exception);
179 }
cristy3d1a5512009-10-25 21:23:27 +0000180 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000181 {
182 (void) fputs(*metadata,stdout);
183 (void) fputc('\n',stdout);
184 *metadata=DestroyString(*metadata);
185 }
186 }
187 }
cristyceae09d2009-10-28 17:18:47 +0000188 else
189 {
190 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000191#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000192 # pragma omp parallel for shared(status)
193#endif
cristybb503372010-05-27 20:51:26 +0000194 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000195 {
cristy33557d72009-11-06 00:54:33 +0000196 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000197 continue;
198 if (duration > 0)
199 {
200 if (GetElapsedTime(timer) > duration)
201 continue;
202 (void) ContinueTimer(timer);
203 }
204 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000205#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000206 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000207#endif
208 {
209 if (exception->severity != UndefinedException)
210 {
211 if ((exception->severity > ErrorException) ||
212 (regard_warnings != MagickFalse))
213 status=MagickTrue;
214 CatchException(exception);
215 }
216 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
217 {
218 (void) fputs(*metadata,stdout);
219 (void) fputc('\n',stdout);
220 *metadata=DestroyString(*metadata);
221 }
222 }
223 }
224 }
cristy3980b0d2009-10-25 14:37:13 +0000225 if (iterations > 1)
226 {
227 elapsed_time=GetElapsedTime(timer);
228 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000229 (void) FormatLocaleFile(stderr,
cristye8c25f92010-06-03 00:53:06 +0000230 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
231 iterations,1.0*iterations/elapsed_time,user_time,(double)
232 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
233 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000234 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000235 }
236 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000237 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000238}
239
240/*
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242% %
243% %
244% %
cristy3ed852e2009-09-05 21:47:34 +0000245+ M o g r i f y I m a g e %
246% %
247% %
248% %
249%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250%
anthonye9c27192011-03-27 08:07:06 +0000251% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000252% image that may be part of a large list, but also handles any 'region'
253% image handling.
anthonye9c27192011-03-27 08:07:06 +0000254%
255% The image in the list may be modified in three different ways...
256%
257% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
258% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
259% * replace by a list of images (only the -separate option!)
260%
261% In each case the result is returned into the list, and a pointer to the
262% modified image (last image added if replaced by a list of images) is
263% returned.
264%
265% ASIDE: The -crop is present but restricted to non-tile single image crops
266%
267% This means if all the images are being processed (such as by
268% MogrifyImages(), next image to be processed will be as per the pointer
269% (*image)->next. Also the image list may grow as a result of some specific
270% operations but as images are never merged or deleted, it will never shrink
271% in length. Typically the list will remain the same length.
272%
273% WARNING: As the image pointed to may be replaced, the first image in the
274% list may also change. GetFirstImageInList() should be used by caller if
275% they wish return the Image pointer to the first image in list.
276%
cristy3ed852e2009-09-05 21:47:34 +0000277%
278% The format of the MogrifyImage method is:
279%
280% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
281% const char **argv,Image **image)
282%
283% A description of each parameter follows:
284%
285% o image_info: the image info..
286%
287% o argc: Specifies a pointer to an integer describing the number of
288% elements in the argument vector.
289%
290% o argv: Specifies a pointer to a text array containing the command line
291% arguments.
292%
293% o image: the image.
294%
295% o exception: return any errors or warnings in this structure.
296%
297*/
298
cristy4c08aed2011-07-01 19:47:50 +0000299/*
300** GetImageCache() will read an image into a image cache if not already
301** present then return the image that is in the cache under that filename.
302*/
anthonydf8ebac2011-04-27 09:03:19 +0000303static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
304 ExceptionInfo *exception)
305{
306 char
307 key[MaxTextExtent];
308
309 ExceptionInfo
310 *sans_exception;
311
312 Image
313 *image;
314
315 ImageInfo
316 *read_info;
317
cristyb51dff52011-05-19 16:55:47 +0000318 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000319 sans_exception=AcquireExceptionInfo();
320 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
321 sans_exception=DestroyExceptionInfo(sans_exception);
322 if (image != (Image *) NULL)
323 return(image);
324 read_info=CloneImageInfo(image_info);
325 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
326 image=ReadImage(read_info,exception);
327 read_info=DestroyImageInfo(read_info);
328 if (image != (Image *) NULL)
329 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
330 return(image);
331}
332
cristy3ed852e2009-09-05 21:47:34 +0000333static MagickBooleanType IsPathWritable(const char *path)
334{
335 if (IsPathAccessible(path) == MagickFalse)
336 return(MagickFalse);
337 if (access(path,W_OK) != 0)
338 return(MagickFalse);
339 return(MagickTrue);
340}
341
cristybb503372010-05-27 20:51:26 +0000342static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000343{
344 if (x > y)
345 return(x);
346 return(y);
347}
348
anthonydf8ebac2011-04-27 09:03:19 +0000349static MagickBooleanType MonitorProgress(const char *text,
350 const MagickOffsetType offset,const MagickSizeType extent,
351 void *wand_unused(client_data))
352{
353 char
354 message[MaxTextExtent],
355 tag[MaxTextExtent];
356
357 const char
358 *locale_message;
359
360 register char
361 *p;
362
363 if (extent < 2)
364 return(MagickTrue);
365 (void) CopyMagickMemory(tag,text,MaxTextExtent);
366 p=strrchr(tag,'/');
367 if (p != (char *) NULL)
368 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000369 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000370 locale_message=GetLocaleMessage(message);
371 if (locale_message == message)
372 locale_message=tag;
373 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000374 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
375 locale_message,(long) offset,(unsigned long) extent,(long)
376 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000377 else
cristyb51dff52011-05-19 16:55:47 +0000378 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000379 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
380 (100L*offset/(extent-1)));
381 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000382 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000383 (void) fflush(stderr);
384 return(MagickTrue);
385}
386
387/*
anthony3d2f4862011-05-01 13:48:16 +0000388** SparseColorOption() parses the complex -sparse-color argument into an
389** an array of floating point values then calls SparseColorImage().
anthonydf8ebac2011-04-27 09:03:19 +0000390** Argument is a complex mix of floating-point pixel coodinates, and color
391** specifications (or direct floating point numbers). The number of floats
anthony3d2f4862011-05-01 13:48:16 +0000392** needed to represent a color varies depending on the current channel
anthonydf8ebac2011-04-27 09:03:19 +0000393** setting.
394*/
cristy3884f692011-07-08 18:00:18 +0000395static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000396 const SparseColorMethod method,const char *arguments,
397 const MagickBooleanType color_from_image,ExceptionInfo *exception)
398{
anthonydf8ebac2011-04-27 09:03:19 +0000399 char
400 token[MaxTextExtent];
401
402 const char
403 *p;
404
405 double
406 *sparse_arguments;
407
anthonydf8ebac2011-04-27 09:03:19 +0000408 Image
409 *sparse_image;
410
cristy4c08aed2011-07-01 19:47:50 +0000411 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000412 color;
413
414 MagickBooleanType
415 error;
416
cristy5f09d852011-05-29 01:39:29 +0000417 register size_t
418 x;
419
420 size_t
421 number_arguments,
422 number_colors;
423
anthonydf8ebac2011-04-27 09:03:19 +0000424 assert(image != (Image *) NULL);
425 assert(image->signature == MagickSignature);
426 if (image->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
428 assert(exception != (ExceptionInfo *) NULL);
429 assert(exception->signature == MagickSignature);
430 /*
431 Limit channels according to image - and add up number of color channel.
432 */
anthonydf8ebac2011-04-27 09:03:19 +0000433 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000434 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000435 number_colors++;
cristyed231572011-07-14 02:18:59 +0000436 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000437 number_colors++;
cristyed231572011-07-14 02:18:59 +0000438 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000439 number_colors++;
cristyed231572011-07-14 02:18:59 +0000440 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000441 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000442 number_colors++;
cristyed231572011-07-14 02:18:59 +0000443 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000444 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000445 number_colors++;
446
447 /*
448 Read string, to determine number of arguments needed,
449 */
450 p=arguments;
451 x=0;
452 while( *p != '\0' )
453 {
454 GetMagickToken(p,&p,token);
455 if ( token[0] == ',' ) continue;
456 if ( isalpha((int) token[0]) || token[0] == '#' ) {
457 if ( color_from_image ) {
458 (void) ThrowMagickException(exception,GetMagickModule(),
459 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
460 "Color arg given, when colors are coming from image");
461 return( (Image *)NULL);
462 }
463 x += number_colors; /* color argument */
464 }
465 else {
466 x++; /* floating point argument */
467 }
468 }
469 error=MagickTrue;
470 if ( color_from_image ) {
471 /* just the control points are being given */
472 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
473 number_arguments=(x/2)*(2+number_colors);
474 }
475 else {
476 /* control points and color values */
477 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
478 number_arguments=x;
479 }
480 if ( error ) {
481 (void) ThrowMagickException(exception,GetMagickModule(),
482 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
483 "Invalid number of Arguments");
484 return( (Image *)NULL);
485 }
486
487 /* Allocate and fill in the floating point arguments */
488 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
489 sizeof(*sparse_arguments));
490 if (sparse_arguments == (double *) NULL) {
491 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
492 "MemoryAllocationFailed","%s","SparseColorOption");
493 return( (Image *)NULL);
494 }
495 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
496 sizeof(*sparse_arguments));
497 p=arguments;
498 x=0;
499 while( *p != '\0' && x < number_arguments ) {
500 /* X coordinate */
501 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
502 if ( token[0] == '\0' ) break;
503 if ( isalpha((int) token[0]) || token[0] == '#' ) {
504 (void) ThrowMagickException(exception,GetMagickModule(),
505 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
506 "Color found, instead of X-coord");
507 error = MagickTrue;
508 break;
509 }
cristyc1acd842011-05-19 23:05:47 +0000510 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000511 /* Y coordinate */
512 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
513 if ( token[0] == '\0' ) break;
514 if ( isalpha((int) token[0]) || token[0] == '#' ) {
515 (void) ThrowMagickException(exception,GetMagickModule(),
516 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
517 "Color found, instead of Y-coord");
518 error = MagickTrue;
519 break;
520 }
cristyc1acd842011-05-19 23:05:47 +0000521 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000522 /* color values for this control point */
523#if 0
524 if ( (color_from_image ) {
525 /* get color from image */
526 /* HOW??? */
527 }
528 else
529#endif
530 {
531 /* color name or function given in string argument */
532 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
533 if ( token[0] == '\0' ) break;
534 if ( isalpha((int) token[0]) || token[0] == '#' ) {
535 /* Color string given */
536 (void) QueryMagickColor(token,&color,exception);
cristyed231572011-07-14 02:18:59 +0000537 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000538 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000539 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000540 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000541 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000542 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000543 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000544 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000545 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000546 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000547 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000548 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000549 }
550 else {
551 /* Colors given as a set of floating point values - experimental */
552 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000553 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000554 {
anthonydf8ebac2011-04-27 09:03:19 +0000555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristyc1acd842011-05-19 23:05:47 +0000558 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000559 token[0] = ','; /* used this token - get another */
560 }
cristyed231572011-07-14 02:18:59 +0000561 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000562 {
anthonydf8ebac2011-04-27 09:03:19 +0000563 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
564 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
565 break;
cristyc1acd842011-05-19 23:05:47 +0000566 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000567 token[0] = ','; /* used this token - get another */
568 }
cristyed231572011-07-14 02:18:59 +0000569 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000570 {
anthonydf8ebac2011-04-27 09:03:19 +0000571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristyc1acd842011-05-19 23:05:47 +0000574 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
cristyed231572011-07-14 02:18:59 +0000577 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000578 (image->colorspace == CMYKColorspace))
579 {
anthonydf8ebac2011-04-27 09:03:19 +0000580 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
581 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
582 break;
cristyc1acd842011-05-19 23:05:47 +0000583 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000584 token[0] = ','; /* used this token - get another */
585 }
cristyed231572011-07-14 02:18:59 +0000586 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000587 (image->matte != MagickFalse))
588 {
anthonydf8ebac2011-04-27 09:03:19 +0000589 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
590 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
591 break;
cristyc1acd842011-05-19 23:05:47 +0000592 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000593 token[0] = ','; /* used this token - get another */
594 }
595 }
596 }
597 }
598 if ( number_arguments != x && !error ) {
599 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
600 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
601 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
602 return( (Image *)NULL);
603 }
604 if ( error )
605 return( (Image *)NULL);
606
607 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000608 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
609 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000610 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
611 return( sparse_image );
612}
613
cristy3ed852e2009-09-05 21:47:34 +0000614WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
615 const char **argv,Image **image,ExceptionInfo *exception)
616{
anthonydf8ebac2011-04-27 09:03:19 +0000617 ChannelType
618 channel;
619
620 const char
621 *format,
622 *option;
623
624 DrawInfo
625 *draw_info;
626
627 GeometryInfo
628 geometry_info;
629
cristy3ed852e2009-09-05 21:47:34 +0000630 Image
631 *region_image;
632
anthonydf8ebac2011-04-27 09:03:19 +0000633 ImageInfo
634 *mogrify_info;
635
cristyebbcfea2011-02-25 02:43:54 +0000636 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000637 status;
638
cristy4c08aed2011-07-01 19:47:50 +0000639 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000640 fill;
cristy3ed852e2009-09-05 21:47:34 +0000641
anthonydf8ebac2011-04-27 09:03:19 +0000642 MagickStatusType
643 flags;
644
645 QuantizeInfo
646 *quantize_info;
647
648 RectangleInfo
649 geometry,
650 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000651
cristybb503372010-05-27 20:51:26 +0000652 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000653 i;
654
655 /*
656 Initialize method variables.
657 */
658 assert(image_info != (const ImageInfo *) NULL);
659 assert(image_info->signature == MagickSignature);
660 assert(image != (Image **) NULL);
661 assert((*image)->signature == MagickSignature);
662 if ((*image)->debug != MagickFalse)
663 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
664 if (argc < 0)
665 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000666 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000667 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
668 quantize_info=AcquireQuantizeInfo(mogrify_info);
669 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000670 GetPixelInfo(*image,&fill);
671 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
anthonydf8ebac2011-04-27 09:03:19 +0000672 channel=mogrify_info->channel;
673 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000674 SetGeometry(*image,&region_geometry);
675 region_image=NewImageList();
676 /*
677 Transmogrify the image.
678 */
cristybb503372010-05-27 20:51:26 +0000679 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000680 {
anthonydf8ebac2011-04-27 09:03:19 +0000681 Image
682 *mogrify_image;
683
anthonye9c27192011-03-27 08:07:06 +0000684 ssize_t
685 count;
686
anthonydf8ebac2011-04-27 09:03:19 +0000687 option=argv[i];
688 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000689 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000690 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
691 0L);
cristycee97112010-05-28 00:44:52 +0000692 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000693 break;
cristy6b3da3a2010-06-20 02:21:46 +0000694 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000695 mogrify_image=(Image *)NULL;
696 switch (*(option+1))
697 {
698 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000699 {
anthonydf8ebac2011-04-27 09:03:19 +0000700 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000701 {
anthonydf8ebac2011-04-27 09:03:19 +0000702 /*
703 Adaptive blur image.
704 */
705 (void) SyncImageSettings(mogrify_info,*image);
706 flags=ParseGeometry(argv[i+1],&geometry_info);
707 if ((flags & SigmaValue) == 0)
708 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000709 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
710 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000711 break;
cristy3ed852e2009-09-05 21:47:34 +0000712 }
anthonydf8ebac2011-04-27 09:03:19 +0000713 if (LocaleCompare("adaptive-resize",option+1) == 0)
714 {
715 /*
716 Adaptive resize image.
717 */
718 (void) SyncImageSettings(mogrify_info,*image);
719 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
720 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
721 geometry.height,exception);
722 break;
723 }
724 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
725 {
726 /*
727 Adaptive sharpen image.
728 */
729 (void) SyncImageSettings(mogrify_info,*image);
730 flags=ParseGeometry(argv[i+1],&geometry_info);
731 if ((flags & SigmaValue) == 0)
732 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000733 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
734 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000735 break;
736 }
737 if (LocaleCompare("affine",option+1) == 0)
738 {
739 /*
740 Affine matrix.
741 */
742 if (*option == '+')
743 {
744 GetAffineMatrix(&draw_info->affine);
745 break;
746 }
747 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
748 break;
749 }
750 if (LocaleCompare("alpha",option+1) == 0)
751 {
752 AlphaChannelType
753 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000754
anthonydf8ebac2011-04-27 09:03:19 +0000755 (void) SyncImageSettings(mogrify_info,*image);
756 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
757 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000758 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000759 break;
760 }
761 if (LocaleCompare("annotate",option+1) == 0)
762 {
763 char
764 *text,
765 geometry[MaxTextExtent];
766
767 /*
768 Annotate image.
769 */
770 (void) SyncImageSettings(mogrify_info,*image);
771 SetGeometryInfo(&geometry_info);
772 flags=ParseGeometry(argv[i+1],&geometry_info);
773 if ((flags & SigmaValue) == 0)
774 geometry_info.sigma=geometry_info.rho;
775 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
776 InheritException(exception,&(*image)->exception);
777 if (text == (char *) NULL)
778 break;
779 (void) CloneString(&draw_info->text,text);
780 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000781 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000782 geometry_info.xi,geometry_info.psi);
783 (void) CloneString(&draw_info->geometry,geometry);
784 draw_info->affine.sx=cos(DegreesToRadians(
785 fmod(geometry_info.rho,360.0)));
786 draw_info->affine.rx=sin(DegreesToRadians(
787 fmod(geometry_info.rho,360.0)));
788 draw_info->affine.ry=(-sin(DegreesToRadians(
789 fmod(geometry_info.sigma,360.0))));
790 draw_info->affine.sy=cos(DegreesToRadians(
791 fmod(geometry_info.sigma,360.0)));
792 (void) AnnotateImage(*image,draw_info);
793 InheritException(exception,&(*image)->exception);
794 break;
795 }
796 if (LocaleCompare("antialias",option+1) == 0)
797 {
798 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
799 MagickFalse;
800 draw_info->text_antialias=(*option == '-') ? MagickTrue :
801 MagickFalse;
802 break;
803 }
804 if (LocaleCompare("auto-gamma",option+1) == 0)
805 {
806 /*
807 Auto Adjust Gamma of image based on its mean
808 */
809 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000810 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000811 break;
812 }
813 if (LocaleCompare("auto-level",option+1) == 0)
814 {
815 /*
816 Perfectly Normalize (max/min stretch) the image
817 */
818 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000819 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000820 break;
821 }
822 if (LocaleCompare("auto-orient",option+1) == 0)
823 {
824 (void) SyncImageSettings(mogrify_info,*image);
825 switch ((*image)->orientation)
826 {
827 case TopRightOrientation:
828 {
829 mogrify_image=FlopImage(*image,exception);
830 break;
831 }
832 case BottomRightOrientation:
833 {
834 mogrify_image=RotateImage(*image,180.0,exception);
835 break;
836 }
837 case BottomLeftOrientation:
838 {
839 mogrify_image=FlipImage(*image,exception);
840 break;
841 }
842 case LeftTopOrientation:
843 {
844 mogrify_image=TransposeImage(*image,exception);
845 break;
846 }
847 case RightTopOrientation:
848 {
849 mogrify_image=RotateImage(*image,90.0,exception);
850 break;
851 }
852 case RightBottomOrientation:
853 {
854 mogrify_image=TransverseImage(*image,exception);
855 break;
856 }
857 case LeftBottomOrientation:
858 {
859 mogrify_image=RotateImage(*image,270.0,exception);
860 break;
861 }
862 default:
863 break;
864 }
865 if (mogrify_image != (Image *) NULL)
866 mogrify_image->orientation=TopLeftOrientation;
867 break;
868 }
869 break;
870 }
871 case 'b':
872 {
873 if (LocaleCompare("black-threshold",option+1) == 0)
874 {
875 /*
876 Black threshold image.
877 */
878 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000879 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000880 InheritException(exception,&(*image)->exception);
881 break;
882 }
883 if (LocaleCompare("blue-shift",option+1) == 0)
884 {
885 /*
886 Blue shift image.
887 */
888 (void) SyncImageSettings(mogrify_info,*image);
889 geometry_info.rho=1.5;
890 if (*option == '-')
891 flags=ParseGeometry(argv[i+1],&geometry_info);
892 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
893 break;
894 }
895 if (LocaleCompare("blur",option+1) == 0)
896 {
897 /*
898 Gaussian blur image.
899 */
900 (void) SyncImageSettings(mogrify_info,*image);
901 flags=ParseGeometry(argv[i+1],&geometry_info);
902 if ((flags & SigmaValue) == 0)
903 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000904 mogrify_image=BlurImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +0000905 geometry_info.sigma,exception);
906 break;
907 }
908 if (LocaleCompare("border",option+1) == 0)
909 {
910 /*
911 Surround image with a border of solid color.
912 */
913 (void) SyncImageSettings(mogrify_info,*image);
914 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
915 if ((flags & SigmaValue) == 0)
916 geometry.height=geometry.width;
917 mogrify_image=BorderImage(*image,&geometry,exception);
918 break;
919 }
920 if (LocaleCompare("bordercolor",option+1) == 0)
921 {
922 if (*option == '+')
923 {
cristy638895a2011-08-06 23:19:14 +0000924 (void) QueryColorDatabase(MogrifyBorderColor,&draw_info->border_color,
anthonydf8ebac2011-04-27 09:03:19 +0000925 exception);
926 break;
927 }
928 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
929 exception);
930 break;
931 }
932 if (LocaleCompare("box",option+1) == 0)
933 {
934 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
935 exception);
936 break;
937 }
938 if (LocaleCompare("brightness-contrast",option+1) == 0)
939 {
940 double
941 brightness,
942 contrast;
943
944 GeometryInfo
945 geometry_info;
946
947 MagickStatusType
948 flags;
949
950 /*
951 Brightness / contrast image.
952 */
953 (void) SyncImageSettings(mogrify_info,*image);
954 flags=ParseGeometry(argv[i+1],&geometry_info);
955 brightness=geometry_info.rho;
956 contrast=0.0;
957 if ((flags & SigmaValue) != 0)
958 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000959 (void) BrightnessContrastImage(*image,brightness,contrast,
960 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000961 InheritException(exception,&(*image)->exception);
962 break;
963 }
964 break;
965 }
966 case 'c':
967 {
968 if (LocaleCompare("cdl",option+1) == 0)
969 {
970 char
971 *color_correction_collection;
972
973 /*
974 Color correct with a color decision list.
975 */
976 (void) SyncImageSettings(mogrify_info,*image);
977 color_correction_collection=FileToString(argv[i+1],~0,exception);
978 if (color_correction_collection == (char *) NULL)
979 break;
cristy1bfa9f02011-08-11 02:35:43 +0000980 (void) ColorDecisionListImage(*image,color_correction_collection,
981 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000982 InheritException(exception,&(*image)->exception);
983 break;
984 }
985 if (LocaleCompare("channel",option+1) == 0)
986 {
987 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000988 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000989 else
cristyfa806a72011-07-04 02:06:13 +0000990 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +0000991 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000992 break;
993 }
994 if (LocaleCompare("charcoal",option+1) == 0)
995 {
996 /*
997 Charcoal image.
998 */
999 (void) SyncImageSettings(mogrify_info,*image);
1000 flags=ParseGeometry(argv[i+1],&geometry_info);
1001 if ((flags & SigmaValue) == 0)
1002 geometry_info.sigma=1.0;
1003 mogrify_image=CharcoalImage(*image,geometry_info.rho,
1004 geometry_info.sigma,exception);
1005 break;
1006 }
1007 if (LocaleCompare("chop",option+1) == 0)
1008 {
1009 /*
1010 Chop the image.
1011 */
1012 (void) SyncImageSettings(mogrify_info,*image);
1013 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1014 mogrify_image=ChopImage(*image,&geometry,exception);
1015 break;
1016 }
1017 if (LocaleCompare("clamp",option+1) == 0)
1018 {
1019 /*
1020 Clamp image.
1021 */
1022 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001023 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001024 InheritException(exception,&(*image)->exception);
1025 break;
1026 }
1027 if (LocaleCompare("clip",option+1) == 0)
1028 {
1029 (void) SyncImageSettings(mogrify_info,*image);
1030 if (*option == '+')
1031 {
1032 (void) SetImageClipMask(*image,(Image *) NULL);
1033 InheritException(exception,&(*image)->exception);
1034 break;
1035 }
1036 (void) ClipImage(*image);
1037 InheritException(exception,&(*image)->exception);
1038 break;
1039 }
1040 if (LocaleCompare("clip-mask",option+1) == 0)
1041 {
1042 CacheView
1043 *mask_view;
1044
1045 Image
1046 *mask_image;
1047
cristy4c08aed2011-07-01 19:47:50 +00001048 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001049 *restrict q;
1050
1051 register ssize_t
1052 x;
1053
1054 ssize_t
1055 y;
1056
1057 (void) SyncImageSettings(mogrify_info,*image);
1058 if (*option == '+')
1059 {
1060 /*
1061 Remove a mask.
1062 */
1063 (void) SetImageMask(*image,(Image *) NULL);
1064 InheritException(exception,&(*image)->exception);
1065 break;
1066 }
1067 /*
1068 Set the image mask.
1069 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1070 */
1071 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1072 if (mask_image == (Image *) NULL)
1073 break;
cristy574cc262011-08-05 01:23:58 +00001074 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001075 return(MagickFalse);
1076 mask_view=AcquireCacheView(mask_image);
1077 for (y=0; y < (ssize_t) mask_image->rows; y++)
1078 {
1079 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1080 exception);
cristy4c08aed2011-07-01 19:47:50 +00001081 if (q == (const Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001082 break;
1083 for (x=0; x < (ssize_t) mask_image->columns; x++)
1084 {
1085 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001086 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1087 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1088 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1089 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001090 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001091 }
1092 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1093 break;
1094 }
1095 mask_view=DestroyCacheView(mask_view);
1096 mask_image->matte=MagickTrue;
1097 (void) SetImageClipMask(*image,mask_image);
1098 mask_image=DestroyImage(mask_image);
1099 InheritException(exception,&(*image)->exception);
1100 break;
1101 }
1102 if (LocaleCompare("clip-path",option+1) == 0)
1103 {
1104 (void) SyncImageSettings(mogrify_info,*image);
1105 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1106 MagickFalse);
1107 InheritException(exception,&(*image)->exception);
1108 break;
1109 }
1110 if (LocaleCompare("colorize",option+1) == 0)
1111 {
1112 /*
1113 Colorize the image.
1114 */
1115 (void) SyncImageSettings(mogrify_info,*image);
1116 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1117 exception);
1118 break;
1119 }
1120 if (LocaleCompare("color-matrix",option+1) == 0)
1121 {
1122 KernelInfo
1123 *kernel;
1124
1125 (void) SyncImageSettings(mogrify_info,*image);
1126 kernel=AcquireKernelInfo(argv[i+1]);
1127 if (kernel == (KernelInfo *) NULL)
1128 break;
1129 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1130 kernel=DestroyKernelInfo(kernel);
1131 break;
1132 }
1133 if (LocaleCompare("colors",option+1) == 0)
1134 {
1135 /*
1136 Reduce the number of colors in the image.
1137 */
1138 (void) SyncImageSettings(mogrify_info,*image);
1139 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1140 if (quantize_info->number_colors == 0)
1141 break;
1142 if (((*image)->storage_class == DirectClass) ||
1143 (*image)->colors > quantize_info->number_colors)
1144 (void) QuantizeImage(quantize_info,*image);
1145 else
1146 (void) CompressImageColormap(*image);
1147 InheritException(exception,&(*image)->exception);
1148 break;
1149 }
1150 if (LocaleCompare("colorspace",option+1) == 0)
1151 {
1152 ColorspaceType
1153 colorspace;
1154
1155 (void) SyncImageSettings(mogrify_info,*image);
1156 if (*option == '+')
1157 {
1158 (void) TransformImageColorspace(*image,RGBColorspace);
1159 InheritException(exception,&(*image)->exception);
1160 break;
1161 }
1162 colorspace=(ColorspaceType) ParseCommandOption(
1163 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1164 (void) TransformImageColorspace(*image,colorspace);
1165 InheritException(exception,&(*image)->exception);
1166 break;
1167 }
1168 if (LocaleCompare("contrast",option+1) == 0)
1169 {
1170 (void) SyncImageSettings(mogrify_info,*image);
1171 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1172 MagickFalse);
1173 InheritException(exception,&(*image)->exception);
1174 break;
1175 }
1176 if (LocaleCompare("contrast-stretch",option+1) == 0)
1177 {
1178 double
1179 black_point,
1180 white_point;
1181
1182 MagickStatusType
1183 flags;
1184
1185 /*
1186 Contrast stretch image.
1187 */
1188 (void) SyncImageSettings(mogrify_info,*image);
1189 flags=ParseGeometry(argv[i+1],&geometry_info);
1190 black_point=geometry_info.rho;
1191 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1192 black_point;
1193 if ((flags & PercentValue) != 0)
1194 {
1195 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1196 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1197 }
1198 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1199 white_point;
cristy50fbc382011-07-07 02:19:17 +00001200 (void) ContrastStretchImage(*image,black_point,white_point);
anthonydf8ebac2011-04-27 09:03:19 +00001201 InheritException(exception,&(*image)->exception);
1202 break;
1203 }
1204 if (LocaleCompare("convolve",option+1) == 0)
1205 {
anthonydf8ebac2011-04-27 09:03:19 +00001206 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001207 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001208
anthonydf8ebac2011-04-27 09:03:19 +00001209 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001210 kernel_info=AcquireKernelInfo(argv[i+1]);
1211 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001212 break;
cristy0a922382011-07-16 15:30:34 +00001213 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001214 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001215 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001216 break;
1217 }
1218 if (LocaleCompare("crop",option+1) == 0)
1219 {
1220 /*
1221 Crop a image to a smaller size
1222 */
1223 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001224 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001225 break;
1226 }
1227 if (LocaleCompare("cycle",option+1) == 0)
1228 {
1229 /*
1230 Cycle an image colormap.
1231 */
1232 (void) SyncImageSettings(mogrify_info,*image);
1233 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1234 InheritException(exception,&(*image)->exception);
1235 break;
1236 }
1237 break;
1238 }
1239 case 'd':
1240 {
1241 if (LocaleCompare("decipher",option+1) == 0)
1242 {
1243 StringInfo
1244 *passkey;
1245
1246 /*
1247 Decipher pixels.
1248 */
1249 (void) SyncImageSettings(mogrify_info,*image);
1250 passkey=FileToStringInfo(argv[i+1],~0,exception);
1251 if (passkey != (StringInfo *) NULL)
1252 {
1253 (void) PasskeyDecipherImage(*image,passkey,exception);
1254 passkey=DestroyStringInfo(passkey);
1255 }
1256 break;
1257 }
1258 if (LocaleCompare("density",option+1) == 0)
1259 {
1260 /*
1261 Set image density.
1262 */
1263 (void) CloneString(&draw_info->density,argv[i+1]);
1264 break;
1265 }
1266 if (LocaleCompare("depth",option+1) == 0)
1267 {
1268 (void) SyncImageSettings(mogrify_info,*image);
1269 if (*option == '+')
1270 {
1271 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1272 break;
1273 }
1274 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1275 break;
1276 }
1277 if (LocaleCompare("deskew",option+1) == 0)
1278 {
1279 double
1280 threshold;
1281
1282 /*
1283 Straighten the image.
1284 */
1285 (void) SyncImageSettings(mogrify_info,*image);
1286 if (*option == '+')
1287 threshold=40.0*QuantumRange/100.0;
1288 else
1289 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1290 mogrify_image=DeskewImage(*image,threshold,exception);
1291 break;
1292 }
1293 if (LocaleCompare("despeckle",option+1) == 0)
1294 {
1295 /*
1296 Reduce the speckles within an image.
1297 */
1298 (void) SyncImageSettings(mogrify_info,*image);
1299 mogrify_image=DespeckleImage(*image,exception);
1300 break;
1301 }
1302 if (LocaleCompare("display",option+1) == 0)
1303 {
1304 (void) CloneString(&draw_info->server_name,argv[i+1]);
1305 break;
1306 }
1307 if (LocaleCompare("distort",option+1) == 0)
1308 {
1309 char
1310 *args,
1311 token[MaxTextExtent];
1312
1313 const char
1314 *p;
1315
1316 DistortImageMethod
1317 method;
1318
1319 double
1320 *arguments;
1321
1322 register ssize_t
1323 x;
1324
1325 size_t
1326 number_arguments;
1327
1328 /*
1329 Distort image.
1330 */
1331 (void) SyncImageSettings(mogrify_info,*image);
1332 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1333 MagickFalse,argv[i+1]);
1334 if ( method == ResizeDistortion )
1335 {
1336 /* Special Case - Argument is actually a resize geometry!
1337 ** Convert that to an appropriate distortion argument array.
1338 */
1339 double
1340 resize_args[2];
1341 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1342 exception);
1343 resize_args[0]=(double)geometry.width;
1344 resize_args[1]=(double)geometry.height;
1345 mogrify_image=DistortImage(*image,method,(size_t)2,
1346 resize_args,MagickTrue,exception);
1347 break;
1348 }
1349 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1350 InheritException(exception,&(*image)->exception);
1351 if (args == (char *) NULL)
1352 break;
1353 p=(char *) args;
1354 for (x=0; *p != '\0'; x++)
1355 {
1356 GetMagickToken(p,&p,token);
1357 if (*token == ',')
1358 GetMagickToken(p,&p,token);
1359 }
1360 number_arguments=(size_t) x;
1361 arguments=(double *) AcquireQuantumMemory(number_arguments,
1362 sizeof(*arguments));
1363 if (arguments == (double *) NULL)
1364 ThrowWandFatalException(ResourceLimitFatalError,
1365 "MemoryAllocationFailed",(*image)->filename);
1366 (void) ResetMagickMemory(arguments,0,number_arguments*
1367 sizeof(*arguments));
1368 p=(char *) args;
1369 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1370 {
1371 GetMagickToken(p,&p,token);
1372 if (*token == ',')
1373 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001374 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001375 }
1376 args=DestroyString(args);
1377 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1378 (*option == '+') ? MagickTrue : MagickFalse,exception);
1379 arguments=(double *) RelinquishMagickMemory(arguments);
1380 break;
1381 }
1382 if (LocaleCompare("dither",option+1) == 0)
1383 {
1384 if (*option == '+')
1385 {
1386 quantize_info->dither=MagickFalse;
1387 break;
1388 }
1389 quantize_info->dither=MagickTrue;
1390 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1391 MagickDitherOptions,MagickFalse,argv[i+1]);
1392 if (quantize_info->dither_method == NoDitherMethod)
1393 quantize_info->dither=MagickFalse;
1394 break;
1395 }
1396 if (LocaleCompare("draw",option+1) == 0)
1397 {
1398 /*
1399 Draw image.
1400 */
1401 (void) SyncImageSettings(mogrify_info,*image);
1402 (void) CloneString(&draw_info->primitive,argv[i+1]);
1403 (void) DrawImage(*image,draw_info);
1404 InheritException(exception,&(*image)->exception);
1405 break;
1406 }
1407 break;
1408 }
1409 case 'e':
1410 {
1411 if (LocaleCompare("edge",option+1) == 0)
1412 {
1413 /*
1414 Enhance edges in the image.
1415 */
1416 (void) SyncImageSettings(mogrify_info,*image);
1417 flags=ParseGeometry(argv[i+1],&geometry_info);
1418 if ((flags & SigmaValue) == 0)
1419 geometry_info.sigma=1.0;
1420 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1421 break;
1422 }
1423 if (LocaleCompare("emboss",option+1) == 0)
1424 {
1425 /*
1426 Gaussian embossen image.
1427 */
1428 (void) SyncImageSettings(mogrify_info,*image);
1429 flags=ParseGeometry(argv[i+1],&geometry_info);
1430 if ((flags & SigmaValue) == 0)
1431 geometry_info.sigma=1.0;
1432 mogrify_image=EmbossImage(*image,geometry_info.rho,
1433 geometry_info.sigma,exception);
1434 break;
1435 }
1436 if (LocaleCompare("encipher",option+1) == 0)
1437 {
1438 StringInfo
1439 *passkey;
1440
1441 /*
1442 Encipher pixels.
1443 */
1444 (void) SyncImageSettings(mogrify_info,*image);
1445 passkey=FileToStringInfo(argv[i+1],~0,exception);
1446 if (passkey != (StringInfo *) NULL)
1447 {
1448 (void) PasskeyEncipherImage(*image,passkey,exception);
1449 passkey=DestroyStringInfo(passkey);
1450 }
1451 break;
1452 }
1453 if (LocaleCompare("encoding",option+1) == 0)
1454 {
1455 (void) CloneString(&draw_info->encoding,argv[i+1]);
1456 break;
1457 }
1458 if (LocaleCompare("enhance",option+1) == 0)
1459 {
1460 /*
1461 Enhance image.
1462 */
1463 (void) SyncImageSettings(mogrify_info,*image);
1464 mogrify_image=EnhanceImage(*image,exception);
1465 break;
1466 }
1467 if (LocaleCompare("equalize",option+1) == 0)
1468 {
1469 /*
1470 Equalize image.
1471 */
1472 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00001473 (void) EqualizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001474 InheritException(exception,&(*image)->exception);
1475 break;
1476 }
1477 if (LocaleCompare("evaluate",option+1) == 0)
1478 {
1479 double
1480 constant;
1481
1482 MagickEvaluateOperator
1483 op;
1484
1485 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001486 op=(MagickEvaluateOperator) ParseCommandOption(
1487 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001488 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001489 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001490 break;
1491 }
1492 if (LocaleCompare("extent",option+1) == 0)
1493 {
1494 /*
1495 Set the image extent.
1496 */
1497 (void) SyncImageSettings(mogrify_info,*image);
1498 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1499 if (geometry.width == 0)
1500 geometry.width=(*image)->columns;
1501 if (geometry.height == 0)
1502 geometry.height=(*image)->rows;
1503 mogrify_image=ExtentImage(*image,&geometry,exception);
1504 break;
1505 }
1506 break;
1507 }
1508 case 'f':
1509 {
1510 if (LocaleCompare("family",option+1) == 0)
1511 {
1512 if (*option == '+')
1513 {
1514 if (draw_info->family != (char *) NULL)
1515 draw_info->family=DestroyString(draw_info->family);
1516 break;
1517 }
1518 (void) CloneString(&draw_info->family,argv[i+1]);
1519 break;
1520 }
1521 if (LocaleCompare("features",option+1) == 0)
1522 {
1523 if (*option == '+')
1524 {
1525 (void) DeleteImageArtifact(*image,"identify:features");
1526 break;
1527 }
1528 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1529 break;
1530 }
1531 if (LocaleCompare("fill",option+1) == 0)
1532 {
1533 ExceptionInfo
1534 *sans;
1535
cristy4c08aed2011-07-01 19:47:50 +00001536 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001537 if (*option == '+')
1538 {
1539 (void) QueryMagickColor("none",&fill,exception);
1540 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1541 if (draw_info->fill_pattern != (Image *) NULL)
1542 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1543 break;
1544 }
1545 sans=AcquireExceptionInfo();
1546 (void) QueryMagickColor(argv[i+1],&fill,sans);
1547 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1548 sans=DestroyExceptionInfo(sans);
1549 if (status == MagickFalse)
1550 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1551 exception);
1552 break;
1553 }
1554 if (LocaleCompare("flip",option+1) == 0)
1555 {
1556 /*
1557 Flip image scanlines.
1558 */
1559 (void) SyncImageSettings(mogrify_info,*image);
1560 mogrify_image=FlipImage(*image,exception);
1561 break;
1562 }
anthonydf8ebac2011-04-27 09:03:19 +00001563 if (LocaleCompare("floodfill",option+1) == 0)
1564 {
cristy4c08aed2011-07-01 19:47:50 +00001565 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001566 target;
1567
1568 /*
1569 Floodfill image.
1570 */
1571 (void) SyncImageSettings(mogrify_info,*image);
1572 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1573 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001574 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
1575 geometry.y,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00001576 InheritException(exception,&(*image)->exception);
1577 break;
1578 }
anthony3d2f4862011-05-01 13:48:16 +00001579 if (LocaleCompare("flop",option+1) == 0)
1580 {
1581 /*
1582 Flop image scanlines.
1583 */
1584 (void) SyncImageSettings(mogrify_info,*image);
1585 mogrify_image=FlopImage(*image,exception);
1586 break;
1587 }
anthonydf8ebac2011-04-27 09:03:19 +00001588 if (LocaleCompare("font",option+1) == 0)
1589 {
1590 if (*option == '+')
1591 {
1592 if (draw_info->font != (char *) NULL)
1593 draw_info->font=DestroyString(draw_info->font);
1594 break;
1595 }
1596 (void) CloneString(&draw_info->font,argv[i+1]);
1597 break;
1598 }
1599 if (LocaleCompare("format",option+1) == 0)
1600 {
1601 format=argv[i+1];
1602 break;
1603 }
1604 if (LocaleCompare("frame",option+1) == 0)
1605 {
1606 FrameInfo
1607 frame_info;
1608
1609 /*
1610 Surround image with an ornamental border.
1611 */
1612 (void) SyncImageSettings(mogrify_info,*image);
1613 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1614 frame_info.width=geometry.width;
1615 frame_info.height=geometry.height;
1616 if ((flags & HeightValue) == 0)
1617 frame_info.height=geometry.width;
1618 frame_info.outer_bevel=geometry.x;
1619 frame_info.inner_bevel=geometry.y;
1620 frame_info.x=(ssize_t) frame_info.width;
1621 frame_info.y=(ssize_t) frame_info.height;
1622 frame_info.width=(*image)->columns+2*frame_info.width;
1623 frame_info.height=(*image)->rows+2*frame_info.height;
1624 mogrify_image=FrameImage(*image,&frame_info,exception);
1625 break;
1626 }
1627 if (LocaleCompare("function",option+1) == 0)
1628 {
1629 char
1630 *arguments,
1631 token[MaxTextExtent];
1632
1633 const char
1634 *p;
1635
1636 double
1637 *parameters;
1638
1639 MagickFunction
1640 function;
1641
1642 register ssize_t
1643 x;
1644
1645 size_t
1646 number_parameters;
1647
1648 /*
1649 Function Modify Image Values
1650 */
1651 (void) SyncImageSettings(mogrify_info,*image);
1652 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1653 MagickFalse,argv[i+1]);
1654 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1655 InheritException(exception,&(*image)->exception);
1656 if (arguments == (char *) NULL)
1657 break;
1658 p=(char *) arguments;
1659 for (x=0; *p != '\0'; x++)
1660 {
1661 GetMagickToken(p,&p,token);
1662 if (*token == ',')
1663 GetMagickToken(p,&p,token);
1664 }
1665 number_parameters=(size_t) x;
1666 parameters=(double *) AcquireQuantumMemory(number_parameters,
1667 sizeof(*parameters));
1668 if (parameters == (double *) NULL)
1669 ThrowWandFatalException(ResourceLimitFatalError,
1670 "MemoryAllocationFailed",(*image)->filename);
1671 (void) ResetMagickMemory(parameters,0,number_parameters*
1672 sizeof(*parameters));
1673 p=(char *) arguments;
1674 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1675 {
1676 GetMagickToken(p,&p,token);
1677 if (*token == ',')
1678 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001679 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001680 }
1681 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001682 (void) FunctionImage(*image,function,number_parameters,parameters,
1683 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001684 parameters=(double *) RelinquishMagickMemory(parameters);
1685 break;
1686 }
1687 break;
1688 }
1689 case 'g':
1690 {
1691 if (LocaleCompare("gamma",option+1) == 0)
1692 {
1693 /*
1694 Gamma image.
1695 */
1696 (void) SyncImageSettings(mogrify_info,*image);
1697 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001698 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001699 else
cristyb3e7c6c2011-07-24 01:43:55 +00001700 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1701 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001702 break;
1703 }
1704 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1705 (LocaleCompare("gaussian",option+1) == 0))
1706 {
1707 /*
1708 Gaussian blur image.
1709 */
1710 (void) SyncImageSettings(mogrify_info,*image);
1711 flags=ParseGeometry(argv[i+1],&geometry_info);
1712 if ((flags & SigmaValue) == 0)
1713 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001714 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1715 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001716 break;
1717 }
1718 if (LocaleCompare("geometry",option+1) == 0)
1719 {
1720 /*
1721 Record Image offset, Resize last image.
1722 */
1723 (void) SyncImageSettings(mogrify_info,*image);
1724 if (*option == '+')
1725 {
1726 if ((*image)->geometry != (char *) NULL)
1727 (*image)->geometry=DestroyString((*image)->geometry);
1728 break;
1729 }
1730 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1731 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1732 (void) CloneString(&(*image)->geometry,argv[i+1]);
1733 else
1734 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1735 (*image)->filter,(*image)->blur,exception);
1736 break;
1737 }
1738 if (LocaleCompare("gravity",option+1) == 0)
1739 {
1740 if (*option == '+')
1741 {
1742 draw_info->gravity=UndefinedGravity;
1743 break;
1744 }
1745 draw_info->gravity=(GravityType) ParseCommandOption(
1746 MagickGravityOptions,MagickFalse,argv[i+1]);
1747 break;
1748 }
1749 break;
1750 }
1751 case 'h':
1752 {
1753 if (LocaleCompare("highlight-color",option+1) == 0)
1754 {
1755 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1756 break;
1757 }
1758 break;
1759 }
1760 case 'i':
1761 {
1762 if (LocaleCompare("identify",option+1) == 0)
1763 {
1764 char
1765 *text;
1766
1767 (void) SyncImageSettings(mogrify_info,*image);
1768 if (format == (char *) NULL)
1769 {
1770 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1771 InheritException(exception,&(*image)->exception);
1772 break;
1773 }
1774 text=InterpretImageProperties(mogrify_info,*image,format);
1775 InheritException(exception,&(*image)->exception);
1776 if (text == (char *) NULL)
1777 break;
1778 (void) fputs(text,stdout);
1779 (void) fputc('\n',stdout);
1780 text=DestroyString(text);
1781 break;
1782 }
1783 if (LocaleCompare("implode",option+1) == 0)
1784 {
1785 /*
1786 Implode image.
1787 */
1788 (void) SyncImageSettings(mogrify_info,*image);
1789 (void) ParseGeometry(argv[i+1],&geometry_info);
1790 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1791 break;
1792 }
1793 if (LocaleCompare("interline-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->interline_spacing=geometry_info.rho;
1800 break;
1801 }
1802 if (LocaleCompare("interword-spacing",option+1) == 0)
1803 {
1804 if (*option == '+')
1805 (void) ParseGeometry("0",&geometry_info);
1806 else
1807 (void) ParseGeometry(argv[i+1],&geometry_info);
1808 draw_info->interword_spacing=geometry_info.rho;
1809 break;
1810 }
1811 break;
1812 }
1813 case 'k':
1814 {
1815 if (LocaleCompare("kerning",option+1) == 0)
1816 {
1817 if (*option == '+')
1818 (void) ParseGeometry("0",&geometry_info);
1819 else
1820 (void) ParseGeometry(argv[i+1],&geometry_info);
1821 draw_info->kerning=geometry_info.rho;
1822 break;
1823 }
1824 break;
1825 }
1826 case 'l':
1827 {
1828 if (LocaleCompare("lat",option+1) == 0)
1829 {
1830 /*
1831 Local adaptive threshold image.
1832 */
1833 (void) SyncImageSettings(mogrify_info,*image);
1834 flags=ParseGeometry(argv[i+1],&geometry_info);
1835 if ((flags & PercentValue) != 0)
1836 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1837 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001838 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001839 geometry_info.xi,exception);
1840 break;
1841 }
1842 if (LocaleCompare("level",option+1) == 0)
1843 {
1844 MagickRealType
1845 black_point,
1846 gamma,
1847 white_point;
1848
1849 MagickStatusType
1850 flags;
1851
1852 /*
1853 Parse levels.
1854 */
1855 (void) SyncImageSettings(mogrify_info,*image);
1856 flags=ParseGeometry(argv[i+1],&geometry_info);
1857 black_point=geometry_info.rho;
1858 white_point=(MagickRealType) QuantumRange;
1859 if ((flags & SigmaValue) != 0)
1860 white_point=geometry_info.sigma;
1861 gamma=1.0;
1862 if ((flags & XiValue) != 0)
1863 gamma=geometry_info.xi;
1864 if ((flags & PercentValue) != 0)
1865 {
1866 black_point*=(MagickRealType) (QuantumRange/100.0);
1867 white_point*=(MagickRealType) (QuantumRange/100.0);
1868 }
1869 if ((flags & SigmaValue) == 0)
1870 white_point=(MagickRealType) QuantumRange-black_point;
1871 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy50fbc382011-07-07 02:19:17 +00001872 (void) LevelizeImage(*image,black_point,white_point,gamma);
anthonydf8ebac2011-04-27 09:03:19 +00001873 else
cristy01e9afd2011-08-10 17:38:41 +00001874 (void) LevelImage(*image,black_point,white_point,gamma,
1875 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001876 InheritException(exception,&(*image)->exception);
1877 break;
1878 }
1879 if (LocaleCompare("level-colors",option+1) == 0)
1880 {
1881 char
1882 token[MaxTextExtent];
1883
1884 const char
1885 *p;
1886
cristy4c08aed2011-07-01 19:47:50 +00001887 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001888 black_point,
1889 white_point;
1890
1891 p=(const char *) argv[i+1];
1892 GetMagickToken(p,&p,token); /* get black point color */
1893 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1894 (void) QueryMagickColor(token,&black_point,exception);
1895 else
1896 (void) QueryMagickColor("#000000",&black_point,exception);
1897 if (isalpha((int) token[0]) || (token[0] == '#'))
1898 GetMagickToken(p,&p,token);
1899 if (*token == '\0')
1900 white_point=black_point; /* set everything to that color */
1901 else
1902 {
1903 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1904 GetMagickToken(p,&p,token); /* Get white point color. */
1905 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1906 (void) QueryMagickColor(token,&white_point,exception);
1907 else
1908 (void) QueryMagickColor("#ffffff",&white_point,exception);
1909 }
cristy490408a2011-07-07 14:42:05 +00001910 (void) LevelImageColors(*image,&black_point,&white_point,
1911 *option == '+' ? MagickTrue : MagickFalse);
anthonydf8ebac2011-04-27 09:03:19 +00001912 break;
1913 }
1914 if (LocaleCompare("linear-stretch",option+1) == 0)
1915 {
1916 double
1917 black_point,
1918 white_point;
1919
1920 MagickStatusType
1921 flags;
1922
1923 (void) SyncImageSettings(mogrify_info,*image);
1924 flags=ParseGeometry(argv[i+1],&geometry_info);
1925 black_point=geometry_info.rho;
1926 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1927 if ((flags & SigmaValue) != 0)
1928 white_point=geometry_info.sigma;
1929 if ((flags & PercentValue) != 0)
1930 {
1931 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1932 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1933 }
1934 if ((flags & SigmaValue) == 0)
1935 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1936 black_point;
1937 (void) LinearStretchImage(*image,black_point,white_point);
1938 InheritException(exception,&(*image)->exception);
1939 break;
1940 }
1941 if (LocaleCompare("linewidth",option+1) == 0)
1942 {
cristyc1acd842011-05-19 23:05:47 +00001943 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
1944 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001945 break;
1946 }
1947 if (LocaleCompare("liquid-rescale",option+1) == 0)
1948 {
1949 /*
1950 Liquid rescale image.
1951 */
1952 (void) SyncImageSettings(mogrify_info,*image);
1953 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1954 if ((flags & XValue) == 0)
1955 geometry.x=1;
1956 if ((flags & YValue) == 0)
1957 geometry.y=0;
1958 mogrify_image=LiquidRescaleImage(*image,geometry.width,
1959 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
1960 break;
1961 }
1962 if (LocaleCompare("lowlight-color",option+1) == 0)
1963 {
1964 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1965 break;
1966 }
1967 break;
1968 }
1969 case 'm':
1970 {
1971 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00001972 {
cristy3ed852e2009-09-05 21:47:34 +00001973 Image
anthonydf8ebac2011-04-27 09:03:19 +00001974 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00001975
anthonydf8ebac2011-04-27 09:03:19 +00001976 /*
1977 Transform image colors to match this set of colors.
1978 */
1979 (void) SyncImageSettings(mogrify_info,*image);
1980 if (*option == '+')
1981 break;
1982 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
1983 if (remap_image == (Image *) NULL)
1984 break;
1985 (void) RemapImage(quantize_info,*image,remap_image);
1986 InheritException(exception,&(*image)->exception);
1987 remap_image=DestroyImage(remap_image);
1988 break;
1989 }
1990 if (LocaleCompare("mask",option+1) == 0)
1991 {
1992 Image
1993 *mask;
1994
1995 (void) SyncImageSettings(mogrify_info,*image);
1996 if (*option == '+')
1997 {
1998 /*
1999 Remove a mask.
2000 */
2001 (void) SetImageMask(*image,(Image *) NULL);
2002 InheritException(exception,&(*image)->exception);
2003 break;
2004 }
2005 /*
2006 Set the image mask.
2007 */
2008 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2009 if (mask == (Image *) NULL)
2010 break;
2011 (void) SetImageMask(*image,mask);
2012 mask=DestroyImage(mask);
2013 InheritException(exception,&(*image)->exception);
2014 break;
2015 }
2016 if (LocaleCompare("matte",option+1) == 0)
2017 {
2018 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002019 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002020 break;
2021 }
2022 if (LocaleCompare("median",option+1) == 0)
2023 {
2024 /*
2025 Median filter 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,MedianStatistic,(size_t)
2030 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002031 break;
2032 }
2033 if (LocaleCompare("mode",option+1) == 0)
2034 {
2035 /*
2036 Mode image.
2037 */
2038 (void) SyncImageSettings(mogrify_info,*image);
2039 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002040 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2041 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002042 break;
2043 }
2044 if (LocaleCompare("modulate",option+1) == 0)
2045 {
2046 (void) SyncImageSettings(mogrify_info,*image);
2047 (void) ModulateImage(*image,argv[i+1]);
2048 InheritException(exception,&(*image)->exception);
2049 break;
2050 }
2051 if (LocaleCompare("monitor",option+1) == 0)
2052 {
2053 if (*option == '+')
2054 {
2055 (void) SetImageProgressMonitor(*image,
2056 (MagickProgressMonitor) NULL,(void *) NULL);
2057 break;
2058 }
2059 (void) SetImageProgressMonitor(*image,MonitorProgress,
2060 (void *) NULL);
2061 break;
2062 }
2063 if (LocaleCompare("monochrome",option+1) == 0)
2064 {
2065 (void) SyncImageSettings(mogrify_info,*image);
2066 (void) SetImageType(*image,BilevelType);
2067 InheritException(exception,&(*image)->exception);
2068 break;
2069 }
2070 if (LocaleCompare("morphology",option+1) == 0)
2071 {
2072 char
2073 token[MaxTextExtent];
2074
2075 const char
2076 *p;
2077
2078 KernelInfo
2079 *kernel;
2080
2081 MorphologyMethod
2082 method;
2083
2084 ssize_t
2085 iterations;
2086
2087 /*
2088 Morphological Image Operation
2089 */
2090 (void) SyncImageSettings(mogrify_info,*image);
2091 p=argv[i+1];
2092 GetMagickToken(p,&p,token);
2093 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2094 MagickFalse,token);
2095 iterations=1L;
2096 GetMagickToken(p,&p,token);
2097 if ((*p == ':') || (*p == ','))
2098 GetMagickToken(p,&p,token);
2099 if ((*p != '\0'))
2100 iterations=(ssize_t) StringToLong(p);
2101 kernel=AcquireKernelInfo(argv[i+2]);
2102 if (kernel == (KernelInfo *) NULL)
2103 {
2104 (void) ThrowMagickException(exception,GetMagickModule(),
2105 OptionError,"UnabletoParseKernel","morphology");
2106 status=MagickFalse;
2107 break;
2108 }
cristyf4ad9df2011-07-08 16:49:03 +00002109 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2110 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002111 kernel=DestroyKernelInfo(kernel);
2112 break;
2113 }
2114 if (LocaleCompare("motion-blur",option+1) == 0)
2115 {
2116 /*
2117 Motion blur image.
2118 */
2119 (void) SyncImageSettings(mogrify_info,*image);
2120 flags=ParseGeometry(argv[i+1],&geometry_info);
2121 if ((flags & SigmaValue) == 0)
2122 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002123 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2124 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002125 break;
2126 }
2127 break;
2128 }
2129 case 'n':
2130 {
2131 if (LocaleCompare("negate",option+1) == 0)
2132 {
2133 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002134 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002135 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002136 break;
2137 }
2138 if (LocaleCompare("noise",option+1) == 0)
2139 {
2140 (void) SyncImageSettings(mogrify_info,*image);
2141 if (*option == '-')
2142 {
2143 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002144 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2145 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002146 }
2147 else
2148 {
2149 NoiseType
2150 noise;
2151
2152 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2153 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002154 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002155 }
2156 break;
2157 }
2158 if (LocaleCompare("normalize",option+1) == 0)
2159 {
2160 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002161 (void) NormalizeImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00002162 InheritException(exception,&(*image)->exception);
2163 break;
2164 }
2165 break;
2166 }
2167 case 'o':
2168 {
2169 if (LocaleCompare("opaque",option+1) == 0)
2170 {
cristy4c08aed2011-07-01 19:47:50 +00002171 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002172 target;
2173
2174 (void) SyncImageSettings(mogrify_info,*image);
2175 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002176 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2177 MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002178 break;
2179 }
2180 if (LocaleCompare("ordered-dither",option+1) == 0)
2181 {
2182 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002183 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002184 break;
2185 }
2186 break;
2187 }
2188 case 'p':
2189 {
2190 if (LocaleCompare("paint",option+1) == 0)
2191 {
anthonydf8ebac2011-04-27 09:03:19 +00002192 (void) SyncImageSettings(mogrify_info,*image);
2193 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002194 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002195 break;
2196 }
2197 if (LocaleCompare("pen",option+1) == 0)
2198 {
2199 if (*option == '+')
2200 {
2201 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2202 break;
2203 }
2204 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2205 break;
2206 }
2207 if (LocaleCompare("pointsize",option+1) == 0)
2208 {
2209 if (*option == '+')
2210 (void) ParseGeometry("12",&geometry_info);
2211 else
2212 (void) ParseGeometry(argv[i+1],&geometry_info);
2213 draw_info->pointsize=geometry_info.rho;
2214 break;
2215 }
2216 if (LocaleCompare("polaroid",option+1) == 0)
2217 {
2218 double
2219 angle;
2220
2221 RandomInfo
2222 *random_info;
2223
2224 /*
2225 Simulate a Polaroid picture.
2226 */
2227 (void) SyncImageSettings(mogrify_info,*image);
2228 random_info=AcquireRandomInfo();
2229 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2230 random_info=DestroyRandomInfo(random_info);
2231 if (*option == '-')
2232 {
2233 SetGeometryInfo(&geometry_info);
2234 flags=ParseGeometry(argv[i+1],&geometry_info);
2235 angle=geometry_info.rho;
2236 }
2237 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2238 break;
2239 }
2240 if (LocaleCompare("posterize",option+1) == 0)
2241 {
2242 /*
2243 Posterize image.
2244 */
2245 (void) SyncImageSettings(mogrify_info,*image);
2246 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2247 quantize_info->dither);
2248 InheritException(exception,&(*image)->exception);
2249 break;
2250 }
2251 if (LocaleCompare("preview",option+1) == 0)
2252 {
2253 PreviewType
2254 preview_type;
2255
2256 /*
2257 Preview image.
2258 */
2259 (void) SyncImageSettings(mogrify_info,*image);
2260 if (*option == '+')
2261 preview_type=UndefinedPreview;
2262 else
2263 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2264 MagickFalse,argv[i+1]);
2265 mogrify_image=PreviewImage(*image,preview_type,exception);
2266 break;
2267 }
2268 if (LocaleCompare("profile",option+1) == 0)
2269 {
2270 const char
2271 *name;
2272
2273 const StringInfo
2274 *profile;
2275
2276 Image
2277 *profile_image;
2278
2279 ImageInfo
2280 *profile_info;
2281
2282 (void) SyncImageSettings(mogrify_info,*image);
2283 if (*option == '+')
2284 {
2285 /*
2286 Remove a profile from the image.
2287 */
2288 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2289 NULL,0,MagickTrue);
2290 InheritException(exception,&(*image)->exception);
2291 break;
2292 }
2293 /*
2294 Associate a profile with the image.
2295 */
2296 profile_info=CloneImageInfo(mogrify_info);
2297 profile=GetImageProfile(*image,"iptc");
2298 if (profile != (StringInfo *) NULL)
2299 profile_info->profile=(void *) CloneStringInfo(profile);
2300 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2301 profile_info=DestroyImageInfo(profile_info);
2302 if (profile_image == (Image *) NULL)
2303 {
2304 StringInfo
2305 *profile;
2306
2307 profile_info=CloneImageInfo(mogrify_info);
2308 (void) CopyMagickString(profile_info->filename,argv[i+1],
2309 MaxTextExtent);
2310 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2311 if (profile != (StringInfo *) NULL)
2312 {
2313 (void) ProfileImage(*image,profile_info->magick,
2314 GetStringInfoDatum(profile),(size_t)
2315 GetStringInfoLength(profile),MagickFalse);
2316 profile=DestroyStringInfo(profile);
2317 }
2318 profile_info=DestroyImageInfo(profile_info);
2319 break;
2320 }
2321 ResetImageProfileIterator(profile_image);
2322 name=GetNextImageProfile(profile_image);
2323 while (name != (const char *) NULL)
2324 {
2325 profile=GetImageProfile(profile_image,name);
2326 if (profile != (StringInfo *) NULL)
2327 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2328 (size_t) GetStringInfoLength(profile),MagickFalse);
2329 name=GetNextImageProfile(profile_image);
2330 }
2331 profile_image=DestroyImage(profile_image);
2332 break;
2333 }
2334 break;
2335 }
2336 case 'q':
2337 {
2338 if (LocaleCompare("quantize",option+1) == 0)
2339 {
2340 if (*option == '+')
2341 {
2342 quantize_info->colorspace=UndefinedColorspace;
2343 break;
2344 }
2345 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2346 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2347 break;
2348 }
2349 break;
2350 }
2351 case 'r':
2352 {
2353 if (LocaleCompare("radial-blur",option+1) == 0)
2354 {
2355 /*
2356 Radial blur image.
2357 */
2358 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002359 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2360 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002361 break;
2362 }
2363 if (LocaleCompare("raise",option+1) == 0)
2364 {
2365 /*
2366 Surround image with a raise of solid color.
2367 */
2368 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2369 if ((flags & SigmaValue) == 0)
2370 geometry.height=geometry.width;
2371 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2372 MagickFalse);
2373 InheritException(exception,&(*image)->exception);
2374 break;
2375 }
2376 if (LocaleCompare("random-threshold",option+1) == 0)
2377 {
2378 /*
2379 Threshold image.
2380 */
2381 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002382 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002383 break;
2384 }
2385 if (LocaleCompare("recolor",option+1) == 0)
2386 {
2387 KernelInfo
2388 *kernel;
2389
2390 (void) SyncImageSettings(mogrify_info,*image);
2391 kernel=AcquireKernelInfo(argv[i+1]);
2392 if (kernel == (KernelInfo *) NULL)
2393 break;
2394 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2395 kernel=DestroyKernelInfo(kernel);
2396 break;
2397 }
2398 if (LocaleCompare("region",option+1) == 0)
2399 {
2400 (void) SyncImageSettings(mogrify_info,*image);
2401 if (region_image != (Image *) NULL)
2402 {
2403 /*
2404 Composite region.
2405 */
2406 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002407 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2408 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002409 InheritException(exception,&region_image->exception);
2410 *image=DestroyImage(*image);
2411 *image=region_image;
2412 region_image = (Image *) NULL;
2413 }
2414 if (*option == '+')
2415 break;
2416 /*
2417 Apply transformations to a selected region of the image.
2418 */
cristy3ed852e2009-09-05 21:47:34 +00002419 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2420 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002421 mogrify_image=CropImage(*image,&region_geometry,exception);
2422 if (mogrify_image == (Image *) NULL)
2423 break;
2424 region_image=(*image);
2425 *image=mogrify_image;
2426 mogrify_image=(Image *) NULL;
2427 break;
cristy3ed852e2009-09-05 21:47:34 +00002428 }
anthonydf8ebac2011-04-27 09:03:19 +00002429 if (LocaleCompare("render",option+1) == 0)
2430 {
2431 (void) SyncImageSettings(mogrify_info,*image);
2432 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2433 break;
2434 }
2435 if (LocaleCompare("remap",option+1) == 0)
2436 {
2437 Image
2438 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002439
anthonydf8ebac2011-04-27 09:03:19 +00002440 /*
2441 Transform image colors to match this set of colors.
2442 */
2443 (void) SyncImageSettings(mogrify_info,*image);
2444 if (*option == '+')
2445 break;
2446 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2447 if (remap_image == (Image *) NULL)
2448 break;
2449 (void) RemapImage(quantize_info,*image,remap_image);
2450 InheritException(exception,&(*image)->exception);
2451 remap_image=DestroyImage(remap_image);
2452 break;
2453 }
2454 if (LocaleCompare("repage",option+1) == 0)
2455 {
2456 if (*option == '+')
2457 {
2458 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2459 break;
2460 }
2461 (void) ResetImagePage(*image,argv[i+1]);
2462 InheritException(exception,&(*image)->exception);
2463 break;
2464 }
2465 if (LocaleCompare("resample",option+1) == 0)
2466 {
2467 /*
2468 Resample image.
2469 */
2470 (void) SyncImageSettings(mogrify_info,*image);
2471 flags=ParseGeometry(argv[i+1],&geometry_info);
2472 if ((flags & SigmaValue) == 0)
2473 geometry_info.sigma=geometry_info.rho;
2474 mogrify_image=ResampleImage(*image,geometry_info.rho,
2475 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2476 break;
2477 }
2478 if (LocaleCompare("resize",option+1) == 0)
2479 {
2480 /*
2481 Resize image.
2482 */
2483 (void) SyncImageSettings(mogrify_info,*image);
2484 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2485 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2486 (*image)->filter,(*image)->blur,exception);
2487 break;
2488 }
2489 if (LocaleCompare("roll",option+1) == 0)
2490 {
2491 /*
2492 Roll image.
2493 */
2494 (void) SyncImageSettings(mogrify_info,*image);
2495 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2496 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2497 break;
2498 }
2499 if (LocaleCompare("rotate",option+1) == 0)
2500 {
2501 char
2502 *geometry;
2503
2504 /*
2505 Check for conditional image rotation.
2506 */
2507 (void) SyncImageSettings(mogrify_info,*image);
2508 if (strchr(argv[i+1],'>') != (char *) NULL)
2509 if ((*image)->columns <= (*image)->rows)
2510 break;
2511 if (strchr(argv[i+1],'<') != (char *) NULL)
2512 if ((*image)->columns >= (*image)->rows)
2513 break;
2514 /*
2515 Rotate image.
2516 */
2517 geometry=ConstantString(argv[i+1]);
2518 (void) SubstituteString(&geometry,">","");
2519 (void) SubstituteString(&geometry,"<","");
2520 (void) ParseGeometry(geometry,&geometry_info);
2521 geometry=DestroyString(geometry);
2522 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2523 break;
2524 }
2525 break;
2526 }
2527 case 's':
2528 {
2529 if (LocaleCompare("sample",option+1) == 0)
2530 {
2531 /*
2532 Sample image with pixel replication.
2533 */
2534 (void) SyncImageSettings(mogrify_info,*image);
2535 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2536 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2537 exception);
2538 break;
2539 }
2540 if (LocaleCompare("scale",option+1) == 0)
2541 {
2542 /*
2543 Resize image.
2544 */
2545 (void) SyncImageSettings(mogrify_info,*image);
2546 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2547 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2548 exception);
2549 break;
2550 }
2551 if (LocaleCompare("selective-blur",option+1) == 0)
2552 {
2553 /*
2554 Selectively blur pixels within a contrast threshold.
2555 */
2556 (void) SyncImageSettings(mogrify_info,*image);
2557 flags=ParseGeometry(argv[i+1],&geometry_info);
2558 if ((flags & PercentValue) != 0)
2559 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002560 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2561 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002562 break;
2563 }
2564 if (LocaleCompare("separate",option+1) == 0)
2565 {
2566 /*
2567 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002568 */
2569 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002570 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002571 break;
2572 }
2573 if (LocaleCompare("sepia-tone",option+1) == 0)
2574 {
2575 double
2576 threshold;
2577
2578 /*
2579 Sepia-tone image.
2580 */
2581 (void) SyncImageSettings(mogrify_info,*image);
2582 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2583 mogrify_image=SepiaToneImage(*image,threshold,exception);
2584 break;
2585 }
2586 if (LocaleCompare("segment",option+1) == 0)
2587 {
2588 /*
2589 Segment image.
2590 */
2591 (void) SyncImageSettings(mogrify_info,*image);
2592 flags=ParseGeometry(argv[i+1],&geometry_info);
2593 if ((flags & SigmaValue) == 0)
2594 geometry_info.sigma=1.0;
2595 (void) SegmentImage(*image,(*image)->colorspace,
2596 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2597 InheritException(exception,&(*image)->exception);
2598 break;
2599 }
2600 if (LocaleCompare("set",option+1) == 0)
2601 {
2602 char
2603 *value;
2604
2605 /*
2606 Set image option.
2607 */
2608 if (*option == '+')
2609 {
2610 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2611 (void) DeleteImageRegistry(argv[i+1]+9);
2612 else
2613 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2614 {
2615 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2616 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2617 }
2618 else
2619 (void) DeleteImageProperty(*image,argv[i+1]);
2620 break;
2621 }
2622 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2623 if (value == (char *) NULL)
2624 break;
2625 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2626 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2627 exception);
2628 else
2629 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2630 {
2631 (void) SetImageOption(image_info,argv[i+1]+7,value);
2632 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2633 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2634 }
2635 else
2636 (void) SetImageProperty(*image,argv[i+1],value);
2637 value=DestroyString(value);
2638 break;
2639 }
2640 if (LocaleCompare("shade",option+1) == 0)
2641 {
2642 /*
2643 Shade image.
2644 */
2645 (void) SyncImageSettings(mogrify_info,*image);
2646 flags=ParseGeometry(argv[i+1],&geometry_info);
2647 if ((flags & SigmaValue) == 0)
2648 geometry_info.sigma=1.0;
2649 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2650 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2651 break;
2652 }
2653 if (LocaleCompare("shadow",option+1) == 0)
2654 {
2655 /*
2656 Shadow image.
2657 */
2658 (void) SyncImageSettings(mogrify_info,*image);
2659 flags=ParseGeometry(argv[i+1],&geometry_info);
2660 if ((flags & SigmaValue) == 0)
2661 geometry_info.sigma=1.0;
2662 if ((flags & XiValue) == 0)
2663 geometry_info.xi=4.0;
2664 if ((flags & PsiValue) == 0)
2665 geometry_info.psi=4.0;
2666 mogrify_image=ShadowImage(*image,geometry_info.rho,
2667 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2668 ceil(geometry_info.psi-0.5),exception);
2669 break;
2670 }
2671 if (LocaleCompare("sharpen",option+1) == 0)
2672 {
2673 /*
2674 Sharpen image.
2675 */
2676 (void) SyncImageSettings(mogrify_info,*image);
2677 flags=ParseGeometry(argv[i+1],&geometry_info);
2678 if ((flags & SigmaValue) == 0)
2679 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002680 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002681 geometry_info.sigma,exception);
2682 break;
2683 }
2684 if (LocaleCompare("shave",option+1) == 0)
2685 {
2686 /*
2687 Shave the image edges.
2688 */
2689 (void) SyncImageSettings(mogrify_info,*image);
2690 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2691 mogrify_image=ShaveImage(*image,&geometry,exception);
2692 break;
2693 }
2694 if (LocaleCompare("shear",option+1) == 0)
2695 {
2696 /*
2697 Shear image.
2698 */
2699 (void) SyncImageSettings(mogrify_info,*image);
2700 flags=ParseGeometry(argv[i+1],&geometry_info);
2701 if ((flags & SigmaValue) == 0)
2702 geometry_info.sigma=geometry_info.rho;
2703 mogrify_image=ShearImage(*image,geometry_info.rho,
2704 geometry_info.sigma,exception);
2705 break;
2706 }
2707 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2708 {
2709 /*
2710 Sigmoidal non-linearity contrast control.
2711 */
2712 (void) SyncImageSettings(mogrify_info,*image);
2713 flags=ParseGeometry(argv[i+1],&geometry_info);
2714 if ((flags & SigmaValue) == 0)
2715 geometry_info.sigma=(double) QuantumRange/2.0;
2716 if ((flags & PercentValue) != 0)
2717 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2718 100.0;
cristy9ee60942011-07-06 14:54:38 +00002719 (void) SigmoidalContrastImage(*image,(*option == '-') ?
2720 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma);
anthonydf8ebac2011-04-27 09:03:19 +00002721 InheritException(exception,&(*image)->exception);
2722 break;
2723 }
2724 if (LocaleCompare("sketch",option+1) == 0)
2725 {
2726 /*
2727 Sketch image.
2728 */
2729 (void) SyncImageSettings(mogrify_info,*image);
2730 flags=ParseGeometry(argv[i+1],&geometry_info);
2731 if ((flags & SigmaValue) == 0)
2732 geometry_info.sigma=1.0;
2733 mogrify_image=SketchImage(*image,geometry_info.rho,
2734 geometry_info.sigma,geometry_info.xi,exception);
2735 break;
2736 }
2737 if (LocaleCompare("solarize",option+1) == 0)
2738 {
2739 double
2740 threshold;
2741
2742 (void) SyncImageSettings(mogrify_info,*image);
2743 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2744 (void) SolarizeImage(*image,threshold);
2745 InheritException(exception,&(*image)->exception);
2746 break;
2747 }
2748 if (LocaleCompare("sparse-color",option+1) == 0)
2749 {
2750 SparseColorMethod
2751 method;
2752
2753 char
2754 *arguments;
2755
2756 /*
2757 Sparse Color Interpolated Gradient
2758 */
2759 (void) SyncImageSettings(mogrify_info,*image);
2760 method=(SparseColorMethod) ParseCommandOption(
2761 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2762 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2763 InheritException(exception,&(*image)->exception);
2764 if (arguments == (char *) NULL)
2765 break;
cristy3884f692011-07-08 18:00:18 +00002766 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002767 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2768 arguments=DestroyString(arguments);
2769 break;
2770 }
2771 if (LocaleCompare("splice",option+1) == 0)
2772 {
2773 /*
2774 Splice a solid color into the image.
2775 */
2776 (void) SyncImageSettings(mogrify_info,*image);
2777 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2778 mogrify_image=SpliceImage(*image,&geometry,exception);
2779 break;
2780 }
2781 if (LocaleCompare("spread",option+1) == 0)
2782 {
2783 /*
2784 Spread an image.
2785 */
2786 (void) SyncImageSettings(mogrify_info,*image);
2787 (void) ParseGeometry(argv[i+1],&geometry_info);
2788 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2789 break;
2790 }
2791 if (LocaleCompare("statistic",option+1) == 0)
2792 {
2793 StatisticType
2794 type;
2795
2796 (void) SyncImageSettings(mogrify_info,*image);
2797 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2798 MagickFalse,argv[i+1]);
2799 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002800 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2801 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002802 break;
2803 }
2804 if (LocaleCompare("stretch",option+1) == 0)
2805 {
2806 if (*option == '+')
2807 {
2808 draw_info->stretch=UndefinedStretch;
2809 break;
2810 }
2811 draw_info->stretch=(StretchType) ParseCommandOption(
2812 MagickStretchOptions,MagickFalse,argv[i+1]);
2813 break;
2814 }
2815 if (LocaleCompare("strip",option+1) == 0)
2816 {
2817 /*
2818 Strip image of profiles and comments.
2819 */
2820 (void) SyncImageSettings(mogrify_info,*image);
2821 (void) StripImage(*image);
2822 InheritException(exception,&(*image)->exception);
2823 break;
2824 }
2825 if (LocaleCompare("stroke",option+1) == 0)
2826 {
2827 ExceptionInfo
2828 *sans;
2829
2830 if (*option == '+')
2831 {
2832 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2833 if (draw_info->stroke_pattern != (Image *) NULL)
2834 draw_info->stroke_pattern=DestroyImage(
2835 draw_info->stroke_pattern);
2836 break;
2837 }
2838 sans=AcquireExceptionInfo();
2839 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2840 sans=DestroyExceptionInfo(sans);
2841 if (status == MagickFalse)
2842 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2843 exception);
2844 break;
2845 }
2846 if (LocaleCompare("strokewidth",option+1) == 0)
2847 {
cristyc1acd842011-05-19 23:05:47 +00002848 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2849 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002850 break;
2851 }
2852 if (LocaleCompare("style",option+1) == 0)
2853 {
2854 if (*option == '+')
2855 {
2856 draw_info->style=UndefinedStyle;
2857 break;
2858 }
2859 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2860 MagickFalse,argv[i+1]);
2861 break;
2862 }
2863 if (LocaleCompare("swirl",option+1) == 0)
2864 {
2865 /*
2866 Swirl image.
2867 */
2868 (void) SyncImageSettings(mogrify_info,*image);
2869 (void) ParseGeometry(argv[i+1],&geometry_info);
2870 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2871 break;
2872 }
2873 break;
2874 }
2875 case 't':
2876 {
2877 if (LocaleCompare("threshold",option+1) == 0)
2878 {
2879 double
2880 threshold;
2881
2882 /*
2883 Threshold image.
2884 */
2885 (void) SyncImageSettings(mogrify_info,*image);
2886 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002887 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002888 else
2889 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002890 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002891 InheritException(exception,&(*image)->exception);
2892 break;
2893 }
2894 if (LocaleCompare("thumbnail",option+1) == 0)
2895 {
2896 /*
2897 Thumbnail image.
2898 */
2899 (void) SyncImageSettings(mogrify_info,*image);
2900 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2901 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2902 exception);
2903 break;
2904 }
2905 if (LocaleCompare("tile",option+1) == 0)
2906 {
2907 if (*option == '+')
2908 {
2909 if (draw_info->fill_pattern != (Image *) NULL)
2910 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2911 break;
2912 }
2913 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2914 exception);
2915 break;
2916 }
2917 if (LocaleCompare("tint",option+1) == 0)
2918 {
2919 /*
2920 Tint the image.
2921 */
2922 (void) SyncImageSettings(mogrify_info,*image);
2923 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2924 break;
2925 }
2926 if (LocaleCompare("transform",option+1) == 0)
2927 {
2928 /*
2929 Affine transform image.
2930 */
2931 (void) SyncImageSettings(mogrify_info,*image);
2932 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2933 exception);
2934 break;
2935 }
2936 if (LocaleCompare("transparent",option+1) == 0)
2937 {
cristy4c08aed2011-07-01 19:47:50 +00002938 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002939 target;
2940
2941 (void) SyncImageSettings(mogrify_info,*image);
2942 (void) QueryMagickColor(argv[i+1],&target,exception);
2943 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002944 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002945 InheritException(exception,&(*image)->exception);
2946 break;
2947 }
2948 if (LocaleCompare("transpose",option+1) == 0)
2949 {
2950 /*
2951 Transpose image scanlines.
2952 */
2953 (void) SyncImageSettings(mogrify_info,*image);
2954 mogrify_image=TransposeImage(*image,exception);
2955 break;
2956 }
2957 if (LocaleCompare("transverse",option+1) == 0)
2958 {
2959 /*
2960 Transverse image scanlines.
2961 */
2962 (void) SyncImageSettings(mogrify_info,*image);
2963 mogrify_image=TransverseImage(*image,exception);
2964 break;
2965 }
2966 if (LocaleCompare("treedepth",option+1) == 0)
2967 {
2968 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2969 break;
2970 }
2971 if (LocaleCompare("trim",option+1) == 0)
2972 {
2973 /*
2974 Trim image.
2975 */
2976 (void) SyncImageSettings(mogrify_info,*image);
2977 mogrify_image=TrimImage(*image,exception);
2978 break;
2979 }
2980 if (LocaleCompare("type",option+1) == 0)
2981 {
2982 ImageType
2983 type;
2984
2985 (void) SyncImageSettings(mogrify_info,*image);
2986 if (*option == '+')
2987 type=UndefinedType;
2988 else
2989 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2990 argv[i+1]);
2991 (*image)->type=UndefinedType;
2992 (void) SetImageType(*image,type);
2993 InheritException(exception,&(*image)->exception);
2994 break;
2995 }
2996 break;
2997 }
2998 case 'u':
2999 {
3000 if (LocaleCompare("undercolor",option+1) == 0)
3001 {
3002 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3003 exception);
3004 break;
3005 }
3006 if (LocaleCompare("unique",option+1) == 0)
3007 {
3008 if (*option == '+')
3009 {
3010 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3011 break;
3012 }
3013 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3014 (void) SetImageArtifact(*image,"verbose","true");
3015 break;
3016 }
3017 if (LocaleCompare("unique-colors",option+1) == 0)
3018 {
3019 /*
3020 Unique image colors.
3021 */
3022 (void) SyncImageSettings(mogrify_info,*image);
3023 mogrify_image=UniqueImageColors(*image,exception);
3024 break;
3025 }
3026 if (LocaleCompare("unsharp",option+1) == 0)
3027 {
3028 /*
3029 Unsharp mask image.
3030 */
3031 (void) SyncImageSettings(mogrify_info,*image);
3032 flags=ParseGeometry(argv[i+1],&geometry_info);
3033 if ((flags & SigmaValue) == 0)
3034 geometry_info.sigma=1.0;
3035 if ((flags & XiValue) == 0)
3036 geometry_info.xi=1.0;
3037 if ((flags & PsiValue) == 0)
3038 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003039 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3040 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003041 break;
3042 }
3043 break;
3044 }
3045 case 'v':
3046 {
3047 if (LocaleCompare("verbose",option+1) == 0)
3048 {
3049 (void) SetImageArtifact(*image,option+1,
3050 *option == '+' ? "false" : "true");
3051 break;
3052 }
3053 if (LocaleCompare("vignette",option+1) == 0)
3054 {
3055 /*
3056 Vignette image.
3057 */
3058 (void) SyncImageSettings(mogrify_info,*image);
3059 flags=ParseGeometry(argv[i+1],&geometry_info);
3060 if ((flags & SigmaValue) == 0)
3061 geometry_info.sigma=1.0;
3062 if ((flags & XiValue) == 0)
3063 geometry_info.xi=0.1*(*image)->columns;
3064 if ((flags & PsiValue) == 0)
3065 geometry_info.psi=0.1*(*image)->rows;
3066 mogrify_image=VignetteImage(*image,geometry_info.rho,
3067 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3068 ceil(geometry_info.psi-0.5),exception);
3069 break;
3070 }
3071 if (LocaleCompare("virtual-pixel",option+1) == 0)
3072 {
3073 if (*option == '+')
3074 {
3075 (void) SetImageVirtualPixelMethod(*image,
3076 UndefinedVirtualPixelMethod);
3077 break;
3078 }
3079 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3080 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3081 argv[i+1]));
3082 break;
3083 }
3084 break;
3085 }
3086 case 'w':
3087 {
3088 if (LocaleCompare("wave",option+1) == 0)
3089 {
3090 /*
3091 Wave image.
3092 */
3093 (void) SyncImageSettings(mogrify_info,*image);
3094 flags=ParseGeometry(argv[i+1],&geometry_info);
3095 if ((flags & SigmaValue) == 0)
3096 geometry_info.sigma=1.0;
3097 mogrify_image=WaveImage(*image,geometry_info.rho,
3098 geometry_info.sigma,exception);
3099 break;
3100 }
3101 if (LocaleCompare("weight",option+1) == 0)
3102 {
3103 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3104 if (LocaleCompare(argv[i+1],"all") == 0)
3105 draw_info->weight=0;
3106 if (LocaleCompare(argv[i+1],"bold") == 0)
3107 draw_info->weight=700;
3108 if (LocaleCompare(argv[i+1],"bolder") == 0)
3109 if (draw_info->weight <= 800)
3110 draw_info->weight+=100;
3111 if (LocaleCompare(argv[i+1],"lighter") == 0)
3112 if (draw_info->weight >= 100)
3113 draw_info->weight-=100;
3114 if (LocaleCompare(argv[i+1],"normal") == 0)
3115 draw_info->weight=400;
3116 break;
3117 }
3118 if (LocaleCompare("white-threshold",option+1) == 0)
3119 {
3120 /*
3121 White threshold image.
3122 */
3123 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003124 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003125 InheritException(exception,&(*image)->exception);
3126 break;
3127 }
3128 break;
3129 }
3130 default:
3131 break;
3132 }
3133 /*
3134 Replace current image with any image that was generated
3135 */
3136 if (mogrify_image != (Image *) NULL)
3137 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003138 i+=count;
3139 }
3140 if (region_image != (Image *) NULL)
3141 {
anthonydf8ebac2011-04-27 09:03:19 +00003142 /*
3143 Composite transformed region onto image.
3144 */
cristy6b3da3a2010-06-20 02:21:46 +00003145 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003146 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003147 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3148 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003149 InheritException(exception,&region_image->exception);
3150 *image=DestroyImage(*image);
3151 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003152 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003153 }
3154 /*
3155 Free resources.
3156 */
anthonydf8ebac2011-04-27 09:03:19 +00003157 quantize_info=DestroyQuantizeInfo(quantize_info);
3158 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003159 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003160 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003161 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003162 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003163}
3164
3165/*
3166%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3167% %
3168% %
3169% %
cristy5063d812010-10-19 16:28:10 +00003170+ 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 +00003171% %
3172% %
3173% %
3174%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3175%
3176% MogrifyImageCommand() transforms an image or a sequence of images. These
3177% transforms include image scaling, image rotation, color reduction, and
3178% others. The transmogrified image overwrites the original image.
3179%
3180% The format of the MogrifyImageCommand method is:
3181%
3182% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3183% const char **argv,char **metadata,ExceptionInfo *exception)
3184%
3185% A description of each parameter follows:
3186%
3187% o image_info: the image info.
3188%
3189% o argc: the number of elements in the argument vector.
3190%
3191% o argv: A text array containing the command line arguments.
3192%
3193% o metadata: any metadata is returned here.
3194%
3195% o exception: return any errors or warnings in this structure.
3196%
3197*/
3198
3199static MagickBooleanType MogrifyUsage(void)
3200{
3201 static const char
3202 *miscellaneous[]=
3203 {
3204 "-debug events display copious debugging information",
3205 "-help print program options",
3206 "-list type print a list of supported option arguments",
3207 "-log format format of debugging information",
3208 "-version print version information",
3209 (char *) NULL
3210 },
3211 *operators[]=
3212 {
3213 "-adaptive-blur geometry",
3214 " adaptively blur pixels; decrease effect near edges",
3215 "-adaptive-resize geometry",
3216 " adaptively resize image using 'mesh' interpolation",
3217 "-adaptive-sharpen geometry",
3218 " adaptively sharpen pixels; increase effect near edges",
3219 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3220 " transparent, extract, background, or shape",
3221 "-annotate geometry text",
3222 " annotate the image with text",
3223 "-auto-gamma automagically adjust gamma level of image",
3224 "-auto-level automagically adjust color levels of image",
3225 "-auto-orient automagically orient (rotate) image",
3226 "-bench iterations measure performance",
3227 "-black-threshold value",
3228 " force all pixels below the threshold into black",
3229 "-blue-shift simulate a scene at nighttime in the moonlight",
3230 "-blur geometry reduce image noise and reduce detail levels",
3231 "-border geometry surround image with a border of color",
3232 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003233 "-brightness-contrast geometry",
3234 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003235 "-cdl filename color correct with a color decision list",
3236 "-charcoal radius simulate a charcoal drawing",
3237 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003238 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003239 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003240 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003241 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003242 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003243 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003244 "-contrast enhance or reduce the image contrast",
3245 "-contrast-stretch geometry",
3246 " improve contrast by `stretching' the intensity range",
3247 "-convolve coefficients",
3248 " apply a convolution kernel to the image",
3249 "-cycle amount cycle the image colormap",
3250 "-decipher filename convert cipher pixels to plain pixels",
3251 "-deskew threshold straighten an image",
3252 "-despeckle reduce the speckles within an image",
3253 "-distort method args",
3254 " distort images according to given method ad args",
3255 "-draw string annotate the image with a graphic primitive",
3256 "-edge radius apply a filter to detect edges in the image",
3257 "-encipher filename convert plain pixels to cipher pixels",
3258 "-emboss radius emboss an image",
3259 "-enhance apply a digital filter to enhance a noisy image",
3260 "-equalize perform histogram equalization to an image",
3261 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003262 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003263 "-extent geometry set the image size",
3264 "-extract geometry extract area from image",
3265 "-fft implements the discrete Fourier transform (DFT)",
3266 "-flip flip image vertically",
3267 "-floodfill geometry color",
3268 " floodfill the image with color",
3269 "-flop flop image horizontally",
3270 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003271 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003272 " apply function over image values",
3273 "-gamma value level of gamma correction",
3274 "-gaussian-blur geometry",
3275 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003276 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003277 "-identify identify the format and characteristics of the image",
3278 "-ift implements the inverse discrete Fourier transform (DFT)",
3279 "-implode amount implode image pixels about the center",
3280 "-lat geometry local adaptive thresholding",
3281 "-layers method optimize, merge, or compare image layers",
3282 "-level value adjust the level of image contrast",
3283 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003284 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003285 "-linear-stretch geometry",
3286 " improve contrast by `stretching with saturation'",
3287 "-liquid-rescale geometry",
3288 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003289 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003290 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003291 "-modulate value vary the brightness, saturation, and hue",
3292 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003293 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003294 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003295 "-motion-blur geometry",
3296 " simulate motion blur",
3297 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003298 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003299 "-normalize transform image to span the full range of colors",
3300 "-opaque color change this color to the fill color",
3301 "-ordered-dither NxN",
3302 " add a noise pattern to the image with specific",
3303 " amplitudes",
3304 "-paint radius simulate an oil painting",
3305 "-polaroid angle simulate a Polaroid picture",
3306 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003307 "-profile filename add, delete, or apply an image profile",
3308 "-quantize colorspace reduce colors in this colorspace",
3309 "-radial-blur angle radial blur the image",
3310 "-raise value lighten/darken image edges to create a 3-D effect",
3311 "-random-threshold low,high",
3312 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003313 "-region geometry apply options to a portion of the image",
3314 "-render render vector graphics",
3315 "-repage geometry size and location of an image canvas",
3316 "-resample geometry change the resolution of an image",
3317 "-resize geometry resize the image",
3318 "-roll geometry roll an image vertically or horizontally",
3319 "-rotate degrees apply Paeth rotation to the image",
3320 "-sample geometry scale image with pixel sampling",
3321 "-scale geometry scale the image",
3322 "-segment values segment an image",
3323 "-selective-blur geometry",
3324 " selectively blur pixels within a contrast threshold",
3325 "-sepia-tone threshold",
3326 " simulate a sepia-toned photo",
3327 "-set property value set an image property",
3328 "-shade degrees shade the image using a distant light source",
3329 "-shadow geometry simulate an image shadow",
3330 "-sharpen geometry sharpen the image",
3331 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003332 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003333 "-sigmoidal-contrast geometry",
3334 " increase the contrast without saturating highlights or shadows",
3335 "-sketch geometry simulate a pencil sketch",
3336 "-solarize threshold negate all pixels above the threshold level",
3337 "-sparse-color method args",
3338 " fill in a image based on a few color points",
3339 "-splice geometry splice the background color into the image",
3340 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003341 "-statistic type radius",
3342 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003343 "-strip strip image of all profiles and comments",
3344 "-swirl degrees swirl image pixels about the center",
3345 "-threshold value threshold the image",
3346 "-thumbnail geometry create a thumbnail of the image",
3347 "-tile filename tile image when filling a graphic primitive",
3348 "-tint value tint the image with the fill color",
3349 "-transform affine transform image",
3350 "-transparent color make this color transparent within the image",
3351 "-transpose flip image vertically and rotate 90 degrees",
3352 "-transverse flop image horizontally and rotate 270 degrees",
3353 "-trim trim image edges",
3354 "-type type image type",
3355 "-unique-colors discard all but one of any pixel color",
3356 "-unsharp geometry sharpen the image",
3357 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003358 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003359 "-white-threshold value",
3360 " force all pixels above the threshold into white",
3361 (char *) NULL
3362 },
3363 *sequence_operators[]=
3364 {
cristy4285d782011-02-09 20:12:28 +00003365 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003366 "-clut apply a color lookup table to the image",
3367 "-coalesce merge a sequence of images",
3368 "-combine combine a sequence of images",
3369 "-composite composite image",
3370 "-crop geometry cut out a rectangular region of the image",
3371 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003372 "-evaluate-sequence operator",
3373 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003374 "-flatten flatten a sequence of images",
3375 "-fx expression apply mathematical expression to an image channel(s)",
3376 "-hald-clut apply a Hald color lookup table to the image",
3377 "-morph value morph an image sequence",
3378 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003379 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003380 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003381 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003382 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003383 "-write filename write images to this file",
3384 (char *) NULL
3385 },
3386 *settings[]=
3387 {
3388 "-adjoin join images into a single multi-image file",
3389 "-affine matrix affine transform matrix",
3390 "-alpha option activate, deactivate, reset, or set the alpha channel",
3391 "-antialias remove pixel-aliasing",
3392 "-authenticate password",
3393 " decipher image with this password",
3394 "-attenuate value lessen (or intensify) when adding noise to an image",
3395 "-background color background color",
3396 "-bias value add bias when convolving an image",
3397 "-black-point-compensation",
3398 " use black point compensation",
3399 "-blue-primary point chromaticity blue primary point",
3400 "-bordercolor color border color",
3401 "-caption string assign a caption to an image",
3402 "-channel type apply option to select image channels",
3403 "-colors value preferred number of colors in the image",
3404 "-colorspace type alternate image colorspace",
3405 "-comment string annotate image with comment",
3406 "-compose operator set image composite operator",
3407 "-compress type type of pixel compression when writing the image",
3408 "-define format:option",
3409 " define one or more image format options",
3410 "-delay value display the next image after pausing",
3411 "-density geometry horizontal and vertical density of the image",
3412 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003413 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003414 "-display server get image or font from this X server",
3415 "-dispose method layer disposal method",
3416 "-dither method apply error diffusion to image",
3417 "-encoding type text encoding type",
3418 "-endian type endianness (MSB or LSB) of the image",
3419 "-family name render text with this font family",
3420 "-fill color color to use when filling a graphic primitive",
3421 "-filter type use this filter when resizing an image",
3422 "-font name render text with this font",
3423 "-format \"string\" output formatted image characteristics",
3424 "-fuzz distance colors within this distance are considered equal",
3425 "-gravity type horizontal and vertical text placement",
3426 "-green-primary point chromaticity green primary point",
3427 "-intent type type of rendering intent when managing the image color",
3428 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003429 "-interline-spacing value",
3430 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003431 "-interpolate method pixel color interpolation method",
3432 "-interword-spacing value",
3433 " set the space between two words",
3434 "-kerning value set the space between two letters",
3435 "-label string assign a label to an image",
3436 "-limit type value pixel cache resource limit",
3437 "-loop iterations add Netscape loop extension to your GIF animation",
3438 "-mask filename associate a mask with the image",
3439 "-mattecolor color frame color",
3440 "-monitor monitor progress",
3441 "-orient type image orientation",
3442 "-page geometry size and location of an image canvas (setting)",
3443 "-ping efficiently determine image attributes",
3444 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003445 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003446 "-preview type image preview type",
3447 "-quality value JPEG/MIFF/PNG compression level",
3448 "-quiet suppress all warning messages",
3449 "-red-primary point chromaticity red primary point",
3450 "-regard-warnings pay attention to warning messages",
3451 "-remap filename transform image colors to match this set of colors",
3452 "-respect-parentheses settings remain in effect until parenthesis boundary",
3453 "-sampling-factor geometry",
3454 " horizontal and vertical sampling factor",
3455 "-scene value image scene number",
3456 "-seed value seed a new sequence of pseudo-random numbers",
3457 "-size geometry width and height of image",
3458 "-stretch type render text with this font stretch",
3459 "-stroke color graphic primitive stroke color",
3460 "-strokewidth value graphic primitive stroke width",
3461 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003462 "-synchronize synchronize image to storage device",
3463 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003464 "-texture filename name of texture to tile onto the image background",
3465 "-tile-offset geometry",
3466 " tile offset",
3467 "-treedepth value color tree depth",
3468 "-transparent-color color",
3469 " transparent color",
3470 "-undercolor color annotation bounding box color",
3471 "-units type the units of image resolution",
3472 "-verbose print detailed information about the image",
3473 "-view FlashPix viewing transforms",
3474 "-virtual-pixel method",
3475 " virtual pixel access method",
3476 "-weight type render text with this font weight",
3477 "-white-point point chromaticity white point",
3478 (char *) NULL
3479 },
3480 *stack_operators[]=
3481 {
anthonyb69c4b32011-03-23 04:37:44 +00003482 "-delete indexes delete the image from the image sequence",
3483 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003484 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003485 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003486 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003487 "-swap indexes swap two images in the image sequence",
3488 (char *) NULL
3489 };
3490
3491 const char
3492 **p;
3493
cristybb503372010-05-27 20:51:26 +00003494 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003495 (void) printf("Copyright: %s\n",GetMagickCopyright());
3496 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003497 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3498 GetClientName());
3499 (void) printf("\nImage Settings:\n");
3500 for (p=settings; *p != (char *) NULL; p++)
3501 (void) printf(" %s\n",*p);
3502 (void) printf("\nImage Operators:\n");
3503 for (p=operators; *p != (char *) NULL; p++)
3504 (void) printf(" %s\n",*p);
3505 (void) printf("\nImage Sequence Operators:\n");
3506 for (p=sequence_operators; *p != (char *) NULL; p++)
3507 (void) printf(" %s\n",*p);
3508 (void) printf("\nImage Stack Operators:\n");
3509 for (p=stack_operators; *p != (char *) NULL; p++)
3510 (void) printf(" %s\n",*p);
3511 (void) printf("\nMiscellaneous Options:\n");
3512 for (p=miscellaneous; *p != (char *) NULL; p++)
3513 (void) printf(" %s\n",*p);
3514 (void) printf(
3515 "\nBy default, the image format of `file' is determined by its magic\n");
3516 (void) printf(
3517 "number. To specify a particular image format, precede the filename\n");
3518 (void) printf(
3519 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3520 (void) printf(
3521 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3522 (void) printf("'-' for standard input or output.\n");
3523 return(MagickFalse);
3524}
3525
3526WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3527 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3528{
3529#define DestroyMogrify() \
3530{ \
3531 if (format != (char *) NULL) \
3532 format=DestroyString(format); \
3533 if (path != (char *) NULL) \
3534 path=DestroyString(path); \
3535 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003536 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003537 argv[i]=DestroyString(argv[i]); \
3538 argv=(char **) RelinquishMagickMemory(argv); \
3539}
3540#define ThrowMogrifyException(asperity,tag,option) \
3541{ \
3542 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3543 option); \
3544 DestroyMogrify(); \
3545 return(MagickFalse); \
3546}
3547#define ThrowMogrifyInvalidArgumentException(option,argument) \
3548{ \
3549 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3550 "InvalidArgument","`%s': %s",argument,option); \
3551 DestroyMogrify(); \
3552 return(MagickFalse); \
3553}
3554
3555 char
3556 *format,
3557 *option,
3558 *path;
3559
3560 Image
3561 *image;
3562
3563 ImageStack
3564 image_stack[MaxImageStackDepth+1];
3565
cristy3ed852e2009-09-05 21:47:34 +00003566 MagickBooleanType
3567 global_colormap;
3568
3569 MagickBooleanType
3570 fire,
cristyebbcfea2011-02-25 02:43:54 +00003571 pend,
3572 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003573
3574 MagickStatusType
3575 status;
3576
cristyebbcfea2011-02-25 02:43:54 +00003577 register ssize_t
3578 i;
3579
3580 ssize_t
3581 j,
3582 k;
3583
cristy3ed852e2009-09-05 21:47:34 +00003584 /*
3585 Set defaults.
3586 */
3587 assert(image_info != (ImageInfo *) NULL);
3588 assert(image_info->signature == MagickSignature);
3589 if (image_info->debug != MagickFalse)
3590 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3591 assert(exception != (ExceptionInfo *) NULL);
3592 if (argc == 2)
3593 {
3594 option=argv[1];
3595 if ((LocaleCompare("version",option+1) == 0) ||
3596 (LocaleCompare("-version",option+1) == 0))
3597 {
cristyb51dff52011-05-19 16:55:47 +00003598 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003599 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003600 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3601 GetMagickCopyright());
3602 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3603 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003604 return(MagickFalse);
3605 }
3606 }
3607 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003608 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003609 format=(char *) NULL;
3610 path=(char *) NULL;
3611 global_colormap=MagickFalse;
3612 k=0;
3613 j=1;
3614 NewImageStack();
3615 option=(char *) NULL;
3616 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003617 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003618 status=MagickTrue;
3619 /*
3620 Parse command line.
3621 */
3622 ReadCommandlLine(argc,&argv);
3623 status=ExpandFilenames(&argc,&argv);
3624 if (status == MagickFalse)
3625 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3626 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003627 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003628 {
3629 option=argv[i];
3630 if (LocaleCompare(option,"(") == 0)
3631 {
3632 FireImageStack(MagickFalse,MagickTrue,pend);
3633 if (k == MaxImageStackDepth)
3634 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3635 option);
3636 PushImageStack();
3637 continue;
3638 }
3639 if (LocaleCompare(option,")") == 0)
3640 {
3641 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3642 if (k == 0)
3643 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3644 PopImageStack();
3645 continue;
3646 }
cristy042ee782011-04-22 18:48:30 +00003647 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003648 {
3649 char
3650 backup_filename[MaxTextExtent],
3651 *filename;
3652
3653 Image
3654 *images;
3655
3656 /*
3657 Option is a file name: begin by reading image from specified file.
3658 */
3659 FireImageStack(MagickFalse,MagickFalse,pend);
3660 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003661 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003662 filename=argv[++i];
3663 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3664 images=ReadImages(image_info,exception);
3665 status&=(images != (Image *) NULL) &&
3666 (exception->severity < ErrorException);
3667 if (images == (Image *) NULL)
3668 continue;
cristydaa76602010-06-30 13:05:11 +00003669 if (format != (char *) NULL)
3670 (void) CopyMagickString(images->filename,images->magick_filename,
3671 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003672 if (path != (char *) NULL)
3673 {
3674 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003675 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003676 path,*DirectorySeparator,filename);
3677 }
3678 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003679 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003680 AppendImageStack(images);
3681 FinalizeImageSettings(image_info,image,MagickFalse);
3682 if (global_colormap != MagickFalse)
3683 {
3684 QuantizeInfo
3685 *quantize_info;
3686
3687 quantize_info=AcquireQuantizeInfo(image_info);
3688 (void) RemapImages(quantize_info,images,(Image *) NULL);
3689 quantize_info=DestroyQuantizeInfo(quantize_info);
3690 }
3691 *backup_filename='\0';
3692 if ((LocaleCompare(image->filename,"-") != 0) &&
3693 (IsPathWritable(image->filename) != MagickFalse))
3694 {
cristybb503372010-05-27 20:51:26 +00003695 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003696 i;
3697
3698 /*
3699 Rename image file as backup.
3700 */
3701 (void) CopyMagickString(backup_filename,image->filename,
3702 MaxTextExtent);
3703 for (i=0; i < 6; i++)
3704 {
3705 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3706 if (IsPathAccessible(backup_filename) == MagickFalse)
3707 break;
3708 }
3709 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3710 (rename(image->filename,backup_filename) != 0))
3711 *backup_filename='\0';
3712 }
3713 /*
3714 Write transmogrified image to disk.
3715 */
3716 image_info->synchronize=MagickTrue;
3717 status&=WriteImages(image_info,image,image->filename,exception);
3718 if ((status == MagickFalse) && (*backup_filename != '\0'))
3719 (void) remove(backup_filename);
3720 RemoveAllImageStack();
3721 continue;
3722 }
3723 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3724 switch (*(option+1))
3725 {
3726 case 'a':
3727 {
3728 if (LocaleCompare("adaptive-blur",option+1) == 0)
3729 {
3730 i++;
cristybb503372010-05-27 20:51:26 +00003731 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003732 ThrowMogrifyException(OptionError,"MissingArgument",option);
3733 if (IsGeometry(argv[i]) == MagickFalse)
3734 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3735 break;
3736 }
3737 if (LocaleCompare("adaptive-resize",option+1) == 0)
3738 {
3739 i++;
cristybb503372010-05-27 20:51:26 +00003740 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003741 ThrowMogrifyException(OptionError,"MissingArgument",option);
3742 if (IsGeometry(argv[i]) == MagickFalse)
3743 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3744 break;
3745 }
3746 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3747 {
3748 i++;
cristybb503372010-05-27 20:51:26 +00003749 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003750 ThrowMogrifyException(OptionError,"MissingArgument",option);
3751 if (IsGeometry(argv[i]) == MagickFalse)
3752 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3753 break;
3754 }
3755 if (LocaleCompare("affine",option+1) == 0)
3756 {
3757 if (*option == '+')
3758 break;
3759 i++;
cristybb503372010-05-27 20:51:26 +00003760 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003761 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003762 break;
3763 }
3764 if (LocaleCompare("alpha",option+1) == 0)
3765 {
cristybb503372010-05-27 20:51:26 +00003766 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003767 type;
3768
3769 if (*option == '+')
3770 break;
3771 i++;
cristybb503372010-05-27 20:51:26 +00003772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003773 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003774 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003775 if (type < 0)
3776 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3777 argv[i]);
3778 break;
3779 }
3780 if (LocaleCompare("annotate",option+1) == 0)
3781 {
3782 if (*option == '+')
3783 break;
3784 i++;
cristybb503372010-05-27 20:51:26 +00003785 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003786 ThrowMogrifyException(OptionError,"MissingArgument",option);
3787 if (IsGeometry(argv[i]) == MagickFalse)
3788 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003789 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003790 ThrowMogrifyException(OptionError,"MissingArgument",option);
3791 i++;
3792 break;
3793 }
3794 if (LocaleCompare("antialias",option+1) == 0)
3795 break;
3796 if (LocaleCompare("append",option+1) == 0)
3797 break;
3798 if (LocaleCompare("attenuate",option+1) == 0)
3799 {
3800 if (*option == '+')
3801 break;
3802 i++;
cristybb503372010-05-27 20:51:26 +00003803 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003804 ThrowMogrifyException(OptionError,"MissingArgument",option);
3805 if (IsGeometry(argv[i]) == MagickFalse)
3806 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3807 break;
3808 }
3809 if (LocaleCompare("authenticate",option+1) == 0)
3810 {
3811 if (*option == '+')
3812 break;
3813 i++;
cristybb503372010-05-27 20:51:26 +00003814 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003815 ThrowMogrifyException(OptionError,"MissingArgument",option);
3816 break;
3817 }
3818 if (LocaleCompare("auto-gamma",option+1) == 0)
3819 break;
3820 if (LocaleCompare("auto-level",option+1) == 0)
3821 break;
3822 if (LocaleCompare("auto-orient",option+1) == 0)
3823 break;
3824 if (LocaleCompare("average",option+1) == 0)
3825 break;
3826 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3827 }
3828 case 'b':
3829 {
3830 if (LocaleCompare("background",option+1) == 0)
3831 {
3832 if (*option == '+')
3833 break;
3834 i++;
cristybb503372010-05-27 20:51:26 +00003835 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003836 ThrowMogrifyException(OptionError,"MissingArgument",option);
3837 break;
3838 }
3839 if (LocaleCompare("bias",option+1) == 0)
3840 {
3841 if (*option == '+')
3842 break;
3843 i++;
cristybb503372010-05-27 20:51:26 +00003844 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003845 ThrowMogrifyException(OptionError,"MissingArgument",option);
3846 if (IsGeometry(argv[i]) == MagickFalse)
3847 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3848 break;
3849 }
3850 if (LocaleCompare("black-point-compensation",option+1) == 0)
3851 break;
3852 if (LocaleCompare("black-threshold",option+1) == 0)
3853 {
3854 if (*option == '+')
3855 break;
3856 i++;
cristybb503372010-05-27 20:51:26 +00003857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003858 ThrowMogrifyException(OptionError,"MissingArgument",option);
3859 if (IsGeometry(argv[i]) == MagickFalse)
3860 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3861 break;
3862 }
3863 if (LocaleCompare("blue-primary",option+1) == 0)
3864 {
3865 if (*option == '+')
3866 break;
3867 i++;
cristybb503372010-05-27 20:51:26 +00003868 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003869 ThrowMogrifyException(OptionError,"MissingArgument",option);
3870 if (IsGeometry(argv[i]) == MagickFalse)
3871 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3872 break;
3873 }
3874 if (LocaleCompare("blue-shift",option+1) == 0)
3875 {
3876 i++;
cristybb503372010-05-27 20:51:26 +00003877 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003878 ThrowMogrifyException(OptionError,"MissingArgument",option);
3879 if (IsGeometry(argv[i]) == MagickFalse)
3880 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3881 break;
3882 }
3883 if (LocaleCompare("blur",option+1) == 0)
3884 {
3885 i++;
cristybb503372010-05-27 20:51:26 +00003886 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003887 ThrowMogrifyException(OptionError,"MissingArgument",option);
3888 if (IsGeometry(argv[i]) == MagickFalse)
3889 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3890 break;
3891 }
3892 if (LocaleCompare("border",option+1) == 0)
3893 {
3894 if (*option == '+')
3895 break;
3896 i++;
cristybb503372010-05-27 20:51:26 +00003897 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003898 ThrowMogrifyException(OptionError,"MissingArgument",option);
3899 if (IsGeometry(argv[i]) == MagickFalse)
3900 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3901 break;
3902 }
3903 if (LocaleCompare("bordercolor",option+1) == 0)
3904 {
3905 if (*option == '+')
3906 break;
3907 i++;
cristybb503372010-05-27 20:51:26 +00003908 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003909 ThrowMogrifyException(OptionError,"MissingArgument",option);
3910 break;
3911 }
3912 if (LocaleCompare("box",option+1) == 0)
3913 {
3914 if (*option == '+')
3915 break;
3916 i++;
cristybb503372010-05-27 20:51:26 +00003917 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003918 ThrowMogrifyException(OptionError,"MissingArgument",option);
3919 break;
3920 }
cristya28d6b82010-01-11 20:03:47 +00003921 if (LocaleCompare("brightness-contrast",option+1) == 0)
3922 {
3923 i++;
cristybb503372010-05-27 20:51:26 +00003924 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003925 ThrowMogrifyException(OptionError,"MissingArgument",option);
3926 if (IsGeometry(argv[i]) == MagickFalse)
3927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3928 break;
3929 }
cristy3ed852e2009-09-05 21:47:34 +00003930 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3931 }
3932 case 'c':
3933 {
3934 if (LocaleCompare("cache",option+1) == 0)
3935 {
3936 if (*option == '+')
3937 break;
3938 i++;
cristybb503372010-05-27 20:51:26 +00003939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003940 ThrowMogrifyException(OptionError,"MissingArgument",option);
3941 if (IsGeometry(argv[i]) == MagickFalse)
3942 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3943 break;
3944 }
3945 if (LocaleCompare("caption",option+1) == 0)
3946 {
3947 if (*option == '+')
3948 break;
3949 i++;
cristybb503372010-05-27 20:51:26 +00003950 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003951 ThrowMogrifyException(OptionError,"MissingArgument",option);
3952 break;
3953 }
3954 if (LocaleCompare("channel",option+1) == 0)
3955 {
cristybb503372010-05-27 20:51:26 +00003956 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003957 channel;
3958
3959 if (*option == '+')
3960 break;
3961 i++;
cristybb503372010-05-27 20:51:26 +00003962 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003963 ThrowMogrifyException(OptionError,"MissingArgument",option);
3964 channel=ParseChannelOption(argv[i]);
3965 if (channel < 0)
3966 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3967 argv[i]);
3968 break;
3969 }
3970 if (LocaleCompare("cdl",option+1) == 0)
3971 {
3972 if (*option == '+')
3973 break;
3974 i++;
cristybb503372010-05-27 20:51:26 +00003975 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003976 ThrowMogrifyException(OptionError,"MissingArgument",option);
3977 break;
3978 }
3979 if (LocaleCompare("charcoal",option+1) == 0)
3980 {
3981 if (*option == '+')
3982 break;
3983 i++;
cristybb503372010-05-27 20:51:26 +00003984 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003985 ThrowMogrifyException(OptionError,"MissingArgument",option);
3986 if (IsGeometry(argv[i]) == MagickFalse)
3987 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3988 break;
3989 }
3990 if (LocaleCompare("chop",option+1) == 0)
3991 {
3992 if (*option == '+')
3993 break;
3994 i++;
cristybb503372010-05-27 20:51:26 +00003995 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003996 ThrowMogrifyException(OptionError,"MissingArgument",option);
3997 if (IsGeometry(argv[i]) == MagickFalse)
3998 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3999 break;
4000 }
cristy1eb45dd2009-09-25 16:38:06 +00004001 if (LocaleCompare("clamp",option+1) == 0)
4002 break;
4003 if (LocaleCompare("clip",option+1) == 0)
4004 break;
cristy3ed852e2009-09-05 21:47:34 +00004005 if (LocaleCompare("clip-mask",option+1) == 0)
4006 {
4007 if (*option == '+')
4008 break;
4009 i++;
cristybb503372010-05-27 20:51:26 +00004010 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004011 ThrowMogrifyException(OptionError,"MissingArgument",option);
4012 break;
4013 }
4014 if (LocaleCompare("clut",option+1) == 0)
4015 break;
4016 if (LocaleCompare("coalesce",option+1) == 0)
4017 break;
4018 if (LocaleCompare("colorize",option+1) == 0)
4019 {
4020 if (*option == '+')
4021 break;
4022 i++;
cristybb503372010-05-27 20:51:26 +00004023 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004024 ThrowMogrifyException(OptionError,"MissingArgument",option);
4025 if (IsGeometry(argv[i]) == MagickFalse)
4026 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4027 break;
4028 }
cristye6365592010-04-02 17:31:23 +00004029 if (LocaleCompare("color-matrix",option+1) == 0)
4030 {
cristyb6bd4ad2010-08-08 01:12:27 +00004031 KernelInfo
4032 *kernel_info;
4033
cristye6365592010-04-02 17:31:23 +00004034 if (*option == '+')
4035 break;
4036 i++;
cristybb503372010-05-27 20:51:26 +00004037 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004038 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004039 kernel_info=AcquireKernelInfo(argv[i]);
4040 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004041 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004042 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004043 break;
4044 }
cristy3ed852e2009-09-05 21:47:34 +00004045 if (LocaleCompare("colors",option+1) == 0)
4046 {
4047 if (*option == '+')
4048 break;
4049 i++;
cristybb503372010-05-27 20:51:26 +00004050 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004051 ThrowMogrifyException(OptionError,"MissingArgument",option);
4052 if (IsGeometry(argv[i]) == MagickFalse)
4053 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4054 break;
4055 }
4056 if (LocaleCompare("colorspace",option+1) == 0)
4057 {
cristybb503372010-05-27 20:51:26 +00004058 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004059 colorspace;
4060
4061 if (*option == '+')
4062 break;
4063 i++;
cristybb503372010-05-27 20:51:26 +00004064 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004065 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004066 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004067 argv[i]);
4068 if (colorspace < 0)
4069 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4070 argv[i]);
4071 break;
4072 }
4073 if (LocaleCompare("combine",option+1) == 0)
4074 break;
4075 if (LocaleCompare("comment",option+1) == 0)
4076 {
4077 if (*option == '+')
4078 break;
4079 i++;
cristybb503372010-05-27 20:51:26 +00004080 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004081 ThrowMogrifyException(OptionError,"MissingArgument",option);
4082 break;
4083 }
4084 if (LocaleCompare("composite",option+1) == 0)
4085 break;
4086 if (LocaleCompare("compress",option+1) == 0)
4087 {
cristybb503372010-05-27 20:51:26 +00004088 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004089 compress;
4090
4091 if (*option == '+')
4092 break;
4093 i++;
cristybb503372010-05-27 20:51:26 +00004094 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004095 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004096 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004097 argv[i]);
4098 if (compress < 0)
4099 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4100 argv[i]);
4101 break;
4102 }
cristy22879752009-10-25 23:55:40 +00004103 if (LocaleCompare("concurrent",option+1) == 0)
4104 break;
cristy3ed852e2009-09-05 21:47:34 +00004105 if (LocaleCompare("contrast",option+1) == 0)
4106 break;
4107 if (LocaleCompare("contrast-stretch",option+1) == 0)
4108 {
4109 i++;
cristybb503372010-05-27 20:51:26 +00004110 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004111 ThrowMogrifyException(OptionError,"MissingArgument",option);
4112 if (IsGeometry(argv[i]) == MagickFalse)
4113 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4114 break;
4115 }
4116 if (LocaleCompare("convolve",option+1) == 0)
4117 {
cristyb6bd4ad2010-08-08 01:12:27 +00004118 KernelInfo
4119 *kernel_info;
4120
cristy3ed852e2009-09-05 21:47:34 +00004121 if (*option == '+')
4122 break;
4123 i++;
cristybb503372010-05-27 20:51:26 +00004124 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004125 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004126 kernel_info=AcquireKernelInfo(argv[i]);
4127 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004128 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004129 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004130 break;
4131 }
4132 if (LocaleCompare("crop",option+1) == 0)
4133 {
4134 if (*option == '+')
4135 break;
4136 i++;
cristybb503372010-05-27 20:51:26 +00004137 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004138 ThrowMogrifyException(OptionError,"MissingArgument",option);
4139 if (IsGeometry(argv[i]) == MagickFalse)
4140 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4141 break;
4142 }
4143 if (LocaleCompare("cycle",option+1) == 0)
4144 {
4145 if (*option == '+')
4146 break;
4147 i++;
cristybb503372010-05-27 20:51:26 +00004148 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004149 ThrowMogrifyException(OptionError,"MissingArgument",option);
4150 if (IsGeometry(argv[i]) == MagickFalse)
4151 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4152 break;
4153 }
4154 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4155 }
4156 case 'd':
4157 {
4158 if (LocaleCompare("decipher",option+1) == 0)
4159 {
4160 if (*option == '+')
4161 break;
4162 i++;
cristybb503372010-05-27 20:51:26 +00004163 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004164 ThrowMogrifyException(OptionError,"MissingArgument",option);
4165 break;
4166 }
4167 if (LocaleCompare("deconstruct",option+1) == 0)
4168 break;
4169 if (LocaleCompare("debug",option+1) == 0)
4170 {
cristybb503372010-05-27 20:51:26 +00004171 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004172 event;
4173
4174 if (*option == '+')
4175 break;
4176 i++;
cristybb503372010-05-27 20:51:26 +00004177 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004178 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004179 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004180 if (event < 0)
4181 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4182 argv[i]);
4183 (void) SetLogEventMask(argv[i]);
4184 break;
4185 }
4186 if (LocaleCompare("define",option+1) == 0)
4187 {
4188 i++;
cristybb503372010-05-27 20:51:26 +00004189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004190 ThrowMogrifyException(OptionError,"MissingArgument",option);
4191 if (*option == '+')
4192 {
4193 const char
4194 *define;
4195
4196 define=GetImageOption(image_info,argv[i]);
4197 if (define == (const char *) NULL)
4198 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4199 break;
4200 }
4201 break;
4202 }
4203 if (LocaleCompare("delay",option+1) == 0)
4204 {
4205 if (*option == '+')
4206 break;
4207 i++;
cristybb503372010-05-27 20:51:26 +00004208 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004209 ThrowMogrifyException(OptionError,"MissingArgument",option);
4210 if (IsGeometry(argv[i]) == MagickFalse)
4211 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4212 break;
4213 }
cristyecb10ff2011-03-22 13:14:03 +00004214 if (LocaleCompare("delete",option+1) == 0)
4215 {
4216 if (*option == '+')
4217 break;
4218 i++;
4219 if (i == (ssize_t) (argc-1))
4220 ThrowMogrifyException(OptionError,"MissingArgument",option);
4221 if (IsGeometry(argv[i]) == MagickFalse)
4222 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4223 break;
4224 }
cristy3ed852e2009-09-05 21:47:34 +00004225 if (LocaleCompare("density",option+1) == 0)
4226 {
4227 if (*option == '+')
4228 break;
4229 i++;
cristybb503372010-05-27 20:51:26 +00004230 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004231 ThrowMogrifyException(OptionError,"MissingArgument",option);
4232 if (IsGeometry(argv[i]) == MagickFalse)
4233 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4234 break;
4235 }
4236 if (LocaleCompare("depth",option+1) == 0)
4237 {
4238 if (*option == '+')
4239 break;
4240 i++;
cristybb503372010-05-27 20:51:26 +00004241 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004242 ThrowMogrifyException(OptionError,"MissingArgument",option);
4243 if (IsGeometry(argv[i]) == MagickFalse)
4244 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4245 break;
4246 }
4247 if (LocaleCompare("deskew",option+1) == 0)
4248 {
4249 if (*option == '+')
4250 break;
4251 i++;
cristybb503372010-05-27 20:51:26 +00004252 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004253 ThrowMogrifyException(OptionError,"MissingArgument",option);
4254 if (IsGeometry(argv[i]) == MagickFalse)
4255 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4256 break;
4257 }
4258 if (LocaleCompare("despeckle",option+1) == 0)
4259 break;
4260 if (LocaleCompare("dft",option+1) == 0)
4261 break;
cristyc9b12952010-03-28 01:12:28 +00004262 if (LocaleCompare("direction",option+1) == 0)
4263 {
cristybb503372010-05-27 20:51:26 +00004264 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004265 direction;
4266
4267 if (*option == '+')
4268 break;
4269 i++;
cristybb503372010-05-27 20:51:26 +00004270 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004271 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004272 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004273 argv[i]);
4274 if (direction < 0)
4275 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4276 argv[i]);
4277 break;
4278 }
cristy3ed852e2009-09-05 21:47:34 +00004279 if (LocaleCompare("display",option+1) == 0)
4280 {
4281 if (*option == '+')
4282 break;
4283 i++;
cristybb503372010-05-27 20:51:26 +00004284 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004285 ThrowMogrifyException(OptionError,"MissingArgument",option);
4286 break;
4287 }
4288 if (LocaleCompare("dispose",option+1) == 0)
4289 {
cristybb503372010-05-27 20:51:26 +00004290 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004291 dispose;
4292
4293 if (*option == '+')
4294 break;
4295 i++;
cristybb503372010-05-27 20:51:26 +00004296 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004297 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004298 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004299 if (dispose < 0)
4300 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4301 argv[i]);
4302 break;
4303 }
4304 if (LocaleCompare("distort",option+1) == 0)
4305 {
cristybb503372010-05-27 20:51:26 +00004306 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004307 op;
4308
4309 i++;
cristybb503372010-05-27 20:51:26 +00004310 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004311 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004312 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004313 if (op < 0)
4314 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4315 argv[i]);
4316 i++;
cristybb503372010-05-27 20:51:26 +00004317 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004318 ThrowMogrifyException(OptionError,"MissingArgument",option);
4319 break;
4320 }
4321 if (LocaleCompare("dither",option+1) == 0)
4322 {
cristybb503372010-05-27 20:51:26 +00004323 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004324 method;
4325
4326 if (*option == '+')
4327 break;
4328 i++;
cristybb503372010-05-27 20:51:26 +00004329 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004330 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004331 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004332 if (method < 0)
4333 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4334 argv[i]);
4335 break;
4336 }
4337 if (LocaleCompare("draw",option+1) == 0)
4338 {
4339 if (*option == '+')
4340 break;
4341 i++;
cristybb503372010-05-27 20:51:26 +00004342 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004343 ThrowMogrifyException(OptionError,"MissingArgument",option);
4344 break;
4345 }
cristyecb10ff2011-03-22 13:14:03 +00004346 if (LocaleCompare("duplicate",option+1) == 0)
4347 {
4348 if (*option == '+')
4349 break;
4350 i++;
4351 if (i == (ssize_t) (argc-1))
4352 ThrowMogrifyException(OptionError,"MissingArgument",option);
4353 if (IsGeometry(argv[i]) == MagickFalse)
4354 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4355 break;
4356 }
cristy22879752009-10-25 23:55:40 +00004357 if (LocaleCompare("duration",option+1) == 0)
4358 {
4359 if (*option == '+')
4360 break;
4361 i++;
cristybb503372010-05-27 20:51:26 +00004362 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004363 ThrowMogrifyException(OptionError,"MissingArgument",option);
4364 if (IsGeometry(argv[i]) == MagickFalse)
4365 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4366 break;
4367 }
cristy3ed852e2009-09-05 21:47:34 +00004368 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4369 }
4370 case 'e':
4371 {
4372 if (LocaleCompare("edge",option+1) == 0)
4373 {
4374 if (*option == '+')
4375 break;
4376 i++;
cristybb503372010-05-27 20:51:26 +00004377 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004378 ThrowMogrifyException(OptionError,"MissingArgument",option);
4379 if (IsGeometry(argv[i]) == MagickFalse)
4380 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4381 break;
4382 }
4383 if (LocaleCompare("emboss",option+1) == 0)
4384 {
4385 if (*option == '+')
4386 break;
4387 i++;
cristybb503372010-05-27 20:51:26 +00004388 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004389 ThrowMogrifyException(OptionError,"MissingArgument",option);
4390 if (IsGeometry(argv[i]) == MagickFalse)
4391 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4392 break;
4393 }
4394 if (LocaleCompare("encipher",option+1) == 0)
4395 {
4396 if (*option == '+')
4397 break;
4398 i++;
cristybb503372010-05-27 20:51:26 +00004399 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004400 ThrowMogrifyException(OptionError,"MissingArgument",option);
4401 break;
4402 }
4403 if (LocaleCompare("encoding",option+1) == 0)
4404 {
4405 if (*option == '+')
4406 break;
4407 i++;
cristybb503372010-05-27 20:51:26 +00004408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004409 ThrowMogrifyException(OptionError,"MissingArgument",option);
4410 break;
4411 }
4412 if (LocaleCompare("endian",option+1) == 0)
4413 {
cristybb503372010-05-27 20:51:26 +00004414 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004415 endian;
4416
4417 if (*option == '+')
4418 break;
4419 i++;
cristybb503372010-05-27 20:51:26 +00004420 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004421 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004422 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004423 if (endian < 0)
4424 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4425 argv[i]);
4426 break;
4427 }
4428 if (LocaleCompare("enhance",option+1) == 0)
4429 break;
4430 if (LocaleCompare("equalize",option+1) == 0)
4431 break;
4432 if (LocaleCompare("evaluate",option+1) == 0)
4433 {
cristybb503372010-05-27 20:51:26 +00004434 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004435 op;
4436
4437 if (*option == '+')
4438 break;
4439 i++;
cristybb503372010-05-27 20:51:26 +00004440 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004441 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004442 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004443 if (op < 0)
4444 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4445 argv[i]);
4446 i++;
cristybb503372010-05-27 20:51:26 +00004447 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004448 ThrowMogrifyException(OptionError,"MissingArgument",option);
4449 if (IsGeometry(argv[i]) == MagickFalse)
4450 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4451 break;
4452 }
cristyd18ae7c2010-03-07 17:39:52 +00004453 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4454 {
cristybb503372010-05-27 20:51:26 +00004455 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004456 op;
4457
4458 if (*option == '+')
4459 break;
4460 i++;
cristybb503372010-05-27 20:51:26 +00004461 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004462 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004463 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004464 if (op < 0)
4465 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4466 argv[i]);
4467 break;
4468 }
cristy3ed852e2009-09-05 21:47:34 +00004469 if (LocaleCompare("extent",option+1) == 0)
4470 {
4471 if (*option == '+')
4472 break;
4473 i++;
cristybb503372010-05-27 20:51:26 +00004474 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004475 ThrowMogrifyException(OptionError,"MissingArgument",option);
4476 if (IsGeometry(argv[i]) == MagickFalse)
4477 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4478 break;
4479 }
4480 if (LocaleCompare("extract",option+1) == 0)
4481 {
4482 if (*option == '+')
4483 break;
4484 i++;
cristybb503372010-05-27 20:51:26 +00004485 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004486 ThrowMogrifyException(OptionError,"MissingArgument",option);
4487 if (IsGeometry(argv[i]) == MagickFalse)
4488 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4489 break;
4490 }
4491 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4492 }
4493 case 'f':
4494 {
4495 if (LocaleCompare("family",option+1) == 0)
4496 {
4497 if (*option == '+')
4498 break;
4499 i++;
cristybb503372010-05-27 20:51:26 +00004500 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004501 ThrowMogrifyException(OptionError,"MissingArgument",option);
4502 break;
4503 }
4504 if (LocaleCompare("fill",option+1) == 0)
4505 {
4506 if (*option == '+')
4507 break;
4508 i++;
cristybb503372010-05-27 20:51:26 +00004509 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004510 ThrowMogrifyException(OptionError,"MissingArgument",option);
4511 break;
4512 }
4513 if (LocaleCompare("filter",option+1) == 0)
4514 {
cristybb503372010-05-27 20:51:26 +00004515 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004516 filter;
4517
4518 if (*option == '+')
4519 break;
4520 i++;
cristybb503372010-05-27 20:51:26 +00004521 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004522 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004523 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004524 if (filter < 0)
4525 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4526 argv[i]);
4527 break;
4528 }
4529 if (LocaleCompare("flatten",option+1) == 0)
4530 break;
4531 if (LocaleCompare("flip",option+1) == 0)
4532 break;
4533 if (LocaleCompare("flop",option+1) == 0)
4534 break;
4535 if (LocaleCompare("floodfill",option+1) == 0)
4536 {
4537 if (*option == '+')
4538 break;
4539 i++;
cristybb503372010-05-27 20:51:26 +00004540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004541 ThrowMogrifyException(OptionError,"MissingArgument",option);
4542 if (IsGeometry(argv[i]) == MagickFalse)
4543 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4544 i++;
cristybb503372010-05-27 20:51:26 +00004545 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004546 ThrowMogrifyException(OptionError,"MissingArgument",option);
4547 break;
4548 }
4549 if (LocaleCompare("font",option+1) == 0)
4550 {
4551 if (*option == '+')
4552 break;
4553 i++;
cristybb503372010-05-27 20:51:26 +00004554 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004555 ThrowMogrifyException(OptionError,"MissingArgument",option);
4556 break;
4557 }
4558 if (LocaleCompare("format",option+1) == 0)
4559 {
4560 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4561 (void) CloneString(&format,(char *) NULL);
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 (void) CloneString(&format,argv[i]);
4568 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4569 (void) ConcatenateMagickString(image_info->filename,":",
4570 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004571 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004572 if (*image_info->magick == '\0')
4573 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4574 format);
4575 break;
4576 }
4577 if (LocaleCompare("frame",option+1) == 0)
4578 {
4579 if (*option == '+')
4580 break;
4581 i++;
cristybb503372010-05-27 20:51:26 +00004582 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004583 ThrowMogrifyException(OptionError,"MissingArgument",option);
4584 if (IsGeometry(argv[i]) == MagickFalse)
4585 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4586 break;
4587 }
4588 if (LocaleCompare("function",option+1) == 0)
4589 {
cristybb503372010-05-27 20:51:26 +00004590 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004591 op;
4592
4593 if (*option == '+')
4594 break;
4595 i++;
cristybb503372010-05-27 20:51:26 +00004596 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004597 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004598 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004599 if (op < 0)
4600 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4601 i++;
cristybb503372010-05-27 20:51:26 +00004602 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004603 ThrowMogrifyException(OptionError,"MissingArgument",option);
4604 break;
4605 }
4606 if (LocaleCompare("fuzz",option+1) == 0)
4607 {
4608 if (*option == '+')
4609 break;
4610 i++;
cristybb503372010-05-27 20:51:26 +00004611 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004612 ThrowMogrifyException(OptionError,"MissingArgument",option);
4613 if (IsGeometry(argv[i]) == MagickFalse)
4614 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4615 break;
4616 }
4617 if (LocaleCompare("fx",option+1) == 0)
4618 {
4619 if (*option == '+')
4620 break;
4621 i++;
cristybb503372010-05-27 20:51:26 +00004622 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004623 ThrowMogrifyException(OptionError,"MissingArgument",option);
4624 break;
4625 }
4626 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4627 }
4628 case 'g':
4629 {
4630 if (LocaleCompare("gamma",option+1) == 0)
4631 {
4632 i++;
cristybb503372010-05-27 20:51:26 +00004633 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004634 ThrowMogrifyException(OptionError,"MissingArgument",option);
4635 if (IsGeometry(argv[i]) == MagickFalse)
4636 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4637 break;
4638 }
4639 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4640 (LocaleCompare("gaussian",option+1) == 0))
4641 {
4642 i++;
cristybb503372010-05-27 20:51:26 +00004643 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004644 ThrowMogrifyException(OptionError,"MissingArgument",option);
4645 if (IsGeometry(argv[i]) == MagickFalse)
4646 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4647 break;
4648 }
4649 if (LocaleCompare("geometry",option+1) == 0)
4650 {
4651 if (*option == '+')
4652 break;
4653 i++;
cristybb503372010-05-27 20:51:26 +00004654 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004655 ThrowMogrifyException(OptionError,"MissingArgument",option);
4656 if (IsGeometry(argv[i]) == MagickFalse)
4657 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4658 break;
4659 }
4660 if (LocaleCompare("gravity",option+1) == 0)
4661 {
cristybb503372010-05-27 20:51:26 +00004662 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004663 gravity;
4664
4665 if (*option == '+')
4666 break;
4667 i++;
cristybb503372010-05-27 20:51:26 +00004668 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004669 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004670 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004671 if (gravity < 0)
4672 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4673 argv[i]);
4674 break;
4675 }
4676 if (LocaleCompare("green-primary",option+1) == 0)
4677 {
4678 if (*option == '+')
4679 break;
4680 i++;
cristybb503372010-05-27 20:51:26 +00004681 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004682 ThrowMogrifyException(OptionError,"MissingArgument",option);
4683 if (IsGeometry(argv[i]) == MagickFalse)
4684 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4685 break;
4686 }
4687 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4688 }
4689 case 'h':
4690 {
4691 if (LocaleCompare("hald-clut",option+1) == 0)
4692 break;
4693 if ((LocaleCompare("help",option+1) == 0) ||
4694 (LocaleCompare("-help",option+1) == 0))
4695 return(MogrifyUsage());
4696 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4697 }
4698 case 'i':
4699 {
4700 if (LocaleCompare("identify",option+1) == 0)
4701 break;
4702 if (LocaleCompare("idft",option+1) == 0)
4703 break;
4704 if (LocaleCompare("implode",option+1) == 0)
4705 {
4706 if (*option == '+')
4707 break;
4708 i++;
cristybb503372010-05-27 20:51:26 +00004709 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004710 ThrowMogrifyException(OptionError,"MissingArgument",option);
4711 if (IsGeometry(argv[i]) == MagickFalse)
4712 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4713 break;
4714 }
4715 if (LocaleCompare("intent",option+1) == 0)
4716 {
cristybb503372010-05-27 20:51:26 +00004717 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004718 intent;
4719
4720 if (*option == '+')
4721 break;
4722 i++;
cristybb503372010-05-27 20:51:26 +00004723 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004724 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004725 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004726 if (intent < 0)
4727 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4728 argv[i]);
4729 break;
4730 }
4731 if (LocaleCompare("interlace",option+1) == 0)
4732 {
cristybb503372010-05-27 20:51:26 +00004733 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004734 interlace;
4735
4736 if (*option == '+')
4737 break;
4738 i++;
cristybb503372010-05-27 20:51:26 +00004739 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004740 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004741 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004742 argv[i]);
4743 if (interlace < 0)
4744 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4745 argv[i]);
4746 break;
4747 }
cristyb32b90a2009-09-07 21:45:48 +00004748 if (LocaleCompare("interline-spacing",option+1) == 0)
4749 {
4750 if (*option == '+')
4751 break;
4752 i++;
cristybb503372010-05-27 20:51:26 +00004753 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004754 ThrowMogrifyException(OptionError,"MissingArgument",option);
4755 if (IsGeometry(argv[i]) == MagickFalse)
4756 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4757 break;
4758 }
cristy3ed852e2009-09-05 21:47:34 +00004759 if (LocaleCompare("interpolate",option+1) == 0)
4760 {
cristybb503372010-05-27 20:51:26 +00004761 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004762 interpolate;
4763
4764 if (*option == '+')
4765 break;
4766 i++;
cristybb503372010-05-27 20:51:26 +00004767 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004768 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004769 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004770 argv[i]);
4771 if (interpolate < 0)
4772 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4773 argv[i]);
4774 break;
4775 }
4776 if (LocaleCompare("interword-spacing",option+1) == 0)
4777 {
4778 if (*option == '+')
4779 break;
4780 i++;
cristybb503372010-05-27 20:51:26 +00004781 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004782 ThrowMogrifyException(OptionError,"MissingArgument",option);
4783 if (IsGeometry(argv[i]) == MagickFalse)
4784 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4785 break;
4786 }
4787 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4788 }
4789 case 'k':
4790 {
4791 if (LocaleCompare("kerning",option+1) == 0)
4792 {
4793 if (*option == '+')
4794 break;
4795 i++;
cristybb503372010-05-27 20:51:26 +00004796 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004797 ThrowMogrifyException(OptionError,"MissingArgument",option);
4798 if (IsGeometry(argv[i]) == MagickFalse)
4799 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4800 break;
4801 }
4802 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4803 }
4804 case 'l':
4805 {
4806 if (LocaleCompare("label",option+1) == 0)
4807 {
4808 if (*option == '+')
4809 break;
4810 i++;
cristybb503372010-05-27 20:51:26 +00004811 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004812 ThrowMogrifyException(OptionError,"MissingArgument",option);
4813 break;
4814 }
4815 if (LocaleCompare("lat",option+1) == 0)
4816 {
4817 if (*option == '+')
4818 break;
4819 i++;
cristybb503372010-05-27 20:51:26 +00004820 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004821 ThrowMogrifyException(OptionError,"MissingArgument",option);
4822 if (IsGeometry(argv[i]) == MagickFalse)
4823 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4824 }
4825 if (LocaleCompare("layers",option+1) == 0)
4826 {
cristybb503372010-05-27 20:51:26 +00004827 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004828 type;
4829
4830 if (*option == '+')
4831 break;
4832 i++;
cristybb503372010-05-27 20:51:26 +00004833 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004834 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004835 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004836 if (type < 0)
4837 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4838 argv[i]);
4839 break;
4840 }
4841 if (LocaleCompare("level",option+1) == 0)
4842 {
4843 i++;
cristybb503372010-05-27 20:51:26 +00004844 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004845 ThrowMogrifyException(OptionError,"MissingArgument",option);
4846 if (IsGeometry(argv[i]) == MagickFalse)
4847 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4848 break;
4849 }
4850 if (LocaleCompare("level-colors",option+1) == 0)
4851 {
4852 i++;
cristybb503372010-05-27 20:51:26 +00004853 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004854 ThrowMogrifyException(OptionError,"MissingArgument",option);
4855 break;
4856 }
4857 if (LocaleCompare("linewidth",option+1) == 0)
4858 {
4859 if (*option == '+')
4860 break;
4861 i++;
cristybb503372010-05-27 20:51:26 +00004862 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004863 ThrowMogrifyException(OptionError,"MissingArgument",option);
4864 if (IsGeometry(argv[i]) == MagickFalse)
4865 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4866 break;
4867 }
4868 if (LocaleCompare("limit",option+1) == 0)
4869 {
4870 char
4871 *p;
4872
4873 double
4874 value;
4875
cristybb503372010-05-27 20:51:26 +00004876 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004877 resource;
4878
4879 if (*option == '+')
4880 break;
4881 i++;
cristybb503372010-05-27 20:51:26 +00004882 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004883 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004884 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004885 argv[i]);
4886 if (resource < 0)
4887 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4888 argv[i]);
4889 i++;
cristybb503372010-05-27 20:51:26 +00004890 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004891 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004892 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004893 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004894 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4895 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4896 break;
4897 }
4898 if (LocaleCompare("liquid-rescale",option+1) == 0)
4899 {
4900 i++;
cristybb503372010-05-27 20:51:26 +00004901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004902 ThrowMogrifyException(OptionError,"MissingArgument",option);
4903 if (IsGeometry(argv[i]) == MagickFalse)
4904 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4905 break;
4906 }
4907 if (LocaleCompare("list",option+1) == 0)
4908 {
cristybb503372010-05-27 20:51:26 +00004909 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004910 list;
4911
4912 if (*option == '+')
4913 break;
4914 i++;
cristybb503372010-05-27 20:51:26 +00004915 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004916 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004917 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004918 if (list < 0)
4919 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004920 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004921 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004922 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004923 }
4924 if (LocaleCompare("log",option+1) == 0)
4925 {
4926 if (*option == '+')
4927 break;
4928 i++;
cristybb503372010-05-27 20:51:26 +00004929 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004930 (strchr(argv[i],'%') == (char *) NULL))
4931 ThrowMogrifyException(OptionError,"MissingArgument",option);
4932 break;
4933 }
4934 if (LocaleCompare("loop",option+1) == 0)
4935 {
4936 if (*option == '+')
4937 break;
4938 i++;
cristybb503372010-05-27 20:51:26 +00004939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004940 ThrowMogrifyException(OptionError,"MissingArgument",option);
4941 if (IsGeometry(argv[i]) == MagickFalse)
4942 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4943 break;
4944 }
4945 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4946 }
4947 case 'm':
4948 {
4949 if (LocaleCompare("map",option+1) == 0)
4950 {
4951 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4952 if (*option == '+')
4953 break;
4954 i++;
cristybb503372010-05-27 20:51:26 +00004955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004956 ThrowMogrifyException(OptionError,"MissingArgument",option);
4957 break;
4958 }
4959 if (LocaleCompare("mask",option+1) == 0)
4960 {
4961 if (*option == '+')
4962 break;
4963 i++;
cristybb503372010-05-27 20:51:26 +00004964 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004965 ThrowMogrifyException(OptionError,"MissingArgument",option);
4966 break;
4967 }
4968 if (LocaleCompare("matte",option+1) == 0)
4969 break;
4970 if (LocaleCompare("mattecolor",option+1) == 0)
4971 {
4972 if (*option == '+')
4973 break;
4974 i++;
cristybb503372010-05-27 20:51:26 +00004975 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004976 ThrowMogrifyException(OptionError,"MissingArgument",option);
4977 break;
4978 }
cristyf40785b2010-03-06 02:27:27 +00004979 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004980 break;
cristyf40785b2010-03-06 02:27:27 +00004981 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004982 break;
cristy3ed852e2009-09-05 21:47:34 +00004983 if (LocaleCompare("modulate",option+1) == 0)
4984 {
4985 if (*option == '+')
4986 break;
4987 i++;
cristybb503372010-05-27 20:51:26 +00004988 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004989 ThrowMogrifyException(OptionError,"MissingArgument",option);
4990 if (IsGeometry(argv[i]) == MagickFalse)
4991 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4992 break;
4993 }
4994 if (LocaleCompare("median",option+1) == 0)
4995 {
4996 if (*option == '+')
4997 break;
4998 i++;
cristybb503372010-05-27 20:51:26 +00004999 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005000 ThrowMogrifyException(OptionError,"MissingArgument",option);
5001 if (IsGeometry(argv[i]) == MagickFalse)
5002 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5003 break;
5004 }
cristy69ec32d2011-02-27 23:57:09 +00005005 if (LocaleCompare("mode",option+1) == 0)
5006 {
5007 if (*option == '+')
5008 break;
5009 i++;
5010 if (i == (ssize_t) argc)
5011 ThrowMogrifyException(OptionError,"MissingArgument",option);
5012 if (IsGeometry(argv[i]) == MagickFalse)
5013 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5014 break;
5015 }
cristy3ed852e2009-09-05 21:47:34 +00005016 if (LocaleCompare("monitor",option+1) == 0)
5017 break;
5018 if (LocaleCompare("monochrome",option+1) == 0)
5019 break;
5020 if (LocaleCompare("morph",option+1) == 0)
5021 {
5022 if (*option == '+')
5023 break;
5024 i++;
cristybb503372010-05-27 20:51:26 +00005025 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005026 ThrowMogrifyException(OptionError,"MissingArgument",option);
5027 if (IsGeometry(argv[i]) == MagickFalse)
5028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5029 break;
5030 }
anthony29188a82010-01-22 10:12:34 +00005031 if (LocaleCompare("morphology",option+1) == 0)
5032 {
anthony29188a82010-01-22 10:12:34 +00005033 char
5034 token[MaxTextExtent];
5035
cristyb6bd4ad2010-08-08 01:12:27 +00005036 KernelInfo
5037 *kernel_info;
5038
5039 ssize_t
5040 op;
5041
anthony29188a82010-01-22 10:12:34 +00005042 i++;
cristybb503372010-05-27 20:51:26 +00005043 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005044 ThrowMogrifyException(OptionError,"MissingArgument",option);
5045 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005046 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005047 if (op < 0)
5048 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005049 token);
anthony29188a82010-01-22 10:12:34 +00005050 i++;
cristybb503372010-05-27 20:51:26 +00005051 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005052 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005053 kernel_info=AcquireKernelInfo(argv[i]);
5054 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005055 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005056 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005057 break;
5058 }
cristy3ed852e2009-09-05 21:47:34 +00005059 if (LocaleCompare("mosaic",option+1) == 0)
5060 break;
5061 if (LocaleCompare("motion-blur",option+1) == 0)
5062 {
5063 if (*option == '+')
5064 break;
5065 i++;
cristybb503372010-05-27 20:51:26 +00005066 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005067 ThrowMogrifyException(OptionError,"MissingArgument",option);
5068 if (IsGeometry(argv[i]) == MagickFalse)
5069 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5070 break;
5071 }
5072 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5073 }
5074 case 'n':
5075 {
5076 if (LocaleCompare("negate",option+1) == 0)
5077 break;
5078 if (LocaleCompare("noise",option+1) == 0)
5079 {
5080 i++;
cristybb503372010-05-27 20:51:26 +00005081 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005082 ThrowMogrifyException(OptionError,"MissingArgument",option);
5083 if (*option == '+')
5084 {
cristybb503372010-05-27 20:51:26 +00005085 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005086 noise;
5087
cristy042ee782011-04-22 18:48:30 +00005088 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005089 if (noise < 0)
5090 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5091 argv[i]);
5092 break;
5093 }
5094 if (IsGeometry(argv[i]) == MagickFalse)
5095 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5096 break;
5097 }
5098 if (LocaleCompare("noop",option+1) == 0)
5099 break;
5100 if (LocaleCompare("normalize",option+1) == 0)
5101 break;
5102 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5103 }
5104 case 'o':
5105 {
5106 if (LocaleCompare("opaque",option+1) == 0)
5107 {
cristy3ed852e2009-09-05 21:47:34 +00005108 i++;
cristybb503372010-05-27 20:51:26 +00005109 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005110 ThrowMogrifyException(OptionError,"MissingArgument",option);
5111 break;
5112 }
5113 if (LocaleCompare("ordered-dither",option+1) == 0)
5114 {
5115 if (*option == '+')
5116 break;
5117 i++;
cristybb503372010-05-27 20:51:26 +00005118 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005119 ThrowMogrifyException(OptionError,"MissingArgument",option);
5120 break;
5121 }
5122 if (LocaleCompare("orient",option+1) == 0)
5123 {
cristybb503372010-05-27 20:51:26 +00005124 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005125 orientation;
5126
5127 orientation=UndefinedOrientation;
5128 if (*option == '+')
5129 break;
5130 i++;
cristybb503372010-05-27 20:51:26 +00005131 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005132 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005133 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005134 argv[i]);
5135 if (orientation < 0)
5136 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5137 argv[i]);
5138 break;
5139 }
5140 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5141 }
5142 case 'p':
5143 {
5144 if (LocaleCompare("page",option+1) == 0)
5145 {
5146 if (*option == '+')
5147 break;
5148 i++;
cristybb503372010-05-27 20:51:26 +00005149 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005150 ThrowMogrifyException(OptionError,"MissingArgument",option);
5151 break;
5152 }
5153 if (LocaleCompare("paint",option+1) == 0)
5154 {
5155 if (*option == '+')
5156 break;
5157 i++;
cristybb503372010-05-27 20:51:26 +00005158 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005159 ThrowMogrifyException(OptionError,"MissingArgument",option);
5160 if (IsGeometry(argv[i]) == MagickFalse)
5161 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5162 break;
5163 }
5164 if (LocaleCompare("path",option+1) == 0)
5165 {
5166 (void) CloneString(&path,(char *) NULL);
5167 if (*option == '+')
5168 break;
5169 i++;
cristybb503372010-05-27 20:51:26 +00005170 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005171 ThrowMogrifyException(OptionError,"MissingArgument",option);
5172 (void) CloneString(&path,argv[i]);
5173 break;
5174 }
5175 if (LocaleCompare("pointsize",option+1) == 0)
5176 {
5177 if (*option == '+')
5178 break;
5179 i++;
cristybb503372010-05-27 20:51:26 +00005180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005181 ThrowMogrifyException(OptionError,"MissingArgument",option);
5182 if (IsGeometry(argv[i]) == MagickFalse)
5183 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5184 break;
5185 }
5186 if (LocaleCompare("polaroid",option+1) == 0)
5187 {
5188 if (*option == '+')
5189 break;
5190 i++;
cristybb503372010-05-27 20:51:26 +00005191 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005192 ThrowMogrifyException(OptionError,"MissingArgument",option);
5193 if (IsGeometry(argv[i]) == MagickFalse)
5194 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5195 break;
5196 }
5197 if (LocaleCompare("posterize",option+1) == 0)
5198 {
5199 if (*option == '+')
5200 break;
5201 i++;
cristybb503372010-05-27 20:51:26 +00005202 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005203 ThrowMogrifyException(OptionError,"MissingArgument",option);
5204 if (IsGeometry(argv[i]) == MagickFalse)
5205 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5206 break;
5207 }
cristye7f51092010-01-17 00:39:37 +00005208 if (LocaleCompare("precision",option+1) == 0)
5209 {
5210 if (*option == '+')
5211 break;
5212 i++;
cristybb503372010-05-27 20:51:26 +00005213 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005214 ThrowMogrifyException(OptionError,"MissingArgument",option);
5215 if (IsGeometry(argv[i]) == MagickFalse)
5216 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5217 break;
5218 }
cristy3ed852e2009-09-05 21:47:34 +00005219 if (LocaleCompare("print",option+1) == 0)
5220 {
5221 if (*option == '+')
5222 break;
5223 i++;
cristybb503372010-05-27 20:51:26 +00005224 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005225 ThrowMogrifyException(OptionError,"MissingArgument",option);
5226 break;
5227 }
5228 if (LocaleCompare("process",option+1) == 0)
5229 {
5230 if (*option == '+')
5231 break;
5232 i++;
cristybb503372010-05-27 20:51:26 +00005233 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005234 ThrowMogrifyException(OptionError,"MissingArgument",option);
5235 break;
5236 }
5237 if (LocaleCompare("profile",option+1) == 0)
5238 {
5239 i++;
cristybb503372010-05-27 20:51:26 +00005240 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005241 ThrowMogrifyException(OptionError,"MissingArgument",option);
5242 break;
5243 }
5244 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5245 }
5246 case 'q':
5247 {
5248 if (LocaleCompare("quality",option+1) == 0)
5249 {
5250 if (*option == '+')
5251 break;
5252 i++;
cristybb503372010-05-27 20:51:26 +00005253 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005254 ThrowMogrifyException(OptionError,"MissingArgument",option);
5255 if (IsGeometry(argv[i]) == MagickFalse)
5256 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5257 break;
5258 }
5259 if (LocaleCompare("quantize",option+1) == 0)
5260 {
cristybb503372010-05-27 20:51:26 +00005261 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005262 colorspace;
5263
5264 if (*option == '+')
5265 break;
5266 i++;
cristybb503372010-05-27 20:51:26 +00005267 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005268 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005269 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005270 argv[i]);
5271 if (colorspace < 0)
5272 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5273 argv[i]);
5274 break;
5275 }
5276 if (LocaleCompare("quiet",option+1) == 0)
5277 break;
5278 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5279 }
5280 case 'r':
5281 {
5282 if (LocaleCompare("radial-blur",option+1) == 0)
5283 {
5284 i++;
cristybb503372010-05-27 20:51:26 +00005285 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005286 ThrowMogrifyException(OptionError,"MissingArgument",option);
5287 if (IsGeometry(argv[i]) == MagickFalse)
5288 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5289 break;
5290 }
5291 if (LocaleCompare("raise",option+1) == 0)
5292 {
5293 i++;
cristybb503372010-05-27 20:51:26 +00005294 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005295 ThrowMogrifyException(OptionError,"MissingArgument",option);
5296 if (IsGeometry(argv[i]) == MagickFalse)
5297 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5298 break;
5299 }
5300 if (LocaleCompare("random-threshold",option+1) == 0)
5301 {
5302 if (*option == '+')
5303 break;
5304 i++;
cristybb503372010-05-27 20:51:26 +00005305 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005306 ThrowMogrifyException(OptionError,"MissingArgument",option);
5307 if (IsGeometry(argv[i]) == MagickFalse)
5308 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5309 break;
5310 }
cristye6365592010-04-02 17:31:23 +00005311 if (LocaleCompare("recolor",option+1) == 0)
5312 {
5313 if (*option == '+')
5314 break;
5315 i++;
cristybb503372010-05-27 20:51:26 +00005316 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005317 ThrowMogrifyException(OptionError,"MissingArgument",option);
5318 if (IsGeometry(argv[i]) == MagickFalse)
5319 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5320 break;
5321 }
cristy3ed852e2009-09-05 21:47:34 +00005322 if (LocaleCompare("red-primary",option+1) == 0)
5323 {
5324 if (*option == '+')
5325 break;
5326 i++;
cristybb503372010-05-27 20:51:26 +00005327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005328 ThrowMogrifyException(OptionError,"MissingArgument",option);
5329 if (IsGeometry(argv[i]) == MagickFalse)
5330 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5331 }
cristy9f2083a2010-04-22 19:48:05 +00005332 if (LocaleCompare("regard-warnings",option+1) == 0)
5333 break;
cristy3ed852e2009-09-05 21:47:34 +00005334 if (LocaleCompare("region",option+1) == 0)
5335 {
5336 if (*option == '+')
5337 break;
5338 i++;
cristybb503372010-05-27 20:51:26 +00005339 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005340 ThrowMogrifyException(OptionError,"MissingArgument",option);
5341 if (IsGeometry(argv[i]) == MagickFalse)
5342 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5343 break;
5344 }
cristyf0c78232010-03-15 12:53:40 +00005345 if (LocaleCompare("remap",option+1) == 0)
5346 {
5347 if (*option == '+')
5348 break;
5349 i++;
cristybb503372010-05-27 20:51:26 +00005350 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005351 ThrowMogrifyException(OptionError,"MissingArgument",option);
5352 break;
5353 }
cristy3ed852e2009-09-05 21:47:34 +00005354 if (LocaleCompare("render",option+1) == 0)
5355 break;
5356 if (LocaleCompare("repage",option+1) == 0)
5357 {
5358 if (*option == '+')
5359 break;
5360 i++;
cristybb503372010-05-27 20:51:26 +00005361 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005362 ThrowMogrifyException(OptionError,"MissingArgument",option);
5363 if (IsGeometry(argv[i]) == MagickFalse)
5364 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5365 break;
5366 }
5367 if (LocaleCompare("resample",option+1) == 0)
5368 {
5369 if (*option == '+')
5370 break;
5371 i++;
cristybb503372010-05-27 20:51:26 +00005372 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005373 ThrowMogrifyException(OptionError,"MissingArgument",option);
5374 if (IsGeometry(argv[i]) == MagickFalse)
5375 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5376 break;
5377 }
5378 if (LocaleCompare("resize",option+1) == 0)
5379 {
5380 if (*option == '+')
5381 break;
5382 i++;
cristybb503372010-05-27 20:51:26 +00005383 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005384 ThrowMogrifyException(OptionError,"MissingArgument",option);
5385 if (IsGeometry(argv[i]) == MagickFalse)
5386 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5387 break;
5388 }
cristyebbcfea2011-02-25 02:43:54 +00005389 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5390 {
5391 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5392 break;
5393 }
cristy3ed852e2009-09-05 21:47:34 +00005394 if (LocaleCompare("reverse",option+1) == 0)
5395 break;
5396 if (LocaleCompare("roll",option+1) == 0)
5397 {
5398 if (*option == '+')
5399 break;
5400 i++;
cristybb503372010-05-27 20:51:26 +00005401 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005402 ThrowMogrifyException(OptionError,"MissingArgument",option);
5403 if (IsGeometry(argv[i]) == MagickFalse)
5404 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5405 break;
5406 }
5407 if (LocaleCompare("rotate",option+1) == 0)
5408 {
5409 i++;
cristybb503372010-05-27 20:51:26 +00005410 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005411 ThrowMogrifyException(OptionError,"MissingArgument",option);
5412 if (IsGeometry(argv[i]) == MagickFalse)
5413 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5414 break;
5415 }
5416 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5417 }
5418 case 's':
5419 {
5420 if (LocaleCompare("sample",option+1) == 0)
5421 {
5422 if (*option == '+')
5423 break;
5424 i++;
cristybb503372010-05-27 20:51:26 +00005425 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005426 ThrowMogrifyException(OptionError,"MissingArgument",option);
5427 if (IsGeometry(argv[i]) == MagickFalse)
5428 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5429 break;
5430 }
5431 if (LocaleCompare("sampling-factor",option+1) == 0)
5432 {
5433 if (*option == '+')
5434 break;
5435 i++;
cristybb503372010-05-27 20:51:26 +00005436 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005437 ThrowMogrifyException(OptionError,"MissingArgument",option);
5438 if (IsGeometry(argv[i]) == MagickFalse)
5439 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5440 break;
5441 }
5442 if (LocaleCompare("scale",option+1) == 0)
5443 {
5444 if (*option == '+')
5445 break;
5446 i++;
cristybb503372010-05-27 20:51:26 +00005447 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005448 ThrowMogrifyException(OptionError,"MissingArgument",option);
5449 if (IsGeometry(argv[i]) == MagickFalse)
5450 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5451 break;
5452 }
5453 if (LocaleCompare("scene",option+1) == 0)
5454 {
5455 if (*option == '+')
5456 break;
5457 i++;
cristybb503372010-05-27 20:51:26 +00005458 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005459 ThrowMogrifyException(OptionError,"MissingArgument",option);
5460 if (IsGeometry(argv[i]) == MagickFalse)
5461 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5462 break;
5463 }
5464 if (LocaleCompare("seed",option+1) == 0)
5465 {
5466 if (*option == '+')
5467 break;
5468 i++;
cristybb503372010-05-27 20:51:26 +00005469 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005470 ThrowMogrifyException(OptionError,"MissingArgument",option);
5471 if (IsGeometry(argv[i]) == MagickFalse)
5472 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5473 break;
5474 }
5475 if (LocaleCompare("segment",option+1) == 0)
5476 {
5477 if (*option == '+')
5478 break;
5479 i++;
cristybb503372010-05-27 20:51:26 +00005480 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005481 ThrowMogrifyException(OptionError,"MissingArgument",option);
5482 if (IsGeometry(argv[i]) == MagickFalse)
5483 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5484 break;
5485 }
5486 if (LocaleCompare("selective-blur",option+1) == 0)
5487 {
5488 i++;
cristybb503372010-05-27 20:51:26 +00005489 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005490 ThrowMogrifyException(OptionError,"MissingArgument",option);
5491 if (IsGeometry(argv[i]) == MagickFalse)
5492 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5493 break;
5494 }
5495 if (LocaleCompare("separate",option+1) == 0)
5496 break;
5497 if (LocaleCompare("sepia-tone",option+1) == 0)
5498 {
5499 if (*option == '+')
5500 break;
5501 i++;
cristybb503372010-05-27 20:51:26 +00005502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005503 ThrowMogrifyException(OptionError,"MissingArgument",option);
5504 if (IsGeometry(argv[i]) == MagickFalse)
5505 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5506 break;
5507 }
5508 if (LocaleCompare("set",option+1) == 0)
5509 {
5510 i++;
cristybb503372010-05-27 20:51:26 +00005511 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005512 ThrowMogrifyException(OptionError,"MissingArgument",option);
5513 if (*option == '+')
5514 break;
5515 i++;
cristybb503372010-05-27 20:51:26 +00005516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005517 ThrowMogrifyException(OptionError,"MissingArgument",option);
5518 break;
5519 }
5520 if (LocaleCompare("shade",option+1) == 0)
5521 {
5522 i++;
cristybb503372010-05-27 20:51:26 +00005523 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005524 ThrowMogrifyException(OptionError,"MissingArgument",option);
5525 if (IsGeometry(argv[i]) == MagickFalse)
5526 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5527 break;
5528 }
5529 if (LocaleCompare("shadow",option+1) == 0)
5530 {
5531 if (*option == '+')
5532 break;
5533 i++;
cristybb503372010-05-27 20:51:26 +00005534 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005535 ThrowMogrifyException(OptionError,"MissingArgument",option);
5536 if (IsGeometry(argv[i]) == MagickFalse)
5537 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5538 break;
5539 }
5540 if (LocaleCompare("sharpen",option+1) == 0)
5541 {
5542 i++;
cristybb503372010-05-27 20:51:26 +00005543 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005544 ThrowMogrifyException(OptionError,"MissingArgument",option);
5545 if (IsGeometry(argv[i]) == MagickFalse)
5546 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5547 break;
5548 }
5549 if (LocaleCompare("shave",option+1) == 0)
5550 {
5551 if (*option == '+')
5552 break;
5553 i++;
cristybb503372010-05-27 20:51:26 +00005554 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005555 ThrowMogrifyException(OptionError,"MissingArgument",option);
5556 if (IsGeometry(argv[i]) == MagickFalse)
5557 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5558 break;
5559 }
5560 if (LocaleCompare("shear",option+1) == 0)
5561 {
5562 i++;
cristybb503372010-05-27 20:51:26 +00005563 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005564 ThrowMogrifyException(OptionError,"MissingArgument",option);
5565 if (IsGeometry(argv[i]) == MagickFalse)
5566 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5567 break;
5568 }
5569 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5570 {
5571 i++;
cristybb503372010-05-27 20:51:26 +00005572 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005573 ThrowMogrifyException(OptionError,"MissingArgument",option);
5574 if (IsGeometry(argv[i]) == MagickFalse)
5575 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5576 break;
5577 }
5578 if (LocaleCompare("size",option+1) == 0)
5579 {
5580 if (*option == '+')
5581 break;
5582 i++;
cristybb503372010-05-27 20:51:26 +00005583 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005584 ThrowMogrifyException(OptionError,"MissingArgument",option);
5585 if (IsGeometry(argv[i]) == MagickFalse)
5586 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5587 break;
5588 }
5589 if (LocaleCompare("sketch",option+1) == 0)
5590 {
5591 if (*option == '+')
5592 break;
5593 i++;
cristybb503372010-05-27 20:51:26 +00005594 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005595 ThrowMogrifyException(OptionError,"MissingArgument",option);
5596 if (IsGeometry(argv[i]) == MagickFalse)
5597 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5598 break;
5599 }
cristy4285d782011-02-09 20:12:28 +00005600 if (LocaleCompare("smush",option+1) == 0)
5601 {
cristy4285d782011-02-09 20:12:28 +00005602 i++;
5603 if (i == (ssize_t) argc)
5604 ThrowMogrifyException(OptionError,"MissingArgument",option);
5605 if (IsGeometry(argv[i]) == MagickFalse)
5606 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005607 i++;
5608 break;
5609 }
cristy3ed852e2009-09-05 21:47:34 +00005610 if (LocaleCompare("solarize",option+1) == 0)
5611 {
5612 if (*option == '+')
5613 break;
5614 i++;
cristybb503372010-05-27 20:51:26 +00005615 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005616 ThrowMogrifyException(OptionError,"MissingArgument",option);
5617 if (IsGeometry(argv[i]) == MagickFalse)
5618 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5619 break;
5620 }
5621 if (LocaleCompare("sparse-color",option+1) == 0)
5622 {
cristybb503372010-05-27 20:51:26 +00005623 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005624 op;
5625
5626 i++;
cristybb503372010-05-27 20:51:26 +00005627 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005628 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005629 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005630 if (op < 0)
5631 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5632 argv[i]);
5633 i++;
cristybb503372010-05-27 20:51:26 +00005634 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005635 ThrowMogrifyException(OptionError,"MissingArgument",option);
5636 break;
5637 }
5638 if (LocaleCompare("spread",option+1) == 0)
5639 {
5640 if (*option == '+')
5641 break;
5642 i++;
cristybb503372010-05-27 20:51:26 +00005643 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005644 ThrowMogrifyException(OptionError,"MissingArgument",option);
5645 if (IsGeometry(argv[i]) == MagickFalse)
5646 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5647 break;
5648 }
cristy0834d642011-03-18 18:26:08 +00005649 if (LocaleCompare("statistic",option+1) == 0)
5650 {
5651 ssize_t
5652 op;
5653
5654 if (*option == '+')
5655 break;
5656 i++;
5657 if (i == (ssize_t) argc)
5658 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005659 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005660 if (op < 0)
5661 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5662 argv[i]);
5663 i++;
5664 if (i == (ssize_t) (argc-1))
5665 ThrowMogrifyException(OptionError,"MissingArgument",option);
5666 if (IsGeometry(argv[i]) == MagickFalse)
5667 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5668 break;
5669 }
cristy3ed852e2009-09-05 21:47:34 +00005670 if (LocaleCompare("stretch",option+1) == 0)
5671 {
cristybb503372010-05-27 20:51:26 +00005672 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005673 stretch;
5674
5675 if (*option == '+')
5676 break;
5677 i++;
cristybb503372010-05-27 20:51:26 +00005678 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005679 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005680 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005681 if (stretch < 0)
5682 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5683 argv[i]);
5684 break;
5685 }
5686 if (LocaleCompare("strip",option+1) == 0)
5687 break;
5688 if (LocaleCompare("stroke",option+1) == 0)
5689 {
5690 if (*option == '+')
5691 break;
5692 i++;
cristybb503372010-05-27 20:51:26 +00005693 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005694 ThrowMogrifyException(OptionError,"MissingArgument",option);
5695 break;
5696 }
5697 if (LocaleCompare("strokewidth",option+1) == 0)
5698 {
5699 if (*option == '+')
5700 break;
5701 i++;
cristybb503372010-05-27 20:51:26 +00005702 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005703 ThrowMogrifyException(OptionError,"MissingArgument",option);
5704 if (IsGeometry(argv[i]) == MagickFalse)
5705 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5706 break;
5707 }
5708 if (LocaleCompare("style",option+1) == 0)
5709 {
cristybb503372010-05-27 20:51:26 +00005710 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005711 style;
5712
5713 if (*option == '+')
5714 break;
5715 i++;
cristybb503372010-05-27 20:51:26 +00005716 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005717 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005718 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005719 if (style < 0)
5720 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5721 argv[i]);
5722 break;
5723 }
cristyecb10ff2011-03-22 13:14:03 +00005724 if (LocaleCompare("swap",option+1) == 0)
5725 {
5726 if (*option == '+')
5727 break;
5728 i++;
5729 if (i == (ssize_t) (argc-1))
5730 ThrowMogrifyException(OptionError,"MissingArgument",option);
5731 if (IsGeometry(argv[i]) == MagickFalse)
5732 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5733 break;
5734 }
cristy3ed852e2009-09-05 21:47:34 +00005735 if (LocaleCompare("swirl",option+1) == 0)
5736 {
5737 if (*option == '+')
5738 break;
5739 i++;
cristybb503372010-05-27 20:51:26 +00005740 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005741 ThrowMogrifyException(OptionError,"MissingArgument",option);
5742 if (IsGeometry(argv[i]) == MagickFalse)
5743 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5744 break;
5745 }
cristyd9a29192010-10-16 16:49:53 +00005746 if (LocaleCompare("synchronize",option+1) == 0)
5747 break;
cristy3ed852e2009-09-05 21:47:34 +00005748 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5749 }
5750 case 't':
5751 {
5752 if (LocaleCompare("taint",option+1) == 0)
5753 break;
5754 if (LocaleCompare("texture",option+1) == 0)
5755 {
5756 if (*option == '+')
5757 break;
5758 i++;
cristybb503372010-05-27 20:51:26 +00005759 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005760 ThrowMogrifyException(OptionError,"MissingArgument",option);
5761 break;
5762 }
5763 if (LocaleCompare("tile",option+1) == 0)
5764 {
5765 if (*option == '+')
5766 break;
5767 i++;
cristybb503372010-05-27 20:51:26 +00005768 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005769 ThrowMogrifyException(OptionError,"MissingArgument",option);
5770 break;
5771 }
5772 if (LocaleCompare("tile-offset",option+1) == 0)
5773 {
5774 if (*option == '+')
5775 break;
5776 i++;
cristybb503372010-05-27 20:51:26 +00005777 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005778 ThrowMogrifyException(OptionError,"MissingArgument",option);
5779 if (IsGeometry(argv[i]) == MagickFalse)
5780 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5781 break;
5782 }
5783 if (LocaleCompare("tint",option+1) == 0)
5784 {
5785 if (*option == '+')
5786 break;
5787 i++;
cristybb503372010-05-27 20:51:26 +00005788 if (i == (ssize_t) (argc-1))
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("transform",option+1) == 0)
5795 break;
5796 if (LocaleCompare("transpose",option+1) == 0)
5797 break;
5798 if (LocaleCompare("transverse",option+1) == 0)
5799 break;
5800 if (LocaleCompare("threshold",option+1) == 0)
5801 {
5802 if (*option == '+')
5803 break;
5804 i++;
cristybb503372010-05-27 20:51:26 +00005805 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005806 ThrowMogrifyException(OptionError,"MissingArgument",option);
5807 if (IsGeometry(argv[i]) == MagickFalse)
5808 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5809 break;
5810 }
5811 if (LocaleCompare("thumbnail",option+1) == 0)
5812 {
5813 if (*option == '+')
5814 break;
5815 i++;
cristybb503372010-05-27 20:51:26 +00005816 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005817 ThrowMogrifyException(OptionError,"MissingArgument",option);
5818 if (IsGeometry(argv[i]) == MagickFalse)
5819 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5820 break;
5821 }
5822 if (LocaleCompare("transparent",option+1) == 0)
5823 {
5824 i++;
cristybb503372010-05-27 20:51:26 +00005825 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005826 ThrowMogrifyException(OptionError,"MissingArgument",option);
5827 break;
5828 }
5829 if (LocaleCompare("transparent-color",option+1) == 0)
5830 {
5831 if (*option == '+')
5832 break;
5833 i++;
cristybb503372010-05-27 20:51:26 +00005834 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005835 ThrowMogrifyException(OptionError,"MissingArgument",option);
5836 break;
5837 }
5838 if (LocaleCompare("treedepth",option+1) == 0)
5839 {
5840 if (*option == '+')
5841 break;
5842 i++;
cristybb503372010-05-27 20:51:26 +00005843 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005844 ThrowMogrifyException(OptionError,"MissingArgument",option);
5845 if (IsGeometry(argv[i]) == MagickFalse)
5846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5847 break;
5848 }
5849 if (LocaleCompare("trim",option+1) == 0)
5850 break;
5851 if (LocaleCompare("type",option+1) == 0)
5852 {
cristybb503372010-05-27 20:51:26 +00005853 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005854 type;
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);
cristy042ee782011-04-22 18:48:30 +00005861 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005862 if (type < 0)
5863 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5864 argv[i]);
5865 break;
5866 }
5867 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5868 }
5869 case 'u':
5870 {
5871 if (LocaleCompare("undercolor",option+1) == 0)
5872 {
5873 if (*option == '+')
5874 break;
5875 i++;
cristybb503372010-05-27 20:51:26 +00005876 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005877 ThrowMogrifyException(OptionError,"MissingArgument",option);
5878 break;
5879 }
5880 if (LocaleCompare("unique-colors",option+1) == 0)
5881 break;
5882 if (LocaleCompare("units",option+1) == 0)
5883 {
cristybb503372010-05-27 20:51:26 +00005884 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005885 units;
5886
5887 if (*option == '+')
5888 break;
5889 i++;
cristybb503372010-05-27 20:51:26 +00005890 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005891 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005892 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005893 argv[i]);
5894 if (units < 0)
5895 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5896 argv[i]);
5897 break;
5898 }
5899 if (LocaleCompare("unsharp",option+1) == 0)
5900 {
5901 i++;
cristybb503372010-05-27 20:51:26 +00005902 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005903 ThrowMogrifyException(OptionError,"MissingArgument",option);
5904 if (IsGeometry(argv[i]) == MagickFalse)
5905 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5906 break;
5907 }
5908 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5909 }
5910 case 'v':
5911 {
5912 if (LocaleCompare("verbose",option+1) == 0)
5913 {
5914 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5915 break;
5916 }
5917 if ((LocaleCompare("version",option+1) == 0) ||
5918 (LocaleCompare("-version",option+1) == 0))
5919 {
cristyb51dff52011-05-19 16:55:47 +00005920 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005921 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005922 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5923 GetMagickCopyright());
5924 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5925 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005926 break;
5927 }
5928 if (LocaleCompare("view",option+1) == 0)
5929 {
5930 if (*option == '+')
5931 break;
5932 i++;
cristybb503372010-05-27 20:51:26 +00005933 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005934 ThrowMogrifyException(OptionError,"MissingArgument",option);
5935 break;
5936 }
5937 if (LocaleCompare("vignette",option+1) == 0)
5938 {
5939 if (*option == '+')
5940 break;
5941 i++;
cristybb503372010-05-27 20:51:26 +00005942 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005943 ThrowMogrifyException(OptionError,"MissingArgument",option);
5944 if (IsGeometry(argv[i]) == MagickFalse)
5945 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5946 break;
5947 }
5948 if (LocaleCompare("virtual-pixel",option+1) == 0)
5949 {
cristybb503372010-05-27 20:51:26 +00005950 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005951 method;
5952
5953 if (*option == '+')
5954 break;
5955 i++;
cristybb503372010-05-27 20:51:26 +00005956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005957 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005958 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005959 argv[i]);
5960 if (method < 0)
5961 ThrowMogrifyException(OptionError,
5962 "UnrecognizedVirtualPixelMethod",argv[i]);
5963 break;
5964 }
5965 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5966 }
5967 case 'w':
5968 {
5969 if (LocaleCompare("wave",option+1) == 0)
5970 {
5971 i++;
cristybb503372010-05-27 20:51:26 +00005972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005973 ThrowMogrifyException(OptionError,"MissingArgument",option);
5974 if (IsGeometry(argv[i]) == MagickFalse)
5975 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5976 break;
5977 }
5978 if (LocaleCompare("weight",option+1) == 0)
5979 {
5980 if (*option == '+')
5981 break;
5982 i++;
cristybb503372010-05-27 20:51:26 +00005983 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005984 ThrowMogrifyException(OptionError,"MissingArgument",option);
5985 break;
5986 }
5987 if (LocaleCompare("white-point",option+1) == 0)
5988 {
5989 if (*option == '+')
5990 break;
5991 i++;
cristybb503372010-05-27 20:51:26 +00005992 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005993 ThrowMogrifyException(OptionError,"MissingArgument",option);
5994 if (IsGeometry(argv[i]) == MagickFalse)
5995 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5996 break;
5997 }
5998 if (LocaleCompare("white-threshold",option+1) == 0)
5999 {
6000 if (*option == '+')
6001 break;
6002 i++;
cristybb503372010-05-27 20:51:26 +00006003 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006004 ThrowMogrifyException(OptionError,"MissingArgument",option);
6005 if (IsGeometry(argv[i]) == MagickFalse)
6006 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6007 break;
6008 }
6009 if (LocaleCompare("write",option+1) == 0)
6010 {
6011 i++;
cristybb503372010-05-27 20:51:26 +00006012 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006013 ThrowMogrifyException(OptionError,"MissingArgument",option);
6014 break;
6015 }
6016 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6017 }
6018 case '?':
6019 break;
6020 default:
6021 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6022 }
cristy042ee782011-04-22 18:48:30 +00006023 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6024 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006025 if (fire != MagickFalse)
6026 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6027 }
6028 if (k != 0)
6029 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006030 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006031 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6032 DestroyMogrify();
6033 return(status != 0 ? MagickTrue : MagickFalse);
6034}
6035
6036/*
6037%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6038% %
6039% %
6040% %
6041+ M o g r i f y I m a g e I n f o %
6042% %
6043% %
6044% %
6045%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6046%
6047% MogrifyImageInfo() applies image processing settings to the image as
6048% prescribed by command line options.
6049%
6050% The format of the MogrifyImageInfo method is:
6051%
6052% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6053% const char **argv,ExceptionInfo *exception)
6054%
6055% A description of each parameter follows:
6056%
6057% o image_info: the image info..
6058%
6059% o argc: Specifies a pointer to an integer describing the number of
6060% elements in the argument vector.
6061%
6062% o argv: Specifies a pointer to a text array containing the command line
6063% arguments.
6064%
6065% o exception: return any errors or warnings in this structure.
6066%
6067*/
6068WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6069 const int argc,const char **argv,ExceptionInfo *exception)
6070{
6071 const char
6072 *option;
6073
6074 GeometryInfo
6075 geometry_info;
6076
cristybb503372010-05-27 20:51:26 +00006077 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006078 count;
6079
cristybb503372010-05-27 20:51:26 +00006080 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006081 i;
6082
6083 /*
6084 Initialize method variables.
6085 */
6086 assert(image_info != (ImageInfo *) NULL);
6087 assert(image_info->signature == MagickSignature);
6088 if (image_info->debug != MagickFalse)
6089 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6090 image_info->filename);
6091 if (argc < 0)
6092 return(MagickTrue);
6093 /*
6094 Set the image settings.
6095 */
cristybb503372010-05-27 20:51:26 +00006096 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006097 {
6098 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006099 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006100 continue;
cristy042ee782011-04-22 18:48:30 +00006101 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006102 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006103 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006104 break;
6105 switch (*(option+1))
6106 {
6107 case 'a':
6108 {
6109 if (LocaleCompare("adjoin",option+1) == 0)
6110 {
6111 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6112 break;
6113 }
6114 if (LocaleCompare("antialias",option+1) == 0)
6115 {
6116 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6117 break;
6118 }
6119 if (LocaleCompare("attenuate",option+1) == 0)
6120 {
6121 if (*option == '+')
6122 {
6123 (void) DeleteImageOption(image_info,option+1);
6124 break;
6125 }
6126 (void) SetImageOption(image_info,option+1,argv[i+1]);
6127 break;
6128 }
6129 if (LocaleCompare("authenticate",option+1) == 0)
6130 {
6131 if (*option == '+')
6132 (void) CloneString(&image_info->authenticate,(char *) NULL);
6133 else
6134 (void) CloneString(&image_info->authenticate,argv[i+1]);
6135 break;
6136 }
6137 break;
6138 }
6139 case 'b':
6140 {
6141 if (LocaleCompare("background",option+1) == 0)
6142 {
6143 if (*option == '+')
6144 {
6145 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006146 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006147 &image_info->background_color,exception);
6148 break;
6149 }
6150 (void) SetImageOption(image_info,option+1,argv[i+1]);
6151 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6152 exception);
6153 break;
6154 }
6155 if (LocaleCompare("bias",option+1) == 0)
6156 {
6157 if (*option == '+')
6158 {
6159 (void) SetImageOption(image_info,option+1,"0.0");
6160 break;
6161 }
6162 (void) SetImageOption(image_info,option+1,argv[i+1]);
6163 break;
6164 }
6165 if (LocaleCompare("black-point-compensation",option+1) == 0)
6166 {
6167 if (*option == '+')
6168 {
6169 (void) SetImageOption(image_info,option+1,"false");
6170 break;
6171 }
6172 (void) SetImageOption(image_info,option+1,"true");
6173 break;
6174 }
6175 if (LocaleCompare("blue-primary",option+1) == 0)
6176 {
6177 if (*option == '+')
6178 {
6179 (void) SetImageOption(image_info,option+1,"0.0");
6180 break;
6181 }
6182 (void) SetImageOption(image_info,option+1,argv[i+1]);
6183 break;
6184 }
6185 if (LocaleCompare("bordercolor",option+1) == 0)
6186 {
6187 if (*option == '+')
6188 {
6189 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006190 (void) QueryColorDatabase(MogrifyBorderColor,
6191 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006192 break;
6193 }
6194 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6195 exception);
6196 (void) SetImageOption(image_info,option+1,argv[i+1]);
6197 break;
6198 }
6199 if (LocaleCompare("box",option+1) == 0)
6200 {
6201 if (*option == '+')
6202 {
6203 (void) SetImageOption(image_info,"undercolor","none");
6204 break;
6205 }
6206 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6207 break;
6208 }
6209 break;
6210 }
6211 case 'c':
6212 {
6213 if (LocaleCompare("cache",option+1) == 0)
6214 {
6215 MagickSizeType
6216 limit;
6217
6218 limit=MagickResourceInfinity;
6219 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006220 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006221 (void) SetMagickResourceLimit(MemoryResource,limit);
6222 (void) SetMagickResourceLimit(MapResource,2*limit);
6223 break;
6224 }
6225 if (LocaleCompare("caption",option+1) == 0)
6226 {
6227 if (*option == '+')
6228 {
6229 (void) DeleteImageOption(image_info,option+1);
6230 break;
6231 }
6232 (void) SetImageOption(image_info,option+1,argv[i+1]);
6233 break;
6234 }
6235 if (LocaleCompare("channel",option+1) == 0)
6236 {
6237 if (*option == '+')
6238 {
6239 image_info->channel=DefaultChannels;
6240 break;
6241 }
6242 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6243 break;
6244 }
6245 if (LocaleCompare("colors",option+1) == 0)
6246 {
cristye27293e2009-12-18 02:53:20 +00006247 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006248 break;
6249 }
6250 if (LocaleCompare("colorspace",option+1) == 0)
6251 {
6252 if (*option == '+')
6253 {
6254 image_info->colorspace=UndefinedColorspace;
6255 (void) SetImageOption(image_info,option+1,"undefined");
6256 break;
6257 }
cristy042ee782011-04-22 18:48:30 +00006258 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006259 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6260 (void) SetImageOption(image_info,option+1,argv[i+1]);
6261 break;
6262 }
cristy3ed852e2009-09-05 21:47:34 +00006263 if (LocaleCompare("comment",option+1) == 0)
6264 {
6265 if (*option == '+')
6266 {
6267 (void) DeleteImageOption(image_info,option+1);
6268 break;
6269 }
6270 (void) SetImageOption(image_info,option+1,argv[i+1]);
6271 break;
6272 }
6273 if (LocaleCompare("compose",option+1) == 0)
6274 {
6275 if (*option == '+')
6276 {
6277 (void) SetImageOption(image_info,option+1,"undefined");
6278 break;
6279 }
6280 (void) SetImageOption(image_info,option+1,argv[i+1]);
6281 break;
6282 }
6283 if (LocaleCompare("compress",option+1) == 0)
6284 {
6285 if (*option == '+')
6286 {
6287 image_info->compression=UndefinedCompression;
6288 (void) SetImageOption(image_info,option+1,"undefined");
6289 break;
6290 }
cristy042ee782011-04-22 18:48:30 +00006291 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006292 MagickCompressOptions,MagickFalse,argv[i+1]);
6293 (void) SetImageOption(image_info,option+1,argv[i+1]);
6294 break;
6295 }
6296 break;
6297 }
6298 case 'd':
6299 {
6300 if (LocaleCompare("debug",option+1) == 0)
6301 {
6302 if (*option == '+')
6303 (void) SetLogEventMask("none");
6304 else
6305 (void) SetLogEventMask(argv[i+1]);
6306 image_info->debug=IsEventLogging();
6307 break;
6308 }
6309 if (LocaleCompare("define",option+1) == 0)
6310 {
6311 if (*option == '+')
6312 {
6313 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6314 (void) DeleteImageRegistry(argv[i+1]+9);
6315 else
6316 (void) DeleteImageOption(image_info,argv[i+1]);
6317 break;
6318 }
6319 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6320 {
6321 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6322 exception);
6323 break;
6324 }
6325 (void) DefineImageOption(image_info,argv[i+1]);
6326 break;
6327 }
6328 if (LocaleCompare("delay",option+1) == 0)
6329 {
6330 if (*option == '+')
6331 {
6332 (void) SetImageOption(image_info,option+1,"0");
6333 break;
6334 }
6335 (void) SetImageOption(image_info,option+1,argv[i+1]);
6336 break;
6337 }
6338 if (LocaleCompare("density",option+1) == 0)
6339 {
6340 /*
6341 Set image density.
6342 */
6343 if (*option == '+')
6344 {
6345 if (image_info->density != (char *) NULL)
6346 image_info->density=DestroyString(image_info->density);
6347 (void) SetImageOption(image_info,option+1,"72");
6348 break;
6349 }
6350 (void) CloneString(&image_info->density,argv[i+1]);
6351 (void) SetImageOption(image_info,option+1,argv[i+1]);
6352 break;
6353 }
6354 if (LocaleCompare("depth",option+1) == 0)
6355 {
6356 if (*option == '+')
6357 {
6358 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6359 break;
6360 }
cristye27293e2009-12-18 02:53:20 +00006361 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006362 break;
6363 }
cristyc9b12952010-03-28 01:12:28 +00006364 if (LocaleCompare("direction",option+1) == 0)
6365 {
6366 if (*option == '+')
6367 {
6368 (void) SetImageOption(image_info,option+1,"undefined");
6369 break;
6370 }
6371 (void) SetImageOption(image_info,option+1,argv[i+1]);
6372 break;
6373 }
cristy3ed852e2009-09-05 21:47:34 +00006374 if (LocaleCompare("display",option+1) == 0)
6375 {
6376 if (*option == '+')
6377 {
6378 if (image_info->server_name != (char *) NULL)
6379 image_info->server_name=DestroyString(
6380 image_info->server_name);
6381 break;
6382 }
6383 (void) CloneString(&image_info->server_name,argv[i+1]);
6384 break;
6385 }
6386 if (LocaleCompare("dispose",option+1) == 0)
6387 {
6388 if (*option == '+')
6389 {
6390 (void) SetImageOption(image_info,option+1,"undefined");
6391 break;
6392 }
6393 (void) SetImageOption(image_info,option+1,argv[i+1]);
6394 break;
6395 }
6396 if (LocaleCompare("dither",option+1) == 0)
6397 {
6398 if (*option == '+')
6399 {
6400 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006401 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006402 break;
6403 }
6404 (void) SetImageOption(image_info,option+1,argv[i+1]);
6405 image_info->dither=MagickTrue;
6406 break;
6407 }
6408 break;
6409 }
6410 case 'e':
6411 {
6412 if (LocaleCompare("encoding",option+1) == 0)
6413 {
6414 if (*option == '+')
6415 {
6416 (void) SetImageOption(image_info,option+1,"undefined");
6417 break;
6418 }
6419 (void) SetImageOption(image_info,option+1,argv[i+1]);
6420 break;
6421 }
6422 if (LocaleCompare("endian",option+1) == 0)
6423 {
6424 if (*option == '+')
6425 {
6426 image_info->endian=UndefinedEndian;
6427 (void) SetImageOption(image_info,option+1,"undefined");
6428 break;
6429 }
cristy042ee782011-04-22 18:48:30 +00006430 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006431 MagickEndianOptions,MagickFalse,argv[i+1]);
6432 (void) SetImageOption(image_info,option+1,argv[i+1]);
6433 break;
6434 }
6435 if (LocaleCompare("extract",option+1) == 0)
6436 {
6437 /*
6438 Set image extract geometry.
6439 */
6440 if (*option == '+')
6441 {
6442 if (image_info->extract != (char *) NULL)
6443 image_info->extract=DestroyString(image_info->extract);
6444 break;
6445 }
6446 (void) CloneString(&image_info->extract,argv[i+1]);
6447 break;
6448 }
6449 break;
6450 }
6451 case 'f':
6452 {
6453 if (LocaleCompare("fill",option+1) == 0)
6454 {
6455 if (*option == '+')
6456 {
6457 (void) SetImageOption(image_info,option+1,"none");
6458 break;
6459 }
6460 (void) SetImageOption(image_info,option+1,argv[i+1]);
6461 break;
6462 }
6463 if (LocaleCompare("filter",option+1) == 0)
6464 {
6465 if (*option == '+')
6466 {
6467 (void) SetImageOption(image_info,option+1,"undefined");
6468 break;
6469 }
6470 (void) SetImageOption(image_info,option+1,argv[i+1]);
6471 break;
6472 }
6473 if (LocaleCompare("font",option+1) == 0)
6474 {
6475 if (*option == '+')
6476 {
6477 if (image_info->font != (char *) NULL)
6478 image_info->font=DestroyString(image_info->font);
6479 break;
6480 }
6481 (void) CloneString(&image_info->font,argv[i+1]);
6482 break;
6483 }
6484 if (LocaleCompare("format",option+1) == 0)
6485 {
6486 register const char
6487 *q;
6488
6489 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006490 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006491 image_info->ping=MagickFalse;
6492 (void) SetImageOption(image_info,option+1,argv[i+1]);
6493 break;
6494 }
6495 if (LocaleCompare("fuzz",option+1) == 0)
6496 {
6497 if (*option == '+')
6498 {
6499 image_info->fuzz=0.0;
6500 (void) SetImageOption(image_info,option+1,"0");
6501 break;
6502 }
cristyf2f27272009-12-17 14:48:46 +00006503 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006504 1.0);
6505 (void) SetImageOption(image_info,option+1,argv[i+1]);
6506 break;
6507 }
6508 break;
6509 }
6510 case 'g':
6511 {
6512 if (LocaleCompare("gravity",option+1) == 0)
6513 {
6514 if (*option == '+')
6515 {
6516 (void) SetImageOption(image_info,option+1,"undefined");
6517 break;
6518 }
6519 (void) SetImageOption(image_info,option+1,argv[i+1]);
6520 break;
6521 }
6522 if (LocaleCompare("green-primary",option+1) == 0)
6523 {
6524 if (*option == '+')
6525 {
6526 (void) SetImageOption(image_info,option+1,"0.0");
6527 break;
6528 }
6529 (void) SetImageOption(image_info,option+1,argv[i+1]);
6530 break;
6531 }
6532 break;
6533 }
6534 case 'i':
6535 {
6536 if (LocaleCompare("intent",option+1) == 0)
6537 {
6538 if (*option == '+')
6539 {
6540 (void) SetImageOption(image_info,option+1,"undefined");
6541 break;
6542 }
6543 (void) SetImageOption(image_info,option+1,argv[i+1]);
6544 break;
6545 }
6546 if (LocaleCompare("interlace",option+1) == 0)
6547 {
6548 if (*option == '+')
6549 {
6550 image_info->interlace=UndefinedInterlace;
6551 (void) SetImageOption(image_info,option+1,"undefined");
6552 break;
6553 }
cristy042ee782011-04-22 18:48:30 +00006554 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006555 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6556 (void) SetImageOption(image_info,option+1,argv[i+1]);
6557 break;
6558 }
cristyb32b90a2009-09-07 21:45:48 +00006559 if (LocaleCompare("interline-spacing",option+1) == 0)
6560 {
6561 if (*option == '+')
6562 {
6563 (void) SetImageOption(image_info,option+1,"undefined");
6564 break;
6565 }
6566 (void) SetImageOption(image_info,option+1,argv[i+1]);
6567 break;
6568 }
cristy3ed852e2009-09-05 21:47:34 +00006569 if (LocaleCompare("interpolate",option+1) == 0)
6570 {
6571 if (*option == '+')
6572 {
6573 (void) SetImageOption(image_info,option+1,"undefined");
6574 break;
6575 }
6576 (void) SetImageOption(image_info,option+1,argv[i+1]);
6577 break;
6578 }
6579 if (LocaleCompare("interword-spacing",option+1) == 0)
6580 {
6581 if (*option == '+')
6582 {
6583 (void) SetImageOption(image_info,option+1,"undefined");
6584 break;
6585 }
6586 (void) SetImageOption(image_info,option+1,argv[i+1]);
6587 break;
6588 }
6589 break;
6590 }
6591 case 'k':
6592 {
6593 if (LocaleCompare("kerning",option+1) == 0)
6594 {
6595 if (*option == '+')
6596 {
6597 (void) SetImageOption(image_info,option+1,"undefined");
6598 break;
6599 }
6600 (void) SetImageOption(image_info,option+1,argv[i+1]);
6601 break;
6602 }
6603 break;
6604 }
6605 case 'l':
6606 {
6607 if (LocaleCompare("label",option+1) == 0)
6608 {
6609 if (*option == '+')
6610 {
6611 (void) DeleteImageOption(image_info,option+1);
6612 break;
6613 }
6614 (void) SetImageOption(image_info,option+1,argv[i+1]);
6615 break;
6616 }
6617 if (LocaleCompare("limit",option+1) == 0)
6618 {
6619 MagickSizeType
6620 limit;
6621
6622 ResourceType
6623 type;
6624
6625 if (*option == '+')
6626 break;
cristy042ee782011-04-22 18:48:30 +00006627 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006628 MagickFalse,argv[i+1]);
6629 limit=MagickResourceInfinity;
6630 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006631 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006632 (void) SetMagickResourceLimit(type,limit);
6633 break;
6634 }
6635 if (LocaleCompare("list",option+1) == 0)
6636 {
cristybb503372010-05-27 20:51:26 +00006637 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006638 list;
6639
6640 /*
6641 Display configuration list.
6642 */
cristy042ee782011-04-22 18:48:30 +00006643 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006644 switch (list)
6645 {
6646 case MagickCoderOptions:
6647 {
6648 (void) ListCoderInfo((FILE *) NULL,exception);
6649 break;
6650 }
6651 case MagickColorOptions:
6652 {
6653 (void) ListColorInfo((FILE *) NULL,exception);
6654 break;
6655 }
6656 case MagickConfigureOptions:
6657 {
6658 (void) ListConfigureInfo((FILE *) NULL,exception);
6659 break;
6660 }
6661 case MagickDelegateOptions:
6662 {
6663 (void) ListDelegateInfo((FILE *) NULL,exception);
6664 break;
6665 }
6666 case MagickFontOptions:
6667 {
6668 (void) ListTypeInfo((FILE *) NULL,exception);
6669 break;
6670 }
6671 case MagickFormatOptions:
6672 {
6673 (void) ListMagickInfo((FILE *) NULL,exception);
6674 break;
6675 }
6676 case MagickLocaleOptions:
6677 {
6678 (void) ListLocaleInfo((FILE *) NULL,exception);
6679 break;
6680 }
6681 case MagickLogOptions:
6682 {
6683 (void) ListLogInfo((FILE *) NULL,exception);
6684 break;
6685 }
6686 case MagickMagicOptions:
6687 {
6688 (void) ListMagicInfo((FILE *) NULL,exception);
6689 break;
6690 }
6691 case MagickMimeOptions:
6692 {
6693 (void) ListMimeInfo((FILE *) NULL,exception);
6694 break;
6695 }
6696 case MagickModuleOptions:
6697 {
6698 (void) ListModuleInfo((FILE *) NULL,exception);
6699 break;
6700 }
6701 case MagickPolicyOptions:
6702 {
6703 (void) ListPolicyInfo((FILE *) NULL,exception);
6704 break;
6705 }
6706 case MagickResourceOptions:
6707 {
6708 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6709 break;
6710 }
6711 case MagickThresholdOptions:
6712 {
6713 (void) ListThresholdMaps((FILE *) NULL,exception);
6714 break;
6715 }
6716 default:
6717 {
cristy042ee782011-04-22 18:48:30 +00006718 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006719 exception);
6720 break;
6721 }
6722 }
cristyaeb2cbc2010-05-07 13:28:58 +00006723 break;
cristy3ed852e2009-09-05 21:47:34 +00006724 }
6725 if (LocaleCompare("log",option+1) == 0)
6726 {
6727 if (*option == '+')
6728 break;
6729 (void) SetLogFormat(argv[i+1]);
6730 break;
6731 }
6732 if (LocaleCompare("loop",option+1) == 0)
6733 {
6734 if (*option == '+')
6735 {
6736 (void) SetImageOption(image_info,option+1,"0");
6737 break;
6738 }
6739 (void) SetImageOption(image_info,option+1,argv[i+1]);
6740 break;
6741 }
6742 break;
6743 }
6744 case 'm':
6745 {
6746 if (LocaleCompare("matte",option+1) == 0)
6747 {
6748 if (*option == '+')
6749 {
6750 (void) SetImageOption(image_info,option+1,"false");
6751 break;
6752 }
6753 (void) SetImageOption(image_info,option+1,"true");
6754 break;
6755 }
6756 if (LocaleCompare("mattecolor",option+1) == 0)
6757 {
6758 if (*option == '+')
6759 {
6760 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006761 (void) QueryColorDatabase(MogrifyMatteColor,
6762 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006763 break;
6764 }
6765 (void) SetImageOption(image_info,option+1,argv[i+1]);
6766 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6767 exception);
6768 break;
6769 }
6770 if (LocaleCompare("monitor",option+1) == 0)
6771 {
6772 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6773 (void *) NULL);
6774 break;
6775 }
6776 if (LocaleCompare("monochrome",option+1) == 0)
6777 {
6778 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6779 break;
6780 }
6781 break;
6782 }
6783 case 'o':
6784 {
6785 if (LocaleCompare("orient",option+1) == 0)
6786 {
6787 if (*option == '+')
6788 {
6789 image_info->orientation=UndefinedOrientation;
6790 (void) SetImageOption(image_info,option+1,"undefined");
6791 break;
6792 }
cristy042ee782011-04-22 18:48:30 +00006793 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006794 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006795 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006796 break;
6797 }
6798 }
6799 case 'p':
6800 {
6801 if (LocaleCompare("page",option+1) == 0)
6802 {
6803 char
6804 *canonical_page,
6805 page[MaxTextExtent];
6806
6807 const char
6808 *image_option;
6809
6810 MagickStatusType
6811 flags;
6812
6813 RectangleInfo
6814 geometry;
6815
6816 if (*option == '+')
6817 {
6818 (void) DeleteImageOption(image_info,option+1);
6819 (void) CloneString(&image_info->page,(char *) NULL);
6820 break;
6821 }
6822 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6823 image_option=GetImageOption(image_info,"page");
6824 if (image_option != (const char *) NULL)
6825 flags=ParseAbsoluteGeometry(image_option,&geometry);
6826 canonical_page=GetPageGeometry(argv[i+1]);
6827 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6828 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006829 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006830 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006831 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006832 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006833 (unsigned long) geometry.width,(unsigned long) geometry.height,
6834 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006835 (void) SetImageOption(image_info,option+1,page);
6836 (void) CloneString(&image_info->page,page);
6837 break;
6838 }
6839 if (LocaleCompare("pen",option+1) == 0)
6840 {
6841 if (*option == '+')
6842 {
6843 (void) SetImageOption(image_info,option+1,"none");
6844 break;
6845 }
6846 (void) SetImageOption(image_info,option+1,argv[i+1]);
6847 break;
6848 }
6849 if (LocaleCompare("ping",option+1) == 0)
6850 {
6851 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6852 break;
6853 }
6854 if (LocaleCompare("pointsize",option+1) == 0)
6855 {
6856 if (*option == '+')
6857 geometry_info.rho=0.0;
6858 else
6859 (void) ParseGeometry(argv[i+1],&geometry_info);
6860 image_info->pointsize=geometry_info.rho;
6861 break;
6862 }
cristye7f51092010-01-17 00:39:37 +00006863 if (LocaleCompare("precision",option+1) == 0)
6864 {
cristybf2766a2010-01-17 03:33:23 +00006865 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006866 break;
6867 }
cristy3ed852e2009-09-05 21:47:34 +00006868 if (LocaleCompare("preview",option+1) == 0)
6869 {
6870 /*
6871 Preview image.
6872 */
6873 if (*option == '+')
6874 {
6875 image_info->preview_type=UndefinedPreview;
6876 break;
6877 }
cristy042ee782011-04-22 18:48:30 +00006878 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006879 MagickPreviewOptions,MagickFalse,argv[i+1]);
6880 break;
6881 }
6882 break;
6883 }
6884 case 'q':
6885 {
6886 if (LocaleCompare("quality",option+1) == 0)
6887 {
6888 /*
6889 Set image compression quality.
6890 */
6891 if (*option == '+')
6892 {
6893 image_info->quality=UndefinedCompressionQuality;
6894 (void) SetImageOption(image_info,option+1,"0");
6895 break;
6896 }
cristye27293e2009-12-18 02:53:20 +00006897 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006898 (void) SetImageOption(image_info,option+1,argv[i+1]);
6899 break;
6900 }
6901 if (LocaleCompare("quiet",option+1) == 0)
6902 {
6903 static WarningHandler
6904 warning_handler = (WarningHandler) NULL;
6905
6906 if (*option == '+')
6907 {
6908 /*
6909 Restore error or warning messages.
6910 */
6911 warning_handler=SetWarningHandler(warning_handler);
6912 break;
6913 }
6914 /*
6915 Suppress error or warning messages.
6916 */
6917 warning_handler=SetWarningHandler((WarningHandler) NULL);
6918 break;
6919 }
6920 break;
6921 }
6922 case 'r':
6923 {
6924 if (LocaleCompare("red-primary",option+1) == 0)
6925 {
6926 if (*option == '+')
6927 {
6928 (void) SetImageOption(image_info,option+1,"0.0");
6929 break;
6930 }
6931 (void) SetImageOption(image_info,option+1,argv[i+1]);
6932 break;
6933 }
6934 break;
6935 }
6936 case 's':
6937 {
6938 if (LocaleCompare("sampling-factor",option+1) == 0)
6939 {
6940 /*
6941 Set image sampling factor.
6942 */
6943 if (*option == '+')
6944 {
6945 if (image_info->sampling_factor != (char *) NULL)
6946 image_info->sampling_factor=DestroyString(
6947 image_info->sampling_factor);
6948 break;
6949 }
6950 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6951 break;
6952 }
6953 if (LocaleCompare("scene",option+1) == 0)
6954 {
6955 /*
6956 Set image scene.
6957 */
6958 if (*option == '+')
6959 {
6960 image_info->scene=0;
6961 (void) SetImageOption(image_info,option+1,"0");
6962 break;
6963 }
cristye27293e2009-12-18 02:53:20 +00006964 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006965 (void) SetImageOption(image_info,option+1,argv[i+1]);
6966 break;
6967 }
6968 if (LocaleCompare("seed",option+1) == 0)
6969 {
cristybb503372010-05-27 20:51:26 +00006970 size_t
cristy3ed852e2009-09-05 21:47:34 +00006971 seed;
6972
6973 if (*option == '+')
6974 {
cristybb503372010-05-27 20:51:26 +00006975 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006976 SeedPseudoRandomGenerator(seed);
6977 break;
6978 }
cristye27293e2009-12-18 02:53:20 +00006979 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006980 SeedPseudoRandomGenerator(seed);
6981 break;
6982 }
6983 if (LocaleCompare("size",option+1) == 0)
6984 {
6985 if (*option == '+')
6986 {
6987 if (image_info->size != (char *) NULL)
6988 image_info->size=DestroyString(image_info->size);
6989 break;
6990 }
6991 (void) CloneString(&image_info->size,argv[i+1]);
6992 break;
6993 }
6994 if (LocaleCompare("stroke",option+1) == 0)
6995 {
6996 if (*option == '+')
6997 {
6998 (void) SetImageOption(image_info,option+1,"none");
6999 break;
7000 }
7001 (void) SetImageOption(image_info,option+1,argv[i+1]);
7002 break;
7003 }
7004 if (LocaleCompare("strokewidth",option+1) == 0)
7005 {
7006 if (*option == '+')
7007 {
7008 (void) SetImageOption(image_info,option+1,"0");
7009 break;
7010 }
7011 (void) SetImageOption(image_info,option+1,argv[i+1]);
7012 break;
7013 }
cristyd9a29192010-10-16 16:49:53 +00007014 if (LocaleCompare("synchronize",option+1) == 0)
7015 {
7016 if (*option == '+')
7017 {
7018 image_info->synchronize=MagickFalse;
7019 break;
7020 }
7021 image_info->synchronize=MagickTrue;
7022 break;
7023 }
cristy3ed852e2009-09-05 21:47:34 +00007024 break;
7025 }
7026 case 't':
7027 {
7028 if (LocaleCompare("taint",option+1) == 0)
7029 {
7030 if (*option == '+')
7031 {
7032 (void) SetImageOption(image_info,option+1,"false");
7033 break;
7034 }
7035 (void) SetImageOption(image_info,option+1,"true");
7036 break;
7037 }
7038 if (LocaleCompare("texture",option+1) == 0)
7039 {
7040 if (*option == '+')
7041 {
7042 if (image_info->texture != (char *) NULL)
7043 image_info->texture=DestroyString(image_info->texture);
7044 break;
7045 }
7046 (void) CloneString(&image_info->texture,argv[i+1]);
7047 break;
7048 }
7049 if (LocaleCompare("tile-offset",option+1) == 0)
7050 {
7051 if (*option == '+')
7052 {
7053 (void) SetImageOption(image_info,option+1,"0");
7054 break;
7055 }
7056 (void) SetImageOption(image_info,option+1,argv[i+1]);
7057 break;
7058 }
7059 if (LocaleCompare("transparent-color",option+1) == 0)
7060 {
7061 if (*option == '+')
7062 {
7063 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7064 (void) SetImageOption(image_info,option+1,"none");
7065 break;
7066 }
7067 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7068 exception);
7069 (void) SetImageOption(image_info,option+1,argv[i+1]);
7070 break;
7071 }
7072 if (LocaleCompare("type",option+1) == 0)
7073 {
7074 if (*option == '+')
7075 {
cristy5f1c1ff2010-12-23 21:38:06 +00007076 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007077 (void) SetImageOption(image_info,option+1,"undefined");
7078 break;
7079 }
cristy042ee782011-04-22 18:48:30 +00007080 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007081 MagickFalse,argv[i+1]);
7082 (void) SetImageOption(image_info,option+1,argv[i+1]);
7083 break;
7084 }
7085 break;
7086 }
7087 case 'u':
7088 {
7089 if (LocaleCompare("undercolor",option+1) == 0)
7090 {
7091 if (*option == '+')
7092 {
7093 (void) DeleteImageOption(image_info,option+1);
7094 break;
7095 }
7096 (void) SetImageOption(image_info,option+1,argv[i+1]);
7097 break;
7098 }
7099 if (LocaleCompare("units",option+1) == 0)
7100 {
7101 if (*option == '+')
7102 {
7103 image_info->units=UndefinedResolution;
7104 (void) SetImageOption(image_info,option+1,"undefined");
7105 break;
7106 }
cristy042ee782011-04-22 18:48:30 +00007107 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007108 MagickResolutionOptions,MagickFalse,argv[i+1]);
7109 (void) SetImageOption(image_info,option+1,argv[i+1]);
7110 break;
7111 }
7112 break;
7113 }
7114 case 'v':
7115 {
7116 if (LocaleCompare("verbose",option+1) == 0)
7117 {
7118 if (*option == '+')
7119 {
7120 image_info->verbose=MagickFalse;
7121 break;
7122 }
7123 image_info->verbose=MagickTrue;
7124 image_info->ping=MagickFalse;
7125 break;
7126 }
7127 if (LocaleCompare("view",option+1) == 0)
7128 {
7129 if (*option == '+')
7130 {
7131 if (image_info->view != (char *) NULL)
7132 image_info->view=DestroyString(image_info->view);
7133 break;
7134 }
7135 (void) CloneString(&image_info->view,argv[i+1]);
7136 break;
7137 }
7138 if (LocaleCompare("virtual-pixel",option+1) == 0)
7139 {
7140 if (*option == '+')
7141 {
7142 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7143 (void) SetImageOption(image_info,option+1,"undefined");
7144 break;
7145 }
7146 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007147 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007148 argv[i+1]);
7149 (void) SetImageOption(image_info,option+1,argv[i+1]);
7150 break;
7151 }
7152 break;
7153 }
7154 case 'w':
7155 {
7156 if (LocaleCompare("white-point",option+1) == 0)
7157 {
7158 if (*option == '+')
7159 {
7160 (void) SetImageOption(image_info,option+1,"0.0");
7161 break;
7162 }
7163 (void) SetImageOption(image_info,option+1,argv[i+1]);
7164 break;
7165 }
7166 break;
7167 }
7168 default:
7169 break;
7170 }
7171 i+=count;
7172 }
7173 return(MagickTrue);
7174}
7175
7176/*
7177%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7178% %
7179% %
7180% %
7181+ M o g r i f y I m a g e L i s t %
7182% %
7183% %
7184% %
7185%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7186%
7187% MogrifyImageList() applies any command line options that might affect the
7188% entire image list (e.g. -append, -coalesce, etc.).
7189%
7190% The format of the MogrifyImage method is:
7191%
7192% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7193% const char **argv,Image **images,ExceptionInfo *exception)
7194%
7195% A description of each parameter follows:
7196%
7197% o image_info: the image info..
7198%
7199% o argc: Specifies a pointer to an integer describing the number of
7200% elements in the argument vector.
7201%
7202% o argv: Specifies a pointer to a text array containing the command line
7203% arguments.
7204%
anthonye9c27192011-03-27 08:07:06 +00007205% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007206%
7207% o exception: return any errors or warnings in this structure.
7208%
7209*/
7210WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7211 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7212{
cristy3ed852e2009-09-05 21:47:34 +00007213 const char
7214 *option;
7215
cristy6b3da3a2010-06-20 02:21:46 +00007216 ImageInfo
7217 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007218
7219 MagickStatusType
7220 status;
7221
7222 QuantizeInfo
7223 *quantize_info;
7224
cristybb503372010-05-27 20:51:26 +00007225 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007226 i;
7227
cristy6b3da3a2010-06-20 02:21:46 +00007228 ssize_t
7229 count,
7230 index;
7231
cristy3ed852e2009-09-05 21:47:34 +00007232 /*
7233 Apply options to the image list.
7234 */
7235 assert(image_info != (ImageInfo *) NULL);
7236 assert(image_info->signature == MagickSignature);
7237 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007238 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007239 assert((*images)->signature == MagickSignature);
7240 if ((*images)->debug != MagickFalse)
7241 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7242 (*images)->filename);
7243 if ((argc <= 0) || (*argv == (char *) NULL))
7244 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007245 mogrify_info=CloneImageInfo(image_info);
7246 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007247 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007248 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007249 {
cristy74fe8f12009-10-03 19:09:01 +00007250 if (*images == (Image *) NULL)
7251 break;
cristy3ed852e2009-09-05 21:47:34 +00007252 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007253 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007254 continue;
cristy042ee782011-04-22 18:48:30 +00007255 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007256 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007257 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007258 break;
cristy6b3da3a2010-06-20 02:21:46 +00007259 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007260 switch (*(option+1))
7261 {
7262 case 'a':
7263 {
7264 if (LocaleCompare("affinity",option+1) == 0)
7265 {
cristy6b3da3a2010-06-20 02:21:46 +00007266 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007267 if (*option == '+')
7268 {
7269 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7270 InheritException(exception,&(*images)->exception);
7271 break;
7272 }
7273 i++;
7274 break;
7275 }
7276 if (LocaleCompare("append",option+1) == 0)
7277 {
7278 Image
7279 *append_image;
7280
cristy6b3da3a2010-06-20 02:21:46 +00007281 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007282 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7283 MagickFalse,exception);
7284 if (append_image == (Image *) NULL)
7285 {
7286 status=MagickFalse;
7287 break;
7288 }
7289 *images=DestroyImageList(*images);
7290 *images=append_image;
7291 break;
7292 }
7293 if (LocaleCompare("average",option+1) == 0)
7294 {
7295 Image
7296 *average_image;
7297
cristyd18ae7c2010-03-07 17:39:52 +00007298 /*
7299 Average an image sequence (deprecated).
7300 */
cristy6b3da3a2010-06-20 02:21:46 +00007301 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007302 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7303 exception);
cristy3ed852e2009-09-05 21:47:34 +00007304 if (average_image == (Image *) NULL)
7305 {
7306 status=MagickFalse;
7307 break;
7308 }
7309 *images=DestroyImageList(*images);
7310 *images=average_image;
7311 break;
7312 }
7313 break;
7314 }
7315 case 'c':
7316 {
7317 if (LocaleCompare("channel",option+1) == 0)
7318 {
cristyf4ad9df2011-07-08 16:49:03 +00007319 ChannelType
7320 channel;
7321
cristy3ed852e2009-09-05 21:47:34 +00007322 if (*option == '+')
7323 {
7324 channel=DefaultChannels;
7325 break;
7326 }
7327 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007328 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007329 break;
7330 }
7331 if (LocaleCompare("clut",option+1) == 0)
7332 {
7333 Image
7334 *clut_image,
7335 *image;
7336
cristy6b3da3a2010-06-20 02:21:46 +00007337 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007338 image=RemoveFirstImageFromList(images);
7339 clut_image=RemoveFirstImageFromList(images);
7340 if (clut_image == (Image *) NULL)
7341 {
7342 status=MagickFalse;
7343 break;
7344 }
cristy444eda62011-08-10 02:07:46 +00007345 (void) ClutImage(image,clut_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007346 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007347 *images=DestroyImageList(*images);
7348 *images=image;
7349 break;
7350 }
7351 if (LocaleCompare("coalesce",option+1) == 0)
7352 {
7353 Image
7354 *coalesce_image;
7355
cristy6b3da3a2010-06-20 02:21:46 +00007356 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007357 coalesce_image=CoalesceImages(*images,exception);
7358 if (coalesce_image == (Image *) NULL)
7359 {
7360 status=MagickFalse;
7361 break;
7362 }
7363 *images=DestroyImageList(*images);
7364 *images=coalesce_image;
7365 break;
7366 }
7367 if (LocaleCompare("combine",option+1) == 0)
7368 {
7369 Image
7370 *combine_image;
7371
cristy6b3da3a2010-06-20 02:21:46 +00007372 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007373 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007374 if (combine_image == (Image *) NULL)
7375 {
7376 status=MagickFalse;
7377 break;
7378 }
7379 *images=DestroyImageList(*images);
7380 *images=combine_image;
7381 break;
7382 }
7383 if (LocaleCompare("composite",option+1) == 0)
7384 {
7385 Image
7386 *mask_image,
7387 *composite_image,
7388 *image;
7389
7390 RectangleInfo
7391 geometry;
7392
cristy6b3da3a2010-06-20 02:21:46 +00007393 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007394 image=RemoveFirstImageFromList(images);
7395 composite_image=RemoveFirstImageFromList(images);
7396 if (composite_image == (Image *) NULL)
7397 {
7398 status=MagickFalse;
7399 break;
7400 }
7401 (void) TransformImage(&composite_image,(char *) NULL,
7402 composite_image->geometry);
7403 SetGeometry(composite_image,&geometry);
7404 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7405 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7406 &geometry);
7407 mask_image=RemoveFirstImageFromList(images);
7408 if (mask_image != (Image *) NULL)
7409 {
7410 if ((image->compose == DisplaceCompositeOp) ||
7411 (image->compose == DistortCompositeOp))
7412 {
7413 /*
7414 Merge Y displacement into X displacement image.
7415 */
7416 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7417 mask_image,0,0);
7418 mask_image=DestroyImage(mask_image);
7419 }
7420 else
7421 {
7422 /*
7423 Set a blending mask for the composition.
7424 */
anthonya129f702011-04-14 01:08:48 +00007425 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007426 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007427 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007428 }
7429 }
cristyf4ad9df2011-07-08 16:49:03 +00007430 (void) CompositeImage(image,image->compose,composite_image,
7431 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007432 if (mask_image != (Image *) NULL)
7433 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007434 composite_image=DestroyImage(composite_image);
7435 InheritException(exception,&image->exception);
7436 *images=DestroyImageList(*images);
7437 *images=image;
7438 break;
7439 }
anthony9f4f0342011-03-28 11:47:22 +00007440#if 0
7441This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007442 if (LocaleCompare("crop",option+1) == 0)
7443 {
7444 MagickStatusType
7445 flags;
7446
7447 RectangleInfo
7448 geometry;
7449
anthonye9c27192011-03-27 08:07:06 +00007450 /*
anthony9f4f0342011-03-28 11:47:22 +00007451 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007452 */
cristy6b3da3a2010-06-20 02:21:46 +00007453 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007454 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7455 if (((geometry.width == 0) && (geometry.height == 0)) ||
7456 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7457 break;
7458 (void) TransformImages(images,argv[i+1],(char *) NULL);
7459 InheritException(exception,&(*images)->exception);
7460 break;
7461 }
anthony9f4f0342011-03-28 11:47:22 +00007462#endif
cristy3ed852e2009-09-05 21:47:34 +00007463 break;
7464 }
7465 case 'd':
7466 {
7467 if (LocaleCompare("deconstruct",option+1) == 0)
7468 {
7469 Image
7470 *deconstruct_image;
7471
cristy6b3da3a2010-06-20 02:21:46 +00007472 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007473 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007474 exception);
cristy3ed852e2009-09-05 21:47:34 +00007475 if (deconstruct_image == (Image *) NULL)
7476 {
7477 status=MagickFalse;
7478 break;
7479 }
7480 *images=DestroyImageList(*images);
7481 *images=deconstruct_image;
7482 break;
7483 }
7484 if (LocaleCompare("delete",option+1) == 0)
7485 {
7486 if (*option == '+')
7487 DeleteImages(images,"-1",exception);
7488 else
7489 DeleteImages(images,argv[i+1],exception);
7490 break;
7491 }
7492 if (LocaleCompare("dither",option+1) == 0)
7493 {
7494 if (*option == '+')
7495 {
7496 quantize_info->dither=MagickFalse;
7497 break;
7498 }
7499 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007500 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007501 MagickDitherOptions,MagickFalse,argv[i+1]);
7502 break;
7503 }
cristyecb10ff2011-03-22 13:14:03 +00007504 if (LocaleCompare("duplicate",option+1) == 0)
7505 {
cristy72988482011-03-29 16:34:38 +00007506 Image
7507 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007508
anthony2b6bcae2011-03-23 13:05:34 +00007509 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007510 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7511 else
7512 {
7513 const char
7514 *p;
7515
anthony2b6bcae2011-03-23 13:05:34 +00007516 size_t
7517 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007518
anthony2b6bcae2011-03-23 13:05:34 +00007519 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007520 p=strchr(argv[i+1],',');
7521 if (p == (const char *) NULL)
7522 duplicate_images=DuplicateImages(*images,number_duplicates,
7523 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007524 else
cristy72988482011-03-29 16:34:38 +00007525 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7526 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007527 }
7528 AppendImageToList(images, duplicate_images);
7529 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007530 break;
7531 }
cristy3ed852e2009-09-05 21:47:34 +00007532 break;
7533 }
cristyd18ae7c2010-03-07 17:39:52 +00007534 case 'e':
7535 {
7536 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7537 {
7538 Image
7539 *evaluate_image;
7540
7541 MagickEvaluateOperator
7542 op;
7543
cristy6b3da3a2010-06-20 02:21:46 +00007544 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007545 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007546 MagickFalse,argv[i+1]);
7547 evaluate_image=EvaluateImages(*images,op,exception);
7548 if (evaluate_image == (Image *) NULL)
7549 {
7550 status=MagickFalse;
7551 break;
7552 }
7553 *images=DestroyImageList(*images);
7554 *images=evaluate_image;
7555 break;
7556 }
7557 break;
7558 }
cristy3ed852e2009-09-05 21:47:34 +00007559 case 'f':
7560 {
cristyf0a247f2009-10-04 00:20:03 +00007561 if (LocaleCompare("fft",option+1) == 0)
7562 {
7563 Image
7564 *fourier_image;
7565
7566 /*
7567 Implements the discrete Fourier transform (DFT).
7568 */
cristy6b3da3a2010-06-20 02:21:46 +00007569 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007570 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7571 MagickTrue : MagickFalse,exception);
7572 if (fourier_image == (Image *) NULL)
7573 break;
7574 *images=DestroyImage(*images);
7575 *images=fourier_image;
7576 break;
7577 }
cristy3ed852e2009-09-05 21:47:34 +00007578 if (LocaleCompare("flatten",option+1) == 0)
7579 {
7580 Image
7581 *flatten_image;
7582
cristy6b3da3a2010-06-20 02:21:46 +00007583 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007584 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7585 if (flatten_image == (Image *) NULL)
7586 break;
7587 *images=DestroyImageList(*images);
7588 *images=flatten_image;
7589 break;
7590 }
7591 if (LocaleCompare("fx",option+1) == 0)
7592 {
7593 Image
7594 *fx_image;
7595
cristy6b3da3a2010-06-20 02:21:46 +00007596 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007597 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007598 if (fx_image == (Image *) NULL)
7599 {
7600 status=MagickFalse;
7601 break;
7602 }
7603 *images=DestroyImageList(*images);
7604 *images=fx_image;
7605 break;
7606 }
7607 break;
7608 }
7609 case 'h':
7610 {
7611 if (LocaleCompare("hald-clut",option+1) == 0)
7612 {
7613 Image
7614 *hald_image,
7615 *image;
7616
cristy6b3da3a2010-06-20 02:21:46 +00007617 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007618 image=RemoveFirstImageFromList(images);
7619 hald_image=RemoveFirstImageFromList(images);
7620 if (hald_image == (Image *) NULL)
7621 {
7622 status=MagickFalse;
7623 break;
7624 }
cristyf89cb1d2011-07-07 01:24:37 +00007625 (void) HaldClutImage(image,hald_image);
cristy3ed852e2009-09-05 21:47:34 +00007626 hald_image=DestroyImage(hald_image);
7627 InheritException(exception,&image->exception);
cristy0aff6ea2009-11-14 01:40:53 +00007628 if (*images != (Image *) NULL)
7629 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007630 *images=image;
7631 break;
7632 }
7633 break;
7634 }
7635 case 'i':
7636 {
7637 if (LocaleCompare("ift",option+1) == 0)
7638 {
7639 Image
cristy8587f882009-11-13 20:28:49 +00007640 *fourier_image,
7641 *magnitude_image,
7642 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007643
7644 /*
7645 Implements the inverse fourier discrete Fourier transform (DFT).
7646 */
cristy6b3da3a2010-06-20 02:21:46 +00007647 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007648 magnitude_image=RemoveFirstImageFromList(images);
7649 phase_image=RemoveFirstImageFromList(images);
7650 if (phase_image == (Image *) NULL)
7651 {
7652 status=MagickFalse;
7653 break;
7654 }
7655 fourier_image=InverseFourierTransformImage(magnitude_image,
7656 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007657 if (fourier_image == (Image *) NULL)
7658 break;
cristy0aff6ea2009-11-14 01:40:53 +00007659 if (*images != (Image *) NULL)
7660 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007661 *images=fourier_image;
7662 break;
7663 }
7664 if (LocaleCompare("insert",option+1) == 0)
7665 {
7666 Image
7667 *p,
7668 *q;
7669
7670 index=0;
7671 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007672 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007673 p=RemoveLastImageFromList(images);
7674 if (p == (Image *) NULL)
7675 {
7676 (void) ThrowMagickException(exception,GetMagickModule(),
7677 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7678 status=MagickFalse;
7679 break;
7680 }
7681 q=p;
7682 if (index == 0)
7683 PrependImageToList(images,q);
7684 else
cristybb503372010-05-27 20:51:26 +00007685 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007686 AppendImageToList(images,q);
7687 else
7688 {
7689 q=GetImageFromList(*images,index-1);
7690 if (q == (Image *) NULL)
7691 {
7692 (void) ThrowMagickException(exception,GetMagickModule(),
7693 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7694 status=MagickFalse;
7695 break;
7696 }
7697 InsertImageInList(&q,p);
7698 }
7699 *images=GetFirstImageInList(q);
7700 break;
7701 }
7702 break;
7703 }
7704 case 'l':
7705 {
7706 if (LocaleCompare("layers",option+1) == 0)
7707 {
7708 Image
7709 *layers;
7710
7711 ImageLayerMethod
7712 method;
7713
cristy6b3da3a2010-06-20 02:21:46 +00007714 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007715 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007716 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007717 MagickFalse,argv[i+1]);
7718 switch (method)
7719 {
7720 case CoalesceLayer:
7721 {
7722 layers=CoalesceImages(*images,exception);
7723 break;
7724 }
7725 case CompareAnyLayer:
7726 case CompareClearLayer:
7727 case CompareOverlayLayer:
7728 default:
7729 {
cristy8a9106f2011-07-05 14:39:26 +00007730 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007731 break;
7732 }
7733 case MergeLayer:
7734 case FlattenLayer:
7735 case MosaicLayer:
7736 case TrimBoundsLayer:
7737 {
7738 layers=MergeImageLayers(*images,method,exception);
7739 break;
7740 }
7741 case DisposeLayer:
7742 {
7743 layers=DisposeImages(*images,exception);
7744 break;
7745 }
7746 case OptimizeImageLayer:
7747 {
7748 layers=OptimizeImageLayers(*images,exception);
7749 break;
7750 }
7751 case OptimizePlusLayer:
7752 {
7753 layers=OptimizePlusImageLayers(*images,exception);
7754 break;
7755 }
7756 case OptimizeTransLayer:
7757 {
7758 OptimizeImageTransparency(*images,exception);
7759 break;
7760 }
7761 case RemoveDupsLayer:
7762 {
7763 RemoveDuplicateLayers(images,exception);
7764 break;
7765 }
7766 case RemoveZeroLayer:
7767 {
7768 RemoveZeroDelayLayers(images,exception);
7769 break;
7770 }
7771 case OptimizeLayer:
7772 {
7773 /*
7774 General Purpose, GIF Animation Optimizer.
7775 */
7776 layers=CoalesceImages(*images,exception);
7777 if (layers == (Image *) NULL)
7778 {
7779 status=MagickFalse;
7780 break;
7781 }
7782 InheritException(exception,&layers->exception);
7783 *images=DestroyImageList(*images);
7784 *images=layers;
7785 layers=OptimizeImageLayers(*images,exception);
7786 if (layers == (Image *) NULL)
7787 {
7788 status=MagickFalse;
7789 break;
7790 }
7791 InheritException(exception,&layers->exception);
7792 *images=DestroyImageList(*images);
7793 *images=layers;
7794 layers=(Image *) NULL;
7795 OptimizeImageTransparency(*images,exception);
7796 InheritException(exception,&(*images)->exception);
7797 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7798 break;
7799 }
7800 case CompositeLayer:
7801 {
7802 CompositeOperator
7803 compose;
7804
7805 Image
7806 *source;
7807
7808 RectangleInfo
7809 geometry;
7810
7811 /*
7812 Split image sequence at the first 'NULL:' image.
7813 */
7814 source=(*images);
7815 while (source != (Image *) NULL)
7816 {
7817 source=GetNextImageInList(source);
7818 if ((source != (Image *) NULL) &&
7819 (LocaleCompare(source->magick,"NULL") == 0))
7820 break;
7821 }
7822 if (source != (Image *) NULL)
7823 {
7824 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7825 (GetNextImageInList(source) == (Image *) NULL))
7826 source=(Image *) NULL;
7827 else
7828 {
7829 /*
7830 Separate the two lists, junk the null: image.
7831 */
7832 source=SplitImageList(source->previous);
7833 DeleteImageFromList(&source);
7834 }
7835 }
7836 if (source == (Image *) NULL)
7837 {
7838 (void) ThrowMagickException(exception,GetMagickModule(),
7839 OptionError,"MissingNullSeparator","layers Composite");
7840 status=MagickFalse;
7841 break;
7842 }
7843 /*
7844 Adjust offset with gravity and virtual canvas.
7845 */
7846 SetGeometry(*images,&geometry);
7847 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7848 geometry.width=source->page.width != 0 ?
7849 source->page.width : source->columns;
7850 geometry.height=source->page.height != 0 ?
7851 source->page.height : source->rows;
7852 GravityAdjustGeometry((*images)->page.width != 0 ?
7853 (*images)->page.width : (*images)->columns,
7854 (*images)->page.height != 0 ? (*images)->page.height :
7855 (*images)->rows,(*images)->gravity,&geometry);
7856 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007857 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007858 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007859 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007860 MagickComposeOptions,MagickFalse,option);
7861 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7862 exception);
7863 source=DestroyImageList(source);
7864 break;
7865 }
7866 }
7867 if (layers == (Image *) NULL)
7868 break;
7869 InheritException(exception,&layers->exception);
7870 *images=DestroyImageList(*images);
7871 *images=layers;
7872 break;
7873 }
7874 break;
7875 }
7876 case 'm':
7877 {
7878 if (LocaleCompare("map",option+1) == 0)
7879 {
cristy6b3da3a2010-06-20 02:21:46 +00007880 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007881 if (*option == '+')
7882 {
7883 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7884 InheritException(exception,&(*images)->exception);
7885 break;
7886 }
7887 i++;
7888 break;
7889 }
cristyf40785b2010-03-06 02:27:27 +00007890 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007891 {
7892 Image
cristyf40785b2010-03-06 02:27:27 +00007893 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007894
cristyd18ae7c2010-03-07 17:39:52 +00007895 /*
7896 Maximum image sequence (deprecated).
7897 */
cristy6b3da3a2010-06-20 02:21:46 +00007898 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007899 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007900 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007901 {
7902 status=MagickFalse;
7903 break;
7904 }
7905 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007906 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007907 break;
7908 }
cristyf40785b2010-03-06 02:27:27 +00007909 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007910 {
7911 Image
cristyf40785b2010-03-06 02:27:27 +00007912 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007913
cristyd18ae7c2010-03-07 17:39:52 +00007914 /*
7915 Minimum image sequence (deprecated).
7916 */
cristy6b3da3a2010-06-20 02:21:46 +00007917 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007918 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007919 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007920 {
7921 status=MagickFalse;
7922 break;
7923 }
7924 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007925 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007926 break;
7927 }
cristy3ed852e2009-09-05 21:47:34 +00007928 if (LocaleCompare("morph",option+1) == 0)
7929 {
7930 Image
7931 *morph_image;
7932
cristy6b3da3a2010-06-20 02:21:46 +00007933 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007934 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007935 exception);
7936 if (morph_image == (Image *) NULL)
7937 {
7938 status=MagickFalse;
7939 break;
7940 }
7941 *images=DestroyImageList(*images);
7942 *images=morph_image;
7943 break;
7944 }
7945 if (LocaleCompare("mosaic",option+1) == 0)
7946 {
7947 Image
7948 *mosaic_image;
7949
cristy6b3da3a2010-06-20 02:21:46 +00007950 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007951 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7952 if (mosaic_image == (Image *) NULL)
7953 {
7954 status=MagickFalse;
7955 break;
7956 }
7957 *images=DestroyImageList(*images);
7958 *images=mosaic_image;
7959 break;
7960 }
7961 break;
7962 }
7963 case 'p':
7964 {
7965 if (LocaleCompare("print",option+1) == 0)
7966 {
7967 char
7968 *string;
7969
cristy6b3da3a2010-06-20 02:21:46 +00007970 (void) SyncImagesSettings(mogrify_info,*images);
7971 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007972 if (string == (char *) NULL)
7973 break;
7974 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007975 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007976 string=DestroyString(string);
7977 }
7978 if (LocaleCompare("process",option+1) == 0)
7979 {
7980 char
7981 **arguments;
7982
7983 int
7984 j,
7985 number_arguments;
7986
cristy6b3da3a2010-06-20 02:21:46 +00007987 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007988 arguments=StringToArgv(argv[i+1],&number_arguments);
7989 if (arguments == (char **) NULL)
7990 break;
7991 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7992 {
7993 char
7994 breaker,
7995 quote,
7996 *token;
7997
7998 const char
7999 *arguments;
8000
8001 int
8002 next,
8003 status;
8004
8005 size_t
8006 length;
8007
8008 TokenInfo
8009 *token_info;
8010
8011 /*
8012 Support old style syntax, filter="-option arg".
8013 */
8014 length=strlen(argv[i+1]);
8015 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008016 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008017 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8018 sizeof(*token));
8019 if (token == (char *) NULL)
8020 break;
8021 next=0;
8022 arguments=argv[i+1];
8023 token_info=AcquireTokenInfo();
8024 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8025 "\"",'\0',&breaker,&next,&quote);
8026 token_info=DestroyTokenInfo(token_info);
8027 if (status == 0)
8028 {
8029 const char
8030 *argv;
8031
8032 argv=(&(arguments[next]));
8033 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8034 exception);
8035 }
8036 token=DestroyString(token);
8037 break;
8038 }
cristy91c0da22010-05-02 01:44:07 +00008039 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008040 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8041 number_arguments-2,(const char **) arguments+2,exception);
8042 for (j=0; j < number_arguments; j++)
8043 arguments[j]=DestroyString(arguments[j]);
8044 arguments=(char **) RelinquishMagickMemory(arguments);
8045 break;
8046 }
8047 break;
8048 }
8049 case 'r':
8050 {
8051 if (LocaleCompare("reverse",option+1) == 0)
8052 {
8053 ReverseImageList(images);
8054 InheritException(exception,&(*images)->exception);
8055 break;
8056 }
8057 break;
8058 }
8059 case 's':
8060 {
cristy4285d782011-02-09 20:12:28 +00008061 if (LocaleCompare("smush",option+1) == 0)
8062 {
8063 Image
8064 *smush_image;
8065
8066 ssize_t
8067 offset;
8068
8069 (void) SyncImagesSettings(mogrify_info,*images);
8070 offset=(ssize_t) StringToLong(argv[i+1]);
8071 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8072 MagickFalse,offset,exception);
8073 if (smush_image == (Image *) NULL)
8074 {
8075 status=MagickFalse;
8076 break;
8077 }
8078 *images=DestroyImageList(*images);
8079 *images=smush_image;
8080 break;
8081 }
cristy3ed852e2009-09-05 21:47:34 +00008082 if (LocaleCompare("swap",option+1) == 0)
8083 {
8084 Image
8085 *p,
8086 *q,
8087 *swap;
8088
cristybb503372010-05-27 20:51:26 +00008089 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008090 swap_index;
8091
8092 index=(-1);
8093 swap_index=(-2);
8094 if (*option != '+')
8095 {
8096 GeometryInfo
8097 geometry_info;
8098
8099 MagickStatusType
8100 flags;
8101
8102 swap_index=(-1);
8103 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008104 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008105 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008106 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008107 }
8108 p=GetImageFromList(*images,index);
8109 q=GetImageFromList(*images,swap_index);
8110 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8111 {
8112 (void) ThrowMagickException(exception,GetMagickModule(),
8113 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8114 status=MagickFalse;
8115 break;
8116 }
8117 if (p == q)
8118 break;
8119 swap=CloneImage(p,0,0,MagickTrue,exception);
8120 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8121 ReplaceImageInList(&q,swap);
8122 *images=GetFirstImageInList(q);
8123 break;
8124 }
8125 break;
8126 }
8127 case 'w':
8128 {
8129 if (LocaleCompare("write",option+1) == 0)
8130 {
cristy071dd7b2010-04-09 13:04:54 +00008131 char
cristy06609ee2010-03-17 20:21:27 +00008132 key[MaxTextExtent];
8133
cristy3ed852e2009-09-05 21:47:34 +00008134 Image
8135 *write_images;
8136
8137 ImageInfo
8138 *write_info;
8139
cristy6b3da3a2010-06-20 02:21:46 +00008140 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008141 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008142 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008143 write_images=(*images);
8144 if (*option == '+')
8145 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008146 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008147 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8148 write_info=DestroyImageInfo(write_info);
8149 if (*option == '+')
8150 write_images=DestroyImageList(write_images);
8151 break;
8152 }
8153 break;
8154 }
8155 default:
8156 break;
8157 }
8158 i+=count;
8159 }
8160 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008161 mogrify_info=DestroyImageInfo(mogrify_info);
8162 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008163 return(status != 0 ? MagickTrue : MagickFalse);
8164}
8165
8166/*
8167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8168% %
8169% %
8170% %
8171+ M o g r i f y I m a g e s %
8172% %
8173% %
8174% %
8175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8176%
8177% MogrifyImages() applies image processing options to a sequence of images as
8178% prescribed by command line options.
8179%
8180% The format of the MogrifyImage method is:
8181%
8182% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8183% const MagickBooleanType post,const int argc,const char **argv,
8184% Image **images,Exceptioninfo *exception)
8185%
8186% A description of each parameter follows:
8187%
8188% o image_info: the image info..
8189%
8190% o post: If true, post process image list operators otherwise pre-process.
8191%
8192% o argc: Specifies a pointer to an integer describing the number of
8193% elements in the argument vector.
8194%
8195% o argv: Specifies a pointer to a text array containing the command line
8196% arguments.
8197%
anthonye9c27192011-03-27 08:07:06 +00008198% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008199%
8200% o exception: return any errors or warnings in this structure.
8201%
8202*/
8203WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8204 const MagickBooleanType post,const int argc,const char **argv,
8205 Image **images,ExceptionInfo *exception)
8206{
8207#define MogrifyImageTag "Mogrify/Image"
8208
anthonye9c27192011-03-27 08:07:06 +00008209 MagickStatusType
8210 status;
cristy3ed852e2009-09-05 21:47:34 +00008211
cristy0e9f9c12010-02-11 03:00:47 +00008212 MagickBooleanType
8213 proceed;
8214
anthonye9c27192011-03-27 08:07:06 +00008215 size_t
8216 n;
cristy3ed852e2009-09-05 21:47:34 +00008217
cristybb503372010-05-27 20:51:26 +00008218 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008219 i;
8220
cristy3ed852e2009-09-05 21:47:34 +00008221 assert(image_info != (ImageInfo *) NULL);
8222 assert(image_info->signature == MagickSignature);
8223 if (images == (Image **) NULL)
8224 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008225 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008226 assert((*images)->signature == MagickSignature);
8227 if ((*images)->debug != MagickFalse)
8228 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8229 (*images)->filename);
8230 if ((argc <= 0) || (*argv == (char *) NULL))
8231 return(MagickTrue);
8232 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8233 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008234 status=0;
anthonye9c27192011-03-27 08:07:06 +00008235
anthonyce2716b2011-04-22 09:51:34 +00008236#if 0
cristy1e604812011-05-19 18:07:50 +00008237 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8238 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008239#endif
8240
anthonye9c27192011-03-27 08:07:06 +00008241 /*
8242 Pre-process multi-image sequence operators
8243 */
cristy3ed852e2009-09-05 21:47:34 +00008244 if (post == MagickFalse)
8245 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008246 /*
8247 For each image, process simple single image operators
8248 */
8249 i=0;
8250 n=GetImageListLength(*images);
8251 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008252 {
anthonyce2716b2011-04-22 09:51:34 +00008253#if 0
cristy1e604812011-05-19 18:07:50 +00008254 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8255 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008256#endif
anthonye9c27192011-03-27 08:07:06 +00008257 status&=MogrifyImage(image_info,argc,argv,images,exception);
8258 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008259 if (proceed == MagickFalse)
8260 break;
anthonye9c27192011-03-27 08:07:06 +00008261 if ( (*images)->next == (Image *) NULL )
8262 break;
8263 *images=(*images)->next;
8264 i++;
cristy3ed852e2009-09-05 21:47:34 +00008265 }
anthonye9c27192011-03-27 08:07:06 +00008266 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008267#if 0
cristy1e604812011-05-19 18:07:50 +00008268 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8269 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008270#endif
anthonye9c27192011-03-27 08:07:06 +00008271
8272 /*
8273 Post-process, multi-image sequence operators
8274 */
8275 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008276 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008277 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008278 return(status != 0 ? MagickTrue : MagickFalse);
8279}