blob: a9cb15c9b42b0163bce06c89d1ff3beeb31650dd [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% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 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"
cristy4c08aed2011-07-01 19:47:50 +000054#include "MagickCore/string-private.h"
cristy0740a982011-10-13 15:01:01 +000055#include "MagickCore/thread-private.h"
cristy18c6c272011-09-23 14:40:37 +000056#include "MagickCore/utility-private.h"
cristy3ed852e2009-09-05 21:47:34 +000057
58/*
cristy154fa9d2011-08-05 14:25:15 +000059 Constant declaration.
60*/
cristy3a557c02011-08-06 19:48:02 +000061static const char
cristy638895a2011-08-06 23:19:14 +000062 MogrifyBackgroundColor[] = "#ffffff", /* white */
63 MogrifyBorderColor[] = "#dfdfdf", /* gray */
64 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000065
66/*
cristy3ed852e2009-09-05 21:47:34 +000067 Define declarations.
68*/
69#define UndefinedCompressionQuality 0UL
70
71/*
cristy3ed852e2009-09-05 21:47:34 +000072%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73% %
74% %
75% %
cristy5063d812010-10-19 16:28:10 +000076% 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 +000077% %
78% %
79% %
80%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81%
82% MagickCommandGenesis() applies image processing options to an image as
83% prescribed by command line options.
84%
85% The format of the MagickCommandGenesis method is:
86%
87% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000088% MagickCommand command,int argc,char **argv,char **metadata,
89% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000090%
91% A description of each parameter follows:
92%
93% o image_info: the image info.
94%
cristy5063d812010-10-19 16:28:10 +000095% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000096% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000097% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
98% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000099%
100% o argc: Specifies a pointer to an integer describing the number of
101% elements in the argument vector.
102%
103% o argv: Specifies a pointer to a text array containing the command line
104% arguments.
105%
cristy5063d812010-10-19 16:28:10 +0000106% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000107%
108% o exception: return any errors or warnings in this structure.
109%
110*/
111WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
112 MagickCommand command,int argc,char **argv,char **metadata,
113 ExceptionInfo *exception)
114{
115 char
116 *option;
117
118 double
119 duration,
cristy8ea926d2011-12-09 12:25:04 +0000120 serial;
cristy3980b0d2009-10-25 14:37:13 +0000121
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
cristybb503372010-05-27 20:51:26 +0000130 size_t
cristyc2e3aeb2011-12-09 11:09:38 +0000131 iterations,
cristyc2e3aeb2011-12-09 11:09:38 +0000132 number_threads;
cristy3980b0d2009-10-25 14:37:13 +0000133
cristy118fc662012-02-11 00:02:25 +0000134 ssize_t
135 n;
136
cristyd0a94fa2010-03-12 14:18:11 +0000137 (void) setlocale(LC_ALL,"");
138 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000139 concurrent=MagickFalse;
140 duration=(-1.0);
141 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000142 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000143 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000144 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000145 {
146 option=argv[i];
147 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
148 continue;
149 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000150 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000151 if (LocaleCompare("concurrent",option+1) == 0)
152 concurrent=MagickTrue;
153 if (LocaleCompare("debug",option+1) == 0)
154 (void) SetLogEventMask(argv[++i]);
155 if (LocaleCompare("duration",option+1) == 0)
cristydbdd0e32011-11-04 23:29:40 +0000156 duration=StringToDouble(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000157 if (LocaleCompare("regard-warnings",option+1) == 0)
158 regard_warnings=MagickTrue;
159 }
cristy8ea926d2011-12-09 12:25:04 +0000160 if (iterations == 1)
161 {
162 status=command(image_info,argc,argv,metadata,exception);
163 if (exception->severity != UndefinedException)
164 {
165 if ((exception->severity > ErrorException) ||
166 (regard_warnings != MagickFalse))
167 status=MagickTrue;
168 CatchException(exception);
169 }
170 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
171 {
172 (void) fputs(*metadata,stdout);
173 (void) fputc('\n',stdout);
174 *metadata=DestroyString(*metadata);
175 }
176 return(status);
177 }
cristyc2e3aeb2011-12-09 11:09:38 +0000178 number_threads=GetOpenMPMaximumThreads();
cristy8ea926d2011-12-09 12:25:04 +0000179 serial=0.0;
cristy118fc662012-02-11 00:02:25 +0000180 for (n=1; n <= (ssize_t) number_threads; n++)
cristyc2e3aeb2011-12-09 11:09:38 +0000181 {
182 double
cristy8ea926d2011-12-09 12:25:04 +0000183 e,
184 parallel,
cristyc2e3aeb2011-12-09 11:09:38 +0000185 user_time;
186
187 TimerInfo
188 *timer;
189
cristy118fc662012-02-11 00:02:25 +0000190 SetOpenMPMaximumThreads((int) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000191 timer=AcquireTimerInfo();
192 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000193 {
cristyc2e3aeb2011-12-09 11:09:38 +0000194 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000195 {
cristyc2e3aeb2011-12-09 11:09:38 +0000196 if (status != MagickFalse)
197 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);
cristyceae09d2009-10-28 17:18:47 +0000205 if (exception->severity != UndefinedException)
206 {
207 if ((exception->severity > ErrorException) ||
208 (regard_warnings != MagickFalse))
209 status=MagickTrue;
210 CatchException(exception);
211 }
212 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
213 {
214 (void) fputs(*metadata,stdout);
215 (void) fputc('\n',stdout);
216 *metadata=DestroyString(*metadata);
217 }
218 }
219 }
cristyc2e3aeb2011-12-09 11:09:38 +0000220 else
221 {
222 SetOpenMPNested(1);
223#if defined(MAGICKCORE_OPENMP_SUPPORT)
224 # pragma omp parallel for shared(status)
225#endif
226 for (i=0; i < (ssize_t) iterations; i++)
227 {
228 if (status != MagickFalse)
229 continue;
230 if (duration > 0)
231 {
232 if (GetElapsedTime(timer) > duration)
233 continue;
234 (void) ContinueTimer(timer);
235 }
236 status=command(image_info,argc,argv,metadata,exception);
237#if defined(MAGICKCORE_OPENMP_SUPPORT)
238 # pragma omp critical (MagickCore_CommandGenesis)
239#endif
240 {
241 if (exception->severity != UndefinedException)
242 {
243 if ((exception->severity > ErrorException) ||
244 (regard_warnings != MagickFalse))
245 status=MagickTrue;
246 CatchException(exception);
247 }
248 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
249 {
250 (void) fputs(*metadata,stdout);
251 (void) fputc('\n',stdout);
252 *metadata=DestroyString(*metadata);
253 }
254 }
255 }
256 }
cristyc2e3aeb2011-12-09 11:09:38 +0000257 user_time=GetUserTime(timer);
cristy8ea926d2011-12-09 12:25:04 +0000258 parallel=GetElapsedTime(timer);
259 e=1.0;
260 if (n == 1)
261 serial=parallel;
262 else
263 e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
264 (double) n)))-(1.0/(double) n))/(1.0-1.0/(double) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000265 (void) FormatLocaleFile(stderr,
cristy91ce84d2011-12-09 23:02:25 +0000266 "Performance[%.20g]: %.20gi %0.3fips %0.3fe %0.3fu %lu:%02lu.%03lu\n",
cristy8ea926d2011-12-09 12:25:04 +0000267 (double) n,(double) iterations,(double) iterations/parallel,e,
268 user_time,(unsigned long) (parallel/60.0),(unsigned long)
269 floor(fmod(parallel,60.0)),(unsigned long)
270 (1000.0*(parallel-floor(parallel))+0.5));
cristyc2e3aeb2011-12-09 11:09:38 +0000271 timer=DestroyTimerInfo(timer);
272 }
cristy1f9e1ed2009-11-18 04:09:38 +0000273 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000274}
275
276/*
277%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278% %
279% %
280% %
cristy3ed852e2009-09-05 21:47:34 +0000281+ M o g r i f y I m a g e %
282% %
283% %
284% %
285%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286%
anthonye9c27192011-03-27 08:07:06 +0000287% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000288% image that may be part of a large list, but also handles any 'region'
289% image handling.
anthonye9c27192011-03-27 08:07:06 +0000290%
291% The image in the list may be modified in three different ways...
292%
293% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
294% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
295% * replace by a list of images (only the -separate option!)
296%
297% In each case the result is returned into the list, and a pointer to the
298% modified image (last image added if replaced by a list of images) is
299% returned.
300%
301% ASIDE: The -crop is present but restricted to non-tile single image crops
302%
303% This means if all the images are being processed (such as by
304% MogrifyImages(), next image to be processed will be as per the pointer
305% (*image)->next. Also the image list may grow as a result of some specific
306% operations but as images are never merged or deleted, it will never shrink
307% in length. Typically the list will remain the same length.
308%
309% WARNING: As the image pointed to may be replaced, the first image in the
310% list may also change. GetFirstImageInList() should be used by caller if
311% they wish return the Image pointer to the first image in list.
312%
cristy3ed852e2009-09-05 21:47:34 +0000313%
314% The format of the MogrifyImage method is:
315%
316% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
317% const char **argv,Image **image)
318%
319% A description of each parameter follows:
320%
321% o image_info: the image info..
322%
323% o argc: Specifies a pointer to an integer describing the number of
324% elements in the argument vector.
325%
326% o argv: Specifies a pointer to a text array containing the command line
327% arguments.
328%
329% o image: the image.
330%
331% o exception: return any errors or warnings in this structure.
332%
333*/
334
anthonydf8ebac2011-04-27 09:03:19 +0000335static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
336 ExceptionInfo *exception)
337{
338 char
339 key[MaxTextExtent];
340
341 ExceptionInfo
342 *sans_exception;
343
344 Image
345 *image;
346
347 ImageInfo
348 *read_info;
349
cristyfcd785b2011-11-08 01:48:33 +0000350 /*
351 Read an image into a image cache if not already present. Return the image
352 that is in the cache under that filename.
353 */
cristyb51dff52011-05-19 16:55:47 +0000354 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000355 sans_exception=AcquireExceptionInfo();
356 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
357 sans_exception=DestroyExceptionInfo(sans_exception);
358 if (image != (Image *) NULL)
359 return(image);
360 read_info=CloneImageInfo(image_info);
361 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
362 image=ReadImage(read_info,exception);
363 read_info=DestroyImageInfo(read_info);
364 if (image != (Image *) NULL)
365 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
366 return(image);
367}
368
cristy3ed852e2009-09-05 21:47:34 +0000369static MagickBooleanType IsPathWritable(const char *path)
370{
371 if (IsPathAccessible(path) == MagickFalse)
372 return(MagickFalse);
cristy18c6c272011-09-23 14:40:37 +0000373 if (access_utf8(path,W_OK) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000374 return(MagickFalse);
375 return(MagickTrue);
376}
377
cristybb503372010-05-27 20:51:26 +0000378static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000379{
380 if (x > y)
381 return(x);
382 return(y);
383}
384
anthonydf8ebac2011-04-27 09:03:19 +0000385static MagickBooleanType MonitorProgress(const char *text,
386 const MagickOffsetType offset,const MagickSizeType extent,
387 void *wand_unused(client_data))
388{
389 char
390 message[MaxTextExtent],
391 tag[MaxTextExtent];
392
393 const char
394 *locale_message;
395
396 register char
397 *p;
398
399 if (extent < 2)
400 return(MagickTrue);
401 (void) CopyMagickMemory(tag,text,MaxTextExtent);
402 p=strrchr(tag,'/');
403 if (p != (char *) NULL)
404 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000405 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000406 locale_message=GetLocaleMessage(message);
407 if (locale_message == message)
408 locale_message=tag;
409 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000410 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
411 locale_message,(long) offset,(unsigned long) extent,(long)
412 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000413 else
cristyb51dff52011-05-19 16:55:47 +0000414 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000415 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
416 (100L*offset/(extent-1)));
417 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000418 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000419 (void) fflush(stderr);
420 return(MagickTrue);
421}
422
cristy3884f692011-07-08 18:00:18 +0000423static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000424 const SparseColorMethod method,const char *arguments,
425 const MagickBooleanType color_from_image,ExceptionInfo *exception)
426{
anthonydf8ebac2011-04-27 09:03:19 +0000427 char
428 token[MaxTextExtent];
429
430 const char
431 *p;
432
433 double
434 *sparse_arguments;
435
anthonydf8ebac2011-04-27 09:03:19 +0000436 Image
437 *sparse_image;
438
cristy4c08aed2011-07-01 19:47:50 +0000439 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000440 color;
441
442 MagickBooleanType
443 error;
444
cristy5f09d852011-05-29 01:39:29 +0000445 register size_t
446 x;
447
448 size_t
449 number_arguments,
450 number_colors;
451
cristyf4425a72011-11-08 01:52:04 +0000452 /*
453 SparseColorOption() parses the complex -sparse-color argument into an an
454 array of floating point values then calls SparseColorImage(). Argument is
455 a complex mix of floating-point pixel coodinates, and color specifications
456 (or direct floating point numbers). The number of floats needed to
457 represent a color varies depending on the current channel setting.
458 */
anthonydf8ebac2011-04-27 09:03:19 +0000459 assert(image != (Image *) NULL);
460 assert(image->signature == MagickSignature);
461 if (image->debug != MagickFalse)
462 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
463 assert(exception != (ExceptionInfo *) NULL);
464 assert(exception->signature == MagickSignature);
465 /*
466 Limit channels according to image - and add up number of color channel.
467 */
anthonydf8ebac2011-04-27 09:03:19 +0000468 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000469 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000470 number_colors++;
cristyed231572011-07-14 02:18:59 +0000471 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000472 number_colors++;
cristyed231572011-07-14 02:18:59 +0000473 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000474 number_colors++;
cristyed231572011-07-14 02:18:59 +0000475 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000476 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000477 number_colors++;
cristyed231572011-07-14 02:18:59 +0000478 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000479 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000480 number_colors++;
481
482 /*
483 Read string, to determine number of arguments needed,
484 */
485 p=arguments;
486 x=0;
487 while( *p != '\0' )
488 {
489 GetMagickToken(p,&p,token);
490 if ( token[0] == ',' ) continue;
491 if ( isalpha((int) token[0]) || token[0] == '#' ) {
492 if ( color_from_image ) {
493 (void) ThrowMagickException(exception,GetMagickModule(),
494 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
495 "Color arg given, when colors are coming from image");
496 return( (Image *)NULL);
497 }
498 x += number_colors; /* color argument */
499 }
500 else {
501 x++; /* floating point argument */
502 }
503 }
504 error=MagickTrue;
505 if ( color_from_image ) {
506 /* just the control points are being given */
507 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
508 number_arguments=(x/2)*(2+number_colors);
509 }
510 else {
511 /* control points and color values */
512 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
513 number_arguments=x;
514 }
515 if ( error ) {
516 (void) ThrowMagickException(exception,GetMagickModule(),
517 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
518 "Invalid number of Arguments");
519 return( (Image *)NULL);
520 }
521
522 /* Allocate and fill in the floating point arguments */
523 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
524 sizeof(*sparse_arguments));
525 if (sparse_arguments == (double *) NULL) {
526 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
527 "MemoryAllocationFailed","%s","SparseColorOption");
528 return( (Image *)NULL);
529 }
530 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
531 sizeof(*sparse_arguments));
532 p=arguments;
533 x=0;
534 while( *p != '\0' && x < number_arguments ) {
535 /* X coordinate */
536 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
537 if ( token[0] == '\0' ) break;
538 if ( isalpha((int) token[0]) || token[0] == '#' ) {
539 (void) ThrowMagickException(exception,GetMagickModule(),
540 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
541 "Color found, instead of X-coord");
542 error = MagickTrue;
543 break;
544 }
cristydbdd0e32011-11-04 23:29:40 +0000545 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000546 /* Y coordinate */
547 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
548 if ( token[0] == '\0' ) break;
549 if ( isalpha((int) token[0]) || token[0] == '#' ) {
550 (void) ThrowMagickException(exception,GetMagickModule(),
551 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
552 "Color found, instead of Y-coord");
553 error = MagickTrue;
554 break;
555 }
cristydbdd0e32011-11-04 23:29:40 +0000556 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000557 /* color values for this control point */
558#if 0
559 if ( (color_from_image ) {
560 /* get color from image */
561 /* HOW??? */
562 }
563 else
564#endif
565 {
566 /* color name or function given in string argument */
567 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
568 if ( token[0] == '\0' ) break;
569 if ( isalpha((int) token[0]) || token[0] == '#' ) {
570 /* Color string given */
cristy269c9412011-10-13 23:41:15 +0000571 (void) QueryColorCompliance(token,AllCompliance,&color,exception);
cristyed231572011-07-14 02:18:59 +0000572 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000573 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000574 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000575 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000576 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000577 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000578 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000579 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000580 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000581 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000582 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000583 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000584 }
585 else {
586 /* Colors given as a set of floating point values - experimental */
587 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000588 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000589 {
anthonydf8ebac2011-04-27 09:03:19 +0000590 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
591 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
592 break;
cristydbdd0e32011-11-04 23:29:40 +0000593 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000594 token[0] = ','; /* used this token - get another */
595 }
cristyed231572011-07-14 02:18:59 +0000596 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000597 {
anthonydf8ebac2011-04-27 09:03:19 +0000598 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
599 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
600 break;
cristydbdd0e32011-11-04 23:29:40 +0000601 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000602 token[0] = ','; /* used this token - get another */
603 }
cristyed231572011-07-14 02:18:59 +0000604 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000605 {
anthonydf8ebac2011-04-27 09:03:19 +0000606 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
607 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
608 break;
cristydbdd0e32011-11-04 23:29:40 +0000609 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000610 token[0] = ','; /* used this token - get another */
611 }
cristyed231572011-07-14 02:18:59 +0000612 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000613 (image->colorspace == CMYKColorspace))
614 {
anthonydf8ebac2011-04-27 09:03:19 +0000615 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
616 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
617 break;
cristydbdd0e32011-11-04 23:29:40 +0000618 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000619 token[0] = ','; /* used this token - get another */
620 }
cristyed231572011-07-14 02:18:59 +0000621 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000622 (image->matte != MagickFalse))
623 {
anthonydf8ebac2011-04-27 09:03:19 +0000624 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
625 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
626 break;
cristydbdd0e32011-11-04 23:29:40 +0000627 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000628 token[0] = ','; /* used this token - get another */
629 }
630 }
631 }
632 }
633 if ( number_arguments != x && !error ) {
634 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
635 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
636 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
637 return( (Image *)NULL);
638 }
639 if ( error )
640 return( (Image *)NULL);
641
642 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000643 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
644 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000645 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
646 return( sparse_image );
647}
648
cristy3ed852e2009-09-05 21:47:34 +0000649WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
650 const char **argv,Image **image,ExceptionInfo *exception)
651{
cristy633f0c62011-09-15 13:27:36 +0000652 CompositeOperator
653 compose;
654
anthonydf8ebac2011-04-27 09:03:19 +0000655 const char
656 *format,
657 *option;
658
cristy9ed1f812011-10-08 02:00:08 +0000659 double
660 attenuate;
661
anthonydf8ebac2011-04-27 09:03:19 +0000662 DrawInfo
663 *draw_info;
664
665 GeometryInfo
666 geometry_info;
667
cristy3ed852e2009-09-05 21:47:34 +0000668 Image
669 *region_image;
670
anthonydf8ebac2011-04-27 09:03:19 +0000671 ImageInfo
672 *mogrify_info;
673
cristyebbcfea2011-02-25 02:43:54 +0000674 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000675 status;
676
cristy4c08aed2011-07-01 19:47:50 +0000677 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000678 fill;
cristy3ed852e2009-09-05 21:47:34 +0000679
anthonydf8ebac2011-04-27 09:03:19 +0000680 MagickStatusType
681 flags;
682
cristy28474bf2011-09-11 23:32:52 +0000683 PixelInterpolateMethod
684 interpolate_method;
685
anthonydf8ebac2011-04-27 09:03:19 +0000686 QuantizeInfo
687 *quantize_info;
688
689 RectangleInfo
690 geometry,
691 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000692
cristybb503372010-05-27 20:51:26 +0000693 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000694 i;
695
696 /*
697 Initialize method variables.
698 */
699 assert(image_info != (const ImageInfo *) NULL);
700 assert(image_info->signature == MagickSignature);
701 assert(image != (Image **) NULL);
702 assert((*image)->signature == MagickSignature);
703 if ((*image)->debug != MagickFalse)
704 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
705 if (argc < 0)
706 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000707 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000708 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
709 quantize_info=AcquireQuantizeInfo(mogrify_info);
710 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000711 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000712 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000713 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000714 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000715 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000716 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000717 SetGeometry(*image,&region_geometry);
718 region_image=NewImageList();
719 /*
720 Transmogrify the image.
721 */
cristybb503372010-05-27 20:51:26 +0000722 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000723 {
anthonydf8ebac2011-04-27 09:03:19 +0000724 Image
725 *mogrify_image;
726
anthonye9c27192011-03-27 08:07:06 +0000727 ssize_t
728 count;
729
anthonydf8ebac2011-04-27 09:03:19 +0000730 option=argv[i];
731 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000732 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000733 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
734 0L);
cristycee97112010-05-28 00:44:52 +0000735 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000736 break;
cristy6b3da3a2010-06-20 02:21:46 +0000737 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000738 mogrify_image=(Image *)NULL;
739 switch (*(option+1))
740 {
741 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000742 {
anthonydf8ebac2011-04-27 09:03:19 +0000743 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000744 {
anthonydf8ebac2011-04-27 09:03:19 +0000745 /*
746 Adaptive blur image.
747 */
cristy6fccee12011-10-20 18:43:18 +0000748 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000749 flags=ParseGeometry(argv[i+1],&geometry_info);
750 if ((flags & SigmaValue) == 0)
751 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000752 if ((flags & XiValue) == 0)
753 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000754 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000755 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000756 break;
cristy3ed852e2009-09-05 21:47:34 +0000757 }
anthonydf8ebac2011-04-27 09:03:19 +0000758 if (LocaleCompare("adaptive-resize",option+1) == 0)
759 {
760 /*
761 Adaptive resize image.
762 */
cristy6fccee12011-10-20 18:43:18 +0000763 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000764 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
765 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
anthonyfd706f92012-01-19 04:22:02 +0000766 geometry.height,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000767 break;
768 }
769 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
770 {
771 /*
772 Adaptive sharpen image.
773 */
cristy6fccee12011-10-20 18:43:18 +0000774 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000775 flags=ParseGeometry(argv[i+1],&geometry_info);
776 if ((flags & SigmaValue) == 0)
777 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000778 if ((flags & XiValue) == 0)
779 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000780 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000781 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000782 break;
783 }
784 if (LocaleCompare("affine",option+1) == 0)
785 {
786 /*
787 Affine matrix.
788 */
789 if (*option == '+')
790 {
791 GetAffineMatrix(&draw_info->affine);
792 break;
793 }
794 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
795 break;
796 }
797 if (LocaleCompare("alpha",option+1) == 0)
798 {
799 AlphaChannelType
800 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000801
cristy6fccee12011-10-20 18:43:18 +0000802 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000803 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
804 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000805 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000806 break;
807 }
808 if (LocaleCompare("annotate",option+1) == 0)
809 {
810 char
811 *text,
812 geometry[MaxTextExtent];
813
814 /*
815 Annotate image.
816 */
cristy6fccee12011-10-20 18:43:18 +0000817 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000818 SetGeometryInfo(&geometry_info);
819 flags=ParseGeometry(argv[i+1],&geometry_info);
820 if ((flags & SigmaValue) == 0)
821 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000822 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
823 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000824 if (text == (char *) NULL)
825 break;
826 (void) CloneString(&draw_info->text,text);
827 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000828 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000829 geometry_info.xi,geometry_info.psi);
830 (void) CloneString(&draw_info->geometry,geometry);
831 draw_info->affine.sx=cos(DegreesToRadians(
832 fmod(geometry_info.rho,360.0)));
833 draw_info->affine.rx=sin(DegreesToRadians(
834 fmod(geometry_info.rho,360.0)));
835 draw_info->affine.ry=(-sin(DegreesToRadians(
836 fmod(geometry_info.sigma,360.0))));
837 draw_info->affine.sy=cos(DegreesToRadians(
838 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000839 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000840 break;
841 }
842 if (LocaleCompare("antialias",option+1) == 0)
843 {
844 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
845 MagickFalse;
846 draw_info->text_antialias=(*option == '-') ? MagickTrue :
847 MagickFalse;
848 break;
849 }
cristy9ed1f812011-10-08 02:00:08 +0000850 if (LocaleCompare("attenuate",option+1) == 0)
851 {
852 if (*option == '+')
853 {
854 attenuate=1.0;
855 break;
856 }
cristydbdd0e32011-11-04 23:29:40 +0000857 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000858 break;
859 }
anthonydf8ebac2011-04-27 09:03:19 +0000860 if (LocaleCompare("auto-gamma",option+1) == 0)
861 {
862 /*
863 Auto Adjust Gamma of image based on its mean
864 */
cristy6fccee12011-10-20 18:43:18 +0000865 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000866 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000867 break;
868 }
869 if (LocaleCompare("auto-level",option+1) == 0)
870 {
871 /*
872 Perfectly Normalize (max/min stretch) the image
873 */
cristy6fccee12011-10-20 18:43:18 +0000874 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000875 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000876 break;
877 }
878 if (LocaleCompare("auto-orient",option+1) == 0)
879 {
cristy6fccee12011-10-20 18:43:18 +0000880 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000881 switch ((*image)->orientation)
882 {
883 case TopRightOrientation:
884 {
885 mogrify_image=FlopImage(*image,exception);
886 break;
887 }
888 case BottomRightOrientation:
889 {
890 mogrify_image=RotateImage(*image,180.0,exception);
891 break;
892 }
893 case BottomLeftOrientation:
894 {
895 mogrify_image=FlipImage(*image,exception);
896 break;
897 }
898 case LeftTopOrientation:
899 {
900 mogrify_image=TransposeImage(*image,exception);
901 break;
902 }
903 case RightTopOrientation:
904 {
905 mogrify_image=RotateImage(*image,90.0,exception);
906 break;
907 }
908 case RightBottomOrientation:
909 {
910 mogrify_image=TransverseImage(*image,exception);
911 break;
912 }
913 case LeftBottomOrientation:
914 {
915 mogrify_image=RotateImage(*image,270.0,exception);
916 break;
917 }
918 default:
919 break;
920 }
921 if (mogrify_image != (Image *) NULL)
922 mogrify_image->orientation=TopLeftOrientation;
923 break;
924 }
925 break;
926 }
927 case 'b':
928 {
929 if (LocaleCompare("black-threshold",option+1) == 0)
930 {
931 /*
932 Black threshold image.
933 */
cristy6fccee12011-10-20 18:43:18 +0000934 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000935 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000936 break;
937 }
938 if (LocaleCompare("blue-shift",option+1) == 0)
939 {
940 /*
941 Blue shift image.
942 */
cristy6fccee12011-10-20 18:43:18 +0000943 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000944 geometry_info.rho=1.5;
945 if (*option == '-')
946 flags=ParseGeometry(argv[i+1],&geometry_info);
947 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
948 break;
949 }
950 if (LocaleCompare("blur",option+1) == 0)
951 {
952 /*
953 Gaussian blur image.
954 */
cristy6fccee12011-10-20 18:43:18 +0000955 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000956 flags=ParseGeometry(argv[i+1],&geometry_info);
957 if ((flags & SigmaValue) == 0)
958 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000959 if ((flags & XiValue) == 0)
960 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000961 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000962 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000963 break;
964 }
965 if (LocaleCompare("border",option+1) == 0)
966 {
967 /*
968 Surround image with a border of solid color.
969 */
cristy6fccee12011-10-20 18:43:18 +0000970 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000971 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
972 if ((flags & SigmaValue) == 0)
973 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000974 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000975 break;
976 }
977 if (LocaleCompare("bordercolor",option+1) == 0)
978 {
979 if (*option == '+')
980 {
cristy9950d572011-10-01 18:22:35 +0000981 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000982 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000983 break;
984 }
cristy9950d572011-10-01 18:22:35 +0000985 (void) QueryColorCompliance(argv[i+1],AllCompliance,
986 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000987 break;
988 }
989 if (LocaleCompare("box",option+1) == 0)
990 {
cristy9950d572011-10-01 18:22:35 +0000991 (void) QueryColorCompliance(argv[i+1],AllCompliance,
992 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000993 break;
994 }
995 if (LocaleCompare("brightness-contrast",option+1) == 0)
996 {
997 double
998 brightness,
999 contrast;
1000
1001 GeometryInfo
1002 geometry_info;
1003
1004 MagickStatusType
1005 flags;
1006
1007 /*
1008 Brightness / contrast image.
1009 */
cristy6fccee12011-10-20 18:43:18 +00001010 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001011 flags=ParseGeometry(argv[i+1],&geometry_info);
1012 brightness=geometry_info.rho;
1013 contrast=0.0;
1014 if ((flags & SigmaValue) != 0)
1015 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +00001016 (void) BrightnessContrastImage(*image,brightness,contrast,
1017 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001018 break;
1019 }
1020 break;
1021 }
1022 case 'c':
1023 {
1024 if (LocaleCompare("cdl",option+1) == 0)
1025 {
1026 char
1027 *color_correction_collection;
1028
1029 /*
1030 Color correct with a color decision list.
1031 */
cristy6fccee12011-10-20 18:43:18 +00001032 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001033 color_correction_collection=FileToString(argv[i+1],~0,exception);
1034 if (color_correction_collection == (char *) NULL)
1035 break;
cristy1bfa9f02011-08-11 02:35:43 +00001036 (void) ColorDecisionListImage(*image,color_correction_collection,
1037 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001038 break;
1039 }
anthonydf8ebac2011-04-27 09:03:19 +00001040 if (LocaleCompare("charcoal",option+1) == 0)
1041 {
1042 /*
1043 Charcoal image.
1044 */
cristy6fccee12011-10-20 18:43:18 +00001045 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001046 flags=ParseGeometry(argv[i+1],&geometry_info);
1047 if ((flags & SigmaValue) == 0)
1048 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001049 if ((flags & XiValue) == 0)
1050 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001051 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001052 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001053 break;
1054 }
1055 if (LocaleCompare("chop",option+1) == 0)
1056 {
1057 /*
1058 Chop the image.
1059 */
cristy6fccee12011-10-20 18:43:18 +00001060 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001061 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1062 mogrify_image=ChopImage(*image,&geometry,exception);
1063 break;
1064 }
1065 if (LocaleCompare("clamp",option+1) == 0)
1066 {
1067 /*
1068 Clamp image.
1069 */
cristy6fccee12011-10-20 18:43:18 +00001070 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001071 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001072 break;
1073 }
1074 if (LocaleCompare("clip",option+1) == 0)
1075 {
cristy6fccee12011-10-20 18:43:18 +00001076 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001077 if (*option == '+')
1078 {
cristy10a6c612012-01-29 21:41:05 +00001079 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001080 break;
1081 }
cristy018f07f2011-09-04 21:15:19 +00001082 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001083 break;
1084 }
1085 if (LocaleCompare("clip-mask",option+1) == 0)
1086 {
1087 CacheView
1088 *mask_view;
1089
1090 Image
1091 *mask_image;
1092
cristy4c08aed2011-07-01 19:47:50 +00001093 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001094 *restrict q;
1095
1096 register ssize_t
1097 x;
1098
1099 ssize_t
1100 y;
1101
cristy6fccee12011-10-20 18:43:18 +00001102 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001103 if (*option == '+')
1104 {
1105 /*
1106 Remove a mask.
1107 */
cristy018f07f2011-09-04 21:15:19 +00001108 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001109 break;
1110 }
1111 /*
1112 Set the image mask.
1113 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1114 */
1115 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1116 if (mask_image == (Image *) NULL)
1117 break;
cristy574cc262011-08-05 01:23:58 +00001118 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001119 return(MagickFalse);
1120 mask_view=AcquireCacheView(mask_image);
1121 for (y=0; y < (ssize_t) mask_image->rows; y++)
1122 {
1123 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1124 exception);
cristyacd2ed22011-08-30 01:44:23 +00001125 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001126 break;
1127 for (x=0; x < (ssize_t) mask_image->columns; x++)
1128 {
1129 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001130 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1131 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1132 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1133 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001134 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001135 }
1136 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1137 break;
1138 }
1139 mask_view=DestroyCacheView(mask_view);
1140 mask_image->matte=MagickTrue;
cristy10a6c612012-01-29 21:41:05 +00001141 (void) SetImageMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001142 break;
1143 }
1144 if (LocaleCompare("clip-path",option+1) == 0)
1145 {
cristy6fccee12011-10-20 18:43:18 +00001146 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001147 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001148 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001149 break;
1150 }
1151 if (LocaleCompare("colorize",option+1) == 0)
1152 {
1153 /*
1154 Colorize the image.
1155 */
cristy6fccee12011-10-20 18:43:18 +00001156 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001157 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001158 break;
1159 }
1160 if (LocaleCompare("color-matrix",option+1) == 0)
1161 {
1162 KernelInfo
1163 *kernel;
1164
cristy6fccee12011-10-20 18:43:18 +00001165 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001166 kernel=AcquireKernelInfo(argv[i+1]);
1167 if (kernel == (KernelInfo *) NULL)
1168 break;
anthonyfd706f92012-01-19 04:22:02 +00001169 /* FUTURE: check on size of the matrix */
anthonydf8ebac2011-04-27 09:03:19 +00001170 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1171 kernel=DestroyKernelInfo(kernel);
1172 break;
1173 }
1174 if (LocaleCompare("colors",option+1) == 0)
1175 {
1176 /*
1177 Reduce the number of colors in the image.
1178 */
cristy6fccee12011-10-20 18:43:18 +00001179 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001180 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1181 if (quantize_info->number_colors == 0)
1182 break;
1183 if (((*image)->storage_class == DirectClass) ||
1184 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001185 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001186 else
cristy018f07f2011-09-04 21:15:19 +00001187 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001188 break;
1189 }
1190 if (LocaleCompare("colorspace",option+1) == 0)
1191 {
1192 ColorspaceType
1193 colorspace;
1194
cristy6fccee12011-10-20 18:43:18 +00001195 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001196 if (*option == '+')
1197 {
cristye941a752011-10-15 01:52:48 +00001198 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001199 break;
1200 }
1201 colorspace=(ColorspaceType) ParseCommandOption(
1202 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001203 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001204 break;
1205 }
cristy633f0c62011-09-15 13:27:36 +00001206 if (LocaleCompare("compose",option+1) == 0)
1207 {
cristy6fccee12011-10-20 18:43:18 +00001208 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001209 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1210 MagickFalse,argv[i+1]);
1211 break;
1212 }
anthonydf8ebac2011-04-27 09:03:19 +00001213 if (LocaleCompare("contrast",option+1) == 0)
1214 {
cristy6fccee12011-10-20 18:43:18 +00001215 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001216 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001217 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001218 break;
1219 }
1220 if (LocaleCompare("contrast-stretch",option+1) == 0)
1221 {
1222 double
1223 black_point,
1224 white_point;
1225
1226 MagickStatusType
1227 flags;
1228
1229 /*
1230 Contrast stretch image.
1231 */
cristy6fccee12011-10-20 18:43:18 +00001232 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001233 flags=ParseGeometry(argv[i+1],&geometry_info);
1234 black_point=geometry_info.rho;
1235 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1236 black_point;
1237 if ((flags & PercentValue) != 0)
1238 {
1239 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1240 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1241 }
1242 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1243 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001244 (void) ContrastStretchImage(*image,black_point,white_point,
1245 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001246 break;
1247 }
1248 if (LocaleCompare("convolve",option+1) == 0)
1249 {
anthonydf8ebac2011-04-27 09:03:19 +00001250 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001251 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001252
cristy6fccee12011-10-20 18:43:18 +00001253 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001254 kernel_info=AcquireKernelInfo(argv[i+1]);
1255 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001256 break;
cristy0a922382011-07-16 15:30:34 +00001257 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001258 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001259 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001260 break;
1261 }
1262 if (LocaleCompare("crop",option+1) == 0)
1263 {
1264 /*
1265 Crop a image to a smaller size
1266 */
cristy6fccee12011-10-20 18:43:18 +00001267 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001268 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001269 break;
1270 }
1271 if (LocaleCompare("cycle",option+1) == 0)
1272 {
1273 /*
1274 Cycle an image colormap.
1275 */
cristy6fccee12011-10-20 18:43:18 +00001276 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001277 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1278 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001279 break;
1280 }
1281 break;
1282 }
1283 case 'd':
1284 {
1285 if (LocaleCompare("decipher",option+1) == 0)
1286 {
1287 StringInfo
1288 *passkey;
1289
1290 /*
1291 Decipher pixels.
1292 */
cristy6fccee12011-10-20 18:43:18 +00001293 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001294 passkey=FileToStringInfo(argv[i+1],~0,exception);
1295 if (passkey != (StringInfo *) NULL)
1296 {
1297 (void) PasskeyDecipherImage(*image,passkey,exception);
1298 passkey=DestroyStringInfo(passkey);
1299 }
1300 break;
1301 }
1302 if (LocaleCompare("density",option+1) == 0)
1303 {
1304 /*
1305 Set image density.
1306 */
1307 (void) CloneString(&draw_info->density,argv[i+1]);
1308 break;
1309 }
1310 if (LocaleCompare("depth",option+1) == 0)
1311 {
cristy6fccee12011-10-20 18:43:18 +00001312 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001313 if (*option == '+')
1314 {
cristy8a11cb12011-10-19 23:53:34 +00001315 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001316 break;
1317 }
cristy8a11cb12011-10-19 23:53:34 +00001318 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1319 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001320 break;
1321 }
1322 if (LocaleCompare("deskew",option+1) == 0)
1323 {
1324 double
1325 threshold;
1326
1327 /*
1328 Straighten the image.
1329 */
cristy6fccee12011-10-20 18:43:18 +00001330 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001331 if (*option == '+')
1332 threshold=40.0*QuantumRange/100.0;
1333 else
cristy9b34e302011-11-05 02:15:45 +00001334 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1335 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001336 mogrify_image=DeskewImage(*image,threshold,exception);
1337 break;
1338 }
1339 if (LocaleCompare("despeckle",option+1) == 0)
1340 {
1341 /*
1342 Reduce the speckles within an image.
1343 */
cristy6fccee12011-10-20 18:43:18 +00001344 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001345 mogrify_image=DespeckleImage(*image,exception);
1346 break;
1347 }
1348 if (LocaleCompare("display",option+1) == 0)
1349 {
1350 (void) CloneString(&draw_info->server_name,argv[i+1]);
1351 break;
1352 }
1353 if (LocaleCompare("distort",option+1) == 0)
1354 {
1355 char
1356 *args,
1357 token[MaxTextExtent];
1358
1359 const char
1360 *p;
1361
1362 DistortImageMethod
1363 method;
1364
1365 double
1366 *arguments;
1367
1368 register ssize_t
1369 x;
1370
1371 size_t
1372 number_arguments;
1373
1374 /*
1375 Distort image.
1376 */
cristy6fccee12011-10-20 18:43:18 +00001377 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001378 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1379 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001380 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001381 {
anthonydf8ebac2011-04-27 09:03:19 +00001382 double
1383 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001384
1385 /*
1386 Special Case - Argument is actually a resize geometry!
1387 Convert that to an appropriate distortion argument array.
1388 */
anthonydf8ebac2011-04-27 09:03:19 +00001389 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001390 exception);
1391 resize_args[0]=(double) geometry.width;
1392 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001393 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001394 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001395 break;
1396 }
cristy018f07f2011-09-04 21:15:19 +00001397 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1398 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001399 if (args == (char *) NULL)
1400 break;
1401 p=(char *) args;
1402 for (x=0; *p != '\0'; x++)
1403 {
1404 GetMagickToken(p,&p,token);
1405 if (*token == ',')
1406 GetMagickToken(p,&p,token);
1407 }
1408 number_arguments=(size_t) x;
1409 arguments=(double *) AcquireQuantumMemory(number_arguments,
1410 sizeof(*arguments));
1411 if (arguments == (double *) NULL)
1412 ThrowWandFatalException(ResourceLimitFatalError,
1413 "MemoryAllocationFailed",(*image)->filename);
1414 (void) ResetMagickMemory(arguments,0,number_arguments*
1415 sizeof(*arguments));
1416 p=(char *) args;
1417 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1418 {
1419 GetMagickToken(p,&p,token);
1420 if (*token == ',')
1421 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001422 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001423 }
1424 args=DestroyString(args);
1425 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1426 (*option == '+') ? MagickTrue : MagickFalse,exception);
1427 arguments=(double *) RelinquishMagickMemory(arguments);
1428 break;
1429 }
1430 if (LocaleCompare("dither",option+1) == 0)
1431 {
1432 if (*option == '+')
1433 {
1434 quantize_info->dither=MagickFalse;
1435 break;
1436 }
1437 quantize_info->dither=MagickTrue;
1438 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1439 MagickDitherOptions,MagickFalse,argv[i+1]);
1440 if (quantize_info->dither_method == NoDitherMethod)
1441 quantize_info->dither=MagickFalse;
1442 break;
1443 }
1444 if (LocaleCompare("draw",option+1) == 0)
1445 {
1446 /*
1447 Draw image.
1448 */
cristy6fccee12011-10-20 18:43:18 +00001449 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001450 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001451 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001452 break;
1453 }
1454 break;
1455 }
1456 case 'e':
1457 {
1458 if (LocaleCompare("edge",option+1) == 0)
1459 {
1460 /*
1461 Enhance edges in the image.
1462 */
cristy6fccee12011-10-20 18:43:18 +00001463 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001464 flags=ParseGeometry(argv[i+1],&geometry_info);
1465 if ((flags & SigmaValue) == 0)
1466 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001467 mogrify_image=EdgeImage(*image,geometry_info.rho,
1468 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001469 break;
1470 }
1471 if (LocaleCompare("emboss",option+1) == 0)
1472 {
1473 /*
cristyd89705a2012-01-20 02:52:24 +00001474 Emboss image.
anthonydf8ebac2011-04-27 09:03:19 +00001475 */
cristy6fccee12011-10-20 18:43:18 +00001476 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001477 flags=ParseGeometry(argv[i+1],&geometry_info);
1478 if ((flags & SigmaValue) == 0)
1479 geometry_info.sigma=1.0;
1480 mogrify_image=EmbossImage(*image,geometry_info.rho,
1481 geometry_info.sigma,exception);
1482 break;
1483 }
1484 if (LocaleCompare("encipher",option+1) == 0)
1485 {
1486 StringInfo
1487 *passkey;
1488
1489 /*
1490 Encipher pixels.
1491 */
cristy6fccee12011-10-20 18:43:18 +00001492 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001493 passkey=FileToStringInfo(argv[i+1],~0,exception);
1494 if (passkey != (StringInfo *) NULL)
1495 {
1496 (void) PasskeyEncipherImage(*image,passkey,exception);
1497 passkey=DestroyStringInfo(passkey);
1498 }
1499 break;
1500 }
1501 if (LocaleCompare("encoding",option+1) == 0)
1502 {
1503 (void) CloneString(&draw_info->encoding,argv[i+1]);
1504 break;
1505 }
1506 if (LocaleCompare("enhance",option+1) == 0)
1507 {
1508 /*
1509 Enhance image.
1510 */
cristy6fccee12011-10-20 18:43:18 +00001511 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001512 mogrify_image=EnhanceImage(*image,exception);
1513 break;
1514 }
1515 if (LocaleCompare("equalize",option+1) == 0)
1516 {
1517 /*
1518 Equalize image.
1519 */
cristy6fccee12011-10-20 18:43:18 +00001520 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001521 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001522 break;
1523 }
1524 if (LocaleCompare("evaluate",option+1) == 0)
1525 {
1526 double
1527 constant;
1528
1529 MagickEvaluateOperator
1530 op;
1531
cristy6fccee12011-10-20 18:43:18 +00001532 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001533 op=(MagickEvaluateOperator) ParseCommandOption(
1534 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001535 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1536 1.0);
cristyd42d9952011-07-08 14:21:50 +00001537 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001538 break;
1539 }
1540 if (LocaleCompare("extent",option+1) == 0)
1541 {
1542 /*
1543 Set the image extent.
1544 */
cristy6fccee12011-10-20 18:43:18 +00001545 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001546 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1547 if (geometry.width == 0)
1548 geometry.width=(*image)->columns;
1549 if (geometry.height == 0)
1550 geometry.height=(*image)->rows;
1551 mogrify_image=ExtentImage(*image,&geometry,exception);
1552 break;
1553 }
1554 break;
1555 }
1556 case 'f':
1557 {
1558 if (LocaleCompare("family",option+1) == 0)
1559 {
1560 if (*option == '+')
1561 {
1562 if (draw_info->family != (char *) NULL)
1563 draw_info->family=DestroyString(draw_info->family);
1564 break;
1565 }
1566 (void) CloneString(&draw_info->family,argv[i+1]);
1567 break;
1568 }
1569 if (LocaleCompare("features",option+1) == 0)
1570 {
1571 if (*option == '+')
1572 {
1573 (void) DeleteImageArtifact(*image,"identify:features");
1574 break;
1575 }
1576 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1577 break;
1578 }
1579 if (LocaleCompare("fill",option+1) == 0)
1580 {
1581 ExceptionInfo
1582 *sans;
1583
anthonyfd706f92012-01-19 04:22:02 +00001584 PixelInfo
1585 color;
1586
cristy4c08aed2011-07-01 19:47:50 +00001587 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001588 if (*option == '+')
1589 {
cristy269c9412011-10-13 23:41:15 +00001590 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001591 exception);
anthonyfd706f92012-01-19 04:22:02 +00001592 draw_info->fill=fill;
anthonydf8ebac2011-04-27 09:03:19 +00001593 if (draw_info->fill_pattern != (Image *) NULL)
1594 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1595 break;
1596 }
1597 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00001598 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001599 sans=DestroyExceptionInfo(sans);
1600 if (status == MagickFalse)
1601 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1602 exception);
anthonyfd706f92012-01-19 04:22:02 +00001603 else
1604 draw_info->fill=fill=color;
anthonydf8ebac2011-04-27 09:03:19 +00001605 break;
1606 }
1607 if (LocaleCompare("flip",option+1) == 0)
1608 {
1609 /*
1610 Flip image scanlines.
1611 */
cristy6fccee12011-10-20 18:43:18 +00001612 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001613 mogrify_image=FlipImage(*image,exception);
1614 break;
1615 }
anthonydf8ebac2011-04-27 09:03:19 +00001616 if (LocaleCompare("floodfill",option+1) == 0)
1617 {
cristy4c08aed2011-07-01 19:47:50 +00001618 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001619 target;
1620
1621 /*
1622 Floodfill image.
1623 */
cristy6fccee12011-10-20 18:43:18 +00001624 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001625 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001626 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001627 exception);
cristyd42d9952011-07-08 14:21:50 +00001628 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001629 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001630 break;
1631 }
anthony3d2f4862011-05-01 13:48:16 +00001632 if (LocaleCompare("flop",option+1) == 0)
1633 {
1634 /*
1635 Flop image scanlines.
1636 */
cristy6fccee12011-10-20 18:43:18 +00001637 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001638 mogrify_image=FlopImage(*image,exception);
1639 break;
1640 }
anthonydf8ebac2011-04-27 09:03:19 +00001641 if (LocaleCompare("font",option+1) == 0)
1642 {
1643 if (*option == '+')
1644 {
1645 if (draw_info->font != (char *) NULL)
1646 draw_info->font=DestroyString(draw_info->font);
1647 break;
1648 }
1649 (void) CloneString(&draw_info->font,argv[i+1]);
1650 break;
1651 }
1652 if (LocaleCompare("format",option+1) == 0)
1653 {
1654 format=argv[i+1];
1655 break;
1656 }
1657 if (LocaleCompare("frame",option+1) == 0)
1658 {
1659 FrameInfo
1660 frame_info;
1661
1662 /*
1663 Surround image with an ornamental border.
1664 */
cristy6fccee12011-10-20 18:43:18 +00001665 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001666 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1667 frame_info.width=geometry.width;
1668 frame_info.height=geometry.height;
1669 if ((flags & HeightValue) == 0)
1670 frame_info.height=geometry.width;
1671 frame_info.outer_bevel=geometry.x;
1672 frame_info.inner_bevel=geometry.y;
1673 frame_info.x=(ssize_t) frame_info.width;
1674 frame_info.y=(ssize_t) frame_info.height;
1675 frame_info.width=(*image)->columns+2*frame_info.width;
1676 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001677 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001678 break;
1679 }
1680 if (LocaleCompare("function",option+1) == 0)
1681 {
1682 char
1683 *arguments,
1684 token[MaxTextExtent];
1685
1686 const char
1687 *p;
1688
1689 double
1690 *parameters;
1691
1692 MagickFunction
1693 function;
1694
1695 register ssize_t
1696 x;
1697
1698 size_t
1699 number_parameters;
1700
1701 /*
1702 Function Modify Image Values
1703 */
cristy6fccee12011-10-20 18:43:18 +00001704 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001705 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1706 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001707 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1708 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001709 if (arguments == (char *) NULL)
1710 break;
1711 p=(char *) arguments;
1712 for (x=0; *p != '\0'; x++)
1713 {
1714 GetMagickToken(p,&p,token);
1715 if (*token == ',')
1716 GetMagickToken(p,&p,token);
1717 }
1718 number_parameters=(size_t) x;
1719 parameters=(double *) AcquireQuantumMemory(number_parameters,
1720 sizeof(*parameters));
1721 if (parameters == (double *) NULL)
1722 ThrowWandFatalException(ResourceLimitFatalError,
1723 "MemoryAllocationFailed",(*image)->filename);
1724 (void) ResetMagickMemory(parameters,0,number_parameters*
1725 sizeof(*parameters));
1726 p=(char *) arguments;
1727 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1728 {
1729 GetMagickToken(p,&p,token);
1730 if (*token == ',')
1731 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001732 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001733 }
1734 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001735 (void) FunctionImage(*image,function,number_parameters,parameters,
1736 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001737 parameters=(double *) RelinquishMagickMemory(parameters);
1738 break;
1739 }
1740 break;
1741 }
1742 case 'g':
1743 {
1744 if (LocaleCompare("gamma",option+1) == 0)
1745 {
1746 /*
1747 Gamma image.
1748 */
cristy6fccee12011-10-20 18:43:18 +00001749 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001750 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001751 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001752 else
cristydbdd0e32011-11-04 23:29:40 +00001753 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001754 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001755 break;
1756 }
1757 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1758 (LocaleCompare("gaussian",option+1) == 0))
1759 {
1760 /*
1761 Gaussian blur image.
1762 */
cristy6fccee12011-10-20 18:43:18 +00001763 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001764 flags=ParseGeometry(argv[i+1],&geometry_info);
1765 if ((flags & SigmaValue) == 0)
1766 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001767 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristyd89705a2012-01-20 02:52:24 +00001768 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001769 break;
1770 }
1771 if (LocaleCompare("geometry",option+1) == 0)
1772 {
1773 /*
1774 Record Image offset, Resize last image.
1775 */
cristy6fccee12011-10-20 18:43:18 +00001776 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001777 if (*option == '+')
1778 {
1779 if ((*image)->geometry != (char *) NULL)
1780 (*image)->geometry=DestroyString((*image)->geometry);
1781 break;
1782 }
1783 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1784 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1785 (void) CloneString(&(*image)->geometry,argv[i+1]);
1786 else
1787 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1788 (*image)->filter,(*image)->blur,exception);
1789 break;
1790 }
1791 if (LocaleCompare("gravity",option+1) == 0)
1792 {
1793 if (*option == '+')
1794 {
1795 draw_info->gravity=UndefinedGravity;
1796 break;
1797 }
1798 draw_info->gravity=(GravityType) ParseCommandOption(
1799 MagickGravityOptions,MagickFalse,argv[i+1]);
1800 break;
1801 }
1802 break;
1803 }
1804 case 'h':
1805 {
1806 if (LocaleCompare("highlight-color",option+1) == 0)
1807 {
1808 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1809 break;
1810 }
1811 break;
1812 }
1813 case 'i':
1814 {
1815 if (LocaleCompare("identify",option+1) == 0)
1816 {
1817 char
1818 *text;
1819
cristy6fccee12011-10-20 18:43:18 +00001820 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001821 if (format == (char *) NULL)
1822 {
cristya4037272011-08-28 15:11:39 +00001823 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1824 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001825 break;
1826 }
cristy018f07f2011-09-04 21:15:19 +00001827 text=InterpretImageProperties(mogrify_info,*image,format,
1828 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001829 if (text == (char *) NULL)
1830 break;
1831 (void) fputs(text,stdout);
1832 (void) fputc('\n',stdout);
1833 text=DestroyString(text);
1834 break;
1835 }
1836 if (LocaleCompare("implode",option+1) == 0)
1837 {
1838 /*
1839 Implode image.
1840 */
cristy6fccee12011-10-20 18:43:18 +00001841 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001842 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001843 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1844 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001845 break;
1846 }
1847 if (LocaleCompare("interline-spacing",option+1) == 0)
1848 {
1849 if (*option == '+')
1850 (void) ParseGeometry("0",&geometry_info);
1851 else
1852 (void) ParseGeometry(argv[i+1],&geometry_info);
1853 draw_info->interline_spacing=geometry_info.rho;
1854 break;
1855 }
cristy28474bf2011-09-11 23:32:52 +00001856 if (LocaleCompare("interpolate",option+1) == 0)
1857 {
1858 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1859 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1860 break;
1861 }
anthonydf8ebac2011-04-27 09:03:19 +00001862 if (LocaleCompare("interword-spacing",option+1) == 0)
1863 {
1864 if (*option == '+')
1865 (void) ParseGeometry("0",&geometry_info);
1866 else
1867 (void) ParseGeometry(argv[i+1],&geometry_info);
1868 draw_info->interword_spacing=geometry_info.rho;
1869 break;
1870 }
anthonyfd706f92012-01-19 04:22:02 +00001871 if (LocaleCompare("interpolative-resize",option+1) == 0)
1872 {
1873 /*
1874 Interpolative resize image.
1875 */
1876 (void) SyncImageSettings(mogrify_info,*image,exception);
1877 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1878 mogrify_image=InterpolativeResizeImage(*image,geometry.width,
1879 geometry.height,interpolate_method,exception);
1880 break;
1881 }
anthonydf8ebac2011-04-27 09:03:19 +00001882 break;
1883 }
1884 case 'k':
1885 {
1886 if (LocaleCompare("kerning",option+1) == 0)
1887 {
1888 if (*option == '+')
1889 (void) ParseGeometry("0",&geometry_info);
1890 else
1891 (void) ParseGeometry(argv[i+1],&geometry_info);
1892 draw_info->kerning=geometry_info.rho;
1893 break;
1894 }
1895 break;
1896 }
1897 case 'l':
1898 {
1899 if (LocaleCompare("lat",option+1) == 0)
1900 {
1901 /*
1902 Local adaptive threshold image.
1903 */
cristy6fccee12011-10-20 18:43:18 +00001904 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001905 flags=ParseGeometry(argv[i+1],&geometry_info);
1906 if ((flags & PercentValue) != 0)
1907 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1908 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001909 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001910 geometry_info.xi,exception);
1911 break;
1912 }
1913 if (LocaleCompare("level",option+1) == 0)
1914 {
1915 MagickRealType
1916 black_point,
1917 gamma,
1918 white_point;
1919
1920 MagickStatusType
1921 flags;
1922
1923 /*
1924 Parse levels.
1925 */
cristy6fccee12011-10-20 18:43:18 +00001926 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001927 flags=ParseGeometry(argv[i+1],&geometry_info);
1928 black_point=geometry_info.rho;
1929 white_point=(MagickRealType) QuantumRange;
1930 if ((flags & SigmaValue) != 0)
1931 white_point=geometry_info.sigma;
1932 gamma=1.0;
1933 if ((flags & XiValue) != 0)
1934 gamma=geometry_info.xi;
1935 if ((flags & PercentValue) != 0)
1936 {
1937 black_point*=(MagickRealType) (QuantumRange/100.0);
1938 white_point*=(MagickRealType) (QuantumRange/100.0);
1939 }
1940 if ((flags & SigmaValue) == 0)
1941 white_point=(MagickRealType) QuantumRange-black_point;
1942 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001943 (void) LevelizeImage(*image,black_point,white_point,gamma,
1944 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001945 else
cristy01e9afd2011-08-10 17:38:41 +00001946 (void) LevelImage(*image,black_point,white_point,gamma,
1947 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001948 break;
1949 }
1950 if (LocaleCompare("level-colors",option+1) == 0)
1951 {
1952 char
1953 token[MaxTextExtent];
1954
1955 const char
1956 *p;
1957
cristy4c08aed2011-07-01 19:47:50 +00001958 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001959 black_point,
1960 white_point;
1961
1962 p=(const char *) argv[i+1];
1963 GetMagickToken(p,&p,token); /* get black point color */
1964 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001965 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001966 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001967 else
cristy269c9412011-10-13 23:41:15 +00001968 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001969 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001970 if (isalpha((int) token[0]) || (token[0] == '#'))
1971 GetMagickToken(p,&p,token);
1972 if (*token == '\0')
1973 white_point=black_point; /* set everything to that color */
1974 else
1975 {
1976 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1977 GetMagickToken(p,&p,token); /* Get white point color. */
1978 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001979 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001980 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001981 else
cristy269c9412011-10-13 23:41:15 +00001982 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001983 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001984 }
cristy490408a2011-07-07 14:42:05 +00001985 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001986 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001987 break;
1988 }
1989 if (LocaleCompare("linear-stretch",option+1) == 0)
1990 {
1991 double
1992 black_point,
1993 white_point;
1994
1995 MagickStatusType
1996 flags;
1997
cristy6fccee12011-10-20 18:43:18 +00001998 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001999 flags=ParseGeometry(argv[i+1],&geometry_info);
2000 black_point=geometry_info.rho;
2001 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2002 if ((flags & SigmaValue) != 0)
2003 white_point=geometry_info.sigma;
2004 if ((flags & PercentValue) != 0)
2005 {
2006 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2007 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2008 }
2009 if ((flags & SigmaValue) == 0)
2010 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2011 black_point;
cristy33bd5152011-08-24 01:42:24 +00002012 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002013 break;
2014 }
anthonydf8ebac2011-04-27 09:03:19 +00002015 if (LocaleCompare("liquid-rescale",option+1) == 0)
2016 {
2017 /*
2018 Liquid rescale image.
2019 */
cristy6fccee12011-10-20 18:43:18 +00002020 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002021 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2022 if ((flags & XValue) == 0)
2023 geometry.x=1;
2024 if ((flags & YValue) == 0)
2025 geometry.y=0;
2026 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2027 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2028 break;
2029 }
2030 if (LocaleCompare("lowlight-color",option+1) == 0)
2031 {
2032 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2033 break;
2034 }
2035 break;
2036 }
2037 case 'm':
2038 {
2039 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002040 {
cristy3ed852e2009-09-05 21:47:34 +00002041 Image
anthonydf8ebac2011-04-27 09:03:19 +00002042 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002043
anthonydf8ebac2011-04-27 09:03:19 +00002044 /*
2045 Transform image colors to match this set of colors.
2046 */
cristy6fccee12011-10-20 18:43:18 +00002047 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002048 if (*option == '+')
2049 break;
2050 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2051 if (remap_image == (Image *) NULL)
2052 break;
cristy018f07f2011-09-04 21:15:19 +00002053 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002054 remap_image=DestroyImage(remap_image);
2055 break;
2056 }
2057 if (LocaleCompare("mask",option+1) == 0)
2058 {
2059 Image
2060 *mask;
2061
cristy6fccee12011-10-20 18:43:18 +00002062 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002063 if (*option == '+')
2064 {
2065 /*
2066 Remove a mask.
2067 */
cristy018f07f2011-09-04 21:15:19 +00002068 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002069 break;
2070 }
2071 /*
2072 Set the image mask.
2073 */
2074 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2075 if (mask == (Image *) NULL)
2076 break;
cristy018f07f2011-09-04 21:15:19 +00002077 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002078 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002079 break;
2080 }
2081 if (LocaleCompare("matte",option+1) == 0)
2082 {
2083 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002084 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002085 break;
2086 }
2087 if (LocaleCompare("median",option+1) == 0)
2088 {
2089 /*
2090 Median filter image.
2091 */
cristy6fccee12011-10-20 18:43:18 +00002092 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002093 flags=ParseGeometry(argv[i+1],&geometry_info);
2094 if ((flags & SigmaValue) == 0)
2095 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002096 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002097 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002098 break;
2099 }
2100 if (LocaleCompare("mode",option+1) == 0)
2101 {
2102 /*
2103 Mode image.
2104 */
cristy6fccee12011-10-20 18:43:18 +00002105 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002106 flags=ParseGeometry(argv[i+1],&geometry_info);
2107 if ((flags & SigmaValue) == 0)
2108 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002109 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002110 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002111 break;
2112 }
2113 if (LocaleCompare("modulate",option+1) == 0)
2114 {
cristy6fccee12011-10-20 18:43:18 +00002115 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002116 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002117 break;
2118 }
2119 if (LocaleCompare("monitor",option+1) == 0)
2120 {
2121 if (*option == '+')
2122 {
2123 (void) SetImageProgressMonitor(*image,
2124 (MagickProgressMonitor) NULL,(void *) NULL);
2125 break;
2126 }
2127 (void) SetImageProgressMonitor(*image,MonitorProgress,
2128 (void *) NULL);
2129 break;
2130 }
2131 if (LocaleCompare("monochrome",option+1) == 0)
2132 {
cristy6fccee12011-10-20 18:43:18 +00002133 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002134 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002135 break;
2136 }
2137 if (LocaleCompare("morphology",option+1) == 0)
2138 {
2139 char
2140 token[MaxTextExtent];
2141
2142 const char
2143 *p;
2144
2145 KernelInfo
2146 *kernel;
2147
2148 MorphologyMethod
2149 method;
2150
2151 ssize_t
2152 iterations;
2153
2154 /*
2155 Morphological Image Operation
2156 */
cristy6fccee12011-10-20 18:43:18 +00002157 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002158 p=argv[i+1];
2159 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002160 method=(MorphologyMethod) ParseCommandOption(
2161 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002162 iterations=1L;
2163 GetMagickToken(p,&p,token);
2164 if ((*p == ':') || (*p == ','))
2165 GetMagickToken(p,&p,token);
2166 if ((*p != '\0'))
2167 iterations=(ssize_t) StringToLong(p);
2168 kernel=AcquireKernelInfo(argv[i+2]);
2169 if (kernel == (KernelInfo *) NULL)
2170 {
2171 (void) ThrowMagickException(exception,GetMagickModule(),
2172 OptionError,"UnabletoParseKernel","morphology");
2173 status=MagickFalse;
2174 break;
2175 }
cristyf4ad9df2011-07-08 16:49:03 +00002176 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2177 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002178 kernel=DestroyKernelInfo(kernel);
2179 break;
2180 }
2181 if (LocaleCompare("motion-blur",option+1) == 0)
2182 {
2183 /*
2184 Motion blur image.
2185 */
cristy6fccee12011-10-20 18:43:18 +00002186 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002187 flags=ParseGeometry(argv[i+1],&geometry_info);
2188 if ((flags & SigmaValue) == 0)
2189 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002190 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristy7497f482011-12-08 01:57:31 +00002191 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002192 break;
2193 }
2194 break;
2195 }
2196 case 'n':
2197 {
2198 if (LocaleCompare("negate",option+1) == 0)
2199 {
cristy6fccee12011-10-20 18:43:18 +00002200 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002201 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002202 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002203 break;
2204 }
2205 if (LocaleCompare("noise",option+1) == 0)
2206 {
cristy6fccee12011-10-20 18:43:18 +00002207 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002208 if (*option == '-')
2209 {
cristyf36cbcb2011-09-07 13:28:22 +00002210 flags=ParseGeometry(argv[i+1],&geometry_info);
2211 if ((flags & SigmaValue) == 0)
2212 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002213 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002214 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002215 }
2216 else
2217 {
2218 NoiseType
2219 noise;
2220
2221 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2222 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002223 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002224 }
2225 break;
2226 }
2227 if (LocaleCompare("normalize",option+1) == 0)
2228 {
cristy6fccee12011-10-20 18:43:18 +00002229 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002230 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002231 break;
2232 }
2233 break;
2234 }
2235 case 'o':
2236 {
2237 if (LocaleCompare("opaque",option+1) == 0)
2238 {
cristy4c08aed2011-07-01 19:47:50 +00002239 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002240 target;
2241
cristy6fccee12011-10-20 18:43:18 +00002242 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002243 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002244 exception);
cristyd42d9952011-07-08 14:21:50 +00002245 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002246 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002247 break;
2248 }
2249 if (LocaleCompare("ordered-dither",option+1) == 0)
2250 {
cristy6fccee12011-10-20 18:43:18 +00002251 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002252 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002253 break;
2254 }
2255 break;
2256 }
2257 case 'p':
2258 {
2259 if (LocaleCompare("paint",option+1) == 0)
2260 {
cristy6fccee12011-10-20 18:43:18 +00002261 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002262 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002263 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2264 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002265 break;
2266 }
anthonydf8ebac2011-04-27 09:03:19 +00002267 if (LocaleCompare("pointsize",option+1) == 0)
2268 {
2269 if (*option == '+')
2270 (void) ParseGeometry("12",&geometry_info);
2271 else
2272 (void) ParseGeometry(argv[i+1],&geometry_info);
2273 draw_info->pointsize=geometry_info.rho;
2274 break;
2275 }
2276 if (LocaleCompare("polaroid",option+1) == 0)
2277 {
cristye9e3d382011-12-14 01:50:13 +00002278 const char
2279 *caption;
2280
anthonydf8ebac2011-04-27 09:03:19 +00002281 double
2282 angle;
2283
2284 RandomInfo
2285 *random_info;
2286
2287 /*
2288 Simulate a Polaroid picture.
2289 */
cristy6fccee12011-10-20 18:43:18 +00002290 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002291 random_info=AcquireRandomInfo();
2292 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2293 random_info=DestroyRandomInfo(random_info);
2294 if (*option == '-')
2295 {
2296 SetGeometryInfo(&geometry_info);
2297 flags=ParseGeometry(argv[i+1],&geometry_info);
2298 angle=geometry_info.rho;
2299 }
cristye9e3d382011-12-14 01:50:13 +00002300 caption=GetImageProperty(*image,"caption",exception);
2301 mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
cristy28474bf2011-09-11 23:32:52 +00002302 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002303 break;
2304 }
2305 if (LocaleCompare("posterize",option+1) == 0)
2306 {
2307 /*
2308 Posterize image.
2309 */
cristy6fccee12011-10-20 18:43:18 +00002310 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002311 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002312 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002313 break;
2314 }
2315 if (LocaleCompare("preview",option+1) == 0)
2316 {
2317 PreviewType
2318 preview_type;
2319
2320 /*
2321 Preview image.
2322 */
cristy6fccee12011-10-20 18:43:18 +00002323 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002324 if (*option == '+')
2325 preview_type=UndefinedPreview;
2326 else
cristy28474bf2011-09-11 23:32:52 +00002327 preview_type=(PreviewType) ParseCommandOption(
2328 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002329 mogrify_image=PreviewImage(*image,preview_type,exception);
2330 break;
2331 }
2332 if (LocaleCompare("profile",option+1) == 0)
2333 {
2334 const char
2335 *name;
2336
2337 const StringInfo
2338 *profile;
2339
2340 Image
2341 *profile_image;
2342
2343 ImageInfo
2344 *profile_info;
2345
cristy6fccee12011-10-20 18:43:18 +00002346 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002347 if (*option == '+')
2348 {
2349 /*
2350 Remove a profile from the image.
2351 */
2352 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002353 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002354 break;
2355 }
2356 /*
2357 Associate a profile with the image.
2358 */
2359 profile_info=CloneImageInfo(mogrify_info);
2360 profile=GetImageProfile(*image,"iptc");
2361 if (profile != (StringInfo *) NULL)
2362 profile_info->profile=(void *) CloneStringInfo(profile);
2363 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2364 profile_info=DestroyImageInfo(profile_info);
2365 if (profile_image == (Image *) NULL)
2366 {
2367 StringInfo
2368 *profile;
2369
2370 profile_info=CloneImageInfo(mogrify_info);
2371 (void) CopyMagickString(profile_info->filename,argv[i+1],
2372 MaxTextExtent);
2373 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2374 if (profile != (StringInfo *) NULL)
2375 {
2376 (void) ProfileImage(*image,profile_info->magick,
2377 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002378 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002379 profile=DestroyStringInfo(profile);
2380 }
2381 profile_info=DestroyImageInfo(profile_info);
2382 break;
2383 }
2384 ResetImageProfileIterator(profile_image);
2385 name=GetNextImageProfile(profile_image);
2386 while (name != (const char *) NULL)
2387 {
2388 profile=GetImageProfile(profile_image,name);
2389 if (profile != (StringInfo *) NULL)
2390 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002391 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002392 name=GetNextImageProfile(profile_image);
2393 }
2394 profile_image=DestroyImage(profile_image);
2395 break;
2396 }
2397 break;
2398 }
2399 case 'q':
2400 {
2401 if (LocaleCompare("quantize",option+1) == 0)
2402 {
2403 if (*option == '+')
2404 {
2405 quantize_info->colorspace=UndefinedColorspace;
2406 break;
2407 }
2408 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2409 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2410 break;
2411 }
2412 break;
2413 }
2414 case 'r':
2415 {
2416 if (LocaleCompare("radial-blur",option+1) == 0)
2417 {
2418 /*
2419 Radial blur image.
2420 */
cristy6fccee12011-10-20 18:43:18 +00002421 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002422 flags=ParseGeometry(argv[i+1],&geometry_info);
2423 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2424 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002425 break;
2426 }
2427 if (LocaleCompare("raise",option+1) == 0)
2428 {
2429 /*
2430 Surround image with a raise of solid color.
2431 */
2432 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2433 if ((flags & SigmaValue) == 0)
2434 geometry.height=geometry.width;
2435 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002436 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002437 break;
2438 }
2439 if (LocaleCompare("random-threshold",option+1) == 0)
2440 {
2441 /*
2442 Threshold image.
2443 */
cristy6fccee12011-10-20 18:43:18 +00002444 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002445 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002446 break;
2447 }
anthonydf8ebac2011-04-27 09:03:19 +00002448 if (LocaleCompare("region",option+1) == 0)
2449 {
cristy6fccee12011-10-20 18:43:18 +00002450 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002451 if (region_image != (Image *) NULL)
2452 {
2453 /*
2454 Composite region.
2455 */
2456 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002457 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002458 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002459 *image=DestroyImage(*image);
2460 *image=region_image;
2461 region_image = (Image *) NULL;
2462 }
2463 if (*option == '+')
2464 break;
2465 /*
2466 Apply transformations to a selected region of the image.
2467 */
cristy3ed852e2009-09-05 21:47:34 +00002468 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2469 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002470 mogrify_image=CropImage(*image,&region_geometry,exception);
2471 if (mogrify_image == (Image *) NULL)
2472 break;
2473 region_image=(*image);
2474 *image=mogrify_image;
2475 mogrify_image=(Image *) NULL;
2476 break;
cristy3ed852e2009-09-05 21:47:34 +00002477 }
anthonydf8ebac2011-04-27 09:03:19 +00002478 if (LocaleCompare("render",option+1) == 0)
2479 {
cristy6fccee12011-10-20 18:43:18 +00002480 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002481 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2482 break;
2483 }
2484 if (LocaleCompare("remap",option+1) == 0)
2485 {
2486 Image
2487 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002488
anthonydf8ebac2011-04-27 09:03:19 +00002489 /*
2490 Transform image colors to match this set of colors.
2491 */
cristy6fccee12011-10-20 18:43:18 +00002492 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002493 if (*option == '+')
2494 break;
2495 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2496 if (remap_image == (Image *) NULL)
2497 break;
cristy018f07f2011-09-04 21:15:19 +00002498 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002499 remap_image=DestroyImage(remap_image);
2500 break;
2501 }
2502 if (LocaleCompare("repage",option+1) == 0)
2503 {
2504 if (*option == '+')
2505 {
2506 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2507 break;
2508 }
2509 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002510 break;
2511 }
2512 if (LocaleCompare("resample",option+1) == 0)
2513 {
2514 /*
2515 Resample image.
2516 */
cristy6fccee12011-10-20 18:43:18 +00002517 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002518 flags=ParseGeometry(argv[i+1],&geometry_info);
2519 if ((flags & SigmaValue) == 0)
2520 geometry_info.sigma=geometry_info.rho;
2521 mogrify_image=ResampleImage(*image,geometry_info.rho,
2522 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2523 break;
2524 }
2525 if (LocaleCompare("resize",option+1) == 0)
2526 {
2527 /*
2528 Resize image.
2529 */
cristy6fccee12011-10-20 18:43:18 +00002530 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002531 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2532 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2533 (*image)->filter,(*image)->blur,exception);
2534 break;
2535 }
2536 if (LocaleCompare("roll",option+1) == 0)
2537 {
2538 /*
2539 Roll image.
2540 */
cristy6fccee12011-10-20 18:43:18 +00002541 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002542 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2543 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2544 break;
2545 }
2546 if (LocaleCompare("rotate",option+1) == 0)
2547 {
2548 char
2549 *geometry;
2550
2551 /*
2552 Check for conditional image rotation.
2553 */
cristy6fccee12011-10-20 18:43:18 +00002554 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002555 if (strchr(argv[i+1],'>') != (char *) NULL)
2556 if ((*image)->columns <= (*image)->rows)
2557 break;
2558 if (strchr(argv[i+1],'<') != (char *) NULL)
2559 if ((*image)->columns >= (*image)->rows)
2560 break;
2561 /*
2562 Rotate image.
2563 */
2564 geometry=ConstantString(argv[i+1]);
2565 (void) SubstituteString(&geometry,">","");
2566 (void) SubstituteString(&geometry,"<","");
2567 (void) ParseGeometry(geometry,&geometry_info);
2568 geometry=DestroyString(geometry);
2569 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2570 break;
2571 }
2572 break;
2573 }
2574 case 's':
2575 {
2576 if (LocaleCompare("sample",option+1) == 0)
2577 {
2578 /*
2579 Sample image with pixel replication.
2580 */
cristy6fccee12011-10-20 18:43:18 +00002581 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002582 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2583 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2584 exception);
2585 break;
2586 }
2587 if (LocaleCompare("scale",option+1) == 0)
2588 {
2589 /*
2590 Resize image.
2591 */
cristy6fccee12011-10-20 18:43:18 +00002592 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002593 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2594 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2595 exception);
2596 break;
2597 }
2598 if (LocaleCompare("selective-blur",option+1) == 0)
2599 {
2600 /*
2601 Selectively blur pixels within a contrast threshold.
2602 */
cristy6fccee12011-10-20 18:43:18 +00002603 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002604 flags=ParseGeometry(argv[i+1],&geometry_info);
2605 if ((flags & PercentValue) != 0)
2606 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002607 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002608 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002609 break;
2610 }
2611 if (LocaleCompare("separate",option+1) == 0)
2612 {
2613 /*
2614 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002615 */
cristy6fccee12011-10-20 18:43:18 +00002616 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3139dc22011-07-08 00:11:42 +00002617 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002618 break;
2619 }
2620 if (LocaleCompare("sepia-tone",option+1) == 0)
2621 {
2622 double
2623 threshold;
2624
2625 /*
2626 Sepia-tone image.
2627 */
cristy6fccee12011-10-20 18:43:18 +00002628 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002629 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2630 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002631 mogrify_image=SepiaToneImage(*image,threshold,exception);
2632 break;
2633 }
2634 if (LocaleCompare("segment",option+1) == 0)
2635 {
2636 /*
2637 Segment image.
2638 */
cristy6fccee12011-10-20 18:43:18 +00002639 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002640 flags=ParseGeometry(argv[i+1],&geometry_info);
2641 if ((flags & SigmaValue) == 0)
2642 geometry_info.sigma=1.0;
2643 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002644 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2645 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002646 break;
2647 }
2648 if (LocaleCompare("set",option+1) == 0)
2649 {
2650 char
2651 *value;
2652
2653 /*
2654 Set image option.
2655 */
2656 if (*option == '+')
2657 {
2658 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2659 (void) DeleteImageRegistry(argv[i+1]+9);
2660 else
2661 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2662 {
2663 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2664 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2665 }
2666 else
2667 (void) DeleteImageProperty(*image,argv[i+1]);
2668 break;
2669 }
cristy018f07f2011-09-04 21:15:19 +00002670 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2671 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002672 if (value == (char *) NULL)
2673 break;
2674 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2675 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2676 exception);
2677 else
2678 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2679 {
2680 (void) SetImageOption(image_info,argv[i+1]+7,value);
2681 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2682 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2683 }
2684 else
cristyd15e6592011-10-15 00:13:06 +00002685 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002686 value=DestroyString(value);
2687 break;
2688 }
2689 if (LocaleCompare("shade",option+1) == 0)
2690 {
2691 /*
2692 Shade image.
2693 */
cristy6fccee12011-10-20 18:43:18 +00002694 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002695 flags=ParseGeometry(argv[i+1],&geometry_info);
2696 if ((flags & SigmaValue) == 0)
2697 geometry_info.sigma=1.0;
2698 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2699 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2700 break;
2701 }
2702 if (LocaleCompare("shadow",option+1) == 0)
2703 {
2704 /*
2705 Shadow image.
2706 */
cristy6fccee12011-10-20 18:43:18 +00002707 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002708 flags=ParseGeometry(argv[i+1],&geometry_info);
2709 if ((flags & SigmaValue) == 0)
2710 geometry_info.sigma=1.0;
2711 if ((flags & XiValue) == 0)
2712 geometry_info.xi=4.0;
2713 if ((flags & PsiValue) == 0)
2714 geometry_info.psi=4.0;
2715 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00002716 geometry_info.sigma,(*image)->bias,(ssize_t)
2717 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
2718 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002719 break;
2720 }
2721 if (LocaleCompare("sharpen",option+1) == 0)
2722 {
2723 /*
2724 Sharpen image.
2725 */
cristy6fccee12011-10-20 18:43:18 +00002726 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002727 flags=ParseGeometry(argv[i+1],&geometry_info);
2728 if ((flags & SigmaValue) == 0)
2729 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002730 if ((flags & XiValue) == 0)
2731 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002732 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002733 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002734 break;
2735 }
2736 if (LocaleCompare("shave",option+1) == 0)
2737 {
2738 /*
2739 Shave the image edges.
2740 */
cristy6fccee12011-10-20 18:43:18 +00002741 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002742 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2743 mogrify_image=ShaveImage(*image,&geometry,exception);
2744 break;
2745 }
2746 if (LocaleCompare("shear",option+1) == 0)
2747 {
2748 /*
2749 Shear image.
2750 */
cristy6fccee12011-10-20 18:43:18 +00002751 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002752 flags=ParseGeometry(argv[i+1],&geometry_info);
2753 if ((flags & SigmaValue) == 0)
2754 geometry_info.sigma=geometry_info.rho;
2755 mogrify_image=ShearImage(*image,geometry_info.rho,
2756 geometry_info.sigma,exception);
2757 break;
2758 }
2759 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2760 {
2761 /*
2762 Sigmoidal non-linearity contrast control.
2763 */
cristy6fccee12011-10-20 18:43:18 +00002764 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002765 flags=ParseGeometry(argv[i+1],&geometry_info);
2766 if ((flags & SigmaValue) == 0)
2767 geometry_info.sigma=(double) QuantumRange/2.0;
2768 if ((flags & PercentValue) != 0)
2769 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2770 100.0;
cristy9ee60942011-07-06 14:54:38 +00002771 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002772 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2773 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002774 break;
2775 }
2776 if (LocaleCompare("sketch",option+1) == 0)
2777 {
2778 /*
2779 Sketch image.
2780 */
cristy6fccee12011-10-20 18:43:18 +00002781 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002782 flags=ParseGeometry(argv[i+1],&geometry_info);
2783 if ((flags & SigmaValue) == 0)
2784 geometry_info.sigma=1.0;
2785 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002786 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002787 break;
2788 }
2789 if (LocaleCompare("solarize",option+1) == 0)
2790 {
2791 double
2792 threshold;
2793
cristy6fccee12011-10-20 18:43:18 +00002794 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002795 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2796 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002797 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002798 break;
2799 }
2800 if (LocaleCompare("sparse-color",option+1) == 0)
2801 {
2802 SparseColorMethod
2803 method;
2804
2805 char
2806 *arguments;
2807
2808 /*
2809 Sparse Color Interpolated Gradient
2810 */
cristy6fccee12011-10-20 18:43:18 +00002811 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002812 method=(SparseColorMethod) ParseCommandOption(
2813 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002814 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2815 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002816 if (arguments == (char *) NULL)
2817 break;
cristy3884f692011-07-08 18:00:18 +00002818 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002819 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2820 arguments=DestroyString(arguments);
2821 break;
2822 }
2823 if (LocaleCompare("splice",option+1) == 0)
2824 {
2825 /*
2826 Splice a solid color into the image.
2827 */
cristy6fccee12011-10-20 18:43:18 +00002828 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002829 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2830 mogrify_image=SpliceImage(*image,&geometry,exception);
2831 break;
2832 }
2833 if (LocaleCompare("spread",option+1) == 0)
2834 {
2835 /*
2836 Spread an image.
2837 */
cristy6fccee12011-10-20 18:43:18 +00002838 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002839 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002840 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002841 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002842 break;
2843 }
2844 if (LocaleCompare("statistic",option+1) == 0)
2845 {
2846 StatisticType
2847 type;
2848
cristy6fccee12011-10-20 18:43:18 +00002849 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002850 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2851 MagickFalse,argv[i+1]);
2852 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002853 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2854 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002855 break;
2856 }
2857 if (LocaleCompare("stretch",option+1) == 0)
2858 {
2859 if (*option == '+')
2860 {
2861 draw_info->stretch=UndefinedStretch;
2862 break;
2863 }
2864 draw_info->stretch=(StretchType) ParseCommandOption(
2865 MagickStretchOptions,MagickFalse,argv[i+1]);
2866 break;
2867 }
2868 if (LocaleCompare("strip",option+1) == 0)
2869 {
2870 /*
2871 Strip image of profiles and comments.
2872 */
cristy6fccee12011-10-20 18:43:18 +00002873 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002874 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002875 break;
2876 }
2877 if (LocaleCompare("stroke",option+1) == 0)
2878 {
2879 ExceptionInfo
2880 *sans;
2881
anthonyfd706f92012-01-19 04:22:02 +00002882 PixelInfo
2883 color;
2884
anthonydf8ebac2011-04-27 09:03:19 +00002885 if (*option == '+')
2886 {
cristy9950d572011-10-01 18:22:35 +00002887 (void) QueryColorCompliance("none",AllCompliance,
2888 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002889 if (draw_info->stroke_pattern != (Image *) NULL)
2890 draw_info->stroke_pattern=DestroyImage(
2891 draw_info->stroke_pattern);
2892 break;
2893 }
2894 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00002895 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002896 sans=DestroyExceptionInfo(sans);
2897 if (status == MagickFalse)
2898 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2899 exception);
anthonyfd706f92012-01-19 04:22:02 +00002900 else
2901 draw_info->stroke=color;
anthonydf8ebac2011-04-27 09:03:19 +00002902 break;
2903 }
2904 if (LocaleCompare("strokewidth",option+1) == 0)
2905 {
cristy9b34e302011-11-05 02:15:45 +00002906 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002907 break;
2908 }
2909 if (LocaleCompare("style",option+1) == 0)
2910 {
2911 if (*option == '+')
2912 {
2913 draw_info->style=UndefinedStyle;
2914 break;
2915 }
2916 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2917 MagickFalse,argv[i+1]);
2918 break;
2919 }
2920 if (LocaleCompare("swirl",option+1) == 0)
2921 {
2922 /*
2923 Swirl image.
2924 */
cristy6fccee12011-10-20 18:43:18 +00002925 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002926 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002927 mogrify_image=SwirlImage(*image,geometry_info.rho,
2928 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002929 break;
2930 }
2931 break;
2932 }
2933 case 't':
2934 {
2935 if (LocaleCompare("threshold",option+1) == 0)
2936 {
2937 double
2938 threshold;
2939
2940 /*
2941 Threshold image.
2942 */
cristy6fccee12011-10-20 18:43:18 +00002943 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002944 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002945 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002946 else
cristy9b34e302011-11-05 02:15:45 +00002947 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2948 1.0);
cristye941a752011-10-15 01:52:48 +00002949 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002950 break;
2951 }
2952 if (LocaleCompare("thumbnail",option+1) == 0)
2953 {
2954 /*
2955 Thumbnail image.
2956 */
cristy6fccee12011-10-20 18:43:18 +00002957 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002958 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2959 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2960 exception);
2961 break;
2962 }
2963 if (LocaleCompare("tile",option+1) == 0)
2964 {
2965 if (*option == '+')
2966 {
2967 if (draw_info->fill_pattern != (Image *) NULL)
2968 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2969 break;
2970 }
2971 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2972 exception);
2973 break;
2974 }
2975 if (LocaleCompare("tint",option+1) == 0)
2976 {
2977 /*
2978 Tint the image.
2979 */
cristy6fccee12011-10-20 18:43:18 +00002980 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00002981 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002982 break;
2983 }
2984 if (LocaleCompare("transform",option+1) == 0)
2985 {
2986 /*
2987 Affine transform image.
2988 */
cristy6fccee12011-10-20 18:43:18 +00002989 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002990 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2991 exception);
2992 break;
2993 }
2994 if (LocaleCompare("transparent",option+1) == 0)
2995 {
cristy4c08aed2011-07-01 19:47:50 +00002996 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002997 target;
2998
cristy6fccee12011-10-20 18:43:18 +00002999 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00003000 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00003001 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003002 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00003003 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00003004 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003005 break;
3006 }
3007 if (LocaleCompare("transpose",option+1) == 0)
3008 {
3009 /*
3010 Transpose image scanlines.
3011 */
cristy6fccee12011-10-20 18:43:18 +00003012 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003013 mogrify_image=TransposeImage(*image,exception);
3014 break;
3015 }
3016 if (LocaleCompare("transverse",option+1) == 0)
3017 {
3018 /*
3019 Transverse image scanlines.
3020 */
cristy6fccee12011-10-20 18:43:18 +00003021 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003022 mogrify_image=TransverseImage(*image,exception);
3023 break;
3024 }
3025 if (LocaleCompare("treedepth",option+1) == 0)
3026 {
3027 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3028 break;
3029 }
3030 if (LocaleCompare("trim",option+1) == 0)
3031 {
3032 /*
3033 Trim image.
3034 */
cristy6fccee12011-10-20 18:43:18 +00003035 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003036 mogrify_image=TrimImage(*image,exception);
3037 break;
3038 }
3039 if (LocaleCompare("type",option+1) == 0)
3040 {
3041 ImageType
3042 type;
3043
cristy6fccee12011-10-20 18:43:18 +00003044 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003045 if (*option == '+')
3046 type=UndefinedType;
3047 else
3048 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3049 argv[i+1]);
3050 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003051 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003052 break;
3053 }
3054 break;
3055 }
3056 case 'u':
3057 {
3058 if (LocaleCompare("undercolor",option+1) == 0)
3059 {
cristy9950d572011-10-01 18:22:35 +00003060 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3061 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003062 break;
3063 }
3064 if (LocaleCompare("unique",option+1) == 0)
3065 {
3066 if (*option == '+')
3067 {
3068 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3069 break;
3070 }
3071 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3072 (void) SetImageArtifact(*image,"verbose","true");
3073 break;
3074 }
3075 if (LocaleCompare("unique-colors",option+1) == 0)
3076 {
3077 /*
3078 Unique image colors.
3079 */
cristy6fccee12011-10-20 18:43:18 +00003080 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003081 mogrify_image=UniqueImageColors(*image,exception);
3082 break;
3083 }
3084 if (LocaleCompare("unsharp",option+1) == 0)
3085 {
3086 /*
3087 Unsharp mask image.
3088 */
cristy6fccee12011-10-20 18:43:18 +00003089 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003090 flags=ParseGeometry(argv[i+1],&geometry_info);
3091 if ((flags & SigmaValue) == 0)
3092 geometry_info.sigma=1.0;
3093 if ((flags & XiValue) == 0)
3094 geometry_info.xi=1.0;
3095 if ((flags & PsiValue) == 0)
3096 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003097 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3098 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003099 break;
3100 }
3101 break;
3102 }
3103 case 'v':
3104 {
3105 if (LocaleCompare("verbose",option+1) == 0)
3106 {
3107 (void) SetImageArtifact(*image,option+1,
3108 *option == '+' ? "false" : "true");
3109 break;
3110 }
3111 if (LocaleCompare("vignette",option+1) == 0)
3112 {
3113 /*
3114 Vignette image.
3115 */
cristy6fccee12011-10-20 18:43:18 +00003116 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003117 flags=ParseGeometry(argv[i+1],&geometry_info);
3118 if ((flags & SigmaValue) == 0)
3119 geometry_info.sigma=1.0;
3120 if ((flags & XiValue) == 0)
3121 geometry_info.xi=0.1*(*image)->columns;
3122 if ((flags & PsiValue) == 0)
3123 geometry_info.psi=0.1*(*image)->rows;
3124 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00003125 geometry_info.sigma,(*image)->bias,(ssize_t)
3126 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
3127 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003128 break;
3129 }
3130 if (LocaleCompare("virtual-pixel",option+1) == 0)
3131 {
3132 if (*option == '+')
3133 {
3134 (void) SetImageVirtualPixelMethod(*image,
cristy387430f2012-02-07 13:09:46 +00003135 UndefinedVirtualPixelMethod,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003136 break;
3137 }
3138 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3139 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy387430f2012-02-07 13:09:46 +00003140 argv[i+1]),exception);
anthonydf8ebac2011-04-27 09:03:19 +00003141 break;
3142 }
3143 break;
3144 }
3145 case 'w':
3146 {
3147 if (LocaleCompare("wave",option+1) == 0)
3148 {
3149 /*
3150 Wave image.
3151 */
cristy6fccee12011-10-20 18:43:18 +00003152 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003153 flags=ParseGeometry(argv[i+1],&geometry_info);
3154 if ((flags & SigmaValue) == 0)
3155 geometry_info.sigma=1.0;
3156 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003157 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003158 break;
3159 }
3160 if (LocaleCompare("weight",option+1) == 0)
3161 {
3162 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3163 if (LocaleCompare(argv[i+1],"all") == 0)
3164 draw_info->weight=0;
3165 if (LocaleCompare(argv[i+1],"bold") == 0)
3166 draw_info->weight=700;
3167 if (LocaleCompare(argv[i+1],"bolder") == 0)
3168 if (draw_info->weight <= 800)
3169 draw_info->weight+=100;
3170 if (LocaleCompare(argv[i+1],"lighter") == 0)
3171 if (draw_info->weight >= 100)
3172 draw_info->weight-=100;
3173 if (LocaleCompare(argv[i+1],"normal") == 0)
3174 draw_info->weight=400;
3175 break;
3176 }
3177 if (LocaleCompare("white-threshold",option+1) == 0)
3178 {
3179 /*
3180 White threshold image.
3181 */
cristy6fccee12011-10-20 18:43:18 +00003182 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003183 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003184 break;
3185 }
3186 break;
3187 }
3188 default:
3189 break;
3190 }
3191 /*
3192 Replace current image with any image that was generated
3193 */
3194 if (mogrify_image != (Image *) NULL)
3195 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003196 i+=count;
3197 }
3198 if (region_image != (Image *) NULL)
3199 {
anthonydf8ebac2011-04-27 09:03:19 +00003200 /*
3201 Composite transformed region onto image.
3202 */
cristy6fccee12011-10-20 18:43:18 +00003203 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonya129f702011-04-14 01:08:48 +00003204 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003205 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003206 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003207 *image=DestroyImage(*image);
3208 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003209 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003210 }
3211 /*
3212 Free resources.
3213 */
anthonydf8ebac2011-04-27 09:03:19 +00003214 quantize_info=DestroyQuantizeInfo(quantize_info);
3215 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003216 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003217 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003218 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003219}
3220
3221/*
3222%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3223% %
3224% %
3225% %
cristy5063d812010-10-19 16:28:10 +00003226+ 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 +00003227% %
3228% %
3229% %
3230%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3231%
3232% MogrifyImageCommand() transforms an image or a sequence of images. These
3233% transforms include image scaling, image rotation, color reduction, and
3234% others. The transmogrified image overwrites the original image.
3235%
3236% The format of the MogrifyImageCommand method is:
3237%
3238% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3239% const char **argv,char **metadata,ExceptionInfo *exception)
3240%
3241% A description of each parameter follows:
3242%
3243% o image_info: the image info.
3244%
3245% o argc: the number of elements in the argument vector.
3246%
3247% o argv: A text array containing the command line arguments.
3248%
3249% o metadata: any metadata is returned here.
3250%
3251% o exception: return any errors or warnings in this structure.
3252%
3253*/
3254
3255static MagickBooleanType MogrifyUsage(void)
3256{
3257 static const char
3258 *miscellaneous[]=
3259 {
3260 "-debug events display copious debugging information",
3261 "-help print program options",
3262 "-list type print a list of supported option arguments",
3263 "-log format format of debugging information",
3264 "-version print version information",
3265 (char *) NULL
3266 },
3267 *operators[]=
3268 {
3269 "-adaptive-blur geometry",
3270 " adaptively blur pixels; decrease effect near edges",
3271 "-adaptive-resize geometry",
3272 " adaptively resize image using 'mesh' interpolation",
3273 "-adaptive-sharpen geometry",
3274 " adaptively sharpen pixels; increase effect near edges",
3275 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3276 " transparent, extract, background, or shape",
3277 "-annotate geometry text",
3278 " annotate the image with text",
3279 "-auto-gamma automagically adjust gamma level of image",
3280 "-auto-level automagically adjust color levels of image",
3281 "-auto-orient automagically orient (rotate) image",
3282 "-bench iterations measure performance",
3283 "-black-threshold value",
3284 " force all pixels below the threshold into black",
3285 "-blue-shift simulate a scene at nighttime in the moonlight",
3286 "-blur geometry reduce image noise and reduce detail levels",
3287 "-border geometry surround image with a border of color",
3288 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003289 "-brightness-contrast geometry",
3290 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003291 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003292 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003293 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003294 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003295 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003296 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003297 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003298 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003299 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003300 "-contrast enhance or reduce the image contrast",
3301 "-contrast-stretch geometry",
3302 " improve contrast by `stretching' the intensity range",
3303 "-convolve coefficients",
3304 " apply a convolution kernel to the image",
3305 "-cycle amount cycle the image colormap",
3306 "-decipher filename convert cipher pixels to plain pixels",
3307 "-deskew threshold straighten an image",
3308 "-despeckle reduce the speckles within an image",
3309 "-distort method args",
3310 " distort images according to given method ad args",
3311 "-draw string annotate the image with a graphic primitive",
3312 "-edge radius apply a filter to detect edges in the image",
3313 "-encipher filename convert plain pixels to cipher pixels",
3314 "-emboss radius emboss an image",
3315 "-enhance apply a digital filter to enhance a noisy image",
3316 "-equalize perform histogram equalization to an image",
3317 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003318 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003319 "-extent geometry set the image size",
3320 "-extract geometry extract area from image",
3321 "-fft implements the discrete Fourier transform (DFT)",
3322 "-flip flip image vertically",
3323 "-floodfill geometry color",
3324 " floodfill the image with color",
3325 "-flop flop image horizontally",
3326 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003327 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003328 " apply function over image values",
3329 "-gamma value level of gamma correction",
3330 "-gaussian-blur geometry",
3331 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003332 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003333 "-identify identify the format and characteristics of the image",
3334 "-ift implements the inverse discrete Fourier transform (DFT)",
3335 "-implode amount implode image pixels about the center",
anthonyfd706f92012-01-19 04:22:02 +00003336 "-interpolative-resize geometry",
3337 " resize image using interpolation",
cristy3ed852e2009-09-05 21:47:34 +00003338 "-lat geometry local adaptive thresholding",
3339 "-layers method optimize, merge, or compare image layers",
3340 "-level value adjust the level of image contrast",
3341 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003342 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003343 "-linear-stretch geometry",
3344 " improve contrast by `stretching with saturation'",
3345 "-liquid-rescale geometry",
3346 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003347 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003348 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003349 "-modulate value vary the brightness, saturation, and hue",
3350 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003351 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003352 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003353 "-motion-blur geometry",
3354 " simulate motion blur",
3355 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003356 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003357 "-normalize transform image to span the full range of colors",
3358 "-opaque color change this color to the fill color",
3359 "-ordered-dither NxN",
3360 " add a noise pattern to the image with specific",
3361 " amplitudes",
3362 "-paint radius simulate an oil painting",
3363 "-polaroid angle simulate a Polaroid picture",
3364 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003365 "-profile filename add, delete, or apply an image profile",
3366 "-quantize colorspace reduce colors in this colorspace",
3367 "-radial-blur angle radial blur the image",
3368 "-raise value lighten/darken image edges to create a 3-D effect",
3369 "-random-threshold low,high",
3370 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003371 "-region geometry apply options to a portion of the image",
3372 "-render render vector graphics",
3373 "-repage geometry size and location of an image canvas",
3374 "-resample geometry change the resolution of an image",
3375 "-resize geometry resize the image",
3376 "-roll geometry roll an image vertically or horizontally",
3377 "-rotate degrees apply Paeth rotation to the image",
3378 "-sample geometry scale image with pixel sampling",
3379 "-scale geometry scale the image",
3380 "-segment values segment an image",
3381 "-selective-blur geometry",
3382 " selectively blur pixels within a contrast threshold",
3383 "-sepia-tone threshold",
3384 " simulate a sepia-toned photo",
3385 "-set property value set an image property",
3386 "-shade degrees shade the image using a distant light source",
3387 "-shadow geometry simulate an image shadow",
3388 "-sharpen geometry sharpen the image",
3389 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003390 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003391 "-sigmoidal-contrast geometry",
3392 " increase the contrast without saturating highlights or shadows",
3393 "-sketch geometry simulate a pencil sketch",
3394 "-solarize threshold negate all pixels above the threshold level",
3395 "-sparse-color method args",
3396 " fill in a image based on a few color points",
3397 "-splice geometry splice the background color into the image",
3398 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003399 "-statistic type radius",
3400 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003401 "-strip strip image of all profiles and comments",
3402 "-swirl degrees swirl image pixels about the center",
3403 "-threshold value threshold the image",
3404 "-thumbnail geometry create a thumbnail of the image",
3405 "-tile filename tile image when filling a graphic primitive",
3406 "-tint value tint the image with the fill color",
3407 "-transform affine transform image",
3408 "-transparent color make this color transparent within the image",
3409 "-transpose flip image vertically and rotate 90 degrees",
3410 "-transverse flop image horizontally and rotate 270 degrees",
3411 "-trim trim image edges",
3412 "-type type image type",
3413 "-unique-colors discard all but one of any pixel color",
3414 "-unsharp geometry sharpen the image",
3415 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003416 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003417 "-white-threshold value",
3418 " force all pixels above the threshold into white",
3419 (char *) NULL
3420 },
3421 *sequence_operators[]=
3422 {
cristy4285d782011-02-09 20:12:28 +00003423 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003424 "-clut apply a color lookup table to the image",
3425 "-coalesce merge a sequence of images",
3426 "-combine combine a sequence of images",
3427 "-composite composite image",
3428 "-crop geometry cut out a rectangular region of the image",
3429 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003430 "-evaluate-sequence operator",
3431 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003432 "-flatten flatten a sequence of images",
3433 "-fx expression apply mathematical expression to an image channel(s)",
3434 "-hald-clut apply a Hald color lookup table to the image",
3435 "-morph value morph an image sequence",
3436 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003437 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003438 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003439 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003440 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003441 "-write filename write images to this file",
3442 (char *) NULL
3443 },
3444 *settings[]=
3445 {
3446 "-adjoin join images into a single multi-image file",
3447 "-affine matrix affine transform matrix",
3448 "-alpha option activate, deactivate, reset, or set the alpha channel",
3449 "-antialias remove pixel-aliasing",
3450 "-authenticate password",
3451 " decipher image with this password",
3452 "-attenuate value lessen (or intensify) when adding noise to an image",
3453 "-background color background color",
3454 "-bias value add bias when convolving an image",
3455 "-black-point-compensation",
3456 " use black point compensation",
3457 "-blue-primary point chromaticity blue primary point",
3458 "-bordercolor color border color",
3459 "-caption string assign a caption to an image",
3460 "-channel type apply option to select image channels",
3461 "-colors value preferred number of colors in the image",
3462 "-colorspace type alternate image colorspace",
3463 "-comment string annotate image with comment",
3464 "-compose operator set image composite operator",
3465 "-compress type type of pixel compression when writing the image",
anthonyfd706f92012-01-19 04:22:02 +00003466 "-define format:option=value",
cristy3ed852e2009-09-05 21:47:34 +00003467 " define one or more image format options",
3468 "-delay value display the next image after pausing",
3469 "-density geometry horizontal and vertical density of the image",
3470 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003471 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003472 "-display server get image or font from this X server",
3473 "-dispose method layer disposal method",
3474 "-dither method apply error diffusion to image",
3475 "-encoding type text encoding type",
3476 "-endian type endianness (MSB or LSB) of the image",
3477 "-family name render text with this font family",
3478 "-fill color color to use when filling a graphic primitive",
3479 "-filter type use this filter when resizing an image",
3480 "-font name render text with this font",
anthonyfd706f92012-01-19 04:22:02 +00003481 "-format \"string\" output formatted image characteristics",
cristy3ed852e2009-09-05 21:47:34 +00003482 "-fuzz distance colors within this distance are considered equal",
3483 "-gravity type horizontal and vertical text placement",
3484 "-green-primary point chromaticity green primary point",
3485 "-intent type type of rendering intent when managing the image color",
3486 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003487 "-interline-spacing value",
3488 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003489 "-interpolate method pixel color interpolation method",
3490 "-interword-spacing value",
3491 " set the space between two words",
3492 "-kerning value set the space between two letters",
3493 "-label string assign a label to an image",
3494 "-limit type value pixel cache resource limit",
3495 "-loop iterations add Netscape loop extension to your GIF animation",
3496 "-mask filename associate a mask with the image",
3497 "-mattecolor color frame color",
3498 "-monitor monitor progress",
3499 "-orient type image orientation",
3500 "-page geometry size and location of an image canvas (setting)",
3501 "-ping efficiently determine image attributes",
3502 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003503 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003504 "-preview type image preview type",
3505 "-quality value JPEG/MIFF/PNG compression level",
3506 "-quiet suppress all warning messages",
3507 "-red-primary point chromaticity red primary point",
3508 "-regard-warnings pay attention to warning messages",
3509 "-remap filename transform image colors to match this set of colors",
3510 "-respect-parentheses settings remain in effect until parenthesis boundary",
3511 "-sampling-factor geometry",
3512 " horizontal and vertical sampling factor",
3513 "-scene value image scene number",
3514 "-seed value seed a new sequence of pseudo-random numbers",
3515 "-size geometry width and height of image",
3516 "-stretch type render text with this font stretch",
3517 "-stroke color graphic primitive stroke color",
3518 "-strokewidth value graphic primitive stroke width",
3519 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003520 "-synchronize synchronize image to storage device",
3521 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003522 "-texture filename name of texture to tile onto the image background",
3523 "-tile-offset geometry",
3524 " tile offset",
3525 "-treedepth value color tree depth",
3526 "-transparent-color color",
3527 " transparent color",
3528 "-undercolor color annotation bounding box color",
3529 "-units type the units of image resolution",
3530 "-verbose print detailed information about the image",
3531 "-view FlashPix viewing transforms",
3532 "-virtual-pixel method",
3533 " virtual pixel access method",
3534 "-weight type render text with this font weight",
3535 "-white-point point chromaticity white point",
3536 (char *) NULL
3537 },
3538 *stack_operators[]=
3539 {
anthonyb69c4b32011-03-23 04:37:44 +00003540 "-delete indexes delete the image from the image sequence",
3541 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003542 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003543 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003544 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003545 "-swap indexes swap two images in the image sequence",
3546 (char *) NULL
3547 };
3548
3549 const char
3550 **p;
3551
cristybb503372010-05-27 20:51:26 +00003552 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003553 (void) printf("Copyright: %s\n",GetMagickCopyright());
3554 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003555 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3556 GetClientName());
3557 (void) printf("\nImage Settings:\n");
3558 for (p=settings; *p != (char *) NULL; p++)
3559 (void) printf(" %s\n",*p);
3560 (void) printf("\nImage Operators:\n");
3561 for (p=operators; *p != (char *) NULL; p++)
3562 (void) printf(" %s\n",*p);
3563 (void) printf("\nImage Sequence Operators:\n");
3564 for (p=sequence_operators; *p != (char *) NULL; p++)
3565 (void) printf(" %s\n",*p);
3566 (void) printf("\nImage Stack Operators:\n");
3567 for (p=stack_operators; *p != (char *) NULL; p++)
3568 (void) printf(" %s\n",*p);
3569 (void) printf("\nMiscellaneous Options:\n");
3570 for (p=miscellaneous; *p != (char *) NULL; p++)
3571 (void) printf(" %s\n",*p);
3572 (void) printf(
anthonyfd706f92012-01-19 04:22:02 +00003573 "\nBy default, the image format of 'file' is determined by its magic\n");
cristy3ed852e2009-09-05 21:47:34 +00003574 (void) printf(
3575 "number. To specify a particular image format, precede the filename\n");
3576 (void) printf(
3577 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3578 (void) printf(
3579 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3580 (void) printf("'-' for standard input or output.\n");
3581 return(MagickFalse);
3582}
3583
3584WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3585 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3586{
3587#define DestroyMogrify() \
3588{ \
3589 if (format != (char *) NULL) \
3590 format=DestroyString(format); \
3591 if (path != (char *) NULL) \
3592 path=DestroyString(path); \
3593 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003594 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003595 argv[i]=DestroyString(argv[i]); \
3596 argv=(char **) RelinquishMagickMemory(argv); \
3597}
3598#define ThrowMogrifyException(asperity,tag,option) \
3599{ \
3600 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3601 option); \
3602 DestroyMogrify(); \
3603 return(MagickFalse); \
3604}
3605#define ThrowMogrifyInvalidArgumentException(option,argument) \
3606{ \
3607 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3608 "InvalidArgument","`%s': %s",argument,option); \
3609 DestroyMogrify(); \
3610 return(MagickFalse); \
3611}
3612
3613 char
3614 *format,
3615 *option,
3616 *path;
3617
3618 Image
3619 *image;
3620
3621 ImageStack
3622 image_stack[MaxImageStackDepth+1];
3623
cristy3ed852e2009-09-05 21:47:34 +00003624 MagickBooleanType
3625 global_colormap;
3626
3627 MagickBooleanType
3628 fire,
cristyebbcfea2011-02-25 02:43:54 +00003629 pend,
3630 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003631
3632 MagickStatusType
3633 status;
3634
cristyebbcfea2011-02-25 02:43:54 +00003635 register ssize_t
3636 i;
3637
3638 ssize_t
3639 j,
3640 k;
3641
cristy3ed852e2009-09-05 21:47:34 +00003642 /*
3643 Set defaults.
3644 */
3645 assert(image_info != (ImageInfo *) NULL);
3646 assert(image_info->signature == MagickSignature);
3647 if (image_info->debug != MagickFalse)
3648 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3649 assert(exception != (ExceptionInfo *) NULL);
3650 if (argc == 2)
3651 {
3652 option=argv[1];
3653 if ((LocaleCompare("version",option+1) == 0) ||
3654 (LocaleCompare("-version",option+1) == 0))
3655 {
cristyb51dff52011-05-19 16:55:47 +00003656 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003657 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003658 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3659 GetMagickCopyright());
3660 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3661 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003662 return(MagickFalse);
3663 }
3664 }
3665 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003666 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003667 format=(char *) NULL;
3668 path=(char *) NULL;
3669 global_colormap=MagickFalse;
3670 k=0;
3671 j=1;
3672 NewImageStack();
3673 option=(char *) NULL;
3674 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003675 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003676 status=MagickTrue;
3677 /*
3678 Parse command line.
3679 */
3680 ReadCommandlLine(argc,&argv);
3681 status=ExpandFilenames(&argc,&argv);
3682 if (status == MagickFalse)
3683 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3684 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003685 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003686 {
3687 option=argv[i];
3688 if (LocaleCompare(option,"(") == 0)
3689 {
3690 FireImageStack(MagickFalse,MagickTrue,pend);
3691 if (k == MaxImageStackDepth)
3692 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3693 option);
3694 PushImageStack();
3695 continue;
3696 }
3697 if (LocaleCompare(option,")") == 0)
3698 {
3699 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3700 if (k == 0)
3701 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3702 PopImageStack();
3703 continue;
3704 }
cristy042ee782011-04-22 18:48:30 +00003705 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003706 {
3707 char
3708 backup_filename[MaxTextExtent],
3709 *filename;
3710
3711 Image
3712 *images;
3713
3714 /*
3715 Option is a file name: begin by reading image from specified file.
3716 */
3717 FireImageStack(MagickFalse,MagickFalse,pend);
3718 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003719 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003720 filename=argv[++i];
3721 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3722 images=ReadImages(image_info,exception);
3723 status&=(images != (Image *) NULL) &&
3724 (exception->severity < ErrorException);
3725 if (images == (Image *) NULL)
3726 continue;
cristydaa76602010-06-30 13:05:11 +00003727 if (format != (char *) NULL)
3728 (void) CopyMagickString(images->filename,images->magick_filename,
3729 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003730 if (path != (char *) NULL)
3731 {
3732 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003733 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003734 path,*DirectorySeparator,filename);
3735 }
3736 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003737 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003738 AppendImageStack(images);
3739 FinalizeImageSettings(image_info,image,MagickFalse);
3740 if (global_colormap != MagickFalse)
3741 {
3742 QuantizeInfo
3743 *quantize_info;
3744
3745 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003746 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003747 quantize_info=DestroyQuantizeInfo(quantize_info);
3748 }
3749 *backup_filename='\0';
3750 if ((LocaleCompare(image->filename,"-") != 0) &&
3751 (IsPathWritable(image->filename) != MagickFalse))
3752 {
cristybb503372010-05-27 20:51:26 +00003753 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003754 i;
3755
3756 /*
3757 Rename image file as backup.
3758 */
3759 (void) CopyMagickString(backup_filename,image->filename,
3760 MaxTextExtent);
3761 for (i=0; i < 6; i++)
3762 {
3763 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3764 if (IsPathAccessible(backup_filename) == MagickFalse)
3765 break;
3766 }
3767 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003768 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003769 *backup_filename='\0';
3770 }
3771 /*
3772 Write transmogrified image to disk.
3773 */
3774 image_info->synchronize=MagickTrue;
3775 status&=WriteImages(image_info,image,image->filename,exception);
3776 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003777 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003778 RemoveAllImageStack();
3779 continue;
3780 }
3781 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3782 switch (*(option+1))
3783 {
3784 case 'a':
3785 {
3786 if (LocaleCompare("adaptive-blur",option+1) == 0)
3787 {
3788 i++;
cristybb503372010-05-27 20:51:26 +00003789 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003790 ThrowMogrifyException(OptionError,"MissingArgument",option);
3791 if (IsGeometry(argv[i]) == MagickFalse)
3792 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3793 break;
3794 }
3795 if (LocaleCompare("adaptive-resize",option+1) == 0)
3796 {
3797 i++;
cristybb503372010-05-27 20:51:26 +00003798 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003799 ThrowMogrifyException(OptionError,"MissingArgument",option);
3800 if (IsGeometry(argv[i]) == MagickFalse)
3801 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3802 break;
3803 }
3804 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3805 {
3806 i++;
cristybb503372010-05-27 20:51:26 +00003807 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003808 ThrowMogrifyException(OptionError,"MissingArgument",option);
3809 if (IsGeometry(argv[i]) == MagickFalse)
3810 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3811 break;
3812 }
3813 if (LocaleCompare("affine",option+1) == 0)
3814 {
3815 if (*option == '+')
3816 break;
3817 i++;
cristybb503372010-05-27 20:51:26 +00003818 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003819 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003820 break;
3821 }
3822 if (LocaleCompare("alpha",option+1) == 0)
3823 {
cristybb503372010-05-27 20:51:26 +00003824 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003825 type;
3826
3827 if (*option == '+')
3828 break;
3829 i++;
cristybb503372010-05-27 20:51:26 +00003830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003831 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003832 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003833 if (type < 0)
3834 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3835 argv[i]);
3836 break;
3837 }
3838 if (LocaleCompare("annotate",option+1) == 0)
3839 {
3840 if (*option == '+')
3841 break;
3842 i++;
cristybb503372010-05-27 20:51:26 +00003843 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003844 ThrowMogrifyException(OptionError,"MissingArgument",option);
3845 if (IsGeometry(argv[i]) == MagickFalse)
3846 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003847 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003848 ThrowMogrifyException(OptionError,"MissingArgument",option);
3849 i++;
3850 break;
3851 }
3852 if (LocaleCompare("antialias",option+1) == 0)
3853 break;
3854 if (LocaleCompare("append",option+1) == 0)
3855 break;
3856 if (LocaleCompare("attenuate",option+1) == 0)
3857 {
3858 if (*option == '+')
3859 break;
3860 i++;
cristybb503372010-05-27 20:51:26 +00003861 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003862 ThrowMogrifyException(OptionError,"MissingArgument",option);
3863 if (IsGeometry(argv[i]) == MagickFalse)
3864 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3865 break;
3866 }
3867 if (LocaleCompare("authenticate",option+1) == 0)
3868 {
3869 if (*option == '+')
3870 break;
3871 i++;
cristybb503372010-05-27 20:51:26 +00003872 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003873 ThrowMogrifyException(OptionError,"MissingArgument",option);
3874 break;
3875 }
3876 if (LocaleCompare("auto-gamma",option+1) == 0)
3877 break;
3878 if (LocaleCompare("auto-level",option+1) == 0)
3879 break;
3880 if (LocaleCompare("auto-orient",option+1) == 0)
3881 break;
3882 if (LocaleCompare("average",option+1) == 0)
3883 break;
3884 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3885 }
3886 case 'b':
3887 {
3888 if (LocaleCompare("background",option+1) == 0)
3889 {
3890 if (*option == '+')
3891 break;
3892 i++;
cristybb503372010-05-27 20:51:26 +00003893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003894 ThrowMogrifyException(OptionError,"MissingArgument",option);
3895 break;
3896 }
3897 if (LocaleCompare("bias",option+1) == 0)
3898 {
3899 if (*option == '+')
3900 break;
3901 i++;
cristybb503372010-05-27 20:51:26 +00003902 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003903 ThrowMogrifyException(OptionError,"MissingArgument",option);
3904 if (IsGeometry(argv[i]) == MagickFalse)
3905 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3906 break;
3907 }
3908 if (LocaleCompare("black-point-compensation",option+1) == 0)
3909 break;
3910 if (LocaleCompare("black-threshold",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 if (IsGeometry(argv[i]) == MagickFalse)
3918 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3919 break;
3920 }
3921 if (LocaleCompare("blue-primary",option+1) == 0)
3922 {
3923 if (*option == '+')
3924 break;
3925 i++;
cristybb503372010-05-27 20:51:26 +00003926 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003927 ThrowMogrifyException(OptionError,"MissingArgument",option);
3928 if (IsGeometry(argv[i]) == MagickFalse)
3929 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3930 break;
3931 }
3932 if (LocaleCompare("blue-shift",option+1) == 0)
3933 {
3934 i++;
cristybb503372010-05-27 20:51:26 +00003935 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003936 ThrowMogrifyException(OptionError,"MissingArgument",option);
3937 if (IsGeometry(argv[i]) == MagickFalse)
3938 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3939 break;
3940 }
3941 if (LocaleCompare("blur",option+1) == 0)
3942 {
3943 i++;
cristybb503372010-05-27 20:51:26 +00003944 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003945 ThrowMogrifyException(OptionError,"MissingArgument",option);
3946 if (IsGeometry(argv[i]) == MagickFalse)
3947 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3948 break;
3949 }
3950 if (LocaleCompare("border",option+1) == 0)
3951 {
3952 if (*option == '+')
3953 break;
3954 i++;
cristybb503372010-05-27 20:51:26 +00003955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003956 ThrowMogrifyException(OptionError,"MissingArgument",option);
3957 if (IsGeometry(argv[i]) == MagickFalse)
3958 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3959 break;
3960 }
3961 if (LocaleCompare("bordercolor",option+1) == 0)
3962 {
3963 if (*option == '+')
3964 break;
3965 i++;
cristybb503372010-05-27 20:51:26 +00003966 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003967 ThrowMogrifyException(OptionError,"MissingArgument",option);
3968 break;
3969 }
3970 if (LocaleCompare("box",option+1) == 0)
3971 {
3972 if (*option == '+')
3973 break;
3974 i++;
cristybb503372010-05-27 20:51:26 +00003975 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003976 ThrowMogrifyException(OptionError,"MissingArgument",option);
3977 break;
3978 }
cristya28d6b82010-01-11 20:03:47 +00003979 if (LocaleCompare("brightness-contrast",option+1) == 0)
3980 {
3981 i++;
cristybb503372010-05-27 20:51:26 +00003982 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003983 ThrowMogrifyException(OptionError,"MissingArgument",option);
3984 if (IsGeometry(argv[i]) == MagickFalse)
3985 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3986 break;
3987 }
cristy3ed852e2009-09-05 21:47:34 +00003988 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3989 }
3990 case 'c':
3991 {
3992 if (LocaleCompare("cache",option+1) == 0)
3993 {
3994 if (*option == '+')
3995 break;
3996 i++;
cristybb503372010-05-27 20:51:26 +00003997 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003998 ThrowMogrifyException(OptionError,"MissingArgument",option);
3999 if (IsGeometry(argv[i]) == MagickFalse)
4000 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4001 break;
4002 }
4003 if (LocaleCompare("caption",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("channel",option+1) == 0)
4013 {
cristybb503372010-05-27 20:51:26 +00004014 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004015 channel;
4016
4017 if (*option == '+')
4018 break;
4019 i++;
cristybb503372010-05-27 20:51:26 +00004020 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004021 ThrowMogrifyException(OptionError,"MissingArgument",option);
4022 channel=ParseChannelOption(argv[i]);
4023 if (channel < 0)
4024 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4025 argv[i]);
4026 break;
4027 }
4028 if (LocaleCompare("cdl",option+1) == 0)
4029 {
4030 if (*option == '+')
4031 break;
4032 i++;
cristybb503372010-05-27 20:51:26 +00004033 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004034 ThrowMogrifyException(OptionError,"MissingArgument",option);
4035 break;
4036 }
4037 if (LocaleCompare("charcoal",option+1) == 0)
4038 {
4039 if (*option == '+')
4040 break;
4041 i++;
cristybb503372010-05-27 20:51:26 +00004042 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004043 ThrowMogrifyException(OptionError,"MissingArgument",option);
4044 if (IsGeometry(argv[i]) == MagickFalse)
4045 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4046 break;
4047 }
4048 if (LocaleCompare("chop",option+1) == 0)
4049 {
4050 if (*option == '+')
4051 break;
4052 i++;
cristybb503372010-05-27 20:51:26 +00004053 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004054 ThrowMogrifyException(OptionError,"MissingArgument",option);
4055 if (IsGeometry(argv[i]) == MagickFalse)
4056 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4057 break;
4058 }
cristy1eb45dd2009-09-25 16:38:06 +00004059 if (LocaleCompare("clamp",option+1) == 0)
4060 break;
4061 if (LocaleCompare("clip",option+1) == 0)
4062 break;
cristy3ed852e2009-09-05 21:47:34 +00004063 if (LocaleCompare("clip-mask",option+1) == 0)
4064 {
4065 if (*option == '+')
4066 break;
4067 i++;
cristybb503372010-05-27 20:51:26 +00004068 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004069 ThrowMogrifyException(OptionError,"MissingArgument",option);
4070 break;
4071 }
4072 if (LocaleCompare("clut",option+1) == 0)
4073 break;
4074 if (LocaleCompare("coalesce",option+1) == 0)
4075 break;
4076 if (LocaleCompare("colorize",option+1) == 0)
4077 {
4078 if (*option == '+')
4079 break;
4080 i++;
cristybb503372010-05-27 20:51:26 +00004081 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004082 ThrowMogrifyException(OptionError,"MissingArgument",option);
4083 if (IsGeometry(argv[i]) == MagickFalse)
4084 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4085 break;
4086 }
cristye6365592010-04-02 17:31:23 +00004087 if (LocaleCompare("color-matrix",option+1) == 0)
4088 {
cristyb6bd4ad2010-08-08 01:12:27 +00004089 KernelInfo
4090 *kernel_info;
4091
cristye6365592010-04-02 17:31:23 +00004092 if (*option == '+')
4093 break;
4094 i++;
cristybb503372010-05-27 20:51:26 +00004095 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004096 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004097 kernel_info=AcquireKernelInfo(argv[i]);
4098 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004099 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004100 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004101 break;
4102 }
cristy3ed852e2009-09-05 21:47:34 +00004103 if (LocaleCompare("colors",option+1) == 0)
4104 {
4105 if (*option == '+')
4106 break;
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("colorspace",option+1) == 0)
4115 {
cristybb503372010-05-27 20:51:26 +00004116 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004117 colorspace;
4118
4119 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);
cristy042ee782011-04-22 18:48:30 +00004124 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004125 argv[i]);
4126 if (colorspace < 0)
4127 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4128 argv[i]);
4129 break;
4130 }
4131 if (LocaleCompare("combine",option+1) == 0)
4132 break;
4133 if (LocaleCompare("comment",option+1) == 0)
4134 {
4135 if (*option == '+')
4136 break;
4137 i++;
cristybb503372010-05-27 20:51:26 +00004138 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004139 ThrowMogrifyException(OptionError,"MissingArgument",option);
4140 break;
4141 }
4142 if (LocaleCompare("composite",option+1) == 0)
4143 break;
4144 if (LocaleCompare("compress",option+1) == 0)
4145 {
cristybb503372010-05-27 20:51:26 +00004146 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004147 compress;
4148
4149 if (*option == '+')
4150 break;
4151 i++;
cristybb503372010-05-27 20:51:26 +00004152 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004153 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004154 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004155 argv[i]);
4156 if (compress < 0)
4157 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4158 argv[i]);
4159 break;
4160 }
cristy22879752009-10-25 23:55:40 +00004161 if (LocaleCompare("concurrent",option+1) == 0)
4162 break;
cristy3ed852e2009-09-05 21:47:34 +00004163 if (LocaleCompare("contrast",option+1) == 0)
4164 break;
4165 if (LocaleCompare("contrast-stretch",option+1) == 0)
4166 {
4167 i++;
cristybb503372010-05-27 20:51:26 +00004168 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004169 ThrowMogrifyException(OptionError,"MissingArgument",option);
4170 if (IsGeometry(argv[i]) == MagickFalse)
4171 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4172 break;
4173 }
4174 if (LocaleCompare("convolve",option+1) == 0)
4175 {
cristyb6bd4ad2010-08-08 01:12:27 +00004176 KernelInfo
4177 *kernel_info;
4178
cristy3ed852e2009-09-05 21:47:34 +00004179 if (*option == '+')
4180 break;
4181 i++;
cristybb503372010-05-27 20:51:26 +00004182 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004183 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004184 kernel_info=AcquireKernelInfo(argv[i]);
4185 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004186 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004187 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004188 break;
4189 }
4190 if (LocaleCompare("crop",option+1) == 0)
4191 {
4192 if (*option == '+')
4193 break;
4194 i++;
cristybb503372010-05-27 20:51:26 +00004195 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004196 ThrowMogrifyException(OptionError,"MissingArgument",option);
4197 if (IsGeometry(argv[i]) == MagickFalse)
4198 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4199 break;
4200 }
4201 if (LocaleCompare("cycle",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 }
4212 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4213 }
4214 case 'd':
4215 {
4216 if (LocaleCompare("decipher",option+1) == 0)
4217 {
4218 if (*option == '+')
4219 break;
4220 i++;
cristybb503372010-05-27 20:51:26 +00004221 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004222 ThrowMogrifyException(OptionError,"MissingArgument",option);
4223 break;
4224 }
4225 if (LocaleCompare("deconstruct",option+1) == 0)
4226 break;
4227 if (LocaleCompare("debug",option+1) == 0)
4228 {
cristybb503372010-05-27 20:51:26 +00004229 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004230 event;
4231
4232 if (*option == '+')
4233 break;
4234 i++;
cristybb503372010-05-27 20:51:26 +00004235 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004236 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004237 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004238 if (event < 0)
4239 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4240 argv[i]);
4241 (void) SetLogEventMask(argv[i]);
4242 break;
4243 }
4244 if (LocaleCompare("define",option+1) == 0)
4245 {
4246 i++;
cristybb503372010-05-27 20:51:26 +00004247 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004248 ThrowMogrifyException(OptionError,"MissingArgument",option);
4249 if (*option == '+')
4250 {
4251 const char
4252 *define;
4253
4254 define=GetImageOption(image_info,argv[i]);
4255 if (define == (const char *) NULL)
4256 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4257 break;
4258 }
4259 break;
4260 }
4261 if (LocaleCompare("delay",option+1) == 0)
4262 {
4263 if (*option == '+')
4264 break;
4265 i++;
cristybb503372010-05-27 20:51:26 +00004266 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004267 ThrowMogrifyException(OptionError,"MissingArgument",option);
4268 if (IsGeometry(argv[i]) == MagickFalse)
4269 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4270 break;
4271 }
cristyecb10ff2011-03-22 13:14:03 +00004272 if (LocaleCompare("delete",option+1) == 0)
4273 {
4274 if (*option == '+')
4275 break;
4276 i++;
4277 if (i == (ssize_t) (argc-1))
4278 ThrowMogrifyException(OptionError,"MissingArgument",option);
4279 if (IsGeometry(argv[i]) == MagickFalse)
4280 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4281 break;
4282 }
cristy3ed852e2009-09-05 21:47:34 +00004283 if (LocaleCompare("density",option+1) == 0)
4284 {
4285 if (*option == '+')
4286 break;
4287 i++;
cristybb503372010-05-27 20:51:26 +00004288 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004289 ThrowMogrifyException(OptionError,"MissingArgument",option);
4290 if (IsGeometry(argv[i]) == MagickFalse)
4291 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4292 break;
4293 }
4294 if (LocaleCompare("depth",option+1) == 0)
4295 {
4296 if (*option == '+')
4297 break;
4298 i++;
cristybb503372010-05-27 20:51:26 +00004299 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004300 ThrowMogrifyException(OptionError,"MissingArgument",option);
4301 if (IsGeometry(argv[i]) == MagickFalse)
4302 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4303 break;
4304 }
4305 if (LocaleCompare("deskew",option+1) == 0)
4306 {
4307 if (*option == '+')
4308 break;
4309 i++;
cristybb503372010-05-27 20:51:26 +00004310 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004311 ThrowMogrifyException(OptionError,"MissingArgument",option);
4312 if (IsGeometry(argv[i]) == MagickFalse)
4313 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4314 break;
4315 }
4316 if (LocaleCompare("despeckle",option+1) == 0)
4317 break;
4318 if (LocaleCompare("dft",option+1) == 0)
4319 break;
cristyc9b12952010-03-28 01:12:28 +00004320 if (LocaleCompare("direction",option+1) == 0)
4321 {
cristybb503372010-05-27 20:51:26 +00004322 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004323 direction;
4324
4325 if (*option == '+')
4326 break;
4327 i++;
cristybb503372010-05-27 20:51:26 +00004328 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004329 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004330 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004331 argv[i]);
4332 if (direction < 0)
4333 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4334 argv[i]);
4335 break;
4336 }
cristy3ed852e2009-09-05 21:47:34 +00004337 if (LocaleCompare("display",option+1) == 0)
4338 {
4339 if (*option == '+')
4340 break;
4341 i++;
cristybb503372010-05-27 20:51:26 +00004342 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004343 ThrowMogrifyException(OptionError,"MissingArgument",option);
4344 break;
4345 }
4346 if (LocaleCompare("dispose",option+1) == 0)
4347 {
cristybb503372010-05-27 20:51:26 +00004348 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004349 dispose;
4350
4351 if (*option == '+')
4352 break;
4353 i++;
cristybb503372010-05-27 20:51:26 +00004354 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004355 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004356 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004357 if (dispose < 0)
4358 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4359 argv[i]);
4360 break;
4361 }
4362 if (LocaleCompare("distort",option+1) == 0)
4363 {
cristybb503372010-05-27 20:51:26 +00004364 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004365 op;
4366
4367 i++;
cristybb503372010-05-27 20:51:26 +00004368 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004369 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004370 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004371 if (op < 0)
4372 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4373 argv[i]);
4374 i++;
cristybb503372010-05-27 20:51:26 +00004375 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004376 ThrowMogrifyException(OptionError,"MissingArgument",option);
4377 break;
4378 }
4379 if (LocaleCompare("dither",option+1) == 0)
4380 {
cristybb503372010-05-27 20:51:26 +00004381 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004382 method;
4383
4384 if (*option == '+')
4385 break;
4386 i++;
cristybb503372010-05-27 20:51:26 +00004387 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004388 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004389 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004390 if (method < 0)
4391 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4392 argv[i]);
4393 break;
4394 }
4395 if (LocaleCompare("draw",option+1) == 0)
4396 {
4397 if (*option == '+')
4398 break;
4399 i++;
cristybb503372010-05-27 20:51:26 +00004400 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004401 ThrowMogrifyException(OptionError,"MissingArgument",option);
4402 break;
4403 }
cristyecb10ff2011-03-22 13:14:03 +00004404 if (LocaleCompare("duplicate",option+1) == 0)
4405 {
4406 if (*option == '+')
4407 break;
4408 i++;
4409 if (i == (ssize_t) (argc-1))
4410 ThrowMogrifyException(OptionError,"MissingArgument",option);
4411 if (IsGeometry(argv[i]) == MagickFalse)
4412 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4413 break;
4414 }
cristy22879752009-10-25 23:55:40 +00004415 if (LocaleCompare("duration",option+1) == 0)
4416 {
4417 if (*option == '+')
4418 break;
4419 i++;
cristybb503372010-05-27 20:51:26 +00004420 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004421 ThrowMogrifyException(OptionError,"MissingArgument",option);
4422 if (IsGeometry(argv[i]) == MagickFalse)
4423 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4424 break;
4425 }
cristy3ed852e2009-09-05 21:47:34 +00004426 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4427 }
4428 case 'e':
4429 {
4430 if (LocaleCompare("edge",option+1) == 0)
4431 {
4432 if (*option == '+')
4433 break;
4434 i++;
cristybb503372010-05-27 20:51:26 +00004435 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004436 ThrowMogrifyException(OptionError,"MissingArgument",option);
4437 if (IsGeometry(argv[i]) == MagickFalse)
4438 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4439 break;
4440 }
4441 if (LocaleCompare("emboss",option+1) == 0)
4442 {
4443 if (*option == '+')
4444 break;
4445 i++;
cristybb503372010-05-27 20:51:26 +00004446 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004447 ThrowMogrifyException(OptionError,"MissingArgument",option);
4448 if (IsGeometry(argv[i]) == MagickFalse)
4449 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4450 break;
4451 }
4452 if (LocaleCompare("encipher",option+1) == 0)
4453 {
4454 if (*option == '+')
4455 break;
4456 i++;
cristybb503372010-05-27 20:51:26 +00004457 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004458 ThrowMogrifyException(OptionError,"MissingArgument",option);
4459 break;
4460 }
4461 if (LocaleCompare("encoding",option+1) == 0)
4462 {
4463 if (*option == '+')
4464 break;
4465 i++;
cristybb503372010-05-27 20:51:26 +00004466 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004467 ThrowMogrifyException(OptionError,"MissingArgument",option);
4468 break;
4469 }
4470 if (LocaleCompare("endian",option+1) == 0)
4471 {
cristybb503372010-05-27 20:51:26 +00004472 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004473 endian;
4474
4475 if (*option == '+')
4476 break;
4477 i++;
cristybb503372010-05-27 20:51:26 +00004478 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004479 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004480 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004481 if (endian < 0)
4482 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4483 argv[i]);
4484 break;
4485 }
4486 if (LocaleCompare("enhance",option+1) == 0)
4487 break;
4488 if (LocaleCompare("equalize",option+1) == 0)
4489 break;
4490 if (LocaleCompare("evaluate",option+1) == 0)
4491 {
cristybb503372010-05-27 20:51:26 +00004492 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004493 op;
4494
4495 if (*option == '+')
4496 break;
4497 i++;
cristybb503372010-05-27 20:51:26 +00004498 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004499 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004500 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004501 if (op < 0)
4502 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4503 argv[i]);
4504 i++;
cristybb503372010-05-27 20:51:26 +00004505 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004506 ThrowMogrifyException(OptionError,"MissingArgument",option);
4507 if (IsGeometry(argv[i]) == MagickFalse)
4508 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4509 break;
4510 }
cristyd18ae7c2010-03-07 17:39:52 +00004511 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4512 {
cristybb503372010-05-27 20:51:26 +00004513 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004514 op;
4515
4516 if (*option == '+')
4517 break;
4518 i++;
cristybb503372010-05-27 20:51:26 +00004519 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004520 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004521 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004522 if (op < 0)
4523 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4524 argv[i]);
4525 break;
4526 }
cristy3ed852e2009-09-05 21:47:34 +00004527 if (LocaleCompare("extent",option+1) == 0)
4528 {
4529 if (*option == '+')
4530 break;
4531 i++;
cristybb503372010-05-27 20:51:26 +00004532 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004533 ThrowMogrifyException(OptionError,"MissingArgument",option);
4534 if (IsGeometry(argv[i]) == MagickFalse)
4535 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4536 break;
4537 }
4538 if (LocaleCompare("extract",option+1) == 0)
4539 {
4540 if (*option == '+')
4541 break;
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 if (IsGeometry(argv[i]) == MagickFalse)
4546 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4547 break;
4548 }
4549 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4550 }
4551 case 'f':
4552 {
4553 if (LocaleCompare("family",option+1) == 0)
4554 {
4555 if (*option == '+')
4556 break;
4557 i++;
cristybb503372010-05-27 20:51:26 +00004558 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004559 ThrowMogrifyException(OptionError,"MissingArgument",option);
4560 break;
4561 }
4562 if (LocaleCompare("fill",option+1) == 0)
4563 {
4564 if (*option == '+')
4565 break;
4566 i++;
cristybb503372010-05-27 20:51:26 +00004567 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004568 ThrowMogrifyException(OptionError,"MissingArgument",option);
4569 break;
4570 }
4571 if (LocaleCompare("filter",option+1) == 0)
4572 {
cristybb503372010-05-27 20:51:26 +00004573 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004574 filter;
4575
4576 if (*option == '+')
4577 break;
4578 i++;
cristybb503372010-05-27 20:51:26 +00004579 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004580 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004581 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004582 if (filter < 0)
4583 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4584 argv[i]);
4585 break;
4586 }
4587 if (LocaleCompare("flatten",option+1) == 0)
4588 break;
4589 if (LocaleCompare("flip",option+1) == 0)
4590 break;
4591 if (LocaleCompare("flop",option+1) == 0)
4592 break;
4593 if (LocaleCompare("floodfill",option+1) == 0)
4594 {
4595 if (*option == '+')
4596 break;
4597 i++;
cristybb503372010-05-27 20:51:26 +00004598 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004599 ThrowMogrifyException(OptionError,"MissingArgument",option);
4600 if (IsGeometry(argv[i]) == MagickFalse)
4601 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4602 i++;
cristybb503372010-05-27 20:51:26 +00004603 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004604 ThrowMogrifyException(OptionError,"MissingArgument",option);
4605 break;
4606 }
4607 if (LocaleCompare("font",option+1) == 0)
4608 {
4609 if (*option == '+')
4610 break;
4611 i++;
cristybb503372010-05-27 20:51:26 +00004612 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004613 ThrowMogrifyException(OptionError,"MissingArgument",option);
4614 break;
4615 }
4616 if (LocaleCompare("format",option+1) == 0)
4617 {
4618 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4619 (void) CloneString(&format,(char *) NULL);
4620 if (*option == '+')
4621 break;
4622 i++;
cristybb503372010-05-27 20:51:26 +00004623 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004624 ThrowMogrifyException(OptionError,"MissingArgument",option);
4625 (void) CloneString(&format,argv[i]);
4626 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4627 (void) ConcatenateMagickString(image_info->filename,":",
4628 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004629 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004630 if (*image_info->magick == '\0')
4631 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4632 format);
4633 break;
4634 }
4635 if (LocaleCompare("frame",option+1) == 0)
4636 {
4637 if (*option == '+')
4638 break;
4639 i++;
cristybb503372010-05-27 20:51:26 +00004640 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004641 ThrowMogrifyException(OptionError,"MissingArgument",option);
4642 if (IsGeometry(argv[i]) == MagickFalse)
4643 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4644 break;
4645 }
4646 if (LocaleCompare("function",option+1) == 0)
4647 {
cristybb503372010-05-27 20:51:26 +00004648 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004649 op;
4650
4651 if (*option == '+')
4652 break;
4653 i++;
cristybb503372010-05-27 20:51:26 +00004654 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004655 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004656 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004657 if (op < 0)
4658 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4659 i++;
cristybb503372010-05-27 20:51:26 +00004660 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004661 ThrowMogrifyException(OptionError,"MissingArgument",option);
4662 break;
4663 }
4664 if (LocaleCompare("fuzz",option+1) == 0)
4665 {
4666 if (*option == '+')
4667 break;
4668 i++;
cristybb503372010-05-27 20:51:26 +00004669 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004670 ThrowMogrifyException(OptionError,"MissingArgument",option);
4671 if (IsGeometry(argv[i]) == MagickFalse)
4672 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4673 break;
4674 }
4675 if (LocaleCompare("fx",option+1) == 0)
4676 {
4677 if (*option == '+')
4678 break;
4679 i++;
cristybb503372010-05-27 20:51:26 +00004680 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004681 ThrowMogrifyException(OptionError,"MissingArgument",option);
4682 break;
4683 }
4684 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4685 }
4686 case 'g':
4687 {
4688 if (LocaleCompare("gamma",option+1) == 0)
4689 {
4690 i++;
cristybb503372010-05-27 20:51:26 +00004691 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004692 ThrowMogrifyException(OptionError,"MissingArgument",option);
4693 if (IsGeometry(argv[i]) == MagickFalse)
4694 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4695 break;
4696 }
4697 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4698 (LocaleCompare("gaussian",option+1) == 0))
4699 {
4700 i++;
cristybb503372010-05-27 20:51:26 +00004701 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004702 ThrowMogrifyException(OptionError,"MissingArgument",option);
4703 if (IsGeometry(argv[i]) == MagickFalse)
4704 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4705 break;
4706 }
4707 if (LocaleCompare("geometry",option+1) == 0)
4708 {
4709 if (*option == '+')
4710 break;
4711 i++;
cristybb503372010-05-27 20:51:26 +00004712 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004713 ThrowMogrifyException(OptionError,"MissingArgument",option);
4714 if (IsGeometry(argv[i]) == MagickFalse)
4715 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4716 break;
4717 }
4718 if (LocaleCompare("gravity",option+1) == 0)
4719 {
cristybb503372010-05-27 20:51:26 +00004720 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004721 gravity;
4722
4723 if (*option == '+')
4724 break;
4725 i++;
cristybb503372010-05-27 20:51:26 +00004726 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004727 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004728 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004729 if (gravity < 0)
4730 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4731 argv[i]);
4732 break;
4733 }
4734 if (LocaleCompare("green-primary",option+1) == 0)
4735 {
4736 if (*option == '+')
4737 break;
4738 i++;
cristybb503372010-05-27 20:51:26 +00004739 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004740 ThrowMogrifyException(OptionError,"MissingArgument",option);
4741 if (IsGeometry(argv[i]) == MagickFalse)
4742 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4743 break;
4744 }
4745 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4746 }
4747 case 'h':
4748 {
4749 if (LocaleCompare("hald-clut",option+1) == 0)
4750 break;
4751 if ((LocaleCompare("help",option+1) == 0) ||
4752 (LocaleCompare("-help",option+1) == 0))
4753 return(MogrifyUsage());
4754 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4755 }
4756 case 'i':
4757 {
4758 if (LocaleCompare("identify",option+1) == 0)
4759 break;
4760 if (LocaleCompare("idft",option+1) == 0)
4761 break;
4762 if (LocaleCompare("implode",option+1) == 0)
4763 {
4764 if (*option == '+')
4765 break;
4766 i++;
cristybb503372010-05-27 20:51:26 +00004767 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004768 ThrowMogrifyException(OptionError,"MissingArgument",option);
4769 if (IsGeometry(argv[i]) == MagickFalse)
4770 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4771 break;
4772 }
4773 if (LocaleCompare("intent",option+1) == 0)
4774 {
cristybb503372010-05-27 20:51:26 +00004775 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004776 intent;
4777
4778 if (*option == '+')
4779 break;
4780 i++;
cristybb503372010-05-27 20:51:26 +00004781 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004782 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004783 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004784 if (intent < 0)
4785 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4786 argv[i]);
4787 break;
4788 }
4789 if (LocaleCompare("interlace",option+1) == 0)
4790 {
cristybb503372010-05-27 20:51:26 +00004791 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004792 interlace;
4793
4794 if (*option == '+')
4795 break;
4796 i++;
cristybb503372010-05-27 20:51:26 +00004797 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004798 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004799 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004800 argv[i]);
4801 if (interlace < 0)
4802 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4803 argv[i]);
4804 break;
4805 }
cristyb32b90a2009-09-07 21:45:48 +00004806 if (LocaleCompare("interline-spacing",option+1) == 0)
4807 {
4808 if (*option == '+')
4809 break;
4810 i++;
cristybb503372010-05-27 20:51:26 +00004811 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004812 ThrowMogrifyException(OptionError,"MissingArgument",option);
4813 if (IsGeometry(argv[i]) == MagickFalse)
4814 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4815 break;
4816 }
cristy3ed852e2009-09-05 21:47:34 +00004817 if (LocaleCompare("interpolate",option+1) == 0)
4818 {
cristybb503372010-05-27 20:51:26 +00004819 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004820 interpolate;
4821
4822 if (*option == '+')
4823 break;
4824 i++;
cristybb503372010-05-27 20:51:26 +00004825 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004826 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004827 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004828 argv[i]);
4829 if (interpolate < 0)
4830 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4831 argv[i]);
4832 break;
4833 }
4834 if (LocaleCompare("interword-spacing",option+1) == 0)
4835 {
4836 if (*option == '+')
4837 break;
4838 i++;
cristybb503372010-05-27 20:51:26 +00004839 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004840 ThrowMogrifyException(OptionError,"MissingArgument",option);
4841 if (IsGeometry(argv[i]) == MagickFalse)
4842 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4843 break;
4844 }
4845 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4846 }
4847 case 'k':
4848 {
4849 if (LocaleCompare("kerning",option+1) == 0)
4850 {
4851 if (*option == '+')
4852 break;
4853 i++;
cristybb503372010-05-27 20:51:26 +00004854 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004855 ThrowMogrifyException(OptionError,"MissingArgument",option);
4856 if (IsGeometry(argv[i]) == MagickFalse)
4857 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4858 break;
4859 }
4860 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4861 }
4862 case 'l':
4863 {
4864 if (LocaleCompare("label",option+1) == 0)
4865 {
4866 if (*option == '+')
4867 break;
4868 i++;
cristybb503372010-05-27 20:51:26 +00004869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004870 ThrowMogrifyException(OptionError,"MissingArgument",option);
4871 break;
4872 }
4873 if (LocaleCompare("lat",option+1) == 0)
4874 {
4875 if (*option == '+')
4876 break;
4877 i++;
cristybb503372010-05-27 20:51:26 +00004878 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004879 ThrowMogrifyException(OptionError,"MissingArgument",option);
4880 if (IsGeometry(argv[i]) == MagickFalse)
4881 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4882 }
4883 if (LocaleCompare("layers",option+1) == 0)
4884 {
cristybb503372010-05-27 20:51:26 +00004885 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004886 type;
4887
4888 if (*option == '+')
4889 break;
4890 i++;
cristybb503372010-05-27 20:51:26 +00004891 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004892 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004893 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004894 if (type < 0)
4895 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4896 argv[i]);
4897 break;
4898 }
4899 if (LocaleCompare("level",option+1) == 0)
4900 {
4901 i++;
cristybb503372010-05-27 20:51:26 +00004902 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004903 ThrowMogrifyException(OptionError,"MissingArgument",option);
4904 if (IsGeometry(argv[i]) == MagickFalse)
4905 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4906 break;
4907 }
4908 if (LocaleCompare("level-colors",option+1) == 0)
4909 {
4910 i++;
cristybb503372010-05-27 20:51:26 +00004911 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004912 ThrowMogrifyException(OptionError,"MissingArgument",option);
4913 break;
4914 }
cristy3ed852e2009-09-05 21:47:34 +00004915 if (LocaleCompare("limit",option+1) == 0)
4916 {
4917 char
4918 *p;
4919
4920 double
4921 value;
4922
cristybb503372010-05-27 20:51:26 +00004923 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004924 resource;
4925
4926 if (*option == '+')
4927 break;
4928 i++;
cristybb503372010-05-27 20:51:26 +00004929 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004930 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004931 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004932 argv[i]);
4933 if (resource < 0)
4934 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4935 argv[i]);
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);
cristydbdd0e32011-11-04 23:29:40 +00004939 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004940 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004941 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4942 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4943 break;
4944 }
4945 if (LocaleCompare("liquid-rescale",option+1) == 0)
4946 {
4947 i++;
cristybb503372010-05-27 20:51:26 +00004948 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004949 ThrowMogrifyException(OptionError,"MissingArgument",option);
4950 if (IsGeometry(argv[i]) == MagickFalse)
4951 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4952 break;
4953 }
4954 if (LocaleCompare("list",option+1) == 0)
4955 {
cristybb503372010-05-27 20:51:26 +00004956 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004957 list;
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);
cristy042ee782011-04-22 18:48:30 +00004964 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004965 if (list < 0)
4966 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004967 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004968 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004969 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004970 }
4971 if (LocaleCompare("log",option+1) == 0)
4972 {
4973 if (*option == '+')
4974 break;
4975 i++;
cristybb503372010-05-27 20:51:26 +00004976 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004977 (strchr(argv[i],'%') == (char *) NULL))
4978 ThrowMogrifyException(OptionError,"MissingArgument",option);
4979 break;
4980 }
4981 if (LocaleCompare("loop",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 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4993 }
4994 case 'm':
4995 {
4996 if (LocaleCompare("map",option+1) == 0)
4997 {
4998 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
4999 if (*option == '+')
5000 break;
5001 i++;
cristybb503372010-05-27 20:51:26 +00005002 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005003 ThrowMogrifyException(OptionError,"MissingArgument",option);
5004 break;
5005 }
5006 if (LocaleCompare("mask",option+1) == 0)
5007 {
5008 if (*option == '+')
5009 break;
5010 i++;
cristybb503372010-05-27 20:51:26 +00005011 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005012 ThrowMogrifyException(OptionError,"MissingArgument",option);
5013 break;
5014 }
5015 if (LocaleCompare("matte",option+1) == 0)
5016 break;
5017 if (LocaleCompare("mattecolor",option+1) == 0)
5018 {
5019 if (*option == '+')
5020 break;
5021 i++;
cristybb503372010-05-27 20:51:26 +00005022 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005023 ThrowMogrifyException(OptionError,"MissingArgument",option);
5024 break;
5025 }
cristyf40785b2010-03-06 02:27:27 +00005026 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005027 break;
cristyf40785b2010-03-06 02:27:27 +00005028 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005029 break;
cristy3ed852e2009-09-05 21:47:34 +00005030 if (LocaleCompare("modulate",option+1) == 0)
5031 {
5032 if (*option == '+')
5033 break;
5034 i++;
cristybb503372010-05-27 20:51:26 +00005035 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005036 ThrowMogrifyException(OptionError,"MissingArgument",option);
5037 if (IsGeometry(argv[i]) == MagickFalse)
5038 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5039 break;
5040 }
5041 if (LocaleCompare("median",option+1) == 0)
5042 {
5043 if (*option == '+')
5044 break;
5045 i++;
cristybb503372010-05-27 20:51:26 +00005046 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005047 ThrowMogrifyException(OptionError,"MissingArgument",option);
5048 if (IsGeometry(argv[i]) == MagickFalse)
5049 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5050 break;
5051 }
cristy69ec32d2011-02-27 23:57:09 +00005052 if (LocaleCompare("mode",option+1) == 0)
5053 {
5054 if (*option == '+')
5055 break;
5056 i++;
5057 if (i == (ssize_t) argc)
5058 ThrowMogrifyException(OptionError,"MissingArgument",option);
5059 if (IsGeometry(argv[i]) == MagickFalse)
5060 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5061 break;
5062 }
cristy3ed852e2009-09-05 21:47:34 +00005063 if (LocaleCompare("monitor",option+1) == 0)
5064 break;
5065 if (LocaleCompare("monochrome",option+1) == 0)
5066 break;
5067 if (LocaleCompare("morph",option+1) == 0)
5068 {
5069 if (*option == '+')
5070 break;
5071 i++;
cristybb503372010-05-27 20:51:26 +00005072 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005073 ThrowMogrifyException(OptionError,"MissingArgument",option);
5074 if (IsGeometry(argv[i]) == MagickFalse)
5075 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5076 break;
5077 }
anthony29188a82010-01-22 10:12:34 +00005078 if (LocaleCompare("morphology",option+1) == 0)
5079 {
anthony29188a82010-01-22 10:12:34 +00005080 char
5081 token[MaxTextExtent];
5082
cristyb6bd4ad2010-08-08 01:12:27 +00005083 KernelInfo
5084 *kernel_info;
5085
5086 ssize_t
5087 op;
5088
anthony29188a82010-01-22 10:12:34 +00005089 i++;
cristybb503372010-05-27 20:51:26 +00005090 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005091 ThrowMogrifyException(OptionError,"MissingArgument",option);
5092 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005093 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005094 if (op < 0)
5095 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005096 token);
anthony29188a82010-01-22 10:12:34 +00005097 i++;
cristybb503372010-05-27 20:51:26 +00005098 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005099 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005100 kernel_info=AcquireKernelInfo(argv[i]);
5101 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005102 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005103 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005104 break;
5105 }
cristy3ed852e2009-09-05 21:47:34 +00005106 if (LocaleCompare("mosaic",option+1) == 0)
5107 break;
5108 if (LocaleCompare("motion-blur",option+1) == 0)
5109 {
5110 if (*option == '+')
5111 break;
5112 i++;
cristybb503372010-05-27 20:51:26 +00005113 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005114 ThrowMogrifyException(OptionError,"MissingArgument",option);
5115 if (IsGeometry(argv[i]) == MagickFalse)
5116 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5117 break;
5118 }
5119 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5120 }
5121 case 'n':
5122 {
5123 if (LocaleCompare("negate",option+1) == 0)
5124 break;
5125 if (LocaleCompare("noise",option+1) == 0)
5126 {
5127 i++;
cristybb503372010-05-27 20:51:26 +00005128 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005129 ThrowMogrifyException(OptionError,"MissingArgument",option);
5130 if (*option == '+')
5131 {
cristybb503372010-05-27 20:51:26 +00005132 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005133 noise;
5134
cristy042ee782011-04-22 18:48:30 +00005135 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005136 if (noise < 0)
5137 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5138 argv[i]);
5139 break;
5140 }
5141 if (IsGeometry(argv[i]) == MagickFalse)
5142 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5143 break;
5144 }
5145 if (LocaleCompare("noop",option+1) == 0)
5146 break;
5147 if (LocaleCompare("normalize",option+1) == 0)
5148 break;
5149 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5150 }
5151 case 'o':
5152 {
5153 if (LocaleCompare("opaque",option+1) == 0)
5154 {
cristy3ed852e2009-09-05 21:47:34 +00005155 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 break;
5159 }
5160 if (LocaleCompare("ordered-dither",option+1) == 0)
5161 {
5162 if (*option == '+')
5163 break;
5164 i++;
cristybb503372010-05-27 20:51:26 +00005165 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005166 ThrowMogrifyException(OptionError,"MissingArgument",option);
5167 break;
5168 }
5169 if (LocaleCompare("orient",option+1) == 0)
5170 {
cristybb503372010-05-27 20:51:26 +00005171 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005172 orientation;
5173
5174 orientation=UndefinedOrientation;
5175 if (*option == '+')
5176 break;
5177 i++;
cristybb503372010-05-27 20:51:26 +00005178 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005179 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005180 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005181 argv[i]);
5182 if (orientation < 0)
5183 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5184 argv[i]);
5185 break;
5186 }
5187 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5188 }
5189 case 'p':
5190 {
5191 if (LocaleCompare("page",option+1) == 0)
5192 {
5193 if (*option == '+')
5194 break;
5195 i++;
cristybb503372010-05-27 20:51:26 +00005196 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005197 ThrowMogrifyException(OptionError,"MissingArgument",option);
5198 break;
5199 }
5200 if (LocaleCompare("paint",option+1) == 0)
5201 {
5202 if (*option == '+')
5203 break;
5204 i++;
cristybb503372010-05-27 20:51:26 +00005205 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005206 ThrowMogrifyException(OptionError,"MissingArgument",option);
5207 if (IsGeometry(argv[i]) == MagickFalse)
5208 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5209 break;
5210 }
5211 if (LocaleCompare("path",option+1) == 0)
5212 {
5213 (void) CloneString(&path,(char *) NULL);
5214 if (*option == '+')
5215 break;
5216 i++;
cristybb503372010-05-27 20:51:26 +00005217 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005218 ThrowMogrifyException(OptionError,"MissingArgument",option);
5219 (void) CloneString(&path,argv[i]);
5220 break;
5221 }
5222 if (LocaleCompare("pointsize",option+1) == 0)
5223 {
5224 if (*option == '+')
5225 break;
5226 i++;
cristybb503372010-05-27 20:51:26 +00005227 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005228 ThrowMogrifyException(OptionError,"MissingArgument",option);
5229 if (IsGeometry(argv[i]) == MagickFalse)
5230 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5231 break;
5232 }
5233 if (LocaleCompare("polaroid",option+1) == 0)
5234 {
5235 if (*option == '+')
5236 break;
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 if (IsGeometry(argv[i]) == MagickFalse)
5241 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5242 break;
5243 }
5244 if (LocaleCompare("posterize",option+1) == 0)
5245 {
5246 if (*option == '+')
5247 break;
5248 i++;
cristybb503372010-05-27 20:51:26 +00005249 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005250 ThrowMogrifyException(OptionError,"MissingArgument",option);
5251 if (IsGeometry(argv[i]) == MagickFalse)
5252 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5253 break;
5254 }
cristye7f51092010-01-17 00:39:37 +00005255 if (LocaleCompare("precision",option+1) == 0)
5256 {
5257 if (*option == '+')
5258 break;
5259 i++;
cristybb503372010-05-27 20:51:26 +00005260 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005261 ThrowMogrifyException(OptionError,"MissingArgument",option);
5262 if (IsGeometry(argv[i]) == MagickFalse)
5263 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5264 break;
5265 }
cristy3ed852e2009-09-05 21:47:34 +00005266 if (LocaleCompare("print",option+1) == 0)
5267 {
5268 if (*option == '+')
5269 break;
5270 i++;
cristybb503372010-05-27 20:51:26 +00005271 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005272 ThrowMogrifyException(OptionError,"MissingArgument",option);
5273 break;
5274 }
5275 if (LocaleCompare("process",option+1) == 0)
5276 {
5277 if (*option == '+')
5278 break;
5279 i++;
cristybb503372010-05-27 20:51:26 +00005280 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005281 ThrowMogrifyException(OptionError,"MissingArgument",option);
5282 break;
5283 }
5284 if (LocaleCompare("profile",option+1) == 0)
5285 {
5286 i++;
cristybb503372010-05-27 20:51:26 +00005287 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005288 ThrowMogrifyException(OptionError,"MissingArgument",option);
5289 break;
5290 }
5291 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5292 }
5293 case 'q':
5294 {
5295 if (LocaleCompare("quality",option+1) == 0)
5296 {
5297 if (*option == '+')
5298 break;
5299 i++;
cristybb503372010-05-27 20:51:26 +00005300 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005301 ThrowMogrifyException(OptionError,"MissingArgument",option);
5302 if (IsGeometry(argv[i]) == MagickFalse)
5303 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5304 break;
5305 }
5306 if (LocaleCompare("quantize",option+1) == 0)
5307 {
cristybb503372010-05-27 20:51:26 +00005308 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005309 colorspace;
5310
5311 if (*option == '+')
5312 break;
5313 i++;
cristybb503372010-05-27 20:51:26 +00005314 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005315 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005316 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005317 argv[i]);
5318 if (colorspace < 0)
5319 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5320 argv[i]);
5321 break;
5322 }
5323 if (LocaleCompare("quiet",option+1) == 0)
5324 break;
5325 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5326 }
5327 case 'r':
5328 {
5329 if (LocaleCompare("radial-blur",option+1) == 0)
5330 {
5331 i++;
cristybb503372010-05-27 20:51:26 +00005332 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005333 ThrowMogrifyException(OptionError,"MissingArgument",option);
5334 if (IsGeometry(argv[i]) == MagickFalse)
5335 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5336 break;
5337 }
5338 if (LocaleCompare("raise",option+1) == 0)
5339 {
5340 i++;
cristybb503372010-05-27 20:51:26 +00005341 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005342 ThrowMogrifyException(OptionError,"MissingArgument",option);
5343 if (IsGeometry(argv[i]) == MagickFalse)
5344 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5345 break;
5346 }
5347 if (LocaleCompare("random-threshold",option+1) == 0)
5348 {
5349 if (*option == '+')
5350 break;
5351 i++;
cristybb503372010-05-27 20:51:26 +00005352 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005353 ThrowMogrifyException(OptionError,"MissingArgument",option);
5354 if (IsGeometry(argv[i]) == MagickFalse)
5355 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5356 break;
5357 }
5358 if (LocaleCompare("red-primary",option+1) == 0)
5359 {
5360 if (*option == '+')
5361 break;
5362 i++;
cristybb503372010-05-27 20:51:26 +00005363 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005364 ThrowMogrifyException(OptionError,"MissingArgument",option);
5365 if (IsGeometry(argv[i]) == MagickFalse)
5366 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5367 }
cristy9f2083a2010-04-22 19:48:05 +00005368 if (LocaleCompare("regard-warnings",option+1) == 0)
5369 break;
cristy3ed852e2009-09-05 21:47:34 +00005370 if (LocaleCompare("region",option+1) == 0)
5371 {
5372 if (*option == '+')
5373 break;
5374 i++;
cristybb503372010-05-27 20:51:26 +00005375 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005376 ThrowMogrifyException(OptionError,"MissingArgument",option);
5377 if (IsGeometry(argv[i]) == MagickFalse)
5378 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5379 break;
5380 }
cristyf0c78232010-03-15 12:53:40 +00005381 if (LocaleCompare("remap",option+1) == 0)
5382 {
5383 if (*option == '+')
5384 break;
5385 i++;
cristybb503372010-05-27 20:51:26 +00005386 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005387 ThrowMogrifyException(OptionError,"MissingArgument",option);
5388 break;
5389 }
cristy3ed852e2009-09-05 21:47:34 +00005390 if (LocaleCompare("render",option+1) == 0)
5391 break;
5392 if (LocaleCompare("repage",option+1) == 0)
5393 {
5394 if (*option == '+')
5395 break;
5396 i++;
cristybb503372010-05-27 20:51:26 +00005397 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005398 ThrowMogrifyException(OptionError,"MissingArgument",option);
5399 if (IsGeometry(argv[i]) == MagickFalse)
5400 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5401 break;
5402 }
5403 if (LocaleCompare("resample",option+1) == 0)
5404 {
5405 if (*option == '+')
5406 break;
5407 i++;
cristybb503372010-05-27 20:51:26 +00005408 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005409 ThrowMogrifyException(OptionError,"MissingArgument",option);
5410 if (IsGeometry(argv[i]) == MagickFalse)
5411 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5412 break;
5413 }
5414 if (LocaleCompare("resize",option+1) == 0)
5415 {
5416 if (*option == '+')
5417 break;
5418 i++;
cristybb503372010-05-27 20:51:26 +00005419 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005420 ThrowMogrifyException(OptionError,"MissingArgument",option);
5421 if (IsGeometry(argv[i]) == MagickFalse)
5422 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5423 break;
5424 }
cristyebbcfea2011-02-25 02:43:54 +00005425 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5426 {
5427 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5428 break;
5429 }
cristy3ed852e2009-09-05 21:47:34 +00005430 if (LocaleCompare("reverse",option+1) == 0)
5431 break;
5432 if (LocaleCompare("roll",option+1) == 0)
5433 {
5434 if (*option == '+')
5435 break;
5436 i++;
cristybb503372010-05-27 20:51:26 +00005437 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005438 ThrowMogrifyException(OptionError,"MissingArgument",option);
5439 if (IsGeometry(argv[i]) == MagickFalse)
5440 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5441 break;
5442 }
5443 if (LocaleCompare("rotate",option+1) == 0)
5444 {
5445 i++;
cristybb503372010-05-27 20:51:26 +00005446 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005447 ThrowMogrifyException(OptionError,"MissingArgument",option);
5448 if (IsGeometry(argv[i]) == MagickFalse)
5449 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5450 break;
5451 }
5452 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5453 }
5454 case 's':
5455 {
5456 if (LocaleCompare("sample",option+1) == 0)
5457 {
5458 if (*option == '+')
5459 break;
5460 i++;
cristybb503372010-05-27 20:51:26 +00005461 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005462 ThrowMogrifyException(OptionError,"MissingArgument",option);
5463 if (IsGeometry(argv[i]) == MagickFalse)
5464 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5465 break;
5466 }
5467 if (LocaleCompare("sampling-factor",option+1) == 0)
5468 {
5469 if (*option == '+')
5470 break;
5471 i++;
cristybb503372010-05-27 20:51:26 +00005472 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005473 ThrowMogrifyException(OptionError,"MissingArgument",option);
5474 if (IsGeometry(argv[i]) == MagickFalse)
5475 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5476 break;
5477 }
5478 if (LocaleCompare("scale",option+1) == 0)
5479 {
5480 if (*option == '+')
5481 break;
5482 i++;
cristybb503372010-05-27 20:51:26 +00005483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005484 ThrowMogrifyException(OptionError,"MissingArgument",option);
5485 if (IsGeometry(argv[i]) == MagickFalse)
5486 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5487 break;
5488 }
5489 if (LocaleCompare("scene",option+1) == 0)
5490 {
5491 if (*option == '+')
5492 break;
5493 i++;
cristybb503372010-05-27 20:51:26 +00005494 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005495 ThrowMogrifyException(OptionError,"MissingArgument",option);
5496 if (IsGeometry(argv[i]) == MagickFalse)
5497 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5498 break;
5499 }
5500 if (LocaleCompare("seed",option+1) == 0)
5501 {
5502 if (*option == '+')
5503 break;
5504 i++;
cristybb503372010-05-27 20:51:26 +00005505 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005506 ThrowMogrifyException(OptionError,"MissingArgument",option);
5507 if (IsGeometry(argv[i]) == MagickFalse)
5508 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5509 break;
5510 }
5511 if (LocaleCompare("segment",option+1) == 0)
5512 {
5513 if (*option == '+')
5514 break;
5515 i++;
cristybb503372010-05-27 20:51:26 +00005516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005517 ThrowMogrifyException(OptionError,"MissingArgument",option);
5518 if (IsGeometry(argv[i]) == MagickFalse)
5519 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5520 break;
5521 }
5522 if (LocaleCompare("selective-blur",option+1) == 0)
5523 {
5524 i++;
cristybb503372010-05-27 20:51:26 +00005525 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005526 ThrowMogrifyException(OptionError,"MissingArgument",option);
5527 if (IsGeometry(argv[i]) == MagickFalse)
5528 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5529 break;
5530 }
5531 if (LocaleCompare("separate",option+1) == 0)
5532 break;
5533 if (LocaleCompare("sepia-tone",option+1) == 0)
5534 {
5535 if (*option == '+')
5536 break;
5537 i++;
cristybb503372010-05-27 20:51:26 +00005538 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005539 ThrowMogrifyException(OptionError,"MissingArgument",option);
5540 if (IsGeometry(argv[i]) == MagickFalse)
5541 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5542 break;
5543 }
5544 if (LocaleCompare("set",option+1) == 0)
5545 {
5546 i++;
cristybb503372010-05-27 20:51:26 +00005547 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005548 ThrowMogrifyException(OptionError,"MissingArgument",option);
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 break;
5555 }
5556 if (LocaleCompare("shade",option+1) == 0)
5557 {
5558 i++;
cristybb503372010-05-27 20:51:26 +00005559 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005560 ThrowMogrifyException(OptionError,"MissingArgument",option);
5561 if (IsGeometry(argv[i]) == MagickFalse)
5562 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5563 break;
5564 }
5565 if (LocaleCompare("shadow",option+1) == 0)
5566 {
5567 if (*option == '+')
5568 break;
5569 i++;
cristybb503372010-05-27 20:51:26 +00005570 if (i == (ssize_t) argc)
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("sharpen",option+1) == 0)
5577 {
5578 i++;
cristybb503372010-05-27 20:51:26 +00005579 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005580 ThrowMogrifyException(OptionError,"MissingArgument",option);
5581 if (IsGeometry(argv[i]) == MagickFalse)
5582 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5583 break;
5584 }
5585 if (LocaleCompare("shave",option+1) == 0)
5586 {
5587 if (*option == '+')
5588 break;
5589 i++;
cristybb503372010-05-27 20:51:26 +00005590 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005591 ThrowMogrifyException(OptionError,"MissingArgument",option);
5592 if (IsGeometry(argv[i]) == MagickFalse)
5593 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5594 break;
5595 }
5596 if (LocaleCompare("shear",option+1) == 0)
5597 {
5598 i++;
cristybb503372010-05-27 20:51:26 +00005599 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005600 ThrowMogrifyException(OptionError,"MissingArgument",option);
5601 if (IsGeometry(argv[i]) == MagickFalse)
5602 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5603 break;
5604 }
5605 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5606 {
5607 i++;
cristybb503372010-05-27 20:51:26 +00005608 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005609 ThrowMogrifyException(OptionError,"MissingArgument",option);
5610 if (IsGeometry(argv[i]) == MagickFalse)
5611 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5612 break;
5613 }
5614 if (LocaleCompare("size",option+1) == 0)
5615 {
5616 if (*option == '+')
5617 break;
5618 i++;
cristybb503372010-05-27 20:51:26 +00005619 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005620 ThrowMogrifyException(OptionError,"MissingArgument",option);
5621 if (IsGeometry(argv[i]) == MagickFalse)
5622 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5623 break;
5624 }
5625 if (LocaleCompare("sketch",option+1) == 0)
5626 {
5627 if (*option == '+')
5628 break;
5629 i++;
cristybb503372010-05-27 20:51:26 +00005630 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005631 ThrowMogrifyException(OptionError,"MissingArgument",option);
5632 if (IsGeometry(argv[i]) == MagickFalse)
5633 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5634 break;
5635 }
cristy4285d782011-02-09 20:12:28 +00005636 if (LocaleCompare("smush",option+1) == 0)
5637 {
cristy4285d782011-02-09 20:12:28 +00005638 i++;
5639 if (i == (ssize_t) argc)
5640 ThrowMogrifyException(OptionError,"MissingArgument",option);
5641 if (IsGeometry(argv[i]) == MagickFalse)
5642 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005643 i++;
5644 break;
5645 }
cristy3ed852e2009-09-05 21:47:34 +00005646 if (LocaleCompare("solarize",option+1) == 0)
5647 {
5648 if (*option == '+')
5649 break;
5650 i++;
cristybb503372010-05-27 20:51:26 +00005651 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005652 ThrowMogrifyException(OptionError,"MissingArgument",option);
5653 if (IsGeometry(argv[i]) == MagickFalse)
5654 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5655 break;
5656 }
5657 if (LocaleCompare("sparse-color",option+1) == 0)
5658 {
cristybb503372010-05-27 20:51:26 +00005659 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005660 op;
5661
5662 i++;
cristybb503372010-05-27 20:51:26 +00005663 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005664 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005665 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005666 if (op < 0)
5667 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5668 argv[i]);
5669 i++;
cristybb503372010-05-27 20:51:26 +00005670 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005671 ThrowMogrifyException(OptionError,"MissingArgument",option);
5672 break;
5673 }
5674 if (LocaleCompare("spread",option+1) == 0)
5675 {
5676 if (*option == '+')
5677 break;
5678 i++;
cristybb503372010-05-27 20:51:26 +00005679 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005680 ThrowMogrifyException(OptionError,"MissingArgument",option);
5681 if (IsGeometry(argv[i]) == MagickFalse)
5682 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5683 break;
5684 }
cristy0834d642011-03-18 18:26:08 +00005685 if (LocaleCompare("statistic",option+1) == 0)
5686 {
5687 ssize_t
5688 op;
5689
5690 if (*option == '+')
5691 break;
5692 i++;
5693 if (i == (ssize_t) argc)
5694 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005695 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005696 if (op < 0)
5697 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5698 argv[i]);
5699 i++;
5700 if (i == (ssize_t) (argc-1))
5701 ThrowMogrifyException(OptionError,"MissingArgument",option);
5702 if (IsGeometry(argv[i]) == MagickFalse)
5703 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5704 break;
5705 }
cristy3ed852e2009-09-05 21:47:34 +00005706 if (LocaleCompare("stretch",option+1) == 0)
5707 {
cristybb503372010-05-27 20:51:26 +00005708 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005709 stretch;
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 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005717 if (stretch < 0)
5718 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5719 argv[i]);
5720 break;
5721 }
5722 if (LocaleCompare("strip",option+1) == 0)
5723 break;
5724 if (LocaleCompare("stroke",option+1) == 0)
5725 {
5726 if (*option == '+')
5727 break;
5728 i++;
cristybb503372010-05-27 20:51:26 +00005729 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005730 ThrowMogrifyException(OptionError,"MissingArgument",option);
5731 break;
5732 }
5733 if (LocaleCompare("strokewidth",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 }
5744 if (LocaleCompare("style",option+1) == 0)
5745 {
cristybb503372010-05-27 20:51:26 +00005746 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005747 style;
5748
5749 if (*option == '+')
5750 break;
5751 i++;
cristybb503372010-05-27 20:51:26 +00005752 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005753 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005754 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005755 if (style < 0)
5756 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5757 argv[i]);
5758 break;
5759 }
cristyecb10ff2011-03-22 13:14:03 +00005760 if (LocaleCompare("swap",option+1) == 0)
5761 {
5762 if (*option == '+')
5763 break;
5764 i++;
5765 if (i == (ssize_t) (argc-1))
5766 ThrowMogrifyException(OptionError,"MissingArgument",option);
5767 if (IsGeometry(argv[i]) == MagickFalse)
5768 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5769 break;
5770 }
cristy3ed852e2009-09-05 21:47:34 +00005771 if (LocaleCompare("swirl",option+1) == 0)
5772 {
5773 if (*option == '+')
5774 break;
5775 i++;
cristybb503372010-05-27 20:51:26 +00005776 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005777 ThrowMogrifyException(OptionError,"MissingArgument",option);
5778 if (IsGeometry(argv[i]) == MagickFalse)
5779 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5780 break;
5781 }
cristyd9a29192010-10-16 16:49:53 +00005782 if (LocaleCompare("synchronize",option+1) == 0)
5783 break;
cristy3ed852e2009-09-05 21:47:34 +00005784 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5785 }
5786 case 't':
5787 {
5788 if (LocaleCompare("taint",option+1) == 0)
5789 break;
5790 if (LocaleCompare("texture",option+1) == 0)
5791 {
5792 if (*option == '+')
5793 break;
5794 i++;
cristybb503372010-05-27 20:51:26 +00005795 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005796 ThrowMogrifyException(OptionError,"MissingArgument",option);
5797 break;
5798 }
5799 if (LocaleCompare("tile",option+1) == 0)
5800 {
5801 if (*option == '+')
5802 break;
5803 i++;
cristybb503372010-05-27 20:51:26 +00005804 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005805 ThrowMogrifyException(OptionError,"MissingArgument",option);
5806 break;
5807 }
5808 if (LocaleCompare("tile-offset",option+1) == 0)
5809 {
5810 if (*option == '+')
5811 break;
5812 i++;
cristybb503372010-05-27 20:51:26 +00005813 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005814 ThrowMogrifyException(OptionError,"MissingArgument",option);
5815 if (IsGeometry(argv[i]) == MagickFalse)
5816 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5817 break;
5818 }
5819 if (LocaleCompare("tint",option+1) == 0)
5820 {
5821 if (*option == '+')
5822 break;
5823 i++;
cristybb503372010-05-27 20:51:26 +00005824 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005825 ThrowMogrifyException(OptionError,"MissingArgument",option);
5826 if (IsGeometry(argv[i]) == MagickFalse)
5827 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5828 break;
5829 }
5830 if (LocaleCompare("transform",option+1) == 0)
5831 break;
5832 if (LocaleCompare("transpose",option+1) == 0)
5833 break;
5834 if (LocaleCompare("transverse",option+1) == 0)
5835 break;
5836 if (LocaleCompare("threshold",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("thumbnail",option+1) == 0)
5848 {
5849 if (*option == '+')
5850 break;
5851 i++;
cristybb503372010-05-27 20:51:26 +00005852 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005853 ThrowMogrifyException(OptionError,"MissingArgument",option);
5854 if (IsGeometry(argv[i]) == MagickFalse)
5855 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5856 break;
5857 }
5858 if (LocaleCompare("transparent",option+1) == 0)
5859 {
5860 i++;
cristybb503372010-05-27 20:51:26 +00005861 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005862 ThrowMogrifyException(OptionError,"MissingArgument",option);
5863 break;
5864 }
5865 if (LocaleCompare("transparent-color",option+1) == 0)
5866 {
5867 if (*option == '+')
5868 break;
5869 i++;
cristybb503372010-05-27 20:51:26 +00005870 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005871 ThrowMogrifyException(OptionError,"MissingArgument",option);
5872 break;
5873 }
5874 if (LocaleCompare("treedepth",option+1) == 0)
5875 {
5876 if (*option == '+')
5877 break;
5878 i++;
cristybb503372010-05-27 20:51:26 +00005879 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005880 ThrowMogrifyException(OptionError,"MissingArgument",option);
5881 if (IsGeometry(argv[i]) == MagickFalse)
5882 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5883 break;
5884 }
5885 if (LocaleCompare("trim",option+1) == 0)
5886 break;
5887 if (LocaleCompare("type",option+1) == 0)
5888 {
cristybb503372010-05-27 20:51:26 +00005889 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005890 type;
5891
5892 if (*option == '+')
5893 break;
5894 i++;
cristybb503372010-05-27 20:51:26 +00005895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005896 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005897 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005898 if (type < 0)
5899 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5900 argv[i]);
5901 break;
5902 }
5903 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5904 }
5905 case 'u':
5906 {
5907 if (LocaleCompare("undercolor",option+1) == 0)
5908 {
5909 if (*option == '+')
5910 break;
5911 i++;
cristybb503372010-05-27 20:51:26 +00005912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005913 ThrowMogrifyException(OptionError,"MissingArgument",option);
5914 break;
5915 }
5916 if (LocaleCompare("unique-colors",option+1) == 0)
5917 break;
5918 if (LocaleCompare("units",option+1) == 0)
5919 {
cristybb503372010-05-27 20:51:26 +00005920 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005921 units;
5922
5923 if (*option == '+')
5924 break;
5925 i++;
cristybb503372010-05-27 20:51:26 +00005926 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005927 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005928 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005929 argv[i]);
5930 if (units < 0)
5931 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5932 argv[i]);
5933 break;
5934 }
5935 if (LocaleCompare("unsharp",option+1) == 0)
5936 {
5937 i++;
cristybb503372010-05-27 20:51:26 +00005938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005939 ThrowMogrifyException(OptionError,"MissingArgument",option);
5940 if (IsGeometry(argv[i]) == MagickFalse)
5941 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5942 break;
5943 }
5944 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5945 }
5946 case 'v':
5947 {
5948 if (LocaleCompare("verbose",option+1) == 0)
5949 {
5950 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5951 break;
5952 }
5953 if ((LocaleCompare("version",option+1) == 0) ||
5954 (LocaleCompare("-version",option+1) == 0))
5955 {
cristyb51dff52011-05-19 16:55:47 +00005956 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005957 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005958 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5959 GetMagickCopyright());
5960 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5961 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005962 break;
5963 }
5964 if (LocaleCompare("view",option+1) == 0)
5965 {
5966 if (*option == '+')
5967 break;
5968 i++;
cristybb503372010-05-27 20:51:26 +00005969 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005970 ThrowMogrifyException(OptionError,"MissingArgument",option);
5971 break;
5972 }
5973 if (LocaleCompare("vignette",option+1) == 0)
5974 {
5975 if (*option == '+')
5976 break;
5977 i++;
cristybb503372010-05-27 20:51:26 +00005978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005979 ThrowMogrifyException(OptionError,"MissingArgument",option);
5980 if (IsGeometry(argv[i]) == MagickFalse)
5981 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5982 break;
5983 }
5984 if (LocaleCompare("virtual-pixel",option+1) == 0)
5985 {
cristybb503372010-05-27 20:51:26 +00005986 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005987 method;
5988
5989 if (*option == '+')
5990 break;
5991 i++;
cristybb503372010-05-27 20:51:26 +00005992 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005993 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005994 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005995 argv[i]);
5996 if (method < 0)
5997 ThrowMogrifyException(OptionError,
5998 "UnrecognizedVirtualPixelMethod",argv[i]);
5999 break;
6000 }
6001 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6002 }
6003 case 'w':
6004 {
6005 if (LocaleCompare("wave",option+1) == 0)
6006 {
6007 i++;
cristybb503372010-05-27 20:51:26 +00006008 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006009 ThrowMogrifyException(OptionError,"MissingArgument",option);
6010 if (IsGeometry(argv[i]) == MagickFalse)
6011 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6012 break;
6013 }
6014 if (LocaleCompare("weight",option+1) == 0)
6015 {
6016 if (*option == '+')
6017 break;
6018 i++;
cristybb503372010-05-27 20:51:26 +00006019 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006020 ThrowMogrifyException(OptionError,"MissingArgument",option);
6021 break;
6022 }
6023 if (LocaleCompare("white-point",option+1) == 0)
6024 {
6025 if (*option == '+')
6026 break;
6027 i++;
cristybb503372010-05-27 20:51:26 +00006028 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006029 ThrowMogrifyException(OptionError,"MissingArgument",option);
6030 if (IsGeometry(argv[i]) == MagickFalse)
6031 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6032 break;
6033 }
6034 if (LocaleCompare("white-threshold",option+1) == 0)
6035 {
6036 if (*option == '+')
6037 break;
6038 i++;
cristybb503372010-05-27 20:51:26 +00006039 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006040 ThrowMogrifyException(OptionError,"MissingArgument",option);
6041 if (IsGeometry(argv[i]) == MagickFalse)
6042 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6043 break;
6044 }
6045 if (LocaleCompare("write",option+1) == 0)
6046 {
6047 i++;
cristybb503372010-05-27 20:51:26 +00006048 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006049 ThrowMogrifyException(OptionError,"MissingArgument",option);
6050 break;
6051 }
6052 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6053 }
6054 case '?':
6055 break;
6056 default:
6057 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6058 }
cristy042ee782011-04-22 18:48:30 +00006059 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6060 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006061 if (fire != MagickFalse)
6062 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6063 }
6064 if (k != 0)
6065 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006066 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006067 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6068 DestroyMogrify();
6069 return(status != 0 ? MagickTrue : MagickFalse);
6070}
6071
6072/*
6073%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6074% %
6075% %
6076% %
6077+ M o g r i f y I m a g e I n f o %
6078% %
6079% %
6080% %
6081%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6082%
6083% MogrifyImageInfo() applies image processing settings to the image as
6084% prescribed by command line options.
6085%
6086% The format of the MogrifyImageInfo method is:
6087%
6088% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6089% const char **argv,ExceptionInfo *exception)
6090%
6091% A description of each parameter follows:
6092%
6093% o image_info: the image info..
6094%
6095% o argc: Specifies a pointer to an integer describing the number of
6096% elements in the argument vector.
6097%
6098% o argv: Specifies a pointer to a text array containing the command line
6099% arguments.
6100%
6101% o exception: return any errors or warnings in this structure.
6102%
6103*/
6104WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6105 const int argc,const char **argv,ExceptionInfo *exception)
6106{
6107 const char
6108 *option;
6109
6110 GeometryInfo
6111 geometry_info;
6112
cristybb503372010-05-27 20:51:26 +00006113 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006114 count;
6115
cristybb503372010-05-27 20:51:26 +00006116 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006117 i;
6118
6119 /*
6120 Initialize method variables.
6121 */
6122 assert(image_info != (ImageInfo *) NULL);
6123 assert(image_info->signature == MagickSignature);
6124 if (image_info->debug != MagickFalse)
6125 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6126 image_info->filename);
6127 if (argc < 0)
6128 return(MagickTrue);
6129 /*
6130 Set the image settings.
6131 */
cristybb503372010-05-27 20:51:26 +00006132 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006133 {
6134 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006135 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006136 continue;
cristy042ee782011-04-22 18:48:30 +00006137 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006138 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006139 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006140 break;
6141 switch (*(option+1))
6142 {
6143 case 'a':
6144 {
6145 if (LocaleCompare("adjoin",option+1) == 0)
6146 {
6147 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6148 break;
6149 }
6150 if (LocaleCompare("antialias",option+1) == 0)
6151 {
6152 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6153 break;
6154 }
cristy3ed852e2009-09-05 21:47:34 +00006155 if (LocaleCompare("authenticate",option+1) == 0)
6156 {
6157 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006158 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006159 else
anthony1afdc7a2011-10-05 11:54:28 +00006160 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006161 break;
6162 }
6163 break;
6164 }
6165 case 'b':
6166 {
6167 if (LocaleCompare("background",option+1) == 0)
6168 {
6169 if (*option == '+')
6170 {
6171 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006172 (void) QueryColorCompliance(MogrifyBackgroundColor,
6173 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006174 break;
6175 }
6176 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006177 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6178 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006179 break;
6180 }
6181 if (LocaleCompare("bias",option+1) == 0)
6182 {
6183 if (*option == '+')
6184 {
6185 (void) SetImageOption(image_info,option+1,"0.0");
6186 break;
6187 }
6188 (void) SetImageOption(image_info,option+1,argv[i+1]);
6189 break;
6190 }
6191 if (LocaleCompare("black-point-compensation",option+1) == 0)
6192 {
6193 if (*option == '+')
6194 {
6195 (void) SetImageOption(image_info,option+1,"false");
6196 break;
6197 }
6198 (void) SetImageOption(image_info,option+1,"true");
6199 break;
6200 }
6201 if (LocaleCompare("blue-primary",option+1) == 0)
6202 {
6203 if (*option == '+')
6204 {
6205 (void) SetImageOption(image_info,option+1,"0.0");
6206 break;
6207 }
6208 (void) SetImageOption(image_info,option+1,argv[i+1]);
6209 break;
6210 }
6211 if (LocaleCompare("bordercolor",option+1) == 0)
6212 {
6213 if (*option == '+')
6214 {
6215 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006216 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006217 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006218 break;
6219 }
cristy9950d572011-10-01 18:22:35 +00006220 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6221 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006222 (void) SetImageOption(image_info,option+1,argv[i+1]);
6223 break;
6224 }
6225 if (LocaleCompare("box",option+1) == 0)
6226 {
6227 if (*option == '+')
6228 {
6229 (void) SetImageOption(image_info,"undercolor","none");
6230 break;
6231 }
6232 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6233 break;
6234 }
6235 break;
6236 }
6237 case 'c':
6238 {
6239 if (LocaleCompare("cache",option+1) == 0)
6240 {
6241 MagickSizeType
6242 limit;
6243
6244 limit=MagickResourceInfinity;
6245 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006246 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6247 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006248 (void) SetMagickResourceLimit(MemoryResource,limit);
6249 (void) SetMagickResourceLimit(MapResource,2*limit);
6250 break;
6251 }
6252 if (LocaleCompare("caption",option+1) == 0)
6253 {
6254 if (*option == '+')
6255 {
6256 (void) DeleteImageOption(image_info,option+1);
6257 break;
6258 }
6259 (void) SetImageOption(image_info,option+1,argv[i+1]);
6260 break;
6261 }
6262 if (LocaleCompare("channel",option+1) == 0)
6263 {
6264 if (*option == '+')
6265 {
6266 image_info->channel=DefaultChannels;
6267 break;
6268 }
6269 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6270 break;
6271 }
cristy3ed852e2009-09-05 21:47:34 +00006272 if (LocaleCompare("colorspace",option+1) == 0)
6273 {
6274 if (*option == '+')
6275 {
6276 image_info->colorspace=UndefinedColorspace;
6277 (void) SetImageOption(image_info,option+1,"undefined");
6278 break;
6279 }
cristy042ee782011-04-22 18:48:30 +00006280 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006281 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6282 (void) SetImageOption(image_info,option+1,argv[i+1]);
6283 break;
6284 }
cristy3ed852e2009-09-05 21:47:34 +00006285 if (LocaleCompare("comment",option+1) == 0)
6286 {
6287 if (*option == '+')
6288 {
6289 (void) DeleteImageOption(image_info,option+1);
6290 break;
6291 }
6292 (void) SetImageOption(image_info,option+1,argv[i+1]);
6293 break;
6294 }
6295 if (LocaleCompare("compose",option+1) == 0)
6296 {
6297 if (*option == '+')
6298 {
6299 (void) SetImageOption(image_info,option+1,"undefined");
6300 break;
6301 }
6302 (void) SetImageOption(image_info,option+1,argv[i+1]);
6303 break;
6304 }
6305 if (LocaleCompare("compress",option+1) == 0)
6306 {
6307 if (*option == '+')
6308 {
6309 image_info->compression=UndefinedCompression;
6310 (void) SetImageOption(image_info,option+1,"undefined");
6311 break;
6312 }
cristy042ee782011-04-22 18:48:30 +00006313 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006314 MagickCompressOptions,MagickFalse,argv[i+1]);
6315 (void) SetImageOption(image_info,option+1,argv[i+1]);
6316 break;
6317 }
6318 break;
6319 }
6320 case 'd':
6321 {
6322 if (LocaleCompare("debug",option+1) == 0)
6323 {
6324 if (*option == '+')
6325 (void) SetLogEventMask("none");
6326 else
6327 (void) SetLogEventMask(argv[i+1]);
6328 image_info->debug=IsEventLogging();
6329 break;
6330 }
6331 if (LocaleCompare("define",option+1) == 0)
6332 {
6333 if (*option == '+')
6334 {
6335 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6336 (void) DeleteImageRegistry(argv[i+1]+9);
6337 else
6338 (void) DeleteImageOption(image_info,argv[i+1]);
6339 break;
6340 }
6341 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6342 {
6343 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6344 exception);
6345 break;
6346 }
6347 (void) DefineImageOption(image_info,argv[i+1]);
6348 break;
6349 }
6350 if (LocaleCompare("delay",option+1) == 0)
6351 {
6352 if (*option == '+')
6353 {
6354 (void) SetImageOption(image_info,option+1,"0");
6355 break;
6356 }
6357 (void) SetImageOption(image_info,option+1,argv[i+1]);
6358 break;
6359 }
6360 if (LocaleCompare("density",option+1) == 0)
6361 {
6362 /*
6363 Set image density.
6364 */
6365 if (*option == '+')
6366 {
6367 if (image_info->density != (char *) NULL)
6368 image_info->density=DestroyString(image_info->density);
6369 (void) SetImageOption(image_info,option+1,"72");
6370 break;
6371 }
6372 (void) CloneString(&image_info->density,argv[i+1]);
6373 (void) SetImageOption(image_info,option+1,argv[i+1]);
6374 break;
6375 }
6376 if (LocaleCompare("depth",option+1) == 0)
6377 {
6378 if (*option == '+')
6379 {
6380 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6381 break;
6382 }
cristye27293e2009-12-18 02:53:20 +00006383 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006384 break;
6385 }
cristyc9b12952010-03-28 01:12:28 +00006386 if (LocaleCompare("direction",option+1) == 0)
6387 {
6388 if (*option == '+')
6389 {
6390 (void) SetImageOption(image_info,option+1,"undefined");
6391 break;
6392 }
6393 (void) SetImageOption(image_info,option+1,argv[i+1]);
6394 break;
6395 }
cristy3ed852e2009-09-05 21:47:34 +00006396 if (LocaleCompare("display",option+1) == 0)
6397 {
6398 if (*option == '+')
6399 {
6400 if (image_info->server_name != (char *) NULL)
6401 image_info->server_name=DestroyString(
6402 image_info->server_name);
6403 break;
6404 }
6405 (void) CloneString(&image_info->server_name,argv[i+1]);
6406 break;
6407 }
6408 if (LocaleCompare("dispose",option+1) == 0)
6409 {
6410 if (*option == '+')
6411 {
6412 (void) SetImageOption(image_info,option+1,"undefined");
6413 break;
6414 }
6415 (void) SetImageOption(image_info,option+1,argv[i+1]);
6416 break;
6417 }
6418 if (LocaleCompare("dither",option+1) == 0)
6419 {
6420 if (*option == '+')
6421 {
6422 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006423 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006424 break;
6425 }
6426 (void) SetImageOption(image_info,option+1,argv[i+1]);
6427 image_info->dither=MagickTrue;
6428 break;
6429 }
6430 break;
6431 }
6432 case 'e':
6433 {
6434 if (LocaleCompare("encoding",option+1) == 0)
6435 {
6436 if (*option == '+')
6437 {
6438 (void) SetImageOption(image_info,option+1,"undefined");
6439 break;
6440 }
6441 (void) SetImageOption(image_info,option+1,argv[i+1]);
6442 break;
6443 }
6444 if (LocaleCompare("endian",option+1) == 0)
6445 {
6446 if (*option == '+')
6447 {
6448 image_info->endian=UndefinedEndian;
6449 (void) SetImageOption(image_info,option+1,"undefined");
6450 break;
6451 }
cristy042ee782011-04-22 18:48:30 +00006452 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006453 MagickEndianOptions,MagickFalse,argv[i+1]);
6454 (void) SetImageOption(image_info,option+1,argv[i+1]);
6455 break;
6456 }
6457 if (LocaleCompare("extract",option+1) == 0)
6458 {
6459 /*
6460 Set image extract geometry.
6461 */
6462 if (*option == '+')
6463 {
6464 if (image_info->extract != (char *) NULL)
6465 image_info->extract=DestroyString(image_info->extract);
6466 break;
6467 }
6468 (void) CloneString(&image_info->extract,argv[i+1]);
6469 break;
6470 }
6471 break;
6472 }
6473 case 'f':
6474 {
6475 if (LocaleCompare("fill",option+1) == 0)
6476 {
6477 if (*option == '+')
6478 {
6479 (void) SetImageOption(image_info,option+1,"none");
6480 break;
6481 }
6482 (void) SetImageOption(image_info,option+1,argv[i+1]);
6483 break;
6484 }
6485 if (LocaleCompare("filter",option+1) == 0)
6486 {
6487 if (*option == '+')
6488 {
6489 (void) SetImageOption(image_info,option+1,"undefined");
6490 break;
6491 }
6492 (void) SetImageOption(image_info,option+1,argv[i+1]);
6493 break;
6494 }
6495 if (LocaleCompare("font",option+1) == 0)
6496 {
6497 if (*option == '+')
6498 {
6499 if (image_info->font != (char *) NULL)
6500 image_info->font=DestroyString(image_info->font);
6501 break;
6502 }
6503 (void) CloneString(&image_info->font,argv[i+1]);
6504 break;
6505 }
6506 if (LocaleCompare("format",option+1) == 0)
6507 {
6508 register const char
6509 *q;
6510
6511 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006512 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006513 image_info->ping=MagickFalse;
6514 (void) SetImageOption(image_info,option+1,argv[i+1]);
6515 break;
6516 }
6517 if (LocaleCompare("fuzz",option+1) == 0)
6518 {
6519 if (*option == '+')
6520 {
6521 image_info->fuzz=0.0;
6522 (void) SetImageOption(image_info,option+1,"0");
6523 break;
6524 }
cristydbdd0e32011-11-04 23:29:40 +00006525 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6526 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006527 (void) SetImageOption(image_info,option+1,argv[i+1]);
6528 break;
6529 }
6530 break;
6531 }
6532 case 'g':
6533 {
6534 if (LocaleCompare("gravity",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("green-primary",option+1) == 0)
6545 {
6546 if (*option == '+')
6547 {
6548 (void) SetImageOption(image_info,option+1,"0.0");
6549 break;
6550 }
6551 (void) SetImageOption(image_info,option+1,argv[i+1]);
6552 break;
6553 }
6554 break;
6555 }
6556 case 'i':
6557 {
6558 if (LocaleCompare("intent",option+1) == 0)
6559 {
6560 if (*option == '+')
6561 {
6562 (void) SetImageOption(image_info,option+1,"undefined");
6563 break;
6564 }
6565 (void) SetImageOption(image_info,option+1,argv[i+1]);
6566 break;
6567 }
6568 if (LocaleCompare("interlace",option+1) == 0)
6569 {
6570 if (*option == '+')
6571 {
6572 image_info->interlace=UndefinedInterlace;
6573 (void) SetImageOption(image_info,option+1,"undefined");
6574 break;
6575 }
cristy042ee782011-04-22 18:48:30 +00006576 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006577 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6578 (void) SetImageOption(image_info,option+1,argv[i+1]);
6579 break;
6580 }
cristyb32b90a2009-09-07 21:45:48 +00006581 if (LocaleCompare("interline-spacing",option+1) == 0)
6582 {
6583 if (*option == '+')
6584 {
6585 (void) SetImageOption(image_info,option+1,"undefined");
6586 break;
6587 }
6588 (void) SetImageOption(image_info,option+1,argv[i+1]);
6589 break;
6590 }
cristy3ed852e2009-09-05 21:47:34 +00006591 if (LocaleCompare("interpolate",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 if (LocaleCompare("interword-spacing",option+1) == 0)
6602 {
6603 if (*option == '+')
6604 {
6605 (void) SetImageOption(image_info,option+1,"undefined");
6606 break;
6607 }
6608 (void) SetImageOption(image_info,option+1,argv[i+1]);
6609 break;
6610 }
6611 break;
6612 }
6613 case 'k':
6614 {
6615 if (LocaleCompare("kerning",option+1) == 0)
6616 {
6617 if (*option == '+')
6618 {
6619 (void) SetImageOption(image_info,option+1,"undefined");
6620 break;
6621 }
6622 (void) SetImageOption(image_info,option+1,argv[i+1]);
6623 break;
6624 }
6625 break;
6626 }
6627 case 'l':
6628 {
6629 if (LocaleCompare("label",option+1) == 0)
6630 {
6631 if (*option == '+')
6632 {
6633 (void) DeleteImageOption(image_info,option+1);
6634 break;
6635 }
6636 (void) SetImageOption(image_info,option+1,argv[i+1]);
6637 break;
6638 }
6639 if (LocaleCompare("limit",option+1) == 0)
6640 {
6641 MagickSizeType
6642 limit;
6643
6644 ResourceType
6645 type;
6646
6647 if (*option == '+')
6648 break;
cristy042ee782011-04-22 18:48:30 +00006649 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006650 MagickFalse,argv[i+1]);
6651 limit=MagickResourceInfinity;
6652 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006653 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006654 (void) SetMagickResourceLimit(type,limit);
6655 break;
6656 }
6657 if (LocaleCompare("list",option+1) == 0)
6658 {
cristybb503372010-05-27 20:51:26 +00006659 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006660 list;
6661
6662 /*
6663 Display configuration list.
6664 */
cristy042ee782011-04-22 18:48:30 +00006665 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006666 switch (list)
6667 {
6668 case MagickCoderOptions:
6669 {
6670 (void) ListCoderInfo((FILE *) NULL,exception);
6671 break;
6672 }
6673 case MagickColorOptions:
6674 {
6675 (void) ListColorInfo((FILE *) NULL,exception);
6676 break;
6677 }
6678 case MagickConfigureOptions:
6679 {
6680 (void) ListConfigureInfo((FILE *) NULL,exception);
6681 break;
6682 }
6683 case MagickDelegateOptions:
6684 {
6685 (void) ListDelegateInfo((FILE *) NULL,exception);
6686 break;
6687 }
6688 case MagickFontOptions:
6689 {
6690 (void) ListTypeInfo((FILE *) NULL,exception);
6691 break;
6692 }
6693 case MagickFormatOptions:
6694 {
6695 (void) ListMagickInfo((FILE *) NULL,exception);
6696 break;
6697 }
6698 case MagickLocaleOptions:
6699 {
6700 (void) ListLocaleInfo((FILE *) NULL,exception);
6701 break;
6702 }
6703 case MagickLogOptions:
6704 {
6705 (void) ListLogInfo((FILE *) NULL,exception);
6706 break;
6707 }
6708 case MagickMagicOptions:
6709 {
6710 (void) ListMagicInfo((FILE *) NULL,exception);
6711 break;
6712 }
6713 case MagickMimeOptions:
6714 {
6715 (void) ListMimeInfo((FILE *) NULL,exception);
6716 break;
6717 }
6718 case MagickModuleOptions:
6719 {
6720 (void) ListModuleInfo((FILE *) NULL,exception);
6721 break;
6722 }
6723 case MagickPolicyOptions:
6724 {
6725 (void) ListPolicyInfo((FILE *) NULL,exception);
6726 break;
6727 }
6728 case MagickResourceOptions:
6729 {
6730 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6731 break;
6732 }
6733 case MagickThresholdOptions:
6734 {
6735 (void) ListThresholdMaps((FILE *) NULL,exception);
6736 break;
6737 }
6738 default:
6739 {
cristy042ee782011-04-22 18:48:30 +00006740 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006741 exception);
6742 break;
6743 }
6744 }
cristyaeb2cbc2010-05-07 13:28:58 +00006745 break;
cristy3ed852e2009-09-05 21:47:34 +00006746 }
6747 if (LocaleCompare("log",option+1) == 0)
6748 {
6749 if (*option == '+')
6750 break;
6751 (void) SetLogFormat(argv[i+1]);
6752 break;
6753 }
6754 if (LocaleCompare("loop",option+1) == 0)
6755 {
6756 if (*option == '+')
6757 {
6758 (void) SetImageOption(image_info,option+1,"0");
6759 break;
6760 }
6761 (void) SetImageOption(image_info,option+1,argv[i+1]);
6762 break;
6763 }
6764 break;
6765 }
6766 case 'm':
6767 {
6768 if (LocaleCompare("matte",option+1) == 0)
6769 {
6770 if (*option == '+')
6771 {
6772 (void) SetImageOption(image_info,option+1,"false");
6773 break;
6774 }
6775 (void) SetImageOption(image_info,option+1,"true");
6776 break;
6777 }
6778 if (LocaleCompare("mattecolor",option+1) == 0)
6779 {
6780 if (*option == '+')
6781 {
6782 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006783 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006784 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006785 break;
6786 }
6787 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006788 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6789 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006790 break;
6791 }
6792 if (LocaleCompare("monitor",option+1) == 0)
6793 {
6794 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6795 (void *) NULL);
6796 break;
6797 }
6798 if (LocaleCompare("monochrome",option+1) == 0)
6799 {
6800 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6801 break;
6802 }
6803 break;
6804 }
6805 case 'o':
6806 {
6807 if (LocaleCompare("orient",option+1) == 0)
6808 {
6809 if (*option == '+')
6810 {
6811 image_info->orientation=UndefinedOrientation;
6812 (void) SetImageOption(image_info,option+1,"undefined");
6813 break;
6814 }
cristy042ee782011-04-22 18:48:30 +00006815 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006816 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006817 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006818 break;
6819 }
6820 }
6821 case 'p':
6822 {
6823 if (LocaleCompare("page",option+1) == 0)
6824 {
6825 char
6826 *canonical_page,
6827 page[MaxTextExtent];
6828
6829 const char
6830 *image_option;
6831
6832 MagickStatusType
6833 flags;
6834
6835 RectangleInfo
6836 geometry;
6837
6838 if (*option == '+')
6839 {
6840 (void) DeleteImageOption(image_info,option+1);
6841 (void) CloneString(&image_info->page,(char *) NULL);
6842 break;
6843 }
6844 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6845 image_option=GetImageOption(image_info,"page");
6846 if (image_option != (const char *) NULL)
6847 flags=ParseAbsoluteGeometry(image_option,&geometry);
6848 canonical_page=GetPageGeometry(argv[i+1]);
6849 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6850 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006851 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006852 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006853 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006854 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006855 (unsigned long) geometry.width,(unsigned long) geometry.height,
6856 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006857 (void) SetImageOption(image_info,option+1,page);
6858 (void) CloneString(&image_info->page,page);
6859 break;
6860 }
cristy3ed852e2009-09-05 21:47:34 +00006861 if (LocaleCompare("ping",option+1) == 0)
6862 {
6863 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6864 break;
6865 }
6866 if (LocaleCompare("pointsize",option+1) == 0)
6867 {
6868 if (*option == '+')
6869 geometry_info.rho=0.0;
6870 else
6871 (void) ParseGeometry(argv[i+1],&geometry_info);
6872 image_info->pointsize=geometry_info.rho;
6873 break;
6874 }
cristye7f51092010-01-17 00:39:37 +00006875 if (LocaleCompare("precision",option+1) == 0)
6876 {
cristybf2766a2010-01-17 03:33:23 +00006877 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006878 break;
6879 }
cristy3ed852e2009-09-05 21:47:34 +00006880 if (LocaleCompare("preview",option+1) == 0)
6881 {
6882 /*
6883 Preview image.
6884 */
6885 if (*option == '+')
6886 {
6887 image_info->preview_type=UndefinedPreview;
6888 break;
6889 }
cristy042ee782011-04-22 18:48:30 +00006890 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006891 MagickPreviewOptions,MagickFalse,argv[i+1]);
6892 break;
6893 }
6894 break;
6895 }
6896 case 'q':
6897 {
6898 if (LocaleCompare("quality",option+1) == 0)
6899 {
6900 /*
6901 Set image compression quality.
6902 */
6903 if (*option == '+')
6904 {
6905 image_info->quality=UndefinedCompressionQuality;
6906 (void) SetImageOption(image_info,option+1,"0");
6907 break;
6908 }
cristye27293e2009-12-18 02:53:20 +00006909 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006910 (void) SetImageOption(image_info,option+1,argv[i+1]);
6911 break;
6912 }
6913 if (LocaleCompare("quiet",option+1) == 0)
6914 {
6915 static WarningHandler
6916 warning_handler = (WarningHandler) NULL;
6917
6918 if (*option == '+')
6919 {
6920 /*
6921 Restore error or warning messages.
6922 */
6923 warning_handler=SetWarningHandler(warning_handler);
6924 break;
6925 }
6926 /*
6927 Suppress error or warning messages.
6928 */
6929 warning_handler=SetWarningHandler((WarningHandler) NULL);
6930 break;
6931 }
6932 break;
6933 }
6934 case 'r':
6935 {
6936 if (LocaleCompare("red-primary",option+1) == 0)
6937 {
6938 if (*option == '+')
6939 {
6940 (void) SetImageOption(image_info,option+1,"0.0");
6941 break;
6942 }
6943 (void) SetImageOption(image_info,option+1,argv[i+1]);
6944 break;
6945 }
6946 break;
6947 }
6948 case 's':
6949 {
6950 if (LocaleCompare("sampling-factor",option+1) == 0)
6951 {
6952 /*
6953 Set image sampling factor.
6954 */
6955 if (*option == '+')
6956 {
6957 if (image_info->sampling_factor != (char *) NULL)
6958 image_info->sampling_factor=DestroyString(
6959 image_info->sampling_factor);
6960 break;
6961 }
6962 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6963 break;
6964 }
6965 if (LocaleCompare("scene",option+1) == 0)
6966 {
6967 /*
6968 Set image scene.
6969 */
6970 if (*option == '+')
6971 {
6972 image_info->scene=0;
6973 (void) SetImageOption(image_info,option+1,"0");
6974 break;
6975 }
cristye27293e2009-12-18 02:53:20 +00006976 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006977 (void) SetImageOption(image_info,option+1,argv[i+1]);
6978 break;
6979 }
6980 if (LocaleCompare("seed",option+1) == 0)
6981 {
cristybb503372010-05-27 20:51:26 +00006982 size_t
cristy3ed852e2009-09-05 21:47:34 +00006983 seed;
6984
6985 if (*option == '+')
6986 {
cristybb503372010-05-27 20:51:26 +00006987 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00006988 SeedPseudoRandomGenerator(seed);
6989 break;
6990 }
cristye27293e2009-12-18 02:53:20 +00006991 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006992 SeedPseudoRandomGenerator(seed);
6993 break;
6994 }
6995 if (LocaleCompare("size",option+1) == 0)
6996 {
6997 if (*option == '+')
6998 {
6999 if (image_info->size != (char *) NULL)
7000 image_info->size=DestroyString(image_info->size);
7001 break;
7002 }
7003 (void) CloneString(&image_info->size,argv[i+1]);
7004 break;
7005 }
7006 if (LocaleCompare("stroke",option+1) == 0)
7007 {
7008 if (*option == '+')
7009 {
7010 (void) SetImageOption(image_info,option+1,"none");
7011 break;
7012 }
7013 (void) SetImageOption(image_info,option+1,argv[i+1]);
7014 break;
7015 }
7016 if (LocaleCompare("strokewidth",option+1) == 0)
7017 {
7018 if (*option == '+')
7019 {
7020 (void) SetImageOption(image_info,option+1,"0");
7021 break;
7022 }
7023 (void) SetImageOption(image_info,option+1,argv[i+1]);
7024 break;
7025 }
cristyd9a29192010-10-16 16:49:53 +00007026 if (LocaleCompare("synchronize",option+1) == 0)
7027 {
7028 if (*option == '+')
7029 {
7030 image_info->synchronize=MagickFalse;
7031 break;
7032 }
7033 image_info->synchronize=MagickTrue;
7034 break;
7035 }
cristy3ed852e2009-09-05 21:47:34 +00007036 break;
7037 }
7038 case 't':
7039 {
7040 if (LocaleCompare("taint",option+1) == 0)
7041 {
7042 if (*option == '+')
7043 {
7044 (void) SetImageOption(image_info,option+1,"false");
7045 break;
7046 }
7047 (void) SetImageOption(image_info,option+1,"true");
7048 break;
7049 }
7050 if (LocaleCompare("texture",option+1) == 0)
7051 {
7052 if (*option == '+')
7053 {
7054 if (image_info->texture != (char *) NULL)
7055 image_info->texture=DestroyString(image_info->texture);
7056 break;
7057 }
7058 (void) CloneString(&image_info->texture,argv[i+1]);
7059 break;
7060 }
7061 if (LocaleCompare("tile-offset",option+1) == 0)
7062 {
7063 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007064 (void) SetImageOption(image_info,option+1,"0");
7065 else
7066 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007067 break;
7068 }
7069 if (LocaleCompare("transparent-color",option+1) == 0)
7070 {
7071 if (*option == '+')
7072 {
cristy9950d572011-10-01 18:22:35 +00007073 (void) QueryColorCompliance("none",AllCompliance,
7074 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007075 (void) SetImageOption(image_info,option+1,"none");
7076 break;
7077 }
cristy9950d572011-10-01 18:22:35 +00007078 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7079 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007080 (void) SetImageOption(image_info,option+1,argv[i+1]);
7081 break;
7082 }
7083 if (LocaleCompare("type",option+1) == 0)
7084 {
7085 if (*option == '+')
7086 {
cristy5f1c1ff2010-12-23 21:38:06 +00007087 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007088 (void) SetImageOption(image_info,option+1,"undefined");
7089 break;
7090 }
cristy042ee782011-04-22 18:48:30 +00007091 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007092 MagickFalse,argv[i+1]);
7093 (void) SetImageOption(image_info,option+1,argv[i+1]);
7094 break;
7095 }
7096 break;
7097 }
7098 case 'u':
7099 {
7100 if (LocaleCompare("undercolor",option+1) == 0)
7101 {
7102 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007103 (void) DeleteImageOption(image_info,option+1);
7104 else
7105 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007106 break;
7107 }
7108 if (LocaleCompare("units",option+1) == 0)
7109 {
7110 if (*option == '+')
7111 {
7112 image_info->units=UndefinedResolution;
7113 (void) SetImageOption(image_info,option+1,"undefined");
7114 break;
7115 }
cristy042ee782011-04-22 18:48:30 +00007116 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007117 MagickResolutionOptions,MagickFalse,argv[i+1]);
7118 (void) SetImageOption(image_info,option+1,argv[i+1]);
7119 break;
7120 }
7121 break;
7122 }
7123 case 'v':
7124 {
7125 if (LocaleCompare("verbose",option+1) == 0)
7126 {
7127 if (*option == '+')
7128 {
7129 image_info->verbose=MagickFalse;
7130 break;
7131 }
7132 image_info->verbose=MagickTrue;
7133 image_info->ping=MagickFalse;
7134 break;
7135 }
7136 if (LocaleCompare("view",option+1) == 0)
7137 {
7138 if (*option == '+')
7139 {
7140 if (image_info->view != (char *) NULL)
7141 image_info->view=DestroyString(image_info->view);
7142 break;
7143 }
7144 (void) CloneString(&image_info->view,argv[i+1]);
7145 break;
7146 }
7147 if (LocaleCompare("virtual-pixel",option+1) == 0)
7148 {
7149 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007150 (void) SetImageOption(image_info,option+1,"undefined");
7151 else
7152 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007153 break;
7154 }
7155 break;
7156 }
7157 case 'w':
7158 {
7159 if (LocaleCompare("white-point",option+1) == 0)
7160 {
7161 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007162 (void) SetImageOption(image_info,option+1,"0.0");
7163 else
7164 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007165 break;
7166 }
7167 break;
7168 }
7169 default:
7170 break;
7171 }
7172 i+=count;
7173 }
7174 return(MagickTrue);
7175}
7176
7177/*
7178%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7179% %
7180% %
7181% %
7182+ M o g r i f y I m a g e L i s t %
7183% %
7184% %
7185% %
7186%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7187%
7188% MogrifyImageList() applies any command line options that might affect the
7189% entire image list (e.g. -append, -coalesce, etc.).
7190%
7191% The format of the MogrifyImage method is:
7192%
7193% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7194% const char **argv,Image **images,ExceptionInfo *exception)
7195%
7196% A description of each parameter follows:
7197%
7198% o image_info: the image info..
7199%
7200% o argc: Specifies a pointer to an integer describing the number of
7201% elements in the argument vector.
7202%
7203% o argv: Specifies a pointer to a text array containing the command line
7204% arguments.
7205%
anthonye9c27192011-03-27 08:07:06 +00007206% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007207%
7208% o exception: return any errors or warnings in this structure.
7209%
7210*/
7211WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7212 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7213{
cristy3ed852e2009-09-05 21:47:34 +00007214 const char
7215 *option;
7216
cristy6b3da3a2010-06-20 02:21:46 +00007217 ImageInfo
7218 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007219
7220 MagickStatusType
7221 status;
7222
cristy28474bf2011-09-11 23:32:52 +00007223 PixelInterpolateMethod
7224 interpolate_method;
7225
cristy3ed852e2009-09-05 21:47:34 +00007226 QuantizeInfo
7227 *quantize_info;
7228
cristybb503372010-05-27 20:51:26 +00007229 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007230 i;
7231
cristy6b3da3a2010-06-20 02:21:46 +00007232 ssize_t
7233 count,
7234 index;
7235
cristy3ed852e2009-09-05 21:47:34 +00007236 /*
7237 Apply options to the image list.
7238 */
7239 assert(image_info != (ImageInfo *) NULL);
7240 assert(image_info->signature == MagickSignature);
7241 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007242 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007243 assert((*images)->signature == MagickSignature);
7244 if ((*images)->debug != MagickFalse)
7245 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7246 (*images)->filename);
7247 if ((argc <= 0) || (*argv == (char *) NULL))
7248 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007249 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007250 mogrify_info=CloneImageInfo(image_info);
7251 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007252 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007253 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007254 {
cristy74fe8f12009-10-03 19:09:01 +00007255 if (*images == (Image *) NULL)
7256 break;
cristy3ed852e2009-09-05 21:47:34 +00007257 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007258 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007259 continue;
cristy042ee782011-04-22 18:48:30 +00007260 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007261 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007262 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007263 break;
cristy6b3da3a2010-06-20 02:21:46 +00007264 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007265 switch (*(option+1))
7266 {
7267 case 'a':
7268 {
7269 if (LocaleCompare("affinity",option+1) == 0)
7270 {
cristy6fccee12011-10-20 18:43:18 +00007271 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007272 if (*option == '+')
7273 {
cristy018f07f2011-09-04 21:15:19 +00007274 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7275 exception);
cristy3ed852e2009-09-05 21:47:34 +00007276 break;
7277 }
7278 i++;
7279 break;
7280 }
7281 if (LocaleCompare("append",option+1) == 0)
7282 {
7283 Image
7284 *append_image;
7285
cristy6fccee12011-10-20 18:43:18 +00007286 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007287 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7288 MagickFalse,exception);
7289 if (append_image == (Image *) NULL)
7290 {
7291 status=MagickFalse;
7292 break;
7293 }
7294 *images=DestroyImageList(*images);
7295 *images=append_image;
7296 break;
7297 }
7298 if (LocaleCompare("average",option+1) == 0)
7299 {
7300 Image
7301 *average_image;
7302
cristyd18ae7c2010-03-07 17:39:52 +00007303 /*
7304 Average an image sequence (deprecated).
7305 */
cristy6fccee12011-10-20 18:43:18 +00007306 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007307 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7308 exception);
cristy3ed852e2009-09-05 21:47:34 +00007309 if (average_image == (Image *) NULL)
7310 {
7311 status=MagickFalse;
7312 break;
7313 }
7314 *images=DestroyImageList(*images);
7315 *images=average_image;
7316 break;
7317 }
7318 break;
7319 }
7320 case 'c':
7321 {
cristy3ed852e2009-09-05 21:47:34 +00007322 if (LocaleCompare("clut",option+1) == 0)
7323 {
7324 Image
7325 *clut_image,
7326 *image;
7327
cristy6fccee12011-10-20 18:43:18 +00007328 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007329 image=RemoveFirstImageFromList(images);
7330 clut_image=RemoveFirstImageFromList(images);
7331 if (clut_image == (Image *) NULL)
7332 {
7333 status=MagickFalse;
7334 break;
7335 }
cristy28474bf2011-09-11 23:32:52 +00007336 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007337 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007338 *images=DestroyImageList(*images);
7339 *images=image;
7340 break;
7341 }
7342 if (LocaleCompare("coalesce",option+1) == 0)
7343 {
7344 Image
7345 *coalesce_image;
7346
cristy6fccee12011-10-20 18:43:18 +00007347 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007348 coalesce_image=CoalesceImages(*images,exception);
7349 if (coalesce_image == (Image *) NULL)
7350 {
7351 status=MagickFalse;
7352 break;
7353 }
7354 *images=DestroyImageList(*images);
7355 *images=coalesce_image;
7356 break;
7357 }
7358 if (LocaleCompare("combine",option+1) == 0)
7359 {
7360 Image
7361 *combine_image;
7362
cristy6fccee12011-10-20 18:43:18 +00007363 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007364 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007365 if (combine_image == (Image *) NULL)
7366 {
7367 status=MagickFalse;
7368 break;
7369 }
7370 *images=DestroyImageList(*images);
7371 *images=combine_image;
7372 break;
7373 }
7374 if (LocaleCompare("composite",option+1) == 0)
7375 {
7376 Image
7377 *mask_image,
7378 *composite_image,
7379 *image;
7380
7381 RectangleInfo
7382 geometry;
7383
cristy6fccee12011-10-20 18:43:18 +00007384 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007385 image=RemoveFirstImageFromList(images);
7386 composite_image=RemoveFirstImageFromList(images);
7387 if (composite_image == (Image *) NULL)
7388 {
7389 status=MagickFalse;
7390 break;
7391 }
7392 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007393 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007394 SetGeometry(composite_image,&geometry);
7395 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7396 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7397 &geometry);
7398 mask_image=RemoveFirstImageFromList(images);
7399 if (mask_image != (Image *) NULL)
7400 {
7401 if ((image->compose == DisplaceCompositeOp) ||
7402 (image->compose == DistortCompositeOp))
7403 {
7404 /*
7405 Merge Y displacement into X displacement image.
7406 */
7407 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007408 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007409 mask_image=DestroyImage(mask_image);
7410 }
7411 else
7412 {
7413 /*
anthony80c37752012-01-16 01:03:11 +00007414 Set a blending mask for the composition.
cristy3ed852e2009-09-05 21:47:34 +00007415 */
cristy10a6c612012-01-29 21:41:05 +00007416 (void) NegateImage(mask_image,MagickFalse,exception);
7417 (void) SetImageMask(image,mask_image,exception);
7418 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00007419 }
7420 }
cristyf4ad9df2011-07-08 16:49:03 +00007421 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007422 geometry.x,geometry.y,exception);
cristy10a6c612012-01-29 21:41:05 +00007423 (void) SetImageMask(image,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00007424 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007425 *images=DestroyImageList(*images);
7426 *images=image;
7427 break;
7428 }
cristy3ed852e2009-09-05 21:47:34 +00007429 break;
7430 }
7431 case 'd':
7432 {
7433 if (LocaleCompare("deconstruct",option+1) == 0)
7434 {
7435 Image
7436 *deconstruct_image;
7437
cristy6fccee12011-10-20 18:43:18 +00007438 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007439 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007440 exception);
cristy3ed852e2009-09-05 21:47:34 +00007441 if (deconstruct_image == (Image *) NULL)
7442 {
7443 status=MagickFalse;
7444 break;
7445 }
7446 *images=DestroyImageList(*images);
7447 *images=deconstruct_image;
7448 break;
7449 }
7450 if (LocaleCompare("delete",option+1) == 0)
7451 {
7452 if (*option == '+')
7453 DeleteImages(images,"-1",exception);
7454 else
7455 DeleteImages(images,argv[i+1],exception);
7456 break;
7457 }
7458 if (LocaleCompare("dither",option+1) == 0)
7459 {
7460 if (*option == '+')
7461 {
7462 quantize_info->dither=MagickFalse;
7463 break;
7464 }
7465 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007466 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007467 MagickDitherOptions,MagickFalse,argv[i+1]);
7468 break;
7469 }
cristyecb10ff2011-03-22 13:14:03 +00007470 if (LocaleCompare("duplicate",option+1) == 0)
7471 {
cristy72988482011-03-29 16:34:38 +00007472 Image
7473 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007474
anthony2b6bcae2011-03-23 13:05:34 +00007475 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007476 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7477 else
7478 {
7479 const char
7480 *p;
7481
anthony2b6bcae2011-03-23 13:05:34 +00007482 size_t
7483 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007484
anthony2b6bcae2011-03-23 13:05:34 +00007485 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007486 p=strchr(argv[i+1],',');
7487 if (p == (const char *) NULL)
7488 duplicate_images=DuplicateImages(*images,number_duplicates,
7489 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007490 else
cristy72988482011-03-29 16:34:38 +00007491 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7492 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007493 }
7494 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007495 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007496 break;
7497 }
cristy3ed852e2009-09-05 21:47:34 +00007498 break;
7499 }
cristyd18ae7c2010-03-07 17:39:52 +00007500 case 'e':
7501 {
7502 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7503 {
7504 Image
7505 *evaluate_image;
7506
7507 MagickEvaluateOperator
7508 op;
7509
cristy6fccee12011-10-20 18:43:18 +00007510 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007511 op=(MagickEvaluateOperator) ParseCommandOption(
7512 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007513 evaluate_image=EvaluateImages(*images,op,exception);
7514 if (evaluate_image == (Image *) NULL)
7515 {
7516 status=MagickFalse;
7517 break;
7518 }
7519 *images=DestroyImageList(*images);
7520 *images=evaluate_image;
7521 break;
7522 }
7523 break;
7524 }
cristy3ed852e2009-09-05 21:47:34 +00007525 case 'f':
7526 {
cristyf0a247f2009-10-04 00:20:03 +00007527 if (LocaleCompare("fft",option+1) == 0)
7528 {
7529 Image
7530 *fourier_image;
7531
7532 /*
7533 Implements the discrete Fourier transform (DFT).
7534 */
cristy6fccee12011-10-20 18:43:18 +00007535 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007536 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7537 MagickTrue : MagickFalse,exception);
7538 if (fourier_image == (Image *) NULL)
7539 break;
7540 *images=DestroyImage(*images);
7541 *images=fourier_image;
7542 break;
7543 }
cristy3ed852e2009-09-05 21:47:34 +00007544 if (LocaleCompare("flatten",option+1) == 0)
7545 {
7546 Image
7547 *flatten_image;
7548
cristy6fccee12011-10-20 18:43:18 +00007549 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007550 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7551 if (flatten_image == (Image *) NULL)
7552 break;
7553 *images=DestroyImageList(*images);
7554 *images=flatten_image;
7555 break;
7556 }
7557 if (LocaleCompare("fx",option+1) == 0)
7558 {
7559 Image
7560 *fx_image;
7561
cristy6fccee12011-10-20 18:43:18 +00007562 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007563 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007564 if (fx_image == (Image *) NULL)
7565 {
7566 status=MagickFalse;
7567 break;
7568 }
7569 *images=DestroyImageList(*images);
7570 *images=fx_image;
7571 break;
7572 }
7573 break;
7574 }
7575 case 'h':
7576 {
7577 if (LocaleCompare("hald-clut",option+1) == 0)
7578 {
7579 Image
7580 *hald_image,
7581 *image;
7582
cristy6fccee12011-10-20 18:43:18 +00007583 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007584 image=RemoveFirstImageFromList(images);
7585 hald_image=RemoveFirstImageFromList(images);
7586 if (hald_image == (Image *) NULL)
7587 {
7588 status=MagickFalse;
7589 break;
7590 }
cristy7c0a0a42011-08-23 17:57:25 +00007591 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007592 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007593 if (*images != (Image *) NULL)
7594 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007595 *images=image;
7596 break;
7597 }
7598 break;
7599 }
7600 case 'i':
7601 {
7602 if (LocaleCompare("ift",option+1) == 0)
7603 {
7604 Image
cristy8587f882009-11-13 20:28:49 +00007605 *fourier_image,
7606 *magnitude_image,
7607 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007608
7609 /*
7610 Implements the inverse fourier discrete Fourier transform (DFT).
7611 */
cristy6fccee12011-10-20 18:43:18 +00007612 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007613 magnitude_image=RemoveFirstImageFromList(images);
7614 phase_image=RemoveFirstImageFromList(images);
7615 if (phase_image == (Image *) NULL)
7616 {
7617 status=MagickFalse;
7618 break;
7619 }
7620 fourier_image=InverseFourierTransformImage(magnitude_image,
7621 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007622 if (fourier_image == (Image *) NULL)
7623 break;
cristy0aff6ea2009-11-14 01:40:53 +00007624 if (*images != (Image *) NULL)
7625 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007626 *images=fourier_image;
7627 break;
7628 }
7629 if (LocaleCompare("insert",option+1) == 0)
7630 {
7631 Image
7632 *p,
7633 *q;
7634
7635 index=0;
7636 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007637 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007638 p=RemoveLastImageFromList(images);
7639 if (p == (Image *) NULL)
7640 {
7641 (void) ThrowMagickException(exception,GetMagickModule(),
7642 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7643 status=MagickFalse;
7644 break;
7645 }
7646 q=p;
7647 if (index == 0)
7648 PrependImageToList(images,q);
7649 else
cristybb503372010-05-27 20:51:26 +00007650 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007651 AppendImageToList(images,q);
7652 else
7653 {
7654 q=GetImageFromList(*images,index-1);
7655 if (q == (Image *) NULL)
7656 {
7657 (void) ThrowMagickException(exception,GetMagickModule(),
7658 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7659 status=MagickFalse;
7660 break;
7661 }
7662 InsertImageInList(&q,p);
7663 }
7664 *images=GetFirstImageInList(q);
7665 break;
7666 }
cristy28474bf2011-09-11 23:32:52 +00007667 if (LocaleCompare("interpolate",option+1) == 0)
7668 {
7669 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7670 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7671 break;
7672 }
cristy3ed852e2009-09-05 21:47:34 +00007673 break;
7674 }
7675 case 'l':
7676 {
7677 if (LocaleCompare("layers",option+1) == 0)
7678 {
7679 Image
7680 *layers;
7681
7682 ImageLayerMethod
7683 method;
7684
cristy6fccee12011-10-20 18:43:18 +00007685 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007686 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007687 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007688 MagickFalse,argv[i+1]);
7689 switch (method)
7690 {
7691 case CoalesceLayer:
7692 {
7693 layers=CoalesceImages(*images,exception);
7694 break;
7695 }
7696 case CompareAnyLayer:
7697 case CompareClearLayer:
7698 case CompareOverlayLayer:
7699 default:
7700 {
cristy8a9106f2011-07-05 14:39:26 +00007701 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007702 break;
7703 }
7704 case MergeLayer:
7705 case FlattenLayer:
7706 case MosaicLayer:
7707 case TrimBoundsLayer:
7708 {
7709 layers=MergeImageLayers(*images,method,exception);
7710 break;
7711 }
7712 case DisposeLayer:
7713 {
7714 layers=DisposeImages(*images,exception);
7715 break;
7716 }
7717 case OptimizeImageLayer:
7718 {
7719 layers=OptimizeImageLayers(*images,exception);
7720 break;
7721 }
7722 case OptimizePlusLayer:
7723 {
7724 layers=OptimizePlusImageLayers(*images,exception);
7725 break;
7726 }
7727 case OptimizeTransLayer:
7728 {
7729 OptimizeImageTransparency(*images,exception);
7730 break;
7731 }
7732 case RemoveDupsLayer:
7733 {
7734 RemoveDuplicateLayers(images,exception);
7735 break;
7736 }
7737 case RemoveZeroLayer:
7738 {
7739 RemoveZeroDelayLayers(images,exception);
7740 break;
7741 }
7742 case OptimizeLayer:
7743 {
7744 /*
7745 General Purpose, GIF Animation Optimizer.
7746 */
7747 layers=CoalesceImages(*images,exception);
7748 if (layers == (Image *) NULL)
7749 {
7750 status=MagickFalse;
7751 break;
7752 }
cristy3ed852e2009-09-05 21:47:34 +00007753 *images=DestroyImageList(*images);
7754 *images=layers;
7755 layers=OptimizeImageLayers(*images,exception);
7756 if (layers == (Image *) NULL)
7757 {
7758 status=MagickFalse;
7759 break;
7760 }
cristy3ed852e2009-09-05 21:47:34 +00007761 *images=DestroyImageList(*images);
7762 *images=layers;
7763 layers=(Image *) NULL;
7764 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007765 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7766 exception);
cristy3ed852e2009-09-05 21:47:34 +00007767 break;
7768 }
7769 case CompositeLayer:
7770 {
7771 CompositeOperator
7772 compose;
7773
7774 Image
7775 *source;
7776
7777 RectangleInfo
7778 geometry;
7779
7780 /*
7781 Split image sequence at the first 'NULL:' image.
7782 */
7783 source=(*images);
7784 while (source != (Image *) NULL)
7785 {
7786 source=GetNextImageInList(source);
7787 if ((source != (Image *) NULL) &&
7788 (LocaleCompare(source->magick,"NULL") == 0))
7789 break;
7790 }
7791 if (source != (Image *) NULL)
7792 {
7793 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7794 (GetNextImageInList(source) == (Image *) NULL))
7795 source=(Image *) NULL;
7796 else
7797 {
7798 /*
7799 Separate the two lists, junk the null: image.
7800 */
7801 source=SplitImageList(source->previous);
7802 DeleteImageFromList(&source);
7803 }
7804 }
7805 if (source == (Image *) NULL)
7806 {
7807 (void) ThrowMagickException(exception,GetMagickModule(),
7808 OptionError,"MissingNullSeparator","layers Composite");
7809 status=MagickFalse;
7810 break;
7811 }
7812 /*
7813 Adjust offset with gravity and virtual canvas.
7814 */
7815 SetGeometry(*images,&geometry);
7816 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7817 geometry.width=source->page.width != 0 ?
7818 source->page.width : source->columns;
7819 geometry.height=source->page.height != 0 ?
7820 source->page.height : source->rows;
7821 GravityAdjustGeometry((*images)->page.width != 0 ?
7822 (*images)->page.width : (*images)->columns,
7823 (*images)->page.height != 0 ? (*images)->page.height :
7824 (*images)->rows,(*images)->gravity,&geometry);
7825 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007826 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007827 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007828 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007829 MagickComposeOptions,MagickFalse,option);
7830 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7831 exception);
7832 source=DestroyImageList(source);
7833 break;
7834 }
7835 }
7836 if (layers == (Image *) NULL)
7837 break;
cristy3ed852e2009-09-05 21:47:34 +00007838 *images=DestroyImageList(*images);
7839 *images=layers;
7840 break;
7841 }
7842 break;
7843 }
7844 case 'm':
7845 {
7846 if (LocaleCompare("map",option+1) == 0)
7847 {
cristy6fccee12011-10-20 18:43:18 +00007848 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007849 if (*option == '+')
7850 {
cristy018f07f2011-09-04 21:15:19 +00007851 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7852 exception);
cristy3ed852e2009-09-05 21:47:34 +00007853 break;
7854 }
7855 i++;
7856 break;
7857 }
cristyf40785b2010-03-06 02:27:27 +00007858 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007859 {
7860 Image
cristyf40785b2010-03-06 02:27:27 +00007861 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007862
cristyd18ae7c2010-03-07 17:39:52 +00007863 /*
7864 Maximum image sequence (deprecated).
7865 */
cristy6fccee12011-10-20 18:43:18 +00007866 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007867 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007868 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007869 {
7870 status=MagickFalse;
7871 break;
7872 }
7873 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007874 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007875 break;
7876 }
cristyf40785b2010-03-06 02:27:27 +00007877 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007878 {
7879 Image
cristyf40785b2010-03-06 02:27:27 +00007880 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007881
cristyd18ae7c2010-03-07 17:39:52 +00007882 /*
7883 Minimum image sequence (deprecated).
7884 */
cristy6fccee12011-10-20 18:43:18 +00007885 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007886 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007887 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007888 {
7889 status=MagickFalse;
7890 break;
7891 }
7892 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007893 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007894 break;
7895 }
cristy3ed852e2009-09-05 21:47:34 +00007896 if (LocaleCompare("morph",option+1) == 0)
7897 {
7898 Image
7899 *morph_image;
7900
cristy6fccee12011-10-20 18:43:18 +00007901 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007902 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007903 exception);
7904 if (morph_image == (Image *) NULL)
7905 {
7906 status=MagickFalse;
7907 break;
7908 }
7909 *images=DestroyImageList(*images);
7910 *images=morph_image;
7911 break;
7912 }
7913 if (LocaleCompare("mosaic",option+1) == 0)
7914 {
7915 Image
7916 *mosaic_image;
7917
cristy6fccee12011-10-20 18:43:18 +00007918 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007919 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7920 if (mosaic_image == (Image *) NULL)
7921 {
7922 status=MagickFalse;
7923 break;
7924 }
7925 *images=DestroyImageList(*images);
7926 *images=mosaic_image;
7927 break;
7928 }
7929 break;
7930 }
7931 case 'p':
7932 {
7933 if (LocaleCompare("print",option+1) == 0)
7934 {
7935 char
7936 *string;
7937
cristy6fccee12011-10-20 18:43:18 +00007938 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007939 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7940 exception);
cristy3ed852e2009-09-05 21:47:34 +00007941 if (string == (char *) NULL)
7942 break;
cristyb51dff52011-05-19 16:55:47 +00007943 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007944 string=DestroyString(string);
7945 }
7946 if (LocaleCompare("process",option+1) == 0)
7947 {
7948 char
7949 **arguments;
7950
7951 int
7952 j,
7953 number_arguments;
7954
cristy6fccee12011-10-20 18:43:18 +00007955 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007956 arguments=StringToArgv(argv[i+1],&number_arguments);
7957 if (arguments == (char **) NULL)
7958 break;
7959 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
7960 {
7961 char
7962 breaker,
7963 quote,
7964 *token;
7965
7966 const char
7967 *arguments;
7968
7969 int
7970 next,
7971 status;
7972
7973 size_t
7974 length;
7975
7976 TokenInfo
7977 *token_info;
7978
7979 /*
7980 Support old style syntax, filter="-option arg".
7981 */
7982 length=strlen(argv[i+1]);
7983 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00007984 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00007985 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
7986 sizeof(*token));
7987 if (token == (char *) NULL)
7988 break;
7989 next=0;
7990 arguments=argv[i+1];
7991 token_info=AcquireTokenInfo();
7992 status=Tokenizer(token_info,0,token,length,arguments,"","=",
7993 "\"",'\0',&breaker,&next,&quote);
7994 token_info=DestroyTokenInfo(token_info);
7995 if (status == 0)
7996 {
7997 const char
7998 *argv;
7999
8000 argv=(&(arguments[next]));
8001 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8002 exception);
8003 }
8004 token=DestroyString(token);
8005 break;
8006 }
cristy91c0da22010-05-02 01:44:07 +00008007 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008008 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8009 number_arguments-2,(const char **) arguments+2,exception);
8010 for (j=0; j < number_arguments; j++)
8011 arguments[j]=DestroyString(arguments[j]);
8012 arguments=(char **) RelinquishMagickMemory(arguments);
8013 break;
8014 }
8015 break;
8016 }
8017 case 'r':
8018 {
8019 if (LocaleCompare("reverse",option+1) == 0)
8020 {
8021 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008022 break;
8023 }
8024 break;
8025 }
8026 case 's':
8027 {
cristy4285d782011-02-09 20:12:28 +00008028 if (LocaleCompare("smush",option+1) == 0)
8029 {
8030 Image
8031 *smush_image;
8032
8033 ssize_t
8034 offset;
8035
cristy6fccee12011-10-20 18:43:18 +00008036 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008037 offset=(ssize_t) StringToLong(argv[i+1]);
8038 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8039 MagickFalse,offset,exception);
8040 if (smush_image == (Image *) NULL)
8041 {
8042 status=MagickFalse;
8043 break;
8044 }
8045 *images=DestroyImageList(*images);
8046 *images=smush_image;
8047 break;
8048 }
cristy3ed852e2009-09-05 21:47:34 +00008049 if (LocaleCompare("swap",option+1) == 0)
8050 {
8051 Image
8052 *p,
8053 *q,
8054 *swap;
8055
cristybb503372010-05-27 20:51:26 +00008056 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008057 swap_index;
8058
8059 index=(-1);
8060 swap_index=(-2);
8061 if (*option != '+')
8062 {
8063 GeometryInfo
8064 geometry_info;
8065
8066 MagickStatusType
8067 flags;
8068
8069 swap_index=(-1);
8070 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008071 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008072 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008073 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008074 }
8075 p=GetImageFromList(*images,index);
8076 q=GetImageFromList(*images,swap_index);
8077 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8078 {
8079 (void) ThrowMagickException(exception,GetMagickModule(),
8080 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8081 status=MagickFalse;
8082 break;
8083 }
8084 if (p == q)
8085 break;
8086 swap=CloneImage(p,0,0,MagickTrue,exception);
8087 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8088 ReplaceImageInList(&q,swap);
8089 *images=GetFirstImageInList(q);
8090 break;
8091 }
8092 break;
8093 }
8094 case 'w':
8095 {
8096 if (LocaleCompare("write",option+1) == 0)
8097 {
cristy071dd7b2010-04-09 13:04:54 +00008098 char
cristy06609ee2010-03-17 20:21:27 +00008099 key[MaxTextExtent];
8100
cristy3ed852e2009-09-05 21:47:34 +00008101 Image
8102 *write_images;
8103
8104 ImageInfo
8105 *write_info;
8106
cristy6fccee12011-10-20 18:43:18 +00008107 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008108 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008109 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008110 write_images=(*images);
8111 if (*option == '+')
8112 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008113 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008114 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8115 write_info=DestroyImageInfo(write_info);
8116 if (*option == '+')
8117 write_images=DestroyImageList(write_images);
8118 break;
8119 }
8120 break;
8121 }
8122 default:
8123 break;
8124 }
8125 i+=count;
8126 }
8127 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008128 mogrify_info=DestroyImageInfo(mogrify_info);
8129 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008130 return(status != 0 ? MagickTrue : MagickFalse);
8131}
8132
8133/*
8134%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8135% %
8136% %
8137% %
8138+ M o g r i f y I m a g e s %
8139% %
8140% %
8141% %
8142%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8143%
8144% MogrifyImages() applies image processing options to a sequence of images as
8145% prescribed by command line options.
8146%
8147% The format of the MogrifyImage method is:
8148%
8149% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8150% const MagickBooleanType post,const int argc,const char **argv,
8151% Image **images,Exceptioninfo *exception)
8152%
8153% A description of each parameter follows:
8154%
8155% o image_info: the image info..
8156%
8157% o post: If true, post process image list operators otherwise pre-process.
8158%
8159% o argc: Specifies a pointer to an integer describing the number of
8160% elements in the argument vector.
8161%
8162% o argv: Specifies a pointer to a text array containing the command line
8163% arguments.
8164%
anthonye9c27192011-03-27 08:07:06 +00008165% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008166%
8167% o exception: return any errors or warnings in this structure.
8168%
8169*/
8170WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8171 const MagickBooleanType post,const int argc,const char **argv,
8172 Image **images,ExceptionInfo *exception)
8173{
8174#define MogrifyImageTag "Mogrify/Image"
8175
anthonye9c27192011-03-27 08:07:06 +00008176 MagickStatusType
8177 status;
cristy3ed852e2009-09-05 21:47:34 +00008178
cristy0e9f9c12010-02-11 03:00:47 +00008179 MagickBooleanType
8180 proceed;
8181
anthonye9c27192011-03-27 08:07:06 +00008182 size_t
8183 n;
cristy3ed852e2009-09-05 21:47:34 +00008184
cristybb503372010-05-27 20:51:26 +00008185 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008186 i;
8187
cristy3ed852e2009-09-05 21:47:34 +00008188 assert(image_info != (ImageInfo *) NULL);
8189 assert(image_info->signature == MagickSignature);
8190 if (images == (Image **) NULL)
8191 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008192 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008193 assert((*images)->signature == MagickSignature);
8194 if ((*images)->debug != MagickFalse)
8195 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8196 (*images)->filename);
8197 if ((argc <= 0) || (*argv == (char *) NULL))
8198 return(MagickTrue);
8199 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8200 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008201 status=0;
anthonye9c27192011-03-27 08:07:06 +00008202
anthonyce2716b2011-04-22 09:51:34 +00008203#if 0
cristy1e604812011-05-19 18:07:50 +00008204 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8205 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008206#endif
8207
anthonye9c27192011-03-27 08:07:06 +00008208 /*
8209 Pre-process multi-image sequence operators
8210 */
cristy3ed852e2009-09-05 21:47:34 +00008211 if (post == MagickFalse)
8212 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008213 /*
8214 For each image, process simple single image operators
8215 */
8216 i=0;
8217 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008218 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008219 {
anthonyce2716b2011-04-22 09:51:34 +00008220#if 0
cristy1e604812011-05-19 18:07:50 +00008221 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8222 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008223#endif
anthonye9c27192011-03-27 08:07:06 +00008224 status&=MogrifyImage(image_info,argc,argv,images,exception);
8225 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008226 if (proceed == MagickFalse)
8227 break;
anthonye9c27192011-03-27 08:07:06 +00008228 if ( (*images)->next == (Image *) NULL )
8229 break;
8230 *images=(*images)->next;
8231 i++;
cristy3ed852e2009-09-05 21:47:34 +00008232 }
anthonye9c27192011-03-27 08:07:06 +00008233 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008234#if 0
cristy1e604812011-05-19 18:07:50 +00008235 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8236 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008237#endif
anthonye9c27192011-03-27 08:07:06 +00008238
8239 /*
8240 Post-process, multi-image sequence operators
8241 */
8242 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008243 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008244 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008245 return(status != 0 ? MagickTrue : MagickFalse);
8246}