blob: 26de50678d7b5dfd784143e0c25fd1a380a4272e [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"
cristy03e83172012-03-25 22:41:06 +000057
cristy3ed852e2009-09-05 21:47:34 +000058/*
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;
cristyf4ad9df2011-07-08 16:49:03 +0000752 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +0000753 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000754 break;
cristy3ed852e2009-09-05 21:47:34 +0000755 }
anthonydf8ebac2011-04-27 09:03:19 +0000756 if (LocaleCompare("adaptive-resize",option+1) == 0)
757 {
758 /*
759 Adaptive resize image.
760 */
cristy6fccee12011-10-20 18:43:18 +0000761 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000762 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
763 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
anthonyfd706f92012-01-19 04:22:02 +0000764 geometry.height,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000765 break;
766 }
767 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
768 {
769 /*
770 Adaptive sharpen image.
771 */
cristy6fccee12011-10-20 18:43:18 +0000772 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000773 flags=ParseGeometry(argv[i+1],&geometry_info);
774 if ((flags & SigmaValue) == 0)
775 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +0000776 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +0000777 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000778 break;
779 }
780 if (LocaleCompare("affine",option+1) == 0)
781 {
782 /*
783 Affine matrix.
784 */
785 if (*option == '+')
786 {
787 GetAffineMatrix(&draw_info->affine);
788 break;
789 }
790 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
791 break;
792 }
793 if (LocaleCompare("alpha",option+1) == 0)
794 {
795 AlphaChannelType
796 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000797
cristy6fccee12011-10-20 18:43:18 +0000798 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000799 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
800 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000801 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000802 break;
803 }
804 if (LocaleCompare("annotate",option+1) == 0)
805 {
806 char
807 *text,
808 geometry[MaxTextExtent];
809
810 /*
811 Annotate image.
812 */
cristy6fccee12011-10-20 18:43:18 +0000813 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000814 SetGeometryInfo(&geometry_info);
815 flags=ParseGeometry(argv[i+1],&geometry_info);
816 if ((flags & SigmaValue) == 0)
817 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000818 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
819 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000820 if (text == (char *) NULL)
821 break;
822 (void) CloneString(&draw_info->text,text);
823 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000824 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000825 geometry_info.xi,geometry_info.psi);
826 (void) CloneString(&draw_info->geometry,geometry);
827 draw_info->affine.sx=cos(DegreesToRadians(
828 fmod(geometry_info.rho,360.0)));
829 draw_info->affine.rx=sin(DegreesToRadians(
830 fmod(geometry_info.rho,360.0)));
831 draw_info->affine.ry=(-sin(DegreesToRadians(
832 fmod(geometry_info.sigma,360.0))));
833 draw_info->affine.sy=cos(DegreesToRadians(
834 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000835 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000836 break;
837 }
838 if (LocaleCompare("antialias",option+1) == 0)
839 {
840 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
841 MagickFalse;
842 draw_info->text_antialias=(*option == '-') ? MagickTrue :
843 MagickFalse;
844 break;
845 }
cristy9ed1f812011-10-08 02:00:08 +0000846 if (LocaleCompare("attenuate",option+1) == 0)
847 {
848 if (*option == '+')
849 {
850 attenuate=1.0;
851 break;
852 }
cristydbdd0e32011-11-04 23:29:40 +0000853 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000854 break;
855 }
anthonydf8ebac2011-04-27 09:03:19 +0000856 if (LocaleCompare("auto-gamma",option+1) == 0)
857 {
858 /*
859 Auto Adjust Gamma of image based on its mean
860 */
cristy6fccee12011-10-20 18:43:18 +0000861 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000862 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000863 break;
864 }
865 if (LocaleCompare("auto-level",option+1) == 0)
866 {
867 /*
868 Perfectly Normalize (max/min stretch) the image
869 */
cristy6fccee12011-10-20 18:43:18 +0000870 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000871 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000872 break;
873 }
874 if (LocaleCompare("auto-orient",option+1) == 0)
875 {
cristy6fccee12011-10-20 18:43:18 +0000876 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000877 switch ((*image)->orientation)
878 {
879 case TopRightOrientation:
880 {
881 mogrify_image=FlopImage(*image,exception);
882 break;
883 }
884 case BottomRightOrientation:
885 {
886 mogrify_image=RotateImage(*image,180.0,exception);
887 break;
888 }
889 case BottomLeftOrientation:
890 {
891 mogrify_image=FlipImage(*image,exception);
892 break;
893 }
894 case LeftTopOrientation:
895 {
896 mogrify_image=TransposeImage(*image,exception);
897 break;
898 }
899 case RightTopOrientation:
900 {
901 mogrify_image=RotateImage(*image,90.0,exception);
902 break;
903 }
904 case RightBottomOrientation:
905 {
906 mogrify_image=TransverseImage(*image,exception);
907 break;
908 }
909 case LeftBottomOrientation:
910 {
911 mogrify_image=RotateImage(*image,270.0,exception);
912 break;
913 }
914 default:
915 break;
916 }
917 if (mogrify_image != (Image *) NULL)
918 mogrify_image->orientation=TopLeftOrientation;
919 break;
920 }
921 break;
922 }
923 case 'b':
924 {
925 if (LocaleCompare("black-threshold",option+1) == 0)
926 {
927 /*
928 Black threshold image.
929 */
cristy6fccee12011-10-20 18:43:18 +0000930 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000931 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000932 break;
933 }
934 if (LocaleCompare("blue-shift",option+1) == 0)
935 {
936 /*
937 Blue shift image.
938 */
cristy6fccee12011-10-20 18:43:18 +0000939 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000940 geometry_info.rho=1.5;
941 if (*option == '-')
942 flags=ParseGeometry(argv[i+1],&geometry_info);
943 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
944 break;
945 }
946 if (LocaleCompare("blur",option+1) == 0)
947 {
948 /*
949 Gaussian blur image.
950 */
cristy6fccee12011-10-20 18:43:18 +0000951 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000952 flags=ParseGeometry(argv[i+1],&geometry_info);
953 if ((flags & SigmaValue) == 0)
954 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000955 if ((flags & XiValue) == 0)
956 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000957 mogrify_image=BlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +0000958 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000959 break;
960 }
961 if (LocaleCompare("border",option+1) == 0)
962 {
963 /*
964 Surround image with a border of solid color.
965 */
cristy6fccee12011-10-20 18:43:18 +0000966 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000967 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
968 if ((flags & SigmaValue) == 0)
969 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000970 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000971 break;
972 }
973 if (LocaleCompare("bordercolor",option+1) == 0)
974 {
975 if (*option == '+')
976 {
cristy9950d572011-10-01 18:22:35 +0000977 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000978 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000979 break;
980 }
cristy9950d572011-10-01 18:22:35 +0000981 (void) QueryColorCompliance(argv[i+1],AllCompliance,
982 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000983 break;
984 }
985 if (LocaleCompare("box",option+1) == 0)
986 {
cristy9950d572011-10-01 18:22:35 +0000987 (void) QueryColorCompliance(argv[i+1],AllCompliance,
988 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000989 break;
990 }
991 if (LocaleCompare("brightness-contrast",option+1) == 0)
992 {
993 double
994 brightness,
995 contrast;
996
997 GeometryInfo
998 geometry_info;
999
1000 MagickStatusType
1001 flags;
1002
1003 /*
1004 Brightness / contrast image.
1005 */
cristy6fccee12011-10-20 18:43:18 +00001006 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001007 flags=ParseGeometry(argv[i+1],&geometry_info);
1008 brightness=geometry_info.rho;
1009 contrast=0.0;
1010 if ((flags & SigmaValue) != 0)
1011 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +00001012 (void) BrightnessContrastImage(*image,brightness,contrast,
1013 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001014 break;
1015 }
1016 break;
1017 }
1018 case 'c':
1019 {
1020 if (LocaleCompare("cdl",option+1) == 0)
1021 {
1022 char
1023 *color_correction_collection;
1024
1025 /*
1026 Color correct with a color decision list.
1027 */
cristy6fccee12011-10-20 18:43:18 +00001028 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001029 color_correction_collection=FileToString(argv[i+1],~0,exception);
1030 if (color_correction_collection == (char *) NULL)
1031 break;
cristy1bfa9f02011-08-11 02:35:43 +00001032 (void) ColorDecisionListImage(*image,color_correction_collection,
1033 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001034 break;
1035 }
anthonydf8ebac2011-04-27 09:03:19 +00001036 if (LocaleCompare("charcoal",option+1) == 0)
1037 {
1038 /*
1039 Charcoal image.
1040 */
cristy6fccee12011-10-20 18:43:18 +00001041 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001042 flags=ParseGeometry(argv[i+1],&geometry_info);
1043 if ((flags & SigmaValue) == 0)
1044 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001045 if ((flags & XiValue) == 0)
1046 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001047 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00001048 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001049 break;
1050 }
1051 if (LocaleCompare("chop",option+1) == 0)
1052 {
1053 /*
1054 Chop the image.
1055 */
cristy6fccee12011-10-20 18:43:18 +00001056 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001057 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1058 mogrify_image=ChopImage(*image,&geometry,exception);
1059 break;
1060 }
1061 if (LocaleCompare("clamp",option+1) == 0)
1062 {
1063 /*
1064 Clamp image.
1065 */
cristy6fccee12011-10-20 18:43:18 +00001066 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001067 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001068 break;
1069 }
1070 if (LocaleCompare("clip",option+1) == 0)
1071 {
cristy6fccee12011-10-20 18:43:18 +00001072 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001073 if (*option == '+')
1074 {
cristy10a6c612012-01-29 21:41:05 +00001075 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001076 break;
1077 }
cristy018f07f2011-09-04 21:15:19 +00001078 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001079 break;
1080 }
1081 if (LocaleCompare("clip-mask",option+1) == 0)
1082 {
1083 CacheView
1084 *mask_view;
1085
1086 Image
1087 *mask_image;
1088
cristy4c08aed2011-07-01 19:47:50 +00001089 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001090 *restrict q;
1091
1092 register ssize_t
1093 x;
1094
1095 ssize_t
1096 y;
1097
cristy6fccee12011-10-20 18:43:18 +00001098 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001099 if (*option == '+')
1100 {
1101 /*
1102 Remove a mask.
1103 */
cristy018f07f2011-09-04 21:15:19 +00001104 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001105 break;
1106 }
1107 /*
1108 Set the image mask.
1109 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1110 */
1111 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1112 if (mask_image == (Image *) NULL)
1113 break;
cristy574cc262011-08-05 01:23:58 +00001114 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001115 return(MagickFalse);
1116 mask_view=AcquireCacheView(mask_image);
1117 for (y=0; y < (ssize_t) mask_image->rows; y++)
1118 {
1119 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1120 exception);
cristyacd2ed22011-08-30 01:44:23 +00001121 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001122 break;
1123 for (x=0; x < (ssize_t) mask_image->columns; x++)
1124 {
1125 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001126 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1127 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1128 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1129 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001130 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001131 }
1132 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1133 break;
1134 }
1135 mask_view=DestroyCacheView(mask_view);
1136 mask_image->matte=MagickTrue;
cristy10a6c612012-01-29 21:41:05 +00001137 (void) SetImageMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001138 break;
1139 }
1140 if (LocaleCompare("clip-path",option+1) == 0)
1141 {
cristy6fccee12011-10-20 18:43:18 +00001142 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001143 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001144 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001145 break;
1146 }
1147 if (LocaleCompare("colorize",option+1) == 0)
1148 {
1149 /*
1150 Colorize the image.
1151 */
cristy6fccee12011-10-20 18:43:18 +00001152 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001153 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001154 break;
1155 }
1156 if (LocaleCompare("color-matrix",option+1) == 0)
1157 {
1158 KernelInfo
1159 *kernel;
1160
cristy6fccee12011-10-20 18:43:18 +00001161 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001162 kernel=AcquireKernelInfo(argv[i+1]);
1163 if (kernel == (KernelInfo *) NULL)
1164 break;
anthonyfd706f92012-01-19 04:22:02 +00001165 /* FUTURE: check on size of the matrix */
anthonydf8ebac2011-04-27 09:03:19 +00001166 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1167 kernel=DestroyKernelInfo(kernel);
1168 break;
1169 }
1170 if (LocaleCompare("colors",option+1) == 0)
1171 {
1172 /*
1173 Reduce the number of colors in the image.
1174 */
cristy6fccee12011-10-20 18:43:18 +00001175 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001176 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1177 if (quantize_info->number_colors == 0)
1178 break;
1179 if (((*image)->storage_class == DirectClass) ||
1180 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001181 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001182 else
cristy018f07f2011-09-04 21:15:19 +00001183 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001184 break;
1185 }
1186 if (LocaleCompare("colorspace",option+1) == 0)
1187 {
1188 ColorspaceType
1189 colorspace;
1190
cristy6fccee12011-10-20 18:43:18 +00001191 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001192 if (*option == '+')
1193 {
cristye941a752011-10-15 01:52:48 +00001194 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001195 break;
1196 }
1197 colorspace=(ColorspaceType) ParseCommandOption(
1198 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001199 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001200 break;
1201 }
cristy633f0c62011-09-15 13:27:36 +00001202 if (LocaleCompare("compose",option+1) == 0)
1203 {
cristy6fccee12011-10-20 18:43:18 +00001204 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001205 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1206 MagickFalse,argv[i+1]);
1207 break;
1208 }
anthonydf8ebac2011-04-27 09:03:19 +00001209 if (LocaleCompare("contrast",option+1) == 0)
1210 {
cristy6fccee12011-10-20 18:43:18 +00001211 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001212 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001213 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001214 break;
1215 }
1216 if (LocaleCompare("contrast-stretch",option+1) == 0)
1217 {
1218 double
1219 black_point,
1220 white_point;
1221
1222 MagickStatusType
1223 flags;
1224
1225 /*
1226 Contrast stretch image.
1227 */
cristy6fccee12011-10-20 18:43:18 +00001228 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001229 flags=ParseGeometry(argv[i+1],&geometry_info);
1230 black_point=geometry_info.rho;
1231 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1232 black_point;
1233 if ((flags & PercentValue) != 0)
1234 {
1235 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1236 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1237 }
1238 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1239 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001240 (void) ContrastStretchImage(*image,black_point,white_point,
1241 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001242 break;
1243 }
1244 if (LocaleCompare("convolve",option+1) == 0)
1245 {
anthonydf8ebac2011-04-27 09:03:19 +00001246 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001247 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001248
cristy6fccee12011-10-20 18:43:18 +00001249 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001250 kernel_info=AcquireKernelInfo(argv[i+1]);
1251 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001252 break;
anthonyf46d4262012-03-26 03:30:34 +00001253 /* kernel_info->bias=(*image)->bias; -- FUTURE: check this path! */
cristy5e6be1e2011-07-16 01:23:39 +00001254 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001255 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001256 break;
1257 }
1258 if (LocaleCompare("crop",option+1) == 0)
1259 {
1260 /*
1261 Crop a image to a smaller size
1262 */
cristy6fccee12011-10-20 18:43:18 +00001263 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001264 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001265 break;
1266 }
1267 if (LocaleCompare("cycle",option+1) == 0)
1268 {
1269 /*
1270 Cycle an image colormap.
1271 */
cristy6fccee12011-10-20 18:43:18 +00001272 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001273 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1274 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001275 break;
1276 }
1277 break;
1278 }
1279 case 'd':
1280 {
1281 if (LocaleCompare("decipher",option+1) == 0)
1282 {
1283 StringInfo
1284 *passkey;
1285
1286 /*
1287 Decipher pixels.
1288 */
cristy6fccee12011-10-20 18:43:18 +00001289 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001290 passkey=FileToStringInfo(argv[i+1],~0,exception);
1291 if (passkey != (StringInfo *) NULL)
1292 {
1293 (void) PasskeyDecipherImage(*image,passkey,exception);
1294 passkey=DestroyStringInfo(passkey);
1295 }
1296 break;
1297 }
1298 if (LocaleCompare("density",option+1) == 0)
1299 {
1300 /*
1301 Set image density.
1302 */
1303 (void) CloneString(&draw_info->density,argv[i+1]);
1304 break;
1305 }
1306 if (LocaleCompare("depth",option+1) == 0)
1307 {
cristy6fccee12011-10-20 18:43:18 +00001308 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001309 if (*option == '+')
1310 {
cristy8a11cb12011-10-19 23:53:34 +00001311 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001312 break;
1313 }
cristy8a11cb12011-10-19 23:53:34 +00001314 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1315 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001316 break;
1317 }
1318 if (LocaleCompare("deskew",option+1) == 0)
1319 {
1320 double
1321 threshold;
1322
1323 /*
1324 Straighten the image.
1325 */
cristy6fccee12011-10-20 18:43:18 +00001326 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001327 if (*option == '+')
1328 threshold=40.0*QuantumRange/100.0;
1329 else
cristy9b34e302011-11-05 02:15:45 +00001330 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1331 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001332 mogrify_image=DeskewImage(*image,threshold,exception);
1333 break;
1334 }
1335 if (LocaleCompare("despeckle",option+1) == 0)
1336 {
1337 /*
1338 Reduce the speckles within an image.
1339 */
cristy6fccee12011-10-20 18:43:18 +00001340 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001341 mogrify_image=DespeckleImage(*image,exception);
1342 break;
1343 }
1344 if (LocaleCompare("display",option+1) == 0)
1345 {
1346 (void) CloneString(&draw_info->server_name,argv[i+1]);
1347 break;
1348 }
1349 if (LocaleCompare("distort",option+1) == 0)
1350 {
1351 char
1352 *args,
1353 token[MaxTextExtent];
1354
1355 const char
1356 *p;
1357
1358 DistortImageMethod
1359 method;
1360
1361 double
1362 *arguments;
1363
1364 register ssize_t
1365 x;
1366
1367 size_t
1368 number_arguments;
1369
1370 /*
1371 Distort image.
1372 */
cristy6fccee12011-10-20 18:43:18 +00001373 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001374 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1375 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001376 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001377 {
anthonydf8ebac2011-04-27 09:03:19 +00001378 double
1379 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001380
1381 /*
1382 Special Case - Argument is actually a resize geometry!
1383 Convert that to an appropriate distortion argument array.
1384 */
anthonydf8ebac2011-04-27 09:03:19 +00001385 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001386 exception);
1387 resize_args[0]=(double) geometry.width;
1388 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001389 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001390 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001391 break;
1392 }
cristy018f07f2011-09-04 21:15:19 +00001393 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1394 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001395 if (args == (char *) NULL)
1396 break;
1397 p=(char *) args;
1398 for (x=0; *p != '\0'; x++)
1399 {
1400 GetMagickToken(p,&p,token);
1401 if (*token == ',')
1402 GetMagickToken(p,&p,token);
1403 }
1404 number_arguments=(size_t) x;
1405 arguments=(double *) AcquireQuantumMemory(number_arguments,
1406 sizeof(*arguments));
1407 if (arguments == (double *) NULL)
1408 ThrowWandFatalException(ResourceLimitFatalError,
1409 "MemoryAllocationFailed",(*image)->filename);
1410 (void) ResetMagickMemory(arguments,0,number_arguments*
1411 sizeof(*arguments));
1412 p=(char *) args;
1413 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1414 {
1415 GetMagickToken(p,&p,token);
1416 if (*token == ',')
1417 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001418 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001419 }
1420 args=DestroyString(args);
1421 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1422 (*option == '+') ? MagickTrue : MagickFalse,exception);
1423 arguments=(double *) RelinquishMagickMemory(arguments);
1424 break;
1425 }
1426 if (LocaleCompare("dither",option+1) == 0)
1427 {
1428 if (*option == '+')
1429 {
1430 quantize_info->dither=MagickFalse;
1431 break;
1432 }
1433 quantize_info->dither=MagickTrue;
1434 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1435 MagickDitherOptions,MagickFalse,argv[i+1]);
1436 if (quantize_info->dither_method == NoDitherMethod)
1437 quantize_info->dither=MagickFalse;
1438 break;
1439 }
1440 if (LocaleCompare("draw",option+1) == 0)
1441 {
1442 /*
1443 Draw image.
1444 */
cristy6fccee12011-10-20 18:43:18 +00001445 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001446 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001447 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001448 break;
1449 }
1450 break;
1451 }
1452 case 'e':
1453 {
1454 if (LocaleCompare("edge",option+1) == 0)
1455 {
1456 /*
1457 Enhance edges in the image.
1458 */
cristy6fccee12011-10-20 18:43:18 +00001459 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001460 flags=ParseGeometry(argv[i+1],&geometry_info);
1461 if ((flags & SigmaValue) == 0)
1462 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001463 mogrify_image=EdgeImage(*image,geometry_info.rho,
1464 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001465 break;
1466 }
1467 if (LocaleCompare("emboss",option+1) == 0)
1468 {
1469 /*
cristyd89705a2012-01-20 02:52:24 +00001470 Emboss image.
anthonydf8ebac2011-04-27 09:03:19 +00001471 */
cristy6fccee12011-10-20 18:43:18 +00001472 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001473 flags=ParseGeometry(argv[i+1],&geometry_info);
1474 if ((flags & SigmaValue) == 0)
1475 geometry_info.sigma=1.0;
1476 mogrify_image=EmbossImage(*image,geometry_info.rho,
1477 geometry_info.sigma,exception);
1478 break;
1479 }
1480 if (LocaleCompare("encipher",option+1) == 0)
1481 {
1482 StringInfo
1483 *passkey;
1484
1485 /*
1486 Encipher pixels.
1487 */
cristy6fccee12011-10-20 18:43:18 +00001488 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001489 passkey=FileToStringInfo(argv[i+1],~0,exception);
1490 if (passkey != (StringInfo *) NULL)
1491 {
1492 (void) PasskeyEncipherImage(*image,passkey,exception);
1493 passkey=DestroyStringInfo(passkey);
1494 }
1495 break;
1496 }
1497 if (LocaleCompare("encoding",option+1) == 0)
1498 {
1499 (void) CloneString(&draw_info->encoding,argv[i+1]);
1500 break;
1501 }
1502 if (LocaleCompare("enhance",option+1) == 0)
1503 {
1504 /*
1505 Enhance image.
1506 */
cristy6fccee12011-10-20 18:43:18 +00001507 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001508 mogrify_image=EnhanceImage(*image,exception);
1509 break;
1510 }
1511 if (LocaleCompare("equalize",option+1) == 0)
1512 {
1513 /*
1514 Equalize image.
1515 */
cristy6fccee12011-10-20 18:43:18 +00001516 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001517 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001518 break;
1519 }
1520 if (LocaleCompare("evaluate",option+1) == 0)
1521 {
1522 double
1523 constant;
1524
1525 MagickEvaluateOperator
1526 op;
1527
cristy6fccee12011-10-20 18:43:18 +00001528 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001529 op=(MagickEvaluateOperator) ParseCommandOption(
1530 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001531 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1532 1.0);
cristyd42d9952011-07-08 14:21:50 +00001533 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001534 break;
1535 }
1536 if (LocaleCompare("extent",option+1) == 0)
1537 {
1538 /*
1539 Set the image extent.
1540 */
cristy6fccee12011-10-20 18:43:18 +00001541 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001542 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1543 if (geometry.width == 0)
1544 geometry.width=(*image)->columns;
1545 if (geometry.height == 0)
1546 geometry.height=(*image)->rows;
1547 mogrify_image=ExtentImage(*image,&geometry,exception);
1548 break;
1549 }
1550 break;
1551 }
1552 case 'f':
1553 {
1554 if (LocaleCompare("family",option+1) == 0)
1555 {
1556 if (*option == '+')
1557 {
1558 if (draw_info->family != (char *) NULL)
1559 draw_info->family=DestroyString(draw_info->family);
1560 break;
1561 }
1562 (void) CloneString(&draw_info->family,argv[i+1]);
1563 break;
1564 }
1565 if (LocaleCompare("features",option+1) == 0)
1566 {
1567 if (*option == '+')
1568 {
1569 (void) DeleteImageArtifact(*image,"identify:features");
1570 break;
1571 }
1572 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1573 break;
1574 }
1575 if (LocaleCompare("fill",option+1) == 0)
1576 {
1577 ExceptionInfo
1578 *sans;
1579
anthonyfd706f92012-01-19 04:22:02 +00001580 PixelInfo
1581 color;
1582
cristy4c08aed2011-07-01 19:47:50 +00001583 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001584 if (*option == '+')
1585 {
cristy269c9412011-10-13 23:41:15 +00001586 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001587 exception);
anthonyfd706f92012-01-19 04:22:02 +00001588 draw_info->fill=fill;
anthonydf8ebac2011-04-27 09:03:19 +00001589 if (draw_info->fill_pattern != (Image *) NULL)
1590 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1591 break;
1592 }
1593 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00001594 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001595 sans=DestroyExceptionInfo(sans);
1596 if (status == MagickFalse)
1597 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1598 exception);
anthonyfd706f92012-01-19 04:22:02 +00001599 else
1600 draw_info->fill=fill=color;
anthonydf8ebac2011-04-27 09:03:19 +00001601 break;
1602 }
1603 if (LocaleCompare("flip",option+1) == 0)
1604 {
1605 /*
1606 Flip image scanlines.
1607 */
cristy6fccee12011-10-20 18:43:18 +00001608 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001609 mogrify_image=FlipImage(*image,exception);
1610 break;
1611 }
anthonydf8ebac2011-04-27 09:03:19 +00001612 if (LocaleCompare("floodfill",option+1) == 0)
1613 {
cristy4c08aed2011-07-01 19:47:50 +00001614 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001615 target;
1616
1617 /*
1618 Floodfill image.
1619 */
cristy6fccee12011-10-20 18:43:18 +00001620 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001621 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001622 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001623 exception);
cristyd42d9952011-07-08 14:21:50 +00001624 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001625 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001626 break;
1627 }
anthony3d2f4862011-05-01 13:48:16 +00001628 if (LocaleCompare("flop",option+1) == 0)
1629 {
1630 /*
1631 Flop image scanlines.
1632 */
cristy6fccee12011-10-20 18:43:18 +00001633 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001634 mogrify_image=FlopImage(*image,exception);
1635 break;
1636 }
anthonydf8ebac2011-04-27 09:03:19 +00001637 if (LocaleCompare("font",option+1) == 0)
1638 {
1639 if (*option == '+')
1640 {
1641 if (draw_info->font != (char *) NULL)
1642 draw_info->font=DestroyString(draw_info->font);
1643 break;
1644 }
1645 (void) CloneString(&draw_info->font,argv[i+1]);
1646 break;
1647 }
1648 if (LocaleCompare("format",option+1) == 0)
1649 {
1650 format=argv[i+1];
1651 break;
1652 }
1653 if (LocaleCompare("frame",option+1) == 0)
1654 {
1655 FrameInfo
1656 frame_info;
1657
1658 /*
1659 Surround image with an ornamental border.
1660 */
cristy6fccee12011-10-20 18:43:18 +00001661 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001662 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1663 frame_info.width=geometry.width;
1664 frame_info.height=geometry.height;
1665 if ((flags & HeightValue) == 0)
1666 frame_info.height=geometry.width;
1667 frame_info.outer_bevel=geometry.x;
1668 frame_info.inner_bevel=geometry.y;
1669 frame_info.x=(ssize_t) frame_info.width;
1670 frame_info.y=(ssize_t) frame_info.height;
1671 frame_info.width=(*image)->columns+2*frame_info.width;
1672 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001673 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001674 break;
1675 }
1676 if (LocaleCompare("function",option+1) == 0)
1677 {
1678 char
1679 *arguments,
1680 token[MaxTextExtent];
1681
1682 const char
1683 *p;
1684
1685 double
1686 *parameters;
1687
1688 MagickFunction
1689 function;
1690
1691 register ssize_t
1692 x;
1693
1694 size_t
1695 number_parameters;
1696
1697 /*
1698 Function Modify Image Values
1699 */
cristy6fccee12011-10-20 18:43:18 +00001700 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001701 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1702 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001703 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1704 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001705 if (arguments == (char *) NULL)
1706 break;
1707 p=(char *) arguments;
1708 for (x=0; *p != '\0'; x++)
1709 {
1710 GetMagickToken(p,&p,token);
1711 if (*token == ',')
1712 GetMagickToken(p,&p,token);
1713 }
1714 number_parameters=(size_t) x;
1715 parameters=(double *) AcquireQuantumMemory(number_parameters,
1716 sizeof(*parameters));
1717 if (parameters == (double *) NULL)
1718 ThrowWandFatalException(ResourceLimitFatalError,
1719 "MemoryAllocationFailed",(*image)->filename);
1720 (void) ResetMagickMemory(parameters,0,number_parameters*
1721 sizeof(*parameters));
1722 p=(char *) arguments;
1723 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1724 {
1725 GetMagickToken(p,&p,token);
1726 if (*token == ',')
1727 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001728 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001729 }
1730 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001731 (void) FunctionImage(*image,function,number_parameters,parameters,
1732 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001733 parameters=(double *) RelinquishMagickMemory(parameters);
1734 break;
1735 }
1736 break;
1737 }
1738 case 'g':
1739 {
1740 if (LocaleCompare("gamma",option+1) == 0)
1741 {
1742 /*
1743 Gamma image.
1744 */
cristy6fccee12011-10-20 18:43:18 +00001745 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001746 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001747 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001748 else
cristydbdd0e32011-11-04 23:29:40 +00001749 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001750 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001751 break;
1752 }
1753 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1754 (LocaleCompare("gaussian",option+1) == 0))
1755 {
1756 /*
1757 Gaussian blur image.
1758 */
cristy6fccee12011-10-20 18:43:18 +00001759 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001760 flags=ParseGeometry(argv[i+1],&geometry_info);
1761 if ((flags & SigmaValue) == 0)
1762 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001763 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristyd89705a2012-01-20 02:52:24 +00001764 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001765 break;
1766 }
1767 if (LocaleCompare("geometry",option+1) == 0)
1768 {
1769 /*
1770 Record Image offset, Resize last image.
1771 */
cristy6fccee12011-10-20 18:43:18 +00001772 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001773 if (*option == '+')
1774 {
1775 if ((*image)->geometry != (char *) NULL)
1776 (*image)->geometry=DestroyString((*image)->geometry);
1777 break;
1778 }
1779 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1780 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1781 (void) CloneString(&(*image)->geometry,argv[i+1]);
1782 else
1783 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
cristyaa2c16c2012-03-25 22:21:35 +00001784 (*image)->filter,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001785 break;
1786 }
1787 if (LocaleCompare("gravity",option+1) == 0)
1788 {
1789 if (*option == '+')
1790 {
1791 draw_info->gravity=UndefinedGravity;
1792 break;
1793 }
1794 draw_info->gravity=(GravityType) ParseCommandOption(
1795 MagickGravityOptions,MagickFalse,argv[i+1]);
1796 break;
1797 }
1798 break;
1799 }
1800 case 'h':
1801 {
1802 if (LocaleCompare("highlight-color",option+1) == 0)
1803 {
1804 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1805 break;
1806 }
1807 break;
1808 }
1809 case 'i':
1810 {
1811 if (LocaleCompare("identify",option+1) == 0)
1812 {
1813 char
1814 *text;
1815
cristy6fccee12011-10-20 18:43:18 +00001816 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001817 if (format == (char *) NULL)
1818 {
cristya4037272011-08-28 15:11:39 +00001819 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1820 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001821 break;
1822 }
cristy018f07f2011-09-04 21:15:19 +00001823 text=InterpretImageProperties(mogrify_info,*image,format,
1824 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001825 if (text == (char *) NULL)
1826 break;
1827 (void) fputs(text,stdout);
1828 (void) fputc('\n',stdout);
1829 text=DestroyString(text);
1830 break;
1831 }
1832 if (LocaleCompare("implode",option+1) == 0)
1833 {
1834 /*
1835 Implode image.
1836 */
cristy6fccee12011-10-20 18:43:18 +00001837 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001838 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001839 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1840 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001841 break;
1842 }
1843 if (LocaleCompare("interline-spacing",option+1) == 0)
1844 {
1845 if (*option == '+')
1846 (void) ParseGeometry("0",&geometry_info);
1847 else
1848 (void) ParseGeometry(argv[i+1],&geometry_info);
1849 draw_info->interline_spacing=geometry_info.rho;
1850 break;
1851 }
cristy28474bf2011-09-11 23:32:52 +00001852 if (LocaleCompare("interpolate",option+1) == 0)
1853 {
1854 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1855 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1856 break;
1857 }
anthonydf8ebac2011-04-27 09:03:19 +00001858 if (LocaleCompare("interword-spacing",option+1) == 0)
1859 {
1860 if (*option == '+')
1861 (void) ParseGeometry("0",&geometry_info);
1862 else
1863 (void) ParseGeometry(argv[i+1],&geometry_info);
1864 draw_info->interword_spacing=geometry_info.rho;
1865 break;
1866 }
anthonyfd706f92012-01-19 04:22:02 +00001867 if (LocaleCompare("interpolative-resize",option+1) == 0)
1868 {
1869 /*
1870 Interpolative resize image.
1871 */
1872 (void) SyncImageSettings(mogrify_info,*image,exception);
1873 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1874 mogrify_image=InterpolativeResizeImage(*image,geometry.width,
1875 geometry.height,interpolate_method,exception);
1876 break;
1877 }
anthonydf8ebac2011-04-27 09:03:19 +00001878 break;
1879 }
1880 case 'k':
1881 {
1882 if (LocaleCompare("kerning",option+1) == 0)
1883 {
1884 if (*option == '+')
1885 (void) ParseGeometry("0",&geometry_info);
1886 else
1887 (void) ParseGeometry(argv[i+1],&geometry_info);
1888 draw_info->kerning=geometry_info.rho;
1889 break;
1890 }
1891 break;
1892 }
1893 case 'l':
1894 {
1895 if (LocaleCompare("lat",option+1) == 0)
1896 {
1897 /*
1898 Local adaptive threshold image.
1899 */
cristy6fccee12011-10-20 18:43:18 +00001900 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001901 flags=ParseGeometry(argv[i+1],&geometry_info);
1902 if ((flags & PercentValue) != 0)
1903 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1904 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001905 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001906 geometry_info.xi,exception);
1907 break;
1908 }
1909 if (LocaleCompare("level",option+1) == 0)
1910 {
1911 MagickRealType
1912 black_point,
1913 gamma,
1914 white_point;
1915
1916 MagickStatusType
1917 flags;
1918
1919 /*
1920 Parse levels.
1921 */
cristy6fccee12011-10-20 18:43:18 +00001922 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001923 flags=ParseGeometry(argv[i+1],&geometry_info);
1924 black_point=geometry_info.rho;
1925 white_point=(MagickRealType) QuantumRange;
1926 if ((flags & SigmaValue) != 0)
1927 white_point=geometry_info.sigma;
1928 gamma=1.0;
1929 if ((flags & XiValue) != 0)
1930 gamma=geometry_info.xi;
1931 if ((flags & PercentValue) != 0)
1932 {
1933 black_point*=(MagickRealType) (QuantumRange/100.0);
1934 white_point*=(MagickRealType) (QuantumRange/100.0);
1935 }
1936 if ((flags & SigmaValue) == 0)
1937 white_point=(MagickRealType) QuantumRange-black_point;
1938 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001939 (void) LevelizeImage(*image,black_point,white_point,gamma,
1940 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001941 else
cristy01e9afd2011-08-10 17:38:41 +00001942 (void) LevelImage(*image,black_point,white_point,gamma,
1943 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001944 break;
1945 }
1946 if (LocaleCompare("level-colors",option+1) == 0)
1947 {
1948 char
1949 token[MaxTextExtent];
1950
1951 const char
1952 *p;
1953
cristy4c08aed2011-07-01 19:47:50 +00001954 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001955 black_point,
1956 white_point;
1957
1958 p=(const char *) argv[i+1];
1959 GetMagickToken(p,&p,token); /* get black point color */
1960 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001961 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001962 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001963 else
cristy269c9412011-10-13 23:41:15 +00001964 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001965 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001966 if (isalpha((int) token[0]) || (token[0] == '#'))
1967 GetMagickToken(p,&p,token);
1968 if (*token == '\0')
1969 white_point=black_point; /* set everything to that color */
1970 else
1971 {
1972 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1973 GetMagickToken(p,&p,token); /* Get white 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 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001977 else
cristy269c9412011-10-13 23:41:15 +00001978 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001979 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001980 }
cristy490408a2011-07-07 14:42:05 +00001981 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001982 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001983 break;
1984 }
1985 if (LocaleCompare("linear-stretch",option+1) == 0)
1986 {
1987 double
1988 black_point,
1989 white_point;
1990
1991 MagickStatusType
1992 flags;
1993
cristy6fccee12011-10-20 18:43:18 +00001994 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001995 flags=ParseGeometry(argv[i+1],&geometry_info);
1996 black_point=geometry_info.rho;
1997 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
1998 if ((flags & SigmaValue) != 0)
1999 white_point=geometry_info.sigma;
2000 if ((flags & PercentValue) != 0)
2001 {
2002 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2003 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2004 }
2005 if ((flags & SigmaValue) == 0)
2006 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2007 black_point;
cristy33bd5152011-08-24 01:42:24 +00002008 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002009 break;
2010 }
anthonydf8ebac2011-04-27 09:03:19 +00002011 if (LocaleCompare("liquid-rescale",option+1) == 0)
2012 {
2013 /*
2014 Liquid rescale image.
2015 */
cristy6fccee12011-10-20 18:43:18 +00002016 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002017 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2018 if ((flags & XValue) == 0)
2019 geometry.x=1;
2020 if ((flags & YValue) == 0)
2021 geometry.y=0;
2022 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2023 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2024 break;
2025 }
2026 if (LocaleCompare("lowlight-color",option+1) == 0)
2027 {
2028 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2029 break;
2030 }
2031 break;
2032 }
2033 case 'm':
2034 {
2035 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002036 {
cristy3ed852e2009-09-05 21:47:34 +00002037 Image
anthonydf8ebac2011-04-27 09:03:19 +00002038 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002039
anthonydf8ebac2011-04-27 09:03:19 +00002040 /*
2041 Transform image colors to match this set of colors.
2042 */
cristy6fccee12011-10-20 18:43:18 +00002043 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002044 if (*option == '+')
2045 break;
2046 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2047 if (remap_image == (Image *) NULL)
2048 break;
cristy018f07f2011-09-04 21:15:19 +00002049 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002050 remap_image=DestroyImage(remap_image);
2051 break;
2052 }
2053 if (LocaleCompare("mask",option+1) == 0)
2054 {
2055 Image
2056 *mask;
2057
cristy6fccee12011-10-20 18:43:18 +00002058 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002059 if (*option == '+')
2060 {
2061 /*
2062 Remove a mask.
2063 */
cristy018f07f2011-09-04 21:15:19 +00002064 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002065 break;
2066 }
2067 /*
2068 Set the image mask.
2069 */
2070 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2071 if (mask == (Image *) NULL)
2072 break;
cristy018f07f2011-09-04 21:15:19 +00002073 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002074 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002075 break;
2076 }
2077 if (LocaleCompare("matte",option+1) == 0)
2078 {
2079 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002080 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002081 break;
2082 }
2083 if (LocaleCompare("median",option+1) == 0)
2084 {
2085 /*
2086 Median filter image.
2087 */
cristy6fccee12011-10-20 18:43:18 +00002088 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002089 flags=ParseGeometry(argv[i+1],&geometry_info);
2090 if ((flags & SigmaValue) == 0)
2091 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002092 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002093 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002094 break;
2095 }
2096 if (LocaleCompare("mode",option+1) == 0)
2097 {
2098 /*
2099 Mode image.
2100 */
cristy6fccee12011-10-20 18:43:18 +00002101 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002102 flags=ParseGeometry(argv[i+1],&geometry_info);
2103 if ((flags & SigmaValue) == 0)
2104 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002105 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002106 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002107 break;
2108 }
2109 if (LocaleCompare("modulate",option+1) == 0)
2110 {
cristy6fccee12011-10-20 18:43:18 +00002111 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002112 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002113 break;
2114 }
2115 if (LocaleCompare("monitor",option+1) == 0)
2116 {
2117 if (*option == '+')
2118 {
2119 (void) SetImageProgressMonitor(*image,
2120 (MagickProgressMonitor) NULL,(void *) NULL);
2121 break;
2122 }
2123 (void) SetImageProgressMonitor(*image,MonitorProgress,
2124 (void *) NULL);
2125 break;
2126 }
2127 if (LocaleCompare("monochrome",option+1) == 0)
2128 {
cristy6fccee12011-10-20 18:43:18 +00002129 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002130 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002131 break;
2132 }
2133 if (LocaleCompare("morphology",option+1) == 0)
2134 {
2135 char
2136 token[MaxTextExtent];
2137
2138 const char
2139 *p;
2140
2141 KernelInfo
2142 *kernel;
2143
2144 MorphologyMethod
2145 method;
2146
2147 ssize_t
2148 iterations;
2149
2150 /*
2151 Morphological Image Operation
2152 */
cristy6fccee12011-10-20 18:43:18 +00002153 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002154 p=argv[i+1];
2155 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002156 method=(MorphologyMethod) ParseCommandOption(
2157 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002158 iterations=1L;
2159 GetMagickToken(p,&p,token);
2160 if ((*p == ':') || (*p == ','))
2161 GetMagickToken(p,&p,token);
2162 if ((*p != '\0'))
2163 iterations=(ssize_t) StringToLong(p);
2164 kernel=AcquireKernelInfo(argv[i+2]);
2165 if (kernel == (KernelInfo *) NULL)
2166 {
2167 (void) ThrowMagickException(exception,GetMagickModule(),
2168 OptionError,"UnabletoParseKernel","morphology");
2169 status=MagickFalse;
2170 break;
2171 }
cristyf4ad9df2011-07-08 16:49:03 +00002172 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2173 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002174 kernel=DestroyKernelInfo(kernel);
2175 break;
2176 }
2177 if (LocaleCompare("motion-blur",option+1) == 0)
2178 {
2179 /*
2180 Motion blur image.
2181 */
cristy6fccee12011-10-20 18:43:18 +00002182 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002183 flags=ParseGeometry(argv[i+1],&geometry_info);
2184 if ((flags & SigmaValue) == 0)
2185 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002186 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002187 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002188 break;
2189 }
2190 break;
2191 }
2192 case 'n':
2193 {
2194 if (LocaleCompare("negate",option+1) == 0)
2195 {
cristy6fccee12011-10-20 18:43:18 +00002196 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002197 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002198 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002199 break;
2200 }
2201 if (LocaleCompare("noise",option+1) == 0)
2202 {
cristy6fccee12011-10-20 18:43:18 +00002203 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002204 if (*option == '-')
2205 {
cristyf36cbcb2011-09-07 13:28:22 +00002206 flags=ParseGeometry(argv[i+1],&geometry_info);
2207 if ((flags & SigmaValue) == 0)
2208 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002209 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002210 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002211 }
2212 else
2213 {
2214 NoiseType
2215 noise;
2216
2217 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2218 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002219 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002220 }
2221 break;
2222 }
2223 if (LocaleCompare("normalize",option+1) == 0)
2224 {
cristy6fccee12011-10-20 18:43:18 +00002225 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002226 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002227 break;
2228 }
2229 break;
2230 }
2231 case 'o':
2232 {
2233 if (LocaleCompare("opaque",option+1) == 0)
2234 {
cristy4c08aed2011-07-01 19:47:50 +00002235 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002236 target;
2237
cristy6fccee12011-10-20 18:43:18 +00002238 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002239 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002240 exception);
cristyd42d9952011-07-08 14:21:50 +00002241 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002242 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002243 break;
2244 }
2245 if (LocaleCompare("ordered-dither",option+1) == 0)
2246 {
cristy6fccee12011-10-20 18:43:18 +00002247 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002248 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002249 break;
2250 }
2251 break;
2252 }
2253 case 'p':
2254 {
2255 if (LocaleCompare("paint",option+1) == 0)
2256 {
cristy6fccee12011-10-20 18:43:18 +00002257 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002258 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002259 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2260 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002261 break;
2262 }
anthonydf8ebac2011-04-27 09:03:19 +00002263 if (LocaleCompare("pointsize",option+1) == 0)
2264 {
2265 if (*option == '+')
2266 (void) ParseGeometry("12",&geometry_info);
2267 else
2268 (void) ParseGeometry(argv[i+1],&geometry_info);
2269 draw_info->pointsize=geometry_info.rho;
2270 break;
2271 }
2272 if (LocaleCompare("polaroid",option+1) == 0)
2273 {
cristye9e3d382011-12-14 01:50:13 +00002274 const char
2275 *caption;
2276
anthonydf8ebac2011-04-27 09:03:19 +00002277 double
2278 angle;
2279
2280 RandomInfo
2281 *random_info;
2282
2283 /*
2284 Simulate a Polaroid picture.
2285 */
cristy6fccee12011-10-20 18:43:18 +00002286 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002287 random_info=AcquireRandomInfo();
2288 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2289 random_info=DestroyRandomInfo(random_info);
2290 if (*option == '-')
2291 {
2292 SetGeometryInfo(&geometry_info);
2293 flags=ParseGeometry(argv[i+1],&geometry_info);
2294 angle=geometry_info.rho;
2295 }
cristye9e3d382011-12-14 01:50:13 +00002296 caption=GetImageProperty(*image,"caption",exception);
2297 mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
cristy28474bf2011-09-11 23:32:52 +00002298 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002299 break;
2300 }
2301 if (LocaleCompare("posterize",option+1) == 0)
2302 {
2303 /*
2304 Posterize image.
2305 */
cristy6fccee12011-10-20 18:43:18 +00002306 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002307 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002308 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002309 break;
2310 }
2311 if (LocaleCompare("preview",option+1) == 0)
2312 {
2313 PreviewType
2314 preview_type;
2315
2316 /*
2317 Preview image.
2318 */
cristy6fccee12011-10-20 18:43:18 +00002319 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002320 if (*option == '+')
2321 preview_type=UndefinedPreview;
2322 else
cristy28474bf2011-09-11 23:32:52 +00002323 preview_type=(PreviewType) ParseCommandOption(
2324 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002325 mogrify_image=PreviewImage(*image,preview_type,exception);
2326 break;
2327 }
2328 if (LocaleCompare("profile",option+1) == 0)
2329 {
2330 const char
2331 *name;
2332
2333 const StringInfo
2334 *profile;
2335
2336 Image
2337 *profile_image;
2338
2339 ImageInfo
2340 *profile_info;
2341
cristy6fccee12011-10-20 18:43:18 +00002342 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002343 if (*option == '+')
2344 {
2345 /*
2346 Remove a profile from the image.
2347 */
2348 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002349 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002350 break;
2351 }
2352 /*
2353 Associate a profile with the image.
2354 */
2355 profile_info=CloneImageInfo(mogrify_info);
2356 profile=GetImageProfile(*image,"iptc");
2357 if (profile != (StringInfo *) NULL)
2358 profile_info->profile=(void *) CloneStringInfo(profile);
2359 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2360 profile_info=DestroyImageInfo(profile_info);
2361 if (profile_image == (Image *) NULL)
2362 {
2363 StringInfo
2364 *profile;
2365
2366 profile_info=CloneImageInfo(mogrify_info);
2367 (void) CopyMagickString(profile_info->filename,argv[i+1],
2368 MaxTextExtent);
2369 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2370 if (profile != (StringInfo *) NULL)
2371 {
2372 (void) ProfileImage(*image,profile_info->magick,
2373 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002374 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002375 profile=DestroyStringInfo(profile);
2376 }
2377 profile_info=DestroyImageInfo(profile_info);
2378 break;
2379 }
2380 ResetImageProfileIterator(profile_image);
2381 name=GetNextImageProfile(profile_image);
2382 while (name != (const char *) NULL)
2383 {
2384 profile=GetImageProfile(profile_image,name);
2385 if (profile != (StringInfo *) NULL)
2386 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002387 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002388 name=GetNextImageProfile(profile_image);
2389 }
2390 profile_image=DestroyImage(profile_image);
2391 break;
2392 }
2393 break;
2394 }
2395 case 'q':
2396 {
2397 if (LocaleCompare("quantize",option+1) == 0)
2398 {
2399 if (*option == '+')
2400 {
2401 quantize_info->colorspace=UndefinedColorspace;
2402 break;
2403 }
2404 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2405 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2406 break;
2407 }
2408 break;
2409 }
2410 case 'r':
2411 {
2412 if (LocaleCompare("radial-blur",option+1) == 0)
2413 {
2414 /*
2415 Radial blur image.
2416 */
cristy6fccee12011-10-20 18:43:18 +00002417 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002418 flags=ParseGeometry(argv[i+1],&geometry_info);
cristyaa2c16c2012-03-25 22:21:35 +00002419 mogrify_image=RadialBlurImage(*image,geometry_info.rho,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002420 break;
2421 }
2422 if (LocaleCompare("raise",option+1) == 0)
2423 {
2424 /*
2425 Surround image with a raise of solid color.
2426 */
2427 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2428 if ((flags & SigmaValue) == 0)
2429 geometry.height=geometry.width;
2430 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002431 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002432 break;
2433 }
2434 if (LocaleCompare("random-threshold",option+1) == 0)
2435 {
2436 /*
2437 Threshold image.
2438 */
cristy6fccee12011-10-20 18:43:18 +00002439 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002440 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002441 break;
2442 }
anthonydf8ebac2011-04-27 09:03:19 +00002443 if (LocaleCompare("region",option+1) == 0)
2444 {
cristy6fccee12011-10-20 18:43:18 +00002445 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002446 if (region_image != (Image *) NULL)
2447 {
2448 /*
2449 Composite region.
2450 */
cristyfeb3e962012-03-29 17:25:55 +00002451 (void) CompositeImage(region_image,*image,region_image->matte !=
cristy39172402012-03-30 13:04:39 +00002452 MagickFalse ? CopyCompositeOp : OverCompositeOp,MagickTrue,
cristye941a752011-10-15 01:52:48 +00002453 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002454 *image=DestroyImage(*image);
2455 *image=region_image;
2456 region_image = (Image *) NULL;
2457 }
2458 if (*option == '+')
2459 break;
2460 /*
2461 Apply transformations to a selected region of the image.
2462 */
cristy3ed852e2009-09-05 21:47:34 +00002463 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2464 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002465 mogrify_image=CropImage(*image,&region_geometry,exception);
2466 if (mogrify_image == (Image *) NULL)
2467 break;
2468 region_image=(*image);
2469 *image=mogrify_image;
2470 mogrify_image=(Image *) NULL;
2471 break;
cristy3ed852e2009-09-05 21:47:34 +00002472 }
anthonydf8ebac2011-04-27 09:03:19 +00002473 if (LocaleCompare("render",option+1) == 0)
2474 {
cristy6fccee12011-10-20 18:43:18 +00002475 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002476 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2477 break;
2478 }
2479 if (LocaleCompare("remap",option+1) == 0)
2480 {
2481 Image
2482 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002483
anthonydf8ebac2011-04-27 09:03:19 +00002484 /*
2485 Transform image colors to match this set of colors.
2486 */
cristy6fccee12011-10-20 18:43:18 +00002487 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002488 if (*option == '+')
2489 break;
2490 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2491 if (remap_image == (Image *) NULL)
2492 break;
cristy018f07f2011-09-04 21:15:19 +00002493 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002494 remap_image=DestroyImage(remap_image);
2495 break;
2496 }
2497 if (LocaleCompare("repage",option+1) == 0)
2498 {
2499 if (*option == '+')
2500 {
2501 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2502 break;
2503 }
2504 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002505 break;
2506 }
2507 if (LocaleCompare("resample",option+1) == 0)
2508 {
2509 /*
2510 Resample image.
2511 */
cristy6fccee12011-10-20 18:43:18 +00002512 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002513 flags=ParseGeometry(argv[i+1],&geometry_info);
2514 if ((flags & SigmaValue) == 0)
2515 geometry_info.sigma=geometry_info.rho;
2516 mogrify_image=ResampleImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002517 geometry_info.sigma,(*image)->filter,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002518 break;
2519 }
2520 if (LocaleCompare("resize",option+1) == 0)
2521 {
2522 /*
2523 Resize image.
2524 */
cristy6fccee12011-10-20 18:43:18 +00002525 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002526 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2527 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
cristyaa2c16c2012-03-25 22:21:35 +00002528 (*image)->filter,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002529 break;
2530 }
2531 if (LocaleCompare("roll",option+1) == 0)
2532 {
2533 /*
2534 Roll image.
2535 */
cristy6fccee12011-10-20 18:43:18 +00002536 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002537 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2538 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2539 break;
2540 }
2541 if (LocaleCompare("rotate",option+1) == 0)
2542 {
2543 char
2544 *geometry;
2545
2546 /*
2547 Check for conditional image rotation.
2548 */
cristy6fccee12011-10-20 18:43:18 +00002549 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002550 if (strchr(argv[i+1],'>') != (char *) NULL)
2551 if ((*image)->columns <= (*image)->rows)
2552 break;
2553 if (strchr(argv[i+1],'<') != (char *) NULL)
2554 if ((*image)->columns >= (*image)->rows)
2555 break;
2556 /*
2557 Rotate image.
2558 */
2559 geometry=ConstantString(argv[i+1]);
2560 (void) SubstituteString(&geometry,">","");
2561 (void) SubstituteString(&geometry,"<","");
2562 (void) ParseGeometry(geometry,&geometry_info);
2563 geometry=DestroyString(geometry);
2564 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2565 break;
2566 }
2567 break;
2568 }
2569 case 's':
2570 {
2571 if (LocaleCompare("sample",option+1) == 0)
2572 {
2573 /*
2574 Sample image with pixel replication.
2575 */
cristy6fccee12011-10-20 18:43:18 +00002576 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002577 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2578 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2579 exception);
2580 break;
2581 }
2582 if (LocaleCompare("scale",option+1) == 0)
2583 {
2584 /*
2585 Resize image.
2586 */
cristy6fccee12011-10-20 18:43:18 +00002587 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002588 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2589 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2590 exception);
2591 break;
2592 }
2593 if (LocaleCompare("selective-blur",option+1) == 0)
2594 {
2595 /*
2596 Selectively blur pixels within a contrast threshold.
2597 */
cristy6fccee12011-10-20 18:43:18 +00002598 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002599 flags=ParseGeometry(argv[i+1],&geometry_info);
2600 if ((flags & PercentValue) != 0)
2601 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002602 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002603 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002604 break;
2605 }
2606 if (LocaleCompare("separate",option+1) == 0)
2607 {
2608 /*
2609 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002610 */
cristy6fccee12011-10-20 18:43:18 +00002611 (void) SyncImageSettings(mogrify_info,*image,exception);
cristydfdb19e2012-03-21 22:22:24 +00002612 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002613 break;
2614 }
2615 if (LocaleCompare("sepia-tone",option+1) == 0)
2616 {
2617 double
2618 threshold;
2619
2620 /*
2621 Sepia-tone image.
2622 */
cristy6fccee12011-10-20 18:43:18 +00002623 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002624 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2625 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002626 mogrify_image=SepiaToneImage(*image,threshold,exception);
2627 break;
2628 }
2629 if (LocaleCompare("segment",option+1) == 0)
2630 {
2631 /*
2632 Segment image.
2633 */
cristy6fccee12011-10-20 18:43:18 +00002634 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002635 flags=ParseGeometry(argv[i+1],&geometry_info);
2636 if ((flags & SigmaValue) == 0)
2637 geometry_info.sigma=1.0;
2638 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002639 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2640 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002641 break;
2642 }
2643 if (LocaleCompare("set",option+1) == 0)
2644 {
2645 char
2646 *value;
2647
2648 /*
2649 Set image option.
2650 */
2651 if (*option == '+')
2652 {
2653 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2654 (void) DeleteImageRegistry(argv[i+1]+9);
2655 else
2656 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2657 {
2658 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2659 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2660 }
2661 else
2662 (void) DeleteImageProperty(*image,argv[i+1]);
2663 break;
2664 }
cristy018f07f2011-09-04 21:15:19 +00002665 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2666 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002667 if (value == (char *) NULL)
2668 break;
2669 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2670 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2671 exception);
2672 else
2673 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2674 {
2675 (void) SetImageOption(image_info,argv[i+1]+7,value);
2676 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2677 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2678 }
2679 else
cristyd15e6592011-10-15 00:13:06 +00002680 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002681 value=DestroyString(value);
2682 break;
2683 }
2684 if (LocaleCompare("shade",option+1) == 0)
2685 {
2686 /*
2687 Shade image.
2688 */
cristy6fccee12011-10-20 18:43:18 +00002689 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002690 flags=ParseGeometry(argv[i+1],&geometry_info);
2691 if ((flags & SigmaValue) == 0)
2692 geometry_info.sigma=1.0;
2693 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2694 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2695 break;
2696 }
2697 if (LocaleCompare("shadow",option+1) == 0)
2698 {
2699 /*
2700 Shadow image.
2701 */
cristy6fccee12011-10-20 18:43:18 +00002702 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002703 flags=ParseGeometry(argv[i+1],&geometry_info);
2704 if ((flags & SigmaValue) == 0)
2705 geometry_info.sigma=1.0;
2706 if ((flags & XiValue) == 0)
2707 geometry_info.xi=4.0;
2708 if ((flags & PsiValue) == 0)
2709 geometry_info.psi=4.0;
2710 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002711 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),
2712 (ssize_t) ceil(geometry_info.psi-0.5),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002713 break;
2714 }
2715 if (LocaleCompare("sharpen",option+1) == 0)
2716 {
2717 /*
2718 Sharpen image.
2719 */
cristy6fccee12011-10-20 18:43:18 +00002720 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002721 flags=ParseGeometry(argv[i+1],&geometry_info);
2722 if ((flags & SigmaValue) == 0)
2723 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002724 if ((flags & XiValue) == 0)
2725 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002726 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002727 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002728 break;
2729 }
2730 if (LocaleCompare("shave",option+1) == 0)
2731 {
2732 /*
2733 Shave the image edges.
2734 */
cristy6fccee12011-10-20 18:43:18 +00002735 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002736 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2737 mogrify_image=ShaveImage(*image,&geometry,exception);
2738 break;
2739 }
2740 if (LocaleCompare("shear",option+1) == 0)
2741 {
2742 /*
2743 Shear image.
2744 */
cristy6fccee12011-10-20 18:43:18 +00002745 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002746 flags=ParseGeometry(argv[i+1],&geometry_info);
2747 if ((flags & SigmaValue) == 0)
2748 geometry_info.sigma=geometry_info.rho;
2749 mogrify_image=ShearImage(*image,geometry_info.rho,
2750 geometry_info.sigma,exception);
2751 break;
2752 }
2753 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2754 {
2755 /*
2756 Sigmoidal non-linearity contrast control.
2757 */
cristy6fccee12011-10-20 18:43:18 +00002758 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002759 flags=ParseGeometry(argv[i+1],&geometry_info);
2760 if ((flags & SigmaValue) == 0)
2761 geometry_info.sigma=(double) QuantumRange/2.0;
2762 if ((flags & PercentValue) != 0)
2763 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2764 100.0;
cristy9ee60942011-07-06 14:54:38 +00002765 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002766 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2767 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002768 break;
2769 }
2770 if (LocaleCompare("sketch",option+1) == 0)
2771 {
2772 /*
2773 Sketch image.
2774 */
cristy6fccee12011-10-20 18:43:18 +00002775 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002776 flags=ParseGeometry(argv[i+1],&geometry_info);
2777 if ((flags & SigmaValue) == 0)
2778 geometry_info.sigma=1.0;
2779 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00002780 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002781 break;
2782 }
2783 if (LocaleCompare("solarize",option+1) == 0)
2784 {
2785 double
2786 threshold;
2787
cristy6fccee12011-10-20 18:43:18 +00002788 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002789 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2790 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002791 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002792 break;
2793 }
2794 if (LocaleCompare("sparse-color",option+1) == 0)
2795 {
2796 SparseColorMethod
2797 method;
2798
2799 char
2800 *arguments;
2801
2802 /*
2803 Sparse Color Interpolated Gradient
2804 */
cristy6fccee12011-10-20 18:43:18 +00002805 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002806 method=(SparseColorMethod) ParseCommandOption(
2807 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002808 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2809 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002810 if (arguments == (char *) NULL)
2811 break;
cristy3884f692011-07-08 18:00:18 +00002812 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002813 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2814 arguments=DestroyString(arguments);
2815 break;
2816 }
2817 if (LocaleCompare("splice",option+1) == 0)
2818 {
2819 /*
2820 Splice a solid color into the image.
2821 */
cristy6fccee12011-10-20 18:43:18 +00002822 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002823 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2824 mogrify_image=SpliceImage(*image,&geometry,exception);
2825 break;
2826 }
2827 if (LocaleCompare("spread",option+1) == 0)
2828 {
2829 /*
2830 Spread an image.
2831 */
cristy6fccee12011-10-20 18:43:18 +00002832 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002833 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002834 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002835 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002836 break;
2837 }
2838 if (LocaleCompare("statistic",option+1) == 0)
2839 {
2840 StatisticType
2841 type;
2842
cristy6fccee12011-10-20 18:43:18 +00002843 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002844 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2845 MagickFalse,argv[i+1]);
2846 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002847 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2848 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002849 break;
2850 }
2851 if (LocaleCompare("stretch",option+1) == 0)
2852 {
2853 if (*option == '+')
2854 {
2855 draw_info->stretch=UndefinedStretch;
2856 break;
2857 }
2858 draw_info->stretch=(StretchType) ParseCommandOption(
2859 MagickStretchOptions,MagickFalse,argv[i+1]);
2860 break;
2861 }
2862 if (LocaleCompare("strip",option+1) == 0)
2863 {
2864 /*
2865 Strip image of profiles and comments.
2866 */
cristy6fccee12011-10-20 18:43:18 +00002867 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002868 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002869 break;
2870 }
2871 if (LocaleCompare("stroke",option+1) == 0)
2872 {
2873 ExceptionInfo
2874 *sans;
2875
anthonyfd706f92012-01-19 04:22:02 +00002876 PixelInfo
2877 color;
2878
anthonydf8ebac2011-04-27 09:03:19 +00002879 if (*option == '+')
2880 {
cristy9950d572011-10-01 18:22:35 +00002881 (void) QueryColorCompliance("none",AllCompliance,
2882 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002883 if (draw_info->stroke_pattern != (Image *) NULL)
2884 draw_info->stroke_pattern=DestroyImage(
2885 draw_info->stroke_pattern);
2886 break;
2887 }
2888 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00002889 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002890 sans=DestroyExceptionInfo(sans);
2891 if (status == MagickFalse)
2892 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2893 exception);
anthonyfd706f92012-01-19 04:22:02 +00002894 else
2895 draw_info->stroke=color;
anthonydf8ebac2011-04-27 09:03:19 +00002896 break;
2897 }
2898 if (LocaleCompare("strokewidth",option+1) == 0)
2899 {
cristy9b34e302011-11-05 02:15:45 +00002900 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002901 break;
2902 }
2903 if (LocaleCompare("style",option+1) == 0)
2904 {
2905 if (*option == '+')
2906 {
2907 draw_info->style=UndefinedStyle;
2908 break;
2909 }
2910 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2911 MagickFalse,argv[i+1]);
2912 break;
2913 }
2914 if (LocaleCompare("swirl",option+1) == 0)
2915 {
2916 /*
2917 Swirl image.
2918 */
cristy6fccee12011-10-20 18:43:18 +00002919 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002920 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002921 mogrify_image=SwirlImage(*image,geometry_info.rho,
2922 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002923 break;
2924 }
2925 break;
2926 }
2927 case 't':
2928 {
2929 if (LocaleCompare("threshold",option+1) == 0)
2930 {
2931 double
2932 threshold;
2933
2934 /*
2935 Threshold image.
2936 */
cristy6fccee12011-10-20 18:43:18 +00002937 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002938 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002939 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002940 else
cristy9b34e302011-11-05 02:15:45 +00002941 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2942 1.0);
cristye941a752011-10-15 01:52:48 +00002943 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002944 break;
2945 }
2946 if (LocaleCompare("thumbnail",option+1) == 0)
2947 {
2948 /*
2949 Thumbnail image.
2950 */
cristy6fccee12011-10-20 18:43:18 +00002951 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002952 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2953 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2954 exception);
2955 break;
2956 }
2957 if (LocaleCompare("tile",option+1) == 0)
2958 {
2959 if (*option == '+')
2960 {
2961 if (draw_info->fill_pattern != (Image *) NULL)
2962 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2963 break;
2964 }
2965 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2966 exception);
2967 break;
2968 }
2969 if (LocaleCompare("tint",option+1) == 0)
2970 {
2971 /*
2972 Tint the image.
2973 */
cristy6fccee12011-10-20 18:43:18 +00002974 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00002975 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002976 break;
2977 }
2978 if (LocaleCompare("transform",option+1) == 0)
2979 {
2980 /*
2981 Affine transform image.
2982 */
cristy6fccee12011-10-20 18:43:18 +00002983 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002984 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2985 exception);
2986 break;
2987 }
2988 if (LocaleCompare("transparent",option+1) == 0)
2989 {
cristy4c08aed2011-07-01 19:47:50 +00002990 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002991 target;
2992
cristy6fccee12011-10-20 18:43:18 +00002993 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002994 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002995 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002996 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00002997 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00002998 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002999 break;
3000 }
3001 if (LocaleCompare("transpose",option+1) == 0)
3002 {
3003 /*
3004 Transpose image scanlines.
3005 */
cristy6fccee12011-10-20 18:43:18 +00003006 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003007 mogrify_image=TransposeImage(*image,exception);
3008 break;
3009 }
3010 if (LocaleCompare("transverse",option+1) == 0)
3011 {
3012 /*
3013 Transverse image scanlines.
3014 */
cristy6fccee12011-10-20 18:43:18 +00003015 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003016 mogrify_image=TransverseImage(*image,exception);
3017 break;
3018 }
3019 if (LocaleCompare("treedepth",option+1) == 0)
3020 {
3021 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3022 break;
3023 }
3024 if (LocaleCompare("trim",option+1) == 0)
3025 {
3026 /*
3027 Trim image.
3028 */
cristy6fccee12011-10-20 18:43:18 +00003029 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003030 mogrify_image=TrimImage(*image,exception);
3031 break;
3032 }
3033 if (LocaleCompare("type",option+1) == 0)
3034 {
3035 ImageType
3036 type;
3037
cristy6fccee12011-10-20 18:43:18 +00003038 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003039 if (*option == '+')
3040 type=UndefinedType;
3041 else
3042 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3043 argv[i+1]);
3044 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003045 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003046 break;
3047 }
3048 break;
3049 }
3050 case 'u':
3051 {
3052 if (LocaleCompare("undercolor",option+1) == 0)
3053 {
cristy9950d572011-10-01 18:22:35 +00003054 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3055 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003056 break;
3057 }
3058 if (LocaleCompare("unique",option+1) == 0)
3059 {
3060 if (*option == '+')
3061 {
3062 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3063 break;
3064 }
3065 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3066 (void) SetImageArtifact(*image,"verbose","true");
3067 break;
3068 }
3069 if (LocaleCompare("unique-colors",option+1) == 0)
3070 {
3071 /*
3072 Unique image colors.
3073 */
cristy6fccee12011-10-20 18:43:18 +00003074 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003075 mogrify_image=UniqueImageColors(*image,exception);
3076 break;
3077 }
3078 if (LocaleCompare("unsharp",option+1) == 0)
3079 {
3080 /*
3081 Unsharp mask image.
3082 */
cristy6fccee12011-10-20 18:43:18 +00003083 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003084 flags=ParseGeometry(argv[i+1],&geometry_info);
3085 if ((flags & SigmaValue) == 0)
3086 geometry_info.sigma=1.0;
3087 if ((flags & XiValue) == 0)
3088 geometry_info.xi=1.0;
3089 if ((flags & PsiValue) == 0)
3090 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003091 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3092 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003093 break;
3094 }
3095 break;
3096 }
3097 case 'v':
3098 {
3099 if (LocaleCompare("verbose",option+1) == 0)
3100 {
3101 (void) SetImageArtifact(*image,option+1,
3102 *option == '+' ? "false" : "true");
3103 break;
3104 }
3105 if (LocaleCompare("vignette",option+1) == 0)
3106 {
3107 /*
3108 Vignette image.
3109 */
cristy6fccee12011-10-20 18:43:18 +00003110 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003111 flags=ParseGeometry(argv[i+1],&geometry_info);
3112 if ((flags & SigmaValue) == 0)
3113 geometry_info.sigma=1.0;
3114 if ((flags & XiValue) == 0)
3115 geometry_info.xi=0.1*(*image)->columns;
3116 if ((flags & PsiValue) == 0)
3117 geometry_info.psi=0.1*(*image)->rows;
3118 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyaa2c16c2012-03-25 22:21:35 +00003119 geometry_info.sigma,(ssize_t) ceil(geometry_info.xi-0.5),
3120 (ssize_t) ceil(geometry_info.psi-0.5),exception);
anthonydf8ebac2011-04-27 09:03:19 +00003121 break;
3122 }
3123 if (LocaleCompare("virtual-pixel",option+1) == 0)
3124 {
3125 if (*option == '+')
3126 {
3127 (void) SetImageVirtualPixelMethod(*image,
cristy387430f2012-02-07 13:09:46 +00003128 UndefinedVirtualPixelMethod,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003129 break;
3130 }
3131 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3132 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy387430f2012-02-07 13:09:46 +00003133 argv[i+1]),exception);
anthonydf8ebac2011-04-27 09:03:19 +00003134 break;
3135 }
3136 break;
3137 }
3138 case 'w':
3139 {
3140 if (LocaleCompare("wave",option+1) == 0)
3141 {
3142 /*
3143 Wave image.
3144 */
cristy6fccee12011-10-20 18:43:18 +00003145 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003146 flags=ParseGeometry(argv[i+1],&geometry_info);
3147 if ((flags & SigmaValue) == 0)
3148 geometry_info.sigma=1.0;
3149 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003150 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003151 break;
3152 }
3153 if (LocaleCompare("weight",option+1) == 0)
3154 {
3155 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3156 if (LocaleCompare(argv[i+1],"all") == 0)
3157 draw_info->weight=0;
3158 if (LocaleCompare(argv[i+1],"bold") == 0)
3159 draw_info->weight=700;
3160 if (LocaleCompare(argv[i+1],"bolder") == 0)
3161 if (draw_info->weight <= 800)
3162 draw_info->weight+=100;
3163 if (LocaleCompare(argv[i+1],"lighter") == 0)
3164 if (draw_info->weight >= 100)
3165 draw_info->weight-=100;
3166 if (LocaleCompare(argv[i+1],"normal") == 0)
3167 draw_info->weight=400;
3168 break;
3169 }
3170 if (LocaleCompare("white-threshold",option+1) == 0)
3171 {
3172 /*
3173 White threshold image.
3174 */
cristy6fccee12011-10-20 18:43:18 +00003175 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003176 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003177 break;
3178 }
3179 break;
3180 }
3181 default:
3182 break;
3183 }
3184 /*
3185 Replace current image with any image that was generated
3186 */
3187 if (mogrify_image != (Image *) NULL)
3188 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003189 i+=count;
3190 }
3191 if (region_image != (Image *) NULL)
3192 {
anthonydf8ebac2011-04-27 09:03:19 +00003193 /*
3194 Composite transformed region onto image.
3195 */
cristy6fccee12011-10-20 18:43:18 +00003196 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyfeb3e962012-03-29 17:25:55 +00003197 (void) CompositeImage(region_image,*image,region_image->matte !=
cristy39172402012-03-30 13:04:39 +00003198 MagickFalse ? CopyCompositeOp : OverCompositeOp,MagickTrue,
cristye941a752011-10-15 01:52:48 +00003199 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003200 *image=DestroyImage(*image);
3201 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003202 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003203 }
3204 /*
3205 Free resources.
3206 */
anthonydf8ebac2011-04-27 09:03:19 +00003207 quantize_info=DestroyQuantizeInfo(quantize_info);
3208 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003209 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003210 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003211 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003212}
3213
3214/*
3215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3216% %
3217% %
3218% %
cristy5063d812010-10-19 16:28:10 +00003219+ 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 +00003220% %
3221% %
3222% %
3223%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3224%
3225% MogrifyImageCommand() transforms an image or a sequence of images. These
3226% transforms include image scaling, image rotation, color reduction, and
3227% others. The transmogrified image overwrites the original image.
3228%
3229% The format of the MogrifyImageCommand method is:
3230%
3231% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3232% const char **argv,char **metadata,ExceptionInfo *exception)
3233%
3234% A description of each parameter follows:
3235%
3236% o image_info: the image info.
3237%
3238% o argc: the number of elements in the argument vector.
3239%
3240% o argv: A text array containing the command line arguments.
3241%
3242% o metadata: any metadata is returned here.
3243%
3244% o exception: return any errors or warnings in this structure.
3245%
3246*/
3247
3248static MagickBooleanType MogrifyUsage(void)
3249{
3250 static const char
cristy87c02f42012-02-24 00:19:10 +00003251 *channel_operators[]=
3252 {
cristy5f257b22012-03-07 00:27:29 +00003253 "-channel-fx expression",
cristyd04e7bf2012-03-03 19:19:12 +00003254 " exchange, extract, or transfer one or more image channels",
cristydfdb19e2012-03-21 22:22:24 +00003255 "-separate separate an image channel into a grayscale image",
cristy87c02f42012-02-24 00:19:10 +00003256 (char *) NULL
3257 },
cristy3ed852e2009-09-05 21:47:34 +00003258 *miscellaneous[]=
3259 {
3260 "-debug events display copious debugging information",
3261 "-help print program options",
3262 "-list type print a list of supported option arguments",
3263 "-log format format of debugging information",
3264 "-version print version information",
3265 (char *) NULL
3266 },
3267 *operators[]=
3268 {
3269 "-adaptive-blur geometry",
3270 " adaptively blur pixels; decrease effect near edges",
3271 "-adaptive-resize geometry",
3272 " adaptively resize image using 'mesh' interpolation",
3273 "-adaptive-sharpen geometry",
3274 " adaptively sharpen pixels; increase effect near edges",
3275 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3276 " transparent, extract, background, or shape",
3277 "-annotate geometry text",
3278 " annotate the image with text",
3279 "-auto-gamma automagically adjust gamma level of image",
3280 "-auto-level automagically adjust color levels of image",
3281 "-auto-orient automagically orient (rotate) image",
3282 "-bench iterations measure performance",
3283 "-black-threshold value",
3284 " force all pixels below the threshold into black",
3285 "-blue-shift simulate a scene at nighttime in the moonlight",
3286 "-blur geometry reduce image noise and reduce detail levels",
3287 "-border geometry surround image with a border of color",
3288 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003289 "-brightness-contrast geometry",
3290 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003291 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003292 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003293 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003294 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003295 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003296 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003297 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003298 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003299 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003300 "-contrast enhance or reduce the image contrast",
3301 "-contrast-stretch geometry",
3302 " improve contrast by `stretching' the intensity range",
3303 "-convolve coefficients",
3304 " apply a convolution kernel to the image",
3305 "-cycle amount cycle the image colormap",
3306 "-decipher filename convert cipher pixels to plain pixels",
3307 "-deskew threshold straighten an image",
3308 "-despeckle reduce the speckles within an image",
3309 "-distort method args",
3310 " distort images according to given method ad args",
3311 "-draw string annotate the image with a graphic primitive",
3312 "-edge radius apply a filter to detect edges in the image",
3313 "-encipher filename convert plain pixels to cipher pixels",
3314 "-emboss radius emboss an image",
3315 "-enhance apply a digital filter to enhance a noisy image",
3316 "-equalize perform histogram equalization to an image",
3317 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003318 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003319 "-extent geometry set the image size",
3320 "-extract geometry extract area from image",
3321 "-fft implements the discrete Fourier transform (DFT)",
3322 "-flip flip image vertically",
3323 "-floodfill geometry color",
3324 " floodfill the image with color",
3325 "-flop flop image horizontally",
3326 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003327 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003328 " apply function over image values",
3329 "-gamma value level of gamma correction",
3330 "-gaussian-blur geometry",
3331 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003332 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003333 "-identify identify the format and characteristics of the image",
3334 "-ift implements the inverse discrete Fourier transform (DFT)",
3335 "-implode amount implode image pixels about the center",
anthonyfd706f92012-01-19 04:22:02 +00003336 "-interpolative-resize geometry",
3337 " resize image using interpolation",
cristy3ed852e2009-09-05 21:47:34 +00003338 "-lat geometry local adaptive thresholding",
3339 "-layers method optimize, merge, or compare image layers",
3340 "-level value adjust the level of image contrast",
3341 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003342 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003343 "-linear-stretch geometry",
3344 " improve contrast by `stretching with saturation'",
3345 "-liquid-rescale geometry",
3346 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003347 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003348 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003349 "-modulate value vary the brightness, saturation, and hue",
3350 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003351 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003352 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003353 "-motion-blur geometry",
3354 " simulate motion blur",
3355 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003356 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003357 "-normalize transform image to span the full range of colors",
3358 "-opaque color change this color to the fill color",
3359 "-ordered-dither NxN",
3360 " add a noise pattern to the image with specific",
3361 " amplitudes",
3362 "-paint radius simulate an oil painting",
3363 "-polaroid angle simulate a Polaroid picture",
3364 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003365 "-profile filename add, delete, or apply an image profile",
3366 "-quantize colorspace reduce colors in this colorspace",
3367 "-radial-blur angle radial blur the image",
3368 "-raise value lighten/darken image edges to create a 3-D effect",
3369 "-random-threshold low,high",
3370 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003371 "-region geometry apply options to a portion of the image",
3372 "-render render vector graphics",
3373 "-repage geometry size and location of an image canvas",
3374 "-resample geometry change the resolution of an image",
3375 "-resize geometry resize the image",
3376 "-roll geometry roll an image vertically or horizontally",
3377 "-rotate degrees apply Paeth rotation to the image",
3378 "-sample geometry scale image with pixel sampling",
3379 "-scale geometry scale the image",
3380 "-segment values segment an image",
3381 "-selective-blur geometry",
3382 " selectively blur pixels within a contrast threshold",
3383 "-sepia-tone threshold",
3384 " simulate a sepia-toned photo",
3385 "-set property value set an image property",
3386 "-shade degrees shade the image using a distant light source",
3387 "-shadow geometry simulate an image shadow",
3388 "-sharpen geometry sharpen the image",
3389 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003390 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003391 "-sigmoidal-contrast geometry",
3392 " increase the contrast without saturating highlights or shadows",
3393 "-sketch geometry simulate a pencil sketch",
3394 "-solarize threshold negate all pixels above the threshold level",
3395 "-sparse-color method args",
3396 " fill in a image based on a few color points",
3397 "-splice geometry splice the background color into the image",
3398 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003399 "-statistic type radius",
3400 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003401 "-strip strip image of all profiles and comments",
3402 "-swirl degrees swirl image pixels about the center",
3403 "-threshold value threshold the image",
3404 "-thumbnail geometry create a thumbnail of the image",
3405 "-tile filename tile image when filling a graphic primitive",
3406 "-tint value tint the image with the fill color",
3407 "-transform affine transform image",
3408 "-transparent color make this color transparent within the image",
3409 "-transpose flip image vertically and rotate 90 degrees",
3410 "-transverse flop image horizontally and rotate 270 degrees",
3411 "-trim trim image edges",
3412 "-type type image type",
3413 "-unique-colors discard all but one of any pixel color",
3414 "-unsharp geometry sharpen the image",
3415 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003416 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003417 "-white-threshold value",
3418 " force all pixels above the threshold into white",
3419 (char *) NULL
3420 },
3421 *sequence_operators[]=
3422 {
cristy4285d782011-02-09 20:12:28 +00003423 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003424 "-clut apply a color lookup table to the image",
3425 "-coalesce merge a sequence of images",
3426 "-combine combine a sequence of images",
3427 "-composite composite image",
3428 "-crop geometry cut out a rectangular region of the image",
3429 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003430 "-evaluate-sequence operator",
3431 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003432 "-flatten flatten a sequence of images",
3433 "-fx expression apply mathematical expression to an image channel(s)",
3434 "-hald-clut apply a Hald color lookup table to the image",
3435 "-morph value morph an image sequence",
3436 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003437 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003438 "-process arguments process the image with a custom image filter",
cristy4285d782011-02-09 20:12:28 +00003439 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003440 "-write filename write images to this file",
3441 (char *) NULL
3442 },
3443 *settings[]=
3444 {
3445 "-adjoin join images into a single multi-image file",
3446 "-affine matrix affine transform matrix",
3447 "-alpha option activate, deactivate, reset, or set the alpha channel",
3448 "-antialias remove pixel-aliasing",
3449 "-authenticate password",
3450 " decipher image with this password",
3451 "-attenuate value lessen (or intensify) when adding noise to an image",
3452 "-background color background color",
3453 "-bias value add bias when convolving an image",
3454 "-black-point-compensation",
3455 " use black point compensation",
3456 "-blue-primary point chromaticity blue primary point",
3457 "-bordercolor color border color",
3458 "-caption string assign a caption to an image",
3459 "-channel type apply option to select image channels",
3460 "-colors value preferred number of colors in the image",
3461 "-colorspace type alternate image colorspace",
3462 "-comment string annotate image with comment",
3463 "-compose operator set image composite operator",
3464 "-compress type type of pixel compression when writing the image",
anthonyfd706f92012-01-19 04:22:02 +00003465 "-define format:option=value",
cristy3ed852e2009-09-05 21:47:34 +00003466 " define one or more image format options",
3467 "-delay value display the next image after pausing",
3468 "-density geometry horizontal and vertical density of the image",
3469 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003470 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003471 "-display server get image or font from this X server",
3472 "-dispose method layer disposal method",
3473 "-dither method apply error diffusion to image",
3474 "-encoding type text encoding type",
3475 "-endian type endianness (MSB or LSB) of the image",
3476 "-family name render text with this font family",
3477 "-fill color color to use when filling a graphic primitive",
3478 "-filter type use this filter when resizing an image",
3479 "-font name render text with this font",
anthonyfd706f92012-01-19 04:22:02 +00003480 "-format \"string\" output formatted image characteristics",
cristy3ed852e2009-09-05 21:47:34 +00003481 "-fuzz distance colors within this distance are considered equal",
3482 "-gravity type horizontal and vertical text placement",
3483 "-green-primary point chromaticity green primary point",
3484 "-intent type type of rendering intent when managing the image color",
3485 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003486 "-interline-spacing value",
3487 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003488 "-interpolate method pixel color interpolation method",
3489 "-interword-spacing value",
3490 " set the space between two words",
3491 "-kerning value set the space between two letters",
3492 "-label string assign a label to an image",
3493 "-limit type value pixel cache resource limit",
3494 "-loop iterations add Netscape loop extension to your GIF animation",
3495 "-mask filename associate a mask with the image",
3496 "-mattecolor color frame color",
3497 "-monitor monitor progress",
3498 "-orient type image orientation",
3499 "-page geometry size and location of an image canvas (setting)",
3500 "-ping efficiently determine image attributes",
3501 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003502 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003503 "-preview type image preview type",
3504 "-quality value JPEG/MIFF/PNG compression level",
3505 "-quiet suppress all warning messages",
3506 "-red-primary point chromaticity red primary point",
3507 "-regard-warnings pay attention to warning messages",
3508 "-remap filename transform image colors to match this set of colors",
3509 "-respect-parentheses settings remain in effect until parenthesis boundary",
3510 "-sampling-factor geometry",
3511 " horizontal and vertical sampling factor",
3512 "-scene value image scene number",
3513 "-seed value seed a new sequence of pseudo-random numbers",
3514 "-size geometry width and height of image",
3515 "-stretch type render text with this font stretch",
3516 "-stroke color graphic primitive stroke color",
3517 "-strokewidth value graphic primitive stroke width",
3518 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003519 "-synchronize synchronize image to storage device",
3520 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003521 "-texture filename name of texture to tile onto the image background",
3522 "-tile-offset geometry",
3523 " tile offset",
3524 "-treedepth value color tree depth",
3525 "-transparent-color color",
3526 " transparent color",
3527 "-undercolor color annotation bounding box color",
3528 "-units type the units of image resolution",
3529 "-verbose print detailed information about the image",
3530 "-view FlashPix viewing transforms",
3531 "-virtual-pixel method",
3532 " virtual pixel access method",
3533 "-weight type render text with this font weight",
3534 "-white-point point chromaticity white point",
3535 (char *) NULL
3536 },
3537 *stack_operators[]=
3538 {
anthonyb69c4b32011-03-23 04:37:44 +00003539 "-delete indexes delete the image from the image sequence",
3540 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003541 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003542 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003543 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003544 "-swap indexes swap two images in the image sequence",
3545 (char *) NULL
3546 };
3547
3548 const char
3549 **p;
3550
cristybb503372010-05-27 20:51:26 +00003551 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003552 (void) printf("Copyright: %s\n",GetMagickCopyright());
3553 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003554 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3555 GetClientName());
3556 (void) printf("\nImage Settings:\n");
3557 for (p=settings; *p != (char *) NULL; p++)
3558 (void) printf(" %s\n",*p);
3559 (void) printf("\nImage Operators:\n");
3560 for (p=operators; *p != (char *) NULL; p++)
3561 (void) printf(" %s\n",*p);
cristy87c02f42012-02-24 00:19:10 +00003562 (void) printf("\nImage Channel Operators:\n");
3563 for (p=channel_operators; *p != (char *) NULL; p++)
3564 (void) printf(" %s\n",*p);
cristy3ed852e2009-09-05 21:47:34 +00003565 (void) printf("\nImage Sequence Operators:\n");
3566 for (p=sequence_operators; *p != (char *) NULL; p++)
3567 (void) printf(" %s\n",*p);
3568 (void) printf("\nImage Stack Operators:\n");
3569 for (p=stack_operators; *p != (char *) NULL; p++)
3570 (void) printf(" %s\n",*p);
3571 (void) printf("\nMiscellaneous Options:\n");
3572 for (p=miscellaneous; *p != (char *) NULL; p++)
3573 (void) printf(" %s\n",*p);
3574 (void) printf(
anthonyfd706f92012-01-19 04:22:02 +00003575 "\nBy default, the image format of 'file' is determined by its magic\n");
cristy3ed852e2009-09-05 21:47:34 +00003576 (void) printf(
3577 "number. To specify a particular image format, precede the filename\n");
3578 (void) printf(
3579 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3580 (void) printf(
3581 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3582 (void) printf("'-' for standard input or output.\n");
3583 return(MagickFalse);
3584}
3585
3586WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3587 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3588{
3589#define DestroyMogrify() \
3590{ \
3591 if (format != (char *) NULL) \
3592 format=DestroyString(format); \
3593 if (path != (char *) NULL) \
3594 path=DestroyString(path); \
3595 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003596 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003597 argv[i]=DestroyString(argv[i]); \
3598 argv=(char **) RelinquishMagickMemory(argv); \
3599}
3600#define ThrowMogrifyException(asperity,tag,option) \
3601{ \
3602 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3603 option); \
3604 DestroyMogrify(); \
3605 return(MagickFalse); \
3606}
3607#define ThrowMogrifyInvalidArgumentException(option,argument) \
3608{ \
3609 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3610 "InvalidArgument","`%s': %s",argument,option); \
3611 DestroyMogrify(); \
3612 return(MagickFalse); \
3613}
3614
3615 char
3616 *format,
3617 *option,
3618 *path;
3619
3620 Image
3621 *image;
3622
3623 ImageStack
3624 image_stack[MaxImageStackDepth+1];
3625
cristy3ed852e2009-09-05 21:47:34 +00003626 MagickBooleanType
3627 global_colormap;
3628
3629 MagickBooleanType
3630 fire,
cristyebbcfea2011-02-25 02:43:54 +00003631 pend,
3632 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003633
3634 MagickStatusType
3635 status;
3636
cristyebbcfea2011-02-25 02:43:54 +00003637 register ssize_t
3638 i;
3639
3640 ssize_t
3641 j,
3642 k;
3643
cristy3ed852e2009-09-05 21:47:34 +00003644 /*
3645 Set defaults.
3646 */
3647 assert(image_info != (ImageInfo *) NULL);
3648 assert(image_info->signature == MagickSignature);
3649 if (image_info->debug != MagickFalse)
3650 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3651 assert(exception != (ExceptionInfo *) NULL);
3652 if (argc == 2)
3653 {
3654 option=argv[1];
3655 if ((LocaleCompare("version",option+1) == 0) ||
3656 (LocaleCompare("-version",option+1) == 0))
3657 {
cristyb51dff52011-05-19 16:55:47 +00003658 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003659 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003660 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3661 GetMagickCopyright());
3662 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3663 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003664 return(MagickFalse);
3665 }
3666 }
3667 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003668 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003669 format=(char *) NULL;
3670 path=(char *) NULL;
3671 global_colormap=MagickFalse;
3672 k=0;
3673 j=1;
3674 NewImageStack();
3675 option=(char *) NULL;
3676 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003677 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003678 status=MagickTrue;
3679 /*
3680 Parse command line.
3681 */
3682 ReadCommandlLine(argc,&argv);
3683 status=ExpandFilenames(&argc,&argv);
3684 if (status == MagickFalse)
3685 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3686 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003687 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003688 {
3689 option=argv[i];
3690 if (LocaleCompare(option,"(") == 0)
3691 {
3692 FireImageStack(MagickFalse,MagickTrue,pend);
3693 if (k == MaxImageStackDepth)
3694 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3695 option);
3696 PushImageStack();
3697 continue;
3698 }
3699 if (LocaleCompare(option,")") == 0)
3700 {
3701 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3702 if (k == 0)
3703 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3704 PopImageStack();
3705 continue;
3706 }
cristy042ee782011-04-22 18:48:30 +00003707 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003708 {
3709 char
3710 backup_filename[MaxTextExtent],
3711 *filename;
3712
3713 Image
3714 *images;
3715
3716 /*
3717 Option is a file name: begin by reading image from specified file.
3718 */
3719 FireImageStack(MagickFalse,MagickFalse,pend);
3720 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003721 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003722 filename=argv[++i];
cristy1b58f252012-03-01 01:41:41 +00003723 images=ReadImages(image_info,filename,exception);
cristy3ed852e2009-09-05 21:47:34 +00003724 status&=(images != (Image *) NULL) &&
3725 (exception->severity < ErrorException);
3726 if (images == (Image *) NULL)
3727 continue;
cristydaa76602010-06-30 13:05:11 +00003728 if (format != (char *) NULL)
3729 (void) CopyMagickString(images->filename,images->magick_filename,
3730 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003731 if (path != (char *) NULL)
3732 {
3733 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003734 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003735 path,*DirectorySeparator,filename);
3736 }
3737 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003738 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003739 AppendImageStack(images);
3740 FinalizeImageSettings(image_info,image,MagickFalse);
3741 if (global_colormap != MagickFalse)
3742 {
3743 QuantizeInfo
3744 *quantize_info;
3745
3746 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003747 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003748 quantize_info=DestroyQuantizeInfo(quantize_info);
3749 }
3750 *backup_filename='\0';
3751 if ((LocaleCompare(image->filename,"-") != 0) &&
3752 (IsPathWritable(image->filename) != MagickFalse))
3753 {
cristybb503372010-05-27 20:51:26 +00003754 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003755 i;
3756
3757 /*
3758 Rename image file as backup.
3759 */
3760 (void) CopyMagickString(backup_filename,image->filename,
3761 MaxTextExtent);
3762 for (i=0; i < 6; i++)
3763 {
3764 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3765 if (IsPathAccessible(backup_filename) == MagickFalse)
3766 break;
3767 }
3768 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003769 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003770 *backup_filename='\0';
3771 }
3772 /*
3773 Write transmogrified image to disk.
3774 */
3775 image_info->synchronize=MagickTrue;
3776 status&=WriteImages(image_info,image,image->filename,exception);
3777 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003778 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003779 RemoveAllImageStack();
3780 continue;
3781 }
3782 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3783 switch (*(option+1))
3784 {
3785 case 'a':
3786 {
3787 if (LocaleCompare("adaptive-blur",option+1) == 0)
3788 {
3789 i++;
cristybb503372010-05-27 20:51:26 +00003790 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003791 ThrowMogrifyException(OptionError,"MissingArgument",option);
3792 if (IsGeometry(argv[i]) == MagickFalse)
3793 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3794 break;
3795 }
3796 if (LocaleCompare("adaptive-resize",option+1) == 0)
3797 {
3798 i++;
cristybb503372010-05-27 20:51:26 +00003799 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003800 ThrowMogrifyException(OptionError,"MissingArgument",option);
3801 if (IsGeometry(argv[i]) == MagickFalse)
3802 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3803 break;
3804 }
3805 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3806 {
3807 i++;
cristybb503372010-05-27 20:51:26 +00003808 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003809 ThrowMogrifyException(OptionError,"MissingArgument",option);
3810 if (IsGeometry(argv[i]) == MagickFalse)
3811 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3812 break;
3813 }
3814 if (LocaleCompare("affine",option+1) == 0)
3815 {
3816 if (*option == '+')
3817 break;
3818 i++;
cristybb503372010-05-27 20:51:26 +00003819 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003820 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003821 break;
3822 }
3823 if (LocaleCompare("alpha",option+1) == 0)
3824 {
cristybb503372010-05-27 20:51:26 +00003825 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003826 type;
3827
3828 if (*option == '+')
3829 break;
3830 i++;
cristybb503372010-05-27 20:51:26 +00003831 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003832 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003833 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003834 if (type < 0)
3835 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3836 argv[i]);
3837 break;
3838 }
3839 if (LocaleCompare("annotate",option+1) == 0)
3840 {
3841 if (*option == '+')
3842 break;
3843 i++;
cristybb503372010-05-27 20:51:26 +00003844 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003845 ThrowMogrifyException(OptionError,"MissingArgument",option);
3846 if (IsGeometry(argv[i]) == MagickFalse)
3847 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003848 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003849 ThrowMogrifyException(OptionError,"MissingArgument",option);
3850 i++;
3851 break;
3852 }
3853 if (LocaleCompare("antialias",option+1) == 0)
3854 break;
3855 if (LocaleCompare("append",option+1) == 0)
3856 break;
3857 if (LocaleCompare("attenuate",option+1) == 0)
3858 {
3859 if (*option == '+')
3860 break;
3861 i++;
cristybb503372010-05-27 20:51:26 +00003862 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003863 ThrowMogrifyException(OptionError,"MissingArgument",option);
3864 if (IsGeometry(argv[i]) == MagickFalse)
3865 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3866 break;
3867 }
3868 if (LocaleCompare("authenticate",option+1) == 0)
3869 {
3870 if (*option == '+')
3871 break;
3872 i++;
cristybb503372010-05-27 20:51:26 +00003873 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003874 ThrowMogrifyException(OptionError,"MissingArgument",option);
3875 break;
3876 }
3877 if (LocaleCompare("auto-gamma",option+1) == 0)
3878 break;
3879 if (LocaleCompare("auto-level",option+1) == 0)
3880 break;
3881 if (LocaleCompare("auto-orient",option+1) == 0)
3882 break;
3883 if (LocaleCompare("average",option+1) == 0)
3884 break;
3885 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3886 }
3887 case 'b':
3888 {
3889 if (LocaleCompare("background",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("bias",option+1) == 0)
3899 {
3900 if (*option == '+')
3901 break;
3902 i++;
cristybb503372010-05-27 20:51:26 +00003903 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003904 ThrowMogrifyException(OptionError,"MissingArgument",option);
3905 if (IsGeometry(argv[i]) == MagickFalse)
3906 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3907 break;
3908 }
3909 if (LocaleCompare("black-point-compensation",option+1) == 0)
3910 break;
3911 if (LocaleCompare("black-threshold",option+1) == 0)
3912 {
3913 if (*option == '+')
3914 break;
3915 i++;
cristybb503372010-05-27 20:51:26 +00003916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003917 ThrowMogrifyException(OptionError,"MissingArgument",option);
3918 if (IsGeometry(argv[i]) == MagickFalse)
3919 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3920 break;
3921 }
3922 if (LocaleCompare("blue-primary",option+1) == 0)
3923 {
3924 if (*option == '+')
3925 break;
3926 i++;
cristybb503372010-05-27 20:51:26 +00003927 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003928 ThrowMogrifyException(OptionError,"MissingArgument",option);
3929 if (IsGeometry(argv[i]) == MagickFalse)
3930 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3931 break;
3932 }
3933 if (LocaleCompare("blue-shift",option+1) == 0)
3934 {
3935 i++;
cristybb503372010-05-27 20:51:26 +00003936 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003937 ThrowMogrifyException(OptionError,"MissingArgument",option);
3938 if (IsGeometry(argv[i]) == MagickFalse)
3939 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3940 break;
3941 }
3942 if (LocaleCompare("blur",option+1) == 0)
3943 {
3944 i++;
cristybb503372010-05-27 20:51:26 +00003945 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003946 ThrowMogrifyException(OptionError,"MissingArgument",option);
3947 if (IsGeometry(argv[i]) == MagickFalse)
3948 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3949 break;
3950 }
3951 if (LocaleCompare("border",option+1) == 0)
3952 {
3953 if (*option == '+')
3954 break;
3955 i++;
cristybb503372010-05-27 20:51:26 +00003956 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003957 ThrowMogrifyException(OptionError,"MissingArgument",option);
3958 if (IsGeometry(argv[i]) == MagickFalse)
3959 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3960 break;
3961 }
3962 if (LocaleCompare("bordercolor",option+1) == 0)
3963 {
3964 if (*option == '+')
3965 break;
3966 i++;
cristybb503372010-05-27 20:51:26 +00003967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003968 ThrowMogrifyException(OptionError,"MissingArgument",option);
3969 break;
3970 }
3971 if (LocaleCompare("box",option+1) == 0)
3972 {
3973 if (*option == '+')
3974 break;
3975 i++;
cristybb503372010-05-27 20:51:26 +00003976 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003977 ThrowMogrifyException(OptionError,"MissingArgument",option);
3978 break;
3979 }
cristya28d6b82010-01-11 20:03:47 +00003980 if (LocaleCompare("brightness-contrast",option+1) == 0)
3981 {
3982 i++;
cristybb503372010-05-27 20:51:26 +00003983 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003984 ThrowMogrifyException(OptionError,"MissingArgument",option);
3985 if (IsGeometry(argv[i]) == MagickFalse)
3986 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3987 break;
3988 }
cristy3ed852e2009-09-05 21:47:34 +00003989 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3990 }
3991 case 'c':
3992 {
3993 if (LocaleCompare("cache",option+1) == 0)
3994 {
3995 if (*option == '+')
3996 break;
3997 i++;
cristybb503372010-05-27 20:51:26 +00003998 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003999 ThrowMogrifyException(OptionError,"MissingArgument",option);
4000 if (IsGeometry(argv[i]) == MagickFalse)
4001 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4002 break;
4003 }
4004 if (LocaleCompare("caption",option+1) == 0)
4005 {
4006 if (*option == '+')
4007 break;
4008 i++;
cristybb503372010-05-27 20:51:26 +00004009 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004010 ThrowMogrifyException(OptionError,"MissingArgument",option);
4011 break;
4012 }
4013 if (LocaleCompare("channel",option+1) == 0)
4014 {
cristybb503372010-05-27 20:51:26 +00004015 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004016 channel;
4017
4018 if (*option == '+')
4019 break;
4020 i++;
cristybb503372010-05-27 20:51:26 +00004021 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004022 ThrowMogrifyException(OptionError,"MissingArgument",option);
4023 channel=ParseChannelOption(argv[i]);
4024 if (channel < 0)
4025 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4026 argv[i]);
4027 break;
4028 }
cristy5f257b22012-03-07 00:27:29 +00004029 if (LocaleCompare("channel-fx",option+1) == 0)
cristy87c02f42012-02-24 00:19:10 +00004030 {
4031 ssize_t
4032 channel;
4033
4034 if (*option == '+')
4035 break;
4036 i++;
4037 if (i == (ssize_t) (argc-1))
4038 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy953c4bd2012-02-24 01:04:04 +00004039 channel=ParsePixelChannelOption(argv[i]);
cristy87c02f42012-02-24 00:19:10 +00004040 if (channel < 0)
4041 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4042 argv[i]);
4043 break;
4044 }
cristy3ed852e2009-09-05 21:47:34 +00004045 if (LocaleCompare("cdl",option+1) == 0)
4046 {
4047 if (*option == '+')
4048 break;
4049 i++;
cristybb503372010-05-27 20:51:26 +00004050 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004051 ThrowMogrifyException(OptionError,"MissingArgument",option);
4052 break;
4053 }
4054 if (LocaleCompare("charcoal",option+1) == 0)
4055 {
4056 if (*option == '+')
4057 break;
4058 i++;
cristybb503372010-05-27 20:51:26 +00004059 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004060 ThrowMogrifyException(OptionError,"MissingArgument",option);
4061 if (IsGeometry(argv[i]) == MagickFalse)
4062 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4063 break;
4064 }
4065 if (LocaleCompare("chop",option+1) == 0)
4066 {
4067 if (*option == '+')
4068 break;
4069 i++;
cristybb503372010-05-27 20:51:26 +00004070 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004071 ThrowMogrifyException(OptionError,"MissingArgument",option);
4072 if (IsGeometry(argv[i]) == MagickFalse)
4073 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4074 break;
4075 }
cristy1eb45dd2009-09-25 16:38:06 +00004076 if (LocaleCompare("clamp",option+1) == 0)
4077 break;
4078 if (LocaleCompare("clip",option+1) == 0)
4079 break;
cristy3ed852e2009-09-05 21:47:34 +00004080 if (LocaleCompare("clip-mask",option+1) == 0)
4081 {
4082 if (*option == '+')
4083 break;
4084 i++;
cristybb503372010-05-27 20:51:26 +00004085 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004086 ThrowMogrifyException(OptionError,"MissingArgument",option);
4087 break;
4088 }
4089 if (LocaleCompare("clut",option+1) == 0)
4090 break;
4091 if (LocaleCompare("coalesce",option+1) == 0)
4092 break;
4093 if (LocaleCompare("colorize",option+1) == 0)
4094 {
4095 if (*option == '+')
4096 break;
4097 i++;
cristybb503372010-05-27 20:51:26 +00004098 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004099 ThrowMogrifyException(OptionError,"MissingArgument",option);
4100 if (IsGeometry(argv[i]) == MagickFalse)
4101 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4102 break;
4103 }
cristye6365592010-04-02 17:31:23 +00004104 if (LocaleCompare("color-matrix",option+1) == 0)
4105 {
cristyb6bd4ad2010-08-08 01:12:27 +00004106 KernelInfo
4107 *kernel_info;
4108
cristye6365592010-04-02 17:31:23 +00004109 if (*option == '+')
4110 break;
4111 i++;
cristybb503372010-05-27 20:51:26 +00004112 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004113 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004114 kernel_info=AcquireKernelInfo(argv[i]);
4115 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004116 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004117 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004118 break;
4119 }
cristy3ed852e2009-09-05 21:47:34 +00004120 if (LocaleCompare("colors",option+1) == 0)
4121 {
4122 if (*option == '+')
4123 break;
4124 i++;
cristybb503372010-05-27 20:51:26 +00004125 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004126 ThrowMogrifyException(OptionError,"MissingArgument",option);
4127 if (IsGeometry(argv[i]) == MagickFalse)
4128 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4129 break;
4130 }
4131 if (LocaleCompare("colorspace",option+1) == 0)
4132 {
cristybb503372010-05-27 20:51:26 +00004133 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004134 colorspace;
4135
4136 if (*option == '+')
4137 break;
4138 i++;
cristybb503372010-05-27 20:51:26 +00004139 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004140 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004141 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004142 argv[i]);
4143 if (colorspace < 0)
4144 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4145 argv[i]);
4146 break;
4147 }
4148 if (LocaleCompare("combine",option+1) == 0)
4149 break;
4150 if (LocaleCompare("comment",option+1) == 0)
4151 {
4152 if (*option == '+')
4153 break;
4154 i++;
cristybb503372010-05-27 20:51:26 +00004155 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004156 ThrowMogrifyException(OptionError,"MissingArgument",option);
4157 break;
4158 }
4159 if (LocaleCompare("composite",option+1) == 0)
4160 break;
4161 if (LocaleCompare("compress",option+1) == 0)
4162 {
cristybb503372010-05-27 20:51:26 +00004163 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004164 compress;
4165
4166 if (*option == '+')
4167 break;
4168 i++;
cristybb503372010-05-27 20:51:26 +00004169 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004170 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004171 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004172 argv[i]);
4173 if (compress < 0)
4174 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4175 argv[i]);
4176 break;
4177 }
cristy22879752009-10-25 23:55:40 +00004178 if (LocaleCompare("concurrent",option+1) == 0)
4179 break;
cristy3ed852e2009-09-05 21:47:34 +00004180 if (LocaleCompare("contrast",option+1) == 0)
4181 break;
4182 if (LocaleCompare("contrast-stretch",option+1) == 0)
4183 {
4184 i++;
cristybb503372010-05-27 20:51:26 +00004185 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004186 ThrowMogrifyException(OptionError,"MissingArgument",option);
4187 if (IsGeometry(argv[i]) == MagickFalse)
4188 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4189 break;
4190 }
4191 if (LocaleCompare("convolve",option+1) == 0)
4192 {
cristyb6bd4ad2010-08-08 01:12:27 +00004193 KernelInfo
4194 *kernel_info;
4195
cristy3ed852e2009-09-05 21:47:34 +00004196 if (*option == '+')
4197 break;
4198 i++;
cristybb503372010-05-27 20:51:26 +00004199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004200 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004201 kernel_info=AcquireKernelInfo(argv[i]);
4202 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004203 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004204 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004205 break;
4206 }
4207 if (LocaleCompare("crop",option+1) == 0)
4208 {
4209 if (*option == '+')
4210 break;
4211 i++;
cristybb503372010-05-27 20:51:26 +00004212 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004213 ThrowMogrifyException(OptionError,"MissingArgument",option);
4214 if (IsGeometry(argv[i]) == MagickFalse)
4215 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4216 break;
4217 }
4218 if (LocaleCompare("cycle",option+1) == 0)
4219 {
4220 if (*option == '+')
4221 break;
4222 i++;
cristybb503372010-05-27 20:51:26 +00004223 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004224 ThrowMogrifyException(OptionError,"MissingArgument",option);
4225 if (IsGeometry(argv[i]) == MagickFalse)
4226 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4227 break;
4228 }
4229 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4230 }
4231 case 'd':
4232 {
4233 if (LocaleCompare("decipher",option+1) == 0)
4234 {
4235 if (*option == '+')
4236 break;
4237 i++;
cristybb503372010-05-27 20:51:26 +00004238 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004239 ThrowMogrifyException(OptionError,"MissingArgument",option);
4240 break;
4241 }
4242 if (LocaleCompare("deconstruct",option+1) == 0)
4243 break;
4244 if (LocaleCompare("debug",option+1) == 0)
4245 {
cristybb503372010-05-27 20:51:26 +00004246 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004247 event;
4248
4249 if (*option == '+')
4250 break;
4251 i++;
cristybb503372010-05-27 20:51:26 +00004252 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004253 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004254 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004255 if (event < 0)
4256 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4257 argv[i]);
4258 (void) SetLogEventMask(argv[i]);
4259 break;
4260 }
4261 if (LocaleCompare("define",option+1) == 0)
4262 {
4263 i++;
cristybb503372010-05-27 20:51:26 +00004264 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004265 ThrowMogrifyException(OptionError,"MissingArgument",option);
4266 if (*option == '+')
4267 {
4268 const char
4269 *define;
4270
4271 define=GetImageOption(image_info,argv[i]);
4272 if (define == (const char *) NULL)
4273 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4274 break;
4275 }
4276 break;
4277 }
4278 if (LocaleCompare("delay",option+1) == 0)
4279 {
4280 if (*option == '+')
4281 break;
4282 i++;
cristybb503372010-05-27 20:51:26 +00004283 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004284 ThrowMogrifyException(OptionError,"MissingArgument",option);
4285 if (IsGeometry(argv[i]) == MagickFalse)
4286 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4287 break;
4288 }
cristyecb10ff2011-03-22 13:14:03 +00004289 if (LocaleCompare("delete",option+1) == 0)
4290 {
4291 if (*option == '+')
4292 break;
4293 i++;
4294 if (i == (ssize_t) (argc-1))
4295 ThrowMogrifyException(OptionError,"MissingArgument",option);
4296 if (IsGeometry(argv[i]) == MagickFalse)
4297 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4298 break;
4299 }
cristy3ed852e2009-09-05 21:47:34 +00004300 if (LocaleCompare("density",option+1) == 0)
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);
4307 if (IsGeometry(argv[i]) == MagickFalse)
4308 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4309 break;
4310 }
4311 if (LocaleCompare("depth",option+1) == 0)
4312 {
4313 if (*option == '+')
4314 break;
4315 i++;
cristybb503372010-05-27 20:51:26 +00004316 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004317 ThrowMogrifyException(OptionError,"MissingArgument",option);
4318 if (IsGeometry(argv[i]) == MagickFalse)
4319 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4320 break;
4321 }
4322 if (LocaleCompare("deskew",option+1) == 0)
4323 {
4324 if (*option == '+')
4325 break;
4326 i++;
cristybb503372010-05-27 20:51:26 +00004327 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004328 ThrowMogrifyException(OptionError,"MissingArgument",option);
4329 if (IsGeometry(argv[i]) == MagickFalse)
4330 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4331 break;
4332 }
4333 if (LocaleCompare("despeckle",option+1) == 0)
4334 break;
4335 if (LocaleCompare("dft",option+1) == 0)
4336 break;
cristyc9b12952010-03-28 01:12:28 +00004337 if (LocaleCompare("direction",option+1) == 0)
4338 {
cristybb503372010-05-27 20:51:26 +00004339 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004340 direction;
4341
4342 if (*option == '+')
4343 break;
4344 i++;
cristybb503372010-05-27 20:51:26 +00004345 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004346 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004347 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004348 argv[i]);
4349 if (direction < 0)
4350 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4351 argv[i]);
4352 break;
4353 }
cristy3ed852e2009-09-05 21:47:34 +00004354 if (LocaleCompare("display",option+1) == 0)
4355 {
4356 if (*option == '+')
4357 break;
4358 i++;
cristybb503372010-05-27 20:51:26 +00004359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004360 ThrowMogrifyException(OptionError,"MissingArgument",option);
4361 break;
4362 }
4363 if (LocaleCompare("dispose",option+1) == 0)
4364 {
cristybb503372010-05-27 20:51:26 +00004365 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004366 dispose;
4367
4368 if (*option == '+')
4369 break;
4370 i++;
cristybb503372010-05-27 20:51:26 +00004371 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004372 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004373 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004374 if (dispose < 0)
4375 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4376 argv[i]);
4377 break;
4378 }
4379 if (LocaleCompare("distort",option+1) == 0)
4380 {
cristybb503372010-05-27 20:51:26 +00004381 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004382 op;
4383
4384 i++;
cristybb503372010-05-27 20:51:26 +00004385 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004386 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004387 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004388 if (op < 0)
4389 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4390 argv[i]);
4391 i++;
cristybb503372010-05-27 20:51:26 +00004392 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004393 ThrowMogrifyException(OptionError,"MissingArgument",option);
4394 break;
4395 }
4396 if (LocaleCompare("dither",option+1) == 0)
4397 {
cristybb503372010-05-27 20:51:26 +00004398 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004399 method;
4400
4401 if (*option == '+')
4402 break;
4403 i++;
cristybb503372010-05-27 20:51:26 +00004404 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004405 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004406 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004407 if (method < 0)
4408 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4409 argv[i]);
4410 break;
4411 }
4412 if (LocaleCompare("draw",option+1) == 0)
4413 {
4414 if (*option == '+')
4415 break;
4416 i++;
cristybb503372010-05-27 20:51:26 +00004417 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004418 ThrowMogrifyException(OptionError,"MissingArgument",option);
4419 break;
4420 }
cristyecb10ff2011-03-22 13:14:03 +00004421 if (LocaleCompare("duplicate",option+1) == 0)
4422 {
4423 if (*option == '+')
4424 break;
4425 i++;
4426 if (i == (ssize_t) (argc-1))
4427 ThrowMogrifyException(OptionError,"MissingArgument",option);
4428 if (IsGeometry(argv[i]) == MagickFalse)
4429 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4430 break;
4431 }
cristy22879752009-10-25 23:55:40 +00004432 if (LocaleCompare("duration",option+1) == 0)
4433 {
4434 if (*option == '+')
4435 break;
4436 i++;
cristybb503372010-05-27 20:51:26 +00004437 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004438 ThrowMogrifyException(OptionError,"MissingArgument",option);
4439 if (IsGeometry(argv[i]) == MagickFalse)
4440 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4441 break;
4442 }
cristy3ed852e2009-09-05 21:47:34 +00004443 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4444 }
4445 case 'e':
4446 {
4447 if (LocaleCompare("edge",option+1) == 0)
4448 {
4449 if (*option == '+')
4450 break;
4451 i++;
cristybb503372010-05-27 20:51:26 +00004452 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004453 ThrowMogrifyException(OptionError,"MissingArgument",option);
4454 if (IsGeometry(argv[i]) == MagickFalse)
4455 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4456 break;
4457 }
4458 if (LocaleCompare("emboss",option+1) == 0)
4459 {
4460 if (*option == '+')
4461 break;
4462 i++;
cristybb503372010-05-27 20:51:26 +00004463 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004464 ThrowMogrifyException(OptionError,"MissingArgument",option);
4465 if (IsGeometry(argv[i]) == MagickFalse)
4466 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4467 break;
4468 }
4469 if (LocaleCompare("encipher",option+1) == 0)
4470 {
4471 if (*option == '+')
4472 break;
4473 i++;
cristybb503372010-05-27 20:51:26 +00004474 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004475 ThrowMogrifyException(OptionError,"MissingArgument",option);
4476 break;
4477 }
4478 if (LocaleCompare("encoding",option+1) == 0)
4479 {
4480 if (*option == '+')
4481 break;
4482 i++;
cristybb503372010-05-27 20:51:26 +00004483 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004484 ThrowMogrifyException(OptionError,"MissingArgument",option);
4485 break;
4486 }
4487 if (LocaleCompare("endian",option+1) == 0)
4488 {
cristybb503372010-05-27 20:51:26 +00004489 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004490 endian;
4491
4492 if (*option == '+')
4493 break;
4494 i++;
cristybb503372010-05-27 20:51:26 +00004495 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004496 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004497 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004498 if (endian < 0)
4499 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4500 argv[i]);
4501 break;
4502 }
4503 if (LocaleCompare("enhance",option+1) == 0)
4504 break;
4505 if (LocaleCompare("equalize",option+1) == 0)
4506 break;
4507 if (LocaleCompare("evaluate",option+1) == 0)
4508 {
cristybb503372010-05-27 20:51:26 +00004509 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004510 op;
4511
4512 if (*option == '+')
4513 break;
4514 i++;
cristybb503372010-05-27 20:51:26 +00004515 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004516 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004517 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004518 if (op < 0)
4519 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4520 argv[i]);
4521 i++;
cristybb503372010-05-27 20:51:26 +00004522 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004523 ThrowMogrifyException(OptionError,"MissingArgument",option);
4524 if (IsGeometry(argv[i]) == MagickFalse)
4525 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4526 break;
4527 }
cristyd18ae7c2010-03-07 17:39:52 +00004528 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4529 {
cristybb503372010-05-27 20:51:26 +00004530 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004531 op;
4532
4533 if (*option == '+')
4534 break;
4535 i++;
cristybb503372010-05-27 20:51:26 +00004536 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004537 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004538 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004539 if (op < 0)
4540 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4541 argv[i]);
4542 break;
4543 }
cristy3ed852e2009-09-05 21:47:34 +00004544 if (LocaleCompare("extent",option+1) == 0)
4545 {
4546 if (*option == '+')
4547 break;
4548 i++;
cristybb503372010-05-27 20:51:26 +00004549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004550 ThrowMogrifyException(OptionError,"MissingArgument",option);
4551 if (IsGeometry(argv[i]) == MagickFalse)
4552 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4553 break;
4554 }
4555 if (LocaleCompare("extract",option+1) == 0)
4556 {
4557 if (*option == '+')
4558 break;
4559 i++;
cristybb503372010-05-27 20:51:26 +00004560 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004561 ThrowMogrifyException(OptionError,"MissingArgument",option);
4562 if (IsGeometry(argv[i]) == MagickFalse)
4563 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4564 break;
4565 }
4566 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4567 }
4568 case 'f':
4569 {
4570 if (LocaleCompare("family",option+1) == 0)
4571 {
4572 if (*option == '+')
4573 break;
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 break;
4578 }
4579 if (LocaleCompare("fill",option+1) == 0)
4580 {
4581 if (*option == '+')
4582 break;
4583 i++;
cristybb503372010-05-27 20:51:26 +00004584 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004585 ThrowMogrifyException(OptionError,"MissingArgument",option);
4586 break;
4587 }
4588 if (LocaleCompare("filter",option+1) == 0)
4589 {
cristybb503372010-05-27 20:51:26 +00004590 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004591 filter;
4592
4593 if (*option == '+')
4594 break;
4595 i++;
cristybb503372010-05-27 20:51:26 +00004596 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004597 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004598 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004599 if (filter < 0)
4600 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4601 argv[i]);
4602 break;
4603 }
4604 if (LocaleCompare("flatten",option+1) == 0)
4605 break;
4606 if (LocaleCompare("flip",option+1) == 0)
4607 break;
4608 if (LocaleCompare("flop",option+1) == 0)
4609 break;
4610 if (LocaleCompare("floodfill",option+1) == 0)
4611 {
4612 if (*option == '+')
4613 break;
4614 i++;
cristybb503372010-05-27 20:51:26 +00004615 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004616 ThrowMogrifyException(OptionError,"MissingArgument",option);
4617 if (IsGeometry(argv[i]) == MagickFalse)
4618 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4619 i++;
cristybb503372010-05-27 20:51:26 +00004620 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004621 ThrowMogrifyException(OptionError,"MissingArgument",option);
4622 break;
4623 }
4624 if (LocaleCompare("font",option+1) == 0)
4625 {
4626 if (*option == '+')
4627 break;
4628 i++;
cristybb503372010-05-27 20:51:26 +00004629 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004630 ThrowMogrifyException(OptionError,"MissingArgument",option);
4631 break;
4632 }
4633 if (LocaleCompare("format",option+1) == 0)
4634 {
4635 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4636 (void) CloneString(&format,(char *) NULL);
4637 if (*option == '+')
4638 break;
4639 i++;
cristybb503372010-05-27 20:51:26 +00004640 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004641 ThrowMogrifyException(OptionError,"MissingArgument",option);
4642 (void) CloneString(&format,argv[i]);
4643 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4644 (void) ConcatenateMagickString(image_info->filename,":",
4645 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004646 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004647 if (*image_info->magick == '\0')
4648 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4649 format);
4650 break;
4651 }
4652 if (LocaleCompare("frame",option+1) == 0)
4653 {
4654 if (*option == '+')
4655 break;
4656 i++;
cristybb503372010-05-27 20:51:26 +00004657 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004658 ThrowMogrifyException(OptionError,"MissingArgument",option);
4659 if (IsGeometry(argv[i]) == MagickFalse)
4660 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4661 break;
4662 }
4663 if (LocaleCompare("function",option+1) == 0)
4664 {
cristybb503372010-05-27 20:51:26 +00004665 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004666 op;
4667
4668 if (*option == '+')
4669 break;
4670 i++;
cristybb503372010-05-27 20:51:26 +00004671 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004672 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004673 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004674 if (op < 0)
4675 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4676 i++;
cristybb503372010-05-27 20:51:26 +00004677 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004678 ThrowMogrifyException(OptionError,"MissingArgument",option);
4679 break;
4680 }
4681 if (LocaleCompare("fuzz",option+1) == 0)
4682 {
4683 if (*option == '+')
4684 break;
4685 i++;
cristybb503372010-05-27 20:51:26 +00004686 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004687 ThrowMogrifyException(OptionError,"MissingArgument",option);
4688 if (IsGeometry(argv[i]) == MagickFalse)
4689 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4690 break;
4691 }
4692 if (LocaleCompare("fx",option+1) == 0)
4693 {
4694 if (*option == '+')
4695 break;
4696 i++;
cristybb503372010-05-27 20:51:26 +00004697 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004698 ThrowMogrifyException(OptionError,"MissingArgument",option);
4699 break;
4700 }
4701 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4702 }
4703 case 'g':
4704 {
4705 if (LocaleCompare("gamma",option+1) == 0)
4706 {
4707 i++;
cristybb503372010-05-27 20:51:26 +00004708 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004709 ThrowMogrifyException(OptionError,"MissingArgument",option);
4710 if (IsGeometry(argv[i]) == MagickFalse)
4711 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4712 break;
4713 }
4714 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4715 (LocaleCompare("gaussian",option+1) == 0))
4716 {
4717 i++;
cristybb503372010-05-27 20:51:26 +00004718 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004719 ThrowMogrifyException(OptionError,"MissingArgument",option);
4720 if (IsGeometry(argv[i]) == MagickFalse)
4721 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4722 break;
4723 }
4724 if (LocaleCompare("geometry",option+1) == 0)
4725 {
4726 if (*option == '+')
4727 break;
4728 i++;
cristybb503372010-05-27 20:51:26 +00004729 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004730 ThrowMogrifyException(OptionError,"MissingArgument",option);
4731 if (IsGeometry(argv[i]) == MagickFalse)
4732 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4733 break;
4734 }
4735 if (LocaleCompare("gravity",option+1) == 0)
4736 {
cristybb503372010-05-27 20:51:26 +00004737 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004738 gravity;
4739
4740 if (*option == '+')
4741 break;
4742 i++;
cristybb503372010-05-27 20:51:26 +00004743 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004744 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004745 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004746 if (gravity < 0)
4747 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4748 argv[i]);
4749 break;
4750 }
4751 if (LocaleCompare("green-primary",option+1) == 0)
4752 {
4753 if (*option == '+')
4754 break;
4755 i++;
cristybb503372010-05-27 20:51:26 +00004756 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004757 ThrowMogrifyException(OptionError,"MissingArgument",option);
4758 if (IsGeometry(argv[i]) == MagickFalse)
4759 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4760 break;
4761 }
4762 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4763 }
4764 case 'h':
4765 {
4766 if (LocaleCompare("hald-clut",option+1) == 0)
4767 break;
4768 if ((LocaleCompare("help",option+1) == 0) ||
4769 (LocaleCompare("-help",option+1) == 0))
4770 return(MogrifyUsage());
4771 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4772 }
4773 case 'i':
4774 {
4775 if (LocaleCompare("identify",option+1) == 0)
4776 break;
4777 if (LocaleCompare("idft",option+1) == 0)
4778 break;
4779 if (LocaleCompare("implode",option+1) == 0)
4780 {
4781 if (*option == '+')
4782 break;
4783 i++;
cristybb503372010-05-27 20:51:26 +00004784 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004785 ThrowMogrifyException(OptionError,"MissingArgument",option);
4786 if (IsGeometry(argv[i]) == MagickFalse)
4787 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4788 break;
4789 }
4790 if (LocaleCompare("intent",option+1) == 0)
4791 {
cristybb503372010-05-27 20:51:26 +00004792 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004793 intent;
4794
4795 if (*option == '+')
4796 break;
4797 i++;
cristybb503372010-05-27 20:51:26 +00004798 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004799 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004800 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004801 if (intent < 0)
4802 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4803 argv[i]);
4804 break;
4805 }
4806 if (LocaleCompare("interlace",option+1) == 0)
4807 {
cristybb503372010-05-27 20:51:26 +00004808 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004809 interlace;
4810
4811 if (*option == '+')
4812 break;
4813 i++;
cristybb503372010-05-27 20:51:26 +00004814 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004815 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004816 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004817 argv[i]);
4818 if (interlace < 0)
4819 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4820 argv[i]);
4821 break;
4822 }
cristyb32b90a2009-09-07 21:45:48 +00004823 if (LocaleCompare("interline-spacing",option+1) == 0)
4824 {
4825 if (*option == '+')
4826 break;
4827 i++;
cristybb503372010-05-27 20:51:26 +00004828 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004829 ThrowMogrifyException(OptionError,"MissingArgument",option);
4830 if (IsGeometry(argv[i]) == MagickFalse)
4831 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4832 break;
4833 }
cristy3ed852e2009-09-05 21:47:34 +00004834 if (LocaleCompare("interpolate",option+1) == 0)
4835 {
cristybb503372010-05-27 20:51:26 +00004836 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004837 interpolate;
4838
4839 if (*option == '+')
4840 break;
4841 i++;
cristybb503372010-05-27 20:51:26 +00004842 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004843 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004844 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004845 argv[i]);
4846 if (interpolate < 0)
4847 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4848 argv[i]);
4849 break;
4850 }
4851 if (LocaleCompare("interword-spacing",option+1) == 0)
4852 {
4853 if (*option == '+')
4854 break;
4855 i++;
cristybb503372010-05-27 20:51:26 +00004856 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004857 ThrowMogrifyException(OptionError,"MissingArgument",option);
4858 if (IsGeometry(argv[i]) == MagickFalse)
4859 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4860 break;
4861 }
4862 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4863 }
4864 case 'k':
4865 {
4866 if (LocaleCompare("kerning",option+1) == 0)
4867 {
4868 if (*option == '+')
4869 break;
4870 i++;
cristybb503372010-05-27 20:51:26 +00004871 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004872 ThrowMogrifyException(OptionError,"MissingArgument",option);
4873 if (IsGeometry(argv[i]) == MagickFalse)
4874 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4875 break;
4876 }
4877 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4878 }
4879 case 'l':
4880 {
4881 if (LocaleCompare("label",option+1) == 0)
4882 {
4883 if (*option == '+')
4884 break;
4885 i++;
cristybb503372010-05-27 20:51:26 +00004886 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004887 ThrowMogrifyException(OptionError,"MissingArgument",option);
4888 break;
4889 }
4890 if (LocaleCompare("lat",option+1) == 0)
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);
4897 if (IsGeometry(argv[i]) == MagickFalse)
4898 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4899 }
4900 if (LocaleCompare("layers",option+1) == 0)
4901 {
cristybb503372010-05-27 20:51:26 +00004902 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004903 type;
4904
4905 if (*option == '+')
4906 break;
4907 i++;
cristybb503372010-05-27 20:51:26 +00004908 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004909 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004910 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004911 if (type < 0)
4912 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4913 argv[i]);
4914 break;
4915 }
4916 if (LocaleCompare("level",option+1) == 0)
4917 {
4918 i++;
cristybb503372010-05-27 20:51:26 +00004919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004920 ThrowMogrifyException(OptionError,"MissingArgument",option);
4921 if (IsGeometry(argv[i]) == MagickFalse)
4922 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4923 break;
4924 }
4925 if (LocaleCompare("level-colors",option+1) == 0)
4926 {
4927 i++;
cristybb503372010-05-27 20:51:26 +00004928 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004929 ThrowMogrifyException(OptionError,"MissingArgument",option);
4930 break;
4931 }
cristy3ed852e2009-09-05 21:47:34 +00004932 if (LocaleCompare("limit",option+1) == 0)
4933 {
4934 char
4935 *p;
4936
4937 double
4938 value;
4939
cristybb503372010-05-27 20:51:26 +00004940 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004941 resource;
4942
4943 if (*option == '+')
4944 break;
4945 i++;
cristybb503372010-05-27 20:51:26 +00004946 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004947 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004948 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004949 argv[i]);
4950 if (resource < 0)
4951 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4952 argv[i]);
4953 i++;
cristybb503372010-05-27 20:51:26 +00004954 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004955 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00004956 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004957 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004958 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4959 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4960 break;
4961 }
4962 if (LocaleCompare("liquid-rescale",option+1) == 0)
4963 {
4964 i++;
cristybb503372010-05-27 20:51:26 +00004965 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004966 ThrowMogrifyException(OptionError,"MissingArgument",option);
4967 if (IsGeometry(argv[i]) == MagickFalse)
4968 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4969 break;
4970 }
4971 if (LocaleCompare("list",option+1) == 0)
4972 {
cristybb503372010-05-27 20:51:26 +00004973 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004974 list;
4975
4976 if (*option == '+')
4977 break;
4978 i++;
cristybb503372010-05-27 20:51:26 +00004979 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004980 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004981 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004982 if (list < 0)
4983 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004984 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004985 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004986 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004987 }
4988 if (LocaleCompare("log",option+1) == 0)
4989 {
4990 if (*option == '+')
4991 break;
4992 i++;
cristybb503372010-05-27 20:51:26 +00004993 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00004994 (strchr(argv[i],'%') == (char *) NULL))
4995 ThrowMogrifyException(OptionError,"MissingArgument",option);
4996 break;
4997 }
4998 if (LocaleCompare("loop",option+1) == 0)
4999 {
5000 if (*option == '+')
5001 break;
5002 i++;
cristybb503372010-05-27 20:51:26 +00005003 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005004 ThrowMogrifyException(OptionError,"MissingArgument",option);
5005 if (IsGeometry(argv[i]) == MagickFalse)
5006 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5007 break;
5008 }
5009 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5010 }
5011 case 'm':
5012 {
5013 if (LocaleCompare("map",option+1) == 0)
5014 {
5015 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5016 if (*option == '+')
5017 break;
5018 i++;
cristybb503372010-05-27 20:51:26 +00005019 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005020 ThrowMogrifyException(OptionError,"MissingArgument",option);
5021 break;
5022 }
5023 if (LocaleCompare("mask",option+1) == 0)
5024 {
5025 if (*option == '+')
5026 break;
5027 i++;
cristybb503372010-05-27 20:51:26 +00005028 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005029 ThrowMogrifyException(OptionError,"MissingArgument",option);
5030 break;
5031 }
5032 if (LocaleCompare("matte",option+1) == 0)
5033 break;
5034 if (LocaleCompare("mattecolor",option+1) == 0)
5035 {
5036 if (*option == '+')
5037 break;
5038 i++;
cristybb503372010-05-27 20:51:26 +00005039 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005040 ThrowMogrifyException(OptionError,"MissingArgument",option);
5041 break;
5042 }
cristyf40785b2010-03-06 02:27:27 +00005043 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005044 break;
cristyf40785b2010-03-06 02:27:27 +00005045 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005046 break;
cristy3ed852e2009-09-05 21:47:34 +00005047 if (LocaleCompare("modulate",option+1) == 0)
5048 {
5049 if (*option == '+')
5050 break;
5051 i++;
cristybb503372010-05-27 20:51:26 +00005052 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005053 ThrowMogrifyException(OptionError,"MissingArgument",option);
5054 if (IsGeometry(argv[i]) == MagickFalse)
5055 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5056 break;
5057 }
5058 if (LocaleCompare("median",option+1) == 0)
5059 {
5060 if (*option == '+')
5061 break;
5062 i++;
cristybb503372010-05-27 20:51:26 +00005063 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005064 ThrowMogrifyException(OptionError,"MissingArgument",option);
5065 if (IsGeometry(argv[i]) == MagickFalse)
5066 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5067 break;
5068 }
cristy69ec32d2011-02-27 23:57:09 +00005069 if (LocaleCompare("mode",option+1) == 0)
5070 {
5071 if (*option == '+')
5072 break;
5073 i++;
5074 if (i == (ssize_t) argc)
5075 ThrowMogrifyException(OptionError,"MissingArgument",option);
5076 if (IsGeometry(argv[i]) == MagickFalse)
5077 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5078 break;
5079 }
cristy3ed852e2009-09-05 21:47:34 +00005080 if (LocaleCompare("monitor",option+1) == 0)
5081 break;
5082 if (LocaleCompare("monochrome",option+1) == 0)
5083 break;
5084 if (LocaleCompare("morph",option+1) == 0)
5085 {
5086 if (*option == '+')
5087 break;
5088 i++;
cristybb503372010-05-27 20:51:26 +00005089 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005090 ThrowMogrifyException(OptionError,"MissingArgument",option);
5091 if (IsGeometry(argv[i]) == MagickFalse)
5092 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5093 break;
5094 }
anthony29188a82010-01-22 10:12:34 +00005095 if (LocaleCompare("morphology",option+1) == 0)
5096 {
anthony29188a82010-01-22 10:12:34 +00005097 char
5098 token[MaxTextExtent];
5099
cristyb6bd4ad2010-08-08 01:12:27 +00005100 KernelInfo
5101 *kernel_info;
5102
5103 ssize_t
5104 op;
5105
anthony29188a82010-01-22 10:12:34 +00005106 i++;
cristybb503372010-05-27 20:51:26 +00005107 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005108 ThrowMogrifyException(OptionError,"MissingArgument",option);
5109 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005110 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005111 if (op < 0)
5112 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005113 token);
anthony29188a82010-01-22 10:12:34 +00005114 i++;
cristybb503372010-05-27 20:51:26 +00005115 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005116 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005117 kernel_info=AcquireKernelInfo(argv[i]);
5118 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005119 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005120 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005121 break;
5122 }
cristy3ed852e2009-09-05 21:47:34 +00005123 if (LocaleCompare("mosaic",option+1) == 0)
5124 break;
5125 if (LocaleCompare("motion-blur",option+1) == 0)
5126 {
5127 if (*option == '+')
5128 break;
5129 i++;
cristybb503372010-05-27 20:51:26 +00005130 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005131 ThrowMogrifyException(OptionError,"MissingArgument",option);
5132 if (IsGeometry(argv[i]) == MagickFalse)
5133 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5134 break;
5135 }
5136 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5137 }
5138 case 'n':
5139 {
5140 if (LocaleCompare("negate",option+1) == 0)
5141 break;
5142 if (LocaleCompare("noise",option+1) == 0)
5143 {
5144 i++;
cristybb503372010-05-27 20:51:26 +00005145 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005146 ThrowMogrifyException(OptionError,"MissingArgument",option);
5147 if (*option == '+')
5148 {
cristybb503372010-05-27 20:51:26 +00005149 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005150 noise;
5151
cristy042ee782011-04-22 18:48:30 +00005152 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005153 if (noise < 0)
5154 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5155 argv[i]);
5156 break;
5157 }
5158 if (IsGeometry(argv[i]) == MagickFalse)
5159 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5160 break;
5161 }
5162 if (LocaleCompare("noop",option+1) == 0)
5163 break;
5164 if (LocaleCompare("normalize",option+1) == 0)
5165 break;
5166 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5167 }
5168 case 'o':
5169 {
5170 if (LocaleCompare("opaque",option+1) == 0)
5171 {
cristy3ed852e2009-09-05 21:47:34 +00005172 i++;
cristybb503372010-05-27 20:51:26 +00005173 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005174 ThrowMogrifyException(OptionError,"MissingArgument",option);
5175 break;
5176 }
5177 if (LocaleCompare("ordered-dither",option+1) == 0)
5178 {
5179 if (*option == '+')
5180 break;
5181 i++;
cristybb503372010-05-27 20:51:26 +00005182 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005183 ThrowMogrifyException(OptionError,"MissingArgument",option);
5184 break;
5185 }
5186 if (LocaleCompare("orient",option+1) == 0)
5187 {
cristybb503372010-05-27 20:51:26 +00005188 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005189 orientation;
5190
5191 orientation=UndefinedOrientation;
5192 if (*option == '+')
5193 break;
5194 i++;
cristybb503372010-05-27 20:51:26 +00005195 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005196 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005197 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005198 argv[i]);
5199 if (orientation < 0)
5200 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5201 argv[i]);
5202 break;
5203 }
5204 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5205 }
5206 case 'p':
5207 {
5208 if (LocaleCompare("page",option+1) == 0)
5209 {
5210 if (*option == '+')
5211 break;
5212 i++;
cristybb503372010-05-27 20:51:26 +00005213 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005214 ThrowMogrifyException(OptionError,"MissingArgument",option);
5215 break;
5216 }
5217 if (LocaleCompare("paint",option+1) == 0)
5218 {
5219 if (*option == '+')
5220 break;
5221 i++;
cristybb503372010-05-27 20:51:26 +00005222 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005223 ThrowMogrifyException(OptionError,"MissingArgument",option);
5224 if (IsGeometry(argv[i]) == MagickFalse)
5225 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5226 break;
5227 }
5228 if (LocaleCompare("path",option+1) == 0)
5229 {
5230 (void) CloneString(&path,(char *) NULL);
5231 if (*option == '+')
5232 break;
5233 i++;
cristybb503372010-05-27 20:51:26 +00005234 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005235 ThrowMogrifyException(OptionError,"MissingArgument",option);
5236 (void) CloneString(&path,argv[i]);
5237 break;
5238 }
5239 if (LocaleCompare("pointsize",option+1) == 0)
5240 {
5241 if (*option == '+')
5242 break;
5243 i++;
cristybb503372010-05-27 20:51:26 +00005244 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005245 ThrowMogrifyException(OptionError,"MissingArgument",option);
5246 if (IsGeometry(argv[i]) == MagickFalse)
5247 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5248 break;
5249 }
5250 if (LocaleCompare("polaroid",option+1) == 0)
5251 {
5252 if (*option == '+')
5253 break;
5254 i++;
cristybb503372010-05-27 20:51:26 +00005255 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005256 ThrowMogrifyException(OptionError,"MissingArgument",option);
5257 if (IsGeometry(argv[i]) == MagickFalse)
5258 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5259 break;
5260 }
5261 if (LocaleCompare("posterize",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 if (IsGeometry(argv[i]) == MagickFalse)
5269 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5270 break;
5271 }
cristye7f51092010-01-17 00:39:37 +00005272 if (LocaleCompare("precision",option+1) == 0)
5273 {
5274 if (*option == '+')
5275 break;
5276 i++;
cristybb503372010-05-27 20:51:26 +00005277 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005278 ThrowMogrifyException(OptionError,"MissingArgument",option);
5279 if (IsGeometry(argv[i]) == MagickFalse)
5280 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5281 break;
5282 }
cristy3ed852e2009-09-05 21:47:34 +00005283 if (LocaleCompare("print",option+1) == 0)
5284 {
5285 if (*option == '+')
5286 break;
5287 i++;
cristybb503372010-05-27 20:51:26 +00005288 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005289 ThrowMogrifyException(OptionError,"MissingArgument",option);
5290 break;
5291 }
5292 if (LocaleCompare("process",option+1) == 0)
5293 {
5294 if (*option == '+')
5295 break;
5296 i++;
cristybb503372010-05-27 20:51:26 +00005297 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005298 ThrowMogrifyException(OptionError,"MissingArgument",option);
5299 break;
5300 }
5301 if (LocaleCompare("profile",option+1) == 0)
5302 {
5303 i++;
cristybb503372010-05-27 20:51:26 +00005304 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005305 ThrowMogrifyException(OptionError,"MissingArgument",option);
5306 break;
5307 }
5308 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5309 }
5310 case 'q':
5311 {
5312 if (LocaleCompare("quality",option+1) == 0)
5313 {
5314 if (*option == '+')
5315 break;
5316 i++;
cristybb503372010-05-27 20:51:26 +00005317 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005318 ThrowMogrifyException(OptionError,"MissingArgument",option);
5319 if (IsGeometry(argv[i]) == MagickFalse)
5320 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5321 break;
5322 }
5323 if (LocaleCompare("quantize",option+1) == 0)
5324 {
cristybb503372010-05-27 20:51:26 +00005325 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005326 colorspace;
5327
5328 if (*option == '+')
5329 break;
5330 i++;
cristybb503372010-05-27 20:51:26 +00005331 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005332 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005333 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005334 argv[i]);
5335 if (colorspace < 0)
5336 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5337 argv[i]);
5338 break;
5339 }
5340 if (LocaleCompare("quiet",option+1) == 0)
5341 break;
5342 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5343 }
5344 case 'r':
5345 {
5346 if (LocaleCompare("radial-blur",option+1) == 0)
5347 {
5348 i++;
cristybb503372010-05-27 20:51:26 +00005349 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005350 ThrowMogrifyException(OptionError,"MissingArgument",option);
5351 if (IsGeometry(argv[i]) == MagickFalse)
5352 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5353 break;
5354 }
5355 if (LocaleCompare("raise",option+1) == 0)
5356 {
5357 i++;
cristybb503372010-05-27 20:51:26 +00005358 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005359 ThrowMogrifyException(OptionError,"MissingArgument",option);
5360 if (IsGeometry(argv[i]) == MagickFalse)
5361 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5362 break;
5363 }
5364 if (LocaleCompare("random-threshold",option+1) == 0)
5365 {
5366 if (*option == '+')
5367 break;
5368 i++;
cristybb503372010-05-27 20:51:26 +00005369 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005370 ThrowMogrifyException(OptionError,"MissingArgument",option);
5371 if (IsGeometry(argv[i]) == MagickFalse)
5372 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5373 break;
5374 }
5375 if (LocaleCompare("red-primary",option+1) == 0)
5376 {
5377 if (*option == '+')
5378 break;
5379 i++;
cristybb503372010-05-27 20:51:26 +00005380 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005381 ThrowMogrifyException(OptionError,"MissingArgument",option);
5382 if (IsGeometry(argv[i]) == MagickFalse)
5383 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5384 }
cristy9f2083a2010-04-22 19:48:05 +00005385 if (LocaleCompare("regard-warnings",option+1) == 0)
5386 break;
cristy3ed852e2009-09-05 21:47:34 +00005387 if (LocaleCompare("region",option+1) == 0)
5388 {
5389 if (*option == '+')
5390 break;
5391 i++;
cristybb503372010-05-27 20:51:26 +00005392 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005393 ThrowMogrifyException(OptionError,"MissingArgument",option);
5394 if (IsGeometry(argv[i]) == MagickFalse)
5395 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5396 break;
5397 }
cristyf0c78232010-03-15 12:53:40 +00005398 if (LocaleCompare("remap",option+1) == 0)
5399 {
5400 if (*option == '+')
5401 break;
5402 i++;
cristybb503372010-05-27 20:51:26 +00005403 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005404 ThrowMogrifyException(OptionError,"MissingArgument",option);
5405 break;
5406 }
cristy3ed852e2009-09-05 21:47:34 +00005407 if (LocaleCompare("render",option+1) == 0)
5408 break;
5409 if (LocaleCompare("repage",option+1) == 0)
5410 {
5411 if (*option == '+')
5412 break;
5413 i++;
cristybb503372010-05-27 20:51:26 +00005414 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005415 ThrowMogrifyException(OptionError,"MissingArgument",option);
5416 if (IsGeometry(argv[i]) == MagickFalse)
5417 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5418 break;
5419 }
5420 if (LocaleCompare("resample",option+1) == 0)
5421 {
5422 if (*option == '+')
5423 break;
5424 i++;
cristybb503372010-05-27 20:51:26 +00005425 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005426 ThrowMogrifyException(OptionError,"MissingArgument",option);
5427 if (IsGeometry(argv[i]) == MagickFalse)
5428 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5429 break;
5430 }
5431 if (LocaleCompare("resize",option+1) == 0)
5432 {
5433 if (*option == '+')
5434 break;
5435 i++;
cristybb503372010-05-27 20:51:26 +00005436 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005437 ThrowMogrifyException(OptionError,"MissingArgument",option);
5438 if (IsGeometry(argv[i]) == MagickFalse)
5439 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5440 break;
5441 }
cristyebbcfea2011-02-25 02:43:54 +00005442 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5443 {
5444 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5445 break;
5446 }
cristy3ed852e2009-09-05 21:47:34 +00005447 if (LocaleCompare("reverse",option+1) == 0)
5448 break;
5449 if (LocaleCompare("roll",option+1) == 0)
5450 {
5451 if (*option == '+')
5452 break;
5453 i++;
cristybb503372010-05-27 20:51:26 +00005454 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005455 ThrowMogrifyException(OptionError,"MissingArgument",option);
5456 if (IsGeometry(argv[i]) == MagickFalse)
5457 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5458 break;
5459 }
5460 if (LocaleCompare("rotate",option+1) == 0)
5461 {
5462 i++;
cristybb503372010-05-27 20:51:26 +00005463 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005464 ThrowMogrifyException(OptionError,"MissingArgument",option);
5465 if (IsGeometry(argv[i]) == MagickFalse)
5466 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5467 break;
5468 }
5469 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5470 }
5471 case 's':
5472 {
5473 if (LocaleCompare("sample",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("sampling-factor",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 }
5495 if (LocaleCompare("scale",option+1) == 0)
5496 {
5497 if (*option == '+')
5498 break;
5499 i++;
cristybb503372010-05-27 20:51:26 +00005500 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005501 ThrowMogrifyException(OptionError,"MissingArgument",option);
5502 if (IsGeometry(argv[i]) == MagickFalse)
5503 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5504 break;
5505 }
5506 if (LocaleCompare("scene",option+1) == 0)
5507 {
5508 if (*option == '+')
5509 break;
5510 i++;
cristybb503372010-05-27 20:51:26 +00005511 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005512 ThrowMogrifyException(OptionError,"MissingArgument",option);
5513 if (IsGeometry(argv[i]) == MagickFalse)
5514 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5515 break;
5516 }
5517 if (LocaleCompare("seed",option+1) == 0)
5518 {
5519 if (*option == '+')
5520 break;
5521 i++;
cristybb503372010-05-27 20:51:26 +00005522 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005523 ThrowMogrifyException(OptionError,"MissingArgument",option);
5524 if (IsGeometry(argv[i]) == MagickFalse)
5525 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5526 break;
5527 }
5528 if (LocaleCompare("segment",option+1) == 0)
5529 {
5530 if (*option == '+')
5531 break;
5532 i++;
cristybb503372010-05-27 20:51:26 +00005533 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005534 ThrowMogrifyException(OptionError,"MissingArgument",option);
5535 if (IsGeometry(argv[i]) == MagickFalse)
5536 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5537 break;
5538 }
5539 if (LocaleCompare("selective-blur",option+1) == 0)
5540 {
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("separate",option+1) == 0)
5549 break;
5550 if (LocaleCompare("sepia-tone",option+1) == 0)
5551 {
5552 if (*option == '+')
5553 break;
5554 i++;
cristybb503372010-05-27 20:51:26 +00005555 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005556 ThrowMogrifyException(OptionError,"MissingArgument",option);
5557 if (IsGeometry(argv[i]) == MagickFalse)
5558 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5559 break;
5560 }
5561 if (LocaleCompare("set",option+1) == 0)
5562 {
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 (*option == '+')
5567 break;
5568 i++;
cristybb503372010-05-27 20:51:26 +00005569 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005570 ThrowMogrifyException(OptionError,"MissingArgument",option);
5571 break;
5572 }
5573 if (LocaleCompare("shade",option+1) == 0)
5574 {
5575 i++;
cristybb503372010-05-27 20:51:26 +00005576 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005577 ThrowMogrifyException(OptionError,"MissingArgument",option);
5578 if (IsGeometry(argv[i]) == MagickFalse)
5579 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5580 break;
5581 }
5582 if (LocaleCompare("shadow",option+1) == 0)
5583 {
5584 if (*option == '+')
5585 break;
5586 i++;
cristybb503372010-05-27 20:51:26 +00005587 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005588 ThrowMogrifyException(OptionError,"MissingArgument",option);
5589 if (IsGeometry(argv[i]) == MagickFalse)
5590 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5591 break;
5592 }
5593 if (LocaleCompare("sharpen",option+1) == 0)
5594 {
5595 i++;
cristybb503372010-05-27 20:51:26 +00005596 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005597 ThrowMogrifyException(OptionError,"MissingArgument",option);
5598 if (IsGeometry(argv[i]) == MagickFalse)
5599 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5600 break;
5601 }
5602 if (LocaleCompare("shave",option+1) == 0)
5603 {
5604 if (*option == '+')
5605 break;
5606 i++;
cristybb503372010-05-27 20:51:26 +00005607 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005608 ThrowMogrifyException(OptionError,"MissingArgument",option);
5609 if (IsGeometry(argv[i]) == MagickFalse)
5610 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5611 break;
5612 }
5613 if (LocaleCompare("shear",option+1) == 0)
5614 {
5615 i++;
cristybb503372010-05-27 20:51:26 +00005616 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005617 ThrowMogrifyException(OptionError,"MissingArgument",option);
5618 if (IsGeometry(argv[i]) == MagickFalse)
5619 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5620 break;
5621 }
5622 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5623 {
5624 i++;
cristybb503372010-05-27 20:51:26 +00005625 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005626 ThrowMogrifyException(OptionError,"MissingArgument",option);
5627 if (IsGeometry(argv[i]) == MagickFalse)
5628 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5629 break;
5630 }
5631 if (LocaleCompare("size",option+1) == 0)
5632 {
5633 if (*option == '+')
5634 break;
5635 i++;
cristybb503372010-05-27 20:51:26 +00005636 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005637 ThrowMogrifyException(OptionError,"MissingArgument",option);
5638 if (IsGeometry(argv[i]) == MagickFalse)
5639 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5640 break;
5641 }
5642 if (LocaleCompare("sketch",option+1) == 0)
5643 {
5644 if (*option == '+')
5645 break;
5646 i++;
cristybb503372010-05-27 20:51:26 +00005647 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005648 ThrowMogrifyException(OptionError,"MissingArgument",option);
5649 if (IsGeometry(argv[i]) == MagickFalse)
5650 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5651 break;
5652 }
cristy4285d782011-02-09 20:12:28 +00005653 if (LocaleCompare("smush",option+1) == 0)
5654 {
cristy4285d782011-02-09 20:12:28 +00005655 i++;
5656 if (i == (ssize_t) argc)
5657 ThrowMogrifyException(OptionError,"MissingArgument",option);
5658 if (IsGeometry(argv[i]) == MagickFalse)
5659 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005660 i++;
5661 break;
5662 }
cristy3ed852e2009-09-05 21:47:34 +00005663 if (LocaleCompare("solarize",option+1) == 0)
5664 {
5665 if (*option == '+')
5666 break;
5667 i++;
cristybb503372010-05-27 20:51:26 +00005668 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005669 ThrowMogrifyException(OptionError,"MissingArgument",option);
5670 if (IsGeometry(argv[i]) == MagickFalse)
5671 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5672 break;
5673 }
5674 if (LocaleCompare("sparse-color",option+1) == 0)
5675 {
cristybb503372010-05-27 20:51:26 +00005676 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005677 op;
5678
5679 i++;
cristybb503372010-05-27 20:51:26 +00005680 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005681 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005682 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005683 if (op < 0)
5684 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5685 argv[i]);
5686 i++;
cristybb503372010-05-27 20:51:26 +00005687 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005688 ThrowMogrifyException(OptionError,"MissingArgument",option);
5689 break;
5690 }
5691 if (LocaleCompare("spread",option+1) == 0)
5692 {
5693 if (*option == '+')
5694 break;
5695 i++;
cristybb503372010-05-27 20:51:26 +00005696 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005697 ThrowMogrifyException(OptionError,"MissingArgument",option);
5698 if (IsGeometry(argv[i]) == MagickFalse)
5699 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5700 break;
5701 }
cristy0834d642011-03-18 18:26:08 +00005702 if (LocaleCompare("statistic",option+1) == 0)
5703 {
5704 ssize_t
5705 op;
5706
5707 if (*option == '+')
5708 break;
5709 i++;
5710 if (i == (ssize_t) argc)
5711 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005712 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005713 if (op < 0)
5714 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5715 argv[i]);
5716 i++;
5717 if (i == (ssize_t) (argc-1))
5718 ThrowMogrifyException(OptionError,"MissingArgument",option);
5719 if (IsGeometry(argv[i]) == MagickFalse)
5720 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5721 break;
5722 }
cristy3ed852e2009-09-05 21:47:34 +00005723 if (LocaleCompare("stretch",option+1) == 0)
5724 {
cristybb503372010-05-27 20:51:26 +00005725 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005726 stretch;
5727
5728 if (*option == '+')
5729 break;
5730 i++;
cristybb503372010-05-27 20:51:26 +00005731 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005732 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005733 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005734 if (stretch < 0)
5735 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5736 argv[i]);
5737 break;
5738 }
5739 if (LocaleCompare("strip",option+1) == 0)
5740 break;
5741 if (LocaleCompare("stroke",option+1) == 0)
5742 {
5743 if (*option == '+')
5744 break;
5745 i++;
cristybb503372010-05-27 20:51:26 +00005746 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005747 ThrowMogrifyException(OptionError,"MissingArgument",option);
5748 break;
5749 }
5750 if (LocaleCompare("strokewidth",option+1) == 0)
5751 {
5752 if (*option == '+')
5753 break;
5754 i++;
cristybb503372010-05-27 20:51:26 +00005755 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005756 ThrowMogrifyException(OptionError,"MissingArgument",option);
5757 if (IsGeometry(argv[i]) == MagickFalse)
5758 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5759 break;
5760 }
5761 if (LocaleCompare("style",option+1) == 0)
5762 {
cristybb503372010-05-27 20:51:26 +00005763 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005764 style;
5765
5766 if (*option == '+')
5767 break;
5768 i++;
cristybb503372010-05-27 20:51:26 +00005769 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005770 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005771 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005772 if (style < 0)
5773 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5774 argv[i]);
5775 break;
5776 }
cristyecb10ff2011-03-22 13:14:03 +00005777 if (LocaleCompare("swap",option+1) == 0)
5778 {
5779 if (*option == '+')
5780 break;
5781 i++;
5782 if (i == (ssize_t) (argc-1))
5783 ThrowMogrifyException(OptionError,"MissingArgument",option);
5784 if (IsGeometry(argv[i]) == MagickFalse)
5785 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5786 break;
5787 }
cristy3ed852e2009-09-05 21:47:34 +00005788 if (LocaleCompare("swirl",option+1) == 0)
5789 {
5790 if (*option == '+')
5791 break;
5792 i++;
cristybb503372010-05-27 20:51:26 +00005793 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005794 ThrowMogrifyException(OptionError,"MissingArgument",option);
5795 if (IsGeometry(argv[i]) == MagickFalse)
5796 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5797 break;
5798 }
cristyd9a29192010-10-16 16:49:53 +00005799 if (LocaleCompare("synchronize",option+1) == 0)
5800 break;
cristy3ed852e2009-09-05 21:47:34 +00005801 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5802 }
5803 case 't':
5804 {
5805 if (LocaleCompare("taint",option+1) == 0)
5806 break;
5807 if (LocaleCompare("texture",option+1) == 0)
5808 {
5809 if (*option == '+')
5810 break;
5811 i++;
cristybb503372010-05-27 20:51:26 +00005812 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005813 ThrowMogrifyException(OptionError,"MissingArgument",option);
5814 break;
5815 }
5816 if (LocaleCompare("tile",option+1) == 0)
5817 {
5818 if (*option == '+')
5819 break;
5820 i++;
cristybb503372010-05-27 20:51:26 +00005821 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005822 ThrowMogrifyException(OptionError,"MissingArgument",option);
5823 break;
5824 }
5825 if (LocaleCompare("tile-offset",option+1) == 0)
5826 {
5827 if (*option == '+')
5828 break;
5829 i++;
cristybb503372010-05-27 20:51:26 +00005830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005831 ThrowMogrifyException(OptionError,"MissingArgument",option);
5832 if (IsGeometry(argv[i]) == MagickFalse)
5833 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5834 break;
5835 }
5836 if (LocaleCompare("tint",option+1) == 0)
5837 {
5838 if (*option == '+')
5839 break;
5840 i++;
cristybb503372010-05-27 20:51:26 +00005841 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005842 ThrowMogrifyException(OptionError,"MissingArgument",option);
5843 if (IsGeometry(argv[i]) == MagickFalse)
5844 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5845 break;
5846 }
5847 if (LocaleCompare("transform",option+1) == 0)
5848 break;
5849 if (LocaleCompare("transpose",option+1) == 0)
5850 break;
5851 if (LocaleCompare("transverse",option+1) == 0)
5852 break;
5853 if (LocaleCompare("threshold",option+1) == 0)
5854 {
5855 if (*option == '+')
5856 break;
5857 i++;
cristybb503372010-05-27 20:51:26 +00005858 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005859 ThrowMogrifyException(OptionError,"MissingArgument",option);
5860 if (IsGeometry(argv[i]) == MagickFalse)
5861 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5862 break;
5863 }
5864 if (LocaleCompare("thumbnail",option+1) == 0)
5865 {
5866 if (*option == '+')
5867 break;
5868 i++;
cristybb503372010-05-27 20:51:26 +00005869 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005870 ThrowMogrifyException(OptionError,"MissingArgument",option);
5871 if (IsGeometry(argv[i]) == MagickFalse)
5872 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5873 break;
5874 }
5875 if (LocaleCompare("transparent",option+1) == 0)
5876 {
5877 i++;
cristybb503372010-05-27 20:51:26 +00005878 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005879 ThrowMogrifyException(OptionError,"MissingArgument",option);
5880 break;
5881 }
5882 if (LocaleCompare("transparent-color",option+1) == 0)
5883 {
5884 if (*option == '+')
5885 break;
5886 i++;
cristybb503372010-05-27 20:51:26 +00005887 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005888 ThrowMogrifyException(OptionError,"MissingArgument",option);
5889 break;
5890 }
5891 if (LocaleCompare("treedepth",option+1) == 0)
5892 {
5893 if (*option == '+')
5894 break;
5895 i++;
cristybb503372010-05-27 20:51:26 +00005896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005897 ThrowMogrifyException(OptionError,"MissingArgument",option);
5898 if (IsGeometry(argv[i]) == MagickFalse)
5899 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5900 break;
5901 }
5902 if (LocaleCompare("trim",option+1) == 0)
5903 break;
5904 if (LocaleCompare("type",option+1) == 0)
5905 {
cristybb503372010-05-27 20:51:26 +00005906 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005907 type;
5908
5909 if (*option == '+')
5910 break;
5911 i++;
cristybb503372010-05-27 20:51:26 +00005912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005913 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005914 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005915 if (type < 0)
5916 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5917 argv[i]);
5918 break;
5919 }
5920 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5921 }
5922 case 'u':
5923 {
5924 if (LocaleCompare("undercolor",option+1) == 0)
5925 {
5926 if (*option == '+')
5927 break;
5928 i++;
cristybb503372010-05-27 20:51:26 +00005929 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005930 ThrowMogrifyException(OptionError,"MissingArgument",option);
5931 break;
5932 }
5933 if (LocaleCompare("unique-colors",option+1) == 0)
5934 break;
5935 if (LocaleCompare("units",option+1) == 0)
5936 {
cristybb503372010-05-27 20:51:26 +00005937 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005938 units;
5939
5940 if (*option == '+')
5941 break;
5942 i++;
cristybb503372010-05-27 20:51:26 +00005943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005944 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005945 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005946 argv[i]);
5947 if (units < 0)
5948 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5949 argv[i]);
5950 break;
5951 }
5952 if (LocaleCompare("unsharp",option+1) == 0)
5953 {
5954 i++;
cristybb503372010-05-27 20:51:26 +00005955 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005956 ThrowMogrifyException(OptionError,"MissingArgument",option);
5957 if (IsGeometry(argv[i]) == MagickFalse)
5958 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5959 break;
5960 }
5961 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5962 }
5963 case 'v':
5964 {
5965 if (LocaleCompare("verbose",option+1) == 0)
5966 {
5967 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5968 break;
5969 }
5970 if ((LocaleCompare("version",option+1) == 0) ||
5971 (LocaleCompare("-version",option+1) == 0))
5972 {
cristyb51dff52011-05-19 16:55:47 +00005973 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005974 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005975 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5976 GetMagickCopyright());
5977 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5978 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005979 break;
5980 }
5981 if (LocaleCompare("view",option+1) == 0)
5982 {
5983 if (*option == '+')
5984 break;
5985 i++;
cristybb503372010-05-27 20:51:26 +00005986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005987 ThrowMogrifyException(OptionError,"MissingArgument",option);
5988 break;
5989 }
5990 if (LocaleCompare("vignette",option+1) == 0)
5991 {
5992 if (*option == '+')
5993 break;
5994 i++;
cristybb503372010-05-27 20:51:26 +00005995 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005996 ThrowMogrifyException(OptionError,"MissingArgument",option);
5997 if (IsGeometry(argv[i]) == MagickFalse)
5998 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5999 break;
6000 }
6001 if (LocaleCompare("virtual-pixel",option+1) == 0)
6002 {
cristybb503372010-05-27 20:51:26 +00006003 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006004 method;
6005
6006 if (*option == '+')
6007 break;
6008 i++;
cristybb503372010-05-27 20:51:26 +00006009 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006010 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006011 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006012 argv[i]);
6013 if (method < 0)
6014 ThrowMogrifyException(OptionError,
6015 "UnrecognizedVirtualPixelMethod",argv[i]);
6016 break;
6017 }
6018 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6019 }
6020 case 'w':
6021 {
6022 if (LocaleCompare("wave",option+1) == 0)
6023 {
6024 i++;
cristybb503372010-05-27 20:51:26 +00006025 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006026 ThrowMogrifyException(OptionError,"MissingArgument",option);
6027 if (IsGeometry(argv[i]) == MagickFalse)
6028 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6029 break;
6030 }
6031 if (LocaleCompare("weight",option+1) == 0)
6032 {
6033 if (*option == '+')
6034 break;
6035 i++;
cristybb503372010-05-27 20:51:26 +00006036 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006037 ThrowMogrifyException(OptionError,"MissingArgument",option);
6038 break;
6039 }
6040 if (LocaleCompare("white-point",option+1) == 0)
6041 {
6042 if (*option == '+')
6043 break;
6044 i++;
cristybb503372010-05-27 20:51:26 +00006045 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006046 ThrowMogrifyException(OptionError,"MissingArgument",option);
6047 if (IsGeometry(argv[i]) == MagickFalse)
6048 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6049 break;
6050 }
6051 if (LocaleCompare("white-threshold",option+1) == 0)
6052 {
6053 if (*option == '+')
6054 break;
6055 i++;
cristybb503372010-05-27 20:51:26 +00006056 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006057 ThrowMogrifyException(OptionError,"MissingArgument",option);
6058 if (IsGeometry(argv[i]) == MagickFalse)
6059 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6060 break;
6061 }
6062 if (LocaleCompare("write",option+1) == 0)
6063 {
6064 i++;
cristybb503372010-05-27 20:51:26 +00006065 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006066 ThrowMogrifyException(OptionError,"MissingArgument",option);
6067 break;
6068 }
6069 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6070 }
6071 case '?':
6072 break;
6073 default:
6074 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6075 }
cristy042ee782011-04-22 18:48:30 +00006076 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6077 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006078 if (fire != MagickFalse)
6079 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6080 }
6081 if (k != 0)
6082 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006083 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006084 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6085 DestroyMogrify();
6086 return(status != 0 ? MagickTrue : MagickFalse);
6087}
6088
6089/*
6090%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6091% %
6092% %
6093% %
6094+ M o g r i f y I m a g e I n f o %
6095% %
6096% %
6097% %
6098%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6099%
6100% MogrifyImageInfo() applies image processing settings to the image as
6101% prescribed by command line options.
6102%
6103% The format of the MogrifyImageInfo method is:
6104%
6105% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6106% const char **argv,ExceptionInfo *exception)
6107%
6108% A description of each parameter follows:
6109%
6110% o image_info: the image info..
6111%
6112% o argc: Specifies a pointer to an integer describing the number of
6113% elements in the argument vector.
6114%
6115% o argv: Specifies a pointer to a text array containing the command line
6116% arguments.
6117%
6118% o exception: return any errors or warnings in this structure.
6119%
6120*/
6121WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6122 const int argc,const char **argv,ExceptionInfo *exception)
6123{
6124 const char
6125 *option;
6126
6127 GeometryInfo
6128 geometry_info;
6129
cristybb503372010-05-27 20:51:26 +00006130 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006131 count;
6132
cristybb503372010-05-27 20:51:26 +00006133 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006134 i;
6135
6136 /*
6137 Initialize method variables.
6138 */
6139 assert(image_info != (ImageInfo *) NULL);
6140 assert(image_info->signature == MagickSignature);
6141 if (image_info->debug != MagickFalse)
6142 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6143 image_info->filename);
6144 if (argc < 0)
6145 return(MagickTrue);
6146 /*
6147 Set the image settings.
6148 */
cristybb503372010-05-27 20:51:26 +00006149 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006150 {
6151 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006152 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006153 continue;
cristy042ee782011-04-22 18:48:30 +00006154 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006155 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006156 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006157 break;
6158 switch (*(option+1))
6159 {
6160 case 'a':
6161 {
6162 if (LocaleCompare("adjoin",option+1) == 0)
6163 {
6164 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6165 break;
6166 }
6167 if (LocaleCompare("antialias",option+1) == 0)
6168 {
6169 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6170 break;
6171 }
cristy3ed852e2009-09-05 21:47:34 +00006172 if (LocaleCompare("authenticate",option+1) == 0)
6173 {
6174 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006175 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006176 else
anthony1afdc7a2011-10-05 11:54:28 +00006177 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006178 break;
6179 }
6180 break;
6181 }
6182 case 'b':
6183 {
6184 if (LocaleCompare("background",option+1) == 0)
6185 {
6186 if (*option == '+')
6187 {
6188 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006189 (void) QueryColorCompliance(MogrifyBackgroundColor,
6190 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006191 break;
6192 }
6193 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006194 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6195 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006196 break;
6197 }
6198 if (LocaleCompare("bias",option+1) == 0)
6199 {
6200 if (*option == '+')
6201 {
6202 (void) SetImageOption(image_info,option+1,"0.0");
6203 break;
6204 }
6205 (void) SetImageOption(image_info,option+1,argv[i+1]);
6206 break;
6207 }
6208 if (LocaleCompare("black-point-compensation",option+1) == 0)
6209 {
6210 if (*option == '+')
6211 {
6212 (void) SetImageOption(image_info,option+1,"false");
6213 break;
6214 }
6215 (void) SetImageOption(image_info,option+1,"true");
6216 break;
6217 }
6218 if (LocaleCompare("blue-primary",option+1) == 0)
6219 {
6220 if (*option == '+')
6221 {
6222 (void) SetImageOption(image_info,option+1,"0.0");
6223 break;
6224 }
6225 (void) SetImageOption(image_info,option+1,argv[i+1]);
6226 break;
6227 }
6228 if (LocaleCompare("bordercolor",option+1) == 0)
6229 {
6230 if (*option == '+')
6231 {
6232 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006233 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006234 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006235 break;
6236 }
cristy9950d572011-10-01 18:22:35 +00006237 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6238 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006239 (void) SetImageOption(image_info,option+1,argv[i+1]);
6240 break;
6241 }
6242 if (LocaleCompare("box",option+1) == 0)
6243 {
6244 if (*option == '+')
6245 {
6246 (void) SetImageOption(image_info,"undercolor","none");
6247 break;
6248 }
6249 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6250 break;
6251 }
6252 break;
6253 }
6254 case 'c':
6255 {
6256 if (LocaleCompare("cache",option+1) == 0)
6257 {
6258 MagickSizeType
6259 limit;
6260
6261 limit=MagickResourceInfinity;
6262 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006263 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6264 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006265 (void) SetMagickResourceLimit(MemoryResource,limit);
6266 (void) SetMagickResourceLimit(MapResource,2*limit);
6267 break;
6268 }
6269 if (LocaleCompare("caption",option+1) == 0)
6270 {
6271 if (*option == '+')
6272 {
6273 (void) DeleteImageOption(image_info,option+1);
6274 break;
6275 }
6276 (void) SetImageOption(image_info,option+1,argv[i+1]);
6277 break;
6278 }
6279 if (LocaleCompare("channel",option+1) == 0)
6280 {
6281 if (*option == '+')
6282 {
6283 image_info->channel=DefaultChannels;
cristydfdb19e2012-03-21 22:22:24 +00006284 (void) SetImageOption(image_info,option+1,"default");
cristy3ed852e2009-09-05 21:47:34 +00006285 break;
6286 }
6287 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
cristydfdb19e2012-03-21 22:22:24 +00006288 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006289 break;
6290 }
cristy3ed852e2009-09-05 21:47:34 +00006291 if (LocaleCompare("colorspace",option+1) == 0)
6292 {
6293 if (*option == '+')
6294 {
6295 image_info->colorspace=UndefinedColorspace;
6296 (void) SetImageOption(image_info,option+1,"undefined");
6297 break;
6298 }
cristy042ee782011-04-22 18:48:30 +00006299 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006300 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6301 (void) SetImageOption(image_info,option+1,argv[i+1]);
6302 break;
6303 }
cristy3ed852e2009-09-05 21:47:34 +00006304 if (LocaleCompare("comment",option+1) == 0)
6305 {
6306 if (*option == '+')
6307 {
6308 (void) DeleteImageOption(image_info,option+1);
6309 break;
6310 }
6311 (void) SetImageOption(image_info,option+1,argv[i+1]);
6312 break;
6313 }
6314 if (LocaleCompare("compose",option+1) == 0)
6315 {
6316 if (*option == '+')
6317 {
6318 (void) SetImageOption(image_info,option+1,"undefined");
6319 break;
6320 }
6321 (void) SetImageOption(image_info,option+1,argv[i+1]);
6322 break;
6323 }
6324 if (LocaleCompare("compress",option+1) == 0)
6325 {
6326 if (*option == '+')
6327 {
6328 image_info->compression=UndefinedCompression;
6329 (void) SetImageOption(image_info,option+1,"undefined");
6330 break;
6331 }
cristy042ee782011-04-22 18:48:30 +00006332 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006333 MagickCompressOptions,MagickFalse,argv[i+1]);
6334 (void) SetImageOption(image_info,option+1,argv[i+1]);
6335 break;
6336 }
6337 break;
6338 }
6339 case 'd':
6340 {
6341 if (LocaleCompare("debug",option+1) == 0)
6342 {
6343 if (*option == '+')
6344 (void) SetLogEventMask("none");
6345 else
6346 (void) SetLogEventMask(argv[i+1]);
6347 image_info->debug=IsEventLogging();
6348 break;
6349 }
6350 if (LocaleCompare("define",option+1) == 0)
6351 {
6352 if (*option == '+')
6353 {
6354 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6355 (void) DeleteImageRegistry(argv[i+1]+9);
6356 else
6357 (void) DeleteImageOption(image_info,argv[i+1]);
6358 break;
6359 }
6360 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6361 {
6362 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6363 exception);
6364 break;
6365 }
6366 (void) DefineImageOption(image_info,argv[i+1]);
6367 break;
6368 }
6369 if (LocaleCompare("delay",option+1) == 0)
6370 {
6371 if (*option == '+')
6372 {
6373 (void) SetImageOption(image_info,option+1,"0");
6374 break;
6375 }
6376 (void) SetImageOption(image_info,option+1,argv[i+1]);
6377 break;
6378 }
6379 if (LocaleCompare("density",option+1) == 0)
6380 {
6381 /*
6382 Set image density.
6383 */
6384 if (*option == '+')
6385 {
6386 if (image_info->density != (char *) NULL)
6387 image_info->density=DestroyString(image_info->density);
6388 (void) SetImageOption(image_info,option+1,"72");
6389 break;
6390 }
6391 (void) CloneString(&image_info->density,argv[i+1]);
6392 (void) SetImageOption(image_info,option+1,argv[i+1]);
6393 break;
6394 }
6395 if (LocaleCompare("depth",option+1) == 0)
6396 {
6397 if (*option == '+')
6398 {
6399 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6400 break;
6401 }
cristye27293e2009-12-18 02:53:20 +00006402 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006403 break;
6404 }
cristyc9b12952010-03-28 01:12:28 +00006405 if (LocaleCompare("direction",option+1) == 0)
6406 {
6407 if (*option == '+')
6408 {
6409 (void) SetImageOption(image_info,option+1,"undefined");
6410 break;
6411 }
6412 (void) SetImageOption(image_info,option+1,argv[i+1]);
6413 break;
6414 }
cristy3ed852e2009-09-05 21:47:34 +00006415 if (LocaleCompare("display",option+1) == 0)
6416 {
6417 if (*option == '+')
6418 {
6419 if (image_info->server_name != (char *) NULL)
6420 image_info->server_name=DestroyString(
6421 image_info->server_name);
6422 break;
6423 }
6424 (void) CloneString(&image_info->server_name,argv[i+1]);
6425 break;
6426 }
6427 if (LocaleCompare("dispose",option+1) == 0)
6428 {
6429 if (*option == '+')
6430 {
6431 (void) SetImageOption(image_info,option+1,"undefined");
6432 break;
6433 }
6434 (void) SetImageOption(image_info,option+1,argv[i+1]);
6435 break;
6436 }
6437 if (LocaleCompare("dither",option+1) == 0)
6438 {
6439 if (*option == '+')
6440 {
6441 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006442 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006443 break;
6444 }
6445 (void) SetImageOption(image_info,option+1,argv[i+1]);
6446 image_info->dither=MagickTrue;
6447 break;
6448 }
6449 break;
6450 }
6451 case 'e':
6452 {
6453 if (LocaleCompare("encoding",option+1) == 0)
6454 {
6455 if (*option == '+')
6456 {
6457 (void) SetImageOption(image_info,option+1,"undefined");
6458 break;
6459 }
6460 (void) SetImageOption(image_info,option+1,argv[i+1]);
6461 break;
6462 }
6463 if (LocaleCompare("endian",option+1) == 0)
6464 {
6465 if (*option == '+')
6466 {
6467 image_info->endian=UndefinedEndian;
6468 (void) SetImageOption(image_info,option+1,"undefined");
6469 break;
6470 }
cristy042ee782011-04-22 18:48:30 +00006471 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006472 MagickEndianOptions,MagickFalse,argv[i+1]);
6473 (void) SetImageOption(image_info,option+1,argv[i+1]);
6474 break;
6475 }
6476 if (LocaleCompare("extract",option+1) == 0)
6477 {
6478 /*
6479 Set image extract geometry.
6480 */
6481 if (*option == '+')
6482 {
6483 if (image_info->extract != (char *) NULL)
6484 image_info->extract=DestroyString(image_info->extract);
6485 break;
6486 }
6487 (void) CloneString(&image_info->extract,argv[i+1]);
6488 break;
6489 }
6490 break;
6491 }
6492 case 'f':
6493 {
6494 if (LocaleCompare("fill",option+1) == 0)
6495 {
6496 if (*option == '+')
6497 {
6498 (void) SetImageOption(image_info,option+1,"none");
6499 break;
6500 }
6501 (void) SetImageOption(image_info,option+1,argv[i+1]);
6502 break;
6503 }
6504 if (LocaleCompare("filter",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("font",option+1) == 0)
6515 {
6516 if (*option == '+')
6517 {
6518 if (image_info->font != (char *) NULL)
6519 image_info->font=DestroyString(image_info->font);
6520 break;
6521 }
6522 (void) CloneString(&image_info->font,argv[i+1]);
6523 break;
6524 }
6525 if (LocaleCompare("format",option+1) == 0)
6526 {
6527 register const char
6528 *q;
6529
6530 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006531 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006532 image_info->ping=MagickFalse;
6533 (void) SetImageOption(image_info,option+1,argv[i+1]);
6534 break;
6535 }
6536 if (LocaleCompare("fuzz",option+1) == 0)
6537 {
6538 if (*option == '+')
6539 {
6540 image_info->fuzz=0.0;
6541 (void) SetImageOption(image_info,option+1,"0");
6542 break;
6543 }
cristydbdd0e32011-11-04 23:29:40 +00006544 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6545 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006546 (void) SetImageOption(image_info,option+1,argv[i+1]);
6547 break;
6548 }
6549 break;
6550 }
6551 case 'g':
6552 {
6553 if (LocaleCompare("gravity",option+1) == 0)
6554 {
6555 if (*option == '+')
6556 {
6557 (void) SetImageOption(image_info,option+1,"undefined");
6558 break;
6559 }
6560 (void) SetImageOption(image_info,option+1,argv[i+1]);
6561 break;
6562 }
6563 if (LocaleCompare("green-primary",option+1) == 0)
6564 {
6565 if (*option == '+')
6566 {
6567 (void) SetImageOption(image_info,option+1,"0.0");
6568 break;
6569 }
6570 (void) SetImageOption(image_info,option+1,argv[i+1]);
6571 break;
6572 }
6573 break;
6574 }
6575 case 'i':
6576 {
6577 if (LocaleCompare("intent",option+1) == 0)
6578 {
6579 if (*option == '+')
6580 {
6581 (void) SetImageOption(image_info,option+1,"undefined");
6582 break;
6583 }
6584 (void) SetImageOption(image_info,option+1,argv[i+1]);
6585 break;
6586 }
6587 if (LocaleCompare("interlace",option+1) == 0)
6588 {
6589 if (*option == '+')
6590 {
6591 image_info->interlace=UndefinedInterlace;
6592 (void) SetImageOption(image_info,option+1,"undefined");
6593 break;
6594 }
cristy042ee782011-04-22 18:48:30 +00006595 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006596 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6597 (void) SetImageOption(image_info,option+1,argv[i+1]);
6598 break;
6599 }
cristyb32b90a2009-09-07 21:45:48 +00006600 if (LocaleCompare("interline-spacing",option+1) == 0)
6601 {
6602 if (*option == '+')
6603 {
6604 (void) SetImageOption(image_info,option+1,"undefined");
6605 break;
6606 }
6607 (void) SetImageOption(image_info,option+1,argv[i+1]);
6608 break;
6609 }
cristy3ed852e2009-09-05 21:47:34 +00006610 if (LocaleCompare("interpolate",option+1) == 0)
6611 {
6612 if (*option == '+')
6613 {
6614 (void) SetImageOption(image_info,option+1,"undefined");
6615 break;
6616 }
6617 (void) SetImageOption(image_info,option+1,argv[i+1]);
6618 break;
6619 }
6620 if (LocaleCompare("interword-spacing",option+1) == 0)
6621 {
6622 if (*option == '+')
6623 {
6624 (void) SetImageOption(image_info,option+1,"undefined");
6625 break;
6626 }
6627 (void) SetImageOption(image_info,option+1,argv[i+1]);
6628 break;
6629 }
6630 break;
6631 }
6632 case 'k':
6633 {
6634 if (LocaleCompare("kerning",option+1) == 0)
6635 {
6636 if (*option == '+')
6637 {
6638 (void) SetImageOption(image_info,option+1,"undefined");
6639 break;
6640 }
6641 (void) SetImageOption(image_info,option+1,argv[i+1]);
6642 break;
6643 }
6644 break;
6645 }
6646 case 'l':
6647 {
6648 if (LocaleCompare("label",option+1) == 0)
6649 {
6650 if (*option == '+')
6651 {
6652 (void) DeleteImageOption(image_info,option+1);
6653 break;
6654 }
6655 (void) SetImageOption(image_info,option+1,argv[i+1]);
6656 break;
6657 }
6658 if (LocaleCompare("limit",option+1) == 0)
6659 {
6660 MagickSizeType
6661 limit;
6662
6663 ResourceType
6664 type;
6665
6666 if (*option == '+')
6667 break;
cristy042ee782011-04-22 18:48:30 +00006668 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006669 MagickFalse,argv[i+1]);
6670 limit=MagickResourceInfinity;
6671 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006672 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006673 (void) SetMagickResourceLimit(type,limit);
6674 break;
6675 }
6676 if (LocaleCompare("list",option+1) == 0)
6677 {
cristybb503372010-05-27 20:51:26 +00006678 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006679 list;
6680
6681 /*
6682 Display configuration list.
6683 */
cristy042ee782011-04-22 18:48:30 +00006684 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006685 switch (list)
6686 {
6687 case MagickCoderOptions:
6688 {
6689 (void) ListCoderInfo((FILE *) NULL,exception);
6690 break;
6691 }
6692 case MagickColorOptions:
6693 {
6694 (void) ListColorInfo((FILE *) NULL,exception);
6695 break;
6696 }
6697 case MagickConfigureOptions:
6698 {
6699 (void) ListConfigureInfo((FILE *) NULL,exception);
6700 break;
6701 }
6702 case MagickDelegateOptions:
6703 {
6704 (void) ListDelegateInfo((FILE *) NULL,exception);
6705 break;
6706 }
6707 case MagickFontOptions:
6708 {
6709 (void) ListTypeInfo((FILE *) NULL,exception);
6710 break;
6711 }
6712 case MagickFormatOptions:
6713 {
6714 (void) ListMagickInfo((FILE *) NULL,exception);
6715 break;
6716 }
6717 case MagickLocaleOptions:
6718 {
6719 (void) ListLocaleInfo((FILE *) NULL,exception);
6720 break;
6721 }
6722 case MagickLogOptions:
6723 {
6724 (void) ListLogInfo((FILE *) NULL,exception);
6725 break;
6726 }
6727 case MagickMagicOptions:
6728 {
6729 (void) ListMagicInfo((FILE *) NULL,exception);
6730 break;
6731 }
6732 case MagickMimeOptions:
6733 {
6734 (void) ListMimeInfo((FILE *) NULL,exception);
6735 break;
6736 }
6737 case MagickModuleOptions:
6738 {
6739 (void) ListModuleInfo((FILE *) NULL,exception);
6740 break;
6741 }
6742 case MagickPolicyOptions:
6743 {
6744 (void) ListPolicyInfo((FILE *) NULL,exception);
6745 break;
6746 }
6747 case MagickResourceOptions:
6748 {
6749 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6750 break;
6751 }
6752 case MagickThresholdOptions:
6753 {
6754 (void) ListThresholdMaps((FILE *) NULL,exception);
6755 break;
6756 }
6757 default:
6758 {
cristy042ee782011-04-22 18:48:30 +00006759 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006760 exception);
6761 break;
6762 }
6763 }
cristyaeb2cbc2010-05-07 13:28:58 +00006764 break;
cristy3ed852e2009-09-05 21:47:34 +00006765 }
6766 if (LocaleCompare("log",option+1) == 0)
6767 {
6768 if (*option == '+')
6769 break;
6770 (void) SetLogFormat(argv[i+1]);
6771 break;
6772 }
6773 if (LocaleCompare("loop",option+1) == 0)
6774 {
6775 if (*option == '+')
6776 {
6777 (void) SetImageOption(image_info,option+1,"0");
6778 break;
6779 }
6780 (void) SetImageOption(image_info,option+1,argv[i+1]);
6781 break;
6782 }
6783 break;
6784 }
6785 case 'm':
6786 {
6787 if (LocaleCompare("matte",option+1) == 0)
6788 {
6789 if (*option == '+')
6790 {
6791 (void) SetImageOption(image_info,option+1,"false");
6792 break;
6793 }
6794 (void) SetImageOption(image_info,option+1,"true");
6795 break;
6796 }
6797 if (LocaleCompare("mattecolor",option+1) == 0)
6798 {
6799 if (*option == '+')
6800 {
6801 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006802 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006803 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006804 break;
6805 }
6806 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006807 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6808 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006809 break;
6810 }
6811 if (LocaleCompare("monitor",option+1) == 0)
6812 {
6813 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6814 (void *) NULL);
6815 break;
6816 }
6817 if (LocaleCompare("monochrome",option+1) == 0)
6818 {
6819 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6820 break;
6821 }
6822 break;
6823 }
6824 case 'o':
6825 {
6826 if (LocaleCompare("orient",option+1) == 0)
6827 {
6828 if (*option == '+')
6829 {
6830 image_info->orientation=UndefinedOrientation;
6831 (void) SetImageOption(image_info,option+1,"undefined");
6832 break;
6833 }
cristy042ee782011-04-22 18:48:30 +00006834 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006835 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006836 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006837 break;
6838 }
6839 }
6840 case 'p':
6841 {
6842 if (LocaleCompare("page",option+1) == 0)
6843 {
6844 char
6845 *canonical_page,
6846 page[MaxTextExtent];
6847
6848 const char
6849 *image_option;
6850
6851 MagickStatusType
6852 flags;
6853
6854 RectangleInfo
6855 geometry;
6856
6857 if (*option == '+')
6858 {
6859 (void) DeleteImageOption(image_info,option+1);
6860 (void) CloneString(&image_info->page,(char *) NULL);
6861 break;
6862 }
6863 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6864 image_option=GetImageOption(image_info,"page");
6865 if (image_option != (const char *) NULL)
6866 flags=ParseAbsoluteGeometry(image_option,&geometry);
6867 canonical_page=GetPageGeometry(argv[i+1]);
6868 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6869 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006870 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006871 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006872 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006873 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006874 (unsigned long) geometry.width,(unsigned long) geometry.height,
6875 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006876 (void) SetImageOption(image_info,option+1,page);
6877 (void) CloneString(&image_info->page,page);
6878 break;
6879 }
cristy3ed852e2009-09-05 21:47:34 +00006880 if (LocaleCompare("ping",option+1) == 0)
6881 {
6882 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6883 break;
6884 }
6885 if (LocaleCompare("pointsize",option+1) == 0)
6886 {
6887 if (*option == '+')
6888 geometry_info.rho=0.0;
6889 else
6890 (void) ParseGeometry(argv[i+1],&geometry_info);
6891 image_info->pointsize=geometry_info.rho;
6892 break;
6893 }
cristye7f51092010-01-17 00:39:37 +00006894 if (LocaleCompare("precision",option+1) == 0)
6895 {
cristybf2766a2010-01-17 03:33:23 +00006896 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006897 break;
6898 }
cristy3ed852e2009-09-05 21:47:34 +00006899 if (LocaleCompare("preview",option+1) == 0)
6900 {
6901 /*
6902 Preview image.
6903 */
6904 if (*option == '+')
6905 {
6906 image_info->preview_type=UndefinedPreview;
6907 break;
6908 }
cristy042ee782011-04-22 18:48:30 +00006909 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006910 MagickPreviewOptions,MagickFalse,argv[i+1]);
6911 break;
6912 }
6913 break;
6914 }
6915 case 'q':
6916 {
6917 if (LocaleCompare("quality",option+1) == 0)
6918 {
6919 /*
6920 Set image compression quality.
6921 */
6922 if (*option == '+')
6923 {
6924 image_info->quality=UndefinedCompressionQuality;
6925 (void) SetImageOption(image_info,option+1,"0");
6926 break;
6927 }
cristye27293e2009-12-18 02:53:20 +00006928 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006929 (void) SetImageOption(image_info,option+1,argv[i+1]);
6930 break;
6931 }
6932 if (LocaleCompare("quiet",option+1) == 0)
6933 {
6934 static WarningHandler
6935 warning_handler = (WarningHandler) NULL;
6936
6937 if (*option == '+')
6938 {
6939 /*
6940 Restore error or warning messages.
6941 */
6942 warning_handler=SetWarningHandler(warning_handler);
6943 break;
6944 }
6945 /*
6946 Suppress error or warning messages.
6947 */
6948 warning_handler=SetWarningHandler((WarningHandler) NULL);
6949 break;
6950 }
6951 break;
6952 }
6953 case 'r':
6954 {
6955 if (LocaleCompare("red-primary",option+1) == 0)
6956 {
6957 if (*option == '+')
6958 {
6959 (void) SetImageOption(image_info,option+1,"0.0");
6960 break;
6961 }
6962 (void) SetImageOption(image_info,option+1,argv[i+1]);
6963 break;
6964 }
6965 break;
6966 }
6967 case 's':
6968 {
6969 if (LocaleCompare("sampling-factor",option+1) == 0)
6970 {
6971 /*
6972 Set image sampling factor.
6973 */
6974 if (*option == '+')
6975 {
6976 if (image_info->sampling_factor != (char *) NULL)
6977 image_info->sampling_factor=DestroyString(
6978 image_info->sampling_factor);
6979 break;
6980 }
6981 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6982 break;
6983 }
6984 if (LocaleCompare("scene",option+1) == 0)
6985 {
6986 /*
6987 Set image scene.
6988 */
6989 if (*option == '+')
6990 {
6991 image_info->scene=0;
6992 (void) SetImageOption(image_info,option+1,"0");
6993 break;
6994 }
cristye27293e2009-12-18 02:53:20 +00006995 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006996 (void) SetImageOption(image_info,option+1,argv[i+1]);
6997 break;
6998 }
6999 if (LocaleCompare("seed",option+1) == 0)
7000 {
cristybb503372010-05-27 20:51:26 +00007001 size_t
cristy3ed852e2009-09-05 21:47:34 +00007002 seed;
7003
7004 if (*option == '+')
7005 {
cristybb503372010-05-27 20:51:26 +00007006 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007007 SeedPseudoRandomGenerator(seed);
7008 break;
7009 }
cristye27293e2009-12-18 02:53:20 +00007010 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007011 SeedPseudoRandomGenerator(seed);
7012 break;
7013 }
7014 if (LocaleCompare("size",option+1) == 0)
7015 {
7016 if (*option == '+')
7017 {
7018 if (image_info->size != (char *) NULL)
7019 image_info->size=DestroyString(image_info->size);
7020 break;
7021 }
7022 (void) CloneString(&image_info->size,argv[i+1]);
7023 break;
7024 }
7025 if (LocaleCompare("stroke",option+1) == 0)
7026 {
7027 if (*option == '+')
7028 {
7029 (void) SetImageOption(image_info,option+1,"none");
7030 break;
7031 }
7032 (void) SetImageOption(image_info,option+1,argv[i+1]);
7033 break;
7034 }
7035 if (LocaleCompare("strokewidth",option+1) == 0)
7036 {
7037 if (*option == '+')
7038 {
7039 (void) SetImageOption(image_info,option+1,"0");
7040 break;
7041 }
7042 (void) SetImageOption(image_info,option+1,argv[i+1]);
7043 break;
7044 }
cristyd9a29192010-10-16 16:49:53 +00007045 if (LocaleCompare("synchronize",option+1) == 0)
7046 {
7047 if (*option == '+')
7048 {
7049 image_info->synchronize=MagickFalse;
7050 break;
7051 }
7052 image_info->synchronize=MagickTrue;
7053 break;
7054 }
cristy3ed852e2009-09-05 21:47:34 +00007055 break;
7056 }
7057 case 't':
7058 {
7059 if (LocaleCompare("taint",option+1) == 0)
7060 {
7061 if (*option == '+')
7062 {
7063 (void) SetImageOption(image_info,option+1,"false");
7064 break;
7065 }
7066 (void) SetImageOption(image_info,option+1,"true");
7067 break;
7068 }
7069 if (LocaleCompare("texture",option+1) == 0)
7070 {
7071 if (*option == '+')
7072 {
7073 if (image_info->texture != (char *) NULL)
7074 image_info->texture=DestroyString(image_info->texture);
7075 break;
7076 }
7077 (void) CloneString(&image_info->texture,argv[i+1]);
7078 break;
7079 }
7080 if (LocaleCompare("tile-offset",option+1) == 0)
7081 {
7082 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007083 (void) SetImageOption(image_info,option+1,"0");
7084 else
7085 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007086 break;
7087 }
7088 if (LocaleCompare("transparent-color",option+1) == 0)
7089 {
7090 if (*option == '+')
7091 {
cristy9950d572011-10-01 18:22:35 +00007092 (void) QueryColorCompliance("none",AllCompliance,
7093 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007094 (void) SetImageOption(image_info,option+1,"none");
7095 break;
7096 }
cristy9950d572011-10-01 18:22:35 +00007097 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7098 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007099 (void) SetImageOption(image_info,option+1,argv[i+1]);
7100 break;
7101 }
7102 if (LocaleCompare("type",option+1) == 0)
7103 {
7104 if (*option == '+')
7105 {
cristy5f1c1ff2010-12-23 21:38:06 +00007106 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007107 (void) SetImageOption(image_info,option+1,"undefined");
7108 break;
7109 }
cristy042ee782011-04-22 18:48:30 +00007110 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007111 MagickFalse,argv[i+1]);
7112 (void) SetImageOption(image_info,option+1,argv[i+1]);
7113 break;
7114 }
7115 break;
7116 }
7117 case 'u':
7118 {
7119 if (LocaleCompare("undercolor",option+1) == 0)
7120 {
7121 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007122 (void) DeleteImageOption(image_info,option+1);
7123 else
7124 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007125 break;
7126 }
7127 if (LocaleCompare("units",option+1) == 0)
7128 {
7129 if (*option == '+')
7130 {
7131 image_info->units=UndefinedResolution;
7132 (void) SetImageOption(image_info,option+1,"undefined");
7133 break;
7134 }
cristy042ee782011-04-22 18:48:30 +00007135 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007136 MagickResolutionOptions,MagickFalse,argv[i+1]);
7137 (void) SetImageOption(image_info,option+1,argv[i+1]);
7138 break;
7139 }
7140 break;
7141 }
7142 case 'v':
7143 {
7144 if (LocaleCompare("verbose",option+1) == 0)
7145 {
7146 if (*option == '+')
7147 {
7148 image_info->verbose=MagickFalse;
7149 break;
7150 }
7151 image_info->verbose=MagickTrue;
7152 image_info->ping=MagickFalse;
7153 break;
7154 }
7155 if (LocaleCompare("view",option+1) == 0)
7156 {
7157 if (*option == '+')
7158 {
7159 if (image_info->view != (char *) NULL)
7160 image_info->view=DestroyString(image_info->view);
7161 break;
7162 }
7163 (void) CloneString(&image_info->view,argv[i+1]);
7164 break;
7165 }
7166 if (LocaleCompare("virtual-pixel",option+1) == 0)
7167 {
7168 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007169 (void) SetImageOption(image_info,option+1,"undefined");
7170 else
7171 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007172 break;
7173 }
7174 break;
7175 }
7176 case 'w':
7177 {
7178 if (LocaleCompare("white-point",option+1) == 0)
7179 {
7180 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007181 (void) SetImageOption(image_info,option+1,"0.0");
7182 else
7183 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007184 break;
7185 }
7186 break;
7187 }
7188 default:
7189 break;
7190 }
7191 i+=count;
7192 }
7193 return(MagickTrue);
7194}
7195
7196/*
7197%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7198% %
7199% %
7200% %
7201+ M o g r i f y I m a g e L i s t %
7202% %
7203% %
7204% %
7205%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7206%
7207% MogrifyImageList() applies any command line options that might affect the
7208% entire image list (e.g. -append, -coalesce, etc.).
7209%
7210% The format of the MogrifyImage method is:
7211%
7212% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7213% const char **argv,Image **images,ExceptionInfo *exception)
7214%
7215% A description of each parameter follows:
7216%
7217% o image_info: the image info..
7218%
7219% o argc: Specifies a pointer to an integer describing the number of
7220% elements in the argument vector.
7221%
7222% o argv: Specifies a pointer to a text array containing the command line
7223% arguments.
7224%
anthonye9c27192011-03-27 08:07:06 +00007225% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007226%
7227% o exception: return any errors or warnings in this structure.
7228%
7229*/
7230WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7231 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7232{
cristy3ed852e2009-09-05 21:47:34 +00007233 const char
7234 *option;
7235
cristy6b3da3a2010-06-20 02:21:46 +00007236 ImageInfo
7237 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007238
7239 MagickStatusType
7240 status;
7241
cristy28474bf2011-09-11 23:32:52 +00007242 PixelInterpolateMethod
7243 interpolate_method;
7244
cristy3ed852e2009-09-05 21:47:34 +00007245 QuantizeInfo
7246 *quantize_info;
7247
cristybb503372010-05-27 20:51:26 +00007248 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007249 i;
7250
cristy6b3da3a2010-06-20 02:21:46 +00007251 ssize_t
7252 count,
7253 index;
7254
cristy3ed852e2009-09-05 21:47:34 +00007255 /*
7256 Apply options to the image list.
7257 */
7258 assert(image_info != (ImageInfo *) NULL);
7259 assert(image_info->signature == MagickSignature);
7260 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007261 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007262 assert((*images)->signature == MagickSignature);
7263 if ((*images)->debug != MagickFalse)
7264 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7265 (*images)->filename);
7266 if ((argc <= 0) || (*argv == (char *) NULL))
7267 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007268 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007269 mogrify_info=CloneImageInfo(image_info);
7270 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007271 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007272 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007273 {
cristy74fe8f12009-10-03 19:09:01 +00007274 if (*images == (Image *) NULL)
7275 break;
cristy3ed852e2009-09-05 21:47:34 +00007276 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007277 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007278 continue;
cristy042ee782011-04-22 18:48:30 +00007279 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007280 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007281 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007282 break;
cristy6b3da3a2010-06-20 02:21:46 +00007283 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007284 switch (*(option+1))
7285 {
7286 case 'a':
7287 {
7288 if (LocaleCompare("affinity",option+1) == 0)
7289 {
cristy6fccee12011-10-20 18:43:18 +00007290 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007291 if (*option == '+')
7292 {
cristy018f07f2011-09-04 21:15:19 +00007293 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7294 exception);
cristy3ed852e2009-09-05 21:47:34 +00007295 break;
7296 }
7297 i++;
7298 break;
7299 }
7300 if (LocaleCompare("append",option+1) == 0)
7301 {
7302 Image
7303 *append_image;
7304
cristy6fccee12011-10-20 18:43:18 +00007305 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007306 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7307 MagickFalse,exception);
7308 if (append_image == (Image *) NULL)
7309 {
7310 status=MagickFalse;
7311 break;
7312 }
7313 *images=DestroyImageList(*images);
7314 *images=append_image;
7315 break;
7316 }
7317 if (LocaleCompare("average",option+1) == 0)
7318 {
7319 Image
7320 *average_image;
7321
cristyd18ae7c2010-03-07 17:39:52 +00007322 /*
7323 Average an image sequence (deprecated).
7324 */
cristy6fccee12011-10-20 18:43:18 +00007325 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007326 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7327 exception);
cristy3ed852e2009-09-05 21:47:34 +00007328 if (average_image == (Image *) NULL)
7329 {
7330 status=MagickFalse;
7331 break;
7332 }
7333 *images=DestroyImageList(*images);
7334 *images=average_image;
7335 break;
7336 }
7337 break;
7338 }
7339 case 'c':
7340 {
cristy5f257b22012-03-07 00:27:29 +00007341 if (LocaleCompare("channel-fx",option+1) == 0)
cristy87c02f42012-02-24 00:19:10 +00007342 {
cristyd04e7bf2012-03-03 19:19:12 +00007343 Image
7344 *channel_image;
7345
7346 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy5f257b22012-03-07 00:27:29 +00007347 channel_image=ChannelFxImage(*images,argv[i+1],exception);
cristyd04e7bf2012-03-03 19:19:12 +00007348 if (channel_image == (Image *) NULL)
7349 {
7350 status=MagickFalse;
7351 break;
7352 }
7353 *images=DestroyImageList(*images);
7354 *images=channel_image;
cristy87c02f42012-02-24 00:19:10 +00007355 break;
7356 }
cristy3ed852e2009-09-05 21:47:34 +00007357 if (LocaleCompare("clut",option+1) == 0)
7358 {
7359 Image
7360 *clut_image,
7361 *image;
7362
cristy6fccee12011-10-20 18:43:18 +00007363 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007364 image=RemoveFirstImageFromList(images);
7365 clut_image=RemoveFirstImageFromList(images);
7366 if (clut_image == (Image *) NULL)
7367 {
7368 status=MagickFalse;
7369 break;
7370 }
cristy28474bf2011-09-11 23:32:52 +00007371 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007372 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007373 *images=DestroyImageList(*images);
7374 *images=image;
7375 break;
7376 }
7377 if (LocaleCompare("coalesce",option+1) == 0)
7378 {
7379 Image
7380 *coalesce_image;
7381
cristy6fccee12011-10-20 18:43:18 +00007382 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007383 coalesce_image=CoalesceImages(*images,exception);
7384 if (coalesce_image == (Image *) NULL)
7385 {
7386 status=MagickFalse;
7387 break;
7388 }
7389 *images=DestroyImageList(*images);
7390 *images=coalesce_image;
7391 break;
7392 }
7393 if (LocaleCompare("combine",option+1) == 0)
7394 {
7395 Image
7396 *combine_image;
7397
cristy6fccee12011-10-20 18:43:18 +00007398 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007399 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007400 if (combine_image == (Image *) NULL)
7401 {
7402 status=MagickFalse;
7403 break;
7404 }
7405 *images=DestroyImageList(*images);
7406 *images=combine_image;
7407 break;
7408 }
7409 if (LocaleCompare("composite",option+1) == 0)
7410 {
cristyfeb3e962012-03-29 17:25:55 +00007411 const char
7412 *value;
7413
cristy3ed852e2009-09-05 21:47:34 +00007414 Image
7415 *mask_image,
7416 *composite_image,
7417 *image;
7418
cristyfeb3e962012-03-29 17:25:55 +00007419 MagickBooleanType
7420 clip_to_self;
7421
cristy3ed852e2009-09-05 21:47:34 +00007422 RectangleInfo
7423 geometry;
7424
cristy6fccee12011-10-20 18:43:18 +00007425 (void) SyncImagesSettings(mogrify_info,*images,exception);
anthony7bcfe7f2012-03-30 14:01:22 +00007426
7427 clip_to_self=IsStringTrue(GetImageOption(mogrify_info,
7428 "compose:clip-to-self")); /* if this is true */
7429 if (IsMagickFalse(clip_to_self)) /* or */
7430 clip_to_self=IfMagickFalse(IsStringNotFalse(GetImageOption(
7431 mogrify_info,"compose:outside-overlay"))); /* this false */
7432
cristy3ed852e2009-09-05 21:47:34 +00007433 image=RemoveFirstImageFromList(images);
7434 composite_image=RemoveFirstImageFromList(images);
7435 if (composite_image == (Image *) NULL)
7436 {
7437 status=MagickFalse;
7438 break;
7439 }
7440 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007441 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007442 SetGeometry(composite_image,&geometry);
7443 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7444 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7445 &geometry);
7446 mask_image=RemoveFirstImageFromList(images);
7447 if (mask_image != (Image *) NULL)
7448 {
7449 if ((image->compose == DisplaceCompositeOp) ||
7450 (image->compose == DistortCompositeOp))
7451 {
7452 /*
7453 Merge Y displacement into X displacement image.
7454 */
cristyfeb3e962012-03-29 17:25:55 +00007455 (void) CompositeImage(composite_image,mask_image,
cristy39172402012-03-30 13:04:39 +00007456 CopyGreenCompositeOp,MagickTrue,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007457 mask_image=DestroyImage(mask_image);
7458 }
7459 else
7460 {
7461 /*
anthony80c37752012-01-16 01:03:11 +00007462 Set a blending mask for the composition.
cristy3ed852e2009-09-05 21:47:34 +00007463 */
cristy10a6c612012-01-29 21:41:05 +00007464 (void) NegateImage(mask_image,MagickFalse,exception);
7465 (void) SetImageMask(image,mask_image,exception);
7466 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00007467 }
7468 }
cristyfeb3e962012-03-29 17:25:55 +00007469 (void) CompositeImage(image,composite_image,image->compose,
cristy39172402012-03-30 13:04:39 +00007470 clip_to_self,geometry.x,geometry.y,exception);
cristy10a6c612012-01-29 21:41:05 +00007471 (void) SetImageMask(image,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00007472 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007473 *images=DestroyImageList(*images);
7474 *images=image;
7475 break;
7476 }
cristy3ed852e2009-09-05 21:47:34 +00007477 break;
7478 }
7479 case 'd':
7480 {
7481 if (LocaleCompare("deconstruct",option+1) == 0)
7482 {
7483 Image
7484 *deconstruct_image;
7485
cristy6fccee12011-10-20 18:43:18 +00007486 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007487 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007488 exception);
cristy3ed852e2009-09-05 21:47:34 +00007489 if (deconstruct_image == (Image *) NULL)
7490 {
7491 status=MagickFalse;
7492 break;
7493 }
7494 *images=DestroyImageList(*images);
7495 *images=deconstruct_image;
7496 break;
7497 }
7498 if (LocaleCompare("delete",option+1) == 0)
7499 {
7500 if (*option == '+')
7501 DeleteImages(images,"-1",exception);
7502 else
7503 DeleteImages(images,argv[i+1],exception);
7504 break;
7505 }
7506 if (LocaleCompare("dither",option+1) == 0)
7507 {
7508 if (*option == '+')
7509 {
7510 quantize_info->dither=MagickFalse;
7511 break;
7512 }
7513 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007514 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007515 MagickDitherOptions,MagickFalse,argv[i+1]);
7516 break;
7517 }
cristyecb10ff2011-03-22 13:14:03 +00007518 if (LocaleCompare("duplicate",option+1) == 0)
7519 {
cristy72988482011-03-29 16:34:38 +00007520 Image
7521 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007522
anthony2b6bcae2011-03-23 13:05:34 +00007523 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007524 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7525 else
7526 {
7527 const char
7528 *p;
7529
anthony2b6bcae2011-03-23 13:05:34 +00007530 size_t
7531 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007532
anthony2b6bcae2011-03-23 13:05:34 +00007533 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007534 p=strchr(argv[i+1],',');
7535 if (p == (const char *) NULL)
7536 duplicate_images=DuplicateImages(*images,number_duplicates,
7537 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007538 else
cristy72988482011-03-29 16:34:38 +00007539 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7540 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007541 }
7542 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007543 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007544 break;
7545 }
cristy3ed852e2009-09-05 21:47:34 +00007546 break;
7547 }
cristyd18ae7c2010-03-07 17:39:52 +00007548 case 'e':
7549 {
7550 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7551 {
7552 Image
7553 *evaluate_image;
7554
7555 MagickEvaluateOperator
7556 op;
7557
cristy6fccee12011-10-20 18:43:18 +00007558 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007559 op=(MagickEvaluateOperator) ParseCommandOption(
7560 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007561 evaluate_image=EvaluateImages(*images,op,exception);
7562 if (evaluate_image == (Image *) NULL)
7563 {
7564 status=MagickFalse;
7565 break;
7566 }
7567 *images=DestroyImageList(*images);
7568 *images=evaluate_image;
7569 break;
7570 }
7571 break;
7572 }
cristy3ed852e2009-09-05 21:47:34 +00007573 case 'f':
7574 {
cristyf0a247f2009-10-04 00:20:03 +00007575 if (LocaleCompare("fft",option+1) == 0)
7576 {
7577 Image
7578 *fourier_image;
7579
7580 /*
7581 Implements the discrete Fourier transform (DFT).
7582 */
cristy6fccee12011-10-20 18:43:18 +00007583 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007584 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7585 MagickTrue : MagickFalse,exception);
7586 if (fourier_image == (Image *) NULL)
7587 break;
7588 *images=DestroyImage(*images);
7589 *images=fourier_image;
7590 break;
7591 }
cristy3ed852e2009-09-05 21:47:34 +00007592 if (LocaleCompare("flatten",option+1) == 0)
7593 {
7594 Image
7595 *flatten_image;
7596
cristy6fccee12011-10-20 18:43:18 +00007597 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007598 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7599 if (flatten_image == (Image *) NULL)
7600 break;
7601 *images=DestroyImageList(*images);
7602 *images=flatten_image;
7603 break;
7604 }
7605 if (LocaleCompare("fx",option+1) == 0)
7606 {
7607 Image
7608 *fx_image;
7609
cristy6fccee12011-10-20 18:43:18 +00007610 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007611 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007612 if (fx_image == (Image *) NULL)
7613 {
7614 status=MagickFalse;
7615 break;
7616 }
7617 *images=DestroyImageList(*images);
7618 *images=fx_image;
7619 break;
7620 }
7621 break;
7622 }
7623 case 'h':
7624 {
7625 if (LocaleCompare("hald-clut",option+1) == 0)
7626 {
7627 Image
7628 *hald_image,
7629 *image;
7630
cristy6fccee12011-10-20 18:43:18 +00007631 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007632 image=RemoveFirstImageFromList(images);
7633 hald_image=RemoveFirstImageFromList(images);
7634 if (hald_image == (Image *) NULL)
7635 {
7636 status=MagickFalse;
7637 break;
7638 }
cristy7c0a0a42011-08-23 17:57:25 +00007639 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007640 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007641 if (*images != (Image *) NULL)
7642 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007643 *images=image;
7644 break;
7645 }
7646 break;
7647 }
7648 case 'i':
7649 {
7650 if (LocaleCompare("ift",option+1) == 0)
7651 {
7652 Image
cristy8587f882009-11-13 20:28:49 +00007653 *fourier_image,
7654 *magnitude_image,
7655 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007656
7657 /*
7658 Implements the inverse fourier discrete Fourier transform (DFT).
7659 */
cristy6fccee12011-10-20 18:43:18 +00007660 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007661 magnitude_image=RemoveFirstImageFromList(images);
7662 phase_image=RemoveFirstImageFromList(images);
7663 if (phase_image == (Image *) NULL)
7664 {
7665 status=MagickFalse;
7666 break;
7667 }
7668 fourier_image=InverseFourierTransformImage(magnitude_image,
7669 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007670 if (fourier_image == (Image *) NULL)
7671 break;
cristy0aff6ea2009-11-14 01:40:53 +00007672 if (*images != (Image *) NULL)
7673 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007674 *images=fourier_image;
7675 break;
7676 }
7677 if (LocaleCompare("insert",option+1) == 0)
7678 {
7679 Image
7680 *p,
7681 *q;
7682
7683 index=0;
7684 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007685 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007686 p=RemoveLastImageFromList(images);
7687 if (p == (Image *) NULL)
7688 {
7689 (void) ThrowMagickException(exception,GetMagickModule(),
7690 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7691 status=MagickFalse;
7692 break;
7693 }
7694 q=p;
7695 if (index == 0)
7696 PrependImageToList(images,q);
7697 else
cristybb503372010-05-27 20:51:26 +00007698 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007699 AppendImageToList(images,q);
7700 else
7701 {
7702 q=GetImageFromList(*images,index-1);
7703 if (q == (Image *) NULL)
7704 {
7705 (void) ThrowMagickException(exception,GetMagickModule(),
7706 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7707 status=MagickFalse;
7708 break;
7709 }
7710 InsertImageInList(&q,p);
7711 }
7712 *images=GetFirstImageInList(q);
7713 break;
7714 }
cristy28474bf2011-09-11 23:32:52 +00007715 if (LocaleCompare("interpolate",option+1) == 0)
7716 {
7717 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7718 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7719 break;
7720 }
cristy3ed852e2009-09-05 21:47:34 +00007721 break;
7722 }
7723 case 'l':
7724 {
7725 if (LocaleCompare("layers",option+1) == 0)
7726 {
7727 Image
7728 *layers;
7729
7730 ImageLayerMethod
7731 method;
7732
cristy6fccee12011-10-20 18:43:18 +00007733 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007734 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007735 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007736 MagickFalse,argv[i+1]);
7737 switch (method)
7738 {
7739 case CoalesceLayer:
7740 {
7741 layers=CoalesceImages(*images,exception);
7742 break;
7743 }
7744 case CompareAnyLayer:
7745 case CompareClearLayer:
7746 case CompareOverlayLayer:
7747 default:
7748 {
cristy8a9106f2011-07-05 14:39:26 +00007749 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007750 break;
7751 }
7752 case MergeLayer:
7753 case FlattenLayer:
7754 case MosaicLayer:
7755 case TrimBoundsLayer:
7756 {
7757 layers=MergeImageLayers(*images,method,exception);
7758 break;
7759 }
7760 case DisposeLayer:
7761 {
7762 layers=DisposeImages(*images,exception);
7763 break;
7764 }
7765 case OptimizeImageLayer:
7766 {
7767 layers=OptimizeImageLayers(*images,exception);
7768 break;
7769 }
7770 case OptimizePlusLayer:
7771 {
7772 layers=OptimizePlusImageLayers(*images,exception);
7773 break;
7774 }
7775 case OptimizeTransLayer:
7776 {
7777 OptimizeImageTransparency(*images,exception);
7778 break;
7779 }
7780 case RemoveDupsLayer:
7781 {
7782 RemoveDuplicateLayers(images,exception);
7783 break;
7784 }
7785 case RemoveZeroLayer:
7786 {
7787 RemoveZeroDelayLayers(images,exception);
7788 break;
7789 }
7790 case OptimizeLayer:
7791 {
7792 /*
7793 General Purpose, GIF Animation Optimizer.
7794 */
7795 layers=CoalesceImages(*images,exception);
7796 if (layers == (Image *) NULL)
7797 {
7798 status=MagickFalse;
7799 break;
7800 }
cristy3ed852e2009-09-05 21:47:34 +00007801 *images=DestroyImageList(*images);
7802 *images=layers;
7803 layers=OptimizeImageLayers(*images,exception);
7804 if (layers == (Image *) NULL)
7805 {
7806 status=MagickFalse;
7807 break;
7808 }
cristy3ed852e2009-09-05 21:47:34 +00007809 *images=DestroyImageList(*images);
7810 *images=layers;
7811 layers=(Image *) NULL;
7812 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007813 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7814 exception);
cristy3ed852e2009-09-05 21:47:34 +00007815 break;
7816 }
7817 case CompositeLayer:
7818 {
7819 CompositeOperator
7820 compose;
7821
7822 Image
7823 *source;
7824
7825 RectangleInfo
7826 geometry;
7827
7828 /*
7829 Split image sequence at the first 'NULL:' image.
7830 */
7831 source=(*images);
7832 while (source != (Image *) NULL)
7833 {
7834 source=GetNextImageInList(source);
7835 if ((source != (Image *) NULL) &&
7836 (LocaleCompare(source->magick,"NULL") == 0))
7837 break;
7838 }
7839 if (source != (Image *) NULL)
7840 {
7841 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7842 (GetNextImageInList(source) == (Image *) NULL))
7843 source=(Image *) NULL;
7844 else
7845 {
7846 /*
7847 Separate the two lists, junk the null: image.
7848 */
7849 source=SplitImageList(source->previous);
7850 DeleteImageFromList(&source);
7851 }
7852 }
7853 if (source == (Image *) NULL)
7854 {
7855 (void) ThrowMagickException(exception,GetMagickModule(),
7856 OptionError,"MissingNullSeparator","layers Composite");
7857 status=MagickFalse;
7858 break;
7859 }
7860 /*
7861 Adjust offset with gravity and virtual canvas.
7862 */
7863 SetGeometry(*images,&geometry);
7864 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7865 geometry.width=source->page.width != 0 ?
7866 source->page.width : source->columns;
7867 geometry.height=source->page.height != 0 ?
7868 source->page.height : source->rows;
7869 GravityAdjustGeometry((*images)->page.width != 0 ?
7870 (*images)->page.width : (*images)->columns,
7871 (*images)->page.height != 0 ? (*images)->page.height :
7872 (*images)->rows,(*images)->gravity,&geometry);
7873 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007874 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007875 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007876 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007877 MagickComposeOptions,MagickFalse,option);
7878 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7879 exception);
7880 source=DestroyImageList(source);
7881 break;
7882 }
7883 }
7884 if (layers == (Image *) NULL)
7885 break;
cristy3ed852e2009-09-05 21:47:34 +00007886 *images=DestroyImageList(*images);
7887 *images=layers;
7888 break;
7889 }
7890 break;
7891 }
7892 case 'm':
7893 {
7894 if (LocaleCompare("map",option+1) == 0)
7895 {
cristy6fccee12011-10-20 18:43:18 +00007896 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007897 if (*option == '+')
7898 {
cristy018f07f2011-09-04 21:15:19 +00007899 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7900 exception);
cristy3ed852e2009-09-05 21:47:34 +00007901 break;
7902 }
7903 i++;
7904 break;
7905 }
cristyf40785b2010-03-06 02:27:27 +00007906 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007907 {
7908 Image
cristyf40785b2010-03-06 02:27:27 +00007909 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007910
cristyd18ae7c2010-03-07 17:39:52 +00007911 /*
7912 Maximum image sequence (deprecated).
7913 */
cristy6fccee12011-10-20 18:43:18 +00007914 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007915 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007916 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007917 {
7918 status=MagickFalse;
7919 break;
7920 }
7921 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007922 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007923 break;
7924 }
cristyf40785b2010-03-06 02:27:27 +00007925 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007926 {
7927 Image
cristyf40785b2010-03-06 02:27:27 +00007928 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007929
cristyd18ae7c2010-03-07 17:39:52 +00007930 /*
7931 Minimum image sequence (deprecated).
7932 */
cristy6fccee12011-10-20 18:43:18 +00007933 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007934 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007935 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007936 {
7937 status=MagickFalse;
7938 break;
7939 }
7940 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007941 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007942 break;
7943 }
cristy3ed852e2009-09-05 21:47:34 +00007944 if (LocaleCompare("morph",option+1) == 0)
7945 {
7946 Image
7947 *morph_image;
7948
cristy6fccee12011-10-20 18:43:18 +00007949 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007950 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007951 exception);
7952 if (morph_image == (Image *) NULL)
7953 {
7954 status=MagickFalse;
7955 break;
7956 }
7957 *images=DestroyImageList(*images);
7958 *images=morph_image;
7959 break;
7960 }
7961 if (LocaleCompare("mosaic",option+1) == 0)
7962 {
7963 Image
7964 *mosaic_image;
7965
cristy6fccee12011-10-20 18:43:18 +00007966 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007967 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7968 if (mosaic_image == (Image *) NULL)
7969 {
7970 status=MagickFalse;
7971 break;
7972 }
7973 *images=DestroyImageList(*images);
7974 *images=mosaic_image;
7975 break;
7976 }
7977 break;
7978 }
7979 case 'p':
7980 {
7981 if (LocaleCompare("print",option+1) == 0)
7982 {
7983 char
7984 *string;
7985
cristy6fccee12011-10-20 18:43:18 +00007986 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007987 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7988 exception);
cristy3ed852e2009-09-05 21:47:34 +00007989 if (string == (char *) NULL)
7990 break;
cristyb51dff52011-05-19 16:55:47 +00007991 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007992 string=DestroyString(string);
7993 }
7994 if (LocaleCompare("process",option+1) == 0)
7995 {
7996 char
7997 **arguments;
7998
7999 int
8000 j,
8001 number_arguments;
8002
cristy6fccee12011-10-20 18:43:18 +00008003 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008004 arguments=StringToArgv(argv[i+1],&number_arguments);
8005 if (arguments == (char **) NULL)
8006 break;
8007 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8008 {
8009 char
8010 breaker,
8011 quote,
8012 *token;
8013
8014 const char
8015 *arguments;
8016
8017 int
8018 next,
8019 status;
8020
8021 size_t
8022 length;
8023
8024 TokenInfo
8025 *token_info;
8026
8027 /*
8028 Support old style syntax, filter="-option arg".
8029 */
8030 length=strlen(argv[i+1]);
8031 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008032 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008033 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8034 sizeof(*token));
8035 if (token == (char *) NULL)
8036 break;
8037 next=0;
8038 arguments=argv[i+1];
8039 token_info=AcquireTokenInfo();
8040 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8041 "\"",'\0',&breaker,&next,&quote);
8042 token_info=DestroyTokenInfo(token_info);
8043 if (status == 0)
8044 {
8045 const char
8046 *argv;
8047
8048 argv=(&(arguments[next]));
8049 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8050 exception);
8051 }
8052 token=DestroyString(token);
8053 break;
8054 }
cristy91c0da22010-05-02 01:44:07 +00008055 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008056 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8057 number_arguments-2,(const char **) arguments+2,exception);
8058 for (j=0; j < number_arguments; j++)
8059 arguments[j]=DestroyString(arguments[j]);
8060 arguments=(char **) RelinquishMagickMemory(arguments);
8061 break;
8062 }
8063 break;
8064 }
8065 case 'r':
8066 {
8067 if (LocaleCompare("reverse",option+1) == 0)
8068 {
8069 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008070 break;
8071 }
8072 break;
8073 }
8074 case 's':
8075 {
cristy4285d782011-02-09 20:12:28 +00008076 if (LocaleCompare("smush",option+1) == 0)
8077 {
8078 Image
8079 *smush_image;
8080
8081 ssize_t
8082 offset;
8083
cristy6fccee12011-10-20 18:43:18 +00008084 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008085 offset=(ssize_t) StringToLong(argv[i+1]);
8086 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8087 MagickFalse,offset,exception);
8088 if (smush_image == (Image *) NULL)
8089 {
8090 status=MagickFalse;
8091 break;
8092 }
8093 *images=DestroyImageList(*images);
8094 *images=smush_image;
8095 break;
8096 }
cristy3ed852e2009-09-05 21:47:34 +00008097 if (LocaleCompare("swap",option+1) == 0)
8098 {
8099 Image
8100 *p,
8101 *q,
8102 *swap;
8103
cristybb503372010-05-27 20:51:26 +00008104 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008105 swap_index;
8106
8107 index=(-1);
8108 swap_index=(-2);
8109 if (*option != '+')
8110 {
8111 GeometryInfo
8112 geometry_info;
8113
8114 MagickStatusType
8115 flags;
8116
8117 swap_index=(-1);
8118 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008119 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008120 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008121 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008122 }
8123 p=GetImageFromList(*images,index);
8124 q=GetImageFromList(*images,swap_index);
8125 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8126 {
8127 (void) ThrowMagickException(exception,GetMagickModule(),
8128 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8129 status=MagickFalse;
8130 break;
8131 }
8132 if (p == q)
8133 break;
8134 swap=CloneImage(p,0,0,MagickTrue,exception);
8135 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8136 ReplaceImageInList(&q,swap);
8137 *images=GetFirstImageInList(q);
8138 break;
8139 }
8140 break;
8141 }
8142 case 'w':
8143 {
8144 if (LocaleCompare("write",option+1) == 0)
8145 {
cristy071dd7b2010-04-09 13:04:54 +00008146 char
cristy06609ee2010-03-17 20:21:27 +00008147 key[MaxTextExtent];
8148
cristy3ed852e2009-09-05 21:47:34 +00008149 Image
8150 *write_images;
8151
8152 ImageInfo
8153 *write_info;
8154
cristy6fccee12011-10-20 18:43:18 +00008155 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008156 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008157 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008158 write_images=(*images);
8159 if (*option == '+')
8160 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008161 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008162 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8163 write_info=DestroyImageInfo(write_info);
8164 if (*option == '+')
8165 write_images=DestroyImageList(write_images);
8166 break;
8167 }
8168 break;
8169 }
8170 default:
8171 break;
8172 }
8173 i+=count;
8174 }
8175 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008176 mogrify_info=DestroyImageInfo(mogrify_info);
8177 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008178 return(status != 0 ? MagickTrue : MagickFalse);
8179}
8180
8181/*
8182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8183% %
8184% %
8185% %
8186+ M o g r i f y I m a g e s %
8187% %
8188% %
8189% %
8190%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8191%
8192% MogrifyImages() applies image processing options to a sequence of images as
8193% prescribed by command line options.
8194%
8195% The format of the MogrifyImage method is:
8196%
8197% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8198% const MagickBooleanType post,const int argc,const char **argv,
8199% Image **images,Exceptioninfo *exception)
8200%
8201% A description of each parameter follows:
8202%
8203% o image_info: the image info..
8204%
8205% o post: If true, post process image list operators otherwise pre-process.
8206%
8207% o argc: Specifies a pointer to an integer describing the number of
8208% elements in the argument vector.
8209%
8210% o argv: Specifies a pointer to a text array containing the command line
8211% arguments.
8212%
anthonye9c27192011-03-27 08:07:06 +00008213% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008214%
8215% o exception: return any errors or warnings in this structure.
8216%
8217*/
8218WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8219 const MagickBooleanType post,const int argc,const char **argv,
8220 Image **images,ExceptionInfo *exception)
8221{
8222#define MogrifyImageTag "Mogrify/Image"
8223
anthonye9c27192011-03-27 08:07:06 +00008224 MagickStatusType
8225 status;
cristy3ed852e2009-09-05 21:47:34 +00008226
cristy0e9f9c12010-02-11 03:00:47 +00008227 MagickBooleanType
8228 proceed;
8229
anthonye9c27192011-03-27 08:07:06 +00008230 size_t
8231 n;
cristy3ed852e2009-09-05 21:47:34 +00008232
cristybb503372010-05-27 20:51:26 +00008233 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008234 i;
8235
cristy3ed852e2009-09-05 21:47:34 +00008236 assert(image_info != (ImageInfo *) NULL);
8237 assert(image_info->signature == MagickSignature);
8238 if (images == (Image **) NULL)
8239 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008240 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008241 assert((*images)->signature == MagickSignature);
8242 if ((*images)->debug != MagickFalse)
8243 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8244 (*images)->filename);
8245 if ((argc <= 0) || (*argv == (char *) NULL))
8246 return(MagickTrue);
8247 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8248 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008249 status=0;
anthonye9c27192011-03-27 08:07:06 +00008250
anthonyce2716b2011-04-22 09:51:34 +00008251#if 0
cristy1e604812011-05-19 18:07:50 +00008252 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8253 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008254#endif
8255
anthonye9c27192011-03-27 08:07:06 +00008256 /*
8257 Pre-process multi-image sequence operators
8258 */
cristy3ed852e2009-09-05 21:47:34 +00008259 if (post == MagickFalse)
8260 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008261 /*
8262 For each image, process simple single image operators
8263 */
8264 i=0;
8265 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008266 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008267 {
anthonyce2716b2011-04-22 09:51:34 +00008268#if 0
cristy1e604812011-05-19 18:07:50 +00008269 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8270 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008271#endif
anthonye9c27192011-03-27 08:07:06 +00008272 status&=MogrifyImage(image_info,argc,argv,images,exception);
8273 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008274 if (proceed == MagickFalse)
8275 break;
anthonye9c27192011-03-27 08:07:06 +00008276 if ( (*images)->next == (Image *) NULL )
8277 break;
8278 *images=(*images)->next;
8279 i++;
cristy3ed852e2009-09-05 21:47:34 +00008280 }
anthonye9c27192011-03-27 08:07:06 +00008281 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008282#if 0
cristy1e604812011-05-19 18:07:50 +00008283 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8284 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008285#endif
anthonye9c27192011-03-27 08:07:06 +00008286
8287 /*
8288 Post-process, multi-image sequence operators
8289 */
8290 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008291 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008292 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008293 return(status != 0 ? MagickTrue : MagickFalse);
8294}