blob: c63d7b99154606b4a639f858d2f0f040fe3215ad [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 /*
anthony32d85bf2012-02-15 14:54:59 +0000351 Read an image into a image cache (for repeated usage) if not already in
352 cache. Then return the image that is in the cache.
cristyfcd785b2011-11-08 01:48:33 +0000353 */
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 }
cristy87c02f42012-02-24 00:19:10 +00001040 if (LocaleCompare("channel-extract",option+1) == 0)
1041 {
1042 puts("stand by...");
1043 break;
1044 }
1045 if (LocaleCompare("channel-swap",option+1) == 0)
1046 {
1047 puts("stand by...");
1048 break;
1049 }
anthonydf8ebac2011-04-27 09:03:19 +00001050 if (LocaleCompare("charcoal",option+1) == 0)
1051 {
1052 /*
1053 Charcoal image.
1054 */
cristy6fccee12011-10-20 18:43:18 +00001055 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001056 flags=ParseGeometry(argv[i+1],&geometry_info);
1057 if ((flags & SigmaValue) == 0)
1058 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001059 if ((flags & XiValue) == 0)
1060 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001061 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001062 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001063 break;
1064 }
1065 if (LocaleCompare("chop",option+1) == 0)
1066 {
1067 /*
1068 Chop the image.
1069 */
cristy6fccee12011-10-20 18:43:18 +00001070 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001071 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1072 mogrify_image=ChopImage(*image,&geometry,exception);
1073 break;
1074 }
1075 if (LocaleCompare("clamp",option+1) == 0)
1076 {
1077 /*
1078 Clamp image.
1079 */
cristy6fccee12011-10-20 18:43:18 +00001080 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001081 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001082 break;
1083 }
1084 if (LocaleCompare("clip",option+1) == 0)
1085 {
cristy6fccee12011-10-20 18:43:18 +00001086 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001087 if (*option == '+')
1088 {
cristy10a6c612012-01-29 21:41:05 +00001089 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001090 break;
1091 }
cristy018f07f2011-09-04 21:15:19 +00001092 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001093 break;
1094 }
1095 if (LocaleCompare("clip-mask",option+1) == 0)
1096 {
1097 CacheView
1098 *mask_view;
1099
1100 Image
1101 *mask_image;
1102
cristy4c08aed2011-07-01 19:47:50 +00001103 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001104 *restrict q;
1105
1106 register ssize_t
1107 x;
1108
1109 ssize_t
1110 y;
1111
cristy6fccee12011-10-20 18:43:18 +00001112 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001113 if (*option == '+')
1114 {
1115 /*
1116 Remove a mask.
1117 */
cristy018f07f2011-09-04 21:15:19 +00001118 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001119 break;
1120 }
1121 /*
1122 Set the image mask.
1123 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1124 */
1125 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1126 if (mask_image == (Image *) NULL)
1127 break;
cristy574cc262011-08-05 01:23:58 +00001128 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001129 return(MagickFalse);
1130 mask_view=AcquireCacheView(mask_image);
1131 for (y=0; y < (ssize_t) mask_image->rows; y++)
1132 {
1133 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1134 exception);
cristyacd2ed22011-08-30 01:44:23 +00001135 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001136 break;
1137 for (x=0; x < (ssize_t) mask_image->columns; x++)
1138 {
1139 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001140 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1141 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1142 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1143 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001144 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001145 }
1146 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1147 break;
1148 }
1149 mask_view=DestroyCacheView(mask_view);
1150 mask_image->matte=MagickTrue;
cristy10a6c612012-01-29 21:41:05 +00001151 (void) SetImageMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001152 break;
1153 }
1154 if (LocaleCompare("clip-path",option+1) == 0)
1155 {
cristy6fccee12011-10-20 18:43:18 +00001156 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001157 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001158 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001159 break;
1160 }
1161 if (LocaleCompare("colorize",option+1) == 0)
1162 {
1163 /*
1164 Colorize the image.
1165 */
cristy6fccee12011-10-20 18:43:18 +00001166 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001167 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001168 break;
1169 }
1170 if (LocaleCompare("color-matrix",option+1) == 0)
1171 {
1172 KernelInfo
1173 *kernel;
1174
cristy6fccee12011-10-20 18:43:18 +00001175 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001176 kernel=AcquireKernelInfo(argv[i+1]);
1177 if (kernel == (KernelInfo *) NULL)
1178 break;
anthonyfd706f92012-01-19 04:22:02 +00001179 /* FUTURE: check on size of the matrix */
anthonydf8ebac2011-04-27 09:03:19 +00001180 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1181 kernel=DestroyKernelInfo(kernel);
1182 break;
1183 }
1184 if (LocaleCompare("colors",option+1) == 0)
1185 {
1186 /*
1187 Reduce the number of colors in the image.
1188 */
cristy6fccee12011-10-20 18:43:18 +00001189 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001190 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1191 if (quantize_info->number_colors == 0)
1192 break;
1193 if (((*image)->storage_class == DirectClass) ||
1194 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001195 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001196 else
cristy018f07f2011-09-04 21:15:19 +00001197 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001198 break;
1199 }
1200 if (LocaleCompare("colorspace",option+1) == 0)
1201 {
1202 ColorspaceType
1203 colorspace;
1204
cristy6fccee12011-10-20 18:43:18 +00001205 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001206 if (*option == '+')
1207 {
cristye941a752011-10-15 01:52:48 +00001208 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001209 break;
1210 }
1211 colorspace=(ColorspaceType) ParseCommandOption(
1212 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001213 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001214 break;
1215 }
cristy633f0c62011-09-15 13:27:36 +00001216 if (LocaleCompare("compose",option+1) == 0)
1217 {
cristy6fccee12011-10-20 18:43:18 +00001218 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001219 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1220 MagickFalse,argv[i+1]);
1221 break;
1222 }
anthonydf8ebac2011-04-27 09:03:19 +00001223 if (LocaleCompare("contrast",option+1) == 0)
1224 {
cristy6fccee12011-10-20 18:43:18 +00001225 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001226 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001227 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001228 break;
1229 }
1230 if (LocaleCompare("contrast-stretch",option+1) == 0)
1231 {
1232 double
1233 black_point,
1234 white_point;
1235
1236 MagickStatusType
1237 flags;
1238
1239 /*
1240 Contrast stretch image.
1241 */
cristy6fccee12011-10-20 18:43:18 +00001242 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001243 flags=ParseGeometry(argv[i+1],&geometry_info);
1244 black_point=geometry_info.rho;
1245 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1246 black_point;
1247 if ((flags & PercentValue) != 0)
1248 {
1249 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1250 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1251 }
1252 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1253 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001254 (void) ContrastStretchImage(*image,black_point,white_point,
1255 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001256 break;
1257 }
1258 if (LocaleCompare("convolve",option+1) == 0)
1259 {
anthonydf8ebac2011-04-27 09:03:19 +00001260 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001261 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001262
cristy6fccee12011-10-20 18:43:18 +00001263 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001264 kernel_info=AcquireKernelInfo(argv[i+1]);
1265 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001266 break;
cristy0a922382011-07-16 15:30:34 +00001267 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001268 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001269 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001270 break;
1271 }
1272 if (LocaleCompare("crop",option+1) == 0)
1273 {
1274 /*
1275 Crop a image to a smaller size
1276 */
cristy6fccee12011-10-20 18:43:18 +00001277 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001278 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001279 break;
1280 }
1281 if (LocaleCompare("cycle",option+1) == 0)
1282 {
1283 /*
1284 Cycle an image colormap.
1285 */
cristy6fccee12011-10-20 18:43:18 +00001286 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001287 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1288 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001289 break;
1290 }
1291 break;
1292 }
1293 case 'd':
1294 {
1295 if (LocaleCompare("decipher",option+1) == 0)
1296 {
1297 StringInfo
1298 *passkey;
1299
1300 /*
1301 Decipher pixels.
1302 */
cristy6fccee12011-10-20 18:43:18 +00001303 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001304 passkey=FileToStringInfo(argv[i+1],~0,exception);
1305 if (passkey != (StringInfo *) NULL)
1306 {
1307 (void) PasskeyDecipherImage(*image,passkey,exception);
1308 passkey=DestroyStringInfo(passkey);
1309 }
1310 break;
1311 }
1312 if (LocaleCompare("density",option+1) == 0)
1313 {
1314 /*
1315 Set image density.
1316 */
1317 (void) CloneString(&draw_info->density,argv[i+1]);
1318 break;
1319 }
1320 if (LocaleCompare("depth",option+1) == 0)
1321 {
cristy6fccee12011-10-20 18:43:18 +00001322 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001323 if (*option == '+')
1324 {
cristy8a11cb12011-10-19 23:53:34 +00001325 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001326 break;
1327 }
cristy8a11cb12011-10-19 23:53:34 +00001328 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1329 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001330 break;
1331 }
1332 if (LocaleCompare("deskew",option+1) == 0)
1333 {
1334 double
1335 threshold;
1336
1337 /*
1338 Straighten the image.
1339 */
cristy6fccee12011-10-20 18:43:18 +00001340 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001341 if (*option == '+')
1342 threshold=40.0*QuantumRange/100.0;
1343 else
cristy9b34e302011-11-05 02:15:45 +00001344 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1345 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001346 mogrify_image=DeskewImage(*image,threshold,exception);
1347 break;
1348 }
1349 if (LocaleCompare("despeckle",option+1) == 0)
1350 {
1351 /*
1352 Reduce the speckles within an image.
1353 */
cristy6fccee12011-10-20 18:43:18 +00001354 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001355 mogrify_image=DespeckleImage(*image,exception);
1356 break;
1357 }
1358 if (LocaleCompare("display",option+1) == 0)
1359 {
1360 (void) CloneString(&draw_info->server_name,argv[i+1]);
1361 break;
1362 }
1363 if (LocaleCompare("distort",option+1) == 0)
1364 {
1365 char
1366 *args,
1367 token[MaxTextExtent];
1368
1369 const char
1370 *p;
1371
1372 DistortImageMethod
1373 method;
1374
1375 double
1376 *arguments;
1377
1378 register ssize_t
1379 x;
1380
1381 size_t
1382 number_arguments;
1383
1384 /*
1385 Distort image.
1386 */
cristy6fccee12011-10-20 18:43:18 +00001387 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001388 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1389 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001390 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001391 {
anthonydf8ebac2011-04-27 09:03:19 +00001392 double
1393 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001394
1395 /*
1396 Special Case - Argument is actually a resize geometry!
1397 Convert that to an appropriate distortion argument array.
1398 */
anthonydf8ebac2011-04-27 09:03:19 +00001399 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001400 exception);
1401 resize_args[0]=(double) geometry.width;
1402 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001403 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001404 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001405 break;
1406 }
cristy018f07f2011-09-04 21:15:19 +00001407 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1408 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001409 if (args == (char *) NULL)
1410 break;
1411 p=(char *) args;
1412 for (x=0; *p != '\0'; x++)
1413 {
1414 GetMagickToken(p,&p,token);
1415 if (*token == ',')
1416 GetMagickToken(p,&p,token);
1417 }
1418 number_arguments=(size_t) x;
1419 arguments=(double *) AcquireQuantumMemory(number_arguments,
1420 sizeof(*arguments));
1421 if (arguments == (double *) NULL)
1422 ThrowWandFatalException(ResourceLimitFatalError,
1423 "MemoryAllocationFailed",(*image)->filename);
1424 (void) ResetMagickMemory(arguments,0,number_arguments*
1425 sizeof(*arguments));
1426 p=(char *) args;
1427 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1428 {
1429 GetMagickToken(p,&p,token);
1430 if (*token == ',')
1431 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001432 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001433 }
1434 args=DestroyString(args);
1435 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1436 (*option == '+') ? MagickTrue : MagickFalse,exception);
1437 arguments=(double *) RelinquishMagickMemory(arguments);
1438 break;
1439 }
1440 if (LocaleCompare("dither",option+1) == 0)
1441 {
1442 if (*option == '+')
1443 {
1444 quantize_info->dither=MagickFalse;
1445 break;
1446 }
1447 quantize_info->dither=MagickTrue;
1448 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1449 MagickDitherOptions,MagickFalse,argv[i+1]);
1450 if (quantize_info->dither_method == NoDitherMethod)
1451 quantize_info->dither=MagickFalse;
1452 break;
1453 }
1454 if (LocaleCompare("draw",option+1) == 0)
1455 {
1456 /*
1457 Draw image.
1458 */
cristy6fccee12011-10-20 18:43:18 +00001459 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001460 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001461 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001462 break;
1463 }
1464 break;
1465 }
1466 case 'e':
1467 {
1468 if (LocaleCompare("edge",option+1) == 0)
1469 {
1470 /*
1471 Enhance edges in the image.
1472 */
cristy6fccee12011-10-20 18:43:18 +00001473 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001474 flags=ParseGeometry(argv[i+1],&geometry_info);
1475 if ((flags & SigmaValue) == 0)
1476 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001477 mogrify_image=EdgeImage(*image,geometry_info.rho,
1478 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001479 break;
1480 }
1481 if (LocaleCompare("emboss",option+1) == 0)
1482 {
1483 /*
cristyd89705a2012-01-20 02:52:24 +00001484 Emboss image.
anthonydf8ebac2011-04-27 09:03:19 +00001485 */
cristy6fccee12011-10-20 18:43:18 +00001486 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001487 flags=ParseGeometry(argv[i+1],&geometry_info);
1488 if ((flags & SigmaValue) == 0)
1489 geometry_info.sigma=1.0;
1490 mogrify_image=EmbossImage(*image,geometry_info.rho,
1491 geometry_info.sigma,exception);
1492 break;
1493 }
1494 if (LocaleCompare("encipher",option+1) == 0)
1495 {
1496 StringInfo
1497 *passkey;
1498
1499 /*
1500 Encipher pixels.
1501 */
cristy6fccee12011-10-20 18:43:18 +00001502 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001503 passkey=FileToStringInfo(argv[i+1],~0,exception);
1504 if (passkey != (StringInfo *) NULL)
1505 {
1506 (void) PasskeyEncipherImage(*image,passkey,exception);
1507 passkey=DestroyStringInfo(passkey);
1508 }
1509 break;
1510 }
1511 if (LocaleCompare("encoding",option+1) == 0)
1512 {
1513 (void) CloneString(&draw_info->encoding,argv[i+1]);
1514 break;
1515 }
1516 if (LocaleCompare("enhance",option+1) == 0)
1517 {
1518 /*
1519 Enhance image.
1520 */
cristy6fccee12011-10-20 18:43:18 +00001521 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001522 mogrify_image=EnhanceImage(*image,exception);
1523 break;
1524 }
1525 if (LocaleCompare("equalize",option+1) == 0)
1526 {
1527 /*
1528 Equalize image.
1529 */
cristy6fccee12011-10-20 18:43:18 +00001530 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001531 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001532 break;
1533 }
1534 if (LocaleCompare("evaluate",option+1) == 0)
1535 {
1536 double
1537 constant;
1538
1539 MagickEvaluateOperator
1540 op;
1541
cristy6fccee12011-10-20 18:43:18 +00001542 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001543 op=(MagickEvaluateOperator) ParseCommandOption(
1544 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001545 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1546 1.0);
cristyd42d9952011-07-08 14:21:50 +00001547 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001548 break;
1549 }
1550 if (LocaleCompare("extent",option+1) == 0)
1551 {
1552 /*
1553 Set the image extent.
1554 */
cristy6fccee12011-10-20 18:43:18 +00001555 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001556 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1557 if (geometry.width == 0)
1558 geometry.width=(*image)->columns;
1559 if (geometry.height == 0)
1560 geometry.height=(*image)->rows;
1561 mogrify_image=ExtentImage(*image,&geometry,exception);
1562 break;
1563 }
1564 break;
1565 }
1566 case 'f':
1567 {
1568 if (LocaleCompare("family",option+1) == 0)
1569 {
1570 if (*option == '+')
1571 {
1572 if (draw_info->family != (char *) NULL)
1573 draw_info->family=DestroyString(draw_info->family);
1574 break;
1575 }
1576 (void) CloneString(&draw_info->family,argv[i+1]);
1577 break;
1578 }
1579 if (LocaleCompare("features",option+1) == 0)
1580 {
1581 if (*option == '+')
1582 {
1583 (void) DeleteImageArtifact(*image,"identify:features");
1584 break;
1585 }
1586 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1587 break;
1588 }
1589 if (LocaleCompare("fill",option+1) == 0)
1590 {
1591 ExceptionInfo
1592 *sans;
1593
anthonyfd706f92012-01-19 04:22:02 +00001594 PixelInfo
1595 color;
1596
cristy4c08aed2011-07-01 19:47:50 +00001597 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001598 if (*option == '+')
1599 {
cristy269c9412011-10-13 23:41:15 +00001600 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001601 exception);
anthonyfd706f92012-01-19 04:22:02 +00001602 draw_info->fill=fill;
anthonydf8ebac2011-04-27 09:03:19 +00001603 if (draw_info->fill_pattern != (Image *) NULL)
1604 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1605 break;
1606 }
1607 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00001608 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001609 sans=DestroyExceptionInfo(sans);
1610 if (status == MagickFalse)
1611 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1612 exception);
anthonyfd706f92012-01-19 04:22:02 +00001613 else
1614 draw_info->fill=fill=color;
anthonydf8ebac2011-04-27 09:03:19 +00001615 break;
1616 }
1617 if (LocaleCompare("flip",option+1) == 0)
1618 {
1619 /*
1620 Flip image scanlines.
1621 */
cristy6fccee12011-10-20 18:43:18 +00001622 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001623 mogrify_image=FlipImage(*image,exception);
1624 break;
1625 }
anthonydf8ebac2011-04-27 09:03:19 +00001626 if (LocaleCompare("floodfill",option+1) == 0)
1627 {
cristy4c08aed2011-07-01 19:47:50 +00001628 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001629 target;
1630
1631 /*
1632 Floodfill image.
1633 */
cristy6fccee12011-10-20 18:43:18 +00001634 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001635 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001636 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001637 exception);
cristyd42d9952011-07-08 14:21:50 +00001638 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001639 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001640 break;
1641 }
anthony3d2f4862011-05-01 13:48:16 +00001642 if (LocaleCompare("flop",option+1) == 0)
1643 {
1644 /*
1645 Flop image scanlines.
1646 */
cristy6fccee12011-10-20 18:43:18 +00001647 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001648 mogrify_image=FlopImage(*image,exception);
1649 break;
1650 }
anthonydf8ebac2011-04-27 09:03:19 +00001651 if (LocaleCompare("font",option+1) == 0)
1652 {
1653 if (*option == '+')
1654 {
1655 if (draw_info->font != (char *) NULL)
1656 draw_info->font=DestroyString(draw_info->font);
1657 break;
1658 }
1659 (void) CloneString(&draw_info->font,argv[i+1]);
1660 break;
1661 }
1662 if (LocaleCompare("format",option+1) == 0)
1663 {
1664 format=argv[i+1];
1665 break;
1666 }
1667 if (LocaleCompare("frame",option+1) == 0)
1668 {
1669 FrameInfo
1670 frame_info;
1671
1672 /*
1673 Surround image with an ornamental border.
1674 */
cristy6fccee12011-10-20 18:43:18 +00001675 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001676 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1677 frame_info.width=geometry.width;
1678 frame_info.height=geometry.height;
1679 if ((flags & HeightValue) == 0)
1680 frame_info.height=geometry.width;
1681 frame_info.outer_bevel=geometry.x;
1682 frame_info.inner_bevel=geometry.y;
1683 frame_info.x=(ssize_t) frame_info.width;
1684 frame_info.y=(ssize_t) frame_info.height;
1685 frame_info.width=(*image)->columns+2*frame_info.width;
1686 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001687 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001688 break;
1689 }
1690 if (LocaleCompare("function",option+1) == 0)
1691 {
1692 char
1693 *arguments,
1694 token[MaxTextExtent];
1695
1696 const char
1697 *p;
1698
1699 double
1700 *parameters;
1701
1702 MagickFunction
1703 function;
1704
1705 register ssize_t
1706 x;
1707
1708 size_t
1709 number_parameters;
1710
1711 /*
1712 Function Modify Image Values
1713 */
cristy6fccee12011-10-20 18:43:18 +00001714 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001715 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1716 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001717 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1718 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001719 if (arguments == (char *) NULL)
1720 break;
1721 p=(char *) arguments;
1722 for (x=0; *p != '\0'; x++)
1723 {
1724 GetMagickToken(p,&p,token);
1725 if (*token == ',')
1726 GetMagickToken(p,&p,token);
1727 }
1728 number_parameters=(size_t) x;
1729 parameters=(double *) AcquireQuantumMemory(number_parameters,
1730 sizeof(*parameters));
1731 if (parameters == (double *) NULL)
1732 ThrowWandFatalException(ResourceLimitFatalError,
1733 "MemoryAllocationFailed",(*image)->filename);
1734 (void) ResetMagickMemory(parameters,0,number_parameters*
1735 sizeof(*parameters));
1736 p=(char *) arguments;
1737 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1738 {
1739 GetMagickToken(p,&p,token);
1740 if (*token == ',')
1741 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001742 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001743 }
1744 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001745 (void) FunctionImage(*image,function,number_parameters,parameters,
1746 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001747 parameters=(double *) RelinquishMagickMemory(parameters);
1748 break;
1749 }
1750 break;
1751 }
1752 case 'g':
1753 {
1754 if (LocaleCompare("gamma",option+1) == 0)
1755 {
1756 /*
1757 Gamma image.
1758 */
cristy6fccee12011-10-20 18:43:18 +00001759 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001760 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001761 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001762 else
cristydbdd0e32011-11-04 23:29:40 +00001763 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001764 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001765 break;
1766 }
1767 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1768 (LocaleCompare("gaussian",option+1) == 0))
1769 {
1770 /*
1771 Gaussian blur image.
1772 */
cristy6fccee12011-10-20 18:43:18 +00001773 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001774 flags=ParseGeometry(argv[i+1],&geometry_info);
1775 if ((flags & SigmaValue) == 0)
1776 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001777 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristyd89705a2012-01-20 02:52:24 +00001778 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001779 break;
1780 }
1781 if (LocaleCompare("geometry",option+1) == 0)
1782 {
1783 /*
1784 Record Image offset, Resize last image.
1785 */
cristy6fccee12011-10-20 18:43:18 +00001786 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001787 if (*option == '+')
1788 {
1789 if ((*image)->geometry != (char *) NULL)
1790 (*image)->geometry=DestroyString((*image)->geometry);
1791 break;
1792 }
1793 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1794 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1795 (void) CloneString(&(*image)->geometry,argv[i+1]);
1796 else
1797 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1798 (*image)->filter,(*image)->blur,exception);
1799 break;
1800 }
1801 if (LocaleCompare("gravity",option+1) == 0)
1802 {
1803 if (*option == '+')
1804 {
1805 draw_info->gravity=UndefinedGravity;
1806 break;
1807 }
1808 draw_info->gravity=(GravityType) ParseCommandOption(
1809 MagickGravityOptions,MagickFalse,argv[i+1]);
1810 break;
1811 }
1812 break;
1813 }
1814 case 'h':
1815 {
1816 if (LocaleCompare("highlight-color",option+1) == 0)
1817 {
1818 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1819 break;
1820 }
1821 break;
1822 }
1823 case 'i':
1824 {
1825 if (LocaleCompare("identify",option+1) == 0)
1826 {
1827 char
1828 *text;
1829
cristy6fccee12011-10-20 18:43:18 +00001830 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001831 if (format == (char *) NULL)
1832 {
cristya4037272011-08-28 15:11:39 +00001833 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1834 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001835 break;
1836 }
cristy018f07f2011-09-04 21:15:19 +00001837 text=InterpretImageProperties(mogrify_info,*image,format,
1838 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001839 if (text == (char *) NULL)
1840 break;
1841 (void) fputs(text,stdout);
1842 (void) fputc('\n',stdout);
1843 text=DestroyString(text);
1844 break;
1845 }
1846 if (LocaleCompare("implode",option+1) == 0)
1847 {
1848 /*
1849 Implode image.
1850 */
cristy6fccee12011-10-20 18:43:18 +00001851 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001852 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001853 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1854 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001855 break;
1856 }
1857 if (LocaleCompare("interline-spacing",option+1) == 0)
1858 {
1859 if (*option == '+')
1860 (void) ParseGeometry("0",&geometry_info);
1861 else
1862 (void) ParseGeometry(argv[i+1],&geometry_info);
1863 draw_info->interline_spacing=geometry_info.rho;
1864 break;
1865 }
cristy28474bf2011-09-11 23:32:52 +00001866 if (LocaleCompare("interpolate",option+1) == 0)
1867 {
1868 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1869 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1870 break;
1871 }
anthonydf8ebac2011-04-27 09:03:19 +00001872 if (LocaleCompare("interword-spacing",option+1) == 0)
1873 {
1874 if (*option == '+')
1875 (void) ParseGeometry("0",&geometry_info);
1876 else
1877 (void) ParseGeometry(argv[i+1],&geometry_info);
1878 draw_info->interword_spacing=geometry_info.rho;
1879 break;
1880 }
anthonyfd706f92012-01-19 04:22:02 +00001881 if (LocaleCompare("interpolative-resize",option+1) == 0)
1882 {
1883 /*
1884 Interpolative resize image.
1885 */
1886 (void) SyncImageSettings(mogrify_info,*image,exception);
1887 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1888 mogrify_image=InterpolativeResizeImage(*image,geometry.width,
1889 geometry.height,interpolate_method,exception);
1890 break;
1891 }
anthonydf8ebac2011-04-27 09:03:19 +00001892 break;
1893 }
1894 case 'k':
1895 {
1896 if (LocaleCompare("kerning",option+1) == 0)
1897 {
1898 if (*option == '+')
1899 (void) ParseGeometry("0",&geometry_info);
1900 else
1901 (void) ParseGeometry(argv[i+1],&geometry_info);
1902 draw_info->kerning=geometry_info.rho;
1903 break;
1904 }
1905 break;
1906 }
1907 case 'l':
1908 {
1909 if (LocaleCompare("lat",option+1) == 0)
1910 {
1911 /*
1912 Local adaptive threshold image.
1913 */
cristy6fccee12011-10-20 18:43:18 +00001914 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001915 flags=ParseGeometry(argv[i+1],&geometry_info);
1916 if ((flags & PercentValue) != 0)
1917 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1918 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001919 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001920 geometry_info.xi,exception);
1921 break;
1922 }
1923 if (LocaleCompare("level",option+1) == 0)
1924 {
1925 MagickRealType
1926 black_point,
1927 gamma,
1928 white_point;
1929
1930 MagickStatusType
1931 flags;
1932
1933 /*
1934 Parse levels.
1935 */
cristy6fccee12011-10-20 18:43:18 +00001936 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001937 flags=ParseGeometry(argv[i+1],&geometry_info);
1938 black_point=geometry_info.rho;
1939 white_point=(MagickRealType) QuantumRange;
1940 if ((flags & SigmaValue) != 0)
1941 white_point=geometry_info.sigma;
1942 gamma=1.0;
1943 if ((flags & XiValue) != 0)
1944 gamma=geometry_info.xi;
1945 if ((flags & PercentValue) != 0)
1946 {
1947 black_point*=(MagickRealType) (QuantumRange/100.0);
1948 white_point*=(MagickRealType) (QuantumRange/100.0);
1949 }
1950 if ((flags & SigmaValue) == 0)
1951 white_point=(MagickRealType) QuantumRange-black_point;
1952 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001953 (void) LevelizeImage(*image,black_point,white_point,gamma,
1954 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001955 else
cristy01e9afd2011-08-10 17:38:41 +00001956 (void) LevelImage(*image,black_point,white_point,gamma,
1957 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001958 break;
1959 }
1960 if (LocaleCompare("level-colors",option+1) == 0)
1961 {
1962 char
1963 token[MaxTextExtent];
1964
1965 const char
1966 *p;
1967
cristy4c08aed2011-07-01 19:47:50 +00001968 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001969 black_point,
1970 white_point;
1971
1972 p=(const char *) argv[i+1];
1973 GetMagickToken(p,&p,token); /* get black point color */
1974 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001975 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001976 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001977 else
cristy269c9412011-10-13 23:41:15 +00001978 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001979 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001980 if (isalpha((int) token[0]) || (token[0] == '#'))
1981 GetMagickToken(p,&p,token);
1982 if (*token == '\0')
1983 white_point=black_point; /* set everything to that color */
1984 else
1985 {
1986 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1987 GetMagickToken(p,&p,token); /* Get white point color. */
1988 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001989 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001990 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001991 else
cristy269c9412011-10-13 23:41:15 +00001992 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001993 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001994 }
cristy490408a2011-07-07 14:42:05 +00001995 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001996 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001997 break;
1998 }
1999 if (LocaleCompare("linear-stretch",option+1) == 0)
2000 {
2001 double
2002 black_point,
2003 white_point;
2004
2005 MagickStatusType
2006 flags;
2007
cristy6fccee12011-10-20 18:43:18 +00002008 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002009 flags=ParseGeometry(argv[i+1],&geometry_info);
2010 black_point=geometry_info.rho;
2011 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2012 if ((flags & SigmaValue) != 0)
2013 white_point=geometry_info.sigma;
2014 if ((flags & PercentValue) != 0)
2015 {
2016 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2017 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2018 }
2019 if ((flags & SigmaValue) == 0)
2020 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2021 black_point;
cristy33bd5152011-08-24 01:42:24 +00002022 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002023 break;
2024 }
anthonydf8ebac2011-04-27 09:03:19 +00002025 if (LocaleCompare("liquid-rescale",option+1) == 0)
2026 {
2027 /*
2028 Liquid rescale image.
2029 */
cristy6fccee12011-10-20 18:43:18 +00002030 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002031 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2032 if ((flags & XValue) == 0)
2033 geometry.x=1;
2034 if ((flags & YValue) == 0)
2035 geometry.y=0;
2036 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2037 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2038 break;
2039 }
2040 if (LocaleCompare("lowlight-color",option+1) == 0)
2041 {
2042 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2043 break;
2044 }
2045 break;
2046 }
2047 case 'm':
2048 {
2049 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002050 {
cristy3ed852e2009-09-05 21:47:34 +00002051 Image
anthonydf8ebac2011-04-27 09:03:19 +00002052 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002053
anthonydf8ebac2011-04-27 09:03:19 +00002054 /*
2055 Transform image colors to match this set of colors.
2056 */
cristy6fccee12011-10-20 18:43:18 +00002057 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002058 if (*option == '+')
2059 break;
2060 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2061 if (remap_image == (Image *) NULL)
2062 break;
cristy018f07f2011-09-04 21:15:19 +00002063 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002064 remap_image=DestroyImage(remap_image);
2065 break;
2066 }
2067 if (LocaleCompare("mask",option+1) == 0)
2068 {
2069 Image
2070 *mask;
2071
cristy6fccee12011-10-20 18:43:18 +00002072 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002073 if (*option == '+')
2074 {
2075 /*
2076 Remove a mask.
2077 */
cristy018f07f2011-09-04 21:15:19 +00002078 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002079 break;
2080 }
2081 /*
2082 Set the image mask.
2083 */
2084 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2085 if (mask == (Image *) NULL)
2086 break;
cristy018f07f2011-09-04 21:15:19 +00002087 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002088 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002089 break;
2090 }
2091 if (LocaleCompare("matte",option+1) == 0)
2092 {
2093 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002094 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002095 break;
2096 }
2097 if (LocaleCompare("median",option+1) == 0)
2098 {
2099 /*
2100 Median filter image.
2101 */
cristy6fccee12011-10-20 18:43:18 +00002102 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002103 flags=ParseGeometry(argv[i+1],&geometry_info);
2104 if ((flags & SigmaValue) == 0)
2105 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002106 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002107 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002108 break;
2109 }
2110 if (LocaleCompare("mode",option+1) == 0)
2111 {
2112 /*
2113 Mode image.
2114 */
cristy6fccee12011-10-20 18:43:18 +00002115 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002116 flags=ParseGeometry(argv[i+1],&geometry_info);
2117 if ((flags & SigmaValue) == 0)
2118 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002119 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002120 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002121 break;
2122 }
2123 if (LocaleCompare("modulate",option+1) == 0)
2124 {
cristy6fccee12011-10-20 18:43:18 +00002125 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002126 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002127 break;
2128 }
2129 if (LocaleCompare("monitor",option+1) == 0)
2130 {
2131 if (*option == '+')
2132 {
2133 (void) SetImageProgressMonitor(*image,
2134 (MagickProgressMonitor) NULL,(void *) NULL);
2135 break;
2136 }
2137 (void) SetImageProgressMonitor(*image,MonitorProgress,
2138 (void *) NULL);
2139 break;
2140 }
2141 if (LocaleCompare("monochrome",option+1) == 0)
2142 {
cristy6fccee12011-10-20 18:43:18 +00002143 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002144 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002145 break;
2146 }
2147 if (LocaleCompare("morphology",option+1) == 0)
2148 {
2149 char
2150 token[MaxTextExtent];
2151
2152 const char
2153 *p;
2154
2155 KernelInfo
2156 *kernel;
2157
2158 MorphologyMethod
2159 method;
2160
2161 ssize_t
2162 iterations;
2163
2164 /*
2165 Morphological Image Operation
2166 */
cristy6fccee12011-10-20 18:43:18 +00002167 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002168 p=argv[i+1];
2169 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002170 method=(MorphologyMethod) ParseCommandOption(
2171 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002172 iterations=1L;
2173 GetMagickToken(p,&p,token);
2174 if ((*p == ':') || (*p == ','))
2175 GetMagickToken(p,&p,token);
2176 if ((*p != '\0'))
2177 iterations=(ssize_t) StringToLong(p);
2178 kernel=AcquireKernelInfo(argv[i+2]);
2179 if (kernel == (KernelInfo *) NULL)
2180 {
2181 (void) ThrowMagickException(exception,GetMagickModule(),
2182 OptionError,"UnabletoParseKernel","morphology");
2183 status=MagickFalse;
2184 break;
2185 }
cristyf4ad9df2011-07-08 16:49:03 +00002186 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2187 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002188 kernel=DestroyKernelInfo(kernel);
2189 break;
2190 }
2191 if (LocaleCompare("motion-blur",option+1) == 0)
2192 {
2193 /*
2194 Motion blur image.
2195 */
cristy6fccee12011-10-20 18:43:18 +00002196 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002197 flags=ParseGeometry(argv[i+1],&geometry_info);
2198 if ((flags & SigmaValue) == 0)
2199 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002200 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristy7497f482011-12-08 01:57:31 +00002201 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002202 break;
2203 }
2204 break;
2205 }
2206 case 'n':
2207 {
2208 if (LocaleCompare("negate",option+1) == 0)
2209 {
cristy6fccee12011-10-20 18:43:18 +00002210 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002211 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002212 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002213 break;
2214 }
2215 if (LocaleCompare("noise",option+1) == 0)
2216 {
cristy6fccee12011-10-20 18:43:18 +00002217 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002218 if (*option == '-')
2219 {
cristyf36cbcb2011-09-07 13:28:22 +00002220 flags=ParseGeometry(argv[i+1],&geometry_info);
2221 if ((flags & SigmaValue) == 0)
2222 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002223 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002224 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002225 }
2226 else
2227 {
2228 NoiseType
2229 noise;
2230
2231 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2232 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002233 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002234 }
2235 break;
2236 }
2237 if (LocaleCompare("normalize",option+1) == 0)
2238 {
cristy6fccee12011-10-20 18:43:18 +00002239 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002240 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002241 break;
2242 }
2243 break;
2244 }
2245 case 'o':
2246 {
2247 if (LocaleCompare("opaque",option+1) == 0)
2248 {
cristy4c08aed2011-07-01 19:47:50 +00002249 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002250 target;
2251
cristy6fccee12011-10-20 18:43:18 +00002252 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002253 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002254 exception);
cristyd42d9952011-07-08 14:21:50 +00002255 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002256 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002257 break;
2258 }
2259 if (LocaleCompare("ordered-dither",option+1) == 0)
2260 {
cristy6fccee12011-10-20 18:43:18 +00002261 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002262 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002263 break;
2264 }
2265 break;
2266 }
2267 case 'p':
2268 {
2269 if (LocaleCompare("paint",option+1) == 0)
2270 {
cristy6fccee12011-10-20 18:43:18 +00002271 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002272 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002273 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2274 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002275 break;
2276 }
anthonydf8ebac2011-04-27 09:03:19 +00002277 if (LocaleCompare("pointsize",option+1) == 0)
2278 {
2279 if (*option == '+')
2280 (void) ParseGeometry("12",&geometry_info);
2281 else
2282 (void) ParseGeometry(argv[i+1],&geometry_info);
2283 draw_info->pointsize=geometry_info.rho;
2284 break;
2285 }
2286 if (LocaleCompare("polaroid",option+1) == 0)
2287 {
cristye9e3d382011-12-14 01:50:13 +00002288 const char
2289 *caption;
2290
anthonydf8ebac2011-04-27 09:03:19 +00002291 double
2292 angle;
2293
2294 RandomInfo
2295 *random_info;
2296
2297 /*
2298 Simulate a Polaroid picture.
2299 */
cristy6fccee12011-10-20 18:43:18 +00002300 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002301 random_info=AcquireRandomInfo();
2302 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2303 random_info=DestroyRandomInfo(random_info);
2304 if (*option == '-')
2305 {
2306 SetGeometryInfo(&geometry_info);
2307 flags=ParseGeometry(argv[i+1],&geometry_info);
2308 angle=geometry_info.rho;
2309 }
cristye9e3d382011-12-14 01:50:13 +00002310 caption=GetImageProperty(*image,"caption",exception);
2311 mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
cristy28474bf2011-09-11 23:32:52 +00002312 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002313 break;
2314 }
2315 if (LocaleCompare("posterize",option+1) == 0)
2316 {
2317 /*
2318 Posterize image.
2319 */
cristy6fccee12011-10-20 18:43:18 +00002320 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002321 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002322 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002323 break;
2324 }
2325 if (LocaleCompare("preview",option+1) == 0)
2326 {
2327 PreviewType
2328 preview_type;
2329
2330 /*
2331 Preview image.
2332 */
cristy6fccee12011-10-20 18:43:18 +00002333 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002334 if (*option == '+')
2335 preview_type=UndefinedPreview;
2336 else
cristy28474bf2011-09-11 23:32:52 +00002337 preview_type=(PreviewType) ParseCommandOption(
2338 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002339 mogrify_image=PreviewImage(*image,preview_type,exception);
2340 break;
2341 }
2342 if (LocaleCompare("profile",option+1) == 0)
2343 {
2344 const char
2345 *name;
2346
2347 const StringInfo
2348 *profile;
2349
2350 Image
2351 *profile_image;
2352
2353 ImageInfo
2354 *profile_info;
2355
cristy6fccee12011-10-20 18:43:18 +00002356 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002357 if (*option == '+')
2358 {
2359 /*
2360 Remove a profile from the image.
2361 */
2362 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002363 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002364 break;
2365 }
2366 /*
2367 Associate a profile with the image.
2368 */
2369 profile_info=CloneImageInfo(mogrify_info);
2370 profile=GetImageProfile(*image,"iptc");
2371 if (profile != (StringInfo *) NULL)
2372 profile_info->profile=(void *) CloneStringInfo(profile);
2373 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2374 profile_info=DestroyImageInfo(profile_info);
2375 if (profile_image == (Image *) NULL)
2376 {
2377 StringInfo
2378 *profile;
2379
2380 profile_info=CloneImageInfo(mogrify_info);
2381 (void) CopyMagickString(profile_info->filename,argv[i+1],
2382 MaxTextExtent);
2383 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2384 if (profile != (StringInfo *) NULL)
2385 {
2386 (void) ProfileImage(*image,profile_info->magick,
2387 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002388 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002389 profile=DestroyStringInfo(profile);
2390 }
2391 profile_info=DestroyImageInfo(profile_info);
2392 break;
2393 }
2394 ResetImageProfileIterator(profile_image);
2395 name=GetNextImageProfile(profile_image);
2396 while (name != (const char *) NULL)
2397 {
2398 profile=GetImageProfile(profile_image,name);
2399 if (profile != (StringInfo *) NULL)
2400 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002401 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002402 name=GetNextImageProfile(profile_image);
2403 }
2404 profile_image=DestroyImage(profile_image);
2405 break;
2406 }
2407 break;
2408 }
2409 case 'q':
2410 {
2411 if (LocaleCompare("quantize",option+1) == 0)
2412 {
2413 if (*option == '+')
2414 {
2415 quantize_info->colorspace=UndefinedColorspace;
2416 break;
2417 }
2418 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2419 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2420 break;
2421 }
2422 break;
2423 }
2424 case 'r':
2425 {
2426 if (LocaleCompare("radial-blur",option+1) == 0)
2427 {
2428 /*
2429 Radial blur image.
2430 */
cristy6fccee12011-10-20 18:43:18 +00002431 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002432 flags=ParseGeometry(argv[i+1],&geometry_info);
2433 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2434 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002435 break;
2436 }
2437 if (LocaleCompare("raise",option+1) == 0)
2438 {
2439 /*
2440 Surround image with a raise of solid color.
2441 */
2442 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2443 if ((flags & SigmaValue) == 0)
2444 geometry.height=geometry.width;
2445 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002446 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002447 break;
2448 }
2449 if (LocaleCompare("random-threshold",option+1) == 0)
2450 {
2451 /*
2452 Threshold image.
2453 */
cristy6fccee12011-10-20 18:43:18 +00002454 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002455 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002456 break;
2457 }
anthonydf8ebac2011-04-27 09:03:19 +00002458 if (LocaleCompare("region",option+1) == 0)
2459 {
cristy6fccee12011-10-20 18:43:18 +00002460 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002461 if (region_image != (Image *) NULL)
2462 {
2463 /*
2464 Composite region.
2465 */
2466 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002467 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002468 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002469 *image=DestroyImage(*image);
2470 *image=region_image;
2471 region_image = (Image *) NULL;
2472 }
2473 if (*option == '+')
2474 break;
2475 /*
2476 Apply transformations to a selected region of the image.
2477 */
cristy3ed852e2009-09-05 21:47:34 +00002478 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2479 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002480 mogrify_image=CropImage(*image,&region_geometry,exception);
2481 if (mogrify_image == (Image *) NULL)
2482 break;
2483 region_image=(*image);
2484 *image=mogrify_image;
2485 mogrify_image=(Image *) NULL;
2486 break;
cristy3ed852e2009-09-05 21:47:34 +00002487 }
anthonydf8ebac2011-04-27 09:03:19 +00002488 if (LocaleCompare("render",option+1) == 0)
2489 {
cristy6fccee12011-10-20 18:43:18 +00002490 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002491 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2492 break;
2493 }
2494 if (LocaleCompare("remap",option+1) == 0)
2495 {
2496 Image
2497 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002498
anthonydf8ebac2011-04-27 09:03:19 +00002499 /*
2500 Transform image colors to match this set of colors.
2501 */
cristy6fccee12011-10-20 18:43:18 +00002502 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002503 if (*option == '+')
2504 break;
2505 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2506 if (remap_image == (Image *) NULL)
2507 break;
cristy018f07f2011-09-04 21:15:19 +00002508 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002509 remap_image=DestroyImage(remap_image);
2510 break;
2511 }
2512 if (LocaleCompare("repage",option+1) == 0)
2513 {
2514 if (*option == '+')
2515 {
2516 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2517 break;
2518 }
2519 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002520 break;
2521 }
2522 if (LocaleCompare("resample",option+1) == 0)
2523 {
2524 /*
2525 Resample image.
2526 */
cristy6fccee12011-10-20 18:43:18 +00002527 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002528 flags=ParseGeometry(argv[i+1],&geometry_info);
2529 if ((flags & SigmaValue) == 0)
2530 geometry_info.sigma=geometry_info.rho;
2531 mogrify_image=ResampleImage(*image,geometry_info.rho,
2532 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2533 break;
2534 }
2535 if (LocaleCompare("resize",option+1) == 0)
2536 {
2537 /*
2538 Resize image.
2539 */
cristy6fccee12011-10-20 18:43:18 +00002540 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002541 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2542 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2543 (*image)->filter,(*image)->blur,exception);
2544 break;
2545 }
2546 if (LocaleCompare("roll",option+1) == 0)
2547 {
2548 /*
2549 Roll image.
2550 */
cristy6fccee12011-10-20 18:43:18 +00002551 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002552 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2553 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2554 break;
2555 }
2556 if (LocaleCompare("rotate",option+1) == 0)
2557 {
2558 char
2559 *geometry;
2560
2561 /*
2562 Check for conditional image rotation.
2563 */
cristy6fccee12011-10-20 18:43:18 +00002564 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002565 if (strchr(argv[i+1],'>') != (char *) NULL)
2566 if ((*image)->columns <= (*image)->rows)
2567 break;
2568 if (strchr(argv[i+1],'<') != (char *) NULL)
2569 if ((*image)->columns >= (*image)->rows)
2570 break;
2571 /*
2572 Rotate image.
2573 */
2574 geometry=ConstantString(argv[i+1]);
2575 (void) SubstituteString(&geometry,">","");
2576 (void) SubstituteString(&geometry,"<","");
2577 (void) ParseGeometry(geometry,&geometry_info);
2578 geometry=DestroyString(geometry);
2579 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2580 break;
2581 }
2582 break;
2583 }
2584 case 's':
2585 {
2586 if (LocaleCompare("sample",option+1) == 0)
2587 {
2588 /*
2589 Sample image with pixel replication.
2590 */
cristy6fccee12011-10-20 18:43:18 +00002591 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002592 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2593 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2594 exception);
2595 break;
2596 }
2597 if (LocaleCompare("scale",option+1) == 0)
2598 {
2599 /*
2600 Resize image.
2601 */
cristy6fccee12011-10-20 18:43:18 +00002602 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002603 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2604 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2605 exception);
2606 break;
2607 }
2608 if (LocaleCompare("selective-blur",option+1) == 0)
2609 {
2610 /*
2611 Selectively blur pixels within a contrast threshold.
2612 */
cristy6fccee12011-10-20 18:43:18 +00002613 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002614 flags=ParseGeometry(argv[i+1],&geometry_info);
2615 if ((flags & PercentValue) != 0)
2616 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002617 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002618 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002619 break;
2620 }
2621 if (LocaleCompare("separate",option+1) == 0)
2622 {
2623 /*
2624 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002625 */
cristy6fccee12011-10-20 18:43:18 +00002626 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3139dc22011-07-08 00:11:42 +00002627 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002628 break;
2629 }
2630 if (LocaleCompare("sepia-tone",option+1) == 0)
2631 {
2632 double
2633 threshold;
2634
2635 /*
2636 Sepia-tone image.
2637 */
cristy6fccee12011-10-20 18:43:18 +00002638 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002639 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2640 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002641 mogrify_image=SepiaToneImage(*image,threshold,exception);
2642 break;
2643 }
2644 if (LocaleCompare("segment",option+1) == 0)
2645 {
2646 /*
2647 Segment image.
2648 */
cristy6fccee12011-10-20 18:43:18 +00002649 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002650 flags=ParseGeometry(argv[i+1],&geometry_info);
2651 if ((flags & SigmaValue) == 0)
2652 geometry_info.sigma=1.0;
2653 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002654 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2655 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002656 break;
2657 }
2658 if (LocaleCompare("set",option+1) == 0)
2659 {
2660 char
2661 *value;
2662
2663 /*
2664 Set image option.
2665 */
2666 if (*option == '+')
2667 {
2668 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2669 (void) DeleteImageRegistry(argv[i+1]+9);
2670 else
2671 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2672 {
2673 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2674 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2675 }
2676 else
2677 (void) DeleteImageProperty(*image,argv[i+1]);
2678 break;
2679 }
cristy018f07f2011-09-04 21:15:19 +00002680 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2681 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002682 if (value == (char *) NULL)
2683 break;
2684 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2685 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2686 exception);
2687 else
2688 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2689 {
2690 (void) SetImageOption(image_info,argv[i+1]+7,value);
2691 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2692 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2693 }
2694 else
cristyd15e6592011-10-15 00:13:06 +00002695 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002696 value=DestroyString(value);
2697 break;
2698 }
2699 if (LocaleCompare("shade",option+1) == 0)
2700 {
2701 /*
2702 Shade image.
2703 */
cristy6fccee12011-10-20 18:43:18 +00002704 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002705 flags=ParseGeometry(argv[i+1],&geometry_info);
2706 if ((flags & SigmaValue) == 0)
2707 geometry_info.sigma=1.0;
2708 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2709 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2710 break;
2711 }
2712 if (LocaleCompare("shadow",option+1) == 0)
2713 {
2714 /*
2715 Shadow image.
2716 */
cristy6fccee12011-10-20 18:43:18 +00002717 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002718 flags=ParseGeometry(argv[i+1],&geometry_info);
2719 if ((flags & SigmaValue) == 0)
2720 geometry_info.sigma=1.0;
2721 if ((flags & XiValue) == 0)
2722 geometry_info.xi=4.0;
2723 if ((flags & PsiValue) == 0)
2724 geometry_info.psi=4.0;
2725 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00002726 geometry_info.sigma,(*image)->bias,(ssize_t)
2727 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
2728 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002729 break;
2730 }
2731 if (LocaleCompare("sharpen",option+1) == 0)
2732 {
2733 /*
2734 Sharpen image.
2735 */
cristy6fccee12011-10-20 18:43:18 +00002736 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002737 flags=ParseGeometry(argv[i+1],&geometry_info);
2738 if ((flags & SigmaValue) == 0)
2739 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002740 if ((flags & XiValue) == 0)
2741 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002742 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002743 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002744 break;
2745 }
2746 if (LocaleCompare("shave",option+1) == 0)
2747 {
2748 /*
2749 Shave the image edges.
2750 */
cristy6fccee12011-10-20 18:43:18 +00002751 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002752 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2753 mogrify_image=ShaveImage(*image,&geometry,exception);
2754 break;
2755 }
2756 if (LocaleCompare("shear",option+1) == 0)
2757 {
2758 /*
2759 Shear image.
2760 */
cristy6fccee12011-10-20 18:43:18 +00002761 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002762 flags=ParseGeometry(argv[i+1],&geometry_info);
2763 if ((flags & SigmaValue) == 0)
2764 geometry_info.sigma=geometry_info.rho;
2765 mogrify_image=ShearImage(*image,geometry_info.rho,
2766 geometry_info.sigma,exception);
2767 break;
2768 }
2769 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2770 {
2771 /*
2772 Sigmoidal non-linearity contrast control.
2773 */
cristy6fccee12011-10-20 18:43:18 +00002774 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002775 flags=ParseGeometry(argv[i+1],&geometry_info);
2776 if ((flags & SigmaValue) == 0)
2777 geometry_info.sigma=(double) QuantumRange/2.0;
2778 if ((flags & PercentValue) != 0)
2779 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2780 100.0;
cristy9ee60942011-07-06 14:54:38 +00002781 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002782 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2783 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002784 break;
2785 }
2786 if (LocaleCompare("sketch",option+1) == 0)
2787 {
2788 /*
2789 Sketch image.
2790 */
cristy6fccee12011-10-20 18:43:18 +00002791 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002792 flags=ParseGeometry(argv[i+1],&geometry_info);
2793 if ((flags & SigmaValue) == 0)
2794 geometry_info.sigma=1.0;
2795 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002796 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002797 break;
2798 }
2799 if (LocaleCompare("solarize",option+1) == 0)
2800 {
2801 double
2802 threshold;
2803
cristy6fccee12011-10-20 18:43:18 +00002804 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002805 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2806 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002807 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002808 break;
2809 }
2810 if (LocaleCompare("sparse-color",option+1) == 0)
2811 {
2812 SparseColorMethod
2813 method;
2814
2815 char
2816 *arguments;
2817
2818 /*
2819 Sparse Color Interpolated Gradient
2820 */
cristy6fccee12011-10-20 18:43:18 +00002821 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002822 method=(SparseColorMethod) ParseCommandOption(
2823 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002824 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2825 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002826 if (arguments == (char *) NULL)
2827 break;
cristy3884f692011-07-08 18:00:18 +00002828 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002829 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2830 arguments=DestroyString(arguments);
2831 break;
2832 }
2833 if (LocaleCompare("splice",option+1) == 0)
2834 {
2835 /*
2836 Splice a solid color into the image.
2837 */
cristy6fccee12011-10-20 18:43:18 +00002838 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002839 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2840 mogrify_image=SpliceImage(*image,&geometry,exception);
2841 break;
2842 }
2843 if (LocaleCompare("spread",option+1) == 0)
2844 {
2845 /*
2846 Spread an image.
2847 */
cristy6fccee12011-10-20 18:43:18 +00002848 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002849 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002850 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002851 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002852 break;
2853 }
2854 if (LocaleCompare("statistic",option+1) == 0)
2855 {
2856 StatisticType
2857 type;
2858
cristy6fccee12011-10-20 18:43:18 +00002859 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002860 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2861 MagickFalse,argv[i+1]);
2862 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002863 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2864 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002865 break;
2866 }
2867 if (LocaleCompare("stretch",option+1) == 0)
2868 {
2869 if (*option == '+')
2870 {
2871 draw_info->stretch=UndefinedStretch;
2872 break;
2873 }
2874 draw_info->stretch=(StretchType) ParseCommandOption(
2875 MagickStretchOptions,MagickFalse,argv[i+1]);
2876 break;
2877 }
2878 if (LocaleCompare("strip",option+1) == 0)
2879 {
2880 /*
2881 Strip image of profiles and comments.
2882 */
cristy6fccee12011-10-20 18:43:18 +00002883 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002884 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002885 break;
2886 }
2887 if (LocaleCompare("stroke",option+1) == 0)
2888 {
2889 ExceptionInfo
2890 *sans;
2891
anthonyfd706f92012-01-19 04:22:02 +00002892 PixelInfo
2893 color;
2894
anthonydf8ebac2011-04-27 09:03:19 +00002895 if (*option == '+')
2896 {
cristy9950d572011-10-01 18:22:35 +00002897 (void) QueryColorCompliance("none",AllCompliance,
2898 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002899 if (draw_info->stroke_pattern != (Image *) NULL)
2900 draw_info->stroke_pattern=DestroyImage(
2901 draw_info->stroke_pattern);
2902 break;
2903 }
2904 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00002905 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002906 sans=DestroyExceptionInfo(sans);
2907 if (status == MagickFalse)
2908 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2909 exception);
anthonyfd706f92012-01-19 04:22:02 +00002910 else
2911 draw_info->stroke=color;
anthonydf8ebac2011-04-27 09:03:19 +00002912 break;
2913 }
2914 if (LocaleCompare("strokewidth",option+1) == 0)
2915 {
cristy9b34e302011-11-05 02:15:45 +00002916 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002917 break;
2918 }
2919 if (LocaleCompare("style",option+1) == 0)
2920 {
2921 if (*option == '+')
2922 {
2923 draw_info->style=UndefinedStyle;
2924 break;
2925 }
2926 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2927 MagickFalse,argv[i+1]);
2928 break;
2929 }
2930 if (LocaleCompare("swirl",option+1) == 0)
2931 {
2932 /*
2933 Swirl image.
2934 */
cristy6fccee12011-10-20 18:43:18 +00002935 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002936 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002937 mogrify_image=SwirlImage(*image,geometry_info.rho,
2938 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002939 break;
2940 }
2941 break;
2942 }
2943 case 't':
2944 {
2945 if (LocaleCompare("threshold",option+1) == 0)
2946 {
2947 double
2948 threshold;
2949
2950 /*
2951 Threshold image.
2952 */
cristy6fccee12011-10-20 18:43:18 +00002953 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002954 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002955 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002956 else
cristy9b34e302011-11-05 02:15:45 +00002957 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2958 1.0);
cristye941a752011-10-15 01:52:48 +00002959 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002960 break;
2961 }
2962 if (LocaleCompare("thumbnail",option+1) == 0)
2963 {
2964 /*
2965 Thumbnail image.
2966 */
cristy6fccee12011-10-20 18:43:18 +00002967 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002968 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2969 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2970 exception);
2971 break;
2972 }
2973 if (LocaleCompare("tile",option+1) == 0)
2974 {
2975 if (*option == '+')
2976 {
2977 if (draw_info->fill_pattern != (Image *) NULL)
2978 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2979 break;
2980 }
2981 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2982 exception);
2983 break;
2984 }
2985 if (LocaleCompare("tint",option+1) == 0)
2986 {
2987 /*
2988 Tint the image.
2989 */
cristy6fccee12011-10-20 18:43:18 +00002990 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00002991 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002992 break;
2993 }
2994 if (LocaleCompare("transform",option+1) == 0)
2995 {
2996 /*
2997 Affine transform image.
2998 */
cristy6fccee12011-10-20 18:43:18 +00002999 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003000 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
3001 exception);
3002 break;
3003 }
3004 if (LocaleCompare("transparent",option+1) == 0)
3005 {
cristy4c08aed2011-07-01 19:47:50 +00003006 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00003007 target;
3008
cristy6fccee12011-10-20 18:43:18 +00003009 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00003010 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00003011 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003012 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00003013 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00003014 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003015 break;
3016 }
3017 if (LocaleCompare("transpose",option+1) == 0)
3018 {
3019 /*
3020 Transpose image scanlines.
3021 */
cristy6fccee12011-10-20 18:43:18 +00003022 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003023 mogrify_image=TransposeImage(*image,exception);
3024 break;
3025 }
3026 if (LocaleCompare("transverse",option+1) == 0)
3027 {
3028 /*
3029 Transverse image scanlines.
3030 */
cristy6fccee12011-10-20 18:43:18 +00003031 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003032 mogrify_image=TransverseImage(*image,exception);
3033 break;
3034 }
3035 if (LocaleCompare("treedepth",option+1) == 0)
3036 {
3037 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3038 break;
3039 }
3040 if (LocaleCompare("trim",option+1) == 0)
3041 {
3042 /*
3043 Trim image.
3044 */
cristy6fccee12011-10-20 18:43:18 +00003045 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003046 mogrify_image=TrimImage(*image,exception);
3047 break;
3048 }
3049 if (LocaleCompare("type",option+1) == 0)
3050 {
3051 ImageType
3052 type;
3053
cristy6fccee12011-10-20 18:43:18 +00003054 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003055 if (*option == '+')
3056 type=UndefinedType;
3057 else
3058 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3059 argv[i+1]);
3060 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003061 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003062 break;
3063 }
3064 break;
3065 }
3066 case 'u':
3067 {
3068 if (LocaleCompare("undercolor",option+1) == 0)
3069 {
cristy9950d572011-10-01 18:22:35 +00003070 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3071 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003072 break;
3073 }
3074 if (LocaleCompare("unique",option+1) == 0)
3075 {
3076 if (*option == '+')
3077 {
3078 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3079 break;
3080 }
3081 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3082 (void) SetImageArtifact(*image,"verbose","true");
3083 break;
3084 }
3085 if (LocaleCompare("unique-colors",option+1) == 0)
3086 {
3087 /*
3088 Unique image colors.
3089 */
cristy6fccee12011-10-20 18:43:18 +00003090 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003091 mogrify_image=UniqueImageColors(*image,exception);
3092 break;
3093 }
3094 if (LocaleCompare("unsharp",option+1) == 0)
3095 {
3096 /*
3097 Unsharp mask image.
3098 */
cristy6fccee12011-10-20 18:43:18 +00003099 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003100 flags=ParseGeometry(argv[i+1],&geometry_info);
3101 if ((flags & SigmaValue) == 0)
3102 geometry_info.sigma=1.0;
3103 if ((flags & XiValue) == 0)
3104 geometry_info.xi=1.0;
3105 if ((flags & PsiValue) == 0)
3106 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003107 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3108 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003109 break;
3110 }
3111 break;
3112 }
3113 case 'v':
3114 {
3115 if (LocaleCompare("verbose",option+1) == 0)
3116 {
3117 (void) SetImageArtifact(*image,option+1,
3118 *option == '+' ? "false" : "true");
3119 break;
3120 }
3121 if (LocaleCompare("vignette",option+1) == 0)
3122 {
3123 /*
3124 Vignette image.
3125 */
cristy6fccee12011-10-20 18:43:18 +00003126 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003127 flags=ParseGeometry(argv[i+1],&geometry_info);
3128 if ((flags & SigmaValue) == 0)
3129 geometry_info.sigma=1.0;
3130 if ((flags & XiValue) == 0)
3131 geometry_info.xi=0.1*(*image)->columns;
3132 if ((flags & PsiValue) == 0)
3133 geometry_info.psi=0.1*(*image)->rows;
3134 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00003135 geometry_info.sigma,(*image)->bias,(ssize_t)
3136 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
3137 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003138 break;
3139 }
3140 if (LocaleCompare("virtual-pixel",option+1) == 0)
3141 {
3142 if (*option == '+')
3143 {
3144 (void) SetImageVirtualPixelMethod(*image,
cristy387430f2012-02-07 13:09:46 +00003145 UndefinedVirtualPixelMethod,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003146 break;
3147 }
3148 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3149 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy387430f2012-02-07 13:09:46 +00003150 argv[i+1]),exception);
anthonydf8ebac2011-04-27 09:03:19 +00003151 break;
3152 }
3153 break;
3154 }
3155 case 'w':
3156 {
3157 if (LocaleCompare("wave",option+1) == 0)
3158 {
3159 /*
3160 Wave image.
3161 */
cristy6fccee12011-10-20 18:43:18 +00003162 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003163 flags=ParseGeometry(argv[i+1],&geometry_info);
3164 if ((flags & SigmaValue) == 0)
3165 geometry_info.sigma=1.0;
3166 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003167 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003168 break;
3169 }
3170 if (LocaleCompare("weight",option+1) == 0)
3171 {
3172 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3173 if (LocaleCompare(argv[i+1],"all") == 0)
3174 draw_info->weight=0;
3175 if (LocaleCompare(argv[i+1],"bold") == 0)
3176 draw_info->weight=700;
3177 if (LocaleCompare(argv[i+1],"bolder") == 0)
3178 if (draw_info->weight <= 800)
3179 draw_info->weight+=100;
3180 if (LocaleCompare(argv[i+1],"lighter") == 0)
3181 if (draw_info->weight >= 100)
3182 draw_info->weight-=100;
3183 if (LocaleCompare(argv[i+1],"normal") == 0)
3184 draw_info->weight=400;
3185 break;
3186 }
3187 if (LocaleCompare("white-threshold",option+1) == 0)
3188 {
3189 /*
3190 White threshold image.
3191 */
cristy6fccee12011-10-20 18:43:18 +00003192 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003193 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003194 break;
3195 }
3196 break;
3197 }
3198 default:
3199 break;
3200 }
3201 /*
3202 Replace current image with any image that was generated
3203 */
3204 if (mogrify_image != (Image *) NULL)
3205 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003206 i+=count;
3207 }
3208 if (region_image != (Image *) NULL)
3209 {
anthonydf8ebac2011-04-27 09:03:19 +00003210 /*
3211 Composite transformed region onto image.
3212 */
cristy6fccee12011-10-20 18:43:18 +00003213 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonya129f702011-04-14 01:08:48 +00003214 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003215 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003216 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003217 *image=DestroyImage(*image);
3218 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003219 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003220 }
3221 /*
3222 Free resources.
3223 */
anthonydf8ebac2011-04-27 09:03:19 +00003224 quantize_info=DestroyQuantizeInfo(quantize_info);
3225 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003226 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003227 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003228 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003229}
3230
3231/*
3232%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3233% %
3234% %
3235% %
cristy5063d812010-10-19 16:28:10 +00003236+ 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 +00003237% %
3238% %
3239% %
3240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3241%
3242% MogrifyImageCommand() transforms an image or a sequence of images. These
3243% transforms include image scaling, image rotation, color reduction, and
3244% others. The transmogrified image overwrites the original image.
3245%
3246% The format of the MogrifyImageCommand method is:
3247%
3248% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3249% const char **argv,char **metadata,ExceptionInfo *exception)
3250%
3251% A description of each parameter follows:
3252%
3253% o image_info: the image info.
3254%
3255% o argc: the number of elements in the argument vector.
3256%
3257% o argv: A text array containing the command line arguments.
3258%
3259% o metadata: any metadata is returned here.
3260%
3261% o exception: return any errors or warnings in this structure.
3262%
3263*/
3264
3265static MagickBooleanType MogrifyUsage(void)
3266{
3267 static const char
cristy87c02f42012-02-24 00:19:10 +00003268 *channel_operators[]=
3269 {
3270 "-channel-extract channel-list",
3271 " extract the channels in order",
3272 "-channel-inject channel-list",
3273 " inject the channels in order",
3274 "-channel-swap channel,channel",
3275 " swap channels",
3276 (char *) NULL
3277 },
cristy3ed852e2009-09-05 21:47:34 +00003278 *miscellaneous[]=
3279 {
3280 "-debug events display copious debugging information",
3281 "-help print program options",
3282 "-list type print a list of supported option arguments",
3283 "-log format format of debugging information",
3284 "-version print version information",
3285 (char *) NULL
3286 },
3287 *operators[]=
3288 {
3289 "-adaptive-blur geometry",
3290 " adaptively blur pixels; decrease effect near edges",
3291 "-adaptive-resize geometry",
3292 " adaptively resize image using 'mesh' interpolation",
3293 "-adaptive-sharpen geometry",
3294 " adaptively sharpen pixels; increase effect near edges",
3295 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3296 " transparent, extract, background, or shape",
3297 "-annotate geometry text",
3298 " annotate the image with text",
3299 "-auto-gamma automagically adjust gamma level of image",
3300 "-auto-level automagically adjust color levels of image",
3301 "-auto-orient automagically orient (rotate) image",
3302 "-bench iterations measure performance",
3303 "-black-threshold value",
3304 " force all pixels below the threshold into black",
3305 "-blue-shift simulate a scene at nighttime in the moonlight",
3306 "-blur geometry reduce image noise and reduce detail levels",
3307 "-border geometry surround image with a border of color",
3308 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003309 "-brightness-contrast geometry",
3310 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003311 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003312 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003313 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003314 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003315 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003316 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003317 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003318 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003319 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003320 "-contrast enhance or reduce the image contrast",
3321 "-contrast-stretch geometry",
3322 " improve contrast by `stretching' the intensity range",
3323 "-convolve coefficients",
3324 " apply a convolution kernel to the image",
3325 "-cycle amount cycle the image colormap",
3326 "-decipher filename convert cipher pixels to plain pixels",
3327 "-deskew threshold straighten an image",
3328 "-despeckle reduce the speckles within an image",
3329 "-distort method args",
3330 " distort images according to given method ad args",
3331 "-draw string annotate the image with a graphic primitive",
3332 "-edge radius apply a filter to detect edges in the image",
3333 "-encipher filename convert plain pixels to cipher pixels",
3334 "-emboss radius emboss an image",
3335 "-enhance apply a digital filter to enhance a noisy image",
3336 "-equalize perform histogram equalization to an image",
3337 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003338 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003339 "-extent geometry set the image size",
3340 "-extract geometry extract area from image",
3341 "-fft implements the discrete Fourier transform (DFT)",
3342 "-flip flip image vertically",
3343 "-floodfill geometry color",
3344 " floodfill the image with color",
3345 "-flop flop image horizontally",
3346 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003347 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003348 " apply function over image values",
3349 "-gamma value level of gamma correction",
3350 "-gaussian-blur geometry",
3351 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003352 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003353 "-identify identify the format and characteristics of the image",
3354 "-ift implements the inverse discrete Fourier transform (DFT)",
3355 "-implode amount implode image pixels about the center",
anthonyfd706f92012-01-19 04:22:02 +00003356 "-interpolative-resize geometry",
3357 " resize image using interpolation",
cristy3ed852e2009-09-05 21:47:34 +00003358 "-lat geometry local adaptive thresholding",
3359 "-layers method optimize, merge, or compare image layers",
3360 "-level value adjust the level of image contrast",
3361 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003362 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003363 "-linear-stretch geometry",
3364 " improve contrast by `stretching with saturation'",
3365 "-liquid-rescale geometry",
3366 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003367 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003368 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003369 "-modulate value vary the brightness, saturation, and hue",
3370 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003371 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003372 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003373 "-motion-blur geometry",
3374 " simulate motion blur",
3375 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003376 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003377 "-normalize transform image to span the full range of colors",
3378 "-opaque color change this color to the fill color",
3379 "-ordered-dither NxN",
3380 " add a noise pattern to the image with specific",
3381 " amplitudes",
3382 "-paint radius simulate an oil painting",
3383 "-polaroid angle simulate a Polaroid picture",
3384 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003385 "-profile filename add, delete, or apply an image profile",
3386 "-quantize colorspace reduce colors in this colorspace",
3387 "-radial-blur angle radial blur the image",
3388 "-raise value lighten/darken image edges to create a 3-D effect",
3389 "-random-threshold low,high",
3390 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003391 "-region geometry apply options to a portion of the image",
3392 "-render render vector graphics",
3393 "-repage geometry size and location of an image canvas",
3394 "-resample geometry change the resolution of an image",
3395 "-resize geometry resize the image",
3396 "-roll geometry roll an image vertically or horizontally",
3397 "-rotate degrees apply Paeth rotation to the image",
3398 "-sample geometry scale image with pixel sampling",
3399 "-scale geometry scale the image",
3400 "-segment values segment an image",
3401 "-selective-blur geometry",
3402 " selectively blur pixels within a contrast threshold",
3403 "-sepia-tone threshold",
3404 " simulate a sepia-toned photo",
3405 "-set property value set an image property",
3406 "-shade degrees shade the image using a distant light source",
3407 "-shadow geometry simulate an image shadow",
3408 "-sharpen geometry sharpen the image",
3409 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003410 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003411 "-sigmoidal-contrast geometry",
3412 " increase the contrast without saturating highlights or shadows",
3413 "-sketch geometry simulate a pencil sketch",
3414 "-solarize threshold negate all pixels above the threshold level",
3415 "-sparse-color method args",
3416 " fill in a image based on a few color points",
3417 "-splice geometry splice the background color into the image",
3418 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003419 "-statistic type radius",
3420 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003421 "-strip strip image of all profiles and comments",
3422 "-swirl degrees swirl image pixels about the center",
3423 "-threshold value threshold the image",
3424 "-thumbnail geometry create a thumbnail of the image",
3425 "-tile filename tile image when filling a graphic primitive",
3426 "-tint value tint the image with the fill color",
3427 "-transform affine transform image",
3428 "-transparent color make this color transparent within the image",
3429 "-transpose flip image vertically and rotate 90 degrees",
3430 "-transverse flop image horizontally and rotate 270 degrees",
3431 "-trim trim image edges",
3432 "-type type image type",
3433 "-unique-colors discard all but one of any pixel color",
3434 "-unsharp geometry sharpen the image",
3435 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003436 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003437 "-white-threshold value",
3438 " force all pixels above the threshold into white",
3439 (char *) NULL
3440 },
3441 *sequence_operators[]=
3442 {
cristy4285d782011-02-09 20:12:28 +00003443 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003444 "-clut apply a color lookup table to the image",
3445 "-coalesce merge a sequence of images",
3446 "-combine combine a sequence of images",
3447 "-composite composite image",
3448 "-crop geometry cut out a rectangular region of the image",
3449 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003450 "-evaluate-sequence operator",
3451 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003452 "-flatten flatten a sequence of images",
3453 "-fx expression apply mathematical expression to an image channel(s)",
3454 "-hald-clut apply a Hald color lookup table to the image",
3455 "-morph value morph an image sequence",
3456 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003457 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003458 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003459 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003460 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003461 "-write filename write images to this file",
3462 (char *) NULL
3463 },
3464 *settings[]=
3465 {
3466 "-adjoin join images into a single multi-image file",
3467 "-affine matrix affine transform matrix",
3468 "-alpha option activate, deactivate, reset, or set the alpha channel",
3469 "-antialias remove pixel-aliasing",
3470 "-authenticate password",
3471 " decipher image with this password",
3472 "-attenuate value lessen (or intensify) when adding noise to an image",
3473 "-background color background color",
3474 "-bias value add bias when convolving an image",
3475 "-black-point-compensation",
3476 " use black point compensation",
3477 "-blue-primary point chromaticity blue primary point",
3478 "-bordercolor color border color",
3479 "-caption string assign a caption to an image",
3480 "-channel type apply option to select image channels",
3481 "-colors value preferred number of colors in the image",
3482 "-colorspace type alternate image colorspace",
3483 "-comment string annotate image with comment",
3484 "-compose operator set image composite operator",
3485 "-compress type type of pixel compression when writing the image",
anthonyfd706f92012-01-19 04:22:02 +00003486 "-define format:option=value",
cristy3ed852e2009-09-05 21:47:34 +00003487 " define one or more image format options",
3488 "-delay value display the next image after pausing",
3489 "-density geometry horizontal and vertical density of the image",
3490 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003491 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003492 "-display server get image or font from this X server",
3493 "-dispose method layer disposal method",
3494 "-dither method apply error diffusion to image",
3495 "-encoding type text encoding type",
3496 "-endian type endianness (MSB or LSB) of the image",
3497 "-family name render text with this font family",
3498 "-fill color color to use when filling a graphic primitive",
3499 "-filter type use this filter when resizing an image",
3500 "-font name render text with this font",
anthonyfd706f92012-01-19 04:22:02 +00003501 "-format \"string\" output formatted image characteristics",
cristy3ed852e2009-09-05 21:47:34 +00003502 "-fuzz distance colors within this distance are considered equal",
3503 "-gravity type horizontal and vertical text placement",
3504 "-green-primary point chromaticity green primary point",
3505 "-intent type type of rendering intent when managing the image color",
3506 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003507 "-interline-spacing value",
3508 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003509 "-interpolate method pixel color interpolation method",
3510 "-interword-spacing value",
3511 " set the space between two words",
3512 "-kerning value set the space between two letters",
3513 "-label string assign a label to an image",
3514 "-limit type value pixel cache resource limit",
3515 "-loop iterations add Netscape loop extension to your GIF animation",
3516 "-mask filename associate a mask with the image",
3517 "-mattecolor color frame color",
3518 "-monitor monitor progress",
3519 "-orient type image orientation",
3520 "-page geometry size and location of an image canvas (setting)",
3521 "-ping efficiently determine image attributes",
3522 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003523 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003524 "-preview type image preview type",
3525 "-quality value JPEG/MIFF/PNG compression level",
3526 "-quiet suppress all warning messages",
3527 "-red-primary point chromaticity red primary point",
3528 "-regard-warnings pay attention to warning messages",
3529 "-remap filename transform image colors to match this set of colors",
3530 "-respect-parentheses settings remain in effect until parenthesis boundary",
3531 "-sampling-factor geometry",
3532 " horizontal and vertical sampling factor",
3533 "-scene value image scene number",
3534 "-seed value seed a new sequence of pseudo-random numbers",
3535 "-size geometry width and height of image",
3536 "-stretch type render text with this font stretch",
3537 "-stroke color graphic primitive stroke color",
3538 "-strokewidth value graphic primitive stroke width",
3539 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003540 "-synchronize synchronize image to storage device",
3541 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003542 "-texture filename name of texture to tile onto the image background",
3543 "-tile-offset geometry",
3544 " tile offset",
3545 "-treedepth value color tree depth",
3546 "-transparent-color color",
3547 " transparent color",
3548 "-undercolor color annotation bounding box color",
3549 "-units type the units of image resolution",
3550 "-verbose print detailed information about the image",
3551 "-view FlashPix viewing transforms",
3552 "-virtual-pixel method",
3553 " virtual pixel access method",
3554 "-weight type render text with this font weight",
3555 "-white-point point chromaticity white point",
3556 (char *) NULL
3557 },
3558 *stack_operators[]=
3559 {
anthonyb69c4b32011-03-23 04:37:44 +00003560 "-delete indexes delete the image from the image sequence",
3561 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003562 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003563 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003564 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003565 "-swap indexes swap two images in the image sequence",
3566 (char *) NULL
3567 };
3568
3569 const char
3570 **p;
3571
cristybb503372010-05-27 20:51:26 +00003572 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003573 (void) printf("Copyright: %s\n",GetMagickCopyright());
3574 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003575 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3576 GetClientName());
3577 (void) printf("\nImage Settings:\n");
3578 for (p=settings; *p != (char *) NULL; p++)
3579 (void) printf(" %s\n",*p);
3580 (void) printf("\nImage Operators:\n");
3581 for (p=operators; *p != (char *) NULL; p++)
3582 (void) printf(" %s\n",*p);
cristy87c02f42012-02-24 00:19:10 +00003583 (void) printf("\nImage Channel Operators:\n");
3584 for (p=channel_operators; *p != (char *) NULL; p++)
3585 (void) printf(" %s\n",*p);
cristy3ed852e2009-09-05 21:47:34 +00003586 (void) printf("\nImage Sequence Operators:\n");
3587 for (p=sequence_operators; *p != (char *) NULL; p++)
3588 (void) printf(" %s\n",*p);
3589 (void) printf("\nImage Stack Operators:\n");
3590 for (p=stack_operators; *p != (char *) NULL; p++)
3591 (void) printf(" %s\n",*p);
3592 (void) printf("\nMiscellaneous Options:\n");
3593 for (p=miscellaneous; *p != (char *) NULL; p++)
3594 (void) printf(" %s\n",*p);
3595 (void) printf(
anthonyfd706f92012-01-19 04:22:02 +00003596 "\nBy default, the image format of 'file' is determined by its magic\n");
cristy3ed852e2009-09-05 21:47:34 +00003597 (void) printf(
3598 "number. To specify a particular image format, precede the filename\n");
3599 (void) printf(
3600 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3601 (void) printf(
3602 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3603 (void) printf("'-' for standard input or output.\n");
3604 return(MagickFalse);
3605}
3606
3607WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3608 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3609{
3610#define DestroyMogrify() \
3611{ \
3612 if (format != (char *) NULL) \
3613 format=DestroyString(format); \
3614 if (path != (char *) NULL) \
3615 path=DestroyString(path); \
3616 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003617 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003618 argv[i]=DestroyString(argv[i]); \
3619 argv=(char **) RelinquishMagickMemory(argv); \
3620}
3621#define ThrowMogrifyException(asperity,tag,option) \
3622{ \
3623 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3624 option); \
3625 DestroyMogrify(); \
3626 return(MagickFalse); \
3627}
3628#define ThrowMogrifyInvalidArgumentException(option,argument) \
3629{ \
3630 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3631 "InvalidArgument","`%s': %s",argument,option); \
3632 DestroyMogrify(); \
3633 return(MagickFalse); \
3634}
3635
3636 char
3637 *format,
3638 *option,
3639 *path;
3640
3641 Image
3642 *image;
3643
3644 ImageStack
3645 image_stack[MaxImageStackDepth+1];
3646
cristy3ed852e2009-09-05 21:47:34 +00003647 MagickBooleanType
3648 global_colormap;
3649
3650 MagickBooleanType
3651 fire,
cristyebbcfea2011-02-25 02:43:54 +00003652 pend,
3653 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003654
3655 MagickStatusType
3656 status;
3657
cristyebbcfea2011-02-25 02:43:54 +00003658 register ssize_t
3659 i;
3660
3661 ssize_t
3662 j,
3663 k;
3664
cristy3ed852e2009-09-05 21:47:34 +00003665 /*
3666 Set defaults.
3667 */
3668 assert(image_info != (ImageInfo *) NULL);
3669 assert(image_info->signature == MagickSignature);
3670 if (image_info->debug != MagickFalse)
3671 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3672 assert(exception != (ExceptionInfo *) NULL);
3673 if (argc == 2)
3674 {
3675 option=argv[1];
3676 if ((LocaleCompare("version",option+1) == 0) ||
3677 (LocaleCompare("-version",option+1) == 0))
3678 {
cristyb51dff52011-05-19 16:55:47 +00003679 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003680 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003681 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3682 GetMagickCopyright());
3683 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3684 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003685 return(MagickFalse);
3686 }
3687 }
3688 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003689 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003690 format=(char *) NULL;
3691 path=(char *) NULL;
3692 global_colormap=MagickFalse;
3693 k=0;
3694 j=1;
3695 NewImageStack();
3696 option=(char *) NULL;
3697 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003698 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003699 status=MagickTrue;
3700 /*
3701 Parse command line.
3702 */
3703 ReadCommandlLine(argc,&argv);
3704 status=ExpandFilenames(&argc,&argv);
3705 if (status == MagickFalse)
3706 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3707 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003708 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003709 {
3710 option=argv[i];
3711 if (LocaleCompare(option,"(") == 0)
3712 {
3713 FireImageStack(MagickFalse,MagickTrue,pend);
3714 if (k == MaxImageStackDepth)
3715 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3716 option);
3717 PushImageStack();
3718 continue;
3719 }
3720 if (LocaleCompare(option,")") == 0)
3721 {
3722 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3723 if (k == 0)
3724 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3725 PopImageStack();
3726 continue;
3727 }
cristy042ee782011-04-22 18:48:30 +00003728 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003729 {
3730 char
3731 backup_filename[MaxTextExtent],
3732 *filename;
3733
3734 Image
3735 *images;
3736
3737 /*
3738 Option is a file name: begin by reading image from specified file.
3739 */
3740 FireImageStack(MagickFalse,MagickFalse,pend);
3741 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003742 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003743 filename=argv[++i];
cristy1b58f252012-03-01 01:41:41 +00003744 images=ReadImages(image_info,filename,exception);
cristy3ed852e2009-09-05 21:47:34 +00003745 status&=(images != (Image *) NULL) &&
3746 (exception->severity < ErrorException);
3747 if (images == (Image *) NULL)
3748 continue;
cristydaa76602010-06-30 13:05:11 +00003749 if (format != (char *) NULL)
3750 (void) CopyMagickString(images->filename,images->magick_filename,
3751 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003752 if (path != (char *) NULL)
3753 {
3754 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003755 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003756 path,*DirectorySeparator,filename);
3757 }
3758 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003759 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003760 AppendImageStack(images);
3761 FinalizeImageSettings(image_info,image,MagickFalse);
3762 if (global_colormap != MagickFalse)
3763 {
3764 QuantizeInfo
3765 *quantize_info;
3766
3767 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003768 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003769 quantize_info=DestroyQuantizeInfo(quantize_info);
3770 }
3771 *backup_filename='\0';
3772 if ((LocaleCompare(image->filename,"-") != 0) &&
3773 (IsPathWritable(image->filename) != MagickFalse))
3774 {
cristybb503372010-05-27 20:51:26 +00003775 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003776 i;
3777
3778 /*
3779 Rename image file as backup.
3780 */
3781 (void) CopyMagickString(backup_filename,image->filename,
3782 MaxTextExtent);
3783 for (i=0; i < 6; i++)
3784 {
3785 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3786 if (IsPathAccessible(backup_filename) == MagickFalse)
3787 break;
3788 }
3789 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003790 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003791 *backup_filename='\0';
3792 }
3793 /*
3794 Write transmogrified image to disk.
3795 */
3796 image_info->synchronize=MagickTrue;
3797 status&=WriteImages(image_info,image,image->filename,exception);
3798 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003799 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003800 RemoveAllImageStack();
3801 continue;
3802 }
3803 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3804 switch (*(option+1))
3805 {
3806 case 'a':
3807 {
3808 if (LocaleCompare("adaptive-blur",option+1) == 0)
3809 {
3810 i++;
cristybb503372010-05-27 20:51:26 +00003811 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003812 ThrowMogrifyException(OptionError,"MissingArgument",option);
3813 if (IsGeometry(argv[i]) == MagickFalse)
3814 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3815 break;
3816 }
3817 if (LocaleCompare("adaptive-resize",option+1) == 0)
3818 {
3819 i++;
cristybb503372010-05-27 20:51:26 +00003820 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003821 ThrowMogrifyException(OptionError,"MissingArgument",option);
3822 if (IsGeometry(argv[i]) == MagickFalse)
3823 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3824 break;
3825 }
3826 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3827 {
3828 i++;
cristybb503372010-05-27 20:51:26 +00003829 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003830 ThrowMogrifyException(OptionError,"MissingArgument",option);
3831 if (IsGeometry(argv[i]) == MagickFalse)
3832 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3833 break;
3834 }
3835 if (LocaleCompare("affine",option+1) == 0)
3836 {
3837 if (*option == '+')
3838 break;
3839 i++;
cristybb503372010-05-27 20:51:26 +00003840 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003841 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003842 break;
3843 }
3844 if (LocaleCompare("alpha",option+1) == 0)
3845 {
cristybb503372010-05-27 20:51:26 +00003846 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003847 type;
3848
3849 if (*option == '+')
3850 break;
3851 i++;
cristybb503372010-05-27 20:51:26 +00003852 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003853 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003854 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003855 if (type < 0)
3856 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3857 argv[i]);
3858 break;
3859 }
3860 if (LocaleCompare("annotate",option+1) == 0)
3861 {
3862 if (*option == '+')
3863 break;
3864 i++;
cristybb503372010-05-27 20:51:26 +00003865 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003866 ThrowMogrifyException(OptionError,"MissingArgument",option);
3867 if (IsGeometry(argv[i]) == MagickFalse)
3868 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003870 ThrowMogrifyException(OptionError,"MissingArgument",option);
3871 i++;
3872 break;
3873 }
3874 if (LocaleCompare("antialias",option+1) == 0)
3875 break;
3876 if (LocaleCompare("append",option+1) == 0)
3877 break;
3878 if (LocaleCompare("attenuate",option+1) == 0)
3879 {
3880 if (*option == '+')
3881 break;
3882 i++;
cristybb503372010-05-27 20:51:26 +00003883 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003884 ThrowMogrifyException(OptionError,"MissingArgument",option);
3885 if (IsGeometry(argv[i]) == MagickFalse)
3886 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3887 break;
3888 }
3889 if (LocaleCompare("authenticate",option+1) == 0)
3890 {
3891 if (*option == '+')
3892 break;
3893 i++;
cristybb503372010-05-27 20:51:26 +00003894 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003895 ThrowMogrifyException(OptionError,"MissingArgument",option);
3896 break;
3897 }
3898 if (LocaleCompare("auto-gamma",option+1) == 0)
3899 break;
3900 if (LocaleCompare("auto-level",option+1) == 0)
3901 break;
3902 if (LocaleCompare("auto-orient",option+1) == 0)
3903 break;
3904 if (LocaleCompare("average",option+1) == 0)
3905 break;
3906 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3907 }
3908 case 'b':
3909 {
3910 if (LocaleCompare("background",option+1) == 0)
3911 {
3912 if (*option == '+')
3913 break;
3914 i++;
cristybb503372010-05-27 20:51:26 +00003915 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003916 ThrowMogrifyException(OptionError,"MissingArgument",option);
3917 break;
3918 }
3919 if (LocaleCompare("bias",option+1) == 0)
3920 {
3921 if (*option == '+')
3922 break;
3923 i++;
cristybb503372010-05-27 20:51:26 +00003924 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003925 ThrowMogrifyException(OptionError,"MissingArgument",option);
3926 if (IsGeometry(argv[i]) == MagickFalse)
3927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3928 break;
3929 }
3930 if (LocaleCompare("black-point-compensation",option+1) == 0)
3931 break;
3932 if (LocaleCompare("black-threshold",option+1) == 0)
3933 {
3934 if (*option == '+')
3935 break;
3936 i++;
cristybb503372010-05-27 20:51:26 +00003937 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003938 ThrowMogrifyException(OptionError,"MissingArgument",option);
3939 if (IsGeometry(argv[i]) == MagickFalse)
3940 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3941 break;
3942 }
3943 if (LocaleCompare("blue-primary",option+1) == 0)
3944 {
3945 if (*option == '+')
3946 break;
3947 i++;
cristybb503372010-05-27 20:51:26 +00003948 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003949 ThrowMogrifyException(OptionError,"MissingArgument",option);
3950 if (IsGeometry(argv[i]) == MagickFalse)
3951 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3952 break;
3953 }
3954 if (LocaleCompare("blue-shift",option+1) == 0)
3955 {
3956 i++;
cristybb503372010-05-27 20:51:26 +00003957 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003958 ThrowMogrifyException(OptionError,"MissingArgument",option);
3959 if (IsGeometry(argv[i]) == MagickFalse)
3960 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3961 break;
3962 }
3963 if (LocaleCompare("blur",option+1) == 0)
3964 {
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 if (IsGeometry(argv[i]) == MagickFalse)
3969 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3970 break;
3971 }
3972 if (LocaleCompare("border",option+1) == 0)
3973 {
3974 if (*option == '+')
3975 break;
3976 i++;
cristybb503372010-05-27 20:51:26 +00003977 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003978 ThrowMogrifyException(OptionError,"MissingArgument",option);
3979 if (IsGeometry(argv[i]) == MagickFalse)
3980 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3981 break;
3982 }
3983 if (LocaleCompare("bordercolor",option+1) == 0)
3984 {
3985 if (*option == '+')
3986 break;
3987 i++;
cristybb503372010-05-27 20:51:26 +00003988 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003989 ThrowMogrifyException(OptionError,"MissingArgument",option);
3990 break;
3991 }
3992 if (LocaleCompare("box",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 break;
4000 }
cristya28d6b82010-01-11 20:03:47 +00004001 if (LocaleCompare("brightness-contrast",option+1) == 0)
4002 {
4003 i++;
cristybb503372010-05-27 20:51:26 +00004004 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004005 ThrowMogrifyException(OptionError,"MissingArgument",option);
4006 if (IsGeometry(argv[i]) == MagickFalse)
4007 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4008 break;
4009 }
cristy3ed852e2009-09-05 21:47:34 +00004010 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4011 }
4012 case 'c':
4013 {
4014 if (LocaleCompare("cache",option+1) == 0)
4015 {
4016 if (*option == '+')
4017 break;
4018 i++;
cristybb503372010-05-27 20:51:26 +00004019 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004020 ThrowMogrifyException(OptionError,"MissingArgument",option);
4021 if (IsGeometry(argv[i]) == MagickFalse)
4022 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4023 break;
4024 }
4025 if (LocaleCompare("caption",option+1) == 0)
4026 {
4027 if (*option == '+')
4028 break;
4029 i++;
cristybb503372010-05-27 20:51:26 +00004030 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004031 ThrowMogrifyException(OptionError,"MissingArgument",option);
4032 break;
4033 }
4034 if (LocaleCompare("channel",option+1) == 0)
4035 {
cristybb503372010-05-27 20:51:26 +00004036 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004037 channel;
4038
4039 if (*option == '+')
4040 break;
4041 i++;
cristybb503372010-05-27 20:51:26 +00004042 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004043 ThrowMogrifyException(OptionError,"MissingArgument",option);
4044 channel=ParseChannelOption(argv[i]);
4045 if (channel < 0)
4046 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4047 argv[i]);
4048 break;
4049 }
cristy87c02f42012-02-24 00:19:10 +00004050 if (LocaleCompare("channel-extract",option+1) == 0)
4051 {
4052 ssize_t
4053 channel;
4054
4055 if (*option == '+')
4056 break;
4057 i++;
4058 if (i == (ssize_t) (argc-1))
4059 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy953c4bd2012-02-24 01:04:04 +00004060 channel=ParsePixelChannelOption(argv[i]);
cristy87c02f42012-02-24 00:19:10 +00004061 if (channel < 0)
4062 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4063 argv[i]);
4064 break;
4065 }
4066 if (LocaleCompare("channel-inject",option+1) == 0)
4067 {
4068 ssize_t
4069 channel;
4070
4071 if (*option == '+')
4072 break;
4073 i++;
4074 if (i == (ssize_t) (argc-1))
4075 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy953c4bd2012-02-24 01:04:04 +00004076 channel=ParsePixelChannelOption(argv[i]);
cristy87c02f42012-02-24 00:19:10 +00004077 if (channel < 0)
4078 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4079 argv[i]);
4080 break;
4081 }
4082 if (LocaleCompare("channel-swap",option+1) == 0)
4083 {
4084 ssize_t
4085 channel;
4086
4087 if (*option == '+')
4088 break;
4089 i++;
4090 if (i == (ssize_t) (argc-1))
4091 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy953c4bd2012-02-24 01:04:04 +00004092 channel=ParsePixelChannelOption(argv[i]);
cristy87c02f42012-02-24 00:19:10 +00004093 if (channel < 0)
4094 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4095 argv[i]);
4096 break;
4097 }
cristy3ed852e2009-09-05 21:47:34 +00004098 if (LocaleCompare("cdl",option+1) == 0)
4099 {
4100 if (*option == '+')
4101 break;
4102 i++;
cristybb503372010-05-27 20:51:26 +00004103 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004104 ThrowMogrifyException(OptionError,"MissingArgument",option);
4105 break;
4106 }
4107 if (LocaleCompare("charcoal",option+1) == 0)
4108 {
4109 if (*option == '+')
4110 break;
4111 i++;
cristybb503372010-05-27 20:51:26 +00004112 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004113 ThrowMogrifyException(OptionError,"MissingArgument",option);
4114 if (IsGeometry(argv[i]) == MagickFalse)
4115 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4116 break;
4117 }
4118 if (LocaleCompare("chop",option+1) == 0)
4119 {
4120 if (*option == '+')
4121 break;
4122 i++;
cristybb503372010-05-27 20:51:26 +00004123 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004124 ThrowMogrifyException(OptionError,"MissingArgument",option);
4125 if (IsGeometry(argv[i]) == MagickFalse)
4126 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4127 break;
4128 }
cristy1eb45dd2009-09-25 16:38:06 +00004129 if (LocaleCompare("clamp",option+1) == 0)
4130 break;
4131 if (LocaleCompare("clip",option+1) == 0)
4132 break;
cristy3ed852e2009-09-05 21:47:34 +00004133 if (LocaleCompare("clip-mask",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("clut",option+1) == 0)
4143 break;
4144 if (LocaleCompare("coalesce",option+1) == 0)
4145 break;
4146 if (LocaleCompare("colorize",option+1) == 0)
4147 {
4148 if (*option == '+')
4149 break;
4150 i++;
cristybb503372010-05-27 20:51:26 +00004151 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004152 ThrowMogrifyException(OptionError,"MissingArgument",option);
4153 if (IsGeometry(argv[i]) == MagickFalse)
4154 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4155 break;
4156 }
cristye6365592010-04-02 17:31:23 +00004157 if (LocaleCompare("color-matrix",option+1) == 0)
4158 {
cristyb6bd4ad2010-08-08 01:12:27 +00004159 KernelInfo
4160 *kernel_info;
4161
cristye6365592010-04-02 17:31:23 +00004162 if (*option == '+')
4163 break;
4164 i++;
cristybb503372010-05-27 20:51:26 +00004165 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004166 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004167 kernel_info=AcquireKernelInfo(argv[i]);
4168 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004169 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004170 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004171 break;
4172 }
cristy3ed852e2009-09-05 21:47:34 +00004173 if (LocaleCompare("colors",option+1) == 0)
4174 {
4175 if (*option == '+')
4176 break;
4177 i++;
cristybb503372010-05-27 20:51:26 +00004178 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004179 ThrowMogrifyException(OptionError,"MissingArgument",option);
4180 if (IsGeometry(argv[i]) == MagickFalse)
4181 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4182 break;
4183 }
4184 if (LocaleCompare("colorspace",option+1) == 0)
4185 {
cristybb503372010-05-27 20:51:26 +00004186 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004187 colorspace;
4188
4189 if (*option == '+')
4190 break;
4191 i++;
cristybb503372010-05-27 20:51:26 +00004192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004193 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004194 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004195 argv[i]);
4196 if (colorspace < 0)
4197 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4198 argv[i]);
4199 break;
4200 }
4201 if (LocaleCompare("combine",option+1) == 0)
4202 break;
4203 if (LocaleCompare("comment",option+1) == 0)
4204 {
4205 if (*option == '+')
4206 break;
4207 i++;
cristybb503372010-05-27 20:51:26 +00004208 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004209 ThrowMogrifyException(OptionError,"MissingArgument",option);
4210 break;
4211 }
4212 if (LocaleCompare("composite",option+1) == 0)
4213 break;
4214 if (LocaleCompare("compress",option+1) == 0)
4215 {
cristybb503372010-05-27 20:51:26 +00004216 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004217 compress;
4218
4219 if (*option == '+')
4220 break;
4221 i++;
cristybb503372010-05-27 20:51:26 +00004222 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004223 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004224 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004225 argv[i]);
4226 if (compress < 0)
4227 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4228 argv[i]);
4229 break;
4230 }
cristy22879752009-10-25 23:55:40 +00004231 if (LocaleCompare("concurrent",option+1) == 0)
4232 break;
cristy3ed852e2009-09-05 21:47:34 +00004233 if (LocaleCompare("contrast",option+1) == 0)
4234 break;
4235 if (LocaleCompare("contrast-stretch",option+1) == 0)
4236 {
4237 i++;
cristybb503372010-05-27 20:51:26 +00004238 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004239 ThrowMogrifyException(OptionError,"MissingArgument",option);
4240 if (IsGeometry(argv[i]) == MagickFalse)
4241 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4242 break;
4243 }
4244 if (LocaleCompare("convolve",option+1) == 0)
4245 {
cristyb6bd4ad2010-08-08 01:12:27 +00004246 KernelInfo
4247 *kernel_info;
4248
cristy3ed852e2009-09-05 21:47:34 +00004249 if (*option == '+')
4250 break;
4251 i++;
cristybb503372010-05-27 20:51:26 +00004252 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004253 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004254 kernel_info=AcquireKernelInfo(argv[i]);
4255 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004256 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004257 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004258 break;
4259 }
4260 if (LocaleCompare("crop",option+1) == 0)
4261 {
4262 if (*option == '+')
4263 break;
4264 i++;
cristybb503372010-05-27 20:51:26 +00004265 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004266 ThrowMogrifyException(OptionError,"MissingArgument",option);
4267 if (IsGeometry(argv[i]) == MagickFalse)
4268 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4269 break;
4270 }
4271 if (LocaleCompare("cycle",option+1) == 0)
4272 {
4273 if (*option == '+')
4274 break;
4275 i++;
cristybb503372010-05-27 20:51:26 +00004276 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004277 ThrowMogrifyException(OptionError,"MissingArgument",option);
4278 if (IsGeometry(argv[i]) == MagickFalse)
4279 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4280 break;
4281 }
4282 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4283 }
4284 case 'd':
4285 {
4286 if (LocaleCompare("decipher",option+1) == 0)
4287 {
4288 if (*option == '+')
4289 break;
4290 i++;
cristybb503372010-05-27 20:51:26 +00004291 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004292 ThrowMogrifyException(OptionError,"MissingArgument",option);
4293 break;
4294 }
4295 if (LocaleCompare("deconstruct",option+1) == 0)
4296 break;
4297 if (LocaleCompare("debug",option+1) == 0)
4298 {
cristybb503372010-05-27 20:51:26 +00004299 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004300 event;
4301
4302 if (*option == '+')
4303 break;
4304 i++;
cristybb503372010-05-27 20:51:26 +00004305 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004306 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004307 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004308 if (event < 0)
4309 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4310 argv[i]);
4311 (void) SetLogEventMask(argv[i]);
4312 break;
4313 }
4314 if (LocaleCompare("define",option+1) == 0)
4315 {
4316 i++;
cristybb503372010-05-27 20:51:26 +00004317 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004318 ThrowMogrifyException(OptionError,"MissingArgument",option);
4319 if (*option == '+')
4320 {
4321 const char
4322 *define;
4323
4324 define=GetImageOption(image_info,argv[i]);
4325 if (define == (const char *) NULL)
4326 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4327 break;
4328 }
4329 break;
4330 }
4331 if (LocaleCompare("delay",option+1) == 0)
4332 {
4333 if (*option == '+')
4334 break;
4335 i++;
cristybb503372010-05-27 20:51:26 +00004336 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004337 ThrowMogrifyException(OptionError,"MissingArgument",option);
4338 if (IsGeometry(argv[i]) == MagickFalse)
4339 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4340 break;
4341 }
cristyecb10ff2011-03-22 13:14:03 +00004342 if (LocaleCompare("delete",option+1) == 0)
4343 {
4344 if (*option == '+')
4345 break;
4346 i++;
4347 if (i == (ssize_t) (argc-1))
4348 ThrowMogrifyException(OptionError,"MissingArgument",option);
4349 if (IsGeometry(argv[i]) == MagickFalse)
4350 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4351 break;
4352 }
cristy3ed852e2009-09-05 21:47:34 +00004353 if (LocaleCompare("density",option+1) == 0)
4354 {
4355 if (*option == '+')
4356 break;
4357 i++;
cristybb503372010-05-27 20:51:26 +00004358 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004359 ThrowMogrifyException(OptionError,"MissingArgument",option);
4360 if (IsGeometry(argv[i]) == MagickFalse)
4361 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4362 break;
4363 }
4364 if (LocaleCompare("depth",option+1) == 0)
4365 {
4366 if (*option == '+')
4367 break;
4368 i++;
cristybb503372010-05-27 20:51:26 +00004369 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004370 ThrowMogrifyException(OptionError,"MissingArgument",option);
4371 if (IsGeometry(argv[i]) == MagickFalse)
4372 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4373 break;
4374 }
4375 if (LocaleCompare("deskew",option+1) == 0)
4376 {
4377 if (*option == '+')
4378 break;
4379 i++;
cristybb503372010-05-27 20:51:26 +00004380 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004381 ThrowMogrifyException(OptionError,"MissingArgument",option);
4382 if (IsGeometry(argv[i]) == MagickFalse)
4383 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4384 break;
4385 }
4386 if (LocaleCompare("despeckle",option+1) == 0)
4387 break;
4388 if (LocaleCompare("dft",option+1) == 0)
4389 break;
cristyc9b12952010-03-28 01:12:28 +00004390 if (LocaleCompare("direction",option+1) == 0)
4391 {
cristybb503372010-05-27 20:51:26 +00004392 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004393 direction;
4394
4395 if (*option == '+')
4396 break;
4397 i++;
cristybb503372010-05-27 20:51:26 +00004398 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004399 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004400 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004401 argv[i]);
4402 if (direction < 0)
4403 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4404 argv[i]);
4405 break;
4406 }
cristy3ed852e2009-09-05 21:47:34 +00004407 if (LocaleCompare("display",option+1) == 0)
4408 {
4409 if (*option == '+')
4410 break;
4411 i++;
cristybb503372010-05-27 20:51:26 +00004412 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004413 ThrowMogrifyException(OptionError,"MissingArgument",option);
4414 break;
4415 }
4416 if (LocaleCompare("dispose",option+1) == 0)
4417 {
cristybb503372010-05-27 20:51:26 +00004418 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004419 dispose;
4420
4421 if (*option == '+')
4422 break;
4423 i++;
cristybb503372010-05-27 20:51:26 +00004424 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004425 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004426 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004427 if (dispose < 0)
4428 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4429 argv[i]);
4430 break;
4431 }
4432 if (LocaleCompare("distort",option+1) == 0)
4433 {
cristybb503372010-05-27 20:51:26 +00004434 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004435 op;
4436
4437 i++;
cristybb503372010-05-27 20:51:26 +00004438 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004439 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004440 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004441 if (op < 0)
4442 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4443 argv[i]);
4444 i++;
cristybb503372010-05-27 20:51:26 +00004445 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004446 ThrowMogrifyException(OptionError,"MissingArgument",option);
4447 break;
4448 }
4449 if (LocaleCompare("dither",option+1) == 0)
4450 {
cristybb503372010-05-27 20:51:26 +00004451 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004452 method;
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);
cristy042ee782011-04-22 18:48:30 +00004459 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004460 if (method < 0)
4461 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4462 argv[i]);
4463 break;
4464 }
4465 if (LocaleCompare("draw",option+1) == 0)
4466 {
4467 if (*option == '+')
4468 break;
4469 i++;
cristybb503372010-05-27 20:51:26 +00004470 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004471 ThrowMogrifyException(OptionError,"MissingArgument",option);
4472 break;
4473 }
cristyecb10ff2011-03-22 13:14:03 +00004474 if (LocaleCompare("duplicate",option+1) == 0)
4475 {
4476 if (*option == '+')
4477 break;
4478 i++;
4479 if (i == (ssize_t) (argc-1))
4480 ThrowMogrifyException(OptionError,"MissingArgument",option);
4481 if (IsGeometry(argv[i]) == MagickFalse)
4482 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4483 break;
4484 }
cristy22879752009-10-25 23:55:40 +00004485 if (LocaleCompare("duration",option+1) == 0)
4486 {
4487 if (*option == '+')
4488 break;
4489 i++;
cristybb503372010-05-27 20:51:26 +00004490 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004491 ThrowMogrifyException(OptionError,"MissingArgument",option);
4492 if (IsGeometry(argv[i]) == MagickFalse)
4493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4494 break;
4495 }
cristy3ed852e2009-09-05 21:47:34 +00004496 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4497 }
4498 case 'e':
4499 {
4500 if (LocaleCompare("edge",option+1) == 0)
4501 {
4502 if (*option == '+')
4503 break;
4504 i++;
cristybb503372010-05-27 20:51:26 +00004505 if (i == (ssize_t) argc)
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 }
4511 if (LocaleCompare("emboss",option+1) == 0)
4512 {
4513 if (*option == '+')
4514 break;
4515 i++;
cristybb503372010-05-27 20:51:26 +00004516 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004517 ThrowMogrifyException(OptionError,"MissingArgument",option);
4518 if (IsGeometry(argv[i]) == MagickFalse)
4519 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4520 break;
4521 }
4522 if (LocaleCompare("encipher",option+1) == 0)
4523 {
4524 if (*option == '+')
4525 break;
4526 i++;
cristybb503372010-05-27 20:51:26 +00004527 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004528 ThrowMogrifyException(OptionError,"MissingArgument",option);
4529 break;
4530 }
4531 if (LocaleCompare("encoding",option+1) == 0)
4532 {
4533 if (*option == '+')
4534 break;
4535 i++;
cristybb503372010-05-27 20:51:26 +00004536 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004537 ThrowMogrifyException(OptionError,"MissingArgument",option);
4538 break;
4539 }
4540 if (LocaleCompare("endian",option+1) == 0)
4541 {
cristybb503372010-05-27 20:51:26 +00004542 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004543 endian;
4544
4545 if (*option == '+')
4546 break;
4547 i++;
cristybb503372010-05-27 20:51:26 +00004548 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004549 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004550 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004551 if (endian < 0)
4552 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4553 argv[i]);
4554 break;
4555 }
4556 if (LocaleCompare("enhance",option+1) == 0)
4557 break;
4558 if (LocaleCompare("equalize",option+1) == 0)
4559 break;
4560 if (LocaleCompare("evaluate",option+1) == 0)
4561 {
cristybb503372010-05-27 20:51:26 +00004562 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004563 op;
4564
4565 if (*option == '+')
4566 break;
4567 i++;
cristybb503372010-05-27 20:51:26 +00004568 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004569 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004570 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004571 if (op < 0)
4572 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4573 argv[i]);
4574 i++;
cristybb503372010-05-27 20:51:26 +00004575 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004576 ThrowMogrifyException(OptionError,"MissingArgument",option);
4577 if (IsGeometry(argv[i]) == MagickFalse)
4578 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4579 break;
4580 }
cristyd18ae7c2010-03-07 17:39:52 +00004581 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4582 {
cristybb503372010-05-27 20:51:26 +00004583 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004584 op;
4585
4586 if (*option == '+')
4587 break;
4588 i++;
cristybb503372010-05-27 20:51:26 +00004589 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004590 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004591 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004592 if (op < 0)
4593 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4594 argv[i]);
4595 break;
4596 }
cristy3ed852e2009-09-05 21:47:34 +00004597 if (LocaleCompare("extent",option+1) == 0)
4598 {
4599 if (*option == '+')
4600 break;
4601 i++;
cristybb503372010-05-27 20:51:26 +00004602 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004603 ThrowMogrifyException(OptionError,"MissingArgument",option);
4604 if (IsGeometry(argv[i]) == MagickFalse)
4605 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4606 break;
4607 }
4608 if (LocaleCompare("extract",option+1) == 0)
4609 {
4610 if (*option == '+')
4611 break;
4612 i++;
cristybb503372010-05-27 20:51:26 +00004613 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004614 ThrowMogrifyException(OptionError,"MissingArgument",option);
4615 if (IsGeometry(argv[i]) == MagickFalse)
4616 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4617 break;
4618 }
4619 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4620 }
4621 case 'f':
4622 {
4623 if (LocaleCompare("family",option+1) == 0)
4624 {
4625 if (*option == '+')
4626 break;
4627 i++;
cristybb503372010-05-27 20:51:26 +00004628 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004629 ThrowMogrifyException(OptionError,"MissingArgument",option);
4630 break;
4631 }
4632 if (LocaleCompare("fill",option+1) == 0)
4633 {
4634 if (*option == '+')
4635 break;
4636 i++;
cristybb503372010-05-27 20:51:26 +00004637 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004638 ThrowMogrifyException(OptionError,"MissingArgument",option);
4639 break;
4640 }
4641 if (LocaleCompare("filter",option+1) == 0)
4642 {
cristybb503372010-05-27 20:51:26 +00004643 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004644 filter;
4645
4646 if (*option == '+')
4647 break;
4648 i++;
cristybb503372010-05-27 20:51:26 +00004649 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004650 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004651 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004652 if (filter < 0)
4653 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4654 argv[i]);
4655 break;
4656 }
4657 if (LocaleCompare("flatten",option+1) == 0)
4658 break;
4659 if (LocaleCompare("flip",option+1) == 0)
4660 break;
4661 if (LocaleCompare("flop",option+1) == 0)
4662 break;
4663 if (LocaleCompare("floodfill",option+1) == 0)
4664 {
4665 if (*option == '+')
4666 break;
4667 i++;
cristybb503372010-05-27 20:51:26 +00004668 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004669 ThrowMogrifyException(OptionError,"MissingArgument",option);
4670 if (IsGeometry(argv[i]) == MagickFalse)
4671 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4672 i++;
cristybb503372010-05-27 20:51:26 +00004673 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004674 ThrowMogrifyException(OptionError,"MissingArgument",option);
4675 break;
4676 }
4677 if (LocaleCompare("font",option+1) == 0)
4678 {
4679 if (*option == '+')
4680 break;
4681 i++;
cristybb503372010-05-27 20:51:26 +00004682 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004683 ThrowMogrifyException(OptionError,"MissingArgument",option);
4684 break;
4685 }
4686 if (LocaleCompare("format",option+1) == 0)
4687 {
4688 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4689 (void) CloneString(&format,(char *) NULL);
4690 if (*option == '+')
4691 break;
4692 i++;
cristybb503372010-05-27 20:51:26 +00004693 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004694 ThrowMogrifyException(OptionError,"MissingArgument",option);
4695 (void) CloneString(&format,argv[i]);
4696 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4697 (void) ConcatenateMagickString(image_info->filename,":",
4698 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004699 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004700 if (*image_info->magick == '\0')
4701 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4702 format);
4703 break;
4704 }
4705 if (LocaleCompare("frame",option+1) == 0)
4706 {
4707 if (*option == '+')
4708 break;
4709 i++;
cristybb503372010-05-27 20:51:26 +00004710 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004711 ThrowMogrifyException(OptionError,"MissingArgument",option);
4712 if (IsGeometry(argv[i]) == MagickFalse)
4713 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4714 break;
4715 }
4716 if (LocaleCompare("function",option+1) == 0)
4717 {
cristybb503372010-05-27 20:51:26 +00004718 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004719 op;
4720
4721 if (*option == '+')
4722 break;
4723 i++;
cristybb503372010-05-27 20:51:26 +00004724 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004725 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004726 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004727 if (op < 0)
4728 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4729 i++;
cristybb503372010-05-27 20:51:26 +00004730 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004731 ThrowMogrifyException(OptionError,"MissingArgument",option);
4732 break;
4733 }
4734 if (LocaleCompare("fuzz",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 if (LocaleCompare("fx",option+1) == 0)
4746 {
4747 if (*option == '+')
4748 break;
4749 i++;
cristybb503372010-05-27 20:51:26 +00004750 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004751 ThrowMogrifyException(OptionError,"MissingArgument",option);
4752 break;
4753 }
4754 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4755 }
4756 case 'g':
4757 {
4758 if (LocaleCompare("gamma",option+1) == 0)
4759 {
4760 i++;
cristybb503372010-05-27 20:51:26 +00004761 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004762 ThrowMogrifyException(OptionError,"MissingArgument",option);
4763 if (IsGeometry(argv[i]) == MagickFalse)
4764 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4765 break;
4766 }
4767 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4768 (LocaleCompare("gaussian",option+1) == 0))
4769 {
4770 i++;
cristybb503372010-05-27 20:51:26 +00004771 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004772 ThrowMogrifyException(OptionError,"MissingArgument",option);
4773 if (IsGeometry(argv[i]) == MagickFalse)
4774 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4775 break;
4776 }
4777 if (LocaleCompare("geometry",option+1) == 0)
4778 {
4779 if (*option == '+')
4780 break;
4781 i++;
cristybb503372010-05-27 20:51:26 +00004782 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004783 ThrowMogrifyException(OptionError,"MissingArgument",option);
4784 if (IsGeometry(argv[i]) == MagickFalse)
4785 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4786 break;
4787 }
4788 if (LocaleCompare("gravity",option+1) == 0)
4789 {
cristybb503372010-05-27 20:51:26 +00004790 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004791 gravity;
4792
4793 if (*option == '+')
4794 break;
4795 i++;
cristybb503372010-05-27 20:51:26 +00004796 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004797 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004798 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004799 if (gravity < 0)
4800 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4801 argv[i]);
4802 break;
4803 }
4804 if (LocaleCompare("green-primary",option+1) == 0)
4805 {
4806 if (*option == '+')
4807 break;
4808 i++;
cristybb503372010-05-27 20:51:26 +00004809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004810 ThrowMogrifyException(OptionError,"MissingArgument",option);
4811 if (IsGeometry(argv[i]) == MagickFalse)
4812 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4813 break;
4814 }
4815 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4816 }
4817 case 'h':
4818 {
4819 if (LocaleCompare("hald-clut",option+1) == 0)
4820 break;
4821 if ((LocaleCompare("help",option+1) == 0) ||
4822 (LocaleCompare("-help",option+1) == 0))
4823 return(MogrifyUsage());
4824 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4825 }
4826 case 'i':
4827 {
4828 if (LocaleCompare("identify",option+1) == 0)
4829 break;
4830 if (LocaleCompare("idft",option+1) == 0)
4831 break;
4832 if (LocaleCompare("implode",option+1) == 0)
4833 {
4834 if (*option == '+')
4835 break;
4836 i++;
cristybb503372010-05-27 20:51:26 +00004837 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004838 ThrowMogrifyException(OptionError,"MissingArgument",option);
4839 if (IsGeometry(argv[i]) == MagickFalse)
4840 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4841 break;
4842 }
4843 if (LocaleCompare("intent",option+1) == 0)
4844 {
cristybb503372010-05-27 20:51:26 +00004845 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004846 intent;
4847
4848 if (*option == '+')
4849 break;
4850 i++;
cristybb503372010-05-27 20:51:26 +00004851 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004852 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004853 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004854 if (intent < 0)
4855 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4856 argv[i]);
4857 break;
4858 }
4859 if (LocaleCompare("interlace",option+1) == 0)
4860 {
cristybb503372010-05-27 20:51:26 +00004861 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004862 interlace;
4863
4864 if (*option == '+')
4865 break;
4866 i++;
cristybb503372010-05-27 20:51:26 +00004867 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004868 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004869 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004870 argv[i]);
4871 if (interlace < 0)
4872 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4873 argv[i]);
4874 break;
4875 }
cristyb32b90a2009-09-07 21:45:48 +00004876 if (LocaleCompare("interline-spacing",option+1) == 0)
4877 {
4878 if (*option == '+')
4879 break;
4880 i++;
cristybb503372010-05-27 20:51:26 +00004881 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004882 ThrowMogrifyException(OptionError,"MissingArgument",option);
4883 if (IsGeometry(argv[i]) == MagickFalse)
4884 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4885 break;
4886 }
cristy3ed852e2009-09-05 21:47:34 +00004887 if (LocaleCompare("interpolate",option+1) == 0)
4888 {
cristybb503372010-05-27 20:51:26 +00004889 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004890 interpolate;
4891
4892 if (*option == '+')
4893 break;
4894 i++;
cristybb503372010-05-27 20:51:26 +00004895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004896 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004897 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004898 argv[i]);
4899 if (interpolate < 0)
4900 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4901 argv[i]);
4902 break;
4903 }
4904 if (LocaleCompare("interword-spacing",option+1) == 0)
4905 {
4906 if (*option == '+')
4907 break;
4908 i++;
cristybb503372010-05-27 20:51:26 +00004909 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004910 ThrowMogrifyException(OptionError,"MissingArgument",option);
4911 if (IsGeometry(argv[i]) == MagickFalse)
4912 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4913 break;
4914 }
4915 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4916 }
4917 case 'k':
4918 {
4919 if (LocaleCompare("kerning",option+1) == 0)
4920 {
4921 if (*option == '+')
4922 break;
4923 i++;
cristybb503372010-05-27 20:51:26 +00004924 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004925 ThrowMogrifyException(OptionError,"MissingArgument",option);
4926 if (IsGeometry(argv[i]) == MagickFalse)
4927 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4928 break;
4929 }
4930 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4931 }
4932 case 'l':
4933 {
4934 if (LocaleCompare("label",option+1) == 0)
4935 {
4936 if (*option == '+')
4937 break;
4938 i++;
cristybb503372010-05-27 20:51:26 +00004939 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004940 ThrowMogrifyException(OptionError,"MissingArgument",option);
4941 break;
4942 }
4943 if (LocaleCompare("lat",option+1) == 0)
4944 {
4945 if (*option == '+')
4946 break;
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 }
4953 if (LocaleCompare("layers",option+1) == 0)
4954 {
cristybb503372010-05-27 20:51:26 +00004955 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004956 type;
4957
4958 if (*option == '+')
4959 break;
4960 i++;
cristybb503372010-05-27 20:51:26 +00004961 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004962 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004963 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004964 if (type < 0)
4965 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4966 argv[i]);
4967 break;
4968 }
4969 if (LocaleCompare("level",option+1) == 0)
4970 {
4971 i++;
cristybb503372010-05-27 20:51:26 +00004972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004973 ThrowMogrifyException(OptionError,"MissingArgument",option);
4974 if (IsGeometry(argv[i]) == MagickFalse)
4975 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4976 break;
4977 }
4978 if (LocaleCompare("level-colors",option+1) == 0)
4979 {
4980 i++;
cristybb503372010-05-27 20:51:26 +00004981 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004982 ThrowMogrifyException(OptionError,"MissingArgument",option);
4983 break;
4984 }
cristy3ed852e2009-09-05 21:47:34 +00004985 if (LocaleCompare("limit",option+1) == 0)
4986 {
4987 char
4988 *p;
4989
4990 double
4991 value;
4992
cristybb503372010-05-27 20:51:26 +00004993 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004994 resource;
4995
4996 if (*option == '+')
4997 break;
4998 i++;
cristybb503372010-05-27 20:51:26 +00004999 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005000 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005001 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005002 argv[i]);
5003 if (resource < 0)
5004 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5005 argv[i]);
5006 i++;
cristybb503372010-05-27 20:51:26 +00005007 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005008 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00005009 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00005010 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00005011 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5012 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5013 break;
5014 }
5015 if (LocaleCompare("liquid-rescale",option+1) == 0)
5016 {
5017 i++;
cristybb503372010-05-27 20:51:26 +00005018 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005019 ThrowMogrifyException(OptionError,"MissingArgument",option);
5020 if (IsGeometry(argv[i]) == MagickFalse)
5021 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5022 break;
5023 }
5024 if (LocaleCompare("list",option+1) == 0)
5025 {
cristybb503372010-05-27 20:51:26 +00005026 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005027 list;
5028
5029 if (*option == '+')
5030 break;
5031 i++;
cristybb503372010-05-27 20:51:26 +00005032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005033 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005034 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005035 if (list < 0)
5036 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005037 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005038 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005039 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005040 }
5041 if (LocaleCompare("log",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 (strchr(argv[i],'%') == (char *) NULL))
5048 ThrowMogrifyException(OptionError,"MissingArgument",option);
5049 break;
5050 }
5051 if (LocaleCompare("loop",option+1) == 0)
5052 {
5053 if (*option == '+')
5054 break;
5055 i++;
cristybb503372010-05-27 20:51:26 +00005056 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005057 ThrowMogrifyException(OptionError,"MissingArgument",option);
5058 if (IsGeometry(argv[i]) == MagickFalse)
5059 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5060 break;
5061 }
5062 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5063 }
5064 case 'm':
5065 {
5066 if (LocaleCompare("map",option+1) == 0)
5067 {
5068 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5069 if (*option == '+')
5070 break;
5071 i++;
cristybb503372010-05-27 20:51:26 +00005072 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005073 ThrowMogrifyException(OptionError,"MissingArgument",option);
5074 break;
5075 }
5076 if (LocaleCompare("mask",option+1) == 0)
5077 {
5078 if (*option == '+')
5079 break;
5080 i++;
cristybb503372010-05-27 20:51:26 +00005081 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005082 ThrowMogrifyException(OptionError,"MissingArgument",option);
5083 break;
5084 }
5085 if (LocaleCompare("matte",option+1) == 0)
5086 break;
5087 if (LocaleCompare("mattecolor",option+1) == 0)
5088 {
5089 if (*option == '+')
5090 break;
5091 i++;
cristybb503372010-05-27 20:51:26 +00005092 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005093 ThrowMogrifyException(OptionError,"MissingArgument",option);
5094 break;
5095 }
cristyf40785b2010-03-06 02:27:27 +00005096 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005097 break;
cristyf40785b2010-03-06 02:27:27 +00005098 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005099 break;
cristy3ed852e2009-09-05 21:47:34 +00005100 if (LocaleCompare("modulate",option+1) == 0)
5101 {
5102 if (*option == '+')
5103 break;
5104 i++;
cristybb503372010-05-27 20:51:26 +00005105 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005106 ThrowMogrifyException(OptionError,"MissingArgument",option);
5107 if (IsGeometry(argv[i]) == MagickFalse)
5108 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5109 break;
5110 }
5111 if (LocaleCompare("median",option+1) == 0)
5112 {
5113 if (*option == '+')
5114 break;
5115 i++;
cristybb503372010-05-27 20:51:26 +00005116 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005117 ThrowMogrifyException(OptionError,"MissingArgument",option);
5118 if (IsGeometry(argv[i]) == MagickFalse)
5119 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5120 break;
5121 }
cristy69ec32d2011-02-27 23:57:09 +00005122 if (LocaleCompare("mode",option+1) == 0)
5123 {
5124 if (*option == '+')
5125 break;
5126 i++;
5127 if (i == (ssize_t) argc)
5128 ThrowMogrifyException(OptionError,"MissingArgument",option);
5129 if (IsGeometry(argv[i]) == MagickFalse)
5130 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5131 break;
5132 }
cristy3ed852e2009-09-05 21:47:34 +00005133 if (LocaleCompare("monitor",option+1) == 0)
5134 break;
5135 if (LocaleCompare("monochrome",option+1) == 0)
5136 break;
5137 if (LocaleCompare("morph",option+1) == 0)
5138 {
5139 if (*option == '+')
5140 break;
5141 i++;
cristybb503372010-05-27 20:51:26 +00005142 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005143 ThrowMogrifyException(OptionError,"MissingArgument",option);
5144 if (IsGeometry(argv[i]) == MagickFalse)
5145 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5146 break;
5147 }
anthony29188a82010-01-22 10:12:34 +00005148 if (LocaleCompare("morphology",option+1) == 0)
5149 {
anthony29188a82010-01-22 10:12:34 +00005150 char
5151 token[MaxTextExtent];
5152
cristyb6bd4ad2010-08-08 01:12:27 +00005153 KernelInfo
5154 *kernel_info;
5155
5156 ssize_t
5157 op;
5158
anthony29188a82010-01-22 10:12:34 +00005159 i++;
cristybb503372010-05-27 20:51:26 +00005160 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005161 ThrowMogrifyException(OptionError,"MissingArgument",option);
5162 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005163 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005164 if (op < 0)
5165 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005166 token);
anthony29188a82010-01-22 10:12:34 +00005167 i++;
cristybb503372010-05-27 20:51:26 +00005168 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005169 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005170 kernel_info=AcquireKernelInfo(argv[i]);
5171 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005172 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005173 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005174 break;
5175 }
cristy3ed852e2009-09-05 21:47:34 +00005176 if (LocaleCompare("mosaic",option+1) == 0)
5177 break;
5178 if (LocaleCompare("motion-blur",option+1) == 0)
5179 {
5180 if (*option == '+')
5181 break;
5182 i++;
cristybb503372010-05-27 20:51:26 +00005183 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005184 ThrowMogrifyException(OptionError,"MissingArgument",option);
5185 if (IsGeometry(argv[i]) == MagickFalse)
5186 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5187 break;
5188 }
5189 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5190 }
5191 case 'n':
5192 {
5193 if (LocaleCompare("negate",option+1) == 0)
5194 break;
5195 if (LocaleCompare("noise",option+1) == 0)
5196 {
5197 i++;
cristybb503372010-05-27 20:51:26 +00005198 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005199 ThrowMogrifyException(OptionError,"MissingArgument",option);
5200 if (*option == '+')
5201 {
cristybb503372010-05-27 20:51:26 +00005202 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005203 noise;
5204
cristy042ee782011-04-22 18:48:30 +00005205 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005206 if (noise < 0)
5207 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5208 argv[i]);
5209 break;
5210 }
5211 if (IsGeometry(argv[i]) == MagickFalse)
5212 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5213 break;
5214 }
5215 if (LocaleCompare("noop",option+1) == 0)
5216 break;
5217 if (LocaleCompare("normalize",option+1) == 0)
5218 break;
5219 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5220 }
5221 case 'o':
5222 {
5223 if (LocaleCompare("opaque",option+1) == 0)
5224 {
cristy3ed852e2009-09-05 21:47:34 +00005225 i++;
cristybb503372010-05-27 20:51:26 +00005226 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005227 ThrowMogrifyException(OptionError,"MissingArgument",option);
5228 break;
5229 }
5230 if (LocaleCompare("ordered-dither",option+1) == 0)
5231 {
5232 if (*option == '+')
5233 break;
5234 i++;
cristybb503372010-05-27 20:51:26 +00005235 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005236 ThrowMogrifyException(OptionError,"MissingArgument",option);
5237 break;
5238 }
5239 if (LocaleCompare("orient",option+1) == 0)
5240 {
cristybb503372010-05-27 20:51:26 +00005241 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005242 orientation;
5243
5244 orientation=UndefinedOrientation;
5245 if (*option == '+')
5246 break;
5247 i++;
cristybb503372010-05-27 20:51:26 +00005248 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005249 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005250 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005251 argv[i]);
5252 if (orientation < 0)
5253 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5254 argv[i]);
5255 break;
5256 }
5257 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5258 }
5259 case 'p':
5260 {
5261 if (LocaleCompare("page",option+1) == 0)
5262 {
5263 if (*option == '+')
5264 break;
5265 i++;
cristybb503372010-05-27 20:51:26 +00005266 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005267 ThrowMogrifyException(OptionError,"MissingArgument",option);
5268 break;
5269 }
5270 if (LocaleCompare("paint",option+1) == 0)
5271 {
5272 if (*option == '+')
5273 break;
5274 i++;
cristybb503372010-05-27 20:51:26 +00005275 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005276 ThrowMogrifyException(OptionError,"MissingArgument",option);
5277 if (IsGeometry(argv[i]) == MagickFalse)
5278 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5279 break;
5280 }
5281 if (LocaleCompare("path",option+1) == 0)
5282 {
5283 (void) CloneString(&path,(char *) NULL);
5284 if (*option == '+')
5285 break;
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 (void) CloneString(&path,argv[i]);
5290 break;
5291 }
5292 if (LocaleCompare("pointsize",option+1) == 0)
5293 {
5294 if (*option == '+')
5295 break;
5296 i++;
cristybb503372010-05-27 20:51:26 +00005297 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005298 ThrowMogrifyException(OptionError,"MissingArgument",option);
5299 if (IsGeometry(argv[i]) == MagickFalse)
5300 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5301 break;
5302 }
5303 if (LocaleCompare("polaroid",option+1) == 0)
5304 {
5305 if (*option == '+')
5306 break;
5307 i++;
cristybb503372010-05-27 20:51:26 +00005308 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005309 ThrowMogrifyException(OptionError,"MissingArgument",option);
5310 if (IsGeometry(argv[i]) == MagickFalse)
5311 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5312 break;
5313 }
5314 if (LocaleCompare("posterize",option+1) == 0)
5315 {
5316 if (*option == '+')
5317 break;
5318 i++;
cristybb503372010-05-27 20:51:26 +00005319 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005320 ThrowMogrifyException(OptionError,"MissingArgument",option);
5321 if (IsGeometry(argv[i]) == MagickFalse)
5322 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5323 break;
5324 }
cristye7f51092010-01-17 00:39:37 +00005325 if (LocaleCompare("precision",option+1) == 0)
5326 {
5327 if (*option == '+')
5328 break;
5329 i++;
cristybb503372010-05-27 20:51:26 +00005330 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005331 ThrowMogrifyException(OptionError,"MissingArgument",option);
5332 if (IsGeometry(argv[i]) == MagickFalse)
5333 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5334 break;
5335 }
cristy3ed852e2009-09-05 21:47:34 +00005336 if (LocaleCompare("print",option+1) == 0)
5337 {
5338 if (*option == '+')
5339 break;
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 break;
5344 }
5345 if (LocaleCompare("process",option+1) == 0)
5346 {
5347 if (*option == '+')
5348 break;
5349 i++;
cristybb503372010-05-27 20:51:26 +00005350 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005351 ThrowMogrifyException(OptionError,"MissingArgument",option);
5352 break;
5353 }
5354 if (LocaleCompare("profile",option+1) == 0)
5355 {
5356 i++;
cristybb503372010-05-27 20:51:26 +00005357 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005358 ThrowMogrifyException(OptionError,"MissingArgument",option);
5359 break;
5360 }
5361 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5362 }
5363 case 'q':
5364 {
5365 if (LocaleCompare("quality",option+1) == 0)
5366 {
5367 if (*option == '+')
5368 break;
5369 i++;
cristybb503372010-05-27 20:51:26 +00005370 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005371 ThrowMogrifyException(OptionError,"MissingArgument",option);
5372 if (IsGeometry(argv[i]) == MagickFalse)
5373 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5374 break;
5375 }
5376 if (LocaleCompare("quantize",option+1) == 0)
5377 {
cristybb503372010-05-27 20:51:26 +00005378 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005379 colorspace;
5380
5381 if (*option == '+')
5382 break;
5383 i++;
cristybb503372010-05-27 20:51:26 +00005384 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005385 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005386 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005387 argv[i]);
5388 if (colorspace < 0)
5389 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5390 argv[i]);
5391 break;
5392 }
5393 if (LocaleCompare("quiet",option+1) == 0)
5394 break;
5395 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5396 }
5397 case 'r':
5398 {
5399 if (LocaleCompare("radial-blur",option+1) == 0)
5400 {
5401 i++;
cristybb503372010-05-27 20:51:26 +00005402 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005403 ThrowMogrifyException(OptionError,"MissingArgument",option);
5404 if (IsGeometry(argv[i]) == MagickFalse)
5405 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5406 break;
5407 }
5408 if (LocaleCompare("raise",option+1) == 0)
5409 {
5410 i++;
cristybb503372010-05-27 20:51:26 +00005411 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005412 ThrowMogrifyException(OptionError,"MissingArgument",option);
5413 if (IsGeometry(argv[i]) == MagickFalse)
5414 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5415 break;
5416 }
5417 if (LocaleCompare("random-threshold",option+1) == 0)
5418 {
5419 if (*option == '+')
5420 break;
5421 i++;
cristybb503372010-05-27 20:51:26 +00005422 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005423 ThrowMogrifyException(OptionError,"MissingArgument",option);
5424 if (IsGeometry(argv[i]) == MagickFalse)
5425 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5426 break;
5427 }
5428 if (LocaleCompare("red-primary",option+1) == 0)
5429 {
5430 if (*option == '+')
5431 break;
5432 i++;
cristybb503372010-05-27 20:51:26 +00005433 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005434 ThrowMogrifyException(OptionError,"MissingArgument",option);
5435 if (IsGeometry(argv[i]) == MagickFalse)
5436 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5437 }
cristy9f2083a2010-04-22 19:48:05 +00005438 if (LocaleCompare("regard-warnings",option+1) == 0)
5439 break;
cristy3ed852e2009-09-05 21:47:34 +00005440 if (LocaleCompare("region",option+1) == 0)
5441 {
5442 if (*option == '+')
5443 break;
5444 i++;
cristybb503372010-05-27 20:51:26 +00005445 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005446 ThrowMogrifyException(OptionError,"MissingArgument",option);
5447 if (IsGeometry(argv[i]) == MagickFalse)
5448 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5449 break;
5450 }
cristyf0c78232010-03-15 12:53:40 +00005451 if (LocaleCompare("remap",option+1) == 0)
5452 {
5453 if (*option == '+')
5454 break;
5455 i++;
cristybb503372010-05-27 20:51:26 +00005456 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005457 ThrowMogrifyException(OptionError,"MissingArgument",option);
5458 break;
5459 }
cristy3ed852e2009-09-05 21:47:34 +00005460 if (LocaleCompare("render",option+1) == 0)
5461 break;
5462 if (LocaleCompare("repage",option+1) == 0)
5463 {
5464 if (*option == '+')
5465 break;
5466 i++;
cristybb503372010-05-27 20:51:26 +00005467 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005468 ThrowMogrifyException(OptionError,"MissingArgument",option);
5469 if (IsGeometry(argv[i]) == MagickFalse)
5470 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5471 break;
5472 }
5473 if (LocaleCompare("resample",option+1) == 0)
5474 {
5475 if (*option == '+')
5476 break;
5477 i++;
cristybb503372010-05-27 20:51:26 +00005478 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005479 ThrowMogrifyException(OptionError,"MissingArgument",option);
5480 if (IsGeometry(argv[i]) == MagickFalse)
5481 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5482 break;
5483 }
5484 if (LocaleCompare("resize",option+1) == 0)
5485 {
5486 if (*option == '+')
5487 break;
5488 i++;
cristybb503372010-05-27 20:51:26 +00005489 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005490 ThrowMogrifyException(OptionError,"MissingArgument",option);
5491 if (IsGeometry(argv[i]) == MagickFalse)
5492 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5493 break;
5494 }
cristyebbcfea2011-02-25 02:43:54 +00005495 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5496 {
5497 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5498 break;
5499 }
cristy3ed852e2009-09-05 21:47:34 +00005500 if (LocaleCompare("reverse",option+1) == 0)
5501 break;
5502 if (LocaleCompare("roll",option+1) == 0)
5503 {
5504 if (*option == '+')
5505 break;
5506 i++;
cristybb503372010-05-27 20:51:26 +00005507 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005508 ThrowMogrifyException(OptionError,"MissingArgument",option);
5509 if (IsGeometry(argv[i]) == MagickFalse)
5510 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5511 break;
5512 }
5513 if (LocaleCompare("rotate",option+1) == 0)
5514 {
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 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5523 }
5524 case 's':
5525 {
5526 if (LocaleCompare("sample",option+1) == 0)
5527 {
5528 if (*option == '+')
5529 break;
5530 i++;
cristybb503372010-05-27 20:51:26 +00005531 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005532 ThrowMogrifyException(OptionError,"MissingArgument",option);
5533 if (IsGeometry(argv[i]) == MagickFalse)
5534 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5535 break;
5536 }
5537 if (LocaleCompare("sampling-factor",option+1) == 0)
5538 {
5539 if (*option == '+')
5540 break;
5541 i++;
cristybb503372010-05-27 20:51:26 +00005542 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005543 ThrowMogrifyException(OptionError,"MissingArgument",option);
5544 if (IsGeometry(argv[i]) == MagickFalse)
5545 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5546 break;
5547 }
5548 if (LocaleCompare("scale",option+1) == 0)
5549 {
5550 if (*option == '+')
5551 break;
5552 i++;
cristybb503372010-05-27 20:51:26 +00005553 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005554 ThrowMogrifyException(OptionError,"MissingArgument",option);
5555 if (IsGeometry(argv[i]) == MagickFalse)
5556 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5557 break;
5558 }
5559 if (LocaleCompare("scene",option+1) == 0)
5560 {
5561 if (*option == '+')
5562 break;
5563 i++;
cristybb503372010-05-27 20:51:26 +00005564 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005565 ThrowMogrifyException(OptionError,"MissingArgument",option);
5566 if (IsGeometry(argv[i]) == MagickFalse)
5567 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5568 break;
5569 }
5570 if (LocaleCompare("seed",option+1) == 0)
5571 {
5572 if (*option == '+')
5573 break;
5574 i++;
cristybb503372010-05-27 20:51:26 +00005575 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005576 ThrowMogrifyException(OptionError,"MissingArgument",option);
5577 if (IsGeometry(argv[i]) == MagickFalse)
5578 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5579 break;
5580 }
5581 if (LocaleCompare("segment",option+1) == 0)
5582 {
5583 if (*option == '+')
5584 break;
5585 i++;
cristybb503372010-05-27 20:51:26 +00005586 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005587 ThrowMogrifyException(OptionError,"MissingArgument",option);
5588 if (IsGeometry(argv[i]) == MagickFalse)
5589 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5590 break;
5591 }
5592 if (LocaleCompare("selective-blur",option+1) == 0)
5593 {
5594 i++;
cristybb503372010-05-27 20:51:26 +00005595 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005596 ThrowMogrifyException(OptionError,"MissingArgument",option);
5597 if (IsGeometry(argv[i]) == MagickFalse)
5598 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5599 break;
5600 }
5601 if (LocaleCompare("separate",option+1) == 0)
5602 break;
5603 if (LocaleCompare("sepia-tone",option+1) == 0)
5604 {
5605 if (*option == '+')
5606 break;
5607 i++;
cristybb503372010-05-27 20:51:26 +00005608 if (i == (ssize_t) argc)
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("set",option+1) == 0)
5615 {
5616 i++;
cristybb503372010-05-27 20:51:26 +00005617 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005618 ThrowMogrifyException(OptionError,"MissingArgument",option);
5619 if (*option == '+')
5620 break;
5621 i++;
cristybb503372010-05-27 20:51:26 +00005622 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005623 ThrowMogrifyException(OptionError,"MissingArgument",option);
5624 break;
5625 }
5626 if (LocaleCompare("shade",option+1) == 0)
5627 {
5628 i++;
cristybb503372010-05-27 20:51:26 +00005629 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005630 ThrowMogrifyException(OptionError,"MissingArgument",option);
5631 if (IsGeometry(argv[i]) == MagickFalse)
5632 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5633 break;
5634 }
5635 if (LocaleCompare("shadow",option+1) == 0)
5636 {
5637 if (*option == '+')
5638 break;
5639 i++;
cristybb503372010-05-27 20:51:26 +00005640 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005641 ThrowMogrifyException(OptionError,"MissingArgument",option);
5642 if (IsGeometry(argv[i]) == MagickFalse)
5643 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5644 break;
5645 }
5646 if (LocaleCompare("sharpen",option+1) == 0)
5647 {
5648 i++;
cristybb503372010-05-27 20:51:26 +00005649 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005650 ThrowMogrifyException(OptionError,"MissingArgument",option);
5651 if (IsGeometry(argv[i]) == MagickFalse)
5652 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5653 break;
5654 }
5655 if (LocaleCompare("shave",option+1) == 0)
5656 {
5657 if (*option == '+')
5658 break;
5659 i++;
cristybb503372010-05-27 20:51:26 +00005660 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005661 ThrowMogrifyException(OptionError,"MissingArgument",option);
5662 if (IsGeometry(argv[i]) == MagickFalse)
5663 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5664 break;
5665 }
5666 if (LocaleCompare("shear",option+1) == 0)
5667 {
5668 i++;
cristybb503372010-05-27 20:51:26 +00005669 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005670 ThrowMogrifyException(OptionError,"MissingArgument",option);
5671 if (IsGeometry(argv[i]) == MagickFalse)
5672 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5673 break;
5674 }
5675 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5676 {
5677 i++;
cristybb503372010-05-27 20:51:26 +00005678 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005679 ThrowMogrifyException(OptionError,"MissingArgument",option);
5680 if (IsGeometry(argv[i]) == MagickFalse)
5681 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5682 break;
5683 }
5684 if (LocaleCompare("size",option+1) == 0)
5685 {
5686 if (*option == '+')
5687 break;
5688 i++;
cristybb503372010-05-27 20:51:26 +00005689 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005690 ThrowMogrifyException(OptionError,"MissingArgument",option);
5691 if (IsGeometry(argv[i]) == MagickFalse)
5692 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5693 break;
5694 }
5695 if (LocaleCompare("sketch",option+1) == 0)
5696 {
5697 if (*option == '+')
5698 break;
5699 i++;
cristybb503372010-05-27 20:51:26 +00005700 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005701 ThrowMogrifyException(OptionError,"MissingArgument",option);
5702 if (IsGeometry(argv[i]) == MagickFalse)
5703 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5704 break;
5705 }
cristy4285d782011-02-09 20:12:28 +00005706 if (LocaleCompare("smush",option+1) == 0)
5707 {
cristy4285d782011-02-09 20:12:28 +00005708 i++;
5709 if (i == (ssize_t) argc)
5710 ThrowMogrifyException(OptionError,"MissingArgument",option);
5711 if (IsGeometry(argv[i]) == MagickFalse)
5712 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005713 i++;
5714 break;
5715 }
cristy3ed852e2009-09-05 21:47:34 +00005716 if (LocaleCompare("solarize",option+1) == 0)
5717 {
5718 if (*option == '+')
5719 break;
5720 i++;
cristybb503372010-05-27 20:51:26 +00005721 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005722 ThrowMogrifyException(OptionError,"MissingArgument",option);
5723 if (IsGeometry(argv[i]) == MagickFalse)
5724 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5725 break;
5726 }
5727 if (LocaleCompare("sparse-color",option+1) == 0)
5728 {
cristybb503372010-05-27 20:51:26 +00005729 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005730 op;
5731
5732 i++;
cristybb503372010-05-27 20:51:26 +00005733 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005734 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005735 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005736 if (op < 0)
5737 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5738 argv[i]);
5739 i++;
cristybb503372010-05-27 20:51:26 +00005740 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005741 ThrowMogrifyException(OptionError,"MissingArgument",option);
5742 break;
5743 }
5744 if (LocaleCompare("spread",option+1) == 0)
5745 {
5746 if (*option == '+')
5747 break;
5748 i++;
cristybb503372010-05-27 20:51:26 +00005749 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005750 ThrowMogrifyException(OptionError,"MissingArgument",option);
5751 if (IsGeometry(argv[i]) == MagickFalse)
5752 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5753 break;
5754 }
cristy0834d642011-03-18 18:26:08 +00005755 if (LocaleCompare("statistic",option+1) == 0)
5756 {
5757 ssize_t
5758 op;
5759
5760 if (*option == '+')
5761 break;
5762 i++;
5763 if (i == (ssize_t) argc)
5764 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005765 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005766 if (op < 0)
5767 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5768 argv[i]);
5769 i++;
5770 if (i == (ssize_t) (argc-1))
5771 ThrowMogrifyException(OptionError,"MissingArgument",option);
5772 if (IsGeometry(argv[i]) == MagickFalse)
5773 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5774 break;
5775 }
cristy3ed852e2009-09-05 21:47:34 +00005776 if (LocaleCompare("stretch",option+1) == 0)
5777 {
cristybb503372010-05-27 20:51:26 +00005778 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005779 stretch;
5780
5781 if (*option == '+')
5782 break;
5783 i++;
cristybb503372010-05-27 20:51:26 +00005784 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005785 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005786 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005787 if (stretch < 0)
5788 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5789 argv[i]);
5790 break;
5791 }
5792 if (LocaleCompare("strip",option+1) == 0)
5793 break;
5794 if (LocaleCompare("stroke",option+1) == 0)
5795 {
5796 if (*option == '+')
5797 break;
5798 i++;
cristybb503372010-05-27 20:51:26 +00005799 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005800 ThrowMogrifyException(OptionError,"MissingArgument",option);
5801 break;
5802 }
5803 if (LocaleCompare("strokewidth",option+1) == 0)
5804 {
5805 if (*option == '+')
5806 break;
5807 i++;
cristybb503372010-05-27 20:51:26 +00005808 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005809 ThrowMogrifyException(OptionError,"MissingArgument",option);
5810 if (IsGeometry(argv[i]) == MagickFalse)
5811 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5812 break;
5813 }
5814 if (LocaleCompare("style",option+1) == 0)
5815 {
cristybb503372010-05-27 20:51:26 +00005816 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005817 style;
5818
5819 if (*option == '+')
5820 break;
5821 i++;
cristybb503372010-05-27 20:51:26 +00005822 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005823 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005824 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005825 if (style < 0)
5826 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5827 argv[i]);
5828 break;
5829 }
cristyecb10ff2011-03-22 13:14:03 +00005830 if (LocaleCompare("swap",option+1) == 0)
5831 {
5832 if (*option == '+')
5833 break;
5834 i++;
5835 if (i == (ssize_t) (argc-1))
5836 ThrowMogrifyException(OptionError,"MissingArgument",option);
5837 if (IsGeometry(argv[i]) == MagickFalse)
5838 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5839 break;
5840 }
cristy3ed852e2009-09-05 21:47:34 +00005841 if (LocaleCompare("swirl",option+1) == 0)
5842 {
5843 if (*option == '+')
5844 break;
5845 i++;
cristybb503372010-05-27 20:51:26 +00005846 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005847 ThrowMogrifyException(OptionError,"MissingArgument",option);
5848 if (IsGeometry(argv[i]) == MagickFalse)
5849 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5850 break;
5851 }
cristyd9a29192010-10-16 16:49:53 +00005852 if (LocaleCompare("synchronize",option+1) == 0)
5853 break;
cristy3ed852e2009-09-05 21:47:34 +00005854 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5855 }
5856 case 't':
5857 {
5858 if (LocaleCompare("taint",option+1) == 0)
5859 break;
5860 if (LocaleCompare("texture",option+1) == 0)
5861 {
5862 if (*option == '+')
5863 break;
5864 i++;
cristybb503372010-05-27 20:51:26 +00005865 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005866 ThrowMogrifyException(OptionError,"MissingArgument",option);
5867 break;
5868 }
5869 if (LocaleCompare("tile",option+1) == 0)
5870 {
5871 if (*option == '+')
5872 break;
5873 i++;
cristybb503372010-05-27 20:51:26 +00005874 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005875 ThrowMogrifyException(OptionError,"MissingArgument",option);
5876 break;
5877 }
5878 if (LocaleCompare("tile-offset",option+1) == 0)
5879 {
5880 if (*option == '+')
5881 break;
5882 i++;
cristybb503372010-05-27 20:51:26 +00005883 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005884 ThrowMogrifyException(OptionError,"MissingArgument",option);
5885 if (IsGeometry(argv[i]) == MagickFalse)
5886 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5887 break;
5888 }
5889 if (LocaleCompare("tint",option+1) == 0)
5890 {
5891 if (*option == '+')
5892 break;
5893 i++;
cristybb503372010-05-27 20:51:26 +00005894 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005895 ThrowMogrifyException(OptionError,"MissingArgument",option);
5896 if (IsGeometry(argv[i]) == MagickFalse)
5897 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5898 break;
5899 }
5900 if (LocaleCompare("transform",option+1) == 0)
5901 break;
5902 if (LocaleCompare("transpose",option+1) == 0)
5903 break;
5904 if (LocaleCompare("transverse",option+1) == 0)
5905 break;
5906 if (LocaleCompare("threshold",option+1) == 0)
5907 {
5908 if (*option == '+')
5909 break;
5910 i++;
cristybb503372010-05-27 20:51:26 +00005911 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005912 ThrowMogrifyException(OptionError,"MissingArgument",option);
5913 if (IsGeometry(argv[i]) == MagickFalse)
5914 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5915 break;
5916 }
5917 if (LocaleCompare("thumbnail",option+1) == 0)
5918 {
5919 if (*option == '+')
5920 break;
5921 i++;
cristybb503372010-05-27 20:51:26 +00005922 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005923 ThrowMogrifyException(OptionError,"MissingArgument",option);
5924 if (IsGeometry(argv[i]) == MagickFalse)
5925 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5926 break;
5927 }
5928 if (LocaleCompare("transparent",option+1) == 0)
5929 {
5930 i++;
cristybb503372010-05-27 20:51:26 +00005931 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005932 ThrowMogrifyException(OptionError,"MissingArgument",option);
5933 break;
5934 }
5935 if (LocaleCompare("transparent-color",option+1) == 0)
5936 {
5937 if (*option == '+')
5938 break;
5939 i++;
cristybb503372010-05-27 20:51:26 +00005940 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005941 ThrowMogrifyException(OptionError,"MissingArgument",option);
5942 break;
5943 }
5944 if (LocaleCompare("treedepth",option+1) == 0)
5945 {
5946 if (*option == '+')
5947 break;
5948 i++;
cristybb503372010-05-27 20:51:26 +00005949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005950 ThrowMogrifyException(OptionError,"MissingArgument",option);
5951 if (IsGeometry(argv[i]) == MagickFalse)
5952 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5953 break;
5954 }
5955 if (LocaleCompare("trim",option+1) == 0)
5956 break;
5957 if (LocaleCompare("type",option+1) == 0)
5958 {
cristybb503372010-05-27 20:51:26 +00005959 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005960 type;
5961
5962 if (*option == '+')
5963 break;
5964 i++;
cristybb503372010-05-27 20:51:26 +00005965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005966 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005967 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005968 if (type < 0)
5969 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5970 argv[i]);
5971 break;
5972 }
5973 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5974 }
5975 case 'u':
5976 {
5977 if (LocaleCompare("undercolor",option+1) == 0)
5978 {
5979 if (*option == '+')
5980 break;
5981 i++;
cristybb503372010-05-27 20:51:26 +00005982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005983 ThrowMogrifyException(OptionError,"MissingArgument",option);
5984 break;
5985 }
5986 if (LocaleCompare("unique-colors",option+1) == 0)
5987 break;
5988 if (LocaleCompare("units",option+1) == 0)
5989 {
cristybb503372010-05-27 20:51:26 +00005990 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005991 units;
5992
5993 if (*option == '+')
5994 break;
5995 i++;
cristybb503372010-05-27 20:51:26 +00005996 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005997 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005998 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005999 argv[i]);
6000 if (units < 0)
6001 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6002 argv[i]);
6003 break;
6004 }
6005 if (LocaleCompare("unsharp",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 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6015 }
6016 case 'v':
6017 {
6018 if (LocaleCompare("verbose",option+1) == 0)
6019 {
6020 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6021 break;
6022 }
6023 if ((LocaleCompare("version",option+1) == 0) ||
6024 (LocaleCompare("-version",option+1) == 0))
6025 {
cristyb51dff52011-05-19 16:55:47 +00006026 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006027 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00006028 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
6029 GetMagickCopyright());
6030 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
6031 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006032 break;
6033 }
6034 if (LocaleCompare("view",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 break;
6042 }
6043 if (LocaleCompare("vignette",option+1) == 0)
6044 {
6045 if (*option == '+')
6046 break;
6047 i++;
cristybb503372010-05-27 20:51:26 +00006048 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006049 ThrowMogrifyException(OptionError,"MissingArgument",option);
6050 if (IsGeometry(argv[i]) == MagickFalse)
6051 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6052 break;
6053 }
6054 if (LocaleCompare("virtual-pixel",option+1) == 0)
6055 {
cristybb503372010-05-27 20:51:26 +00006056 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006057 method;
6058
6059 if (*option == '+')
6060 break;
6061 i++;
cristybb503372010-05-27 20:51:26 +00006062 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006063 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006064 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006065 argv[i]);
6066 if (method < 0)
6067 ThrowMogrifyException(OptionError,
6068 "UnrecognizedVirtualPixelMethod",argv[i]);
6069 break;
6070 }
6071 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6072 }
6073 case 'w':
6074 {
6075 if (LocaleCompare("wave",option+1) == 0)
6076 {
6077 i++;
cristybb503372010-05-27 20:51:26 +00006078 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006079 ThrowMogrifyException(OptionError,"MissingArgument",option);
6080 if (IsGeometry(argv[i]) == MagickFalse)
6081 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6082 break;
6083 }
6084 if (LocaleCompare("weight",option+1) == 0)
6085 {
6086 if (*option == '+')
6087 break;
6088 i++;
cristybb503372010-05-27 20:51:26 +00006089 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006090 ThrowMogrifyException(OptionError,"MissingArgument",option);
6091 break;
6092 }
6093 if (LocaleCompare("white-point",option+1) == 0)
6094 {
6095 if (*option == '+')
6096 break;
6097 i++;
cristybb503372010-05-27 20:51:26 +00006098 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006099 ThrowMogrifyException(OptionError,"MissingArgument",option);
6100 if (IsGeometry(argv[i]) == MagickFalse)
6101 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6102 break;
6103 }
6104 if (LocaleCompare("white-threshold",option+1) == 0)
6105 {
6106 if (*option == '+')
6107 break;
6108 i++;
cristybb503372010-05-27 20:51:26 +00006109 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006110 ThrowMogrifyException(OptionError,"MissingArgument",option);
6111 if (IsGeometry(argv[i]) == MagickFalse)
6112 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6113 break;
6114 }
6115 if (LocaleCompare("write",option+1) == 0)
6116 {
6117 i++;
cristybb503372010-05-27 20:51:26 +00006118 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006119 ThrowMogrifyException(OptionError,"MissingArgument",option);
6120 break;
6121 }
6122 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6123 }
6124 case '?':
6125 break;
6126 default:
6127 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6128 }
cristy042ee782011-04-22 18:48:30 +00006129 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6130 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006131 if (fire != MagickFalse)
6132 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6133 }
6134 if (k != 0)
6135 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006136 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006137 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6138 DestroyMogrify();
6139 return(status != 0 ? MagickTrue : MagickFalse);
6140}
6141
6142/*
6143%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6144% %
6145% %
6146% %
6147+ M o g r i f y I m a g e I n f o %
6148% %
6149% %
6150% %
6151%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6152%
6153% MogrifyImageInfo() applies image processing settings to the image as
6154% prescribed by command line options.
6155%
6156% The format of the MogrifyImageInfo method is:
6157%
6158% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6159% const char **argv,ExceptionInfo *exception)
6160%
6161% A description of each parameter follows:
6162%
6163% o image_info: the image info..
6164%
6165% o argc: Specifies a pointer to an integer describing the number of
6166% elements in the argument vector.
6167%
6168% o argv: Specifies a pointer to a text array containing the command line
6169% arguments.
6170%
6171% o exception: return any errors or warnings in this structure.
6172%
6173*/
6174WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6175 const int argc,const char **argv,ExceptionInfo *exception)
6176{
6177 const char
6178 *option;
6179
6180 GeometryInfo
6181 geometry_info;
6182
cristybb503372010-05-27 20:51:26 +00006183 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006184 count;
6185
cristybb503372010-05-27 20:51:26 +00006186 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006187 i;
6188
6189 /*
6190 Initialize method variables.
6191 */
6192 assert(image_info != (ImageInfo *) NULL);
6193 assert(image_info->signature == MagickSignature);
6194 if (image_info->debug != MagickFalse)
6195 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6196 image_info->filename);
6197 if (argc < 0)
6198 return(MagickTrue);
6199 /*
6200 Set the image settings.
6201 */
cristybb503372010-05-27 20:51:26 +00006202 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006203 {
6204 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006205 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006206 continue;
cristy042ee782011-04-22 18:48:30 +00006207 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006208 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006209 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006210 break;
6211 switch (*(option+1))
6212 {
6213 case 'a':
6214 {
6215 if (LocaleCompare("adjoin",option+1) == 0)
6216 {
6217 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6218 break;
6219 }
6220 if (LocaleCompare("antialias",option+1) == 0)
6221 {
6222 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6223 break;
6224 }
cristy3ed852e2009-09-05 21:47:34 +00006225 if (LocaleCompare("authenticate",option+1) == 0)
6226 {
6227 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006228 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006229 else
anthony1afdc7a2011-10-05 11:54:28 +00006230 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006231 break;
6232 }
6233 break;
6234 }
6235 case 'b':
6236 {
6237 if (LocaleCompare("background",option+1) == 0)
6238 {
6239 if (*option == '+')
6240 {
6241 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006242 (void) QueryColorCompliance(MogrifyBackgroundColor,
6243 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006244 break;
6245 }
6246 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006247 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6248 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006249 break;
6250 }
6251 if (LocaleCompare("bias",option+1) == 0)
6252 {
6253 if (*option == '+')
6254 {
6255 (void) SetImageOption(image_info,option+1,"0.0");
6256 break;
6257 }
6258 (void) SetImageOption(image_info,option+1,argv[i+1]);
6259 break;
6260 }
6261 if (LocaleCompare("black-point-compensation",option+1) == 0)
6262 {
6263 if (*option == '+')
6264 {
6265 (void) SetImageOption(image_info,option+1,"false");
6266 break;
6267 }
6268 (void) SetImageOption(image_info,option+1,"true");
6269 break;
6270 }
6271 if (LocaleCompare("blue-primary",option+1) == 0)
6272 {
6273 if (*option == '+')
6274 {
6275 (void) SetImageOption(image_info,option+1,"0.0");
6276 break;
6277 }
6278 (void) SetImageOption(image_info,option+1,argv[i+1]);
6279 break;
6280 }
6281 if (LocaleCompare("bordercolor",option+1) == 0)
6282 {
6283 if (*option == '+')
6284 {
6285 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006286 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006287 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006288 break;
6289 }
cristy9950d572011-10-01 18:22:35 +00006290 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6291 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006292 (void) SetImageOption(image_info,option+1,argv[i+1]);
6293 break;
6294 }
6295 if (LocaleCompare("box",option+1) == 0)
6296 {
6297 if (*option == '+')
6298 {
6299 (void) SetImageOption(image_info,"undercolor","none");
6300 break;
6301 }
6302 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6303 break;
6304 }
6305 break;
6306 }
6307 case 'c':
6308 {
6309 if (LocaleCompare("cache",option+1) == 0)
6310 {
6311 MagickSizeType
6312 limit;
6313
6314 limit=MagickResourceInfinity;
6315 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006316 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6317 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006318 (void) SetMagickResourceLimit(MemoryResource,limit);
6319 (void) SetMagickResourceLimit(MapResource,2*limit);
6320 break;
6321 }
6322 if (LocaleCompare("caption",option+1) == 0)
6323 {
6324 if (*option == '+')
6325 {
6326 (void) DeleteImageOption(image_info,option+1);
6327 break;
6328 }
6329 (void) SetImageOption(image_info,option+1,argv[i+1]);
6330 break;
6331 }
6332 if (LocaleCompare("channel",option+1) == 0)
6333 {
6334 if (*option == '+')
6335 {
6336 image_info->channel=DefaultChannels;
6337 break;
6338 }
6339 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6340 break;
6341 }
cristy3ed852e2009-09-05 21:47:34 +00006342 if (LocaleCompare("colorspace",option+1) == 0)
6343 {
6344 if (*option == '+')
6345 {
6346 image_info->colorspace=UndefinedColorspace;
6347 (void) SetImageOption(image_info,option+1,"undefined");
6348 break;
6349 }
cristy042ee782011-04-22 18:48:30 +00006350 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006351 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6352 (void) SetImageOption(image_info,option+1,argv[i+1]);
6353 break;
6354 }
cristy3ed852e2009-09-05 21:47:34 +00006355 if (LocaleCompare("comment",option+1) == 0)
6356 {
6357 if (*option == '+')
6358 {
6359 (void) DeleteImageOption(image_info,option+1);
6360 break;
6361 }
6362 (void) SetImageOption(image_info,option+1,argv[i+1]);
6363 break;
6364 }
6365 if (LocaleCompare("compose",option+1) == 0)
6366 {
6367 if (*option == '+')
6368 {
6369 (void) SetImageOption(image_info,option+1,"undefined");
6370 break;
6371 }
6372 (void) SetImageOption(image_info,option+1,argv[i+1]);
6373 break;
6374 }
6375 if (LocaleCompare("compress",option+1) == 0)
6376 {
6377 if (*option == '+')
6378 {
6379 image_info->compression=UndefinedCompression;
6380 (void) SetImageOption(image_info,option+1,"undefined");
6381 break;
6382 }
cristy042ee782011-04-22 18:48:30 +00006383 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006384 MagickCompressOptions,MagickFalse,argv[i+1]);
6385 (void) SetImageOption(image_info,option+1,argv[i+1]);
6386 break;
6387 }
6388 break;
6389 }
6390 case 'd':
6391 {
6392 if (LocaleCompare("debug",option+1) == 0)
6393 {
6394 if (*option == '+')
6395 (void) SetLogEventMask("none");
6396 else
6397 (void) SetLogEventMask(argv[i+1]);
6398 image_info->debug=IsEventLogging();
6399 break;
6400 }
6401 if (LocaleCompare("define",option+1) == 0)
6402 {
6403 if (*option == '+')
6404 {
6405 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6406 (void) DeleteImageRegistry(argv[i+1]+9);
6407 else
6408 (void) DeleteImageOption(image_info,argv[i+1]);
6409 break;
6410 }
6411 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6412 {
6413 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6414 exception);
6415 break;
6416 }
6417 (void) DefineImageOption(image_info,argv[i+1]);
6418 break;
6419 }
6420 if (LocaleCompare("delay",option+1) == 0)
6421 {
6422 if (*option == '+')
6423 {
6424 (void) SetImageOption(image_info,option+1,"0");
6425 break;
6426 }
6427 (void) SetImageOption(image_info,option+1,argv[i+1]);
6428 break;
6429 }
6430 if (LocaleCompare("density",option+1) == 0)
6431 {
6432 /*
6433 Set image density.
6434 */
6435 if (*option == '+')
6436 {
6437 if (image_info->density != (char *) NULL)
6438 image_info->density=DestroyString(image_info->density);
6439 (void) SetImageOption(image_info,option+1,"72");
6440 break;
6441 }
6442 (void) CloneString(&image_info->density,argv[i+1]);
6443 (void) SetImageOption(image_info,option+1,argv[i+1]);
6444 break;
6445 }
6446 if (LocaleCompare("depth",option+1) == 0)
6447 {
6448 if (*option == '+')
6449 {
6450 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6451 break;
6452 }
cristye27293e2009-12-18 02:53:20 +00006453 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006454 break;
6455 }
cristyc9b12952010-03-28 01:12:28 +00006456 if (LocaleCompare("direction",option+1) == 0)
6457 {
6458 if (*option == '+')
6459 {
6460 (void) SetImageOption(image_info,option+1,"undefined");
6461 break;
6462 }
6463 (void) SetImageOption(image_info,option+1,argv[i+1]);
6464 break;
6465 }
cristy3ed852e2009-09-05 21:47:34 +00006466 if (LocaleCompare("display",option+1) == 0)
6467 {
6468 if (*option == '+')
6469 {
6470 if (image_info->server_name != (char *) NULL)
6471 image_info->server_name=DestroyString(
6472 image_info->server_name);
6473 break;
6474 }
6475 (void) CloneString(&image_info->server_name,argv[i+1]);
6476 break;
6477 }
6478 if (LocaleCompare("dispose",option+1) == 0)
6479 {
6480 if (*option == '+')
6481 {
6482 (void) SetImageOption(image_info,option+1,"undefined");
6483 break;
6484 }
6485 (void) SetImageOption(image_info,option+1,argv[i+1]);
6486 break;
6487 }
6488 if (LocaleCompare("dither",option+1) == 0)
6489 {
6490 if (*option == '+')
6491 {
6492 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006493 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006494 break;
6495 }
6496 (void) SetImageOption(image_info,option+1,argv[i+1]);
6497 image_info->dither=MagickTrue;
6498 break;
6499 }
6500 break;
6501 }
6502 case 'e':
6503 {
6504 if (LocaleCompare("encoding",option+1) == 0)
6505 {
6506 if (*option == '+')
6507 {
6508 (void) SetImageOption(image_info,option+1,"undefined");
6509 break;
6510 }
6511 (void) SetImageOption(image_info,option+1,argv[i+1]);
6512 break;
6513 }
6514 if (LocaleCompare("endian",option+1) == 0)
6515 {
6516 if (*option == '+')
6517 {
6518 image_info->endian=UndefinedEndian;
6519 (void) SetImageOption(image_info,option+1,"undefined");
6520 break;
6521 }
cristy042ee782011-04-22 18:48:30 +00006522 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006523 MagickEndianOptions,MagickFalse,argv[i+1]);
6524 (void) SetImageOption(image_info,option+1,argv[i+1]);
6525 break;
6526 }
6527 if (LocaleCompare("extract",option+1) == 0)
6528 {
6529 /*
6530 Set image extract geometry.
6531 */
6532 if (*option == '+')
6533 {
6534 if (image_info->extract != (char *) NULL)
6535 image_info->extract=DestroyString(image_info->extract);
6536 break;
6537 }
6538 (void) CloneString(&image_info->extract,argv[i+1]);
6539 break;
6540 }
6541 break;
6542 }
6543 case 'f':
6544 {
6545 if (LocaleCompare("fill",option+1) == 0)
6546 {
6547 if (*option == '+')
6548 {
6549 (void) SetImageOption(image_info,option+1,"none");
6550 break;
6551 }
6552 (void) SetImageOption(image_info,option+1,argv[i+1]);
6553 break;
6554 }
6555 if (LocaleCompare("filter",option+1) == 0)
6556 {
6557 if (*option == '+')
6558 {
6559 (void) SetImageOption(image_info,option+1,"undefined");
6560 break;
6561 }
6562 (void) SetImageOption(image_info,option+1,argv[i+1]);
6563 break;
6564 }
6565 if (LocaleCompare("font",option+1) == 0)
6566 {
6567 if (*option == '+')
6568 {
6569 if (image_info->font != (char *) NULL)
6570 image_info->font=DestroyString(image_info->font);
6571 break;
6572 }
6573 (void) CloneString(&image_info->font,argv[i+1]);
6574 break;
6575 }
6576 if (LocaleCompare("format",option+1) == 0)
6577 {
6578 register const char
6579 *q;
6580
6581 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006582 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006583 image_info->ping=MagickFalse;
6584 (void) SetImageOption(image_info,option+1,argv[i+1]);
6585 break;
6586 }
6587 if (LocaleCompare("fuzz",option+1) == 0)
6588 {
6589 if (*option == '+')
6590 {
6591 image_info->fuzz=0.0;
6592 (void) SetImageOption(image_info,option+1,"0");
6593 break;
6594 }
cristydbdd0e32011-11-04 23:29:40 +00006595 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6596 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006597 (void) SetImageOption(image_info,option+1,argv[i+1]);
6598 break;
6599 }
6600 break;
6601 }
6602 case 'g':
6603 {
6604 if (LocaleCompare("gravity",option+1) == 0)
6605 {
6606 if (*option == '+')
6607 {
6608 (void) SetImageOption(image_info,option+1,"undefined");
6609 break;
6610 }
6611 (void) SetImageOption(image_info,option+1,argv[i+1]);
6612 break;
6613 }
6614 if (LocaleCompare("green-primary",option+1) == 0)
6615 {
6616 if (*option == '+')
6617 {
6618 (void) SetImageOption(image_info,option+1,"0.0");
6619 break;
6620 }
6621 (void) SetImageOption(image_info,option+1,argv[i+1]);
6622 break;
6623 }
6624 break;
6625 }
6626 case 'i':
6627 {
6628 if (LocaleCompare("intent",option+1) == 0)
6629 {
6630 if (*option == '+')
6631 {
6632 (void) SetImageOption(image_info,option+1,"undefined");
6633 break;
6634 }
6635 (void) SetImageOption(image_info,option+1,argv[i+1]);
6636 break;
6637 }
6638 if (LocaleCompare("interlace",option+1) == 0)
6639 {
6640 if (*option == '+')
6641 {
6642 image_info->interlace=UndefinedInterlace;
6643 (void) SetImageOption(image_info,option+1,"undefined");
6644 break;
6645 }
cristy042ee782011-04-22 18:48:30 +00006646 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006647 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6648 (void) SetImageOption(image_info,option+1,argv[i+1]);
6649 break;
6650 }
cristyb32b90a2009-09-07 21:45:48 +00006651 if (LocaleCompare("interline-spacing",option+1) == 0)
6652 {
6653 if (*option == '+')
6654 {
6655 (void) SetImageOption(image_info,option+1,"undefined");
6656 break;
6657 }
6658 (void) SetImageOption(image_info,option+1,argv[i+1]);
6659 break;
6660 }
cristy3ed852e2009-09-05 21:47:34 +00006661 if (LocaleCompare("interpolate",option+1) == 0)
6662 {
6663 if (*option == '+')
6664 {
6665 (void) SetImageOption(image_info,option+1,"undefined");
6666 break;
6667 }
6668 (void) SetImageOption(image_info,option+1,argv[i+1]);
6669 break;
6670 }
6671 if (LocaleCompare("interword-spacing",option+1) == 0)
6672 {
6673 if (*option == '+')
6674 {
6675 (void) SetImageOption(image_info,option+1,"undefined");
6676 break;
6677 }
6678 (void) SetImageOption(image_info,option+1,argv[i+1]);
6679 break;
6680 }
6681 break;
6682 }
6683 case 'k':
6684 {
6685 if (LocaleCompare("kerning",option+1) == 0)
6686 {
6687 if (*option == '+')
6688 {
6689 (void) SetImageOption(image_info,option+1,"undefined");
6690 break;
6691 }
6692 (void) SetImageOption(image_info,option+1,argv[i+1]);
6693 break;
6694 }
6695 break;
6696 }
6697 case 'l':
6698 {
6699 if (LocaleCompare("label",option+1) == 0)
6700 {
6701 if (*option == '+')
6702 {
6703 (void) DeleteImageOption(image_info,option+1);
6704 break;
6705 }
6706 (void) SetImageOption(image_info,option+1,argv[i+1]);
6707 break;
6708 }
6709 if (LocaleCompare("limit",option+1) == 0)
6710 {
6711 MagickSizeType
6712 limit;
6713
6714 ResourceType
6715 type;
6716
6717 if (*option == '+')
6718 break;
cristy042ee782011-04-22 18:48:30 +00006719 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006720 MagickFalse,argv[i+1]);
6721 limit=MagickResourceInfinity;
6722 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006723 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006724 (void) SetMagickResourceLimit(type,limit);
6725 break;
6726 }
6727 if (LocaleCompare("list",option+1) == 0)
6728 {
cristybb503372010-05-27 20:51:26 +00006729 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006730 list;
6731
6732 /*
6733 Display configuration list.
6734 */
cristy042ee782011-04-22 18:48:30 +00006735 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006736 switch (list)
6737 {
6738 case MagickCoderOptions:
6739 {
6740 (void) ListCoderInfo((FILE *) NULL,exception);
6741 break;
6742 }
6743 case MagickColorOptions:
6744 {
6745 (void) ListColorInfo((FILE *) NULL,exception);
6746 break;
6747 }
6748 case MagickConfigureOptions:
6749 {
6750 (void) ListConfigureInfo((FILE *) NULL,exception);
6751 break;
6752 }
6753 case MagickDelegateOptions:
6754 {
6755 (void) ListDelegateInfo((FILE *) NULL,exception);
6756 break;
6757 }
6758 case MagickFontOptions:
6759 {
6760 (void) ListTypeInfo((FILE *) NULL,exception);
6761 break;
6762 }
6763 case MagickFormatOptions:
6764 {
6765 (void) ListMagickInfo((FILE *) NULL,exception);
6766 break;
6767 }
6768 case MagickLocaleOptions:
6769 {
6770 (void) ListLocaleInfo((FILE *) NULL,exception);
6771 break;
6772 }
6773 case MagickLogOptions:
6774 {
6775 (void) ListLogInfo((FILE *) NULL,exception);
6776 break;
6777 }
6778 case MagickMagicOptions:
6779 {
6780 (void) ListMagicInfo((FILE *) NULL,exception);
6781 break;
6782 }
6783 case MagickMimeOptions:
6784 {
6785 (void) ListMimeInfo((FILE *) NULL,exception);
6786 break;
6787 }
6788 case MagickModuleOptions:
6789 {
6790 (void) ListModuleInfo((FILE *) NULL,exception);
6791 break;
6792 }
6793 case MagickPolicyOptions:
6794 {
6795 (void) ListPolicyInfo((FILE *) NULL,exception);
6796 break;
6797 }
6798 case MagickResourceOptions:
6799 {
6800 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6801 break;
6802 }
6803 case MagickThresholdOptions:
6804 {
6805 (void) ListThresholdMaps((FILE *) NULL,exception);
6806 break;
6807 }
6808 default:
6809 {
cristy042ee782011-04-22 18:48:30 +00006810 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006811 exception);
6812 break;
6813 }
6814 }
cristyaeb2cbc2010-05-07 13:28:58 +00006815 break;
cristy3ed852e2009-09-05 21:47:34 +00006816 }
6817 if (LocaleCompare("log",option+1) == 0)
6818 {
6819 if (*option == '+')
6820 break;
6821 (void) SetLogFormat(argv[i+1]);
6822 break;
6823 }
6824 if (LocaleCompare("loop",option+1) == 0)
6825 {
6826 if (*option == '+')
6827 {
6828 (void) SetImageOption(image_info,option+1,"0");
6829 break;
6830 }
6831 (void) SetImageOption(image_info,option+1,argv[i+1]);
6832 break;
6833 }
6834 break;
6835 }
6836 case 'm':
6837 {
6838 if (LocaleCompare("matte",option+1) == 0)
6839 {
6840 if (*option == '+')
6841 {
6842 (void) SetImageOption(image_info,option+1,"false");
6843 break;
6844 }
6845 (void) SetImageOption(image_info,option+1,"true");
6846 break;
6847 }
6848 if (LocaleCompare("mattecolor",option+1) == 0)
6849 {
6850 if (*option == '+')
6851 {
6852 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006853 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006854 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006855 break;
6856 }
6857 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006858 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6859 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006860 break;
6861 }
6862 if (LocaleCompare("monitor",option+1) == 0)
6863 {
6864 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6865 (void *) NULL);
6866 break;
6867 }
6868 if (LocaleCompare("monochrome",option+1) == 0)
6869 {
6870 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6871 break;
6872 }
6873 break;
6874 }
6875 case 'o':
6876 {
6877 if (LocaleCompare("orient",option+1) == 0)
6878 {
6879 if (*option == '+')
6880 {
6881 image_info->orientation=UndefinedOrientation;
6882 (void) SetImageOption(image_info,option+1,"undefined");
6883 break;
6884 }
cristy042ee782011-04-22 18:48:30 +00006885 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006886 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006887 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006888 break;
6889 }
6890 }
6891 case 'p':
6892 {
6893 if (LocaleCompare("page",option+1) == 0)
6894 {
6895 char
6896 *canonical_page,
6897 page[MaxTextExtent];
6898
6899 const char
6900 *image_option;
6901
6902 MagickStatusType
6903 flags;
6904
6905 RectangleInfo
6906 geometry;
6907
6908 if (*option == '+')
6909 {
6910 (void) DeleteImageOption(image_info,option+1);
6911 (void) CloneString(&image_info->page,(char *) NULL);
6912 break;
6913 }
6914 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6915 image_option=GetImageOption(image_info,"page");
6916 if (image_option != (const char *) NULL)
6917 flags=ParseAbsoluteGeometry(image_option,&geometry);
6918 canonical_page=GetPageGeometry(argv[i+1]);
6919 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6920 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006921 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006922 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006923 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006924 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006925 (unsigned long) geometry.width,(unsigned long) geometry.height,
6926 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006927 (void) SetImageOption(image_info,option+1,page);
6928 (void) CloneString(&image_info->page,page);
6929 break;
6930 }
cristy3ed852e2009-09-05 21:47:34 +00006931 if (LocaleCompare("ping",option+1) == 0)
6932 {
6933 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6934 break;
6935 }
6936 if (LocaleCompare("pointsize",option+1) == 0)
6937 {
6938 if (*option == '+')
6939 geometry_info.rho=0.0;
6940 else
6941 (void) ParseGeometry(argv[i+1],&geometry_info);
6942 image_info->pointsize=geometry_info.rho;
6943 break;
6944 }
cristye7f51092010-01-17 00:39:37 +00006945 if (LocaleCompare("precision",option+1) == 0)
6946 {
cristybf2766a2010-01-17 03:33:23 +00006947 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006948 break;
6949 }
cristy3ed852e2009-09-05 21:47:34 +00006950 if (LocaleCompare("preview",option+1) == 0)
6951 {
6952 /*
6953 Preview image.
6954 */
6955 if (*option == '+')
6956 {
6957 image_info->preview_type=UndefinedPreview;
6958 break;
6959 }
cristy042ee782011-04-22 18:48:30 +00006960 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006961 MagickPreviewOptions,MagickFalse,argv[i+1]);
6962 break;
6963 }
6964 break;
6965 }
6966 case 'q':
6967 {
6968 if (LocaleCompare("quality",option+1) == 0)
6969 {
6970 /*
6971 Set image compression quality.
6972 */
6973 if (*option == '+')
6974 {
6975 image_info->quality=UndefinedCompressionQuality;
6976 (void) SetImageOption(image_info,option+1,"0");
6977 break;
6978 }
cristye27293e2009-12-18 02:53:20 +00006979 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006980 (void) SetImageOption(image_info,option+1,argv[i+1]);
6981 break;
6982 }
6983 if (LocaleCompare("quiet",option+1) == 0)
6984 {
6985 static WarningHandler
6986 warning_handler = (WarningHandler) NULL;
6987
6988 if (*option == '+')
6989 {
6990 /*
6991 Restore error or warning messages.
6992 */
6993 warning_handler=SetWarningHandler(warning_handler);
6994 break;
6995 }
6996 /*
6997 Suppress error or warning messages.
6998 */
6999 warning_handler=SetWarningHandler((WarningHandler) NULL);
7000 break;
7001 }
7002 break;
7003 }
7004 case 'r':
7005 {
7006 if (LocaleCompare("red-primary",option+1) == 0)
7007 {
7008 if (*option == '+')
7009 {
7010 (void) SetImageOption(image_info,option+1,"0.0");
7011 break;
7012 }
7013 (void) SetImageOption(image_info,option+1,argv[i+1]);
7014 break;
7015 }
7016 break;
7017 }
7018 case 's':
7019 {
7020 if (LocaleCompare("sampling-factor",option+1) == 0)
7021 {
7022 /*
7023 Set image sampling factor.
7024 */
7025 if (*option == '+')
7026 {
7027 if (image_info->sampling_factor != (char *) NULL)
7028 image_info->sampling_factor=DestroyString(
7029 image_info->sampling_factor);
7030 break;
7031 }
7032 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7033 break;
7034 }
7035 if (LocaleCompare("scene",option+1) == 0)
7036 {
7037 /*
7038 Set image scene.
7039 */
7040 if (*option == '+')
7041 {
7042 image_info->scene=0;
7043 (void) SetImageOption(image_info,option+1,"0");
7044 break;
7045 }
cristye27293e2009-12-18 02:53:20 +00007046 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007047 (void) SetImageOption(image_info,option+1,argv[i+1]);
7048 break;
7049 }
7050 if (LocaleCompare("seed",option+1) == 0)
7051 {
cristybb503372010-05-27 20:51:26 +00007052 size_t
cristy3ed852e2009-09-05 21:47:34 +00007053 seed;
7054
7055 if (*option == '+')
7056 {
cristybb503372010-05-27 20:51:26 +00007057 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007058 SeedPseudoRandomGenerator(seed);
7059 break;
7060 }
cristye27293e2009-12-18 02:53:20 +00007061 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007062 SeedPseudoRandomGenerator(seed);
7063 break;
7064 }
7065 if (LocaleCompare("size",option+1) == 0)
7066 {
7067 if (*option == '+')
7068 {
7069 if (image_info->size != (char *) NULL)
7070 image_info->size=DestroyString(image_info->size);
7071 break;
7072 }
7073 (void) CloneString(&image_info->size,argv[i+1]);
7074 break;
7075 }
7076 if (LocaleCompare("stroke",option+1) == 0)
7077 {
7078 if (*option == '+')
7079 {
7080 (void) SetImageOption(image_info,option+1,"none");
7081 break;
7082 }
7083 (void) SetImageOption(image_info,option+1,argv[i+1]);
7084 break;
7085 }
7086 if (LocaleCompare("strokewidth",option+1) == 0)
7087 {
7088 if (*option == '+')
7089 {
7090 (void) SetImageOption(image_info,option+1,"0");
7091 break;
7092 }
7093 (void) SetImageOption(image_info,option+1,argv[i+1]);
7094 break;
7095 }
cristyd9a29192010-10-16 16:49:53 +00007096 if (LocaleCompare("synchronize",option+1) == 0)
7097 {
7098 if (*option == '+')
7099 {
7100 image_info->synchronize=MagickFalse;
7101 break;
7102 }
7103 image_info->synchronize=MagickTrue;
7104 break;
7105 }
cristy3ed852e2009-09-05 21:47:34 +00007106 break;
7107 }
7108 case 't':
7109 {
7110 if (LocaleCompare("taint",option+1) == 0)
7111 {
7112 if (*option == '+')
7113 {
7114 (void) SetImageOption(image_info,option+1,"false");
7115 break;
7116 }
7117 (void) SetImageOption(image_info,option+1,"true");
7118 break;
7119 }
7120 if (LocaleCompare("texture",option+1) == 0)
7121 {
7122 if (*option == '+')
7123 {
7124 if (image_info->texture != (char *) NULL)
7125 image_info->texture=DestroyString(image_info->texture);
7126 break;
7127 }
7128 (void) CloneString(&image_info->texture,argv[i+1]);
7129 break;
7130 }
7131 if (LocaleCompare("tile-offset",option+1) == 0)
7132 {
7133 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007134 (void) SetImageOption(image_info,option+1,"0");
7135 else
7136 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007137 break;
7138 }
7139 if (LocaleCompare("transparent-color",option+1) == 0)
7140 {
7141 if (*option == '+')
7142 {
cristy9950d572011-10-01 18:22:35 +00007143 (void) QueryColorCompliance("none",AllCompliance,
7144 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007145 (void) SetImageOption(image_info,option+1,"none");
7146 break;
7147 }
cristy9950d572011-10-01 18:22:35 +00007148 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7149 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007150 (void) SetImageOption(image_info,option+1,argv[i+1]);
7151 break;
7152 }
7153 if (LocaleCompare("type",option+1) == 0)
7154 {
7155 if (*option == '+')
7156 {
cristy5f1c1ff2010-12-23 21:38:06 +00007157 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007158 (void) SetImageOption(image_info,option+1,"undefined");
7159 break;
7160 }
cristy042ee782011-04-22 18:48:30 +00007161 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007162 MagickFalse,argv[i+1]);
7163 (void) SetImageOption(image_info,option+1,argv[i+1]);
7164 break;
7165 }
7166 break;
7167 }
7168 case 'u':
7169 {
7170 if (LocaleCompare("undercolor",option+1) == 0)
7171 {
7172 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007173 (void) DeleteImageOption(image_info,option+1);
7174 else
7175 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007176 break;
7177 }
7178 if (LocaleCompare("units",option+1) == 0)
7179 {
7180 if (*option == '+')
7181 {
7182 image_info->units=UndefinedResolution;
7183 (void) SetImageOption(image_info,option+1,"undefined");
7184 break;
7185 }
cristy042ee782011-04-22 18:48:30 +00007186 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007187 MagickResolutionOptions,MagickFalse,argv[i+1]);
7188 (void) SetImageOption(image_info,option+1,argv[i+1]);
7189 break;
7190 }
7191 break;
7192 }
7193 case 'v':
7194 {
7195 if (LocaleCompare("verbose",option+1) == 0)
7196 {
7197 if (*option == '+')
7198 {
7199 image_info->verbose=MagickFalse;
7200 break;
7201 }
7202 image_info->verbose=MagickTrue;
7203 image_info->ping=MagickFalse;
7204 break;
7205 }
7206 if (LocaleCompare("view",option+1) == 0)
7207 {
7208 if (*option == '+')
7209 {
7210 if (image_info->view != (char *) NULL)
7211 image_info->view=DestroyString(image_info->view);
7212 break;
7213 }
7214 (void) CloneString(&image_info->view,argv[i+1]);
7215 break;
7216 }
7217 if (LocaleCompare("virtual-pixel",option+1) == 0)
7218 {
7219 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007220 (void) SetImageOption(image_info,option+1,"undefined");
7221 else
7222 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007223 break;
7224 }
7225 break;
7226 }
7227 case 'w':
7228 {
7229 if (LocaleCompare("white-point",option+1) == 0)
7230 {
7231 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007232 (void) SetImageOption(image_info,option+1,"0.0");
7233 else
7234 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007235 break;
7236 }
7237 break;
7238 }
7239 default:
7240 break;
7241 }
7242 i+=count;
7243 }
7244 return(MagickTrue);
7245}
7246
7247/*
7248%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7249% %
7250% %
7251% %
7252+ M o g r i f y I m a g e L i s t %
7253% %
7254% %
7255% %
7256%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7257%
7258% MogrifyImageList() applies any command line options that might affect the
7259% entire image list (e.g. -append, -coalesce, etc.).
7260%
7261% The format of the MogrifyImage method is:
7262%
7263% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7264% const char **argv,Image **images,ExceptionInfo *exception)
7265%
7266% A description of each parameter follows:
7267%
7268% o image_info: the image info..
7269%
7270% o argc: Specifies a pointer to an integer describing the number of
7271% elements in the argument vector.
7272%
7273% o argv: Specifies a pointer to a text array containing the command line
7274% arguments.
7275%
anthonye9c27192011-03-27 08:07:06 +00007276% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007277%
7278% o exception: return any errors or warnings in this structure.
7279%
7280*/
7281WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7282 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7283{
cristy3ed852e2009-09-05 21:47:34 +00007284 const char
7285 *option;
7286
cristy6b3da3a2010-06-20 02:21:46 +00007287 ImageInfo
7288 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007289
7290 MagickStatusType
7291 status;
7292
cristy28474bf2011-09-11 23:32:52 +00007293 PixelInterpolateMethod
7294 interpolate_method;
7295
cristy3ed852e2009-09-05 21:47:34 +00007296 QuantizeInfo
7297 *quantize_info;
7298
cristybb503372010-05-27 20:51:26 +00007299 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007300 i;
7301
cristy6b3da3a2010-06-20 02:21:46 +00007302 ssize_t
7303 count,
7304 index;
7305
cristy3ed852e2009-09-05 21:47:34 +00007306 /*
7307 Apply options to the image list.
7308 */
7309 assert(image_info != (ImageInfo *) NULL);
7310 assert(image_info->signature == MagickSignature);
7311 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007312 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007313 assert((*images)->signature == MagickSignature);
7314 if ((*images)->debug != MagickFalse)
7315 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7316 (*images)->filename);
7317 if ((argc <= 0) || (*argv == (char *) NULL))
7318 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007319 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007320 mogrify_info=CloneImageInfo(image_info);
7321 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007322 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007323 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007324 {
cristy74fe8f12009-10-03 19:09:01 +00007325 if (*images == (Image *) NULL)
7326 break;
cristy3ed852e2009-09-05 21:47:34 +00007327 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007328 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007329 continue;
cristy042ee782011-04-22 18:48:30 +00007330 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007331 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007332 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007333 break;
cristy6b3da3a2010-06-20 02:21:46 +00007334 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007335 switch (*(option+1))
7336 {
7337 case 'a':
7338 {
7339 if (LocaleCompare("affinity",option+1) == 0)
7340 {
cristy6fccee12011-10-20 18:43:18 +00007341 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007342 if (*option == '+')
7343 {
cristy018f07f2011-09-04 21:15:19 +00007344 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7345 exception);
cristy3ed852e2009-09-05 21:47:34 +00007346 break;
7347 }
7348 i++;
7349 break;
7350 }
7351 if (LocaleCompare("append",option+1) == 0)
7352 {
7353 Image
7354 *append_image;
7355
cristy6fccee12011-10-20 18:43:18 +00007356 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007357 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7358 MagickFalse,exception);
7359 if (append_image == (Image *) NULL)
7360 {
7361 status=MagickFalse;
7362 break;
7363 }
7364 *images=DestroyImageList(*images);
7365 *images=append_image;
7366 break;
7367 }
7368 if (LocaleCompare("average",option+1) == 0)
7369 {
7370 Image
7371 *average_image;
7372
cristyd18ae7c2010-03-07 17:39:52 +00007373 /*
7374 Average an image sequence (deprecated).
7375 */
cristy6fccee12011-10-20 18:43:18 +00007376 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007377 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7378 exception);
cristy3ed852e2009-09-05 21:47:34 +00007379 if (average_image == (Image *) NULL)
7380 {
7381 status=MagickFalse;
7382 break;
7383 }
7384 *images=DestroyImageList(*images);
7385 *images=average_image;
7386 break;
7387 }
7388 break;
7389 }
7390 case 'c':
7391 {
cristy87c02f42012-02-24 00:19:10 +00007392 if (LocaleCompare("channel-inject",option+1) == 0)
7393 {
7394 puts("stand by...");
7395 break;
7396 }
cristy3ed852e2009-09-05 21:47:34 +00007397 if (LocaleCompare("clut",option+1) == 0)
7398 {
7399 Image
7400 *clut_image,
7401 *image;
7402
cristy6fccee12011-10-20 18:43:18 +00007403 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007404 image=RemoveFirstImageFromList(images);
7405 clut_image=RemoveFirstImageFromList(images);
7406 if (clut_image == (Image *) NULL)
7407 {
7408 status=MagickFalse;
7409 break;
7410 }
cristy28474bf2011-09-11 23:32:52 +00007411 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007412 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007413 *images=DestroyImageList(*images);
7414 *images=image;
7415 break;
7416 }
7417 if (LocaleCompare("coalesce",option+1) == 0)
7418 {
7419 Image
7420 *coalesce_image;
7421
cristy6fccee12011-10-20 18:43:18 +00007422 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007423 coalesce_image=CoalesceImages(*images,exception);
7424 if (coalesce_image == (Image *) NULL)
7425 {
7426 status=MagickFalse;
7427 break;
7428 }
7429 *images=DestroyImageList(*images);
7430 *images=coalesce_image;
7431 break;
7432 }
7433 if (LocaleCompare("combine",option+1) == 0)
7434 {
7435 Image
7436 *combine_image;
7437
cristy6fccee12011-10-20 18:43:18 +00007438 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007439 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007440 if (combine_image == (Image *) NULL)
7441 {
7442 status=MagickFalse;
7443 break;
7444 }
7445 *images=DestroyImageList(*images);
7446 *images=combine_image;
7447 break;
7448 }
7449 if (LocaleCompare("composite",option+1) == 0)
7450 {
7451 Image
7452 *mask_image,
7453 *composite_image,
7454 *image;
7455
7456 RectangleInfo
7457 geometry;
7458
cristy6fccee12011-10-20 18:43:18 +00007459 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007460 image=RemoveFirstImageFromList(images);
7461 composite_image=RemoveFirstImageFromList(images);
7462 if (composite_image == (Image *) NULL)
7463 {
7464 status=MagickFalse;
7465 break;
7466 }
7467 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007468 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007469 SetGeometry(composite_image,&geometry);
7470 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7471 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7472 &geometry);
7473 mask_image=RemoveFirstImageFromList(images);
7474 if (mask_image != (Image *) NULL)
7475 {
7476 if ((image->compose == DisplaceCompositeOp) ||
7477 (image->compose == DistortCompositeOp))
7478 {
7479 /*
7480 Merge Y displacement into X displacement image.
7481 */
7482 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007483 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007484 mask_image=DestroyImage(mask_image);
7485 }
7486 else
7487 {
7488 /*
anthony80c37752012-01-16 01:03:11 +00007489 Set a blending mask for the composition.
cristy3ed852e2009-09-05 21:47:34 +00007490 */
cristy10a6c612012-01-29 21:41:05 +00007491 (void) NegateImage(mask_image,MagickFalse,exception);
7492 (void) SetImageMask(image,mask_image,exception);
7493 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00007494 }
7495 }
cristyf4ad9df2011-07-08 16:49:03 +00007496 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007497 geometry.x,geometry.y,exception);
cristy10a6c612012-01-29 21:41:05 +00007498 (void) SetImageMask(image,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00007499 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007500 *images=DestroyImageList(*images);
7501 *images=image;
7502 break;
7503 }
cristy3ed852e2009-09-05 21:47:34 +00007504 break;
7505 }
7506 case 'd':
7507 {
7508 if (LocaleCompare("deconstruct",option+1) == 0)
7509 {
7510 Image
7511 *deconstruct_image;
7512
cristy6fccee12011-10-20 18:43:18 +00007513 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007514 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007515 exception);
cristy3ed852e2009-09-05 21:47:34 +00007516 if (deconstruct_image == (Image *) NULL)
7517 {
7518 status=MagickFalse;
7519 break;
7520 }
7521 *images=DestroyImageList(*images);
7522 *images=deconstruct_image;
7523 break;
7524 }
7525 if (LocaleCompare("delete",option+1) == 0)
7526 {
7527 if (*option == '+')
7528 DeleteImages(images,"-1",exception);
7529 else
7530 DeleteImages(images,argv[i+1],exception);
7531 break;
7532 }
7533 if (LocaleCompare("dither",option+1) == 0)
7534 {
7535 if (*option == '+')
7536 {
7537 quantize_info->dither=MagickFalse;
7538 break;
7539 }
7540 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007541 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007542 MagickDitherOptions,MagickFalse,argv[i+1]);
7543 break;
7544 }
cristyecb10ff2011-03-22 13:14:03 +00007545 if (LocaleCompare("duplicate",option+1) == 0)
7546 {
cristy72988482011-03-29 16:34:38 +00007547 Image
7548 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007549
anthony2b6bcae2011-03-23 13:05:34 +00007550 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007551 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7552 else
7553 {
7554 const char
7555 *p;
7556
anthony2b6bcae2011-03-23 13:05:34 +00007557 size_t
7558 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007559
anthony2b6bcae2011-03-23 13:05:34 +00007560 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007561 p=strchr(argv[i+1],',');
7562 if (p == (const char *) NULL)
7563 duplicate_images=DuplicateImages(*images,number_duplicates,
7564 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007565 else
cristy72988482011-03-29 16:34:38 +00007566 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7567 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007568 }
7569 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007570 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007571 break;
7572 }
cristy3ed852e2009-09-05 21:47:34 +00007573 break;
7574 }
cristyd18ae7c2010-03-07 17:39:52 +00007575 case 'e':
7576 {
7577 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7578 {
7579 Image
7580 *evaluate_image;
7581
7582 MagickEvaluateOperator
7583 op;
7584
cristy6fccee12011-10-20 18:43:18 +00007585 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007586 op=(MagickEvaluateOperator) ParseCommandOption(
7587 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007588 evaluate_image=EvaluateImages(*images,op,exception);
7589 if (evaluate_image == (Image *) NULL)
7590 {
7591 status=MagickFalse;
7592 break;
7593 }
7594 *images=DestroyImageList(*images);
7595 *images=evaluate_image;
7596 break;
7597 }
7598 break;
7599 }
cristy3ed852e2009-09-05 21:47:34 +00007600 case 'f':
7601 {
cristyf0a247f2009-10-04 00:20:03 +00007602 if (LocaleCompare("fft",option+1) == 0)
7603 {
7604 Image
7605 *fourier_image;
7606
7607 /*
7608 Implements the discrete Fourier transform (DFT).
7609 */
cristy6fccee12011-10-20 18:43:18 +00007610 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007611 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7612 MagickTrue : MagickFalse,exception);
7613 if (fourier_image == (Image *) NULL)
7614 break;
7615 *images=DestroyImage(*images);
7616 *images=fourier_image;
7617 break;
7618 }
cristy3ed852e2009-09-05 21:47:34 +00007619 if (LocaleCompare("flatten",option+1) == 0)
7620 {
7621 Image
7622 *flatten_image;
7623
cristy6fccee12011-10-20 18:43:18 +00007624 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007625 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7626 if (flatten_image == (Image *) NULL)
7627 break;
7628 *images=DestroyImageList(*images);
7629 *images=flatten_image;
7630 break;
7631 }
7632 if (LocaleCompare("fx",option+1) == 0)
7633 {
7634 Image
7635 *fx_image;
7636
cristy6fccee12011-10-20 18:43:18 +00007637 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007638 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007639 if (fx_image == (Image *) NULL)
7640 {
7641 status=MagickFalse;
7642 break;
7643 }
7644 *images=DestroyImageList(*images);
7645 *images=fx_image;
7646 break;
7647 }
7648 break;
7649 }
7650 case 'h':
7651 {
7652 if (LocaleCompare("hald-clut",option+1) == 0)
7653 {
7654 Image
7655 *hald_image,
7656 *image;
7657
cristy6fccee12011-10-20 18:43:18 +00007658 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007659 image=RemoveFirstImageFromList(images);
7660 hald_image=RemoveFirstImageFromList(images);
7661 if (hald_image == (Image *) NULL)
7662 {
7663 status=MagickFalse;
7664 break;
7665 }
cristy7c0a0a42011-08-23 17:57:25 +00007666 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007667 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007668 if (*images != (Image *) NULL)
7669 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007670 *images=image;
7671 break;
7672 }
7673 break;
7674 }
7675 case 'i':
7676 {
7677 if (LocaleCompare("ift",option+1) == 0)
7678 {
7679 Image
cristy8587f882009-11-13 20:28:49 +00007680 *fourier_image,
7681 *magnitude_image,
7682 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007683
7684 /*
7685 Implements the inverse fourier discrete Fourier transform (DFT).
7686 */
cristy6fccee12011-10-20 18:43:18 +00007687 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007688 magnitude_image=RemoveFirstImageFromList(images);
7689 phase_image=RemoveFirstImageFromList(images);
7690 if (phase_image == (Image *) NULL)
7691 {
7692 status=MagickFalse;
7693 break;
7694 }
7695 fourier_image=InverseFourierTransformImage(magnitude_image,
7696 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007697 if (fourier_image == (Image *) NULL)
7698 break;
cristy0aff6ea2009-11-14 01:40:53 +00007699 if (*images != (Image *) NULL)
7700 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007701 *images=fourier_image;
7702 break;
7703 }
7704 if (LocaleCompare("insert",option+1) == 0)
7705 {
7706 Image
7707 *p,
7708 *q;
7709
7710 index=0;
7711 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007712 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007713 p=RemoveLastImageFromList(images);
7714 if (p == (Image *) NULL)
7715 {
7716 (void) ThrowMagickException(exception,GetMagickModule(),
7717 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7718 status=MagickFalse;
7719 break;
7720 }
7721 q=p;
7722 if (index == 0)
7723 PrependImageToList(images,q);
7724 else
cristybb503372010-05-27 20:51:26 +00007725 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007726 AppendImageToList(images,q);
7727 else
7728 {
7729 q=GetImageFromList(*images,index-1);
7730 if (q == (Image *) NULL)
7731 {
7732 (void) ThrowMagickException(exception,GetMagickModule(),
7733 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7734 status=MagickFalse;
7735 break;
7736 }
7737 InsertImageInList(&q,p);
7738 }
7739 *images=GetFirstImageInList(q);
7740 break;
7741 }
cristy28474bf2011-09-11 23:32:52 +00007742 if (LocaleCompare("interpolate",option+1) == 0)
7743 {
7744 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7745 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7746 break;
7747 }
cristy3ed852e2009-09-05 21:47:34 +00007748 break;
7749 }
7750 case 'l':
7751 {
7752 if (LocaleCompare("layers",option+1) == 0)
7753 {
7754 Image
7755 *layers;
7756
7757 ImageLayerMethod
7758 method;
7759
cristy6fccee12011-10-20 18:43:18 +00007760 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007761 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007762 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007763 MagickFalse,argv[i+1]);
7764 switch (method)
7765 {
7766 case CoalesceLayer:
7767 {
7768 layers=CoalesceImages(*images,exception);
7769 break;
7770 }
7771 case CompareAnyLayer:
7772 case CompareClearLayer:
7773 case CompareOverlayLayer:
7774 default:
7775 {
cristy8a9106f2011-07-05 14:39:26 +00007776 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007777 break;
7778 }
7779 case MergeLayer:
7780 case FlattenLayer:
7781 case MosaicLayer:
7782 case TrimBoundsLayer:
7783 {
7784 layers=MergeImageLayers(*images,method,exception);
7785 break;
7786 }
7787 case DisposeLayer:
7788 {
7789 layers=DisposeImages(*images,exception);
7790 break;
7791 }
7792 case OptimizeImageLayer:
7793 {
7794 layers=OptimizeImageLayers(*images,exception);
7795 break;
7796 }
7797 case OptimizePlusLayer:
7798 {
7799 layers=OptimizePlusImageLayers(*images,exception);
7800 break;
7801 }
7802 case OptimizeTransLayer:
7803 {
7804 OptimizeImageTransparency(*images,exception);
7805 break;
7806 }
7807 case RemoveDupsLayer:
7808 {
7809 RemoveDuplicateLayers(images,exception);
7810 break;
7811 }
7812 case RemoveZeroLayer:
7813 {
7814 RemoveZeroDelayLayers(images,exception);
7815 break;
7816 }
7817 case OptimizeLayer:
7818 {
7819 /*
7820 General Purpose, GIF Animation Optimizer.
7821 */
7822 layers=CoalesceImages(*images,exception);
7823 if (layers == (Image *) NULL)
7824 {
7825 status=MagickFalse;
7826 break;
7827 }
cristy3ed852e2009-09-05 21:47:34 +00007828 *images=DestroyImageList(*images);
7829 *images=layers;
7830 layers=OptimizeImageLayers(*images,exception);
7831 if (layers == (Image *) NULL)
7832 {
7833 status=MagickFalse;
7834 break;
7835 }
cristy3ed852e2009-09-05 21:47:34 +00007836 *images=DestroyImageList(*images);
7837 *images=layers;
7838 layers=(Image *) NULL;
7839 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007840 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7841 exception);
cristy3ed852e2009-09-05 21:47:34 +00007842 break;
7843 }
7844 case CompositeLayer:
7845 {
7846 CompositeOperator
7847 compose;
7848
7849 Image
7850 *source;
7851
7852 RectangleInfo
7853 geometry;
7854
7855 /*
7856 Split image sequence at the first 'NULL:' image.
7857 */
7858 source=(*images);
7859 while (source != (Image *) NULL)
7860 {
7861 source=GetNextImageInList(source);
7862 if ((source != (Image *) NULL) &&
7863 (LocaleCompare(source->magick,"NULL") == 0))
7864 break;
7865 }
7866 if (source != (Image *) NULL)
7867 {
7868 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7869 (GetNextImageInList(source) == (Image *) NULL))
7870 source=(Image *) NULL;
7871 else
7872 {
7873 /*
7874 Separate the two lists, junk the null: image.
7875 */
7876 source=SplitImageList(source->previous);
7877 DeleteImageFromList(&source);
7878 }
7879 }
7880 if (source == (Image *) NULL)
7881 {
7882 (void) ThrowMagickException(exception,GetMagickModule(),
7883 OptionError,"MissingNullSeparator","layers Composite");
7884 status=MagickFalse;
7885 break;
7886 }
7887 /*
7888 Adjust offset with gravity and virtual canvas.
7889 */
7890 SetGeometry(*images,&geometry);
7891 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7892 geometry.width=source->page.width != 0 ?
7893 source->page.width : source->columns;
7894 geometry.height=source->page.height != 0 ?
7895 source->page.height : source->rows;
7896 GravityAdjustGeometry((*images)->page.width != 0 ?
7897 (*images)->page.width : (*images)->columns,
7898 (*images)->page.height != 0 ? (*images)->page.height :
7899 (*images)->rows,(*images)->gravity,&geometry);
7900 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007901 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007902 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007903 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007904 MagickComposeOptions,MagickFalse,option);
7905 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7906 exception);
7907 source=DestroyImageList(source);
7908 break;
7909 }
7910 }
7911 if (layers == (Image *) NULL)
7912 break;
cristy3ed852e2009-09-05 21:47:34 +00007913 *images=DestroyImageList(*images);
7914 *images=layers;
7915 break;
7916 }
7917 break;
7918 }
7919 case 'm':
7920 {
7921 if (LocaleCompare("map",option+1) == 0)
7922 {
cristy6fccee12011-10-20 18:43:18 +00007923 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007924 if (*option == '+')
7925 {
cristy018f07f2011-09-04 21:15:19 +00007926 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7927 exception);
cristy3ed852e2009-09-05 21:47:34 +00007928 break;
7929 }
7930 i++;
7931 break;
7932 }
cristyf40785b2010-03-06 02:27:27 +00007933 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007934 {
7935 Image
cristyf40785b2010-03-06 02:27:27 +00007936 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007937
cristyd18ae7c2010-03-07 17:39:52 +00007938 /*
7939 Maximum image sequence (deprecated).
7940 */
cristy6fccee12011-10-20 18:43:18 +00007941 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007942 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007943 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007944 {
7945 status=MagickFalse;
7946 break;
7947 }
7948 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007949 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007950 break;
7951 }
cristyf40785b2010-03-06 02:27:27 +00007952 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007953 {
7954 Image
cristyf40785b2010-03-06 02:27:27 +00007955 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007956
cristyd18ae7c2010-03-07 17:39:52 +00007957 /*
7958 Minimum image sequence (deprecated).
7959 */
cristy6fccee12011-10-20 18:43:18 +00007960 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007961 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007962 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007963 {
7964 status=MagickFalse;
7965 break;
7966 }
7967 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007968 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007969 break;
7970 }
cristy3ed852e2009-09-05 21:47:34 +00007971 if (LocaleCompare("morph",option+1) == 0)
7972 {
7973 Image
7974 *morph_image;
7975
cristy6fccee12011-10-20 18:43:18 +00007976 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007977 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007978 exception);
7979 if (morph_image == (Image *) NULL)
7980 {
7981 status=MagickFalse;
7982 break;
7983 }
7984 *images=DestroyImageList(*images);
7985 *images=morph_image;
7986 break;
7987 }
7988 if (LocaleCompare("mosaic",option+1) == 0)
7989 {
7990 Image
7991 *mosaic_image;
7992
cristy6fccee12011-10-20 18:43:18 +00007993 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007994 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7995 if (mosaic_image == (Image *) NULL)
7996 {
7997 status=MagickFalse;
7998 break;
7999 }
8000 *images=DestroyImageList(*images);
8001 *images=mosaic_image;
8002 break;
8003 }
8004 break;
8005 }
8006 case 'p':
8007 {
8008 if (LocaleCompare("print",option+1) == 0)
8009 {
8010 char
8011 *string;
8012
cristy6fccee12011-10-20 18:43:18 +00008013 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00008014 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
8015 exception);
cristy3ed852e2009-09-05 21:47:34 +00008016 if (string == (char *) NULL)
8017 break;
cristyb51dff52011-05-19 16:55:47 +00008018 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008019 string=DestroyString(string);
8020 }
8021 if (LocaleCompare("process",option+1) == 0)
8022 {
8023 char
8024 **arguments;
8025
8026 int
8027 j,
8028 number_arguments;
8029
cristy6fccee12011-10-20 18:43:18 +00008030 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008031 arguments=StringToArgv(argv[i+1],&number_arguments);
8032 if (arguments == (char **) NULL)
8033 break;
8034 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8035 {
8036 char
8037 breaker,
8038 quote,
8039 *token;
8040
8041 const char
8042 *arguments;
8043
8044 int
8045 next,
8046 status;
8047
8048 size_t
8049 length;
8050
8051 TokenInfo
8052 *token_info;
8053
8054 /*
8055 Support old style syntax, filter="-option arg".
8056 */
8057 length=strlen(argv[i+1]);
8058 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008059 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008060 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8061 sizeof(*token));
8062 if (token == (char *) NULL)
8063 break;
8064 next=0;
8065 arguments=argv[i+1];
8066 token_info=AcquireTokenInfo();
8067 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8068 "\"",'\0',&breaker,&next,&quote);
8069 token_info=DestroyTokenInfo(token_info);
8070 if (status == 0)
8071 {
8072 const char
8073 *argv;
8074
8075 argv=(&(arguments[next]));
8076 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8077 exception);
8078 }
8079 token=DestroyString(token);
8080 break;
8081 }
cristy91c0da22010-05-02 01:44:07 +00008082 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008083 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8084 number_arguments-2,(const char **) arguments+2,exception);
8085 for (j=0; j < number_arguments; j++)
8086 arguments[j]=DestroyString(arguments[j]);
8087 arguments=(char **) RelinquishMagickMemory(arguments);
8088 break;
8089 }
8090 break;
8091 }
8092 case 'r':
8093 {
8094 if (LocaleCompare("reverse",option+1) == 0)
8095 {
8096 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008097 break;
8098 }
8099 break;
8100 }
8101 case 's':
8102 {
cristy4285d782011-02-09 20:12:28 +00008103 if (LocaleCompare("smush",option+1) == 0)
8104 {
8105 Image
8106 *smush_image;
8107
8108 ssize_t
8109 offset;
8110
cristy6fccee12011-10-20 18:43:18 +00008111 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008112 offset=(ssize_t) StringToLong(argv[i+1]);
8113 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8114 MagickFalse,offset,exception);
8115 if (smush_image == (Image *) NULL)
8116 {
8117 status=MagickFalse;
8118 break;
8119 }
8120 *images=DestroyImageList(*images);
8121 *images=smush_image;
8122 break;
8123 }
cristy3ed852e2009-09-05 21:47:34 +00008124 if (LocaleCompare("swap",option+1) == 0)
8125 {
8126 Image
8127 *p,
8128 *q,
8129 *swap;
8130
cristybb503372010-05-27 20:51:26 +00008131 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008132 swap_index;
8133
8134 index=(-1);
8135 swap_index=(-2);
8136 if (*option != '+')
8137 {
8138 GeometryInfo
8139 geometry_info;
8140
8141 MagickStatusType
8142 flags;
8143
8144 swap_index=(-1);
8145 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008146 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008147 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008148 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008149 }
8150 p=GetImageFromList(*images,index);
8151 q=GetImageFromList(*images,swap_index);
8152 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8153 {
8154 (void) ThrowMagickException(exception,GetMagickModule(),
8155 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8156 status=MagickFalse;
8157 break;
8158 }
8159 if (p == q)
8160 break;
8161 swap=CloneImage(p,0,0,MagickTrue,exception);
8162 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8163 ReplaceImageInList(&q,swap);
8164 *images=GetFirstImageInList(q);
8165 break;
8166 }
8167 break;
8168 }
8169 case 'w':
8170 {
8171 if (LocaleCompare("write",option+1) == 0)
8172 {
cristy071dd7b2010-04-09 13:04:54 +00008173 char
cristy06609ee2010-03-17 20:21:27 +00008174 key[MaxTextExtent];
8175
cristy3ed852e2009-09-05 21:47:34 +00008176 Image
8177 *write_images;
8178
8179 ImageInfo
8180 *write_info;
8181
cristy6fccee12011-10-20 18:43:18 +00008182 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008183 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008184 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008185 write_images=(*images);
8186 if (*option == '+')
8187 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008188 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008189 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8190 write_info=DestroyImageInfo(write_info);
8191 if (*option == '+')
8192 write_images=DestroyImageList(write_images);
8193 break;
8194 }
8195 break;
8196 }
8197 default:
8198 break;
8199 }
8200 i+=count;
8201 }
8202 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008203 mogrify_info=DestroyImageInfo(mogrify_info);
8204 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008205 return(status != 0 ? MagickTrue : MagickFalse);
8206}
8207
8208/*
8209%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8210% %
8211% %
8212% %
8213+ M o g r i f y I m a g e s %
8214% %
8215% %
8216% %
8217%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8218%
8219% MogrifyImages() applies image processing options to a sequence of images as
8220% prescribed by command line options.
8221%
8222% The format of the MogrifyImage method is:
8223%
8224% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8225% const MagickBooleanType post,const int argc,const char **argv,
8226% Image **images,Exceptioninfo *exception)
8227%
8228% A description of each parameter follows:
8229%
8230% o image_info: the image info..
8231%
8232% o post: If true, post process image list operators otherwise pre-process.
8233%
8234% o argc: Specifies a pointer to an integer describing the number of
8235% elements in the argument vector.
8236%
8237% o argv: Specifies a pointer to a text array containing the command line
8238% arguments.
8239%
anthonye9c27192011-03-27 08:07:06 +00008240% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008241%
8242% o exception: return any errors or warnings in this structure.
8243%
8244*/
8245WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8246 const MagickBooleanType post,const int argc,const char **argv,
8247 Image **images,ExceptionInfo *exception)
8248{
8249#define MogrifyImageTag "Mogrify/Image"
8250
anthonye9c27192011-03-27 08:07:06 +00008251 MagickStatusType
8252 status;
cristy3ed852e2009-09-05 21:47:34 +00008253
cristy0e9f9c12010-02-11 03:00:47 +00008254 MagickBooleanType
8255 proceed;
8256
anthonye9c27192011-03-27 08:07:06 +00008257 size_t
8258 n;
cristy3ed852e2009-09-05 21:47:34 +00008259
cristybb503372010-05-27 20:51:26 +00008260 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008261 i;
8262
cristy3ed852e2009-09-05 21:47:34 +00008263 assert(image_info != (ImageInfo *) NULL);
8264 assert(image_info->signature == MagickSignature);
8265 if (images == (Image **) NULL)
8266 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008267 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008268 assert((*images)->signature == MagickSignature);
8269 if ((*images)->debug != MagickFalse)
8270 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8271 (*images)->filename);
8272 if ((argc <= 0) || (*argv == (char *) NULL))
8273 return(MagickTrue);
8274 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8275 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008276 status=0;
anthonye9c27192011-03-27 08:07:06 +00008277
anthonyce2716b2011-04-22 09:51:34 +00008278#if 0
cristy1e604812011-05-19 18:07:50 +00008279 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8280 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008281#endif
8282
anthonye9c27192011-03-27 08:07:06 +00008283 /*
8284 Pre-process multi-image sequence operators
8285 */
cristy3ed852e2009-09-05 21:47:34 +00008286 if (post == MagickFalse)
8287 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008288 /*
8289 For each image, process simple single image operators
8290 */
8291 i=0;
8292 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008293 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008294 {
anthonyce2716b2011-04-22 09:51:34 +00008295#if 0
cristy1e604812011-05-19 18:07:50 +00008296 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8297 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008298#endif
anthonye9c27192011-03-27 08:07:06 +00008299 status&=MogrifyImage(image_info,argc,argv,images,exception);
8300 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008301 if (proceed == MagickFalse)
8302 break;
anthonye9c27192011-03-27 08:07:06 +00008303 if ( (*images)->next == (Image *) NULL )
8304 break;
8305 *images=(*images)->next;
8306 i++;
cristy3ed852e2009-09-05 21:47:34 +00008307 }
anthonye9c27192011-03-27 08:07:06 +00008308 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008309#if 0
cristy1e604812011-05-19 18:07:50 +00008310 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8311 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008312#endif
anthonye9c27192011-03-27 08:07:06 +00008313
8314 /*
8315 Post-process, multi-image sequence operators
8316 */
8317 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008318 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008319 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008320 return(status != 0 ? MagickTrue : MagickFalse);
8321}