blob: 7570fc0b7570f3d5121f70b5608eb884b7f51507 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
54#include "MagickCore/thread-private.h"
55#include "MagickCore/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000056
57/*
cristy154fa9d2011-08-05 14:25:15 +000058 Constant declaration.
59*/
cristy3a557c02011-08-06 19:48:02 +000060static const char
cristy638895a2011-08-06 23:19:14 +000061 MogrifyBackgroundColor[] = "#ffffff", /* white */
62 MogrifyBorderColor[] = "#dfdfdf", /* gray */
63 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000064
65/*
cristy3ed852e2009-09-05 21:47:34 +000066 Define declarations.
67*/
68#define UndefinedCompressionQuality 0UL
69
70/*
cristy3ed852e2009-09-05 21:47:34 +000071%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% %
73% %
74% %
cristy5063d812010-10-19 16:28:10 +000075% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000076% %
77% %
78% %
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80%
81% MagickCommandGenesis() applies image processing options to an image as
82% prescribed by command line options.
83%
84% The format of the MagickCommandGenesis method is:
85%
86% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000087% MagickCommand command,int argc,char **argv,char **metadata,
88% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000089%
90% A description of each parameter follows:
91%
92% o image_info: the image info.
93%
cristy5063d812010-10-19 16:28:10 +000094% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000095% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000096% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
97% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000098%
99% o argc: Specifies a pointer to an integer describing the number of
100% elements in the argument vector.
101%
102% o argv: Specifies a pointer to a text array containing the command line
103% arguments.
104%
cristy5063d812010-10-19 16:28:10 +0000105% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000106%
107% o exception: return any errors or warnings in this structure.
108%
109*/
110WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
111 MagickCommand command,int argc,char **argv,char **metadata,
112 ExceptionInfo *exception)
113{
114 char
115 *option;
116
117 double
118 duration,
119 elapsed_time,
120 user_time;
121
cristy3980b0d2009-10-25 14:37:13 +0000122 MagickBooleanType
123 concurrent,
124 regard_warnings,
125 status;
126
cristybb503372010-05-27 20:51:26 +0000127 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000128 i;
129
130 TimerInfo
131 *timer;
132
cristybb503372010-05-27 20:51:26 +0000133 size_t
cristy3980b0d2009-10-25 14:37:13 +0000134 iterations;
135
cristyd0a94fa2010-03-12 14:18:11 +0000136 (void) setlocale(LC_ALL,"");
137 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000138 concurrent=MagickFalse;
139 duration=(-1.0);
140 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000141 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000142 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000143 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000144 {
145 option=argv[i];
146 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
147 continue;
148 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000149 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000150 if (LocaleCompare("concurrent",option+1) == 0)
151 concurrent=MagickTrue;
152 if (LocaleCompare("debug",option+1) == 0)
153 (void) SetLogEventMask(argv[++i]);
154 if (LocaleCompare("duration",option+1) == 0)
cristyc1acd842011-05-19 23:05:47 +0000155 duration=InterpretLocaleValue(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000156 if (LocaleCompare("regard-warnings",option+1) == 0)
157 regard_warnings=MagickTrue;
158 }
159 timer=AcquireTimerInfo();
cristyceae09d2009-10-28 17:18:47 +0000160 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000161 {
cristybb503372010-05-27 20:51:26 +0000162 for (i=0; i < (ssize_t) iterations; i++)
cristy3980b0d2009-10-25 14:37:13 +0000163 {
cristy33557d72009-11-06 00:54:33 +0000164 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000165 continue;
166 if (duration > 0)
167 {
168 if (GetElapsedTime(timer) > duration)
169 continue;
170 (void) ContinueTimer(timer);
171 }
172 status=command(image_info,argc,argv,metadata,exception);
cristy3980b0d2009-10-25 14:37:13 +0000173 if (exception->severity != UndefinedException)
174 {
175 if ((exception->severity > ErrorException) ||
176 (regard_warnings != MagickFalse))
177 status=MagickTrue;
178 CatchException(exception);
179 }
cristy3d1a5512009-10-25 21:23:27 +0000180 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
cristy3980b0d2009-10-25 14:37:13 +0000181 {
182 (void) fputs(*metadata,stdout);
183 (void) fputc('\n',stdout);
184 *metadata=DestroyString(*metadata);
185 }
186 }
187 }
cristyceae09d2009-10-28 17:18:47 +0000188 else
189 {
190 SetOpenMPNested(1);
cristyb5d5f722009-11-04 03:03:49 +0000191#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyceae09d2009-10-28 17:18:47 +0000192 # pragma omp parallel for shared(status)
193#endif
cristybb503372010-05-27 20:51:26 +0000194 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000195 {
cristy33557d72009-11-06 00:54:33 +0000196 if (status != MagickFalse)
cristyceae09d2009-10-28 17:18:47 +0000197 continue;
198 if (duration > 0)
199 {
200 if (GetElapsedTime(timer) > duration)
201 continue;
202 (void) ContinueTimer(timer);
203 }
204 status=command(image_info,argc,argv,metadata,exception);
cristyb5d5f722009-11-04 03:03:49 +0000205#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy524549f2010-06-20 21:10:20 +0000206 # pragma omp critical (MagickCore_CommandGenesis)
cristyceae09d2009-10-28 17:18:47 +0000207#endif
208 {
209 if (exception->severity != UndefinedException)
210 {
211 if ((exception->severity > ErrorException) ||
212 (regard_warnings != MagickFalse))
213 status=MagickTrue;
214 CatchException(exception);
215 }
216 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
217 {
218 (void) fputs(*metadata,stdout);
219 (void) fputc('\n',stdout);
220 *metadata=DestroyString(*metadata);
221 }
222 }
223 }
224 }
cristy3980b0d2009-10-25 14:37:13 +0000225 if (iterations > 1)
226 {
227 elapsed_time=GetElapsedTime(timer);
228 user_time=GetUserTime(timer);
cristyb51dff52011-05-19 16:55:47 +0000229 (void) FormatLocaleFile(stderr,
cristye8c25f92010-06-03 00:53:06 +0000230 "Performance: %.20gi %gips %0.3fu %.20g:%02g.%03g\n",(double)
231 iterations,1.0*iterations/elapsed_time,user_time,(double)
232 (elapsed_time/60.0),floor(fmod(elapsed_time,60.0)),(double)
233 (1000.0*(elapsed_time-floor(elapsed_time))));
cristy524549f2010-06-20 21:10:20 +0000234 (void) fflush(stderr);
cristy3980b0d2009-10-25 14:37:13 +0000235 }
236 timer=DestroyTimerInfo(timer);
cristy1f9e1ed2009-11-18 04:09:38 +0000237 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000238}
239
240/*
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242% %
243% %
244% %
cristy3ed852e2009-09-05 21:47:34 +0000245+ M o g r i f y I m a g e %
246% %
247% %
248% %
249%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250%
anthonye9c27192011-03-27 08:07:06 +0000251% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000252% image that may be part of a large list, but also handles any 'region'
253% image handling.
anthonye9c27192011-03-27 08:07:06 +0000254%
255% The image in the list may be modified in three different ways...
256%
257% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
258% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
259% * replace by a list of images (only the -separate option!)
260%
261% In each case the result is returned into the list, and a pointer to the
262% modified image (last image added if replaced by a list of images) is
263% returned.
264%
265% ASIDE: The -crop is present but restricted to non-tile single image crops
266%
267% This means if all the images are being processed (such as by
268% MogrifyImages(), next image to be processed will be as per the pointer
269% (*image)->next. Also the image list may grow as a result of some specific
270% operations but as images are never merged or deleted, it will never shrink
271% in length. Typically the list will remain the same length.
272%
273% WARNING: As the image pointed to may be replaced, the first image in the
274% list may also change. GetFirstImageInList() should be used by caller if
275% they wish return the Image pointer to the first image in list.
276%
cristy3ed852e2009-09-05 21:47:34 +0000277%
278% The format of the MogrifyImage method is:
279%
280% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
281% const char **argv,Image **image)
282%
283% A description of each parameter follows:
284%
285% o image_info: the image info..
286%
287% o argc: Specifies a pointer to an integer describing the number of
288% elements in the argument vector.
289%
290% o argv: Specifies a pointer to a text array containing the command line
291% arguments.
292%
293% o image: the image.
294%
295% o exception: return any errors or warnings in this structure.
296%
297*/
298
cristy4c08aed2011-07-01 19:47:50 +0000299/*
300** GetImageCache() will read an image into a image cache if not already
301** present then return the image that is in the cache under that filename.
302*/
anthonydf8ebac2011-04-27 09:03:19 +0000303static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
304 ExceptionInfo *exception)
305{
306 char
307 key[MaxTextExtent];
308
309 ExceptionInfo
310 *sans_exception;
311
312 Image
313 *image;
314
315 ImageInfo
316 *read_info;
317
cristyb51dff52011-05-19 16:55:47 +0000318 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000319 sans_exception=AcquireExceptionInfo();
320 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
321 sans_exception=DestroyExceptionInfo(sans_exception);
322 if (image != (Image *) NULL)
323 return(image);
324 read_info=CloneImageInfo(image_info);
325 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
326 image=ReadImage(read_info,exception);
327 read_info=DestroyImageInfo(read_info);
328 if (image != (Image *) NULL)
329 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
330 return(image);
331}
332
cristy3ed852e2009-09-05 21:47:34 +0000333static MagickBooleanType IsPathWritable(const char *path)
334{
335 if (IsPathAccessible(path) == MagickFalse)
336 return(MagickFalse);
337 if (access(path,W_OK) != 0)
338 return(MagickFalse);
339 return(MagickTrue);
340}
341
cristybb503372010-05-27 20:51:26 +0000342static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000343{
344 if (x > y)
345 return(x);
346 return(y);
347}
348
anthonydf8ebac2011-04-27 09:03:19 +0000349static MagickBooleanType MonitorProgress(const char *text,
350 const MagickOffsetType offset,const MagickSizeType extent,
351 void *wand_unused(client_data))
352{
353 char
354 message[MaxTextExtent],
355 tag[MaxTextExtent];
356
357 const char
358 *locale_message;
359
360 register char
361 *p;
362
363 if (extent < 2)
364 return(MagickTrue);
365 (void) CopyMagickMemory(tag,text,MaxTextExtent);
366 p=strrchr(tag,'/');
367 if (p != (char *) NULL)
368 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000369 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000370 locale_message=GetLocaleMessage(message);
371 if (locale_message == message)
372 locale_message=tag;
373 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000374 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
375 locale_message,(long) offset,(unsigned long) extent,(long)
376 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000377 else
cristyb51dff52011-05-19 16:55:47 +0000378 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000379 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
380 (100L*offset/(extent-1)));
381 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000382 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000383 (void) fflush(stderr);
384 return(MagickTrue);
385}
386
387/*
anthony3d2f4862011-05-01 13:48:16 +0000388** SparseColorOption() parses the complex -sparse-color argument into an
389** an array of floating point values then calls SparseColorImage().
anthonydf8ebac2011-04-27 09:03:19 +0000390** Argument is a complex mix of floating-point pixel coodinates, and color
391** specifications (or direct floating point numbers). The number of floats
anthony3d2f4862011-05-01 13:48:16 +0000392** needed to represent a color varies depending on the current channel
anthonydf8ebac2011-04-27 09:03:19 +0000393** setting.
394*/
cristy3884f692011-07-08 18:00:18 +0000395static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000396 const SparseColorMethod method,const char *arguments,
397 const MagickBooleanType color_from_image,ExceptionInfo *exception)
398{
anthonydf8ebac2011-04-27 09:03:19 +0000399 char
400 token[MaxTextExtent];
401
402 const char
403 *p;
404
405 double
406 *sparse_arguments;
407
anthonydf8ebac2011-04-27 09:03:19 +0000408 Image
409 *sparse_image;
410
cristy4c08aed2011-07-01 19:47:50 +0000411 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000412 color;
413
414 MagickBooleanType
415 error;
416
cristy5f09d852011-05-29 01:39:29 +0000417 register size_t
418 x;
419
420 size_t
421 number_arguments,
422 number_colors;
423
anthonydf8ebac2011-04-27 09:03:19 +0000424 assert(image != (Image *) NULL);
425 assert(image->signature == MagickSignature);
426 if (image->debug != MagickFalse)
427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
428 assert(exception != (ExceptionInfo *) NULL);
429 assert(exception->signature == MagickSignature);
430 /*
431 Limit channels according to image - and add up number of color channel.
432 */
anthonydf8ebac2011-04-27 09:03:19 +0000433 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000434 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000435 number_colors++;
cristyed231572011-07-14 02:18:59 +0000436 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000437 number_colors++;
cristyed231572011-07-14 02:18:59 +0000438 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000439 number_colors++;
cristyed231572011-07-14 02:18:59 +0000440 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000441 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000442 number_colors++;
cristyed231572011-07-14 02:18:59 +0000443 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000444 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000445 number_colors++;
446
447 /*
448 Read string, to determine number of arguments needed,
449 */
450 p=arguments;
451 x=0;
452 while( *p != '\0' )
453 {
454 GetMagickToken(p,&p,token);
455 if ( token[0] == ',' ) continue;
456 if ( isalpha((int) token[0]) || token[0] == '#' ) {
457 if ( color_from_image ) {
458 (void) ThrowMagickException(exception,GetMagickModule(),
459 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
460 "Color arg given, when colors are coming from image");
461 return( (Image *)NULL);
462 }
463 x += number_colors; /* color argument */
464 }
465 else {
466 x++; /* floating point argument */
467 }
468 }
469 error=MagickTrue;
470 if ( color_from_image ) {
471 /* just the control points are being given */
472 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
473 number_arguments=(x/2)*(2+number_colors);
474 }
475 else {
476 /* control points and color values */
477 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
478 number_arguments=x;
479 }
480 if ( error ) {
481 (void) ThrowMagickException(exception,GetMagickModule(),
482 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
483 "Invalid number of Arguments");
484 return( (Image *)NULL);
485 }
486
487 /* Allocate and fill in the floating point arguments */
488 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
489 sizeof(*sparse_arguments));
490 if (sparse_arguments == (double *) NULL) {
491 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
492 "MemoryAllocationFailed","%s","SparseColorOption");
493 return( (Image *)NULL);
494 }
495 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
496 sizeof(*sparse_arguments));
497 p=arguments;
498 x=0;
499 while( *p != '\0' && x < number_arguments ) {
500 /* X coordinate */
501 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
502 if ( token[0] == '\0' ) break;
503 if ( isalpha((int) token[0]) || token[0] == '#' ) {
504 (void) ThrowMagickException(exception,GetMagickModule(),
505 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
506 "Color found, instead of X-coord");
507 error = MagickTrue;
508 break;
509 }
cristyc1acd842011-05-19 23:05:47 +0000510 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000511 /* Y coordinate */
512 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
513 if ( token[0] == '\0' ) break;
514 if ( isalpha((int) token[0]) || token[0] == '#' ) {
515 (void) ThrowMagickException(exception,GetMagickModule(),
516 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
517 "Color found, instead of Y-coord");
518 error = MagickTrue;
519 break;
520 }
cristyc1acd842011-05-19 23:05:47 +0000521 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000522 /* color values for this control point */
523#if 0
524 if ( (color_from_image ) {
525 /* get color from image */
526 /* HOW??? */
527 }
528 else
529#endif
530 {
531 /* color name or function given in string argument */
532 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
533 if ( token[0] == '\0' ) break;
534 if ( isalpha((int) token[0]) || token[0] == '#' ) {
535 /* Color string given */
536 (void) QueryMagickColor(token,&color,exception);
cristyed231572011-07-14 02:18:59 +0000537 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000538 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000539 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000540 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000541 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000542 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000543 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000544 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000545 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000546 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000547 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000548 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000549 }
550 else {
551 /* Colors given as a set of floating point values - experimental */
552 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000553 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000554 {
anthonydf8ebac2011-04-27 09:03:19 +0000555 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
556 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
557 break;
cristyc1acd842011-05-19 23:05:47 +0000558 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000559 token[0] = ','; /* used this token - get another */
560 }
cristyed231572011-07-14 02:18:59 +0000561 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000562 {
anthonydf8ebac2011-04-27 09:03:19 +0000563 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
564 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
565 break;
cristyc1acd842011-05-19 23:05:47 +0000566 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000567 token[0] = ','; /* used this token - get another */
568 }
cristyed231572011-07-14 02:18:59 +0000569 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000570 {
anthonydf8ebac2011-04-27 09:03:19 +0000571 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
572 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
573 break;
cristyc1acd842011-05-19 23:05:47 +0000574 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000575 token[0] = ','; /* used this token - get another */
576 }
cristyed231572011-07-14 02:18:59 +0000577 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000578 (image->colorspace == CMYKColorspace))
579 {
anthonydf8ebac2011-04-27 09:03:19 +0000580 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
581 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
582 break;
cristyc1acd842011-05-19 23:05:47 +0000583 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000584 token[0] = ','; /* used this token - get another */
585 }
cristyed231572011-07-14 02:18:59 +0000586 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000587 (image->matte != MagickFalse))
588 {
anthonydf8ebac2011-04-27 09:03:19 +0000589 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
590 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
591 break;
cristyc1acd842011-05-19 23:05:47 +0000592 sparse_arguments[x++]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000593 token[0] = ','; /* used this token - get another */
594 }
595 }
596 }
597 }
598 if ( number_arguments != x && !error ) {
599 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
600 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
601 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
602 return( (Image *)NULL);
603 }
604 if ( error )
605 return( (Image *)NULL);
606
607 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000608 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
609 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000610 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
611 return( sparse_image );
612}
613
cristy3ed852e2009-09-05 21:47:34 +0000614WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
615 const char **argv,Image **image,ExceptionInfo *exception)
616{
anthonydf8ebac2011-04-27 09:03:19 +0000617 ChannelType
618 channel;
619
620 const char
621 *format,
622 *option;
623
624 DrawInfo
625 *draw_info;
626
627 GeometryInfo
628 geometry_info;
629
cristy3ed852e2009-09-05 21:47:34 +0000630 Image
631 *region_image;
632
anthonydf8ebac2011-04-27 09:03:19 +0000633 ImageInfo
634 *mogrify_info;
635
cristyebbcfea2011-02-25 02:43:54 +0000636 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000637 status;
638
cristy4c08aed2011-07-01 19:47:50 +0000639 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000640 fill;
cristy3ed852e2009-09-05 21:47:34 +0000641
anthonydf8ebac2011-04-27 09:03:19 +0000642 MagickStatusType
643 flags;
644
645 QuantizeInfo
646 *quantize_info;
647
648 RectangleInfo
649 geometry,
650 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000651
cristybb503372010-05-27 20:51:26 +0000652 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000653 i;
654
655 /*
656 Initialize method variables.
657 */
658 assert(image_info != (const ImageInfo *) NULL);
659 assert(image_info->signature == MagickSignature);
660 assert(image != (Image **) NULL);
661 assert((*image)->signature == MagickSignature);
662 if ((*image)->debug != MagickFalse)
663 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
664 if (argc < 0)
665 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000666 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000667 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
668 quantize_info=AcquireQuantizeInfo(mogrify_info);
669 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000670 GetPixelInfo(*image,&fill);
671 SetPixelInfoPacket(*image,&(*image)->background_color,&fill);
anthonydf8ebac2011-04-27 09:03:19 +0000672 channel=mogrify_info->channel;
673 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000674 SetGeometry(*image,&region_geometry);
675 region_image=NewImageList();
676 /*
677 Transmogrify the image.
678 */
cristybb503372010-05-27 20:51:26 +0000679 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000680 {
anthonydf8ebac2011-04-27 09:03:19 +0000681 Image
682 *mogrify_image;
683
anthonye9c27192011-03-27 08:07:06 +0000684 ssize_t
685 count;
686
anthonydf8ebac2011-04-27 09:03:19 +0000687 option=argv[i];
688 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000689 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000690 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
691 0L);
cristycee97112010-05-28 00:44:52 +0000692 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000693 break;
cristy6b3da3a2010-06-20 02:21:46 +0000694 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000695 mogrify_image=(Image *)NULL;
696 switch (*(option+1))
697 {
698 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000699 {
anthonydf8ebac2011-04-27 09:03:19 +0000700 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000701 {
anthonydf8ebac2011-04-27 09:03:19 +0000702 /*
703 Adaptive blur image.
704 */
705 (void) SyncImageSettings(mogrify_info,*image);
706 flags=ParseGeometry(argv[i+1],&geometry_info);
707 if ((flags & SigmaValue) == 0)
708 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000709 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
710 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000711 break;
cristy3ed852e2009-09-05 21:47:34 +0000712 }
anthonydf8ebac2011-04-27 09:03:19 +0000713 if (LocaleCompare("adaptive-resize",option+1) == 0)
714 {
715 /*
716 Adaptive resize image.
717 */
718 (void) SyncImageSettings(mogrify_info,*image);
719 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
720 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
721 geometry.height,exception);
722 break;
723 }
724 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
725 {
726 /*
727 Adaptive sharpen image.
728 */
729 (void) SyncImageSettings(mogrify_info,*image);
730 flags=ParseGeometry(argv[i+1],&geometry_info);
731 if ((flags & SigmaValue) == 0)
732 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000733 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
734 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000735 break;
736 }
737 if (LocaleCompare("affine",option+1) == 0)
738 {
739 /*
740 Affine matrix.
741 */
742 if (*option == '+')
743 {
744 GetAffineMatrix(&draw_info->affine);
745 break;
746 }
747 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
748 break;
749 }
750 if (LocaleCompare("alpha",option+1) == 0)
751 {
752 AlphaChannelType
753 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000754
anthonydf8ebac2011-04-27 09:03:19 +0000755 (void) SyncImageSettings(mogrify_info,*image);
756 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
757 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000758 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000759 break;
760 }
761 if (LocaleCompare("annotate",option+1) == 0)
762 {
763 char
764 *text,
765 geometry[MaxTextExtent];
766
767 /*
768 Annotate image.
769 */
770 (void) SyncImageSettings(mogrify_info,*image);
771 SetGeometryInfo(&geometry_info);
772 flags=ParseGeometry(argv[i+1],&geometry_info);
773 if ((flags & SigmaValue) == 0)
774 geometry_info.sigma=geometry_info.rho;
775 text=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
776 InheritException(exception,&(*image)->exception);
777 if (text == (char *) NULL)
778 break;
779 (void) CloneString(&draw_info->text,text);
780 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000781 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000782 geometry_info.xi,geometry_info.psi);
783 (void) CloneString(&draw_info->geometry,geometry);
784 draw_info->affine.sx=cos(DegreesToRadians(
785 fmod(geometry_info.rho,360.0)));
786 draw_info->affine.rx=sin(DegreesToRadians(
787 fmod(geometry_info.rho,360.0)));
788 draw_info->affine.ry=(-sin(DegreesToRadians(
789 fmod(geometry_info.sigma,360.0))));
790 draw_info->affine.sy=cos(DegreesToRadians(
791 fmod(geometry_info.sigma,360.0)));
792 (void) AnnotateImage(*image,draw_info);
793 InheritException(exception,&(*image)->exception);
794 break;
795 }
796 if (LocaleCompare("antialias",option+1) == 0)
797 {
798 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
799 MagickFalse;
800 draw_info->text_antialias=(*option == '-') ? MagickTrue :
801 MagickFalse;
802 break;
803 }
804 if (LocaleCompare("auto-gamma",option+1) == 0)
805 {
806 /*
807 Auto Adjust Gamma of image based on its mean
808 */
809 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000810 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000811 break;
812 }
813 if (LocaleCompare("auto-level",option+1) == 0)
814 {
815 /*
816 Perfectly Normalize (max/min stretch) the image
817 */
818 (void) SyncImageSettings(mogrify_info,*image);
cristy95111202011-08-09 19:41:42 +0000819 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000820 break;
821 }
822 if (LocaleCompare("auto-orient",option+1) == 0)
823 {
824 (void) SyncImageSettings(mogrify_info,*image);
825 switch ((*image)->orientation)
826 {
827 case TopRightOrientation:
828 {
829 mogrify_image=FlopImage(*image,exception);
830 break;
831 }
832 case BottomRightOrientation:
833 {
834 mogrify_image=RotateImage(*image,180.0,exception);
835 break;
836 }
837 case BottomLeftOrientation:
838 {
839 mogrify_image=FlipImage(*image,exception);
840 break;
841 }
842 case LeftTopOrientation:
843 {
844 mogrify_image=TransposeImage(*image,exception);
845 break;
846 }
847 case RightTopOrientation:
848 {
849 mogrify_image=RotateImage(*image,90.0,exception);
850 break;
851 }
852 case RightBottomOrientation:
853 {
854 mogrify_image=TransverseImage(*image,exception);
855 break;
856 }
857 case LeftBottomOrientation:
858 {
859 mogrify_image=RotateImage(*image,270.0,exception);
860 break;
861 }
862 default:
863 break;
864 }
865 if (mogrify_image != (Image *) NULL)
866 mogrify_image->orientation=TopLeftOrientation;
867 break;
868 }
869 break;
870 }
871 case 'b':
872 {
873 if (LocaleCompare("black-threshold",option+1) == 0)
874 {
875 /*
876 Black threshold image.
877 */
878 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +0000879 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000880 InheritException(exception,&(*image)->exception);
881 break;
882 }
883 if (LocaleCompare("blue-shift",option+1) == 0)
884 {
885 /*
886 Blue shift image.
887 */
888 (void) SyncImageSettings(mogrify_info,*image);
889 geometry_info.rho=1.5;
890 if (*option == '-')
891 flags=ParseGeometry(argv[i+1],&geometry_info);
892 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
893 break;
894 }
895 if (LocaleCompare("blur",option+1) == 0)
896 {
897 /*
898 Gaussian blur image.
899 */
900 (void) SyncImageSettings(mogrify_info,*image);
901 flags=ParseGeometry(argv[i+1],&geometry_info);
902 if ((flags & SigmaValue) == 0)
903 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000904 mogrify_image=BlurImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +0000905 geometry_info.sigma,exception);
906 break;
907 }
908 if (LocaleCompare("border",option+1) == 0)
909 {
910 /*
911 Surround image with a border of solid color.
912 */
913 (void) SyncImageSettings(mogrify_info,*image);
914 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
915 if ((flags & SigmaValue) == 0)
916 geometry.height=geometry.width;
917 mogrify_image=BorderImage(*image,&geometry,exception);
918 break;
919 }
920 if (LocaleCompare("bordercolor",option+1) == 0)
921 {
922 if (*option == '+')
923 {
cristy638895a2011-08-06 23:19:14 +0000924 (void) QueryColorDatabase(MogrifyBorderColor,&draw_info->border_color,
anthonydf8ebac2011-04-27 09:03:19 +0000925 exception);
926 break;
927 }
928 (void) QueryColorDatabase(argv[i+1],&draw_info->border_color,
929 exception);
930 break;
931 }
932 if (LocaleCompare("box",option+1) == 0)
933 {
934 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
935 exception);
936 break;
937 }
938 if (LocaleCompare("brightness-contrast",option+1) == 0)
939 {
940 double
941 brightness,
942 contrast;
943
944 GeometryInfo
945 geometry_info;
946
947 MagickStatusType
948 flags;
949
950 /*
951 Brightness / contrast image.
952 */
953 (void) SyncImageSettings(mogrify_info,*image);
954 flags=ParseGeometry(argv[i+1],&geometry_info);
955 brightness=geometry_info.rho;
956 contrast=0.0;
957 if ((flags & SigmaValue) != 0)
958 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +0000959 (void) BrightnessContrastImage(*image,brightness,contrast,
960 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000961 InheritException(exception,&(*image)->exception);
962 break;
963 }
964 break;
965 }
966 case 'c':
967 {
968 if (LocaleCompare("cdl",option+1) == 0)
969 {
970 char
971 *color_correction_collection;
972
973 /*
974 Color correct with a color decision list.
975 */
976 (void) SyncImageSettings(mogrify_info,*image);
977 color_correction_collection=FileToString(argv[i+1],~0,exception);
978 if (color_correction_collection == (char *) NULL)
979 break;
cristy1bfa9f02011-08-11 02:35:43 +0000980 (void) ColorDecisionListImage(*image,color_correction_collection,
981 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000982 InheritException(exception,&(*image)->exception);
983 break;
984 }
985 if (LocaleCompare("channel",option+1) == 0)
986 {
987 if (*option == '+')
cristyfa806a72011-07-04 02:06:13 +0000988 channel=DefaultChannels;
anthonydf8ebac2011-04-27 09:03:19 +0000989 else
cristyfa806a72011-07-04 02:06:13 +0000990 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +0000991 SetPixelChannelMap(*image,channel);
anthonydf8ebac2011-04-27 09:03:19 +0000992 break;
993 }
994 if (LocaleCompare("charcoal",option+1) == 0)
995 {
996 /*
997 Charcoal image.
998 */
999 (void) SyncImageSettings(mogrify_info,*image);
1000 flags=ParseGeometry(argv[i+1],&geometry_info);
1001 if ((flags & SigmaValue) == 0)
1002 geometry_info.sigma=1.0;
1003 mogrify_image=CharcoalImage(*image,geometry_info.rho,
1004 geometry_info.sigma,exception);
1005 break;
1006 }
1007 if (LocaleCompare("chop",option+1) == 0)
1008 {
1009 /*
1010 Chop the image.
1011 */
1012 (void) SyncImageSettings(mogrify_info,*image);
1013 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1014 mogrify_image=ChopImage(*image,&geometry,exception);
1015 break;
1016 }
1017 if (LocaleCompare("clamp",option+1) == 0)
1018 {
1019 /*
1020 Clamp image.
1021 */
1022 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00001023 (void) ClampImage(*image);
anthonydf8ebac2011-04-27 09:03:19 +00001024 InheritException(exception,&(*image)->exception);
1025 break;
1026 }
1027 if (LocaleCompare("clip",option+1) == 0)
1028 {
1029 (void) SyncImageSettings(mogrify_info,*image);
1030 if (*option == '+')
1031 {
1032 (void) SetImageClipMask(*image,(Image *) NULL);
1033 InheritException(exception,&(*image)->exception);
1034 break;
1035 }
1036 (void) ClipImage(*image);
1037 InheritException(exception,&(*image)->exception);
1038 break;
1039 }
1040 if (LocaleCompare("clip-mask",option+1) == 0)
1041 {
1042 CacheView
1043 *mask_view;
1044
1045 Image
1046 *mask_image;
1047
cristy4c08aed2011-07-01 19:47:50 +00001048 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001049 *restrict q;
1050
1051 register ssize_t
1052 x;
1053
1054 ssize_t
1055 y;
1056
1057 (void) SyncImageSettings(mogrify_info,*image);
1058 if (*option == '+')
1059 {
1060 /*
1061 Remove a mask.
1062 */
1063 (void) SetImageMask(*image,(Image *) NULL);
1064 InheritException(exception,&(*image)->exception);
1065 break;
1066 }
1067 /*
1068 Set the image mask.
1069 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1070 */
1071 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1072 if (mask_image == (Image *) NULL)
1073 break;
cristy574cc262011-08-05 01:23:58 +00001074 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001075 return(MagickFalse);
1076 mask_view=AcquireCacheView(mask_image);
1077 for (y=0; y < (ssize_t) mask_image->rows; y++)
1078 {
1079 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1080 exception);
cristy4c08aed2011-07-01 19:47:50 +00001081 if (q == (const Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001082 break;
1083 for (x=0; x < (ssize_t) mask_image->columns; x++)
1084 {
1085 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001086 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1087 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1088 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1089 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001090 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001091 }
1092 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1093 break;
1094 }
1095 mask_view=DestroyCacheView(mask_view);
1096 mask_image->matte=MagickTrue;
1097 (void) SetImageClipMask(*image,mask_image);
1098 mask_image=DestroyImage(mask_image);
1099 InheritException(exception,&(*image)->exception);
1100 break;
1101 }
1102 if (LocaleCompare("clip-path",option+1) == 0)
1103 {
1104 (void) SyncImageSettings(mogrify_info,*image);
1105 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1106 MagickFalse);
1107 InheritException(exception,&(*image)->exception);
1108 break;
1109 }
1110 if (LocaleCompare("colorize",option+1) == 0)
1111 {
1112 /*
1113 Colorize the image.
1114 */
1115 (void) SyncImageSettings(mogrify_info,*image);
1116 mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill,
1117 exception);
1118 break;
1119 }
1120 if (LocaleCompare("color-matrix",option+1) == 0)
1121 {
1122 KernelInfo
1123 *kernel;
1124
1125 (void) SyncImageSettings(mogrify_info,*image);
1126 kernel=AcquireKernelInfo(argv[i+1]);
1127 if (kernel == (KernelInfo *) NULL)
1128 break;
1129 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1130 kernel=DestroyKernelInfo(kernel);
1131 break;
1132 }
1133 if (LocaleCompare("colors",option+1) == 0)
1134 {
1135 /*
1136 Reduce the number of colors in the image.
1137 */
1138 (void) SyncImageSettings(mogrify_info,*image);
1139 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1140 if (quantize_info->number_colors == 0)
1141 break;
1142 if (((*image)->storage_class == DirectClass) ||
1143 (*image)->colors > quantize_info->number_colors)
1144 (void) QuantizeImage(quantize_info,*image);
1145 else
1146 (void) CompressImageColormap(*image);
1147 InheritException(exception,&(*image)->exception);
1148 break;
1149 }
1150 if (LocaleCompare("colorspace",option+1) == 0)
1151 {
1152 ColorspaceType
1153 colorspace;
1154
1155 (void) SyncImageSettings(mogrify_info,*image);
1156 if (*option == '+')
1157 {
1158 (void) TransformImageColorspace(*image,RGBColorspace);
1159 InheritException(exception,&(*image)->exception);
1160 break;
1161 }
1162 colorspace=(ColorspaceType) ParseCommandOption(
1163 MagickColorspaceOptions,MagickFalse,argv[i+1]);
1164 (void) TransformImageColorspace(*image,colorspace);
1165 InheritException(exception,&(*image)->exception);
1166 break;
1167 }
1168 if (LocaleCompare("contrast",option+1) == 0)
1169 {
1170 (void) SyncImageSettings(mogrify_info,*image);
1171 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001172 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001173 break;
1174 }
1175 if (LocaleCompare("contrast-stretch",option+1) == 0)
1176 {
1177 double
1178 black_point,
1179 white_point;
1180
1181 MagickStatusType
1182 flags;
1183
1184 /*
1185 Contrast stretch image.
1186 */
1187 (void) SyncImageSettings(mogrify_info,*image);
1188 flags=ParseGeometry(argv[i+1],&geometry_info);
1189 black_point=geometry_info.rho;
1190 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1191 black_point;
1192 if ((flags & PercentValue) != 0)
1193 {
1194 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1195 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1196 }
1197 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1198 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001199 (void) ContrastStretchImage(*image,black_point,white_point,
1200 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001201 InheritException(exception,&(*image)->exception);
1202 break;
1203 }
1204 if (LocaleCompare("convolve",option+1) == 0)
1205 {
anthonydf8ebac2011-04-27 09:03:19 +00001206 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001207 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001208
anthonydf8ebac2011-04-27 09:03:19 +00001209 (void) SyncImageSettings(mogrify_info,*image);
cristy41cbe682011-07-15 19:12:37 +00001210 kernel_info=AcquireKernelInfo(argv[i+1]);
1211 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001212 break;
cristy0a922382011-07-16 15:30:34 +00001213 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001214 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001215 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001216 break;
1217 }
1218 if (LocaleCompare("crop",option+1) == 0)
1219 {
1220 /*
1221 Crop a image to a smaller size
1222 */
1223 (void) SyncImageSettings(mogrify_info,*image);
anthonydf8ebac2011-04-27 09:03:19 +00001224 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001225 break;
1226 }
1227 if (LocaleCompare("cycle",option+1) == 0)
1228 {
1229 /*
1230 Cycle an image colormap.
1231 */
1232 (void) SyncImageSettings(mogrify_info,*image);
1233 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]));
1234 InheritException(exception,&(*image)->exception);
1235 break;
1236 }
1237 break;
1238 }
1239 case 'd':
1240 {
1241 if (LocaleCompare("decipher",option+1) == 0)
1242 {
1243 StringInfo
1244 *passkey;
1245
1246 /*
1247 Decipher pixels.
1248 */
1249 (void) SyncImageSettings(mogrify_info,*image);
1250 passkey=FileToStringInfo(argv[i+1],~0,exception);
1251 if (passkey != (StringInfo *) NULL)
1252 {
1253 (void) PasskeyDecipherImage(*image,passkey,exception);
1254 passkey=DestroyStringInfo(passkey);
1255 }
1256 break;
1257 }
1258 if (LocaleCompare("density",option+1) == 0)
1259 {
1260 /*
1261 Set image density.
1262 */
1263 (void) CloneString(&draw_info->density,argv[i+1]);
1264 break;
1265 }
1266 if (LocaleCompare("depth",option+1) == 0)
1267 {
1268 (void) SyncImageSettings(mogrify_info,*image);
1269 if (*option == '+')
1270 {
1271 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH);
1272 break;
1273 }
1274 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]));
1275 break;
1276 }
1277 if (LocaleCompare("deskew",option+1) == 0)
1278 {
1279 double
1280 threshold;
1281
1282 /*
1283 Straighten the image.
1284 */
1285 (void) SyncImageSettings(mogrify_info,*image);
1286 if (*option == '+')
1287 threshold=40.0*QuantumRange/100.0;
1288 else
1289 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
1290 mogrify_image=DeskewImage(*image,threshold,exception);
1291 break;
1292 }
1293 if (LocaleCompare("despeckle",option+1) == 0)
1294 {
1295 /*
1296 Reduce the speckles within an image.
1297 */
1298 (void) SyncImageSettings(mogrify_info,*image);
1299 mogrify_image=DespeckleImage(*image,exception);
1300 break;
1301 }
1302 if (LocaleCompare("display",option+1) == 0)
1303 {
1304 (void) CloneString(&draw_info->server_name,argv[i+1]);
1305 break;
1306 }
1307 if (LocaleCompare("distort",option+1) == 0)
1308 {
1309 char
1310 *args,
1311 token[MaxTextExtent];
1312
1313 const char
1314 *p;
1315
1316 DistortImageMethod
1317 method;
1318
1319 double
1320 *arguments;
1321
1322 register ssize_t
1323 x;
1324
1325 size_t
1326 number_arguments;
1327
1328 /*
1329 Distort image.
1330 */
1331 (void) SyncImageSettings(mogrify_info,*image);
1332 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1333 MagickFalse,argv[i+1]);
1334 if ( method == ResizeDistortion )
1335 {
1336 /* Special Case - Argument is actually a resize geometry!
1337 ** Convert that to an appropriate distortion argument array.
1338 */
1339 double
1340 resize_args[2];
1341 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1342 exception);
1343 resize_args[0]=(double)geometry.width;
1344 resize_args[1]=(double)geometry.height;
1345 mogrify_image=DistortImage(*image,method,(size_t)2,
1346 resize_args,MagickTrue,exception);
1347 break;
1348 }
1349 args=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1350 InheritException(exception,&(*image)->exception);
1351 if (args == (char *) NULL)
1352 break;
1353 p=(char *) args;
1354 for (x=0; *p != '\0'; x++)
1355 {
1356 GetMagickToken(p,&p,token);
1357 if (*token == ',')
1358 GetMagickToken(p,&p,token);
1359 }
1360 number_arguments=(size_t) x;
1361 arguments=(double *) AcquireQuantumMemory(number_arguments,
1362 sizeof(*arguments));
1363 if (arguments == (double *) NULL)
1364 ThrowWandFatalException(ResourceLimitFatalError,
1365 "MemoryAllocationFailed",(*image)->filename);
1366 (void) ResetMagickMemory(arguments,0,number_arguments*
1367 sizeof(*arguments));
1368 p=(char *) args;
1369 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1370 {
1371 GetMagickToken(p,&p,token);
1372 if (*token == ',')
1373 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001374 arguments[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001375 }
1376 args=DestroyString(args);
1377 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1378 (*option == '+') ? MagickTrue : MagickFalse,exception);
1379 arguments=(double *) RelinquishMagickMemory(arguments);
1380 break;
1381 }
1382 if (LocaleCompare("dither",option+1) == 0)
1383 {
1384 if (*option == '+')
1385 {
1386 quantize_info->dither=MagickFalse;
1387 break;
1388 }
1389 quantize_info->dither=MagickTrue;
1390 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1391 MagickDitherOptions,MagickFalse,argv[i+1]);
1392 if (quantize_info->dither_method == NoDitherMethod)
1393 quantize_info->dither=MagickFalse;
1394 break;
1395 }
1396 if (LocaleCompare("draw",option+1) == 0)
1397 {
1398 /*
1399 Draw image.
1400 */
1401 (void) SyncImageSettings(mogrify_info,*image);
1402 (void) CloneString(&draw_info->primitive,argv[i+1]);
1403 (void) DrawImage(*image,draw_info);
1404 InheritException(exception,&(*image)->exception);
1405 break;
1406 }
1407 break;
1408 }
1409 case 'e':
1410 {
1411 if (LocaleCompare("edge",option+1) == 0)
1412 {
1413 /*
1414 Enhance edges in the image.
1415 */
1416 (void) SyncImageSettings(mogrify_info,*image);
1417 flags=ParseGeometry(argv[i+1],&geometry_info);
1418 if ((flags & SigmaValue) == 0)
1419 geometry_info.sigma=1.0;
1420 mogrify_image=EdgeImage(*image,geometry_info.rho,exception);
1421 break;
1422 }
1423 if (LocaleCompare("emboss",option+1) == 0)
1424 {
1425 /*
1426 Gaussian embossen image.
1427 */
1428 (void) SyncImageSettings(mogrify_info,*image);
1429 flags=ParseGeometry(argv[i+1],&geometry_info);
1430 if ((flags & SigmaValue) == 0)
1431 geometry_info.sigma=1.0;
1432 mogrify_image=EmbossImage(*image,geometry_info.rho,
1433 geometry_info.sigma,exception);
1434 break;
1435 }
1436 if (LocaleCompare("encipher",option+1) == 0)
1437 {
1438 StringInfo
1439 *passkey;
1440
1441 /*
1442 Encipher pixels.
1443 */
1444 (void) SyncImageSettings(mogrify_info,*image);
1445 passkey=FileToStringInfo(argv[i+1],~0,exception);
1446 if (passkey != (StringInfo *) NULL)
1447 {
1448 (void) PasskeyEncipherImage(*image,passkey,exception);
1449 passkey=DestroyStringInfo(passkey);
1450 }
1451 break;
1452 }
1453 if (LocaleCompare("encoding",option+1) == 0)
1454 {
1455 (void) CloneString(&draw_info->encoding,argv[i+1]);
1456 break;
1457 }
1458 if (LocaleCompare("enhance",option+1) == 0)
1459 {
1460 /*
1461 Enhance image.
1462 */
1463 (void) SyncImageSettings(mogrify_info,*image);
1464 mogrify_image=EnhanceImage(*image,exception);
1465 break;
1466 }
1467 if (LocaleCompare("equalize",option+1) == 0)
1468 {
1469 /*
1470 Equalize image.
1471 */
1472 (void) SyncImageSettings(mogrify_info,*image);
cristy6d8c3d72011-08-22 01:20:01 +00001473 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001474 break;
1475 }
1476 if (LocaleCompare("evaluate",option+1) == 0)
1477 {
1478 double
1479 constant;
1480
1481 MagickEvaluateOperator
1482 op;
1483
1484 (void) SyncImageSettings(mogrify_info,*image);
cristyd42d9952011-07-08 14:21:50 +00001485 op=(MagickEvaluateOperator) ParseCommandOption(
1486 MagickEvaluateOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00001487 constant=SiPrefixToDouble(argv[i+2],QuantumRange);
cristyd42d9952011-07-08 14:21:50 +00001488 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001489 break;
1490 }
1491 if (LocaleCompare("extent",option+1) == 0)
1492 {
1493 /*
1494 Set the image extent.
1495 */
1496 (void) SyncImageSettings(mogrify_info,*image);
1497 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1498 if (geometry.width == 0)
1499 geometry.width=(*image)->columns;
1500 if (geometry.height == 0)
1501 geometry.height=(*image)->rows;
1502 mogrify_image=ExtentImage(*image,&geometry,exception);
1503 break;
1504 }
1505 break;
1506 }
1507 case 'f':
1508 {
1509 if (LocaleCompare("family",option+1) == 0)
1510 {
1511 if (*option == '+')
1512 {
1513 if (draw_info->family != (char *) NULL)
1514 draw_info->family=DestroyString(draw_info->family);
1515 break;
1516 }
1517 (void) CloneString(&draw_info->family,argv[i+1]);
1518 break;
1519 }
1520 if (LocaleCompare("features",option+1) == 0)
1521 {
1522 if (*option == '+')
1523 {
1524 (void) DeleteImageArtifact(*image,"identify:features");
1525 break;
1526 }
1527 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1528 break;
1529 }
1530 if (LocaleCompare("fill",option+1) == 0)
1531 {
1532 ExceptionInfo
1533 *sans;
1534
cristy4c08aed2011-07-01 19:47:50 +00001535 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001536 if (*option == '+')
1537 {
1538 (void) QueryMagickColor("none",&fill,exception);
1539 (void) QueryColorDatabase("none",&draw_info->fill,exception);
1540 if (draw_info->fill_pattern != (Image *) NULL)
1541 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1542 break;
1543 }
1544 sans=AcquireExceptionInfo();
1545 (void) QueryMagickColor(argv[i+1],&fill,sans);
1546 status=QueryColorDatabase(argv[i+1],&draw_info->fill,sans);
1547 sans=DestroyExceptionInfo(sans);
1548 if (status == MagickFalse)
1549 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1550 exception);
1551 break;
1552 }
1553 if (LocaleCompare("flip",option+1) == 0)
1554 {
1555 /*
1556 Flip image scanlines.
1557 */
1558 (void) SyncImageSettings(mogrify_info,*image);
1559 mogrify_image=FlipImage(*image,exception);
1560 break;
1561 }
anthonydf8ebac2011-04-27 09:03:19 +00001562 if (LocaleCompare("floodfill",option+1) == 0)
1563 {
cristy4c08aed2011-07-01 19:47:50 +00001564 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001565 target;
1566
1567 /*
1568 Floodfill image.
1569 */
1570 (void) SyncImageSettings(mogrify_info,*image);
1571 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1572 (void) QueryMagickColor(argv[i+2],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00001573 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
1574 geometry.y,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00001575 InheritException(exception,&(*image)->exception);
1576 break;
1577 }
anthony3d2f4862011-05-01 13:48:16 +00001578 if (LocaleCompare("flop",option+1) == 0)
1579 {
1580 /*
1581 Flop image scanlines.
1582 */
1583 (void) SyncImageSettings(mogrify_info,*image);
1584 mogrify_image=FlopImage(*image,exception);
1585 break;
1586 }
anthonydf8ebac2011-04-27 09:03:19 +00001587 if (LocaleCompare("font",option+1) == 0)
1588 {
1589 if (*option == '+')
1590 {
1591 if (draw_info->font != (char *) NULL)
1592 draw_info->font=DestroyString(draw_info->font);
1593 break;
1594 }
1595 (void) CloneString(&draw_info->font,argv[i+1]);
1596 break;
1597 }
1598 if (LocaleCompare("format",option+1) == 0)
1599 {
1600 format=argv[i+1];
1601 break;
1602 }
1603 if (LocaleCompare("frame",option+1) == 0)
1604 {
1605 FrameInfo
1606 frame_info;
1607
1608 /*
1609 Surround image with an ornamental border.
1610 */
1611 (void) SyncImageSettings(mogrify_info,*image);
1612 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1613 frame_info.width=geometry.width;
1614 frame_info.height=geometry.height;
1615 if ((flags & HeightValue) == 0)
1616 frame_info.height=geometry.width;
1617 frame_info.outer_bevel=geometry.x;
1618 frame_info.inner_bevel=geometry.y;
1619 frame_info.x=(ssize_t) frame_info.width;
1620 frame_info.y=(ssize_t) frame_info.height;
1621 frame_info.width=(*image)->columns+2*frame_info.width;
1622 frame_info.height=(*image)->rows+2*frame_info.height;
1623 mogrify_image=FrameImage(*image,&frame_info,exception);
1624 break;
1625 }
1626 if (LocaleCompare("function",option+1) == 0)
1627 {
1628 char
1629 *arguments,
1630 token[MaxTextExtent];
1631
1632 const char
1633 *p;
1634
1635 double
1636 *parameters;
1637
1638 MagickFunction
1639 function;
1640
1641 register ssize_t
1642 x;
1643
1644 size_t
1645 number_parameters;
1646
1647 /*
1648 Function Modify Image Values
1649 */
1650 (void) SyncImageSettings(mogrify_info,*image);
1651 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1652 MagickFalse,argv[i+1]);
1653 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
1654 InheritException(exception,&(*image)->exception);
1655 if (arguments == (char *) NULL)
1656 break;
1657 p=(char *) arguments;
1658 for (x=0; *p != '\0'; x++)
1659 {
1660 GetMagickToken(p,&p,token);
1661 if (*token == ',')
1662 GetMagickToken(p,&p,token);
1663 }
1664 number_parameters=(size_t) x;
1665 parameters=(double *) AcquireQuantumMemory(number_parameters,
1666 sizeof(*parameters));
1667 if (parameters == (double *) NULL)
1668 ThrowWandFatalException(ResourceLimitFatalError,
1669 "MemoryAllocationFailed",(*image)->filename);
1670 (void) ResetMagickMemory(parameters,0,number_parameters*
1671 sizeof(*parameters));
1672 p=(char *) arguments;
1673 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1674 {
1675 GetMagickToken(p,&p,token);
1676 if (*token == ',')
1677 GetMagickToken(p,&p,token);
cristyc1acd842011-05-19 23:05:47 +00001678 parameters[x]=InterpretLocaleValue(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001679 }
1680 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001681 (void) FunctionImage(*image,function,number_parameters,parameters,
1682 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001683 parameters=(double *) RelinquishMagickMemory(parameters);
1684 break;
1685 }
1686 break;
1687 }
1688 case 'g':
1689 {
1690 if (LocaleCompare("gamma",option+1) == 0)
1691 {
1692 /*
1693 Gamma image.
1694 */
1695 (void) SyncImageSettings(mogrify_info,*image);
1696 if (*option == '+')
cristyc1acd842011-05-19 23:05:47 +00001697 (*image)->gamma=InterpretLocaleValue(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001698 else
cristyb3e7c6c2011-07-24 01:43:55 +00001699 (void) GammaImage(*image,InterpretLocaleValue(argv[i+1],
1700 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001701 break;
1702 }
1703 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1704 (LocaleCompare("gaussian",option+1) == 0))
1705 {
1706 /*
1707 Gaussian blur image.
1708 */
1709 (void) SyncImageSettings(mogrify_info,*image);
1710 flags=ParseGeometry(argv[i+1],&geometry_info);
1711 if ((flags & SigmaValue) == 0)
1712 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001713 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1714 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001715 break;
1716 }
1717 if (LocaleCompare("geometry",option+1) == 0)
1718 {
1719 /*
1720 Record Image offset, Resize last image.
1721 */
1722 (void) SyncImageSettings(mogrify_info,*image);
1723 if (*option == '+')
1724 {
1725 if ((*image)->geometry != (char *) NULL)
1726 (*image)->geometry=DestroyString((*image)->geometry);
1727 break;
1728 }
1729 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1730 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1731 (void) CloneString(&(*image)->geometry,argv[i+1]);
1732 else
1733 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1734 (*image)->filter,(*image)->blur,exception);
1735 break;
1736 }
1737 if (LocaleCompare("gravity",option+1) == 0)
1738 {
1739 if (*option == '+')
1740 {
1741 draw_info->gravity=UndefinedGravity;
1742 break;
1743 }
1744 draw_info->gravity=(GravityType) ParseCommandOption(
1745 MagickGravityOptions,MagickFalse,argv[i+1]);
1746 break;
1747 }
1748 break;
1749 }
1750 case 'h':
1751 {
1752 if (LocaleCompare("highlight-color",option+1) == 0)
1753 {
1754 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1755 break;
1756 }
1757 break;
1758 }
1759 case 'i':
1760 {
1761 if (LocaleCompare("identify",option+1) == 0)
1762 {
1763 char
1764 *text;
1765
1766 (void) SyncImageSettings(mogrify_info,*image);
1767 if (format == (char *) NULL)
1768 {
1769 (void) IdentifyImage(*image,stdout,mogrify_info->verbose);
1770 InheritException(exception,&(*image)->exception);
1771 break;
1772 }
1773 text=InterpretImageProperties(mogrify_info,*image,format);
1774 InheritException(exception,&(*image)->exception);
1775 if (text == (char *) NULL)
1776 break;
1777 (void) fputs(text,stdout);
1778 (void) fputc('\n',stdout);
1779 text=DestroyString(text);
1780 break;
1781 }
1782 if (LocaleCompare("implode",option+1) == 0)
1783 {
1784 /*
1785 Implode image.
1786 */
1787 (void) SyncImageSettings(mogrify_info,*image);
1788 (void) ParseGeometry(argv[i+1],&geometry_info);
1789 mogrify_image=ImplodeImage(*image,geometry_info.rho,exception);
1790 break;
1791 }
1792 if (LocaleCompare("interline-spacing",option+1) == 0)
1793 {
1794 if (*option == '+')
1795 (void) ParseGeometry("0",&geometry_info);
1796 else
1797 (void) ParseGeometry(argv[i+1],&geometry_info);
1798 draw_info->interline_spacing=geometry_info.rho;
1799 break;
1800 }
1801 if (LocaleCompare("interword-spacing",option+1) == 0)
1802 {
1803 if (*option == '+')
1804 (void) ParseGeometry("0",&geometry_info);
1805 else
1806 (void) ParseGeometry(argv[i+1],&geometry_info);
1807 draw_info->interword_spacing=geometry_info.rho;
1808 break;
1809 }
1810 break;
1811 }
1812 case 'k':
1813 {
1814 if (LocaleCompare("kerning",option+1) == 0)
1815 {
1816 if (*option == '+')
1817 (void) ParseGeometry("0",&geometry_info);
1818 else
1819 (void) ParseGeometry(argv[i+1],&geometry_info);
1820 draw_info->kerning=geometry_info.rho;
1821 break;
1822 }
1823 break;
1824 }
1825 case 'l':
1826 {
1827 if (LocaleCompare("lat",option+1) == 0)
1828 {
1829 /*
1830 Local adaptive threshold image.
1831 */
1832 (void) SyncImageSettings(mogrify_info,*image);
1833 flags=ParseGeometry(argv[i+1],&geometry_info);
1834 if ((flags & PercentValue) != 0)
1835 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1836 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001837 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001838 geometry_info.xi,exception);
1839 break;
1840 }
1841 if (LocaleCompare("level",option+1) == 0)
1842 {
1843 MagickRealType
1844 black_point,
1845 gamma,
1846 white_point;
1847
1848 MagickStatusType
1849 flags;
1850
1851 /*
1852 Parse levels.
1853 */
1854 (void) SyncImageSettings(mogrify_info,*image);
1855 flags=ParseGeometry(argv[i+1],&geometry_info);
1856 black_point=geometry_info.rho;
1857 white_point=(MagickRealType) QuantumRange;
1858 if ((flags & SigmaValue) != 0)
1859 white_point=geometry_info.sigma;
1860 gamma=1.0;
1861 if ((flags & XiValue) != 0)
1862 gamma=geometry_info.xi;
1863 if ((flags & PercentValue) != 0)
1864 {
1865 black_point*=(MagickRealType) (QuantumRange/100.0);
1866 white_point*=(MagickRealType) (QuantumRange/100.0);
1867 }
1868 if ((flags & SigmaValue) == 0)
1869 white_point=(MagickRealType) QuantumRange-black_point;
1870 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001871 (void) LevelizeImage(*image,black_point,white_point,gamma,
1872 exception);
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,
cristy7c0a0a42011-08-23 17:57:25 +00001911 *option == '+' ? MagickTrue : MagickFalse,exception);
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;
cristy33bd5152011-08-24 01:42:24 +00001937 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001938 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);
cristy33bd5152011-08-24 01:42:24 +00002047 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002048 break;
2049 }
2050 if (LocaleCompare("monitor",option+1) == 0)
2051 {
2052 if (*option == '+')
2053 {
2054 (void) SetImageProgressMonitor(*image,
2055 (MagickProgressMonitor) NULL,(void *) NULL);
2056 break;
2057 }
2058 (void) SetImageProgressMonitor(*image,MonitorProgress,
2059 (void *) NULL);
2060 break;
2061 }
2062 if (LocaleCompare("monochrome",option+1) == 0)
2063 {
2064 (void) SyncImageSettings(mogrify_info,*image);
2065 (void) SetImageType(*image,BilevelType);
2066 InheritException(exception,&(*image)->exception);
2067 break;
2068 }
2069 if (LocaleCompare("morphology",option+1) == 0)
2070 {
2071 char
2072 token[MaxTextExtent];
2073
2074 const char
2075 *p;
2076
2077 KernelInfo
2078 *kernel;
2079
2080 MorphologyMethod
2081 method;
2082
2083 ssize_t
2084 iterations;
2085
2086 /*
2087 Morphological Image Operation
2088 */
2089 (void) SyncImageSettings(mogrify_info,*image);
2090 p=argv[i+1];
2091 GetMagickToken(p,&p,token);
2092 method=(MorphologyMethod) ParseCommandOption(MagickMorphologyOptions,
2093 MagickFalse,token);
2094 iterations=1L;
2095 GetMagickToken(p,&p,token);
2096 if ((*p == ':') || (*p == ','))
2097 GetMagickToken(p,&p,token);
2098 if ((*p != '\0'))
2099 iterations=(ssize_t) StringToLong(p);
2100 kernel=AcquireKernelInfo(argv[i+2]);
2101 if (kernel == (KernelInfo *) NULL)
2102 {
2103 (void) ThrowMagickException(exception,GetMagickModule(),
2104 OptionError,"UnabletoParseKernel","morphology");
2105 status=MagickFalse;
2106 break;
2107 }
cristyf4ad9df2011-07-08 16:49:03 +00002108 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2109 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002110 kernel=DestroyKernelInfo(kernel);
2111 break;
2112 }
2113 if (LocaleCompare("motion-blur",option+1) == 0)
2114 {
2115 /*
2116 Motion blur image.
2117 */
2118 (void) SyncImageSettings(mogrify_info,*image);
2119 flags=ParseGeometry(argv[i+1],&geometry_info);
2120 if ((flags & SigmaValue) == 0)
2121 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002122 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2123 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002124 break;
2125 }
2126 break;
2127 }
2128 case 'n':
2129 {
2130 if (LocaleCompare("negate",option+1) == 0)
2131 {
2132 (void) SyncImageSettings(mogrify_info,*image);
cristy50fbc382011-07-07 02:19:17 +00002133 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002134 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002135 break;
2136 }
2137 if (LocaleCompare("noise",option+1) == 0)
2138 {
2139 (void) SyncImageSettings(mogrify_info,*image);
2140 if (*option == '-')
2141 {
2142 (void) ParseGeometry(argv[i+1],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002143 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2144 geometry_info.rho,(size_t) geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002145 }
2146 else
2147 {
2148 NoiseType
2149 noise;
2150
2151 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2152 MagickFalse,argv[i+1]);
cristy490408a2011-07-07 14:42:05 +00002153 mogrify_image=AddNoiseImage(*image,noise,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002154 }
2155 break;
2156 }
2157 if (LocaleCompare("normalize",option+1) == 0)
2158 {
2159 (void) SyncImageSettings(mogrify_info,*image);
cristye23ec9d2011-08-16 18:15:40 +00002160 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002161 break;
2162 }
2163 break;
2164 }
2165 case 'o':
2166 {
2167 if (LocaleCompare("opaque",option+1) == 0)
2168 {
cristy4c08aed2011-07-01 19:47:50 +00002169 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002170 target;
2171
2172 (void) SyncImageSettings(mogrify_info,*image);
2173 (void) QueryMagickColor(argv[i+1],&target,exception);
cristyd42d9952011-07-08 14:21:50 +00002174 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2175 MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002176 break;
2177 }
2178 if (LocaleCompare("ordered-dither",option+1) == 0)
2179 {
2180 (void) SyncImageSettings(mogrify_info,*image);
cristy13020672011-07-08 02:33:26 +00002181 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002182 break;
2183 }
2184 break;
2185 }
2186 case 'p':
2187 {
2188 if (LocaleCompare("paint",option+1) == 0)
2189 {
anthonydf8ebac2011-04-27 09:03:19 +00002190 (void) SyncImageSettings(mogrify_info,*image);
2191 (void) ParseGeometry(argv[i+1],&geometry_info);
anthony3d2f4862011-05-01 13:48:16 +00002192 mogrify_image=OilPaintImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002193 break;
2194 }
2195 if (LocaleCompare("pen",option+1) == 0)
2196 {
2197 if (*option == '+')
2198 {
2199 (void) QueryColorDatabase("none",&draw_info->fill,exception);
2200 break;
2201 }
2202 (void) QueryColorDatabase(argv[i+1],&draw_info->fill,exception);
2203 break;
2204 }
2205 if (LocaleCompare("pointsize",option+1) == 0)
2206 {
2207 if (*option == '+')
2208 (void) ParseGeometry("12",&geometry_info);
2209 else
2210 (void) ParseGeometry(argv[i+1],&geometry_info);
2211 draw_info->pointsize=geometry_info.rho;
2212 break;
2213 }
2214 if (LocaleCompare("polaroid",option+1) == 0)
2215 {
2216 double
2217 angle;
2218
2219 RandomInfo
2220 *random_info;
2221
2222 /*
2223 Simulate a Polaroid picture.
2224 */
2225 (void) SyncImageSettings(mogrify_info,*image);
2226 random_info=AcquireRandomInfo();
2227 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2228 random_info=DestroyRandomInfo(random_info);
2229 if (*option == '-')
2230 {
2231 SetGeometryInfo(&geometry_info);
2232 flags=ParseGeometry(argv[i+1],&geometry_info);
2233 angle=geometry_info.rho;
2234 }
2235 mogrify_image=PolaroidImage(*image,draw_info,angle,exception);
2236 break;
2237 }
2238 if (LocaleCompare("posterize",option+1) == 0)
2239 {
2240 /*
2241 Posterize image.
2242 */
2243 (void) SyncImageSettings(mogrify_info,*image);
2244 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2245 quantize_info->dither);
2246 InheritException(exception,&(*image)->exception);
2247 break;
2248 }
2249 if (LocaleCompare("preview",option+1) == 0)
2250 {
2251 PreviewType
2252 preview_type;
2253
2254 /*
2255 Preview image.
2256 */
2257 (void) SyncImageSettings(mogrify_info,*image);
2258 if (*option == '+')
2259 preview_type=UndefinedPreview;
2260 else
2261 preview_type=(PreviewType) ParseCommandOption(MagickPreviewOptions,
2262 MagickFalse,argv[i+1]);
2263 mogrify_image=PreviewImage(*image,preview_type,exception);
2264 break;
2265 }
2266 if (LocaleCompare("profile",option+1) == 0)
2267 {
2268 const char
2269 *name;
2270
2271 const StringInfo
2272 *profile;
2273
2274 Image
2275 *profile_image;
2276
2277 ImageInfo
2278 *profile_info;
2279
2280 (void) SyncImageSettings(mogrify_info,*image);
2281 if (*option == '+')
2282 {
2283 /*
2284 Remove a profile from the image.
2285 */
2286 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2287 NULL,0,MagickTrue);
2288 InheritException(exception,&(*image)->exception);
2289 break;
2290 }
2291 /*
2292 Associate a profile with the image.
2293 */
2294 profile_info=CloneImageInfo(mogrify_info);
2295 profile=GetImageProfile(*image,"iptc");
2296 if (profile != (StringInfo *) NULL)
2297 profile_info->profile=(void *) CloneStringInfo(profile);
2298 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2299 profile_info=DestroyImageInfo(profile_info);
2300 if (profile_image == (Image *) NULL)
2301 {
2302 StringInfo
2303 *profile;
2304
2305 profile_info=CloneImageInfo(mogrify_info);
2306 (void) CopyMagickString(profile_info->filename,argv[i+1],
2307 MaxTextExtent);
2308 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2309 if (profile != (StringInfo *) NULL)
2310 {
2311 (void) ProfileImage(*image,profile_info->magick,
2312 GetStringInfoDatum(profile),(size_t)
2313 GetStringInfoLength(profile),MagickFalse);
2314 profile=DestroyStringInfo(profile);
2315 }
2316 profile_info=DestroyImageInfo(profile_info);
2317 break;
2318 }
2319 ResetImageProfileIterator(profile_image);
2320 name=GetNextImageProfile(profile_image);
2321 while (name != (const char *) NULL)
2322 {
2323 profile=GetImageProfile(profile_image,name);
2324 if (profile != (StringInfo *) NULL)
2325 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2326 (size_t) GetStringInfoLength(profile),MagickFalse);
2327 name=GetNextImageProfile(profile_image);
2328 }
2329 profile_image=DestroyImage(profile_image);
2330 break;
2331 }
2332 break;
2333 }
2334 case 'q':
2335 {
2336 if (LocaleCompare("quantize",option+1) == 0)
2337 {
2338 if (*option == '+')
2339 {
2340 quantize_info->colorspace=UndefinedColorspace;
2341 break;
2342 }
2343 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2344 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2345 break;
2346 }
2347 break;
2348 }
2349 case 'r':
2350 {
2351 if (LocaleCompare("radial-blur",option+1) == 0)
2352 {
2353 /*
2354 Radial blur image.
2355 */
2356 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002357 mogrify_image=RadialBlurImage(*image,InterpretLocaleValue(argv[i+1],
2358 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002359 break;
2360 }
2361 if (LocaleCompare("raise",option+1) == 0)
2362 {
2363 /*
2364 Surround image with a raise of solid color.
2365 */
2366 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2367 if ((flags & SigmaValue) == 0)
2368 geometry.height=geometry.width;
2369 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2370 MagickFalse);
2371 InheritException(exception,&(*image)->exception);
2372 break;
2373 }
2374 if (LocaleCompare("random-threshold",option+1) == 0)
2375 {
2376 /*
2377 Threshold image.
2378 */
2379 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00002380 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002381 break;
2382 }
2383 if (LocaleCompare("recolor",option+1) == 0)
2384 {
2385 KernelInfo
2386 *kernel;
2387
2388 (void) SyncImageSettings(mogrify_info,*image);
2389 kernel=AcquireKernelInfo(argv[i+1]);
2390 if (kernel == (KernelInfo *) NULL)
2391 break;
2392 mogrify_image=ColorMatrixImage(*image,kernel,exception);
2393 kernel=DestroyKernelInfo(kernel);
2394 break;
2395 }
2396 if (LocaleCompare("region",option+1) == 0)
2397 {
2398 (void) SyncImageSettings(mogrify_info,*image);
2399 if (region_image != (Image *) NULL)
2400 {
2401 /*
2402 Composite region.
2403 */
2404 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002405 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2406 region_geometry.x,region_geometry.y);
anthonydf8ebac2011-04-27 09:03:19 +00002407 InheritException(exception,&region_image->exception);
2408 *image=DestroyImage(*image);
2409 *image=region_image;
2410 region_image = (Image *) NULL;
2411 }
2412 if (*option == '+')
2413 break;
2414 /*
2415 Apply transformations to a selected region of the image.
2416 */
cristy3ed852e2009-09-05 21:47:34 +00002417 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2418 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002419 mogrify_image=CropImage(*image,&region_geometry,exception);
2420 if (mogrify_image == (Image *) NULL)
2421 break;
2422 region_image=(*image);
2423 *image=mogrify_image;
2424 mogrify_image=(Image *) NULL;
2425 break;
cristy3ed852e2009-09-05 21:47:34 +00002426 }
anthonydf8ebac2011-04-27 09:03:19 +00002427 if (LocaleCompare("render",option+1) == 0)
2428 {
2429 (void) SyncImageSettings(mogrify_info,*image);
2430 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2431 break;
2432 }
2433 if (LocaleCompare("remap",option+1) == 0)
2434 {
2435 Image
2436 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002437
anthonydf8ebac2011-04-27 09:03:19 +00002438 /*
2439 Transform image colors to match this set of colors.
2440 */
2441 (void) SyncImageSettings(mogrify_info,*image);
2442 if (*option == '+')
2443 break;
2444 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2445 if (remap_image == (Image *) NULL)
2446 break;
2447 (void) RemapImage(quantize_info,*image,remap_image);
2448 InheritException(exception,&(*image)->exception);
2449 remap_image=DestroyImage(remap_image);
2450 break;
2451 }
2452 if (LocaleCompare("repage",option+1) == 0)
2453 {
2454 if (*option == '+')
2455 {
2456 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2457 break;
2458 }
2459 (void) ResetImagePage(*image,argv[i+1]);
2460 InheritException(exception,&(*image)->exception);
2461 break;
2462 }
2463 if (LocaleCompare("resample",option+1) == 0)
2464 {
2465 /*
2466 Resample image.
2467 */
2468 (void) SyncImageSettings(mogrify_info,*image);
2469 flags=ParseGeometry(argv[i+1],&geometry_info);
2470 if ((flags & SigmaValue) == 0)
2471 geometry_info.sigma=geometry_info.rho;
2472 mogrify_image=ResampleImage(*image,geometry_info.rho,
2473 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2474 break;
2475 }
2476 if (LocaleCompare("resize",option+1) == 0)
2477 {
2478 /*
2479 Resize image.
2480 */
2481 (void) SyncImageSettings(mogrify_info,*image);
2482 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2483 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2484 (*image)->filter,(*image)->blur,exception);
2485 break;
2486 }
2487 if (LocaleCompare("roll",option+1) == 0)
2488 {
2489 /*
2490 Roll image.
2491 */
2492 (void) SyncImageSettings(mogrify_info,*image);
2493 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2494 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2495 break;
2496 }
2497 if (LocaleCompare("rotate",option+1) == 0)
2498 {
2499 char
2500 *geometry;
2501
2502 /*
2503 Check for conditional image rotation.
2504 */
2505 (void) SyncImageSettings(mogrify_info,*image);
2506 if (strchr(argv[i+1],'>') != (char *) NULL)
2507 if ((*image)->columns <= (*image)->rows)
2508 break;
2509 if (strchr(argv[i+1],'<') != (char *) NULL)
2510 if ((*image)->columns >= (*image)->rows)
2511 break;
2512 /*
2513 Rotate image.
2514 */
2515 geometry=ConstantString(argv[i+1]);
2516 (void) SubstituteString(&geometry,">","");
2517 (void) SubstituteString(&geometry,"<","");
2518 (void) ParseGeometry(geometry,&geometry_info);
2519 geometry=DestroyString(geometry);
2520 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2521 break;
2522 }
2523 break;
2524 }
2525 case 's':
2526 {
2527 if (LocaleCompare("sample",option+1) == 0)
2528 {
2529 /*
2530 Sample image with pixel replication.
2531 */
2532 (void) SyncImageSettings(mogrify_info,*image);
2533 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2534 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2535 exception);
2536 break;
2537 }
2538 if (LocaleCompare("scale",option+1) == 0)
2539 {
2540 /*
2541 Resize image.
2542 */
2543 (void) SyncImageSettings(mogrify_info,*image);
2544 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2545 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2546 exception);
2547 break;
2548 }
2549 if (LocaleCompare("selective-blur",option+1) == 0)
2550 {
2551 /*
2552 Selectively blur pixels within a contrast threshold.
2553 */
2554 (void) SyncImageSettings(mogrify_info,*image);
2555 flags=ParseGeometry(argv[i+1],&geometry_info);
2556 if ((flags & PercentValue) != 0)
2557 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002558 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2559 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002560 break;
2561 }
2562 if (LocaleCompare("separate",option+1) == 0)
2563 {
2564 /*
2565 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002566 */
2567 (void) SyncImageSettings(mogrify_info,*image);
cristy3139dc22011-07-08 00:11:42 +00002568 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002569 break;
2570 }
2571 if (LocaleCompare("sepia-tone",option+1) == 0)
2572 {
2573 double
2574 threshold;
2575
2576 /*
2577 Sepia-tone image.
2578 */
2579 (void) SyncImageSettings(mogrify_info,*image);
2580 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2581 mogrify_image=SepiaToneImage(*image,threshold,exception);
2582 break;
2583 }
2584 if (LocaleCompare("segment",option+1) == 0)
2585 {
2586 /*
2587 Segment image.
2588 */
2589 (void) SyncImageSettings(mogrify_info,*image);
2590 flags=ParseGeometry(argv[i+1],&geometry_info);
2591 if ((flags & SigmaValue) == 0)
2592 geometry_info.sigma=1.0;
2593 (void) SegmentImage(*image,(*image)->colorspace,
2594 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma);
2595 InheritException(exception,&(*image)->exception);
2596 break;
2597 }
2598 if (LocaleCompare("set",option+1) == 0)
2599 {
2600 char
2601 *value;
2602
2603 /*
2604 Set image option.
2605 */
2606 if (*option == '+')
2607 {
2608 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2609 (void) DeleteImageRegistry(argv[i+1]+9);
2610 else
2611 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2612 {
2613 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2614 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2615 }
2616 else
2617 (void) DeleteImageProperty(*image,argv[i+1]);
2618 break;
2619 }
2620 value=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2621 if (value == (char *) NULL)
2622 break;
2623 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2624 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2625 exception);
2626 else
2627 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2628 {
2629 (void) SetImageOption(image_info,argv[i+1]+7,value);
2630 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2631 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2632 }
2633 else
2634 (void) SetImageProperty(*image,argv[i+1],value);
2635 value=DestroyString(value);
2636 break;
2637 }
2638 if (LocaleCompare("shade",option+1) == 0)
2639 {
2640 /*
2641 Shade image.
2642 */
2643 (void) SyncImageSettings(mogrify_info,*image);
2644 flags=ParseGeometry(argv[i+1],&geometry_info);
2645 if ((flags & SigmaValue) == 0)
2646 geometry_info.sigma=1.0;
2647 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2648 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2649 break;
2650 }
2651 if (LocaleCompare("shadow",option+1) == 0)
2652 {
2653 /*
2654 Shadow image.
2655 */
2656 (void) SyncImageSettings(mogrify_info,*image);
2657 flags=ParseGeometry(argv[i+1],&geometry_info);
2658 if ((flags & SigmaValue) == 0)
2659 geometry_info.sigma=1.0;
2660 if ((flags & XiValue) == 0)
2661 geometry_info.xi=4.0;
2662 if ((flags & PsiValue) == 0)
2663 geometry_info.psi=4.0;
2664 mogrify_image=ShadowImage(*image,geometry_info.rho,
2665 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
2666 ceil(geometry_info.psi-0.5),exception);
2667 break;
2668 }
2669 if (LocaleCompare("sharpen",option+1) == 0)
2670 {
2671 /*
2672 Sharpen image.
2673 */
2674 (void) SyncImageSettings(mogrify_info,*image);
2675 flags=ParseGeometry(argv[i+1],&geometry_info);
2676 if ((flags & SigmaValue) == 0)
2677 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002678 mogrify_image=SharpenImage(*image,geometry_info.rho,
anthonydf8ebac2011-04-27 09:03:19 +00002679 geometry_info.sigma,exception);
2680 break;
2681 }
2682 if (LocaleCompare("shave",option+1) == 0)
2683 {
2684 /*
2685 Shave the image edges.
2686 */
2687 (void) SyncImageSettings(mogrify_info,*image);
2688 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2689 mogrify_image=ShaveImage(*image,&geometry,exception);
2690 break;
2691 }
2692 if (LocaleCompare("shear",option+1) == 0)
2693 {
2694 /*
2695 Shear image.
2696 */
2697 (void) SyncImageSettings(mogrify_info,*image);
2698 flags=ParseGeometry(argv[i+1],&geometry_info);
2699 if ((flags & SigmaValue) == 0)
2700 geometry_info.sigma=geometry_info.rho;
2701 mogrify_image=ShearImage(*image,geometry_info.rho,
2702 geometry_info.sigma,exception);
2703 break;
2704 }
2705 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2706 {
2707 /*
2708 Sigmoidal non-linearity contrast control.
2709 */
2710 (void) SyncImageSettings(mogrify_info,*image);
2711 flags=ParseGeometry(argv[i+1],&geometry_info);
2712 if ((flags & SigmaValue) == 0)
2713 geometry_info.sigma=(double) QuantumRange/2.0;
2714 if ((flags & PercentValue) != 0)
2715 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2716 100.0;
cristy9ee60942011-07-06 14:54:38 +00002717 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002718 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2719 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002720 break;
2721 }
2722 if (LocaleCompare("sketch",option+1) == 0)
2723 {
2724 /*
2725 Sketch image.
2726 */
2727 (void) SyncImageSettings(mogrify_info,*image);
2728 flags=ParseGeometry(argv[i+1],&geometry_info);
2729 if ((flags & SigmaValue) == 0)
2730 geometry_info.sigma=1.0;
2731 mogrify_image=SketchImage(*image,geometry_info.rho,
2732 geometry_info.sigma,geometry_info.xi,exception);
2733 break;
2734 }
2735 if (LocaleCompare("solarize",option+1) == 0)
2736 {
2737 double
2738 threshold;
2739
2740 (void) SyncImageSettings(mogrify_info,*image);
2741 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
2742 (void) SolarizeImage(*image,threshold);
2743 InheritException(exception,&(*image)->exception);
2744 break;
2745 }
2746 if (LocaleCompare("sparse-color",option+1) == 0)
2747 {
2748 SparseColorMethod
2749 method;
2750
2751 char
2752 *arguments;
2753
2754 /*
2755 Sparse Color Interpolated Gradient
2756 */
2757 (void) SyncImageSettings(mogrify_info,*image);
2758 method=(SparseColorMethod) ParseCommandOption(
2759 MagickSparseColorOptions,MagickFalse,argv[i+1]);
2760 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2]);
2761 InheritException(exception,&(*image)->exception);
2762 if (arguments == (char *) NULL)
2763 break;
cristy3884f692011-07-08 18:00:18 +00002764 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002765 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2766 arguments=DestroyString(arguments);
2767 break;
2768 }
2769 if (LocaleCompare("splice",option+1) == 0)
2770 {
2771 /*
2772 Splice a solid color into the image.
2773 */
2774 (void) SyncImageSettings(mogrify_info,*image);
2775 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2776 mogrify_image=SpliceImage(*image,&geometry,exception);
2777 break;
2778 }
2779 if (LocaleCompare("spread",option+1) == 0)
2780 {
2781 /*
2782 Spread an image.
2783 */
2784 (void) SyncImageSettings(mogrify_info,*image);
2785 (void) ParseGeometry(argv[i+1],&geometry_info);
2786 mogrify_image=SpreadImage(*image,geometry_info.rho,exception);
2787 break;
2788 }
2789 if (LocaleCompare("statistic",option+1) == 0)
2790 {
2791 StatisticType
2792 type;
2793
2794 (void) SyncImageSettings(mogrify_info,*image);
2795 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2796 MagickFalse,argv[i+1]);
2797 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002798 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2799 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002800 break;
2801 }
2802 if (LocaleCompare("stretch",option+1) == 0)
2803 {
2804 if (*option == '+')
2805 {
2806 draw_info->stretch=UndefinedStretch;
2807 break;
2808 }
2809 draw_info->stretch=(StretchType) ParseCommandOption(
2810 MagickStretchOptions,MagickFalse,argv[i+1]);
2811 break;
2812 }
2813 if (LocaleCompare("strip",option+1) == 0)
2814 {
2815 /*
2816 Strip image of profiles and comments.
2817 */
2818 (void) SyncImageSettings(mogrify_info,*image);
2819 (void) StripImage(*image);
2820 InheritException(exception,&(*image)->exception);
2821 break;
2822 }
2823 if (LocaleCompare("stroke",option+1) == 0)
2824 {
2825 ExceptionInfo
2826 *sans;
2827
2828 if (*option == '+')
2829 {
2830 (void) QueryColorDatabase("none",&draw_info->stroke,exception);
2831 if (draw_info->stroke_pattern != (Image *) NULL)
2832 draw_info->stroke_pattern=DestroyImage(
2833 draw_info->stroke_pattern);
2834 break;
2835 }
2836 sans=AcquireExceptionInfo();
2837 status=QueryColorDatabase(argv[i+1],&draw_info->stroke,sans);
2838 sans=DestroyExceptionInfo(sans);
2839 if (status == MagickFalse)
2840 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2841 exception);
2842 break;
2843 }
2844 if (LocaleCompare("strokewidth",option+1) == 0)
2845 {
cristyc1acd842011-05-19 23:05:47 +00002846 draw_info->stroke_width=InterpretLocaleValue(argv[i+1],
2847 (char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002848 break;
2849 }
2850 if (LocaleCompare("style",option+1) == 0)
2851 {
2852 if (*option == '+')
2853 {
2854 draw_info->style=UndefinedStyle;
2855 break;
2856 }
2857 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2858 MagickFalse,argv[i+1]);
2859 break;
2860 }
2861 if (LocaleCompare("swirl",option+1) == 0)
2862 {
2863 /*
2864 Swirl image.
2865 */
2866 (void) SyncImageSettings(mogrify_info,*image);
2867 (void) ParseGeometry(argv[i+1],&geometry_info);
2868 mogrify_image=SwirlImage(*image,geometry_info.rho,exception);
2869 break;
2870 }
2871 break;
2872 }
2873 case 't':
2874 {
2875 if (LocaleCompare("threshold",option+1) == 0)
2876 {
2877 double
2878 threshold;
2879
2880 /*
2881 Threshold image.
2882 */
2883 (void) SyncImageSettings(mogrify_info,*image);
2884 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002885 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002886 else
2887 threshold=SiPrefixToDouble(argv[i+1],QuantumRange);
cristyf4ad9df2011-07-08 16:49:03 +00002888 (void) BilevelImage(*image,threshold);
anthonydf8ebac2011-04-27 09:03:19 +00002889 InheritException(exception,&(*image)->exception);
2890 break;
2891 }
2892 if (LocaleCompare("thumbnail",option+1) == 0)
2893 {
2894 /*
2895 Thumbnail image.
2896 */
2897 (void) SyncImageSettings(mogrify_info,*image);
2898 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2899 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2900 exception);
2901 break;
2902 }
2903 if (LocaleCompare("tile",option+1) == 0)
2904 {
2905 if (*option == '+')
2906 {
2907 if (draw_info->fill_pattern != (Image *) NULL)
2908 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2909 break;
2910 }
2911 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2912 exception);
2913 break;
2914 }
2915 if (LocaleCompare("tint",option+1) == 0)
2916 {
2917 /*
2918 Tint the image.
2919 */
2920 (void) SyncImageSettings(mogrify_info,*image);
2921 mogrify_image=TintImage(*image,argv[i+1],draw_info->fill,exception);
2922 break;
2923 }
2924 if (LocaleCompare("transform",option+1) == 0)
2925 {
2926 /*
2927 Affine transform image.
2928 */
2929 (void) SyncImageSettings(mogrify_info,*image);
2930 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2931 exception);
2932 break;
2933 }
2934 if (LocaleCompare("transparent",option+1) == 0)
2935 {
cristy4c08aed2011-07-01 19:47:50 +00002936 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002937 target;
2938
2939 (void) SyncImageSettings(mogrify_info,*image);
2940 (void) QueryMagickColor(argv[i+1],&target,exception);
2941 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy4c08aed2011-07-01 19:47:50 +00002942 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue);
anthonydf8ebac2011-04-27 09:03:19 +00002943 InheritException(exception,&(*image)->exception);
2944 break;
2945 }
2946 if (LocaleCompare("transpose",option+1) == 0)
2947 {
2948 /*
2949 Transpose image scanlines.
2950 */
2951 (void) SyncImageSettings(mogrify_info,*image);
2952 mogrify_image=TransposeImage(*image,exception);
2953 break;
2954 }
2955 if (LocaleCompare("transverse",option+1) == 0)
2956 {
2957 /*
2958 Transverse image scanlines.
2959 */
2960 (void) SyncImageSettings(mogrify_info,*image);
2961 mogrify_image=TransverseImage(*image,exception);
2962 break;
2963 }
2964 if (LocaleCompare("treedepth",option+1) == 0)
2965 {
2966 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
2967 break;
2968 }
2969 if (LocaleCompare("trim",option+1) == 0)
2970 {
2971 /*
2972 Trim image.
2973 */
2974 (void) SyncImageSettings(mogrify_info,*image);
2975 mogrify_image=TrimImage(*image,exception);
2976 break;
2977 }
2978 if (LocaleCompare("type",option+1) == 0)
2979 {
2980 ImageType
2981 type;
2982
2983 (void) SyncImageSettings(mogrify_info,*image);
2984 if (*option == '+')
2985 type=UndefinedType;
2986 else
2987 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
2988 argv[i+1]);
2989 (*image)->type=UndefinedType;
2990 (void) SetImageType(*image,type);
2991 InheritException(exception,&(*image)->exception);
2992 break;
2993 }
2994 break;
2995 }
2996 case 'u':
2997 {
2998 if (LocaleCompare("undercolor",option+1) == 0)
2999 {
3000 (void) QueryColorDatabase(argv[i+1],&draw_info->undercolor,
3001 exception);
3002 break;
3003 }
3004 if (LocaleCompare("unique",option+1) == 0)
3005 {
3006 if (*option == '+')
3007 {
3008 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3009 break;
3010 }
3011 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3012 (void) SetImageArtifact(*image,"verbose","true");
3013 break;
3014 }
3015 if (LocaleCompare("unique-colors",option+1) == 0)
3016 {
3017 /*
3018 Unique image colors.
3019 */
3020 (void) SyncImageSettings(mogrify_info,*image);
3021 mogrify_image=UniqueImageColors(*image,exception);
3022 break;
3023 }
3024 if (LocaleCompare("unsharp",option+1) == 0)
3025 {
3026 /*
3027 Unsharp mask image.
3028 */
3029 (void) SyncImageSettings(mogrify_info,*image);
3030 flags=ParseGeometry(argv[i+1],&geometry_info);
3031 if ((flags & SigmaValue) == 0)
3032 geometry_info.sigma=1.0;
3033 if ((flags & XiValue) == 0)
3034 geometry_info.xi=1.0;
3035 if ((flags & PsiValue) == 0)
3036 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003037 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3038 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003039 break;
3040 }
3041 break;
3042 }
3043 case 'v':
3044 {
3045 if (LocaleCompare("verbose",option+1) == 0)
3046 {
3047 (void) SetImageArtifact(*image,option+1,
3048 *option == '+' ? "false" : "true");
3049 break;
3050 }
3051 if (LocaleCompare("vignette",option+1) == 0)
3052 {
3053 /*
3054 Vignette image.
3055 */
3056 (void) SyncImageSettings(mogrify_info,*image);
3057 flags=ParseGeometry(argv[i+1],&geometry_info);
3058 if ((flags & SigmaValue) == 0)
3059 geometry_info.sigma=1.0;
3060 if ((flags & XiValue) == 0)
3061 geometry_info.xi=0.1*(*image)->columns;
3062 if ((flags & PsiValue) == 0)
3063 geometry_info.psi=0.1*(*image)->rows;
3064 mogrify_image=VignetteImage(*image,geometry_info.rho,
3065 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),(ssize_t)
3066 ceil(geometry_info.psi-0.5),exception);
3067 break;
3068 }
3069 if (LocaleCompare("virtual-pixel",option+1) == 0)
3070 {
3071 if (*option == '+')
3072 {
3073 (void) SetImageVirtualPixelMethod(*image,
3074 UndefinedVirtualPixelMethod);
3075 break;
3076 }
3077 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3078 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3079 argv[i+1]));
3080 break;
3081 }
3082 break;
3083 }
3084 case 'w':
3085 {
3086 if (LocaleCompare("wave",option+1) == 0)
3087 {
3088 /*
3089 Wave image.
3090 */
3091 (void) SyncImageSettings(mogrify_info,*image);
3092 flags=ParseGeometry(argv[i+1],&geometry_info);
3093 if ((flags & SigmaValue) == 0)
3094 geometry_info.sigma=1.0;
3095 mogrify_image=WaveImage(*image,geometry_info.rho,
3096 geometry_info.sigma,exception);
3097 break;
3098 }
3099 if (LocaleCompare("weight",option+1) == 0)
3100 {
3101 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3102 if (LocaleCompare(argv[i+1],"all") == 0)
3103 draw_info->weight=0;
3104 if (LocaleCompare(argv[i+1],"bold") == 0)
3105 draw_info->weight=700;
3106 if (LocaleCompare(argv[i+1],"bolder") == 0)
3107 if (draw_info->weight <= 800)
3108 draw_info->weight+=100;
3109 if (LocaleCompare(argv[i+1],"lighter") == 0)
3110 if (draw_info->weight >= 100)
3111 draw_info->weight-=100;
3112 if (LocaleCompare(argv[i+1],"normal") == 0)
3113 draw_info->weight=400;
3114 break;
3115 }
3116 if (LocaleCompare("white-threshold",option+1) == 0)
3117 {
3118 /*
3119 White threshold image.
3120 */
3121 (void) SyncImageSettings(mogrify_info,*image);
cristyf4ad9df2011-07-08 16:49:03 +00003122 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003123 InheritException(exception,&(*image)->exception);
3124 break;
3125 }
3126 break;
3127 }
3128 default:
3129 break;
3130 }
3131 /*
3132 Replace current image with any image that was generated
3133 */
3134 if (mogrify_image != (Image *) NULL)
3135 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003136 i+=count;
3137 }
3138 if (region_image != (Image *) NULL)
3139 {
anthonydf8ebac2011-04-27 09:03:19 +00003140 /*
3141 Composite transformed region onto image.
3142 */
cristy6b3da3a2010-06-20 02:21:46 +00003143 (void) SyncImageSettings(mogrify_info,*image);
anthonya129f702011-04-14 01:08:48 +00003144 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003145 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3146 region_geometry.x,region_geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00003147 InheritException(exception,&region_image->exception);
3148 *image=DestroyImage(*image);
3149 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003150 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003151 }
3152 /*
3153 Free resources.
3154 */
anthonydf8ebac2011-04-27 09:03:19 +00003155 quantize_info=DestroyQuantizeInfo(quantize_info);
3156 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003157 mogrify_info=DestroyImageInfo(mogrify_info);
cristy4c08aed2011-07-01 19:47:50 +00003158 status=(MagickStatusType) ((*image)->exception.severity ==
cristy5f09d852011-05-29 01:39:29 +00003159 UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003160 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003161}
3162
3163/*
3164%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3165% %
3166% %
3167% %
cristy5063d812010-10-19 16:28:10 +00003168+ 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 +00003169% %
3170% %
3171% %
3172%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3173%
3174% MogrifyImageCommand() transforms an image or a sequence of images. These
3175% transforms include image scaling, image rotation, color reduction, and
3176% others. The transmogrified image overwrites the original image.
3177%
3178% The format of the MogrifyImageCommand method is:
3179%
3180% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3181% const char **argv,char **metadata,ExceptionInfo *exception)
3182%
3183% A description of each parameter follows:
3184%
3185% o image_info: the image info.
3186%
3187% o argc: the number of elements in the argument vector.
3188%
3189% o argv: A text array containing the command line arguments.
3190%
3191% o metadata: any metadata is returned here.
3192%
3193% o exception: return any errors or warnings in this structure.
3194%
3195*/
3196
3197static MagickBooleanType MogrifyUsage(void)
3198{
3199 static const char
3200 *miscellaneous[]=
3201 {
3202 "-debug events display copious debugging information",
3203 "-help print program options",
3204 "-list type print a list of supported option arguments",
3205 "-log format format of debugging information",
3206 "-version print version information",
3207 (char *) NULL
3208 },
3209 *operators[]=
3210 {
3211 "-adaptive-blur geometry",
3212 " adaptively blur pixels; decrease effect near edges",
3213 "-adaptive-resize geometry",
3214 " adaptively resize image using 'mesh' interpolation",
3215 "-adaptive-sharpen geometry",
3216 " adaptively sharpen pixels; increase effect near edges",
3217 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3218 " transparent, extract, background, or shape",
3219 "-annotate geometry text",
3220 " annotate the image with text",
3221 "-auto-gamma automagically adjust gamma level of image",
3222 "-auto-level automagically adjust color levels of image",
3223 "-auto-orient automagically orient (rotate) image",
3224 "-bench iterations measure performance",
3225 "-black-threshold value",
3226 " force all pixels below the threshold into black",
3227 "-blue-shift simulate a scene at nighttime in the moonlight",
3228 "-blur geometry reduce image noise and reduce detail levels",
3229 "-border geometry surround image with a border of color",
3230 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003231 "-brightness-contrast geometry",
3232 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003233 "-cdl filename color correct with a color decision list",
3234 "-charcoal radius simulate a charcoal drawing",
3235 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003236 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003237 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003238 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003239 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003240 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003241 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003242 "-contrast enhance or reduce the image contrast",
3243 "-contrast-stretch geometry",
3244 " improve contrast by `stretching' the intensity range",
3245 "-convolve coefficients",
3246 " apply a convolution kernel to the image",
3247 "-cycle amount cycle the image colormap",
3248 "-decipher filename convert cipher pixels to plain pixels",
3249 "-deskew threshold straighten an image",
3250 "-despeckle reduce the speckles within an image",
3251 "-distort method args",
3252 " distort images according to given method ad args",
3253 "-draw string annotate the image with a graphic primitive",
3254 "-edge radius apply a filter to detect edges in the image",
3255 "-encipher filename convert plain pixels to cipher pixels",
3256 "-emboss radius emboss an image",
3257 "-enhance apply a digital filter to enhance a noisy image",
3258 "-equalize perform histogram equalization to an image",
3259 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003260 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003261 "-extent geometry set the image size",
3262 "-extract geometry extract area from image",
3263 "-fft implements the discrete Fourier transform (DFT)",
3264 "-flip flip image vertically",
3265 "-floodfill geometry color",
3266 " floodfill the image with color",
3267 "-flop flop image horizontally",
3268 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003269 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003270 " apply function over image values",
3271 "-gamma value level of gamma correction",
3272 "-gaussian-blur geometry",
3273 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003274 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003275 "-identify identify the format and characteristics of the image",
3276 "-ift implements the inverse discrete Fourier transform (DFT)",
3277 "-implode amount implode image pixels about the center",
3278 "-lat geometry local adaptive thresholding",
3279 "-layers method optimize, merge, or compare image layers",
3280 "-level value adjust the level of image contrast",
3281 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003282 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003283 "-linear-stretch geometry",
3284 " improve contrast by `stretching with saturation'",
3285 "-liquid-rescale geometry",
3286 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003287 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003288 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003289 "-modulate value vary the brightness, saturation, and hue",
3290 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003291 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003292 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003293 "-motion-blur geometry",
3294 " simulate motion blur",
3295 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003296 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003297 "-normalize transform image to span the full range of colors",
3298 "-opaque color change this color to the fill color",
3299 "-ordered-dither NxN",
3300 " add a noise pattern to the image with specific",
3301 " amplitudes",
3302 "-paint radius simulate an oil painting",
3303 "-polaroid angle simulate a Polaroid picture",
3304 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003305 "-profile filename add, delete, or apply an image profile",
3306 "-quantize colorspace reduce colors in this colorspace",
3307 "-radial-blur angle radial blur the image",
3308 "-raise value lighten/darken image edges to create a 3-D effect",
3309 "-random-threshold low,high",
3310 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003311 "-region geometry apply options to a portion of the image",
3312 "-render render vector graphics",
3313 "-repage geometry size and location of an image canvas",
3314 "-resample geometry change the resolution of an image",
3315 "-resize geometry resize the image",
3316 "-roll geometry roll an image vertically or horizontally",
3317 "-rotate degrees apply Paeth rotation to the image",
3318 "-sample geometry scale image with pixel sampling",
3319 "-scale geometry scale the image",
3320 "-segment values segment an image",
3321 "-selective-blur geometry",
3322 " selectively blur pixels within a contrast threshold",
3323 "-sepia-tone threshold",
3324 " simulate a sepia-toned photo",
3325 "-set property value set an image property",
3326 "-shade degrees shade the image using a distant light source",
3327 "-shadow geometry simulate an image shadow",
3328 "-sharpen geometry sharpen the image",
3329 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003330 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003331 "-sigmoidal-contrast geometry",
3332 " increase the contrast without saturating highlights or shadows",
3333 "-sketch geometry simulate a pencil sketch",
3334 "-solarize threshold negate all pixels above the threshold level",
3335 "-sparse-color method args",
3336 " fill in a image based on a few color points",
3337 "-splice geometry splice the background color into the image",
3338 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003339 "-statistic type radius",
3340 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003341 "-strip strip image of all profiles and comments",
3342 "-swirl degrees swirl image pixels about the center",
3343 "-threshold value threshold the image",
3344 "-thumbnail geometry create a thumbnail of the image",
3345 "-tile filename tile image when filling a graphic primitive",
3346 "-tint value tint the image with the fill color",
3347 "-transform affine transform image",
3348 "-transparent color make this color transparent within the image",
3349 "-transpose flip image vertically and rotate 90 degrees",
3350 "-transverse flop image horizontally and rotate 270 degrees",
3351 "-trim trim image edges",
3352 "-type type image type",
3353 "-unique-colors discard all but one of any pixel color",
3354 "-unsharp geometry sharpen the image",
3355 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003356 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003357 "-white-threshold value",
3358 " force all pixels above the threshold into white",
3359 (char *) NULL
3360 },
3361 *sequence_operators[]=
3362 {
cristy4285d782011-02-09 20:12:28 +00003363 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003364 "-clut apply a color lookup table to the image",
3365 "-coalesce merge a sequence of images",
3366 "-combine combine a sequence of images",
3367 "-composite composite image",
3368 "-crop geometry cut out a rectangular region of the image",
3369 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003370 "-evaluate-sequence operator",
3371 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003372 "-flatten flatten a sequence of images",
3373 "-fx expression apply mathematical expression to an image channel(s)",
3374 "-hald-clut apply a Hald color lookup table to the image",
3375 "-morph value morph an image sequence",
3376 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003377 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003378 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003379 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003380 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003381 "-write filename write images to this file",
3382 (char *) NULL
3383 },
3384 *settings[]=
3385 {
3386 "-adjoin join images into a single multi-image file",
3387 "-affine matrix affine transform matrix",
3388 "-alpha option activate, deactivate, reset, or set the alpha channel",
3389 "-antialias remove pixel-aliasing",
3390 "-authenticate password",
3391 " decipher image with this password",
3392 "-attenuate value lessen (or intensify) when adding noise to an image",
3393 "-background color background color",
3394 "-bias value add bias when convolving an image",
3395 "-black-point-compensation",
3396 " use black point compensation",
3397 "-blue-primary point chromaticity blue primary point",
3398 "-bordercolor color border color",
3399 "-caption string assign a caption to an image",
3400 "-channel type apply option to select image channels",
3401 "-colors value preferred number of colors in the image",
3402 "-colorspace type alternate image colorspace",
3403 "-comment string annotate image with comment",
3404 "-compose operator set image composite operator",
3405 "-compress type type of pixel compression when writing the image",
3406 "-define format:option",
3407 " define one or more image format options",
3408 "-delay value display the next image after pausing",
3409 "-density geometry horizontal and vertical density of the image",
3410 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003411 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003412 "-display server get image or font from this X server",
3413 "-dispose method layer disposal method",
3414 "-dither method apply error diffusion to image",
3415 "-encoding type text encoding type",
3416 "-endian type endianness (MSB or LSB) of the image",
3417 "-family name render text with this font family",
3418 "-fill color color to use when filling a graphic primitive",
3419 "-filter type use this filter when resizing an image",
3420 "-font name render text with this font",
3421 "-format \"string\" output formatted image characteristics",
3422 "-fuzz distance colors within this distance are considered equal",
3423 "-gravity type horizontal and vertical text placement",
3424 "-green-primary point chromaticity green primary point",
3425 "-intent type type of rendering intent when managing the image color",
3426 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003427 "-interline-spacing value",
3428 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003429 "-interpolate method pixel color interpolation method",
3430 "-interword-spacing value",
3431 " set the space between two words",
3432 "-kerning value set the space between two letters",
3433 "-label string assign a label to an image",
3434 "-limit type value pixel cache resource limit",
3435 "-loop iterations add Netscape loop extension to your GIF animation",
3436 "-mask filename associate a mask with the image",
3437 "-mattecolor color frame color",
3438 "-monitor monitor progress",
3439 "-orient type image orientation",
3440 "-page geometry size and location of an image canvas (setting)",
3441 "-ping efficiently determine image attributes",
3442 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003443 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003444 "-preview type image preview type",
3445 "-quality value JPEG/MIFF/PNG compression level",
3446 "-quiet suppress all warning messages",
3447 "-red-primary point chromaticity red primary point",
3448 "-regard-warnings pay attention to warning messages",
3449 "-remap filename transform image colors to match this set of colors",
3450 "-respect-parentheses settings remain in effect until parenthesis boundary",
3451 "-sampling-factor geometry",
3452 " horizontal and vertical sampling factor",
3453 "-scene value image scene number",
3454 "-seed value seed a new sequence of pseudo-random numbers",
3455 "-size geometry width and height of image",
3456 "-stretch type render text with this font stretch",
3457 "-stroke color graphic primitive stroke color",
3458 "-strokewidth value graphic primitive stroke width",
3459 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003460 "-synchronize synchronize image to storage device",
3461 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003462 "-texture filename name of texture to tile onto the image background",
3463 "-tile-offset geometry",
3464 " tile offset",
3465 "-treedepth value color tree depth",
3466 "-transparent-color color",
3467 " transparent color",
3468 "-undercolor color annotation bounding box color",
3469 "-units type the units of image resolution",
3470 "-verbose print detailed information about the image",
3471 "-view FlashPix viewing transforms",
3472 "-virtual-pixel method",
3473 " virtual pixel access method",
3474 "-weight type render text with this font weight",
3475 "-white-point point chromaticity white point",
3476 (char *) NULL
3477 },
3478 *stack_operators[]=
3479 {
anthonyb69c4b32011-03-23 04:37:44 +00003480 "-delete indexes delete the image from the image sequence",
3481 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003482 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003483 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003484 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003485 "-swap indexes swap two images in the image sequence",
3486 (char *) NULL
3487 };
3488
3489 const char
3490 **p;
3491
cristybb503372010-05-27 20:51:26 +00003492 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003493 (void) printf("Copyright: %s\n",GetMagickCopyright());
3494 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003495 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3496 GetClientName());
3497 (void) printf("\nImage Settings:\n");
3498 for (p=settings; *p != (char *) NULL; p++)
3499 (void) printf(" %s\n",*p);
3500 (void) printf("\nImage Operators:\n");
3501 for (p=operators; *p != (char *) NULL; p++)
3502 (void) printf(" %s\n",*p);
3503 (void) printf("\nImage Sequence Operators:\n");
3504 for (p=sequence_operators; *p != (char *) NULL; p++)
3505 (void) printf(" %s\n",*p);
3506 (void) printf("\nImage Stack Operators:\n");
3507 for (p=stack_operators; *p != (char *) NULL; p++)
3508 (void) printf(" %s\n",*p);
3509 (void) printf("\nMiscellaneous Options:\n");
3510 for (p=miscellaneous; *p != (char *) NULL; p++)
3511 (void) printf(" %s\n",*p);
3512 (void) printf(
3513 "\nBy default, the image format of `file' is determined by its magic\n");
3514 (void) printf(
3515 "number. To specify a particular image format, precede the filename\n");
3516 (void) printf(
3517 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3518 (void) printf(
3519 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3520 (void) printf("'-' for standard input or output.\n");
3521 return(MagickFalse);
3522}
3523
3524WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3525 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3526{
3527#define DestroyMogrify() \
3528{ \
3529 if (format != (char *) NULL) \
3530 format=DestroyString(format); \
3531 if (path != (char *) NULL) \
3532 path=DestroyString(path); \
3533 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003534 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003535 argv[i]=DestroyString(argv[i]); \
3536 argv=(char **) RelinquishMagickMemory(argv); \
3537}
3538#define ThrowMogrifyException(asperity,tag,option) \
3539{ \
3540 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3541 option); \
3542 DestroyMogrify(); \
3543 return(MagickFalse); \
3544}
3545#define ThrowMogrifyInvalidArgumentException(option,argument) \
3546{ \
3547 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3548 "InvalidArgument","`%s': %s",argument,option); \
3549 DestroyMogrify(); \
3550 return(MagickFalse); \
3551}
3552
3553 char
3554 *format,
3555 *option,
3556 *path;
3557
3558 Image
3559 *image;
3560
3561 ImageStack
3562 image_stack[MaxImageStackDepth+1];
3563
cristy3ed852e2009-09-05 21:47:34 +00003564 MagickBooleanType
3565 global_colormap;
3566
3567 MagickBooleanType
3568 fire,
cristyebbcfea2011-02-25 02:43:54 +00003569 pend,
3570 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003571
3572 MagickStatusType
3573 status;
3574
cristyebbcfea2011-02-25 02:43:54 +00003575 register ssize_t
3576 i;
3577
3578 ssize_t
3579 j,
3580 k;
3581
cristy3ed852e2009-09-05 21:47:34 +00003582 /*
3583 Set defaults.
3584 */
3585 assert(image_info != (ImageInfo *) NULL);
3586 assert(image_info->signature == MagickSignature);
3587 if (image_info->debug != MagickFalse)
3588 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3589 assert(exception != (ExceptionInfo *) NULL);
3590 if (argc == 2)
3591 {
3592 option=argv[1];
3593 if ((LocaleCompare("version",option+1) == 0) ||
3594 (LocaleCompare("-version",option+1) == 0))
3595 {
cristyb51dff52011-05-19 16:55:47 +00003596 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003597 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003598 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3599 GetMagickCopyright());
3600 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3601 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003602 return(MagickFalse);
3603 }
3604 }
3605 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003606 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003607 format=(char *) NULL;
3608 path=(char *) NULL;
3609 global_colormap=MagickFalse;
3610 k=0;
3611 j=1;
3612 NewImageStack();
3613 option=(char *) NULL;
3614 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003615 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003616 status=MagickTrue;
3617 /*
3618 Parse command line.
3619 */
3620 ReadCommandlLine(argc,&argv);
3621 status=ExpandFilenames(&argc,&argv);
3622 if (status == MagickFalse)
3623 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3624 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003625 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003626 {
3627 option=argv[i];
3628 if (LocaleCompare(option,"(") == 0)
3629 {
3630 FireImageStack(MagickFalse,MagickTrue,pend);
3631 if (k == MaxImageStackDepth)
3632 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3633 option);
3634 PushImageStack();
3635 continue;
3636 }
3637 if (LocaleCompare(option,")") == 0)
3638 {
3639 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3640 if (k == 0)
3641 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3642 PopImageStack();
3643 continue;
3644 }
cristy042ee782011-04-22 18:48:30 +00003645 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003646 {
3647 char
3648 backup_filename[MaxTextExtent],
3649 *filename;
3650
3651 Image
3652 *images;
3653
3654 /*
3655 Option is a file name: begin by reading image from specified file.
3656 */
3657 FireImageStack(MagickFalse,MagickFalse,pend);
3658 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003659 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003660 filename=argv[++i];
3661 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3662 images=ReadImages(image_info,exception);
3663 status&=(images != (Image *) NULL) &&
3664 (exception->severity < ErrorException);
3665 if (images == (Image *) NULL)
3666 continue;
cristydaa76602010-06-30 13:05:11 +00003667 if (format != (char *) NULL)
3668 (void) CopyMagickString(images->filename,images->magick_filename,
3669 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003670 if (path != (char *) NULL)
3671 {
3672 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003673 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003674 path,*DirectorySeparator,filename);
3675 }
3676 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003677 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003678 AppendImageStack(images);
3679 FinalizeImageSettings(image_info,image,MagickFalse);
3680 if (global_colormap != MagickFalse)
3681 {
3682 QuantizeInfo
3683 *quantize_info;
3684
3685 quantize_info=AcquireQuantizeInfo(image_info);
3686 (void) RemapImages(quantize_info,images,(Image *) NULL);
3687 quantize_info=DestroyQuantizeInfo(quantize_info);
3688 }
3689 *backup_filename='\0';
3690 if ((LocaleCompare(image->filename,"-") != 0) &&
3691 (IsPathWritable(image->filename) != MagickFalse))
3692 {
cristybb503372010-05-27 20:51:26 +00003693 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003694 i;
3695
3696 /*
3697 Rename image file as backup.
3698 */
3699 (void) CopyMagickString(backup_filename,image->filename,
3700 MaxTextExtent);
3701 for (i=0; i < 6; i++)
3702 {
3703 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3704 if (IsPathAccessible(backup_filename) == MagickFalse)
3705 break;
3706 }
3707 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3708 (rename(image->filename,backup_filename) != 0))
3709 *backup_filename='\0';
3710 }
3711 /*
3712 Write transmogrified image to disk.
3713 */
3714 image_info->synchronize=MagickTrue;
3715 status&=WriteImages(image_info,image,image->filename,exception);
3716 if ((status == MagickFalse) && (*backup_filename != '\0'))
3717 (void) remove(backup_filename);
3718 RemoveAllImageStack();
3719 continue;
3720 }
3721 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3722 switch (*(option+1))
3723 {
3724 case 'a':
3725 {
3726 if (LocaleCompare("adaptive-blur",option+1) == 0)
3727 {
3728 i++;
cristybb503372010-05-27 20:51:26 +00003729 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003730 ThrowMogrifyException(OptionError,"MissingArgument",option);
3731 if (IsGeometry(argv[i]) == MagickFalse)
3732 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3733 break;
3734 }
3735 if (LocaleCompare("adaptive-resize",option+1) == 0)
3736 {
3737 i++;
cristybb503372010-05-27 20:51:26 +00003738 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003739 ThrowMogrifyException(OptionError,"MissingArgument",option);
3740 if (IsGeometry(argv[i]) == MagickFalse)
3741 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3742 break;
3743 }
3744 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3745 {
3746 i++;
cristybb503372010-05-27 20:51:26 +00003747 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003748 ThrowMogrifyException(OptionError,"MissingArgument",option);
3749 if (IsGeometry(argv[i]) == MagickFalse)
3750 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3751 break;
3752 }
3753 if (LocaleCompare("affine",option+1) == 0)
3754 {
3755 if (*option == '+')
3756 break;
3757 i++;
cristybb503372010-05-27 20:51:26 +00003758 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003759 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003760 break;
3761 }
3762 if (LocaleCompare("alpha",option+1) == 0)
3763 {
cristybb503372010-05-27 20:51:26 +00003764 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003765 type;
3766
3767 if (*option == '+')
3768 break;
3769 i++;
cristybb503372010-05-27 20:51:26 +00003770 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003771 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003772 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003773 if (type < 0)
3774 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3775 argv[i]);
3776 break;
3777 }
3778 if (LocaleCompare("annotate",option+1) == 0)
3779 {
3780 if (*option == '+')
3781 break;
3782 i++;
cristybb503372010-05-27 20:51:26 +00003783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003784 ThrowMogrifyException(OptionError,"MissingArgument",option);
3785 if (IsGeometry(argv[i]) == MagickFalse)
3786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003787 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003788 ThrowMogrifyException(OptionError,"MissingArgument",option);
3789 i++;
3790 break;
3791 }
3792 if (LocaleCompare("antialias",option+1) == 0)
3793 break;
3794 if (LocaleCompare("append",option+1) == 0)
3795 break;
3796 if (LocaleCompare("attenuate",option+1) == 0)
3797 {
3798 if (*option == '+')
3799 break;
3800 i++;
cristybb503372010-05-27 20:51:26 +00003801 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003802 ThrowMogrifyException(OptionError,"MissingArgument",option);
3803 if (IsGeometry(argv[i]) == MagickFalse)
3804 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3805 break;
3806 }
3807 if (LocaleCompare("authenticate",option+1) == 0)
3808 {
3809 if (*option == '+')
3810 break;
3811 i++;
cristybb503372010-05-27 20:51:26 +00003812 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003813 ThrowMogrifyException(OptionError,"MissingArgument",option);
3814 break;
3815 }
3816 if (LocaleCompare("auto-gamma",option+1) == 0)
3817 break;
3818 if (LocaleCompare("auto-level",option+1) == 0)
3819 break;
3820 if (LocaleCompare("auto-orient",option+1) == 0)
3821 break;
3822 if (LocaleCompare("average",option+1) == 0)
3823 break;
3824 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3825 }
3826 case 'b':
3827 {
3828 if (LocaleCompare("background",option+1) == 0)
3829 {
3830 if (*option == '+')
3831 break;
3832 i++;
cristybb503372010-05-27 20:51:26 +00003833 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003834 ThrowMogrifyException(OptionError,"MissingArgument",option);
3835 break;
3836 }
3837 if (LocaleCompare("bias",option+1) == 0)
3838 {
3839 if (*option == '+')
3840 break;
3841 i++;
cristybb503372010-05-27 20:51:26 +00003842 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003843 ThrowMogrifyException(OptionError,"MissingArgument",option);
3844 if (IsGeometry(argv[i]) == MagickFalse)
3845 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3846 break;
3847 }
3848 if (LocaleCompare("black-point-compensation",option+1) == 0)
3849 break;
3850 if (LocaleCompare("black-threshold",option+1) == 0)
3851 {
3852 if (*option == '+')
3853 break;
3854 i++;
cristybb503372010-05-27 20:51:26 +00003855 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003856 ThrowMogrifyException(OptionError,"MissingArgument",option);
3857 if (IsGeometry(argv[i]) == MagickFalse)
3858 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3859 break;
3860 }
3861 if (LocaleCompare("blue-primary",option+1) == 0)
3862 {
3863 if (*option == '+')
3864 break;
3865 i++;
cristybb503372010-05-27 20:51:26 +00003866 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003867 ThrowMogrifyException(OptionError,"MissingArgument",option);
3868 if (IsGeometry(argv[i]) == MagickFalse)
3869 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3870 break;
3871 }
3872 if (LocaleCompare("blue-shift",option+1) == 0)
3873 {
3874 i++;
cristybb503372010-05-27 20:51:26 +00003875 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003876 ThrowMogrifyException(OptionError,"MissingArgument",option);
3877 if (IsGeometry(argv[i]) == MagickFalse)
3878 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3879 break;
3880 }
3881 if (LocaleCompare("blur",option+1) == 0)
3882 {
3883 i++;
cristybb503372010-05-27 20:51:26 +00003884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003885 ThrowMogrifyException(OptionError,"MissingArgument",option);
3886 if (IsGeometry(argv[i]) == MagickFalse)
3887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3888 break;
3889 }
3890 if (LocaleCompare("border",option+1) == 0)
3891 {
3892 if (*option == '+')
3893 break;
3894 i++;
cristybb503372010-05-27 20:51:26 +00003895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003896 ThrowMogrifyException(OptionError,"MissingArgument",option);
3897 if (IsGeometry(argv[i]) == MagickFalse)
3898 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3899 break;
3900 }
3901 if (LocaleCompare("bordercolor",option+1) == 0)
3902 {
3903 if (*option == '+')
3904 break;
3905 i++;
cristybb503372010-05-27 20:51:26 +00003906 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003907 ThrowMogrifyException(OptionError,"MissingArgument",option);
3908 break;
3909 }
3910 if (LocaleCompare("box",option+1) == 0)
3911 {
3912 if (*option == '+')
3913 break;
3914 i++;
cristybb503372010-05-27 20:51:26 +00003915 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003916 ThrowMogrifyException(OptionError,"MissingArgument",option);
3917 break;
3918 }
cristya28d6b82010-01-11 20:03:47 +00003919 if (LocaleCompare("brightness-contrast",option+1) == 0)
3920 {
3921 i++;
cristybb503372010-05-27 20:51:26 +00003922 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003923 ThrowMogrifyException(OptionError,"MissingArgument",option);
3924 if (IsGeometry(argv[i]) == MagickFalse)
3925 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3926 break;
3927 }
cristy3ed852e2009-09-05 21:47:34 +00003928 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3929 }
3930 case 'c':
3931 {
3932 if (LocaleCompare("cache",option+1) == 0)
3933 {
3934 if (*option == '+')
3935 break;
3936 i++;
cristybb503372010-05-27 20:51:26 +00003937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003938 ThrowMogrifyException(OptionError,"MissingArgument",option);
3939 if (IsGeometry(argv[i]) == MagickFalse)
3940 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3941 break;
3942 }
3943 if (LocaleCompare("caption",option+1) == 0)
3944 {
3945 if (*option == '+')
3946 break;
3947 i++;
cristybb503372010-05-27 20:51:26 +00003948 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003949 ThrowMogrifyException(OptionError,"MissingArgument",option);
3950 break;
3951 }
3952 if (LocaleCompare("channel",option+1) == 0)
3953 {
cristybb503372010-05-27 20:51:26 +00003954 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003955 channel;
3956
3957 if (*option == '+')
3958 break;
3959 i++;
cristybb503372010-05-27 20:51:26 +00003960 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003961 ThrowMogrifyException(OptionError,"MissingArgument",option);
3962 channel=ParseChannelOption(argv[i]);
3963 if (channel < 0)
3964 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
3965 argv[i]);
3966 break;
3967 }
3968 if (LocaleCompare("cdl",option+1) == 0)
3969 {
3970 if (*option == '+')
3971 break;
3972 i++;
cristybb503372010-05-27 20:51:26 +00003973 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003974 ThrowMogrifyException(OptionError,"MissingArgument",option);
3975 break;
3976 }
3977 if (LocaleCompare("charcoal",option+1) == 0)
3978 {
3979 if (*option == '+')
3980 break;
3981 i++;
cristybb503372010-05-27 20:51:26 +00003982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003983 ThrowMogrifyException(OptionError,"MissingArgument",option);
3984 if (IsGeometry(argv[i]) == MagickFalse)
3985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3986 break;
3987 }
3988 if (LocaleCompare("chop",option+1) == 0)
3989 {
3990 if (*option == '+')
3991 break;
3992 i++;
cristybb503372010-05-27 20:51:26 +00003993 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003994 ThrowMogrifyException(OptionError,"MissingArgument",option);
3995 if (IsGeometry(argv[i]) == MagickFalse)
3996 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3997 break;
3998 }
cristy1eb45dd2009-09-25 16:38:06 +00003999 if (LocaleCompare("clamp",option+1) == 0)
4000 break;
4001 if (LocaleCompare("clip",option+1) == 0)
4002 break;
cristy3ed852e2009-09-05 21:47:34 +00004003 if (LocaleCompare("clip-mask",option+1) == 0)
4004 {
4005 if (*option == '+')
4006 break;
4007 i++;
cristybb503372010-05-27 20:51:26 +00004008 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004009 ThrowMogrifyException(OptionError,"MissingArgument",option);
4010 break;
4011 }
4012 if (LocaleCompare("clut",option+1) == 0)
4013 break;
4014 if (LocaleCompare("coalesce",option+1) == 0)
4015 break;
4016 if (LocaleCompare("colorize",option+1) == 0)
4017 {
4018 if (*option == '+')
4019 break;
4020 i++;
cristybb503372010-05-27 20:51:26 +00004021 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004022 ThrowMogrifyException(OptionError,"MissingArgument",option);
4023 if (IsGeometry(argv[i]) == MagickFalse)
4024 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4025 break;
4026 }
cristye6365592010-04-02 17:31:23 +00004027 if (LocaleCompare("color-matrix",option+1) == 0)
4028 {
cristyb6bd4ad2010-08-08 01:12:27 +00004029 KernelInfo
4030 *kernel_info;
4031
cristye6365592010-04-02 17:31:23 +00004032 if (*option == '+')
4033 break;
4034 i++;
cristybb503372010-05-27 20:51:26 +00004035 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004036 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004037 kernel_info=AcquireKernelInfo(argv[i]);
4038 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004039 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004040 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004041 break;
4042 }
cristy3ed852e2009-09-05 21:47:34 +00004043 if (LocaleCompare("colors",option+1) == 0)
4044 {
4045 if (*option == '+')
4046 break;
4047 i++;
cristybb503372010-05-27 20:51:26 +00004048 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004049 ThrowMogrifyException(OptionError,"MissingArgument",option);
4050 if (IsGeometry(argv[i]) == MagickFalse)
4051 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4052 break;
4053 }
4054 if (LocaleCompare("colorspace",option+1) == 0)
4055 {
cristybb503372010-05-27 20:51:26 +00004056 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004057 colorspace;
4058
4059 if (*option == '+')
4060 break;
4061 i++;
cristybb503372010-05-27 20:51:26 +00004062 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004063 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004064 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004065 argv[i]);
4066 if (colorspace < 0)
4067 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4068 argv[i]);
4069 break;
4070 }
4071 if (LocaleCompare("combine",option+1) == 0)
4072 break;
4073 if (LocaleCompare("comment",option+1) == 0)
4074 {
4075 if (*option == '+')
4076 break;
4077 i++;
cristybb503372010-05-27 20:51:26 +00004078 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004079 ThrowMogrifyException(OptionError,"MissingArgument",option);
4080 break;
4081 }
4082 if (LocaleCompare("composite",option+1) == 0)
4083 break;
4084 if (LocaleCompare("compress",option+1) == 0)
4085 {
cristybb503372010-05-27 20:51:26 +00004086 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004087 compress;
4088
4089 if (*option == '+')
4090 break;
4091 i++;
cristybb503372010-05-27 20:51:26 +00004092 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004093 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004094 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004095 argv[i]);
4096 if (compress < 0)
4097 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4098 argv[i]);
4099 break;
4100 }
cristy22879752009-10-25 23:55:40 +00004101 if (LocaleCompare("concurrent",option+1) == 0)
4102 break;
cristy3ed852e2009-09-05 21:47:34 +00004103 if (LocaleCompare("contrast",option+1) == 0)
4104 break;
4105 if (LocaleCompare("contrast-stretch",option+1) == 0)
4106 {
4107 i++;
cristybb503372010-05-27 20:51:26 +00004108 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004109 ThrowMogrifyException(OptionError,"MissingArgument",option);
4110 if (IsGeometry(argv[i]) == MagickFalse)
4111 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4112 break;
4113 }
4114 if (LocaleCompare("convolve",option+1) == 0)
4115 {
cristyb6bd4ad2010-08-08 01:12:27 +00004116 KernelInfo
4117 *kernel_info;
4118
cristy3ed852e2009-09-05 21:47:34 +00004119 if (*option == '+')
4120 break;
4121 i++;
cristybb503372010-05-27 20:51:26 +00004122 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004123 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004124 kernel_info=AcquireKernelInfo(argv[i]);
4125 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004126 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004127 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004128 break;
4129 }
4130 if (LocaleCompare("crop",option+1) == 0)
4131 {
4132 if (*option == '+')
4133 break;
4134 i++;
cristybb503372010-05-27 20:51:26 +00004135 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004136 ThrowMogrifyException(OptionError,"MissingArgument",option);
4137 if (IsGeometry(argv[i]) == MagickFalse)
4138 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4139 break;
4140 }
4141 if (LocaleCompare("cycle",option+1) == 0)
4142 {
4143 if (*option == '+')
4144 break;
4145 i++;
cristybb503372010-05-27 20:51:26 +00004146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004147 ThrowMogrifyException(OptionError,"MissingArgument",option);
4148 if (IsGeometry(argv[i]) == MagickFalse)
4149 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4150 break;
4151 }
4152 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4153 }
4154 case 'd':
4155 {
4156 if (LocaleCompare("decipher",option+1) == 0)
4157 {
4158 if (*option == '+')
4159 break;
4160 i++;
cristybb503372010-05-27 20:51:26 +00004161 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004162 ThrowMogrifyException(OptionError,"MissingArgument",option);
4163 break;
4164 }
4165 if (LocaleCompare("deconstruct",option+1) == 0)
4166 break;
4167 if (LocaleCompare("debug",option+1) == 0)
4168 {
cristybb503372010-05-27 20:51:26 +00004169 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004170 event;
4171
4172 if (*option == '+')
4173 break;
4174 i++;
cristybb503372010-05-27 20:51:26 +00004175 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004176 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004177 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004178 if (event < 0)
4179 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4180 argv[i]);
4181 (void) SetLogEventMask(argv[i]);
4182 break;
4183 }
4184 if (LocaleCompare("define",option+1) == 0)
4185 {
4186 i++;
cristybb503372010-05-27 20:51:26 +00004187 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004188 ThrowMogrifyException(OptionError,"MissingArgument",option);
4189 if (*option == '+')
4190 {
4191 const char
4192 *define;
4193
4194 define=GetImageOption(image_info,argv[i]);
4195 if (define == (const char *) NULL)
4196 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4197 break;
4198 }
4199 break;
4200 }
4201 if (LocaleCompare("delay",option+1) == 0)
4202 {
4203 if (*option == '+')
4204 break;
4205 i++;
cristybb503372010-05-27 20:51:26 +00004206 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004207 ThrowMogrifyException(OptionError,"MissingArgument",option);
4208 if (IsGeometry(argv[i]) == MagickFalse)
4209 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4210 break;
4211 }
cristyecb10ff2011-03-22 13:14:03 +00004212 if (LocaleCompare("delete",option+1) == 0)
4213 {
4214 if (*option == '+')
4215 break;
4216 i++;
4217 if (i == (ssize_t) (argc-1))
4218 ThrowMogrifyException(OptionError,"MissingArgument",option);
4219 if (IsGeometry(argv[i]) == MagickFalse)
4220 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4221 break;
4222 }
cristy3ed852e2009-09-05 21:47:34 +00004223 if (LocaleCompare("density",option+1) == 0)
4224 {
4225 if (*option == '+')
4226 break;
4227 i++;
cristybb503372010-05-27 20:51:26 +00004228 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004229 ThrowMogrifyException(OptionError,"MissingArgument",option);
4230 if (IsGeometry(argv[i]) == MagickFalse)
4231 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4232 break;
4233 }
4234 if (LocaleCompare("depth",option+1) == 0)
4235 {
4236 if (*option == '+')
4237 break;
4238 i++;
cristybb503372010-05-27 20:51:26 +00004239 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004240 ThrowMogrifyException(OptionError,"MissingArgument",option);
4241 if (IsGeometry(argv[i]) == MagickFalse)
4242 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4243 break;
4244 }
4245 if (LocaleCompare("deskew",option+1) == 0)
4246 {
4247 if (*option == '+')
4248 break;
4249 i++;
cristybb503372010-05-27 20:51:26 +00004250 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004251 ThrowMogrifyException(OptionError,"MissingArgument",option);
4252 if (IsGeometry(argv[i]) == MagickFalse)
4253 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4254 break;
4255 }
4256 if (LocaleCompare("despeckle",option+1) == 0)
4257 break;
4258 if (LocaleCompare("dft",option+1) == 0)
4259 break;
cristyc9b12952010-03-28 01:12:28 +00004260 if (LocaleCompare("direction",option+1) == 0)
4261 {
cristybb503372010-05-27 20:51:26 +00004262 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004263 direction;
4264
4265 if (*option == '+')
4266 break;
4267 i++;
cristybb503372010-05-27 20:51:26 +00004268 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004269 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004270 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004271 argv[i]);
4272 if (direction < 0)
4273 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4274 argv[i]);
4275 break;
4276 }
cristy3ed852e2009-09-05 21:47:34 +00004277 if (LocaleCompare("display",option+1) == 0)
4278 {
4279 if (*option == '+')
4280 break;
4281 i++;
cristybb503372010-05-27 20:51:26 +00004282 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004283 ThrowMogrifyException(OptionError,"MissingArgument",option);
4284 break;
4285 }
4286 if (LocaleCompare("dispose",option+1) == 0)
4287 {
cristybb503372010-05-27 20:51:26 +00004288 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004289 dispose;
4290
4291 if (*option == '+')
4292 break;
4293 i++;
cristybb503372010-05-27 20:51:26 +00004294 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004295 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004296 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004297 if (dispose < 0)
4298 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4299 argv[i]);
4300 break;
4301 }
4302 if (LocaleCompare("distort",option+1) == 0)
4303 {
cristybb503372010-05-27 20:51:26 +00004304 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004305 op;
4306
4307 i++;
cristybb503372010-05-27 20:51:26 +00004308 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004309 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004310 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004311 if (op < 0)
4312 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4313 argv[i]);
4314 i++;
cristybb503372010-05-27 20:51:26 +00004315 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004316 ThrowMogrifyException(OptionError,"MissingArgument",option);
4317 break;
4318 }
4319 if (LocaleCompare("dither",option+1) == 0)
4320 {
cristybb503372010-05-27 20:51:26 +00004321 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004322 method;
4323
4324 if (*option == '+')
4325 break;
4326 i++;
cristybb503372010-05-27 20:51:26 +00004327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004328 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004329 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004330 if (method < 0)
4331 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4332 argv[i]);
4333 break;
4334 }
4335 if (LocaleCompare("draw",option+1) == 0)
4336 {
4337 if (*option == '+')
4338 break;
4339 i++;
cristybb503372010-05-27 20:51:26 +00004340 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004341 ThrowMogrifyException(OptionError,"MissingArgument",option);
4342 break;
4343 }
cristyecb10ff2011-03-22 13:14:03 +00004344 if (LocaleCompare("duplicate",option+1) == 0)
4345 {
4346 if (*option == '+')
4347 break;
4348 i++;
4349 if (i == (ssize_t) (argc-1))
4350 ThrowMogrifyException(OptionError,"MissingArgument",option);
4351 if (IsGeometry(argv[i]) == MagickFalse)
4352 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4353 break;
4354 }
cristy22879752009-10-25 23:55:40 +00004355 if (LocaleCompare("duration",option+1) == 0)
4356 {
4357 if (*option == '+')
4358 break;
4359 i++;
cristybb503372010-05-27 20:51:26 +00004360 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004361 ThrowMogrifyException(OptionError,"MissingArgument",option);
4362 if (IsGeometry(argv[i]) == MagickFalse)
4363 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4364 break;
4365 }
cristy3ed852e2009-09-05 21:47:34 +00004366 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4367 }
4368 case 'e':
4369 {
4370 if (LocaleCompare("edge",option+1) == 0)
4371 {
4372 if (*option == '+')
4373 break;
4374 i++;
cristybb503372010-05-27 20:51:26 +00004375 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004376 ThrowMogrifyException(OptionError,"MissingArgument",option);
4377 if (IsGeometry(argv[i]) == MagickFalse)
4378 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4379 break;
4380 }
4381 if (LocaleCompare("emboss",option+1) == 0)
4382 {
4383 if (*option == '+')
4384 break;
4385 i++;
cristybb503372010-05-27 20:51:26 +00004386 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004387 ThrowMogrifyException(OptionError,"MissingArgument",option);
4388 if (IsGeometry(argv[i]) == MagickFalse)
4389 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4390 break;
4391 }
4392 if (LocaleCompare("encipher",option+1) == 0)
4393 {
4394 if (*option == '+')
4395 break;
4396 i++;
cristybb503372010-05-27 20:51:26 +00004397 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004398 ThrowMogrifyException(OptionError,"MissingArgument",option);
4399 break;
4400 }
4401 if (LocaleCompare("encoding",option+1) == 0)
4402 {
4403 if (*option == '+')
4404 break;
4405 i++;
cristybb503372010-05-27 20:51:26 +00004406 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004407 ThrowMogrifyException(OptionError,"MissingArgument",option);
4408 break;
4409 }
4410 if (LocaleCompare("endian",option+1) == 0)
4411 {
cristybb503372010-05-27 20:51:26 +00004412 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004413 endian;
4414
4415 if (*option == '+')
4416 break;
4417 i++;
cristybb503372010-05-27 20:51:26 +00004418 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004419 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004420 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004421 if (endian < 0)
4422 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4423 argv[i]);
4424 break;
4425 }
4426 if (LocaleCompare("enhance",option+1) == 0)
4427 break;
4428 if (LocaleCompare("equalize",option+1) == 0)
4429 break;
4430 if (LocaleCompare("evaluate",option+1) == 0)
4431 {
cristybb503372010-05-27 20:51:26 +00004432 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004433 op;
4434
4435 if (*option == '+')
4436 break;
4437 i++;
cristybb503372010-05-27 20:51:26 +00004438 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004439 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004440 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004441 if (op < 0)
4442 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4443 argv[i]);
4444 i++;
cristybb503372010-05-27 20:51:26 +00004445 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004446 ThrowMogrifyException(OptionError,"MissingArgument",option);
4447 if (IsGeometry(argv[i]) == MagickFalse)
4448 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4449 break;
4450 }
cristyd18ae7c2010-03-07 17:39:52 +00004451 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4452 {
cristybb503372010-05-27 20:51:26 +00004453 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004454 op;
4455
4456 if (*option == '+')
4457 break;
4458 i++;
cristybb503372010-05-27 20:51:26 +00004459 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004460 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004461 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004462 if (op < 0)
4463 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4464 argv[i]);
4465 break;
4466 }
cristy3ed852e2009-09-05 21:47:34 +00004467 if (LocaleCompare("extent",option+1) == 0)
4468 {
4469 if (*option == '+')
4470 break;
4471 i++;
cristybb503372010-05-27 20:51:26 +00004472 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004473 ThrowMogrifyException(OptionError,"MissingArgument",option);
4474 if (IsGeometry(argv[i]) == MagickFalse)
4475 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4476 break;
4477 }
4478 if (LocaleCompare("extract",option+1) == 0)
4479 {
4480 if (*option == '+')
4481 break;
4482 i++;
cristybb503372010-05-27 20:51:26 +00004483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004484 ThrowMogrifyException(OptionError,"MissingArgument",option);
4485 if (IsGeometry(argv[i]) == MagickFalse)
4486 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4487 break;
4488 }
4489 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4490 }
4491 case 'f':
4492 {
4493 if (LocaleCompare("family",option+1) == 0)
4494 {
4495 if (*option == '+')
4496 break;
4497 i++;
cristybb503372010-05-27 20:51:26 +00004498 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004499 ThrowMogrifyException(OptionError,"MissingArgument",option);
4500 break;
4501 }
4502 if (LocaleCompare("fill",option+1) == 0)
4503 {
4504 if (*option == '+')
4505 break;
4506 i++;
cristybb503372010-05-27 20:51:26 +00004507 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004508 ThrowMogrifyException(OptionError,"MissingArgument",option);
4509 break;
4510 }
4511 if (LocaleCompare("filter",option+1) == 0)
4512 {
cristybb503372010-05-27 20:51:26 +00004513 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004514 filter;
4515
4516 if (*option == '+')
4517 break;
4518 i++;
cristybb503372010-05-27 20:51:26 +00004519 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004520 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004521 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004522 if (filter < 0)
4523 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4524 argv[i]);
4525 break;
4526 }
4527 if (LocaleCompare("flatten",option+1) == 0)
4528 break;
4529 if (LocaleCompare("flip",option+1) == 0)
4530 break;
4531 if (LocaleCompare("flop",option+1) == 0)
4532 break;
4533 if (LocaleCompare("floodfill",option+1) == 0)
4534 {
4535 if (*option == '+')
4536 break;
4537 i++;
cristybb503372010-05-27 20:51:26 +00004538 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004539 ThrowMogrifyException(OptionError,"MissingArgument",option);
4540 if (IsGeometry(argv[i]) == MagickFalse)
4541 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4542 i++;
cristybb503372010-05-27 20:51:26 +00004543 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004544 ThrowMogrifyException(OptionError,"MissingArgument",option);
4545 break;
4546 }
4547 if (LocaleCompare("font",option+1) == 0)
4548 {
4549 if (*option == '+')
4550 break;
4551 i++;
cristybb503372010-05-27 20:51:26 +00004552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004553 ThrowMogrifyException(OptionError,"MissingArgument",option);
4554 break;
4555 }
4556 if (LocaleCompare("format",option+1) == 0)
4557 {
4558 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4559 (void) CloneString(&format,(char *) NULL);
4560 if (*option == '+')
4561 break;
4562 i++;
cristybb503372010-05-27 20:51:26 +00004563 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004564 ThrowMogrifyException(OptionError,"MissingArgument",option);
4565 (void) CloneString(&format,argv[i]);
4566 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4567 (void) ConcatenateMagickString(image_info->filename,":",
4568 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004569 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004570 if (*image_info->magick == '\0')
4571 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4572 format);
4573 break;
4574 }
4575 if (LocaleCompare("frame",option+1) == 0)
4576 {
4577 if (*option == '+')
4578 break;
4579 i++;
cristybb503372010-05-27 20:51:26 +00004580 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004581 ThrowMogrifyException(OptionError,"MissingArgument",option);
4582 if (IsGeometry(argv[i]) == MagickFalse)
4583 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4584 break;
4585 }
4586 if (LocaleCompare("function",option+1) == 0)
4587 {
cristybb503372010-05-27 20:51:26 +00004588 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004589 op;
4590
4591 if (*option == '+')
4592 break;
4593 i++;
cristybb503372010-05-27 20:51:26 +00004594 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004595 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004596 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004597 if (op < 0)
4598 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4599 i++;
cristybb503372010-05-27 20:51:26 +00004600 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004601 ThrowMogrifyException(OptionError,"MissingArgument",option);
4602 break;
4603 }
4604 if (LocaleCompare("fuzz",option+1) == 0)
4605 {
4606 if (*option == '+')
4607 break;
4608 i++;
cristybb503372010-05-27 20:51:26 +00004609 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004610 ThrowMogrifyException(OptionError,"MissingArgument",option);
4611 if (IsGeometry(argv[i]) == MagickFalse)
4612 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4613 break;
4614 }
4615 if (LocaleCompare("fx",option+1) == 0)
4616 {
4617 if (*option == '+')
4618 break;
4619 i++;
cristybb503372010-05-27 20:51:26 +00004620 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004621 ThrowMogrifyException(OptionError,"MissingArgument",option);
4622 break;
4623 }
4624 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4625 }
4626 case 'g':
4627 {
4628 if (LocaleCompare("gamma",option+1) == 0)
4629 {
4630 i++;
cristybb503372010-05-27 20:51:26 +00004631 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004632 ThrowMogrifyException(OptionError,"MissingArgument",option);
4633 if (IsGeometry(argv[i]) == MagickFalse)
4634 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4635 break;
4636 }
4637 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4638 (LocaleCompare("gaussian",option+1) == 0))
4639 {
4640 i++;
cristybb503372010-05-27 20:51:26 +00004641 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004642 ThrowMogrifyException(OptionError,"MissingArgument",option);
4643 if (IsGeometry(argv[i]) == MagickFalse)
4644 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4645 break;
4646 }
4647 if (LocaleCompare("geometry",option+1) == 0)
4648 {
4649 if (*option == '+')
4650 break;
4651 i++;
cristybb503372010-05-27 20:51:26 +00004652 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004653 ThrowMogrifyException(OptionError,"MissingArgument",option);
4654 if (IsGeometry(argv[i]) == MagickFalse)
4655 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4656 break;
4657 }
4658 if (LocaleCompare("gravity",option+1) == 0)
4659 {
cristybb503372010-05-27 20:51:26 +00004660 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004661 gravity;
4662
4663 if (*option == '+')
4664 break;
4665 i++;
cristybb503372010-05-27 20:51:26 +00004666 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004667 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004668 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004669 if (gravity < 0)
4670 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4671 argv[i]);
4672 break;
4673 }
4674 if (LocaleCompare("green-primary",option+1) == 0)
4675 {
4676 if (*option == '+')
4677 break;
4678 i++;
cristybb503372010-05-27 20:51:26 +00004679 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004680 ThrowMogrifyException(OptionError,"MissingArgument",option);
4681 if (IsGeometry(argv[i]) == MagickFalse)
4682 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4683 break;
4684 }
4685 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4686 }
4687 case 'h':
4688 {
4689 if (LocaleCompare("hald-clut",option+1) == 0)
4690 break;
4691 if ((LocaleCompare("help",option+1) == 0) ||
4692 (LocaleCompare("-help",option+1) == 0))
4693 return(MogrifyUsage());
4694 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4695 }
4696 case 'i':
4697 {
4698 if (LocaleCompare("identify",option+1) == 0)
4699 break;
4700 if (LocaleCompare("idft",option+1) == 0)
4701 break;
4702 if (LocaleCompare("implode",option+1) == 0)
4703 {
4704 if (*option == '+')
4705 break;
4706 i++;
cristybb503372010-05-27 20:51:26 +00004707 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004708 ThrowMogrifyException(OptionError,"MissingArgument",option);
4709 if (IsGeometry(argv[i]) == MagickFalse)
4710 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4711 break;
4712 }
4713 if (LocaleCompare("intent",option+1) == 0)
4714 {
cristybb503372010-05-27 20:51:26 +00004715 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004716 intent;
4717
4718 if (*option == '+')
4719 break;
4720 i++;
cristybb503372010-05-27 20:51:26 +00004721 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004722 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004723 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004724 if (intent < 0)
4725 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4726 argv[i]);
4727 break;
4728 }
4729 if (LocaleCompare("interlace",option+1) == 0)
4730 {
cristybb503372010-05-27 20:51:26 +00004731 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004732 interlace;
4733
4734 if (*option == '+')
4735 break;
4736 i++;
cristybb503372010-05-27 20:51:26 +00004737 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004738 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004739 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004740 argv[i]);
4741 if (interlace < 0)
4742 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4743 argv[i]);
4744 break;
4745 }
cristyb32b90a2009-09-07 21:45:48 +00004746 if (LocaleCompare("interline-spacing",option+1) == 0)
4747 {
4748 if (*option == '+')
4749 break;
4750 i++;
cristybb503372010-05-27 20:51:26 +00004751 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004752 ThrowMogrifyException(OptionError,"MissingArgument",option);
4753 if (IsGeometry(argv[i]) == MagickFalse)
4754 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4755 break;
4756 }
cristy3ed852e2009-09-05 21:47:34 +00004757 if (LocaleCompare("interpolate",option+1) == 0)
4758 {
cristybb503372010-05-27 20:51:26 +00004759 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004760 interpolate;
4761
4762 if (*option == '+')
4763 break;
4764 i++;
cristybb503372010-05-27 20:51:26 +00004765 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004766 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004767 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004768 argv[i]);
4769 if (interpolate < 0)
4770 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4771 argv[i]);
4772 break;
4773 }
4774 if (LocaleCompare("interword-spacing",option+1) == 0)
4775 {
4776 if (*option == '+')
4777 break;
4778 i++;
cristybb503372010-05-27 20:51:26 +00004779 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004780 ThrowMogrifyException(OptionError,"MissingArgument",option);
4781 if (IsGeometry(argv[i]) == MagickFalse)
4782 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4783 break;
4784 }
4785 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4786 }
4787 case 'k':
4788 {
4789 if (LocaleCompare("kerning",option+1) == 0)
4790 {
4791 if (*option == '+')
4792 break;
4793 i++;
cristybb503372010-05-27 20:51:26 +00004794 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004795 ThrowMogrifyException(OptionError,"MissingArgument",option);
4796 if (IsGeometry(argv[i]) == MagickFalse)
4797 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4798 break;
4799 }
4800 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4801 }
4802 case 'l':
4803 {
4804 if (LocaleCompare("label",option+1) == 0)
4805 {
4806 if (*option == '+')
4807 break;
4808 i++;
cristybb503372010-05-27 20:51:26 +00004809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004810 ThrowMogrifyException(OptionError,"MissingArgument",option);
4811 break;
4812 }
4813 if (LocaleCompare("lat",option+1) == 0)
4814 {
4815 if (*option == '+')
4816 break;
4817 i++;
cristybb503372010-05-27 20:51:26 +00004818 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004819 ThrowMogrifyException(OptionError,"MissingArgument",option);
4820 if (IsGeometry(argv[i]) == MagickFalse)
4821 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4822 }
4823 if (LocaleCompare("layers",option+1) == 0)
4824 {
cristybb503372010-05-27 20:51:26 +00004825 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004826 type;
4827
4828 if (*option == '+')
4829 break;
4830 i++;
cristybb503372010-05-27 20:51:26 +00004831 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004832 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004833 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004834 if (type < 0)
4835 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4836 argv[i]);
4837 break;
4838 }
4839 if (LocaleCompare("level",option+1) == 0)
4840 {
4841 i++;
cristybb503372010-05-27 20:51:26 +00004842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004843 ThrowMogrifyException(OptionError,"MissingArgument",option);
4844 if (IsGeometry(argv[i]) == MagickFalse)
4845 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4846 break;
4847 }
4848 if (LocaleCompare("level-colors",option+1) == 0)
4849 {
4850 i++;
cristybb503372010-05-27 20:51:26 +00004851 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004852 ThrowMogrifyException(OptionError,"MissingArgument",option);
4853 break;
4854 }
4855 if (LocaleCompare("linewidth",option+1) == 0)
4856 {
4857 if (*option == '+')
4858 break;
4859 i++;
cristybb503372010-05-27 20:51:26 +00004860 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004861 ThrowMogrifyException(OptionError,"MissingArgument",option);
4862 if (IsGeometry(argv[i]) == MagickFalse)
4863 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4864 break;
4865 }
4866 if (LocaleCompare("limit",option+1) == 0)
4867 {
4868 char
4869 *p;
4870
4871 double
4872 value;
4873
cristybb503372010-05-27 20:51:26 +00004874 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004875 resource;
4876
4877 if (*option == '+')
4878 break;
4879 i++;
cristybb503372010-05-27 20:51:26 +00004880 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004881 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004882 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004883 argv[i]);
4884 if (resource < 0)
4885 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4886 argv[i]);
4887 i++;
cristybb503372010-05-27 20:51:26 +00004888 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004889 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyc1acd842011-05-19 23:05:47 +00004890 value=InterpretLocaleValue(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004891 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004892 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4893 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4894 break;
4895 }
4896 if (LocaleCompare("liquid-rescale",option+1) == 0)
4897 {
4898 i++;
cristybb503372010-05-27 20:51:26 +00004899 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004900 ThrowMogrifyException(OptionError,"MissingArgument",option);
4901 if (IsGeometry(argv[i]) == MagickFalse)
4902 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4903 break;
4904 }
4905 if (LocaleCompare("list",option+1) == 0)
4906 {
cristybb503372010-05-27 20:51:26 +00004907 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004908 list;
4909
4910 if (*option == '+')
4911 break;
4912 i++;
cristybb503372010-05-27 20:51:26 +00004913 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004914 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004915 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004916 if (list < 0)
4917 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004918 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004919 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004920 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004921 }
4922 if (LocaleCompare("log",option+1) == 0)
4923 {
4924 if (*option == '+')
4925 break;
4926 i++;
cristybb503372010-05-27 20:51:26 +00004927 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004928 (strchr(argv[i],'%') == (char *) NULL))
4929 ThrowMogrifyException(OptionError,"MissingArgument",option);
4930 break;
4931 }
4932 if (LocaleCompare("loop",option+1) == 0)
4933 {
4934 if (*option == '+')
4935 break;
4936 i++;
cristybb503372010-05-27 20:51:26 +00004937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004938 ThrowMogrifyException(OptionError,"MissingArgument",option);
4939 if (IsGeometry(argv[i]) == MagickFalse)
4940 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4941 break;
4942 }
4943 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4944 }
4945 case 'm':
4946 {
4947 if (LocaleCompare("map",option+1) == 0)
4948 {
4949 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4950 if (*option == '+')
4951 break;
4952 i++;
cristybb503372010-05-27 20:51:26 +00004953 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004954 ThrowMogrifyException(OptionError,"MissingArgument",option);
4955 break;
4956 }
4957 if (LocaleCompare("mask",option+1) == 0)
4958 {
4959 if (*option == '+')
4960 break;
4961 i++;
cristybb503372010-05-27 20:51:26 +00004962 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004963 ThrowMogrifyException(OptionError,"MissingArgument",option);
4964 break;
4965 }
4966 if (LocaleCompare("matte",option+1) == 0)
4967 break;
4968 if (LocaleCompare("mattecolor",option+1) == 0)
4969 {
4970 if (*option == '+')
4971 break;
4972 i++;
cristybb503372010-05-27 20:51:26 +00004973 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004974 ThrowMogrifyException(OptionError,"MissingArgument",option);
4975 break;
4976 }
cristyf40785b2010-03-06 02:27:27 +00004977 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004978 break;
cristyf40785b2010-03-06 02:27:27 +00004979 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00004980 break;
cristy3ed852e2009-09-05 21:47:34 +00004981 if (LocaleCompare("modulate",option+1) == 0)
4982 {
4983 if (*option == '+')
4984 break;
4985 i++;
cristybb503372010-05-27 20:51:26 +00004986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004987 ThrowMogrifyException(OptionError,"MissingArgument",option);
4988 if (IsGeometry(argv[i]) == MagickFalse)
4989 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4990 break;
4991 }
4992 if (LocaleCompare("median",option+1) == 0)
4993 {
4994 if (*option == '+')
4995 break;
4996 i++;
cristybb503372010-05-27 20:51:26 +00004997 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004998 ThrowMogrifyException(OptionError,"MissingArgument",option);
4999 if (IsGeometry(argv[i]) == MagickFalse)
5000 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5001 break;
5002 }
cristy69ec32d2011-02-27 23:57:09 +00005003 if (LocaleCompare("mode",option+1) == 0)
5004 {
5005 if (*option == '+')
5006 break;
5007 i++;
5008 if (i == (ssize_t) argc)
5009 ThrowMogrifyException(OptionError,"MissingArgument",option);
5010 if (IsGeometry(argv[i]) == MagickFalse)
5011 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5012 break;
5013 }
cristy3ed852e2009-09-05 21:47:34 +00005014 if (LocaleCompare("monitor",option+1) == 0)
5015 break;
5016 if (LocaleCompare("monochrome",option+1) == 0)
5017 break;
5018 if (LocaleCompare("morph",option+1) == 0)
5019 {
5020 if (*option == '+')
5021 break;
5022 i++;
cristybb503372010-05-27 20:51:26 +00005023 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005024 ThrowMogrifyException(OptionError,"MissingArgument",option);
5025 if (IsGeometry(argv[i]) == MagickFalse)
5026 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5027 break;
5028 }
anthony29188a82010-01-22 10:12:34 +00005029 if (LocaleCompare("morphology",option+1) == 0)
5030 {
anthony29188a82010-01-22 10:12:34 +00005031 char
5032 token[MaxTextExtent];
5033
cristyb6bd4ad2010-08-08 01:12:27 +00005034 KernelInfo
5035 *kernel_info;
5036
5037 ssize_t
5038 op;
5039
anthony29188a82010-01-22 10:12:34 +00005040 i++;
cristybb503372010-05-27 20:51:26 +00005041 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005042 ThrowMogrifyException(OptionError,"MissingArgument",option);
5043 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005044 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005045 if (op < 0)
5046 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005047 token);
anthony29188a82010-01-22 10:12:34 +00005048 i++;
cristybb503372010-05-27 20:51:26 +00005049 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005050 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005051 kernel_info=AcquireKernelInfo(argv[i]);
5052 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005053 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005054 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005055 break;
5056 }
cristy3ed852e2009-09-05 21:47:34 +00005057 if (LocaleCompare("mosaic",option+1) == 0)
5058 break;
5059 if (LocaleCompare("motion-blur",option+1) == 0)
5060 {
5061 if (*option == '+')
5062 break;
5063 i++;
cristybb503372010-05-27 20:51:26 +00005064 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005065 ThrowMogrifyException(OptionError,"MissingArgument",option);
5066 if (IsGeometry(argv[i]) == MagickFalse)
5067 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5068 break;
5069 }
5070 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5071 }
5072 case 'n':
5073 {
5074 if (LocaleCompare("negate",option+1) == 0)
5075 break;
5076 if (LocaleCompare("noise",option+1) == 0)
5077 {
5078 i++;
cristybb503372010-05-27 20:51:26 +00005079 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005080 ThrowMogrifyException(OptionError,"MissingArgument",option);
5081 if (*option == '+')
5082 {
cristybb503372010-05-27 20:51:26 +00005083 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005084 noise;
5085
cristy042ee782011-04-22 18:48:30 +00005086 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005087 if (noise < 0)
5088 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5089 argv[i]);
5090 break;
5091 }
5092 if (IsGeometry(argv[i]) == MagickFalse)
5093 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5094 break;
5095 }
5096 if (LocaleCompare("noop",option+1) == 0)
5097 break;
5098 if (LocaleCompare("normalize",option+1) == 0)
5099 break;
5100 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5101 }
5102 case 'o':
5103 {
5104 if (LocaleCompare("opaque",option+1) == 0)
5105 {
cristy3ed852e2009-09-05 21:47:34 +00005106 i++;
cristybb503372010-05-27 20:51:26 +00005107 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005108 ThrowMogrifyException(OptionError,"MissingArgument",option);
5109 break;
5110 }
5111 if (LocaleCompare("ordered-dither",option+1) == 0)
5112 {
5113 if (*option == '+')
5114 break;
5115 i++;
cristybb503372010-05-27 20:51:26 +00005116 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005117 ThrowMogrifyException(OptionError,"MissingArgument",option);
5118 break;
5119 }
5120 if (LocaleCompare("orient",option+1) == 0)
5121 {
cristybb503372010-05-27 20:51:26 +00005122 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005123 orientation;
5124
5125 orientation=UndefinedOrientation;
5126 if (*option == '+')
5127 break;
5128 i++;
cristybb503372010-05-27 20:51:26 +00005129 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005130 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005131 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005132 argv[i]);
5133 if (orientation < 0)
5134 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5135 argv[i]);
5136 break;
5137 }
5138 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5139 }
5140 case 'p':
5141 {
5142 if (LocaleCompare("page",option+1) == 0)
5143 {
5144 if (*option == '+')
5145 break;
5146 i++;
cristybb503372010-05-27 20:51:26 +00005147 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005148 ThrowMogrifyException(OptionError,"MissingArgument",option);
5149 break;
5150 }
5151 if (LocaleCompare("paint",option+1) == 0)
5152 {
5153 if (*option == '+')
5154 break;
5155 i++;
cristybb503372010-05-27 20:51:26 +00005156 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005157 ThrowMogrifyException(OptionError,"MissingArgument",option);
5158 if (IsGeometry(argv[i]) == MagickFalse)
5159 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5160 break;
5161 }
5162 if (LocaleCompare("path",option+1) == 0)
5163 {
5164 (void) CloneString(&path,(char *) NULL);
5165 if (*option == '+')
5166 break;
5167 i++;
cristybb503372010-05-27 20:51:26 +00005168 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005169 ThrowMogrifyException(OptionError,"MissingArgument",option);
5170 (void) CloneString(&path,argv[i]);
5171 break;
5172 }
5173 if (LocaleCompare("pointsize",option+1) == 0)
5174 {
5175 if (*option == '+')
5176 break;
5177 i++;
cristybb503372010-05-27 20:51:26 +00005178 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005179 ThrowMogrifyException(OptionError,"MissingArgument",option);
5180 if (IsGeometry(argv[i]) == MagickFalse)
5181 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5182 break;
5183 }
5184 if (LocaleCompare("polaroid",option+1) == 0)
5185 {
5186 if (*option == '+')
5187 break;
5188 i++;
cristybb503372010-05-27 20:51:26 +00005189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005190 ThrowMogrifyException(OptionError,"MissingArgument",option);
5191 if (IsGeometry(argv[i]) == MagickFalse)
5192 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5193 break;
5194 }
5195 if (LocaleCompare("posterize",option+1) == 0)
5196 {
5197 if (*option == '+')
5198 break;
5199 i++;
cristybb503372010-05-27 20:51:26 +00005200 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005201 ThrowMogrifyException(OptionError,"MissingArgument",option);
5202 if (IsGeometry(argv[i]) == MagickFalse)
5203 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5204 break;
5205 }
cristye7f51092010-01-17 00:39:37 +00005206 if (LocaleCompare("precision",option+1) == 0)
5207 {
5208 if (*option == '+')
5209 break;
5210 i++;
cristybb503372010-05-27 20:51:26 +00005211 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005212 ThrowMogrifyException(OptionError,"MissingArgument",option);
5213 if (IsGeometry(argv[i]) == MagickFalse)
5214 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5215 break;
5216 }
cristy3ed852e2009-09-05 21:47:34 +00005217 if (LocaleCompare("print",option+1) == 0)
5218 {
5219 if (*option == '+')
5220 break;
5221 i++;
cristybb503372010-05-27 20:51:26 +00005222 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005223 ThrowMogrifyException(OptionError,"MissingArgument",option);
5224 break;
5225 }
5226 if (LocaleCompare("process",option+1) == 0)
5227 {
5228 if (*option == '+')
5229 break;
5230 i++;
cristybb503372010-05-27 20:51:26 +00005231 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005232 ThrowMogrifyException(OptionError,"MissingArgument",option);
5233 break;
5234 }
5235 if (LocaleCompare("profile",option+1) == 0)
5236 {
5237 i++;
cristybb503372010-05-27 20:51:26 +00005238 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005239 ThrowMogrifyException(OptionError,"MissingArgument",option);
5240 break;
5241 }
5242 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5243 }
5244 case 'q':
5245 {
5246 if (LocaleCompare("quality",option+1) == 0)
5247 {
5248 if (*option == '+')
5249 break;
5250 i++;
cristybb503372010-05-27 20:51:26 +00005251 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005252 ThrowMogrifyException(OptionError,"MissingArgument",option);
5253 if (IsGeometry(argv[i]) == MagickFalse)
5254 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5255 break;
5256 }
5257 if (LocaleCompare("quantize",option+1) == 0)
5258 {
cristybb503372010-05-27 20:51:26 +00005259 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005260 colorspace;
5261
5262 if (*option == '+')
5263 break;
5264 i++;
cristybb503372010-05-27 20:51:26 +00005265 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005266 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005267 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005268 argv[i]);
5269 if (colorspace < 0)
5270 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5271 argv[i]);
5272 break;
5273 }
5274 if (LocaleCompare("quiet",option+1) == 0)
5275 break;
5276 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5277 }
5278 case 'r':
5279 {
5280 if (LocaleCompare("radial-blur",option+1) == 0)
5281 {
5282 i++;
cristybb503372010-05-27 20:51:26 +00005283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005284 ThrowMogrifyException(OptionError,"MissingArgument",option);
5285 if (IsGeometry(argv[i]) == MagickFalse)
5286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5287 break;
5288 }
5289 if (LocaleCompare("raise",option+1) == 0)
5290 {
5291 i++;
cristybb503372010-05-27 20:51:26 +00005292 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005293 ThrowMogrifyException(OptionError,"MissingArgument",option);
5294 if (IsGeometry(argv[i]) == MagickFalse)
5295 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5296 break;
5297 }
5298 if (LocaleCompare("random-threshold",option+1) == 0)
5299 {
5300 if (*option == '+')
5301 break;
5302 i++;
cristybb503372010-05-27 20:51:26 +00005303 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005304 ThrowMogrifyException(OptionError,"MissingArgument",option);
5305 if (IsGeometry(argv[i]) == MagickFalse)
5306 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5307 break;
5308 }
cristye6365592010-04-02 17:31:23 +00005309 if (LocaleCompare("recolor",option+1) == 0)
5310 {
5311 if (*option == '+')
5312 break;
5313 i++;
cristybb503372010-05-27 20:51:26 +00005314 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00005315 ThrowMogrifyException(OptionError,"MissingArgument",option);
5316 if (IsGeometry(argv[i]) == MagickFalse)
5317 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5318 break;
5319 }
cristy3ed852e2009-09-05 21:47:34 +00005320 if (LocaleCompare("red-primary",option+1) == 0)
5321 {
5322 if (*option == '+')
5323 break;
5324 i++;
cristybb503372010-05-27 20:51:26 +00005325 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005326 ThrowMogrifyException(OptionError,"MissingArgument",option);
5327 if (IsGeometry(argv[i]) == MagickFalse)
5328 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5329 }
cristy9f2083a2010-04-22 19:48:05 +00005330 if (LocaleCompare("regard-warnings",option+1) == 0)
5331 break;
cristy3ed852e2009-09-05 21:47:34 +00005332 if (LocaleCompare("region",option+1) == 0)
5333 {
5334 if (*option == '+')
5335 break;
5336 i++;
cristybb503372010-05-27 20:51:26 +00005337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005338 ThrowMogrifyException(OptionError,"MissingArgument",option);
5339 if (IsGeometry(argv[i]) == MagickFalse)
5340 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5341 break;
5342 }
cristyf0c78232010-03-15 12:53:40 +00005343 if (LocaleCompare("remap",option+1) == 0)
5344 {
5345 if (*option == '+')
5346 break;
5347 i++;
cristybb503372010-05-27 20:51:26 +00005348 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005349 ThrowMogrifyException(OptionError,"MissingArgument",option);
5350 break;
5351 }
cristy3ed852e2009-09-05 21:47:34 +00005352 if (LocaleCompare("render",option+1) == 0)
5353 break;
5354 if (LocaleCompare("repage",option+1) == 0)
5355 {
5356 if (*option == '+')
5357 break;
5358 i++;
cristybb503372010-05-27 20:51:26 +00005359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005360 ThrowMogrifyException(OptionError,"MissingArgument",option);
5361 if (IsGeometry(argv[i]) == MagickFalse)
5362 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5363 break;
5364 }
5365 if (LocaleCompare("resample",option+1) == 0)
5366 {
5367 if (*option == '+')
5368 break;
5369 i++;
cristybb503372010-05-27 20:51:26 +00005370 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005371 ThrowMogrifyException(OptionError,"MissingArgument",option);
5372 if (IsGeometry(argv[i]) == MagickFalse)
5373 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5374 break;
5375 }
5376 if (LocaleCompare("resize",option+1) == 0)
5377 {
5378 if (*option == '+')
5379 break;
5380 i++;
cristybb503372010-05-27 20:51:26 +00005381 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005382 ThrowMogrifyException(OptionError,"MissingArgument",option);
5383 if (IsGeometry(argv[i]) == MagickFalse)
5384 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5385 break;
5386 }
cristyebbcfea2011-02-25 02:43:54 +00005387 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5388 {
5389 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5390 break;
5391 }
cristy3ed852e2009-09-05 21:47:34 +00005392 if (LocaleCompare("reverse",option+1) == 0)
5393 break;
5394 if (LocaleCompare("roll",option+1) == 0)
5395 {
5396 if (*option == '+')
5397 break;
5398 i++;
cristybb503372010-05-27 20:51:26 +00005399 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005400 ThrowMogrifyException(OptionError,"MissingArgument",option);
5401 if (IsGeometry(argv[i]) == MagickFalse)
5402 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5403 break;
5404 }
5405 if (LocaleCompare("rotate",option+1) == 0)
5406 {
5407 i++;
cristybb503372010-05-27 20:51:26 +00005408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005409 ThrowMogrifyException(OptionError,"MissingArgument",option);
5410 if (IsGeometry(argv[i]) == MagickFalse)
5411 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5412 break;
5413 }
5414 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5415 }
5416 case 's':
5417 {
5418 if (LocaleCompare("sample",option+1) == 0)
5419 {
5420 if (*option == '+')
5421 break;
5422 i++;
cristybb503372010-05-27 20:51:26 +00005423 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005424 ThrowMogrifyException(OptionError,"MissingArgument",option);
5425 if (IsGeometry(argv[i]) == MagickFalse)
5426 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5427 break;
5428 }
5429 if (LocaleCompare("sampling-factor",option+1) == 0)
5430 {
5431 if (*option == '+')
5432 break;
5433 i++;
cristybb503372010-05-27 20:51:26 +00005434 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005435 ThrowMogrifyException(OptionError,"MissingArgument",option);
5436 if (IsGeometry(argv[i]) == MagickFalse)
5437 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5438 break;
5439 }
5440 if (LocaleCompare("scale",option+1) == 0)
5441 {
5442 if (*option == '+')
5443 break;
5444 i++;
cristybb503372010-05-27 20:51:26 +00005445 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005446 ThrowMogrifyException(OptionError,"MissingArgument",option);
5447 if (IsGeometry(argv[i]) == MagickFalse)
5448 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5449 break;
5450 }
5451 if (LocaleCompare("scene",option+1) == 0)
5452 {
5453 if (*option == '+')
5454 break;
5455 i++;
cristybb503372010-05-27 20:51:26 +00005456 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005457 ThrowMogrifyException(OptionError,"MissingArgument",option);
5458 if (IsGeometry(argv[i]) == MagickFalse)
5459 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5460 break;
5461 }
5462 if (LocaleCompare("seed",option+1) == 0)
5463 {
5464 if (*option == '+')
5465 break;
5466 i++;
cristybb503372010-05-27 20:51:26 +00005467 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005468 ThrowMogrifyException(OptionError,"MissingArgument",option);
5469 if (IsGeometry(argv[i]) == MagickFalse)
5470 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5471 break;
5472 }
5473 if (LocaleCompare("segment",option+1) == 0)
5474 {
5475 if (*option == '+')
5476 break;
5477 i++;
cristybb503372010-05-27 20:51:26 +00005478 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005479 ThrowMogrifyException(OptionError,"MissingArgument",option);
5480 if (IsGeometry(argv[i]) == MagickFalse)
5481 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5482 break;
5483 }
5484 if (LocaleCompare("selective-blur",option+1) == 0)
5485 {
5486 i++;
cristybb503372010-05-27 20:51:26 +00005487 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005488 ThrowMogrifyException(OptionError,"MissingArgument",option);
5489 if (IsGeometry(argv[i]) == MagickFalse)
5490 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5491 break;
5492 }
5493 if (LocaleCompare("separate",option+1) == 0)
5494 break;
5495 if (LocaleCompare("sepia-tone",option+1) == 0)
5496 {
5497 if (*option == '+')
5498 break;
5499 i++;
cristybb503372010-05-27 20:51:26 +00005500 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005501 ThrowMogrifyException(OptionError,"MissingArgument",option);
5502 if (IsGeometry(argv[i]) == MagickFalse)
5503 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5504 break;
5505 }
5506 if (LocaleCompare("set",option+1) == 0)
5507 {
5508 i++;
cristybb503372010-05-27 20:51:26 +00005509 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005510 ThrowMogrifyException(OptionError,"MissingArgument",option);
5511 if (*option == '+')
5512 break;
5513 i++;
cristybb503372010-05-27 20:51:26 +00005514 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005515 ThrowMogrifyException(OptionError,"MissingArgument",option);
5516 break;
5517 }
5518 if (LocaleCompare("shade",option+1) == 0)
5519 {
5520 i++;
cristybb503372010-05-27 20:51:26 +00005521 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005522 ThrowMogrifyException(OptionError,"MissingArgument",option);
5523 if (IsGeometry(argv[i]) == MagickFalse)
5524 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5525 break;
5526 }
5527 if (LocaleCompare("shadow",option+1) == 0)
5528 {
5529 if (*option == '+')
5530 break;
5531 i++;
cristybb503372010-05-27 20:51:26 +00005532 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005533 ThrowMogrifyException(OptionError,"MissingArgument",option);
5534 if (IsGeometry(argv[i]) == MagickFalse)
5535 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5536 break;
5537 }
5538 if (LocaleCompare("sharpen",option+1) == 0)
5539 {
5540 i++;
cristybb503372010-05-27 20:51:26 +00005541 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005542 ThrowMogrifyException(OptionError,"MissingArgument",option);
5543 if (IsGeometry(argv[i]) == MagickFalse)
5544 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5545 break;
5546 }
5547 if (LocaleCompare("shave",option+1) == 0)
5548 {
5549 if (*option == '+')
5550 break;
5551 i++;
cristybb503372010-05-27 20:51:26 +00005552 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005553 ThrowMogrifyException(OptionError,"MissingArgument",option);
5554 if (IsGeometry(argv[i]) == MagickFalse)
5555 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5556 break;
5557 }
5558 if (LocaleCompare("shear",option+1) == 0)
5559 {
5560 i++;
cristybb503372010-05-27 20:51:26 +00005561 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005562 ThrowMogrifyException(OptionError,"MissingArgument",option);
5563 if (IsGeometry(argv[i]) == MagickFalse)
5564 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5565 break;
5566 }
5567 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5568 {
5569 i++;
cristybb503372010-05-27 20:51:26 +00005570 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005571 ThrowMogrifyException(OptionError,"MissingArgument",option);
5572 if (IsGeometry(argv[i]) == MagickFalse)
5573 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5574 break;
5575 }
5576 if (LocaleCompare("size",option+1) == 0)
5577 {
5578 if (*option == '+')
5579 break;
5580 i++;
cristybb503372010-05-27 20:51:26 +00005581 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005582 ThrowMogrifyException(OptionError,"MissingArgument",option);
5583 if (IsGeometry(argv[i]) == MagickFalse)
5584 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5585 break;
5586 }
5587 if (LocaleCompare("sketch",option+1) == 0)
5588 {
5589 if (*option == '+')
5590 break;
5591 i++;
cristybb503372010-05-27 20:51:26 +00005592 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005593 ThrowMogrifyException(OptionError,"MissingArgument",option);
5594 if (IsGeometry(argv[i]) == MagickFalse)
5595 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5596 break;
5597 }
cristy4285d782011-02-09 20:12:28 +00005598 if (LocaleCompare("smush",option+1) == 0)
5599 {
cristy4285d782011-02-09 20:12:28 +00005600 i++;
5601 if (i == (ssize_t) argc)
5602 ThrowMogrifyException(OptionError,"MissingArgument",option);
5603 if (IsGeometry(argv[i]) == MagickFalse)
5604 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005605 i++;
5606 break;
5607 }
cristy3ed852e2009-09-05 21:47:34 +00005608 if (LocaleCompare("solarize",option+1) == 0)
5609 {
5610 if (*option == '+')
5611 break;
5612 i++;
cristybb503372010-05-27 20:51:26 +00005613 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005614 ThrowMogrifyException(OptionError,"MissingArgument",option);
5615 if (IsGeometry(argv[i]) == MagickFalse)
5616 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5617 break;
5618 }
5619 if (LocaleCompare("sparse-color",option+1) == 0)
5620 {
cristybb503372010-05-27 20:51:26 +00005621 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005622 op;
5623
5624 i++;
cristybb503372010-05-27 20:51:26 +00005625 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005626 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005627 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005628 if (op < 0)
5629 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5630 argv[i]);
5631 i++;
cristybb503372010-05-27 20:51:26 +00005632 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005633 ThrowMogrifyException(OptionError,"MissingArgument",option);
5634 break;
5635 }
5636 if (LocaleCompare("spread",option+1) == 0)
5637 {
5638 if (*option == '+')
5639 break;
5640 i++;
cristybb503372010-05-27 20:51:26 +00005641 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005642 ThrowMogrifyException(OptionError,"MissingArgument",option);
5643 if (IsGeometry(argv[i]) == MagickFalse)
5644 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5645 break;
5646 }
cristy0834d642011-03-18 18:26:08 +00005647 if (LocaleCompare("statistic",option+1) == 0)
5648 {
5649 ssize_t
5650 op;
5651
5652 if (*option == '+')
5653 break;
5654 i++;
5655 if (i == (ssize_t) argc)
5656 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005657 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005658 if (op < 0)
5659 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5660 argv[i]);
5661 i++;
5662 if (i == (ssize_t) (argc-1))
5663 ThrowMogrifyException(OptionError,"MissingArgument",option);
5664 if (IsGeometry(argv[i]) == MagickFalse)
5665 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5666 break;
5667 }
cristy3ed852e2009-09-05 21:47:34 +00005668 if (LocaleCompare("stretch",option+1) == 0)
5669 {
cristybb503372010-05-27 20:51:26 +00005670 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005671 stretch;
5672
5673 if (*option == '+')
5674 break;
5675 i++;
cristybb503372010-05-27 20:51:26 +00005676 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005677 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005678 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005679 if (stretch < 0)
5680 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5681 argv[i]);
5682 break;
5683 }
5684 if (LocaleCompare("strip",option+1) == 0)
5685 break;
5686 if (LocaleCompare("stroke",option+1) == 0)
5687 {
5688 if (*option == '+')
5689 break;
5690 i++;
cristybb503372010-05-27 20:51:26 +00005691 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005692 ThrowMogrifyException(OptionError,"MissingArgument",option);
5693 break;
5694 }
5695 if (LocaleCompare("strokewidth",option+1) == 0)
5696 {
5697 if (*option == '+')
5698 break;
5699 i++;
cristybb503372010-05-27 20:51:26 +00005700 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005701 ThrowMogrifyException(OptionError,"MissingArgument",option);
5702 if (IsGeometry(argv[i]) == MagickFalse)
5703 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5704 break;
5705 }
5706 if (LocaleCompare("style",option+1) == 0)
5707 {
cristybb503372010-05-27 20:51:26 +00005708 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005709 style;
5710
5711 if (*option == '+')
5712 break;
5713 i++;
cristybb503372010-05-27 20:51:26 +00005714 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005715 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005716 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005717 if (style < 0)
5718 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5719 argv[i]);
5720 break;
5721 }
cristyecb10ff2011-03-22 13:14:03 +00005722 if (LocaleCompare("swap",option+1) == 0)
5723 {
5724 if (*option == '+')
5725 break;
5726 i++;
5727 if (i == (ssize_t) (argc-1))
5728 ThrowMogrifyException(OptionError,"MissingArgument",option);
5729 if (IsGeometry(argv[i]) == MagickFalse)
5730 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5731 break;
5732 }
cristy3ed852e2009-09-05 21:47:34 +00005733 if (LocaleCompare("swirl",option+1) == 0)
5734 {
5735 if (*option == '+')
5736 break;
5737 i++;
cristybb503372010-05-27 20:51:26 +00005738 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005739 ThrowMogrifyException(OptionError,"MissingArgument",option);
5740 if (IsGeometry(argv[i]) == MagickFalse)
5741 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5742 break;
5743 }
cristyd9a29192010-10-16 16:49:53 +00005744 if (LocaleCompare("synchronize",option+1) == 0)
5745 break;
cristy3ed852e2009-09-05 21:47:34 +00005746 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5747 }
5748 case 't':
5749 {
5750 if (LocaleCompare("taint",option+1) == 0)
5751 break;
5752 if (LocaleCompare("texture",option+1) == 0)
5753 {
5754 if (*option == '+')
5755 break;
5756 i++;
cristybb503372010-05-27 20:51:26 +00005757 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005758 ThrowMogrifyException(OptionError,"MissingArgument",option);
5759 break;
5760 }
5761 if (LocaleCompare("tile",option+1) == 0)
5762 {
5763 if (*option == '+')
5764 break;
5765 i++;
cristybb503372010-05-27 20:51:26 +00005766 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005767 ThrowMogrifyException(OptionError,"MissingArgument",option);
5768 break;
5769 }
5770 if (LocaleCompare("tile-offset",option+1) == 0)
5771 {
5772 if (*option == '+')
5773 break;
5774 i++;
cristybb503372010-05-27 20:51:26 +00005775 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005776 ThrowMogrifyException(OptionError,"MissingArgument",option);
5777 if (IsGeometry(argv[i]) == MagickFalse)
5778 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5779 break;
5780 }
5781 if (LocaleCompare("tint",option+1) == 0)
5782 {
5783 if (*option == '+')
5784 break;
5785 i++;
cristybb503372010-05-27 20:51:26 +00005786 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005787 ThrowMogrifyException(OptionError,"MissingArgument",option);
5788 if (IsGeometry(argv[i]) == MagickFalse)
5789 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5790 break;
5791 }
5792 if (LocaleCompare("transform",option+1) == 0)
5793 break;
5794 if (LocaleCompare("transpose",option+1) == 0)
5795 break;
5796 if (LocaleCompare("transverse",option+1) == 0)
5797 break;
5798 if (LocaleCompare("threshold",option+1) == 0)
5799 {
5800 if (*option == '+')
5801 break;
5802 i++;
cristybb503372010-05-27 20:51:26 +00005803 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005804 ThrowMogrifyException(OptionError,"MissingArgument",option);
5805 if (IsGeometry(argv[i]) == MagickFalse)
5806 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5807 break;
5808 }
5809 if (LocaleCompare("thumbnail",option+1) == 0)
5810 {
5811 if (*option == '+')
5812 break;
5813 i++;
cristybb503372010-05-27 20:51:26 +00005814 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005815 ThrowMogrifyException(OptionError,"MissingArgument",option);
5816 if (IsGeometry(argv[i]) == MagickFalse)
5817 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5818 break;
5819 }
5820 if (LocaleCompare("transparent",option+1) == 0)
5821 {
5822 i++;
cristybb503372010-05-27 20:51:26 +00005823 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005824 ThrowMogrifyException(OptionError,"MissingArgument",option);
5825 break;
5826 }
5827 if (LocaleCompare("transparent-color",option+1) == 0)
5828 {
5829 if (*option == '+')
5830 break;
5831 i++;
cristybb503372010-05-27 20:51:26 +00005832 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005833 ThrowMogrifyException(OptionError,"MissingArgument",option);
5834 break;
5835 }
5836 if (LocaleCompare("treedepth",option+1) == 0)
5837 {
5838 if (*option == '+')
5839 break;
5840 i++;
cristybb503372010-05-27 20:51:26 +00005841 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005842 ThrowMogrifyException(OptionError,"MissingArgument",option);
5843 if (IsGeometry(argv[i]) == MagickFalse)
5844 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5845 break;
5846 }
5847 if (LocaleCompare("trim",option+1) == 0)
5848 break;
5849 if (LocaleCompare("type",option+1) == 0)
5850 {
cristybb503372010-05-27 20:51:26 +00005851 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005852 type;
5853
5854 if (*option == '+')
5855 break;
5856 i++;
cristybb503372010-05-27 20:51:26 +00005857 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005858 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005859 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005860 if (type < 0)
5861 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5862 argv[i]);
5863 break;
5864 }
5865 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5866 }
5867 case 'u':
5868 {
5869 if (LocaleCompare("undercolor",option+1) == 0)
5870 {
5871 if (*option == '+')
5872 break;
5873 i++;
cristybb503372010-05-27 20:51:26 +00005874 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005875 ThrowMogrifyException(OptionError,"MissingArgument",option);
5876 break;
5877 }
5878 if (LocaleCompare("unique-colors",option+1) == 0)
5879 break;
5880 if (LocaleCompare("units",option+1) == 0)
5881 {
cristybb503372010-05-27 20:51:26 +00005882 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005883 units;
5884
5885 if (*option == '+')
5886 break;
5887 i++;
cristybb503372010-05-27 20:51:26 +00005888 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005889 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005890 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005891 argv[i]);
5892 if (units < 0)
5893 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5894 argv[i]);
5895 break;
5896 }
5897 if (LocaleCompare("unsharp",option+1) == 0)
5898 {
5899 i++;
cristybb503372010-05-27 20:51:26 +00005900 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005901 ThrowMogrifyException(OptionError,"MissingArgument",option);
5902 if (IsGeometry(argv[i]) == MagickFalse)
5903 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5904 break;
5905 }
5906 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5907 }
5908 case 'v':
5909 {
5910 if (LocaleCompare("verbose",option+1) == 0)
5911 {
5912 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5913 break;
5914 }
5915 if ((LocaleCompare("version",option+1) == 0) ||
5916 (LocaleCompare("-version",option+1) == 0))
5917 {
cristyb51dff52011-05-19 16:55:47 +00005918 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005919 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005920 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5921 GetMagickCopyright());
5922 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5923 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005924 break;
5925 }
5926 if (LocaleCompare("view",option+1) == 0)
5927 {
5928 if (*option == '+')
5929 break;
5930 i++;
cristybb503372010-05-27 20:51:26 +00005931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005932 ThrowMogrifyException(OptionError,"MissingArgument",option);
5933 break;
5934 }
5935 if (LocaleCompare("vignette",option+1) == 0)
5936 {
5937 if (*option == '+')
5938 break;
5939 i++;
cristybb503372010-05-27 20:51:26 +00005940 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005941 ThrowMogrifyException(OptionError,"MissingArgument",option);
5942 if (IsGeometry(argv[i]) == MagickFalse)
5943 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5944 break;
5945 }
5946 if (LocaleCompare("virtual-pixel",option+1) == 0)
5947 {
cristybb503372010-05-27 20:51:26 +00005948 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005949 method;
5950
5951 if (*option == '+')
5952 break;
5953 i++;
cristybb503372010-05-27 20:51:26 +00005954 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005955 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005956 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005957 argv[i]);
5958 if (method < 0)
5959 ThrowMogrifyException(OptionError,
5960 "UnrecognizedVirtualPixelMethod",argv[i]);
5961 break;
5962 }
5963 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5964 }
5965 case 'w':
5966 {
5967 if (LocaleCompare("wave",option+1) == 0)
5968 {
5969 i++;
cristybb503372010-05-27 20:51:26 +00005970 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005971 ThrowMogrifyException(OptionError,"MissingArgument",option);
5972 if (IsGeometry(argv[i]) == MagickFalse)
5973 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5974 break;
5975 }
5976 if (LocaleCompare("weight",option+1) == 0)
5977 {
5978 if (*option == '+')
5979 break;
5980 i++;
cristybb503372010-05-27 20:51:26 +00005981 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005982 ThrowMogrifyException(OptionError,"MissingArgument",option);
5983 break;
5984 }
5985 if (LocaleCompare("white-point",option+1) == 0)
5986 {
5987 if (*option == '+')
5988 break;
5989 i++;
cristybb503372010-05-27 20:51:26 +00005990 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005991 ThrowMogrifyException(OptionError,"MissingArgument",option);
5992 if (IsGeometry(argv[i]) == MagickFalse)
5993 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5994 break;
5995 }
5996 if (LocaleCompare("white-threshold",option+1) == 0)
5997 {
5998 if (*option == '+')
5999 break;
6000 i++;
cristybb503372010-05-27 20:51:26 +00006001 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006002 ThrowMogrifyException(OptionError,"MissingArgument",option);
6003 if (IsGeometry(argv[i]) == MagickFalse)
6004 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6005 break;
6006 }
6007 if (LocaleCompare("write",option+1) == 0)
6008 {
6009 i++;
cristybb503372010-05-27 20:51:26 +00006010 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006011 ThrowMogrifyException(OptionError,"MissingArgument",option);
6012 break;
6013 }
6014 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6015 }
6016 case '?':
6017 break;
6018 default:
6019 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6020 }
cristy042ee782011-04-22 18:48:30 +00006021 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6022 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006023 if (fire != MagickFalse)
6024 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6025 }
6026 if (k != 0)
6027 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006028 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006029 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6030 DestroyMogrify();
6031 return(status != 0 ? MagickTrue : MagickFalse);
6032}
6033
6034/*
6035%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6036% %
6037% %
6038% %
6039+ M o g r i f y I m a g e I n f o %
6040% %
6041% %
6042% %
6043%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6044%
6045% MogrifyImageInfo() applies image processing settings to the image as
6046% prescribed by command line options.
6047%
6048% The format of the MogrifyImageInfo method is:
6049%
6050% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6051% const char **argv,ExceptionInfo *exception)
6052%
6053% A description of each parameter follows:
6054%
6055% o image_info: the image info..
6056%
6057% o argc: Specifies a pointer to an integer describing the number of
6058% elements in the argument vector.
6059%
6060% o argv: Specifies a pointer to a text array containing the command line
6061% arguments.
6062%
6063% o exception: return any errors or warnings in this structure.
6064%
6065*/
6066WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6067 const int argc,const char **argv,ExceptionInfo *exception)
6068{
6069 const char
6070 *option;
6071
6072 GeometryInfo
6073 geometry_info;
6074
cristybb503372010-05-27 20:51:26 +00006075 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006076 count;
6077
cristybb503372010-05-27 20:51:26 +00006078 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006079 i;
6080
6081 /*
6082 Initialize method variables.
6083 */
6084 assert(image_info != (ImageInfo *) NULL);
6085 assert(image_info->signature == MagickSignature);
6086 if (image_info->debug != MagickFalse)
6087 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6088 image_info->filename);
6089 if (argc < 0)
6090 return(MagickTrue);
6091 /*
6092 Set the image settings.
6093 */
cristybb503372010-05-27 20:51:26 +00006094 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006095 {
6096 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006097 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006098 continue;
cristy042ee782011-04-22 18:48:30 +00006099 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006100 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006101 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006102 break;
6103 switch (*(option+1))
6104 {
6105 case 'a':
6106 {
6107 if (LocaleCompare("adjoin",option+1) == 0)
6108 {
6109 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6110 break;
6111 }
6112 if (LocaleCompare("antialias",option+1) == 0)
6113 {
6114 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6115 break;
6116 }
6117 if (LocaleCompare("attenuate",option+1) == 0)
6118 {
6119 if (*option == '+')
6120 {
6121 (void) DeleteImageOption(image_info,option+1);
6122 break;
6123 }
6124 (void) SetImageOption(image_info,option+1,argv[i+1]);
6125 break;
6126 }
6127 if (LocaleCompare("authenticate",option+1) == 0)
6128 {
6129 if (*option == '+')
6130 (void) CloneString(&image_info->authenticate,(char *) NULL);
6131 else
6132 (void) CloneString(&image_info->authenticate,argv[i+1]);
6133 break;
6134 }
6135 break;
6136 }
6137 case 'b':
6138 {
6139 if (LocaleCompare("background",option+1) == 0)
6140 {
6141 if (*option == '+')
6142 {
6143 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006144 (void) QueryColorDatabase(MogrifyBackgroundColor,
cristy3ed852e2009-09-05 21:47:34 +00006145 &image_info->background_color,exception);
6146 break;
6147 }
6148 (void) SetImageOption(image_info,option+1,argv[i+1]);
6149 (void) QueryColorDatabase(argv[i+1],&image_info->background_color,
6150 exception);
6151 break;
6152 }
6153 if (LocaleCompare("bias",option+1) == 0)
6154 {
6155 if (*option == '+')
6156 {
6157 (void) SetImageOption(image_info,option+1,"0.0");
6158 break;
6159 }
6160 (void) SetImageOption(image_info,option+1,argv[i+1]);
6161 break;
6162 }
6163 if (LocaleCompare("black-point-compensation",option+1) == 0)
6164 {
6165 if (*option == '+')
6166 {
6167 (void) SetImageOption(image_info,option+1,"false");
6168 break;
6169 }
6170 (void) SetImageOption(image_info,option+1,"true");
6171 break;
6172 }
6173 if (LocaleCompare("blue-primary",option+1) == 0)
6174 {
6175 if (*option == '+')
6176 {
6177 (void) SetImageOption(image_info,option+1,"0.0");
6178 break;
6179 }
6180 (void) SetImageOption(image_info,option+1,argv[i+1]);
6181 break;
6182 }
6183 if (LocaleCompare("bordercolor",option+1) == 0)
6184 {
6185 if (*option == '+')
6186 {
6187 (void) DeleteImageOption(image_info,option+1);
cristy638895a2011-08-06 23:19:14 +00006188 (void) QueryColorDatabase(MogrifyBorderColor,
6189 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006190 break;
6191 }
6192 (void) QueryColorDatabase(argv[i+1],&image_info->border_color,
6193 exception);
6194 (void) SetImageOption(image_info,option+1,argv[i+1]);
6195 break;
6196 }
6197 if (LocaleCompare("box",option+1) == 0)
6198 {
6199 if (*option == '+')
6200 {
6201 (void) SetImageOption(image_info,"undercolor","none");
6202 break;
6203 }
6204 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6205 break;
6206 }
6207 break;
6208 }
6209 case 'c':
6210 {
6211 if (LocaleCompare("cache",option+1) == 0)
6212 {
6213 MagickSizeType
6214 limit;
6215
6216 limit=MagickResourceInfinity;
6217 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006218 limit=(MagickSizeType) SiPrefixToDouble(argv[i+1],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006219 (void) SetMagickResourceLimit(MemoryResource,limit);
6220 (void) SetMagickResourceLimit(MapResource,2*limit);
6221 break;
6222 }
6223 if (LocaleCompare("caption",option+1) == 0)
6224 {
6225 if (*option == '+')
6226 {
6227 (void) DeleteImageOption(image_info,option+1);
6228 break;
6229 }
6230 (void) SetImageOption(image_info,option+1,argv[i+1]);
6231 break;
6232 }
6233 if (LocaleCompare("channel",option+1) == 0)
6234 {
6235 if (*option == '+')
6236 {
6237 image_info->channel=DefaultChannels;
6238 break;
6239 }
6240 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6241 break;
6242 }
6243 if (LocaleCompare("colors",option+1) == 0)
6244 {
cristye27293e2009-12-18 02:53:20 +00006245 image_info->colors=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006246 break;
6247 }
6248 if (LocaleCompare("colorspace",option+1) == 0)
6249 {
6250 if (*option == '+')
6251 {
6252 image_info->colorspace=UndefinedColorspace;
6253 (void) SetImageOption(image_info,option+1,"undefined");
6254 break;
6255 }
cristy042ee782011-04-22 18:48:30 +00006256 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006257 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6258 (void) SetImageOption(image_info,option+1,argv[i+1]);
6259 break;
6260 }
cristy3ed852e2009-09-05 21:47:34 +00006261 if (LocaleCompare("comment",option+1) == 0)
6262 {
6263 if (*option == '+')
6264 {
6265 (void) DeleteImageOption(image_info,option+1);
6266 break;
6267 }
6268 (void) SetImageOption(image_info,option+1,argv[i+1]);
6269 break;
6270 }
6271 if (LocaleCompare("compose",option+1) == 0)
6272 {
6273 if (*option == '+')
6274 {
6275 (void) SetImageOption(image_info,option+1,"undefined");
6276 break;
6277 }
6278 (void) SetImageOption(image_info,option+1,argv[i+1]);
6279 break;
6280 }
6281 if (LocaleCompare("compress",option+1) == 0)
6282 {
6283 if (*option == '+')
6284 {
6285 image_info->compression=UndefinedCompression;
6286 (void) SetImageOption(image_info,option+1,"undefined");
6287 break;
6288 }
cristy042ee782011-04-22 18:48:30 +00006289 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006290 MagickCompressOptions,MagickFalse,argv[i+1]);
6291 (void) SetImageOption(image_info,option+1,argv[i+1]);
6292 break;
6293 }
6294 break;
6295 }
6296 case 'd':
6297 {
6298 if (LocaleCompare("debug",option+1) == 0)
6299 {
6300 if (*option == '+')
6301 (void) SetLogEventMask("none");
6302 else
6303 (void) SetLogEventMask(argv[i+1]);
6304 image_info->debug=IsEventLogging();
6305 break;
6306 }
6307 if (LocaleCompare("define",option+1) == 0)
6308 {
6309 if (*option == '+')
6310 {
6311 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6312 (void) DeleteImageRegistry(argv[i+1]+9);
6313 else
6314 (void) DeleteImageOption(image_info,argv[i+1]);
6315 break;
6316 }
6317 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6318 {
6319 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6320 exception);
6321 break;
6322 }
6323 (void) DefineImageOption(image_info,argv[i+1]);
6324 break;
6325 }
6326 if (LocaleCompare("delay",option+1) == 0)
6327 {
6328 if (*option == '+')
6329 {
6330 (void) SetImageOption(image_info,option+1,"0");
6331 break;
6332 }
6333 (void) SetImageOption(image_info,option+1,argv[i+1]);
6334 break;
6335 }
6336 if (LocaleCompare("density",option+1) == 0)
6337 {
6338 /*
6339 Set image density.
6340 */
6341 if (*option == '+')
6342 {
6343 if (image_info->density != (char *) NULL)
6344 image_info->density=DestroyString(image_info->density);
6345 (void) SetImageOption(image_info,option+1,"72");
6346 break;
6347 }
6348 (void) CloneString(&image_info->density,argv[i+1]);
6349 (void) SetImageOption(image_info,option+1,argv[i+1]);
6350 break;
6351 }
6352 if (LocaleCompare("depth",option+1) == 0)
6353 {
6354 if (*option == '+')
6355 {
6356 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6357 break;
6358 }
cristye27293e2009-12-18 02:53:20 +00006359 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006360 break;
6361 }
cristyc9b12952010-03-28 01:12:28 +00006362 if (LocaleCompare("direction",option+1) == 0)
6363 {
6364 if (*option == '+')
6365 {
6366 (void) SetImageOption(image_info,option+1,"undefined");
6367 break;
6368 }
6369 (void) SetImageOption(image_info,option+1,argv[i+1]);
6370 break;
6371 }
cristy3ed852e2009-09-05 21:47:34 +00006372 if (LocaleCompare("display",option+1) == 0)
6373 {
6374 if (*option == '+')
6375 {
6376 if (image_info->server_name != (char *) NULL)
6377 image_info->server_name=DestroyString(
6378 image_info->server_name);
6379 break;
6380 }
6381 (void) CloneString(&image_info->server_name,argv[i+1]);
6382 break;
6383 }
6384 if (LocaleCompare("dispose",option+1) == 0)
6385 {
6386 if (*option == '+')
6387 {
6388 (void) SetImageOption(image_info,option+1,"undefined");
6389 break;
6390 }
6391 (void) SetImageOption(image_info,option+1,argv[i+1]);
6392 break;
6393 }
6394 if (LocaleCompare("dither",option+1) == 0)
6395 {
6396 if (*option == '+')
6397 {
6398 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006399 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006400 break;
6401 }
6402 (void) SetImageOption(image_info,option+1,argv[i+1]);
6403 image_info->dither=MagickTrue;
6404 break;
6405 }
6406 break;
6407 }
6408 case 'e':
6409 {
6410 if (LocaleCompare("encoding",option+1) == 0)
6411 {
6412 if (*option == '+')
6413 {
6414 (void) SetImageOption(image_info,option+1,"undefined");
6415 break;
6416 }
6417 (void) SetImageOption(image_info,option+1,argv[i+1]);
6418 break;
6419 }
6420 if (LocaleCompare("endian",option+1) == 0)
6421 {
6422 if (*option == '+')
6423 {
6424 image_info->endian=UndefinedEndian;
6425 (void) SetImageOption(image_info,option+1,"undefined");
6426 break;
6427 }
cristy042ee782011-04-22 18:48:30 +00006428 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006429 MagickEndianOptions,MagickFalse,argv[i+1]);
6430 (void) SetImageOption(image_info,option+1,argv[i+1]);
6431 break;
6432 }
6433 if (LocaleCompare("extract",option+1) == 0)
6434 {
6435 /*
6436 Set image extract geometry.
6437 */
6438 if (*option == '+')
6439 {
6440 if (image_info->extract != (char *) NULL)
6441 image_info->extract=DestroyString(image_info->extract);
6442 break;
6443 }
6444 (void) CloneString(&image_info->extract,argv[i+1]);
6445 break;
6446 }
6447 break;
6448 }
6449 case 'f':
6450 {
6451 if (LocaleCompare("fill",option+1) == 0)
6452 {
6453 if (*option == '+')
6454 {
6455 (void) SetImageOption(image_info,option+1,"none");
6456 break;
6457 }
6458 (void) SetImageOption(image_info,option+1,argv[i+1]);
6459 break;
6460 }
6461 if (LocaleCompare("filter",option+1) == 0)
6462 {
6463 if (*option == '+')
6464 {
6465 (void) SetImageOption(image_info,option+1,"undefined");
6466 break;
6467 }
6468 (void) SetImageOption(image_info,option+1,argv[i+1]);
6469 break;
6470 }
6471 if (LocaleCompare("font",option+1) == 0)
6472 {
6473 if (*option == '+')
6474 {
6475 if (image_info->font != (char *) NULL)
6476 image_info->font=DestroyString(image_info->font);
6477 break;
6478 }
6479 (void) CloneString(&image_info->font,argv[i+1]);
6480 break;
6481 }
6482 if (LocaleCompare("format",option+1) == 0)
6483 {
6484 register const char
6485 *q;
6486
6487 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006488 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006489 image_info->ping=MagickFalse;
6490 (void) SetImageOption(image_info,option+1,argv[i+1]);
6491 break;
6492 }
6493 if (LocaleCompare("fuzz",option+1) == 0)
6494 {
6495 if (*option == '+')
6496 {
6497 image_info->fuzz=0.0;
6498 (void) SetImageOption(image_info,option+1,"0");
6499 break;
6500 }
cristyf2f27272009-12-17 14:48:46 +00006501 image_info->fuzz=SiPrefixToDouble(argv[i+1],(double) QuantumRange+
cristy3ed852e2009-09-05 21:47:34 +00006502 1.0);
6503 (void) SetImageOption(image_info,option+1,argv[i+1]);
6504 break;
6505 }
6506 break;
6507 }
6508 case 'g':
6509 {
6510 if (LocaleCompare("gravity",option+1) == 0)
6511 {
6512 if (*option == '+')
6513 {
6514 (void) SetImageOption(image_info,option+1,"undefined");
6515 break;
6516 }
6517 (void) SetImageOption(image_info,option+1,argv[i+1]);
6518 break;
6519 }
6520 if (LocaleCompare("green-primary",option+1) == 0)
6521 {
6522 if (*option == '+')
6523 {
6524 (void) SetImageOption(image_info,option+1,"0.0");
6525 break;
6526 }
6527 (void) SetImageOption(image_info,option+1,argv[i+1]);
6528 break;
6529 }
6530 break;
6531 }
6532 case 'i':
6533 {
6534 if (LocaleCompare("intent",option+1) == 0)
6535 {
6536 if (*option == '+')
6537 {
6538 (void) SetImageOption(image_info,option+1,"undefined");
6539 break;
6540 }
6541 (void) SetImageOption(image_info,option+1,argv[i+1]);
6542 break;
6543 }
6544 if (LocaleCompare("interlace",option+1) == 0)
6545 {
6546 if (*option == '+')
6547 {
6548 image_info->interlace=UndefinedInterlace;
6549 (void) SetImageOption(image_info,option+1,"undefined");
6550 break;
6551 }
cristy042ee782011-04-22 18:48:30 +00006552 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006553 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6554 (void) SetImageOption(image_info,option+1,argv[i+1]);
6555 break;
6556 }
cristyb32b90a2009-09-07 21:45:48 +00006557 if (LocaleCompare("interline-spacing",option+1) == 0)
6558 {
6559 if (*option == '+')
6560 {
6561 (void) SetImageOption(image_info,option+1,"undefined");
6562 break;
6563 }
6564 (void) SetImageOption(image_info,option+1,argv[i+1]);
6565 break;
6566 }
cristy3ed852e2009-09-05 21:47:34 +00006567 if (LocaleCompare("interpolate",option+1) == 0)
6568 {
6569 if (*option == '+')
6570 {
6571 (void) SetImageOption(image_info,option+1,"undefined");
6572 break;
6573 }
6574 (void) SetImageOption(image_info,option+1,argv[i+1]);
6575 break;
6576 }
6577 if (LocaleCompare("interword-spacing",option+1) == 0)
6578 {
6579 if (*option == '+')
6580 {
6581 (void) SetImageOption(image_info,option+1,"undefined");
6582 break;
6583 }
6584 (void) SetImageOption(image_info,option+1,argv[i+1]);
6585 break;
6586 }
6587 break;
6588 }
6589 case 'k':
6590 {
6591 if (LocaleCompare("kerning",option+1) == 0)
6592 {
6593 if (*option == '+')
6594 {
6595 (void) SetImageOption(image_info,option+1,"undefined");
6596 break;
6597 }
6598 (void) SetImageOption(image_info,option+1,argv[i+1]);
6599 break;
6600 }
6601 break;
6602 }
6603 case 'l':
6604 {
6605 if (LocaleCompare("label",option+1) == 0)
6606 {
6607 if (*option == '+')
6608 {
6609 (void) DeleteImageOption(image_info,option+1);
6610 break;
6611 }
6612 (void) SetImageOption(image_info,option+1,argv[i+1]);
6613 break;
6614 }
6615 if (LocaleCompare("limit",option+1) == 0)
6616 {
6617 MagickSizeType
6618 limit;
6619
6620 ResourceType
6621 type;
6622
6623 if (*option == '+')
6624 break;
cristy042ee782011-04-22 18:48:30 +00006625 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006626 MagickFalse,argv[i+1]);
6627 limit=MagickResourceInfinity;
6628 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyf2f27272009-12-17 14:48:46 +00006629 limit=(MagickSizeType) SiPrefixToDouble(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006630 (void) SetMagickResourceLimit(type,limit);
6631 break;
6632 }
6633 if (LocaleCompare("list",option+1) == 0)
6634 {
cristybb503372010-05-27 20:51:26 +00006635 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006636 list;
6637
6638 /*
6639 Display configuration list.
6640 */
cristy042ee782011-04-22 18:48:30 +00006641 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006642 switch (list)
6643 {
6644 case MagickCoderOptions:
6645 {
6646 (void) ListCoderInfo((FILE *) NULL,exception);
6647 break;
6648 }
6649 case MagickColorOptions:
6650 {
6651 (void) ListColorInfo((FILE *) NULL,exception);
6652 break;
6653 }
6654 case MagickConfigureOptions:
6655 {
6656 (void) ListConfigureInfo((FILE *) NULL,exception);
6657 break;
6658 }
6659 case MagickDelegateOptions:
6660 {
6661 (void) ListDelegateInfo((FILE *) NULL,exception);
6662 break;
6663 }
6664 case MagickFontOptions:
6665 {
6666 (void) ListTypeInfo((FILE *) NULL,exception);
6667 break;
6668 }
6669 case MagickFormatOptions:
6670 {
6671 (void) ListMagickInfo((FILE *) NULL,exception);
6672 break;
6673 }
6674 case MagickLocaleOptions:
6675 {
6676 (void) ListLocaleInfo((FILE *) NULL,exception);
6677 break;
6678 }
6679 case MagickLogOptions:
6680 {
6681 (void) ListLogInfo((FILE *) NULL,exception);
6682 break;
6683 }
6684 case MagickMagicOptions:
6685 {
6686 (void) ListMagicInfo((FILE *) NULL,exception);
6687 break;
6688 }
6689 case MagickMimeOptions:
6690 {
6691 (void) ListMimeInfo((FILE *) NULL,exception);
6692 break;
6693 }
6694 case MagickModuleOptions:
6695 {
6696 (void) ListModuleInfo((FILE *) NULL,exception);
6697 break;
6698 }
6699 case MagickPolicyOptions:
6700 {
6701 (void) ListPolicyInfo((FILE *) NULL,exception);
6702 break;
6703 }
6704 case MagickResourceOptions:
6705 {
6706 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6707 break;
6708 }
6709 case MagickThresholdOptions:
6710 {
6711 (void) ListThresholdMaps((FILE *) NULL,exception);
6712 break;
6713 }
6714 default:
6715 {
cristy042ee782011-04-22 18:48:30 +00006716 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006717 exception);
6718 break;
6719 }
6720 }
cristyaeb2cbc2010-05-07 13:28:58 +00006721 break;
cristy3ed852e2009-09-05 21:47:34 +00006722 }
6723 if (LocaleCompare("log",option+1) == 0)
6724 {
6725 if (*option == '+')
6726 break;
6727 (void) SetLogFormat(argv[i+1]);
6728 break;
6729 }
6730 if (LocaleCompare("loop",option+1) == 0)
6731 {
6732 if (*option == '+')
6733 {
6734 (void) SetImageOption(image_info,option+1,"0");
6735 break;
6736 }
6737 (void) SetImageOption(image_info,option+1,argv[i+1]);
6738 break;
6739 }
6740 break;
6741 }
6742 case 'm':
6743 {
6744 if (LocaleCompare("matte",option+1) == 0)
6745 {
6746 if (*option == '+')
6747 {
6748 (void) SetImageOption(image_info,option+1,"false");
6749 break;
6750 }
6751 (void) SetImageOption(image_info,option+1,"true");
6752 break;
6753 }
6754 if (LocaleCompare("mattecolor",option+1) == 0)
6755 {
6756 if (*option == '+')
6757 {
6758 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy638895a2011-08-06 23:19:14 +00006759 (void) QueryColorDatabase(MogrifyMatteColor,
6760 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006761 break;
6762 }
6763 (void) SetImageOption(image_info,option+1,argv[i+1]);
6764 (void) QueryColorDatabase(argv[i+1],&image_info->matte_color,
6765 exception);
6766 break;
6767 }
6768 if (LocaleCompare("monitor",option+1) == 0)
6769 {
6770 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6771 (void *) NULL);
6772 break;
6773 }
6774 if (LocaleCompare("monochrome",option+1) == 0)
6775 {
6776 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6777 break;
6778 }
6779 break;
6780 }
6781 case 'o':
6782 {
6783 if (LocaleCompare("orient",option+1) == 0)
6784 {
6785 if (*option == '+')
6786 {
6787 image_info->orientation=UndefinedOrientation;
6788 (void) SetImageOption(image_info,option+1,"undefined");
6789 break;
6790 }
cristy042ee782011-04-22 18:48:30 +00006791 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006792 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006793 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006794 break;
6795 }
6796 }
6797 case 'p':
6798 {
6799 if (LocaleCompare("page",option+1) == 0)
6800 {
6801 char
6802 *canonical_page,
6803 page[MaxTextExtent];
6804
6805 const char
6806 *image_option;
6807
6808 MagickStatusType
6809 flags;
6810
6811 RectangleInfo
6812 geometry;
6813
6814 if (*option == '+')
6815 {
6816 (void) DeleteImageOption(image_info,option+1);
6817 (void) CloneString(&image_info->page,(char *) NULL);
6818 break;
6819 }
6820 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6821 image_option=GetImageOption(image_info,"page");
6822 if (image_option != (const char *) NULL)
6823 flags=ParseAbsoluteGeometry(image_option,&geometry);
6824 canonical_page=GetPageGeometry(argv[i+1]);
6825 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6826 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006827 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006828 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006829 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006830 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006831 (unsigned long) geometry.width,(unsigned long) geometry.height,
6832 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006833 (void) SetImageOption(image_info,option+1,page);
6834 (void) CloneString(&image_info->page,page);
6835 break;
6836 }
6837 if (LocaleCompare("pen",option+1) == 0)
6838 {
6839 if (*option == '+')
6840 {
6841 (void) SetImageOption(image_info,option+1,"none");
6842 break;
6843 }
6844 (void) SetImageOption(image_info,option+1,argv[i+1]);
6845 break;
6846 }
6847 if (LocaleCompare("ping",option+1) == 0)
6848 {
6849 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6850 break;
6851 }
6852 if (LocaleCompare("pointsize",option+1) == 0)
6853 {
6854 if (*option == '+')
6855 geometry_info.rho=0.0;
6856 else
6857 (void) ParseGeometry(argv[i+1],&geometry_info);
6858 image_info->pointsize=geometry_info.rho;
6859 break;
6860 }
cristye7f51092010-01-17 00:39:37 +00006861 if (LocaleCompare("precision",option+1) == 0)
6862 {
cristybf2766a2010-01-17 03:33:23 +00006863 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006864 break;
6865 }
cristy3ed852e2009-09-05 21:47:34 +00006866 if (LocaleCompare("preview",option+1) == 0)
6867 {
6868 /*
6869 Preview image.
6870 */
6871 if (*option == '+')
6872 {
6873 image_info->preview_type=UndefinedPreview;
6874 break;
6875 }
cristy042ee782011-04-22 18:48:30 +00006876 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006877 MagickPreviewOptions,MagickFalse,argv[i+1]);
6878 break;
6879 }
6880 break;
6881 }
6882 case 'q':
6883 {
6884 if (LocaleCompare("quality",option+1) == 0)
6885 {
6886 /*
6887 Set image compression quality.
6888 */
6889 if (*option == '+')
6890 {
6891 image_info->quality=UndefinedCompressionQuality;
6892 (void) SetImageOption(image_info,option+1,"0");
6893 break;
6894 }
cristye27293e2009-12-18 02:53:20 +00006895 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006896 (void) SetImageOption(image_info,option+1,argv[i+1]);
6897 break;
6898 }
6899 if (LocaleCompare("quiet",option+1) == 0)
6900 {
6901 static WarningHandler
6902 warning_handler = (WarningHandler) NULL;
6903
6904 if (*option == '+')
6905 {
6906 /*
6907 Restore error or warning messages.
6908 */
6909 warning_handler=SetWarningHandler(warning_handler);
6910 break;
6911 }
6912 /*
6913 Suppress error or warning messages.
6914 */
6915 warning_handler=SetWarningHandler((WarningHandler) NULL);
6916 break;
6917 }
6918 break;
6919 }
6920 case 'r':
6921 {
6922 if (LocaleCompare("red-primary",option+1) == 0)
6923 {
6924 if (*option == '+')
6925 {
6926 (void) SetImageOption(image_info,option+1,"0.0");
6927 break;
6928 }
6929 (void) SetImageOption(image_info,option+1,argv[i+1]);
6930 break;
6931 }
6932 break;
6933 }
6934 case 's':
6935 {
6936 if (LocaleCompare("sampling-factor",option+1) == 0)
6937 {
6938 /*
6939 Set image sampling factor.
6940 */
6941 if (*option == '+')
6942 {
6943 if (image_info->sampling_factor != (char *) NULL)
6944 image_info->sampling_factor=DestroyString(
6945 image_info->sampling_factor);
6946 break;
6947 }
6948 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6949 break;
6950 }
6951 if (LocaleCompare("scene",option+1) == 0)
6952 {
6953 /*
6954 Set image scene.
6955 */
6956 if (*option == '+')
6957 {
6958 image_info->scene=0;
6959 (void) SetImageOption(image_info,option+1,"0");
6960 break;
6961 }
cristye27293e2009-12-18 02:53:20 +00006962 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006963 (void) SetImageOption(image_info,option+1,argv[i+1]);
6964 break;
6965 }
6966 if (LocaleCompare("seed",option+1) == 0)
6967 {
cristybb503372010-05-27 20:51:26 +00006968 size_t
cristy3ed852e2009-09-05 21:47:34 +00006969 seed;
6970
6971 if (*option == '+')
6972 {
cristybb503372010-05-27 20:51:26 +00006973 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006974 SeedPseudoRandomGenerator(seed);
6975 break;
6976 }
cristye27293e2009-12-18 02:53:20 +00006977 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006978 SeedPseudoRandomGenerator(seed);
6979 break;
6980 }
6981 if (LocaleCompare("size",option+1) == 0)
6982 {
6983 if (*option == '+')
6984 {
6985 if (image_info->size != (char *) NULL)
6986 image_info->size=DestroyString(image_info->size);
6987 break;
6988 }
6989 (void) CloneString(&image_info->size,argv[i+1]);
6990 break;
6991 }
6992 if (LocaleCompare("stroke",option+1) == 0)
6993 {
6994 if (*option == '+')
6995 {
6996 (void) SetImageOption(image_info,option+1,"none");
6997 break;
6998 }
6999 (void) SetImageOption(image_info,option+1,argv[i+1]);
7000 break;
7001 }
7002 if (LocaleCompare("strokewidth",option+1) == 0)
7003 {
7004 if (*option == '+')
7005 {
7006 (void) SetImageOption(image_info,option+1,"0");
7007 break;
7008 }
7009 (void) SetImageOption(image_info,option+1,argv[i+1]);
7010 break;
7011 }
cristyd9a29192010-10-16 16:49:53 +00007012 if (LocaleCompare("synchronize",option+1) == 0)
7013 {
7014 if (*option == '+')
7015 {
7016 image_info->synchronize=MagickFalse;
7017 break;
7018 }
7019 image_info->synchronize=MagickTrue;
7020 break;
7021 }
cristy3ed852e2009-09-05 21:47:34 +00007022 break;
7023 }
7024 case 't':
7025 {
7026 if (LocaleCompare("taint",option+1) == 0)
7027 {
7028 if (*option == '+')
7029 {
7030 (void) SetImageOption(image_info,option+1,"false");
7031 break;
7032 }
7033 (void) SetImageOption(image_info,option+1,"true");
7034 break;
7035 }
7036 if (LocaleCompare("texture",option+1) == 0)
7037 {
7038 if (*option == '+')
7039 {
7040 if (image_info->texture != (char *) NULL)
7041 image_info->texture=DestroyString(image_info->texture);
7042 break;
7043 }
7044 (void) CloneString(&image_info->texture,argv[i+1]);
7045 break;
7046 }
7047 if (LocaleCompare("tile-offset",option+1) == 0)
7048 {
7049 if (*option == '+')
7050 {
7051 (void) SetImageOption(image_info,option+1,"0");
7052 break;
7053 }
7054 (void) SetImageOption(image_info,option+1,argv[i+1]);
7055 break;
7056 }
7057 if (LocaleCompare("transparent-color",option+1) == 0)
7058 {
7059 if (*option == '+')
7060 {
7061 (void) QueryColorDatabase("none",&image_info->transparent_color, exception);
7062 (void) SetImageOption(image_info,option+1,"none");
7063 break;
7064 }
7065 (void) QueryColorDatabase(argv[i+1],&image_info->transparent_color,
7066 exception);
7067 (void) SetImageOption(image_info,option+1,argv[i+1]);
7068 break;
7069 }
7070 if (LocaleCompare("type",option+1) == 0)
7071 {
7072 if (*option == '+')
7073 {
cristy5f1c1ff2010-12-23 21:38:06 +00007074 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007075 (void) SetImageOption(image_info,option+1,"undefined");
7076 break;
7077 }
cristy042ee782011-04-22 18:48:30 +00007078 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007079 MagickFalse,argv[i+1]);
7080 (void) SetImageOption(image_info,option+1,argv[i+1]);
7081 break;
7082 }
7083 break;
7084 }
7085 case 'u':
7086 {
7087 if (LocaleCompare("undercolor",option+1) == 0)
7088 {
7089 if (*option == '+')
7090 {
7091 (void) DeleteImageOption(image_info,option+1);
7092 break;
7093 }
7094 (void) SetImageOption(image_info,option+1,argv[i+1]);
7095 break;
7096 }
7097 if (LocaleCompare("units",option+1) == 0)
7098 {
7099 if (*option == '+')
7100 {
7101 image_info->units=UndefinedResolution;
7102 (void) SetImageOption(image_info,option+1,"undefined");
7103 break;
7104 }
cristy042ee782011-04-22 18:48:30 +00007105 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007106 MagickResolutionOptions,MagickFalse,argv[i+1]);
7107 (void) SetImageOption(image_info,option+1,argv[i+1]);
7108 break;
7109 }
7110 break;
7111 }
7112 case 'v':
7113 {
7114 if (LocaleCompare("verbose",option+1) == 0)
7115 {
7116 if (*option == '+')
7117 {
7118 image_info->verbose=MagickFalse;
7119 break;
7120 }
7121 image_info->verbose=MagickTrue;
7122 image_info->ping=MagickFalse;
7123 break;
7124 }
7125 if (LocaleCompare("view",option+1) == 0)
7126 {
7127 if (*option == '+')
7128 {
7129 if (image_info->view != (char *) NULL)
7130 image_info->view=DestroyString(image_info->view);
7131 break;
7132 }
7133 (void) CloneString(&image_info->view,argv[i+1]);
7134 break;
7135 }
7136 if (LocaleCompare("virtual-pixel",option+1) == 0)
7137 {
7138 if (*option == '+')
7139 {
7140 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7141 (void) SetImageOption(image_info,option+1,"undefined");
7142 break;
7143 }
7144 image_info->virtual_pixel_method=(VirtualPixelMethod)
cristy042ee782011-04-22 18:48:30 +00007145 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00007146 argv[i+1]);
7147 (void) SetImageOption(image_info,option+1,argv[i+1]);
7148 break;
7149 }
7150 break;
7151 }
7152 case 'w':
7153 {
7154 if (LocaleCompare("white-point",option+1) == 0)
7155 {
7156 if (*option == '+')
7157 {
7158 (void) SetImageOption(image_info,option+1,"0.0");
7159 break;
7160 }
7161 (void) SetImageOption(image_info,option+1,argv[i+1]);
7162 break;
7163 }
7164 break;
7165 }
7166 default:
7167 break;
7168 }
7169 i+=count;
7170 }
7171 return(MagickTrue);
7172}
7173
7174/*
7175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7176% %
7177% %
7178% %
7179+ M o g r i f y I m a g e L i s t %
7180% %
7181% %
7182% %
7183%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7184%
7185% MogrifyImageList() applies any command line options that might affect the
7186% entire image list (e.g. -append, -coalesce, etc.).
7187%
7188% The format of the MogrifyImage method is:
7189%
7190% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7191% const char **argv,Image **images,ExceptionInfo *exception)
7192%
7193% A description of each parameter follows:
7194%
7195% o image_info: the image info..
7196%
7197% o argc: Specifies a pointer to an integer describing the number of
7198% elements in the argument vector.
7199%
7200% o argv: Specifies a pointer to a text array containing the command line
7201% arguments.
7202%
anthonye9c27192011-03-27 08:07:06 +00007203% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007204%
7205% o exception: return any errors or warnings in this structure.
7206%
7207*/
7208WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7209 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7210{
cristy3ed852e2009-09-05 21:47:34 +00007211 const char
7212 *option;
7213
cristy6b3da3a2010-06-20 02:21:46 +00007214 ImageInfo
7215 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007216
7217 MagickStatusType
7218 status;
7219
7220 QuantizeInfo
7221 *quantize_info;
7222
cristybb503372010-05-27 20:51:26 +00007223 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007224 i;
7225
cristy6b3da3a2010-06-20 02:21:46 +00007226 ssize_t
7227 count,
7228 index;
7229
cristy3ed852e2009-09-05 21:47:34 +00007230 /*
7231 Apply options to the image list.
7232 */
7233 assert(image_info != (ImageInfo *) NULL);
7234 assert(image_info->signature == MagickSignature);
7235 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007236 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007237 assert((*images)->signature == MagickSignature);
7238 if ((*images)->debug != MagickFalse)
7239 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7240 (*images)->filename);
7241 if ((argc <= 0) || (*argv == (char *) NULL))
7242 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +00007243 mogrify_info=CloneImageInfo(image_info);
7244 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007245 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007246 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007247 {
cristy74fe8f12009-10-03 19:09:01 +00007248 if (*images == (Image *) NULL)
7249 break;
cristy3ed852e2009-09-05 21:47:34 +00007250 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007251 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007252 continue;
cristy042ee782011-04-22 18:48:30 +00007253 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007254 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007255 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007256 break;
cristy6b3da3a2010-06-20 02:21:46 +00007257 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007258 switch (*(option+1))
7259 {
7260 case 'a':
7261 {
7262 if (LocaleCompare("affinity",option+1) == 0)
7263 {
cristy6b3da3a2010-06-20 02:21:46 +00007264 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007265 if (*option == '+')
7266 {
7267 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7268 InheritException(exception,&(*images)->exception);
7269 break;
7270 }
7271 i++;
7272 break;
7273 }
7274 if (LocaleCompare("append",option+1) == 0)
7275 {
7276 Image
7277 *append_image;
7278
cristy6b3da3a2010-06-20 02:21:46 +00007279 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007280 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7281 MagickFalse,exception);
7282 if (append_image == (Image *) NULL)
7283 {
7284 status=MagickFalse;
7285 break;
7286 }
7287 *images=DestroyImageList(*images);
7288 *images=append_image;
7289 break;
7290 }
7291 if (LocaleCompare("average",option+1) == 0)
7292 {
7293 Image
7294 *average_image;
7295
cristyd18ae7c2010-03-07 17:39:52 +00007296 /*
7297 Average an image sequence (deprecated).
7298 */
cristy6b3da3a2010-06-20 02:21:46 +00007299 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007300 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7301 exception);
cristy3ed852e2009-09-05 21:47:34 +00007302 if (average_image == (Image *) NULL)
7303 {
7304 status=MagickFalse;
7305 break;
7306 }
7307 *images=DestroyImageList(*images);
7308 *images=average_image;
7309 break;
7310 }
7311 break;
7312 }
7313 case 'c':
7314 {
7315 if (LocaleCompare("channel",option+1) == 0)
7316 {
cristyf4ad9df2011-07-08 16:49:03 +00007317 ChannelType
7318 channel;
7319
cristy3ed852e2009-09-05 21:47:34 +00007320 if (*option == '+')
7321 {
7322 channel=DefaultChannels;
7323 break;
7324 }
7325 channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristyed231572011-07-14 02:18:59 +00007326 SetPixelChannelMap(*images,channel);
cristy3ed852e2009-09-05 21:47:34 +00007327 break;
7328 }
7329 if (LocaleCompare("clut",option+1) == 0)
7330 {
7331 Image
7332 *clut_image,
7333 *image;
7334
cristy6b3da3a2010-06-20 02:21:46 +00007335 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007336 image=RemoveFirstImageFromList(images);
7337 clut_image=RemoveFirstImageFromList(images);
7338 if (clut_image == (Image *) NULL)
7339 {
7340 status=MagickFalse;
7341 break;
7342 }
cristy444eda62011-08-10 02:07:46 +00007343 (void) ClutImage(image,clut_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007344 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007345 *images=DestroyImageList(*images);
7346 *images=image;
7347 break;
7348 }
7349 if (LocaleCompare("coalesce",option+1) == 0)
7350 {
7351 Image
7352 *coalesce_image;
7353
cristy6b3da3a2010-06-20 02:21:46 +00007354 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007355 coalesce_image=CoalesceImages(*images,exception);
7356 if (coalesce_image == (Image *) NULL)
7357 {
7358 status=MagickFalse;
7359 break;
7360 }
7361 *images=DestroyImageList(*images);
7362 *images=coalesce_image;
7363 break;
7364 }
7365 if (LocaleCompare("combine",option+1) == 0)
7366 {
7367 Image
7368 *combine_image;
7369
cristy6b3da3a2010-06-20 02:21:46 +00007370 (void) SyncImagesSettings(mogrify_info,*images);
cristy3139dc22011-07-08 00:11:42 +00007371 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007372 if (combine_image == (Image *) NULL)
7373 {
7374 status=MagickFalse;
7375 break;
7376 }
7377 *images=DestroyImageList(*images);
7378 *images=combine_image;
7379 break;
7380 }
7381 if (LocaleCompare("composite",option+1) == 0)
7382 {
7383 Image
7384 *mask_image,
7385 *composite_image,
7386 *image;
7387
7388 RectangleInfo
7389 geometry;
7390
cristy6b3da3a2010-06-20 02:21:46 +00007391 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007392 image=RemoveFirstImageFromList(images);
7393 composite_image=RemoveFirstImageFromList(images);
7394 if (composite_image == (Image *) NULL)
7395 {
7396 status=MagickFalse;
7397 break;
7398 }
7399 (void) TransformImage(&composite_image,(char *) NULL,
7400 composite_image->geometry);
7401 SetGeometry(composite_image,&geometry);
7402 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7403 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7404 &geometry);
7405 mask_image=RemoveFirstImageFromList(images);
7406 if (mask_image != (Image *) NULL)
7407 {
7408 if ((image->compose == DisplaceCompositeOp) ||
7409 (image->compose == DistortCompositeOp))
7410 {
7411 /*
7412 Merge Y displacement into X displacement image.
7413 */
7414 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7415 mask_image,0,0);
7416 mask_image=DestroyImage(mask_image);
7417 }
7418 else
7419 {
7420 /*
7421 Set a blending mask for the composition.
7422 */
anthonya129f702011-04-14 01:08:48 +00007423 /* POSIBLE ERROR; what if image->mask already set */
cristy3ed852e2009-09-05 21:47:34 +00007424 image->mask=mask_image;
cristyb3e7c6c2011-07-24 01:43:55 +00007425 (void) NegateImage(image->mask,MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007426 }
7427 }
cristyf4ad9df2011-07-08 16:49:03 +00007428 (void) CompositeImage(image,image->compose,composite_image,
7429 geometry.x,geometry.y);
anthonya129f702011-04-14 01:08:48 +00007430 if (mask_image != (Image *) NULL)
7431 mask_image=image->mask=DestroyImage(image->mask);
cristy3ed852e2009-09-05 21:47:34 +00007432 composite_image=DestroyImage(composite_image);
7433 InheritException(exception,&image->exception);
7434 *images=DestroyImageList(*images);
7435 *images=image;
7436 break;
7437 }
anthony9f4f0342011-03-28 11:47:22 +00007438#if 0
7439This has been merged completely into MogrifyImage()
cristy3ed852e2009-09-05 21:47:34 +00007440 if (LocaleCompare("crop",option+1) == 0)
7441 {
7442 MagickStatusType
7443 flags;
7444
7445 RectangleInfo
7446 geometry;
7447
anthonye9c27192011-03-27 08:07:06 +00007448 /*
anthony9f4f0342011-03-28 11:47:22 +00007449 Crop Image.
anthonye9c27192011-03-27 08:07:06 +00007450 */
cristy6b3da3a2010-06-20 02:21:46 +00007451 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007452 flags=ParseGravityGeometry(*images,argv[i+1],&geometry,exception);
7453 if (((geometry.width == 0) && (geometry.height == 0)) ||
7454 ((flags & XValue) != 0) || ((flags & YValue) != 0))
7455 break;
7456 (void) TransformImages(images,argv[i+1],(char *) NULL);
7457 InheritException(exception,&(*images)->exception);
7458 break;
7459 }
anthony9f4f0342011-03-28 11:47:22 +00007460#endif
cristy3ed852e2009-09-05 21:47:34 +00007461 break;
7462 }
7463 case 'd':
7464 {
7465 if (LocaleCompare("deconstruct",option+1) == 0)
7466 {
7467 Image
7468 *deconstruct_image;
7469
cristy6b3da3a2010-06-20 02:21:46 +00007470 (void) SyncImagesSettings(mogrify_info,*images);
cristy8a9106f2011-07-05 14:39:26 +00007471 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007472 exception);
cristy3ed852e2009-09-05 21:47:34 +00007473 if (deconstruct_image == (Image *) NULL)
7474 {
7475 status=MagickFalse;
7476 break;
7477 }
7478 *images=DestroyImageList(*images);
7479 *images=deconstruct_image;
7480 break;
7481 }
7482 if (LocaleCompare("delete",option+1) == 0)
7483 {
7484 if (*option == '+')
7485 DeleteImages(images,"-1",exception);
7486 else
7487 DeleteImages(images,argv[i+1],exception);
7488 break;
7489 }
7490 if (LocaleCompare("dither",option+1) == 0)
7491 {
7492 if (*option == '+')
7493 {
7494 quantize_info->dither=MagickFalse;
7495 break;
7496 }
7497 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007498 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007499 MagickDitherOptions,MagickFalse,argv[i+1]);
7500 break;
7501 }
cristyecb10ff2011-03-22 13:14:03 +00007502 if (LocaleCompare("duplicate",option+1) == 0)
7503 {
cristy72988482011-03-29 16:34:38 +00007504 Image
7505 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007506
anthony2b6bcae2011-03-23 13:05:34 +00007507 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007508 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7509 else
7510 {
7511 const char
7512 *p;
7513
anthony2b6bcae2011-03-23 13:05:34 +00007514 size_t
7515 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007516
anthony2b6bcae2011-03-23 13:05:34 +00007517 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007518 p=strchr(argv[i+1],',');
7519 if (p == (const char *) NULL)
7520 duplicate_images=DuplicateImages(*images,number_duplicates,
7521 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007522 else
cristy72988482011-03-29 16:34:38 +00007523 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7524 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007525 }
7526 AppendImageToList(images, duplicate_images);
7527 (void) SyncImagesSettings(mogrify_info,*images);
cristyecb10ff2011-03-22 13:14:03 +00007528 break;
7529 }
cristy3ed852e2009-09-05 21:47:34 +00007530 break;
7531 }
cristyd18ae7c2010-03-07 17:39:52 +00007532 case 'e':
7533 {
7534 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7535 {
7536 Image
7537 *evaluate_image;
7538
7539 MagickEvaluateOperator
7540 op;
7541
cristy6b3da3a2010-06-20 02:21:46 +00007542 (void) SyncImageSettings(mogrify_info,*images);
cristy042ee782011-04-22 18:48:30 +00007543 op=(MagickEvaluateOperator) ParseCommandOption(MagickEvaluateOptions,
cristyd18ae7c2010-03-07 17:39:52 +00007544 MagickFalse,argv[i+1]);
7545 evaluate_image=EvaluateImages(*images,op,exception);
7546 if (evaluate_image == (Image *) NULL)
7547 {
7548 status=MagickFalse;
7549 break;
7550 }
7551 *images=DestroyImageList(*images);
7552 *images=evaluate_image;
7553 break;
7554 }
7555 break;
7556 }
cristy3ed852e2009-09-05 21:47:34 +00007557 case 'f':
7558 {
cristyf0a247f2009-10-04 00:20:03 +00007559 if (LocaleCompare("fft",option+1) == 0)
7560 {
7561 Image
7562 *fourier_image;
7563
7564 /*
7565 Implements the discrete Fourier transform (DFT).
7566 */
cristy6b3da3a2010-06-20 02:21:46 +00007567 (void) SyncImageSettings(mogrify_info,*images);
cristyf0a247f2009-10-04 00:20:03 +00007568 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7569 MagickTrue : MagickFalse,exception);
7570 if (fourier_image == (Image *) NULL)
7571 break;
7572 *images=DestroyImage(*images);
7573 *images=fourier_image;
7574 break;
7575 }
cristy3ed852e2009-09-05 21:47:34 +00007576 if (LocaleCompare("flatten",option+1) == 0)
7577 {
7578 Image
7579 *flatten_image;
7580
cristy6b3da3a2010-06-20 02:21:46 +00007581 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007582 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7583 if (flatten_image == (Image *) NULL)
7584 break;
7585 *images=DestroyImageList(*images);
7586 *images=flatten_image;
7587 break;
7588 }
7589 if (LocaleCompare("fx",option+1) == 0)
7590 {
7591 Image
7592 *fx_image;
7593
cristy6b3da3a2010-06-20 02:21:46 +00007594 (void) SyncImagesSettings(mogrify_info,*images);
cristy490408a2011-07-07 14:42:05 +00007595 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007596 if (fx_image == (Image *) NULL)
7597 {
7598 status=MagickFalse;
7599 break;
7600 }
7601 *images=DestroyImageList(*images);
7602 *images=fx_image;
7603 break;
7604 }
7605 break;
7606 }
7607 case 'h':
7608 {
7609 if (LocaleCompare("hald-clut",option+1) == 0)
7610 {
7611 Image
7612 *hald_image,
7613 *image;
7614
cristy6b3da3a2010-06-20 02:21:46 +00007615 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007616 image=RemoveFirstImageFromList(images);
7617 hald_image=RemoveFirstImageFromList(images);
7618 if (hald_image == (Image *) NULL)
7619 {
7620 status=MagickFalse;
7621 break;
7622 }
cristy7c0a0a42011-08-23 17:57:25 +00007623 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007624 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007625 if (*images != (Image *) NULL)
7626 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007627 *images=image;
7628 break;
7629 }
7630 break;
7631 }
7632 case 'i':
7633 {
7634 if (LocaleCompare("ift",option+1) == 0)
7635 {
7636 Image
cristy8587f882009-11-13 20:28:49 +00007637 *fourier_image,
7638 *magnitude_image,
7639 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007640
7641 /*
7642 Implements the inverse fourier discrete Fourier transform (DFT).
7643 */
cristy6b3da3a2010-06-20 02:21:46 +00007644 (void) SyncImagesSettings(mogrify_info,*images);
cristy8587f882009-11-13 20:28:49 +00007645 magnitude_image=RemoveFirstImageFromList(images);
7646 phase_image=RemoveFirstImageFromList(images);
7647 if (phase_image == (Image *) NULL)
7648 {
7649 status=MagickFalse;
7650 break;
7651 }
7652 fourier_image=InverseFourierTransformImage(magnitude_image,
7653 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007654 if (fourier_image == (Image *) NULL)
7655 break;
cristy0aff6ea2009-11-14 01:40:53 +00007656 if (*images != (Image *) NULL)
7657 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007658 *images=fourier_image;
7659 break;
7660 }
7661 if (LocaleCompare("insert",option+1) == 0)
7662 {
7663 Image
7664 *p,
7665 *q;
7666
7667 index=0;
7668 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007669 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007670 p=RemoveLastImageFromList(images);
7671 if (p == (Image *) NULL)
7672 {
7673 (void) ThrowMagickException(exception,GetMagickModule(),
7674 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7675 status=MagickFalse;
7676 break;
7677 }
7678 q=p;
7679 if (index == 0)
7680 PrependImageToList(images,q);
7681 else
cristybb503372010-05-27 20:51:26 +00007682 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007683 AppendImageToList(images,q);
7684 else
7685 {
7686 q=GetImageFromList(*images,index-1);
7687 if (q == (Image *) NULL)
7688 {
7689 (void) ThrowMagickException(exception,GetMagickModule(),
7690 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7691 status=MagickFalse;
7692 break;
7693 }
7694 InsertImageInList(&q,p);
7695 }
7696 *images=GetFirstImageInList(q);
7697 break;
7698 }
7699 break;
7700 }
7701 case 'l':
7702 {
7703 if (LocaleCompare("layers",option+1) == 0)
7704 {
7705 Image
7706 *layers;
7707
7708 ImageLayerMethod
7709 method;
7710
cristy6b3da3a2010-06-20 02:21:46 +00007711 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007712 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007713 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007714 MagickFalse,argv[i+1]);
7715 switch (method)
7716 {
7717 case CoalesceLayer:
7718 {
7719 layers=CoalesceImages(*images,exception);
7720 break;
7721 }
7722 case CompareAnyLayer:
7723 case CompareClearLayer:
7724 case CompareOverlayLayer:
7725 default:
7726 {
cristy8a9106f2011-07-05 14:39:26 +00007727 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007728 break;
7729 }
7730 case MergeLayer:
7731 case FlattenLayer:
7732 case MosaicLayer:
7733 case TrimBoundsLayer:
7734 {
7735 layers=MergeImageLayers(*images,method,exception);
7736 break;
7737 }
7738 case DisposeLayer:
7739 {
7740 layers=DisposeImages(*images,exception);
7741 break;
7742 }
7743 case OptimizeImageLayer:
7744 {
7745 layers=OptimizeImageLayers(*images,exception);
7746 break;
7747 }
7748 case OptimizePlusLayer:
7749 {
7750 layers=OptimizePlusImageLayers(*images,exception);
7751 break;
7752 }
7753 case OptimizeTransLayer:
7754 {
7755 OptimizeImageTransparency(*images,exception);
7756 break;
7757 }
7758 case RemoveDupsLayer:
7759 {
7760 RemoveDuplicateLayers(images,exception);
7761 break;
7762 }
7763 case RemoveZeroLayer:
7764 {
7765 RemoveZeroDelayLayers(images,exception);
7766 break;
7767 }
7768 case OptimizeLayer:
7769 {
7770 /*
7771 General Purpose, GIF Animation Optimizer.
7772 */
7773 layers=CoalesceImages(*images,exception);
7774 if (layers == (Image *) NULL)
7775 {
7776 status=MagickFalse;
7777 break;
7778 }
7779 InheritException(exception,&layers->exception);
7780 *images=DestroyImageList(*images);
7781 *images=layers;
7782 layers=OptimizeImageLayers(*images,exception);
7783 if (layers == (Image *) NULL)
7784 {
7785 status=MagickFalse;
7786 break;
7787 }
7788 InheritException(exception,&layers->exception);
7789 *images=DestroyImageList(*images);
7790 *images=layers;
7791 layers=(Image *) NULL;
7792 OptimizeImageTransparency(*images,exception);
7793 InheritException(exception,&(*images)->exception);
7794 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7795 break;
7796 }
7797 case CompositeLayer:
7798 {
7799 CompositeOperator
7800 compose;
7801
7802 Image
7803 *source;
7804
7805 RectangleInfo
7806 geometry;
7807
7808 /*
7809 Split image sequence at the first 'NULL:' image.
7810 */
7811 source=(*images);
7812 while (source != (Image *) NULL)
7813 {
7814 source=GetNextImageInList(source);
7815 if ((source != (Image *) NULL) &&
7816 (LocaleCompare(source->magick,"NULL") == 0))
7817 break;
7818 }
7819 if (source != (Image *) NULL)
7820 {
7821 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7822 (GetNextImageInList(source) == (Image *) NULL))
7823 source=(Image *) NULL;
7824 else
7825 {
7826 /*
7827 Separate the two lists, junk the null: image.
7828 */
7829 source=SplitImageList(source->previous);
7830 DeleteImageFromList(&source);
7831 }
7832 }
7833 if (source == (Image *) NULL)
7834 {
7835 (void) ThrowMagickException(exception,GetMagickModule(),
7836 OptionError,"MissingNullSeparator","layers Composite");
7837 status=MagickFalse;
7838 break;
7839 }
7840 /*
7841 Adjust offset with gravity and virtual canvas.
7842 */
7843 SetGeometry(*images,&geometry);
7844 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7845 geometry.width=source->page.width != 0 ?
7846 source->page.width : source->columns;
7847 geometry.height=source->page.height != 0 ?
7848 source->page.height : source->rows;
7849 GravityAdjustGeometry((*images)->page.width != 0 ?
7850 (*images)->page.width : (*images)->columns,
7851 (*images)->page.height != 0 ? (*images)->page.height :
7852 (*images)->rows,(*images)->gravity,&geometry);
7853 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007854 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007855 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007856 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007857 MagickComposeOptions,MagickFalse,option);
7858 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7859 exception);
7860 source=DestroyImageList(source);
7861 break;
7862 }
7863 }
7864 if (layers == (Image *) NULL)
7865 break;
7866 InheritException(exception,&layers->exception);
7867 *images=DestroyImageList(*images);
7868 *images=layers;
7869 break;
7870 }
7871 break;
7872 }
7873 case 'm':
7874 {
7875 if (LocaleCompare("map",option+1) == 0)
7876 {
cristy6b3da3a2010-06-20 02:21:46 +00007877 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007878 if (*option == '+')
7879 {
7880 (void) RemapImages(quantize_info,*images,(Image *) NULL);
7881 InheritException(exception,&(*images)->exception);
7882 break;
7883 }
7884 i++;
7885 break;
7886 }
cristyf40785b2010-03-06 02:27:27 +00007887 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007888 {
7889 Image
cristyf40785b2010-03-06 02:27:27 +00007890 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007891
cristyd18ae7c2010-03-07 17:39:52 +00007892 /*
7893 Maximum image sequence (deprecated).
7894 */
cristy6b3da3a2010-06-20 02:21:46 +00007895 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007896 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007897 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007898 {
7899 status=MagickFalse;
7900 break;
7901 }
7902 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007903 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007904 break;
7905 }
cristyf40785b2010-03-06 02:27:27 +00007906 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007907 {
7908 Image
cristyf40785b2010-03-06 02:27:27 +00007909 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007910
cristyd18ae7c2010-03-07 17:39:52 +00007911 /*
7912 Minimum image sequence (deprecated).
7913 */
cristy6b3da3a2010-06-20 02:21:46 +00007914 (void) SyncImagesSettings(mogrify_info,*images);
cristyd18ae7c2010-03-07 17:39:52 +00007915 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007916 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007917 {
7918 status=MagickFalse;
7919 break;
7920 }
7921 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007922 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007923 break;
7924 }
cristy3ed852e2009-09-05 21:47:34 +00007925 if (LocaleCompare("morph",option+1) == 0)
7926 {
7927 Image
7928 *morph_image;
7929
cristy6b3da3a2010-06-20 02:21:46 +00007930 (void) SyncImagesSettings(mogrify_info,*images);
cristye27293e2009-12-18 02:53:20 +00007931 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007932 exception);
7933 if (morph_image == (Image *) NULL)
7934 {
7935 status=MagickFalse;
7936 break;
7937 }
7938 *images=DestroyImageList(*images);
7939 *images=morph_image;
7940 break;
7941 }
7942 if (LocaleCompare("mosaic",option+1) == 0)
7943 {
7944 Image
7945 *mosaic_image;
7946
cristy6b3da3a2010-06-20 02:21:46 +00007947 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007948 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7949 if (mosaic_image == (Image *) NULL)
7950 {
7951 status=MagickFalse;
7952 break;
7953 }
7954 *images=DestroyImageList(*images);
7955 *images=mosaic_image;
7956 break;
7957 }
7958 break;
7959 }
7960 case 'p':
7961 {
7962 if (LocaleCompare("print",option+1) == 0)
7963 {
7964 char
7965 *string;
7966
cristy6b3da3a2010-06-20 02:21:46 +00007967 (void) SyncImagesSettings(mogrify_info,*images);
7968 string=InterpretImageProperties(mogrify_info,*images,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007969 if (string == (char *) NULL)
7970 break;
7971 InheritException(exception,&(*images)->exception);
cristyb51dff52011-05-19 16:55:47 +00007972 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007973 string=DestroyString(string);
7974 }
7975 if (LocaleCompare("process",option+1) == 0)
7976 {
7977 char
7978 **arguments;
7979
7980 int
7981 j,
7982 number_arguments;
7983
cristy6b3da3a2010-06-20 02:21:46 +00007984 (void) SyncImagesSettings(mogrify_info,*images);
cristy3ed852e2009-09-05 21:47:34 +00007985 arguments=StringToArgv(argv[i+1],&number_arguments);
7986 if (arguments == (char **) NULL)
7987 break;
7988 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7989 {
7990 char
7991 breaker,
7992 quote,
7993 *token;
7994
7995 const char
7996 *arguments;
7997
7998 int
7999 next,
8000 status;
8001
8002 size_t
8003 length;
8004
8005 TokenInfo
8006 *token_info;
8007
8008 /*
8009 Support old style syntax, filter="-option arg".
8010 */
8011 length=strlen(argv[i+1]);
8012 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008013 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008014 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8015 sizeof(*token));
8016 if (token == (char *) NULL)
8017 break;
8018 next=0;
8019 arguments=argv[i+1];
8020 token_info=AcquireTokenInfo();
8021 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8022 "\"",'\0',&breaker,&next,&quote);
8023 token_info=DestroyTokenInfo(token_info);
8024 if (status == 0)
8025 {
8026 const char
8027 *argv;
8028
8029 argv=(&(arguments[next]));
8030 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8031 exception);
8032 }
8033 token=DestroyString(token);
8034 break;
8035 }
cristy91c0da22010-05-02 01:44:07 +00008036 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008037 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8038 number_arguments-2,(const char **) arguments+2,exception);
8039 for (j=0; j < number_arguments; j++)
8040 arguments[j]=DestroyString(arguments[j]);
8041 arguments=(char **) RelinquishMagickMemory(arguments);
8042 break;
8043 }
8044 break;
8045 }
8046 case 'r':
8047 {
8048 if (LocaleCompare("reverse",option+1) == 0)
8049 {
8050 ReverseImageList(images);
8051 InheritException(exception,&(*images)->exception);
8052 break;
8053 }
8054 break;
8055 }
8056 case 's':
8057 {
cristy4285d782011-02-09 20:12:28 +00008058 if (LocaleCompare("smush",option+1) == 0)
8059 {
8060 Image
8061 *smush_image;
8062
8063 ssize_t
8064 offset;
8065
8066 (void) SyncImagesSettings(mogrify_info,*images);
8067 offset=(ssize_t) StringToLong(argv[i+1]);
8068 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8069 MagickFalse,offset,exception);
8070 if (smush_image == (Image *) NULL)
8071 {
8072 status=MagickFalse;
8073 break;
8074 }
8075 *images=DestroyImageList(*images);
8076 *images=smush_image;
8077 break;
8078 }
cristy3ed852e2009-09-05 21:47:34 +00008079 if (LocaleCompare("swap",option+1) == 0)
8080 {
8081 Image
8082 *p,
8083 *q,
8084 *swap;
8085
cristybb503372010-05-27 20:51:26 +00008086 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008087 swap_index;
8088
8089 index=(-1);
8090 swap_index=(-2);
8091 if (*option != '+')
8092 {
8093 GeometryInfo
8094 geometry_info;
8095
8096 MagickStatusType
8097 flags;
8098
8099 swap_index=(-1);
8100 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008101 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008102 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008103 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008104 }
8105 p=GetImageFromList(*images,index);
8106 q=GetImageFromList(*images,swap_index);
8107 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8108 {
8109 (void) ThrowMagickException(exception,GetMagickModule(),
8110 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8111 status=MagickFalse;
8112 break;
8113 }
8114 if (p == q)
8115 break;
8116 swap=CloneImage(p,0,0,MagickTrue,exception);
8117 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8118 ReplaceImageInList(&q,swap);
8119 *images=GetFirstImageInList(q);
8120 break;
8121 }
8122 break;
8123 }
8124 case 'w':
8125 {
8126 if (LocaleCompare("write",option+1) == 0)
8127 {
cristy071dd7b2010-04-09 13:04:54 +00008128 char
cristy06609ee2010-03-17 20:21:27 +00008129 key[MaxTextExtent];
8130
cristy3ed852e2009-09-05 21:47:34 +00008131 Image
8132 *write_images;
8133
8134 ImageInfo
8135 *write_info;
8136
cristy6b3da3a2010-06-20 02:21:46 +00008137 (void) SyncImagesSettings(mogrify_info,*images);
cristyb51dff52011-05-19 16:55:47 +00008138 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008139 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008140 write_images=(*images);
8141 if (*option == '+')
8142 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008143 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008144 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8145 write_info=DestroyImageInfo(write_info);
8146 if (*option == '+')
8147 write_images=DestroyImageList(write_images);
8148 break;
8149 }
8150 break;
8151 }
8152 default:
8153 break;
8154 }
8155 i+=count;
8156 }
8157 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008158 mogrify_info=DestroyImageInfo(mogrify_info);
8159 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008160 return(status != 0 ? MagickTrue : MagickFalse);
8161}
8162
8163/*
8164%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8165% %
8166% %
8167% %
8168+ M o g r i f y I m a g e s %
8169% %
8170% %
8171% %
8172%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8173%
8174% MogrifyImages() applies image processing options to a sequence of images as
8175% prescribed by command line options.
8176%
8177% The format of the MogrifyImage method is:
8178%
8179% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8180% const MagickBooleanType post,const int argc,const char **argv,
8181% Image **images,Exceptioninfo *exception)
8182%
8183% A description of each parameter follows:
8184%
8185% o image_info: the image info..
8186%
8187% o post: If true, post process image list operators otherwise pre-process.
8188%
8189% o argc: Specifies a pointer to an integer describing the number of
8190% elements in the argument vector.
8191%
8192% o argv: Specifies a pointer to a text array containing the command line
8193% arguments.
8194%
anthonye9c27192011-03-27 08:07:06 +00008195% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008196%
8197% o exception: return any errors or warnings in this structure.
8198%
8199*/
8200WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8201 const MagickBooleanType post,const int argc,const char **argv,
8202 Image **images,ExceptionInfo *exception)
8203{
8204#define MogrifyImageTag "Mogrify/Image"
8205
anthonye9c27192011-03-27 08:07:06 +00008206 MagickStatusType
8207 status;
cristy3ed852e2009-09-05 21:47:34 +00008208
cristy0e9f9c12010-02-11 03:00:47 +00008209 MagickBooleanType
8210 proceed;
8211
anthonye9c27192011-03-27 08:07:06 +00008212 size_t
8213 n;
cristy3ed852e2009-09-05 21:47:34 +00008214
cristybb503372010-05-27 20:51:26 +00008215 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008216 i;
8217
cristy3ed852e2009-09-05 21:47:34 +00008218 assert(image_info != (ImageInfo *) NULL);
8219 assert(image_info->signature == MagickSignature);
8220 if (images == (Image **) NULL)
8221 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008222 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008223 assert((*images)->signature == MagickSignature);
8224 if ((*images)->debug != MagickFalse)
8225 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8226 (*images)->filename);
8227 if ((argc <= 0) || (*argv == (char *) NULL))
8228 return(MagickTrue);
8229 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8230 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008231 status=0;
anthonye9c27192011-03-27 08:07:06 +00008232
anthonyce2716b2011-04-22 09:51:34 +00008233#if 0
cristy1e604812011-05-19 18:07:50 +00008234 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8235 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008236#endif
8237
anthonye9c27192011-03-27 08:07:06 +00008238 /*
8239 Pre-process multi-image sequence operators
8240 */
cristy3ed852e2009-09-05 21:47:34 +00008241 if (post == MagickFalse)
8242 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008243 /*
8244 For each image, process simple single image operators
8245 */
8246 i=0;
8247 n=GetImageListLength(*images);
8248 for (;;)
cristy3ed852e2009-09-05 21:47:34 +00008249 {
anthonyce2716b2011-04-22 09:51:34 +00008250#if 0
cristy1e604812011-05-19 18:07:50 +00008251 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8252 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008253#endif
anthonye9c27192011-03-27 08:07:06 +00008254 status&=MogrifyImage(image_info,argc,argv,images,exception);
8255 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008256 if (proceed == MagickFalse)
8257 break;
anthonye9c27192011-03-27 08:07:06 +00008258 if ( (*images)->next == (Image *) NULL )
8259 break;
8260 *images=(*images)->next;
8261 i++;
cristy3ed852e2009-09-05 21:47:34 +00008262 }
anthonye9c27192011-03-27 08:07:06 +00008263 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008264#if 0
cristy1e604812011-05-19 18:07:50 +00008265 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8266 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008267#endif
anthonye9c27192011-03-27 08:07:06 +00008268
8269 /*
8270 Post-process, multi-image sequence operators
8271 */
8272 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008273 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008274 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008275 return(status != 0 ? MagickTrue : MagickFalse);
8276}