blob: 16baf3281f775a14e4bde1a2e32d7dd6da5df659 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO GGGGG RRRR IIIII FFFFF Y Y %
7% MM MM O O G R R I F Y Y %
8% M M M O O G GGG RRRR I FFF Y %
9% M M O O G G R R I F Y %
10% M M OOO GGGG R R IIIII F Y %
11% %
12% %
13% MagickWand Module Methods %
14% %
15% Software Design %
16% John Cristy %
17% March 2000 %
18% %
19% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37% draw on, flip, join, re-sample, and much more. This tool is similiar to
38% convert except that the original image file is overwritten (unless you
39% change the file suffix with the -format option) with any changes you
cristy6a917d92009-10-06 19:23:54 +000040% request.
cristy3ed852e2009-09-05 21:47:34 +000041%
42*/
43
44/*
45 Include declarations.
46*/
cristy4c08aed2011-07-01 19:47:50 +000047#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#undef DegreesToRadians
51#undef RadiansToDegrees
52#include "MagickCore/image-private.h"
53#include "MagickCore/monitor-private.h"
cristy4c08aed2011-07-01 19:47:50 +000054#include "MagickCore/string-private.h"
cristy0740a982011-10-13 15:01:01 +000055#include "MagickCore/thread-private.h"
cristy18c6c272011-09-23 14:40:37 +000056#include "MagickCore/utility-private.h"
cristy3ed852e2009-09-05 21:47:34 +000057
58/*
cristy154fa9d2011-08-05 14:25:15 +000059 Constant declaration.
60*/
cristy3a557c02011-08-06 19:48:02 +000061static const char
cristy638895a2011-08-06 23:19:14 +000062 MogrifyBackgroundColor[] = "#ffffff", /* white */
63 MogrifyBorderColor[] = "#dfdfdf", /* gray */
64 MogrifyMatteColor[] = "#bdbdbd"; /* gray */
cristy154fa9d2011-08-05 14:25:15 +000065
66/*
cristy3ed852e2009-09-05 21:47:34 +000067 Define declarations.
68*/
69#define UndefinedCompressionQuality 0UL
70
71/*
cristy3ed852e2009-09-05 21:47:34 +000072%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73% %
74% %
75% %
cristy5063d812010-10-19 16:28:10 +000076% M a g i c k C o m m a n d G e n e s i s %
cristy3980b0d2009-10-25 14:37:13 +000077% %
78% %
79% %
80%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81%
82% MagickCommandGenesis() applies image processing options to an image as
83% prescribed by command line options.
84%
85% The format of the MagickCommandGenesis method is:
86%
87% MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
cristy5063d812010-10-19 16:28:10 +000088% MagickCommand command,int argc,char **argv,char **metadata,
89% ExceptionInfo *exception)
cristy3980b0d2009-10-25 14:37:13 +000090%
91% A description of each parameter follows:
92%
93% o image_info: the image info.
94%
cristy5063d812010-10-19 16:28:10 +000095% o command: Choose from ConvertImageCommand, IdentifyImageCommand,
cristy8a9106f2011-07-05 14:39:26 +000096% MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
cristy5063d812010-10-19 16:28:10 +000097% ConjureImageCommand, StreamImageCommand, ImportImageCommand,
98% DisplayImageCommand, or AnimateImageCommand.
cristy3980b0d2009-10-25 14:37:13 +000099%
100% o argc: Specifies a pointer to an integer describing the number of
101% elements in the argument vector.
102%
103% o argv: Specifies a pointer to a text array containing the command line
104% arguments.
105%
cristy5063d812010-10-19 16:28:10 +0000106% o metadata: any metadata is returned here.
cristy3980b0d2009-10-25 14:37:13 +0000107%
108% o exception: return any errors or warnings in this structure.
109%
110*/
111WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
112 MagickCommand command,int argc,char **argv,char **metadata,
113 ExceptionInfo *exception)
114{
115 char
116 *option;
117
118 double
119 duration,
cristy8ea926d2011-12-09 12:25:04 +0000120 serial;
cristy3980b0d2009-10-25 14:37:13 +0000121
cristy3980b0d2009-10-25 14:37:13 +0000122 MagickBooleanType
123 concurrent,
124 regard_warnings,
125 status;
126
cristybb503372010-05-27 20:51:26 +0000127 register ssize_t
cristy3980b0d2009-10-25 14:37:13 +0000128 i;
129
cristybb503372010-05-27 20:51:26 +0000130 size_t
cristyc2e3aeb2011-12-09 11:09:38 +0000131 iterations,
cristyc2e3aeb2011-12-09 11:09:38 +0000132 number_threads;
cristy3980b0d2009-10-25 14:37:13 +0000133
cristy118fc662012-02-11 00:02:25 +0000134 ssize_t
135 n;
136
cristyd0a94fa2010-03-12 14:18:11 +0000137 (void) setlocale(LC_ALL,"");
138 (void) setlocale(LC_NUMERIC,"C");
cristy3980b0d2009-10-25 14:37:13 +0000139 concurrent=MagickFalse;
140 duration=(-1.0);
141 iterations=1;
cristy33557d72009-11-06 00:54:33 +0000142 status=MagickFalse;
cristy3980b0d2009-10-25 14:37:13 +0000143 regard_warnings=MagickFalse;
cristybb503372010-05-27 20:51:26 +0000144 for (i=1; i < (ssize_t) (argc-1); i++)
cristy3980b0d2009-10-25 14:37:13 +0000145 {
146 option=argv[i];
147 if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
148 continue;
149 if (LocaleCompare("bench",option+1) == 0)
cristye27293e2009-12-18 02:53:20 +0000150 iterations=StringToUnsignedLong(argv[++i]);
cristy3980b0d2009-10-25 14:37:13 +0000151 if (LocaleCompare("concurrent",option+1) == 0)
152 concurrent=MagickTrue;
153 if (LocaleCompare("debug",option+1) == 0)
154 (void) SetLogEventMask(argv[++i]);
155 if (LocaleCompare("duration",option+1) == 0)
cristydbdd0e32011-11-04 23:29:40 +0000156 duration=StringToDouble(argv[++i],(char **) NULL);
cristy3980b0d2009-10-25 14:37:13 +0000157 if (LocaleCompare("regard-warnings",option+1) == 0)
158 regard_warnings=MagickTrue;
159 }
cristy8ea926d2011-12-09 12:25:04 +0000160 if (iterations == 1)
161 {
162 status=command(image_info,argc,argv,metadata,exception);
163 if (exception->severity != UndefinedException)
164 {
165 if ((exception->severity > ErrorException) ||
166 (regard_warnings != MagickFalse))
167 status=MagickTrue;
168 CatchException(exception);
169 }
170 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
171 {
172 (void) fputs(*metadata,stdout);
173 (void) fputc('\n',stdout);
174 *metadata=DestroyString(*metadata);
175 }
176 return(status);
177 }
cristyc2e3aeb2011-12-09 11:09:38 +0000178 number_threads=GetOpenMPMaximumThreads();
cristy8ea926d2011-12-09 12:25:04 +0000179 serial=0.0;
cristy118fc662012-02-11 00:02:25 +0000180 for (n=1; n <= (ssize_t) number_threads; n++)
cristyc2e3aeb2011-12-09 11:09:38 +0000181 {
182 double
cristy8ea926d2011-12-09 12:25:04 +0000183 e,
184 parallel,
cristyc2e3aeb2011-12-09 11:09:38 +0000185 user_time;
186
187 TimerInfo
188 *timer;
189
cristy118fc662012-02-11 00:02:25 +0000190 SetOpenMPMaximumThreads((int) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000191 timer=AcquireTimerInfo();
192 if (concurrent == MagickFalse)
cristy3980b0d2009-10-25 14:37:13 +0000193 {
cristyc2e3aeb2011-12-09 11:09:38 +0000194 for (i=0; i < (ssize_t) iterations; i++)
cristyceae09d2009-10-28 17:18:47 +0000195 {
cristyc2e3aeb2011-12-09 11:09:38 +0000196 if (status != MagickFalse)
197 continue;
198 if (duration > 0)
199 {
200 if (GetElapsedTime(timer) > duration)
201 continue;
202 (void) ContinueTimer(timer);
203 }
204 status=command(image_info,argc,argv,metadata,exception);
cristyceae09d2009-10-28 17:18:47 +0000205 if (exception->severity != UndefinedException)
206 {
207 if ((exception->severity > ErrorException) ||
208 (regard_warnings != MagickFalse))
209 status=MagickTrue;
210 CatchException(exception);
211 }
212 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
213 {
214 (void) fputs(*metadata,stdout);
215 (void) fputc('\n',stdout);
216 *metadata=DestroyString(*metadata);
217 }
218 }
219 }
cristyc2e3aeb2011-12-09 11:09:38 +0000220 else
221 {
222 SetOpenMPNested(1);
223#if defined(MAGICKCORE_OPENMP_SUPPORT)
224 # pragma omp parallel for shared(status)
225#endif
226 for (i=0; i < (ssize_t) iterations; i++)
227 {
228 if (status != MagickFalse)
229 continue;
230 if (duration > 0)
231 {
232 if (GetElapsedTime(timer) > duration)
233 continue;
234 (void) ContinueTimer(timer);
235 }
236 status=command(image_info,argc,argv,metadata,exception);
237#if defined(MAGICKCORE_OPENMP_SUPPORT)
238 # pragma omp critical (MagickCore_CommandGenesis)
239#endif
240 {
241 if (exception->severity != UndefinedException)
242 {
243 if ((exception->severity > ErrorException) ||
244 (regard_warnings != MagickFalse))
245 status=MagickTrue;
246 CatchException(exception);
247 }
248 if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
249 {
250 (void) fputs(*metadata,stdout);
251 (void) fputc('\n',stdout);
252 *metadata=DestroyString(*metadata);
253 }
254 }
255 }
256 }
cristyc2e3aeb2011-12-09 11:09:38 +0000257 user_time=GetUserTime(timer);
cristy8ea926d2011-12-09 12:25:04 +0000258 parallel=GetElapsedTime(timer);
259 e=1.0;
260 if (n == 1)
261 serial=parallel;
262 else
263 e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
264 (double) n)))-(1.0/(double) n))/(1.0-1.0/(double) n);
cristyc2e3aeb2011-12-09 11:09:38 +0000265 (void) FormatLocaleFile(stderr,
cristy91ce84d2011-12-09 23:02:25 +0000266 "Performance[%.20g]: %.20gi %0.3fips %0.3fe %0.3fu %lu:%02lu.%03lu\n",
cristy8ea926d2011-12-09 12:25:04 +0000267 (double) n,(double) iterations,(double) iterations/parallel,e,
268 user_time,(unsigned long) (parallel/60.0),(unsigned long)
269 floor(fmod(parallel,60.0)),(unsigned long)
270 (1000.0*(parallel-floor(parallel))+0.5));
cristyc2e3aeb2011-12-09 11:09:38 +0000271 timer=DestroyTimerInfo(timer);
272 }
cristy1f9e1ed2009-11-18 04:09:38 +0000273 return(status);
cristy3980b0d2009-10-25 14:37:13 +0000274}
275
276/*
277%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278% %
279% %
280% %
cristy3ed852e2009-09-05 21:47:34 +0000281+ M o g r i f y I m a g e %
282% %
283% %
284% %
285%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286%
anthonye9c27192011-03-27 08:07:06 +0000287% MogrifyImage() applies simple single image processing options to a single
anthonydf8ebac2011-04-27 09:03:19 +0000288% image that may be part of a large list, but also handles any 'region'
289% image handling.
anthonye9c27192011-03-27 08:07:06 +0000290%
291% The image in the list may be modified in three different ways...
292%
293% * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
294% * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
295% * replace by a list of images (only the -separate option!)
296%
297% In each case the result is returned into the list, and a pointer to the
298% modified image (last image added if replaced by a list of images) is
299% returned.
300%
301% ASIDE: The -crop is present but restricted to non-tile single image crops
302%
303% This means if all the images are being processed (such as by
304% MogrifyImages(), next image to be processed will be as per the pointer
305% (*image)->next. Also the image list may grow as a result of some specific
306% operations but as images are never merged or deleted, it will never shrink
307% in length. Typically the list will remain the same length.
308%
309% WARNING: As the image pointed to may be replaced, the first image in the
310% list may also change. GetFirstImageInList() should be used by caller if
311% they wish return the Image pointer to the first image in list.
312%
cristy3ed852e2009-09-05 21:47:34 +0000313%
314% The format of the MogrifyImage method is:
315%
316% MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
317% const char **argv,Image **image)
318%
319% A description of each parameter follows:
320%
321% o image_info: the image info..
322%
323% o argc: Specifies a pointer to an integer describing the number of
324% elements in the argument vector.
325%
326% o argv: Specifies a pointer to a text array containing the command line
327% arguments.
328%
329% o image: the image.
330%
331% o exception: return any errors or warnings in this structure.
332%
333*/
334
anthonydf8ebac2011-04-27 09:03:19 +0000335static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
336 ExceptionInfo *exception)
337{
338 char
339 key[MaxTextExtent];
340
341 ExceptionInfo
342 *sans_exception;
343
344 Image
345 *image;
346
347 ImageInfo
348 *read_info;
349
cristyfcd785b2011-11-08 01:48:33 +0000350 /*
anthony32d85bf2012-02-15 14:54:59 +0000351 Read an image into a image cache (for repeated usage) if not already in
352 cache. Then return the image that is in the cache.
cristyfcd785b2011-11-08 01:48:33 +0000353 */
cristyb51dff52011-05-19 16:55:47 +0000354 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
anthonydf8ebac2011-04-27 09:03:19 +0000355 sans_exception=AcquireExceptionInfo();
356 image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
357 sans_exception=DestroyExceptionInfo(sans_exception);
358 if (image != (Image *) NULL)
359 return(image);
360 read_info=CloneImageInfo(image_info);
361 (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
362 image=ReadImage(read_info,exception);
363 read_info=DestroyImageInfo(read_info);
364 if (image != (Image *) NULL)
365 (void) SetImageRegistry(ImageRegistryType,key,image,exception);
366 return(image);
367}
368
cristy3ed852e2009-09-05 21:47:34 +0000369static MagickBooleanType IsPathWritable(const char *path)
370{
371 if (IsPathAccessible(path) == MagickFalse)
372 return(MagickFalse);
cristy18c6c272011-09-23 14:40:37 +0000373 if (access_utf8(path,W_OK) != 0)
cristy3ed852e2009-09-05 21:47:34 +0000374 return(MagickFalse);
375 return(MagickTrue);
376}
377
cristybb503372010-05-27 20:51:26 +0000378static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
cristy3ed852e2009-09-05 21:47:34 +0000379{
380 if (x > y)
381 return(x);
382 return(y);
383}
384
anthonydf8ebac2011-04-27 09:03:19 +0000385static MagickBooleanType MonitorProgress(const char *text,
386 const MagickOffsetType offset,const MagickSizeType extent,
387 void *wand_unused(client_data))
388{
389 char
390 message[MaxTextExtent],
391 tag[MaxTextExtent];
392
393 const char
394 *locale_message;
395
396 register char
397 *p;
398
399 if (extent < 2)
400 return(MagickTrue);
401 (void) CopyMagickMemory(tag,text,MaxTextExtent);
402 p=strrchr(tag,'/');
403 if (p != (char *) NULL)
404 *p='\0';
cristyb51dff52011-05-19 16:55:47 +0000405 (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
anthonydf8ebac2011-04-27 09:03:19 +0000406 locale_message=GetLocaleMessage(message);
407 if (locale_message == message)
408 locale_message=tag;
409 if (p == (char *) NULL)
cristy1e604812011-05-19 18:07:50 +0000410 (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
411 locale_message,(long) offset,(unsigned long) extent,(long)
412 (100L*offset/(extent-1)));
anthonydf8ebac2011-04-27 09:03:19 +0000413 else
cristyb51dff52011-05-19 16:55:47 +0000414 (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
anthonydf8ebac2011-04-27 09:03:19 +0000415 locale_message,p+1,(long) offset,(unsigned long) extent,(long)
416 (100L*offset/(extent-1)));
417 if (offset == (MagickOffsetType) (extent-1))
cristyb51dff52011-05-19 16:55:47 +0000418 (void) FormatLocaleFile(stderr,"\n");
anthonydf8ebac2011-04-27 09:03:19 +0000419 (void) fflush(stderr);
420 return(MagickTrue);
421}
422
cristy3884f692011-07-08 18:00:18 +0000423static Image *SparseColorOption(const Image *image,
anthonydf8ebac2011-04-27 09:03:19 +0000424 const SparseColorMethod method,const char *arguments,
425 const MagickBooleanType color_from_image,ExceptionInfo *exception)
426{
anthonydf8ebac2011-04-27 09:03:19 +0000427 char
428 token[MaxTextExtent];
429
430 const char
431 *p;
432
433 double
434 *sparse_arguments;
435
anthonydf8ebac2011-04-27 09:03:19 +0000436 Image
437 *sparse_image;
438
cristy4c08aed2011-07-01 19:47:50 +0000439 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000440 color;
441
442 MagickBooleanType
443 error;
444
cristy5f09d852011-05-29 01:39:29 +0000445 register size_t
446 x;
447
448 size_t
449 number_arguments,
450 number_colors;
451
cristyf4425a72011-11-08 01:52:04 +0000452 /*
453 SparseColorOption() parses the complex -sparse-color argument into an an
454 array of floating point values then calls SparseColorImage(). Argument is
455 a complex mix of floating-point pixel coodinates, and color specifications
456 (or direct floating point numbers). The number of floats needed to
457 represent a color varies depending on the current channel setting.
458 */
anthonydf8ebac2011-04-27 09:03:19 +0000459 assert(image != (Image *) NULL);
460 assert(image->signature == MagickSignature);
461 if (image->debug != MagickFalse)
462 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
463 assert(exception != (ExceptionInfo *) NULL);
464 assert(exception->signature == MagickSignature);
465 /*
466 Limit channels according to image - and add up number of color channel.
467 */
anthonydf8ebac2011-04-27 09:03:19 +0000468 number_colors=0;
cristyed231572011-07-14 02:18:59 +0000469 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000470 number_colors++;
cristyed231572011-07-14 02:18:59 +0000471 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000472 number_colors++;
cristyed231572011-07-14 02:18:59 +0000473 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000474 number_colors++;
cristyed231572011-07-14 02:18:59 +0000475 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000476 (image->colorspace == CMYKColorspace))
anthonydf8ebac2011-04-27 09:03:19 +0000477 number_colors++;
cristyed231572011-07-14 02:18:59 +0000478 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000479 (image->matte != MagickFalse))
anthonydf8ebac2011-04-27 09:03:19 +0000480 number_colors++;
481
482 /*
483 Read string, to determine number of arguments needed,
484 */
485 p=arguments;
486 x=0;
487 while( *p != '\0' )
488 {
489 GetMagickToken(p,&p,token);
490 if ( token[0] == ',' ) continue;
491 if ( isalpha((int) token[0]) || token[0] == '#' ) {
492 if ( color_from_image ) {
493 (void) ThrowMagickException(exception,GetMagickModule(),
494 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
495 "Color arg given, when colors are coming from image");
496 return( (Image *)NULL);
497 }
498 x += number_colors; /* color argument */
499 }
500 else {
501 x++; /* floating point argument */
502 }
503 }
504 error=MagickTrue;
505 if ( color_from_image ) {
506 /* just the control points are being given */
507 error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
508 number_arguments=(x/2)*(2+number_colors);
509 }
510 else {
511 /* control points and color values */
512 error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
513 number_arguments=x;
514 }
515 if ( error ) {
516 (void) ThrowMagickException(exception,GetMagickModule(),
517 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
518 "Invalid number of Arguments");
519 return( (Image *)NULL);
520 }
521
522 /* Allocate and fill in the floating point arguments */
523 sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
524 sizeof(*sparse_arguments));
525 if (sparse_arguments == (double *) NULL) {
526 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
527 "MemoryAllocationFailed","%s","SparseColorOption");
528 return( (Image *)NULL);
529 }
530 (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
531 sizeof(*sparse_arguments));
532 p=arguments;
533 x=0;
534 while( *p != '\0' && x < number_arguments ) {
535 /* X coordinate */
536 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
537 if ( token[0] == '\0' ) break;
538 if ( isalpha((int) token[0]) || token[0] == '#' ) {
539 (void) ThrowMagickException(exception,GetMagickModule(),
540 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
541 "Color found, instead of X-coord");
542 error = MagickTrue;
543 break;
544 }
cristydbdd0e32011-11-04 23:29:40 +0000545 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000546 /* Y coordinate */
547 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
548 if ( token[0] == '\0' ) break;
549 if ( isalpha((int) token[0]) || token[0] == '#' ) {
550 (void) ThrowMagickException(exception,GetMagickModule(),
551 OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
552 "Color found, instead of Y-coord");
553 error = MagickTrue;
554 break;
555 }
cristydbdd0e32011-11-04 23:29:40 +0000556 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000557 /* color values for this control point */
558#if 0
559 if ( (color_from_image ) {
560 /* get color from image */
561 /* HOW??? */
562 }
563 else
564#endif
565 {
566 /* color name or function given in string argument */
567 token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
568 if ( token[0] == '\0' ) break;
569 if ( isalpha((int) token[0]) || token[0] == '#' ) {
570 /* Color string given */
cristy269c9412011-10-13 23:41:15 +0000571 (void) QueryColorCompliance(token,AllCompliance,&color,exception);
cristyed231572011-07-14 02:18:59 +0000572 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000573 sparse_arguments[x++] = QuantumScale*color.red;
cristyed231572011-07-14 02:18:59 +0000574 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000575 sparse_arguments[x++] = QuantumScale*color.green;
cristyed231572011-07-14 02:18:59 +0000576 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
anthonydf8ebac2011-04-27 09:03:19 +0000577 sparse_arguments[x++] = QuantumScale*color.blue;
cristyed231572011-07-14 02:18:59 +0000578 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000579 (image->colorspace == CMYKColorspace))
cristy4c08aed2011-07-01 19:47:50 +0000580 sparse_arguments[x++] = QuantumScale*color.black;
cristyed231572011-07-14 02:18:59 +0000581 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000582 (image->matte != MagickFalse))
cristy4c08aed2011-07-01 19:47:50 +0000583 sparse_arguments[x++] = QuantumScale*color.alpha;
anthonydf8ebac2011-04-27 09:03:19 +0000584 }
585 else {
586 /* Colors given as a set of floating point values - experimental */
587 /* NB: token contains the first floating point value to use! */
cristyed231572011-07-14 02:18:59 +0000588 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000589 {
anthonydf8ebac2011-04-27 09:03:19 +0000590 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
591 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
592 break;
cristydbdd0e32011-11-04 23:29:40 +0000593 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000594 token[0] = ','; /* used this token - get another */
595 }
cristyed231572011-07-14 02:18:59 +0000596 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000597 {
anthonydf8ebac2011-04-27 09:03:19 +0000598 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
599 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
600 break;
cristydbdd0e32011-11-04 23:29:40 +0000601 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000602 token[0] = ','; /* used this token - get another */
603 }
cristyed231572011-07-14 02:18:59 +0000604 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
cristy3884f692011-07-08 18:00:18 +0000605 {
anthonydf8ebac2011-04-27 09:03:19 +0000606 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
607 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
608 break;
cristydbdd0e32011-11-04 23:29:40 +0000609 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000610 token[0] = ','; /* used this token - get another */
611 }
cristyed231572011-07-14 02:18:59 +0000612 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000613 (image->colorspace == CMYKColorspace))
614 {
anthonydf8ebac2011-04-27 09:03:19 +0000615 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
616 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
617 break;
cristydbdd0e32011-11-04 23:29:40 +0000618 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000619 token[0] = ','; /* used this token - get another */
620 }
cristyed231572011-07-14 02:18:59 +0000621 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
cristy3884f692011-07-08 18:00:18 +0000622 (image->matte != MagickFalse))
623 {
anthonydf8ebac2011-04-27 09:03:19 +0000624 while ( token[0] == ',' ) GetMagickToken(p,&p,token);
625 if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
626 break;
cristydbdd0e32011-11-04 23:29:40 +0000627 sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +0000628 token[0] = ','; /* used this token - get another */
629 }
630 }
631 }
632 }
633 if ( number_arguments != x && !error ) {
634 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
635 "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
636 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
637 return( (Image *)NULL);
638 }
639 if ( error )
640 return( (Image *)NULL);
641
642 /* Call the Interpolation function with the parsed arguments */
cristy3884f692011-07-08 18:00:18 +0000643 sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
644 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000645 sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
646 return( sparse_image );
647}
648
cristy3ed852e2009-09-05 21:47:34 +0000649WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
650 const char **argv,Image **image,ExceptionInfo *exception)
651{
cristy633f0c62011-09-15 13:27:36 +0000652 CompositeOperator
653 compose;
654
anthonydf8ebac2011-04-27 09:03:19 +0000655 const char
656 *format,
657 *option;
658
cristy9ed1f812011-10-08 02:00:08 +0000659 double
660 attenuate;
661
anthonydf8ebac2011-04-27 09:03:19 +0000662 DrawInfo
663 *draw_info;
664
665 GeometryInfo
666 geometry_info;
667
cristy3ed852e2009-09-05 21:47:34 +0000668 Image
669 *region_image;
670
anthonydf8ebac2011-04-27 09:03:19 +0000671 ImageInfo
672 *mogrify_info;
673
cristyebbcfea2011-02-25 02:43:54 +0000674 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000675 status;
676
cristy4c08aed2011-07-01 19:47:50 +0000677 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +0000678 fill;
cristy3ed852e2009-09-05 21:47:34 +0000679
anthonydf8ebac2011-04-27 09:03:19 +0000680 MagickStatusType
681 flags;
682
cristy28474bf2011-09-11 23:32:52 +0000683 PixelInterpolateMethod
684 interpolate_method;
685
anthonydf8ebac2011-04-27 09:03:19 +0000686 QuantizeInfo
687 *quantize_info;
688
689 RectangleInfo
690 geometry,
691 region_geometry;
anthony56ad4222011-04-25 11:04:27 +0000692
cristybb503372010-05-27 20:51:26 +0000693 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000694 i;
695
696 /*
697 Initialize method variables.
698 */
699 assert(image_info != (const ImageInfo *) NULL);
700 assert(image_info->signature == MagickSignature);
701 assert(image != (Image **) NULL);
702 assert((*image)->signature == MagickSignature);
703 if ((*image)->debug != MagickFalse)
704 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
705 if (argc < 0)
706 return(MagickTrue);
cristy6b3da3a2010-06-20 02:21:46 +0000707 mogrify_info=CloneImageInfo(image_info);
anthonydf8ebac2011-04-27 09:03:19 +0000708 draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
709 quantize_info=AcquireQuantizeInfo(mogrify_info);
710 SetGeometryInfo(&geometry_info);
cristy4c08aed2011-07-01 19:47:50 +0000711 GetPixelInfo(*image,&fill);
cristy9d8c8ce2011-10-25 16:13:52 +0000712 fill=(*image)->background_color;
cristy9ed1f812011-10-08 02:00:08 +0000713 attenuate=1.0;
cristy633f0c62011-09-15 13:27:36 +0000714 compose=(*image)->compose;
cristy28474bf2011-09-11 23:32:52 +0000715 interpolate_method=UndefinedInterpolatePixel;
anthonydf8ebac2011-04-27 09:03:19 +0000716 format=GetImageOption(mogrify_info,"format");
cristy3ed852e2009-09-05 21:47:34 +0000717 SetGeometry(*image,&region_geometry);
718 region_image=NewImageList();
719 /*
720 Transmogrify the image.
721 */
cristybb503372010-05-27 20:51:26 +0000722 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000723 {
anthonydf8ebac2011-04-27 09:03:19 +0000724 Image
725 *mogrify_image;
726
anthonye9c27192011-03-27 08:07:06 +0000727 ssize_t
728 count;
729
anthonydf8ebac2011-04-27 09:03:19 +0000730 option=argv[i];
731 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000732 continue;
anthonydf8ebac2011-04-27 09:03:19 +0000733 count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
734 0L);
cristycee97112010-05-28 00:44:52 +0000735 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +0000736 break;
cristy6b3da3a2010-06-20 02:21:46 +0000737 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000738 mogrify_image=(Image *)NULL;
739 switch (*(option+1))
740 {
741 case 'a':
cristy3ed852e2009-09-05 21:47:34 +0000742 {
anthonydf8ebac2011-04-27 09:03:19 +0000743 if (LocaleCompare("adaptive-blur",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +0000744 {
anthonydf8ebac2011-04-27 09:03:19 +0000745 /*
746 Adaptive blur image.
747 */
cristy6fccee12011-10-20 18:43:18 +0000748 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000749 flags=ParseGeometry(argv[i+1],&geometry_info);
750 if ((flags & SigmaValue) == 0)
751 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000752 if ((flags & XiValue) == 0)
753 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000754 mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000755 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000756 break;
cristy3ed852e2009-09-05 21:47:34 +0000757 }
anthonydf8ebac2011-04-27 09:03:19 +0000758 if (LocaleCompare("adaptive-resize",option+1) == 0)
759 {
760 /*
761 Adaptive resize image.
762 */
cristy6fccee12011-10-20 18:43:18 +0000763 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000764 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
765 mogrify_image=AdaptiveResizeImage(*image,geometry.width,
anthonyfd706f92012-01-19 04:22:02 +0000766 geometry.height,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000767 break;
768 }
769 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
770 {
771 /*
772 Adaptive sharpen image.
773 */
cristy6fccee12011-10-20 18:43:18 +0000774 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000775 flags=ParseGeometry(argv[i+1],&geometry_info);
776 if ((flags & SigmaValue) == 0)
777 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000778 if ((flags & XiValue) == 0)
779 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000780 mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
cristy4c11c2b2011-09-05 20:17:07 +0000781 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000782 break;
783 }
784 if (LocaleCompare("affine",option+1) == 0)
785 {
786 /*
787 Affine matrix.
788 */
789 if (*option == '+')
790 {
791 GetAffineMatrix(&draw_info->affine);
792 break;
793 }
794 (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
795 break;
796 }
797 if (LocaleCompare("alpha",option+1) == 0)
798 {
799 AlphaChannelType
800 alpha_type;
cristy3ed852e2009-09-05 21:47:34 +0000801
cristy6fccee12011-10-20 18:43:18 +0000802 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000803 alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
804 MagickFalse,argv[i+1]);
cristy63240882011-08-05 19:05:27 +0000805 (void) SetImageAlphaChannel(*image,alpha_type,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000806 break;
807 }
808 if (LocaleCompare("annotate",option+1) == 0)
809 {
810 char
811 *text,
812 geometry[MaxTextExtent];
813
814 /*
815 Annotate image.
816 */
cristy6fccee12011-10-20 18:43:18 +0000817 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000818 SetGeometryInfo(&geometry_info);
819 flags=ParseGeometry(argv[i+1],&geometry_info);
820 if ((flags & SigmaValue) == 0)
821 geometry_info.sigma=geometry_info.rho;
cristy018f07f2011-09-04 21:15:19 +0000822 text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
823 exception);
anthonydf8ebac2011-04-27 09:03:19 +0000824 if (text == (char *) NULL)
825 break;
826 (void) CloneString(&draw_info->text,text);
827 text=DestroyString(text);
cristyb51dff52011-05-19 16:55:47 +0000828 (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
anthonydf8ebac2011-04-27 09:03:19 +0000829 geometry_info.xi,geometry_info.psi);
830 (void) CloneString(&draw_info->geometry,geometry);
831 draw_info->affine.sx=cos(DegreesToRadians(
832 fmod(geometry_info.rho,360.0)));
833 draw_info->affine.rx=sin(DegreesToRadians(
834 fmod(geometry_info.rho,360.0)));
835 draw_info->affine.ry=(-sin(DegreesToRadians(
836 fmod(geometry_info.sigma,360.0))));
837 draw_info->affine.sy=cos(DegreesToRadians(
838 fmod(geometry_info.sigma,360.0)));
cristy5cbc0162011-08-29 00:36:28 +0000839 (void) AnnotateImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000840 break;
841 }
842 if (LocaleCompare("antialias",option+1) == 0)
843 {
844 draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
845 MagickFalse;
846 draw_info->text_antialias=(*option == '-') ? MagickTrue :
847 MagickFalse;
848 break;
849 }
cristy9ed1f812011-10-08 02:00:08 +0000850 if (LocaleCompare("attenuate",option+1) == 0)
851 {
852 if (*option == '+')
853 {
854 attenuate=1.0;
855 break;
856 }
cristydbdd0e32011-11-04 23:29:40 +0000857 attenuate=StringToDouble(argv[i+1],(char **) NULL);
cristy9ed1f812011-10-08 02:00:08 +0000858 break;
859 }
anthonydf8ebac2011-04-27 09:03:19 +0000860 if (LocaleCompare("auto-gamma",option+1) == 0)
861 {
862 /*
863 Auto Adjust Gamma of image based on its mean
864 */
cristy6fccee12011-10-20 18:43:18 +0000865 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000866 (void) AutoGammaImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000867 break;
868 }
869 if (LocaleCompare("auto-level",option+1) == 0)
870 {
871 /*
872 Perfectly Normalize (max/min stretch) the image
873 */
cristy6fccee12011-10-20 18:43:18 +0000874 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy95111202011-08-09 19:41:42 +0000875 (void) AutoLevelImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000876 break;
877 }
878 if (LocaleCompare("auto-orient",option+1) == 0)
879 {
cristy6fccee12011-10-20 18:43:18 +0000880 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000881 switch ((*image)->orientation)
882 {
883 case TopRightOrientation:
884 {
885 mogrify_image=FlopImage(*image,exception);
886 break;
887 }
888 case BottomRightOrientation:
889 {
890 mogrify_image=RotateImage(*image,180.0,exception);
891 break;
892 }
893 case BottomLeftOrientation:
894 {
895 mogrify_image=FlipImage(*image,exception);
896 break;
897 }
898 case LeftTopOrientation:
899 {
900 mogrify_image=TransposeImage(*image,exception);
901 break;
902 }
903 case RightTopOrientation:
904 {
905 mogrify_image=RotateImage(*image,90.0,exception);
906 break;
907 }
908 case RightBottomOrientation:
909 {
910 mogrify_image=TransverseImage(*image,exception);
911 break;
912 }
913 case LeftBottomOrientation:
914 {
915 mogrify_image=RotateImage(*image,270.0,exception);
916 break;
917 }
918 default:
919 break;
920 }
921 if (mogrify_image != (Image *) NULL)
922 mogrify_image->orientation=TopLeftOrientation;
923 break;
924 }
925 break;
926 }
927 case 'b':
928 {
929 if (LocaleCompare("black-threshold",option+1) == 0)
930 {
931 /*
932 Black threshold image.
933 */
cristy6fccee12011-10-20 18:43:18 +0000934 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +0000935 (void) BlackThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +0000936 break;
937 }
938 if (LocaleCompare("blue-shift",option+1) == 0)
939 {
940 /*
941 Blue shift image.
942 */
cristy6fccee12011-10-20 18:43:18 +0000943 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000944 geometry_info.rho=1.5;
945 if (*option == '-')
946 flags=ParseGeometry(argv[i+1],&geometry_info);
947 mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
948 break;
949 }
950 if (LocaleCompare("blur",option+1) == 0)
951 {
952 /*
953 Gaussian blur image.
954 */
cristy6fccee12011-10-20 18:43:18 +0000955 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000956 flags=ParseGeometry(argv[i+1],&geometry_info);
957 if ((flags & SigmaValue) == 0)
958 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +0000959 if ((flags & XiValue) == 0)
960 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +0000961 mogrify_image=BlurImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +0000962 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000963 break;
964 }
965 if (LocaleCompare("border",option+1) == 0)
966 {
967 /*
968 Surround image with a border of solid color.
969 */
cristy6fccee12011-10-20 18:43:18 +0000970 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000971 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
972 if ((flags & SigmaValue) == 0)
973 geometry.height=geometry.width;
cristy633f0c62011-09-15 13:27:36 +0000974 mogrify_image=BorderImage(*image,&geometry,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000975 break;
976 }
977 if (LocaleCompare("bordercolor",option+1) == 0)
978 {
979 if (*option == '+')
980 {
cristy9950d572011-10-01 18:22:35 +0000981 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy05c0c9a2011-09-05 23:16:13 +0000982 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000983 break;
984 }
cristy9950d572011-10-01 18:22:35 +0000985 (void) QueryColorCompliance(argv[i+1],AllCompliance,
986 &draw_info->border_color,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000987 break;
988 }
989 if (LocaleCompare("box",option+1) == 0)
990 {
cristy9950d572011-10-01 18:22:35 +0000991 (void) QueryColorCompliance(argv[i+1],AllCompliance,
992 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +0000993 break;
994 }
995 if (LocaleCompare("brightness-contrast",option+1) == 0)
996 {
997 double
998 brightness,
999 contrast;
1000
1001 GeometryInfo
1002 geometry_info;
1003
1004 MagickStatusType
1005 flags;
1006
1007 /*
1008 Brightness / contrast image.
1009 */
cristy6fccee12011-10-20 18:43:18 +00001010 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001011 flags=ParseGeometry(argv[i+1],&geometry_info);
1012 brightness=geometry_info.rho;
1013 contrast=0.0;
1014 if ((flags & SigmaValue) != 0)
1015 contrast=geometry_info.sigma;
cristy444eda62011-08-10 02:07:46 +00001016 (void) BrightnessContrastImage(*image,brightness,contrast,
1017 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001018 break;
1019 }
1020 break;
1021 }
1022 case 'c':
1023 {
1024 if (LocaleCompare("cdl",option+1) == 0)
1025 {
1026 char
1027 *color_correction_collection;
1028
1029 /*
1030 Color correct with a color decision list.
1031 */
cristy6fccee12011-10-20 18:43:18 +00001032 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001033 color_correction_collection=FileToString(argv[i+1],~0,exception);
1034 if (color_correction_collection == (char *) NULL)
1035 break;
cristy1bfa9f02011-08-11 02:35:43 +00001036 (void) ColorDecisionListImage(*image,color_correction_collection,
1037 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001038 break;
1039 }
cristy87c02f42012-02-24 00:19:10 +00001040 if (LocaleCompare("channel-extract",option+1) == 0)
1041 {
1042 puts("stand by...");
1043 break;
1044 }
1045 if (LocaleCompare("channel-swap",option+1) == 0)
1046 {
1047 puts("stand by...");
1048 break;
1049 }
anthonydf8ebac2011-04-27 09:03:19 +00001050 if (LocaleCompare("charcoal",option+1) == 0)
1051 {
1052 /*
1053 Charcoal image.
1054 */
cristy6fccee12011-10-20 18:43:18 +00001055 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001056 flags=ParseGeometry(argv[i+1],&geometry_info);
1057 if ((flags & SigmaValue) == 0)
1058 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00001059 if ((flags & XiValue) == 0)
1060 geometry_info.xi=1.0;
anthonydf8ebac2011-04-27 09:03:19 +00001061 mogrify_image=CharcoalImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00001062 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001063 break;
1064 }
1065 if (LocaleCompare("chop",option+1) == 0)
1066 {
1067 /*
1068 Chop the image.
1069 */
cristy6fccee12011-10-20 18:43:18 +00001070 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001071 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1072 mogrify_image=ChopImage(*image,&geometry,exception);
1073 break;
1074 }
1075 if (LocaleCompare("clamp",option+1) == 0)
1076 {
1077 /*
1078 Clamp image.
1079 */
cristy6fccee12011-10-20 18:43:18 +00001080 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy092d71c2011-10-14 18:01:29 +00001081 (void) ClampImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001082 break;
1083 }
1084 if (LocaleCompare("clip",option+1) == 0)
1085 {
cristy6fccee12011-10-20 18:43:18 +00001086 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001087 if (*option == '+')
1088 {
cristy10a6c612012-01-29 21:41:05 +00001089 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001090 break;
1091 }
cristy018f07f2011-09-04 21:15:19 +00001092 (void) ClipImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001093 break;
1094 }
1095 if (LocaleCompare("clip-mask",option+1) == 0)
1096 {
1097 CacheView
1098 *mask_view;
1099
1100 Image
1101 *mask_image;
1102
cristy4c08aed2011-07-01 19:47:50 +00001103 register Quantum
anthonydf8ebac2011-04-27 09:03:19 +00001104 *restrict q;
1105
1106 register ssize_t
1107 x;
1108
1109 ssize_t
1110 y;
1111
cristy6fccee12011-10-20 18:43:18 +00001112 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001113 if (*option == '+')
1114 {
1115 /*
1116 Remove a mask.
1117 */
cristy018f07f2011-09-04 21:15:19 +00001118 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001119 break;
1120 }
1121 /*
1122 Set the image mask.
1123 FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1124 */
1125 mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1126 if (mask_image == (Image *) NULL)
1127 break;
cristy574cc262011-08-05 01:23:58 +00001128 if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
anthonydf8ebac2011-04-27 09:03:19 +00001129 return(MagickFalse);
1130 mask_view=AcquireCacheView(mask_image);
1131 for (y=0; y < (ssize_t) mask_image->rows; y++)
1132 {
1133 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1134 exception);
cristyacd2ed22011-08-30 01:44:23 +00001135 if (q == (Quantum *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001136 break;
1137 for (x=0; x < (ssize_t) mask_image->columns; x++)
1138 {
1139 if (mask_image->matte == MagickFalse)
cristy4c08aed2011-07-01 19:47:50 +00001140 SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1141 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1142 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1143 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
cristyed231572011-07-14 02:18:59 +00001144 q+=GetPixelChannels(mask_image);
anthonydf8ebac2011-04-27 09:03:19 +00001145 }
1146 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1147 break;
1148 }
1149 mask_view=DestroyCacheView(mask_view);
1150 mask_image->matte=MagickTrue;
cristy10a6c612012-01-29 21:41:05 +00001151 (void) SetImageMask(*image,mask_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001152 break;
1153 }
1154 if (LocaleCompare("clip-path",option+1) == 0)
1155 {
cristy6fccee12011-10-20 18:43:18 +00001156 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001157 (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
cristy018f07f2011-09-04 21:15:19 +00001158 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001159 break;
1160 }
1161 if (LocaleCompare("colorize",option+1) == 0)
1162 {
1163 /*
1164 Colorize the image.
1165 */
cristy6fccee12011-10-20 18:43:18 +00001166 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyc7e6ff62011-10-03 13:46:11 +00001167 mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001168 break;
1169 }
1170 if (LocaleCompare("color-matrix",option+1) == 0)
1171 {
1172 KernelInfo
1173 *kernel;
1174
cristy6fccee12011-10-20 18:43:18 +00001175 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001176 kernel=AcquireKernelInfo(argv[i+1]);
1177 if (kernel == (KernelInfo *) NULL)
1178 break;
anthonyfd706f92012-01-19 04:22:02 +00001179 /* FUTURE: check on size of the matrix */
anthonydf8ebac2011-04-27 09:03:19 +00001180 mogrify_image=ColorMatrixImage(*image,kernel,exception);
1181 kernel=DestroyKernelInfo(kernel);
1182 break;
1183 }
1184 if (LocaleCompare("colors",option+1) == 0)
1185 {
1186 /*
1187 Reduce the number of colors in the image.
1188 */
cristy6fccee12011-10-20 18:43:18 +00001189 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001190 quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1191 if (quantize_info->number_colors == 0)
1192 break;
1193 if (((*image)->storage_class == DirectClass) ||
1194 (*image)->colors > quantize_info->number_colors)
cristy018f07f2011-09-04 21:15:19 +00001195 (void) QuantizeImage(quantize_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001196 else
cristy018f07f2011-09-04 21:15:19 +00001197 (void) CompressImageColormap(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001198 break;
1199 }
1200 if (LocaleCompare("colorspace",option+1) == 0)
1201 {
1202 ColorspaceType
1203 colorspace;
1204
cristy6fccee12011-10-20 18:43:18 +00001205 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001206 if (*option == '+')
1207 {
cristye941a752011-10-15 01:52:48 +00001208 (void) TransformImageColorspace(*image,RGBColorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001209 break;
1210 }
1211 colorspace=(ColorspaceType) ParseCommandOption(
1212 MagickColorspaceOptions,MagickFalse,argv[i+1]);
cristye941a752011-10-15 01:52:48 +00001213 (void) TransformImageColorspace(*image,colorspace,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001214 break;
1215 }
cristy633f0c62011-09-15 13:27:36 +00001216 if (LocaleCompare("compose",option+1) == 0)
1217 {
cristy6fccee12011-10-20 18:43:18 +00001218 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy633f0c62011-09-15 13:27:36 +00001219 compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1220 MagickFalse,argv[i+1]);
1221 break;
1222 }
anthonydf8ebac2011-04-27 09:03:19 +00001223 if (LocaleCompare("contrast",option+1) == 0)
1224 {
cristy6fccee12011-10-20 18:43:18 +00001225 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001226 (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
cristye23ec9d2011-08-16 18:15:40 +00001227 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001228 break;
1229 }
1230 if (LocaleCompare("contrast-stretch",option+1) == 0)
1231 {
1232 double
1233 black_point,
1234 white_point;
1235
1236 MagickStatusType
1237 flags;
1238
1239 /*
1240 Contrast stretch image.
1241 */
cristy6fccee12011-10-20 18:43:18 +00001242 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001243 flags=ParseGeometry(argv[i+1],&geometry_info);
1244 black_point=geometry_info.rho;
1245 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1246 black_point;
1247 if ((flags & PercentValue) != 0)
1248 {
1249 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1250 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1251 }
1252 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1253 white_point;
cristye23ec9d2011-08-16 18:15:40 +00001254 (void) ContrastStretchImage(*image,black_point,white_point,
1255 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001256 break;
1257 }
1258 if (LocaleCompare("convolve",option+1) == 0)
1259 {
anthonydf8ebac2011-04-27 09:03:19 +00001260 KernelInfo
cristy41cbe682011-07-15 19:12:37 +00001261 *kernel_info;
anthonydf8ebac2011-04-27 09:03:19 +00001262
cristy6fccee12011-10-20 18:43:18 +00001263 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy41cbe682011-07-15 19:12:37 +00001264 kernel_info=AcquireKernelInfo(argv[i+1]);
1265 if (kernel_info == (KernelInfo *) NULL)
anthonydf8ebac2011-04-27 09:03:19 +00001266 break;
cristy0a922382011-07-16 15:30:34 +00001267 kernel_info->bias=(*image)->bias;
cristy5e6be1e2011-07-16 01:23:39 +00001268 mogrify_image=ConvolveImage(*image,kernel_info,exception);
cristy41cbe682011-07-15 19:12:37 +00001269 kernel_info=DestroyKernelInfo(kernel_info);
anthonydf8ebac2011-04-27 09:03:19 +00001270 break;
1271 }
1272 if (LocaleCompare("crop",option+1) == 0)
1273 {
1274 /*
1275 Crop a image to a smaller size
1276 */
cristy6fccee12011-10-20 18:43:18 +00001277 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001278 mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00001279 break;
1280 }
1281 if (LocaleCompare("cycle",option+1) == 0)
1282 {
1283 /*
1284 Cycle an image colormap.
1285 */
cristy6fccee12011-10-20 18:43:18 +00001286 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00001287 (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1288 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001289 break;
1290 }
1291 break;
1292 }
1293 case 'd':
1294 {
1295 if (LocaleCompare("decipher",option+1) == 0)
1296 {
1297 StringInfo
1298 *passkey;
1299
1300 /*
1301 Decipher pixels.
1302 */
cristy6fccee12011-10-20 18:43:18 +00001303 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001304 passkey=FileToStringInfo(argv[i+1],~0,exception);
1305 if (passkey != (StringInfo *) NULL)
1306 {
1307 (void) PasskeyDecipherImage(*image,passkey,exception);
1308 passkey=DestroyStringInfo(passkey);
1309 }
1310 break;
1311 }
1312 if (LocaleCompare("density",option+1) == 0)
1313 {
1314 /*
1315 Set image density.
1316 */
1317 (void) CloneString(&draw_info->density,argv[i+1]);
1318 break;
1319 }
1320 if (LocaleCompare("depth",option+1) == 0)
1321 {
cristy6fccee12011-10-20 18:43:18 +00001322 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001323 if (*option == '+')
1324 {
cristy8a11cb12011-10-19 23:53:34 +00001325 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001326 break;
1327 }
cristy8a11cb12011-10-19 23:53:34 +00001328 (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1329 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001330 break;
1331 }
1332 if (LocaleCompare("deskew",option+1) == 0)
1333 {
1334 double
1335 threshold;
1336
1337 /*
1338 Straighten the image.
1339 */
cristy6fccee12011-10-20 18:43:18 +00001340 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001341 if (*option == '+')
1342 threshold=40.0*QuantumRange/100.0;
1343 else
cristy9b34e302011-11-05 02:15:45 +00001344 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1345 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00001346 mogrify_image=DeskewImage(*image,threshold,exception);
1347 break;
1348 }
1349 if (LocaleCompare("despeckle",option+1) == 0)
1350 {
1351 /*
1352 Reduce the speckles within an image.
1353 */
cristy6fccee12011-10-20 18:43:18 +00001354 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001355 mogrify_image=DespeckleImage(*image,exception);
1356 break;
1357 }
1358 if (LocaleCompare("display",option+1) == 0)
1359 {
1360 (void) CloneString(&draw_info->server_name,argv[i+1]);
1361 break;
1362 }
1363 if (LocaleCompare("distort",option+1) == 0)
1364 {
1365 char
1366 *args,
1367 token[MaxTextExtent];
1368
1369 const char
1370 *p;
1371
1372 DistortImageMethod
1373 method;
1374
1375 double
1376 *arguments;
1377
1378 register ssize_t
1379 x;
1380
1381 size_t
1382 number_arguments;
1383
1384 /*
1385 Distort image.
1386 */
cristy6fccee12011-10-20 18:43:18 +00001387 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001388 method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1389 MagickFalse,argv[i+1]);
cristy56835872011-11-06 01:19:13 +00001390 if (method == ResizeDistortion)
anthonydf8ebac2011-04-27 09:03:19 +00001391 {
anthonydf8ebac2011-04-27 09:03:19 +00001392 double
1393 resize_args[2];
cristy56835872011-11-06 01:19:13 +00001394
1395 /*
1396 Special Case - Argument is actually a resize geometry!
1397 Convert that to an appropriate distortion argument array.
1398 */
anthonydf8ebac2011-04-27 09:03:19 +00001399 (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
cristy56835872011-11-06 01:19:13 +00001400 exception);
1401 resize_args[0]=(double) geometry.width;
1402 resize_args[1]=(double) geometry.height;
anthonydf8ebac2011-04-27 09:03:19 +00001403 mogrify_image=DistortImage(*image,method,(size_t)2,
cristy56835872011-11-06 01:19:13 +00001404 resize_args,MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001405 break;
1406 }
cristy018f07f2011-09-04 21:15:19 +00001407 args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1408 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001409 if (args == (char *) NULL)
1410 break;
1411 p=(char *) args;
1412 for (x=0; *p != '\0'; x++)
1413 {
1414 GetMagickToken(p,&p,token);
1415 if (*token == ',')
1416 GetMagickToken(p,&p,token);
1417 }
1418 number_arguments=(size_t) x;
1419 arguments=(double *) AcquireQuantumMemory(number_arguments,
1420 sizeof(*arguments));
1421 if (arguments == (double *) NULL)
1422 ThrowWandFatalException(ResourceLimitFatalError,
1423 "MemoryAllocationFailed",(*image)->filename);
1424 (void) ResetMagickMemory(arguments,0,number_arguments*
1425 sizeof(*arguments));
1426 p=(char *) args;
1427 for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1428 {
1429 GetMagickToken(p,&p,token);
1430 if (*token == ',')
1431 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001432 arguments[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001433 }
1434 args=DestroyString(args);
1435 mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1436 (*option == '+') ? MagickTrue : MagickFalse,exception);
1437 arguments=(double *) RelinquishMagickMemory(arguments);
1438 break;
1439 }
1440 if (LocaleCompare("dither",option+1) == 0)
1441 {
1442 if (*option == '+')
1443 {
1444 quantize_info->dither=MagickFalse;
1445 break;
1446 }
1447 quantize_info->dither=MagickTrue;
1448 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1449 MagickDitherOptions,MagickFalse,argv[i+1]);
1450 if (quantize_info->dither_method == NoDitherMethod)
1451 quantize_info->dither=MagickFalse;
1452 break;
1453 }
1454 if (LocaleCompare("draw",option+1) == 0)
1455 {
1456 /*
1457 Draw image.
1458 */
cristy6fccee12011-10-20 18:43:18 +00001459 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001460 (void) CloneString(&draw_info->primitive,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001461 (void) DrawImage(*image,draw_info,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001462 break;
1463 }
1464 break;
1465 }
1466 case 'e':
1467 {
1468 if (LocaleCompare("edge",option+1) == 0)
1469 {
1470 /*
1471 Enhance edges in the image.
1472 */
cristy6fccee12011-10-20 18:43:18 +00001473 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001474 flags=ParseGeometry(argv[i+1],&geometry_info);
1475 if ((flags & SigmaValue) == 0)
1476 geometry_info.sigma=1.0;
cristy8ae632d2011-09-05 17:29:53 +00001477 mogrify_image=EdgeImage(*image,geometry_info.rho,
1478 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001479 break;
1480 }
1481 if (LocaleCompare("emboss",option+1) == 0)
1482 {
1483 /*
cristyd89705a2012-01-20 02:52:24 +00001484 Emboss image.
anthonydf8ebac2011-04-27 09:03:19 +00001485 */
cristy6fccee12011-10-20 18:43:18 +00001486 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001487 flags=ParseGeometry(argv[i+1],&geometry_info);
1488 if ((flags & SigmaValue) == 0)
1489 geometry_info.sigma=1.0;
1490 mogrify_image=EmbossImage(*image,geometry_info.rho,
1491 geometry_info.sigma,exception);
1492 break;
1493 }
1494 if (LocaleCompare("encipher",option+1) == 0)
1495 {
1496 StringInfo
1497 *passkey;
1498
1499 /*
1500 Encipher pixels.
1501 */
cristy6fccee12011-10-20 18:43:18 +00001502 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001503 passkey=FileToStringInfo(argv[i+1],~0,exception);
1504 if (passkey != (StringInfo *) NULL)
1505 {
1506 (void) PasskeyEncipherImage(*image,passkey,exception);
1507 passkey=DestroyStringInfo(passkey);
1508 }
1509 break;
1510 }
1511 if (LocaleCompare("encoding",option+1) == 0)
1512 {
1513 (void) CloneString(&draw_info->encoding,argv[i+1]);
1514 break;
1515 }
1516 if (LocaleCompare("enhance",option+1) == 0)
1517 {
1518 /*
1519 Enhance image.
1520 */
cristy6fccee12011-10-20 18:43:18 +00001521 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001522 mogrify_image=EnhanceImage(*image,exception);
1523 break;
1524 }
1525 if (LocaleCompare("equalize",option+1) == 0)
1526 {
1527 /*
1528 Equalize image.
1529 */
cristy6fccee12011-10-20 18:43:18 +00001530 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6d8c3d72011-08-22 01:20:01 +00001531 (void) EqualizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001532 break;
1533 }
1534 if (LocaleCompare("evaluate",option+1) == 0)
1535 {
1536 double
1537 constant;
1538
1539 MagickEvaluateOperator
1540 op;
1541
cristy6fccee12011-10-20 18:43:18 +00001542 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyd42d9952011-07-08 14:21:50 +00001543 op=(MagickEvaluateOperator) ParseCommandOption(
1544 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristy9b34e302011-11-05 02:15:45 +00001545 constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1546 1.0);
cristyd42d9952011-07-08 14:21:50 +00001547 (void) EvaluateImage(*image,op,constant,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001548 break;
1549 }
1550 if (LocaleCompare("extent",option+1) == 0)
1551 {
1552 /*
1553 Set the image extent.
1554 */
cristy6fccee12011-10-20 18:43:18 +00001555 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001556 flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1557 if (geometry.width == 0)
1558 geometry.width=(*image)->columns;
1559 if (geometry.height == 0)
1560 geometry.height=(*image)->rows;
1561 mogrify_image=ExtentImage(*image,&geometry,exception);
1562 break;
1563 }
1564 break;
1565 }
1566 case 'f':
1567 {
1568 if (LocaleCompare("family",option+1) == 0)
1569 {
1570 if (*option == '+')
1571 {
1572 if (draw_info->family != (char *) NULL)
1573 draw_info->family=DestroyString(draw_info->family);
1574 break;
1575 }
1576 (void) CloneString(&draw_info->family,argv[i+1]);
1577 break;
1578 }
1579 if (LocaleCompare("features",option+1) == 0)
1580 {
1581 if (*option == '+')
1582 {
1583 (void) DeleteImageArtifact(*image,"identify:features");
1584 break;
1585 }
1586 (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1587 break;
1588 }
1589 if (LocaleCompare("fill",option+1) == 0)
1590 {
1591 ExceptionInfo
1592 *sans;
1593
anthonyfd706f92012-01-19 04:22:02 +00001594 PixelInfo
1595 color;
1596
cristy4c08aed2011-07-01 19:47:50 +00001597 GetPixelInfo(*image,&fill);
anthonydf8ebac2011-04-27 09:03:19 +00001598 if (*option == '+')
1599 {
cristy269c9412011-10-13 23:41:15 +00001600 (void) QueryColorCompliance("none",AllCompliance,&fill,
cristy9950d572011-10-01 18:22:35 +00001601 exception);
anthonyfd706f92012-01-19 04:22:02 +00001602 draw_info->fill=fill;
anthonydf8ebac2011-04-27 09:03:19 +00001603 if (draw_info->fill_pattern != (Image *) NULL)
1604 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1605 break;
1606 }
1607 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00001608 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00001609 sans=DestroyExceptionInfo(sans);
1610 if (status == MagickFalse)
1611 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1612 exception);
anthonyfd706f92012-01-19 04:22:02 +00001613 else
1614 draw_info->fill=fill=color;
anthonydf8ebac2011-04-27 09:03:19 +00001615 break;
1616 }
1617 if (LocaleCompare("flip",option+1) == 0)
1618 {
1619 /*
1620 Flip image scanlines.
1621 */
cristy6fccee12011-10-20 18:43:18 +00001622 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001623 mogrify_image=FlipImage(*image,exception);
1624 break;
1625 }
anthonydf8ebac2011-04-27 09:03:19 +00001626 if (LocaleCompare("floodfill",option+1) == 0)
1627 {
cristy4c08aed2011-07-01 19:47:50 +00001628 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001629 target;
1630
1631 /*
1632 Floodfill image.
1633 */
cristy6fccee12011-10-20 18:43:18 +00001634 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001635 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
cristy269c9412011-10-13 23:41:15 +00001636 (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00001637 exception);
cristyd42d9952011-07-08 14:21:50 +00001638 (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
cristy189e84c2011-08-27 18:08:53 +00001639 geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001640 break;
1641 }
anthony3d2f4862011-05-01 13:48:16 +00001642 if (LocaleCompare("flop",option+1) == 0)
1643 {
1644 /*
1645 Flop image scanlines.
1646 */
cristy6fccee12011-10-20 18:43:18 +00001647 (void) SyncImageSettings(mogrify_info,*image,exception);
anthony3d2f4862011-05-01 13:48:16 +00001648 mogrify_image=FlopImage(*image,exception);
1649 break;
1650 }
anthonydf8ebac2011-04-27 09:03:19 +00001651 if (LocaleCompare("font",option+1) == 0)
1652 {
1653 if (*option == '+')
1654 {
1655 if (draw_info->font != (char *) NULL)
1656 draw_info->font=DestroyString(draw_info->font);
1657 break;
1658 }
1659 (void) CloneString(&draw_info->font,argv[i+1]);
1660 break;
1661 }
1662 if (LocaleCompare("format",option+1) == 0)
1663 {
1664 format=argv[i+1];
1665 break;
1666 }
1667 if (LocaleCompare("frame",option+1) == 0)
1668 {
1669 FrameInfo
1670 frame_info;
1671
1672 /*
1673 Surround image with an ornamental border.
1674 */
cristy6fccee12011-10-20 18:43:18 +00001675 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001676 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1677 frame_info.width=geometry.width;
1678 frame_info.height=geometry.height;
1679 if ((flags & HeightValue) == 0)
1680 frame_info.height=geometry.width;
1681 frame_info.outer_bevel=geometry.x;
1682 frame_info.inner_bevel=geometry.y;
1683 frame_info.x=(ssize_t) frame_info.width;
1684 frame_info.y=(ssize_t) frame_info.height;
1685 frame_info.width=(*image)->columns+2*frame_info.width;
1686 frame_info.height=(*image)->rows+2*frame_info.height;
cristy633f0c62011-09-15 13:27:36 +00001687 mogrify_image=FrameImage(*image,&frame_info,compose,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001688 break;
1689 }
1690 if (LocaleCompare("function",option+1) == 0)
1691 {
1692 char
1693 *arguments,
1694 token[MaxTextExtent];
1695
1696 const char
1697 *p;
1698
1699 double
1700 *parameters;
1701
1702 MagickFunction
1703 function;
1704
1705 register ssize_t
1706 x;
1707
1708 size_t
1709 number_parameters;
1710
1711 /*
1712 Function Modify Image Values
1713 */
cristy6fccee12011-10-20 18:43:18 +00001714 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001715 function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1716 MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00001717 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1718 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001719 if (arguments == (char *) NULL)
1720 break;
1721 p=(char *) arguments;
1722 for (x=0; *p != '\0'; x++)
1723 {
1724 GetMagickToken(p,&p,token);
1725 if (*token == ',')
1726 GetMagickToken(p,&p,token);
1727 }
1728 number_parameters=(size_t) x;
1729 parameters=(double *) AcquireQuantumMemory(number_parameters,
1730 sizeof(*parameters));
1731 if (parameters == (double *) NULL)
1732 ThrowWandFatalException(ResourceLimitFatalError,
1733 "MemoryAllocationFailed",(*image)->filename);
1734 (void) ResetMagickMemory(parameters,0,number_parameters*
1735 sizeof(*parameters));
1736 p=(char *) arguments;
1737 for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1738 {
1739 GetMagickToken(p,&p,token);
1740 if (*token == ',')
1741 GetMagickToken(p,&p,token);
cristydbdd0e32011-11-04 23:29:40 +00001742 parameters[x]=StringToDouble(token,(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001743 }
1744 arguments=DestroyString(arguments);
cristyd42d9952011-07-08 14:21:50 +00001745 (void) FunctionImage(*image,function,number_parameters,parameters,
1746 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001747 parameters=(double *) RelinquishMagickMemory(parameters);
1748 break;
1749 }
1750 break;
1751 }
1752 case 'g':
1753 {
1754 if (LocaleCompare("gamma",option+1) == 0)
1755 {
1756 /*
1757 Gamma image.
1758 */
cristy6fccee12011-10-20 18:43:18 +00001759 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001760 if (*option == '+')
cristydbdd0e32011-11-04 23:29:40 +00001761 (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00001762 else
cristydbdd0e32011-11-04 23:29:40 +00001763 (void) GammaImage(*image,StringToDouble(argv[i+1],
cristyb3e7c6c2011-07-24 01:43:55 +00001764 (char **) NULL),exception);
anthonydf8ebac2011-04-27 09:03:19 +00001765 break;
1766 }
1767 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1768 (LocaleCompare("gaussian",option+1) == 0))
1769 {
1770 /*
1771 Gaussian blur image.
1772 */
cristy6fccee12011-10-20 18:43:18 +00001773 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001774 flags=ParseGeometry(argv[i+1],&geometry_info);
1775 if ((flags & SigmaValue) == 0)
1776 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00001777 mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
cristyd89705a2012-01-20 02:52:24 +00001778 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001779 break;
1780 }
1781 if (LocaleCompare("geometry",option+1) == 0)
1782 {
1783 /*
1784 Record Image offset, Resize last image.
1785 */
cristy6fccee12011-10-20 18:43:18 +00001786 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001787 if (*option == '+')
1788 {
1789 if ((*image)->geometry != (char *) NULL)
1790 (*image)->geometry=DestroyString((*image)->geometry);
1791 break;
1792 }
1793 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1794 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1795 (void) CloneString(&(*image)->geometry,argv[i+1]);
1796 else
1797 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1798 (*image)->filter,(*image)->blur,exception);
1799 break;
1800 }
1801 if (LocaleCompare("gravity",option+1) == 0)
1802 {
1803 if (*option == '+')
1804 {
1805 draw_info->gravity=UndefinedGravity;
1806 break;
1807 }
1808 draw_info->gravity=(GravityType) ParseCommandOption(
1809 MagickGravityOptions,MagickFalse,argv[i+1]);
1810 break;
1811 }
1812 break;
1813 }
1814 case 'h':
1815 {
1816 if (LocaleCompare("highlight-color",option+1) == 0)
1817 {
1818 (void) SetImageArtifact(*image,option+1,argv[i+1]);
1819 break;
1820 }
1821 break;
1822 }
1823 case 'i':
1824 {
1825 if (LocaleCompare("identify",option+1) == 0)
1826 {
1827 char
1828 *text;
1829
cristy6fccee12011-10-20 18:43:18 +00001830 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001831 if (format == (char *) NULL)
1832 {
cristya4037272011-08-28 15:11:39 +00001833 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1834 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001835 break;
1836 }
cristy018f07f2011-09-04 21:15:19 +00001837 text=InterpretImageProperties(mogrify_info,*image,format,
1838 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001839 if (text == (char *) NULL)
1840 break;
1841 (void) fputs(text,stdout);
1842 (void) fputc('\n',stdout);
1843 text=DestroyString(text);
1844 break;
1845 }
1846 if (LocaleCompare("implode",option+1) == 0)
1847 {
1848 /*
1849 Implode image.
1850 */
cristy6fccee12011-10-20 18:43:18 +00001851 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001852 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00001853 mogrify_image=ImplodeImage(*image,geometry_info.rho,
1854 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001855 break;
1856 }
1857 if (LocaleCompare("interline-spacing",option+1) == 0)
1858 {
1859 if (*option == '+')
1860 (void) ParseGeometry("0",&geometry_info);
1861 else
1862 (void) ParseGeometry(argv[i+1],&geometry_info);
1863 draw_info->interline_spacing=geometry_info.rho;
1864 break;
1865 }
cristy28474bf2011-09-11 23:32:52 +00001866 if (LocaleCompare("interpolate",option+1) == 0)
1867 {
1868 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1869 MagickInterpolateOptions,MagickFalse,argv[i+1]);
1870 break;
1871 }
anthonydf8ebac2011-04-27 09:03:19 +00001872 if (LocaleCompare("interword-spacing",option+1) == 0)
1873 {
1874 if (*option == '+')
1875 (void) ParseGeometry("0",&geometry_info);
1876 else
1877 (void) ParseGeometry(argv[i+1],&geometry_info);
1878 draw_info->interword_spacing=geometry_info.rho;
1879 break;
1880 }
anthonyfd706f92012-01-19 04:22:02 +00001881 if (LocaleCompare("interpolative-resize",option+1) == 0)
1882 {
1883 /*
1884 Interpolative resize image.
1885 */
1886 (void) SyncImageSettings(mogrify_info,*image,exception);
1887 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1888 mogrify_image=InterpolativeResizeImage(*image,geometry.width,
1889 geometry.height,interpolate_method,exception);
1890 break;
1891 }
anthonydf8ebac2011-04-27 09:03:19 +00001892 break;
1893 }
1894 case 'k':
1895 {
1896 if (LocaleCompare("kerning",option+1) == 0)
1897 {
1898 if (*option == '+')
1899 (void) ParseGeometry("0",&geometry_info);
1900 else
1901 (void) ParseGeometry(argv[i+1],&geometry_info);
1902 draw_info->kerning=geometry_info.rho;
1903 break;
1904 }
1905 break;
1906 }
1907 case 'l':
1908 {
1909 if (LocaleCompare("lat",option+1) == 0)
1910 {
1911 /*
1912 Local adaptive threshold image.
1913 */
cristy6fccee12011-10-20 18:43:18 +00001914 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001915 flags=ParseGeometry(argv[i+1],&geometry_info);
1916 if ((flags & PercentValue) != 0)
1917 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1918 mogrify_image=AdaptiveThresholdImage(*image,(size_t)
cristyde5cc632011-07-18 14:47:00 +00001919 geometry_info.rho,(size_t) geometry_info.sigma,(double)
anthonydf8ebac2011-04-27 09:03:19 +00001920 geometry_info.xi,exception);
1921 break;
1922 }
1923 if (LocaleCompare("level",option+1) == 0)
1924 {
1925 MagickRealType
1926 black_point,
1927 gamma,
1928 white_point;
1929
1930 MagickStatusType
1931 flags;
1932
1933 /*
1934 Parse levels.
1935 */
cristy6fccee12011-10-20 18:43:18 +00001936 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001937 flags=ParseGeometry(argv[i+1],&geometry_info);
1938 black_point=geometry_info.rho;
1939 white_point=(MagickRealType) QuantumRange;
1940 if ((flags & SigmaValue) != 0)
1941 white_point=geometry_info.sigma;
1942 gamma=1.0;
1943 if ((flags & XiValue) != 0)
1944 gamma=geometry_info.xi;
1945 if ((flags & PercentValue) != 0)
1946 {
1947 black_point*=(MagickRealType) (QuantumRange/100.0);
1948 white_point*=(MagickRealType) (QuantumRange/100.0);
1949 }
1950 if ((flags & SigmaValue) == 0)
1951 white_point=(MagickRealType) QuantumRange-black_point;
1952 if ((*option == '+') || ((flags & AspectValue) != 0))
cristy7c0a0a42011-08-23 17:57:25 +00001953 (void) LevelizeImage(*image,black_point,white_point,gamma,
1954 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001955 else
cristy01e9afd2011-08-10 17:38:41 +00001956 (void) LevelImage(*image,black_point,white_point,gamma,
1957 exception);
anthonydf8ebac2011-04-27 09:03:19 +00001958 break;
1959 }
1960 if (LocaleCompare("level-colors",option+1) == 0)
1961 {
1962 char
1963 token[MaxTextExtent];
1964
1965 const char
1966 *p;
1967
cristy4c08aed2011-07-01 19:47:50 +00001968 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00001969 black_point,
1970 white_point;
1971
1972 p=(const char *) argv[i+1];
1973 GetMagickToken(p,&p,token); /* get black point color */
1974 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001975 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001976 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001977 else
cristy269c9412011-10-13 23:41:15 +00001978 (void) QueryColorCompliance("#000000",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001979 &black_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001980 if (isalpha((int) token[0]) || (token[0] == '#'))
1981 GetMagickToken(p,&p,token);
1982 if (*token == '\0')
1983 white_point=black_point; /* set everything to that color */
1984 else
1985 {
1986 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1987 GetMagickToken(p,&p,token); /* Get white point color. */
1988 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
cristy269c9412011-10-13 23:41:15 +00001989 (void) QueryColorCompliance(token,AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001990 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001991 else
cristy269c9412011-10-13 23:41:15 +00001992 (void) QueryColorCompliance("#ffffff",AllCompliance,
cristy9950d572011-10-01 18:22:35 +00001993 &white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001994 }
cristy490408a2011-07-07 14:42:05 +00001995 (void) LevelImageColors(*image,&black_point,&white_point,
cristy7c0a0a42011-08-23 17:57:25 +00001996 *option == '+' ? MagickTrue : MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00001997 break;
1998 }
1999 if (LocaleCompare("linear-stretch",option+1) == 0)
2000 {
2001 double
2002 black_point,
2003 white_point;
2004
2005 MagickStatusType
2006 flags;
2007
cristy6fccee12011-10-20 18:43:18 +00002008 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002009 flags=ParseGeometry(argv[i+1],&geometry_info);
2010 black_point=geometry_info.rho;
2011 white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2012 if ((flags & SigmaValue) != 0)
2013 white_point=geometry_info.sigma;
2014 if ((flags & PercentValue) != 0)
2015 {
2016 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2017 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2018 }
2019 if ((flags & SigmaValue) == 0)
2020 white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2021 black_point;
cristy33bd5152011-08-24 01:42:24 +00002022 (void) LinearStretchImage(*image,black_point,white_point,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002023 break;
2024 }
anthonydf8ebac2011-04-27 09:03:19 +00002025 if (LocaleCompare("liquid-rescale",option+1) == 0)
2026 {
2027 /*
2028 Liquid rescale image.
2029 */
cristy6fccee12011-10-20 18:43:18 +00002030 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002031 flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2032 if ((flags & XValue) == 0)
2033 geometry.x=1;
2034 if ((flags & YValue) == 0)
2035 geometry.y=0;
2036 mogrify_image=LiquidRescaleImage(*image,geometry.width,
2037 geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2038 break;
2039 }
2040 if (LocaleCompare("lowlight-color",option+1) == 0)
2041 {
2042 (void) SetImageArtifact(*image,option+1,argv[i+1]);
2043 break;
2044 }
2045 break;
2046 }
2047 case 'm':
2048 {
2049 if (LocaleCompare("map",option+1) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002050 {
cristy3ed852e2009-09-05 21:47:34 +00002051 Image
anthonydf8ebac2011-04-27 09:03:19 +00002052 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002053
anthonydf8ebac2011-04-27 09:03:19 +00002054 /*
2055 Transform image colors to match this set of colors.
2056 */
cristy6fccee12011-10-20 18:43:18 +00002057 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002058 if (*option == '+')
2059 break;
2060 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2061 if (remap_image == (Image *) NULL)
2062 break;
cristy018f07f2011-09-04 21:15:19 +00002063 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002064 remap_image=DestroyImage(remap_image);
2065 break;
2066 }
2067 if (LocaleCompare("mask",option+1) == 0)
2068 {
2069 Image
2070 *mask;
2071
cristy6fccee12011-10-20 18:43:18 +00002072 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002073 if (*option == '+')
2074 {
2075 /*
2076 Remove a mask.
2077 */
cristy018f07f2011-09-04 21:15:19 +00002078 (void) SetImageMask(*image,(Image *) NULL,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002079 break;
2080 }
2081 /*
2082 Set the image mask.
2083 */
2084 mask=GetImageCache(mogrify_info,argv[i+1],exception);
2085 if (mask == (Image *) NULL)
2086 break;
cristy018f07f2011-09-04 21:15:19 +00002087 (void) SetImageMask(*image,mask,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002088 mask=DestroyImage(mask);
anthonydf8ebac2011-04-27 09:03:19 +00002089 break;
2090 }
2091 if (LocaleCompare("matte",option+1) == 0)
2092 {
2093 (void) SetImageAlphaChannel(*image,(*option == '-') ?
cristy63240882011-08-05 19:05:27 +00002094 SetAlphaChannel : DeactivateAlphaChannel,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002095 break;
2096 }
2097 if (LocaleCompare("median",option+1) == 0)
2098 {
2099 /*
2100 Median filter image.
2101 */
cristy6fccee12011-10-20 18:43:18 +00002102 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002103 flags=ParseGeometry(argv[i+1],&geometry_info);
2104 if ((flags & SigmaValue) == 0)
2105 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002106 mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002107 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002108 break;
2109 }
2110 if (LocaleCompare("mode",option+1) == 0)
2111 {
2112 /*
2113 Mode image.
2114 */
cristy6fccee12011-10-20 18:43:18 +00002115 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf36cbcb2011-09-07 13:28:22 +00002116 flags=ParseGeometry(argv[i+1],&geometry_info);
2117 if ((flags & SigmaValue) == 0)
2118 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002119 mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002120 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002121 break;
2122 }
2123 if (LocaleCompare("modulate",option+1) == 0)
2124 {
cristy6fccee12011-10-20 18:43:18 +00002125 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy33bd5152011-08-24 01:42:24 +00002126 (void) ModulateImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002127 break;
2128 }
2129 if (LocaleCompare("monitor",option+1) == 0)
2130 {
2131 if (*option == '+')
2132 {
2133 (void) SetImageProgressMonitor(*image,
2134 (MagickProgressMonitor) NULL,(void *) NULL);
2135 break;
2136 }
2137 (void) SetImageProgressMonitor(*image,MonitorProgress,
2138 (void *) NULL);
2139 break;
2140 }
2141 if (LocaleCompare("monochrome",option+1) == 0)
2142 {
cristy6fccee12011-10-20 18:43:18 +00002143 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy018f07f2011-09-04 21:15:19 +00002144 (void) SetImageType(*image,BilevelType,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002145 break;
2146 }
2147 if (LocaleCompare("morphology",option+1) == 0)
2148 {
2149 char
2150 token[MaxTextExtent];
2151
2152 const char
2153 *p;
2154
2155 KernelInfo
2156 *kernel;
2157
2158 MorphologyMethod
2159 method;
2160
2161 ssize_t
2162 iterations;
2163
2164 /*
2165 Morphological Image Operation
2166 */
cristy6fccee12011-10-20 18:43:18 +00002167 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002168 p=argv[i+1];
2169 GetMagickToken(p,&p,token);
cristy28474bf2011-09-11 23:32:52 +00002170 method=(MorphologyMethod) ParseCommandOption(
2171 MagickMorphologyOptions,MagickFalse,token);
anthonydf8ebac2011-04-27 09:03:19 +00002172 iterations=1L;
2173 GetMagickToken(p,&p,token);
2174 if ((*p == ':') || (*p == ','))
2175 GetMagickToken(p,&p,token);
2176 if ((*p != '\0'))
2177 iterations=(ssize_t) StringToLong(p);
2178 kernel=AcquireKernelInfo(argv[i+2]);
2179 if (kernel == (KernelInfo *) NULL)
2180 {
2181 (void) ThrowMagickException(exception,GetMagickModule(),
2182 OptionError,"UnabletoParseKernel","morphology");
2183 status=MagickFalse;
2184 break;
2185 }
cristyf4ad9df2011-07-08 16:49:03 +00002186 mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2187 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002188 kernel=DestroyKernelInfo(kernel);
2189 break;
2190 }
2191 if (LocaleCompare("motion-blur",option+1) == 0)
2192 {
2193 /*
2194 Motion blur image.
2195 */
cristy6fccee12011-10-20 18:43:18 +00002196 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002197 flags=ParseGeometry(argv[i+1],&geometry_info);
2198 if ((flags & SigmaValue) == 0)
2199 geometry_info.sigma=1.0;
cristyf4ad9df2011-07-08 16:49:03 +00002200 mogrify_image=MotionBlurImage(*image,geometry_info.rho,
cristy7497f482011-12-08 01:57:31 +00002201 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002202 break;
2203 }
2204 break;
2205 }
2206 case 'n':
2207 {
2208 if (LocaleCompare("negate",option+1) == 0)
2209 {
cristy6fccee12011-10-20 18:43:18 +00002210 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy50fbc382011-07-07 02:19:17 +00002211 (void) NegateImage(*image,*option == '+' ? MagickTrue :
cristyb3e7c6c2011-07-24 01:43:55 +00002212 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002213 break;
2214 }
2215 if (LocaleCompare("noise",option+1) == 0)
2216 {
cristy6fccee12011-10-20 18:43:18 +00002217 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002218 if (*option == '-')
2219 {
cristyf36cbcb2011-09-07 13:28:22 +00002220 flags=ParseGeometry(argv[i+1],&geometry_info);
2221 if ((flags & SigmaValue) == 0)
2222 geometry_info.sigma=geometry_info.rho;
cristyf4ad9df2011-07-08 16:49:03 +00002223 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
cristyf36cbcb2011-09-07 13:28:22 +00002224 geometry_info.rho,(size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002225 }
2226 else
2227 {
2228 NoiseType
2229 noise;
2230
2231 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2232 MagickFalse,argv[i+1]);
cristy9ed1f812011-10-08 02:00:08 +00002233 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002234 }
2235 break;
2236 }
2237 if (LocaleCompare("normalize",option+1) == 0)
2238 {
cristy6fccee12011-10-20 18:43:18 +00002239 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye23ec9d2011-08-16 18:15:40 +00002240 (void) NormalizeImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002241 break;
2242 }
2243 break;
2244 }
2245 case 'o':
2246 {
2247 if (LocaleCompare("opaque",option+1) == 0)
2248 {
cristy4c08aed2011-07-01 19:47:50 +00002249 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00002250 target;
2251
cristy6fccee12011-10-20 18:43:18 +00002252 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00002253 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00002254 exception);
cristyd42d9952011-07-08 14:21:50 +00002255 (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
cristy189e84c2011-08-27 18:08:53 +00002256 MagickFalse : MagickTrue,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002257 break;
2258 }
2259 if (LocaleCompare("ordered-dither",option+1) == 0)
2260 {
cristy6fccee12011-10-20 18:43:18 +00002261 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy13020672011-07-08 02:33:26 +00002262 (void) OrderedPosterizeImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002263 break;
2264 }
2265 break;
2266 }
2267 case 'p':
2268 {
2269 if (LocaleCompare("paint",option+1) == 0)
2270 {
cristy6fccee12011-10-20 18:43:18 +00002271 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002272 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy14973ba2011-08-27 23:48:07 +00002273 mogrify_image=OilPaintImage(*image,geometry_info.rho,
2274 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002275 break;
2276 }
anthonydf8ebac2011-04-27 09:03:19 +00002277 if (LocaleCompare("pointsize",option+1) == 0)
2278 {
2279 if (*option == '+')
2280 (void) ParseGeometry("12",&geometry_info);
2281 else
2282 (void) ParseGeometry(argv[i+1],&geometry_info);
2283 draw_info->pointsize=geometry_info.rho;
2284 break;
2285 }
2286 if (LocaleCompare("polaroid",option+1) == 0)
2287 {
cristye9e3d382011-12-14 01:50:13 +00002288 const char
2289 *caption;
2290
anthonydf8ebac2011-04-27 09:03:19 +00002291 double
2292 angle;
2293
2294 RandomInfo
2295 *random_info;
2296
2297 /*
2298 Simulate a Polaroid picture.
2299 */
cristy6fccee12011-10-20 18:43:18 +00002300 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002301 random_info=AcquireRandomInfo();
2302 angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2303 random_info=DestroyRandomInfo(random_info);
2304 if (*option == '-')
2305 {
2306 SetGeometryInfo(&geometry_info);
2307 flags=ParseGeometry(argv[i+1],&geometry_info);
2308 angle=geometry_info.rho;
2309 }
cristye9e3d382011-12-14 01:50:13 +00002310 caption=GetImageProperty(*image,"caption",exception);
2311 mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
cristy28474bf2011-09-11 23:32:52 +00002312 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002313 break;
2314 }
2315 if (LocaleCompare("posterize",option+1) == 0)
2316 {
2317 /*
2318 Posterize image.
2319 */
cristy6fccee12011-10-20 18:43:18 +00002320 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002321 (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
cristy018f07f2011-09-04 21:15:19 +00002322 quantize_info->dither,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002323 break;
2324 }
2325 if (LocaleCompare("preview",option+1) == 0)
2326 {
2327 PreviewType
2328 preview_type;
2329
2330 /*
2331 Preview image.
2332 */
cristy6fccee12011-10-20 18:43:18 +00002333 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002334 if (*option == '+')
2335 preview_type=UndefinedPreview;
2336 else
cristy28474bf2011-09-11 23:32:52 +00002337 preview_type=(PreviewType) ParseCommandOption(
2338 MagickPreviewOptions,MagickFalse,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002339 mogrify_image=PreviewImage(*image,preview_type,exception);
2340 break;
2341 }
2342 if (LocaleCompare("profile",option+1) == 0)
2343 {
2344 const char
2345 *name;
2346
2347 const StringInfo
2348 *profile;
2349
2350 Image
2351 *profile_image;
2352
2353 ImageInfo
2354 *profile_info;
2355
cristy6fccee12011-10-20 18:43:18 +00002356 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002357 if (*option == '+')
2358 {
2359 /*
2360 Remove a profile from the image.
2361 */
2362 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
cristy092d71c2011-10-14 18:01:29 +00002363 NULL,0,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002364 break;
2365 }
2366 /*
2367 Associate a profile with the image.
2368 */
2369 profile_info=CloneImageInfo(mogrify_info);
2370 profile=GetImageProfile(*image,"iptc");
2371 if (profile != (StringInfo *) NULL)
2372 profile_info->profile=(void *) CloneStringInfo(profile);
2373 profile_image=GetImageCache(profile_info,argv[i+1],exception);
2374 profile_info=DestroyImageInfo(profile_info);
2375 if (profile_image == (Image *) NULL)
2376 {
2377 StringInfo
2378 *profile;
2379
2380 profile_info=CloneImageInfo(mogrify_info);
2381 (void) CopyMagickString(profile_info->filename,argv[i+1],
2382 MaxTextExtent);
2383 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2384 if (profile != (StringInfo *) NULL)
2385 {
2386 (void) ProfileImage(*image,profile_info->magick,
2387 GetStringInfoDatum(profile),(size_t)
cristy3fac9ec2011-11-17 18:04:39 +00002388 GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002389 profile=DestroyStringInfo(profile);
2390 }
2391 profile_info=DestroyImageInfo(profile_info);
2392 break;
2393 }
2394 ResetImageProfileIterator(profile_image);
2395 name=GetNextImageProfile(profile_image);
2396 while (name != (const char *) NULL)
2397 {
2398 profile=GetImageProfile(profile_image,name);
2399 if (profile != (StringInfo *) NULL)
2400 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
cristy3fac9ec2011-11-17 18:04:39 +00002401 (size_t) GetStringInfoLength(profile),exception);
anthonydf8ebac2011-04-27 09:03:19 +00002402 name=GetNextImageProfile(profile_image);
2403 }
2404 profile_image=DestroyImage(profile_image);
2405 break;
2406 }
2407 break;
2408 }
2409 case 'q':
2410 {
2411 if (LocaleCompare("quantize",option+1) == 0)
2412 {
2413 if (*option == '+')
2414 {
2415 quantize_info->colorspace=UndefinedColorspace;
2416 break;
2417 }
2418 quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2419 MagickColorspaceOptions,MagickFalse,argv[i+1]);
2420 break;
2421 }
2422 break;
2423 }
2424 case 'r':
2425 {
2426 if (LocaleCompare("radial-blur",option+1) == 0)
2427 {
2428 /*
2429 Radial blur image.
2430 */
cristy6fccee12011-10-20 18:43:18 +00002431 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy6435bd92011-09-10 02:10:07 +00002432 flags=ParseGeometry(argv[i+1],&geometry_info);
2433 mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2434 geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002435 break;
2436 }
2437 if (LocaleCompare("raise",option+1) == 0)
2438 {
2439 /*
2440 Surround image with a raise of solid color.
2441 */
2442 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2443 if ((flags & SigmaValue) == 0)
2444 geometry.height=geometry.width;
2445 (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
cristy6170ac32011-08-28 14:15:37 +00002446 MagickFalse,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002447 break;
2448 }
2449 if (LocaleCompare("random-threshold",option+1) == 0)
2450 {
2451 /*
2452 Threshold image.
2453 */
cristy6fccee12011-10-20 18:43:18 +00002454 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00002455 (void) RandomThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00002456 break;
2457 }
anthonydf8ebac2011-04-27 09:03:19 +00002458 if (LocaleCompare("region",option+1) == 0)
2459 {
cristy6fccee12011-10-20 18:43:18 +00002460 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002461 if (region_image != (Image *) NULL)
2462 {
2463 /*
2464 Composite region.
2465 */
2466 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00002467 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00002468 region_geometry.x,region_geometry.y,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002469 *image=DestroyImage(*image);
2470 *image=region_image;
2471 region_image = (Image *) NULL;
2472 }
2473 if (*option == '+')
2474 break;
2475 /*
2476 Apply transformations to a selected region of the image.
2477 */
cristy3ed852e2009-09-05 21:47:34 +00002478 (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2479 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002480 mogrify_image=CropImage(*image,&region_geometry,exception);
2481 if (mogrify_image == (Image *) NULL)
2482 break;
2483 region_image=(*image);
2484 *image=mogrify_image;
2485 mogrify_image=(Image *) NULL;
2486 break;
cristy3ed852e2009-09-05 21:47:34 +00002487 }
anthonydf8ebac2011-04-27 09:03:19 +00002488 if (LocaleCompare("render",option+1) == 0)
2489 {
cristy6fccee12011-10-20 18:43:18 +00002490 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002491 draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2492 break;
2493 }
2494 if (LocaleCompare("remap",option+1) == 0)
2495 {
2496 Image
2497 *remap_image;
cristy3ed852e2009-09-05 21:47:34 +00002498
anthonydf8ebac2011-04-27 09:03:19 +00002499 /*
2500 Transform image colors to match this set of colors.
2501 */
cristy6fccee12011-10-20 18:43:18 +00002502 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002503 if (*option == '+')
2504 break;
2505 remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2506 if (remap_image == (Image *) NULL)
2507 break;
cristy018f07f2011-09-04 21:15:19 +00002508 (void) RemapImage(quantize_info,*image,remap_image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002509 remap_image=DestroyImage(remap_image);
2510 break;
2511 }
2512 if (LocaleCompare("repage",option+1) == 0)
2513 {
2514 if (*option == '+')
2515 {
2516 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2517 break;
2518 }
2519 (void) ResetImagePage(*image,argv[i+1]);
anthonydf8ebac2011-04-27 09:03:19 +00002520 break;
2521 }
2522 if (LocaleCompare("resample",option+1) == 0)
2523 {
2524 /*
2525 Resample image.
2526 */
cristy6fccee12011-10-20 18:43:18 +00002527 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002528 flags=ParseGeometry(argv[i+1],&geometry_info);
2529 if ((flags & SigmaValue) == 0)
2530 geometry_info.sigma=geometry_info.rho;
2531 mogrify_image=ResampleImage(*image,geometry_info.rho,
2532 geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2533 break;
2534 }
2535 if (LocaleCompare("resize",option+1) == 0)
2536 {
2537 /*
2538 Resize image.
2539 */
cristy6fccee12011-10-20 18:43:18 +00002540 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002541 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2542 mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2543 (*image)->filter,(*image)->blur,exception);
2544 break;
2545 }
2546 if (LocaleCompare("roll",option+1) == 0)
2547 {
2548 /*
2549 Roll image.
2550 */
cristy6fccee12011-10-20 18:43:18 +00002551 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002552 (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2553 mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2554 break;
2555 }
2556 if (LocaleCompare("rotate",option+1) == 0)
2557 {
2558 char
2559 *geometry;
2560
2561 /*
2562 Check for conditional image rotation.
2563 */
cristy6fccee12011-10-20 18:43:18 +00002564 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002565 if (strchr(argv[i+1],'>') != (char *) NULL)
2566 if ((*image)->columns <= (*image)->rows)
2567 break;
2568 if (strchr(argv[i+1],'<') != (char *) NULL)
2569 if ((*image)->columns >= (*image)->rows)
2570 break;
2571 /*
2572 Rotate image.
2573 */
2574 geometry=ConstantString(argv[i+1]);
2575 (void) SubstituteString(&geometry,">","");
2576 (void) SubstituteString(&geometry,"<","");
2577 (void) ParseGeometry(geometry,&geometry_info);
2578 geometry=DestroyString(geometry);
2579 mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2580 break;
2581 }
2582 break;
2583 }
2584 case 's':
2585 {
2586 if (LocaleCompare("sample",option+1) == 0)
2587 {
2588 /*
2589 Sample image with pixel replication.
2590 */
cristy6fccee12011-10-20 18:43:18 +00002591 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002592 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2593 mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2594 exception);
2595 break;
2596 }
2597 if (LocaleCompare("scale",option+1) == 0)
2598 {
2599 /*
2600 Resize image.
2601 */
cristy6fccee12011-10-20 18:43:18 +00002602 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002603 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2604 mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2605 exception);
2606 break;
2607 }
2608 if (LocaleCompare("selective-blur",option+1) == 0)
2609 {
2610 /*
2611 Selectively blur pixels within a contrast threshold.
2612 */
cristy6fccee12011-10-20 18:43:18 +00002613 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002614 flags=ParseGeometry(argv[i+1],&geometry_info);
2615 if ((flags & PercentValue) != 0)
2616 geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
cristyf4ad9df2011-07-08 16:49:03 +00002617 mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
cristy1e7aa312011-09-10 20:01:36 +00002618 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002619 break;
2620 }
2621 if (LocaleCompare("separate",option+1) == 0)
2622 {
2623 /*
2624 Break channels into separate images.
anthonydf8ebac2011-04-27 09:03:19 +00002625 */
cristy6fccee12011-10-20 18:43:18 +00002626 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy3139dc22011-07-08 00:11:42 +00002627 mogrify_image=SeparateImages(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002628 break;
2629 }
2630 if (LocaleCompare("sepia-tone",option+1) == 0)
2631 {
2632 double
2633 threshold;
2634
2635 /*
2636 Sepia-tone image.
2637 */
cristy6fccee12011-10-20 18:43:18 +00002638 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002639 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2640 1.0);
anthonydf8ebac2011-04-27 09:03:19 +00002641 mogrify_image=SepiaToneImage(*image,threshold,exception);
2642 break;
2643 }
2644 if (LocaleCompare("segment",option+1) == 0)
2645 {
2646 /*
2647 Segment image.
2648 */
cristy6fccee12011-10-20 18:43:18 +00002649 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002650 flags=ParseGeometry(argv[i+1],&geometry_info);
2651 if ((flags & SigmaValue) == 0)
2652 geometry_info.sigma=1.0;
2653 (void) SegmentImage(*image,(*image)->colorspace,
cristy018f07f2011-09-04 21:15:19 +00002654 mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2655 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002656 break;
2657 }
2658 if (LocaleCompare("set",option+1) == 0)
2659 {
2660 char
2661 *value;
2662
2663 /*
2664 Set image option.
2665 */
2666 if (*option == '+')
2667 {
2668 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2669 (void) DeleteImageRegistry(argv[i+1]+9);
2670 else
2671 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2672 {
2673 (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2674 (void) DeleteImageArtifact(*image,argv[i+1]+7);
2675 }
2676 else
2677 (void) DeleteImageProperty(*image,argv[i+1]);
2678 break;
2679 }
cristy018f07f2011-09-04 21:15:19 +00002680 value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2681 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002682 if (value == (char *) NULL)
2683 break;
2684 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2685 (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2686 exception);
2687 else
2688 if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2689 {
2690 (void) SetImageOption(image_info,argv[i+1]+7,value);
2691 (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2692 (void) SetImageArtifact(*image,argv[i+1]+7,value);
2693 }
2694 else
cristyd15e6592011-10-15 00:13:06 +00002695 (void) SetImageProperty(*image,argv[i+1],value,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002696 value=DestroyString(value);
2697 break;
2698 }
2699 if (LocaleCompare("shade",option+1) == 0)
2700 {
2701 /*
2702 Shade image.
2703 */
cristy6fccee12011-10-20 18:43:18 +00002704 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002705 flags=ParseGeometry(argv[i+1],&geometry_info);
2706 if ((flags & SigmaValue) == 0)
2707 geometry_info.sigma=1.0;
2708 mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2709 MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2710 break;
2711 }
2712 if (LocaleCompare("shadow",option+1) == 0)
2713 {
2714 /*
2715 Shadow image.
2716 */
cristy6fccee12011-10-20 18:43:18 +00002717 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002718 flags=ParseGeometry(argv[i+1],&geometry_info);
2719 if ((flags & SigmaValue) == 0)
2720 geometry_info.sigma=1.0;
2721 if ((flags & XiValue) == 0)
2722 geometry_info.xi=4.0;
2723 if ((flags & PsiValue) == 0)
2724 geometry_info.psi=4.0;
2725 mogrify_image=ShadowImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00002726 geometry_info.sigma,(*image)->bias,(ssize_t)
2727 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
2728 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002729 break;
2730 }
2731 if (LocaleCompare("sharpen",option+1) == 0)
2732 {
2733 /*
2734 Sharpen image.
2735 */
cristy6fccee12011-10-20 18:43:18 +00002736 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002737 flags=ParseGeometry(argv[i+1],&geometry_info);
2738 if ((flags & SigmaValue) == 0)
2739 geometry_info.sigma=1.0;
cristy05c0c9a2011-09-05 23:16:13 +00002740 if ((flags & XiValue) == 0)
2741 geometry_info.xi=0.0;
cristyf4ad9df2011-07-08 16:49:03 +00002742 mogrify_image=SharpenImage(*image,geometry_info.rho,
cristy05c0c9a2011-09-05 23:16:13 +00002743 geometry_info.sigma,geometry_info.xi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002744 break;
2745 }
2746 if (LocaleCompare("shave",option+1) == 0)
2747 {
2748 /*
2749 Shave the image edges.
2750 */
cristy6fccee12011-10-20 18:43:18 +00002751 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002752 flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2753 mogrify_image=ShaveImage(*image,&geometry,exception);
2754 break;
2755 }
2756 if (LocaleCompare("shear",option+1) == 0)
2757 {
2758 /*
2759 Shear image.
2760 */
cristy6fccee12011-10-20 18:43:18 +00002761 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002762 flags=ParseGeometry(argv[i+1],&geometry_info);
2763 if ((flags & SigmaValue) == 0)
2764 geometry_info.sigma=geometry_info.rho;
2765 mogrify_image=ShearImage(*image,geometry_info.rho,
2766 geometry_info.sigma,exception);
2767 break;
2768 }
2769 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2770 {
2771 /*
2772 Sigmoidal non-linearity contrast control.
2773 */
cristy6fccee12011-10-20 18:43:18 +00002774 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002775 flags=ParseGeometry(argv[i+1],&geometry_info);
2776 if ((flags & SigmaValue) == 0)
2777 geometry_info.sigma=(double) QuantumRange/2.0;
2778 if ((flags & PercentValue) != 0)
2779 geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2780 100.0;
cristy9ee60942011-07-06 14:54:38 +00002781 (void) SigmoidalContrastImage(*image,(*option == '-') ?
cristy33bd5152011-08-24 01:42:24 +00002782 MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2783 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002784 break;
2785 }
2786 if (LocaleCompare("sketch",option+1) == 0)
2787 {
2788 /*
2789 Sketch image.
2790 */
cristy6fccee12011-10-20 18:43:18 +00002791 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002792 flags=ParseGeometry(argv[i+1],&geometry_info);
2793 if ((flags & SigmaValue) == 0)
2794 geometry_info.sigma=1.0;
2795 mogrify_image=SketchImage(*image,geometry_info.rho,
cristyf7ef0252011-09-09 14:50:06 +00002796 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002797 break;
2798 }
2799 if (LocaleCompare("solarize",option+1) == 0)
2800 {
2801 double
2802 threshold;
2803
cristy6fccee12011-10-20 18:43:18 +00002804 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy9b34e302011-11-05 02:15:45 +00002805 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2806 1.0);
cristy5cbc0162011-08-29 00:36:28 +00002807 (void) SolarizeImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002808 break;
2809 }
2810 if (LocaleCompare("sparse-color",option+1) == 0)
2811 {
2812 SparseColorMethod
2813 method;
2814
2815 char
2816 *arguments;
2817
2818 /*
2819 Sparse Color Interpolated Gradient
2820 */
cristy6fccee12011-10-20 18:43:18 +00002821 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002822 method=(SparseColorMethod) ParseCommandOption(
2823 MagickSparseColorOptions,MagickFalse,argv[i+1]);
cristy018f07f2011-09-04 21:15:19 +00002824 arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2825 exception);
anthonydf8ebac2011-04-27 09:03:19 +00002826 if (arguments == (char *) NULL)
2827 break;
cristy3884f692011-07-08 18:00:18 +00002828 mogrify_image=SparseColorOption(*image,method,arguments,
anthonydf8ebac2011-04-27 09:03:19 +00002829 option[0] == '+' ? MagickTrue : MagickFalse,exception);
2830 arguments=DestroyString(arguments);
2831 break;
2832 }
2833 if (LocaleCompare("splice",option+1) == 0)
2834 {
2835 /*
2836 Splice a solid color into the image.
2837 */
cristy6fccee12011-10-20 18:43:18 +00002838 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002839 (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2840 mogrify_image=SpliceImage(*image,&geometry,exception);
2841 break;
2842 }
2843 if (LocaleCompare("spread",option+1) == 0)
2844 {
2845 /*
2846 Spread an image.
2847 */
cristy6fccee12011-10-20 18:43:18 +00002848 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002849 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy5c4e2582011-09-11 19:21:03 +00002850 mogrify_image=SpreadImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00002851 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002852 break;
2853 }
2854 if (LocaleCompare("statistic",option+1) == 0)
2855 {
2856 StatisticType
2857 type;
2858
cristy6fccee12011-10-20 18:43:18 +00002859 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002860 type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2861 MagickFalse,argv[i+1]);
2862 (void) ParseGeometry(argv[i+2],&geometry_info);
cristyf4ad9df2011-07-08 16:49:03 +00002863 mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2864 (size_t) geometry_info.sigma,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002865 break;
2866 }
2867 if (LocaleCompare("stretch",option+1) == 0)
2868 {
2869 if (*option == '+')
2870 {
2871 draw_info->stretch=UndefinedStretch;
2872 break;
2873 }
2874 draw_info->stretch=(StretchType) ParseCommandOption(
2875 MagickStretchOptions,MagickFalse,argv[i+1]);
2876 break;
2877 }
2878 if (LocaleCompare("strip",option+1) == 0)
2879 {
2880 /*
2881 Strip image of profiles and comments.
2882 */
cristy6fccee12011-10-20 18:43:18 +00002883 (void) SyncImageSettings(mogrify_info,*image,exception);
cristye941a752011-10-15 01:52:48 +00002884 (void) StripImage(*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002885 break;
2886 }
2887 if (LocaleCompare("stroke",option+1) == 0)
2888 {
2889 ExceptionInfo
2890 *sans;
2891
anthonyfd706f92012-01-19 04:22:02 +00002892 PixelInfo
2893 color;
2894
anthonydf8ebac2011-04-27 09:03:19 +00002895 if (*option == '+')
2896 {
cristy9950d572011-10-01 18:22:35 +00002897 (void) QueryColorCompliance("none",AllCompliance,
2898 &draw_info->stroke,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002899 if (draw_info->stroke_pattern != (Image *) NULL)
2900 draw_info->stroke_pattern=DestroyImage(
2901 draw_info->stroke_pattern);
2902 break;
2903 }
2904 sans=AcquireExceptionInfo();
anthonyfd706f92012-01-19 04:22:02 +00002905 status=QueryColorCompliance(argv[i+1],AllCompliance,&color,sans);
anthonydf8ebac2011-04-27 09:03:19 +00002906 sans=DestroyExceptionInfo(sans);
2907 if (status == MagickFalse)
2908 draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2909 exception);
anthonyfd706f92012-01-19 04:22:02 +00002910 else
2911 draw_info->stroke=color;
anthonydf8ebac2011-04-27 09:03:19 +00002912 break;
2913 }
2914 if (LocaleCompare("strokewidth",option+1) == 0)
2915 {
cristy9b34e302011-11-05 02:15:45 +00002916 draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
anthonydf8ebac2011-04-27 09:03:19 +00002917 break;
2918 }
2919 if (LocaleCompare("style",option+1) == 0)
2920 {
2921 if (*option == '+')
2922 {
2923 draw_info->style=UndefinedStyle;
2924 break;
2925 }
2926 draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2927 MagickFalse,argv[i+1]);
2928 break;
2929 }
2930 if (LocaleCompare("swirl",option+1) == 0)
2931 {
2932 /*
2933 Swirl image.
2934 */
cristy6fccee12011-10-20 18:43:18 +00002935 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002936 (void) ParseGeometry(argv[i+1],&geometry_info);
cristy76f512e2011-09-12 01:26:56 +00002937 mogrify_image=SwirlImage(*image,geometry_info.rho,
2938 interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002939 break;
2940 }
2941 break;
2942 }
2943 case 't':
2944 {
2945 if (LocaleCompare("threshold",option+1) == 0)
2946 {
2947 double
2948 threshold;
2949
2950 /*
2951 Threshold image.
2952 */
cristy6fccee12011-10-20 18:43:18 +00002953 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002954 if (*option == '+')
anthony247a86d2011-05-03 13:18:18 +00002955 threshold=(double) QuantumRange/2;
anthonydf8ebac2011-04-27 09:03:19 +00002956 else
cristy9b34e302011-11-05 02:15:45 +00002957 threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2958 1.0);
cristye941a752011-10-15 01:52:48 +00002959 (void) BilevelImage(*image,threshold,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002960 break;
2961 }
2962 if (LocaleCompare("thumbnail",option+1) == 0)
2963 {
2964 /*
2965 Thumbnail image.
2966 */
cristy6fccee12011-10-20 18:43:18 +00002967 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002968 (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2969 mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2970 exception);
2971 break;
2972 }
2973 if (LocaleCompare("tile",option+1) == 0)
2974 {
2975 if (*option == '+')
2976 {
2977 if (draw_info->fill_pattern != (Image *) NULL)
2978 draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
2979 break;
2980 }
2981 draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
2982 exception);
2983 break;
2984 }
2985 if (LocaleCompare("tint",option+1) == 0)
2986 {
2987 /*
2988 Tint the image.
2989 */
cristy6fccee12011-10-20 18:43:18 +00002990 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy28474bf2011-09-11 23:32:52 +00002991 mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
anthonydf8ebac2011-04-27 09:03:19 +00002992 break;
2993 }
2994 if (LocaleCompare("transform",option+1) == 0)
2995 {
2996 /*
2997 Affine transform image.
2998 */
cristy6fccee12011-10-20 18:43:18 +00002999 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003000 mogrify_image=AffineTransformImage(*image,&draw_info->affine,
3001 exception);
3002 break;
3003 }
3004 if (LocaleCompare("transparent",option+1) == 0)
3005 {
cristy4c08aed2011-07-01 19:47:50 +00003006 PixelInfo
anthonydf8ebac2011-04-27 09:03:19 +00003007 target;
3008
cristy6fccee12011-10-20 18:43:18 +00003009 (void) SyncImageSettings(mogrify_info,*image,exception);
cristy269c9412011-10-13 23:41:15 +00003010 (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
cristy9950d572011-10-01 18:22:35 +00003011 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003012 (void) TransparentPaintImage(*image,&target,(Quantum)
cristy189e84c2011-08-27 18:08:53 +00003013 TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
cristy82d7af52011-10-16 16:26:41 +00003014 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003015 break;
3016 }
3017 if (LocaleCompare("transpose",option+1) == 0)
3018 {
3019 /*
3020 Transpose image scanlines.
3021 */
cristy6fccee12011-10-20 18:43:18 +00003022 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003023 mogrify_image=TransposeImage(*image,exception);
3024 break;
3025 }
3026 if (LocaleCompare("transverse",option+1) == 0)
3027 {
3028 /*
3029 Transverse image scanlines.
3030 */
cristy6fccee12011-10-20 18:43:18 +00003031 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003032 mogrify_image=TransverseImage(*image,exception);
3033 break;
3034 }
3035 if (LocaleCompare("treedepth",option+1) == 0)
3036 {
3037 quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3038 break;
3039 }
3040 if (LocaleCompare("trim",option+1) == 0)
3041 {
3042 /*
3043 Trim image.
3044 */
cristy6fccee12011-10-20 18:43:18 +00003045 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003046 mogrify_image=TrimImage(*image,exception);
3047 break;
3048 }
3049 if (LocaleCompare("type",option+1) == 0)
3050 {
3051 ImageType
3052 type;
3053
cristy6fccee12011-10-20 18:43:18 +00003054 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003055 if (*option == '+')
3056 type=UndefinedType;
3057 else
3058 type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3059 argv[i+1]);
3060 (*image)->type=UndefinedType;
cristy018f07f2011-09-04 21:15:19 +00003061 (void) SetImageType(*image,type,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003062 break;
3063 }
3064 break;
3065 }
3066 case 'u':
3067 {
3068 if (LocaleCompare("undercolor",option+1) == 0)
3069 {
cristy9950d572011-10-01 18:22:35 +00003070 (void) QueryColorCompliance(argv[i+1],AllCompliance,
3071 &draw_info->undercolor,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003072 break;
3073 }
3074 if (LocaleCompare("unique",option+1) == 0)
3075 {
3076 if (*option == '+')
3077 {
3078 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3079 break;
3080 }
3081 (void) SetImageArtifact(*image,"identify:unique-colors","true");
3082 (void) SetImageArtifact(*image,"verbose","true");
3083 break;
3084 }
3085 if (LocaleCompare("unique-colors",option+1) == 0)
3086 {
3087 /*
3088 Unique image colors.
3089 */
cristy6fccee12011-10-20 18:43:18 +00003090 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003091 mogrify_image=UniqueImageColors(*image,exception);
3092 break;
3093 }
3094 if (LocaleCompare("unsharp",option+1) == 0)
3095 {
3096 /*
3097 Unsharp mask image.
3098 */
cristy6fccee12011-10-20 18:43:18 +00003099 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003100 flags=ParseGeometry(argv[i+1],&geometry_info);
3101 if ((flags & SigmaValue) == 0)
3102 geometry_info.sigma=1.0;
3103 if ((flags & XiValue) == 0)
3104 geometry_info.xi=1.0;
3105 if ((flags & PsiValue) == 0)
3106 geometry_info.psi=0.05;
cristyf4ad9df2011-07-08 16:49:03 +00003107 mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3108 geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003109 break;
3110 }
3111 break;
3112 }
3113 case 'v':
3114 {
3115 if (LocaleCompare("verbose",option+1) == 0)
3116 {
3117 (void) SetImageArtifact(*image,option+1,
3118 *option == '+' ? "false" : "true");
3119 break;
3120 }
3121 if (LocaleCompare("vignette",option+1) == 0)
3122 {
3123 /*
3124 Vignette image.
3125 */
cristy6fccee12011-10-20 18:43:18 +00003126 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003127 flags=ParseGeometry(argv[i+1],&geometry_info);
3128 if ((flags & SigmaValue) == 0)
3129 geometry_info.sigma=1.0;
3130 if ((flags & XiValue) == 0)
3131 geometry_info.xi=0.1*(*image)->columns;
3132 if ((flags & PsiValue) == 0)
3133 geometry_info.psi=0.1*(*image)->rows;
3134 mogrify_image=VignetteImage(*image,geometry_info.rho,
cristyeb6e6582011-12-09 09:14:23 +00003135 geometry_info.sigma,(*image)->bias,(ssize_t)
3136 ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
3137 exception);
anthonydf8ebac2011-04-27 09:03:19 +00003138 break;
3139 }
3140 if (LocaleCompare("virtual-pixel",option+1) == 0)
3141 {
3142 if (*option == '+')
3143 {
3144 (void) SetImageVirtualPixelMethod(*image,
cristy387430f2012-02-07 13:09:46 +00003145 UndefinedVirtualPixelMethod,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003146 break;
3147 }
3148 (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3149 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy387430f2012-02-07 13:09:46 +00003150 argv[i+1]),exception);
anthonydf8ebac2011-04-27 09:03:19 +00003151 break;
3152 }
3153 break;
3154 }
3155 case 'w':
3156 {
3157 if (LocaleCompare("wave",option+1) == 0)
3158 {
3159 /*
3160 Wave image.
3161 */
cristy6fccee12011-10-20 18:43:18 +00003162 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003163 flags=ParseGeometry(argv[i+1],&geometry_info);
3164 if ((flags & SigmaValue) == 0)
3165 geometry_info.sigma=1.0;
3166 mogrify_image=WaveImage(*image,geometry_info.rho,
cristy28474bf2011-09-11 23:32:52 +00003167 geometry_info.sigma,interpolate_method,exception);
anthonydf8ebac2011-04-27 09:03:19 +00003168 break;
3169 }
3170 if (LocaleCompare("weight",option+1) == 0)
3171 {
3172 draw_info->weight=StringToUnsignedLong(argv[i+1]);
3173 if (LocaleCompare(argv[i+1],"all") == 0)
3174 draw_info->weight=0;
3175 if (LocaleCompare(argv[i+1],"bold") == 0)
3176 draw_info->weight=700;
3177 if (LocaleCompare(argv[i+1],"bolder") == 0)
3178 if (draw_info->weight <= 800)
3179 draw_info->weight+=100;
3180 if (LocaleCompare(argv[i+1],"lighter") == 0)
3181 if (draw_info->weight >= 100)
3182 draw_info->weight-=100;
3183 if (LocaleCompare(argv[i+1],"normal") == 0)
3184 draw_info->weight=400;
3185 break;
3186 }
3187 if (LocaleCompare("white-threshold",option+1) == 0)
3188 {
3189 /*
3190 White threshold image.
3191 */
cristy6fccee12011-10-20 18:43:18 +00003192 (void) SyncImageSettings(mogrify_info,*image,exception);
cristyf4ad9df2011-07-08 16:49:03 +00003193 (void) WhiteThresholdImage(*image,argv[i+1],exception);
anthonydf8ebac2011-04-27 09:03:19 +00003194 break;
3195 }
3196 break;
3197 }
3198 default:
3199 break;
3200 }
3201 /*
3202 Replace current image with any image that was generated
3203 */
3204 if (mogrify_image != (Image *) NULL)
3205 ReplaceImageInListReturnLast(image,mogrify_image);
cristy3ed852e2009-09-05 21:47:34 +00003206 i+=count;
3207 }
3208 if (region_image != (Image *) NULL)
3209 {
anthonydf8ebac2011-04-27 09:03:19 +00003210 /*
3211 Composite transformed region onto image.
3212 */
cristy6fccee12011-10-20 18:43:18 +00003213 (void) SyncImageSettings(mogrify_info,*image,exception);
anthonya129f702011-04-14 01:08:48 +00003214 (void) CompositeImage(region_image,region_image->matte !=
cristyf4ad9df2011-07-08 16:49:03 +00003215 MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
cristye941a752011-10-15 01:52:48 +00003216 region_geometry.x,region_geometry.y,exception);
cristy3ed852e2009-09-05 21:47:34 +00003217 *image=DestroyImage(*image);
3218 *image=region_image;
anthonye9c27192011-03-27 08:07:06 +00003219 region_image = (Image *) NULL;
cristy3ed852e2009-09-05 21:47:34 +00003220 }
3221 /*
3222 Free resources.
3223 */
anthonydf8ebac2011-04-27 09:03:19 +00003224 quantize_info=DestroyQuantizeInfo(quantize_info);
3225 draw_info=DestroyDrawInfo(draw_info);
cristy6b3da3a2010-06-20 02:21:46 +00003226 mogrify_info=DestroyImageInfo(mogrify_info);
cristy82d7af52011-10-16 16:26:41 +00003227 status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
cristy72988482011-03-29 16:34:38 +00003228 return(status == 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003229}
3230
3231/*
3232%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3233% %
3234% %
3235% %
cristy5063d812010-10-19 16:28:10 +00003236+ M o g r i f y I m a g e C o m m a n d %
cristy3ed852e2009-09-05 21:47:34 +00003237% %
3238% %
3239% %
3240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3241%
3242% MogrifyImageCommand() transforms an image or a sequence of images. These
3243% transforms include image scaling, image rotation, color reduction, and
3244% others. The transmogrified image overwrites the original image.
3245%
3246% The format of the MogrifyImageCommand method is:
3247%
3248% MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3249% const char **argv,char **metadata,ExceptionInfo *exception)
3250%
3251% A description of each parameter follows:
3252%
3253% o image_info: the image info.
3254%
3255% o argc: the number of elements in the argument vector.
3256%
3257% o argv: A text array containing the command line arguments.
3258%
3259% o metadata: any metadata is returned here.
3260%
3261% o exception: return any errors or warnings in this structure.
3262%
3263*/
3264
3265static MagickBooleanType MogrifyUsage(void)
3266{
3267 static const char
cristy87c02f42012-02-24 00:19:10 +00003268 *channel_operators[]=
3269 {
3270 "-channel-extract channel-list",
3271 " extract the channels in order",
3272 "-channel-inject channel-list",
3273 " inject the channels in order",
3274 "-channel-swap channel,channel",
3275 " swap channels",
3276 (char *) NULL
3277 },
cristy3ed852e2009-09-05 21:47:34 +00003278 *miscellaneous[]=
3279 {
3280 "-debug events display copious debugging information",
3281 "-help print program options",
3282 "-list type print a list of supported option arguments",
3283 "-log format format of debugging information",
3284 "-version print version information",
3285 (char *) NULL
3286 },
3287 *operators[]=
3288 {
3289 "-adaptive-blur geometry",
3290 " adaptively blur pixels; decrease effect near edges",
3291 "-adaptive-resize geometry",
3292 " adaptively resize image using 'mesh' interpolation",
3293 "-adaptive-sharpen geometry",
3294 " adaptively sharpen pixels; increase effect near edges",
3295 "-alpha option on, activate, off, deactivate, set, opaque, copy",
3296 " transparent, extract, background, or shape",
3297 "-annotate geometry text",
3298 " annotate the image with text",
3299 "-auto-gamma automagically adjust gamma level of image",
3300 "-auto-level automagically adjust color levels of image",
3301 "-auto-orient automagically orient (rotate) image",
3302 "-bench iterations measure performance",
3303 "-black-threshold value",
3304 " force all pixels below the threshold into black",
3305 "-blue-shift simulate a scene at nighttime in the moonlight",
3306 "-blur geometry reduce image noise and reduce detail levels",
3307 "-border geometry surround image with a border of color",
3308 "-bordercolor color border color",
cristya28d6b82010-01-11 20:03:47 +00003309 "-brightness-contrast geometry",
3310 " improve brightness / contrast of the image",
cristy3ed852e2009-09-05 21:47:34 +00003311 "-cdl filename color correct with a color decision list",
cristy05c0c9a2011-09-05 23:16:13 +00003312 "-charcoal geometry simulate a charcoal drawing",
cristy3ed852e2009-09-05 21:47:34 +00003313 "-chop geometry remove pixels from the image interior",
cristyecb0c6d2009-09-25 16:50:09 +00003314 "-clamp restrict pixel range from 0 to the quantum depth",
cristycee97112010-05-28 00:44:52 +00003315 "-clip clip along the first path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003316 "-clip-mask filename associate a clip mask with the image",
cristycee97112010-05-28 00:44:52 +00003317 "-clip-path id clip along a named path from the 8BIM profile",
cristy3ed852e2009-09-05 21:47:34 +00003318 "-colorize value colorize the image with the fill color",
cristye6365592010-04-02 17:31:23 +00003319 "-color-matrix matrix apply color correction to the image",
cristy3ed852e2009-09-05 21:47:34 +00003320 "-contrast enhance or reduce the image contrast",
3321 "-contrast-stretch geometry",
3322 " improve contrast by `stretching' the intensity range",
3323 "-convolve coefficients",
3324 " apply a convolution kernel to the image",
3325 "-cycle amount cycle the image colormap",
3326 "-decipher filename convert cipher pixels to plain pixels",
3327 "-deskew threshold straighten an image",
3328 "-despeckle reduce the speckles within an image",
3329 "-distort method args",
3330 " distort images according to given method ad args",
3331 "-draw string annotate the image with a graphic primitive",
3332 "-edge radius apply a filter to detect edges in the image",
3333 "-encipher filename convert plain pixels to cipher pixels",
3334 "-emboss radius emboss an image",
3335 "-enhance apply a digital filter to enhance a noisy image",
3336 "-equalize perform histogram equalization to an image",
3337 "-evaluate operator value",
cristyd18ae7c2010-03-07 17:39:52 +00003338 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003339 "-extent geometry set the image size",
3340 "-extract geometry extract area from image",
3341 "-fft implements the discrete Fourier transform (DFT)",
3342 "-flip flip image vertically",
3343 "-floodfill geometry color",
3344 " floodfill the image with color",
3345 "-flop flop image horizontally",
3346 "-frame geometry surround image with an ornamental border",
cristyc2b730e2009-11-24 14:32:09 +00003347 "-function name parameters",
cristy3ed852e2009-09-05 21:47:34 +00003348 " apply function over image values",
3349 "-gamma value level of gamma correction",
3350 "-gaussian-blur geometry",
3351 " reduce image noise and reduce detail levels",
cristy901f09d2009-10-16 22:56:10 +00003352 "-geometry geometry preferred size or location of the image",
cristy3ed852e2009-09-05 21:47:34 +00003353 "-identify identify the format and characteristics of the image",
3354 "-ift implements the inverse discrete Fourier transform (DFT)",
3355 "-implode amount implode image pixels about the center",
anthonyfd706f92012-01-19 04:22:02 +00003356 "-interpolative-resize geometry",
3357 " resize image using interpolation",
cristy3ed852e2009-09-05 21:47:34 +00003358 "-lat geometry local adaptive thresholding",
3359 "-layers method optimize, merge, or compare image layers",
3360 "-level value adjust the level of image contrast",
3361 "-level-colors color,color",
cristyee0f8d72009-09-19 00:58:29 +00003362 " level image with the given colors",
cristy3ed852e2009-09-05 21:47:34 +00003363 "-linear-stretch geometry",
3364 " improve contrast by `stretching with saturation'",
3365 "-liquid-rescale geometry",
3366 " rescale image with seam-carving",
cristy3c741502011-04-01 23:21:16 +00003367 "-median geometry apply a median filter to the image",
glennrp30d2dc62011-06-25 03:17:16 +00003368 "-mode geometry make each pixel the 'predominant color' of the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003369 "-modulate value vary the brightness, saturation, and hue",
3370 "-monochrome transform image to black and white",
cristy7c1b9fd2010-02-02 14:36:00 +00003371 "-morphology method kernel",
anthony29188a82010-01-22 10:12:34 +00003372 " apply a morphology method to the image",
cristy3ed852e2009-09-05 21:47:34 +00003373 "-motion-blur geometry",
3374 " simulate motion blur",
3375 "-negate replace every pixel with its complementary color ",
cristy3c741502011-04-01 23:21:16 +00003376 "-noise geometry add or reduce noise in an image",
cristy3ed852e2009-09-05 21:47:34 +00003377 "-normalize transform image to span the full range of colors",
3378 "-opaque color change this color to the fill color",
3379 "-ordered-dither NxN",
3380 " add a noise pattern to the image with specific",
3381 " amplitudes",
3382 "-paint radius simulate an oil painting",
3383 "-polaroid angle simulate a Polaroid picture",
3384 "-posterize levels reduce the image to a limited number of color levels",
cristy3ed852e2009-09-05 21:47:34 +00003385 "-profile filename add, delete, or apply an image profile",
3386 "-quantize colorspace reduce colors in this colorspace",
3387 "-radial-blur angle radial blur the image",
3388 "-raise value lighten/darken image edges to create a 3-D effect",
3389 "-random-threshold low,high",
3390 " random threshold the image",
cristy3ed852e2009-09-05 21:47:34 +00003391 "-region geometry apply options to a portion of the image",
3392 "-render render vector graphics",
3393 "-repage geometry size and location of an image canvas",
3394 "-resample geometry change the resolution of an image",
3395 "-resize geometry resize the image",
3396 "-roll geometry roll an image vertically or horizontally",
3397 "-rotate degrees apply Paeth rotation to the image",
3398 "-sample geometry scale image with pixel sampling",
3399 "-scale geometry scale the image",
3400 "-segment values segment an image",
3401 "-selective-blur geometry",
3402 " selectively blur pixels within a contrast threshold",
3403 "-sepia-tone threshold",
3404 " simulate a sepia-toned photo",
3405 "-set property value set an image property",
3406 "-shade degrees shade the image using a distant light source",
3407 "-shadow geometry simulate an image shadow",
3408 "-sharpen geometry sharpen the image",
3409 "-shave geometry shave pixels from the image edges",
cristycee97112010-05-28 00:44:52 +00003410 "-shear geometry slide one edge of the image along the X or Y axis",
cristy3ed852e2009-09-05 21:47:34 +00003411 "-sigmoidal-contrast geometry",
3412 " increase the contrast without saturating highlights or shadows",
3413 "-sketch geometry simulate a pencil sketch",
3414 "-solarize threshold negate all pixels above the threshold level",
3415 "-sparse-color method args",
3416 " fill in a image based on a few color points",
3417 "-splice geometry splice the background color into the image",
3418 "-spread radius displace image pixels by a random amount",
cristy0834d642011-03-18 18:26:08 +00003419 "-statistic type radius",
3420 " replace each pixel with corresponding statistic from the neighborhood",
cristy3ed852e2009-09-05 21:47:34 +00003421 "-strip strip image of all profiles and comments",
3422 "-swirl degrees swirl image pixels about the center",
3423 "-threshold value threshold the image",
3424 "-thumbnail geometry create a thumbnail of the image",
3425 "-tile filename tile image when filling a graphic primitive",
3426 "-tint value tint the image with the fill color",
3427 "-transform affine transform image",
3428 "-transparent color make this color transparent within the image",
3429 "-transpose flip image vertically and rotate 90 degrees",
3430 "-transverse flop image horizontally and rotate 270 degrees",
3431 "-trim trim image edges",
3432 "-type type image type",
3433 "-unique-colors discard all but one of any pixel color",
3434 "-unsharp geometry sharpen the image",
3435 "-vignette geometry soften the edges of the image in vignette style",
cristycee97112010-05-28 00:44:52 +00003436 "-wave geometry alter an image along a sine wave",
cristy3ed852e2009-09-05 21:47:34 +00003437 "-white-threshold value",
3438 " force all pixels above the threshold into white",
3439 (char *) NULL
3440 },
3441 *sequence_operators[]=
3442 {
cristy4285d782011-02-09 20:12:28 +00003443 "-append append an image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003444 "-clut apply a color lookup table to the image",
3445 "-coalesce merge a sequence of images",
3446 "-combine combine a sequence of images",
3447 "-composite composite image",
3448 "-crop geometry cut out a rectangular region of the image",
3449 "-deconstruct break down an image sequence into constituent parts",
cristyd18ae7c2010-03-07 17:39:52 +00003450 "-evaluate-sequence operator",
3451 " evaluate an arithmetic, relational, or logical expression",
cristy3ed852e2009-09-05 21:47:34 +00003452 "-flatten flatten a sequence of images",
3453 "-fx expression apply mathematical expression to an image channel(s)",
3454 "-hald-clut apply a Hald color lookup table to the image",
3455 "-morph value morph an image sequence",
3456 "-mosaic create a mosaic from an image sequence",
cristy36b94822010-05-20 12:48:16 +00003457 "-print string interpret string and print to console",
cristy3ed852e2009-09-05 21:47:34 +00003458 "-process arguments process the image with a custom image filter",
cristy3ed852e2009-09-05 21:47:34 +00003459 "-separate separate an image channel into a grayscale image",
cristy4285d782011-02-09 20:12:28 +00003460 "-smush geometry smush an image sequence together",
cristy3ed852e2009-09-05 21:47:34 +00003461 "-write filename write images to this file",
3462 (char *) NULL
3463 },
3464 *settings[]=
3465 {
3466 "-adjoin join images into a single multi-image file",
3467 "-affine matrix affine transform matrix",
3468 "-alpha option activate, deactivate, reset, or set the alpha channel",
3469 "-antialias remove pixel-aliasing",
3470 "-authenticate password",
3471 " decipher image with this password",
3472 "-attenuate value lessen (or intensify) when adding noise to an image",
3473 "-background color background color",
3474 "-bias value add bias when convolving an image",
3475 "-black-point-compensation",
3476 " use black point compensation",
3477 "-blue-primary point chromaticity blue primary point",
3478 "-bordercolor color border color",
3479 "-caption string assign a caption to an image",
3480 "-channel type apply option to select image channels",
3481 "-colors value preferred number of colors in the image",
3482 "-colorspace type alternate image colorspace",
3483 "-comment string annotate image with comment",
3484 "-compose operator set image composite operator",
3485 "-compress type type of pixel compression when writing the image",
anthonyfd706f92012-01-19 04:22:02 +00003486 "-define format:option=value",
cristy3ed852e2009-09-05 21:47:34 +00003487 " define one or more image format options",
3488 "-delay value display the next image after pausing",
3489 "-density geometry horizontal and vertical density of the image",
3490 "-depth value image depth",
cristyc9b12952010-03-28 01:12:28 +00003491 "-direction type render text right-to-left or left-to-right",
cristy3ed852e2009-09-05 21:47:34 +00003492 "-display server get image or font from this X server",
3493 "-dispose method layer disposal method",
3494 "-dither method apply error diffusion to image",
3495 "-encoding type text encoding type",
3496 "-endian type endianness (MSB or LSB) of the image",
3497 "-family name render text with this font family",
3498 "-fill color color to use when filling a graphic primitive",
3499 "-filter type use this filter when resizing an image",
3500 "-font name render text with this font",
anthonyfd706f92012-01-19 04:22:02 +00003501 "-format \"string\" output formatted image characteristics",
cristy3ed852e2009-09-05 21:47:34 +00003502 "-fuzz distance colors within this distance are considered equal",
3503 "-gravity type horizontal and vertical text placement",
3504 "-green-primary point chromaticity green primary point",
3505 "-intent type type of rendering intent when managing the image color",
3506 "-interlace type type of image interlacing scheme",
cristyb32b90a2009-09-07 21:45:48 +00003507 "-interline-spacing value",
3508 " set the space between two text lines",
cristy3ed852e2009-09-05 21:47:34 +00003509 "-interpolate method pixel color interpolation method",
3510 "-interword-spacing value",
3511 " set the space between two words",
3512 "-kerning value set the space between two letters",
3513 "-label string assign a label to an image",
3514 "-limit type value pixel cache resource limit",
3515 "-loop iterations add Netscape loop extension to your GIF animation",
3516 "-mask filename associate a mask with the image",
3517 "-mattecolor color frame color",
3518 "-monitor monitor progress",
3519 "-orient type image orientation",
3520 "-page geometry size and location of an image canvas (setting)",
3521 "-ping efficiently determine image attributes",
3522 "-pointsize value font point size",
cristy7c1b9fd2010-02-02 14:36:00 +00003523 "-precision value maximum number of significant digits to print",
cristy3ed852e2009-09-05 21:47:34 +00003524 "-preview type image preview type",
3525 "-quality value JPEG/MIFF/PNG compression level",
3526 "-quiet suppress all warning messages",
3527 "-red-primary point chromaticity red primary point",
3528 "-regard-warnings pay attention to warning messages",
3529 "-remap filename transform image colors to match this set of colors",
3530 "-respect-parentheses settings remain in effect until parenthesis boundary",
3531 "-sampling-factor geometry",
3532 " horizontal and vertical sampling factor",
3533 "-scene value image scene number",
3534 "-seed value seed a new sequence of pseudo-random numbers",
3535 "-size geometry width and height of image",
3536 "-stretch type render text with this font stretch",
3537 "-stroke color graphic primitive stroke color",
3538 "-strokewidth value graphic primitive stroke width",
3539 "-style type render text with this font style",
cristyd9a29192010-10-16 16:49:53 +00003540 "-synchronize synchronize image to storage device",
3541 "-taint declare the image as modified",
cristy3ed852e2009-09-05 21:47:34 +00003542 "-texture filename name of texture to tile onto the image background",
3543 "-tile-offset geometry",
3544 " tile offset",
3545 "-treedepth value color tree depth",
3546 "-transparent-color color",
3547 " transparent color",
3548 "-undercolor color annotation bounding box color",
3549 "-units type the units of image resolution",
3550 "-verbose print detailed information about the image",
3551 "-view FlashPix viewing transforms",
3552 "-virtual-pixel method",
3553 " virtual pixel access method",
3554 "-weight type render text with this font weight",
3555 "-white-point point chromaticity white point",
3556 (char *) NULL
3557 },
3558 *stack_operators[]=
3559 {
anthonyb69c4b32011-03-23 04:37:44 +00003560 "-delete indexes delete the image from the image sequence",
3561 "-duplicate count,indexes",
cristyecb10ff2011-03-22 13:14:03 +00003562 " duplicate an image one or more times",
cristy3ed852e2009-09-05 21:47:34 +00003563 "-insert index insert last image into the image sequence",
anthony9bd15492011-03-23 02:11:13 +00003564 "-reverse reverse image sequence",
cristy3ed852e2009-09-05 21:47:34 +00003565 "-swap indexes swap two images in the image sequence",
3566 (char *) NULL
3567 };
3568
3569 const char
3570 **p;
3571
cristybb503372010-05-27 20:51:26 +00003572 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
cristy610b2e22009-10-22 14:59:43 +00003573 (void) printf("Copyright: %s\n",GetMagickCopyright());
3574 (void) printf("Features: %s\n\n",GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003575 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3576 GetClientName());
3577 (void) printf("\nImage Settings:\n");
3578 for (p=settings; *p != (char *) NULL; p++)
3579 (void) printf(" %s\n",*p);
3580 (void) printf("\nImage Operators:\n");
3581 for (p=operators; *p != (char *) NULL; p++)
3582 (void) printf(" %s\n",*p);
cristy87c02f42012-02-24 00:19:10 +00003583 (void) printf("\nImage Channel Operators:\n");
3584 for (p=channel_operators; *p != (char *) NULL; p++)
3585 (void) printf(" %s\n",*p);
cristy3ed852e2009-09-05 21:47:34 +00003586 (void) printf("\nImage Sequence Operators:\n");
3587 for (p=sequence_operators; *p != (char *) NULL; p++)
3588 (void) printf(" %s\n",*p);
3589 (void) printf("\nImage Stack Operators:\n");
3590 for (p=stack_operators; *p != (char *) NULL; p++)
3591 (void) printf(" %s\n",*p);
3592 (void) printf("\nMiscellaneous Options:\n");
3593 for (p=miscellaneous; *p != (char *) NULL; p++)
3594 (void) printf(" %s\n",*p);
3595 (void) printf(
anthonyfd706f92012-01-19 04:22:02 +00003596 "\nBy default, the image format of 'file' is determined by its magic\n");
cristy3ed852e2009-09-05 21:47:34 +00003597 (void) printf(
3598 "number. To specify a particular image format, precede the filename\n");
3599 (void) printf(
3600 "with an image format name and a colon (i.e. ps:image) or specify the\n");
3601 (void) printf(
3602 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
3603 (void) printf("'-' for standard input or output.\n");
3604 return(MagickFalse);
3605}
3606
3607WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3608 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3609{
3610#define DestroyMogrify() \
3611{ \
3612 if (format != (char *) NULL) \
3613 format=DestroyString(format); \
3614 if (path != (char *) NULL) \
3615 path=DestroyString(path); \
3616 DestroyImageStack(); \
cristybb503372010-05-27 20:51:26 +00003617 for (i=0; i < (ssize_t) argc; i++) \
cristy3ed852e2009-09-05 21:47:34 +00003618 argv[i]=DestroyString(argv[i]); \
3619 argv=(char **) RelinquishMagickMemory(argv); \
3620}
3621#define ThrowMogrifyException(asperity,tag,option) \
3622{ \
3623 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3624 option); \
3625 DestroyMogrify(); \
3626 return(MagickFalse); \
3627}
3628#define ThrowMogrifyInvalidArgumentException(option,argument) \
3629{ \
3630 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3631 "InvalidArgument","`%s': %s",argument,option); \
3632 DestroyMogrify(); \
3633 return(MagickFalse); \
3634}
3635
3636 char
3637 *format,
3638 *option,
3639 *path;
3640
3641 Image
3642 *image;
3643
3644 ImageStack
3645 image_stack[MaxImageStackDepth+1];
3646
cristy3ed852e2009-09-05 21:47:34 +00003647 MagickBooleanType
3648 global_colormap;
3649
3650 MagickBooleanType
3651 fire,
cristyebbcfea2011-02-25 02:43:54 +00003652 pend,
3653 respect_parenthesis;
cristy3ed852e2009-09-05 21:47:34 +00003654
3655 MagickStatusType
3656 status;
3657
cristyebbcfea2011-02-25 02:43:54 +00003658 register ssize_t
3659 i;
3660
3661 ssize_t
3662 j,
3663 k;
3664
cristy3ed852e2009-09-05 21:47:34 +00003665 /*
3666 Set defaults.
3667 */
3668 assert(image_info != (ImageInfo *) NULL);
3669 assert(image_info->signature == MagickSignature);
3670 if (image_info->debug != MagickFalse)
3671 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3672 assert(exception != (ExceptionInfo *) NULL);
3673 if (argc == 2)
3674 {
3675 option=argv[1];
3676 if ((LocaleCompare("version",option+1) == 0) ||
3677 (LocaleCompare("-version",option+1) == 0))
3678 {
cristyb51dff52011-05-19 16:55:47 +00003679 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00003680 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00003681 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3682 GetMagickCopyright());
3683 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3684 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00003685 return(MagickFalse);
3686 }
3687 }
3688 if (argc < 2)
cristy13e61a12010-02-04 20:19:00 +00003689 return(MogrifyUsage());
cristy3ed852e2009-09-05 21:47:34 +00003690 format=(char *) NULL;
3691 path=(char *) NULL;
3692 global_colormap=MagickFalse;
3693 k=0;
3694 j=1;
3695 NewImageStack();
3696 option=(char *) NULL;
3697 pend=MagickFalse;
cristyebbcfea2011-02-25 02:43:54 +00003698 respect_parenthesis=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003699 status=MagickTrue;
3700 /*
3701 Parse command line.
3702 */
3703 ReadCommandlLine(argc,&argv);
3704 status=ExpandFilenames(&argc,&argv);
3705 if (status == MagickFalse)
3706 ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3707 GetExceptionMessage(errno));
cristybb503372010-05-27 20:51:26 +00003708 for (i=1; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00003709 {
3710 option=argv[i];
3711 if (LocaleCompare(option,"(") == 0)
3712 {
3713 FireImageStack(MagickFalse,MagickTrue,pend);
3714 if (k == MaxImageStackDepth)
3715 ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3716 option);
3717 PushImageStack();
3718 continue;
3719 }
3720 if (LocaleCompare(option,")") == 0)
3721 {
3722 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3723 if (k == 0)
3724 ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3725 PopImageStack();
3726 continue;
3727 }
cristy042ee782011-04-22 18:48:30 +00003728 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003729 {
3730 char
3731 backup_filename[MaxTextExtent],
3732 *filename;
3733
3734 Image
3735 *images;
3736
3737 /*
3738 Option is a file name: begin by reading image from specified file.
3739 */
3740 FireImageStack(MagickFalse,MagickFalse,pend);
3741 filename=argv[i];
cristycee97112010-05-28 00:44:52 +00003742 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
cristy3ed852e2009-09-05 21:47:34 +00003743 filename=argv[++i];
3744 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3745 images=ReadImages(image_info,exception);
3746 status&=(images != (Image *) NULL) &&
3747 (exception->severity < ErrorException);
3748 if (images == (Image *) NULL)
3749 continue;
cristydaa76602010-06-30 13:05:11 +00003750 if (format != (char *) NULL)
3751 (void) CopyMagickString(images->filename,images->magick_filename,
3752 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003753 if (path != (char *) NULL)
3754 {
3755 GetPathComponent(option,TailPath,filename);
cristyb51dff52011-05-19 16:55:47 +00003756 (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
cristy3ed852e2009-09-05 21:47:34 +00003757 path,*DirectorySeparator,filename);
3758 }
3759 if (format != (char *) NULL)
cristydaa76602010-06-30 13:05:11 +00003760 AppendImageFormat(format,images->filename);
cristy3ed852e2009-09-05 21:47:34 +00003761 AppendImageStack(images);
3762 FinalizeImageSettings(image_info,image,MagickFalse);
3763 if (global_colormap != MagickFalse)
3764 {
3765 QuantizeInfo
3766 *quantize_info;
3767
3768 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003769 (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00003770 quantize_info=DestroyQuantizeInfo(quantize_info);
3771 }
3772 *backup_filename='\0';
3773 if ((LocaleCompare(image->filename,"-") != 0) &&
3774 (IsPathWritable(image->filename) != MagickFalse))
3775 {
cristybb503372010-05-27 20:51:26 +00003776 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003777 i;
3778
3779 /*
3780 Rename image file as backup.
3781 */
3782 (void) CopyMagickString(backup_filename,image->filename,
3783 MaxTextExtent);
3784 for (i=0; i < 6; i++)
3785 {
3786 (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3787 if (IsPathAccessible(backup_filename) == MagickFalse)
3788 break;
3789 }
3790 if ((IsPathAccessible(backup_filename) != MagickFalse) ||
cristy320684d2011-09-23 14:55:47 +00003791 (rename_utf8(image->filename,backup_filename) != 0))
cristy3ed852e2009-09-05 21:47:34 +00003792 *backup_filename='\0';
3793 }
3794 /*
3795 Write transmogrified image to disk.
3796 */
3797 image_info->synchronize=MagickTrue;
3798 status&=WriteImages(image_info,image,image->filename,exception);
3799 if ((status == MagickFalse) && (*backup_filename != '\0'))
cristy18c6c272011-09-23 14:40:37 +00003800 (void) remove_utf8(backup_filename);
cristy3ed852e2009-09-05 21:47:34 +00003801 RemoveAllImageStack();
3802 continue;
3803 }
3804 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3805 switch (*(option+1))
3806 {
3807 case 'a':
3808 {
3809 if (LocaleCompare("adaptive-blur",option+1) == 0)
3810 {
3811 i++;
cristybb503372010-05-27 20:51:26 +00003812 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003813 ThrowMogrifyException(OptionError,"MissingArgument",option);
3814 if (IsGeometry(argv[i]) == MagickFalse)
3815 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3816 break;
3817 }
3818 if (LocaleCompare("adaptive-resize",option+1) == 0)
3819 {
3820 i++;
cristybb503372010-05-27 20:51:26 +00003821 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003822 ThrowMogrifyException(OptionError,"MissingArgument",option);
3823 if (IsGeometry(argv[i]) == MagickFalse)
3824 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3825 break;
3826 }
3827 if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3828 {
3829 i++;
cristybb503372010-05-27 20:51:26 +00003830 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003831 ThrowMogrifyException(OptionError,"MissingArgument",option);
3832 if (IsGeometry(argv[i]) == MagickFalse)
3833 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3834 break;
3835 }
3836 if (LocaleCompare("affine",option+1) == 0)
3837 {
3838 if (*option == '+')
3839 break;
3840 i++;
cristybb503372010-05-27 20:51:26 +00003841 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003842 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy3ed852e2009-09-05 21:47:34 +00003843 break;
3844 }
3845 if (LocaleCompare("alpha",option+1) == 0)
3846 {
cristybb503372010-05-27 20:51:26 +00003847 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003848 type;
3849
3850 if (*option == '+')
3851 break;
3852 i++;
cristybb503372010-05-27 20:51:26 +00003853 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003854 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00003855 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00003856 if (type < 0)
3857 ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3858 argv[i]);
3859 break;
3860 }
3861 if (LocaleCompare("annotate",option+1) == 0)
3862 {
3863 if (*option == '+')
3864 break;
3865 i++;
cristybb503372010-05-27 20:51:26 +00003866 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003867 ThrowMogrifyException(OptionError,"MissingArgument",option);
3868 if (IsGeometry(argv[i]) == MagickFalse)
3869 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristybb503372010-05-27 20:51:26 +00003870 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003871 ThrowMogrifyException(OptionError,"MissingArgument",option);
3872 i++;
3873 break;
3874 }
3875 if (LocaleCompare("antialias",option+1) == 0)
3876 break;
3877 if (LocaleCompare("append",option+1) == 0)
3878 break;
3879 if (LocaleCompare("attenuate",option+1) == 0)
3880 {
3881 if (*option == '+')
3882 break;
3883 i++;
cristybb503372010-05-27 20:51:26 +00003884 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003885 ThrowMogrifyException(OptionError,"MissingArgument",option);
3886 if (IsGeometry(argv[i]) == MagickFalse)
3887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3888 break;
3889 }
3890 if (LocaleCompare("authenticate",option+1) == 0)
3891 {
3892 if (*option == '+')
3893 break;
3894 i++;
cristybb503372010-05-27 20:51:26 +00003895 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003896 ThrowMogrifyException(OptionError,"MissingArgument",option);
3897 break;
3898 }
3899 if (LocaleCompare("auto-gamma",option+1) == 0)
3900 break;
3901 if (LocaleCompare("auto-level",option+1) == 0)
3902 break;
3903 if (LocaleCompare("auto-orient",option+1) == 0)
3904 break;
3905 if (LocaleCompare("average",option+1) == 0)
3906 break;
3907 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3908 }
3909 case 'b':
3910 {
3911 if (LocaleCompare("background",option+1) == 0)
3912 {
3913 if (*option == '+')
3914 break;
3915 i++;
cristybb503372010-05-27 20:51:26 +00003916 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003917 ThrowMogrifyException(OptionError,"MissingArgument",option);
3918 break;
3919 }
3920 if (LocaleCompare("bias",option+1) == 0)
3921 {
3922 if (*option == '+')
3923 break;
3924 i++;
cristybb503372010-05-27 20:51:26 +00003925 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00003926 ThrowMogrifyException(OptionError,"MissingArgument",option);
3927 if (IsGeometry(argv[i]) == MagickFalse)
3928 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3929 break;
3930 }
3931 if (LocaleCompare("black-point-compensation",option+1) == 0)
3932 break;
3933 if (LocaleCompare("black-threshold",option+1) == 0)
3934 {
3935 if (*option == '+')
3936 break;
3937 i++;
cristybb503372010-05-27 20:51:26 +00003938 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003939 ThrowMogrifyException(OptionError,"MissingArgument",option);
3940 if (IsGeometry(argv[i]) == MagickFalse)
3941 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3942 break;
3943 }
3944 if (LocaleCompare("blue-primary",option+1) == 0)
3945 {
3946 if (*option == '+')
3947 break;
3948 i++;
cristybb503372010-05-27 20:51:26 +00003949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003950 ThrowMogrifyException(OptionError,"MissingArgument",option);
3951 if (IsGeometry(argv[i]) == MagickFalse)
3952 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3953 break;
3954 }
3955 if (LocaleCompare("blue-shift",option+1) == 0)
3956 {
3957 i++;
cristybb503372010-05-27 20:51:26 +00003958 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003959 ThrowMogrifyException(OptionError,"MissingArgument",option);
3960 if (IsGeometry(argv[i]) == MagickFalse)
3961 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3962 break;
3963 }
3964 if (LocaleCompare("blur",option+1) == 0)
3965 {
3966 i++;
cristybb503372010-05-27 20:51:26 +00003967 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003968 ThrowMogrifyException(OptionError,"MissingArgument",option);
3969 if (IsGeometry(argv[i]) == MagickFalse)
3970 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3971 break;
3972 }
3973 if (LocaleCompare("border",option+1) == 0)
3974 {
3975 if (*option == '+')
3976 break;
3977 i++;
cristybb503372010-05-27 20:51:26 +00003978 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003979 ThrowMogrifyException(OptionError,"MissingArgument",option);
3980 if (IsGeometry(argv[i]) == MagickFalse)
3981 ThrowMogrifyInvalidArgumentException(option,argv[i]);
3982 break;
3983 }
3984 if (LocaleCompare("bordercolor",option+1) == 0)
3985 {
3986 if (*option == '+')
3987 break;
3988 i++;
cristybb503372010-05-27 20:51:26 +00003989 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003990 ThrowMogrifyException(OptionError,"MissingArgument",option);
3991 break;
3992 }
3993 if (LocaleCompare("box",option+1) == 0)
3994 {
3995 if (*option == '+')
3996 break;
3997 i++;
cristybb503372010-05-27 20:51:26 +00003998 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00003999 ThrowMogrifyException(OptionError,"MissingArgument",option);
4000 break;
4001 }
cristya28d6b82010-01-11 20:03:47 +00004002 if (LocaleCompare("brightness-contrast",option+1) == 0)
4003 {
4004 i++;
cristybb503372010-05-27 20:51:26 +00004005 if (i == (ssize_t) argc)
cristya28d6b82010-01-11 20:03:47 +00004006 ThrowMogrifyException(OptionError,"MissingArgument",option);
4007 if (IsGeometry(argv[i]) == MagickFalse)
4008 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4009 break;
4010 }
cristy3ed852e2009-09-05 21:47:34 +00004011 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4012 }
4013 case 'c':
4014 {
4015 if (LocaleCompare("cache",option+1) == 0)
4016 {
4017 if (*option == '+')
4018 break;
4019 i++;
cristybb503372010-05-27 20:51:26 +00004020 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004021 ThrowMogrifyException(OptionError,"MissingArgument",option);
4022 if (IsGeometry(argv[i]) == MagickFalse)
4023 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4024 break;
4025 }
4026 if (LocaleCompare("caption",option+1) == 0)
4027 {
4028 if (*option == '+')
4029 break;
4030 i++;
cristybb503372010-05-27 20:51:26 +00004031 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004032 ThrowMogrifyException(OptionError,"MissingArgument",option);
4033 break;
4034 }
4035 if (LocaleCompare("channel",option+1) == 0)
4036 {
cristybb503372010-05-27 20:51:26 +00004037 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004038 channel;
4039
4040 if (*option == '+')
4041 break;
4042 i++;
cristybb503372010-05-27 20:51:26 +00004043 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004044 ThrowMogrifyException(OptionError,"MissingArgument",option);
4045 channel=ParseChannelOption(argv[i]);
4046 if (channel < 0)
4047 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4048 argv[i]);
4049 break;
4050 }
cristy87c02f42012-02-24 00:19:10 +00004051 if (LocaleCompare("channel-extract",option+1) == 0)
4052 {
4053 ssize_t
4054 channel;
4055
4056 if (*option == '+')
4057 break;
4058 i++;
4059 if (i == (ssize_t) (argc-1))
4060 ThrowMogrifyException(OptionError,"MissingArgument",option);
4061 channel=ParseChannelOption(argv[i]);
4062 if (channel < 0)
4063 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4064 argv[i]);
4065 break;
4066 }
4067 if (LocaleCompare("channel-inject",option+1) == 0)
4068 {
4069 ssize_t
4070 channel;
4071
4072 if (*option == '+')
4073 break;
4074 i++;
4075 if (i == (ssize_t) (argc-1))
4076 ThrowMogrifyException(OptionError,"MissingArgument",option);
4077 channel=ParseChannelOption(argv[i]);
4078 if (channel < 0)
4079 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4080 argv[i]);
4081 break;
4082 }
4083 if (LocaleCompare("channel-swap",option+1) == 0)
4084 {
4085 ssize_t
4086 channel;
4087
4088 if (*option == '+')
4089 break;
4090 i++;
4091 if (i == (ssize_t) (argc-1))
4092 ThrowMogrifyException(OptionError,"MissingArgument",option);
4093 channel=ParseChannelOption(argv[i]);
4094 if (channel < 0)
4095 ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4096 argv[i]);
4097 break;
4098 }
cristy3ed852e2009-09-05 21:47:34 +00004099 if (LocaleCompare("cdl",option+1) == 0)
4100 {
4101 if (*option == '+')
4102 break;
4103 i++;
cristybb503372010-05-27 20:51:26 +00004104 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004105 ThrowMogrifyException(OptionError,"MissingArgument",option);
4106 break;
4107 }
4108 if (LocaleCompare("charcoal",option+1) == 0)
4109 {
4110 if (*option == '+')
4111 break;
4112 i++;
cristybb503372010-05-27 20:51:26 +00004113 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004114 ThrowMogrifyException(OptionError,"MissingArgument",option);
4115 if (IsGeometry(argv[i]) == MagickFalse)
4116 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4117 break;
4118 }
4119 if (LocaleCompare("chop",option+1) == 0)
4120 {
4121 if (*option == '+')
4122 break;
4123 i++;
cristybb503372010-05-27 20:51:26 +00004124 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004125 ThrowMogrifyException(OptionError,"MissingArgument",option);
4126 if (IsGeometry(argv[i]) == MagickFalse)
4127 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4128 break;
4129 }
cristy1eb45dd2009-09-25 16:38:06 +00004130 if (LocaleCompare("clamp",option+1) == 0)
4131 break;
4132 if (LocaleCompare("clip",option+1) == 0)
4133 break;
cristy3ed852e2009-09-05 21:47:34 +00004134 if (LocaleCompare("clip-mask",option+1) == 0)
4135 {
4136 if (*option == '+')
4137 break;
4138 i++;
cristybb503372010-05-27 20:51:26 +00004139 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004140 ThrowMogrifyException(OptionError,"MissingArgument",option);
4141 break;
4142 }
4143 if (LocaleCompare("clut",option+1) == 0)
4144 break;
4145 if (LocaleCompare("coalesce",option+1) == 0)
4146 break;
4147 if (LocaleCompare("colorize",option+1) == 0)
4148 {
4149 if (*option == '+')
4150 break;
4151 i++;
cristybb503372010-05-27 20:51:26 +00004152 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004153 ThrowMogrifyException(OptionError,"MissingArgument",option);
4154 if (IsGeometry(argv[i]) == MagickFalse)
4155 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4156 break;
4157 }
cristye6365592010-04-02 17:31:23 +00004158 if (LocaleCompare("color-matrix",option+1) == 0)
4159 {
cristyb6bd4ad2010-08-08 01:12:27 +00004160 KernelInfo
4161 *kernel_info;
4162
cristye6365592010-04-02 17:31:23 +00004163 if (*option == '+')
4164 break;
4165 i++;
cristybb503372010-05-27 20:51:26 +00004166 if (i == (ssize_t) (argc-1))
cristye6365592010-04-02 17:31:23 +00004167 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004168 kernel_info=AcquireKernelInfo(argv[i]);
4169 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004170 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004171 kernel_info=DestroyKernelInfo(kernel_info);
cristye6365592010-04-02 17:31:23 +00004172 break;
4173 }
cristy3ed852e2009-09-05 21:47:34 +00004174 if (LocaleCompare("colors",option+1) == 0)
4175 {
4176 if (*option == '+')
4177 break;
4178 i++;
cristybb503372010-05-27 20:51:26 +00004179 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004180 ThrowMogrifyException(OptionError,"MissingArgument",option);
4181 if (IsGeometry(argv[i]) == MagickFalse)
4182 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4183 break;
4184 }
4185 if (LocaleCompare("colorspace",option+1) == 0)
4186 {
cristybb503372010-05-27 20:51:26 +00004187 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004188 colorspace;
4189
4190 if (*option == '+')
4191 break;
4192 i++;
cristybb503372010-05-27 20:51:26 +00004193 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004194 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004195 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004196 argv[i]);
4197 if (colorspace < 0)
4198 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4199 argv[i]);
4200 break;
4201 }
4202 if (LocaleCompare("combine",option+1) == 0)
4203 break;
4204 if (LocaleCompare("comment",option+1) == 0)
4205 {
4206 if (*option == '+')
4207 break;
4208 i++;
cristybb503372010-05-27 20:51:26 +00004209 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004210 ThrowMogrifyException(OptionError,"MissingArgument",option);
4211 break;
4212 }
4213 if (LocaleCompare("composite",option+1) == 0)
4214 break;
4215 if (LocaleCompare("compress",option+1) == 0)
4216 {
cristybb503372010-05-27 20:51:26 +00004217 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004218 compress;
4219
4220 if (*option == '+')
4221 break;
4222 i++;
cristybb503372010-05-27 20:51:26 +00004223 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004224 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004225 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004226 argv[i]);
4227 if (compress < 0)
4228 ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4229 argv[i]);
4230 break;
4231 }
cristy22879752009-10-25 23:55:40 +00004232 if (LocaleCompare("concurrent",option+1) == 0)
4233 break;
cristy3ed852e2009-09-05 21:47:34 +00004234 if (LocaleCompare("contrast",option+1) == 0)
4235 break;
4236 if (LocaleCompare("contrast-stretch",option+1) == 0)
4237 {
4238 i++;
cristybb503372010-05-27 20:51:26 +00004239 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004240 ThrowMogrifyException(OptionError,"MissingArgument",option);
4241 if (IsGeometry(argv[i]) == MagickFalse)
4242 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4243 break;
4244 }
4245 if (LocaleCompare("convolve",option+1) == 0)
4246 {
cristyb6bd4ad2010-08-08 01:12:27 +00004247 KernelInfo
4248 *kernel_info;
4249
cristy3ed852e2009-09-05 21:47:34 +00004250 if (*option == '+')
4251 break;
4252 i++;
cristybb503372010-05-27 20:51:26 +00004253 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004254 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00004255 kernel_info=AcquireKernelInfo(argv[i]);
4256 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00004257 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00004258 kernel_info=DestroyKernelInfo(kernel_info);
cristy3ed852e2009-09-05 21:47:34 +00004259 break;
4260 }
4261 if (LocaleCompare("crop",option+1) == 0)
4262 {
4263 if (*option == '+')
4264 break;
4265 i++;
cristybb503372010-05-27 20:51:26 +00004266 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004267 ThrowMogrifyException(OptionError,"MissingArgument",option);
4268 if (IsGeometry(argv[i]) == MagickFalse)
4269 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4270 break;
4271 }
4272 if (LocaleCompare("cycle",option+1) == 0)
4273 {
4274 if (*option == '+')
4275 break;
4276 i++;
cristybb503372010-05-27 20:51:26 +00004277 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004278 ThrowMogrifyException(OptionError,"MissingArgument",option);
4279 if (IsGeometry(argv[i]) == MagickFalse)
4280 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4281 break;
4282 }
4283 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4284 }
4285 case 'd':
4286 {
4287 if (LocaleCompare("decipher",option+1) == 0)
4288 {
4289 if (*option == '+')
4290 break;
4291 i++;
cristybb503372010-05-27 20:51:26 +00004292 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004293 ThrowMogrifyException(OptionError,"MissingArgument",option);
4294 break;
4295 }
4296 if (LocaleCompare("deconstruct",option+1) == 0)
4297 break;
4298 if (LocaleCompare("debug",option+1) == 0)
4299 {
cristybb503372010-05-27 20:51:26 +00004300 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004301 event;
4302
4303 if (*option == '+')
4304 break;
4305 i++;
cristybb503372010-05-27 20:51:26 +00004306 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004307 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004308 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004309 if (event < 0)
4310 ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4311 argv[i]);
4312 (void) SetLogEventMask(argv[i]);
4313 break;
4314 }
4315 if (LocaleCompare("define",option+1) == 0)
4316 {
4317 i++;
cristybb503372010-05-27 20:51:26 +00004318 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004319 ThrowMogrifyException(OptionError,"MissingArgument",option);
4320 if (*option == '+')
4321 {
4322 const char
4323 *define;
4324
4325 define=GetImageOption(image_info,argv[i]);
4326 if (define == (const char *) NULL)
4327 ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4328 break;
4329 }
4330 break;
4331 }
4332 if (LocaleCompare("delay",option+1) == 0)
4333 {
4334 if (*option == '+')
4335 break;
4336 i++;
cristybb503372010-05-27 20:51:26 +00004337 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004338 ThrowMogrifyException(OptionError,"MissingArgument",option);
4339 if (IsGeometry(argv[i]) == MagickFalse)
4340 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4341 break;
4342 }
cristyecb10ff2011-03-22 13:14:03 +00004343 if (LocaleCompare("delete",option+1) == 0)
4344 {
4345 if (*option == '+')
4346 break;
4347 i++;
4348 if (i == (ssize_t) (argc-1))
4349 ThrowMogrifyException(OptionError,"MissingArgument",option);
4350 if (IsGeometry(argv[i]) == MagickFalse)
4351 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4352 break;
4353 }
cristy3ed852e2009-09-05 21:47:34 +00004354 if (LocaleCompare("density",option+1) == 0)
4355 {
4356 if (*option == '+')
4357 break;
4358 i++;
cristybb503372010-05-27 20:51:26 +00004359 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004360 ThrowMogrifyException(OptionError,"MissingArgument",option);
4361 if (IsGeometry(argv[i]) == MagickFalse)
4362 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4363 break;
4364 }
4365 if (LocaleCompare("depth",option+1) == 0)
4366 {
4367 if (*option == '+')
4368 break;
4369 i++;
cristybb503372010-05-27 20:51:26 +00004370 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004371 ThrowMogrifyException(OptionError,"MissingArgument",option);
4372 if (IsGeometry(argv[i]) == MagickFalse)
4373 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4374 break;
4375 }
4376 if (LocaleCompare("deskew",option+1) == 0)
4377 {
4378 if (*option == '+')
4379 break;
4380 i++;
cristybb503372010-05-27 20:51:26 +00004381 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004382 ThrowMogrifyException(OptionError,"MissingArgument",option);
4383 if (IsGeometry(argv[i]) == MagickFalse)
4384 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4385 break;
4386 }
4387 if (LocaleCompare("despeckle",option+1) == 0)
4388 break;
4389 if (LocaleCompare("dft",option+1) == 0)
4390 break;
cristyc9b12952010-03-28 01:12:28 +00004391 if (LocaleCompare("direction",option+1) == 0)
4392 {
cristybb503372010-05-27 20:51:26 +00004393 ssize_t
cristyc9b12952010-03-28 01:12:28 +00004394 direction;
4395
4396 if (*option == '+')
4397 break;
4398 i++;
cristybb503372010-05-27 20:51:26 +00004399 if (i == (ssize_t) argc)
cristyc9b12952010-03-28 01:12:28 +00004400 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004401 direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
cristyc9b12952010-03-28 01:12:28 +00004402 argv[i]);
4403 if (direction < 0)
4404 ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4405 argv[i]);
4406 break;
4407 }
cristy3ed852e2009-09-05 21:47:34 +00004408 if (LocaleCompare("display",option+1) == 0)
4409 {
4410 if (*option == '+')
4411 break;
4412 i++;
cristybb503372010-05-27 20:51:26 +00004413 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004414 ThrowMogrifyException(OptionError,"MissingArgument",option);
4415 break;
4416 }
4417 if (LocaleCompare("dispose",option+1) == 0)
4418 {
cristybb503372010-05-27 20:51:26 +00004419 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004420 dispose;
4421
4422 if (*option == '+')
4423 break;
4424 i++;
cristybb503372010-05-27 20:51:26 +00004425 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004426 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004427 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004428 if (dispose < 0)
4429 ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4430 argv[i]);
4431 break;
4432 }
4433 if (LocaleCompare("distort",option+1) == 0)
4434 {
cristybb503372010-05-27 20:51:26 +00004435 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004436 op;
4437
4438 i++;
cristybb503372010-05-27 20:51:26 +00004439 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004440 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004441 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004442 if (op < 0)
4443 ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4444 argv[i]);
4445 i++;
cristybb503372010-05-27 20:51:26 +00004446 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004447 ThrowMogrifyException(OptionError,"MissingArgument",option);
4448 break;
4449 }
4450 if (LocaleCompare("dither",option+1) == 0)
4451 {
cristybb503372010-05-27 20:51:26 +00004452 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004453 method;
4454
4455 if (*option == '+')
4456 break;
4457 i++;
cristybb503372010-05-27 20:51:26 +00004458 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004459 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004460 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004461 if (method < 0)
4462 ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4463 argv[i]);
4464 break;
4465 }
4466 if (LocaleCompare("draw",option+1) == 0)
4467 {
4468 if (*option == '+')
4469 break;
4470 i++;
cristybb503372010-05-27 20:51:26 +00004471 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004472 ThrowMogrifyException(OptionError,"MissingArgument",option);
4473 break;
4474 }
cristyecb10ff2011-03-22 13:14:03 +00004475 if (LocaleCompare("duplicate",option+1) == 0)
4476 {
4477 if (*option == '+')
4478 break;
4479 i++;
4480 if (i == (ssize_t) (argc-1))
4481 ThrowMogrifyException(OptionError,"MissingArgument",option);
4482 if (IsGeometry(argv[i]) == MagickFalse)
4483 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4484 break;
4485 }
cristy22879752009-10-25 23:55:40 +00004486 if (LocaleCompare("duration",option+1) == 0)
4487 {
4488 if (*option == '+')
4489 break;
4490 i++;
cristybb503372010-05-27 20:51:26 +00004491 if (i == (ssize_t) (argc-1))
cristy22879752009-10-25 23:55:40 +00004492 ThrowMogrifyException(OptionError,"MissingArgument",option);
4493 if (IsGeometry(argv[i]) == MagickFalse)
4494 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4495 break;
4496 }
cristy3ed852e2009-09-05 21:47:34 +00004497 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4498 }
4499 case 'e':
4500 {
4501 if (LocaleCompare("edge",option+1) == 0)
4502 {
4503 if (*option == '+')
4504 break;
4505 i++;
cristybb503372010-05-27 20:51:26 +00004506 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004507 ThrowMogrifyException(OptionError,"MissingArgument",option);
4508 if (IsGeometry(argv[i]) == MagickFalse)
4509 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4510 break;
4511 }
4512 if (LocaleCompare("emboss",option+1) == 0)
4513 {
4514 if (*option == '+')
4515 break;
4516 i++;
cristybb503372010-05-27 20:51:26 +00004517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004518 ThrowMogrifyException(OptionError,"MissingArgument",option);
4519 if (IsGeometry(argv[i]) == MagickFalse)
4520 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4521 break;
4522 }
4523 if (LocaleCompare("encipher",option+1) == 0)
4524 {
4525 if (*option == '+')
4526 break;
4527 i++;
cristybb503372010-05-27 20:51:26 +00004528 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004529 ThrowMogrifyException(OptionError,"MissingArgument",option);
4530 break;
4531 }
4532 if (LocaleCompare("encoding",option+1) == 0)
4533 {
4534 if (*option == '+')
4535 break;
4536 i++;
cristybb503372010-05-27 20:51:26 +00004537 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004538 ThrowMogrifyException(OptionError,"MissingArgument",option);
4539 break;
4540 }
4541 if (LocaleCompare("endian",option+1) == 0)
4542 {
cristybb503372010-05-27 20:51:26 +00004543 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004544 endian;
4545
4546 if (*option == '+')
4547 break;
4548 i++;
cristybb503372010-05-27 20:51:26 +00004549 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004550 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004551 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004552 if (endian < 0)
4553 ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4554 argv[i]);
4555 break;
4556 }
4557 if (LocaleCompare("enhance",option+1) == 0)
4558 break;
4559 if (LocaleCompare("equalize",option+1) == 0)
4560 break;
4561 if (LocaleCompare("evaluate",option+1) == 0)
4562 {
cristybb503372010-05-27 20:51:26 +00004563 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004564 op;
4565
4566 if (*option == '+')
4567 break;
4568 i++;
cristybb503372010-05-27 20:51:26 +00004569 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004570 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004571 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004572 if (op < 0)
4573 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4574 argv[i]);
4575 i++;
cristybb503372010-05-27 20:51:26 +00004576 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004577 ThrowMogrifyException(OptionError,"MissingArgument",option);
4578 if (IsGeometry(argv[i]) == MagickFalse)
4579 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4580 break;
4581 }
cristyd18ae7c2010-03-07 17:39:52 +00004582 if (LocaleCompare("evaluate-sequence",option+1) == 0)
4583 {
cristybb503372010-05-27 20:51:26 +00004584 ssize_t
cristyd18ae7c2010-03-07 17:39:52 +00004585 op;
4586
4587 if (*option == '+')
4588 break;
4589 i++;
cristybb503372010-05-27 20:51:26 +00004590 if (i == (ssize_t) argc)
cristyd18ae7c2010-03-07 17:39:52 +00004591 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004592 op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
cristyd18ae7c2010-03-07 17:39:52 +00004593 if (op < 0)
4594 ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4595 argv[i]);
4596 break;
4597 }
cristy3ed852e2009-09-05 21:47:34 +00004598 if (LocaleCompare("extent",option+1) == 0)
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);
4605 if (IsGeometry(argv[i]) == MagickFalse)
4606 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4607 break;
4608 }
4609 if (LocaleCompare("extract",option+1) == 0)
4610 {
4611 if (*option == '+')
4612 break;
4613 i++;
cristybb503372010-05-27 20:51:26 +00004614 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004615 ThrowMogrifyException(OptionError,"MissingArgument",option);
4616 if (IsGeometry(argv[i]) == MagickFalse)
4617 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4618 break;
4619 }
4620 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4621 }
4622 case 'f':
4623 {
4624 if (LocaleCompare("family",option+1) == 0)
4625 {
4626 if (*option == '+')
4627 break;
4628 i++;
cristybb503372010-05-27 20:51:26 +00004629 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004630 ThrowMogrifyException(OptionError,"MissingArgument",option);
4631 break;
4632 }
4633 if (LocaleCompare("fill",option+1) == 0)
4634 {
4635 if (*option == '+')
4636 break;
4637 i++;
cristybb503372010-05-27 20:51:26 +00004638 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004639 ThrowMogrifyException(OptionError,"MissingArgument",option);
4640 break;
4641 }
4642 if (LocaleCompare("filter",option+1) == 0)
4643 {
cristybb503372010-05-27 20:51:26 +00004644 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004645 filter;
4646
4647 if (*option == '+')
4648 break;
4649 i++;
cristybb503372010-05-27 20:51:26 +00004650 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004651 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004652 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004653 if (filter < 0)
4654 ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4655 argv[i]);
4656 break;
4657 }
4658 if (LocaleCompare("flatten",option+1) == 0)
4659 break;
4660 if (LocaleCompare("flip",option+1) == 0)
4661 break;
4662 if (LocaleCompare("flop",option+1) == 0)
4663 break;
4664 if (LocaleCompare("floodfill",option+1) == 0)
4665 {
4666 if (*option == '+')
4667 break;
4668 i++;
cristybb503372010-05-27 20:51:26 +00004669 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004670 ThrowMogrifyException(OptionError,"MissingArgument",option);
4671 if (IsGeometry(argv[i]) == MagickFalse)
4672 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4673 i++;
cristybb503372010-05-27 20:51:26 +00004674 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004675 ThrowMogrifyException(OptionError,"MissingArgument",option);
4676 break;
4677 }
4678 if (LocaleCompare("font",option+1) == 0)
4679 {
4680 if (*option == '+')
4681 break;
4682 i++;
cristybb503372010-05-27 20:51:26 +00004683 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004684 ThrowMogrifyException(OptionError,"MissingArgument",option);
4685 break;
4686 }
4687 if (LocaleCompare("format",option+1) == 0)
4688 {
4689 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4690 (void) CloneString(&format,(char *) NULL);
4691 if (*option == '+')
4692 break;
4693 i++;
cristybb503372010-05-27 20:51:26 +00004694 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004695 ThrowMogrifyException(OptionError,"MissingArgument",option);
4696 (void) CloneString(&format,argv[i]);
4697 (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4698 (void) ConcatenateMagickString(image_info->filename,":",
4699 MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00004700 (void) SetImageInfo(image_info,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004701 if (*image_info->magick == '\0')
4702 ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4703 format);
4704 break;
4705 }
4706 if (LocaleCompare("frame",option+1) == 0)
4707 {
4708 if (*option == '+')
4709 break;
4710 i++;
cristybb503372010-05-27 20:51:26 +00004711 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004712 ThrowMogrifyException(OptionError,"MissingArgument",option);
4713 if (IsGeometry(argv[i]) == MagickFalse)
4714 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4715 break;
4716 }
4717 if (LocaleCompare("function",option+1) == 0)
4718 {
cristybb503372010-05-27 20:51:26 +00004719 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004720 op;
4721
4722 if (*option == '+')
4723 break;
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);
cristy042ee782011-04-22 18:48:30 +00004727 op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004728 if (op < 0)
4729 ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4730 i++;
cristybb503372010-05-27 20:51:26 +00004731 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004732 ThrowMogrifyException(OptionError,"MissingArgument",option);
4733 break;
4734 }
4735 if (LocaleCompare("fuzz",option+1) == 0)
4736 {
4737 if (*option == '+')
4738 break;
4739 i++;
cristybb503372010-05-27 20:51:26 +00004740 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004741 ThrowMogrifyException(OptionError,"MissingArgument",option);
4742 if (IsGeometry(argv[i]) == MagickFalse)
4743 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4744 break;
4745 }
4746 if (LocaleCompare("fx",option+1) == 0)
4747 {
4748 if (*option == '+')
4749 break;
4750 i++;
cristybb503372010-05-27 20:51:26 +00004751 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004752 ThrowMogrifyException(OptionError,"MissingArgument",option);
4753 break;
4754 }
4755 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4756 }
4757 case 'g':
4758 {
4759 if (LocaleCompare("gamma",option+1) == 0)
4760 {
4761 i++;
cristybb503372010-05-27 20:51:26 +00004762 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004763 ThrowMogrifyException(OptionError,"MissingArgument",option);
4764 if (IsGeometry(argv[i]) == MagickFalse)
4765 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4766 break;
4767 }
4768 if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4769 (LocaleCompare("gaussian",option+1) == 0))
4770 {
4771 i++;
cristybb503372010-05-27 20:51:26 +00004772 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004773 ThrowMogrifyException(OptionError,"MissingArgument",option);
4774 if (IsGeometry(argv[i]) == MagickFalse)
4775 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4776 break;
4777 }
4778 if (LocaleCompare("geometry",option+1) == 0)
4779 {
4780 if (*option == '+')
4781 break;
4782 i++;
cristybb503372010-05-27 20:51:26 +00004783 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004784 ThrowMogrifyException(OptionError,"MissingArgument",option);
4785 if (IsGeometry(argv[i]) == MagickFalse)
4786 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4787 break;
4788 }
4789 if (LocaleCompare("gravity",option+1) == 0)
4790 {
cristybb503372010-05-27 20:51:26 +00004791 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004792 gravity;
4793
4794 if (*option == '+')
4795 break;
4796 i++;
cristybb503372010-05-27 20:51:26 +00004797 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004798 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004799 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004800 if (gravity < 0)
4801 ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4802 argv[i]);
4803 break;
4804 }
4805 if (LocaleCompare("green-primary",option+1) == 0)
4806 {
4807 if (*option == '+')
4808 break;
4809 i++;
cristybb503372010-05-27 20:51:26 +00004810 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004811 ThrowMogrifyException(OptionError,"MissingArgument",option);
4812 if (IsGeometry(argv[i]) == MagickFalse)
4813 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4814 break;
4815 }
4816 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4817 }
4818 case 'h':
4819 {
4820 if (LocaleCompare("hald-clut",option+1) == 0)
4821 break;
4822 if ((LocaleCompare("help",option+1) == 0) ||
4823 (LocaleCompare("-help",option+1) == 0))
4824 return(MogrifyUsage());
4825 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4826 }
4827 case 'i':
4828 {
4829 if (LocaleCompare("identify",option+1) == 0)
4830 break;
4831 if (LocaleCompare("idft",option+1) == 0)
4832 break;
4833 if (LocaleCompare("implode",option+1) == 0)
4834 {
4835 if (*option == '+')
4836 break;
4837 i++;
cristybb503372010-05-27 20:51:26 +00004838 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004839 ThrowMogrifyException(OptionError,"MissingArgument",option);
4840 if (IsGeometry(argv[i]) == MagickFalse)
4841 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4842 break;
4843 }
4844 if (LocaleCompare("intent",option+1) == 0)
4845 {
cristybb503372010-05-27 20:51:26 +00004846 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004847 intent;
4848
4849 if (*option == '+')
4850 break;
4851 i++;
cristybb503372010-05-27 20:51:26 +00004852 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004853 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004854 intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004855 if (intent < 0)
4856 ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4857 argv[i]);
4858 break;
4859 }
4860 if (LocaleCompare("interlace",option+1) == 0)
4861 {
cristybb503372010-05-27 20:51:26 +00004862 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004863 interlace;
4864
4865 if (*option == '+')
4866 break;
4867 i++;
cristybb503372010-05-27 20:51:26 +00004868 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004869 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004870 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004871 argv[i]);
4872 if (interlace < 0)
4873 ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4874 argv[i]);
4875 break;
4876 }
cristyb32b90a2009-09-07 21:45:48 +00004877 if (LocaleCompare("interline-spacing",option+1) == 0)
4878 {
4879 if (*option == '+')
4880 break;
4881 i++;
cristybb503372010-05-27 20:51:26 +00004882 if (i == (ssize_t) (argc-1))
cristyb32b90a2009-09-07 21:45:48 +00004883 ThrowMogrifyException(OptionError,"MissingArgument",option);
4884 if (IsGeometry(argv[i]) == MagickFalse)
4885 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4886 break;
4887 }
cristy3ed852e2009-09-05 21:47:34 +00004888 if (LocaleCompare("interpolate",option+1) == 0)
4889 {
cristybb503372010-05-27 20:51:26 +00004890 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004891 interpolate;
4892
4893 if (*option == '+')
4894 break;
4895 i++;
cristybb503372010-05-27 20:51:26 +00004896 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004897 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004898 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00004899 argv[i]);
4900 if (interpolate < 0)
4901 ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4902 argv[i]);
4903 break;
4904 }
4905 if (LocaleCompare("interword-spacing",option+1) == 0)
4906 {
4907 if (*option == '+')
4908 break;
4909 i++;
cristybb503372010-05-27 20:51:26 +00004910 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004911 ThrowMogrifyException(OptionError,"MissingArgument",option);
4912 if (IsGeometry(argv[i]) == MagickFalse)
4913 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4914 break;
4915 }
4916 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4917 }
4918 case 'k':
4919 {
4920 if (LocaleCompare("kerning",option+1) == 0)
4921 {
4922 if (*option == '+')
4923 break;
4924 i++;
cristybb503372010-05-27 20:51:26 +00004925 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004926 ThrowMogrifyException(OptionError,"MissingArgument",option);
4927 if (IsGeometry(argv[i]) == MagickFalse)
4928 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4929 break;
4930 }
4931 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4932 }
4933 case 'l':
4934 {
4935 if (LocaleCompare("label",option+1) == 0)
4936 {
4937 if (*option == '+')
4938 break;
4939 i++;
cristybb503372010-05-27 20:51:26 +00004940 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004941 ThrowMogrifyException(OptionError,"MissingArgument",option);
4942 break;
4943 }
4944 if (LocaleCompare("lat",option+1) == 0)
4945 {
4946 if (*option == '+')
4947 break;
4948 i++;
cristybb503372010-05-27 20:51:26 +00004949 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004950 ThrowMogrifyException(OptionError,"MissingArgument",option);
4951 if (IsGeometry(argv[i]) == MagickFalse)
4952 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4953 }
4954 if (LocaleCompare("layers",option+1) == 0)
4955 {
cristybb503372010-05-27 20:51:26 +00004956 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004957 type;
4958
4959 if (*option == '+')
4960 break;
4961 i++;
cristybb503372010-05-27 20:51:26 +00004962 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00004963 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00004964 type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00004965 if (type < 0)
4966 ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4967 argv[i]);
4968 break;
4969 }
4970 if (LocaleCompare("level",option+1) == 0)
4971 {
4972 i++;
cristybb503372010-05-27 20:51:26 +00004973 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004974 ThrowMogrifyException(OptionError,"MissingArgument",option);
4975 if (IsGeometry(argv[i]) == MagickFalse)
4976 ThrowMogrifyInvalidArgumentException(option,argv[i]);
4977 break;
4978 }
4979 if (LocaleCompare("level-colors",option+1) == 0)
4980 {
4981 i++;
cristybb503372010-05-27 20:51:26 +00004982 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00004983 ThrowMogrifyException(OptionError,"MissingArgument",option);
4984 break;
4985 }
cristy3ed852e2009-09-05 21:47:34 +00004986 if (LocaleCompare("limit",option+1) == 0)
4987 {
4988 char
4989 *p;
4990
4991 double
4992 value;
4993
cristybb503372010-05-27 20:51:26 +00004994 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004995 resource;
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 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005002 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005003 argv[i]);
5004 if (resource < 0)
5005 ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
5006 argv[i]);
5007 i++;
cristybb503372010-05-27 20:51:26 +00005008 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005009 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristydbdd0e32011-11-04 23:29:40 +00005010 value=StringToDouble(argv[i],&p);
cristyda16f162011-02-19 23:52:17 +00005011 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00005012 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
5013 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5014 break;
5015 }
5016 if (LocaleCompare("liquid-rescale",option+1) == 0)
5017 {
5018 i++;
cristybb503372010-05-27 20:51:26 +00005019 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005020 ThrowMogrifyException(OptionError,"MissingArgument",option);
5021 if (IsGeometry(argv[i]) == MagickFalse)
5022 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5023 break;
5024 }
5025 if (LocaleCompare("list",option+1) == 0)
5026 {
cristybb503372010-05-27 20:51:26 +00005027 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005028 list;
5029
5030 if (*option == '+')
5031 break;
5032 i++;
cristybb503372010-05-27 20:51:26 +00005033 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005034 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005035 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005036 if (list < 0)
5037 ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
cristyaeb2cbc2010-05-07 13:28:58 +00005038 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
cristy3ed852e2009-09-05 21:47:34 +00005039 argv+j,exception);
cristyaeb2cbc2010-05-07 13:28:58 +00005040 return(status != 0 ? MagickFalse : MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00005041 }
5042 if (LocaleCompare("log",option+1) == 0)
5043 {
5044 if (*option == '+')
5045 break;
5046 i++;
cristybb503372010-05-27 20:51:26 +00005047 if ((i == (ssize_t) argc) ||
cristy3ed852e2009-09-05 21:47:34 +00005048 (strchr(argv[i],'%') == (char *) NULL))
5049 ThrowMogrifyException(OptionError,"MissingArgument",option);
5050 break;
5051 }
5052 if (LocaleCompare("loop",option+1) == 0)
5053 {
5054 if (*option == '+')
5055 break;
5056 i++;
cristybb503372010-05-27 20:51:26 +00005057 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005058 ThrowMogrifyException(OptionError,"MissingArgument",option);
5059 if (IsGeometry(argv[i]) == MagickFalse)
5060 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5061 break;
5062 }
5063 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5064 }
5065 case 'm':
5066 {
5067 if (LocaleCompare("map",option+1) == 0)
5068 {
5069 global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5070 if (*option == '+')
5071 break;
5072 i++;
cristybb503372010-05-27 20:51:26 +00005073 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005074 ThrowMogrifyException(OptionError,"MissingArgument",option);
5075 break;
5076 }
5077 if (LocaleCompare("mask",option+1) == 0)
5078 {
5079 if (*option == '+')
5080 break;
5081 i++;
cristybb503372010-05-27 20:51:26 +00005082 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005083 ThrowMogrifyException(OptionError,"MissingArgument",option);
5084 break;
5085 }
5086 if (LocaleCompare("matte",option+1) == 0)
5087 break;
5088 if (LocaleCompare("mattecolor",option+1) == 0)
5089 {
5090 if (*option == '+')
5091 break;
5092 i++;
cristybb503372010-05-27 20:51:26 +00005093 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005094 ThrowMogrifyException(OptionError,"MissingArgument",option);
5095 break;
5096 }
cristyf40785b2010-03-06 02:27:27 +00005097 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005098 break;
cristyf40785b2010-03-06 02:27:27 +00005099 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00005100 break;
cristy3ed852e2009-09-05 21:47:34 +00005101 if (LocaleCompare("modulate",option+1) == 0)
5102 {
5103 if (*option == '+')
5104 break;
5105 i++;
cristybb503372010-05-27 20:51:26 +00005106 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005107 ThrowMogrifyException(OptionError,"MissingArgument",option);
5108 if (IsGeometry(argv[i]) == MagickFalse)
5109 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5110 break;
5111 }
5112 if (LocaleCompare("median",option+1) == 0)
5113 {
5114 if (*option == '+')
5115 break;
5116 i++;
cristybb503372010-05-27 20:51:26 +00005117 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005118 ThrowMogrifyException(OptionError,"MissingArgument",option);
5119 if (IsGeometry(argv[i]) == MagickFalse)
5120 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5121 break;
5122 }
cristy69ec32d2011-02-27 23:57:09 +00005123 if (LocaleCompare("mode",option+1) == 0)
5124 {
5125 if (*option == '+')
5126 break;
5127 i++;
5128 if (i == (ssize_t) argc)
5129 ThrowMogrifyException(OptionError,"MissingArgument",option);
5130 if (IsGeometry(argv[i]) == MagickFalse)
5131 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5132 break;
5133 }
cristy3ed852e2009-09-05 21:47:34 +00005134 if (LocaleCompare("monitor",option+1) == 0)
5135 break;
5136 if (LocaleCompare("monochrome",option+1) == 0)
5137 break;
5138 if (LocaleCompare("morph",option+1) == 0)
5139 {
5140 if (*option == '+')
5141 break;
5142 i++;
cristybb503372010-05-27 20:51:26 +00005143 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005144 ThrowMogrifyException(OptionError,"MissingArgument",option);
5145 if (IsGeometry(argv[i]) == MagickFalse)
5146 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5147 break;
5148 }
anthony29188a82010-01-22 10:12:34 +00005149 if (LocaleCompare("morphology",option+1) == 0)
5150 {
anthony29188a82010-01-22 10:12:34 +00005151 char
5152 token[MaxTextExtent];
5153
cristyb6bd4ad2010-08-08 01:12:27 +00005154 KernelInfo
5155 *kernel_info;
5156
5157 ssize_t
5158 op;
5159
anthony29188a82010-01-22 10:12:34 +00005160 i++;
cristybb503372010-05-27 20:51:26 +00005161 if (i == (ssize_t) argc)
anthony29188a82010-01-22 10:12:34 +00005162 ThrowMogrifyException(OptionError,"MissingArgument",option);
5163 GetMagickToken(argv[i],NULL,token);
cristy042ee782011-04-22 18:48:30 +00005164 op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
anthony29188a82010-01-22 10:12:34 +00005165 if (op < 0)
5166 ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
cristyf0c78232010-03-15 12:53:40 +00005167 token);
anthony29188a82010-01-22 10:12:34 +00005168 i++;
cristybb503372010-05-27 20:51:26 +00005169 if (i == (ssize_t) (argc-1))
anthony29188a82010-01-22 10:12:34 +00005170 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristyb6bd4ad2010-08-08 01:12:27 +00005171 kernel_info=AcquireKernelInfo(argv[i]);
5172 if (kernel_info == (KernelInfo *) NULL)
cristyf4e8c912010-08-08 01:51:19 +00005173 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristyb6bd4ad2010-08-08 01:12:27 +00005174 kernel_info=DestroyKernelInfo(kernel_info);
anthony29188a82010-01-22 10:12:34 +00005175 break;
5176 }
cristy3ed852e2009-09-05 21:47:34 +00005177 if (LocaleCompare("mosaic",option+1) == 0)
5178 break;
5179 if (LocaleCompare("motion-blur",option+1) == 0)
5180 {
5181 if (*option == '+')
5182 break;
5183 i++;
cristybb503372010-05-27 20:51:26 +00005184 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005185 ThrowMogrifyException(OptionError,"MissingArgument",option);
5186 if (IsGeometry(argv[i]) == MagickFalse)
5187 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5188 break;
5189 }
5190 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5191 }
5192 case 'n':
5193 {
5194 if (LocaleCompare("negate",option+1) == 0)
5195 break;
5196 if (LocaleCompare("noise",option+1) == 0)
5197 {
5198 i++;
cristybb503372010-05-27 20:51:26 +00005199 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005200 ThrowMogrifyException(OptionError,"MissingArgument",option);
5201 if (*option == '+')
5202 {
cristybb503372010-05-27 20:51:26 +00005203 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005204 noise;
5205
cristy042ee782011-04-22 18:48:30 +00005206 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005207 if (noise < 0)
5208 ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5209 argv[i]);
5210 break;
5211 }
5212 if (IsGeometry(argv[i]) == MagickFalse)
5213 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5214 break;
5215 }
5216 if (LocaleCompare("noop",option+1) == 0)
5217 break;
5218 if (LocaleCompare("normalize",option+1) == 0)
5219 break;
5220 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5221 }
5222 case 'o':
5223 {
5224 if (LocaleCompare("opaque",option+1) == 0)
5225 {
cristy3ed852e2009-09-05 21:47:34 +00005226 i++;
cristybb503372010-05-27 20:51:26 +00005227 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005228 ThrowMogrifyException(OptionError,"MissingArgument",option);
5229 break;
5230 }
5231 if (LocaleCompare("ordered-dither",option+1) == 0)
5232 {
5233 if (*option == '+')
5234 break;
5235 i++;
cristybb503372010-05-27 20:51:26 +00005236 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005237 ThrowMogrifyException(OptionError,"MissingArgument",option);
5238 break;
5239 }
5240 if (LocaleCompare("orient",option+1) == 0)
5241 {
cristybb503372010-05-27 20:51:26 +00005242 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005243 orientation;
5244
5245 orientation=UndefinedOrientation;
5246 if (*option == '+')
5247 break;
5248 i++;
cristybb503372010-05-27 20:51:26 +00005249 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005250 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005251 orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005252 argv[i]);
5253 if (orientation < 0)
5254 ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5255 argv[i]);
5256 break;
5257 }
5258 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5259 }
5260 case 'p':
5261 {
5262 if (LocaleCompare("page",option+1) == 0)
5263 {
5264 if (*option == '+')
5265 break;
5266 i++;
cristybb503372010-05-27 20:51:26 +00005267 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005268 ThrowMogrifyException(OptionError,"MissingArgument",option);
5269 break;
5270 }
5271 if (LocaleCompare("paint",option+1) == 0)
5272 {
5273 if (*option == '+')
5274 break;
5275 i++;
cristybb503372010-05-27 20:51:26 +00005276 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005277 ThrowMogrifyException(OptionError,"MissingArgument",option);
5278 if (IsGeometry(argv[i]) == MagickFalse)
5279 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5280 break;
5281 }
5282 if (LocaleCompare("path",option+1) == 0)
5283 {
5284 (void) CloneString(&path,(char *) NULL);
5285 if (*option == '+')
5286 break;
5287 i++;
cristybb503372010-05-27 20:51:26 +00005288 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005289 ThrowMogrifyException(OptionError,"MissingArgument",option);
5290 (void) CloneString(&path,argv[i]);
5291 break;
5292 }
5293 if (LocaleCompare("pointsize",option+1) == 0)
5294 {
5295 if (*option == '+')
5296 break;
5297 i++;
cristybb503372010-05-27 20:51:26 +00005298 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005299 ThrowMogrifyException(OptionError,"MissingArgument",option);
5300 if (IsGeometry(argv[i]) == MagickFalse)
5301 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5302 break;
5303 }
5304 if (LocaleCompare("polaroid",option+1) == 0)
5305 {
5306 if (*option == '+')
5307 break;
5308 i++;
cristybb503372010-05-27 20:51:26 +00005309 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005310 ThrowMogrifyException(OptionError,"MissingArgument",option);
5311 if (IsGeometry(argv[i]) == MagickFalse)
5312 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5313 break;
5314 }
5315 if (LocaleCompare("posterize",option+1) == 0)
5316 {
5317 if (*option == '+')
5318 break;
5319 i++;
cristybb503372010-05-27 20:51:26 +00005320 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005321 ThrowMogrifyException(OptionError,"MissingArgument",option);
5322 if (IsGeometry(argv[i]) == MagickFalse)
5323 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5324 break;
5325 }
cristye7f51092010-01-17 00:39:37 +00005326 if (LocaleCompare("precision",option+1) == 0)
5327 {
5328 if (*option == '+')
5329 break;
5330 i++;
cristybb503372010-05-27 20:51:26 +00005331 if (i == (ssize_t) argc)
cristye7f51092010-01-17 00:39:37 +00005332 ThrowMogrifyException(OptionError,"MissingArgument",option);
5333 if (IsGeometry(argv[i]) == MagickFalse)
5334 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5335 break;
5336 }
cristy3ed852e2009-09-05 21:47:34 +00005337 if (LocaleCompare("print",option+1) == 0)
5338 {
5339 if (*option == '+')
5340 break;
5341 i++;
cristybb503372010-05-27 20:51:26 +00005342 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005343 ThrowMogrifyException(OptionError,"MissingArgument",option);
5344 break;
5345 }
5346 if (LocaleCompare("process",option+1) == 0)
5347 {
5348 if (*option == '+')
5349 break;
5350 i++;
cristybb503372010-05-27 20:51:26 +00005351 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005352 ThrowMogrifyException(OptionError,"MissingArgument",option);
5353 break;
5354 }
5355 if (LocaleCompare("profile",option+1) == 0)
5356 {
5357 i++;
cristybb503372010-05-27 20:51:26 +00005358 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005359 ThrowMogrifyException(OptionError,"MissingArgument",option);
5360 break;
5361 }
5362 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5363 }
5364 case 'q':
5365 {
5366 if (LocaleCompare("quality",option+1) == 0)
5367 {
5368 if (*option == '+')
5369 break;
5370 i++;
cristybb503372010-05-27 20:51:26 +00005371 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005372 ThrowMogrifyException(OptionError,"MissingArgument",option);
5373 if (IsGeometry(argv[i]) == MagickFalse)
5374 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5375 break;
5376 }
5377 if (LocaleCompare("quantize",option+1) == 0)
5378 {
cristybb503372010-05-27 20:51:26 +00005379 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005380 colorspace;
5381
5382 if (*option == '+')
5383 break;
5384 i++;
cristybb503372010-05-27 20:51:26 +00005385 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005386 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005387 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00005388 argv[i]);
5389 if (colorspace < 0)
5390 ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5391 argv[i]);
5392 break;
5393 }
5394 if (LocaleCompare("quiet",option+1) == 0)
5395 break;
5396 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5397 }
5398 case 'r':
5399 {
5400 if (LocaleCompare("radial-blur",option+1) == 0)
5401 {
5402 i++;
cristybb503372010-05-27 20:51:26 +00005403 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005404 ThrowMogrifyException(OptionError,"MissingArgument",option);
5405 if (IsGeometry(argv[i]) == MagickFalse)
5406 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5407 break;
5408 }
5409 if (LocaleCompare("raise",option+1) == 0)
5410 {
5411 i++;
cristybb503372010-05-27 20:51:26 +00005412 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005413 ThrowMogrifyException(OptionError,"MissingArgument",option);
5414 if (IsGeometry(argv[i]) == MagickFalse)
5415 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5416 break;
5417 }
5418 if (LocaleCompare("random-threshold",option+1) == 0)
5419 {
5420 if (*option == '+')
5421 break;
5422 i++;
cristybb503372010-05-27 20:51:26 +00005423 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005424 ThrowMogrifyException(OptionError,"MissingArgument",option);
5425 if (IsGeometry(argv[i]) == MagickFalse)
5426 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5427 break;
5428 }
5429 if (LocaleCompare("red-primary",option+1) == 0)
5430 {
5431 if (*option == '+')
5432 break;
5433 i++;
cristybb503372010-05-27 20:51:26 +00005434 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005435 ThrowMogrifyException(OptionError,"MissingArgument",option);
5436 if (IsGeometry(argv[i]) == MagickFalse)
5437 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5438 }
cristy9f2083a2010-04-22 19:48:05 +00005439 if (LocaleCompare("regard-warnings",option+1) == 0)
5440 break;
cristy3ed852e2009-09-05 21:47:34 +00005441 if (LocaleCompare("region",option+1) == 0)
5442 {
5443 if (*option == '+')
5444 break;
5445 i++;
cristybb503372010-05-27 20:51:26 +00005446 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005447 ThrowMogrifyException(OptionError,"MissingArgument",option);
5448 if (IsGeometry(argv[i]) == MagickFalse)
5449 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5450 break;
5451 }
cristyf0c78232010-03-15 12:53:40 +00005452 if (LocaleCompare("remap",option+1) == 0)
5453 {
5454 if (*option == '+')
5455 break;
5456 i++;
cristybb503372010-05-27 20:51:26 +00005457 if (i == (ssize_t) (argc-1))
cristyf0c78232010-03-15 12:53:40 +00005458 ThrowMogrifyException(OptionError,"MissingArgument",option);
5459 break;
5460 }
cristy3ed852e2009-09-05 21:47:34 +00005461 if (LocaleCompare("render",option+1) == 0)
5462 break;
5463 if (LocaleCompare("repage",option+1) == 0)
5464 {
5465 if (*option == '+')
5466 break;
5467 i++;
cristybb503372010-05-27 20:51:26 +00005468 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005469 ThrowMogrifyException(OptionError,"MissingArgument",option);
5470 if (IsGeometry(argv[i]) == MagickFalse)
5471 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5472 break;
5473 }
5474 if (LocaleCompare("resample",option+1) == 0)
5475 {
5476 if (*option == '+')
5477 break;
5478 i++;
cristybb503372010-05-27 20:51:26 +00005479 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005480 ThrowMogrifyException(OptionError,"MissingArgument",option);
5481 if (IsGeometry(argv[i]) == MagickFalse)
5482 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5483 break;
5484 }
5485 if (LocaleCompare("resize",option+1) == 0)
5486 {
5487 if (*option == '+')
5488 break;
5489 i++;
cristybb503372010-05-27 20:51:26 +00005490 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005491 ThrowMogrifyException(OptionError,"MissingArgument",option);
5492 if (IsGeometry(argv[i]) == MagickFalse)
5493 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5494 break;
5495 }
cristyebbcfea2011-02-25 02:43:54 +00005496 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5497 {
5498 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5499 break;
5500 }
cristy3ed852e2009-09-05 21:47:34 +00005501 if (LocaleCompare("reverse",option+1) == 0)
5502 break;
5503 if (LocaleCompare("roll",option+1) == 0)
5504 {
5505 if (*option == '+')
5506 break;
5507 i++;
cristybb503372010-05-27 20:51:26 +00005508 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005509 ThrowMogrifyException(OptionError,"MissingArgument",option);
5510 if (IsGeometry(argv[i]) == MagickFalse)
5511 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5512 break;
5513 }
5514 if (LocaleCompare("rotate",option+1) == 0)
5515 {
5516 i++;
cristybb503372010-05-27 20:51:26 +00005517 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005518 ThrowMogrifyException(OptionError,"MissingArgument",option);
5519 if (IsGeometry(argv[i]) == MagickFalse)
5520 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5521 break;
5522 }
5523 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5524 }
5525 case 's':
5526 {
5527 if (LocaleCompare("sample",option+1) == 0)
5528 {
5529 if (*option == '+')
5530 break;
5531 i++;
cristybb503372010-05-27 20:51:26 +00005532 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005533 ThrowMogrifyException(OptionError,"MissingArgument",option);
5534 if (IsGeometry(argv[i]) == MagickFalse)
5535 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5536 break;
5537 }
5538 if (LocaleCompare("sampling-factor",option+1) == 0)
5539 {
5540 if (*option == '+')
5541 break;
5542 i++;
cristybb503372010-05-27 20:51:26 +00005543 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005544 ThrowMogrifyException(OptionError,"MissingArgument",option);
5545 if (IsGeometry(argv[i]) == MagickFalse)
5546 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5547 break;
5548 }
5549 if (LocaleCompare("scale",option+1) == 0)
5550 {
5551 if (*option == '+')
5552 break;
5553 i++;
cristybb503372010-05-27 20:51:26 +00005554 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005555 ThrowMogrifyException(OptionError,"MissingArgument",option);
5556 if (IsGeometry(argv[i]) == MagickFalse)
5557 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5558 break;
5559 }
5560 if (LocaleCompare("scene",option+1) == 0)
5561 {
5562 if (*option == '+')
5563 break;
5564 i++;
cristybb503372010-05-27 20:51:26 +00005565 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005566 ThrowMogrifyException(OptionError,"MissingArgument",option);
5567 if (IsGeometry(argv[i]) == MagickFalse)
5568 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5569 break;
5570 }
5571 if (LocaleCompare("seed",option+1) == 0)
5572 {
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 if (IsGeometry(argv[i]) == MagickFalse)
5579 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5580 break;
5581 }
5582 if (LocaleCompare("segment",option+1) == 0)
5583 {
5584 if (*option == '+')
5585 break;
5586 i++;
cristybb503372010-05-27 20:51:26 +00005587 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005588 ThrowMogrifyException(OptionError,"MissingArgument",option);
5589 if (IsGeometry(argv[i]) == MagickFalse)
5590 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5591 break;
5592 }
5593 if (LocaleCompare("selective-blur",option+1) == 0)
5594 {
5595 i++;
cristybb503372010-05-27 20:51:26 +00005596 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005597 ThrowMogrifyException(OptionError,"MissingArgument",option);
5598 if (IsGeometry(argv[i]) == MagickFalse)
5599 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5600 break;
5601 }
5602 if (LocaleCompare("separate",option+1) == 0)
5603 break;
5604 if (LocaleCompare("sepia-tone",option+1) == 0)
5605 {
5606 if (*option == '+')
5607 break;
5608 i++;
cristybb503372010-05-27 20:51:26 +00005609 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005610 ThrowMogrifyException(OptionError,"MissingArgument",option);
5611 if (IsGeometry(argv[i]) == MagickFalse)
5612 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5613 break;
5614 }
5615 if (LocaleCompare("set",option+1) == 0)
5616 {
5617 i++;
cristybb503372010-05-27 20:51:26 +00005618 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005619 ThrowMogrifyException(OptionError,"MissingArgument",option);
5620 if (*option == '+')
5621 break;
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 break;
5626 }
5627 if (LocaleCompare("shade",option+1) == 0)
5628 {
5629 i++;
cristybb503372010-05-27 20:51:26 +00005630 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005631 ThrowMogrifyException(OptionError,"MissingArgument",option);
5632 if (IsGeometry(argv[i]) == MagickFalse)
5633 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5634 break;
5635 }
5636 if (LocaleCompare("shadow",option+1) == 0)
5637 {
5638 if (*option == '+')
5639 break;
5640 i++;
cristybb503372010-05-27 20:51:26 +00005641 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005642 ThrowMogrifyException(OptionError,"MissingArgument",option);
5643 if (IsGeometry(argv[i]) == MagickFalse)
5644 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5645 break;
5646 }
5647 if (LocaleCompare("sharpen",option+1) == 0)
5648 {
5649 i++;
cristybb503372010-05-27 20:51:26 +00005650 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005651 ThrowMogrifyException(OptionError,"MissingArgument",option);
5652 if (IsGeometry(argv[i]) == MagickFalse)
5653 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5654 break;
5655 }
5656 if (LocaleCompare("shave",option+1) == 0)
5657 {
5658 if (*option == '+')
5659 break;
5660 i++;
cristybb503372010-05-27 20:51:26 +00005661 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005662 ThrowMogrifyException(OptionError,"MissingArgument",option);
5663 if (IsGeometry(argv[i]) == MagickFalse)
5664 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5665 break;
5666 }
5667 if (LocaleCompare("shear",option+1) == 0)
5668 {
5669 i++;
cristybb503372010-05-27 20:51:26 +00005670 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005671 ThrowMogrifyException(OptionError,"MissingArgument",option);
5672 if (IsGeometry(argv[i]) == MagickFalse)
5673 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5674 break;
5675 }
5676 if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5677 {
5678 i++;
cristybb503372010-05-27 20:51:26 +00005679 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005680 ThrowMogrifyException(OptionError,"MissingArgument",option);
5681 if (IsGeometry(argv[i]) == MagickFalse)
5682 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5683 break;
5684 }
5685 if (LocaleCompare("size",option+1) == 0)
5686 {
5687 if (*option == '+')
5688 break;
5689 i++;
cristybb503372010-05-27 20:51:26 +00005690 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005691 ThrowMogrifyException(OptionError,"MissingArgument",option);
5692 if (IsGeometry(argv[i]) == MagickFalse)
5693 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5694 break;
5695 }
5696 if (LocaleCompare("sketch",option+1) == 0)
5697 {
5698 if (*option == '+')
5699 break;
5700 i++;
cristybb503372010-05-27 20:51:26 +00005701 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005702 ThrowMogrifyException(OptionError,"MissingArgument",option);
5703 if (IsGeometry(argv[i]) == MagickFalse)
5704 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5705 break;
5706 }
cristy4285d782011-02-09 20:12:28 +00005707 if (LocaleCompare("smush",option+1) == 0)
5708 {
cristy4285d782011-02-09 20:12:28 +00005709 i++;
5710 if (i == (ssize_t) argc)
5711 ThrowMogrifyException(OptionError,"MissingArgument",option);
5712 if (IsGeometry(argv[i]) == MagickFalse)
5713 ThrowMogrifyInvalidArgumentException(option,argv[i]);
cristy4285d782011-02-09 20:12:28 +00005714 i++;
5715 break;
5716 }
cristy3ed852e2009-09-05 21:47:34 +00005717 if (LocaleCompare("solarize",option+1) == 0)
5718 {
5719 if (*option == '+')
5720 break;
5721 i++;
cristybb503372010-05-27 20:51:26 +00005722 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005723 ThrowMogrifyException(OptionError,"MissingArgument",option);
5724 if (IsGeometry(argv[i]) == MagickFalse)
5725 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5726 break;
5727 }
5728 if (LocaleCompare("sparse-color",option+1) == 0)
5729 {
cristybb503372010-05-27 20:51:26 +00005730 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005731 op;
5732
5733 i++;
cristybb503372010-05-27 20:51:26 +00005734 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005735 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005736 op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005737 if (op < 0)
5738 ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5739 argv[i]);
5740 i++;
cristybb503372010-05-27 20:51:26 +00005741 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005742 ThrowMogrifyException(OptionError,"MissingArgument",option);
5743 break;
5744 }
5745 if (LocaleCompare("spread",option+1) == 0)
5746 {
5747 if (*option == '+')
5748 break;
5749 i++;
cristybb503372010-05-27 20:51:26 +00005750 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005751 ThrowMogrifyException(OptionError,"MissingArgument",option);
5752 if (IsGeometry(argv[i]) == MagickFalse)
5753 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5754 break;
5755 }
cristy0834d642011-03-18 18:26:08 +00005756 if (LocaleCompare("statistic",option+1) == 0)
5757 {
5758 ssize_t
5759 op;
5760
5761 if (*option == '+')
5762 break;
5763 i++;
5764 if (i == (ssize_t) argc)
5765 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005766 op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
cristy0834d642011-03-18 18:26:08 +00005767 if (op < 0)
5768 ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5769 argv[i]);
5770 i++;
5771 if (i == (ssize_t) (argc-1))
5772 ThrowMogrifyException(OptionError,"MissingArgument",option);
5773 if (IsGeometry(argv[i]) == MagickFalse)
5774 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5775 break;
5776 }
cristy3ed852e2009-09-05 21:47:34 +00005777 if (LocaleCompare("stretch",option+1) == 0)
5778 {
cristybb503372010-05-27 20:51:26 +00005779 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005780 stretch;
5781
5782 if (*option == '+')
5783 break;
5784 i++;
cristybb503372010-05-27 20:51:26 +00005785 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005786 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005787 stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005788 if (stretch < 0)
5789 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5790 argv[i]);
5791 break;
5792 }
5793 if (LocaleCompare("strip",option+1) == 0)
5794 break;
5795 if (LocaleCompare("stroke",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 break;
5803 }
5804 if (LocaleCompare("strokewidth",option+1) == 0)
5805 {
5806 if (*option == '+')
5807 break;
5808 i++;
cristybb503372010-05-27 20:51:26 +00005809 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005810 ThrowMogrifyException(OptionError,"MissingArgument",option);
5811 if (IsGeometry(argv[i]) == MagickFalse)
5812 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5813 break;
5814 }
5815 if (LocaleCompare("style",option+1) == 0)
5816 {
cristybb503372010-05-27 20:51:26 +00005817 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005818 style;
5819
5820 if (*option == '+')
5821 break;
5822 i++;
cristybb503372010-05-27 20:51:26 +00005823 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005824 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005825 style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005826 if (style < 0)
5827 ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5828 argv[i]);
5829 break;
5830 }
cristyecb10ff2011-03-22 13:14:03 +00005831 if (LocaleCompare("swap",option+1) == 0)
5832 {
5833 if (*option == '+')
5834 break;
5835 i++;
5836 if (i == (ssize_t) (argc-1))
5837 ThrowMogrifyException(OptionError,"MissingArgument",option);
5838 if (IsGeometry(argv[i]) == MagickFalse)
5839 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5840 break;
5841 }
cristy3ed852e2009-09-05 21:47:34 +00005842 if (LocaleCompare("swirl",option+1) == 0)
5843 {
5844 if (*option == '+')
5845 break;
5846 i++;
cristybb503372010-05-27 20:51:26 +00005847 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005848 ThrowMogrifyException(OptionError,"MissingArgument",option);
5849 if (IsGeometry(argv[i]) == MagickFalse)
5850 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5851 break;
5852 }
cristyd9a29192010-10-16 16:49:53 +00005853 if (LocaleCompare("synchronize",option+1) == 0)
5854 break;
cristy3ed852e2009-09-05 21:47:34 +00005855 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5856 }
5857 case 't':
5858 {
5859 if (LocaleCompare("taint",option+1) == 0)
5860 break;
5861 if (LocaleCompare("texture",option+1) == 0)
5862 {
5863 if (*option == '+')
5864 break;
5865 i++;
cristybb503372010-05-27 20:51:26 +00005866 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005867 ThrowMogrifyException(OptionError,"MissingArgument",option);
5868 break;
5869 }
5870 if (LocaleCompare("tile",option+1) == 0)
5871 {
5872 if (*option == '+')
5873 break;
5874 i++;
cristybb503372010-05-27 20:51:26 +00005875 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005876 ThrowMogrifyException(OptionError,"MissingArgument",option);
5877 break;
5878 }
5879 if (LocaleCompare("tile-offset",option+1) == 0)
5880 {
5881 if (*option == '+')
5882 break;
5883 i++;
cristybb503372010-05-27 20:51:26 +00005884 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005885 ThrowMogrifyException(OptionError,"MissingArgument",option);
5886 if (IsGeometry(argv[i]) == MagickFalse)
5887 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5888 break;
5889 }
5890 if (LocaleCompare("tint",option+1) == 0)
5891 {
5892 if (*option == '+')
5893 break;
5894 i++;
cristybb503372010-05-27 20:51:26 +00005895 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005896 ThrowMogrifyException(OptionError,"MissingArgument",option);
5897 if (IsGeometry(argv[i]) == MagickFalse)
5898 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5899 break;
5900 }
5901 if (LocaleCompare("transform",option+1) == 0)
5902 break;
5903 if (LocaleCompare("transpose",option+1) == 0)
5904 break;
5905 if (LocaleCompare("transverse",option+1) == 0)
5906 break;
5907 if (LocaleCompare("threshold",option+1) == 0)
5908 {
5909 if (*option == '+')
5910 break;
5911 i++;
cristybb503372010-05-27 20:51:26 +00005912 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005913 ThrowMogrifyException(OptionError,"MissingArgument",option);
5914 if (IsGeometry(argv[i]) == MagickFalse)
5915 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5916 break;
5917 }
5918 if (LocaleCompare("thumbnail",option+1) == 0)
5919 {
5920 if (*option == '+')
5921 break;
5922 i++;
cristybb503372010-05-27 20:51:26 +00005923 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005924 ThrowMogrifyException(OptionError,"MissingArgument",option);
5925 if (IsGeometry(argv[i]) == MagickFalse)
5926 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5927 break;
5928 }
5929 if (LocaleCompare("transparent",option+1) == 0)
5930 {
5931 i++;
cristybb503372010-05-27 20:51:26 +00005932 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005933 ThrowMogrifyException(OptionError,"MissingArgument",option);
5934 break;
5935 }
5936 if (LocaleCompare("transparent-color",option+1) == 0)
5937 {
5938 if (*option == '+')
5939 break;
5940 i++;
cristybb503372010-05-27 20:51:26 +00005941 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00005942 ThrowMogrifyException(OptionError,"MissingArgument",option);
5943 break;
5944 }
5945 if (LocaleCompare("treedepth",option+1) == 0)
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);
5952 if (IsGeometry(argv[i]) == MagickFalse)
5953 ThrowMogrifyInvalidArgumentException(option,argv[i]);
5954 break;
5955 }
5956 if (LocaleCompare("trim",option+1) == 0)
5957 break;
5958 if (LocaleCompare("type",option+1) == 0)
5959 {
cristybb503372010-05-27 20:51:26 +00005960 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005961 type;
5962
5963 if (*option == '+')
5964 break;
5965 i++;
cristybb503372010-05-27 20:51:26 +00005966 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005967 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005968 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
cristy3ed852e2009-09-05 21:47:34 +00005969 if (type < 0)
5970 ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5971 argv[i]);
5972 break;
5973 }
5974 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5975 }
5976 case 'u':
5977 {
5978 if (LocaleCompare("undercolor",option+1) == 0)
5979 {
5980 if (*option == '+')
5981 break;
5982 i++;
cristybb503372010-05-27 20:51:26 +00005983 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005984 ThrowMogrifyException(OptionError,"MissingArgument",option);
5985 break;
5986 }
5987 if (LocaleCompare("unique-colors",option+1) == 0)
5988 break;
5989 if (LocaleCompare("units",option+1) == 0)
5990 {
cristybb503372010-05-27 20:51:26 +00005991 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005992 units;
5993
5994 if (*option == '+')
5995 break;
5996 i++;
cristybb503372010-05-27 20:51:26 +00005997 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00005998 ThrowMogrifyException(OptionError,"MissingArgument",option);
cristy042ee782011-04-22 18:48:30 +00005999 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006000 argv[i]);
6001 if (units < 0)
6002 ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
6003 argv[i]);
6004 break;
6005 }
6006 if (LocaleCompare("unsharp",option+1) == 0)
6007 {
6008 i++;
cristybb503372010-05-27 20:51:26 +00006009 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006010 ThrowMogrifyException(OptionError,"MissingArgument",option);
6011 if (IsGeometry(argv[i]) == MagickFalse)
6012 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6013 break;
6014 }
6015 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6016 }
6017 case 'v':
6018 {
6019 if (LocaleCompare("verbose",option+1) == 0)
6020 {
6021 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6022 break;
6023 }
6024 if ((LocaleCompare("version",option+1) == 0) ||
6025 (LocaleCompare("-version",option+1) == 0))
6026 {
cristyb51dff52011-05-19 16:55:47 +00006027 (void) FormatLocaleFile(stdout,"Version: %s\n",
cristybb503372010-05-27 20:51:26 +00006028 GetMagickVersion((size_t *) NULL));
cristy1e604812011-05-19 18:07:50 +00006029 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
6030 GetMagickCopyright());
6031 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
6032 GetMagickFeatures());
cristy3ed852e2009-09-05 21:47:34 +00006033 break;
6034 }
6035 if (LocaleCompare("view",option+1) == 0)
6036 {
6037 if (*option == '+')
6038 break;
6039 i++;
cristybb503372010-05-27 20:51:26 +00006040 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006041 ThrowMogrifyException(OptionError,"MissingArgument",option);
6042 break;
6043 }
6044 if (LocaleCompare("vignette",option+1) == 0)
6045 {
6046 if (*option == '+')
6047 break;
6048 i++;
cristybb503372010-05-27 20:51:26 +00006049 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006050 ThrowMogrifyException(OptionError,"MissingArgument",option);
6051 if (IsGeometry(argv[i]) == MagickFalse)
6052 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6053 break;
6054 }
6055 if (LocaleCompare("virtual-pixel",option+1) == 0)
6056 {
cristybb503372010-05-27 20:51:26 +00006057 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006058 method;
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);
cristy042ee782011-04-22 18:48:30 +00006065 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
cristy3ed852e2009-09-05 21:47:34 +00006066 argv[i]);
6067 if (method < 0)
6068 ThrowMogrifyException(OptionError,
6069 "UnrecognizedVirtualPixelMethod",argv[i]);
6070 break;
6071 }
6072 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6073 }
6074 case 'w':
6075 {
6076 if (LocaleCompare("wave",option+1) == 0)
6077 {
6078 i++;
cristybb503372010-05-27 20:51:26 +00006079 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006080 ThrowMogrifyException(OptionError,"MissingArgument",option);
6081 if (IsGeometry(argv[i]) == MagickFalse)
6082 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6083 break;
6084 }
6085 if (LocaleCompare("weight",option+1) == 0)
6086 {
6087 if (*option == '+')
6088 break;
6089 i++;
cristybb503372010-05-27 20:51:26 +00006090 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006091 ThrowMogrifyException(OptionError,"MissingArgument",option);
6092 break;
6093 }
6094 if (LocaleCompare("white-point",option+1) == 0)
6095 {
6096 if (*option == '+')
6097 break;
6098 i++;
cristybb503372010-05-27 20:51:26 +00006099 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006100 ThrowMogrifyException(OptionError,"MissingArgument",option);
6101 if (IsGeometry(argv[i]) == MagickFalse)
6102 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6103 break;
6104 }
6105 if (LocaleCompare("white-threshold",option+1) == 0)
6106 {
6107 if (*option == '+')
6108 break;
6109 i++;
cristybb503372010-05-27 20:51:26 +00006110 if (i == (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006111 ThrowMogrifyException(OptionError,"MissingArgument",option);
6112 if (IsGeometry(argv[i]) == MagickFalse)
6113 ThrowMogrifyInvalidArgumentException(option,argv[i]);
6114 break;
6115 }
6116 if (LocaleCompare("write",option+1) == 0)
6117 {
6118 i++;
cristybb503372010-05-27 20:51:26 +00006119 if (i == (ssize_t) (argc-1))
cristy3ed852e2009-09-05 21:47:34 +00006120 ThrowMogrifyException(OptionError,"MissingArgument",option);
6121 break;
6122 }
6123 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6124 }
6125 case '?':
6126 break;
6127 default:
6128 ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6129 }
cristy042ee782011-04-22 18:48:30 +00006130 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6131 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00006132 if (fire != MagickFalse)
6133 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6134 }
6135 if (k != 0)
6136 ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
cristycee97112010-05-28 00:44:52 +00006137 if (i != (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006138 ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6139 DestroyMogrify();
6140 return(status != 0 ? MagickTrue : MagickFalse);
6141}
6142
6143/*
6144%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6145% %
6146% %
6147% %
6148+ M o g r i f y I m a g e I n f o %
6149% %
6150% %
6151% %
6152%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6153%
6154% MogrifyImageInfo() applies image processing settings to the image as
6155% prescribed by command line options.
6156%
6157% The format of the MogrifyImageInfo method is:
6158%
6159% MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6160% const char **argv,ExceptionInfo *exception)
6161%
6162% A description of each parameter follows:
6163%
6164% o image_info: the image info..
6165%
6166% o argc: Specifies a pointer to an integer describing the number of
6167% elements in the argument vector.
6168%
6169% o argv: Specifies a pointer to a text array containing the command line
6170% arguments.
6171%
6172% o exception: return any errors or warnings in this structure.
6173%
6174*/
6175WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6176 const int argc,const char **argv,ExceptionInfo *exception)
6177{
6178 const char
6179 *option;
6180
6181 GeometryInfo
6182 geometry_info;
6183
cristybb503372010-05-27 20:51:26 +00006184 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006185 count;
6186
cristybb503372010-05-27 20:51:26 +00006187 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006188 i;
6189
6190 /*
6191 Initialize method variables.
6192 */
6193 assert(image_info != (ImageInfo *) NULL);
6194 assert(image_info->signature == MagickSignature);
6195 if (image_info->debug != MagickFalse)
6196 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6197 image_info->filename);
6198 if (argc < 0)
6199 return(MagickTrue);
6200 /*
6201 Set the image settings.
6202 */
cristybb503372010-05-27 20:51:26 +00006203 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00006204 {
6205 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00006206 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00006207 continue;
cristy042ee782011-04-22 18:48:30 +00006208 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00006209 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00006210 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00006211 break;
6212 switch (*(option+1))
6213 {
6214 case 'a':
6215 {
6216 if (LocaleCompare("adjoin",option+1) == 0)
6217 {
6218 image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6219 break;
6220 }
6221 if (LocaleCompare("antialias",option+1) == 0)
6222 {
6223 image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6224 break;
6225 }
cristy3ed852e2009-09-05 21:47:34 +00006226 if (LocaleCompare("authenticate",option+1) == 0)
6227 {
6228 if (*option == '+')
anthony1afdc7a2011-10-05 11:54:28 +00006229 (void) DeleteImageOption(image_info,option+1);
cristy3ed852e2009-09-05 21:47:34 +00006230 else
anthony1afdc7a2011-10-05 11:54:28 +00006231 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006232 break;
6233 }
6234 break;
6235 }
6236 case 'b':
6237 {
6238 if (LocaleCompare("background",option+1) == 0)
6239 {
6240 if (*option == '+')
6241 {
6242 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006243 (void) QueryColorCompliance(MogrifyBackgroundColor,
6244 AllCompliance,&image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006245 break;
6246 }
6247 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006248 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6249 &image_info->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006250 break;
6251 }
6252 if (LocaleCompare("bias",option+1) == 0)
6253 {
6254 if (*option == '+')
6255 {
6256 (void) SetImageOption(image_info,option+1,"0.0");
6257 break;
6258 }
6259 (void) SetImageOption(image_info,option+1,argv[i+1]);
6260 break;
6261 }
6262 if (LocaleCompare("black-point-compensation",option+1) == 0)
6263 {
6264 if (*option == '+')
6265 {
6266 (void) SetImageOption(image_info,option+1,"false");
6267 break;
6268 }
6269 (void) SetImageOption(image_info,option+1,"true");
6270 break;
6271 }
6272 if (LocaleCompare("blue-primary",option+1) == 0)
6273 {
6274 if (*option == '+')
6275 {
6276 (void) SetImageOption(image_info,option+1,"0.0");
6277 break;
6278 }
6279 (void) SetImageOption(image_info,option+1,argv[i+1]);
6280 break;
6281 }
6282 if (LocaleCompare("bordercolor",option+1) == 0)
6283 {
6284 if (*option == '+')
6285 {
6286 (void) DeleteImageOption(image_info,option+1);
cristy9950d572011-10-01 18:22:35 +00006287 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006288 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006289 break;
6290 }
cristy9950d572011-10-01 18:22:35 +00006291 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6292 &image_info->border_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006293 (void) SetImageOption(image_info,option+1,argv[i+1]);
6294 break;
6295 }
6296 if (LocaleCompare("box",option+1) == 0)
6297 {
6298 if (*option == '+')
6299 {
6300 (void) SetImageOption(image_info,"undercolor","none");
6301 break;
6302 }
6303 (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6304 break;
6305 }
6306 break;
6307 }
6308 case 'c':
6309 {
6310 if (LocaleCompare("cache",option+1) == 0)
6311 {
6312 MagickSizeType
6313 limit;
6314
6315 limit=MagickResourceInfinity;
6316 if (LocaleCompare("unlimited",argv[i+1]) != 0)
cristy9b34e302011-11-05 02:15:45 +00006317 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6318 100.0);
cristy3ed852e2009-09-05 21:47:34 +00006319 (void) SetMagickResourceLimit(MemoryResource,limit);
6320 (void) SetMagickResourceLimit(MapResource,2*limit);
6321 break;
6322 }
6323 if (LocaleCompare("caption",option+1) == 0)
6324 {
6325 if (*option == '+')
6326 {
6327 (void) DeleteImageOption(image_info,option+1);
6328 break;
6329 }
6330 (void) SetImageOption(image_info,option+1,argv[i+1]);
6331 break;
6332 }
6333 if (LocaleCompare("channel",option+1) == 0)
6334 {
6335 if (*option == '+')
6336 {
6337 image_info->channel=DefaultChannels;
6338 break;
6339 }
6340 image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6341 break;
6342 }
cristy3ed852e2009-09-05 21:47:34 +00006343 if (LocaleCompare("colorspace",option+1) == 0)
6344 {
6345 if (*option == '+')
6346 {
6347 image_info->colorspace=UndefinedColorspace;
6348 (void) SetImageOption(image_info,option+1,"undefined");
6349 break;
6350 }
cristy042ee782011-04-22 18:48:30 +00006351 image_info->colorspace=(ColorspaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006352 MagickColorspaceOptions,MagickFalse,argv[i+1]);
6353 (void) SetImageOption(image_info,option+1,argv[i+1]);
6354 break;
6355 }
cristy3ed852e2009-09-05 21:47:34 +00006356 if (LocaleCompare("comment",option+1) == 0)
6357 {
6358 if (*option == '+')
6359 {
6360 (void) DeleteImageOption(image_info,option+1);
6361 break;
6362 }
6363 (void) SetImageOption(image_info,option+1,argv[i+1]);
6364 break;
6365 }
6366 if (LocaleCompare("compose",option+1) == 0)
6367 {
6368 if (*option == '+')
6369 {
6370 (void) SetImageOption(image_info,option+1,"undefined");
6371 break;
6372 }
6373 (void) SetImageOption(image_info,option+1,argv[i+1]);
6374 break;
6375 }
6376 if (LocaleCompare("compress",option+1) == 0)
6377 {
6378 if (*option == '+')
6379 {
6380 image_info->compression=UndefinedCompression;
6381 (void) SetImageOption(image_info,option+1,"undefined");
6382 break;
6383 }
cristy042ee782011-04-22 18:48:30 +00006384 image_info->compression=(CompressionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006385 MagickCompressOptions,MagickFalse,argv[i+1]);
6386 (void) SetImageOption(image_info,option+1,argv[i+1]);
6387 break;
6388 }
6389 break;
6390 }
6391 case 'd':
6392 {
6393 if (LocaleCompare("debug",option+1) == 0)
6394 {
6395 if (*option == '+')
6396 (void) SetLogEventMask("none");
6397 else
6398 (void) SetLogEventMask(argv[i+1]);
6399 image_info->debug=IsEventLogging();
6400 break;
6401 }
6402 if (LocaleCompare("define",option+1) == 0)
6403 {
6404 if (*option == '+')
6405 {
6406 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6407 (void) DeleteImageRegistry(argv[i+1]+9);
6408 else
6409 (void) DeleteImageOption(image_info,argv[i+1]);
6410 break;
6411 }
6412 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6413 {
6414 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6415 exception);
6416 break;
6417 }
6418 (void) DefineImageOption(image_info,argv[i+1]);
6419 break;
6420 }
6421 if (LocaleCompare("delay",option+1) == 0)
6422 {
6423 if (*option == '+')
6424 {
6425 (void) SetImageOption(image_info,option+1,"0");
6426 break;
6427 }
6428 (void) SetImageOption(image_info,option+1,argv[i+1]);
6429 break;
6430 }
6431 if (LocaleCompare("density",option+1) == 0)
6432 {
6433 /*
6434 Set image density.
6435 */
6436 if (*option == '+')
6437 {
6438 if (image_info->density != (char *) NULL)
6439 image_info->density=DestroyString(image_info->density);
6440 (void) SetImageOption(image_info,option+1,"72");
6441 break;
6442 }
6443 (void) CloneString(&image_info->density,argv[i+1]);
6444 (void) SetImageOption(image_info,option+1,argv[i+1]);
6445 break;
6446 }
6447 if (LocaleCompare("depth",option+1) == 0)
6448 {
6449 if (*option == '+')
6450 {
6451 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6452 break;
6453 }
cristye27293e2009-12-18 02:53:20 +00006454 image_info->depth=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006455 break;
6456 }
cristyc9b12952010-03-28 01:12:28 +00006457 if (LocaleCompare("direction",option+1) == 0)
6458 {
6459 if (*option == '+')
6460 {
6461 (void) SetImageOption(image_info,option+1,"undefined");
6462 break;
6463 }
6464 (void) SetImageOption(image_info,option+1,argv[i+1]);
6465 break;
6466 }
cristy3ed852e2009-09-05 21:47:34 +00006467 if (LocaleCompare("display",option+1) == 0)
6468 {
6469 if (*option == '+')
6470 {
6471 if (image_info->server_name != (char *) NULL)
6472 image_info->server_name=DestroyString(
6473 image_info->server_name);
6474 break;
6475 }
6476 (void) CloneString(&image_info->server_name,argv[i+1]);
6477 break;
6478 }
6479 if (LocaleCompare("dispose",option+1) == 0)
6480 {
6481 if (*option == '+')
6482 {
6483 (void) SetImageOption(image_info,option+1,"undefined");
6484 break;
6485 }
6486 (void) SetImageOption(image_info,option+1,argv[i+1]);
6487 break;
6488 }
6489 if (LocaleCompare("dither",option+1) == 0)
6490 {
6491 if (*option == '+')
6492 {
6493 image_info->dither=MagickFalse;
cristyd5acfd12010-06-15 00:11:38 +00006494 (void) SetImageOption(image_info,option+1,"none");
cristy3ed852e2009-09-05 21:47:34 +00006495 break;
6496 }
6497 (void) SetImageOption(image_info,option+1,argv[i+1]);
6498 image_info->dither=MagickTrue;
6499 break;
6500 }
6501 break;
6502 }
6503 case 'e':
6504 {
6505 if (LocaleCompare("encoding",option+1) == 0)
6506 {
6507 if (*option == '+')
6508 {
6509 (void) SetImageOption(image_info,option+1,"undefined");
6510 break;
6511 }
6512 (void) SetImageOption(image_info,option+1,argv[i+1]);
6513 break;
6514 }
6515 if (LocaleCompare("endian",option+1) == 0)
6516 {
6517 if (*option == '+')
6518 {
6519 image_info->endian=UndefinedEndian;
6520 (void) SetImageOption(image_info,option+1,"undefined");
6521 break;
6522 }
cristy042ee782011-04-22 18:48:30 +00006523 image_info->endian=(EndianType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006524 MagickEndianOptions,MagickFalse,argv[i+1]);
6525 (void) SetImageOption(image_info,option+1,argv[i+1]);
6526 break;
6527 }
6528 if (LocaleCompare("extract",option+1) == 0)
6529 {
6530 /*
6531 Set image extract geometry.
6532 */
6533 if (*option == '+')
6534 {
6535 if (image_info->extract != (char *) NULL)
6536 image_info->extract=DestroyString(image_info->extract);
6537 break;
6538 }
6539 (void) CloneString(&image_info->extract,argv[i+1]);
6540 break;
6541 }
6542 break;
6543 }
6544 case 'f':
6545 {
6546 if (LocaleCompare("fill",option+1) == 0)
6547 {
6548 if (*option == '+')
6549 {
6550 (void) SetImageOption(image_info,option+1,"none");
6551 break;
6552 }
6553 (void) SetImageOption(image_info,option+1,argv[i+1]);
6554 break;
6555 }
6556 if (LocaleCompare("filter",option+1) == 0)
6557 {
6558 if (*option == '+')
6559 {
6560 (void) SetImageOption(image_info,option+1,"undefined");
6561 break;
6562 }
6563 (void) SetImageOption(image_info,option+1,argv[i+1]);
6564 break;
6565 }
6566 if (LocaleCompare("font",option+1) == 0)
6567 {
6568 if (*option == '+')
6569 {
6570 if (image_info->font != (char *) NULL)
6571 image_info->font=DestroyString(image_info->font);
6572 break;
6573 }
6574 (void) CloneString(&image_info->font,argv[i+1]);
6575 break;
6576 }
6577 if (LocaleCompare("format",option+1) == 0)
6578 {
6579 register const char
6580 *q;
6581
6582 for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
cristy9ed85672011-03-02 00:19:13 +00006583 if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00006584 image_info->ping=MagickFalse;
6585 (void) SetImageOption(image_info,option+1,argv[i+1]);
6586 break;
6587 }
6588 if (LocaleCompare("fuzz",option+1) == 0)
6589 {
6590 if (*option == '+')
6591 {
6592 image_info->fuzz=0.0;
6593 (void) SetImageOption(image_info,option+1,"0");
6594 break;
6595 }
cristydbdd0e32011-11-04 23:29:40 +00006596 image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6597 QuantumRange+1.0);
cristy3ed852e2009-09-05 21:47:34 +00006598 (void) SetImageOption(image_info,option+1,argv[i+1]);
6599 break;
6600 }
6601 break;
6602 }
6603 case 'g':
6604 {
6605 if (LocaleCompare("gravity",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 }
6615 if (LocaleCompare("green-primary",option+1) == 0)
6616 {
6617 if (*option == '+')
6618 {
6619 (void) SetImageOption(image_info,option+1,"0.0");
6620 break;
6621 }
6622 (void) SetImageOption(image_info,option+1,argv[i+1]);
6623 break;
6624 }
6625 break;
6626 }
6627 case 'i':
6628 {
6629 if (LocaleCompare("intent",option+1) == 0)
6630 {
6631 if (*option == '+')
6632 {
6633 (void) SetImageOption(image_info,option+1,"undefined");
6634 break;
6635 }
6636 (void) SetImageOption(image_info,option+1,argv[i+1]);
6637 break;
6638 }
6639 if (LocaleCompare("interlace",option+1) == 0)
6640 {
6641 if (*option == '+')
6642 {
6643 image_info->interlace=UndefinedInterlace;
6644 (void) SetImageOption(image_info,option+1,"undefined");
6645 break;
6646 }
cristy042ee782011-04-22 18:48:30 +00006647 image_info->interlace=(InterlaceType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006648 MagickInterlaceOptions,MagickFalse,argv[i+1]);
6649 (void) SetImageOption(image_info,option+1,argv[i+1]);
6650 break;
6651 }
cristyb32b90a2009-09-07 21:45:48 +00006652 if (LocaleCompare("interline-spacing",option+1) == 0)
6653 {
6654 if (*option == '+')
6655 {
6656 (void) SetImageOption(image_info,option+1,"undefined");
6657 break;
6658 }
6659 (void) SetImageOption(image_info,option+1,argv[i+1]);
6660 break;
6661 }
cristy3ed852e2009-09-05 21:47:34 +00006662 if (LocaleCompare("interpolate",option+1) == 0)
6663 {
6664 if (*option == '+')
6665 {
6666 (void) SetImageOption(image_info,option+1,"undefined");
6667 break;
6668 }
6669 (void) SetImageOption(image_info,option+1,argv[i+1]);
6670 break;
6671 }
6672 if (LocaleCompare("interword-spacing",option+1) == 0)
6673 {
6674 if (*option == '+')
6675 {
6676 (void) SetImageOption(image_info,option+1,"undefined");
6677 break;
6678 }
6679 (void) SetImageOption(image_info,option+1,argv[i+1]);
6680 break;
6681 }
6682 break;
6683 }
6684 case 'k':
6685 {
6686 if (LocaleCompare("kerning",option+1) == 0)
6687 {
6688 if (*option == '+')
6689 {
6690 (void) SetImageOption(image_info,option+1,"undefined");
6691 break;
6692 }
6693 (void) SetImageOption(image_info,option+1,argv[i+1]);
6694 break;
6695 }
6696 break;
6697 }
6698 case 'l':
6699 {
6700 if (LocaleCompare("label",option+1) == 0)
6701 {
6702 if (*option == '+')
6703 {
6704 (void) DeleteImageOption(image_info,option+1);
6705 break;
6706 }
6707 (void) SetImageOption(image_info,option+1,argv[i+1]);
6708 break;
6709 }
6710 if (LocaleCompare("limit",option+1) == 0)
6711 {
6712 MagickSizeType
6713 limit;
6714
6715 ResourceType
6716 type;
6717
6718 if (*option == '+')
6719 break;
cristy042ee782011-04-22 18:48:30 +00006720 type=(ResourceType) ParseCommandOption(MagickResourceOptions,
cristy3ed852e2009-09-05 21:47:34 +00006721 MagickFalse,argv[i+1]);
6722 limit=MagickResourceInfinity;
6723 if (LocaleCompare("unlimited",argv[i+2]) != 0)
cristyc0627342011-11-18 21:15:24 +00006724 limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
cristy3ed852e2009-09-05 21:47:34 +00006725 (void) SetMagickResourceLimit(type,limit);
6726 break;
6727 }
6728 if (LocaleCompare("list",option+1) == 0)
6729 {
cristybb503372010-05-27 20:51:26 +00006730 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00006731 list;
6732
6733 /*
6734 Display configuration list.
6735 */
cristy042ee782011-04-22 18:48:30 +00006736 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006737 switch (list)
6738 {
6739 case MagickCoderOptions:
6740 {
6741 (void) ListCoderInfo((FILE *) NULL,exception);
6742 break;
6743 }
6744 case MagickColorOptions:
6745 {
6746 (void) ListColorInfo((FILE *) NULL,exception);
6747 break;
6748 }
6749 case MagickConfigureOptions:
6750 {
6751 (void) ListConfigureInfo((FILE *) NULL,exception);
6752 break;
6753 }
6754 case MagickDelegateOptions:
6755 {
6756 (void) ListDelegateInfo((FILE *) NULL,exception);
6757 break;
6758 }
6759 case MagickFontOptions:
6760 {
6761 (void) ListTypeInfo((FILE *) NULL,exception);
6762 break;
6763 }
6764 case MagickFormatOptions:
6765 {
6766 (void) ListMagickInfo((FILE *) NULL,exception);
6767 break;
6768 }
6769 case MagickLocaleOptions:
6770 {
6771 (void) ListLocaleInfo((FILE *) NULL,exception);
6772 break;
6773 }
6774 case MagickLogOptions:
6775 {
6776 (void) ListLogInfo((FILE *) NULL,exception);
6777 break;
6778 }
6779 case MagickMagicOptions:
6780 {
6781 (void) ListMagicInfo((FILE *) NULL,exception);
6782 break;
6783 }
6784 case MagickMimeOptions:
6785 {
6786 (void) ListMimeInfo((FILE *) NULL,exception);
6787 break;
6788 }
6789 case MagickModuleOptions:
6790 {
6791 (void) ListModuleInfo((FILE *) NULL,exception);
6792 break;
6793 }
6794 case MagickPolicyOptions:
6795 {
6796 (void) ListPolicyInfo((FILE *) NULL,exception);
6797 break;
6798 }
6799 case MagickResourceOptions:
6800 {
6801 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6802 break;
6803 }
6804 case MagickThresholdOptions:
6805 {
6806 (void) ListThresholdMaps((FILE *) NULL,exception);
6807 break;
6808 }
6809 default:
6810 {
cristy042ee782011-04-22 18:48:30 +00006811 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
cristy3ed852e2009-09-05 21:47:34 +00006812 exception);
6813 break;
6814 }
6815 }
cristyaeb2cbc2010-05-07 13:28:58 +00006816 break;
cristy3ed852e2009-09-05 21:47:34 +00006817 }
6818 if (LocaleCompare("log",option+1) == 0)
6819 {
6820 if (*option == '+')
6821 break;
6822 (void) SetLogFormat(argv[i+1]);
6823 break;
6824 }
6825 if (LocaleCompare("loop",option+1) == 0)
6826 {
6827 if (*option == '+')
6828 {
6829 (void) SetImageOption(image_info,option+1,"0");
6830 break;
6831 }
6832 (void) SetImageOption(image_info,option+1,argv[i+1]);
6833 break;
6834 }
6835 break;
6836 }
6837 case 'm':
6838 {
6839 if (LocaleCompare("matte",option+1) == 0)
6840 {
6841 if (*option == '+')
6842 {
6843 (void) SetImageOption(image_info,option+1,"false");
6844 break;
6845 }
6846 (void) SetImageOption(image_info,option+1,"true");
6847 break;
6848 }
6849 if (LocaleCompare("mattecolor",option+1) == 0)
6850 {
6851 if (*option == '+')
6852 {
6853 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006854 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
cristy638895a2011-08-06 23:19:14 +00006855 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006856 break;
6857 }
6858 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy9950d572011-10-01 18:22:35 +00006859 (void) QueryColorCompliance(argv[i+1],AllCompliance,
6860 &image_info->matte_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00006861 break;
6862 }
6863 if (LocaleCompare("monitor",option+1) == 0)
6864 {
6865 (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6866 (void *) NULL);
6867 break;
6868 }
6869 if (LocaleCompare("monochrome",option+1) == 0)
6870 {
6871 image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6872 break;
6873 }
6874 break;
6875 }
6876 case 'o':
6877 {
6878 if (LocaleCompare("orient",option+1) == 0)
6879 {
6880 if (*option == '+')
6881 {
6882 image_info->orientation=UndefinedOrientation;
6883 (void) SetImageOption(image_info,option+1,"undefined");
6884 break;
6885 }
cristy042ee782011-04-22 18:48:30 +00006886 image_info->orientation=(OrientationType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006887 MagickOrientationOptions,MagickFalse,argv[i+1]);
cristyc6e214d2010-08-08 00:31:08 +00006888 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006889 break;
6890 }
6891 }
6892 case 'p':
6893 {
6894 if (LocaleCompare("page",option+1) == 0)
6895 {
6896 char
6897 *canonical_page,
6898 page[MaxTextExtent];
6899
6900 const char
6901 *image_option;
6902
6903 MagickStatusType
6904 flags;
6905
6906 RectangleInfo
6907 geometry;
6908
6909 if (*option == '+')
6910 {
6911 (void) DeleteImageOption(image_info,option+1);
6912 (void) CloneString(&image_info->page,(char *) NULL);
6913 break;
6914 }
6915 (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6916 image_option=GetImageOption(image_info,"page");
6917 if (image_option != (const char *) NULL)
6918 flags=ParseAbsoluteGeometry(image_option,&geometry);
6919 canonical_page=GetPageGeometry(argv[i+1]);
6920 flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6921 canonical_page=DestroyString(canonical_page);
cristyb51dff52011-05-19 16:55:47 +00006922 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
cristyf2faecf2010-05-28 19:19:36 +00006923 (unsigned long) geometry.width,(unsigned long) geometry.height);
cristy3ed852e2009-09-05 21:47:34 +00006924 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
cristyb51dff52011-05-19 16:55:47 +00006925 (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
cristyf2faecf2010-05-28 19:19:36 +00006926 (unsigned long) geometry.width,(unsigned long) geometry.height,
6927 (long) geometry.x,(long) geometry.y);
cristy3ed852e2009-09-05 21:47:34 +00006928 (void) SetImageOption(image_info,option+1,page);
6929 (void) CloneString(&image_info->page,page);
6930 break;
6931 }
cristy3ed852e2009-09-05 21:47:34 +00006932 if (LocaleCompare("ping",option+1) == 0)
6933 {
6934 image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6935 break;
6936 }
6937 if (LocaleCompare("pointsize",option+1) == 0)
6938 {
6939 if (*option == '+')
6940 geometry_info.rho=0.0;
6941 else
6942 (void) ParseGeometry(argv[i+1],&geometry_info);
6943 image_info->pointsize=geometry_info.rho;
6944 break;
6945 }
cristye7f51092010-01-17 00:39:37 +00006946 if (LocaleCompare("precision",option+1) == 0)
6947 {
cristybf2766a2010-01-17 03:33:23 +00006948 (void) SetMagickPrecision(StringToInteger(argv[i+1]));
cristye7f51092010-01-17 00:39:37 +00006949 break;
6950 }
cristy3ed852e2009-09-05 21:47:34 +00006951 if (LocaleCompare("preview",option+1) == 0)
6952 {
6953 /*
6954 Preview image.
6955 */
6956 if (*option == '+')
6957 {
6958 image_info->preview_type=UndefinedPreview;
6959 break;
6960 }
cristy042ee782011-04-22 18:48:30 +00006961 image_info->preview_type=(PreviewType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00006962 MagickPreviewOptions,MagickFalse,argv[i+1]);
6963 break;
6964 }
6965 break;
6966 }
6967 case 'q':
6968 {
6969 if (LocaleCompare("quality",option+1) == 0)
6970 {
6971 /*
6972 Set image compression quality.
6973 */
6974 if (*option == '+')
6975 {
6976 image_info->quality=UndefinedCompressionQuality;
6977 (void) SetImageOption(image_info,option+1,"0");
6978 break;
6979 }
cristye27293e2009-12-18 02:53:20 +00006980 image_info->quality=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00006981 (void) SetImageOption(image_info,option+1,argv[i+1]);
6982 break;
6983 }
6984 if (LocaleCompare("quiet",option+1) == 0)
6985 {
6986 static WarningHandler
6987 warning_handler = (WarningHandler) NULL;
6988
6989 if (*option == '+')
6990 {
6991 /*
6992 Restore error or warning messages.
6993 */
6994 warning_handler=SetWarningHandler(warning_handler);
6995 break;
6996 }
6997 /*
6998 Suppress error or warning messages.
6999 */
7000 warning_handler=SetWarningHandler((WarningHandler) NULL);
7001 break;
7002 }
7003 break;
7004 }
7005 case 'r':
7006 {
7007 if (LocaleCompare("red-primary",option+1) == 0)
7008 {
7009 if (*option == '+')
7010 {
7011 (void) SetImageOption(image_info,option+1,"0.0");
7012 break;
7013 }
7014 (void) SetImageOption(image_info,option+1,argv[i+1]);
7015 break;
7016 }
7017 break;
7018 }
7019 case 's':
7020 {
7021 if (LocaleCompare("sampling-factor",option+1) == 0)
7022 {
7023 /*
7024 Set image sampling factor.
7025 */
7026 if (*option == '+')
7027 {
7028 if (image_info->sampling_factor != (char *) NULL)
7029 image_info->sampling_factor=DestroyString(
7030 image_info->sampling_factor);
7031 break;
7032 }
7033 (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7034 break;
7035 }
7036 if (LocaleCompare("scene",option+1) == 0)
7037 {
7038 /*
7039 Set image scene.
7040 */
7041 if (*option == '+')
7042 {
7043 image_info->scene=0;
7044 (void) SetImageOption(image_info,option+1,"0");
7045 break;
7046 }
cristye27293e2009-12-18 02:53:20 +00007047 image_info->scene=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007048 (void) SetImageOption(image_info,option+1,argv[i+1]);
7049 break;
7050 }
7051 if (LocaleCompare("seed",option+1) == 0)
7052 {
cristybb503372010-05-27 20:51:26 +00007053 size_t
cristy3ed852e2009-09-05 21:47:34 +00007054 seed;
7055
7056 if (*option == '+')
7057 {
cristybb503372010-05-27 20:51:26 +00007058 seed=(size_t) time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007059 SeedPseudoRandomGenerator(seed);
7060 break;
7061 }
cristye27293e2009-12-18 02:53:20 +00007062 seed=StringToUnsignedLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007063 SeedPseudoRandomGenerator(seed);
7064 break;
7065 }
7066 if (LocaleCompare("size",option+1) == 0)
7067 {
7068 if (*option == '+')
7069 {
7070 if (image_info->size != (char *) NULL)
7071 image_info->size=DestroyString(image_info->size);
7072 break;
7073 }
7074 (void) CloneString(&image_info->size,argv[i+1]);
7075 break;
7076 }
7077 if (LocaleCompare("stroke",option+1) == 0)
7078 {
7079 if (*option == '+')
7080 {
7081 (void) SetImageOption(image_info,option+1,"none");
7082 break;
7083 }
7084 (void) SetImageOption(image_info,option+1,argv[i+1]);
7085 break;
7086 }
7087 if (LocaleCompare("strokewidth",option+1) == 0)
7088 {
7089 if (*option == '+')
7090 {
7091 (void) SetImageOption(image_info,option+1,"0");
7092 break;
7093 }
7094 (void) SetImageOption(image_info,option+1,argv[i+1]);
7095 break;
7096 }
cristyd9a29192010-10-16 16:49:53 +00007097 if (LocaleCompare("synchronize",option+1) == 0)
7098 {
7099 if (*option == '+')
7100 {
7101 image_info->synchronize=MagickFalse;
7102 break;
7103 }
7104 image_info->synchronize=MagickTrue;
7105 break;
7106 }
cristy3ed852e2009-09-05 21:47:34 +00007107 break;
7108 }
7109 case 't':
7110 {
7111 if (LocaleCompare("taint",option+1) == 0)
7112 {
7113 if (*option == '+')
7114 {
7115 (void) SetImageOption(image_info,option+1,"false");
7116 break;
7117 }
7118 (void) SetImageOption(image_info,option+1,"true");
7119 break;
7120 }
7121 if (LocaleCompare("texture",option+1) == 0)
7122 {
7123 if (*option == '+')
7124 {
7125 if (image_info->texture != (char *) NULL)
7126 image_info->texture=DestroyString(image_info->texture);
7127 break;
7128 }
7129 (void) CloneString(&image_info->texture,argv[i+1]);
7130 break;
7131 }
7132 if (LocaleCompare("tile-offset",option+1) == 0)
7133 {
7134 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007135 (void) SetImageOption(image_info,option+1,"0");
7136 else
7137 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007138 break;
7139 }
7140 if (LocaleCompare("transparent-color",option+1) == 0)
7141 {
7142 if (*option == '+')
7143 {
cristy9950d572011-10-01 18:22:35 +00007144 (void) QueryColorCompliance("none",AllCompliance,
7145 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007146 (void) SetImageOption(image_info,option+1,"none");
7147 break;
7148 }
cristy9950d572011-10-01 18:22:35 +00007149 (void) QueryColorCompliance(argv[i+1],AllCompliance,
7150 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00007151 (void) SetImageOption(image_info,option+1,argv[i+1]);
7152 break;
7153 }
7154 if (LocaleCompare("type",option+1) == 0)
7155 {
7156 if (*option == '+')
7157 {
cristy5f1c1ff2010-12-23 21:38:06 +00007158 image_info->type=UndefinedType;
cristy3ed852e2009-09-05 21:47:34 +00007159 (void) SetImageOption(image_info,option+1,"undefined");
7160 break;
7161 }
cristy042ee782011-04-22 18:48:30 +00007162 image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
cristy3ed852e2009-09-05 21:47:34 +00007163 MagickFalse,argv[i+1]);
7164 (void) SetImageOption(image_info,option+1,argv[i+1]);
7165 break;
7166 }
7167 break;
7168 }
7169 case 'u':
7170 {
7171 if (LocaleCompare("undercolor",option+1) == 0)
7172 {
7173 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007174 (void) DeleteImageOption(image_info,option+1);
7175 else
7176 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007177 break;
7178 }
7179 if (LocaleCompare("units",option+1) == 0)
7180 {
7181 if (*option == '+')
7182 {
7183 image_info->units=UndefinedResolution;
7184 (void) SetImageOption(image_info,option+1,"undefined");
7185 break;
7186 }
cristy042ee782011-04-22 18:48:30 +00007187 image_info->units=(ResolutionType) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007188 MagickResolutionOptions,MagickFalse,argv[i+1]);
7189 (void) SetImageOption(image_info,option+1,argv[i+1]);
7190 break;
7191 }
7192 break;
7193 }
7194 case 'v':
7195 {
7196 if (LocaleCompare("verbose",option+1) == 0)
7197 {
7198 if (*option == '+')
7199 {
7200 image_info->verbose=MagickFalse;
7201 break;
7202 }
7203 image_info->verbose=MagickTrue;
7204 image_info->ping=MagickFalse;
7205 break;
7206 }
7207 if (LocaleCompare("view",option+1) == 0)
7208 {
7209 if (*option == '+')
7210 {
7211 if (image_info->view != (char *) NULL)
7212 image_info->view=DestroyString(image_info->view);
7213 break;
7214 }
7215 (void) CloneString(&image_info->view,argv[i+1]);
7216 break;
7217 }
7218 if (LocaleCompare("virtual-pixel",option+1) == 0)
7219 {
7220 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007221 (void) SetImageOption(image_info,option+1,"undefined");
7222 else
7223 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007224 break;
7225 }
7226 break;
7227 }
7228 case 'w':
7229 {
7230 if (LocaleCompare("white-point",option+1) == 0)
7231 {
7232 if (*option == '+')
anthonyfd706f92012-01-19 04:22:02 +00007233 (void) SetImageOption(image_info,option+1,"0.0");
7234 else
7235 (void) SetImageOption(image_info,option+1,argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007236 break;
7237 }
7238 break;
7239 }
7240 default:
7241 break;
7242 }
7243 i+=count;
7244 }
7245 return(MagickTrue);
7246}
7247
7248/*
7249%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7250% %
7251% %
7252% %
7253+ M o g r i f y I m a g e L i s t %
7254% %
7255% %
7256% %
7257%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7258%
7259% MogrifyImageList() applies any command line options that might affect the
7260% entire image list (e.g. -append, -coalesce, etc.).
7261%
7262% The format of the MogrifyImage method is:
7263%
7264% MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7265% const char **argv,Image **images,ExceptionInfo *exception)
7266%
7267% A description of each parameter follows:
7268%
7269% o image_info: the image info..
7270%
7271% o argc: Specifies a pointer to an integer describing the number of
7272% elements in the argument vector.
7273%
7274% o argv: Specifies a pointer to a text array containing the command line
7275% arguments.
7276%
anthonye9c27192011-03-27 08:07:06 +00007277% o images: pointer to pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00007278%
7279% o exception: return any errors or warnings in this structure.
7280%
7281*/
7282WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7283 const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7284{
cristy3ed852e2009-09-05 21:47:34 +00007285 const char
7286 *option;
7287
cristy6b3da3a2010-06-20 02:21:46 +00007288 ImageInfo
7289 *mogrify_info;
cristy3ed852e2009-09-05 21:47:34 +00007290
7291 MagickStatusType
7292 status;
7293
cristy28474bf2011-09-11 23:32:52 +00007294 PixelInterpolateMethod
7295 interpolate_method;
7296
cristy3ed852e2009-09-05 21:47:34 +00007297 QuantizeInfo
7298 *quantize_info;
7299
cristybb503372010-05-27 20:51:26 +00007300 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00007301 i;
7302
cristy6b3da3a2010-06-20 02:21:46 +00007303 ssize_t
7304 count,
7305 index;
7306
cristy3ed852e2009-09-05 21:47:34 +00007307 /*
7308 Apply options to the image list.
7309 */
7310 assert(image_info != (ImageInfo *) NULL);
7311 assert(image_info->signature == MagickSignature);
7312 assert(images != (Image **) NULL);
anthonye9c27192011-03-27 08:07:06 +00007313 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00007314 assert((*images)->signature == MagickSignature);
7315 if ((*images)->debug != MagickFalse)
7316 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7317 (*images)->filename);
7318 if ((argc <= 0) || (*argv == (char *) NULL))
7319 return(MagickTrue);
cristy28474bf2011-09-11 23:32:52 +00007320 interpolate_method=UndefinedInterpolatePixel;
cristy6b3da3a2010-06-20 02:21:46 +00007321 mogrify_info=CloneImageInfo(image_info);
7322 quantize_info=AcquireQuantizeInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00007323 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00007324 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +00007325 {
cristy74fe8f12009-10-03 19:09:01 +00007326 if (*images == (Image *) NULL)
7327 break;
cristy3ed852e2009-09-05 21:47:34 +00007328 option=argv[i];
cristy042ee782011-04-22 18:48:30 +00007329 if (IsCommandOption(option) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00007330 continue;
cristy042ee782011-04-22 18:48:30 +00007331 count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
anthonyce2716b2011-04-22 09:51:34 +00007332 count=MagickMax(count,0L);
cristycee97112010-05-28 00:44:52 +00007333 if ((i+count) >= (ssize_t) argc)
cristy3ed852e2009-09-05 21:47:34 +00007334 break;
cristy6b3da3a2010-06-20 02:21:46 +00007335 status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
cristy3ed852e2009-09-05 21:47:34 +00007336 switch (*(option+1))
7337 {
7338 case 'a':
7339 {
7340 if (LocaleCompare("affinity",option+1) == 0)
7341 {
cristy6fccee12011-10-20 18:43:18 +00007342 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007343 if (*option == '+')
7344 {
cristy018f07f2011-09-04 21:15:19 +00007345 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7346 exception);
cristy3ed852e2009-09-05 21:47:34 +00007347 break;
7348 }
7349 i++;
7350 break;
7351 }
7352 if (LocaleCompare("append",option+1) == 0)
7353 {
7354 Image
7355 *append_image;
7356
cristy6fccee12011-10-20 18:43:18 +00007357 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007358 append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7359 MagickFalse,exception);
7360 if (append_image == (Image *) NULL)
7361 {
7362 status=MagickFalse;
7363 break;
7364 }
7365 *images=DestroyImageList(*images);
7366 *images=append_image;
7367 break;
7368 }
7369 if (LocaleCompare("average",option+1) == 0)
7370 {
7371 Image
7372 *average_image;
7373
cristyd18ae7c2010-03-07 17:39:52 +00007374 /*
7375 Average an image sequence (deprecated).
7376 */
cristy6fccee12011-10-20 18:43:18 +00007377 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007378 average_image=EvaluateImages(*images,MeanEvaluateOperator,
7379 exception);
cristy3ed852e2009-09-05 21:47:34 +00007380 if (average_image == (Image *) NULL)
7381 {
7382 status=MagickFalse;
7383 break;
7384 }
7385 *images=DestroyImageList(*images);
7386 *images=average_image;
7387 break;
7388 }
7389 break;
7390 }
7391 case 'c':
7392 {
cristy87c02f42012-02-24 00:19:10 +00007393 if (LocaleCompare("channel-inject",option+1) == 0)
7394 {
7395 puts("stand by...");
7396 break;
7397 }
cristy3ed852e2009-09-05 21:47:34 +00007398 if (LocaleCompare("clut",option+1) == 0)
7399 {
7400 Image
7401 *clut_image,
7402 *image;
7403
cristy6fccee12011-10-20 18:43:18 +00007404 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007405 image=RemoveFirstImageFromList(images);
7406 clut_image=RemoveFirstImageFromList(images);
7407 if (clut_image == (Image *) NULL)
7408 {
7409 status=MagickFalse;
7410 break;
7411 }
cristy28474bf2011-09-11 23:32:52 +00007412 (void) ClutImage(image,clut_image,interpolate_method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007413 clut_image=DestroyImage(clut_image);
cristy3ed852e2009-09-05 21:47:34 +00007414 *images=DestroyImageList(*images);
7415 *images=image;
7416 break;
7417 }
7418 if (LocaleCompare("coalesce",option+1) == 0)
7419 {
7420 Image
7421 *coalesce_image;
7422
cristy6fccee12011-10-20 18:43:18 +00007423 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007424 coalesce_image=CoalesceImages(*images,exception);
7425 if (coalesce_image == (Image *) NULL)
7426 {
7427 status=MagickFalse;
7428 break;
7429 }
7430 *images=DestroyImageList(*images);
7431 *images=coalesce_image;
7432 break;
7433 }
7434 if (LocaleCompare("combine",option+1) == 0)
7435 {
7436 Image
7437 *combine_image;
7438
cristy6fccee12011-10-20 18:43:18 +00007439 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3139dc22011-07-08 00:11:42 +00007440 combine_image=CombineImages(*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007441 if (combine_image == (Image *) NULL)
7442 {
7443 status=MagickFalse;
7444 break;
7445 }
7446 *images=DestroyImageList(*images);
7447 *images=combine_image;
7448 break;
7449 }
7450 if (LocaleCompare("composite",option+1) == 0)
7451 {
7452 Image
7453 *mask_image,
7454 *composite_image,
7455 *image;
7456
7457 RectangleInfo
7458 geometry;
7459
cristy6fccee12011-10-20 18:43:18 +00007460 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007461 image=RemoveFirstImageFromList(images);
7462 composite_image=RemoveFirstImageFromList(images);
7463 if (composite_image == (Image *) NULL)
7464 {
7465 status=MagickFalse;
7466 break;
7467 }
7468 (void) TransformImage(&composite_image,(char *) NULL,
cristye941a752011-10-15 01:52:48 +00007469 composite_image->geometry,exception);
cristy3ed852e2009-09-05 21:47:34 +00007470 SetGeometry(composite_image,&geometry);
7471 (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7472 GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7473 &geometry);
7474 mask_image=RemoveFirstImageFromList(images);
7475 if (mask_image != (Image *) NULL)
7476 {
7477 if ((image->compose == DisplaceCompositeOp) ||
7478 (image->compose == DistortCompositeOp))
7479 {
7480 /*
7481 Merge Y displacement into X displacement image.
7482 */
7483 (void) CompositeImage(composite_image,CopyGreenCompositeOp,
cristye941a752011-10-15 01:52:48 +00007484 mask_image,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00007485 mask_image=DestroyImage(mask_image);
7486 }
7487 else
7488 {
7489 /*
anthony80c37752012-01-16 01:03:11 +00007490 Set a blending mask for the composition.
cristy3ed852e2009-09-05 21:47:34 +00007491 */
cristy10a6c612012-01-29 21:41:05 +00007492 (void) NegateImage(mask_image,MagickFalse,exception);
7493 (void) SetImageMask(image,mask_image,exception);
7494 mask_image=DestroyImage(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00007495 }
7496 }
cristyf4ad9df2011-07-08 16:49:03 +00007497 (void) CompositeImage(image,image->compose,composite_image,
cristye941a752011-10-15 01:52:48 +00007498 geometry.x,geometry.y,exception);
cristy10a6c612012-01-29 21:41:05 +00007499 (void) SetImageMask(image,(Image *) NULL,exception);
cristy3ed852e2009-09-05 21:47:34 +00007500 composite_image=DestroyImage(composite_image);
cristy3ed852e2009-09-05 21:47:34 +00007501 *images=DestroyImageList(*images);
7502 *images=image;
7503 break;
7504 }
cristy3ed852e2009-09-05 21:47:34 +00007505 break;
7506 }
7507 case 'd':
7508 {
7509 if (LocaleCompare("deconstruct",option+1) == 0)
7510 {
7511 Image
7512 *deconstruct_image;
7513
cristy6fccee12011-10-20 18:43:18 +00007514 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8a9106f2011-07-05 14:39:26 +00007515 deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
cristy4c08aed2011-07-01 19:47:50 +00007516 exception);
cristy3ed852e2009-09-05 21:47:34 +00007517 if (deconstruct_image == (Image *) NULL)
7518 {
7519 status=MagickFalse;
7520 break;
7521 }
7522 *images=DestroyImageList(*images);
7523 *images=deconstruct_image;
7524 break;
7525 }
7526 if (LocaleCompare("delete",option+1) == 0)
7527 {
7528 if (*option == '+')
7529 DeleteImages(images,"-1",exception);
7530 else
7531 DeleteImages(images,argv[i+1],exception);
7532 break;
7533 }
7534 if (LocaleCompare("dither",option+1) == 0)
7535 {
7536 if (*option == '+')
7537 {
7538 quantize_info->dither=MagickFalse;
7539 break;
7540 }
7541 quantize_info->dither=MagickTrue;
cristy042ee782011-04-22 18:48:30 +00007542 quantize_info->dither_method=(DitherMethod) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007543 MagickDitherOptions,MagickFalse,argv[i+1]);
7544 break;
7545 }
cristyecb10ff2011-03-22 13:14:03 +00007546 if (LocaleCompare("duplicate",option+1) == 0)
7547 {
cristy72988482011-03-29 16:34:38 +00007548 Image
7549 *duplicate_images;
cristybf95deb2011-03-23 00:25:36 +00007550
anthony2b6bcae2011-03-23 13:05:34 +00007551 if (*option == '+')
cristy72988482011-03-29 16:34:38 +00007552 duplicate_images=DuplicateImages(*images,1,"-1",exception);
7553 else
7554 {
7555 const char
7556 *p;
7557
anthony2b6bcae2011-03-23 13:05:34 +00007558 size_t
7559 number_duplicates;
anthony9bd15492011-03-23 02:11:13 +00007560
anthony2b6bcae2011-03-23 13:05:34 +00007561 number_duplicates=(size_t) StringToLong(argv[i+1]);
cristy72988482011-03-29 16:34:38 +00007562 p=strchr(argv[i+1],',');
7563 if (p == (const char *) NULL)
7564 duplicate_images=DuplicateImages(*images,number_duplicates,
7565 "-1",exception);
anthony2b6bcae2011-03-23 13:05:34 +00007566 else
cristy72988482011-03-29 16:34:38 +00007567 duplicate_images=DuplicateImages(*images,number_duplicates,p,
7568 exception);
anthony2b6bcae2011-03-23 13:05:34 +00007569 }
7570 AppendImageToList(images, duplicate_images);
cristy6fccee12011-10-20 18:43:18 +00007571 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyecb10ff2011-03-22 13:14:03 +00007572 break;
7573 }
cristy3ed852e2009-09-05 21:47:34 +00007574 break;
7575 }
cristyd18ae7c2010-03-07 17:39:52 +00007576 case 'e':
7577 {
7578 if (LocaleCompare("evaluate-sequence",option+1) == 0)
7579 {
7580 Image
7581 *evaluate_image;
7582
7583 MagickEvaluateOperator
7584 op;
7585
cristy6fccee12011-10-20 18:43:18 +00007586 (void) SyncImageSettings(mogrify_info,*images,exception);
cristy28474bf2011-09-11 23:32:52 +00007587 op=(MagickEvaluateOperator) ParseCommandOption(
7588 MagickEvaluateOptions,MagickFalse,argv[i+1]);
cristyd18ae7c2010-03-07 17:39:52 +00007589 evaluate_image=EvaluateImages(*images,op,exception);
7590 if (evaluate_image == (Image *) NULL)
7591 {
7592 status=MagickFalse;
7593 break;
7594 }
7595 *images=DestroyImageList(*images);
7596 *images=evaluate_image;
7597 break;
7598 }
7599 break;
7600 }
cristy3ed852e2009-09-05 21:47:34 +00007601 case 'f':
7602 {
cristyf0a247f2009-10-04 00:20:03 +00007603 if (LocaleCompare("fft",option+1) == 0)
7604 {
7605 Image
7606 *fourier_image;
7607
7608 /*
7609 Implements the discrete Fourier transform (DFT).
7610 */
cristy6fccee12011-10-20 18:43:18 +00007611 (void) SyncImageSettings(mogrify_info,*images,exception);
cristyf0a247f2009-10-04 00:20:03 +00007612 fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7613 MagickTrue : MagickFalse,exception);
7614 if (fourier_image == (Image *) NULL)
7615 break;
7616 *images=DestroyImage(*images);
7617 *images=fourier_image;
7618 break;
7619 }
cristy3ed852e2009-09-05 21:47:34 +00007620 if (LocaleCompare("flatten",option+1) == 0)
7621 {
7622 Image
7623 *flatten_image;
7624
cristy6fccee12011-10-20 18:43:18 +00007625 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007626 flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7627 if (flatten_image == (Image *) NULL)
7628 break;
7629 *images=DestroyImageList(*images);
7630 *images=flatten_image;
7631 break;
7632 }
7633 if (LocaleCompare("fx",option+1) == 0)
7634 {
7635 Image
7636 *fx_image;
7637
cristy6fccee12011-10-20 18:43:18 +00007638 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy490408a2011-07-07 14:42:05 +00007639 fx_image=FxImage(*images,argv[i+1],exception);
cristy3ed852e2009-09-05 21:47:34 +00007640 if (fx_image == (Image *) NULL)
7641 {
7642 status=MagickFalse;
7643 break;
7644 }
7645 *images=DestroyImageList(*images);
7646 *images=fx_image;
7647 break;
7648 }
7649 break;
7650 }
7651 case 'h':
7652 {
7653 if (LocaleCompare("hald-clut",option+1) == 0)
7654 {
7655 Image
7656 *hald_image,
7657 *image;
7658
cristy6fccee12011-10-20 18:43:18 +00007659 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007660 image=RemoveFirstImageFromList(images);
7661 hald_image=RemoveFirstImageFromList(images);
7662 if (hald_image == (Image *) NULL)
7663 {
7664 status=MagickFalse;
7665 break;
7666 }
cristy7c0a0a42011-08-23 17:57:25 +00007667 (void) HaldClutImage(image,hald_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00007668 hald_image=DestroyImage(hald_image);
cristy0aff6ea2009-11-14 01:40:53 +00007669 if (*images != (Image *) NULL)
7670 *images=DestroyImageList(*images);
cristy3ed852e2009-09-05 21:47:34 +00007671 *images=image;
7672 break;
7673 }
7674 break;
7675 }
7676 case 'i':
7677 {
7678 if (LocaleCompare("ift",option+1) == 0)
7679 {
7680 Image
cristy8587f882009-11-13 20:28:49 +00007681 *fourier_image,
7682 *magnitude_image,
7683 *phase_image;
cristy3ed852e2009-09-05 21:47:34 +00007684
7685 /*
7686 Implements the inverse fourier discrete Fourier transform (DFT).
7687 */
cristy6fccee12011-10-20 18:43:18 +00007688 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy8587f882009-11-13 20:28:49 +00007689 magnitude_image=RemoveFirstImageFromList(images);
7690 phase_image=RemoveFirstImageFromList(images);
7691 if (phase_image == (Image *) NULL)
7692 {
7693 status=MagickFalse;
7694 break;
7695 }
7696 fourier_image=InverseFourierTransformImage(magnitude_image,
7697 phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
cristy3ed852e2009-09-05 21:47:34 +00007698 if (fourier_image == (Image *) NULL)
7699 break;
cristy0aff6ea2009-11-14 01:40:53 +00007700 if (*images != (Image *) NULL)
7701 *images=DestroyImage(*images);
cristy3ed852e2009-09-05 21:47:34 +00007702 *images=fourier_image;
7703 break;
7704 }
7705 if (LocaleCompare("insert",option+1) == 0)
7706 {
7707 Image
7708 *p,
7709 *q;
7710
7711 index=0;
7712 if (*option != '+')
cristy32c2aea2010-12-01 01:00:50 +00007713 index=(ssize_t) StringToLong(argv[i+1]);
cristy3ed852e2009-09-05 21:47:34 +00007714 p=RemoveLastImageFromList(images);
7715 if (p == (Image *) NULL)
7716 {
7717 (void) ThrowMagickException(exception,GetMagickModule(),
7718 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7719 status=MagickFalse;
7720 break;
7721 }
7722 q=p;
7723 if (index == 0)
7724 PrependImageToList(images,q);
7725 else
cristybb503372010-05-27 20:51:26 +00007726 if (index == (ssize_t) GetImageListLength(*images))
cristy3ed852e2009-09-05 21:47:34 +00007727 AppendImageToList(images,q);
7728 else
7729 {
7730 q=GetImageFromList(*images,index-1);
7731 if (q == (Image *) NULL)
7732 {
7733 (void) ThrowMagickException(exception,GetMagickModule(),
7734 OptionError,"NoSuchImage","`%s'",argv[i+1]);
7735 status=MagickFalse;
7736 break;
7737 }
7738 InsertImageInList(&q,p);
7739 }
7740 *images=GetFirstImageInList(q);
7741 break;
7742 }
cristy28474bf2011-09-11 23:32:52 +00007743 if (LocaleCompare("interpolate",option+1) == 0)
7744 {
7745 interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7746 MagickInterpolateOptions,MagickFalse,argv[i+1]);
7747 break;
7748 }
cristy3ed852e2009-09-05 21:47:34 +00007749 break;
7750 }
7751 case 'l':
7752 {
7753 if (LocaleCompare("layers",option+1) == 0)
7754 {
7755 Image
7756 *layers;
7757
7758 ImageLayerMethod
7759 method;
7760
cristy6fccee12011-10-20 18:43:18 +00007761 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007762 layers=(Image *) NULL;
cristy042ee782011-04-22 18:48:30 +00007763 method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
cristy3ed852e2009-09-05 21:47:34 +00007764 MagickFalse,argv[i+1]);
7765 switch (method)
7766 {
7767 case CoalesceLayer:
7768 {
7769 layers=CoalesceImages(*images,exception);
7770 break;
7771 }
7772 case CompareAnyLayer:
7773 case CompareClearLayer:
7774 case CompareOverlayLayer:
7775 default:
7776 {
cristy8a9106f2011-07-05 14:39:26 +00007777 layers=CompareImagesLayers(*images,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00007778 break;
7779 }
7780 case MergeLayer:
7781 case FlattenLayer:
7782 case MosaicLayer:
7783 case TrimBoundsLayer:
7784 {
7785 layers=MergeImageLayers(*images,method,exception);
7786 break;
7787 }
7788 case DisposeLayer:
7789 {
7790 layers=DisposeImages(*images,exception);
7791 break;
7792 }
7793 case OptimizeImageLayer:
7794 {
7795 layers=OptimizeImageLayers(*images,exception);
7796 break;
7797 }
7798 case OptimizePlusLayer:
7799 {
7800 layers=OptimizePlusImageLayers(*images,exception);
7801 break;
7802 }
7803 case OptimizeTransLayer:
7804 {
7805 OptimizeImageTransparency(*images,exception);
7806 break;
7807 }
7808 case RemoveDupsLayer:
7809 {
7810 RemoveDuplicateLayers(images,exception);
7811 break;
7812 }
7813 case RemoveZeroLayer:
7814 {
7815 RemoveZeroDelayLayers(images,exception);
7816 break;
7817 }
7818 case OptimizeLayer:
7819 {
7820 /*
7821 General Purpose, GIF Animation Optimizer.
7822 */
7823 layers=CoalesceImages(*images,exception);
7824 if (layers == (Image *) NULL)
7825 {
7826 status=MagickFalse;
7827 break;
7828 }
cristy3ed852e2009-09-05 21:47:34 +00007829 *images=DestroyImageList(*images);
7830 *images=layers;
7831 layers=OptimizeImageLayers(*images,exception);
7832 if (layers == (Image *) NULL)
7833 {
7834 status=MagickFalse;
7835 break;
7836 }
cristy3ed852e2009-09-05 21:47:34 +00007837 *images=DestroyImageList(*images);
7838 *images=layers;
7839 layers=(Image *) NULL;
7840 OptimizeImageTransparency(*images,exception);
cristy018f07f2011-09-04 21:15:19 +00007841 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7842 exception);
cristy3ed852e2009-09-05 21:47:34 +00007843 break;
7844 }
7845 case CompositeLayer:
7846 {
7847 CompositeOperator
7848 compose;
7849
7850 Image
7851 *source;
7852
7853 RectangleInfo
7854 geometry;
7855
7856 /*
7857 Split image sequence at the first 'NULL:' image.
7858 */
7859 source=(*images);
7860 while (source != (Image *) NULL)
7861 {
7862 source=GetNextImageInList(source);
7863 if ((source != (Image *) NULL) &&
7864 (LocaleCompare(source->magick,"NULL") == 0))
7865 break;
7866 }
7867 if (source != (Image *) NULL)
7868 {
7869 if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7870 (GetNextImageInList(source) == (Image *) NULL))
7871 source=(Image *) NULL;
7872 else
7873 {
7874 /*
7875 Separate the two lists, junk the null: image.
7876 */
7877 source=SplitImageList(source->previous);
7878 DeleteImageFromList(&source);
7879 }
7880 }
7881 if (source == (Image *) NULL)
7882 {
7883 (void) ThrowMagickException(exception,GetMagickModule(),
7884 OptionError,"MissingNullSeparator","layers Composite");
7885 status=MagickFalse;
7886 break;
7887 }
7888 /*
7889 Adjust offset with gravity and virtual canvas.
7890 */
7891 SetGeometry(*images,&geometry);
7892 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7893 geometry.width=source->page.width != 0 ?
7894 source->page.width : source->columns;
7895 geometry.height=source->page.height != 0 ?
7896 source->page.height : source->rows;
7897 GravityAdjustGeometry((*images)->page.width != 0 ?
7898 (*images)->page.width : (*images)->columns,
7899 (*images)->page.height != 0 ? (*images)->page.height :
7900 (*images)->rows,(*images)->gravity,&geometry);
7901 compose=OverCompositeOp;
cristy6b3da3a2010-06-20 02:21:46 +00007902 option=GetImageOption(mogrify_info,"compose");
cristy3ed852e2009-09-05 21:47:34 +00007903 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00007904 compose=(CompositeOperator) ParseCommandOption(
cristy3ed852e2009-09-05 21:47:34 +00007905 MagickComposeOptions,MagickFalse,option);
7906 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7907 exception);
7908 source=DestroyImageList(source);
7909 break;
7910 }
7911 }
7912 if (layers == (Image *) NULL)
7913 break;
cristy3ed852e2009-09-05 21:47:34 +00007914 *images=DestroyImageList(*images);
7915 *images=layers;
7916 break;
7917 }
7918 break;
7919 }
7920 case 'm':
7921 {
7922 if (LocaleCompare("map",option+1) == 0)
7923 {
cristy6fccee12011-10-20 18:43:18 +00007924 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007925 if (*option == '+')
7926 {
cristy018f07f2011-09-04 21:15:19 +00007927 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7928 exception);
cristy3ed852e2009-09-05 21:47:34 +00007929 break;
7930 }
7931 i++;
7932 break;
7933 }
cristyf40785b2010-03-06 02:27:27 +00007934 if (LocaleCompare("maximum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007935 {
7936 Image
cristyf40785b2010-03-06 02:27:27 +00007937 *maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007938
cristyd18ae7c2010-03-07 17:39:52 +00007939 /*
7940 Maximum image sequence (deprecated).
7941 */
cristy6fccee12011-10-20 18:43:18 +00007942 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007943 maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007944 if (maximum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007945 {
7946 status=MagickFalse;
7947 break;
7948 }
7949 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007950 *images=maximum_image;
cristy1c274c92010-03-06 02:06:45 +00007951 break;
7952 }
cristyf40785b2010-03-06 02:27:27 +00007953 if (LocaleCompare("minimum",option+1) == 0)
cristy1c274c92010-03-06 02:06:45 +00007954 {
7955 Image
cristyf40785b2010-03-06 02:27:27 +00007956 *minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007957
cristyd18ae7c2010-03-07 17:39:52 +00007958 /*
7959 Minimum image sequence (deprecated).
7960 */
cristy6fccee12011-10-20 18:43:18 +00007961 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyd18ae7c2010-03-07 17:39:52 +00007962 minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
cristyf40785b2010-03-06 02:27:27 +00007963 if (minimum_image == (Image *) NULL)
cristy1c274c92010-03-06 02:06:45 +00007964 {
7965 status=MagickFalse;
7966 break;
7967 }
7968 *images=DestroyImageList(*images);
cristyf40785b2010-03-06 02:27:27 +00007969 *images=minimum_image;
cristy1c274c92010-03-06 02:06:45 +00007970 break;
7971 }
cristy3ed852e2009-09-05 21:47:34 +00007972 if (LocaleCompare("morph",option+1) == 0)
7973 {
7974 Image
7975 *morph_image;
7976
cristy6fccee12011-10-20 18:43:18 +00007977 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristye27293e2009-12-18 02:53:20 +00007978 morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
cristy3ed852e2009-09-05 21:47:34 +00007979 exception);
7980 if (morph_image == (Image *) NULL)
7981 {
7982 status=MagickFalse;
7983 break;
7984 }
7985 *images=DestroyImageList(*images);
7986 *images=morph_image;
7987 break;
7988 }
7989 if (LocaleCompare("mosaic",option+1) == 0)
7990 {
7991 Image
7992 *mosaic_image;
7993
cristy6fccee12011-10-20 18:43:18 +00007994 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00007995 mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
7996 if (mosaic_image == (Image *) NULL)
7997 {
7998 status=MagickFalse;
7999 break;
8000 }
8001 *images=DestroyImageList(*images);
8002 *images=mosaic_image;
8003 break;
8004 }
8005 break;
8006 }
8007 case 'p':
8008 {
8009 if (LocaleCompare("print",option+1) == 0)
8010 {
8011 char
8012 *string;
8013
cristy6fccee12011-10-20 18:43:18 +00008014 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy018f07f2011-09-04 21:15:19 +00008015 string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
8016 exception);
cristy3ed852e2009-09-05 21:47:34 +00008017 if (string == (char *) NULL)
8018 break;
cristyb51dff52011-05-19 16:55:47 +00008019 (void) FormatLocaleFile(stdout,"%s",string);
cristy3ed852e2009-09-05 21:47:34 +00008020 string=DestroyString(string);
8021 }
8022 if (LocaleCompare("process",option+1) == 0)
8023 {
8024 char
8025 **arguments;
8026
8027 int
8028 j,
8029 number_arguments;
8030
cristy6fccee12011-10-20 18:43:18 +00008031 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008032 arguments=StringToArgv(argv[i+1],&number_arguments);
8033 if (arguments == (char **) NULL)
8034 break;
8035 if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8036 {
8037 char
8038 breaker,
8039 quote,
8040 *token;
8041
8042 const char
8043 *arguments;
8044
8045 int
8046 next,
8047 status;
8048
8049 size_t
8050 length;
8051
8052 TokenInfo
8053 *token_info;
8054
8055 /*
8056 Support old style syntax, filter="-option arg".
8057 */
8058 length=strlen(argv[i+1]);
8059 token=(char *) NULL;
cristy37e0b382011-06-07 13:31:21 +00008060 if (~length >= (MaxTextExtent-1))
cristy3ed852e2009-09-05 21:47:34 +00008061 token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8062 sizeof(*token));
8063 if (token == (char *) NULL)
8064 break;
8065 next=0;
8066 arguments=argv[i+1];
8067 token_info=AcquireTokenInfo();
8068 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8069 "\"",'\0',&breaker,&next,&quote);
8070 token_info=DestroyTokenInfo(token_info);
8071 if (status == 0)
8072 {
8073 const char
8074 *argv;
8075
8076 argv=(&(arguments[next]));
8077 (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8078 exception);
8079 }
8080 token=DestroyString(token);
8081 break;
8082 }
cristy91c0da22010-05-02 01:44:07 +00008083 (void) SubstituteString(&arguments[1],"-","");
cristy3ed852e2009-09-05 21:47:34 +00008084 (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8085 number_arguments-2,(const char **) arguments+2,exception);
8086 for (j=0; j < number_arguments; j++)
8087 arguments[j]=DestroyString(arguments[j]);
8088 arguments=(char **) RelinquishMagickMemory(arguments);
8089 break;
8090 }
8091 break;
8092 }
8093 case 'r':
8094 {
8095 if (LocaleCompare("reverse",option+1) == 0)
8096 {
8097 ReverseImageList(images);
cristy3ed852e2009-09-05 21:47:34 +00008098 break;
8099 }
8100 break;
8101 }
8102 case 's':
8103 {
cristy4285d782011-02-09 20:12:28 +00008104 if (LocaleCompare("smush",option+1) == 0)
8105 {
8106 Image
8107 *smush_image;
8108
8109 ssize_t
8110 offset;
8111
cristy6fccee12011-10-20 18:43:18 +00008112 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristy4285d782011-02-09 20:12:28 +00008113 offset=(ssize_t) StringToLong(argv[i+1]);
8114 smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8115 MagickFalse,offset,exception);
8116 if (smush_image == (Image *) NULL)
8117 {
8118 status=MagickFalse;
8119 break;
8120 }
8121 *images=DestroyImageList(*images);
8122 *images=smush_image;
8123 break;
8124 }
cristy3ed852e2009-09-05 21:47:34 +00008125 if (LocaleCompare("swap",option+1) == 0)
8126 {
8127 Image
8128 *p,
8129 *q,
8130 *swap;
8131
cristybb503372010-05-27 20:51:26 +00008132 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008133 swap_index;
8134
8135 index=(-1);
8136 swap_index=(-2);
8137 if (*option != '+')
8138 {
8139 GeometryInfo
8140 geometry_info;
8141
8142 MagickStatusType
8143 flags;
8144
8145 swap_index=(-1);
8146 flags=ParseGeometry(argv[i+1],&geometry_info);
cristybb503372010-05-27 20:51:26 +00008147 index=(ssize_t) geometry_info.rho;
cristy3ed852e2009-09-05 21:47:34 +00008148 if ((flags & SigmaValue) != 0)
cristybb503372010-05-27 20:51:26 +00008149 swap_index=(ssize_t) geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00008150 }
8151 p=GetImageFromList(*images,index);
8152 q=GetImageFromList(*images,swap_index);
8153 if ((p == (Image *) NULL) || (q == (Image *) NULL))
8154 {
8155 (void) ThrowMagickException(exception,GetMagickModule(),
8156 OptionError,"NoSuchImage","`%s'",(*images)->filename);
8157 status=MagickFalse;
8158 break;
8159 }
8160 if (p == q)
8161 break;
8162 swap=CloneImage(p,0,0,MagickTrue,exception);
8163 ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8164 ReplaceImageInList(&q,swap);
8165 *images=GetFirstImageInList(q);
8166 break;
8167 }
8168 break;
8169 }
8170 case 'w':
8171 {
8172 if (LocaleCompare("write",option+1) == 0)
8173 {
cristy071dd7b2010-04-09 13:04:54 +00008174 char
cristy06609ee2010-03-17 20:21:27 +00008175 key[MaxTextExtent];
8176
cristy3ed852e2009-09-05 21:47:34 +00008177 Image
8178 *write_images;
8179
8180 ImageInfo
8181 *write_info;
8182
cristy6fccee12011-10-20 18:43:18 +00008183 (void) SyncImagesSettings(mogrify_info,*images,exception);
cristyb51dff52011-05-19 16:55:47 +00008184 (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
cristy06609ee2010-03-17 20:21:27 +00008185 (void) DeleteImageRegistry(key);
cristy3ed852e2009-09-05 21:47:34 +00008186 write_images=(*images);
8187 if (*option == '+')
8188 write_images=CloneImageList(*images,exception);
cristy6b3da3a2010-06-20 02:21:46 +00008189 write_info=CloneImageInfo(mogrify_info);
cristy3ed852e2009-09-05 21:47:34 +00008190 status&=WriteImages(write_info,write_images,argv[i+1],exception);
8191 write_info=DestroyImageInfo(write_info);
8192 if (*option == '+')
8193 write_images=DestroyImageList(write_images);
8194 break;
8195 }
8196 break;
8197 }
8198 default:
8199 break;
8200 }
8201 i+=count;
8202 }
8203 quantize_info=DestroyQuantizeInfo(quantize_info);
cristy6b3da3a2010-06-20 02:21:46 +00008204 mogrify_info=DestroyImageInfo(mogrify_info);
8205 status&=MogrifyImageInfo(image_info,argc,argv,exception);
cristy3ed852e2009-09-05 21:47:34 +00008206 return(status != 0 ? MagickTrue : MagickFalse);
8207}
8208
8209/*
8210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8211% %
8212% %
8213% %
8214+ M o g r i f y I m a g e s %
8215% %
8216% %
8217% %
8218%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8219%
8220% MogrifyImages() applies image processing options to a sequence of images as
8221% prescribed by command line options.
8222%
8223% The format of the MogrifyImage method is:
8224%
8225% MagickBooleanType MogrifyImages(ImageInfo *image_info,
8226% const MagickBooleanType post,const int argc,const char **argv,
8227% Image **images,Exceptioninfo *exception)
8228%
8229% A description of each parameter follows:
8230%
8231% o image_info: the image info..
8232%
8233% o post: If true, post process image list operators otherwise pre-process.
8234%
8235% o argc: Specifies a pointer to an integer describing the number of
8236% elements in the argument vector.
8237%
8238% o argv: Specifies a pointer to a text array containing the command line
8239% arguments.
8240%
anthonye9c27192011-03-27 08:07:06 +00008241% o images: pointer to a pointer of the first image in image list.
cristy3ed852e2009-09-05 21:47:34 +00008242%
8243% o exception: return any errors or warnings in this structure.
8244%
8245*/
8246WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8247 const MagickBooleanType post,const int argc,const char **argv,
8248 Image **images,ExceptionInfo *exception)
8249{
8250#define MogrifyImageTag "Mogrify/Image"
8251
anthonye9c27192011-03-27 08:07:06 +00008252 MagickStatusType
8253 status;
cristy3ed852e2009-09-05 21:47:34 +00008254
cristy0e9f9c12010-02-11 03:00:47 +00008255 MagickBooleanType
8256 proceed;
8257
anthonye9c27192011-03-27 08:07:06 +00008258 size_t
8259 n;
cristy3ed852e2009-09-05 21:47:34 +00008260
cristybb503372010-05-27 20:51:26 +00008261 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00008262 i;
8263
cristy3ed852e2009-09-05 21:47:34 +00008264 assert(image_info != (ImageInfo *) NULL);
8265 assert(image_info->signature == MagickSignature);
8266 if (images == (Image **) NULL)
8267 return(MogrifyImage(image_info,argc,argv,images,exception));
anthonye9c27192011-03-27 08:07:06 +00008268 assert((*images)->previous == (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008269 assert((*images)->signature == MagickSignature);
8270 if ((*images)->debug != MagickFalse)
8271 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8272 (*images)->filename);
8273 if ((argc <= 0) || (*argv == (char *) NULL))
8274 return(MagickTrue);
8275 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8276 (void *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00008277 status=0;
anthonye9c27192011-03-27 08:07:06 +00008278
anthonyce2716b2011-04-22 09:51:34 +00008279#if 0
cristy1e604812011-05-19 18:07:50 +00008280 (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8281 post?"post":"pre");
anthonyce2716b2011-04-22 09:51:34 +00008282#endif
8283
anthonye9c27192011-03-27 08:07:06 +00008284 /*
8285 Pre-process multi-image sequence operators
8286 */
cristy3ed852e2009-09-05 21:47:34 +00008287 if (post == MagickFalse)
8288 status&=MogrifyImageList(image_info,argc,argv,images,exception);
anthonye9c27192011-03-27 08:07:06 +00008289 /*
8290 For each image, process simple single image operators
8291 */
8292 i=0;
8293 n=GetImageListLength(*images);
cristy9f027d12011-09-21 01:17:17 +00008294 for ( ; ; )
cristy3ed852e2009-09-05 21:47:34 +00008295 {
anthonyce2716b2011-04-22 09:51:34 +00008296#if 0
cristy1e604812011-05-19 18:07:50 +00008297 (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8298 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008299#endif
anthonye9c27192011-03-27 08:07:06 +00008300 status&=MogrifyImage(image_info,argc,argv,images,exception);
8301 proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
cristy0e9f9c12010-02-11 03:00:47 +00008302 if (proceed == MagickFalse)
8303 break;
anthonye9c27192011-03-27 08:07:06 +00008304 if ( (*images)->next == (Image *) NULL )
8305 break;
8306 *images=(*images)->next;
8307 i++;
cristy3ed852e2009-09-05 21:47:34 +00008308 }
anthonye9c27192011-03-27 08:07:06 +00008309 assert( *images != (Image *) NULL );
anthonyce2716b2011-04-22 09:51:34 +00008310#if 0
cristy1e604812011-05-19 18:07:50 +00008311 (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8312 GetImageIndexInList(*images),(long)GetImageListLength(*images));
anthonyce2716b2011-04-22 09:51:34 +00008313#endif
anthonye9c27192011-03-27 08:07:06 +00008314
8315 /*
8316 Post-process, multi-image sequence operators
8317 */
8318 *images=GetFirstImageInList(*images);
cristy3ed852e2009-09-05 21:47:34 +00008319 if (post != MagickFalse)
anthonye9c27192011-03-27 08:07:06 +00008320 status&=MogrifyImageList(image_info,argc,argv,images,exception);
cristy3ed852e2009-09-05 21:47:34 +00008321 return(status != 0 ? MagickTrue : MagickFalse);
8322}