blob: 2ffbc07ac8f6fa16011d5c38ad762508916ed8d9 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
cristy4c08aed2011-07-01 19:47:50 +000054#include "MagickCore/string-private.h"
cristy0740a982011-10-13 15:01:01 +000055#include "MagickCore/thread-private.h"
cristy18c6c272011-09-23 14:40:37 +000056#include "MagickCore/utility-private.h"
cristy3ed852e2009-09-05 21:47:34 +000057
58/*
cristy154fa9d2011-08-05 14:25:15 +000059 Constant declaration.
60*/
cristy3a557c02011-08-06 19:48:02 +000061static const char
cristy638895a2011-08-06 23:19:14 +000062 MogrifyBackgroundColor[] = "#ffffff", /* white */
63 MogrifyBorderColor[] = "#dfdfdf", /* gray */
64 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000065
66/*
cristy3ed852e2009-09-05 21:47:34 +000067 Define declarations.
68*/
69#define UndefinedCompressionQuality 0UL
70
71/*
cristy3ed852e2009-09-05 21:47:34 +000072%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73% %
74% %
75% %
cristy5063d812010-10-19 16:28:10 +000076% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000077% %
78% %
79% %
80%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81%
82% MagickCommandGenesis() applies image processing options to an image as
83% prescribed by command line options.
84%
85% The format of the MagickCommandGenesis method is:
86%
87% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000088% MagickCommand command,int argc,char **argv,char **metadata,
89% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000090%
91% A description of each parameter follows:
92%
93% o image_info: the image info.
94%
cristy5063d812010-10-19 16:28:10 +000095% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000096% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000097% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
98% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000099%
100% o argc: Specifies a pointer to an integer describing the number of
101% elements in the argument vector.
102%
103% o argv: Specifies a pointer to a text array containing the command line
104% arguments.
105%
cristy5063d812010-10-19 16:28:10 +0000106% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000107%
108% o exception: return any errors or warnings in this structure.
109%
110*/
111WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
112 MagickCommand command,int argc,char **argv,char **metadata,
113 ExceptionInfo *exception)
114{
115 char
116 *option;
117
118 double
119 duration,
cristy8ea926d2011-12-09 12:25:04 +0000120 serial;
cristy3980b0d2009-10-25 14:37:13 +0000121
cristy3980b0d2009-10-25 14:37:13 +0000122 MagickBooleanType
123 concurrent,
124 regard_warnings,
125 status;
126
cristybb503372010-05-27 20:51:26 +0000127 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000128 i;
129
cristybb503372010-05-27 20:51:26 +0000130 size_t
cristyc2e3aeb2011-12-09 11:09:38 +0000131 iterations,
cristyc2e3aeb2011-12-09 11:09:38 +0000132 number_threads;
cristy3980b0d2009-10-25 14:37:13 +0000133
cristy118fc662012-02-11 00:02:25 +0000134 ssize_t
135 n;
136
cristyd0a94fa2010-03-12 14:18:11 +0000137 (void) setlocale(LC_ALL,"");
138 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000139 concurrent=MagickFalse;
140 duration=(-1.0);
141 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000142 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000143 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000144 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000145 {
146 option=argv[i];
147 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
148 continue;
149 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000150 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000151 if (LocaleCompare("concurrent",option+1) == 0)
152 concurrent=MagickTrue;
153 if (LocaleCompare("debug",option+1) == 0)
154 (void) SetLogEventMask(argv[++i]);
155 if (LocaleCompare("duration",option+1) == 0)
cristydbdd0e32011-11-04 23:29:40 +0000156 duration=StringToDouble(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000157 if (LocaleCompare("regard-warnings",option+1) == 0)
158 regard_warnings=MagickTrue;
159 }
cristy8ea926d2011-12-09 12:25:04 +0000160 if (iterations == 1)
161 {
162 status=command(image_info,argc,argv,metadata,exception);
163 if (exception->severity != UndefinedException)
164 {
165 if ((exception->severity > ErrorException) ||
166 (regard_warnings != MagickFalse))
167 status=MagickTrue;
168 CatchException(exception);
169 }
170 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
171 {
172 (void) fputs(*metadata,stdout);
173 (void) fputc('\n',stdout);
174 *metadata=DestroyString(*metadata);
175 }
176 return(status);
177 }
cristyc2e3aeb2011-12-09 11:09:38 +0000178 number_threads=GetOpenMPMaximumThreads();
cristy8ea926d2011-12-09 12:25:04 +0000179 serial=0.0;
cristy118fc662012-02-11 00:02:25 +0000180 for (n=1; n <= (ssize_t) number_threads; n++)
cristyc2e3aeb2011-12-09 11:09:38 +0000181 {
182 double
cristy8ea926d2011-12-09 12:25:04 +0000183 e,
184 parallel,
cristyc2e3aeb2011-12-09 11:09:38 +0000185 user_time;
186
187 TimerInfo
188 *timer;
189
cristy118fc662012-02-11 00:02:25 +0000190 SetOpenMPMaximumThreads((int) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000191 timer=AcquireTimerInfo();
192 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000193 {
cristyc2e3aeb2011-12-09 11:09:38 +0000194 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000195 {
cristyc2e3aeb2011-12-09 11:09:38 +0000196 if (status != MagickFalse)
197 continue;
198 if (duration > 0)
199 {
200 if (GetElapsedTime(timer) > duration)
201 continue;
202 (void) ContinueTimer(timer);
203 }
204 status=command(image_info,argc,argv,metadata,exception);
cristyceae09d2009-10-28 17:18:47 +0000205 if (exception->severity != UndefinedException)
206 {
207 if ((exception->severity > ErrorException) ||
208 (regard_warnings != MagickFalse))
209 status=MagickTrue;
210 CatchException(exception);
211 }
212 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
213 {
214 (void) fputs(*metadata,stdout);
215 (void) fputc('\n',stdout);
216 *metadata=DestroyString(*metadata);
217 }
218 }
219 }
cristyc2e3aeb2011-12-09 11:09:38 +0000220 else
221 {
222 SetOpenMPNested(1);
223#if defined(MAGICKCORE_OPENMP_SUPPORT)
224 # pragma omp parallel for shared(status)
225#endif
226 for (i=0; i < (ssize_t) iterations; i++)
227 {
228 if (status != MagickFalse)
229 continue;
230 if (duration > 0)
231 {
232 if (GetElapsedTime(timer) > duration)
233 continue;
234 (void) ContinueTimer(timer);
235 }
236 status=command(image_info,argc,argv,metadata,exception);
237#if defined(MAGICKCORE_OPENMP_SUPPORT)
238 # pragma omp critical (MagickCore_CommandGenesis)
239#endif
240 {
241 if (exception->severity != UndefinedException)
242 {
243 if ((exception->severity > ErrorException) ||
244 (regard_warnings != MagickFalse))
245 status=MagickTrue;
246 CatchException(exception);
247 }
248 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
249 {
250 (void) fputs(*metadata,stdout);
251 (void) fputc('\n',stdout);
252 *metadata=DestroyString(*metadata);
253 }
254 }
255 }
256 }
cristyc2e3aeb2011-12-09 11:09:38 +0000257 user_time=GetUserTime(timer);
cristy8ea926d2011-12-09 12:25:04 +0000258 parallel=GetElapsedTime(timer);
259 e=1.0;
260 if (n == 1)
261 serial=parallel;
262 else
263 e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
264 (double) n)))-(1.0/(double) n))/(1.0-1.0/(double) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000265 (void) FormatLocaleFile(stderr,
cristy91ce84d2011-12-09 23:02:25 +0000266 "Performance[%.20g]: %.20gi %0.3fips %0.3fe %0.3fu %lu:%02lu.%03lu\n",
cristy8ea926d2011-12-09 12:25:04 +0000267 (double) n,(double) iterations,(double) iterations/parallel,e,
268 user_time,(unsigned long) (parallel/60.0),(unsigned long)
269 floor(fmod(parallel,60.0)),(unsigned long)
270 (1000.0*(parallel-floor(parallel))+0.5));
cristyc2e3aeb2011-12-09 11:09:38 +0000271 timer=DestroyTimerInfo(timer);
272 }
cristy1f9e1ed2009-11-18 04:09:38 +0000273 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000274}
275
276/*
277%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278% %
279% %
280% %
cristy3ed852e2009-09-05 21:47:34 +0000281+ M o g r i f y I m a g e %
282% %
283% %
284% %
285%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286%
anthonye9c27192011-03-27 08:07:06 +0000287% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000288% image that may be part of a large list, but also handles any 'region'
289% image handling.
anthonye9c27192011-03-27 08:07:06 +0000290%
291% The image in the list may be modified in three different ways...
292%
293% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
294% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
295% * replace by a list of images (only the -separate option!)
296%
297% In each case the result is returned into the list, and a pointer to the
298% modified image (last image added if replaced by a list of images) is
299% returned.
300%
301% ASIDE: The -crop is present but restricted to non-tile single image crops
302%
303% This means if all the images are being processed (such as by
304% MogrifyImages(), next image to be processed will be as per the pointer
305% (*image)->next. Also the image list may grow as a result of some specific
306% operations but as images are never merged or deleted, it will never shrink
307% in length. Typically the list will remain the same length.
308%
309% WARNING: As the image pointed to may be replaced, the first image in the
310% list may also change. GetFirstImageInList() should be used by caller if
311% they wish return the Image pointer to the first image in list.
312%
cristy3ed852e2009-09-05 21:47:34 +0000313%
314% The format of the MogrifyImage method is:
315%
316% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
317% const char **argv,Image **image)
318%
319% A description of each parameter follows:
320%
321% o image_info: the image info..
322%
323% o argc: Specifies a pointer to an integer describing the number of
324% elements in the argument vector.
325%
326% o argv: Specifies a pointer to a text array containing the command line
327% arguments.
328%
329% o image: the image.
330%
331% o exception: return any errors or warnings in this structure.
332%
333*/
334
anthonydf8ebac2011-04-27 09:03:19 +0000335static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
336 ExceptionInfo *exception)
337{
338 char
339 key[MaxTextExtent];
340
341 ExceptionInfo
342 *sans_exception;
343
344 Image
345 *image;
346
347 ImageInfo
348 *read_info;
349
cristyfcd785b2011-11-08 01:48:33 +0000350 /*
anthony32d85bf2012-02-15 14:54:59 +0000351 Read an image into a image cache (for repeated usage) if not already in
352 cache. Then return the image that is in the cache.
cristyfcd785b2011-11-08 01:48:33 +0000353 */
cristyb51dff52011-05-19 16:55:47 +0000354 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000355 sans_exception=AcquireExceptionInfo();
356 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
357 sans_exception=DestroyExceptionInfo(sans_exception);
358 if (image != (Image *) NULL)
359 return(image);
360 read_info=CloneImageInfo(image_info);
361 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
362 image=ReadImage(read_info,exception);
363 read_info=DestroyImageInfo(read_info);
364 if (image != (Image *) NULL)
365 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
366 return(image);
367}
368
cristy3ed852e2009-09-05 21:47:34 +0000369static MagickBooleanType IsPathWritable(const char *path)
370{
371 if (IsPathAccessible(path) == MagickFalse)
372 return(MagickFalse);
cristy18c6c272011-09-23 14:40:37 +0000373 if (access_utf8(path,W_OK) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000374 return(MagickFalse);
375 return(MagickTrue);
376}
377
cristybb503372010-05-27 20:51:26 +0000378static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000379{
380 if (x > y)
381 return(x);
382 return(y);
383}
384
anthonydf8ebac2011-04-27 09:03:19 +0000385static MagickBooleanType MonitorProgress(const char *text,
386 const MagickOffsetType offset,const MagickSizeType extent,
387 void *wand_unused(client_data))
388{
389 char
390 message[MaxTextExtent],
391 tag[MaxTextExtent];
392
393 const char
394 *locale_message;
395
396 register char
397 *p;
398
399 if (extent < 2)
400 return(MagickTrue);
401 (void) CopyMagickMemory(tag,text,MaxTextExtent);
402 p=strrchr(tag,'/');
403 if (p != (char *) NULL)
404 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000405 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000406 locale_message=GetLocaleMessage(message);
407 if (locale_message == message)
408 locale_message=tag;
409 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000410 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
411 locale_message,(long) offset,(unsigned long) extent,(long)
412 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000413 else
cristyb51dff52011-05-19 16:55:47 +0000414 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000415 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
416 (100L*offset/(extent-1)));
417 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000418 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000419 (void) fflush(stderr);
420 return(MagickTrue);
421}
422
cristy3884f692011-07-08 18:00:18 +0000423static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000424 const SparseColorMethod method,const char *arguments,
425 const MagickBooleanType color_from_image,ExceptionInfo *exception)
426{
anthonydf8ebac2011-04-27 09:03:19 +0000427 char
428 token[MaxTextExtent];
429
430 const char
431 *p;
432
433 double
434 *sparse_arguments;
435
anthonydf8ebac2011-04-27 09:03:19 +0000436 Image
437 *sparse_image;
438
cristy4c08aed2011-07-01 19:47:50 +0000439 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000440 color;
441
442 MagickBooleanType
443 error;
444
cristy5f09d852011-05-29 01:39:29 +0000445 register size_t
446 x;
447
448 size_t
449 number_arguments,
450 number_colors;
451
cristyf4425a72011-11-08 01:52:04 +0000452 /*
453 SparseColorOption() parses the complex -sparse-color argument into an an
454 array of floating point values then calls SparseColorImage(). Argument is
455 a complex mix of floating-point pixel coodinates, and color specifications
456 (or direct floating point numbers). The number of floats needed to
457 represent a color varies depending on the current channel setting.
458 */
anthonydf8ebac2011-04-27 09:03:19 +0000459 assert(image != (Image *) NULL);
460 assert(image->signature == MagickSignature);
461 if (image->debug != MagickFalse)
462 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
463 assert(exception != (ExceptionInfo *) NULL);
464 assert(exception->signature == MagickSignature);
465 /*
466 Limit channels according to image - and add up number of color channel.
467 */
anthonydf8ebac2011-04-27 09:03:19 +0000468 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000469 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000470 number_colors++;
cristyed231572011-07-14 02:18:59 +0000471 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000472 number_colors++;
cristyed231572011-07-14 02:18:59 +0000473 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000474 number_colors++;
cristyed231572011-07-14 02:18:59 +0000475 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000476 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000477 number_colors++;
cristyed231572011-07-14 02:18:59 +0000478 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000479 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000480 number_colors++;
481
482 /*
483 Read string, to determine number of arguments needed,
484 */
485 p=arguments;
486 x=0;
487 while( *p != '\0' )
488 {
489 GetMagickToken(p,&p,token);
490 if ( token[0] == ',' ) continue;
491 if ( isalpha((int) token[0]) || token[0] == '#' ) {
492 if ( color_from_image ) {
493 (void) ThrowMagickException(exception,GetMagickModule(),
494 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
495 "Color arg given, when colors are coming from image");
496 return( (Image *)NULL);
497 }
498 x += number_colors; /* color argument */
499 }
500 else {
501 x++; /* floating point argument */
502 }
503 }
504 error=MagickTrue;
505 if ( color_from_image ) {
506 /* just the control points are being given */
507 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
508 number_arguments=(x/2)*(2+number_colors);
509 }
510 else {
511 /* control points and color values */
512 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
513 number_arguments=x;
514 }
515 if ( error ) {
516 (void) ThrowMagickException(exception,GetMagickModule(),
517 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
518 "Invalid number of Arguments");
519 return( (Image *)NULL);
520 }
521
522 /* Allocate and fill in the floating point arguments */
523 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
524 sizeof(*sparse_arguments));
525 if (sparse_arguments == (double *) NULL) {
526 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
527 "MemoryAllocationFailed","%s","SparseColorOption");
528 return( (Image *)NULL);
529 }
530 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
531 sizeof(*sparse_arguments));
532 p=arguments;
533 x=0;
534 while( *p != '\0' && x < number_arguments ) {
535 /* X coordinate */
536 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
537 if ( token[0] == '\0' ) break;
538 if ( isalpha((int) token[0]) || token[0] == '#' ) {
539 (void) ThrowMagickException(exception,GetMagickModule(),
540 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
541 "Color found, instead of X-coord");
542 error = MagickTrue;
543 break;
544 }
cristydbdd0e32011-11-04 23:29:40 +0000545 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000546 /* Y coordinate */
547 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
548 if ( token[0] == '\0' ) break;
549 if ( isalpha((int) token[0]) || token[0] == '#' ) {
550 (void) ThrowMagickException(exception,GetMagickModule(),
551 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
552 "Color found, instead of Y-coord");
553 error = MagickTrue;
554 break;
555 }
cristydbdd0e32011-11-04 23:29:40 +0000556 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000557 /* color values for this control point */
558#if 0
559 if ( (color_from_image ) {
560 /* get color from image */
561 /* HOW??? */
562 }
563 else
564#endif
565 {
566 /* color name or function given in string argument */
567 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
568 if ( token[0] == '\0' ) break;
569 if ( isalpha((int) token[0]) || token[0] == '#' ) {
570 /* Color string given */
cristy269c9412011-10-13 23:41:15 +0000571 (void) QueryColorCompliance(token,AllCompliance,&color,exception);
cristyed231572011-07-14 02:18:59 +0000572 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000573 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000574 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000575 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000576 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000577 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000578 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000579 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000580 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000581 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000582 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000583 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000584 }
585 else {
586 /* Colors given as a set of floating point values - experimental */
587 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000588 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000589 {
anthonydf8ebac2011-04-27 09:03:19 +0000590 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
591 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
592 break;
cristydbdd0e32011-11-04 23:29:40 +0000593 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000594 token[0] = ','; /* used this token - get another */
595 }
cristyed231572011-07-14 02:18:59 +0000596 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000597 {
anthonydf8ebac2011-04-27 09:03:19 +0000598 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
599 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
600 break;
cristydbdd0e32011-11-04 23:29:40 +0000601 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000602 token[0] = ','; /* used this token - get another */
603 }
cristyed231572011-07-14 02:18:59 +0000604 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000605 {
anthonydf8ebac2011-04-27 09:03:19 +0000606 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
607 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
608 break;
cristydbdd0e32011-11-04 23:29:40 +0000609 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000610 token[0] = ','; /* used this token - get another */
611 }
cristyed231572011-07-14 02:18:59 +0000612 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000613 (image->colorspace == CMYKColorspace))
614 {
anthonydf8ebac2011-04-27 09:03:19 +0000615 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
616 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
617 break;
cristydbdd0e32011-11-04 23:29:40 +0000618 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000619 token[0] = ','; /* used this token - get another */
620 }
cristyed231572011-07-14 02:18:59 +0000621 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000622 (image->matte != MagickFalse))
623 {
anthonydf8ebac2011-04-27 09:03:19 +0000624 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
625 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
626 break;
cristydbdd0e32011-11-04 23:29:40 +0000627 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000628 token[0] = ','; /* used this token - get another */
629 }
630 }
631 }
632 }
633 if ( number_arguments != x && !error ) {
634 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
635 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
636 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
637 return( (Image *)NULL);
638 }
639 if ( error )
640 return( (Image *)NULL);
641
642 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000643 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
644 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000645 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
646 return( sparse_image );
647}
648
cristy3ed852e2009-09-05 21:47:34 +0000649WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
650 const char **argv,Image **image,ExceptionInfo *exception)
651{
cristy633f0c62011-09-15 13:27:36 +0000652 CompositeOperator
653 compose;
654
anthonydf8ebac2011-04-27 09:03:19 +0000655 const char
656 *format,
657 *option;
658
cristy9ed1f812011-10-08 02:00:08 +0000659 double
660 attenuate;
661
anthonydf8ebac2011-04-27 09:03:19 +0000662 DrawInfo
663 *draw_info;
664
665 GeometryInfo
666 geometry_info;
667
cristy3ed852e2009-09-05 21:47:34 +0000668 Image
669 *region_image;
670
anthonydf8ebac2011-04-27 09:03:19 +0000671 ImageInfo
672 *mogrify_info;
673
cristyebbcfea2011-02-25 02:43:54 +0000674 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000675 status;
676
cristy4c08aed2011-07-01 19:47:50 +0000677 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000678 fill;
cristy3ed852e2009-09-05 21:47:34 +0000679
anthonydf8ebac2011-04-27 09:03:19 +0000680 MagickStatusType
681 flags;
682
cristy28474bf2011-09-11 23:32:52 +0000683 PixelInterpolateMethod
684 interpolate_method;
685
anthonydf8ebac2011-04-27 09:03:19 +0000686 QuantizeInfo
687 *quantize_info;
688
689 RectangleInfo
690 geometry,
691 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000692
cristybb503372010-05-27 20:51:26 +0000693 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000694 i;
695
696 /*
697 Initialize method variables.
698 */
699 assert(image_info != (const ImageInfo *) NULL);
700 assert(image_info->signature == MagickSignature);
701 assert(image != (Image **) NULL);
702 assert((*image)->signature == MagickSignature);
703 if ((*image)->debug != MagickFalse)
704 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
705 if (argc < 0)
706 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000707 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000708 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
709 quantize_info=AcquireQuantizeInfo(mogrify_info);
710 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000711 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000712 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000713 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000714 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000715 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000716 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000717 SetGeometry(*image,&region_geometry);
718 region_image=NewImageList();
719 /*
720 Transmogrify the image.
721 */
cristybb503372010-05-27 20:51:26 +0000722 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000723 {
anthonydf8ebac2011-04-27 09:03:19 +0000724 Image
725 *mogrify_image;
726
anthonye9c27192011-03-27 08:07:06 +0000727 ssize_t
728 count;
729
anthonydf8ebac2011-04-27 09:03:19 +0000730 option=argv[i];
731 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000732 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000733 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
734 0L);
cristycee97112010-05-28 00:44:52 +0000735 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000736 break;
cristy6b3da3a2010-06-20 02:21:46 +0000737 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000738 mogrify_image=(Image *)NULL;
739 switch (*(option+1))
740 {
741 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000742 {
anthonydf8ebac2011-04-27 09:03:19 +0000743 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000744 {
anthonydf8ebac2011-04-27 09:03:19 +0000745 /*
746 Adaptive blur image.
747 */
cristy6fccee12011-10-20 18:43:18 +0000748 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000749 flags=ParseGeometry(argv[i+1],&geometry_info);
750 if ((flags & SigmaValue) == 0)
751 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000752 if ((flags & XiValue) == 0)
753 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000754 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000755 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000756 break;
cristy3ed852e2009-09-05 21:47:34 +0000757 }
anthonydf8ebac2011-04-27 09:03:19 +0000758 if (LocaleCompare("adaptive-resize",option+1) == 0)
759 {
760 /*
761 Adaptive resize image.
762 */
cristy6fccee12011-10-20 18:43:18 +0000763 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000764 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
765 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
anthonyfd706f92012-01-19 04:22:02 +0000766 geometry.height,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000767 break;
768 }
769 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
770 {
771 /*
772 Adaptive sharpen image.
773 */
cristy6fccee12011-10-20 18:43:18 +0000774 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000775 flags=ParseGeometry(argv[i+1],&geometry_info);
776 if ((flags & SigmaValue) == 0)
777 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000778 if ((flags & XiValue) == 0)
779 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000780 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000781 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000782 break;
783 }
784 if (LocaleCompare("affine",option+1) == 0)
785 {
786 /*
787 Affine matrix.
788 */
789 if (*option == '+')
790 {
791 GetAffineMatrix(&draw_info->affine);
792 break;
793 }
794 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
795 break;
796 }
797 if (LocaleCompare("alpha",option+1) == 0)
798 {
799 AlphaChannelType
800 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000801
cristy6fccee12011-10-20 18:43:18 +0000802 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000803 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
804 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000805 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000806 break;
807 }
808 if (LocaleCompare("annotate",option+1) == 0)
809 {
810 char
811 *text,
812 geometry[MaxTextExtent];
813
814 /*
815 Annotate image.
816 */
cristy6fccee12011-10-20 18:43:18 +0000817 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000818 SetGeometryInfo(&geometry_info);
819 flags=ParseGeometry(argv[i+1],&geometry_info);
820 if ((flags & SigmaValue) == 0)
821 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000822 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
823 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000824 if (text == (char *) NULL)
825 break;
826 (void) CloneString(&draw_info->text,text);
827 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000828 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000829 geometry_info.xi,geometry_info.psi);
830 (void) CloneString(&draw_info->geometry,geometry);
831 draw_info->affine.sx=cos(DegreesToRadians(
832 fmod(geometry_info.rho,360.0)));
833 draw_info->affine.rx=sin(DegreesToRadians(
834 fmod(geometry_info.rho,360.0)));
835 draw_info->affine.ry=(-sin(DegreesToRadians(
836 fmod(geometry_info.sigma,360.0))));
837 draw_info->affine.sy=cos(DegreesToRadians(
838 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000839 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000840 break;
841 }
842 if (LocaleCompare("antialias",option+1) == 0)
843 {
844 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
845 MagickFalse;
846 draw_info->text_antialias=(*option == '-') ? MagickTrue :
847 MagickFalse;
848 break;
849 }
cristy9ed1f812011-10-08 02:00:08 +0000850 if (LocaleCompare("attenuate",option+1) == 0)
851 {
852 if (*option == '+')
853 {
854 attenuate=1.0;
855 break;
856 }
cristydbdd0e32011-11-04 23:29:40 +0000857 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000858 break;
859 }
anthonydf8ebac2011-04-27 09:03:19 +0000860 if (LocaleCompare("auto-gamma",option+1) == 0)
861 {
862 /*
863 Auto Adjust Gamma of image based on its mean
864 */
cristy6fccee12011-10-20 18:43:18 +0000865 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000866 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000867 break;
868 }
869 if (LocaleCompare("auto-level",option+1) == 0)
870 {
871 /*
872 Perfectly Normalize (max/min stretch) the image
873 */
cristy6fccee12011-10-20 18:43:18 +0000874 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000875 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000876 break;
877 }
878 if (LocaleCompare("auto-orient",option+1) == 0)
879 {
cristy6fccee12011-10-20 18:43:18 +0000880 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000881 switch ((*image)->orientation)
882 {
883 case TopRightOrientation:
884 {
885 mogrify_image=FlopImage(*image,exception);
886 break;
887 }
888 case BottomRightOrientation:
889 {
890 mogrify_image=RotateImage(*image,180.0,exception);
891 break;
892 }
893 case BottomLeftOrientation:
894 {
895 mogrify_image=FlipImage(*image,exception);
896 break;
897 }
898 case LeftTopOrientation:
899 {
900 mogrify_image=TransposeImage(*image,exception);
901 break;
902 }
903 case RightTopOrientation:
904 {
905 mogrify_image=RotateImage(*image,90.0,exception);
906 break;
907 }
908 case RightBottomOrientation:
909 {
910 mogrify_image=TransverseImage(*image,exception);
911 break;
912 }
913 case LeftBottomOrientation:
914 {
915 mogrify_image=RotateImage(*image,270.0,exception);
916 break;
917 }
918 default:
919 break;
920 }
921 if (mogrify_image != (Image *) NULL)
922 mogrify_image->orientation=TopLeftOrientation;
923 break;
924 }
925 break;
926 }
927 case 'b':
928 {
929 if (LocaleCompare("black-threshold",option+1) == 0)
930 {
931 /*
932 Black threshold image.
933 */
cristy6fccee12011-10-20 18:43:18 +0000934 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000935 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000936 break;
937 }
938 if (LocaleCompare("blue-shift",option+1) == 0)
939 {
940 /*
941 Blue shift image.
942 */
cristy6fccee12011-10-20 18:43:18 +0000943 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000944 geometry_info.rho=1.5;
945 if (*option == '-')
946 flags=ParseGeometry(argv[i+1],&geometry_info);
947 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
948 break;
949 }
950 if (LocaleCompare("blur",option+1) == 0)
951 {
952 /*
953 Gaussian blur image.
954 */
cristy6fccee12011-10-20 18:43:18 +0000955 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000956 flags=ParseGeometry(argv[i+1],&geometry_info);
957 if ((flags & SigmaValue) == 0)
958 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000959 if ((flags & XiValue) == 0)
960 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000961 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000962 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000963 break;
964 }
965 if (LocaleCompare("border",option+1) == 0)
966 {
967 /*
968 Surround image with a border of solid color.
969 */
cristy6fccee12011-10-20 18:43:18 +0000970 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000971 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
972 if ((flags & SigmaValue) == 0)
973 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000974 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000975 break;
976 }
977 if (LocaleCompare("bordercolor",option+1) == 0)
978 {
979 if (*option == '+')
980 {
cristy9950d572011-10-01 18:22:35 +0000981 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000982 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000983 break;
984 }
cristy9950d572011-10-01 18:22:35 +0000985 (void) QueryColorCompliance(argv[i+1],AllCompliance,
986 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000987 break;
988 }
989 if (LocaleCompare("box",option+1) == 0)
990 {
cristy9950d572011-10-01 18:22:35 +0000991 (void) QueryColorCompliance(argv[i+1],AllCompliance,
992 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000993 break;
994 }
995 if (LocaleCompare("brightness-contrast",option+1) == 0)
996 {
997 double
998 brightness,
999 contrast;
1000
1001 GeometryInfo
1002 geometry_info;
1003
1004 MagickStatusType
1005 flags;
1006
1007 /*
1008 Brightness / contrast image.
1009 */
cristy6fccee12011-10-20 18:43:18 +00001010 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001011 flags=ParseGeometry(argv[i+1],&geometry_info);
1012 brightness=geometry_info.rho;
1013 contrast=0.0;
1014 if ((flags & SigmaValue) != 0)
1015 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +00001016 (void) BrightnessContrastImage(*image,brightness,contrast,
1017 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001018 break;
1019 }
1020 break;
1021 }
1022 case 'c':
1023 {
1024 if (LocaleCompare("cdl",option+1) == 0)
1025 {
1026 char
1027 *color_correction_collection;
1028
1029 /*
1030 Color correct with a color decision list.
1031 */
cristy6fccee12011-10-20 18:43:18 +00001032 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001033 color_correction_collection=FileToString(argv[i+1],~0,exception);
1034 if (color_correction_collection == (char *) NULL)
1035 break;
cristy1bfa9f02011-08-11 02:35:43 +00001036 (void) ColorDecisionListImage(*image,color_correction_collection,
1037 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001038 break;
1039 }
anthonydf8ebac2011-04-27 09:03:19 +00001040 if (LocaleCompare("charcoal",option+1) == 0)
1041 {
1042 /*
1043 Charcoal image.
1044 */
cristy6fccee12011-10-20 18:43:18 +00001045 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001046 flags=ParseGeometry(argv[i+1],&geometry_info);
1047 if ((flags & SigmaValue) == 0)
1048 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001049 if ((flags & XiValue) == 0)
1050 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001051 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001052 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001053 break;
1054 }
1055 if (LocaleCompare("chop",option+1) == 0)
1056 {
1057 /*
1058 Chop the image.
1059 */
cristy6fccee12011-10-20 18:43:18 +00001060 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001061 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1062 mogrify_image=ChopImage(*image,&geometry,exception);
1063 break;
1064 }
1065 if (LocaleCompare("clamp",option+1) == 0)
1066 {
1067 /*
1068 Clamp image.
1069 */
cristy6fccee12011-10-20 18:43:18 +00001070 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001071 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001072 break;
1073 }
1074 if (LocaleCompare("clip",option+1) == 0)
1075 {
cristy6fccee12011-10-20 18:43:18 +00001076 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001077 if (*option == '+')
1078 {
cristy10a6c612012-01-29 21:41:05 +00001079 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001080 break;
1081 }
cristy018f07f2011-09-04 21:15:19 +00001082 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001083 break;
1084 }
1085 if (LocaleCompare("clip-mask",option+1) == 0)
1086 {
1087 CacheView
1088 *mask_view;
1089
1090 Image
1091 *mask_image;
1092
cristy4c08aed2011-07-01 19:47:50 +00001093 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001094 *restrict q;
1095
1096 register ssize_t
1097 x;
1098
1099 ssize_t
1100 y;
1101
cristy6fccee12011-10-20 18:43:18 +00001102 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001103 if (*option == '+')
1104 {
1105 /*
1106 Remove a mask.
1107 */
cristy018f07f2011-09-04 21:15:19 +00001108 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001109 break;
1110 }
1111 /*
1112 Set the image mask.
1113 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1114 */
1115 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1116 if (mask_image == (Image *) NULL)
1117 break;
cristy574cc262011-08-05 01:23:58 +00001118 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001119 return(MagickFalse);
1120 mask_view=AcquireCacheView(mask_image);
1121 for (y=0; y < (ssize_t) mask_image->rows; y++)
1122 {
1123 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1124 exception);
cristyacd2ed22011-08-30 01:44:23 +00001125 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001126 break;
1127 for (x=0; x < (ssize_t) mask_image->columns; x++)
1128 {
1129 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001130 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1131 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1132 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1133 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001134 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001135 }
1136 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1137 break;
1138 }
1139 mask_view=DestroyCacheView(mask_view);
1140 mask_image->matte=MagickTrue;
cristy10a6c612012-01-29 21:41:05 +00001141 (void) SetImageMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001142 break;
1143 }
1144 if (LocaleCompare("clip-path",option+1) == 0)
1145 {
cristy6fccee12011-10-20 18:43:18 +00001146 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001147 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001148 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001149 break;
1150 }
1151 if (LocaleCompare("colorize",option+1) == 0)
1152 {
1153 /*
1154 Colorize the image.
1155 */
cristy6fccee12011-10-20 18:43:18 +00001156 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001157 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001158 break;
1159 }
1160 if (LocaleCompare("color-matrix",option+1) == 0)
1161 {
1162 KernelInfo
1163 *kernel;
1164
cristy6fccee12011-10-20 18:43:18 +00001165 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001166 kernel=AcquireKernelInfo(argv[i+1]);
1167 if (kernel == (KernelInfo *) NULL)
1168 break;
anthonyfd706f92012-01-19 04:22:02 +00001169 /* FUTURE: check on size of the matrix */
anthonydf8ebac2011-04-27 09:03:19 +00001170 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1171 kernel=DestroyKernelInfo(kernel);
1172 break;
1173 }
1174 if (LocaleCompare("colors",option+1) == 0)
1175 {
1176 /*
1177 Reduce the number of colors in the image.
1178 */
cristy6fccee12011-10-20 18:43:18 +00001179 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001180 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1181 if (quantize_info->number_colors == 0)
1182 break;
1183 if (((*image)->storage_class == DirectClass) ||
1184 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001185 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001186 else
cristy018f07f2011-09-04 21:15:19 +00001187 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001188 break;
1189 }
1190 if (LocaleCompare("colorspace",option+1) == 0)
1191 {
1192 ColorspaceType
1193 colorspace;
1194
cristy6fccee12011-10-20 18:43:18 +00001195 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001196 if (*option == '+')
1197 {
cristye941a752011-10-15 01:52:48 +00001198 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001199 break;
1200 }
1201 colorspace=(ColorspaceType) ParseCommandOption(
1202 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001203 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001204 break;
1205 }
cristy633f0c62011-09-15 13:27:36 +00001206 if (LocaleCompare("compose",option+1) == 0)
1207 {
cristy6fccee12011-10-20 18:43:18 +00001208 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001209 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1210 MagickFalse,argv[i+1]);
1211 break;
1212 }
anthonydf8ebac2011-04-27 09:03:19 +00001213 if (LocaleCompare("contrast",option+1) == 0)
1214 {
cristy6fccee12011-10-20 18:43:18 +00001215 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001216 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001217 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001218 break;
1219 }
1220 if (LocaleCompare("contrast-stretch",option+1) == 0)
1221 {
1222 double
1223 black_point,
1224 white_point;
1225
1226 MagickStatusType
1227 flags;
1228
1229 /*
1230 Contrast stretch image.
1231 */
cristy6fccee12011-10-20 18:43:18 +00001232 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001233 flags=ParseGeometry(argv[i+1],&geometry_info);
1234 black_point=geometry_info.rho;
1235 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1236 black_point;
1237 if ((flags & PercentValue) != 0)
1238 {
1239 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1240 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1241 }
1242 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1243 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001244 (void) ContrastStretchImage(*image,black_point,white_point,
1245 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001246 break;
1247 }
1248 if (LocaleCompare("convolve",option+1) == 0)
1249 {
anthonydf8ebac2011-04-27 09:03:19 +00001250 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001251 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001252
cristy6fccee12011-10-20 18:43:18 +00001253 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001254 kernel_info=AcquireKernelInfo(argv[i+1]);
1255 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001256 break;
cristy0a922382011-07-16 15:30:34 +00001257 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001258 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001259 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001260 break;
1261 }
1262 if (LocaleCompare("crop",option+1) == 0)
1263 {
1264 /*
1265 Crop a image to a smaller size
1266 */
cristy6fccee12011-10-20 18:43:18 +00001267 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001268 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001269 break;
1270 }
1271 if (LocaleCompare("cycle",option+1) == 0)
1272 {
1273 /*
1274 Cycle an image colormap.
1275 */
cristy6fccee12011-10-20 18:43:18 +00001276 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001277 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1278 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001279 break;
1280 }
1281 break;
1282 }
1283 case 'd':
1284 {
1285 if (LocaleCompare("decipher",option+1) == 0)
1286 {
1287 StringInfo
1288 *passkey;
1289
1290 /*
1291 Decipher pixels.
1292 */
cristy6fccee12011-10-20 18:43:18 +00001293 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001294 passkey=FileToStringInfo(argv[i+1],~0,exception);
1295 if (passkey != (StringInfo *) NULL)
1296 {
1297 (void) PasskeyDecipherImage(*image,passkey,exception);
1298 passkey=DestroyStringInfo(passkey);
1299 }
1300 break;
1301 }
1302 if (LocaleCompare("density",option+1) == 0)
1303 {
1304 /*
1305 Set image density.
1306 */
1307 (void) CloneString(&draw_info->density,argv[i+1]);
1308 break;
1309 }
1310 if (LocaleCompare("depth",option+1) == 0)
1311 {
cristy6fccee12011-10-20 18:43:18 +00001312 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001313 if (*option == '+')
1314 {
cristy8a11cb12011-10-19 23:53:34 +00001315 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001316 break;
1317 }
cristy8a11cb12011-10-19 23:53:34 +00001318 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1319 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001320 break;
1321 }
1322 if (LocaleCompare("deskew",option+1) == 0)
1323 {
1324 double
1325 threshold;
1326
1327 /*
1328 Straighten the image.
1329 */
cristy6fccee12011-10-20 18:43:18 +00001330 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001331 if (*option == '+')
1332 threshold=40.0*QuantumRange/100.0;
1333 else
cristy9b34e302011-11-05 02:15:45 +00001334 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1335 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001336 mogrify_image=DeskewImage(*image,threshold,exception);
1337 break;
1338 }
1339 if (LocaleCompare("despeckle",option+1) == 0)
1340 {
1341 /*
1342 Reduce the speckles within an image.
1343 */
cristy6fccee12011-10-20 18:43:18 +00001344 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001345 mogrify_image=DespeckleImage(*image,exception);
1346 break;
1347 }
1348 if (LocaleCompare("display",option+1) == 0)
1349 {
1350 (void) CloneString(&draw_info->server_name,argv[i+1]);
1351 break;
1352 }
1353 if (LocaleCompare("distort",option+1) == 0)
1354 {
1355 char
1356 *args,
1357 token[MaxTextExtent];
1358
1359 const char
1360 *p;
1361
1362 DistortImageMethod
1363 method;
1364
1365 double
1366 *arguments;
1367
1368 register ssize_t
1369 x;
1370
1371 size_t
1372 number_arguments;
1373
1374 /*
1375 Distort image.
1376 */
cristy6fccee12011-10-20 18:43:18 +00001377 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001378 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1379 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001380 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001381 {
anthonydf8ebac2011-04-27 09:03:19 +00001382 double
1383 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001384
1385 /*
1386 Special Case - Argument is actually a resize geometry!
1387 Convert that to an appropriate distortion argument array.
1388 */
anthonydf8ebac2011-04-27 09:03:19 +00001389 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001390 exception);
1391 resize_args[0]=(double) geometry.width;
1392 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001393 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001394 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001395 break;
1396 }
cristy018f07f2011-09-04 21:15:19 +00001397 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1398 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001399 if (args == (char *) NULL)
1400 break;
1401 p=(char *) args;
1402 for (x=0; *p != '\0'; x++)
1403 {
1404 GetMagickToken(p,&p,token);
1405 if (*token == ',')
1406 GetMagickToken(p,&p,token);
1407 }
1408 number_arguments=(size_t) x;
1409 arguments=(double *) AcquireQuantumMemory(number_arguments,
1410 sizeof(*arguments));
1411 if (arguments == (double *) NULL)
1412 ThrowWandFatalException(ResourceLimitFatalError,
1413 "MemoryAllocationFailed",(*image)->filename);
1414 (void) ResetMagickMemory(arguments,0,number_arguments*
1415 sizeof(*arguments));
1416 p=(char *) args;
1417 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1418 {
1419 GetMagickToken(p,&p,token);
1420 if (*token == ',')
1421 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001422 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001423 }
1424 args=DestroyString(args);
1425 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1426 (*option == '+') ? MagickTrue : MagickFalse,exception);
1427 arguments=(double *) RelinquishMagickMemory(arguments);
1428 break;
1429 }
1430 if (LocaleCompare("dither",option+1) == 0)
1431 {
1432 if (*option == '+')
1433 {
1434 quantize_info->dither=MagickFalse;
1435 break;
1436 }
1437 quantize_info->dither=MagickTrue;
1438 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1439 MagickDitherOptions,MagickFalse,argv[i+1]);
1440 if (quantize_info->dither_method == NoDitherMethod)
1441 quantize_info->dither=MagickFalse;
1442 break;
1443 }
1444 if (LocaleCompare("draw",option+1) == 0)
1445 {
1446 /*
1447 Draw image.
1448 */
cristy6fccee12011-10-20 18:43:18 +00001449 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001450 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001451 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001452 break;
1453 }
1454 break;
1455 }
1456 case 'e':
1457 {
1458 if (LocaleCompare("edge",option+1) == 0)
1459 {
1460 /*
1461 Enhance edges in the image.
1462 */
cristy6fccee12011-10-20 18:43:18 +00001463 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001464 flags=ParseGeometry(argv[i+1],&geometry_info);
1465 if ((flags & SigmaValue) == 0)
1466 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001467 mogrify_image=EdgeImage(*image,geometry_info.rho,
1468 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001469 break;
1470 }
1471 if (LocaleCompare("emboss",option+1) == 0)
1472 {
1473 /*
cristyd89705a2012-01-20 02:52:24 +00001474 Emboss image.
anthonydf8ebac2011-04-27 09:03:19 +00001475 */
cristy6fccee12011-10-20 18:43:18 +00001476 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001477 flags=ParseGeometry(argv[i+1],&geometry_info);
1478 if ((flags & SigmaValue) == 0)
1479 geometry_info.sigma=1.0;
1480 mogrify_image=EmbossImage(*image,geometry_info.rho,
1481 geometry_info.sigma,exception);
1482 break;
1483 }
1484 if (LocaleCompare("encipher",option+1) == 0)
1485 {
1486 StringInfo
1487 *passkey;
1488
1489 /*
1490 Encipher pixels.
1491 */
cristy6fccee12011-10-20 18:43:18 +00001492 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001493 passkey=FileToStringInfo(argv[i+1],~0,exception);
1494 if (passkey != (StringInfo *) NULL)
1495 {
1496 (void) PasskeyEncipherImage(*image,passkey,exception);
1497 passkey=DestroyStringInfo(passkey);
1498 }
1499 break;
1500 }
1501 if (LocaleCompare("encoding",option+1) == 0)
1502 {
1503 (void) CloneString(&draw_info->encoding,argv[i+1]);
1504 break;
1505 }
1506 if (LocaleCompare("enhance",option+1) == 0)
1507 {
1508 /*
1509 Enhance image.
1510 */
cristy6fccee12011-10-20 18:43:18 +00001511 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001512 mogrify_image=EnhanceImage(*image,exception);
1513 break;
1514 }
1515 if (LocaleCompare("equalize",option+1) == 0)
1516 {
1517 /*
1518 Equalize image.
1519 */
cristy6fccee12011-10-20 18:43:18 +00001520 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001521 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001522 break;
1523 }
1524 if (LocaleCompare("evaluate",option+1) == 0)
1525 {
1526 double
1527 constant;
1528
1529 MagickEvaluateOperator
1530 op;
1531
cristy6fccee12011-10-20 18:43:18 +00001532 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001533 op=(MagickEvaluateOperator) ParseCommandOption(
1534 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001535 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1536 1.0);
cristyd42d9952011-07-08 14:21:50 +00001537 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001538 break;
1539 }
1540 if (LocaleCompare("extent",option+1) == 0)
1541 {
1542 /*
1543 Set the image extent.
1544 */
cristy6fccee12011-10-20 18:43:18 +00001545 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001546 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1547 if (geometry.width == 0)
1548 geometry.width=(*image)->columns;
1549 if (geometry.height == 0)
1550 geometry.height=(*image)->rows;
1551 mogrify_image=ExtentImage(*image,&geometry,exception);
1552 break;
1553 }
1554 break;
1555 }
1556 case 'f':
1557 {
1558 if (LocaleCompare("family",option+1) == 0)
1559 {
1560 if (*option == '+')
1561 {
1562 if (draw_info->family != (char *) NULL)
1563 draw_info->family=DestroyString(draw_info->family);
1564 break;
1565 }
1566 (void) CloneString(&draw_info->family,argv[i+1]);
1567 break;
1568 }
1569 if (LocaleCompare("features",option+1) == 0)
1570 {
1571 if (*option == '+')
1572 {
1573 (void) DeleteImageArtifact(*image,"identify:features");
1574 break;
1575 }
1576 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1577 break;
1578 }
1579 if (LocaleCompare("fill",option+1) == 0)
1580 {
1581 ExceptionInfo
1582 *sans;
1583
anthonyfd706f92012-01-19 04:22:02 +00001584 PixelInfo
1585 color;
1586
cristy4c08aed2011-07-01 19:47:50 +00001587 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001588 if (*option == '+')
1589 {
cristy269c9412011-10-13 23:41:15 +00001590 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001591 exception);
anthonyfd706f92012-01-19 04:22:02 +00001592 draw_info->fill=fill;
anthonydf8ebac2011-04-27 09:03:19 +00001593 if (draw_info->fill_pattern != (Image *) NULL)
1594 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1595 break;
1596 }
1597 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00001598 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001599 sans=DestroyExceptionInfo(sans);
1600 if (status == MagickFalse)
1601 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1602 exception);
anthonyfd706f92012-01-19 04:22:02 +00001603 else
1604 draw_info->fill=fill=color;
anthonydf8ebac2011-04-27 09:03:19 +00001605 break;
1606 }
1607 if (LocaleCompare("flip",option+1) == 0)
1608 {
1609 /*
1610 Flip image scanlines.
1611 */
cristy6fccee12011-10-20 18:43:18 +00001612 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001613 mogrify_image=FlipImage(*image,exception);
1614 break;
1615 }
anthonydf8ebac2011-04-27 09:03:19 +00001616 if (LocaleCompare("floodfill",option+1) == 0)
1617 {
cristy4c08aed2011-07-01 19:47:50 +00001618 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001619 target;
1620
1621 /*
1622 Floodfill image.
1623 */
cristy6fccee12011-10-20 18:43:18 +00001624 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001625 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001626 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001627 exception);
cristyd42d9952011-07-08 14:21:50 +00001628 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001629 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001630 break;
1631 }
anthony3d2f4862011-05-01 13:48:16 +00001632 if (LocaleCompare("flop",option+1) == 0)
1633 {
1634 /*
1635 Flop image scanlines.
1636 */
cristy6fccee12011-10-20 18:43:18 +00001637 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001638 mogrify_image=FlopImage(*image,exception);
1639 break;
1640 }
anthonydf8ebac2011-04-27 09:03:19 +00001641 if (LocaleCompare("font",option+1) == 0)
1642 {
1643 if (*option == '+')
1644 {
1645 if (draw_info->font != (char *) NULL)
1646 draw_info->font=DestroyString(draw_info->font);
1647 break;
1648 }
1649 (void) CloneString(&draw_info->font,argv[i+1]);
1650 break;
1651 }
1652 if (LocaleCompare("format",option+1) == 0)
1653 {
1654 format=argv[i+1];
1655 break;
1656 }
1657 if (LocaleCompare("frame",option+1) == 0)
1658 {
1659 FrameInfo
1660 frame_info;
1661
1662 /*
1663 Surround image with an ornamental border.
1664 */
cristy6fccee12011-10-20 18:43:18 +00001665 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001666 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1667 frame_info.width=geometry.width;
1668 frame_info.height=geometry.height;
1669 if ((flags & HeightValue) == 0)
1670 frame_info.height=geometry.width;
1671 frame_info.outer_bevel=geometry.x;
1672 frame_info.inner_bevel=geometry.y;
1673 frame_info.x=(ssize_t) frame_info.width;
1674 frame_info.y=(ssize_t) frame_info.height;
1675 frame_info.width=(*image)->columns+2*frame_info.width;
1676 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001677 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001678 break;
1679 }
1680 if (LocaleCompare("function",option+1) == 0)
1681 {
1682 char
1683 *arguments,
1684 token[MaxTextExtent];
1685
1686 const char
1687 *p;
1688
1689 double
1690 *parameters;
1691
1692 MagickFunction
1693 function;
1694
1695 register ssize_t
1696 x;
1697
1698 size_t
1699 number_parameters;
1700
1701 /*
1702 Function Modify Image Values
1703 */
cristy6fccee12011-10-20 18:43:18 +00001704 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001705 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1706 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001707 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1708 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001709 if (arguments == (char *) NULL)
1710 break;
1711 p=(char *) arguments;
1712 for (x=0; *p != '\0'; x++)
1713 {
1714 GetMagickToken(p,&p,token);
1715 if (*token == ',')
1716 GetMagickToken(p,&p,token);
1717 }
1718 number_parameters=(size_t) x;
1719 parameters=(double *) AcquireQuantumMemory(number_parameters,
1720 sizeof(*parameters));
1721 if (parameters == (double *) NULL)
1722 ThrowWandFatalException(ResourceLimitFatalError,
1723 "MemoryAllocationFailed",(*image)->filename);
1724 (void) ResetMagickMemory(parameters,0,number_parameters*
1725 sizeof(*parameters));
1726 p=(char *) arguments;
1727 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1728 {
1729 GetMagickToken(p,&p,token);
1730 if (*token == ',')
1731 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001732 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001733 }
1734 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001735 (void) FunctionImage(*image,function,number_parameters,parameters,
1736 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001737 parameters=(double *) RelinquishMagickMemory(parameters);
1738 break;
1739 }
1740 break;
1741 }
1742 case 'g':
1743 {
1744 if (LocaleCompare("gamma",option+1) == 0)
1745 {
1746 /*
1747 Gamma image.
1748 */
cristy6fccee12011-10-20 18:43:18 +00001749 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001750 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001751 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001752 else
cristydbdd0e32011-11-04 23:29:40 +00001753 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001754 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001755 break;
1756 }
1757 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1758 (LocaleCompare("gaussian",option+1) == 0))
1759 {
1760 /*
1761 Gaussian blur image.
1762 */
cristy6fccee12011-10-20 18:43:18 +00001763 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001764 flags=ParseGeometry(argv[i+1],&geometry_info);
1765 if ((flags & SigmaValue) == 0)
1766 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001767 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristyd89705a2012-01-20 02:52:24 +00001768 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001769 break;
1770 }
1771 if (LocaleCompare("geometry",option+1) == 0)
1772 {
1773 /*
1774 Record Image offset, Resize last image.
1775 */
cristy6fccee12011-10-20 18:43:18 +00001776 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001777 if (*option == '+')
1778 {
1779 if ((*image)->geometry != (char *) NULL)
1780 (*image)->geometry=DestroyString((*image)->geometry);
1781 break;
1782 }
1783 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1784 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1785 (void) CloneString(&(*image)->geometry,argv[i+1]);
1786 else
1787 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1788 (*image)->filter,(*image)->blur,exception);
1789 break;
1790 }
1791 if (LocaleCompare("gravity",option+1) == 0)
1792 {
1793 if (*option == '+')
1794 {
1795 draw_info->gravity=UndefinedGravity;
1796 break;
1797 }
1798 draw_info->gravity=(GravityType) ParseCommandOption(
1799 MagickGravityOptions,MagickFalse,argv[i+1]);
1800 break;
1801 }
1802 break;
1803 }
1804 case 'h':
1805 {
1806 if (LocaleCompare("highlight-color",option+1) == 0)
1807 {
1808 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1809 break;
1810 }
1811 break;
1812 }
1813 case 'i':
1814 {
1815 if (LocaleCompare("identify",option+1) == 0)
1816 {
1817 char
1818 *text;
1819
cristy6fccee12011-10-20 18:43:18 +00001820 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001821 if (format == (char *) NULL)
1822 {
cristya4037272011-08-28 15:11:39 +00001823 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1824 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001825 break;
1826 }
cristy018f07f2011-09-04 21:15:19 +00001827 text=InterpretImageProperties(mogrify_info,*image,format,
1828 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001829 if (text == (char *) NULL)
1830 break;
1831 (void) fputs(text,stdout);
1832 (void) fputc('\n',stdout);
1833 text=DestroyString(text);
1834 break;
1835 }
1836 if (LocaleCompare("implode",option+1) == 0)
1837 {
1838 /*
1839 Implode image.
1840 */
cristy6fccee12011-10-20 18:43:18 +00001841 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001842 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001843 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1844 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001845 break;
1846 }
1847 if (LocaleCompare("interline-spacing",option+1) == 0)
1848 {
1849 if (*option == '+')
1850 (void) ParseGeometry("0",&geometry_info);
1851 else
1852 (void) ParseGeometry(argv[i+1],&geometry_info);
1853 draw_info->interline_spacing=geometry_info.rho;
1854 break;
1855 }
cristy28474bf2011-09-11 23:32:52 +00001856 if (LocaleCompare("interpolate",option+1) == 0)
1857 {
1858 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1859 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1860 break;
1861 }
anthonydf8ebac2011-04-27 09:03:19 +00001862 if (LocaleCompare("interword-spacing",option+1) == 0)
1863 {
1864 if (*option == '+')
1865 (void) ParseGeometry("0",&geometry_info);
1866 else
1867 (void) ParseGeometry(argv[i+1],&geometry_info);
1868 draw_info->interword_spacing=geometry_info.rho;
1869 break;
1870 }
anthonyfd706f92012-01-19 04:22:02 +00001871 if (LocaleCompare("interpolative-resize",option+1) == 0)
1872 {
1873 /*
1874 Interpolative resize image.
1875 */
1876 (void) SyncImageSettings(mogrify_info,*image,exception);
1877 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1878 mogrify_image=InterpolativeResizeImage(*image,geometry.width,
1879 geometry.height,interpolate_method,exception);
1880 break;
1881 }
anthonydf8ebac2011-04-27 09:03:19 +00001882 break;
1883 }
1884 case 'k':
1885 {
1886 if (LocaleCompare("kerning",option+1) == 0)
1887 {
1888 if (*option == '+')
1889 (void) ParseGeometry("0",&geometry_info);
1890 else
1891 (void) ParseGeometry(argv[i+1],&geometry_info);
1892 draw_info->kerning=geometry_info.rho;
1893 break;
1894 }
1895 break;
1896 }
1897 case 'l':
1898 {
1899 if (LocaleCompare("lat",option+1) == 0)
1900 {
1901 /*
1902 Local adaptive threshold image.
1903 */
cristy6fccee12011-10-20 18:43:18 +00001904 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001905 flags=ParseGeometry(argv[i+1],&geometry_info);
1906 if ((flags & PercentValue) != 0)
1907 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1908 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001909 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001910 geometry_info.xi,exception);
1911 break;
1912 }
1913 if (LocaleCompare("level",option+1) == 0)
1914 {
1915 MagickRealType
1916 black_point,
1917 gamma,
1918 white_point;
1919
1920 MagickStatusType
1921 flags;
1922
1923 /*
1924 Parse levels.
1925 */
cristy6fccee12011-10-20 18:43:18 +00001926 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001927 flags=ParseGeometry(argv[i+1],&geometry_info);
1928 black_point=geometry_info.rho;
1929 white_point=(MagickRealType) QuantumRange;
1930 if ((flags & SigmaValue) != 0)
1931 white_point=geometry_info.sigma;
1932 gamma=1.0;
1933 if ((flags & XiValue) != 0)
1934 gamma=geometry_info.xi;
1935 if ((flags & PercentValue) != 0)
1936 {
1937 black_point*=(MagickRealType) (QuantumRange/100.0);
1938 white_point*=(MagickRealType) (QuantumRange/100.0);
1939 }
1940 if ((flags & SigmaValue) == 0)
1941 white_point=(MagickRealType) QuantumRange-black_point;
1942 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001943 (void) LevelizeImage(*image,black_point,white_point,gamma,
1944 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001945 else
cristy01e9afd2011-08-10 17:38:41 +00001946 (void) LevelImage(*image,black_point,white_point,gamma,
1947 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001948 break;
1949 }
1950 if (LocaleCompare("level-colors",option+1) == 0)
1951 {
1952 char
1953 token[MaxTextExtent];
1954
1955 const char
1956 *p;
1957
cristy4c08aed2011-07-01 19:47:50 +00001958 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001959 black_point,
1960 white_point;
1961
1962 p=(const char *) argv[i+1];
1963 GetMagickToken(p,&p,token); /* get black point color */
1964 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001965 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001966 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001967 else
cristy269c9412011-10-13 23:41:15 +00001968 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001969 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001970 if (isalpha((int) token[0]) || (token[0] == '#'))
1971 GetMagickToken(p,&p,token);
1972 if (*token == '\0')
1973 white_point=black_point; /* set everything to that color */
1974 else
1975 {
1976 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1977 GetMagickToken(p,&p,token); /* Get white point color. */
1978 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001979 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001980 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001981 else
cristy269c9412011-10-13 23:41:15 +00001982 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001983 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001984 }
cristy490408a2011-07-07 14:42:05 +00001985 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001986 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001987 break;
1988 }
1989 if (LocaleCompare("linear-stretch",option+1) == 0)
1990 {
1991 double
1992 black_point,
1993 white_point;
1994
1995 MagickStatusType
1996 flags;
1997
cristy6fccee12011-10-20 18:43:18 +00001998 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001999 flags=ParseGeometry(argv[i+1],&geometry_info);
2000 black_point=geometry_info.rho;
2001 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2002 if ((flags & SigmaValue) != 0)
2003 white_point=geometry_info.sigma;
2004 if ((flags & PercentValue) != 0)
2005 {
2006 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2007 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2008 }
2009 if ((flags & SigmaValue) == 0)
2010 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2011 black_point;
cristy33bd5152011-08-24 01:42:24 +00002012 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002013 break;
2014 }
anthonydf8ebac2011-04-27 09:03:19 +00002015 if (LocaleCompare("liquid-rescale",option+1) == 0)
2016 {
2017 /*
2018 Liquid rescale image.
2019 */
cristy6fccee12011-10-20 18:43:18 +00002020 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002021 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2022 if ((flags & XValue) == 0)
2023 geometry.x=1;
2024 if ((flags & YValue) == 0)
2025 geometry.y=0;
2026 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2027 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2028 break;
2029 }
2030 if (LocaleCompare("lowlight-color",option+1) == 0)
2031 {
2032 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2033 break;
2034 }
2035 break;
2036 }
2037 case 'm':
2038 {
2039 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002040 {
cristy3ed852e2009-09-05 21:47:34 +00002041 Image
anthonydf8ebac2011-04-27 09:03:19 +00002042 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002043
anthonydf8ebac2011-04-27 09:03:19 +00002044 /*
2045 Transform image colors to match this set of colors.
2046 */
cristy6fccee12011-10-20 18:43:18 +00002047 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002048 if (*option == '+')
2049 break;
2050 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2051 if (remap_image == (Image *) NULL)
2052 break;
cristy018f07f2011-09-04 21:15:19 +00002053 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002054 remap_image=DestroyImage(remap_image);
2055 break;
2056 }
2057 if (LocaleCompare("mask",option+1) == 0)
2058 {
2059 Image
2060 *mask;
2061
cristy6fccee12011-10-20 18:43:18 +00002062 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002063 if (*option == '+')
2064 {
2065 /*
2066 Remove a mask.
2067 */
cristy018f07f2011-09-04 21:15:19 +00002068 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002069 break;
2070 }
2071 /*
2072 Set the image mask.
2073 */
2074 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2075 if (mask == (Image *) NULL)
2076 break;
cristy018f07f2011-09-04 21:15:19 +00002077 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002078 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002079 break;
2080 }
2081 if (LocaleCompare("matte",option+1) == 0)
2082 {
2083 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002084 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002085 break;
2086 }
2087 if (LocaleCompare("median",option+1) == 0)
2088 {
2089 /*
2090 Median filter image.
2091 */
cristy6fccee12011-10-20 18:43:18 +00002092 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002093 flags=ParseGeometry(argv[i+1],&geometry_info);
2094 if ((flags & SigmaValue) == 0)
2095 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002096 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002097 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002098 break;
2099 }
2100 if (LocaleCompare("mode",option+1) == 0)
2101 {
2102 /*
2103 Mode image.
2104 */
cristy6fccee12011-10-20 18:43:18 +00002105 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002106 flags=ParseGeometry(argv[i+1],&geometry_info);
2107 if ((flags & SigmaValue) == 0)
2108 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002109 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002110 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002111 break;
2112 }
2113 if (LocaleCompare("modulate",option+1) == 0)
2114 {
cristy6fccee12011-10-20 18:43:18 +00002115 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002116 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002117 break;
2118 }
2119 if (LocaleCompare("monitor",option+1) == 0)
2120 {
2121 if (*option == '+')
2122 {
2123 (void) SetImageProgressMonitor(*image,
2124 (MagickProgressMonitor) NULL,(void *) NULL);
2125 break;
2126 }
2127 (void) SetImageProgressMonitor(*image,MonitorProgress,
2128 (void *) NULL);
2129 break;
2130 }
2131 if (LocaleCompare("monochrome",option+1) == 0)
2132 {
cristy6fccee12011-10-20 18:43:18 +00002133 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002134 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002135 break;
2136 }
2137 if (LocaleCompare("morphology",option+1) == 0)
2138 {
2139 char
2140 token[MaxTextExtent];
2141
2142 const char
2143 *p;
2144
2145 KernelInfo
2146 *kernel;
2147
2148 MorphologyMethod
2149 method;
2150
2151 ssize_t
2152 iterations;
2153
2154 /*
2155 Morphological Image Operation
2156 */
cristy6fccee12011-10-20 18:43:18 +00002157 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002158 p=argv[i+1];
2159 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002160 method=(MorphologyMethod) ParseCommandOption(
2161 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002162 iterations=1L;
2163 GetMagickToken(p,&p,token);
2164 if ((*p == ':') || (*p == ','))
2165 GetMagickToken(p,&p,token);
2166 if ((*p != '\0'))
2167 iterations=(ssize_t) StringToLong(p);
2168 kernel=AcquireKernelInfo(argv[i+2]);
2169 if (kernel == (KernelInfo *) NULL)
2170 {
2171 (void) ThrowMagickException(exception,GetMagickModule(),
2172 OptionError,"UnabletoParseKernel","morphology");
2173 status=MagickFalse;
2174 break;
2175 }
cristyf4ad9df2011-07-08 16:49:03 +00002176 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2177 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002178 kernel=DestroyKernelInfo(kernel);
2179 break;
2180 }
2181 if (LocaleCompare("motion-blur",option+1) == 0)
2182 {
2183 /*
2184 Motion blur image.
2185 */
cristy6fccee12011-10-20 18:43:18 +00002186 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002187 flags=ParseGeometry(argv[i+1],&geometry_info);
2188 if ((flags & SigmaValue) == 0)
2189 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002190 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristy7497f482011-12-08 01:57:31 +00002191 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002192 break;
2193 }
2194 break;
2195 }
2196 case 'n':
2197 {
2198 if (LocaleCompare("negate",option+1) == 0)
2199 {
cristy6fccee12011-10-20 18:43:18 +00002200 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002201 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002202 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002203 break;
2204 }
2205 if (LocaleCompare("noise",option+1) == 0)
2206 {
cristy6fccee12011-10-20 18:43:18 +00002207 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002208 if (*option == '-')
2209 {
cristyf36cbcb2011-09-07 13:28:22 +00002210 flags=ParseGeometry(argv[i+1],&geometry_info);
2211 if ((flags & SigmaValue) == 0)
2212 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002213 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002214 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002215 }
2216 else
2217 {
2218 NoiseType
2219 noise;
2220
2221 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2222 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002223 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002224 }
2225 break;
2226 }
2227 if (LocaleCompare("normalize",option+1) == 0)
2228 {
cristy6fccee12011-10-20 18:43:18 +00002229 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002230 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002231 break;
2232 }
2233 break;
2234 }
2235 case 'o':
2236 {
2237 if (LocaleCompare("opaque",option+1) == 0)
2238 {
cristy4c08aed2011-07-01 19:47:50 +00002239 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002240 target;
2241
cristy6fccee12011-10-20 18:43:18 +00002242 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002243 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002244 exception);
cristyd42d9952011-07-08 14:21:50 +00002245 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002246 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002247 break;
2248 }
2249 if (LocaleCompare("ordered-dither",option+1) == 0)
2250 {
cristy6fccee12011-10-20 18:43:18 +00002251 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002252 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002253 break;
2254 }
2255 break;
2256 }
2257 case 'p':
2258 {
2259 if (LocaleCompare("paint",option+1) == 0)
2260 {
cristy6fccee12011-10-20 18:43:18 +00002261 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002262 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002263 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2264 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002265 break;
2266 }
anthonydf8ebac2011-04-27 09:03:19 +00002267 if (LocaleCompare("pointsize",option+1) == 0)
2268 {
2269 if (*option == '+')
2270 (void) ParseGeometry("12",&geometry_info);
2271 else
2272 (void) ParseGeometry(argv[i+1],&geometry_info);
2273 draw_info->pointsize=geometry_info.rho;
2274 break;
2275 }
2276 if (LocaleCompare("polaroid",option+1) == 0)
2277 {
cristye9e3d382011-12-14 01:50:13 +00002278 const char
2279 *caption;
2280
anthonydf8ebac2011-04-27 09:03:19 +00002281 double
2282 angle;
2283
2284 RandomInfo
2285 *random_info;
2286
2287 /*
2288 Simulate a Polaroid picture.
2289 */
cristy6fccee12011-10-20 18:43:18 +00002290 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002291 random_info=AcquireRandomInfo();
2292 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2293 random_info=DestroyRandomInfo(random_info);
2294 if (*option == '-')
2295 {
2296 SetGeometryInfo(&geometry_info);
2297 flags=ParseGeometry(argv[i+1],&geometry_info);
2298 angle=geometry_info.rho;
2299 }
cristye9e3d382011-12-14 01:50:13 +00002300 caption=GetImageProperty(*image,"caption",exception);
2301 mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
cristy28474bf2011-09-11 23:32:52 +00002302 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002303 break;
2304 }
2305 if (LocaleCompare("posterize",option+1) == 0)
2306 {
2307 /*
2308 Posterize image.
2309 */
cristy6fccee12011-10-20 18:43:18 +00002310 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002311 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002312 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002313 break;
2314 }
2315 if (LocaleCompare("preview",option+1) == 0)
2316 {
2317 PreviewType
2318 preview_type;
2319
2320 /*
2321 Preview image.
2322 */
cristy6fccee12011-10-20 18:43:18 +00002323 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002324 if (*option == '+')
2325 preview_type=UndefinedPreview;
2326 else
cristy28474bf2011-09-11 23:32:52 +00002327 preview_type=(PreviewType) ParseCommandOption(
2328 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002329 mogrify_image=PreviewImage(*image,preview_type,exception);
2330 break;
2331 }
2332 if (LocaleCompare("profile",option+1) == 0)
2333 {
2334 const char
2335 *name;
2336
2337 const StringInfo
2338 *profile;
2339
2340 Image
2341 *profile_image;
2342
2343 ImageInfo
2344 *profile_info;
2345
cristy6fccee12011-10-20 18:43:18 +00002346 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002347 if (*option == '+')
2348 {
2349 /*
2350 Remove a profile from the image.
2351 */
2352 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002353 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002354 break;
2355 }
2356 /*
2357 Associate a profile with the image.
2358 */
2359 profile_info=CloneImageInfo(mogrify_info);
2360 profile=GetImageProfile(*image,"iptc");
2361 if (profile != (StringInfo *) NULL)
2362 profile_info->profile=(void *) CloneStringInfo(profile);
2363 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2364 profile_info=DestroyImageInfo(profile_info);
2365 if (profile_image == (Image *) NULL)
2366 {
2367 StringInfo
2368 *profile;
2369
2370 profile_info=CloneImageInfo(mogrify_info);
2371 (void) CopyMagickString(profile_info->filename,argv[i+1],
2372 MaxTextExtent);
2373 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2374 if (profile != (StringInfo *) NULL)
2375 {
2376 (void) ProfileImage(*image,profile_info->magick,
2377 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002378 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002379 profile=DestroyStringInfo(profile);
2380 }
2381 profile_info=DestroyImageInfo(profile_info);
2382 break;
2383 }
2384 ResetImageProfileIterator(profile_image);
2385 name=GetNextImageProfile(profile_image);
2386 while (name != (const char *) NULL)
2387 {
2388 profile=GetImageProfile(profile_image,name);
2389 if (profile != (StringInfo *) NULL)
2390 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002391 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002392 name=GetNextImageProfile(profile_image);
2393 }
2394 profile_image=DestroyImage(profile_image);
2395 break;
2396 }
2397 break;
2398 }
2399 case 'q':
2400 {
2401 if (LocaleCompare("quantize",option+1) == 0)
2402 {
2403 if (*option == '+')
2404 {
2405 quantize_info->colorspace=UndefinedColorspace;
2406 break;
2407 }
2408 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2409 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2410 break;
2411 }
2412 break;
2413 }
2414 case 'r':
2415 {
2416 if (LocaleCompare("radial-blur",option+1) == 0)
2417 {
2418 /*
2419 Radial blur image.
2420 */
cristy6fccee12011-10-20 18:43:18 +00002421 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002422 flags=ParseGeometry(argv[i+1],&geometry_info);
2423 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2424 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002425 break;
2426 }
2427 if (LocaleCompare("raise",option+1) == 0)
2428 {
2429 /*
2430 Surround image with a raise of solid color.
2431 */
2432 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2433 if ((flags & SigmaValue) == 0)
2434 geometry.height=geometry.width;
2435 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002436 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002437 break;
2438 }
2439 if (LocaleCompare("random-threshold",option+1) == 0)
2440 {
2441 /*
2442 Threshold image.
2443 */
cristy6fccee12011-10-20 18:43:18 +00002444 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002445 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002446 break;
2447 }
anthonydf8ebac2011-04-27 09:03:19 +00002448 if (LocaleCompare("region",option+1) == 0)
2449 {
cristy6fccee12011-10-20 18:43:18 +00002450 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002451 if (region_image != (Image *) NULL)
2452 {
2453 /*
2454 Composite region.
2455 */
2456 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002457 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002458 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002459 *image=DestroyImage(*image);
2460 *image=region_image;
2461 region_image = (Image *) NULL;
2462 }
2463 if (*option == '+')
2464 break;
2465 /*
2466 Apply transformations to a selected region of the image.
2467 */
cristy3ed852e2009-09-05 21:47:34 +00002468 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2469 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002470 mogrify_image=CropImage(*image,&region_geometry,exception);
2471 if (mogrify_image == (Image *) NULL)
2472 break;
2473 region_image=(*image);
2474 *image=mogrify_image;
2475 mogrify_image=(Image *) NULL;
2476 break;
cristy3ed852e2009-09-05 21:47:34 +00002477 }
anthonydf8ebac2011-04-27 09:03:19 +00002478 if (LocaleCompare("render",option+1) == 0)
2479 {
cristy6fccee12011-10-20 18:43:18 +00002480 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002481 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2482 break;
2483 }
2484 if (LocaleCompare("remap",option+1) == 0)
2485 {
2486 Image
2487 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002488
anthonydf8ebac2011-04-27 09:03:19 +00002489 /*
2490 Transform image colors to match this set of colors.
2491 */
cristy6fccee12011-10-20 18:43:18 +00002492 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002493 if (*option == '+')
2494 break;
2495 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2496 if (remap_image == (Image *) NULL)
2497 break;
cristy018f07f2011-09-04 21:15:19 +00002498 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002499 remap_image=DestroyImage(remap_image);
2500 break;
2501 }
2502 if (LocaleCompare("repage",option+1) == 0)
2503 {
2504 if (*option == '+')
2505 {
2506 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2507 break;
2508 }
2509 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002510 break;
2511 }
2512 if (LocaleCompare("resample",option+1) == 0)
2513 {
2514 /*
2515 Resample image.
2516 */
cristy6fccee12011-10-20 18:43:18 +00002517 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002518 flags=ParseGeometry(argv[i+1],&geometry_info);
2519 if ((flags & SigmaValue) == 0)
2520 geometry_info.sigma=geometry_info.rho;
2521 mogrify_image=ResampleImage(*image,geometry_info.rho,
2522 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2523 break;
2524 }
2525 if (LocaleCompare("resize",option+1) == 0)
2526 {
2527 /*
2528 Resize image.
2529 */
cristy6fccee12011-10-20 18:43:18 +00002530 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002531 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2532 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2533 (*image)->filter,(*image)->blur,exception);
2534 break;
2535 }
2536 if (LocaleCompare("roll",option+1) == 0)
2537 {
2538 /*
2539 Roll image.
2540 */
cristy6fccee12011-10-20 18:43:18 +00002541 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002542 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2543 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2544 break;
2545 }
2546 if (LocaleCompare("rotate",option+1) == 0)
2547 {
2548 char
2549 *geometry;
2550
2551 /*
2552 Check for conditional image rotation.
2553 */
cristy6fccee12011-10-20 18:43:18 +00002554 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002555 if (strchr(argv[i+1],'>') != (char *) NULL)
2556 if ((*image)->columns <= (*image)->rows)
2557 break;
2558 if (strchr(argv[i+1],'<') != (char *) NULL)
2559 if ((*image)->columns >= (*image)->rows)
2560 break;
2561 /*
2562 Rotate image.
2563 */
2564 geometry=ConstantString(argv[i+1]);
2565 (void) SubstituteString(&geometry,">","");
2566 (void) SubstituteString(&geometry,"<","");
2567 (void) ParseGeometry(geometry,&geometry_info);
2568 geometry=DestroyString(geometry);
2569 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2570 break;
2571 }
2572 break;
2573 }
2574 case 's':
2575 {
2576 if (LocaleCompare("sample",option+1) == 0)
2577 {
2578 /*
2579 Sample image with pixel replication.
2580 */
cristy6fccee12011-10-20 18:43:18 +00002581 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002582 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2583 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2584 exception);
2585 break;
2586 }
2587 if (LocaleCompare("scale",option+1) == 0)
2588 {
2589 /*
2590 Resize image.
2591 */
cristy6fccee12011-10-20 18:43:18 +00002592 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002593 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2594 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2595 exception);
2596 break;
2597 }
2598 if (LocaleCompare("selective-blur",option+1) == 0)
2599 {
2600 /*
2601 Selectively blur pixels within a contrast threshold.
2602 */
cristy6fccee12011-10-20 18:43:18 +00002603 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002604 flags=ParseGeometry(argv[i+1],&geometry_info);
2605 if ((flags & PercentValue) != 0)
2606 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002607 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002608 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002609 break;
2610 }
2611 if (LocaleCompare("separate",option+1) == 0)
2612 {
2613 /*
2614 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002615 */
cristy6fccee12011-10-20 18:43:18 +00002616 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3139dc22011-07-08 00:11:42 +00002617 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002618 break;
2619 }
2620 if (LocaleCompare("sepia-tone",option+1) == 0)
2621 {
2622 double
2623 threshold;
2624
2625 /*
2626 Sepia-tone image.
2627 */
cristy6fccee12011-10-20 18:43:18 +00002628 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002629 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2630 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002631 mogrify_image=SepiaToneImage(*image,threshold,exception);
2632 break;
2633 }
2634 if (LocaleCompare("segment",option+1) == 0)
2635 {
2636 /*
2637 Segment image.
2638 */
cristy6fccee12011-10-20 18:43:18 +00002639 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002640 flags=ParseGeometry(argv[i+1],&geometry_info);
2641 if ((flags & SigmaValue) == 0)
2642 geometry_info.sigma=1.0;
2643 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002644 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2645 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002646 break;
2647 }
2648 if (LocaleCompare("set",option+1) == 0)
2649 {
2650 char
2651 *value;
2652
2653 /*
2654 Set image option.
2655 */
2656 if (*option == '+')
2657 {
2658 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2659 (void) DeleteImageRegistry(argv[i+1]+9);
2660 else
2661 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2662 {
2663 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2664 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2665 }
2666 else
2667 (void) DeleteImageProperty(*image,argv[i+1]);
2668 break;
2669 }
cristy018f07f2011-09-04 21:15:19 +00002670 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2671 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002672 if (value == (char *) NULL)
2673 break;
2674 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2675 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2676 exception);
2677 else
2678 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2679 {
2680 (void) SetImageOption(image_info,argv[i+1]+7,value);
2681 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2682 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2683 }
2684 else
cristyd15e6592011-10-15 00:13:06 +00002685 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002686 value=DestroyString(value);
2687 break;
2688 }
2689 if (LocaleCompare("shade",option+1) == 0)
2690 {
2691 /*
2692 Shade image.
2693 */
cristy6fccee12011-10-20 18:43:18 +00002694 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002695 flags=ParseGeometry(argv[i+1],&geometry_info);
2696 if ((flags & SigmaValue) == 0)
2697 geometry_info.sigma=1.0;
2698 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2699 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2700 break;
2701 }
2702 if (LocaleCompare("shadow",option+1) == 0)
2703 {
2704 /*
2705 Shadow image.
2706 */
cristy6fccee12011-10-20 18:43:18 +00002707 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002708 flags=ParseGeometry(argv[i+1],&geometry_info);
2709 if ((flags & SigmaValue) == 0)
2710 geometry_info.sigma=1.0;
2711 if ((flags & XiValue) == 0)
2712 geometry_info.xi=4.0;
2713 if ((flags & PsiValue) == 0)
2714 geometry_info.psi=4.0;
2715 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00002716 geometry_info.sigma,(*image)->bias,(ssize_t)
2717 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
2718 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002719 break;
2720 }
2721 if (LocaleCompare("sharpen",option+1) == 0)
2722 {
2723 /*
2724 Sharpen image.
2725 */
cristy6fccee12011-10-20 18:43:18 +00002726 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002727 flags=ParseGeometry(argv[i+1],&geometry_info);
2728 if ((flags & SigmaValue) == 0)
2729 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002730 if ((flags & XiValue) == 0)
2731 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002732 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002733 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002734 break;
2735 }
2736 if (LocaleCompare("shave",option+1) == 0)
2737 {
2738 /*
2739 Shave the image edges.
2740 */
cristy6fccee12011-10-20 18:43:18 +00002741 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002742 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2743 mogrify_image=ShaveImage(*image,&geometry,exception);
2744 break;
2745 }
2746 if (LocaleCompare("shear",option+1) == 0)
2747 {
2748 /*
2749 Shear image.
2750 */
cristy6fccee12011-10-20 18:43:18 +00002751 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002752 flags=ParseGeometry(argv[i+1],&geometry_info);
2753 if ((flags & SigmaValue) == 0)
2754 geometry_info.sigma=geometry_info.rho;
2755 mogrify_image=ShearImage(*image,geometry_info.rho,
2756 geometry_info.sigma,exception);
2757 break;
2758 }
2759 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2760 {
2761 /*
2762 Sigmoidal non-linearity contrast control.
2763 */
cristy6fccee12011-10-20 18:43:18 +00002764 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002765 flags=ParseGeometry(argv[i+1],&geometry_info);
2766 if ((flags & SigmaValue) == 0)
2767 geometry_info.sigma=(double) QuantumRange/2.0;
2768 if ((flags & PercentValue) != 0)
2769 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2770 100.0;
cristy9ee60942011-07-06 14:54:38 +00002771 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002772 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2773 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002774 break;
2775 }
2776 if (LocaleCompare("sketch",option+1) == 0)
2777 {
2778 /*
2779 Sketch image.
2780 */
cristy6fccee12011-10-20 18:43:18 +00002781 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002782 flags=ParseGeometry(argv[i+1],&geometry_info);
2783 if ((flags & SigmaValue) == 0)
2784 geometry_info.sigma=1.0;
2785 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002786 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002787 break;
2788 }
2789 if (LocaleCompare("solarize",option+1) == 0)
2790 {
2791 double
2792 threshold;
2793
cristy6fccee12011-10-20 18:43:18 +00002794 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002795 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2796 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002797 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002798 break;
2799 }
2800 if (LocaleCompare("sparse-color",option+1) == 0)
2801 {
2802 SparseColorMethod
2803 method;
2804
2805 char
2806 *arguments;
2807
2808 /*
2809 Sparse Color Interpolated Gradient
2810 */
cristy6fccee12011-10-20 18:43:18 +00002811 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002812 method=(SparseColorMethod) ParseCommandOption(
2813 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002814 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2815 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002816 if (arguments == (char *) NULL)
2817 break;
cristy3884f692011-07-08 18:00:18 +00002818 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002819 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2820 arguments=DestroyString(arguments);
2821 break;
2822 }
2823 if (LocaleCompare("splice",option+1) == 0)
2824 {
2825 /*
2826 Splice a solid color into the image.
2827 */
cristy6fccee12011-10-20 18:43:18 +00002828 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002829 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2830 mogrify_image=SpliceImage(*image,&geometry,exception);
2831 break;
2832 }
2833 if (LocaleCompare("spread",option+1) == 0)
2834 {
2835 /*
2836 Spread an image.
2837 */
cristy6fccee12011-10-20 18:43:18 +00002838 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002839 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002840 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002841 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002842 break;
2843 }
2844 if (LocaleCompare("statistic",option+1) == 0)
2845 {
2846 StatisticType
2847 type;
2848
cristy6fccee12011-10-20 18:43:18 +00002849 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002850 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2851 MagickFalse,argv[i+1]);
2852 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002853 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2854 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002855 break;
2856 }
2857 if (LocaleCompare("stretch",option+1) == 0)
2858 {
2859 if (*option == '+')
2860 {
2861 draw_info->stretch=UndefinedStretch;
2862 break;
2863 }
2864 draw_info->stretch=(StretchType) ParseCommandOption(
2865 MagickStretchOptions,MagickFalse,argv[i+1]);
2866 break;
2867 }
2868 if (LocaleCompare("strip",option+1) == 0)
2869 {
2870 /*
2871 Strip image of profiles and comments.
2872 */
cristy6fccee12011-10-20 18:43:18 +00002873 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002874 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002875 break;
2876 }
2877 if (LocaleCompare("stroke",option+1) == 0)
2878 {
2879 ExceptionInfo
2880 *sans;
2881
anthonyfd706f92012-01-19 04:22:02 +00002882 PixelInfo
2883 color;
2884
anthonydf8ebac2011-04-27 09:03:19 +00002885 if (*option == '+')
2886 {
cristy9950d572011-10-01 18:22:35 +00002887 (void) QueryColorCompliance("none",AllCompliance,
2888 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002889 if (draw_info->stroke_pattern != (Image *) NULL)
2890 draw_info->stroke_pattern=DestroyImage(
2891 draw_info->stroke_pattern);
2892 break;
2893 }
2894 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00002895 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002896 sans=DestroyExceptionInfo(sans);
2897 if (status == MagickFalse)
2898 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2899 exception);
anthonyfd706f92012-01-19 04:22:02 +00002900 else
2901 draw_info->stroke=color;
anthonydf8ebac2011-04-27 09:03:19 +00002902 break;
2903 }
2904 if (LocaleCompare("strokewidth",option+1) == 0)
2905 {
cristy9b34e302011-11-05 02:15:45 +00002906 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002907 break;
2908 }
2909 if (LocaleCompare("style",option+1) == 0)
2910 {
2911 if (*option == '+')
2912 {
2913 draw_info->style=UndefinedStyle;
2914 break;
2915 }
2916 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2917 MagickFalse,argv[i+1]);
2918 break;
2919 }
2920 if (LocaleCompare("swirl",option+1) == 0)
2921 {
2922 /*
2923 Swirl image.
2924 */
cristy6fccee12011-10-20 18:43:18 +00002925 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002926 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002927 mogrify_image=SwirlImage(*image,geometry_info.rho,
2928 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002929 break;
2930 }
2931 break;
2932 }
2933 case 't':
2934 {
2935 if (LocaleCompare("threshold",option+1) == 0)
2936 {
2937 double
2938 threshold;
2939
2940 /*
2941 Threshold image.
2942 */
cristy6fccee12011-10-20 18:43:18 +00002943 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002944 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002945 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002946 else
cristy9b34e302011-11-05 02:15:45 +00002947 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2948 1.0);
cristye941a752011-10-15 01:52:48 +00002949 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002950 break;
2951 }
2952 if (LocaleCompare("thumbnail",option+1) == 0)
2953 {
2954 /*
2955 Thumbnail image.
2956 */
cristy6fccee12011-10-20 18:43:18 +00002957 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002958 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2959 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2960 exception);
2961 break;
2962 }
2963 if (LocaleCompare("tile",option+1) == 0)
2964 {
2965 if (*option == '+')
2966 {
2967 if (draw_info->fill_pattern != (Image *) NULL)
2968 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2969 break;
2970 }
2971 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2972 exception);
2973 break;
2974 }
2975 if (LocaleCompare("tint",option+1) == 0)
2976 {
2977 /*
2978 Tint the image.
2979 */
cristy6fccee12011-10-20 18:43:18 +00002980 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00002981 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002982 break;
2983 }
2984 if (LocaleCompare("transform",option+1) == 0)
2985 {
2986 /*
2987 Affine transform image.
2988 */
cristy6fccee12011-10-20 18:43:18 +00002989 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002990 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
2991 exception);
2992 break;
2993 }
2994 if (LocaleCompare("transparent",option+1) == 0)
2995 {
cristy4c08aed2011-07-01 19:47:50 +00002996 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002997 target;
2998
cristy6fccee12011-10-20 18:43:18 +00002999 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00003000 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00003001 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003002 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00003003 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00003004 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003005 break;
3006 }
3007 if (LocaleCompare("transpose",option+1) == 0)
3008 {
3009 /*
3010 Transpose image scanlines.
3011 */
cristy6fccee12011-10-20 18:43:18 +00003012 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003013 mogrify_image=TransposeImage(*image,exception);
3014 break;
3015 }
3016 if (LocaleCompare("transverse",option+1) == 0)
3017 {
3018 /*
3019 Transverse image scanlines.
3020 */
cristy6fccee12011-10-20 18:43:18 +00003021 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003022 mogrify_image=TransverseImage(*image,exception);
3023 break;
3024 }
3025 if (LocaleCompare("treedepth",option+1) == 0)
3026 {
3027 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3028 break;
3029 }
3030 if (LocaleCompare("trim",option+1) == 0)
3031 {
3032 /*
3033 Trim image.
3034 */
cristy6fccee12011-10-20 18:43:18 +00003035 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003036 mogrify_image=TrimImage(*image,exception);
3037 break;
3038 }
3039 if (LocaleCompare("type",option+1) == 0)
3040 {
3041 ImageType
3042 type;
3043
cristy6fccee12011-10-20 18:43:18 +00003044 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003045 if (*option == '+')
3046 type=UndefinedType;
3047 else
3048 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3049 argv[i+1]);
3050 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003051 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003052 break;
3053 }
3054 break;
3055 }
3056 case 'u':
3057 {
3058 if (LocaleCompare("undercolor",option+1) == 0)
3059 {
cristy9950d572011-10-01 18:22:35 +00003060 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3061 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003062 break;
3063 }
3064 if (LocaleCompare("unique",option+1) == 0)
3065 {
3066 if (*option == '+')
3067 {
3068 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3069 break;
3070 }
3071 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3072 (void) SetImageArtifact(*image,"verbose","true");
3073 break;
3074 }
3075 if (LocaleCompare("unique-colors",option+1) == 0)
3076 {
3077 /*
3078 Unique image colors.
3079 */
cristy6fccee12011-10-20 18:43:18 +00003080 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003081 mogrify_image=UniqueImageColors(*image,exception);
3082 break;
3083 }
3084 if (LocaleCompare("unsharp",option+1) == 0)
3085 {
3086 /*
3087 Unsharp mask image.
3088 */
cristy6fccee12011-10-20 18:43:18 +00003089 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003090 flags=ParseGeometry(argv[i+1],&geometry_info);
3091 if ((flags & SigmaValue) == 0)
3092 geometry_info.sigma=1.0;
3093 if ((flags & XiValue) == 0)
3094 geometry_info.xi=1.0;
3095 if ((flags & PsiValue) == 0)
3096 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003097 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3098 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003099 break;
3100 }
3101 break;
3102 }
3103 case 'v':
3104 {
3105 if (LocaleCompare("verbose",option+1) == 0)
3106 {
3107 (void) SetImageArtifact(*image,option+1,
3108 *option == '+' ? "false" : "true");
3109 break;
3110 }
3111 if (LocaleCompare("vignette",option+1) == 0)
3112 {
3113 /*
3114 Vignette image.
3115 */
cristy6fccee12011-10-20 18:43:18 +00003116 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003117 flags=ParseGeometry(argv[i+1],&geometry_info);
3118 if ((flags & SigmaValue) == 0)
3119 geometry_info.sigma=1.0;
3120 if ((flags & XiValue) == 0)
3121 geometry_info.xi=0.1*(*image)->columns;
3122 if ((flags & PsiValue) == 0)
3123 geometry_info.psi=0.1*(*image)->rows;
3124 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00003125 geometry_info.sigma,(*image)->bias,(ssize_t)
3126 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
3127 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003128 break;
3129 }
3130 if (LocaleCompare("virtual-pixel",option+1) == 0)
3131 {
3132 if (*option == '+')
3133 {
3134 (void) SetImageVirtualPixelMethod(*image,
cristy387430f2012-02-07 13:09:46 +00003135 UndefinedVirtualPixelMethod,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003136 break;
3137 }
3138 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3139 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy387430f2012-02-07 13:09:46 +00003140 argv[i+1]),exception);
anthonydf8ebac2011-04-27 09:03:19 +00003141 break;
3142 }
3143 break;
3144 }
3145 case 'w':
3146 {
3147 if (LocaleCompare("wave",option+1) == 0)
3148 {
3149 /*
3150 Wave image.
3151 */
cristy6fccee12011-10-20 18:43:18 +00003152 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003153 flags=ParseGeometry(argv[i+1],&geometry_info);
3154 if ((flags & SigmaValue) == 0)
3155 geometry_info.sigma=1.0;
3156 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003157 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003158 break;
3159 }
3160 if (LocaleCompare("weight",option+1) == 0)
3161 {
3162 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3163 if (LocaleCompare(argv[i+1],"all") == 0)
3164 draw_info->weight=0;
3165 if (LocaleCompare(argv[i+1],"bold") == 0)
3166 draw_info->weight=700;
3167 if (LocaleCompare(argv[i+1],"bolder") == 0)
3168 if (draw_info->weight <= 800)
3169 draw_info->weight+=100;
3170 if (LocaleCompare(argv[i+1],"lighter") == 0)
3171 if (draw_info->weight >= 100)
3172 draw_info->weight-=100;
3173 if (LocaleCompare(argv[i+1],"normal") == 0)
3174 draw_info->weight=400;
3175 break;
3176 }
3177 if (LocaleCompare("white-threshold",option+1) == 0)
3178 {
3179 /*
3180 White threshold image.
3181 */
cristy6fccee12011-10-20 18:43:18 +00003182 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003183 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003184 break;
3185 }
3186 break;
3187 }
3188 default:
3189 break;
3190 }
3191 /*
3192 Replace current image with any image that was generated
3193 */
3194 if (mogrify_image != (Image *) NULL)
3195 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003196 i+=count;
3197 }
3198 if (region_image != (Image *) NULL)
3199 {
anthonydf8ebac2011-04-27 09:03:19 +00003200 /*
3201 Composite transformed region onto image.
3202 */
cristy6fccee12011-10-20 18:43:18 +00003203 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonya129f702011-04-14 01:08:48 +00003204 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003205 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003206 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003207 *image=DestroyImage(*image);
3208 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003209 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003210 }
3211 /*
3212 Free resources.
3213 */
anthonydf8ebac2011-04-27 09:03:19 +00003214 quantize_info=DestroyQuantizeInfo(quantize_info);
3215 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003216 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003217 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003218 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003219}
3220
3221/*
3222%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3223% %
3224% %
3225% %
cristy5063d812010-10-19 16:28:10 +00003226+ M o g r i f y I m a g e C o m m a n d %
cristy3ed852e2009-09-05 21:47:34 +00003227% %
3228% %
3229% %
3230%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3231%
3232% MogrifyImageCommand() transforms an image or a sequence of images. These
3233% transforms include image scaling, image rotation, color reduction, and
3234% others. The transmogrified image overwrites the original image.
3235%
3236% The format of the MogrifyImageCommand method is:
3237%
3238% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3239% const char **argv,char **metadata,ExceptionInfo *exception)
3240%
3241% A description of each parameter follows:
3242%
3243% o image_info: the image info.
3244%
3245% o argc: the number of elements in the argument vector.
3246%
3247% o argv: A text array containing the command line arguments.
3248%
3249% o metadata: any metadata is returned here.
3250%
3251% o exception: return any errors or warnings in this structure.
3252%
3253*/
3254
3255static MagickBooleanType MogrifyUsage(void)
3256{
3257 static const char
cristy87c02f42012-02-24 00:19:10 +00003258 *channel_operators[]=
3259 {
cristyd04e7bf2012-03-03 19:19:12 +00003260 "-channel-ops expression",
3261 " exchange, extract, or transfer one or more image channels",
cristy87c02f42012-02-24 00:19:10 +00003262 (char *) NULL
3263 },
cristy3ed852e2009-09-05 21:47:34 +00003264 *miscellaneous[]=
3265 {
3266 "-debug events display copious debugging information",
3267 "-help print program options",
3268 "-list type print a list of supported option arguments",
3269 "-log format format of debugging information",
3270 "-version print version information",
3271 (char *) NULL
3272 },
3273 *operators[]=
3274 {
3275 "-adaptive-blur geometry",
3276 " adaptively blur pixels; decrease effect near edges",
3277 "-adaptive-resize geometry",
3278 " adaptively resize image using 'mesh' interpolation",
3279 "-adaptive-sharpen geometry",
3280 " adaptively sharpen pixels; increase effect near edges",
3281 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3282 " transparent, extract, background, or shape",
3283 "-annotate geometry text",
3284 " annotate the image with text",
3285 "-auto-gamma automagically adjust gamma level of image",
3286 "-auto-level automagically adjust color levels of image",
3287 "-auto-orient automagically orient (rotate) image",
3288 "-bench iterations measure performance",
3289 "-black-threshold value",
3290 " force all pixels below the threshold into black",
3291 "-blue-shift simulate a scene at nighttime in the moonlight",
3292 "-blur geometry reduce image noise and reduce detail levels",
3293 "-border geometry surround image with a border of color",
3294 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003295 "-brightness-contrast geometry",
3296 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003297 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003298 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003299 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003300 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003301 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003302 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003303 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003304 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003305 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003306 "-contrast enhance or reduce the image contrast",
3307 "-contrast-stretch geometry",
3308 " improve contrast by `stretching' the intensity range",
3309 "-convolve coefficients",
3310 " apply a convolution kernel to the image",
3311 "-cycle amount cycle the image colormap",
3312 "-decipher filename convert cipher pixels to plain pixels",
3313 "-deskew threshold straighten an image",
3314 "-despeckle reduce the speckles within an image",
3315 "-distort method args",
3316 " distort images according to given method ad args",
3317 "-draw string annotate the image with a graphic primitive",
3318 "-edge radius apply a filter to detect edges in the image",
3319 "-encipher filename convert plain pixels to cipher pixels",
3320 "-emboss radius emboss an image",
3321 "-enhance apply a digital filter to enhance a noisy image",
3322 "-equalize perform histogram equalization to an image",
3323 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003324 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003325 "-extent geometry set the image size",
3326 "-extract geometry extract area from image",
3327 "-fft implements the discrete Fourier transform (DFT)",
3328 "-flip flip image vertically",
3329 "-floodfill geometry color",
3330 " floodfill the image with color",
3331 "-flop flop image horizontally",
3332 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003333 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003334 " apply function over image values",
3335 "-gamma value level of gamma correction",
3336 "-gaussian-blur geometry",
3337 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003338 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003339 "-identify identify the format and characteristics of the image",
3340 "-ift implements the inverse discrete Fourier transform (DFT)",
3341 "-implode amount implode image pixels about the center",
anthonyfd706f92012-01-19 04:22:02 +00003342 "-interpolative-resize geometry",
3343 " resize image using interpolation",
cristy3ed852e2009-09-05 21:47:34 +00003344 "-lat geometry local adaptive thresholding",
3345 "-layers method optimize, merge, or compare image layers",
3346 "-level value adjust the level of image contrast",
3347 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003348 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003349 "-linear-stretch geometry",
3350 " improve contrast by `stretching with saturation'",
3351 "-liquid-rescale geometry",
3352 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003353 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003354 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003355 "-modulate value vary the brightness, saturation, and hue",
3356 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003357 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003358 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003359 "-motion-blur geometry",
3360 " simulate motion blur",
3361 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003362 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003363 "-normalize transform image to span the full range of colors",
3364 "-opaque color change this color to the fill color",
3365 "-ordered-dither NxN",
3366 " add a noise pattern to the image with specific",
3367 " amplitudes",
3368 "-paint radius simulate an oil painting",
3369 "-polaroid angle simulate a Polaroid picture",
3370 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003371 "-profile filename add, delete, or apply an image profile",
3372 "-quantize colorspace reduce colors in this colorspace",
3373 "-radial-blur angle radial blur the image",
3374 "-raise value lighten/darken image edges to create a 3-D effect",
3375 "-random-threshold low,high",
3376 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003377 "-region geometry apply options to a portion of the image",
3378 "-render render vector graphics",
3379 "-repage geometry size and location of an image canvas",
3380 "-resample geometry change the resolution of an image",
3381 "-resize geometry resize the image",
3382 "-roll geometry roll an image vertically or horizontally",
3383 "-rotate degrees apply Paeth rotation to the image",
3384 "-sample geometry scale image with pixel sampling",
3385 "-scale geometry scale the image",
3386 "-segment values segment an image",
3387 "-selective-blur geometry",
3388 " selectively blur pixels within a contrast threshold",
3389 "-sepia-tone threshold",
3390 " simulate a sepia-toned photo",
3391 "-set property value set an image property",
3392 "-shade degrees shade the image using a distant light source",
3393 "-shadow geometry simulate an image shadow",
3394 "-sharpen geometry sharpen the image",
3395 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003396 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003397 "-sigmoidal-contrast geometry",
3398 " increase the contrast without saturating highlights or shadows",
3399 "-sketch geometry simulate a pencil sketch",
3400 "-solarize threshold negate all pixels above the threshold level",
3401 "-sparse-color method args",
3402 " fill in a image based on a few color points",
3403 "-splice geometry splice the background color into the image",
3404 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003405 "-statistic type radius",
3406 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003407 "-strip strip image of all profiles and comments",
3408 "-swirl degrees swirl image pixels about the center",
3409 "-threshold value threshold the image",
3410 "-thumbnail geometry create a thumbnail of the image",
3411 "-tile filename tile image when filling a graphic primitive",
3412 "-tint value tint the image with the fill color",
3413 "-transform affine transform image",
3414 "-transparent color make this color transparent within the image",
3415 "-transpose flip image vertically and rotate 90 degrees",
3416 "-transverse flop image horizontally and rotate 270 degrees",
3417 "-trim trim image edges",
3418 "-type type image type",
3419 "-unique-colors discard all but one of any pixel color",
3420 "-unsharp geometry sharpen the image",
3421 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003422 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003423 "-white-threshold value",
3424 " force all pixels above the threshold into white",
3425 (char *) NULL
3426 },
3427 *sequence_operators[]=
3428 {
cristy4285d782011-02-09 20:12:28 +00003429 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003430 "-clut apply a color lookup table to the image",
3431 "-coalesce merge a sequence of images",
3432 "-combine combine a sequence of images",
3433 "-composite composite image",
3434 "-crop geometry cut out a rectangular region of the image",
3435 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003436 "-evaluate-sequence operator",
3437 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003438 "-flatten flatten a sequence of images",
3439 "-fx expression apply mathematical expression to an image channel(s)",
3440 "-hald-clut apply a Hald color lookup table to the image",
3441 "-morph value morph an image sequence",
3442 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003443 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003444 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003445 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003446 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003447 "-write filename write images to this file",
3448 (char *) NULL
3449 },
3450 *settings[]=
3451 {
3452 "-adjoin join images into a single multi-image file",
3453 "-affine matrix affine transform matrix",
3454 "-alpha option activate, deactivate, reset, or set the alpha channel",
3455 "-antialias remove pixel-aliasing",
3456 "-authenticate password",
3457 " decipher image with this password",
3458 "-attenuate value lessen (or intensify) when adding noise to an image",
3459 "-background color background color",
3460 "-bias value add bias when convolving an image",
3461 "-black-point-compensation",
3462 " use black point compensation",
3463 "-blue-primary point chromaticity blue primary point",
3464 "-bordercolor color border color",
3465 "-caption string assign a caption to an image",
3466 "-channel type apply option to select image channels",
3467 "-colors value preferred number of colors in the image",
3468 "-colorspace type alternate image colorspace",
3469 "-comment string annotate image with comment",
3470 "-compose operator set image composite operator",
3471 "-compress type type of pixel compression when writing the image",
anthonyfd706f92012-01-19 04:22:02 +00003472 "-define format:option=value",
cristy3ed852e2009-09-05 21:47:34 +00003473 " define one or more image format options",
3474 "-delay value display the next image after pausing",
3475 "-density geometry horizontal and vertical density of the image",
3476 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003477 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003478 "-display server get image or font from this X server",
3479 "-dispose method layer disposal method",
3480 "-dither method apply error diffusion to image",
3481 "-encoding type text encoding type",
3482 "-endian type endianness (MSB or LSB) of the image",
3483 "-family name render text with this font family",
3484 "-fill color color to use when filling a graphic primitive",
3485 "-filter type use this filter when resizing an image",
3486 "-font name render text with this font",
anthonyfd706f92012-01-19 04:22:02 +00003487 "-format \"string\" output formatted image characteristics",
cristy3ed852e2009-09-05 21:47:34 +00003488 "-fuzz distance colors within this distance are considered equal",
3489 "-gravity type horizontal and vertical text placement",
3490 "-green-primary point chromaticity green primary point",
3491 "-intent type type of rendering intent when managing the image color",
3492 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003493 "-interline-spacing value",
3494 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003495 "-interpolate method pixel color interpolation method",
3496 "-interword-spacing value",
3497 " set the space between two words",
3498 "-kerning value set the space between two letters",
3499 "-label string assign a label to an image",
3500 "-limit type value pixel cache resource limit",
3501 "-loop iterations add Netscape loop extension to your GIF animation",
3502 "-mask filename associate a mask with the image",
3503 "-mattecolor color frame color",
3504 "-monitor monitor progress",
3505 "-orient type image orientation",
3506 "-page geometry size and location of an image canvas (setting)",
3507 "-ping efficiently determine image attributes",
3508 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003509 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003510 "-preview type image preview type",
3511 "-quality value JPEG/MIFF/PNG compression level",
3512 "-quiet suppress all warning messages",
3513 "-red-primary point chromaticity red primary point",
3514 "-regard-warnings pay attention to warning messages",
3515 "-remap filename transform image colors to match this set of colors",
3516 "-respect-parentheses settings remain in effect until parenthesis boundary",
3517 "-sampling-factor geometry",
3518 " horizontal and vertical sampling factor",
3519 "-scene value image scene number",
3520 "-seed value seed a new sequence of pseudo-random numbers",
3521 "-size geometry width and height of image",
3522 "-stretch type render text with this font stretch",
3523 "-stroke color graphic primitive stroke color",
3524 "-strokewidth value graphic primitive stroke width",
3525 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003526 "-synchronize synchronize image to storage device",
3527 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003528 "-texture filename name of texture to tile onto the image background",
3529 "-tile-offset geometry",
3530 " tile offset",
3531 "-treedepth value color tree depth",
3532 "-transparent-color color",
3533 " transparent color",
3534 "-undercolor color annotation bounding box color",
3535 "-units type the units of image resolution",
3536 "-verbose print detailed information about the image",
3537 "-view FlashPix viewing transforms",
3538 "-virtual-pixel method",
3539 " virtual pixel access method",
3540 "-weight type render text with this font weight",
3541 "-white-point point chromaticity white point",
3542 (char *) NULL
3543 },
3544 *stack_operators[]=
3545 {
anthonyb69c4b32011-03-23 04:37:44 +00003546 "-delete indexes delete the image from the image sequence",
3547 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003548 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003549 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003550 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003551 "-swap indexes swap two images in the image sequence",
3552 (char *) NULL
3553 };
3554
3555 const char
3556 **p;
3557
cristybb503372010-05-27 20:51:26 +00003558 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003559 (void) printf("Copyright: %s\n",GetMagickCopyright());
3560 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003561 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3562 GetClientName());
3563 (void) printf("\nImage Settings:\n");
3564 for (p=settings; *p != (char *) NULL; p++)
3565 (void) printf(" %s\n",*p);
3566 (void) printf("\nImage Operators:\n");
3567 for (p=operators; *p != (char *) NULL; p++)
3568 (void) printf(" %s\n",*p);
cristy87c02f42012-02-24 00:19:10 +00003569 (void) printf("\nImage Channel Operators:\n");
3570 for (p=channel_operators; *p != (char *) NULL; p++)
3571 (void) printf(" %s\n",*p);
cristy3ed852e2009-09-05 21:47:34 +00003572 (void) printf("\nImage Sequence Operators:\n");
3573 for (p=sequence_operators; *p != (char *) NULL; p++)
3574 (void) printf(" %s\n",*p);
3575 (void) printf("\nImage Stack Operators:\n");
3576 for (p=stack_operators; *p != (char *) NULL; p++)
3577 (void) printf(" %s\n",*p);
3578 (void) printf("\nMiscellaneous Options:\n");
3579 for (p=miscellaneous; *p != (char *) NULL; p++)
3580 (void) printf(" %s\n",*p);
3581 (void) printf(
anthonyfd706f92012-01-19 04:22:02 +00003582 "\nBy default, the image format of 'file' is determined by its magic\n");
cristy3ed852e2009-09-05 21:47:34 +00003583 (void) printf(
3584 "number. To specify a particular image format, precede the filename\n");
3585 (void) printf(
3586 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3587 (void) printf(
3588 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3589 (void) printf("'-' for standard input or output.\n");
3590 return(MagickFalse);
3591}
3592
3593WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3594 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3595{
3596#define DestroyMogrify() \
3597{ \
3598 if (format != (char *) NULL) \
3599 format=DestroyString(format); \
3600 if (path != (char *) NULL) \
3601 path=DestroyString(path); \
3602 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003603 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003604 argv[i]=DestroyString(argv[i]); \
3605 argv=(char **) RelinquishMagickMemory(argv); \
3606}
3607#define ThrowMogrifyException(asperity,tag,option) \
3608{ \
3609 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3610 option); \
3611 DestroyMogrify(); \
3612 return(MagickFalse); \
3613}
3614#define ThrowMogrifyInvalidArgumentException(option,argument) \
3615{ \
3616 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3617 "InvalidArgument","`%s': %s",argument,option); \
3618 DestroyMogrify(); \
3619 return(MagickFalse); \
3620}
3621
3622 char
3623 *format,
3624 *option,
3625 *path;
3626
3627 Image
3628 *image;
3629
3630 ImageStack
3631 image_stack[MaxImageStackDepth+1];
3632
cristy3ed852e2009-09-05 21:47:34 +00003633 MagickBooleanType
3634 global_colormap;
3635
3636 MagickBooleanType
3637 fire,
cristyebbcfea2011-02-25 02:43:54 +00003638 pend,
3639 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003640
3641 MagickStatusType
3642 status;
3643
cristyebbcfea2011-02-25 02:43:54 +00003644 register ssize_t
3645 i;
3646
3647 ssize_t
3648 j,
3649 k;
3650
cristy3ed852e2009-09-05 21:47:34 +00003651 /*
3652 Set defaults.
3653 */
3654 assert(image_info != (ImageInfo *) NULL);
3655 assert(image_info->signature == MagickSignature);
3656 if (image_info->debug != MagickFalse)
3657 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3658 assert(exception != (ExceptionInfo *) NULL);
3659 if (argc == 2)
3660 {
3661 option=argv[1];
3662 if ((LocaleCompare("version",option+1) == 0) ||
3663 (LocaleCompare("-version",option+1) == 0))
3664 {
cristyb51dff52011-05-19 16:55:47 +00003665 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003666 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003667 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3668 GetMagickCopyright());
3669 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3670 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003671 return(MagickFalse);
3672 }
3673 }
3674 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003675 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003676 format=(char *) NULL;
3677 path=(char *) NULL;
3678 global_colormap=MagickFalse;
3679 k=0;
3680 j=1;
3681 NewImageStack();
3682 option=(char *) NULL;
3683 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003684 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003685 status=MagickTrue;
3686 /*
3687 Parse command line.
3688 */
3689 ReadCommandlLine(argc,&argv);
3690 status=ExpandFilenames(&argc,&argv);
3691 if (status == MagickFalse)
3692 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3693 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003694 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003695 {
3696 option=argv[i];
3697 if (LocaleCompare(option,"(") == 0)
3698 {
3699 FireImageStack(MagickFalse,MagickTrue,pend);
3700 if (k == MaxImageStackDepth)
3701 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3702 option);
3703 PushImageStack();
3704 continue;
3705 }
3706 if (LocaleCompare(option,")") == 0)
3707 {
3708 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3709 if (k == 0)
3710 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3711 PopImageStack();
3712 continue;
3713 }
cristy042ee782011-04-22 18:48:30 +00003714 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003715 {
3716 char
3717 backup_filename[MaxTextExtent],
3718 *filename;
3719
3720 Image
3721 *images;
3722
3723 /*
3724 Option is a file name: begin by reading image from specified file.
3725 */
3726 FireImageStack(MagickFalse,MagickFalse,pend);
3727 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003728 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003729 filename=argv[++i];
cristy1b58f252012-03-01 01:41:41 +00003730 images=ReadImages(image_info,filename,exception);
cristy3ed852e2009-09-05 21:47:34 +00003731 status&=(images != (Image *) NULL) &&
3732 (exception->severity < ErrorException);
3733 if (images == (Image *) NULL)
3734 continue;
cristydaa76602010-06-30 13:05:11 +00003735 if (format != (char *) NULL)
3736 (void) CopyMagickString(images->filename,images->magick_filename,
3737 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003738 if (path != (char *) NULL)
3739 {
3740 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003741 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003742 path,*DirectorySeparator,filename);
3743 }
3744 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003745 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003746 AppendImageStack(images);
3747 FinalizeImageSettings(image_info,image,MagickFalse);
3748 if (global_colormap != MagickFalse)
3749 {
3750 QuantizeInfo
3751 *quantize_info;
3752
3753 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003754 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003755 quantize_info=DestroyQuantizeInfo(quantize_info);
3756 }
3757 *backup_filename='\0';
3758 if ((LocaleCompare(image->filename,"-") != 0) &&
3759 (IsPathWritable(image->filename) != MagickFalse))
3760 {
cristybb503372010-05-27 20:51:26 +00003761 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003762 i;
3763
3764 /*
3765 Rename image file as backup.
3766 */
3767 (void) CopyMagickString(backup_filename,image->filename,
3768 MaxTextExtent);
3769 for (i=0; i < 6; i++)
3770 {
3771 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3772 if (IsPathAccessible(backup_filename) == MagickFalse)
3773 break;
3774 }
3775 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003776 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003777 *backup_filename='\0';
3778 }
3779 /*
3780 Write transmogrified image to disk.
3781 */
3782 image_info->synchronize=MagickTrue;
3783 status&=WriteImages(image_info,image,image->filename,exception);
3784 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003785 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003786 RemoveAllImageStack();
3787 continue;
3788 }
3789 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3790 switch (*(option+1))
3791 {
3792 case 'a':
3793 {
3794 if (LocaleCompare("adaptive-blur",option+1) == 0)
3795 {
3796 i++;
cristybb503372010-05-27 20:51:26 +00003797 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003798 ThrowMogrifyException(OptionError,"MissingArgument",option);
3799 if (IsGeometry(argv[i]) == MagickFalse)
3800 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3801 break;
3802 }
3803 if (LocaleCompare("adaptive-resize",option+1) == 0)
3804 {
3805 i++;
cristybb503372010-05-27 20:51:26 +00003806 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003807 ThrowMogrifyException(OptionError,"MissingArgument",option);
3808 if (IsGeometry(argv[i]) == MagickFalse)
3809 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3810 break;
3811 }
3812 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3813 {
3814 i++;
cristybb503372010-05-27 20:51:26 +00003815 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003816 ThrowMogrifyException(OptionError,"MissingArgument",option);
3817 if (IsGeometry(argv[i]) == MagickFalse)
3818 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3819 break;
3820 }
3821 if (LocaleCompare("affine",option+1) == 0)
3822 {
3823 if (*option == '+')
3824 break;
3825 i++;
cristybb503372010-05-27 20:51:26 +00003826 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003827 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003828 break;
3829 }
3830 if (LocaleCompare("alpha",option+1) == 0)
3831 {
cristybb503372010-05-27 20:51:26 +00003832 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003833 type;
3834
3835 if (*option == '+')
3836 break;
3837 i++;
cristybb503372010-05-27 20:51:26 +00003838 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003839 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003840 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003841 if (type < 0)
3842 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3843 argv[i]);
3844 break;
3845 }
3846 if (LocaleCompare("annotate",option+1) == 0)
3847 {
3848 if (*option == '+')
3849 break;
3850 i++;
cristybb503372010-05-27 20:51:26 +00003851 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003852 ThrowMogrifyException(OptionError,"MissingArgument",option);
3853 if (IsGeometry(argv[i]) == MagickFalse)
3854 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003855 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003856 ThrowMogrifyException(OptionError,"MissingArgument",option);
3857 i++;
3858 break;
3859 }
3860 if (LocaleCompare("antialias",option+1) == 0)
3861 break;
3862 if (LocaleCompare("append",option+1) == 0)
3863 break;
3864 if (LocaleCompare("attenuate",option+1) == 0)
3865 {
3866 if (*option == '+')
3867 break;
3868 i++;
cristybb503372010-05-27 20:51:26 +00003869 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003870 ThrowMogrifyException(OptionError,"MissingArgument",option);
3871 if (IsGeometry(argv[i]) == MagickFalse)
3872 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3873 break;
3874 }
3875 if (LocaleCompare("authenticate",option+1) == 0)
3876 {
3877 if (*option == '+')
3878 break;
3879 i++;
cristybb503372010-05-27 20:51:26 +00003880 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003881 ThrowMogrifyException(OptionError,"MissingArgument",option);
3882 break;
3883 }
3884 if (LocaleCompare("auto-gamma",option+1) == 0)
3885 break;
3886 if (LocaleCompare("auto-level",option+1) == 0)
3887 break;
3888 if (LocaleCompare("auto-orient",option+1) == 0)
3889 break;
3890 if (LocaleCompare("average",option+1) == 0)
3891 break;
3892 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3893 }
3894 case 'b':
3895 {
3896 if (LocaleCompare("background",option+1) == 0)
3897 {
3898 if (*option == '+')
3899 break;
3900 i++;
cristybb503372010-05-27 20:51:26 +00003901 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003902 ThrowMogrifyException(OptionError,"MissingArgument",option);
3903 break;
3904 }
3905 if (LocaleCompare("bias",option+1) == 0)
3906 {
3907 if (*option == '+')
3908 break;
3909 i++;
cristybb503372010-05-27 20:51:26 +00003910 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003911 ThrowMogrifyException(OptionError,"MissingArgument",option);
3912 if (IsGeometry(argv[i]) == MagickFalse)
3913 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3914 break;
3915 }
3916 if (LocaleCompare("black-point-compensation",option+1) == 0)
3917 break;
3918 if (LocaleCompare("black-threshold",option+1) == 0)
3919 {
3920 if (*option == '+')
3921 break;
3922 i++;
cristybb503372010-05-27 20:51:26 +00003923 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003924 ThrowMogrifyException(OptionError,"MissingArgument",option);
3925 if (IsGeometry(argv[i]) == MagickFalse)
3926 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3927 break;
3928 }
3929 if (LocaleCompare("blue-primary",option+1) == 0)
3930 {
3931 if (*option == '+')
3932 break;
3933 i++;
cristybb503372010-05-27 20:51:26 +00003934 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003935 ThrowMogrifyException(OptionError,"MissingArgument",option);
3936 if (IsGeometry(argv[i]) == MagickFalse)
3937 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3938 break;
3939 }
3940 if (LocaleCompare("blue-shift",option+1) == 0)
3941 {
3942 i++;
cristybb503372010-05-27 20:51:26 +00003943 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003944 ThrowMogrifyException(OptionError,"MissingArgument",option);
3945 if (IsGeometry(argv[i]) == MagickFalse)
3946 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3947 break;
3948 }
3949 if (LocaleCompare("blur",option+1) == 0)
3950 {
3951 i++;
cristybb503372010-05-27 20:51:26 +00003952 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003953 ThrowMogrifyException(OptionError,"MissingArgument",option);
3954 if (IsGeometry(argv[i]) == MagickFalse)
3955 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3956 break;
3957 }
3958 if (LocaleCompare("border",option+1) == 0)
3959 {
3960 if (*option == '+')
3961 break;
3962 i++;
cristybb503372010-05-27 20:51:26 +00003963 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003964 ThrowMogrifyException(OptionError,"MissingArgument",option);
3965 if (IsGeometry(argv[i]) == MagickFalse)
3966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3967 break;
3968 }
3969 if (LocaleCompare("bordercolor",option+1) == 0)
3970 {
3971 if (*option == '+')
3972 break;
3973 i++;
cristybb503372010-05-27 20:51:26 +00003974 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003975 ThrowMogrifyException(OptionError,"MissingArgument",option);
3976 break;
3977 }
3978 if (LocaleCompare("box",option+1) == 0)
3979 {
3980 if (*option == '+')
3981 break;
3982 i++;
cristybb503372010-05-27 20:51:26 +00003983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003984 ThrowMogrifyException(OptionError,"MissingArgument",option);
3985 break;
3986 }
cristya28d6b82010-01-11 20:03:47 +00003987 if (LocaleCompare("brightness-contrast",option+1) == 0)
3988 {
3989 i++;
cristybb503372010-05-27 20:51:26 +00003990 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00003991 ThrowMogrifyException(OptionError,"MissingArgument",option);
3992 if (IsGeometry(argv[i]) == MagickFalse)
3993 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3994 break;
3995 }
cristy3ed852e2009-09-05 21:47:34 +00003996 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3997 }
3998 case 'c':
3999 {
4000 if (LocaleCompare("cache",option+1) == 0)
4001 {
4002 if (*option == '+')
4003 break;
4004 i++;
cristybb503372010-05-27 20:51:26 +00004005 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004006 ThrowMogrifyException(OptionError,"MissingArgument",option);
4007 if (IsGeometry(argv[i]) == MagickFalse)
4008 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4009 break;
4010 }
4011 if (LocaleCompare("caption",option+1) == 0)
4012 {
4013 if (*option == '+')
4014 break;
4015 i++;
cristybb503372010-05-27 20:51:26 +00004016 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004017 ThrowMogrifyException(OptionError,"MissingArgument",option);
4018 break;
4019 }
4020 if (LocaleCompare("channel",option+1) == 0)
4021 {
cristybb503372010-05-27 20:51:26 +00004022 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004023 channel;
4024
4025 if (*option == '+')
4026 break;
4027 i++;
cristybb503372010-05-27 20:51:26 +00004028 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004029 ThrowMogrifyException(OptionError,"MissingArgument",option);
4030 channel=ParseChannelOption(argv[i]);
4031 if (channel < 0)
4032 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4033 argv[i]);
4034 break;
4035 }
cristyd04e7bf2012-03-03 19:19:12 +00004036 if (LocaleCompare("channel-ops",option+1) == 0)
cristy87c02f42012-02-24 00:19:10 +00004037 {
4038 ssize_t
4039 channel;
4040
4041 if (*option == '+')
4042 break;
4043 i++;
4044 if (i == (ssize_t) (argc-1))
4045 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy953c4bd2012-02-24 01:04:04 +00004046 channel=ParsePixelChannelOption(argv[i]);
cristy87c02f42012-02-24 00:19:10 +00004047 if (channel < 0)
4048 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4049 argv[i]);
4050 break;
4051 }
cristy3ed852e2009-09-05 21:47:34 +00004052 if (LocaleCompare("cdl",option+1) == 0)
4053 {
4054 if (*option == '+')
4055 break;
4056 i++;
cristybb503372010-05-27 20:51:26 +00004057 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004058 ThrowMogrifyException(OptionError,"MissingArgument",option);
4059 break;
4060 }
4061 if (LocaleCompare("charcoal",option+1) == 0)
4062 {
4063 if (*option == '+')
4064 break;
4065 i++;
cristybb503372010-05-27 20:51:26 +00004066 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004067 ThrowMogrifyException(OptionError,"MissingArgument",option);
4068 if (IsGeometry(argv[i]) == MagickFalse)
4069 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4070 break;
4071 }
4072 if (LocaleCompare("chop",option+1) == 0)
4073 {
4074 if (*option == '+')
4075 break;
4076 i++;
cristybb503372010-05-27 20:51:26 +00004077 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004078 ThrowMogrifyException(OptionError,"MissingArgument",option);
4079 if (IsGeometry(argv[i]) == MagickFalse)
4080 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4081 break;
4082 }
cristy1eb45dd2009-09-25 16:38:06 +00004083 if (LocaleCompare("clamp",option+1) == 0)
4084 break;
4085 if (LocaleCompare("clip",option+1) == 0)
4086 break;
cristy3ed852e2009-09-05 21:47:34 +00004087 if (LocaleCompare("clip-mask",option+1) == 0)
4088 {
4089 if (*option == '+')
4090 break;
4091 i++;
cristybb503372010-05-27 20:51:26 +00004092 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004093 ThrowMogrifyException(OptionError,"MissingArgument",option);
4094 break;
4095 }
4096 if (LocaleCompare("clut",option+1) == 0)
4097 break;
4098 if (LocaleCompare("coalesce",option+1) == 0)
4099 break;
4100 if (LocaleCompare("colorize",option+1) == 0)
4101 {
4102 if (*option == '+')
4103 break;
4104 i++;
cristybb503372010-05-27 20:51:26 +00004105 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004106 ThrowMogrifyException(OptionError,"MissingArgument",option);
4107 if (IsGeometry(argv[i]) == MagickFalse)
4108 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4109 break;
4110 }
cristye6365592010-04-02 17:31:23 +00004111 if (LocaleCompare("color-matrix",option+1) == 0)
4112 {
cristyb6bd4ad2010-08-08 01:12:27 +00004113 KernelInfo
4114 *kernel_info;
4115
cristye6365592010-04-02 17:31:23 +00004116 if (*option == '+')
4117 break;
4118 i++;
cristybb503372010-05-27 20:51:26 +00004119 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004120 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004121 kernel_info=AcquireKernelInfo(argv[i]);
4122 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004123 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004124 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004125 break;
4126 }
cristy3ed852e2009-09-05 21:47:34 +00004127 if (LocaleCompare("colors",option+1) == 0)
4128 {
4129 if (*option == '+')
4130 break;
4131 i++;
cristybb503372010-05-27 20:51:26 +00004132 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004133 ThrowMogrifyException(OptionError,"MissingArgument",option);
4134 if (IsGeometry(argv[i]) == MagickFalse)
4135 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4136 break;
4137 }
4138 if (LocaleCompare("colorspace",option+1) == 0)
4139 {
cristybb503372010-05-27 20:51:26 +00004140 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004141 colorspace;
4142
4143 if (*option == '+')
4144 break;
4145 i++;
cristybb503372010-05-27 20:51:26 +00004146 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004147 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004148 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004149 argv[i]);
4150 if (colorspace < 0)
4151 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4152 argv[i]);
4153 break;
4154 }
4155 if (LocaleCompare("combine",option+1) == 0)
4156 break;
4157 if (LocaleCompare("comment",option+1) == 0)
4158 {
4159 if (*option == '+')
4160 break;
4161 i++;
cristybb503372010-05-27 20:51:26 +00004162 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004163 ThrowMogrifyException(OptionError,"MissingArgument",option);
4164 break;
4165 }
4166 if (LocaleCompare("composite",option+1) == 0)
4167 break;
4168 if (LocaleCompare("compress",option+1) == 0)
4169 {
cristybb503372010-05-27 20:51:26 +00004170 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004171 compress;
4172
4173 if (*option == '+')
4174 break;
4175 i++;
cristybb503372010-05-27 20:51:26 +00004176 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004177 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004178 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004179 argv[i]);
4180 if (compress < 0)
4181 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4182 argv[i]);
4183 break;
4184 }
cristy22879752009-10-25 23:55:40 +00004185 if (LocaleCompare("concurrent",option+1) == 0)
4186 break;
cristy3ed852e2009-09-05 21:47:34 +00004187 if (LocaleCompare("contrast",option+1) == 0)
4188 break;
4189 if (LocaleCompare("contrast-stretch",option+1) == 0)
4190 {
4191 i++;
cristybb503372010-05-27 20:51:26 +00004192 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004193 ThrowMogrifyException(OptionError,"MissingArgument",option);
4194 if (IsGeometry(argv[i]) == MagickFalse)
4195 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4196 break;
4197 }
4198 if (LocaleCompare("convolve",option+1) == 0)
4199 {
cristyb6bd4ad2010-08-08 01:12:27 +00004200 KernelInfo
4201 *kernel_info;
4202
cristy3ed852e2009-09-05 21:47:34 +00004203 if (*option == '+')
4204 break;
4205 i++;
cristybb503372010-05-27 20:51:26 +00004206 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004207 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004208 kernel_info=AcquireKernelInfo(argv[i]);
4209 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004210 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004211 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004212 break;
4213 }
4214 if (LocaleCompare("crop",option+1) == 0)
4215 {
4216 if (*option == '+')
4217 break;
4218 i++;
cristybb503372010-05-27 20:51:26 +00004219 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004220 ThrowMogrifyException(OptionError,"MissingArgument",option);
4221 if (IsGeometry(argv[i]) == MagickFalse)
4222 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4223 break;
4224 }
4225 if (LocaleCompare("cycle",option+1) == 0)
4226 {
4227 if (*option == '+')
4228 break;
4229 i++;
cristybb503372010-05-27 20:51:26 +00004230 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004231 ThrowMogrifyException(OptionError,"MissingArgument",option);
4232 if (IsGeometry(argv[i]) == MagickFalse)
4233 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4234 break;
4235 }
4236 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4237 }
4238 case 'd':
4239 {
4240 if (LocaleCompare("decipher",option+1) == 0)
4241 {
4242 if (*option == '+')
4243 break;
4244 i++;
cristybb503372010-05-27 20:51:26 +00004245 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004246 ThrowMogrifyException(OptionError,"MissingArgument",option);
4247 break;
4248 }
4249 if (LocaleCompare("deconstruct",option+1) == 0)
4250 break;
4251 if (LocaleCompare("debug",option+1) == 0)
4252 {
cristybb503372010-05-27 20:51:26 +00004253 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004254 event;
4255
4256 if (*option == '+')
4257 break;
4258 i++;
cristybb503372010-05-27 20:51:26 +00004259 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004260 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004261 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004262 if (event < 0)
4263 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4264 argv[i]);
4265 (void) SetLogEventMask(argv[i]);
4266 break;
4267 }
4268 if (LocaleCompare("define",option+1) == 0)
4269 {
4270 i++;
cristybb503372010-05-27 20:51:26 +00004271 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004272 ThrowMogrifyException(OptionError,"MissingArgument",option);
4273 if (*option == '+')
4274 {
4275 const char
4276 *define;
4277
4278 define=GetImageOption(image_info,argv[i]);
4279 if (define == (const char *) NULL)
4280 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4281 break;
4282 }
4283 break;
4284 }
4285 if (LocaleCompare("delay",option+1) == 0)
4286 {
4287 if (*option == '+')
4288 break;
4289 i++;
cristybb503372010-05-27 20:51:26 +00004290 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004291 ThrowMogrifyException(OptionError,"MissingArgument",option);
4292 if (IsGeometry(argv[i]) == MagickFalse)
4293 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4294 break;
4295 }
cristyecb10ff2011-03-22 13:14:03 +00004296 if (LocaleCompare("delete",option+1) == 0)
4297 {
4298 if (*option == '+')
4299 break;
4300 i++;
4301 if (i == (ssize_t) (argc-1))
4302 ThrowMogrifyException(OptionError,"MissingArgument",option);
4303 if (IsGeometry(argv[i]) == MagickFalse)
4304 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4305 break;
4306 }
cristy3ed852e2009-09-05 21:47:34 +00004307 if (LocaleCompare("density",option+1) == 0)
4308 {
4309 if (*option == '+')
4310 break;
4311 i++;
cristybb503372010-05-27 20:51:26 +00004312 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004313 ThrowMogrifyException(OptionError,"MissingArgument",option);
4314 if (IsGeometry(argv[i]) == MagickFalse)
4315 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4316 break;
4317 }
4318 if (LocaleCompare("depth",option+1) == 0)
4319 {
4320 if (*option == '+')
4321 break;
4322 i++;
cristybb503372010-05-27 20:51:26 +00004323 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004324 ThrowMogrifyException(OptionError,"MissingArgument",option);
4325 if (IsGeometry(argv[i]) == MagickFalse)
4326 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4327 break;
4328 }
4329 if (LocaleCompare("deskew",option+1) == 0)
4330 {
4331 if (*option == '+')
4332 break;
4333 i++;
cristybb503372010-05-27 20:51:26 +00004334 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004335 ThrowMogrifyException(OptionError,"MissingArgument",option);
4336 if (IsGeometry(argv[i]) == MagickFalse)
4337 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4338 break;
4339 }
4340 if (LocaleCompare("despeckle",option+1) == 0)
4341 break;
4342 if (LocaleCompare("dft",option+1) == 0)
4343 break;
cristyc9b12952010-03-28 01:12:28 +00004344 if (LocaleCompare("direction",option+1) == 0)
4345 {
cristybb503372010-05-27 20:51:26 +00004346 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004347 direction;
4348
4349 if (*option == '+')
4350 break;
4351 i++;
cristybb503372010-05-27 20:51:26 +00004352 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004353 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004354 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004355 argv[i]);
4356 if (direction < 0)
4357 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4358 argv[i]);
4359 break;
4360 }
cristy3ed852e2009-09-05 21:47:34 +00004361 if (LocaleCompare("display",option+1) == 0)
4362 {
4363 if (*option == '+')
4364 break;
4365 i++;
cristybb503372010-05-27 20:51:26 +00004366 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004367 ThrowMogrifyException(OptionError,"MissingArgument",option);
4368 break;
4369 }
4370 if (LocaleCompare("dispose",option+1) == 0)
4371 {
cristybb503372010-05-27 20:51:26 +00004372 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004373 dispose;
4374
4375 if (*option == '+')
4376 break;
4377 i++;
cristybb503372010-05-27 20:51:26 +00004378 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004379 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004380 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004381 if (dispose < 0)
4382 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4383 argv[i]);
4384 break;
4385 }
4386 if (LocaleCompare("distort",option+1) == 0)
4387 {
cristybb503372010-05-27 20:51:26 +00004388 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004389 op;
4390
4391 i++;
cristybb503372010-05-27 20:51:26 +00004392 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004393 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004394 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004395 if (op < 0)
4396 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4397 argv[i]);
4398 i++;
cristybb503372010-05-27 20:51:26 +00004399 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004400 ThrowMogrifyException(OptionError,"MissingArgument",option);
4401 break;
4402 }
4403 if (LocaleCompare("dither",option+1) == 0)
4404 {
cristybb503372010-05-27 20:51:26 +00004405 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004406 method;
4407
4408 if (*option == '+')
4409 break;
4410 i++;
cristybb503372010-05-27 20:51:26 +00004411 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004412 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004413 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004414 if (method < 0)
4415 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4416 argv[i]);
4417 break;
4418 }
4419 if (LocaleCompare("draw",option+1) == 0)
4420 {
4421 if (*option == '+')
4422 break;
4423 i++;
cristybb503372010-05-27 20:51:26 +00004424 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004425 ThrowMogrifyException(OptionError,"MissingArgument",option);
4426 break;
4427 }
cristyecb10ff2011-03-22 13:14:03 +00004428 if (LocaleCompare("duplicate",option+1) == 0)
4429 {
4430 if (*option == '+')
4431 break;
4432 i++;
4433 if (i == (ssize_t) (argc-1))
4434 ThrowMogrifyException(OptionError,"MissingArgument",option);
4435 if (IsGeometry(argv[i]) == MagickFalse)
4436 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4437 break;
4438 }
cristy22879752009-10-25 23:55:40 +00004439 if (LocaleCompare("duration",option+1) == 0)
4440 {
4441 if (*option == '+')
4442 break;
4443 i++;
cristybb503372010-05-27 20:51:26 +00004444 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004445 ThrowMogrifyException(OptionError,"MissingArgument",option);
4446 if (IsGeometry(argv[i]) == MagickFalse)
4447 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4448 break;
4449 }
cristy3ed852e2009-09-05 21:47:34 +00004450 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4451 }
4452 case 'e':
4453 {
4454 if (LocaleCompare("edge",option+1) == 0)
4455 {
4456 if (*option == '+')
4457 break;
4458 i++;
cristybb503372010-05-27 20:51:26 +00004459 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004460 ThrowMogrifyException(OptionError,"MissingArgument",option);
4461 if (IsGeometry(argv[i]) == MagickFalse)
4462 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4463 break;
4464 }
4465 if (LocaleCompare("emboss",option+1) == 0)
4466 {
4467 if (*option == '+')
4468 break;
4469 i++;
cristybb503372010-05-27 20:51:26 +00004470 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004471 ThrowMogrifyException(OptionError,"MissingArgument",option);
4472 if (IsGeometry(argv[i]) == MagickFalse)
4473 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4474 break;
4475 }
4476 if (LocaleCompare("encipher",option+1) == 0)
4477 {
4478 if (*option == '+')
4479 break;
4480 i++;
cristybb503372010-05-27 20:51:26 +00004481 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004482 ThrowMogrifyException(OptionError,"MissingArgument",option);
4483 break;
4484 }
4485 if (LocaleCompare("encoding",option+1) == 0)
4486 {
4487 if (*option == '+')
4488 break;
4489 i++;
cristybb503372010-05-27 20:51:26 +00004490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004491 ThrowMogrifyException(OptionError,"MissingArgument",option);
4492 break;
4493 }
4494 if (LocaleCompare("endian",option+1) == 0)
4495 {
cristybb503372010-05-27 20:51:26 +00004496 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004497 endian;
4498
4499 if (*option == '+')
4500 break;
4501 i++;
cristybb503372010-05-27 20:51:26 +00004502 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004503 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004504 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004505 if (endian < 0)
4506 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4507 argv[i]);
4508 break;
4509 }
4510 if (LocaleCompare("enhance",option+1) == 0)
4511 break;
4512 if (LocaleCompare("equalize",option+1) == 0)
4513 break;
4514 if (LocaleCompare("evaluate",option+1) == 0)
4515 {
cristybb503372010-05-27 20:51:26 +00004516 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004517 op;
4518
4519 if (*option == '+')
4520 break;
4521 i++;
cristybb503372010-05-27 20:51:26 +00004522 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004523 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004524 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004525 if (op < 0)
4526 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4527 argv[i]);
4528 i++;
cristybb503372010-05-27 20:51:26 +00004529 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004530 ThrowMogrifyException(OptionError,"MissingArgument",option);
4531 if (IsGeometry(argv[i]) == MagickFalse)
4532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4533 break;
4534 }
cristyd18ae7c2010-03-07 17:39:52 +00004535 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4536 {
cristybb503372010-05-27 20:51:26 +00004537 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004538 op;
4539
4540 if (*option == '+')
4541 break;
4542 i++;
cristybb503372010-05-27 20:51:26 +00004543 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004544 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004545 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004546 if (op < 0)
4547 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4548 argv[i]);
4549 break;
4550 }
cristy3ed852e2009-09-05 21:47:34 +00004551 if (LocaleCompare("extent",option+1) == 0)
4552 {
4553 if (*option == '+')
4554 break;
4555 i++;
cristybb503372010-05-27 20:51:26 +00004556 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004557 ThrowMogrifyException(OptionError,"MissingArgument",option);
4558 if (IsGeometry(argv[i]) == MagickFalse)
4559 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4560 break;
4561 }
4562 if (LocaleCompare("extract",option+1) == 0)
4563 {
4564 if (*option == '+')
4565 break;
4566 i++;
cristybb503372010-05-27 20:51:26 +00004567 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004568 ThrowMogrifyException(OptionError,"MissingArgument",option);
4569 if (IsGeometry(argv[i]) == MagickFalse)
4570 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4571 break;
4572 }
4573 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4574 }
4575 case 'f':
4576 {
4577 if (LocaleCompare("family",option+1) == 0)
4578 {
4579 if (*option == '+')
4580 break;
4581 i++;
cristybb503372010-05-27 20:51:26 +00004582 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004583 ThrowMogrifyException(OptionError,"MissingArgument",option);
4584 break;
4585 }
4586 if (LocaleCompare("fill",option+1) == 0)
4587 {
4588 if (*option == '+')
4589 break;
4590 i++;
cristybb503372010-05-27 20:51:26 +00004591 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004592 ThrowMogrifyException(OptionError,"MissingArgument",option);
4593 break;
4594 }
4595 if (LocaleCompare("filter",option+1) == 0)
4596 {
cristybb503372010-05-27 20:51:26 +00004597 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004598 filter;
4599
4600 if (*option == '+')
4601 break;
4602 i++;
cristybb503372010-05-27 20:51:26 +00004603 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004604 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004605 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004606 if (filter < 0)
4607 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4608 argv[i]);
4609 break;
4610 }
4611 if (LocaleCompare("flatten",option+1) == 0)
4612 break;
4613 if (LocaleCompare("flip",option+1) == 0)
4614 break;
4615 if (LocaleCompare("flop",option+1) == 0)
4616 break;
4617 if (LocaleCompare("floodfill",option+1) == 0)
4618 {
4619 if (*option == '+')
4620 break;
4621 i++;
cristybb503372010-05-27 20:51:26 +00004622 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004623 ThrowMogrifyException(OptionError,"MissingArgument",option);
4624 if (IsGeometry(argv[i]) == MagickFalse)
4625 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4626 i++;
cristybb503372010-05-27 20:51:26 +00004627 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004628 ThrowMogrifyException(OptionError,"MissingArgument",option);
4629 break;
4630 }
4631 if (LocaleCompare("font",option+1) == 0)
4632 {
4633 if (*option == '+')
4634 break;
4635 i++;
cristybb503372010-05-27 20:51:26 +00004636 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004637 ThrowMogrifyException(OptionError,"MissingArgument",option);
4638 break;
4639 }
4640 if (LocaleCompare("format",option+1) == 0)
4641 {
4642 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4643 (void) CloneString(&format,(char *) NULL);
4644 if (*option == '+')
4645 break;
4646 i++;
cristybb503372010-05-27 20:51:26 +00004647 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004648 ThrowMogrifyException(OptionError,"MissingArgument",option);
4649 (void) CloneString(&format,argv[i]);
4650 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4651 (void) ConcatenateMagickString(image_info->filename,":",
4652 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004653 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004654 if (*image_info->magick == '\0')
4655 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4656 format);
4657 break;
4658 }
4659 if (LocaleCompare("frame",option+1) == 0)
4660 {
4661 if (*option == '+')
4662 break;
4663 i++;
cristybb503372010-05-27 20:51:26 +00004664 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004665 ThrowMogrifyException(OptionError,"MissingArgument",option);
4666 if (IsGeometry(argv[i]) == MagickFalse)
4667 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4668 break;
4669 }
4670 if (LocaleCompare("function",option+1) == 0)
4671 {
cristybb503372010-05-27 20:51:26 +00004672 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004673 op;
4674
4675 if (*option == '+')
4676 break;
4677 i++;
cristybb503372010-05-27 20:51:26 +00004678 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004679 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004680 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004681 if (op < 0)
4682 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4683 i++;
cristybb503372010-05-27 20:51:26 +00004684 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004685 ThrowMogrifyException(OptionError,"MissingArgument",option);
4686 break;
4687 }
4688 if (LocaleCompare("fuzz",option+1) == 0)
4689 {
4690 if (*option == '+')
4691 break;
4692 i++;
cristybb503372010-05-27 20:51:26 +00004693 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004694 ThrowMogrifyException(OptionError,"MissingArgument",option);
4695 if (IsGeometry(argv[i]) == MagickFalse)
4696 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4697 break;
4698 }
4699 if (LocaleCompare("fx",option+1) == 0)
4700 {
4701 if (*option == '+')
4702 break;
4703 i++;
cristybb503372010-05-27 20:51:26 +00004704 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004705 ThrowMogrifyException(OptionError,"MissingArgument",option);
4706 break;
4707 }
4708 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4709 }
4710 case 'g':
4711 {
4712 if (LocaleCompare("gamma",option+1) == 0)
4713 {
4714 i++;
cristybb503372010-05-27 20:51:26 +00004715 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004716 ThrowMogrifyException(OptionError,"MissingArgument",option);
4717 if (IsGeometry(argv[i]) == MagickFalse)
4718 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4719 break;
4720 }
4721 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4722 (LocaleCompare("gaussian",option+1) == 0))
4723 {
4724 i++;
cristybb503372010-05-27 20:51:26 +00004725 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004726 ThrowMogrifyException(OptionError,"MissingArgument",option);
4727 if (IsGeometry(argv[i]) == MagickFalse)
4728 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4729 break;
4730 }
4731 if (LocaleCompare("geometry",option+1) == 0)
4732 {
4733 if (*option == '+')
4734 break;
4735 i++;
cristybb503372010-05-27 20:51:26 +00004736 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004737 ThrowMogrifyException(OptionError,"MissingArgument",option);
4738 if (IsGeometry(argv[i]) == MagickFalse)
4739 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4740 break;
4741 }
4742 if (LocaleCompare("gravity",option+1) == 0)
4743 {
cristybb503372010-05-27 20:51:26 +00004744 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004745 gravity;
4746
4747 if (*option == '+')
4748 break;
4749 i++;
cristybb503372010-05-27 20:51:26 +00004750 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004751 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004752 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004753 if (gravity < 0)
4754 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4755 argv[i]);
4756 break;
4757 }
4758 if (LocaleCompare("green-primary",option+1) == 0)
4759 {
4760 if (*option == '+')
4761 break;
4762 i++;
cristybb503372010-05-27 20:51:26 +00004763 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004764 ThrowMogrifyException(OptionError,"MissingArgument",option);
4765 if (IsGeometry(argv[i]) == MagickFalse)
4766 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4767 break;
4768 }
4769 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4770 }
4771 case 'h':
4772 {
4773 if (LocaleCompare("hald-clut",option+1) == 0)
4774 break;
4775 if ((LocaleCompare("help",option+1) == 0) ||
4776 (LocaleCompare("-help",option+1) == 0))
4777 return(MogrifyUsage());
4778 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4779 }
4780 case 'i':
4781 {
4782 if (LocaleCompare("identify",option+1) == 0)
4783 break;
4784 if (LocaleCompare("idft",option+1) == 0)
4785 break;
4786 if (LocaleCompare("implode",option+1) == 0)
4787 {
4788 if (*option == '+')
4789 break;
4790 i++;
cristybb503372010-05-27 20:51:26 +00004791 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004792 ThrowMogrifyException(OptionError,"MissingArgument",option);
4793 if (IsGeometry(argv[i]) == MagickFalse)
4794 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4795 break;
4796 }
4797 if (LocaleCompare("intent",option+1) == 0)
4798 {
cristybb503372010-05-27 20:51:26 +00004799 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004800 intent;
4801
4802 if (*option == '+')
4803 break;
4804 i++;
cristybb503372010-05-27 20:51:26 +00004805 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004806 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004807 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004808 if (intent < 0)
4809 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4810 argv[i]);
4811 break;
4812 }
4813 if (LocaleCompare("interlace",option+1) == 0)
4814 {
cristybb503372010-05-27 20:51:26 +00004815 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004816 interlace;
4817
4818 if (*option == '+')
4819 break;
4820 i++;
cristybb503372010-05-27 20:51:26 +00004821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004822 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004823 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004824 argv[i]);
4825 if (interlace < 0)
4826 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4827 argv[i]);
4828 break;
4829 }
cristyb32b90a2009-09-07 21:45:48 +00004830 if (LocaleCompare("interline-spacing",option+1) == 0)
4831 {
4832 if (*option == '+')
4833 break;
4834 i++;
cristybb503372010-05-27 20:51:26 +00004835 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004836 ThrowMogrifyException(OptionError,"MissingArgument",option);
4837 if (IsGeometry(argv[i]) == MagickFalse)
4838 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4839 break;
4840 }
cristy3ed852e2009-09-05 21:47:34 +00004841 if (LocaleCompare("interpolate",option+1) == 0)
4842 {
cristybb503372010-05-27 20:51:26 +00004843 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004844 interpolate;
4845
4846 if (*option == '+')
4847 break;
4848 i++;
cristybb503372010-05-27 20:51:26 +00004849 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004850 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004851 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004852 argv[i]);
4853 if (interpolate < 0)
4854 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4855 argv[i]);
4856 break;
4857 }
4858 if (LocaleCompare("interword-spacing",option+1) == 0)
4859 {
4860 if (*option == '+')
4861 break;
4862 i++;
cristybb503372010-05-27 20:51:26 +00004863 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004864 ThrowMogrifyException(OptionError,"MissingArgument",option);
4865 if (IsGeometry(argv[i]) == MagickFalse)
4866 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4867 break;
4868 }
4869 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4870 }
4871 case 'k':
4872 {
4873 if (LocaleCompare("kerning",option+1) == 0)
4874 {
4875 if (*option == '+')
4876 break;
4877 i++;
cristybb503372010-05-27 20:51:26 +00004878 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004879 ThrowMogrifyException(OptionError,"MissingArgument",option);
4880 if (IsGeometry(argv[i]) == MagickFalse)
4881 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4882 break;
4883 }
4884 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4885 }
4886 case 'l':
4887 {
4888 if (LocaleCompare("label",option+1) == 0)
4889 {
4890 if (*option == '+')
4891 break;
4892 i++;
cristybb503372010-05-27 20:51:26 +00004893 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004894 ThrowMogrifyException(OptionError,"MissingArgument",option);
4895 break;
4896 }
4897 if (LocaleCompare("lat",option+1) == 0)
4898 {
4899 if (*option == '+')
4900 break;
4901 i++;
cristybb503372010-05-27 20:51:26 +00004902 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004903 ThrowMogrifyException(OptionError,"MissingArgument",option);
4904 if (IsGeometry(argv[i]) == MagickFalse)
4905 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4906 }
4907 if (LocaleCompare("layers",option+1) == 0)
4908 {
cristybb503372010-05-27 20:51:26 +00004909 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004910 type;
4911
4912 if (*option == '+')
4913 break;
4914 i++;
cristybb503372010-05-27 20:51:26 +00004915 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004916 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004917 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004918 if (type < 0)
4919 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4920 argv[i]);
4921 break;
4922 }
4923 if (LocaleCompare("level",option+1) == 0)
4924 {
4925 i++;
cristybb503372010-05-27 20:51:26 +00004926 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004927 ThrowMogrifyException(OptionError,"MissingArgument",option);
4928 if (IsGeometry(argv[i]) == MagickFalse)
4929 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4930 break;
4931 }
4932 if (LocaleCompare("level-colors",option+1) == 0)
4933 {
4934 i++;
cristybb503372010-05-27 20:51:26 +00004935 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004936 ThrowMogrifyException(OptionError,"MissingArgument",option);
4937 break;
4938 }
cristy3ed852e2009-09-05 21:47:34 +00004939 if (LocaleCompare("limit",option+1) == 0)
4940 {
4941 char
4942 *p;
4943
4944 double
4945 value;
4946
cristybb503372010-05-27 20:51:26 +00004947 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004948 resource;
4949
4950 if (*option == '+')
4951 break;
4952 i++;
cristybb503372010-05-27 20:51:26 +00004953 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004954 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004955 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004956 argv[i]);
4957 if (resource < 0)
4958 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4959 argv[i]);
4960 i++;
cristybb503372010-05-27 20:51:26 +00004961 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004962 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00004963 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00004964 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00004965 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4966 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4967 break;
4968 }
4969 if (LocaleCompare("liquid-rescale",option+1) == 0)
4970 {
4971 i++;
cristybb503372010-05-27 20:51:26 +00004972 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004973 ThrowMogrifyException(OptionError,"MissingArgument",option);
4974 if (IsGeometry(argv[i]) == MagickFalse)
4975 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4976 break;
4977 }
4978 if (LocaleCompare("list",option+1) == 0)
4979 {
cristybb503372010-05-27 20:51:26 +00004980 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004981 list;
4982
4983 if (*option == '+')
4984 break;
4985 i++;
cristybb503372010-05-27 20:51:26 +00004986 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004987 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004988 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004989 if (list < 0)
4990 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00004991 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00004992 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00004993 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00004994 }
4995 if (LocaleCompare("log",option+1) == 0)
4996 {
4997 if (*option == '+')
4998 break;
4999 i++;
cristybb503372010-05-27 20:51:26 +00005000 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005001 (strchr(argv[i],'%') == (char *) NULL))
5002 ThrowMogrifyException(OptionError,"MissingArgument",option);
5003 break;
5004 }
5005 if (LocaleCompare("loop",option+1) == 0)
5006 {
5007 if (*option == '+')
5008 break;
5009 i++;
cristybb503372010-05-27 20:51:26 +00005010 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005011 ThrowMogrifyException(OptionError,"MissingArgument",option);
5012 if (IsGeometry(argv[i]) == MagickFalse)
5013 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5014 break;
5015 }
5016 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5017 }
5018 case 'm':
5019 {
5020 if (LocaleCompare("map",option+1) == 0)
5021 {
5022 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5023 if (*option == '+')
5024 break;
5025 i++;
cristybb503372010-05-27 20:51:26 +00005026 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005027 ThrowMogrifyException(OptionError,"MissingArgument",option);
5028 break;
5029 }
5030 if (LocaleCompare("mask",option+1) == 0)
5031 {
5032 if (*option == '+')
5033 break;
5034 i++;
cristybb503372010-05-27 20:51:26 +00005035 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005036 ThrowMogrifyException(OptionError,"MissingArgument",option);
5037 break;
5038 }
5039 if (LocaleCompare("matte",option+1) == 0)
5040 break;
5041 if (LocaleCompare("mattecolor",option+1) == 0)
5042 {
5043 if (*option == '+')
5044 break;
5045 i++;
cristybb503372010-05-27 20:51:26 +00005046 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005047 ThrowMogrifyException(OptionError,"MissingArgument",option);
5048 break;
5049 }
cristyf40785b2010-03-06 02:27:27 +00005050 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005051 break;
cristyf40785b2010-03-06 02:27:27 +00005052 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005053 break;
cristy3ed852e2009-09-05 21:47:34 +00005054 if (LocaleCompare("modulate",option+1) == 0)
5055 {
5056 if (*option == '+')
5057 break;
5058 i++;
cristybb503372010-05-27 20:51:26 +00005059 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005060 ThrowMogrifyException(OptionError,"MissingArgument",option);
5061 if (IsGeometry(argv[i]) == MagickFalse)
5062 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5063 break;
5064 }
5065 if (LocaleCompare("median",option+1) == 0)
5066 {
5067 if (*option == '+')
5068 break;
5069 i++;
cristybb503372010-05-27 20:51:26 +00005070 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005071 ThrowMogrifyException(OptionError,"MissingArgument",option);
5072 if (IsGeometry(argv[i]) == MagickFalse)
5073 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5074 break;
5075 }
cristy69ec32d2011-02-27 23:57:09 +00005076 if (LocaleCompare("mode",option+1) == 0)
5077 {
5078 if (*option == '+')
5079 break;
5080 i++;
5081 if (i == (ssize_t) argc)
5082 ThrowMogrifyException(OptionError,"MissingArgument",option);
5083 if (IsGeometry(argv[i]) == MagickFalse)
5084 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5085 break;
5086 }
cristy3ed852e2009-09-05 21:47:34 +00005087 if (LocaleCompare("monitor",option+1) == 0)
5088 break;
5089 if (LocaleCompare("monochrome",option+1) == 0)
5090 break;
5091 if (LocaleCompare("morph",option+1) == 0)
5092 {
5093 if (*option == '+')
5094 break;
5095 i++;
cristybb503372010-05-27 20:51:26 +00005096 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005097 ThrowMogrifyException(OptionError,"MissingArgument",option);
5098 if (IsGeometry(argv[i]) == MagickFalse)
5099 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5100 break;
5101 }
anthony29188a82010-01-22 10:12:34 +00005102 if (LocaleCompare("morphology",option+1) == 0)
5103 {
anthony29188a82010-01-22 10:12:34 +00005104 char
5105 token[MaxTextExtent];
5106
cristyb6bd4ad2010-08-08 01:12:27 +00005107 KernelInfo
5108 *kernel_info;
5109
5110 ssize_t
5111 op;
5112
anthony29188a82010-01-22 10:12:34 +00005113 i++;
cristybb503372010-05-27 20:51:26 +00005114 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005115 ThrowMogrifyException(OptionError,"MissingArgument",option);
5116 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005117 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005118 if (op < 0)
5119 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005120 token);
anthony29188a82010-01-22 10:12:34 +00005121 i++;
cristybb503372010-05-27 20:51:26 +00005122 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005123 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005124 kernel_info=AcquireKernelInfo(argv[i]);
5125 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005126 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005127 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005128 break;
5129 }
cristy3ed852e2009-09-05 21:47:34 +00005130 if (LocaleCompare("mosaic",option+1) == 0)
5131 break;
5132 if (LocaleCompare("motion-blur",option+1) == 0)
5133 {
5134 if (*option == '+')
5135 break;
5136 i++;
cristybb503372010-05-27 20:51:26 +00005137 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005138 ThrowMogrifyException(OptionError,"MissingArgument",option);
5139 if (IsGeometry(argv[i]) == MagickFalse)
5140 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5141 break;
5142 }
5143 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5144 }
5145 case 'n':
5146 {
5147 if (LocaleCompare("negate",option+1) == 0)
5148 break;
5149 if (LocaleCompare("noise",option+1) == 0)
5150 {
5151 i++;
cristybb503372010-05-27 20:51:26 +00005152 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005153 ThrowMogrifyException(OptionError,"MissingArgument",option);
5154 if (*option == '+')
5155 {
cristybb503372010-05-27 20:51:26 +00005156 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005157 noise;
5158
cristy042ee782011-04-22 18:48:30 +00005159 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005160 if (noise < 0)
5161 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5162 argv[i]);
5163 break;
5164 }
5165 if (IsGeometry(argv[i]) == MagickFalse)
5166 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5167 break;
5168 }
5169 if (LocaleCompare("noop",option+1) == 0)
5170 break;
5171 if (LocaleCompare("normalize",option+1) == 0)
5172 break;
5173 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5174 }
5175 case 'o':
5176 {
5177 if (LocaleCompare("opaque",option+1) == 0)
5178 {
cristy3ed852e2009-09-05 21:47:34 +00005179 i++;
cristybb503372010-05-27 20:51:26 +00005180 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005181 ThrowMogrifyException(OptionError,"MissingArgument",option);
5182 break;
5183 }
5184 if (LocaleCompare("ordered-dither",option+1) == 0)
5185 {
5186 if (*option == '+')
5187 break;
5188 i++;
cristybb503372010-05-27 20:51:26 +00005189 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005190 ThrowMogrifyException(OptionError,"MissingArgument",option);
5191 break;
5192 }
5193 if (LocaleCompare("orient",option+1) == 0)
5194 {
cristybb503372010-05-27 20:51:26 +00005195 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005196 orientation;
5197
5198 orientation=UndefinedOrientation;
5199 if (*option == '+')
5200 break;
5201 i++;
cristybb503372010-05-27 20:51:26 +00005202 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005203 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005204 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005205 argv[i]);
5206 if (orientation < 0)
5207 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5208 argv[i]);
5209 break;
5210 }
5211 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5212 }
5213 case 'p':
5214 {
5215 if (LocaleCompare("page",option+1) == 0)
5216 {
5217 if (*option == '+')
5218 break;
5219 i++;
cristybb503372010-05-27 20:51:26 +00005220 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005221 ThrowMogrifyException(OptionError,"MissingArgument",option);
5222 break;
5223 }
5224 if (LocaleCompare("paint",option+1) == 0)
5225 {
5226 if (*option == '+')
5227 break;
5228 i++;
cristybb503372010-05-27 20:51:26 +00005229 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005230 ThrowMogrifyException(OptionError,"MissingArgument",option);
5231 if (IsGeometry(argv[i]) == MagickFalse)
5232 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5233 break;
5234 }
5235 if (LocaleCompare("path",option+1) == 0)
5236 {
5237 (void) CloneString(&path,(char *) NULL);
5238 if (*option == '+')
5239 break;
5240 i++;
cristybb503372010-05-27 20:51:26 +00005241 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005242 ThrowMogrifyException(OptionError,"MissingArgument",option);
5243 (void) CloneString(&path,argv[i]);
5244 break;
5245 }
5246 if (LocaleCompare("pointsize",option+1) == 0)
5247 {
5248 if (*option == '+')
5249 break;
5250 i++;
cristybb503372010-05-27 20:51:26 +00005251 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005252 ThrowMogrifyException(OptionError,"MissingArgument",option);
5253 if (IsGeometry(argv[i]) == MagickFalse)
5254 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5255 break;
5256 }
5257 if (LocaleCompare("polaroid",option+1) == 0)
5258 {
5259 if (*option == '+')
5260 break;
5261 i++;
cristybb503372010-05-27 20:51:26 +00005262 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005263 ThrowMogrifyException(OptionError,"MissingArgument",option);
5264 if (IsGeometry(argv[i]) == MagickFalse)
5265 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5266 break;
5267 }
5268 if (LocaleCompare("posterize",option+1) == 0)
5269 {
5270 if (*option == '+')
5271 break;
5272 i++;
cristybb503372010-05-27 20:51:26 +00005273 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005274 ThrowMogrifyException(OptionError,"MissingArgument",option);
5275 if (IsGeometry(argv[i]) == MagickFalse)
5276 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5277 break;
5278 }
cristye7f51092010-01-17 00:39:37 +00005279 if (LocaleCompare("precision",option+1) == 0)
5280 {
5281 if (*option == '+')
5282 break;
5283 i++;
cristybb503372010-05-27 20:51:26 +00005284 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005285 ThrowMogrifyException(OptionError,"MissingArgument",option);
5286 if (IsGeometry(argv[i]) == MagickFalse)
5287 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5288 break;
5289 }
cristy3ed852e2009-09-05 21:47:34 +00005290 if (LocaleCompare("print",option+1) == 0)
5291 {
5292 if (*option == '+')
5293 break;
5294 i++;
cristybb503372010-05-27 20:51:26 +00005295 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005296 ThrowMogrifyException(OptionError,"MissingArgument",option);
5297 break;
5298 }
5299 if (LocaleCompare("process",option+1) == 0)
5300 {
5301 if (*option == '+')
5302 break;
5303 i++;
cristybb503372010-05-27 20:51:26 +00005304 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005305 ThrowMogrifyException(OptionError,"MissingArgument",option);
5306 break;
5307 }
5308 if (LocaleCompare("profile",option+1) == 0)
5309 {
5310 i++;
cristybb503372010-05-27 20:51:26 +00005311 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005312 ThrowMogrifyException(OptionError,"MissingArgument",option);
5313 break;
5314 }
5315 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5316 }
5317 case 'q':
5318 {
5319 if (LocaleCompare("quality",option+1) == 0)
5320 {
5321 if (*option == '+')
5322 break;
5323 i++;
cristybb503372010-05-27 20:51:26 +00005324 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005325 ThrowMogrifyException(OptionError,"MissingArgument",option);
5326 if (IsGeometry(argv[i]) == MagickFalse)
5327 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5328 break;
5329 }
5330 if (LocaleCompare("quantize",option+1) == 0)
5331 {
cristybb503372010-05-27 20:51:26 +00005332 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005333 colorspace;
5334
5335 if (*option == '+')
5336 break;
5337 i++;
cristybb503372010-05-27 20:51:26 +00005338 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005339 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005340 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005341 argv[i]);
5342 if (colorspace < 0)
5343 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5344 argv[i]);
5345 break;
5346 }
5347 if (LocaleCompare("quiet",option+1) == 0)
5348 break;
5349 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5350 }
5351 case 'r':
5352 {
5353 if (LocaleCompare("radial-blur",option+1) == 0)
5354 {
5355 i++;
cristybb503372010-05-27 20:51:26 +00005356 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005357 ThrowMogrifyException(OptionError,"MissingArgument",option);
5358 if (IsGeometry(argv[i]) == MagickFalse)
5359 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5360 break;
5361 }
5362 if (LocaleCompare("raise",option+1) == 0)
5363 {
5364 i++;
cristybb503372010-05-27 20:51:26 +00005365 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005366 ThrowMogrifyException(OptionError,"MissingArgument",option);
5367 if (IsGeometry(argv[i]) == MagickFalse)
5368 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5369 break;
5370 }
5371 if (LocaleCompare("random-threshold",option+1) == 0)
5372 {
5373 if (*option == '+')
5374 break;
5375 i++;
cristybb503372010-05-27 20:51:26 +00005376 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005377 ThrowMogrifyException(OptionError,"MissingArgument",option);
5378 if (IsGeometry(argv[i]) == MagickFalse)
5379 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5380 break;
5381 }
5382 if (LocaleCompare("red-primary",option+1) == 0)
5383 {
5384 if (*option == '+')
5385 break;
5386 i++;
cristybb503372010-05-27 20:51:26 +00005387 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005388 ThrowMogrifyException(OptionError,"MissingArgument",option);
5389 if (IsGeometry(argv[i]) == MagickFalse)
5390 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5391 }
cristy9f2083a2010-04-22 19:48:05 +00005392 if (LocaleCompare("regard-warnings",option+1) == 0)
5393 break;
cristy3ed852e2009-09-05 21:47:34 +00005394 if (LocaleCompare("region",option+1) == 0)
5395 {
5396 if (*option == '+')
5397 break;
5398 i++;
cristybb503372010-05-27 20:51:26 +00005399 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005400 ThrowMogrifyException(OptionError,"MissingArgument",option);
5401 if (IsGeometry(argv[i]) == MagickFalse)
5402 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5403 break;
5404 }
cristyf0c78232010-03-15 12:53:40 +00005405 if (LocaleCompare("remap",option+1) == 0)
5406 {
5407 if (*option == '+')
5408 break;
5409 i++;
cristybb503372010-05-27 20:51:26 +00005410 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005411 ThrowMogrifyException(OptionError,"MissingArgument",option);
5412 break;
5413 }
cristy3ed852e2009-09-05 21:47:34 +00005414 if (LocaleCompare("render",option+1) == 0)
5415 break;
5416 if (LocaleCompare("repage",option+1) == 0)
5417 {
5418 if (*option == '+')
5419 break;
5420 i++;
cristybb503372010-05-27 20:51:26 +00005421 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005422 ThrowMogrifyException(OptionError,"MissingArgument",option);
5423 if (IsGeometry(argv[i]) == MagickFalse)
5424 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5425 break;
5426 }
5427 if (LocaleCompare("resample",option+1) == 0)
5428 {
5429 if (*option == '+')
5430 break;
5431 i++;
cristybb503372010-05-27 20:51:26 +00005432 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005433 ThrowMogrifyException(OptionError,"MissingArgument",option);
5434 if (IsGeometry(argv[i]) == MagickFalse)
5435 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5436 break;
5437 }
5438 if (LocaleCompare("resize",option+1) == 0)
5439 {
5440 if (*option == '+')
5441 break;
5442 i++;
cristybb503372010-05-27 20:51:26 +00005443 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005444 ThrowMogrifyException(OptionError,"MissingArgument",option);
5445 if (IsGeometry(argv[i]) == MagickFalse)
5446 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5447 break;
5448 }
cristyebbcfea2011-02-25 02:43:54 +00005449 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5450 {
5451 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5452 break;
5453 }
cristy3ed852e2009-09-05 21:47:34 +00005454 if (LocaleCompare("reverse",option+1) == 0)
5455 break;
5456 if (LocaleCompare("roll",option+1) == 0)
5457 {
5458 if (*option == '+')
5459 break;
5460 i++;
cristybb503372010-05-27 20:51:26 +00005461 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005462 ThrowMogrifyException(OptionError,"MissingArgument",option);
5463 if (IsGeometry(argv[i]) == MagickFalse)
5464 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5465 break;
5466 }
5467 if (LocaleCompare("rotate",option+1) == 0)
5468 {
5469 i++;
cristybb503372010-05-27 20:51:26 +00005470 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005471 ThrowMogrifyException(OptionError,"MissingArgument",option);
5472 if (IsGeometry(argv[i]) == MagickFalse)
5473 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5474 break;
5475 }
5476 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5477 }
5478 case 's':
5479 {
5480 if (LocaleCompare("sample",option+1) == 0)
5481 {
5482 if (*option == '+')
5483 break;
5484 i++;
cristybb503372010-05-27 20:51:26 +00005485 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005486 ThrowMogrifyException(OptionError,"MissingArgument",option);
5487 if (IsGeometry(argv[i]) == MagickFalse)
5488 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5489 break;
5490 }
5491 if (LocaleCompare("sampling-factor",option+1) == 0)
5492 {
5493 if (*option == '+')
5494 break;
5495 i++;
cristybb503372010-05-27 20:51:26 +00005496 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005497 ThrowMogrifyException(OptionError,"MissingArgument",option);
5498 if (IsGeometry(argv[i]) == MagickFalse)
5499 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5500 break;
5501 }
5502 if (LocaleCompare("scale",option+1) == 0)
5503 {
5504 if (*option == '+')
5505 break;
5506 i++;
cristybb503372010-05-27 20:51:26 +00005507 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005508 ThrowMogrifyException(OptionError,"MissingArgument",option);
5509 if (IsGeometry(argv[i]) == MagickFalse)
5510 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5511 break;
5512 }
5513 if (LocaleCompare("scene",option+1) == 0)
5514 {
5515 if (*option == '+')
5516 break;
5517 i++;
cristybb503372010-05-27 20:51:26 +00005518 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005519 ThrowMogrifyException(OptionError,"MissingArgument",option);
5520 if (IsGeometry(argv[i]) == MagickFalse)
5521 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5522 break;
5523 }
5524 if (LocaleCompare("seed",option+1) == 0)
5525 {
5526 if (*option == '+')
5527 break;
5528 i++;
cristybb503372010-05-27 20:51:26 +00005529 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005530 ThrowMogrifyException(OptionError,"MissingArgument",option);
5531 if (IsGeometry(argv[i]) == MagickFalse)
5532 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5533 break;
5534 }
5535 if (LocaleCompare("segment",option+1) == 0)
5536 {
5537 if (*option == '+')
5538 break;
5539 i++;
cristybb503372010-05-27 20:51:26 +00005540 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005541 ThrowMogrifyException(OptionError,"MissingArgument",option);
5542 if (IsGeometry(argv[i]) == MagickFalse)
5543 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5544 break;
5545 }
5546 if (LocaleCompare("selective-blur",option+1) == 0)
5547 {
5548 i++;
cristybb503372010-05-27 20:51:26 +00005549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005550 ThrowMogrifyException(OptionError,"MissingArgument",option);
5551 if (IsGeometry(argv[i]) == MagickFalse)
5552 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5553 break;
5554 }
5555 if (LocaleCompare("separate",option+1) == 0)
5556 break;
5557 if (LocaleCompare("sepia-tone",option+1) == 0)
5558 {
5559 if (*option == '+')
5560 break;
5561 i++;
cristybb503372010-05-27 20:51:26 +00005562 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005563 ThrowMogrifyException(OptionError,"MissingArgument",option);
5564 if (IsGeometry(argv[i]) == MagickFalse)
5565 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5566 break;
5567 }
5568 if (LocaleCompare("set",option+1) == 0)
5569 {
5570 i++;
cristybb503372010-05-27 20:51:26 +00005571 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005572 ThrowMogrifyException(OptionError,"MissingArgument",option);
5573 if (*option == '+')
5574 break;
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 break;
5579 }
5580 if (LocaleCompare("shade",option+1) == 0)
5581 {
5582 i++;
cristybb503372010-05-27 20:51:26 +00005583 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005584 ThrowMogrifyException(OptionError,"MissingArgument",option);
5585 if (IsGeometry(argv[i]) == MagickFalse)
5586 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5587 break;
5588 }
5589 if (LocaleCompare("shadow",option+1) == 0)
5590 {
5591 if (*option == '+')
5592 break;
5593 i++;
cristybb503372010-05-27 20:51:26 +00005594 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005595 ThrowMogrifyException(OptionError,"MissingArgument",option);
5596 if (IsGeometry(argv[i]) == MagickFalse)
5597 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5598 break;
5599 }
5600 if (LocaleCompare("sharpen",option+1) == 0)
5601 {
5602 i++;
cristybb503372010-05-27 20:51:26 +00005603 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005604 ThrowMogrifyException(OptionError,"MissingArgument",option);
5605 if (IsGeometry(argv[i]) == MagickFalse)
5606 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5607 break;
5608 }
5609 if (LocaleCompare("shave",option+1) == 0)
5610 {
5611 if (*option == '+')
5612 break;
5613 i++;
cristybb503372010-05-27 20:51:26 +00005614 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005615 ThrowMogrifyException(OptionError,"MissingArgument",option);
5616 if (IsGeometry(argv[i]) == MagickFalse)
5617 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5618 break;
5619 }
5620 if (LocaleCompare("shear",option+1) == 0)
5621 {
5622 i++;
cristybb503372010-05-27 20:51:26 +00005623 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005624 ThrowMogrifyException(OptionError,"MissingArgument",option);
5625 if (IsGeometry(argv[i]) == MagickFalse)
5626 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5627 break;
5628 }
5629 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5630 {
5631 i++;
cristybb503372010-05-27 20:51:26 +00005632 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005633 ThrowMogrifyException(OptionError,"MissingArgument",option);
5634 if (IsGeometry(argv[i]) == MagickFalse)
5635 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5636 break;
5637 }
5638 if (LocaleCompare("size",option+1) == 0)
5639 {
5640 if (*option == '+')
5641 break;
5642 i++;
cristybb503372010-05-27 20:51:26 +00005643 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005644 ThrowMogrifyException(OptionError,"MissingArgument",option);
5645 if (IsGeometry(argv[i]) == MagickFalse)
5646 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5647 break;
5648 }
5649 if (LocaleCompare("sketch",option+1) == 0)
5650 {
5651 if (*option == '+')
5652 break;
5653 i++;
cristybb503372010-05-27 20:51:26 +00005654 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005655 ThrowMogrifyException(OptionError,"MissingArgument",option);
5656 if (IsGeometry(argv[i]) == MagickFalse)
5657 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5658 break;
5659 }
cristy4285d782011-02-09 20:12:28 +00005660 if (LocaleCompare("smush",option+1) == 0)
5661 {
cristy4285d782011-02-09 20:12:28 +00005662 i++;
5663 if (i == (ssize_t) argc)
5664 ThrowMogrifyException(OptionError,"MissingArgument",option);
5665 if (IsGeometry(argv[i]) == MagickFalse)
5666 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005667 i++;
5668 break;
5669 }
cristy3ed852e2009-09-05 21:47:34 +00005670 if (LocaleCompare("solarize",option+1) == 0)
5671 {
5672 if (*option == '+')
5673 break;
5674 i++;
cristybb503372010-05-27 20:51:26 +00005675 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005676 ThrowMogrifyException(OptionError,"MissingArgument",option);
5677 if (IsGeometry(argv[i]) == MagickFalse)
5678 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5679 break;
5680 }
5681 if (LocaleCompare("sparse-color",option+1) == 0)
5682 {
cristybb503372010-05-27 20:51:26 +00005683 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005684 op;
5685
5686 i++;
cristybb503372010-05-27 20:51:26 +00005687 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005688 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005689 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005690 if (op < 0)
5691 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5692 argv[i]);
5693 i++;
cristybb503372010-05-27 20:51:26 +00005694 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005695 ThrowMogrifyException(OptionError,"MissingArgument",option);
5696 break;
5697 }
5698 if (LocaleCompare("spread",option+1) == 0)
5699 {
5700 if (*option == '+')
5701 break;
5702 i++;
cristybb503372010-05-27 20:51:26 +00005703 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005704 ThrowMogrifyException(OptionError,"MissingArgument",option);
5705 if (IsGeometry(argv[i]) == MagickFalse)
5706 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5707 break;
5708 }
cristy0834d642011-03-18 18:26:08 +00005709 if (LocaleCompare("statistic",option+1) == 0)
5710 {
5711 ssize_t
5712 op;
5713
5714 if (*option == '+')
5715 break;
5716 i++;
5717 if (i == (ssize_t) argc)
5718 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005719 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005720 if (op < 0)
5721 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5722 argv[i]);
5723 i++;
5724 if (i == (ssize_t) (argc-1))
5725 ThrowMogrifyException(OptionError,"MissingArgument",option);
5726 if (IsGeometry(argv[i]) == MagickFalse)
5727 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5728 break;
5729 }
cristy3ed852e2009-09-05 21:47:34 +00005730 if (LocaleCompare("stretch",option+1) == 0)
5731 {
cristybb503372010-05-27 20:51:26 +00005732 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005733 stretch;
5734
5735 if (*option == '+')
5736 break;
5737 i++;
cristybb503372010-05-27 20:51:26 +00005738 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005739 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005740 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005741 if (stretch < 0)
5742 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5743 argv[i]);
5744 break;
5745 }
5746 if (LocaleCompare("strip",option+1) == 0)
5747 break;
5748 if (LocaleCompare("stroke",option+1) == 0)
5749 {
5750 if (*option == '+')
5751 break;
5752 i++;
cristybb503372010-05-27 20:51:26 +00005753 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005754 ThrowMogrifyException(OptionError,"MissingArgument",option);
5755 break;
5756 }
5757 if (LocaleCompare("strokewidth",option+1) == 0)
5758 {
5759 if (*option == '+')
5760 break;
5761 i++;
cristybb503372010-05-27 20:51:26 +00005762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005763 ThrowMogrifyException(OptionError,"MissingArgument",option);
5764 if (IsGeometry(argv[i]) == MagickFalse)
5765 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5766 break;
5767 }
5768 if (LocaleCompare("style",option+1) == 0)
5769 {
cristybb503372010-05-27 20:51:26 +00005770 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005771 style;
5772
5773 if (*option == '+')
5774 break;
5775 i++;
cristybb503372010-05-27 20:51:26 +00005776 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005777 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005778 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005779 if (style < 0)
5780 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5781 argv[i]);
5782 break;
5783 }
cristyecb10ff2011-03-22 13:14:03 +00005784 if (LocaleCompare("swap",option+1) == 0)
5785 {
5786 if (*option == '+')
5787 break;
5788 i++;
5789 if (i == (ssize_t) (argc-1))
5790 ThrowMogrifyException(OptionError,"MissingArgument",option);
5791 if (IsGeometry(argv[i]) == MagickFalse)
5792 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5793 break;
5794 }
cristy3ed852e2009-09-05 21:47:34 +00005795 if (LocaleCompare("swirl",option+1) == 0)
5796 {
5797 if (*option == '+')
5798 break;
5799 i++;
cristybb503372010-05-27 20:51:26 +00005800 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005801 ThrowMogrifyException(OptionError,"MissingArgument",option);
5802 if (IsGeometry(argv[i]) == MagickFalse)
5803 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5804 break;
5805 }
cristyd9a29192010-10-16 16:49:53 +00005806 if (LocaleCompare("synchronize",option+1) == 0)
5807 break;
cristy3ed852e2009-09-05 21:47:34 +00005808 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5809 }
5810 case 't':
5811 {
5812 if (LocaleCompare("taint",option+1) == 0)
5813 break;
5814 if (LocaleCompare("texture",option+1) == 0)
5815 {
5816 if (*option == '+')
5817 break;
5818 i++;
cristybb503372010-05-27 20:51:26 +00005819 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005820 ThrowMogrifyException(OptionError,"MissingArgument",option);
5821 break;
5822 }
5823 if (LocaleCompare("tile",option+1) == 0)
5824 {
5825 if (*option == '+')
5826 break;
5827 i++;
cristybb503372010-05-27 20:51:26 +00005828 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005829 ThrowMogrifyException(OptionError,"MissingArgument",option);
5830 break;
5831 }
5832 if (LocaleCompare("tile-offset",option+1) == 0)
5833 {
5834 if (*option == '+')
5835 break;
5836 i++;
cristybb503372010-05-27 20:51:26 +00005837 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005838 ThrowMogrifyException(OptionError,"MissingArgument",option);
5839 if (IsGeometry(argv[i]) == MagickFalse)
5840 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5841 break;
5842 }
5843 if (LocaleCompare("tint",option+1) == 0)
5844 {
5845 if (*option == '+')
5846 break;
5847 i++;
cristybb503372010-05-27 20:51:26 +00005848 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005849 ThrowMogrifyException(OptionError,"MissingArgument",option);
5850 if (IsGeometry(argv[i]) == MagickFalse)
5851 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5852 break;
5853 }
5854 if (LocaleCompare("transform",option+1) == 0)
5855 break;
5856 if (LocaleCompare("transpose",option+1) == 0)
5857 break;
5858 if (LocaleCompare("transverse",option+1) == 0)
5859 break;
5860 if (LocaleCompare("threshold",option+1) == 0)
5861 {
5862 if (*option == '+')
5863 break;
5864 i++;
cristybb503372010-05-27 20:51:26 +00005865 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005866 ThrowMogrifyException(OptionError,"MissingArgument",option);
5867 if (IsGeometry(argv[i]) == MagickFalse)
5868 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5869 break;
5870 }
5871 if (LocaleCompare("thumbnail",option+1) == 0)
5872 {
5873 if (*option == '+')
5874 break;
5875 i++;
cristybb503372010-05-27 20:51:26 +00005876 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005877 ThrowMogrifyException(OptionError,"MissingArgument",option);
5878 if (IsGeometry(argv[i]) == MagickFalse)
5879 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5880 break;
5881 }
5882 if (LocaleCompare("transparent",option+1) == 0)
5883 {
5884 i++;
cristybb503372010-05-27 20:51:26 +00005885 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005886 ThrowMogrifyException(OptionError,"MissingArgument",option);
5887 break;
5888 }
5889 if (LocaleCompare("transparent-color",option+1) == 0)
5890 {
5891 if (*option == '+')
5892 break;
5893 i++;
cristybb503372010-05-27 20:51:26 +00005894 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005895 ThrowMogrifyException(OptionError,"MissingArgument",option);
5896 break;
5897 }
5898 if (LocaleCompare("treedepth",option+1) == 0)
5899 {
5900 if (*option == '+')
5901 break;
5902 i++;
cristybb503372010-05-27 20:51:26 +00005903 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005904 ThrowMogrifyException(OptionError,"MissingArgument",option);
5905 if (IsGeometry(argv[i]) == MagickFalse)
5906 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5907 break;
5908 }
5909 if (LocaleCompare("trim",option+1) == 0)
5910 break;
5911 if (LocaleCompare("type",option+1) == 0)
5912 {
cristybb503372010-05-27 20:51:26 +00005913 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005914 type;
5915
5916 if (*option == '+')
5917 break;
5918 i++;
cristybb503372010-05-27 20:51:26 +00005919 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005920 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005921 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005922 if (type < 0)
5923 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5924 argv[i]);
5925 break;
5926 }
5927 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5928 }
5929 case 'u':
5930 {
5931 if (LocaleCompare("undercolor",option+1) == 0)
5932 {
5933 if (*option == '+')
5934 break;
5935 i++;
cristybb503372010-05-27 20:51:26 +00005936 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005937 ThrowMogrifyException(OptionError,"MissingArgument",option);
5938 break;
5939 }
5940 if (LocaleCompare("unique-colors",option+1) == 0)
5941 break;
5942 if (LocaleCompare("units",option+1) == 0)
5943 {
cristybb503372010-05-27 20:51:26 +00005944 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005945 units;
5946
5947 if (*option == '+')
5948 break;
5949 i++;
cristybb503372010-05-27 20:51:26 +00005950 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005951 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005952 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005953 argv[i]);
5954 if (units < 0)
5955 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5956 argv[i]);
5957 break;
5958 }
5959 if (LocaleCompare("unsharp",option+1) == 0)
5960 {
5961 i++;
cristybb503372010-05-27 20:51:26 +00005962 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005963 ThrowMogrifyException(OptionError,"MissingArgument",option);
5964 if (IsGeometry(argv[i]) == MagickFalse)
5965 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5966 break;
5967 }
5968 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5969 }
5970 case 'v':
5971 {
5972 if (LocaleCompare("verbose",option+1) == 0)
5973 {
5974 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
5975 break;
5976 }
5977 if ((LocaleCompare("version",option+1) == 0) ||
5978 (LocaleCompare("-version",option+1) == 0))
5979 {
cristyb51dff52011-05-19 16:55:47 +00005980 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00005981 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00005982 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
5983 GetMagickCopyright());
5984 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
5985 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00005986 break;
5987 }
5988 if (LocaleCompare("view",option+1) == 0)
5989 {
5990 if (*option == '+')
5991 break;
5992 i++;
cristybb503372010-05-27 20:51:26 +00005993 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005994 ThrowMogrifyException(OptionError,"MissingArgument",option);
5995 break;
5996 }
5997 if (LocaleCompare("vignette",option+1) == 0)
5998 {
5999 if (*option == '+')
6000 break;
6001 i++;
cristybb503372010-05-27 20:51:26 +00006002 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006003 ThrowMogrifyException(OptionError,"MissingArgument",option);
6004 if (IsGeometry(argv[i]) == MagickFalse)
6005 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6006 break;
6007 }
6008 if (LocaleCompare("virtual-pixel",option+1) == 0)
6009 {
cristybb503372010-05-27 20:51:26 +00006010 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006011 method;
6012
6013 if (*option == '+')
6014 break;
6015 i++;
cristybb503372010-05-27 20:51:26 +00006016 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006017 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00006018 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006019 argv[i]);
6020 if (method < 0)
6021 ThrowMogrifyException(OptionError,
6022 "UnrecognizedVirtualPixelMethod",argv[i]);
6023 break;
6024 }
6025 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6026 }
6027 case 'w':
6028 {
6029 if (LocaleCompare("wave",option+1) == 0)
6030 {
6031 i++;
cristybb503372010-05-27 20:51:26 +00006032 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006033 ThrowMogrifyException(OptionError,"MissingArgument",option);
6034 if (IsGeometry(argv[i]) == MagickFalse)
6035 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6036 break;
6037 }
6038 if (LocaleCompare("weight",option+1) == 0)
6039 {
6040 if (*option == '+')
6041 break;
6042 i++;
cristybb503372010-05-27 20:51:26 +00006043 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006044 ThrowMogrifyException(OptionError,"MissingArgument",option);
6045 break;
6046 }
6047 if (LocaleCompare("white-point",option+1) == 0)
6048 {
6049 if (*option == '+')
6050 break;
6051 i++;
cristybb503372010-05-27 20:51:26 +00006052 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006053 ThrowMogrifyException(OptionError,"MissingArgument",option);
6054 if (IsGeometry(argv[i]) == MagickFalse)
6055 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6056 break;
6057 }
6058 if (LocaleCompare("white-threshold",option+1) == 0)
6059 {
6060 if (*option == '+')
6061 break;
6062 i++;
cristybb503372010-05-27 20:51:26 +00006063 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006064 ThrowMogrifyException(OptionError,"MissingArgument",option);
6065 if (IsGeometry(argv[i]) == MagickFalse)
6066 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6067 break;
6068 }
6069 if (LocaleCompare("write",option+1) == 0)
6070 {
6071 i++;
cristybb503372010-05-27 20:51:26 +00006072 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006073 ThrowMogrifyException(OptionError,"MissingArgument",option);
6074 break;
6075 }
6076 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6077 }
6078 case '?':
6079 break;
6080 default:
6081 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6082 }
cristy042ee782011-04-22 18:48:30 +00006083 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6084 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006085 if (fire != MagickFalse)
6086 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6087 }
6088 if (k != 0)
6089 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006090 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006091 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6092 DestroyMogrify();
6093 return(status != 0 ? MagickTrue : MagickFalse);
6094}
6095
6096/*
6097%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6098% %
6099% %
6100% %
6101+ M o g r i f y I m a g e I n f o %
6102% %
6103% %
6104% %
6105%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6106%
6107% MogrifyImageInfo() applies image processing settings to the image as
6108% prescribed by command line options.
6109%
6110% The format of the MogrifyImageInfo method is:
6111%
6112% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6113% const char **argv,ExceptionInfo *exception)
6114%
6115% A description of each parameter follows:
6116%
6117% o image_info: the image info..
6118%
6119% o argc: Specifies a pointer to an integer describing the number of
6120% elements in the argument vector.
6121%
6122% o argv: Specifies a pointer to a text array containing the command line
6123% arguments.
6124%
6125% o exception: return any errors or warnings in this structure.
6126%
6127*/
6128WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6129 const int argc,const char **argv,ExceptionInfo *exception)
6130{
6131 const char
6132 *option;
6133
6134 GeometryInfo
6135 geometry_info;
6136
cristybb503372010-05-27 20:51:26 +00006137 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006138 count;
6139
cristybb503372010-05-27 20:51:26 +00006140 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006141 i;
6142
6143 /*
6144 Initialize method variables.
6145 */
6146 assert(image_info != (ImageInfo *) NULL);
6147 assert(image_info->signature == MagickSignature);
6148 if (image_info->debug != MagickFalse)
6149 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6150 image_info->filename);
6151 if (argc < 0)
6152 return(MagickTrue);
6153 /*
6154 Set the image settings.
6155 */
cristybb503372010-05-27 20:51:26 +00006156 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006157 {
6158 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006159 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006160 continue;
cristy042ee782011-04-22 18:48:30 +00006161 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006162 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006163 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006164 break;
6165 switch (*(option+1))
6166 {
6167 case 'a':
6168 {
6169 if (LocaleCompare("adjoin",option+1) == 0)
6170 {
6171 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6172 break;
6173 }
6174 if (LocaleCompare("antialias",option+1) == 0)
6175 {
6176 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6177 break;
6178 }
cristy3ed852e2009-09-05 21:47:34 +00006179 if (LocaleCompare("authenticate",option+1) == 0)
6180 {
6181 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006182 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006183 else
anthony1afdc7a2011-10-05 11:54:28 +00006184 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006185 break;
6186 }
6187 break;
6188 }
6189 case 'b':
6190 {
6191 if (LocaleCompare("background",option+1) == 0)
6192 {
6193 if (*option == '+')
6194 {
6195 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006196 (void) QueryColorCompliance(MogrifyBackgroundColor,
6197 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006198 break;
6199 }
6200 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006201 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6202 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006203 break;
6204 }
6205 if (LocaleCompare("bias",option+1) == 0)
6206 {
6207 if (*option == '+')
6208 {
6209 (void) SetImageOption(image_info,option+1,"0.0");
6210 break;
6211 }
6212 (void) SetImageOption(image_info,option+1,argv[i+1]);
6213 break;
6214 }
6215 if (LocaleCompare("black-point-compensation",option+1) == 0)
6216 {
6217 if (*option == '+')
6218 {
6219 (void) SetImageOption(image_info,option+1,"false");
6220 break;
6221 }
6222 (void) SetImageOption(image_info,option+1,"true");
6223 break;
6224 }
6225 if (LocaleCompare("blue-primary",option+1) == 0)
6226 {
6227 if (*option == '+')
6228 {
6229 (void) SetImageOption(image_info,option+1,"0.0");
6230 break;
6231 }
6232 (void) SetImageOption(image_info,option+1,argv[i+1]);
6233 break;
6234 }
6235 if (LocaleCompare("bordercolor",option+1) == 0)
6236 {
6237 if (*option == '+')
6238 {
6239 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006240 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006241 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006242 break;
6243 }
cristy9950d572011-10-01 18:22:35 +00006244 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6245 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006246 (void) SetImageOption(image_info,option+1,argv[i+1]);
6247 break;
6248 }
6249 if (LocaleCompare("box",option+1) == 0)
6250 {
6251 if (*option == '+')
6252 {
6253 (void) SetImageOption(image_info,"undercolor","none");
6254 break;
6255 }
6256 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6257 break;
6258 }
6259 break;
6260 }
6261 case 'c':
6262 {
6263 if (LocaleCompare("cache",option+1) == 0)
6264 {
6265 MagickSizeType
6266 limit;
6267
6268 limit=MagickResourceInfinity;
6269 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006270 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6271 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006272 (void) SetMagickResourceLimit(MemoryResource,limit);
6273 (void) SetMagickResourceLimit(MapResource,2*limit);
6274 break;
6275 }
6276 if (LocaleCompare("caption",option+1) == 0)
6277 {
6278 if (*option == '+')
6279 {
6280 (void) DeleteImageOption(image_info,option+1);
6281 break;
6282 }
6283 (void) SetImageOption(image_info,option+1,argv[i+1]);
6284 break;
6285 }
6286 if (LocaleCompare("channel",option+1) == 0)
6287 {
6288 if (*option == '+')
6289 {
6290 image_info->channel=DefaultChannels;
6291 break;
6292 }
6293 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6294 break;
6295 }
cristy3ed852e2009-09-05 21:47:34 +00006296 if (LocaleCompare("colorspace",option+1) == 0)
6297 {
6298 if (*option == '+')
6299 {
6300 image_info->colorspace=UndefinedColorspace;
6301 (void) SetImageOption(image_info,option+1,"undefined");
6302 break;
6303 }
cristy042ee782011-04-22 18:48:30 +00006304 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006305 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6306 (void) SetImageOption(image_info,option+1,argv[i+1]);
6307 break;
6308 }
cristy3ed852e2009-09-05 21:47:34 +00006309 if (LocaleCompare("comment",option+1) == 0)
6310 {
6311 if (*option == '+')
6312 {
6313 (void) DeleteImageOption(image_info,option+1);
6314 break;
6315 }
6316 (void) SetImageOption(image_info,option+1,argv[i+1]);
6317 break;
6318 }
6319 if (LocaleCompare("compose",option+1) == 0)
6320 {
6321 if (*option == '+')
6322 {
6323 (void) SetImageOption(image_info,option+1,"undefined");
6324 break;
6325 }
6326 (void) SetImageOption(image_info,option+1,argv[i+1]);
6327 break;
6328 }
6329 if (LocaleCompare("compress",option+1) == 0)
6330 {
6331 if (*option == '+')
6332 {
6333 image_info->compression=UndefinedCompression;
6334 (void) SetImageOption(image_info,option+1,"undefined");
6335 break;
6336 }
cristy042ee782011-04-22 18:48:30 +00006337 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006338 MagickCompressOptions,MagickFalse,argv[i+1]);
6339 (void) SetImageOption(image_info,option+1,argv[i+1]);
6340 break;
6341 }
6342 break;
6343 }
6344 case 'd':
6345 {
6346 if (LocaleCompare("debug",option+1) == 0)
6347 {
6348 if (*option == '+')
6349 (void) SetLogEventMask("none");
6350 else
6351 (void) SetLogEventMask(argv[i+1]);
6352 image_info->debug=IsEventLogging();
6353 break;
6354 }
6355 if (LocaleCompare("define",option+1) == 0)
6356 {
6357 if (*option == '+')
6358 {
6359 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6360 (void) DeleteImageRegistry(argv[i+1]+9);
6361 else
6362 (void) DeleteImageOption(image_info,argv[i+1]);
6363 break;
6364 }
6365 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6366 {
6367 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6368 exception);
6369 break;
6370 }
6371 (void) DefineImageOption(image_info,argv[i+1]);
6372 break;
6373 }
6374 if (LocaleCompare("delay",option+1) == 0)
6375 {
6376 if (*option == '+')
6377 {
6378 (void) SetImageOption(image_info,option+1,"0");
6379 break;
6380 }
6381 (void) SetImageOption(image_info,option+1,argv[i+1]);
6382 break;
6383 }
6384 if (LocaleCompare("density",option+1) == 0)
6385 {
6386 /*
6387 Set image density.
6388 */
6389 if (*option == '+')
6390 {
6391 if (image_info->density != (char *) NULL)
6392 image_info->density=DestroyString(image_info->density);
6393 (void) SetImageOption(image_info,option+1,"72");
6394 break;
6395 }
6396 (void) CloneString(&image_info->density,argv[i+1]);
6397 (void) SetImageOption(image_info,option+1,argv[i+1]);
6398 break;
6399 }
6400 if (LocaleCompare("depth",option+1) == 0)
6401 {
6402 if (*option == '+')
6403 {
6404 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6405 break;
6406 }
cristye27293e2009-12-18 02:53:20 +00006407 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006408 break;
6409 }
cristyc9b12952010-03-28 01:12:28 +00006410 if (LocaleCompare("direction",option+1) == 0)
6411 {
6412 if (*option == '+')
6413 {
6414 (void) SetImageOption(image_info,option+1,"undefined");
6415 break;
6416 }
6417 (void) SetImageOption(image_info,option+1,argv[i+1]);
6418 break;
6419 }
cristy3ed852e2009-09-05 21:47:34 +00006420 if (LocaleCompare("display",option+1) == 0)
6421 {
6422 if (*option == '+')
6423 {
6424 if (image_info->server_name != (char *) NULL)
6425 image_info->server_name=DestroyString(
6426 image_info->server_name);
6427 break;
6428 }
6429 (void) CloneString(&image_info->server_name,argv[i+1]);
6430 break;
6431 }
6432 if (LocaleCompare("dispose",option+1) == 0)
6433 {
6434 if (*option == '+')
6435 {
6436 (void) SetImageOption(image_info,option+1,"undefined");
6437 break;
6438 }
6439 (void) SetImageOption(image_info,option+1,argv[i+1]);
6440 break;
6441 }
6442 if (LocaleCompare("dither",option+1) == 0)
6443 {
6444 if (*option == '+')
6445 {
6446 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006447 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006448 break;
6449 }
6450 (void) SetImageOption(image_info,option+1,argv[i+1]);
6451 image_info->dither=MagickTrue;
6452 break;
6453 }
6454 break;
6455 }
6456 case 'e':
6457 {
6458 if (LocaleCompare("encoding",option+1) == 0)
6459 {
6460 if (*option == '+')
6461 {
6462 (void) SetImageOption(image_info,option+1,"undefined");
6463 break;
6464 }
6465 (void) SetImageOption(image_info,option+1,argv[i+1]);
6466 break;
6467 }
6468 if (LocaleCompare("endian",option+1) == 0)
6469 {
6470 if (*option == '+')
6471 {
6472 image_info->endian=UndefinedEndian;
6473 (void) SetImageOption(image_info,option+1,"undefined");
6474 break;
6475 }
cristy042ee782011-04-22 18:48:30 +00006476 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006477 MagickEndianOptions,MagickFalse,argv[i+1]);
6478 (void) SetImageOption(image_info,option+1,argv[i+1]);
6479 break;
6480 }
6481 if (LocaleCompare("extract",option+1) == 0)
6482 {
6483 /*
6484 Set image extract geometry.
6485 */
6486 if (*option == '+')
6487 {
6488 if (image_info->extract != (char *) NULL)
6489 image_info->extract=DestroyString(image_info->extract);
6490 break;
6491 }
6492 (void) CloneString(&image_info->extract,argv[i+1]);
6493 break;
6494 }
6495 break;
6496 }
6497 case 'f':
6498 {
6499 if (LocaleCompare("fill",option+1) == 0)
6500 {
6501 if (*option == '+')
6502 {
6503 (void) SetImageOption(image_info,option+1,"none");
6504 break;
6505 }
6506 (void) SetImageOption(image_info,option+1,argv[i+1]);
6507 break;
6508 }
6509 if (LocaleCompare("filter",option+1) == 0)
6510 {
6511 if (*option == '+')
6512 {
6513 (void) SetImageOption(image_info,option+1,"undefined");
6514 break;
6515 }
6516 (void) SetImageOption(image_info,option+1,argv[i+1]);
6517 break;
6518 }
6519 if (LocaleCompare("font",option+1) == 0)
6520 {
6521 if (*option == '+')
6522 {
6523 if (image_info->font != (char *) NULL)
6524 image_info->font=DestroyString(image_info->font);
6525 break;
6526 }
6527 (void) CloneString(&image_info->font,argv[i+1]);
6528 break;
6529 }
6530 if (LocaleCompare("format",option+1) == 0)
6531 {
6532 register const char
6533 *q;
6534
6535 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006536 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006537 image_info->ping=MagickFalse;
6538 (void) SetImageOption(image_info,option+1,argv[i+1]);
6539 break;
6540 }
6541 if (LocaleCompare("fuzz",option+1) == 0)
6542 {
6543 if (*option == '+')
6544 {
6545 image_info->fuzz=0.0;
6546 (void) SetImageOption(image_info,option+1,"0");
6547 break;
6548 }
cristydbdd0e32011-11-04 23:29:40 +00006549 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6550 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006551 (void) SetImageOption(image_info,option+1,argv[i+1]);
6552 break;
6553 }
6554 break;
6555 }
6556 case 'g':
6557 {
6558 if (LocaleCompare("gravity",option+1) == 0)
6559 {
6560 if (*option == '+')
6561 {
6562 (void) SetImageOption(image_info,option+1,"undefined");
6563 break;
6564 }
6565 (void) SetImageOption(image_info,option+1,argv[i+1]);
6566 break;
6567 }
6568 if (LocaleCompare("green-primary",option+1) == 0)
6569 {
6570 if (*option == '+')
6571 {
6572 (void) SetImageOption(image_info,option+1,"0.0");
6573 break;
6574 }
6575 (void) SetImageOption(image_info,option+1,argv[i+1]);
6576 break;
6577 }
6578 break;
6579 }
6580 case 'i':
6581 {
6582 if (LocaleCompare("intent",option+1) == 0)
6583 {
6584 if (*option == '+')
6585 {
6586 (void) SetImageOption(image_info,option+1,"undefined");
6587 break;
6588 }
6589 (void) SetImageOption(image_info,option+1,argv[i+1]);
6590 break;
6591 }
6592 if (LocaleCompare("interlace",option+1) == 0)
6593 {
6594 if (*option == '+')
6595 {
6596 image_info->interlace=UndefinedInterlace;
6597 (void) SetImageOption(image_info,option+1,"undefined");
6598 break;
6599 }
cristy042ee782011-04-22 18:48:30 +00006600 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006601 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6602 (void) SetImageOption(image_info,option+1,argv[i+1]);
6603 break;
6604 }
cristyb32b90a2009-09-07 21:45:48 +00006605 if (LocaleCompare("interline-spacing",option+1) == 0)
6606 {
6607 if (*option == '+')
6608 {
6609 (void) SetImageOption(image_info,option+1,"undefined");
6610 break;
6611 }
6612 (void) SetImageOption(image_info,option+1,argv[i+1]);
6613 break;
6614 }
cristy3ed852e2009-09-05 21:47:34 +00006615 if (LocaleCompare("interpolate",option+1) == 0)
6616 {
6617 if (*option == '+')
6618 {
6619 (void) SetImageOption(image_info,option+1,"undefined");
6620 break;
6621 }
6622 (void) SetImageOption(image_info,option+1,argv[i+1]);
6623 break;
6624 }
6625 if (LocaleCompare("interword-spacing",option+1) == 0)
6626 {
6627 if (*option == '+')
6628 {
6629 (void) SetImageOption(image_info,option+1,"undefined");
6630 break;
6631 }
6632 (void) SetImageOption(image_info,option+1,argv[i+1]);
6633 break;
6634 }
6635 break;
6636 }
6637 case 'k':
6638 {
6639 if (LocaleCompare("kerning",option+1) == 0)
6640 {
6641 if (*option == '+')
6642 {
6643 (void) SetImageOption(image_info,option+1,"undefined");
6644 break;
6645 }
6646 (void) SetImageOption(image_info,option+1,argv[i+1]);
6647 break;
6648 }
6649 break;
6650 }
6651 case 'l':
6652 {
6653 if (LocaleCompare("label",option+1) == 0)
6654 {
6655 if (*option == '+')
6656 {
6657 (void) DeleteImageOption(image_info,option+1);
6658 break;
6659 }
6660 (void) SetImageOption(image_info,option+1,argv[i+1]);
6661 break;
6662 }
6663 if (LocaleCompare("limit",option+1) == 0)
6664 {
6665 MagickSizeType
6666 limit;
6667
6668 ResourceType
6669 type;
6670
6671 if (*option == '+')
6672 break;
cristy042ee782011-04-22 18:48:30 +00006673 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006674 MagickFalse,argv[i+1]);
6675 limit=MagickResourceInfinity;
6676 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006677 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006678 (void) SetMagickResourceLimit(type,limit);
6679 break;
6680 }
6681 if (LocaleCompare("list",option+1) == 0)
6682 {
cristybb503372010-05-27 20:51:26 +00006683 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006684 list;
6685
6686 /*
6687 Display configuration list.
6688 */
cristy042ee782011-04-22 18:48:30 +00006689 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006690 switch (list)
6691 {
6692 case MagickCoderOptions:
6693 {
6694 (void) ListCoderInfo((FILE *) NULL,exception);
6695 break;
6696 }
6697 case MagickColorOptions:
6698 {
6699 (void) ListColorInfo((FILE *) NULL,exception);
6700 break;
6701 }
6702 case MagickConfigureOptions:
6703 {
6704 (void) ListConfigureInfo((FILE *) NULL,exception);
6705 break;
6706 }
6707 case MagickDelegateOptions:
6708 {
6709 (void) ListDelegateInfo((FILE *) NULL,exception);
6710 break;
6711 }
6712 case MagickFontOptions:
6713 {
6714 (void) ListTypeInfo((FILE *) NULL,exception);
6715 break;
6716 }
6717 case MagickFormatOptions:
6718 {
6719 (void) ListMagickInfo((FILE *) NULL,exception);
6720 break;
6721 }
6722 case MagickLocaleOptions:
6723 {
6724 (void) ListLocaleInfo((FILE *) NULL,exception);
6725 break;
6726 }
6727 case MagickLogOptions:
6728 {
6729 (void) ListLogInfo((FILE *) NULL,exception);
6730 break;
6731 }
6732 case MagickMagicOptions:
6733 {
6734 (void) ListMagicInfo((FILE *) NULL,exception);
6735 break;
6736 }
6737 case MagickMimeOptions:
6738 {
6739 (void) ListMimeInfo((FILE *) NULL,exception);
6740 break;
6741 }
6742 case MagickModuleOptions:
6743 {
6744 (void) ListModuleInfo((FILE *) NULL,exception);
6745 break;
6746 }
6747 case MagickPolicyOptions:
6748 {
6749 (void) ListPolicyInfo((FILE *) NULL,exception);
6750 break;
6751 }
6752 case MagickResourceOptions:
6753 {
6754 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6755 break;
6756 }
6757 case MagickThresholdOptions:
6758 {
6759 (void) ListThresholdMaps((FILE *) NULL,exception);
6760 break;
6761 }
6762 default:
6763 {
cristy042ee782011-04-22 18:48:30 +00006764 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006765 exception);
6766 break;
6767 }
6768 }
cristyaeb2cbc2010-05-07 13:28:58 +00006769 break;
cristy3ed852e2009-09-05 21:47:34 +00006770 }
6771 if (LocaleCompare("log",option+1) == 0)
6772 {
6773 if (*option == '+')
6774 break;
6775 (void) SetLogFormat(argv[i+1]);
6776 break;
6777 }
6778 if (LocaleCompare("loop",option+1) == 0)
6779 {
6780 if (*option == '+')
6781 {
6782 (void) SetImageOption(image_info,option+1,"0");
6783 break;
6784 }
6785 (void) SetImageOption(image_info,option+1,argv[i+1]);
6786 break;
6787 }
6788 break;
6789 }
6790 case 'm':
6791 {
6792 if (LocaleCompare("matte",option+1) == 0)
6793 {
6794 if (*option == '+')
6795 {
6796 (void) SetImageOption(image_info,option+1,"false");
6797 break;
6798 }
6799 (void) SetImageOption(image_info,option+1,"true");
6800 break;
6801 }
6802 if (LocaleCompare("mattecolor",option+1) == 0)
6803 {
6804 if (*option == '+')
6805 {
6806 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006807 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006808 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006809 break;
6810 }
6811 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006812 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6813 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006814 break;
6815 }
6816 if (LocaleCompare("monitor",option+1) == 0)
6817 {
6818 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6819 (void *) NULL);
6820 break;
6821 }
6822 if (LocaleCompare("monochrome",option+1) == 0)
6823 {
6824 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6825 break;
6826 }
6827 break;
6828 }
6829 case 'o':
6830 {
6831 if (LocaleCompare("orient",option+1) == 0)
6832 {
6833 if (*option == '+')
6834 {
6835 image_info->orientation=UndefinedOrientation;
6836 (void) SetImageOption(image_info,option+1,"undefined");
6837 break;
6838 }
cristy042ee782011-04-22 18:48:30 +00006839 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006840 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006841 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006842 break;
6843 }
6844 }
6845 case 'p':
6846 {
6847 if (LocaleCompare("page",option+1) == 0)
6848 {
6849 char
6850 *canonical_page,
6851 page[MaxTextExtent];
6852
6853 const char
6854 *image_option;
6855
6856 MagickStatusType
6857 flags;
6858
6859 RectangleInfo
6860 geometry;
6861
6862 if (*option == '+')
6863 {
6864 (void) DeleteImageOption(image_info,option+1);
6865 (void) CloneString(&image_info->page,(char *) NULL);
6866 break;
6867 }
6868 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6869 image_option=GetImageOption(image_info,"page");
6870 if (image_option != (const char *) NULL)
6871 flags=ParseAbsoluteGeometry(image_option,&geometry);
6872 canonical_page=GetPageGeometry(argv[i+1]);
6873 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6874 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006875 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006876 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006877 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006878 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006879 (unsigned long) geometry.width,(unsigned long) geometry.height,
6880 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006881 (void) SetImageOption(image_info,option+1,page);
6882 (void) CloneString(&image_info->page,page);
6883 break;
6884 }
cristy3ed852e2009-09-05 21:47:34 +00006885 if (LocaleCompare("ping",option+1) == 0)
6886 {
6887 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6888 break;
6889 }
6890 if (LocaleCompare("pointsize",option+1) == 0)
6891 {
6892 if (*option == '+')
6893 geometry_info.rho=0.0;
6894 else
6895 (void) ParseGeometry(argv[i+1],&geometry_info);
6896 image_info->pointsize=geometry_info.rho;
6897 break;
6898 }
cristye7f51092010-01-17 00:39:37 +00006899 if (LocaleCompare("precision",option+1) == 0)
6900 {
cristybf2766a2010-01-17 03:33:23 +00006901 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006902 break;
6903 }
cristy3ed852e2009-09-05 21:47:34 +00006904 if (LocaleCompare("preview",option+1) == 0)
6905 {
6906 /*
6907 Preview image.
6908 */
6909 if (*option == '+')
6910 {
6911 image_info->preview_type=UndefinedPreview;
6912 break;
6913 }
cristy042ee782011-04-22 18:48:30 +00006914 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006915 MagickPreviewOptions,MagickFalse,argv[i+1]);
6916 break;
6917 }
6918 break;
6919 }
6920 case 'q':
6921 {
6922 if (LocaleCompare("quality",option+1) == 0)
6923 {
6924 /*
6925 Set image compression quality.
6926 */
6927 if (*option == '+')
6928 {
6929 image_info->quality=UndefinedCompressionQuality;
6930 (void) SetImageOption(image_info,option+1,"0");
6931 break;
6932 }
cristye27293e2009-12-18 02:53:20 +00006933 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006934 (void) SetImageOption(image_info,option+1,argv[i+1]);
6935 break;
6936 }
6937 if (LocaleCompare("quiet",option+1) == 0)
6938 {
6939 static WarningHandler
6940 warning_handler = (WarningHandler) NULL;
6941
6942 if (*option == '+')
6943 {
6944 /*
6945 Restore error or warning messages.
6946 */
6947 warning_handler=SetWarningHandler(warning_handler);
6948 break;
6949 }
6950 /*
6951 Suppress error or warning messages.
6952 */
6953 warning_handler=SetWarningHandler((WarningHandler) NULL);
6954 break;
6955 }
6956 break;
6957 }
6958 case 'r':
6959 {
6960 if (LocaleCompare("red-primary",option+1) == 0)
6961 {
6962 if (*option == '+')
6963 {
6964 (void) SetImageOption(image_info,option+1,"0.0");
6965 break;
6966 }
6967 (void) SetImageOption(image_info,option+1,argv[i+1]);
6968 break;
6969 }
6970 break;
6971 }
6972 case 's':
6973 {
6974 if (LocaleCompare("sampling-factor",option+1) == 0)
6975 {
6976 /*
6977 Set image sampling factor.
6978 */
6979 if (*option == '+')
6980 {
6981 if (image_info->sampling_factor != (char *) NULL)
6982 image_info->sampling_factor=DestroyString(
6983 image_info->sampling_factor);
6984 break;
6985 }
6986 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
6987 break;
6988 }
6989 if (LocaleCompare("scene",option+1) == 0)
6990 {
6991 /*
6992 Set image scene.
6993 */
6994 if (*option == '+')
6995 {
6996 image_info->scene=0;
6997 (void) SetImageOption(image_info,option+1,"0");
6998 break;
6999 }
cristye27293e2009-12-18 02:53:20 +00007000 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007001 (void) SetImageOption(image_info,option+1,argv[i+1]);
7002 break;
7003 }
7004 if (LocaleCompare("seed",option+1) == 0)
7005 {
cristybb503372010-05-27 20:51:26 +00007006 size_t
cristy3ed852e2009-09-05 21:47:34 +00007007 seed;
7008
7009 if (*option == '+')
7010 {
cristybb503372010-05-27 20:51:26 +00007011 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007012 SeedPseudoRandomGenerator(seed);
7013 break;
7014 }
cristye27293e2009-12-18 02:53:20 +00007015 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007016 SeedPseudoRandomGenerator(seed);
7017 break;
7018 }
7019 if (LocaleCompare("size",option+1) == 0)
7020 {
7021 if (*option == '+')
7022 {
7023 if (image_info->size != (char *) NULL)
7024 image_info->size=DestroyString(image_info->size);
7025 break;
7026 }
7027 (void) CloneString(&image_info->size,argv[i+1]);
7028 break;
7029 }
7030 if (LocaleCompare("stroke",option+1) == 0)
7031 {
7032 if (*option == '+')
7033 {
7034 (void) SetImageOption(image_info,option+1,"none");
7035 break;
7036 }
7037 (void) SetImageOption(image_info,option+1,argv[i+1]);
7038 break;
7039 }
7040 if (LocaleCompare("strokewidth",option+1) == 0)
7041 {
7042 if (*option == '+')
7043 {
7044 (void) SetImageOption(image_info,option+1,"0");
7045 break;
7046 }
7047 (void) SetImageOption(image_info,option+1,argv[i+1]);
7048 break;
7049 }
cristyd9a29192010-10-16 16:49:53 +00007050 if (LocaleCompare("synchronize",option+1) == 0)
7051 {
7052 if (*option == '+')
7053 {
7054 image_info->synchronize=MagickFalse;
7055 break;
7056 }
7057 image_info->synchronize=MagickTrue;
7058 break;
7059 }
cristy3ed852e2009-09-05 21:47:34 +00007060 break;
7061 }
7062 case 't':
7063 {
7064 if (LocaleCompare("taint",option+1) == 0)
7065 {
7066 if (*option == '+')
7067 {
7068 (void) SetImageOption(image_info,option+1,"false");
7069 break;
7070 }
7071 (void) SetImageOption(image_info,option+1,"true");
7072 break;
7073 }
7074 if (LocaleCompare("texture",option+1) == 0)
7075 {
7076 if (*option == '+')
7077 {
7078 if (image_info->texture != (char *) NULL)
7079 image_info->texture=DestroyString(image_info->texture);
7080 break;
7081 }
7082 (void) CloneString(&image_info->texture,argv[i+1]);
7083 break;
7084 }
7085 if (LocaleCompare("tile-offset",option+1) == 0)
7086 {
7087 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007088 (void) SetImageOption(image_info,option+1,"0");
7089 else
7090 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007091 break;
7092 }
7093 if (LocaleCompare("transparent-color",option+1) == 0)
7094 {
7095 if (*option == '+')
7096 {
cristy9950d572011-10-01 18:22:35 +00007097 (void) QueryColorCompliance("none",AllCompliance,
7098 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007099 (void) SetImageOption(image_info,option+1,"none");
7100 break;
7101 }
cristy9950d572011-10-01 18:22:35 +00007102 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7103 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007104 (void) SetImageOption(image_info,option+1,argv[i+1]);
7105 break;
7106 }
7107 if (LocaleCompare("type",option+1) == 0)
7108 {
7109 if (*option == '+')
7110 {
cristy5f1c1ff2010-12-23 21:38:06 +00007111 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007112 (void) SetImageOption(image_info,option+1,"undefined");
7113 break;
7114 }
cristy042ee782011-04-22 18:48:30 +00007115 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007116 MagickFalse,argv[i+1]);
7117 (void) SetImageOption(image_info,option+1,argv[i+1]);
7118 break;
7119 }
7120 break;
7121 }
7122 case 'u':
7123 {
7124 if (LocaleCompare("undercolor",option+1) == 0)
7125 {
7126 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007127 (void) DeleteImageOption(image_info,option+1);
7128 else
7129 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007130 break;
7131 }
7132 if (LocaleCompare("units",option+1) == 0)
7133 {
7134 if (*option == '+')
7135 {
7136 image_info->units=UndefinedResolution;
7137 (void) SetImageOption(image_info,option+1,"undefined");
7138 break;
7139 }
cristy042ee782011-04-22 18:48:30 +00007140 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007141 MagickResolutionOptions,MagickFalse,argv[i+1]);
7142 (void) SetImageOption(image_info,option+1,argv[i+1]);
7143 break;
7144 }
7145 break;
7146 }
7147 case 'v':
7148 {
7149 if (LocaleCompare("verbose",option+1) == 0)
7150 {
7151 if (*option == '+')
7152 {
7153 image_info->verbose=MagickFalse;
7154 break;
7155 }
7156 image_info->verbose=MagickTrue;
7157 image_info->ping=MagickFalse;
7158 break;
7159 }
7160 if (LocaleCompare("view",option+1) == 0)
7161 {
7162 if (*option == '+')
7163 {
7164 if (image_info->view != (char *) NULL)
7165 image_info->view=DestroyString(image_info->view);
7166 break;
7167 }
7168 (void) CloneString(&image_info->view,argv[i+1]);
7169 break;
7170 }
7171 if (LocaleCompare("virtual-pixel",option+1) == 0)
7172 {
7173 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007174 (void) SetImageOption(image_info,option+1,"undefined");
7175 else
7176 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007177 break;
7178 }
7179 break;
7180 }
7181 case 'w':
7182 {
7183 if (LocaleCompare("white-point",option+1) == 0)
7184 {
7185 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007186 (void) SetImageOption(image_info,option+1,"0.0");
7187 else
7188 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007189 break;
7190 }
7191 break;
7192 }
7193 default:
7194 break;
7195 }
7196 i+=count;
7197 }
7198 return(MagickTrue);
7199}
7200
7201/*
7202%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7203% %
7204% %
7205% %
7206+ M o g r i f y I m a g e L i s t %
7207% %
7208% %
7209% %
7210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7211%
7212% MogrifyImageList() applies any command line options that might affect the
7213% entire image list (e.g. -append, -coalesce, etc.).
7214%
7215% The format of the MogrifyImage method is:
7216%
7217% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7218% const char **argv,Image **images,ExceptionInfo *exception)
7219%
7220% A description of each parameter follows:
7221%
7222% o image_info: the image info..
7223%
7224% o argc: Specifies a pointer to an integer describing the number of
7225% elements in the argument vector.
7226%
7227% o argv: Specifies a pointer to a text array containing the command line
7228% arguments.
7229%
anthonye9c27192011-03-27 08:07:06 +00007230% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007231%
7232% o exception: return any errors or warnings in this structure.
7233%
7234*/
7235WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7236 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7237{
cristy3ed852e2009-09-05 21:47:34 +00007238 const char
7239 *option;
7240
cristy6b3da3a2010-06-20 02:21:46 +00007241 ImageInfo
7242 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007243
7244 MagickStatusType
7245 status;
7246
cristy28474bf2011-09-11 23:32:52 +00007247 PixelInterpolateMethod
7248 interpolate_method;
7249
cristy3ed852e2009-09-05 21:47:34 +00007250 QuantizeInfo
7251 *quantize_info;
7252
cristybb503372010-05-27 20:51:26 +00007253 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007254 i;
7255
cristy6b3da3a2010-06-20 02:21:46 +00007256 ssize_t
7257 count,
7258 index;
7259
cristy3ed852e2009-09-05 21:47:34 +00007260 /*
7261 Apply options to the image list.
7262 */
7263 assert(image_info != (ImageInfo *) NULL);
7264 assert(image_info->signature == MagickSignature);
7265 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007266 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007267 assert((*images)->signature == MagickSignature);
7268 if ((*images)->debug != MagickFalse)
7269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7270 (*images)->filename);
7271 if ((argc <= 0) || (*argv == (char *) NULL))
7272 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007273 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007274 mogrify_info=CloneImageInfo(image_info);
7275 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007276 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007277 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007278 {
cristy74fe8f12009-10-03 19:09:01 +00007279 if (*images == (Image *) NULL)
7280 break;
cristy3ed852e2009-09-05 21:47:34 +00007281 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007282 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007283 continue;
cristy042ee782011-04-22 18:48:30 +00007284 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007285 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007286 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007287 break;
cristy6b3da3a2010-06-20 02:21:46 +00007288 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007289 switch (*(option+1))
7290 {
7291 case 'a':
7292 {
7293 if (LocaleCompare("affinity",option+1) == 0)
7294 {
cristy6fccee12011-10-20 18:43:18 +00007295 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007296 if (*option == '+')
7297 {
cristy018f07f2011-09-04 21:15:19 +00007298 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7299 exception);
cristy3ed852e2009-09-05 21:47:34 +00007300 break;
7301 }
7302 i++;
7303 break;
7304 }
7305 if (LocaleCompare("append",option+1) == 0)
7306 {
7307 Image
7308 *append_image;
7309
cristy6fccee12011-10-20 18:43:18 +00007310 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007311 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7312 MagickFalse,exception);
7313 if (append_image == (Image *) NULL)
7314 {
7315 status=MagickFalse;
7316 break;
7317 }
7318 *images=DestroyImageList(*images);
7319 *images=append_image;
7320 break;
7321 }
7322 if (LocaleCompare("average",option+1) == 0)
7323 {
7324 Image
7325 *average_image;
7326
cristyd18ae7c2010-03-07 17:39:52 +00007327 /*
7328 Average an image sequence (deprecated).
7329 */
cristy6fccee12011-10-20 18:43:18 +00007330 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007331 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7332 exception);
cristy3ed852e2009-09-05 21:47:34 +00007333 if (average_image == (Image *) NULL)
7334 {
7335 status=MagickFalse;
7336 break;
7337 }
7338 *images=DestroyImageList(*images);
7339 *images=average_image;
7340 break;
7341 }
7342 break;
7343 }
7344 case 'c':
7345 {
cristyd04e7bf2012-03-03 19:19:12 +00007346 if (LocaleCompare("channel-ops",option+1) == 0)
cristy87c02f42012-02-24 00:19:10 +00007347 {
cristyd04e7bf2012-03-03 19:19:12 +00007348 Image
7349 *channel_image;
7350
7351 (void) SyncImagesSettings(mogrify_info,*images,exception);
7352 channel_image=ChannelOperationImage(*images,argv[i+1],exception);
7353 if (channel_image == (Image *) NULL)
7354 {
7355 status=MagickFalse;
7356 break;
7357 }
7358 *images=DestroyImageList(*images);
7359 *images=channel_image;
cristy87c02f42012-02-24 00:19:10 +00007360 break;
7361 }
cristy3ed852e2009-09-05 21:47:34 +00007362 if (LocaleCompare("clut",option+1) == 0)
7363 {
7364 Image
7365 *clut_image,
7366 *image;
7367
cristy6fccee12011-10-20 18:43:18 +00007368 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007369 image=RemoveFirstImageFromList(images);
7370 clut_image=RemoveFirstImageFromList(images);
7371 if (clut_image == (Image *) NULL)
7372 {
7373 status=MagickFalse;
7374 break;
7375 }
cristy28474bf2011-09-11 23:32:52 +00007376 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007377 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007378 *images=DestroyImageList(*images);
7379 *images=image;
7380 break;
7381 }
7382 if (LocaleCompare("coalesce",option+1) == 0)
7383 {
7384 Image
7385 *coalesce_image;
7386
cristy6fccee12011-10-20 18:43:18 +00007387 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007388 coalesce_image=CoalesceImages(*images,exception);
7389 if (coalesce_image == (Image *) NULL)
7390 {
7391 status=MagickFalse;
7392 break;
7393 }
7394 *images=DestroyImageList(*images);
7395 *images=coalesce_image;
7396 break;
7397 }
7398 if (LocaleCompare("combine",option+1) == 0)
7399 {
7400 Image
7401 *combine_image;
7402
cristy6fccee12011-10-20 18:43:18 +00007403 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007404 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007405 if (combine_image == (Image *) NULL)
7406 {
7407 status=MagickFalse;
7408 break;
7409 }
7410 *images=DestroyImageList(*images);
7411 *images=combine_image;
7412 break;
7413 }
7414 if (LocaleCompare("composite",option+1) == 0)
7415 {
7416 Image
7417 *mask_image,
7418 *composite_image,
7419 *image;
7420
7421 RectangleInfo
7422 geometry;
7423
cristy6fccee12011-10-20 18:43:18 +00007424 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007425 image=RemoveFirstImageFromList(images);
7426 composite_image=RemoveFirstImageFromList(images);
7427 if (composite_image == (Image *) NULL)
7428 {
7429 status=MagickFalse;
7430 break;
7431 }
7432 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007433 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007434 SetGeometry(composite_image,&geometry);
7435 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7436 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7437 &geometry);
7438 mask_image=RemoveFirstImageFromList(images);
7439 if (mask_image != (Image *) NULL)
7440 {
7441 if ((image->compose == DisplaceCompositeOp) ||
7442 (image->compose == DistortCompositeOp))
7443 {
7444 /*
7445 Merge Y displacement into X displacement image.
7446 */
7447 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007448 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007449 mask_image=DestroyImage(mask_image);
7450 }
7451 else
7452 {
7453 /*
anthony80c37752012-01-16 01:03:11 +00007454 Set a blending mask for the composition.
cristy3ed852e2009-09-05 21:47:34 +00007455 */
cristy10a6c612012-01-29 21:41:05 +00007456 (void) NegateImage(mask_image,MagickFalse,exception);
7457 (void) SetImageMask(image,mask_image,exception);
7458 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00007459 }
7460 }
cristyf4ad9df2011-07-08 16:49:03 +00007461 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007462 geometry.x,geometry.y,exception);
cristy10a6c612012-01-29 21:41:05 +00007463 (void) SetImageMask(image,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00007464 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007465 *images=DestroyImageList(*images);
7466 *images=image;
7467 break;
7468 }
cristy3ed852e2009-09-05 21:47:34 +00007469 break;
7470 }
7471 case 'd':
7472 {
7473 if (LocaleCompare("deconstruct",option+1) == 0)
7474 {
7475 Image
7476 *deconstruct_image;
7477
cristy6fccee12011-10-20 18:43:18 +00007478 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007479 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007480 exception);
cristy3ed852e2009-09-05 21:47:34 +00007481 if (deconstruct_image == (Image *) NULL)
7482 {
7483 status=MagickFalse;
7484 break;
7485 }
7486 *images=DestroyImageList(*images);
7487 *images=deconstruct_image;
7488 break;
7489 }
7490 if (LocaleCompare("delete",option+1) == 0)
7491 {
7492 if (*option == '+')
7493 DeleteImages(images,"-1",exception);
7494 else
7495 DeleteImages(images,argv[i+1],exception);
7496 break;
7497 }
7498 if (LocaleCompare("dither",option+1) == 0)
7499 {
7500 if (*option == '+')
7501 {
7502 quantize_info->dither=MagickFalse;
7503 break;
7504 }
7505 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007506 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007507 MagickDitherOptions,MagickFalse,argv[i+1]);
7508 break;
7509 }
cristyecb10ff2011-03-22 13:14:03 +00007510 if (LocaleCompare("duplicate",option+1) == 0)
7511 {
cristy72988482011-03-29 16:34:38 +00007512 Image
7513 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007514
anthony2b6bcae2011-03-23 13:05:34 +00007515 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007516 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7517 else
7518 {
7519 const char
7520 *p;
7521
anthony2b6bcae2011-03-23 13:05:34 +00007522 size_t
7523 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007524
anthony2b6bcae2011-03-23 13:05:34 +00007525 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007526 p=strchr(argv[i+1],',');
7527 if (p == (const char *) NULL)
7528 duplicate_images=DuplicateImages(*images,number_duplicates,
7529 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007530 else
cristy72988482011-03-29 16:34:38 +00007531 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7532 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007533 }
7534 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007535 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007536 break;
7537 }
cristy3ed852e2009-09-05 21:47:34 +00007538 break;
7539 }
cristyd18ae7c2010-03-07 17:39:52 +00007540 case 'e':
7541 {
7542 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7543 {
7544 Image
7545 *evaluate_image;
7546
7547 MagickEvaluateOperator
7548 op;
7549
cristy6fccee12011-10-20 18:43:18 +00007550 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007551 op=(MagickEvaluateOperator) ParseCommandOption(
7552 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007553 evaluate_image=EvaluateImages(*images,op,exception);
7554 if (evaluate_image == (Image *) NULL)
7555 {
7556 status=MagickFalse;
7557 break;
7558 }
7559 *images=DestroyImageList(*images);
7560 *images=evaluate_image;
7561 break;
7562 }
7563 break;
7564 }
cristy3ed852e2009-09-05 21:47:34 +00007565 case 'f':
7566 {
cristyf0a247f2009-10-04 00:20:03 +00007567 if (LocaleCompare("fft",option+1) == 0)
7568 {
7569 Image
7570 *fourier_image;
7571
7572 /*
7573 Implements the discrete Fourier transform (DFT).
7574 */
cristy6fccee12011-10-20 18:43:18 +00007575 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007576 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7577 MagickTrue : MagickFalse,exception);
7578 if (fourier_image == (Image *) NULL)
7579 break;
7580 *images=DestroyImage(*images);
7581 *images=fourier_image;
7582 break;
7583 }
cristy3ed852e2009-09-05 21:47:34 +00007584 if (LocaleCompare("flatten",option+1) == 0)
7585 {
7586 Image
7587 *flatten_image;
7588
cristy6fccee12011-10-20 18:43:18 +00007589 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007590 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7591 if (flatten_image == (Image *) NULL)
7592 break;
7593 *images=DestroyImageList(*images);
7594 *images=flatten_image;
7595 break;
7596 }
7597 if (LocaleCompare("fx",option+1) == 0)
7598 {
7599 Image
7600 *fx_image;
7601
cristy6fccee12011-10-20 18:43:18 +00007602 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007603 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007604 if (fx_image == (Image *) NULL)
7605 {
7606 status=MagickFalse;
7607 break;
7608 }
7609 *images=DestroyImageList(*images);
7610 *images=fx_image;
7611 break;
7612 }
7613 break;
7614 }
7615 case 'h':
7616 {
7617 if (LocaleCompare("hald-clut",option+1) == 0)
7618 {
7619 Image
7620 *hald_image,
7621 *image;
7622
cristy6fccee12011-10-20 18:43:18 +00007623 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007624 image=RemoveFirstImageFromList(images);
7625 hald_image=RemoveFirstImageFromList(images);
7626 if (hald_image == (Image *) NULL)
7627 {
7628 status=MagickFalse;
7629 break;
7630 }
cristy7c0a0a42011-08-23 17:57:25 +00007631 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007632 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007633 if (*images != (Image *) NULL)
7634 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007635 *images=image;
7636 break;
7637 }
7638 break;
7639 }
7640 case 'i':
7641 {
7642 if (LocaleCompare("ift",option+1) == 0)
7643 {
7644 Image
cristy8587f882009-11-13 20:28:49 +00007645 *fourier_image,
7646 *magnitude_image,
7647 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007648
7649 /*
7650 Implements the inverse fourier discrete Fourier transform (DFT).
7651 */
cristy6fccee12011-10-20 18:43:18 +00007652 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007653 magnitude_image=RemoveFirstImageFromList(images);
7654 phase_image=RemoveFirstImageFromList(images);
7655 if (phase_image == (Image *) NULL)
7656 {
7657 status=MagickFalse;
7658 break;
7659 }
7660 fourier_image=InverseFourierTransformImage(magnitude_image,
7661 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007662 if (fourier_image == (Image *) NULL)
7663 break;
cristy0aff6ea2009-11-14 01:40:53 +00007664 if (*images != (Image *) NULL)
7665 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007666 *images=fourier_image;
7667 break;
7668 }
7669 if (LocaleCompare("insert",option+1) == 0)
7670 {
7671 Image
7672 *p,
7673 *q;
7674
7675 index=0;
7676 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007677 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007678 p=RemoveLastImageFromList(images);
7679 if (p == (Image *) NULL)
7680 {
7681 (void) ThrowMagickException(exception,GetMagickModule(),
7682 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7683 status=MagickFalse;
7684 break;
7685 }
7686 q=p;
7687 if (index == 0)
7688 PrependImageToList(images,q);
7689 else
cristybb503372010-05-27 20:51:26 +00007690 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007691 AppendImageToList(images,q);
7692 else
7693 {
7694 q=GetImageFromList(*images,index-1);
7695 if (q == (Image *) NULL)
7696 {
7697 (void) ThrowMagickException(exception,GetMagickModule(),
7698 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7699 status=MagickFalse;
7700 break;
7701 }
7702 InsertImageInList(&q,p);
7703 }
7704 *images=GetFirstImageInList(q);
7705 break;
7706 }
cristy28474bf2011-09-11 23:32:52 +00007707 if (LocaleCompare("interpolate",option+1) == 0)
7708 {
7709 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7710 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7711 break;
7712 }
cristy3ed852e2009-09-05 21:47:34 +00007713 break;
7714 }
7715 case 'l':
7716 {
7717 if (LocaleCompare("layers",option+1) == 0)
7718 {
7719 Image
7720 *layers;
7721
7722 ImageLayerMethod
7723 method;
7724
cristy6fccee12011-10-20 18:43:18 +00007725 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007726 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007727 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007728 MagickFalse,argv[i+1]);
7729 switch (method)
7730 {
7731 case CoalesceLayer:
7732 {
7733 layers=CoalesceImages(*images,exception);
7734 break;
7735 }
7736 case CompareAnyLayer:
7737 case CompareClearLayer:
7738 case CompareOverlayLayer:
7739 default:
7740 {
cristy8a9106f2011-07-05 14:39:26 +00007741 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007742 break;
7743 }
7744 case MergeLayer:
7745 case FlattenLayer:
7746 case MosaicLayer:
7747 case TrimBoundsLayer:
7748 {
7749 layers=MergeImageLayers(*images,method,exception);
7750 break;
7751 }
7752 case DisposeLayer:
7753 {
7754 layers=DisposeImages(*images,exception);
7755 break;
7756 }
7757 case OptimizeImageLayer:
7758 {
7759 layers=OptimizeImageLayers(*images,exception);
7760 break;
7761 }
7762 case OptimizePlusLayer:
7763 {
7764 layers=OptimizePlusImageLayers(*images,exception);
7765 break;
7766 }
7767 case OptimizeTransLayer:
7768 {
7769 OptimizeImageTransparency(*images,exception);
7770 break;
7771 }
7772 case RemoveDupsLayer:
7773 {
7774 RemoveDuplicateLayers(images,exception);
7775 break;
7776 }
7777 case RemoveZeroLayer:
7778 {
7779 RemoveZeroDelayLayers(images,exception);
7780 break;
7781 }
7782 case OptimizeLayer:
7783 {
7784 /*
7785 General Purpose, GIF Animation Optimizer.
7786 */
7787 layers=CoalesceImages(*images,exception);
7788 if (layers == (Image *) NULL)
7789 {
7790 status=MagickFalse;
7791 break;
7792 }
cristy3ed852e2009-09-05 21:47:34 +00007793 *images=DestroyImageList(*images);
7794 *images=layers;
7795 layers=OptimizeImageLayers(*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=(Image *) NULL;
7804 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007805 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7806 exception);
cristy3ed852e2009-09-05 21:47:34 +00007807 break;
7808 }
7809 case CompositeLayer:
7810 {
7811 CompositeOperator
7812 compose;
7813
7814 Image
7815 *source;
7816
7817 RectangleInfo
7818 geometry;
7819
7820 /*
7821 Split image sequence at the first 'NULL:' image.
7822 */
7823 source=(*images);
7824 while (source != (Image *) NULL)
7825 {
7826 source=GetNextImageInList(source);
7827 if ((source != (Image *) NULL) &&
7828 (LocaleCompare(source->magick,"NULL") == 0))
7829 break;
7830 }
7831 if (source != (Image *) NULL)
7832 {
7833 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7834 (GetNextImageInList(source) == (Image *) NULL))
7835 source=(Image *) NULL;
7836 else
7837 {
7838 /*
7839 Separate the two lists, junk the null: image.
7840 */
7841 source=SplitImageList(source->previous);
7842 DeleteImageFromList(&source);
7843 }
7844 }
7845 if (source == (Image *) NULL)
7846 {
7847 (void) ThrowMagickException(exception,GetMagickModule(),
7848 OptionError,"MissingNullSeparator","layers Composite");
7849 status=MagickFalse;
7850 break;
7851 }
7852 /*
7853 Adjust offset with gravity and virtual canvas.
7854 */
7855 SetGeometry(*images,&geometry);
7856 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7857 geometry.width=source->page.width != 0 ?
7858 source->page.width : source->columns;
7859 geometry.height=source->page.height != 0 ?
7860 source->page.height : source->rows;
7861 GravityAdjustGeometry((*images)->page.width != 0 ?
7862 (*images)->page.width : (*images)->columns,
7863 (*images)->page.height != 0 ? (*images)->page.height :
7864 (*images)->rows,(*images)->gravity,&geometry);
7865 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007866 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007867 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007868 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007869 MagickComposeOptions,MagickFalse,option);
7870 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7871 exception);
7872 source=DestroyImageList(source);
7873 break;
7874 }
7875 }
7876 if (layers == (Image *) NULL)
7877 break;
cristy3ed852e2009-09-05 21:47:34 +00007878 *images=DestroyImageList(*images);
7879 *images=layers;
7880 break;
7881 }
7882 break;
7883 }
7884 case 'm':
7885 {
7886 if (LocaleCompare("map",option+1) == 0)
7887 {
cristy6fccee12011-10-20 18:43:18 +00007888 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007889 if (*option == '+')
7890 {
cristy018f07f2011-09-04 21:15:19 +00007891 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7892 exception);
cristy3ed852e2009-09-05 21:47:34 +00007893 break;
7894 }
7895 i++;
7896 break;
7897 }
cristyf40785b2010-03-06 02:27:27 +00007898 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007899 {
7900 Image
cristyf40785b2010-03-06 02:27:27 +00007901 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007902
cristyd18ae7c2010-03-07 17:39:52 +00007903 /*
7904 Maximum image sequence (deprecated).
7905 */
cristy6fccee12011-10-20 18:43:18 +00007906 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007907 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007908 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007909 {
7910 status=MagickFalse;
7911 break;
7912 }
7913 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007914 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007915 break;
7916 }
cristyf40785b2010-03-06 02:27:27 +00007917 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007918 {
7919 Image
cristyf40785b2010-03-06 02:27:27 +00007920 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007921
cristyd18ae7c2010-03-07 17:39:52 +00007922 /*
7923 Minimum image sequence (deprecated).
7924 */
cristy6fccee12011-10-20 18:43:18 +00007925 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007926 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007927 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007928 {
7929 status=MagickFalse;
7930 break;
7931 }
7932 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007933 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007934 break;
7935 }
cristy3ed852e2009-09-05 21:47:34 +00007936 if (LocaleCompare("morph",option+1) == 0)
7937 {
7938 Image
7939 *morph_image;
7940
cristy6fccee12011-10-20 18:43:18 +00007941 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007942 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007943 exception);
7944 if (morph_image == (Image *) NULL)
7945 {
7946 status=MagickFalse;
7947 break;
7948 }
7949 *images=DestroyImageList(*images);
7950 *images=morph_image;
7951 break;
7952 }
7953 if (LocaleCompare("mosaic",option+1) == 0)
7954 {
7955 Image
7956 *mosaic_image;
7957
cristy6fccee12011-10-20 18:43:18 +00007958 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007959 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7960 if (mosaic_image == (Image *) NULL)
7961 {
7962 status=MagickFalse;
7963 break;
7964 }
7965 *images=DestroyImageList(*images);
7966 *images=mosaic_image;
7967 break;
7968 }
7969 break;
7970 }
7971 case 'p':
7972 {
7973 if (LocaleCompare("print",option+1) == 0)
7974 {
7975 char
7976 *string;
7977
cristy6fccee12011-10-20 18:43:18 +00007978 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007979 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
7980 exception);
cristy3ed852e2009-09-05 21:47:34 +00007981 if (string == (char *) NULL)
7982 break;
cristyb51dff52011-05-19 16:55:47 +00007983 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00007984 string=DestroyString(string);
7985 }
7986 if (LocaleCompare("process",option+1) == 0)
7987 {
7988 char
7989 **arguments;
7990
7991 int
7992 j,
7993 number_arguments;
7994
cristy6fccee12011-10-20 18:43:18 +00007995 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007996 arguments=StringToArgv(argv[i+1],&number_arguments);
7997 if (arguments == (char **) NULL)
7998 break;
7999 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8000 {
8001 char
8002 breaker,
8003 quote,
8004 *token;
8005
8006 const char
8007 *arguments;
8008
8009 int
8010 next,
8011 status;
8012
8013 size_t
8014 length;
8015
8016 TokenInfo
8017 *token_info;
8018
8019 /*
8020 Support old style syntax, filter="-option arg".
8021 */
8022 length=strlen(argv[i+1]);
8023 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008024 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008025 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8026 sizeof(*token));
8027 if (token == (char *) NULL)
8028 break;
8029 next=0;
8030 arguments=argv[i+1];
8031 token_info=AcquireTokenInfo();
8032 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8033 "\"",'\0',&breaker,&next,&quote);
8034 token_info=DestroyTokenInfo(token_info);
8035 if (status == 0)
8036 {
8037 const char
8038 *argv;
8039
8040 argv=(&(arguments[next]));
8041 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8042 exception);
8043 }
8044 token=DestroyString(token);
8045 break;
8046 }
cristy91c0da22010-05-02 01:44:07 +00008047 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008048 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8049 number_arguments-2,(const char **) arguments+2,exception);
8050 for (j=0; j < number_arguments; j++)
8051 arguments[j]=DestroyString(arguments[j]);
8052 arguments=(char **) RelinquishMagickMemory(arguments);
8053 break;
8054 }
8055 break;
8056 }
8057 case 'r':
8058 {
8059 if (LocaleCompare("reverse",option+1) == 0)
8060 {
8061 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008062 break;
8063 }
8064 break;
8065 }
8066 case 's':
8067 {
cristy4285d782011-02-09 20:12:28 +00008068 if (LocaleCompare("smush",option+1) == 0)
8069 {
8070 Image
8071 *smush_image;
8072
8073 ssize_t
8074 offset;
8075
cristy6fccee12011-10-20 18:43:18 +00008076 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008077 offset=(ssize_t) StringToLong(argv[i+1]);
8078 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8079 MagickFalse,offset,exception);
8080 if (smush_image == (Image *) NULL)
8081 {
8082 status=MagickFalse;
8083 break;
8084 }
8085 *images=DestroyImageList(*images);
8086 *images=smush_image;
8087 break;
8088 }
cristy3ed852e2009-09-05 21:47:34 +00008089 if (LocaleCompare("swap",option+1) == 0)
8090 {
8091 Image
8092 *p,
8093 *q,
8094 *swap;
8095
cristybb503372010-05-27 20:51:26 +00008096 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008097 swap_index;
8098
8099 index=(-1);
8100 swap_index=(-2);
8101 if (*option != '+')
8102 {
8103 GeometryInfo
8104 geometry_info;
8105
8106 MagickStatusType
8107 flags;
8108
8109 swap_index=(-1);
8110 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008111 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008112 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008113 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008114 }
8115 p=GetImageFromList(*images,index);
8116 q=GetImageFromList(*images,swap_index);
8117 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8118 {
8119 (void) ThrowMagickException(exception,GetMagickModule(),
8120 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8121 status=MagickFalse;
8122 break;
8123 }
8124 if (p == q)
8125 break;
8126 swap=CloneImage(p,0,0,MagickTrue,exception);
8127 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8128 ReplaceImageInList(&q,swap);
8129 *images=GetFirstImageInList(q);
8130 break;
8131 }
8132 break;
8133 }
8134 case 'w':
8135 {
8136 if (LocaleCompare("write",option+1) == 0)
8137 {
cristy071dd7b2010-04-09 13:04:54 +00008138 char
cristy06609ee2010-03-17 20:21:27 +00008139 key[MaxTextExtent];
8140
cristy3ed852e2009-09-05 21:47:34 +00008141 Image
8142 *write_images;
8143
8144 ImageInfo
8145 *write_info;
8146
cristy6fccee12011-10-20 18:43:18 +00008147 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008148 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008149 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008150 write_images=(*images);
8151 if (*option == '+')
8152 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008153 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008154 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8155 write_info=DestroyImageInfo(write_info);
8156 if (*option == '+')
8157 write_images=DestroyImageList(write_images);
8158 break;
8159 }
8160 break;
8161 }
8162 default:
8163 break;
8164 }
8165 i+=count;
8166 }
8167 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008168 mogrify_info=DestroyImageInfo(mogrify_info);
8169 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008170 return(status != 0 ? MagickTrue : MagickFalse);
8171}
8172
8173/*
8174%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8175% %
8176% %
8177% %
8178+ M o g r i f y I m a g e s %
8179% %
8180% %
8181% %
8182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8183%
8184% MogrifyImages() applies image processing options to a sequence of images as
8185% prescribed by command line options.
8186%
8187% The format of the MogrifyImage method is:
8188%
8189% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8190% const MagickBooleanType post,const int argc,const char **argv,
8191% Image **images,Exceptioninfo *exception)
8192%
8193% A description of each parameter follows:
8194%
8195% o image_info: the image info..
8196%
8197% o post: If true, post process image list operators otherwise pre-process.
8198%
8199% o argc: Specifies a pointer to an integer describing the number of
8200% elements in the argument vector.
8201%
8202% o argv: Specifies a pointer to a text array containing the command line
8203% arguments.
8204%
anthonye9c27192011-03-27 08:07:06 +00008205% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008206%
8207% o exception: return any errors or warnings in this structure.
8208%
8209*/
8210WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8211 const MagickBooleanType post,const int argc,const char **argv,
8212 Image **images,ExceptionInfo *exception)
8213{
8214#define MogrifyImageTag "Mogrify/Image"
8215
anthonye9c27192011-03-27 08:07:06 +00008216 MagickStatusType
8217 status;
cristy3ed852e2009-09-05 21:47:34 +00008218
cristy0e9f9c12010-02-11 03:00:47 +00008219 MagickBooleanType
8220 proceed;
8221
anthonye9c27192011-03-27 08:07:06 +00008222 size_t
8223 n;
cristy3ed852e2009-09-05 21:47:34 +00008224
cristybb503372010-05-27 20:51:26 +00008225 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008226 i;
8227
cristy3ed852e2009-09-05 21:47:34 +00008228 assert(image_info != (ImageInfo *) NULL);
8229 assert(image_info->signature == MagickSignature);
8230 if (images == (Image **) NULL)
8231 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008232 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008233 assert((*images)->signature == MagickSignature);
8234 if ((*images)->debug != MagickFalse)
8235 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8236 (*images)->filename);
8237 if ((argc <= 0) || (*argv == (char *) NULL))
8238 return(MagickTrue);
8239 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8240 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008241 status=0;
anthonye9c27192011-03-27 08:07:06 +00008242
anthonyce2716b2011-04-22 09:51:34 +00008243#if 0
cristy1e604812011-05-19 18:07:50 +00008244 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8245 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008246#endif
8247
anthonye9c27192011-03-27 08:07:06 +00008248 /*
8249 Pre-process multi-image sequence operators
8250 */
cristy3ed852e2009-09-05 21:47:34 +00008251 if (post == MagickFalse)
8252 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008253 /*
8254 For each image, process simple single image operators
8255 */
8256 i=0;
8257 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008258 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008259 {
anthonyce2716b2011-04-22 09:51:34 +00008260#if 0
cristy1e604812011-05-19 18:07:50 +00008261 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8262 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008263#endif
anthonye9c27192011-03-27 08:07:06 +00008264 status&=MogrifyImage(image_info,argc,argv,images,exception);
8265 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008266 if (proceed == MagickFalse)
8267 break;
anthonye9c27192011-03-27 08:07:06 +00008268 if ( (*images)->next == (Image *) NULL )
8269 break;
8270 *images=(*images)->next;
8271 i++;
cristy3ed852e2009-09-05 21:47:34 +00008272 }
anthonye9c27192011-03-27 08:07:06 +00008273 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008274#if 0
cristy1e604812011-05-19 18:07:50 +00008275 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8276 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008277#endif
anthonye9c27192011-03-27 08:07:06 +00008278
8279 /*
8280 Post-process, multi-image sequence operators
8281 */
8282 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008283 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008284 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008285 return(status != 0 ? MagickTrue : MagickFalse);
8286}